1
\$\begingroup\$

I am using TinyObj to load models. I found many obj files have different vertices and normal size, how could it happen? I thought in the obj file one normal should be correspond to one vertex.

For example, I am loading one apple model, the vertices size is 6492 and normal size is 6557. How to handle this stituation? Some files have more vertices and some have more normals. Does it means I have to give up some attributes of the model?

I also found the obj file has normal index, but I dont know how to use it. Does it matter to this problem?

In opengl/directx I have only used vertex index in the index buffer.

Can you give me some idea or reference about it?

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

The Wikipedia page about the Wavefront .obj file, contains a lot of information boiled down to less lines than it could be.

Some files have more vertices and some have more normals. Does it means I have to give up some attributes of the model?

No, that's just how the OBJ format works. Essentially whether the file contains:

v 0.5 0.5 0.5
v 0.5 0.5 0.5

f 1 ...
f 2 ...

or

v 0.5 0.5 0.5

f 1 ...
f 1 ...

It would be the same model. The reason you're seeing more normals than vertices, is because there's more common vertices than normals. Some faces are essentially sharing the same vertex in the sense of an OBJ model. So in your case there's more faces shares vertices than normals.

In opengl/directx I have only used vertex index in the index buffer.

When it comes to drawing the model. Then you can't just leverage the indices from the OBJ model. Because an index buffer needs an index to a vertex. Where a vertex consists of the position, normal, etc. In the OBJ format that's not the case.

So after loading all the vertices, normals, texture coordinates and faces. You'd basically have to remap it. Extracting all the triangles, so to speak

\$\endgroup\$
2
  • \$\begingroup\$ thank u, I have done it. But there comes another problem, some obj files have full normals vn and textcoordsvt and the full index of them f ../../.., but many don't have. If I need these datas, how to fix it? do you know somewhere to find these full obj models? \$\endgroup\$
    – HUAQ
    Mar 24, 2017 at 5:32
  • \$\begingroup\$ @Fer_Hua go back to where you got the obj file from and check if they have a version with the texture/normal, if not then you will need to pull it in a modeling application and add them yourself. \$\endgroup\$ Mar 24, 2017 at 9:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .