开发者

Loading 'indices' from Wavefront OBJ format

开发者 https://www.devze.com 2023-01-28 13:15 出处:网络
I\'m developing an Android application with OpenGL ES 2.0. I want to load an export made with Blender 2.49b in Wavefront OBJ format. I have identified verxtex position, normal and texture.

I'm developing an Android application with OpenGL ES 2.0.

I want to load an export made with Blender 2.49b in Wavefront OBJ format. I have identified verxtex position, normal and texture.

I want to use glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices) to draw my mesh but I don't know how I can obtai开发者_StackOverflow中文版n the last parameter, indices, from a Wavefront OBJ file.

Are faces the 'indices' that I'm looking for?

I've found this on a forum: faces = indices starting with 1!

What is the meaning of 'starting with 1!'?

Thanks.


It means the first index is 1 instead of zero. Java/C arrays/collections use zero based indicies and the first element starts with zero. Wavefront OBJ format indexes start with 1.

faces are made up for 3 values v/vt/vn which are indexes. The indexes are not specified directly in the file format. Instead it's the order in which the v, vt, vn elements occur in the file. So as you are parsing the file you have to keep track of how many vertexes, vertex texture, and vertex normals you have encountered.

For all the details on the format you'll want to consult the spec.

http://www.martinreddy.net/gfx/3d/OBJ.spec


There are no indices in the wavefront .obj format. You are the one that specifies the indices when you load the mesh data from the file. What I'd do is:

iterate per face:
    iterate every vertex of a face
        assign index here when you store the data to your own project's vector

In other words for each of these lines:

f 3/55/23 34/2/12 34/43/128
f ...

for each triple of attributes introduce a new vertex (to be stored in the vertex buffer) and a new index (to be stored in the index buffer).

0

精彩评论

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