How to select animation to be played in model

Feb 27, 2013 at 7:58 AM
Hi , i have a animated model that have four animations, When i load the model, it play the default animation very well. I tried to select animation to play but i'm not success. Here is my code:

void input_KeyDown(object sender, KeyboardEventArgs e)
    {
        if (e.Key == Keys.D1)
        {
            var beast = scene.FindName<Nine.Graphics.Model>("beast");
            AnimationPlayer player = beast.Animations;
            player.Play("Idle");
        }
        if (e.Key == Keys.D2)
        {
            var beast = scene.FindName<Nine.Graphics.Model>("beast");
            BoneAnimation animation = new BoneAnimation(beast.Skeleton);
            animation.Play();
        }
        if (e.Key == Keys.D3)
        {
            var beast = scene.FindName<Nine.Graphics.Model>("beast");
            AnimationPlayer player = beast.Animations;
            player.Play("Bite");
        }
        if (e.Key == Keys.D4)
        {
            var beast = scene.FindName<Nine.Graphics.Model>("beast");
            AnimationPlayer player = beast.Animations;
            player.Play("Take Damage");
        }
    }
How can i do?
Developer
Mar 1, 2013 at 11:04 AM
if (player["Take Damage"].State != AnimationState.Playing)
    player.Play("Take Damage");
Sorry for my late answer. I hope this will fix your issue. :)
Mar 6, 2013 at 7:40 AM
Thank you for your supports.

I think the problem is the animated model. It's format is FBX and your animated model is X format. I have applied your codes to file peon.X and it run smoothly but it not work in my FBX Model. I use FBX Importor of XNA and Model Processor of Nine Engine.

Could you review the FBX model for me? You can download them at: http://www.apress.com/downloadable/download/sample/sample_id/526/

In chapter12 of the source code, it has two FBX models, Beast and Marine. and a custom pipleline to demonstrate them.
Developer
Mar 6, 2013 at 12:25 PM
There are some issue with the Marine, its bounding box is not 100% right (this can be related to Nine) other then that it works fine.
        var Marine = scene.FindName<Nine.Graphics.Model>("Marine");
        if (Marine.Animations["Shoot"].State != AnimationState.Playing)
            Marine.Animations.Play("Shoot");

        var Beast = scene.FindName<Nine.Graphics.Model>("Beast");
        if (Beast.Animations["Take Damage"].State != AnimationState.Playing)
            Beast.Animations.Play("Take Damage");
Mar 7, 2013 at 1:45 AM
Edited Mar 7, 2013 at 1:46 AM
I'm so sorry but i think i need asking your help again. When i load Beast model using Nine 1.4, it only load one animate like image below:

Image

And this is my code for render beast in scene:

<Model Source="{ContentReference ../Models/EnemyBeast}" Name="Beast" Transform.Scale="0.1,0.1,0.1" Transform.Position="-20, 0, 0" Transform.Rotation="{Degrees 0,180,0}" AnimationCullingEnabled="False">
    <Model.Material>
        <MaterialGroup>
            <SkinnedMaterialPart />
            <DiffuseMaterialPart />
            <SpecularMaterialPart />
            <ShadowMapMaterialPart />
            <DirectionalLightMaterialPart />
        </MaterialGroup>
    </Model.Material>
</Model>
Was i missing something?
Developer
Mar 7, 2013 at 2:13 AM

Try setting the pipeline processer to Nine's Model. If you already haven't done that.

On Mar 7, 2013 3:45 AM, "thanhvinh1" <notifications@codeplex.com> wrote:

From: thanhvinh1

I'm so sorry but i think i need asking your help again. When i load Beast model using Nine 1.4, it only load one anime like image below:

Image

And this is my code for render beast in scene:

<Model Source="{ContentReference ../Models/EnemyBeast}" Name="Beast" Transform.Scale="0.1,0.1,0.1" Transform.Position="-20, 0, 0" Transform.Rotation="{Degrees 0,180,0}" AnimationCullingEnabled="False">
    <Model.Material>
        <MaterialGroup>
            <SkinnedMaterialPart />
            <DiffuseMaterialPart />
            <SpecularMaterialPart />
            <ShadowMapMaterialPart />
            <DirectionalLightMaterialPart />
        </MaterialGroup>
    </Model.Material>
</Model>
Was i missing something?

Read the full discussion online.

To add a post to this discussion, reply to this email (nine@discussions.codeplex.com)

To start a new discussion for this project, email nine@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Mar 8, 2013 at 10:53 AM
I find another solution, i split that model into five. each of them will contain one animations :)

But now i have another problem, the animation speed is slower than i need. How do i increase the speed animation?