   .Obj confusion
  heey all,Lately I've been trying to load a .obj file into my game. There is only one thing i'm confused about.I understand that all indices are 1-based.I understand that there is 1 normal per vertex in a triangle (this makes 3 normals per triangle)But what I don't understand is the following:I have a .obj file for a cube.In this fill are:- 8 vertices- 36 normals- 24 texture vertices- 12 faces (triangles)Why are there only 24 texture vertices? should there be 36, one for each vertex in a triangle, 3 per triangle?Can anyone help me with this?assainatorthe file:v  -10.9964 -11.5421 0.0000v  -8.6342 -11.5421 0.0000v  -10.9964 -9.5735 0.0000v  -8.6342 -9.5735 0.0000v  -10.9964 -11.5421 2.7559v  -8.6342 -11.5421 2.7559v  -10.9964 -9.5735 2.7559v  -8.6342 -9.5735 2.7559# 8 verticesvn 0.0000 0.0000 -1.0000vn 0.0000 0.0000 -1.0000vn 0.0000 0.0000 -1.0000vn 0.0000 0.0000 -1.0000vn 0.0000 0.0000 -1.0000vn 0.0000 0.0000 -1.0000vn 0.0000 0.0000 1.0000vn 0.0000 0.0000 1.0000vn 0.0000 0.0000 1.0000vn 0.0000 0.0000 1.0000vn 0.0000 0.0000 1.0000vn 0.0000 0.0000 1.0000vn 0.0000 -1.0000 0.0000vn 0.0000 -1.0000 0.0000vn 0.0000 -1.0000 0.0000vn 0.0000 -1.0000 0.0000vn 0.0000 -1.0000 0.0000vn 0.0000 -1.0000 0.0000vn 1.0000 0.0000 0.0000vn 1.0000 0.0000 0.0000vn 1.0000 0.0000 0.0000vn 1.0000 0.0000 0.0000vn 1.0000 0.0000 0.0000vn 1.0000 0.0000 0.0000vn 0.0000 1.0000 0.0000vn 0.0000 1.0000 0.0000vn 0.0000 1.0000 0.0000vn 0.0000 1.0000 0.0000vn 0.0000 1.0000 0.0000vn 0.0000 1.0000 0.0000vn -1.0000 0.0000 0.0000vn -1.0000 0.0000 0.0000vn -1.0000 0.0000 0.0000vn -1.0000 0.0000 0.0000vn -1.0000 0.0000 0.0000vn -1.0000 0.0000 0.0000# 36 vertex normalsvt 0.6742 0.4165 0.0000vt 0.3839 0.4165 0.0000vt 0.3839 0.0100 0.0000vt 0.6742 0.0100 0.0000vt 0.3584 0.8484 0.0000vt 0.0100 0.8484 0.0000vt 0.0100 0.4419 0.0000vt 0.3584 0.4419 0.0000vt 0.6997 0.0100 0.0000vt 0.9900 0.0100 0.0000vt 0.9900 0.3584 0.0000vt 0.6997 0.3584 0.0000vt 0.6742 0.8484 0.0000vt 0.3839 0.8484 0.0000vt 0.3839 0.4419 0.0000vt 0.6742 0.4419 0.0000vt 0.3584 0.4165 0.0000vt 0.0100 0.4165 0.0000vt 0.0100 0.0100 0.0000vt 0.3584 0.0100 0.0000vt 0.9900 0.4419 0.0000vt 0.9900 0.7903 0.0000vt 0.6997 0.7903 0.0000vt 0.6997 0.4419 0.0000# 24 texture coordsg Box01f 1/9/1 3/10/2 4/11/3 f 4/11/4 2/12/5 1/9/6 f 5/21/7 6/22/8 8/23/9 f 8/23/10 7/24/11 5/21/12 f 1/5/13 2/6/14 6/7/15 f 6/7/16 5/8/17 1/5/18 f 2/13/19 4/14/20 8/15/21 f 8/15/22 6/16/23 2/13/24 f 4/17/25 3/18/26 7/19/27 f 7/19/28 8/20/29 4/17/30 f 3/1/31 1/2/32 5/3/33 f 5/3/34 7/4/35 3/1/36 # 12 faces
  Each side of the cube is made up of two triangles.  The triangles share two of their texture verts.  Therefore each side of the cube only needs four texture verts (one per corner) x 6 sides = 24 texture verts.I'm not experienced with the .obj format, but I wonder why the normals weren't shared as well (since there only needs to be 6 of those)   ;  Thanks for the explanation. But what if the model isn't a cube but a large >15.000 polygon mesh? Then how does it work? thanks in advance,assainator   ;Quote:Original post by assainatorThanks for the explanation. But what if the model isn't a cube but a large >15.000 polygon mesh? Then how does it work? thanks in advance,assainatorThat depends on the exporter you use. But usually (optimally) shared vertices have shared normals and uv coordinates, unless for example there is a seam in the uv map or a sharp edge in the normals.   ;  But the problem is: how to find out?I have found a format that I like a lot more, it looks like obj but is still quite different: STLThe only disadvantage is that vertices are defined more than once.How do I filter that out?a box example:solid Object01  facet normal 0.000000e+000 -0.000000e+000 -1.000000e+000    outer loop vertex 3.464709e+000 4.705885e+000 0.000000e+000 vertex 3.464709e+000 6.674389e+000 0.000000e+000 vertex 5.433213e+000 6.674389e+000 0.000000e+000    endloop  endfacet  facet normal 0.000000e+000 0.000000e+000 -1.000000e+000    outer loop vertex 5.433213e+000 6.674389e+000 0.000000e+000 vertex 5.433213e+000 4.705885e+000 0.000000e+000 vertex 3.464709e+000 4.705885e+000 0.000000e+000    endloop  endfacet  facet normal 0.000000e+000 0.000000e+000 1.000000e+000    outer loop vertex 3.464709e+000 4.705885e+000 1.968504e+000 vertex 5.433213e+000 4.705885e+000 1.968504e+000 vertex 5.433213e+000 6.674389e+000 1.968504e+000    endloop  endfacet  facet normal 0.000000e+000 0.000000e+000 1.000000e+000    outer loop vertex 5.433213e+000 6.674389e+000 1.968504e+000 vertex 3.464709e+000 6.674389e+000 1.968504e+000 vertex 3.464709e+000 4.705885e+000 1.968504e+000    endloop  endfacet  facet normal -0.000000e+000 -1.000000e+000 0.000000e+000    outer loop vertex 3.464709e+000 4.705885e+000 0.000000e+000 vertex 5.433213e+000 4.705885e+000 0.000000e+000 vertex 5.433213e+000 4.705885e+000 1.968504e+000    endloop  endfacet  facet normal 0.000000e+000 -1.000000e+000 0.000000e+000    outer loop vertex 5.433213e+000 4.705885e+000 1.968504e+000 vertex 3.464709e+000 4.705885e+000 1.968504e+000 vertex 3.464709e+000 4.705885e+000 0.000000e+000    endloop  endfacet  facet normal 1.000000e+000 0.000000e+000 0.000000e+000    outer loop vertex 5.433213e+000 4.705885e+000 0.000000e+000 vertex 5.433213e+000 6.674389e+000 0.000000e+000 vertex 5.433213e+000 6.674389e+000 1.968504e+000    endloop  endfacet  facet normal 1.000000e+000 0.000000e+000 0.000000e+000    outer loop vertex 5.433213e+000 6.674389e+000 1.968504e+000 vertex 5.433213e+000 4.705885e+000 1.968504e+000 vertex 5.433213e+000 4.705885e+000 0.000000e+000    endloop  endfacet  facet normal -0.000000e+000 1.000000e+000 0.000000e+000    outer loop vertex 5.433213e+000 6.674389e+000 0.000000e+000 vertex 3.464709e+000 6.674389e+000 0.000000e+000 vertex 3.464709e+000 6.674389e+000 1.968504e+000    endloop  endfacet  facet normal 0.000000e+000 1.000000e+000 0.000000e+000    outer loop vertex 3.464709e+000 6.674389e+000 1.968504e+000 vertex 5.433213e+000 6.674389e+000 1.968504e+000 vertex 5.433213e+000 6.674389e+000 0.000000e+000    endloop  endfacet  facet normal -1.000000e+000 0.000000e+000 0.000000e+000    outer loop vertex 3.464709e+000 6.674389e+000 0.000000e+000 vertex 3.464709e+000 4.705885e+000 0.000000e+000 vertex 3.464709e+000 4.705885e+000 1.968504e+000    endloop  endfacet  facet normal -1.000000e+000 0.000000e+000 0.000000e+000    outer loop vertex 3.464709e+000 4.705885e+000 1.968504e+000 vertex 3.464709e+000 6.674389e+000 1.968504e+000 vertex 3.464709e+000 6.674389e+000 0.000000e+000    endloop  endfacetendsolid Object01;  Assuming that you're still asking about OBJ's, what you might want to do is create some kind of map between the given individual indices (vertex index, normal index, etc) and your "unified vertex index".For example you could have a map with a key that is a tuple (int vertindex, int normalindex, int texcoordindex).Then when you parse your obj file you come across this:1/9/1So you ask your map: Do I have a vertex for key(1,9,1)? If you don't have one then just copy those three values into a new "unified vertex", and assign an index for it into the map. Then if 1/9/1 comes up again later in the OBJ you already have it. While if you see (1,9,2), you just duplicate all the data again into a new vertex.I know it feels like a waste, but this is what the GPU needs to render it properly.   