#### Archived

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

# Animation Tweening Between KeyFrames - I.E. Smooth Animation!

This topic is 5064 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a .X Model Which has a few keyframes in it I'm using AnimationController to animate this model but I face two problems: 1. The Animation is extremely fast 2. There's no tweening between frames and this model requires tweening between frames to function properly Could Someone please help me out and tell me what I need to do to accomplish these two things using ID3DXAnimationController Thanks, -jason [edited by - hexskillz on April 8, 2004 5:55:51 PM]

##### Share on other sites
well, i can''t help you out completely yet, cause im studying this now as well, but essentialy what you need to do is blend between keyframes.

what this means is if for example you have a vertex at x=0 and at the next keyframe, after 10 seconds it''s at x=10, then it''s position after one second should be 90% of x=0 and 10% of x=10, so new_x = (0.9 * 0 + 0.1 * 10 ), this will place the new_x at x=1. after another second it''s 80% and 20%...so new_x = (0.8 * 0 + 0.2 * 10), so the new_x is 2...your''e whole path between 2 keyframes is 100%...you just figure out a general formula to transform/rotate each vertex, and decide how many % of animation is advanced every time unit u decide (second for example).

this is just what i got from reading for a few minutes...im not 100% sure that this is right, though it seems reasonable to me.

hope this helps..

##### Share on other sites
Try looking at the Dolphin sample in the DXSDK, I haven''t taken a close look at it but I know it uses vertex tweening.

##### Share on other sites
Get the "Advanced Animation With DirectX 9" book by Jim Adams. It will save you a lot of time.

##### Share on other sites

I am aware at how to calculate the mid positions between frames manually although right now i'm not at that option unless i choose to write my own animation controller. I am quite certain that the animation controller can do this however I can't firgure out how.

I'm guessing you need to enable 2 animation tracks and use one of their blending properties? Some code would help me out.

The Dolphin example does not do animation tweening between keyframes rather it uses 3 seperate meshes and tweens between these seperate meshes without the animation controller.

I would definitly like that book! however its not availible to a me near a local store right now and buying it over the internet is not an option.

I'll be able to order it from my store probably - I'm not sure quite yet.

Thanks,
-Jason

[edited by - hexskillz on April 5, 2004 6:47:12 PM]

##### Share on other sites
Jim''s book is pretty good but he sure makes it harder than it needs to. Just check out gamedev''s out little animation article. It is about all you need. Jim goes into his own animation blending code, but it is already but in dx so I don''t know why. Also I have seen his in action and dx''s in action, and they appear nearly identical. So he made a 200 page answer out of which could have taken a small tutorial.

http://www.gamedev.net/reference/articles/article2079.asp

##### Share on other sites
I fail to see the "tweening" part of that article (which is the article that got me to this point where i am today)

##### Share on other sites
The animations controller has a keyframe setup I believe.

KeyframedAnimationSet

here are 2 ok links. Dx has the support, it is just a matter of using it. Since the tutorial is a good start and it sounds like you have it loaded, just look into setting up the controller using one of these.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_m/directx/ref/ns/microsoft.directx.direct3d/c/keyframedanimationset/m/ctor.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_m/directx/ref/ns/microsoft.directx.direct3d/c/keyframedanimationset/keyframedanimationset.asp

##### Share on other sites
Also check into this

http://www.gamedev.net/reference/programming/features/vertextweening/page2.asp

##### Share on other sites
I appreciate your help although I still don''t think you know what I''m looking for.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_m/directx/ref/ns/microsoft.directx.direct3d/c/keyframedanimationset/m/ctor.asp

I''m using Unmanaged C++ not .NET although even so KeyframedAnimationSet provides no way of tweening animation key frames. I''m quite aware on how to play back animations without tweening.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_m/directx/ref/ns/microsoft.directx.direct3d/c/keyframedanimationset/keyframedanimationset.asp

Once again i''m not using .NET however that just looks like a ID3DXAnimationController but posting a reference to ID3DXAnimationController isn''t any help at all; i''ve looked at it continously and i''m asking how to use that interface to produce animation tweening.

http://www.gamedev.net/reference/programming/features/vertextweening/page2.asp

I''ve seen this before too this still doesn''t provide help on

"tell me what I need to do to accomplish these two things __using__ ID3DXAnimationController"

Using that form of animation tweening would require me to disect the ID3DXMesh too much.

thanks
-Jason

##### Share on other sites
Part of the confusion is use of the word ''tweening.'' There''s vertex tweening as a runtime concept, where you set a lerp value and submit two position vectors in the vertex stream, and the runtime lerps between them. That''s not what the animation controller does.

If you''re able to load the .x file and get in into an animation controller, it should just be a matter of:

o Set the animation set to a track in the animation controller
o Set the track properties to enable it, and set its speed
o AdvanceTime (in, say, seconds) to play it out. This updates the frame hierarchy, and you can use that to render the parts of the mesh.

The MultiAnimation sample goes through this. That''s the sample to check out to see how the animation interfaces work.

I like pie.

##### Share on other sites
I''ve gotten that far, now i''d like tweening to be done between each keyframe.

I''ve seen a lot of "blendable" options in AnimationController
as well as its definition is:

This interface is used to control animation functionality, connecting animation sets with the transformation frames that are being animated. The interface has methods to mix multiple animations and to modify blending parameters over time to enable smooth transitions and other effects.

"Smooth transitions" is what i mean by tweening
my model has 3 keyframes i want mesh positions to be calculated in between the keyframes for smooth animation.

How?

##### Share on other sites
quote:
Original post by HexSkillz
I''ve gotten that far, now i''d like tweening to be done between each keyframe.

I''ve seen a lot of "blendable" options in AnimationController
as well as its definition is:

This interface is used to control animation functionality, connecting animation sets with the transformation frames that are being animated. The interface has methods to mix multiple animations and to modify blending parameters over time to enable smooth transitions and other effects.

"Smooth transitions" is what i mean by tweening
my model has 3 keyframes i want mesh positions to be calculated in between the keyframes for smooth animation.

How?

I''m not sure we''re eye to eye on terminology.

You have three keyframes in a single animation set? Or three animation sets you''d like to blend together?

If you have just one animatoin set with three keyframes (or however many), just set that one animation set to a track and call AdvanceTime in small increments. It''ll do the tweening for you.

If you have several animation sets and you want to transition between two of them, set each to a track in the animation controller, enable both tracks, and then use the KeyTrackWeight method to specify weight transitions from 0-1 on one track, and 1-0 on the other. Refer to the MultiAnimation sample for that.

I like pie.

##### Share on other sites
Oh really it does the tweening for me?

Ok now how do i slow down the playback of the animationset(Note: SetTrackSpeed(0, 0.1f) didn''t slow the speed down)

All i get are my guys arms flying around in a circle really fast.

##### Share on other sites
Maybe it is just your mesh, or you are advancing the time in huge amounts. The advace time for the animation controller is delta elasped not entire app time. Cause when you advance the time, it advances each track based on their speed... so if you are advancing it in huge amounts it won't matter what the track speed is.

One other thing, when you load the tiny.x does it work correctly? Cause if it is super fast it is your code, but it is ok then maybe you are setting it up wrong. I know the load hierarchy works for bones but I am not sure how well it works for keyframed meshes. If it is just keyframed meshes it is easy enough to do for yourself and not work about the animation controllers. Cause the term tweening usually doesn't apply for bones since it really is just an interpolation and then the vertices are shaped based on weight and the animation track weight. So you don't really tweewn the vertices between to frames, just interpolate...

[edited by - JimmyNelson on April 9, 2004 2:45:34 PM]

##### Share on other sites
tiny is keyframed/skeletal similar to my mesh

I think i found the problem

the keyframes for my mesh are placed on the timeframe 1 millisecond apart:

warrior1.x:
AnimationKey {
4;
24;
0; 16; 0.992628
1; 16; 0.981168
2; 16; 0.964500
3; 16; 0.949278
...

tiny.x:
AnimationKey {
4;
62;
0;16;0.215193,
80;16;0.229303
160;16;0.245110
240;16;0.260841
}

ill make the modifications and post again

thanks
-Jason

[edited by - hexskillz on April 9, 2004 3:29:58 PM]

##### Share on other sites
works!

thanks for everyones help

now i''ll just need a program to wad its way through this mesh.x file and change all the timing :-S

Mmmmmmmm. Perl.

I like pie.

##### Share on other sites
mmm i don''t know perl.. :''(

##### Share on other sites
s/don\''t/should learn/;
s/\''$$/$$/;
post \$_;

I like pie.