Sign in to follow this  
lilrooness

How do I use face data in an OBJ file ?

Recommended Posts

After watching this tutorial by the coding universe (http://www.youtube.com/watch?v=izKAvSV3qk0), 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 ?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this