Sign in to follow this  
MohammadAhmed

.X file with animation clips

Recommended Posts

MohammadAhmed    279

I have many animations files for one model !! 


attak.x
walk.x
run.x
.................
and many others .

Now  how to mix them into one file so that I can use them in my XNA 3D animation game engine which accepts .X file only  ?? ( Pls I can't find an importer for 3d max so skip this solution smile.png )

 

Edited by mrmohadnan

Share this post


Link to post
Share on other sites
belfegor    2834

The easy way is the old DX utility mview (in attachment).

 

mview.jpg

 

Note that it doesn't support meshes with tanget/binormals, and some other cases.

 

First you open your mesh, then choose "Add Animation" (load X file with same mesh but different animation)  and repeat process for all.

Under "Animations" you should see the list of all animations that you have added.

Edited by belfegor

Share this post


Link to post
Share on other sites
MohammadAhmed    279

Ok , now My Animations are ready to being used ?? 

1 : If I want to it be for the enemy I don't need update methode called every user key input ?? 
if ( mouseButton.Right)
{

        enemy.walk; // example

}

but instead :
if(player.ray.intersects(enemy.boundingbox))
{
    enemy.walk;

}

i.e , I should used the animations for the enemy based on Machine state AI not based on user Input !! as the last one used for the player not the enemy ??!! right !!! sorry I am not strong in the animations :/ 

Share this post


Link to post
Share on other sites
MohammadAhmed    279

Ok , May be my question was not clear , again :

Q : Now I have model.x with multiple animations clips ( walk , run , attak , jump ....etc ) , Now I must make a machine state so that the enemy will run according to sum conditions and also attack if I am close enough ?? do you have pseudo code on how to do that , or do you have any information about this :) ?

Share this post


Link to post
Share on other sites
MohammadAhmed    279
I have used  XNA Animation Component Library to load ".x" files with multiple animations clips , now there is a sample called dwarfmodel and here is the code used to animate it :

private void UpdateEnemyState(GameTime gameTime, KeyboardState keyState, KeyboardState prebiousKeyState,
            MouseState mouseState)
        {
            BonePoseCollection poses = dwarfAnimator.BonePoses;
            if (stateModel == "idle")
            {
                currentSpeed = 0;
                // Add this to the beginning of the if (state=="idle") block in the UpdateState method
                // Remove the old if (keyState.IsKeyDown(Keys.W)) block
                if (keyState.IsKeyDown(Keys.W))
                {
                    blendFactor = 0;
                    stateModel = "idleToWalk";
                }
                // Add this in the if (state=="idle") block of the UpdateState method
                if (keyState.IsKeyDown(Keys.Space))
                {
                    crouch.ElapsedTime = 0;
                    crouch.IsLooping = false;
                    stateModel = "crouchDown";
                }

                if (mouseState.LeftButton == ButtonState.Pressed)
                {
                    stateModel = "attack0";
                }

                RunController(dwarfAnimator, idle);

            }
            else if (stateModel == "walk")
            {
                currentSpeed = WALK_SPEED;
                // Add this to the beginning of the if (state=="walk") block in the UpdateState method
                // Remove the old if (keyState.IsKeyUp(Keys.W)) block
                if (keyState.IsKeyUp(Keys.W))
                {
                    blendFactor = 0;
                    stateModel = "walkToIdle";
                }
                if (keyState.IsKeyDown(Keys.LeftShift) && keyState.IsKeyDown(Keys.W))
                {
                    blendFactor = 0;
                    stateModel = "walkToRun";
                    run.SpeedFactor = 0;
                }
                RunController(dwarfAnimator, crouch );
            }
            // Add this to the UpdateState method
            else if (stateModel == "idleToWalk")
            {
                blendFactor += .1f;
                currentSpeed = blendFactor * WALK_SPEED;
                if (blendFactor >= 1)
                {
                    blendFactor = 1;
                    stateModel = "walk";
                }
                foreach (BonePose p in poses)
                {
                    p.CurrentController = idle;
                    p.CurrentBlendController = walk;
                    p.BlendFactor = blendFactor;
                }
            }
            // Add this to the UpdateState method
            else if (stateModel == "walkToIdle")
            {
                blendFactor += .1f;
                currentSpeed = (1f - blendFactor) * WALK_SPEED;
                if (blendFactor >= 1)
                {
                    blendFactor = 1;
                    stateModel = "idle";
                }
                foreach (BonePose p in poses)
                {
                    p.CurrentController = walk;
                    p.CurrentBlendController = idle;
                    p.BlendFactor = blendFactor;
                }
            }
            // Add this in the UpdateState method
            else if (stateModel == "crouchDown")
            {
                crouch.AnimationEnded += crouch_AnimationEnded;
                RunController(dwarfAnimator, crouch);
            }
            else if (stateModel == "stayCrouched")
            {
                // Add this to the if (state == "stayCrouched") block in the UpdateState method
                if (keyState.IsKeyDown(Keys.Space) && prebiousKeyState.IsKeyUp(Keys.Space))
                {
                    crouch.ElapsedTime = crouch.AnimationSource.Duration;
                    crouch.SpeedFactor = 0;
                    stateModel = "standUp";
                }
                RunController(dwarfAnimator, stayCrouched);
            }
            // Add this to the UpdateState method
            else if (stateModel == "standUp")
            {
                if (crouch.ElapsedTime - gameTime.ElapsedGameTime.Ticks <= 0)
                {
                    crouch.SpeedFactor = 1;
                    crouch.ElapsedTime = 0;
                    idle.ElapsedTime = 0;
                    stateModel = "idle";
                }
                else
                    crouch.ElapsedTime -= gameTime.ElapsedGameTime.Ticks;
                RunController(dwarfAnimator, crouch);
            }
            // Add this to the UpdateState method
            else if (stateModel == "walkToRun")
            {
                blendFactor += .05f;
                if (blendFactor >= 1)
                {
                    blendFactor = 1;
                    run.SpeedFactor = 1;
                    stateModel = "run";
                }
                double factor = (double)walk.ElapsedTime / walk.AnimationSource.Duration;
                run.ElapsedTime = (long)(factor * run.AnimationSource.Duration);
                currentSpeed = WALK_SPEED + blendFactor * (RUN_SPEED - WALK_SPEED);
                foreach (BonePose p in poses)
                {
                    p.CurrentController = walk;
                    p.CurrentBlendController = run;
                    p.BlendFactor = blendFactor;
                }
            }
            else if (stateModel == "run")
            {
                currentSpeed = RUN_SPEED;
                if (keyState.IsKeyUp(Keys.LeftShift))
                {
                    blendFactor = 0;
                    stateModel = "runToWalk";
                    walk.SpeedFactor = 0;
                }
                foreach (BonePose p in poses)
                {
                    p.CurrentController = run;
                    p.CurrentBlendController = null;
                }
            }
            else if (stateModel == "runToWalk")
            {
                blendFactor += .05f;
                if (blendFactor >= 1)
                {
                    blendFactor = 1;
                    walk.SpeedFactor = 1;
                    stateModel = "walk";
                }
                double factor = (double)run.ElapsedTime / run.AnimationSource.Duration;
                walk.ElapsedTime = (long)(factor * walk.AnimationSource.Duration);
                currentSpeed = WALK_SPEED + (1f - blendFactor) * (RUN_SPEED - WALK_SPEED);
                foreach (BonePose p in poses)
                {
                    p.CurrentController = run;
                    p.CurrentBlendController = walk;
                    p.BlendFactor = blendFactor;
                }

            }

            else if (stateModel == "attack0")
            {
                attak.SpeedFactor = 2;
                blendFactor += .5f;
                if (mouseState.LeftButton == ButtonState.Released)
                    stateModel = "idle";

                RunController(dwarfAnimator, attak);
            }

        }

 

 

Q1 : So , I want to change that , to become animated based on Machine state AI , for example if I am close enough then attack and so on !!
Q2 : I have problem with modifying the xml file used for the model  , as the animation for "beast.x" model not animated like the one used for "dwarfmodel.x" , I know it's hard to understand my questions smile.png but say what you want smile.png

 

How to change making my enemy animate based on key Input to become animate based on some AI behaviours ( for example if Hero close enough then attack not it key.w then attack !! )

Edited by mrmohadnan

Share this post


Link to post
Share on other sites
MohammadAhmed    279

in addition to is being said :

the animations ( walk , run , couch , idle , attack ) are not runs well , but instead two of them are loaded correctly (walk , idle ) ?? what do you think about this problem ?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this