Req. Animation Component

Topics: User Forum
Jan 5, 2007 at 4:47 AM

I saw the X file for e.g.

Animation {
{ armL }
AnimationKey {
....<some key numbers>

now the question is if i want to move armL how do I go about it.

Jan 7, 2007 at 6:19 AM
Can you please elaborate on that?
Jan 8, 2007 at 4:27 AM
sorry if i was not clear...

I was going through bear.x file, when i came across..

Animation {
{ Head } //other examples armL, armR, legL, legR
AnimationKey {

so what i assume is these (head, armL, armR etc.) are small-small keys, and when all of these adds up we see a bear animating. right!

now let us say I want, only armL should animate and rest of them should be static.

then how do we go about it!!

may be my question is wrong!!
I am sorry for that as I am new to animation stuff! :)
Jan 9, 2007 at 5:45 AM
AnimationSet actually represents an animation, and Animation represents the movement of one bone in the animation.

So, to make a new animation with just armL moving, you would add

AnimationSet MyArmAnimation

To the end of the file
Jan 23, 2007 at 6:01 PM
I'm trying this in my project and the model doesn't show up at all at runtime:

AnimationSet {
Animation {
{ Head }
AnimationKey {

AnimationSet MyAnim {
Animation {
{ Head }
AnimationKey {

Am I doing something wrong?

Jan 23, 2007 at 6:05 PM
...By the way, this is with the bear_walking.x file that came with the sample project, using this code to call it:

Model model;
// TODO: Load any ResourceManagementMode.Automatic content
model = content.Load<Model>("bear_walking");
//Animation.ModelViewer viewer = new ModelViewer(this, model);
AnimationController controller = new AnimationController(this, model, "MyAnim");

No errors, just doesn't show up at debug.
Jan 23, 2007 at 6:34 PM
You need to set the world/view/projection if you use AnimationController. ModelViewer is basically for convenience so people can make sure that there model is loading and animating properly. It also provides a sort of example of how to use the component to make a camera/moving model.
Jan 24, 2007 at 12:14 AM
Back with more noob questions...

I tried applying the projection etc. code from the "Help" section code that comes with the XNA package, I'm getting an error on debug but that's beside the point.

What's the best way to apply projection etc.? Thanks again!
Jan 24, 2007 at 1:07 AM
Matrix.CreatePerspectiveFOV can be used for the projection, and Matrix.CreateLookAt can be used for view.
Jan 24, 2007 at 2:00 PM
Ok - I'm trying to use this code:


foreach (ModelMesh mesh in myModel.Meshes)
//This is where the mesh orientation is set, as well as our camera and projection
foreach (BasicPaletteEffect effect in mesh.Effects)
effect.World = transformsmesh.ParentBone.Index * Matrix.CreateRotationY(modelRotation)
* Matrix.CreateTranslation(modelPosition);
effect.View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f),
aspectRatio, 1.0f, 10000.0f);
//Draw the mesh, will use the effects set above.


And for some reason the model isn't showing up! Doesn't seem to make sense as it loads the same as in the demo. I am using AnimationController in the Update func, does that make a difference. Grrrrrr.
Jan 25, 2007 at 11:55 PM
The animation controller takes care of the World matrix in effects, and uses it to run the animation. If you want to set the world matrix of the animated model, use the Controller.World property.

However, this shouldn't cause the model to not display. The only thing I can thing of is that your camera is too far or too close to the model. I will try running your code using the bear model sometime soon.

The ModelViewer class, as I explained before, only uses the Controller.World and View/Projection matrices of the effect to display the animated model and let the user move it/rotate it. The code isn't currently commented (sorry, the code is changing too often for full documentation right now), but you can try looking at it.
Jan 26, 2007 at 1:29 PM
Thanks for the help, I tried looking at the code but couldn't seem to get any of that code to work for me. I'd really appreciate it if you could look into it for me. Hopefully once this is cleared up I can get off your guys backs and get to work :).
Jan 26, 2007 at 6:00 PM
I'm having a similar problem... or maybe its my lack of understanding how to implement the view/projection settings.

dastle, you mentioned that Animation Controller takes care of the world matrix effects... and that we can use the "" to set the world property. So how do we set the "view", "eyeposition", and "projection" settings?

When I look at the source code, it appears "world" is being set for all of the values during the draw(). Shouldn't we have a "animationcontroller.view, ani...llerr.eyeposition, ani..ller.projection" to set the model in the world? (Of course I only understand a fraction of what most of your code does >_< )

I bring this up, because when I look at the viewmodel code, "view, eyeposition, and projection" are all being set...

Jan 26, 2007 at 6:37 PM
... nevermind, I just figured it out...
After studing your code a bit more, I basically needed to write a few lines of code to initialize effects.

Jan 27, 2007 at 10:21 PM
Check out the walking bear example I posted today, which shows you how to use AnimationController to make a bear walk around.
Feb 1, 2007 at 11:12 PM
Edited Feb 2, 2007 at 2:33 AM
Thanks so much for the help. I walking example works great. I now see the projection code!
Feb 2, 2007 at 2:34 AM
Edited Feb 2, 2007 at 2:37 AM
Oh great, here goes again lol:

When I try to sub a simple animated .x model in for bear_walking.x I get an:

Unable to cast object of type 'Microsoft.Xna.Framework.Graphics.BasicEffect' to type 'Animation.BasicPaletteEffect'.

on this bit of code:
protected override void LoadGraphicsContent(bool loadAllContent)
if (loadAllContent)
// Here we load the bear model and initialize the view/projection matrices and lighting
// for its effects
Model model = content.Load<Model>("test");
foreach (ModelMesh mesh in model.Meshes) {
-------->foreach (BasicPaletteEffect eff in mesh.Effects)

...error. Any ideas? Can post the project files if need be. Sorry to bother you guys with this crap, just wish I could get all the way through this process!
Feb 2, 2007 at 4:01 AM
I had a similiar problem when substituting my own models in, and I simply changed the reference to BasicPaletteEffect to BasicEffect and all was well.

Feb 2, 2007 at 6:14 AM
Edited Feb 2, 2007 at 6:20 AM
I'll put this up in a doc wiki soon. Here is how the effects are decided when the model is loaded:

1. If someone has designated their own custom effect in the file, that is used. I'll also put up a wiki on how to use your own effects with the lib.
2. Else, if the model has skinning info (skin weights and indices), BasicPaletteEffect is used.
3. Otherwise, BasicEffect is used.

This is intended for efficiency.
Feb 2, 2007 at 6:17 AM
Edited Feb 2, 2007 at 6:25 AM
Oh, and just as an fyi, the eta for per-bone animation, which you'll need if you want to blend different animations for different body parts, is this weekend. I've been workin a lot on real life work as well as animation work, and I have a pretty in-depth gui done that lets you run through an animation and split it up into parts. (has pause/speed/export xml/import xml/time bar/can load diff models)
Feb 2, 2007 at 12:56 PM
It works! Thanks again guys!

Sounds great dastle. Can't wait to see it!