So I'm writing a parser for wavefront obj model files and there are a few irregularities that I'm not sure how to handle.
So based off of my reading, a mesh can be broken up into groups using the 'g' command and a material can be assigned to each group using the 'usemtl' command
So an ideal file would look like this:
g group1
usemtl material1
//vertices
//UV coords
//faces
g group2
usemtl material2
//vertices
//UV coords
//faces
etc....
However in some obj files I've downloaded (from places like Turbosquid), I've seen a single group contain multiple "usemtl" like this:
g group1
usemtl material1
//vertices, faces, etc
usemtl material2
//vertices, faces, etc
g group2
usematerial material3
//vertices, faces, etc
So if there can be multiple materials per group then what is the point of a group?
Are these files considered "non-standard" or broken?
Should I instead be grouping faces based on shared material instead of shared group?
Having multiple materials per group would complicate a lot of my code (for instance - let's say I have to generate a set of N random samples on a group of triangles/faces with a certain material. If there's just one material per group I can just look up the triangles in that group and generate samples. But if that group contained some triangles with the correct material and some without, I'd have to do some weird material checking on top of the group checking to generate the right samples. This is just one example - there are others where this becomes an issue as well)
The OBJ file format is a simple data-format that represents 3D geometry alone — namely, the position of each vertex, the UV position of each texture coordinate vertex, vertex normals, and the faces that make each polygon defined as a list of vertices, and texture vertices.
Just install the software OBJ Viewer To begin viewing 3D files, simply do the following Install the extension OBJ Viewer Click on the extension icon Choose the 3D file you wish to open Begin viewing your 3D files online today!
An OBJ file (. obj) contains information about the geometry of 3D objects. The files are used for exchanging information, CAD, and 3D printing. OBJ files can support unlimited colors, and one file can define multiple objects.
The f indicates a face of the model (e.g., a triangle or a quad). The numbers are indices into the vertex list that indicate the way you should join it to form the face.
Obj meshes can be grouped not only into group items ( g), but objects (o) and smooth zones (s) Too. The easiest way is making faces reference the current material specified by usemtl, or just group by usemtl
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With