Graphics Reference
In-Depth Information
How it works…
As you can see, all the hard work has already been completed in the two previous recipes.
Along with the bones, the CMO file includes a list of animations for manipulating these bones.
Each animation consists of a start and end time, and a list of key-frames. These are loaded
into the Common.Mesh.Animations property. The structure of these objects within the CMO
file and how they are represented in the Common.Mesh class is shown in the following code
extracted from Common\Mesh.cs .
public class Mesh {
...
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct Keyframe
{
public uint BoneIndex;
public float Time;
public Matrix Transform;
};
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct Animation
{
public float StartTime;
public float EndTime;
public List<Keyframe> Keyframes;
};
...
// Named list of bone animations
public Dictionary<string, Animation> Animations { get; }
}
What we're doing in this recipe is retrieving the key-frames of an animation that was created
within the original scene by using Blender. When exporting the scene to Autodesk FBX from
Blender, the option to include animations was selected. The Visual Studio graphics content
pipeline has then preserved these animations when creating the compiled mesh.
Our mesh class loads the animation key-frames (which are basically a set of frame times),
bone transforms (or animation transforms), and bone indices. We iterate these frames up
to the current frame time and replace the existing bone's local transform with that of the
key-frame. We then interpolate each bone's current key-frame with its next future key-frame
based on the amount of time that has lapsed between the two frames.
 
Search WWH ::




Custom Search