When you need to animate a character (running, jumping, falling, and so on), the animation process becomes more complex. This is because you’ll need to modify the character’s mesh, called skinning. This chapter focuses on techniques for animating characters. Let’s begin by looking at the two main types of animation.
There are two main types of animation: keyframed animation and skeletal animation. Each type of animation is used in different situations and has its advantages and disadvantages.
Keyframed Animation
In the animation shown in Figure 12-1, you will need to add tweening between the first and second animation frames, to make the animation appear smooth. (Tweening refers to generating the intermediate frames between keyframes.) However, you don’t necessarily need to create all of the frames beforehand, because you can obtain them by interpolating between the first and second frames.
One of the advantages of keyframed animation is that it’s fast, because all interpolation calculations have been done at startup. All the animation frames are stored in memory, and during the animation, you only need to change to the next mesh in the animation each frame. However, a disadvantage of this method is that it’s necessary to store all the model meshes in memory. If a model needs 100 animation frames, it’s necessary to store its mesh 100 times.
The use of keyframed animated models with XNA is simple, because XNA already has the classes needed to handle static models. Therefore, you can treat a keyframed animation model in XNA as an array of static models using the Model class, where you store one Model object for each frame of the animation.
Skeletal Animation
In this process, the entire model is structured on a skeleton, which is a combination of bones. The skeleton has one bone for each movable part of the model: one bone for a shoulder, one for an upper arm, one for a forearm, one for the hand plate, and then some more for the fingers.
Each bone needs to know to which parent bone it connects and how it is connected there, which is defined by the rotation about the connection point.
To build the model’s mesh, skeleton, and animations, you can use different modeling tools that support skeletal (or bone) animation, such as 3ds Max, Maya, Blender, and others. After you create the model, you also need to export it to a format that supports skeletal animation. Among the model formats that XNA supports natively, the X (DirectX) and FBX (Autodesk) formats support skeletal animation.