开发者

Getting a Maya Model into the iPhone

开发者 https://www.devze.com 2023-02-03 18:44 出处:网络
What i开发者_C百科s 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 rendered on the iPho

What i开发者_C百科s 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 rendered on the iPhone screen, but I'd be stoked if there was a way to render it, then support pinch to zoom, etc.

Thanks a lot, just finished my first 3D modeling class today and I'm stoked!


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.

EDIT:

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.

EDIT2:

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


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.


You can also use unity3d and cocos3d as well

0

精彩评论

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