Skinned Model Sample
This sample shows how to process and render a skinned character model using the XNA Framework Content Pipeline.Sample Overview
Out of the box, the XNA Framework provides only partial support for animation. It defines an intermediate object model for storing animation data inside the Content Pipeline, and can import data into this object model from FBX and X formats. The built-in ModelProcessor also converts vertex channels of BoneWeightCollection data into pairs of channels with VertexElementUsage BlendIndices and BlendWeight, suitable for skinned rendering on the GPU. The framework, however, does not include any run-time animation classes. That functionality is implemented by this sample.
Sample Controls
This sample uses the following keyboard and gamepad controls.
Action | Keyboard control | Gamepad control |
---|---|---|
Rotate the model |
UP ARROW, DOWN ARROW, LEFT ARROW, and RIGHT ARROW or W, S, A, and D |
Right thumb stick |
Zoom. | Z and X | Triggers |
Reset | R | Right thumb stick |
Exit | ESC or ALT+F4 | BACK |
How the Sample Works
There are three projects in the sample.
- SkinnedModel contains the classes used to store and play back animation data. These types are used both during the Content Pipeline build process and at run time by the game.
- SkinnedModelPipeline is a Content Pipeline assembly. It implements a new content processor for building skinned models.
- SkinningSample is a sample game showing how to animate and render a skinned model.
The sample contains separate projects for SkinnedModel and SkinningSample, used when developing for Windows, Xbox 360, or Windows Phone. Only a single project is required for SkinnedModelPipeline, as this runs only on Windows as part of the Content Pipeline build process.
The Xbox 360 and Windows Phone solution files include both Xbox 360 / Windows Phone and Windows versions of the SkinnedModel project. This assembly is used both during the content build process (on Windows) and at run time (on Xbox 360 or Windows Phone), so it must be built for both platforms.
To render a skinned model, we need two things:
- An effect that will implement the mesh deformation.
- Some animation data describing how the mesh should be deformed.
The SkinnedModelProcessor attaches all this information to the existing Model type provided by the XNA Framework.
The SkinnedModelProcessor.DefaultEffect property overload specifies that the built model should always use SkinnedEffect rather than the default BasicEffect shader.
Animation data is converted into a suitable run-time format by the SkinnedModelProcessor.ProcessAnimations method, which stores a custom SkinningData object in the Tag property of the framework Model instance.
Extending the Sample
The AnimationPlayer class that the sample implements can play back only a single animation at a time. You could implement blending between multiple animations, or play back different animations on different parts of the character, by calling UpdateBoneTransforms on several AnimationPlayer instances. You would then blend the resulting matrices into the BoneTransforms array of a single output player before calling UpdateWorldTransforms and UpdateSkinTransforms.