PDA

View Full Version : loading in a wavefront .obj to be read into OpenGL



RET80
11-24-2011, 12:16 PM
I have created a loader to load in a wavefront obj file and then separate it into its respective parts.

So I have the v and vt read into their respective floats (and vn as well if its needed) however, I have no idea how to interpret the 'f' section, which would be faces.

Now the v and vt, once separated from the original .obj file that was read in, they are incrementally put into 2D arrays of floats and then put together in a model constructor.

Now what I'm stuck on is the f values, what are they, how do I interprit them, and how can read something like a/b a/b/c in.

I've looked online and some say its an index to an array? But I'm not too sure how or why, also I looked into the .obj file and the f section (face section) has negative values such as:

f -815/-4678 -816/-4679 -817/-4680
f -813/-4675 -814/-4676 -815/-4677
f -813/-4672 -815/-4673 -817/-4674

This is for a side project, programming on a preparatory platform in C
And yes, I am VERY new at this. :)

mobeen
11-24-2011, 08:42 PM
Hi,
The f section contains the indices of position/uv and normals. For the example I am giving below, I am assuming that you have a triangular face having position (v), texture coord(vt), and normals(vn) then these will be arranged as follows,


f i0/t0/n0 i1/t1/n1 i2/t2/n2

i0 is the index of the first vertex's position, i1 for second and i2 for third vertex,
t0 is the index of the first vertex's texture coordinate, t1 for second and t2 for third vertex,
n0 is the index of the first vertex's normal, n1 for second and n2 for third vertex.

So this way each line gives you all of the per vertex attribute indices.

For an example of loading a simple Obj mesh refer to the OBJ loader project here: http://spacesimulator.net/wiki/index.php?title=3d_Engine_Projects

Direct link to src code: http://spacesimulator.net/wiki/images/ObjLoader.zip

See if this helps.