A Simple md5mesh/md5anim Animation Demo
Download
About
This is a very simple GLUT program which shows how to load md5mesh and md5anim files and animate them.
The core loading code is in md5parser.h, md5mesh.cpp/h, and md5anim.cpp/h. The core transformtation code is in md5instance.cpp/h, which uses the core loading code. The other files (md5geomsimple.cpp/h, main.cpp) use the core loading and transformation code to produce a small demo application.
This archive also includes the data for a zombie and the space marine, so right out of the box (by typing ``make run'' on OS X) it should produce output that looks like the following image.
Some history
These are resources for loading md5mesh and md5anim files that I tossed together for students taking a graphics class I TAed in Spring 2006. This code was intended to be somewhat incomplete so students could figure out some details on animation themeselves, and I finally got around to fleshing out this reasonably well structured and commented demo about a year later.
There were some bugs in the initial implementation which some students found for me.
A Blurb on md5 formats
A md5mesh file contains a bunch of rigged (controlled through a bunch of rigid joints) geometry.
A md5anim file contains a bunch of key frames for those joints.
In order to draw the triangles that you'll find in a md5mesh, you'll first need to calculate the vertex positions for those triangles.
Those vertex positions are given in terms of transformed joint orientation, so the first thing you'll need to do is calculate transformed joint orientations.
The md5mesh starter code
A md5mesh consists of
- joints A joint specifies a coordinate system (or equivalently, 4x4 matrix) in space with respect to which vertices' positions can be specified.
-
meshes
A mesh consists of
- vertices A vertex consists of a texture coordinate and a set of weights (specified by an initial index and the number of weights). Adding up the weighted position of the weights will get you this vertex's position. Note that the sum of the weight fraction of all each vertex's weights should be one.
- triangles Triangles specify three indices into the vertex array. It should be noted that these are in clockwise order, unlike OBJ files (and most other files)
- weights A weight specifies a weight fraction, a joint, and a position in that joint's coordinate system. The transformed position of a weight can be calculated as the joint's transformation matrix times the position.
The md5anim starter code
A md5anim consists of a bunch of frames, each of which specify each joint's orientation with respect to its parent's orientation.
Some notes
- The vertices for triangles in md5mesh files are specified in clockwise order instead of counter-clockwise (which is what OpenGL expects and what OBJ files do)
- These meshes are strange sizes and orientations (they aren't about one unit in size with the Y axis pointing up). The file main.cpp gives a sample transformation that can be used to draw them.
If you have questions, feel free to ask!