Archived

This topic is now archived and is closed to further replies.

Night Elf

Animation blending in DX9

Recommended Posts

The DirectX 9 docs mention blending many times, especially in the ID3DXAnimationController reference section. But it isn''t clear (for me, at least) what they are talking about. Is it possible to blend two animations together so as to achieve a smooth transition from one to the other using the new DX9 interfaces? If so, how do you do it? (A source snippet would be great).

Share this post


Link to post
Share on other sites
I''ve been playing with the Mesh Viewer source code, trying to make tracks 0 and 1 blend but I''ve been unsuccessful.
These are the functions I''ve tried (they all belong to the ID3DXAnimationController class):
- Key/SetPriorityBlend()
- Key/SetTrackAnimationTime()
- Key/SetTrackEnable()
- Key/SetTrackWeight()
- RegisterAnimationSet()
- SetTrackAnimationSet()

Share this post


Link to post
Share on other sites
I've also been experimenting with animation blending, and like you, I've also been unsuccessful. For some reason I can't get anything other then track 0 to animate. Everything from track 1 and up doesn't work.

Has Anyone successfully blended between two animated tracks?

[edited by - MagTDK on December 26, 2002 12:28:20 PM]

Share this post


Link to post
Share on other sites
quote:

Does ID3DXAnimationController::GetMaxNumTracks return more than 1 track?


Yeah, it returns: 2

I'm loading two animation sets.

I can do this:

      
LPD3DXANIMATIONCONTROLLER AnimationController;
LPD3DXANIMATIONSET AnimSet;

AnimationController->GetAnimationSet(1, &AnimSet);
m_pAnimController->SetTrackAnimationSet(0, AnimSet);


But this only renders track 0. Can't I just render track 1 directly without getting and setting the track?

[edited by - MagTDK on December 26, 2002 1:06:41 PM]

Share this post


Link to post
Share on other sites
I''ve also been unsuccesful so far with blending animations. I can play different tracks, but whenever I switch animations, the transition is not smooth, it just resets to the new animationset.

Share this post


Link to post
Share on other sites
I would think this portion of code would blend from track 0 to track 1 but it doesn't.

AnimationController->KeyTrackWeight(0, 0.0f, AnimationController->GetTime(), 0.5f, 0);
AnimationController->KeyTrackWeight(1, 1.0f, AnimationController->GetTime(), 0.5f, 0);

There's something I'm missing

[edited by - MagTDK on December 26, 2002 2:17:40 PM]

Share this post


Link to post
Share on other sites
How I wish the DX9 docs were complete (or something other than 90% function prototypes).

Anyone planning on writing up a nice tutorial on using the animation classes in DX9? (maybe in C#)

Share this post


Link to post
Share on other sites
quote:

How I wish the DX9 docs were complete (or something other than 90% function prototypes).



I agree with you, Pseudo. It''s really hard to learn from the DX docs... The only way to learn form the SDK is to decrypt the poorly-commented source code of the samples. Unfortunately they haven''t included an animation blending sample :-(

Thank you all for your replies.
I will keep looking into animation blending and will post anything I find. I hope you do the same.

Share this post


Link to post
Share on other sites
quote:

Even before you get to animation blending...how do you export a 3DS model with more than one animation or timeline?


You don''t. AFAIK, you have two options:
1. Export to different .X files and manually merge them into a single file by copying and pasting. (This has been explained in other threads. See: http://www.gamedev.net/community/forums/topic.asp?topic_id=126399). Then you just load the resulting file.
2. Export to different .X files and load the animations from these files into a single animation controller. This is the way multiple animations are loaded in the Mesh Viewer tool that comes with the DX9 SDK.

Share this post


Link to post
Share on other sites
Thx, I''ve got multiple animations in one file now.

I''ve also got the different animations bound to different keys, and they switch nicely.

I can''t seem to figure out how to blend between animations tho. The last and final piece to the puzzle...

I imagine the process goes something like this:

1) load/register animation sets
2) key track params
3) enable tracks/mixer

But who knows...

Is there a Microsoft email we can all flood with requests for a sample app demonstrating animation blending?

Share this post


Link to post
Share on other sites
I couldnt get it to work either.... grrrr... Im running out of hair to pull out!

One of you be kind enough to lead us lesser mortals in the right direction when you figure it out plz.

Share this post


Link to post
Share on other sites
This is what I did. I imagine that the times would need to be different depending on the speed of your animation.

This code blends from one animation to another. The current animation is at track 0, and the new animation index is AnimIndex in the code.

The Track Description has the time of the track, and when you set a new animation set, it is undefined. So it''s quite important to set it.

(Apologies for posting inline, not sure how to do the cute code windows yet)


// Move Track 0 to track 1
D3DXTRACK_DESC Desc;
LPD3DXANIMATIONSET AnimSet;
m_AnimController->GetTrackDesc(0, &Desc);
m_AnimController->SetTrackDesc(1, &Desc);
m_AnimController->GetTrackAnimationSet(0, &AnimSet);
m_AnimController->SetTrackAnimationSet(1, AnimSet);

// Load the new animation set into track 0
m_AnimController->GetAnimationSet(AnimIndex, &AnimSet);
m_AnimController->SetTrackAnimationSet(0, AnimSet);

// Set the track description
// Set the weight to 0 for the blend
Desc.Weight = 0;
Desc.AnimTime = AnimSet->GetPeriod();
m_AnimController->SetTrackDesc(0, &Desc);

// Key the blend
m_AnimController->KeyTrackWeight(1, 0, m_AnimController->GetTime(), 0.002, D3DXTRANSITION_EASEINEASEOUT );
m_AnimController->KeyTrackWeight(0, 1, m_AnimController->GetTime(), 0.002, D3DXTRANSITION_EASEINEASEOUT );

Share this post


Link to post
Share on other sites

quote:

I can''t believe that MagTDK couldn''t get this to work... I got all of my animation help from his post.



Smoot, if your referring to animation blending, I posted how I did it a while back ago here:

http://www.gamedev.net/community/forums/topic.asp?topic_id=130637

Share this post


Link to post
Share on other sites