danielepanozzo / cg-old

43 stars 16 forks source link

Why do .obj files specify separate vertex/texture-coordinate/normal/ values for each vertex of a face? #48

Open oveddan opened 7 years ago

oveddan commented 7 years ago

I'm trying to use some obj files downloaded from the web for assets.

In the faces section of the file, some of the faces look like:

f 25/25/25 23/23/23 24/24/24
f 24/24/24 26/26/26 25/25/25
f 27/27/27 25/25/25 26/26/26
f 26/26/26 28/28/28 27/27/27
f 10/10/10 27/27/27 28/28/28
f 28/28/28 11/11/11 10/10/10
f 29/29/29 7/30/7 8/31/8
f 8/31/8 30/32/30 29/29/29
f 31/33/31 29/29/29 30/32/30
f 30/32/30 32/34/32 31/33/31
f 33/35/33 31/33/31 32/34/32
f 32/34/32 34/36/34 33/35/33
f 35/37/35 33/35/33 34/36/3

Where each vertex represented on the face is in the format: v1/vt1/vn1 (Vertex index/Vertex Texture Coordinate Index/Vertex Normal Index)

Why would the texture coordinate and normal index be different from the vertex index?

How are we supposed to line up texture coordinates to verteces when we want to send them as VBOs?

Is there anyways of using this with the element array buffer?

danielepanozzo commented 7 years ago

We briefly discussed this in class. The obj contains two meshes: one for editing (and computing normals) and one for texture mapping. The two arrays of faces are in 1-1 correspondence (the first face of the editing mesh corresponds to the first face of the uv mesh), while the vertices can be different. This is needed since you need to have UV seams for the texture that are potentially different than the seams that are used to design the mesh. When you compute normals, you should not follow the UV seams, or it will create strange discontinuities.

If you want to render it, you should use only the UV mesh, and replicate the normal informations on the "mesh vertices" into the "uv vertices".