Sign in to follow this  
chillypacman

Blending animations in DirectX - is this technically possible?

Recommended Posts

I have an animated mesh in the .x format I've loaded with D3DXLoadMeshHierarchyFromX and have an animation controller for it. The mesh has two animations, one for walking and one for throwing where the walk animation. Is it at all possible to blend the two animations in such a way that both animations can run together with the walk taking priority for frames below the hip while throwing animation takes priority for frames above it? If it is will the effect look convincing therefore worth pursuing? Do game developers typically blend animations in such a way to get all the different animations they wish or do they simply create multiple versions of the same animation, i.e. walking while throwing, standing while throwing, walking without throwing?

Share this post


Link to post
Share on other sites
First, I've never done what you're thinking about, but it might be possible, though I doubt it can be done through the built-in animation controller. There is a callback function, but I don't believe you'd be able to change the updating of the transforms.

Just blue-sky thinking, but, if you have two identical animated meshes, you could apply the walk animation to one and a throw animation to the other. Then use the frame transformationMatrices for the "upper" bones from the "throwing" mesh to calculate your final transforms for the "upper" bones of the "walking" mesh. Then render just the "walking" mesh. The "throwing" mesh wouldn't be rendered, just used for getting the needed transforms. Kind of expensive CPU-wise, perhaps.

Not necessarily DirectX, but Half-Life 2, for instance, has many separate animations for various combinations of moves - run-crouch, run-shoot, etc.

Share this post


Link to post
Share on other sites

Quote:
Just blue-sky thinking, but, if you have two identical animated meshes, you could apply the walk animation to one and a throw animation to the other.


Yep I think that could work in fact that's what I'm doing right now but am coming across problems with synching up the animations together when they are the same. Would you know how I can make it so that when i set the animation for the upper body and lower body to be the same set that I can make them update simultaneously? I've tried calling ResetTime() but that hasn't helped much...


Quote:
Original post by Shael
I'd suggest taking a look at the MultiAnimation demo in the DX SDK. I can't remember for sure if it does any blending but its worth a look.


That is what I'm using for my animation system, but it only has blending from one whole animation set to another.

Share this post


Link to post
Share on other sites
BTW yes this is what almost all games do for 3d skeletal animation.

They can play different animations on different bone groups, or even blend multiple animations together on the same or overlapping groups of bones.

Also if you are curious, when switching from one animation to another, games will often start the weight of the old aniamtion at 1.0 and the weight of the new aniamtion at 0.0 and over time slowly change that (over a period of 0.2 seconds on average) so that the old animation is weighted at 0.0 and the new animation is weighted at 1.0.

At this point, the blend transition from the old animation to the new animation is complete.

It's done this way so that when you change animations there isnt a visual pop from one pose to another.

hope that helps (:

Share this post


Link to post
Share on other sites
Quote:
problems with synching up the animations together when they are the same.

???? Not sure what you mean by "when they're the same."
Quote:
Would you know how I can make it so that when i set the animation for the upper body and lower body to be the same set that I can make them update simultaneously?

Maybe I'm not understanding your question.

For what I'm suggesting, you won't be able to set the animation to the same set for both meshes. To do what you want, I believe you'll have to have two meshes and two animation sets - one for "walk" and another for "throw."

Each rendering frame, call both WalkAnimCtrl->Advance() and ThrowAnimCtrl->Advance(). From the Throw mesh's frame array, grab the frame TransformMatrix (not the combined or final) from each upper body bone and copy it to the TransformMatrix for the matching upper body bone in the Walk mesh's frame array. Then calculate the combined and final matrices for the Walk mesh. Render only the Walk mesh.

Note: Is this your question? It may be possible to load a separate animation set, previously saved and cloned into the animation controller. That may be very complicated.

As you appear to understand, the other suggestions are, indeed, methods to transition between animation sets in 2 tracks, not combine portions of 2 animation sets in a single track.

EDIT: If you use the "two mesh" approach, I don't see any problem releasing the 2nd mesh - NOT the frame array or animation controller - just the LPD3DXMESH itself, to save a bit of memory. When you're done, delete/release the rest of the objects per normal. You'd probably have to keep the SkinInfo object, also, even though you may have copied the offset transforms, as I think the anim-controller needs SkinInfo for the bone influences.

[Edited by - Buckeye on February 10, 2010 6:24:33 AM]

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