
Load and draw an animated model (.md2)
Posted Monday, 16 August, 2010 - 23:13 by chandragon inHello,
I would like to render an animated 3d model that would be stored in a file.
I know two ways of doing it: with bones and with frames.
I would like to be able to render a lot of times the animated model (but not at the same frame) and I don't need a very accurate render so I think the best thing is to use frames.
To make the animated model I use Blender with bones and then I would like to export the frames of the animation to a file.
I searched the right file format and I think MD2 could do, then I searched a way of loading a MD2 file and I found this topic where TheKrokodil posted a MD2 loader:
http://www.opentk.com/node/450
The problem I encounter is that each triangle not only contains vertex indices but also texcoord indices.
I also looked at the .obj file format, and I saw that each face could even have normal indices.
But the only ways I know of rendering 3D models are those explained here:
http://www.opentk.com/doc/chapter/2/opengl/geometry/drawing
And as far as I know, we can use GL.DrawElements to precise the vertex indices, but there is no way method that uses texcoord indices, or even normal indices.
So once I have loaded my model from a md2 or obj file, how do I render it (except using immediate mode) ?
And if we can do it with vertex arrays and VBO, what would be the faster ? (knowing that the vertex positions would always change).
Thank you


Comments
Re: Load and draw an animated model (.md2)
Hello,
I would like to render an animated 3d model that would be stored in a file.
I know two ways of doing it: with bones and with frames.
I would like to be able to render a lot of times the animated model (but not at the same frame) and I don't need a very accurate render so I think the best thing is to use frames.
To make the animated model I use Blender with bones and then I would like to export the frames of the animation to a file.
I searched the right file format and I think MD2 could do, then I searched a way of loading a MD2 file and I found this topic where TheKrokodil posted a MD2 loader:
http://www.opentk.com/node/450
The problem I encounter is that each triangle not only contains vertex indices but also texcoord indices.
I also looked at the .obj file format, and I saw that each face could even have normal indices.
But the only ways I know of rendering 3D models are those explained here:
http://www.opentk.com/doc/chapter/2/opengl/geometry/drawing
And as far as I know, we can use GL.DrawElements to precise the vertex indices, but there is no way method that uses texcoord indices, or even normal indices.
OpenGL only accepts one set of indexes. This index is used to reference the vertex data, normals, tex coordinates and any other vertex attributes. So this means that your tex coordinates and normal array have to be in the same order as your vertex arrays. The Obj format and most other have separate indexs for the normals etc. You'll have to reorganize your arrays so that they all match. Create new arrays for each of the different vertex attributes (these should all be the same size) and then use the indexes to populate them.
So once I have loaded my model from a md2 or obj file, how do I render it (except using immediate mode) ?
And if we can do it with vertex arrays and VBO, what would be the faster ? (knowing that the vertex positions would always change).
Thank you
Don't use immediate mode, vbos and vaos will be a lot faster.
Re: Load and draw an animated model (.md2)
Okay, but what if one vertex is used with different texcoords/normals, I have to create a new vertex at the same position ?
Thanks
Re: Load and draw an animated model (.md2)
Yes.
Re: Load and draw an animated model (.md2)
Okay, Thank you !
And what is the best to use to render animations, Vertex arrays or VBO ?
Re: Load and draw an animated model (.md2)
I would start with Vertex Arrays... a VAO is just an addition to that that stores the enabled arrays so that it can be rendered in a single call...
If you plan to interpolate between frames in the MD2, I would put the TexCoords in one Array and the Positions & Normals in another since the Position and Normals will need to be updated every render.
Below is prototype code as an example.
Re: Load and draw an animated model (.md2)
Allright !
Thanks a lot !