Custom Avatar Animation Sample

This sample shows how to load and process a custom animation for an avatar by using the XNA Framework Content Pipeline.

Sample Overview

This sample demonstrates how to load a custom animation from an FBX file exported from an avatar rig. A custom content processor is used to extract the animation data from the exported file and save it as a CustomAvatarAnimationData object. The animation data can then be loaded at run-time and played back using the CustomAvatarAnimationPlayer. The CustomAvatarAnimationPlayer exposes a number of properties similar to AvatarAnimation. You can use the CustomAvatarAnimationPlayer.BoneTransforms property to get the current bone transforms to be used with the AvatarRenderer.Draw method.

Animation of the avatar's facial features such as the eyes and mouth is done using texture animations. These texture animations can be driven by an additional data file which is associated with the FBX animation through the content pipeline

Note

When you build this sample, you may see a number of warnings related to the FBX model files, depending on the source of the model, that are expected and can be safely ignored.

When using animations exported from Maya, you will see these warnings during the content build process:

    .
  • Cannot process information from FBX node Controls. The attribute type 13 is invalid. The node and all of its children have been skipped.
  • UV set __DecalColorMap occurs on different layers per mesh. Textures that use this UV set will not be given a TextureCoordinate opaque data property, as they do not map to any single texture coordinate channel.
  • The FBX scene contained multiple bind poses for the following node or nodes […]

When using animations generated from Softimage, you will see this warning during the content build process:

  • There were vertices which did not contain texture coordinates in the following mesh or meshes […]

Sample Controls

This sample uses the following gamepad controls.

Action Gamepad control
Play jump animation A
Play kick animation B
Play punch animation X
Play faint animation Y
Load profile 1 avatar Left bumper
New random avatar Right bumper
Move the avatar Left thumb stick
Rotate the camera Right thumb stick
Zoom in Right trigger
Zoom out Left trigger
Reset the camera Right thumb stick press
Exit the sample BACK

Export Settings

To create a custom animation, you must use an animation rig specific to the avatar system. Avatar animation packs are available for different modeling packages such as Autodesk Maya 2008 and Softimage Mod Tool Pro 7.5. You can find these rigs on the XNA Creators Club site (http://creators.xna.com). After creating the animation, you need to export it to the FBX format and load it using the content processor found in this sample. For instructions on how to export the animations, see the readme for each of the animation rigs.

How the Sample Works

The sample contains four projects:

  • CustomAvatarAnimationPipeline is the Content Pipeline assembly containing the new content processor that converts the avatar animation .fbx file into the CustomAvatarAnimationData type.
  • CustomAvatarAnimationWindows and CustomAvatarAnimationXbox are shared projects that both contain the same files. They contain the classes used to store and play back the custom avatar animation. The Windows version is needed at build time by the CustomAvatarAnimationPipeline project, and the Xbox version is needed at run time to load the custom animation.
  • CustomAvatarAnimationSampleXbox contains the sample's game logic that demonstrates how to load and play the custom animation.

The CustomAvatarAnimationProcessor works similarly to the Skinned Model sample found on the http://creators.xna.com site. It finds the skeleton and animations and converts them into a CustomAvatarAnimationData class. The skeleton contains some extra bones at the end of each part of the hierarchy that the AvatarRenderer doesn't use. The RemoveEndBonesAndFixBoneNames method removes these extra bones and also calls CleanBoneName to remove unneeded text from the bone names that is added as part of the export from the modeling package.

At run time, CustomAvatarAnimationData is loaded using a Content Manager like any other asset. You can then construct a CustomAnimationPlayer from the data to enable playback. You then use this player like an AvatarAnimation  to draw the avatar by using the AvatarRenderer.Draw method.  In addition to CustomAvatarAnimationData, you can load an associated Avatar facial expression.  The Avatar Facial expression is a comma-separated file that specifies facial keyframe data as enumerated values.  Valid expression values are as follows:

Eye

Neutral

0

Sad

1

Angry

2

Confused

3

Laughing

4

Shocked

5

Happy

6

Yawning

7

Sleeping

8

LookUp

9

LookDown

10

LookLeft

11

LookRight

12

Blink

13

Eyebrow

Neutral

0

Sad

1

Angry

2

Confused

3

Raised

4

AvatarMouth

Neutral

0

Sad

1

Angry

2

Confused

3

Laughing

4

Shocked

5

Happy

6

PhoneticO

7

PhoneticAi

8

PhoneticEe

9

PhoneticFv

10

PhoneticW

11

PhoneticL

12

PhoneticDth

13

 

These enumerations correspond to values used by the Maya and Max Avatar animation rigs, so this file could be potentially be generated automatically using a script or plugin.  The file can be manually created as well.

 

The facial expression file has the following format:

TimeInMilliseconds,LeftEye,LeftEyebrow,Mouth,RightEye,RightEyebrow

 

This file is associated with the CustomAvatarAnimationData in the XNA Content Pipeline.  Ensure that the CustomAvatarAnimationProcessor is being used as the Content Processor for the animation.  The facial expression file can then be specified in the properties rollout for the Content Processor.

Extending the Sample

The CustomAvatarAnimationPlayer class only supports playback of a single animation. One way to extend the sample would be to add support for multiple animations and blending between them. You could also add support for playback of multiple animations for different parts of the avatar. This would allow for playback of the walk animation at the same time the upper body of the avatar plays another animation, such as clapping.