# Questions about the obj file format

I'm wirting my first OpenGL Application for Android at the moment and now I get stuck on the ObjectLoader for obj files. I have some qestions to this file format and I can't an answer on the internet for this. Maybe it is easier if we go throught all these questions with an example file:

#Cube file - has no texture
mtllib dice_material.mtl

v 0.475013 0.999999 -0.066651    # 1
v 0.457026 0.999999 -0.067220    # 2
v 0.439582 0.999999 -0.067505    # 3
...
vn 0.000000 1.000000 0.000000    # 1
vn 0.000000 0.999969 0.000000
vn 0.000000 0.778466 0.627674
...
f 1//1 11//1 14//1 2//1          # the first 1 references to the first v right?
f 2//1 14//1 15//1 3//1          # the first 2 references to the second v right?
f 3//1 15//1 16//1 4//1

• Can I assume that allways the verticies v are on the head of the document (after some comments) followed by the texture coordinates (tv) and the normales (vn)?

• If an object has a texture does the obj file allways have the texture coordinates? If not how can I calculate them on my own?

• If the object has a texture is it required that the object has a material too or can an object have a texture without a material?

• If the file contains the texture coordinates do the polygons (f) must contain the texture coordinates? Or is f 1//1 a valid polygon too if the file contains the texture coordinates?

• I suggest you have a look at those two articles from scratch-a-pixel, they will answer most of your questions about obj's. They are very well written and describe the reading process as well. – G.Rassovsky Jul 26 '14 at 19:12

1: Im not 100% sure, but those 3d-softwares i know WILL write all the vertices before the faces

2: No not everytime and you cant calculate them

Edit: Of course, if it has a texture it will have texture-coordinates (if your 3d-modeling-software doesnt suck :D )

3: You cant put an texture directly on the mesh, you can only put an material on the mesh which itself uses an material, so there is no way that there is a texture but no material. (Speaking from 3D-Modeling software. how you render then is up to you, you dont need to read the material-data if you dont want to, just load the texture and use it)

4: i dont really understand?! f 1/1/1 2/2/2 3/3/3 Every block (1/1/1 is one block) is one single point, 3 of them make a triangle. the first number is the vertex-index (for 'v') the second is the texturecoordinate-index (for 'vt'), and the third one is the normal-index (for 'vn')

The vertex-index is the only one which is really needed. you could just use only vertex-indices: f 1 2 3 you could also use vertex-indices and texture-indices f 1/1 2/2 3/3 or vertex-indices and normal-indices: f 1//1 2//2 3//3

You can read http://en.wikipedia.org/wiki/Wavefront_.obj_file for more Informations, im sorry, my english isnt good enough to explain this better :/