Search code examples
opengllwjglwavefront

Parsing OBJ file having multiple objects


On reading through the OBJ file format, I realized that there are several other attributes like Sub-objects (-o), Groups (-g) etc.

I am having trouble understanding how to parse these other parameters (if necessary). Should I load the vertices and faces data of every (-o) into separate VAOs?

Also, in that case, how will the rotation of the whole object work? Will all Sub-objects start rotating about their own centers?

How to make the multiple sub-objects rotate in unison like a single object and still have independent control over each whenever necessary?


Solution

  • Should I load the vertices and faces data of every (-o) into separate VAOs?

    Basically yes. Each object (-o) or smoothing group (-g or -s) is essentially a separate part of the overall model. So you should be creating a separate renderable mesh for each group.

    Generally the vertex data (vertices, normals, texture coordinates) is not shared between models, but there's nothing in the OBJ format to say they couldn't be AFAIK.

    How to make the multiple sub-objects rotate in unison like a single object and still have independent control over each whenever necessary?

    This is more of a design question. Assuming you have some sort of tree-like scene-graph then you would create a root node for the entire OBJ model and attach separate nodes for each group. To rotate the whole model you apply a transform to the root node. As far as I know the OBJ format does not specify transformations, rotations, etc.