Character Animation Basics |
DigitalRune Animation provides comprehensive support for 3D character animation: Skeletal animation, inverse kinematics, ragdoll physics, and more.
This topic contains the following sections:
Skeletal animation is the prevalent technique for 3D character animation. The mesh of a character model is deformed based on an underlying skeleton. The technique is known under a variety of names: mesh skinning, enveloping, matrix deformation, linear blend skinning, smooth skinning or skeleton-subspace deformation.
A Skeleton defines the structure of a skeleton. It defines the hierarchy of bones and their position and orientation in bind pose (also called rest pose). The bind pose is usually the pose in which the character mesh is modeled. The Skeleton is immutable, that means once a skeleton is created it cannot be modified. Multiple characters can share the same instance of the Skeleton class.
A SkeletonPose defines a new pose for an existing skeleton. A new skeleton pose is defined by a set of bone transforms. A bone transform defines the transformation of a bone relative to its bind pose. Bone transforms can be set manually at runtime or, for example, by using a SkeletonKeyFrameAnimation. The SkeletonPose returns the matrices required for mesh skinning: See properties SkinningMatrices and SkinningMatricesXna.
DigitalRune Animation uses the value type SrtTransform to represent bone transforms. An SRT transform describes a scale transformation, followed by a rotation, followed by a translation. (SRT transforms are particularly well suited for character animation.) See the SrtTransform for more information.
Note |
---|
DigitalRune Animation and the SrtTransform type uses LERP (linear interpolation) operations instead of a SLERP (spherical linear interpolation) operation to interpolate quaternions. Using LERP is faster, and the difference to SLERP is negligible in most cases. |
DigitalRune Animations uses following terms to refer to different coordinate spaces and bone transformations:
Bind Pose Space: The bind pose is the pose in which the character mesh is modeled (usually a T pose). The Skeleton class manages the bind pose transformations of all bones.
Bind Pose Transformation: A bind pose transformation defines the position, orientation and scale of a bone relative to its parent bone or relative to model space. The Skeleton class manages the bind pose transformations of all bones.
Bone Space: The bone space is the local coordinate space that is fixed on a bone. The origin of this space is the origin of the bone. Sometimes, one coordinate axis points into the direction of the bone. Bone Transforms are always relative to bone space.
Parent Bone Space: Each bone except the root bone of the model has a unique parent bone. The parent bone space is the bone space of the parent bone. The parent bone space of the root bone is the model space. Transformations that are relative to the parent bone space have the term Relative in their name, for example: GetBonePoseRelative
Model Space: The model space is the local coordinate space of the whole model. The origin of this space is usually at the feet of the character. Transformations that are relative to the model space have the term Absolute in their name, for example: GetBonePoseAbsolute
World Space: The world space is the coordinate space that contains all game objects. The origin of this space is usually the center of a game level.
Bone Transform: A bone transform is a local transformation in bone space that is applied to a bone. Bones are animated by changing the bone transforms of a skeleton pose. If a bone transform is the identity transformation (scale is 1, no rotation, no translation), then the bone is not animated. If all bone transforms of a skeleton pose are identity transformations, then the character is displayed in its bind pose.
Bone Pose: A bone pose transformation matrix (or short: bone pose) defines the resulting pose of bone after the bone transforms are applied. A bone pose describes the bone's position, orientation and scale relative to another coordinate space. A relative bone pose describes the pose of a bone relative to the parent bone. An absolute bone pose describes the pose of a bone relative to model space. Bone poses are computed automatically (when needed) from the current bone transforms by the SkeletonPose class.
Skinning Matrix: Skinning matrices are used to transform the vertices of the character mesh. A skinning matrix transform a vertex position (in model space) of the bind pose mesh to a vertex position (in model space) of the deformed mesh.
Understanding how all matrices and coordinate spaces fit together is far from trivial. Here is some code that explains how the bone poses and skinning matrices are computed by the SkeletonPose. (Please note: This is pseudo-code. And don't forget: The multiplication order of the transformations is from right to left.)
// Apply current animation (bone transform) to the rest pose (= bind pose) to get the final bone pose. for (int i = 0; i < numberOfBones; i++) bonePoseRelative[i] = bindPosesRelative[i] * boneTransforms[i]; // bonePoseRelative is the bonePose relative to the parent bone. // Compute bonePoseAbsolute, which is the bonePose relative to the model space. bonePoseAbsolute[0] = bonePoseRelative[0]; for (int i = 1; i < numberOfBones; i++) { int parentIndex = skeleton.GetParent(i); bonePoseAbsolute[i] = bonePoseAbsolute[parentIndex] * bonePoseRelative[i]; } // Compute the skinning matrices needed in a skinning shader. for (int i = 0; i < numberOfBones; i++) skinningMatrices[i] = bonePoseAbsolute[i] * bindPosesAbsoluteInverse[i];
The type SkeletonPose can be animated. It implements the interface IAnimatableProperty of type SkeletonPose, as well as the interface IAnimatableObject. That means the whole skeleton pose can be animated using a SkeletonKeyFrameAnimation. The SkeletonKeyFrameAnimation controls all bones of the skeleton (but it supports per-bone weights). But it is also possible to animate only individual bones using SrtKeyFrameAnimation animations. See SkeletonPose for more information.
The CharacterAnimationSample (see Samples) shows how to animate 3D characters.
Besides skeletal animation, morphing is another important technique used for 3D character animation: A mesh of a character model is changed by blending between various morph targets (blend shapes). The technique is hence also known as morph target animation or blend shape interpolation.
Morph target animation is typically used for facial animation where different facial poses are modeled and stored as morph targets. Weights (usually floating-point values) are assigned to each morph target. The weights are animated at runtime and the morph targets are blended together based on their weights.
Morph target weights can be animated using the basic animation types. Hence, DigitalRune Animation does not provide special support for morph target animation.