This project is read-only.

Animation blending problems

Sep 9, 2011 at 11:28 PM

Hi everyone,

I am in the process of building a simple application that displays an animated model with 4 animations: idle, pointing, waving, scratching. The imported model is built using 3DS max 2011 x64, rigged in 3DS max 2011 x64, and animated in Motionbuilder 2011 x64. The result is an .fbx file that was imported back into 3DS max, to generate one long take with all animations in it. Using the kW X-port plugin in 3DS max, i splitted up the animations again and generated an .X file. This .X file is then used in the Xen API. The model renders correctly, and playing seperate animations works fine.

1. Problem 1: When 2 animations are blended, the scale of the model grows larger and larger, with a maximum scale when both animations have a weighting of 0.5f applied. I have checked the model in 3DS max and motionbuilder to check for any scale keys, but none could be found. I have a suspicion that this could be caused in the kW X-port plugin, which possibly scales the model (and the bones), causing the growth of the model in a blended state.

2. Problem 2: Sometimes when an animation is finished and another one hasn't started yet, the game might execute a call to the Draw() method when the model is in it's initial pose. In my project, this initial pose has a scale much larger than the scale under animation (which might also be a cause of problem 1 above). This should be avoided at all costs!

Any tips on how i can solve this? Listed below is the code i have used for the AnimatedModel. (This code demonstrates the scaling problem in particular with the keys F1 and F2 to change the weights).

class AnimatedModel : IDraw, IUpdate, IContentOwner
    {
        private ModelInstance model;
        private Matrix worldMatrix;

        private AnimationController animControl;
        private AnimationInstance prevAnimation;
        private AnimationInstance currAnimation;

        private AnimationInstance wavingAnimation;
        private AnimationInstance scratchingAnimation;

        int wavingIndex;
        int scratchingIndex;

        public AnimatedModel(ContentRegister content, UpdateManager update, Vector3 position)
        {
            worldMatrix = Matrix.CreateScale(1.0f) * Matrix.CreateTranslation(position) * Matrix.CreateRotationX(MathHelper.PiOver2);

            this.model = new ModelInstance();

            update.Add(this);
            content.Add(this);

            animControl = model.GetAsyncAnimationController(update);

            wavingIndex = animControl.AnimationIndex("waving");
            scratchingIndex = animControl.AnimationIndex("scratching");

            wavingAnimation = animControl.PlayLoopingAnimation(wavingIndex);
            scratchingAnimation = animControl.PlayLoopingAnimation(scratchingIndex);
            wavingAnimation.Weighting = 0.5f;
            scratchingAnimation.Weighting = 0.5f;

            var lightCollection = new MaterialLightCollection();

            lightCollection.CreateDirectionalLight(new Vector3(1.0f, -1.0f, -1.0f), Color.White,Color.White);
            lightCollection.CreateDirectionalLight(new Vector3(-1.0f, -1.0f, -1.0f), Color.Green,Color.White);
            lightCollection.AmbientLightColour = new Vector3(0.2f,0.2f,0.2f);
            model.LightCollection = lightCollection;
        }

        public void Draw(DrawState state)
        {
            using (state.WorldMatrix.Push(ref worldMatrix))
            {
                if (model.CullTest(state))
                    model.Draw(state);
            }
        }

        public bool CullTest(ICuller culler)
        {
            return true;
        }

        public UpdateFrequency Update(UpdateState state)
        {
             if (state.KeyboardState.KeyState.F1.OnPressed)
             {
                 if (scratchingAnimation.Weighting < 0.99f)
                 {
                     wavingAnimation.Weighting -= 0.01f;
                     scratchingAnimation.Weighting += 0.01f;
                 }
             }
             if (state.KeyboardState.KeyState.F2.OnPressed)
             {
                 if (wavingAnimation.Weighting < 0.99f)
                 {
                     wavingAnimation.Weighting += 0.01f;
                     scratchingAnimation.Weighting -= 0.01f;
                 }

             }       
            return UpdateFrequency.FullUpdate60hz;
        }

        public void LoadContent(ContentState state)
        {
            model.ModelData = state.Load<Xen.Ex.Graphics.Content.ModelData>(@"chimpanzeeTest");
        }
    }
 

Oct 1, 2011 at 2:44 PM

anyone? I still havent figured it out.

Also, I have noticed that not all parts of the model are rendering. I reduced the code to the bare minimum to do skinned animation, but my animations are still missing.

 

namespace XenEngineTest
{
    class AnimatedModel : IDraw, IUpdate, IContentOwner
    {
        private ModelInstance model;
        private Matrix worldMatrix;
        private AnimationController animControl;
        private AnimationInstance animation;

        public AnimatedModel(ContentRegister content, Vector3 position)
        {
            this.model = new ModelInstance();
            content.Add(this);
            worldMatrix = Matrix.CreateTranslation(position);
            this.animControl = this.model.GetAnimationController();
            int animIndex = animControl.AnimationIndex("waving");
            animation = animControl.PlayLoopingAnimation(animIndex);
        }

        public void Draw(DrawState state)
        {
            using (state.WorldMatrix.Push(ref worldMatrix))
            {
                if (model.CullTest(state))
                    model.Draw(state);
            }
        }

        public bool CullTest(ICuller culler)
        {
            return true;
        }

        public UpdateFrequency Update(UpdateState state)
        {
            return UpdateFrequency.FullUpdate60hz;
        }

        public void LoadContent(ContentState state)
        {
            model.ModelData = state.Load<Xen.Ex.Graphics.Content.ModelData>(@"chimpanzee");
        }
    }
}