Animation sample from Microsoft released!

Topics: Developer Forum, Project Management Forum, User Forum
Mar 5, 2007 at 5:33 PM
Microsoft released a skinned animation sample.

Mar 7, 2007 at 3:57 AM
Edited Mar 7, 2007 at 4:02 AM
Yup, it's a nice sample because it shows the basics behind running skinned animation in XNA. It only covers the very basics, however, since Microsoft wants to keep its samples short, readable, and informative.

Basically, it works exactly the same as the library (but without all the extra features such as blending, interpolation, specifying which animations run on which bones, and a full blown matrix palette effect), and I hope that it will allow new people to contribute to this library since more people will now (hopefully) understand how to do skinning in XNA.

It is well commented and informative, so I give props to MS.
Mar 17, 2007 at 8:02 AM
I'm trying to use the microsoft animation fbx sample model and load with the Xclna animation library code. I was able to process it and load it in the game properly. When the game tries to render the model I get "Specified cast is not valid." exception. The exception was throw in ModelAnimator.cs line 240. I'm not sure exactly what's going on because there doesn't seem to be a cast on that line.
Mar 17, 2007 at 9:47 AM
I found out what it was. There is a 56 bone limit that I didn't know about.
The test model in the xna example has 58 bones.

How strict is this limit? Is the 56 for pc and 40 for xbox a hard limit?
Mar 18, 2007 at 11:19 PM
Edited Mar 18, 2007 at 11:20 PM
The limit of bones is dependent on the shader. I ran out of registers for BasicPaletteEffect, which uses a lot of registers for lighting, so I had to make the cap around 56 (although 58 could work, I didn't find the absolute max cap).

For custom shaders, the limit is the size of the palette.

You can try to squeeze out a couple of more bones for the cap of BasicPaletteEffect by editing the source in the ReplaceBasicEffects method of AnimatedModelProcessor, or by creating a new processor that subclasses AnimatedModelProcessor and overriding the ReplaceBasicEffects method. Here is the code snippet that decides the palette size:

// Create a new PaletteSourceCode object and set its palette size
// based on the platform since xbox has fewer registers.
PaletteSourceCode source;
if (context.TargetPlatform != TargetPlatform.Xbox360)
source = new PaletteSourceCode(56);
source = new PaletteSourceCode(40);
Mar 18, 2007 at 11:22 PM
Edited Mar 18, 2007 at 11:22 PM
Thanks for pointing this out. I should re-add the code that informs users when they use too many bones. I had this in a previous version, and don't know how it got deleted.
Mar 29, 2007 at 3:04 PM
So is there a limit for the number of bones?

I have 67 bones in a homemade mesh ( I use the skinning example form Microsoft) and I get an "Specified cast is not valid." error. Anybody know anything about that?
Mar 29, 2007 at 10:16 PM
Edited Mar 29, 2007 at 10:17 PM
Yes, there is a limit. It is possible to increase the number of bones, but it is not supported by the library and is a pain in the ass to code because it requires splitting up each mesh into multiple meshes based on their bone count and introduces all sorts of code maintenance problems.

The current limit is 56 for windows and 40 for xbox. I'll probably be pushing the xbox limit up a bit but for BasicPaletteEffect, the 56 is pretty much set in stone.
Apr 2, 2007 at 10:12 AM
I posted a file in the releases section that splits the mesh up. It won't be integrated until the next release though.
Apr 2, 2007 at 10:31 AM
Changed my mind and incorporated it into the release.