What is the best way to do this? Googling has shown me a bunch of ways, but what is the current best? I\'d be happy enough to just get the model exported from Maya and rende
I just finished writing a full featured model viewer and manipulator for iPhone and iPad. Basically, I just wrote my own file parser that would store the arrays of vertices, then in my render loop I just render the arrays. It's fairly straight forward to do, although binary files read in much faster than .obj files do. This way, you can open any file, not just ones you "process". There are a lot of examples around the internet as well.
Just put your vertices into a close packed array:
vertexX, vertexY, vertexZ, normalX, normalY, normalZ
So that you have a one dimensional array of floats, but is mapped out like above. Once you have a float array, it's simple to render.
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(vertices[0])*6, &vertices[0]);
glNormalPointer(GL_FLOAT, sizeof(vertices[0])*6, &vertices[3]);
glColor4f(R, G, B, 1); //range 0-1
glDrawArrays(GL_TRIANGLES, 0, numVertices); //number of floats in array divided by 6
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
Then just put this in your OpenGL-ES 1.1 render loop. Let me know if this does it for you.
Just clarifying for you, if you open the OBJ file in a text editor, it is laid out like so:
list of vertices
list of texture coordinates
list of normals
list of faces
and the list of faces references the indices in the other three lists in the same order. For example, one line might look like:
f 16/4/1 4/4/4 1/1/1
meaning the first vertex of the face references index 16 of vertices, index 4 of textures, and index 1 of normals. Second index references index 4 of vertices, index 4 of textures, and index 4 of normals, etc. Then you just need to parse the faces and pull the correct values from the different arrays into a single float array containing vertices and normals based on the face indices.
Check the book from the Pangea guys. Link here. I do not remember if he [Brain] shows the code to read Maya or Alias. Anyways, it's a must read.
[edit] he shows how to read maya files in Chapter 13
You can also use unity3d and cocos3d as well
Well, unless someone has a better way, I followed this post: http://heikobehrens.net/2009/08/27/obj2opengl/ . It involves exporting the model as a .obj, then running it through a Perl script to convert it to a .h of C structures.