Jump to content
  • Advertisement
Sign in to follow this  

So confused on animating bones basics

This topic is 2855 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I read through several tutorials about animating DirectX meshes with bone structures. They're all so confusing that I still am at loss as to where to begin. Currently I'm an expert C++ programmer and additionally specialize in C++ so the language isn't the problem.

All the tutorials have made animation seem like a daunting task even a simple demo ended up being like 20-30 something pages long.

Can anyone help me out in some way. I want to design video games and become fluent in all aspects of DirectX like I am C++ but not being able to provide bone animations provides for a pretty sorry video game or other 3D program.

Share this post

Link to post
Share on other sites
Are you familiar with the concept of a spatial scene graph? If so, then you already understand 90% of doing bone based animation. If not, then check out the wild magic engine for some extensive lessons on how they work.

The basic idea is that each bone represents one node within a spatial hierarchy, and it just defines its orientation and position relative to its parent. All of the animation data just tells it how much rotation and translation to apply to itself, and it is normally keyframed or procedurally calculated.

Each vertex in the model is given a bone index that links it to one of these nodes (its common to blend between several bones, but that is just interpolation between two or more of the basic calculations, and isn't necessary for the first steps). When the model is created, it is stored in a 'bind pose' and all changes to bone position will be relative to their state in the bind pose.

All of the matrices that get calculated for rendering the model basically follow two steps for each bone:

1. Calculate the inverse matrix that will transform a particular bone to the origin. This moves the vertices associated with that bone into a space referencing the origin.

2. Apply a matrix transformation that takes the vertices from this neutral space out to whatever orientation is dictated by the calculated animation data (as mentioned above).

The inverse matrix from step 1 is more or less just the inverse of the bind pose for each bone - you just calculate it once and then reuse it forever. The transformations for step 2 are just calculated like a normal spatial scene graph node transform, which is fairly simple to get working.

I hope this helps clarify things a bit. One piece of advice - don't get discouraged if you have trouble loading these types of models and their animation data from files. This is an evil practice that is guaranteed to suck and take more time than it is supposed to... it took me almost a month to load and use MS3D files properly!

Share this post

Link to post
Share on other sites
Actually, understanding model animation (in DirectX or other API) is, in fact, a pretty convoluted subject. If you want to get into 3D animation in DirectX, I suggest you start by buying Frank Luna's book, Introduction to 3D Game Programming With DirectX 9.0c, A Shader Approach. Get the latest revision.

All the source code, including a very nice vertex shader for animating x-file models, is available online.

A quick overview of the subject:

A model is a mesh, an array of vertices forming triangles. To animate the mesh, it is skinned to a "bone structure." A bone structure, sometimes called a frame structure, is nothing more than a hierarchal array of matrices or reference frame. There is usually a root bone, the parent of all the other bones in the structure. That is, is the root bone (matrix) is rotated or translated, the entire mesh is rotated or translated.

The root bone has "child" bones (such as "Hip" or "Pelvis"). Those child bones have child bones (BackBone, Neck, UpperArm, etc.) which form that hierarchal set of matrices. "Hierarchal" in this sense means: if the upper arm is moved, all of its children are moved (lower arm, hand, fingers, etc.) For discussion purposes, call this hierarchy the "base" matrices for the bones.

In addition to the model and the bone structure, there are one or more sets of "animations." Animations are time-based sets of matrices or quaternions which determine how each bone moves in relationship to its parent bone over increments of time.

The principle for animation is that each vertex in the mesh is influenced by one or more bones. That is, each rendered frame, each vertex is multiplied by several matrices which determine a new position in world space for the vertex. E.g., during an animation sequence, as the upper arm is rotated (the "upper arm" matrix is modified), the vertices which it influences will be rotated in space with respect to the position of the upper arm. All the mesh vertex movements (legs, arms, head, etc.) appear as the animated model.

Putting it altogether, each rendered frame, the base matrix for each bone is multiplied by an animation matrix. That matrix is then combined with (multiplied by) its parent's matrix (which has been multiplied by it's parent's matrix..). Those combined matrices are then used to multiply the mesh vertices to position the model to be rendered.

I've left out a lot of details, so it's not surprising that you're finding 20 to 30 page explanations of the process.

Good luck!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!