Question

I followed this great tutorial on how to prepare an .obj file parser and I got lost in the end and I don't know what to do!

I Made some very simple model in Blender and saved it just like it is said in the tutorial. According to that, I should have 3 faces coordinates like this:

f 5/1/1 1/2/1 4/3/1
f 5/1/1 4/3/1 8/4/1
f 3/5/2 7/6/2 8/7/2
f 3/5/2 8/7/2 4/8/2
f 2/9/3 6/10/3 3/5/3
f 6/10/4 7/6/4 3/5/4
f 1/2/5 5/1/5 2/9/5
f 5/1/6 6/10/6 2/9/6
f 5/1/7 8/11/7 6/10/7
f 8/11/7 7/12/7 6/10/7
f 1/2/8 2/9/8 3/13/8
f 1/2/8 3/13/8 4/14/8

In my case, I have only two, and the middle one is empty:

f 1//1 2//1 4//1
f 5//2 8//2 7//2
f 1//3 5//3 2//3
f 2//4 6//4 7//4
f 3//5 7//5 8//5
f 5//6 1//6 4//6
f 8//7 5//7 4//7
f 6//8 5//8 7//8
f 2//9 3//9 4//9
f 5//10 6//10 2//10
f 3//11 2//11 7//11
f 4//5 3//5 8//5

I'm surely doing something wrong, but I have no idea what is that.

Was it helpful?

Solution

It's allowed in OBJ file format to simply omit texture attribute. Thus, f 1//1 2//1 3//1 is a valid triangle, just only with positions and normals. You should change your parser to accept that (which shouldn't be very hard).

Wikipedia article about OBJ explains that rather well:

Vertex/normal

As texture coordinates are optional, one can define geometry without them, but one must put two slashes after the vertex index before putting the normal index:

f v1//vn1 v2//vn2 v3//vn3

Also keep in mind that you don't have to specify normals either, and a face can look like:

f 1/1 2/2 3/3
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top