Jump to content
  • Advertisement
Sign in to follow this  
lilrooness

How do I use face data in an OBJ file ?

This topic is 2083 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 ?

Share this post


Link to post
Share on other sites
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!