Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wavefront OBJ Format -> Groups & usemtl command

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)

like image 312
Sunny724 Avatar asked Jun 01 '15 20:06

Sunny724


People also ask

How is an OBJ file structured?

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.

How do I open a Wavefront OBJ file?

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!

What does OBJ file format stand for?

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.

What does F mean in OBJ file?

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.


1 Answers

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

like image 90
Shurbsk Avatar answered Oct 19 '22 18:10

Shurbsk