开发者

.obj file conversion to OpenGL model header file - indices and f parameters?

The OpenGL model header file I'm working with contains definitio开发者_开发技巧ns along the following:

static const float modelVertices[NUM_OBJECT_VERTEX * 3] = {}

static const float modelTexCoords[NUM_OBJECT_VERTEX * 2] = {}

static const float modelNormals[NUM_OBJECT_VERTEX * 3] = {}

static const unsigned short modelIndices[NUM_OBJECT_INDEX] = {}

Where there are a bunch of numbers (floats and integers, as fitting) separated by comma's inbetween the brackets.

It seems straight-forward to convert an .obj file's v, vt, vn to the above format. My .obj file also has a bunch of f's which include triplets separated by /. I'm not sure what these parameters are exactly...

Which parameters do I need to convert to get the fourth - the modelIndices?

(I need to admit in advance that I am a newbie to OpenGL, so apologies if this seems too elementary!)


Triplets are just a face definition.

If you have f 1 2 3

This means you have a triangle that is made of vertex of indices 1 2 and 3.

If all entries are like that, that means you can directly fill your modelIndices with those indices, and draw them using GL_TRIANGLES.

Now if they are separated by / this means you have different mapping between vertices position and texture coordinates and/or normals.

This is something OpenGL can't handle directly and the way to go for you is to explode the texcoord and normal data into arrays of the same size than vertice position array.

To do this is trivial: here's pseudo code:

read face data (triplets)
for each triplet
   read vertex indice
   read texcoord and normal indices
   fetch texcoord @ texcoord indice from your vt array
   store texcoord @ vertex indice in your modelTexCoords array
   fetch normal @ normal indice from your vn array
   store normal @ vertex indice in your modelTexCoords array

   etc

See also wikipedia's doc, which explain well .obj format: http://en.wikipedia.org/wiki/Obj

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜