how to rotate individual bone ? Please Help

Jun 19, 2011 at 7:01 PM

Hi every one I have a soldier model , and he have idle ,walk .... animations .  and i need to rotate the spin bone to let my model to see up and down .

how can i achive that? (please i'm just a begginer)

Jun 23, 2011 at 11:52 PM

I have the same question.  You may want to try Microsoft's example with the XNA Framework (i.e. Simple XNA Animation).  It's very straight forward, and easy to implement.

I'm having trouble using that with the dwarf model, though.  The dwarf's bones just don't move.  I tried disabling the standard animations.  Is there a way to perform per-bone-transformation in the Animation Library that's just not in the documentation?

Jun 24, 2011 at 4:04 PM
Edited Jun 25, 2011 at 4:11 AM

I found one way to do it, but I'm not sure if it's the proper way.  Just apply your transforms to animator.BonePoses[i].DefaultTransform, and remove any controllers you assigned to that bone (i.e. animator.BonePoses[i].CurrentController = null).  The code-snippet inserter isn't working:

//--- Code Start ---//

        ModelAnimator _animator;
        ModelBone _headBone;
        ModelBone _rightElboBone;
        Matrix _headTransform;
        Matrix _rightElboTransform;

        protected override void LoadContent()
            _model = Content.Load<Model>("dwarfmodel");
            _skinEffect = Content.Load<Effect>("skinFX");

            _animator = new ModelAnimator(Game, _model);

            // Look up shortcut references to the bones we are going to animate.
            _headBone = _model.Bones["head"];
            _rightElboBone = _model.Bones["relbo"];

            // Store the original transform matrix for each animating bone.
            _headTransform = _headBone.Transform;
            _rightElboTransform = _rightElboBone.Transform;
             // Load animations for the model
            _idle = new AnimationController(Game, _animator.Animations["idle0"]);

            // Run the starting animation
            RunAnimationController(_animator, _idle);


        public override void Draw(GameTime gameTime)
            // Calculate matrices based on the current animation position.
            Matrix headRotation = Matrix.CreateRotationX(CameraPitch * 0.5f);
            Matrix rightElboRotation = Matrix.CreateRotationX(CameraPitch * 0.3f);

            // Apply matrices to the relevant bones.
            _animator.BonePoses["head"].DefaultTransform = headRotation * _headTransform;
            _animator.BonePoses["relbo"].DefaultTransform = rightElboRotation * _rightElboTransform;


        void RunAnimationController(ModelAnimator animator, AnimationController controller)
            foreach (BonePose bonePose in animator.BonePoses)
                // Don't set a controller for bones that are being controlled manually
                if (bonePose.Name == "head" || bonePose.Name == "relbo")
                bonePose.CurrentController = controller;
                bonePose.CurrentBlendController = null;

//--- Code End ---//

Of course, you'll have to add your drawing code, or load the rest of the animations.  You may also want to enable/disable a bonePose's CurrentController depending if you're manually controlling it or not.  The proper way might be to create your own controller that inherits from IAnimationController and assign that to the bonePose's CurrentController, but I haven't tried that yet.

Jun 25, 2011 at 2:50 AM

thanks friend for reply . i will try it right now .

Jun 25, 2011 at 3:23 AM

this line not work " _headBone = Model.Bones["head"];" friend .

i have some questions ?

1- if i want to play idle animation to the upper body (from spin to the arms and head) and play run animation to (legs), can i do that with component library or not ?

2- if i need to apply boundingSphere to some bones for sliding collision without using the collisionCube.cs that comes with this library .can this library allow that? (because im using xna4 and there is'nt collionsCube.cs for this version)

3- if need to make blend shape for my character(close hes eyes,open mouth or any thing), is there a way in this library?

4- is there a way to do normal map in the newer version from component libraray?

5- finally . why is'nt there an advance tutorials for this library ?


Jun 25, 2011 at 3:39 AM
Edited Jun 25, 2011 at 3:46 AM

Hey alfarza,

It's been a while since I've looked at this library. I wrote it a while ago, but I'll try to answer the questions to the best of my ability. At this point in time, it is more of a reference of how skeletal animation is done at the low level than an actual production library. Ive been seeing your posts pop up in my gmail alerts, and would feel guilty if I didn't respond to them.


1. Yes, this is supported with the library. It will take a bit of custom coding, but the animations can target specific parts of the skeleton and you can loop the animation.

2. The library was created without any regards to collision detection. It has no built in collision bounding. However, it would be possible to compute a bounding sphere on any given frame because both the world matrix transformation for the model would exist as well as the computed transformation for any given bone. Again, this is not built into the library, but would be possible to compute given the frame.

3. I don't know. Blend shapes are a concept that exist in the context of your 3d modeling tool. I don't know how they translate to the animations that you export. When I made this library, this is not something I considered.

4. You would have to create a custom shader. When I made the library, I created a very basic vertex/pixel shader based off what was available at the time. The library allows you to use your own shaders, so using normal maps is entirely possible. But again, there is no magic bullet for doing this with the original codebase. I tried to make the library flexible so that you could use any effect that you created.

5. There are no advanced tutorials because I haven't had the time to commit to this library in the past couple of years. This library was made while I was at college, and I had all the time in the world to perfect it in every manner possible at the time it was created. Now that I am working full time at a job, I simply don't have the free time to maintain the library to the extent that I wish. My current job is involved with code that has absolutely no relation to 3D programming (I currently work for a company that offers an IT security product, and writing code for it is just as fun and challenging as 3D animation).

However, I really do want to find the time to update the library. I think it is a great accomplishment and has assisted a LOT of programmers with trying to understand the fundamentals of 3D animation.

Jun 25, 2011 at 4:14 AM

alfarza wrote:

this line not work " _headBone = Model.Bones["head"];" friend .


That line should have read:

_headBone = _model.Bones["head"];

I updated my post to reflect that.  Also, it's possible your model doesn't have a bone called "head".  The code is designed to work for the dwarf model.  You can check the Bones property to find the bone you want to animate.

Jun 25, 2011 at 6:25 PM

oooops sorry i will try again drifter . thanx

and thaks for dastle also .

Jun 26, 2011 at 11:36 PM

thanks drifter it's work finally .