obj format question

Started by
4 comments, last by timothyjlaird 8 years, 5 months ago

Question: can I have more than one object (denoted by 'o myobject') each with more than one group in it (denoted by 'g mygroup') in one wavefront obj file? This is my goal but it is not working.

if I do that I get a mangled model. The verts are in all the right places but they are not linked into triangles correctly (model is there but looks like crap).

If I split each wavefront object ('o') into its own seperate file with its own groups the model renders correctly.

If I don't bother with groups ('g') and replace each group with an object in a single file the model renders correctly.

Is this supposed to be the case? I have tried this with two different 3d model tools (open3dmod and DeleD) and the pattern seems consistent.

That is a bit long winded so I attached some files...

'head.obj', 'upper.obj' and 'lower.obj' each have one object (one file per object). These files import right.

'player_out.obj' has 'head.obj', 'upper.obj' and 'lower.obj' in it but it does not render correctly. Same text, just all appended in one file.

What combining all three objects with groups in one file and importing renders as...

player_out_mangled_zpsvwimy4ew.jpg

What importing all three obj files separately (each with only one object) renders as...

head_upper_lower_correct_zpslzehdb5x.jpg

My goal is to make player_out.obj work but it doesn't seem to be happening. I'm trying to figure out if I have misunderstood the format or the rendering programs (DeleD and open3mod) are not working correctly (unlikely).

To be clear...the model files I have attached were extracted (converted from md3 to obj). I did not make the original md3 models.

[attachment=29717:ayumi_objs.zip]

Advertisement

For a direct answer, I don't think the format supports multiple independent models the way you are describing. It does support having free-form objects, but that isn't really what you seem to describe. Normally it is one model per file. That one model can be a part of an even bigger model, composed with other data.

With that out of the way, I'm a little confused, WHY do you need this? What problem are you trying to solve?

Games routinely load hundreds, sometimes thousands of models.

The models initially are located at the origin, meaning position (0,0,0) of the world, but they can be rotated and translated, moved and turned and twisted until they are at the right location in the scene. They can also be instanced, meaning drawing the same model many times from the same data.

Generally the game engine and the modeler use some rules to build special vertex points to snap models together when they move. The game needs to use rules to build a hierarchy of what model is attached where, which is a tree structure easily maintained. When parts don't move they can still be combined together in various ways (depending on the engine) so they can all exist as individual meshes but move together or move with joints or otherwise co-exist.

If you are looking for simplifying your meshes and textures to reduce draw calls or something, there are ways to combine meshes together and fuse textures into an atlas for things like customizable clothing.

Is there some reason that won't work for you?

It looks like the lower part of the model render correct in your 'player_out.obj' image. The other parts are wrong as you can not simply put all the .obj's in the same file without changing them. The index used to specify faces are indexed from the start of the All the vertices in the file. So if you copy in head.obj after lower.obj in the same file then the head.obj triangles will use the vertices from lower.obj. You need to use a program such as blender or maya to merge the obj files and write a new one.

@spinningcubes | Blog: Spinningcubes.com | Gamedev notes: GameDev Pensieve | Spinningcubes on Youtube

As to the 'why'...this is more a learning project than a practical one. I wrote some python code to parse three md3 files that form a complete player model, take a frame from each, transform them using a matrix derived from tag data in the md3 files and then output the whole thing to one obj file (player_out.obj). The reason for obj is simply to make sure I got everything right before writing my own rendering code.

Okay.

So for the process of merging meshes, that can be done to effectively make them all a single model. As Spinningcubes pointed out, you'll need to change the indexes.

The file format is all about the geometry of a single object. The geometric object has a bunch of vertex data, texture coordinates, vertex normals, and other geometry data, then has details to build faces and triangle strips and other shapes based on the index numbers within the vertex data, all of it handled by index.

When you add the geometric vertex data to the file it does not restart its count at vertex 1. Instead the addition starts at the end of the previous collection. So if the first object used vertex 1-427, the object you are adding will begin at vertex 428. You will need to adjust all your indeces for faces, textures, normals, splines, and whatever else so it uses the updated index numbers. Instead of a face that included vertex 1, 2, and 3, it would need to be updated to vertex 428, 429, and 430.

Okay.

So for the process of merging meshes, that can be done to effectively make them all a single model. As Spinningcubes pointed out, you'll need to change the indexes.

The file format is all about the geometry of a single object. The geometric object has a bunch of vertex data, texture coordinates, vertex normals, and other geometry data, then has details to build faces and triangle strips and other shapes based on the index numbers within the vertex data, all of it handled by index.

When you add the geometric vertex data to the file it does not restart its count at vertex 1. Instead the addition starts at the end of the previous collection. So if the first object used vertex 1-427, the object you are adding will begin at vertex 428. You will need to adjust all your indeces for faces, textures, normals, splines, and whatever else so it uses the updated index numbers. Instead of a face that included vertex 1, 2, and 3, it would need to be updated to vertex 428, 429, and 430.

Thanks. That did the trick. Got it working.

This topic is closed to new replies.

Advertisement