1
\$\begingroup\$

I have been loading obj files and using indices for handling duplicated vector positions, but I have not gotten to the point of requiring normal data to be passed to the shaders as well.

The problem I have is that obj files store the relevant normal data in the face field, and when it comes to loading a point that is used multiple times, the normal might be different for each subsequent face including a particular vertex, but I can only pass one normal per vertex.

How would people suggest getting around this issue?

I can only think of two ways, either stop using indices and that will allow me to pass unique position vector / normal pairings, or store all instances of position/normal pairs and if a new normal is required for a position, create it and index it accordingly.

\$\endgroup\$
1

1 Answer 1

2
\$\begingroup\$

First convert the obj mesh to a non-indexed mesh with vertex+normal+other attributes.

Then convert back to indexed by merging identical vertex entries.

The 2nd step can be made generic to be re-used for other mesh format loaders and indexing procedurally generated meshes.

\$\endgroup\$
2
  • \$\begingroup\$ So when I come across a vertex and normal pair I have already used, then use the previous index, otherwise, generate a new one? \$\endgroup\$
    – 0xen
    Aug 7, 2017 at 0:22
  • \$\begingroup\$ Yes. You build your vertex buffer and index buffer by looking into the vertex buffer for an identical vertex (including attributes such as normal), if not found, add it and use that new index. \$\endgroup\$ Aug 7, 2017 at 0:43

You must log in to answer this question.

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