Question

I exported a .obj from blender to be loaded into a C++ program i'm writing Everything is fine but I was wondering when Parsing the faces I noticed that there was an unused texture coordinate on the third point in the face data.

  f 1/1 2/2 3/3
//f 1/s 2/t 3/? Its vt3 that is the coordinate in question

What is this used for? and should I be keeping it?

Was it helpful?

Solution

I think you are slightly misunderstanding the obj file format, and getting confused by the mix of 3D and 2D coordinates.

Triangles do in fact have 3 texture coordinates, same as they have 3 positions. This is correct, expected, and even required. It would not make sense if two points on a triangles had texture coordinates, but one of them did not.

The f defines one face, in this case with three vertices (triangle). Each vertex has a single 3D position, and a 2D UV coordinate. This means that a triangle is made up of 3, 3D positions, and 3, 2D UV coordinates (one set for each vertex). The face numbers index into the arrays of vertex positions and texture coordinates, not the individual elements that make up these structures.

The notation actually looks like this.

f v1/vt1 v2/vt2 v3/vt3

Read these for more detail:

http://www.eg-models.de/formats/Format_Obj.html http://www.cs.cmu.edu/~mbz/personal/graphics/obj.html

This can be better visualized by thinking of a triangle structure in code such as:

struct
{
   Vec2 texCoord; // one vt for each vertex (s,t)
   Vec3 position; // one v for each vertex (x,y,z)
} Vertex;

struct
{
   Vertex verts[3]; // 3 vertices 
} Face;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top