• Create Account

How do I use face data in an OBJ file ?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

1 reply to this topic

#1lilrooness  Members

Posted 05 February 2013 - 05:32 PM

After watching this tutorial by the coding universe (), I am confused as to what face data (denoted by an f at the start of the line) in a .obj file is, and how it is supposed to be used.

As an exercise to try and find this out for myself, I experimented and wrote a parser for an obj file in java, that only loaded the vertex and normal data from the Stanford bunny model. I rendered it using glDrawArrays, but it came out contorted, with lines connecting triangles that shouldn't be connected.

It looked like this:

http://derp.co.uk/9a0ba

You can just see the basic shape of the bunny under all the stuff that isn't meant to be there.

Do I need the face data to render the model ? Can you do it without it ? If so how do you use it and what does it mean ?

#2swiftcoder  Senior Moderators

Posted 05 February 2013 - 06:21 PM

The face data defines which vertices make up each triangle in the model.

For example:
f 1 2 3
Defines a triangle made from the 1st, 2nd and 3rd vertices.

Ideally, you load all the vertices from the obj file into a single vertex array, and then load all the faces into an index array, for use with glDrawElements().

Unfortunately, things get significantly more complicated if you happen to have an obj file with normals and/or texture coordinates, because the face definition will give you an index for each. You pretty much have to build up all combinations of vertex/texcoord/normal, and remove the duplicates afterwards (regenerating the index array as you go).

Edited by swiftcoder, 05 February 2013 - 06:24 PM.

Tristam MacDonald - Software Engineer @ Amazon - [swiftcoding] [GitHub]

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.