The first thing that I researched was the .X file. This is the
format that is used by DirectX in order to use meshes in the scene and stores
all kind of information about it, like the specifications of the material and
the textures used and the animation information.
While doing some research online, I found Keith Ditchburn's
website (Toymaker.info). Here I found an example of the source code needed in
order to implement an animated .X file and also a library that could be added
to the project in order to use that functionality. Since I wanted to learn
how the process is actually done, I downloaded the source
code and started looking into it and doing modifications, in order to use it
with my DirectX code from previous projects. Here are some important notes
on how the process works:
Everything in the .X file is stored in hierarchical method. This
hierarchy consists of frames containing matrix and mesh data for different
parts of the model. For example: If we have a model, the body will be the
top frame and each one of the parts of the body below it; each one with its own
matrix and mesh data.
In order to preserve this hierarchy when loading the mesh, the D3DXLoadMeshHierarchyFromX function has to be used. Before it is called,
we have to create functions that would allow us to create/destroy frames and
mesh containers. We do this in a separate class, which will be in charge
on handling the memory allocations for these elements.
When we render the hierarchy, we start by the top frame using
the created DrawFrame function
that would be recursively called for each one of the sibling and child frames.
The animations can be created by altering the matrices of the
frames, which will alter the other ones in the hierarchy. The animation
controller determines the position for each one the the frame matrices
according to provided time. The frame controller will alter the frame matrices
and then the hierarchy of the frame is updated, using these
new matrices to create the new combined frame matrix. Since switching from
one animation to the other one abruptly can look bad, we use tracks in order to
make it look like a normal transition. These tracks will fade out the playing
animation and fade in the new one.
When Skinning (for which each one of the matrices associated to the frames are called bones) geometry bending is used between the mesh and skeleton hierarchy in order to transform the mesh vertices. Every time a bone is altered, it will modify the vertices from the mesh dependent on it. Each one of this bones has a matrix that rotates or translates it according to the father (this is known as "bone space"). In order to transform this matrix to "character space" we use the combined matrix of the parent. Finally, in order to connect the bones to the mesh we use the bone offset matrix.
When Skinning (for which each one of the matrices associated to the frames are called bones) geometry bending is used between the mesh and skeleton hierarchy in order to transform the mesh vertices. Every time a bone is altered, it will modify the vertices from the mesh dependent on it. Each one of this bones has a matrix that rotates or translates it according to the father (this is known as "bone space"). In order to transform this matrix to "character space" we use the combined matrix of the parent. Finally, in order to connect the bones to the mesh we use the bone offset matrix.
Final Bone Matrix = Bone
Offset Matrix * Bone Combined Matrix
The DirectX function UpdateSkinnedMesh will update the mesh
according to this matrix and the provided set of weights for the bones (which
define the vertices affected by the bones).
At the moment I am running test with this concepts and
transforming this source code in order to merge it with my previous projects. I
will post updates for these tests and modifications.
References:
Ditchburn, Keith (2004 - 2010), "X File Hierarchy Loading", Toymaker.info
[Accessed August - September 2011]
Ditchburn, Keith (2004 - 2010), "XAnimator - X File
Animation Loader - Player", Toymaker.info
[Accessed August - September 2011]