0

Code that I'm trying to understand represents meshes using this structure:

struct vertex
{
    float v[3]; // vertex coords
    float t[3]; // texture coords
    float n[3]; // normals
};
typedef unsigned face[3];
struct mesh
{
    vector<vertex> vn;
    vector<face> fn;
};

Then, I wrote a quick parser for wavefront obj mesh format. This is the sample mesh that I'm loading. It only has v, vn, vt, f elements. The most important part of this sample mesh is that it has all faces with matching indices for v/vt/vn and I can load it easily into my struct mesh specified above:

f 2/2/2 2/2/2 1/1/1
f 1/1/1 2/2/2 3/3/3
...

Now, I'm trying to figure out how to load an obj mesh that does not have these v/vt/vn matching. This second sample mesh supposedly should represent identical shape to the one specified above. As you can see faces do not always have matching v/vt/vn triplets, like here:

f 3/3/3 1/1/1 2/2/2
f 2/2/2 1/1/1 6/12/6
...
f 3/15/3 10/13/10 9/14/9
...

It would be ok if the triplets were unique (e.g. always 3/15/3), but there are also different triplets for v=3: 3/3/3.

If I ignore for now /vt/vn part I can still load the shape but I loose normals/texture coords and I do not get correct visual representation of the shape (looses textures and light reflection from the shape). What should I do to load that mesh properly into my internal representation? Should I just create two vertices with identical coords where one vertex would have vn=3,vt=3 and the other one would have vn=15,vt=3?..

(disclaimer: my experience in 3d graphics and meshes is about a day and a half)

Pavel P
  • 15,789
  • 11
  • 79
  • 128

0 Answers0