Nerd Herder

Dean Johnson blogs about life on the XNA platform and tools team

Avatar API preview for XNA Game Studio 3.1

Avatar API preview for XNA Game Studio 3.1

Rate This
  • Comments 13

Since the announcement of the 3.1 features a number of people have had questions about the new Avatar API’s. I wanted to take a few minutes to preview some of Avatar API’s to help developers better understand what to expect in the 3.1 release.

There are three main classes that are used to render and animate an avatar.

AvatarDescription
Each avatar has a description that describes how the avatar looks and what clothing the avatar has on. This description tells the system what models, textures, colors, and scales to use when rendering an avatar. This description is mostly opaque to the developer but does allow for the developer to get the height and body type of the avatar. The height is in meters and the body type allows the developer to know if the avatar is female or male. The AvatarDescription object can be created in three ways. The first way is to read the Avatar property on any of the SingedInGamers. The second is to use the static methods on AvatarDescription to create random descriptions. The third is to send an AvatarDescription over the network or save it to a file by looking up a byte array from the AvatarDescription, transferring those bytes, and then creating a new AvatarDescription from the byte array. I will create a future post to talk more about the third method.

AvatarRenderer
The AvatarRenderer is used to draw an avatar to the screen. You create a new AvatarRenderer by passing in an AvatarDescription object. To draw the avatar to the screen you set the World, View, and Projection matrix properties on the AvatarRenderer object and then call the Draw method. The draw method takes two parameters. The first is an IList<Matrix> called bones. This is a list of the bone transforms to use when rendering the avatar. The transforms are in local bone space relative to their parent. The avatar has a total of 71 bones. The second parameter is an AvatarExpression. Avatars use textures for the mouth, eyes, and eyebrows. The AvatarExpression is a structure that holds enum values that specify the current state of the eyes, eyebrows, and mouth. Now you may be asking where you get the list of bone matrices and the avatar expression. The easiest way is to use the AvatarAnimaion class.

AvatarAnimation
There are 31 built in animations that developers can use in their games. Most of these animations are used in the dash. An AvatarAnimation object is created by passing an enum value from AvatarAnimationPreset. Once created the developer updates the animations current time. After setting the current time in the animation the developer can access the bones and expression needed by the AvatarRednerer.Draw call by using the BoneTransforms and Expression properties.

Now let’s check out how to code this up.

In the games initialize method load the description, renderer, and animation.

AvatarDescription avatarDescription = AvatarDescription.CreateRandom();
AvatarRenderer avatarRenderer = new AvatarRenderer(avatarDescription);
AvatarAnimation avatarAnimation = new AvatarAnimation(AvatarAnimationPreset.Clap);

Now in the games update method update the animation.

avatarAnimation.Update(gameTime.ElapsedGameTime, true);

Finally in the draw method set the world, view, and projection matrix and call the draw method.

avatarRenderer.World = Matrix.CreateRotationY(MathHelper.ToRadians(180.0f));
avatarRenderer.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f),
GraphicsDevice.Viewport.AspectRatio,
.01f, 200.0f); avatarRenderer.View = Matrix.CreateLookAt(new Vector3(0, 1, 3),
new Vector3(0, 1, 0),
Vector3.Up); avatarRenderer.Draw(avatarAnimation.BoneTransforms, avatarAnimation.Expression);

All this talk about how to render an avatar without a picture would be wrong. So below is one of the first screen shots taken while working on this feature.

clip_image001

  • PingBack from http://microsoft-sharepoint.simplynetdev.com/avatar-api-preview-for-xna-game-studio-31/

  • Good stuff.  I am really excited about the avatars in community games.

  • My colleague Dean Johnson has posted a couple of items on his blog that I wanted to link to here to help

  • Playback of one of the 31 built in animations is simple with the AvatarAnimation class. As I discussed

  • Will we be able to define our own AvatarAnimations?

  • We plan to release a sample to show users how to load custom animations.

  • In a couple of previous posts here and here I talked about the AvatarDescription.Description property

  • For information about the 3.1 to XNA Game Studio thanks

  • Introducing such a topic you'd like to congratulate you've let us know. Have good work

  • This is very good news was well informed that the followers of the issue I am. Thank you

  • Hi,

    I'm loving the potential of the Avatars! The information available is still just a bit limited. In the game I am working on I am placing the Avatar on skis, but when the Avatar is wearing boots they stick out of the ski models. Is there a way to turn off the shoes in the description?

    As far as I can tell from searching the net the last 19 numbers of the description is a checksum, so I'm guessing I won't just be able to manually change the values, otherwise I could just save an Avatar with and without shoes and then just check which value differs. I'm guessing. Some guidance would really be appreciated!

  • Excellent post, thank you very much for taking the time to share with those who are starting on the subject

  • thanks for the simple description, just a shame that avatars aren't for pc use as well

Page 1 of 1 (13 items)
Leave a Comment
  • Please add 7 and 2 and type the answer here:
  • Post
Translate This Page
Search
Archive