OBJ to indexed VBO

Started by
1 comment, last by RobTheBloke 15 years, 11 months ago
I'm having problems wrapping my head around on how to convert a OBJ file to a indexed interleaved VBO as OBJ uses separate indexes for vertex, normal, texcoords instead of just 1 for all as OpenGL. Now i only use the vertices and it loads and works great, but i need help on how to get vertex, normal and texcoords (using a single index).
Advertisement
I'm afraid you will have to do a little more work in your Obj loading routines.
(Or of course, you could search for some Obj tool or source).
Anyway ... given a simple model that consists of a Vertex, tex coords and normals and a face index set you need to parse this into a vertex_array_friendly format.

The trick is to understand that the Obj file format is an optimized for storage format and not optimized for rendering. So - with that in mind you should essentially:

read the list of vertex coords and store in a temp vertex list
Do the same for the texture and normals
Then read each face in turn (and each face will have a set of indexes into the vertex, texture and normal temp lists). Use these indexes to obtain the corresponding vertex from the temp vertex list, the face-texture index to read the texture-coord from the temp texture list and so on for all the attributes. Finally, store the result into the Final_array_list and record the index in the final_index_list
see this

This topic is closed to new replies.

Advertisement