Sign in to follow this  
M4573R

Blending two animations

Recommended Posts

I have keyframed animations working. Now I'm trying to blend multiple animations together. It almost works when I add all the bone transform matrices together, but it also adds the scales together, so the model gets twice as big when blending two animations. I've tried accounting for this scale in multiple places, but have been unsuccessful. What is the proper way to blend animations? Thanks

Share this post


Link to post
Share on other sites
When I always thought about animating models, I never thought of transforming the same bone by 2 different animations, id keep each animation for each separate part of the body and never mix them into a single bone.

So the running frames only include the legs, and gun pointing or weapon pointing frames never touch the legs.

Theyd do all sorts of strange things if you combined them together, i probably would never do it.

Share this post


Link to post
Share on other sites
I'm not trying to blend between two animations, I'm trying to play two animations at once. So I could have one animation of the legs running, and then play different animations for the torso. Its all the same skeleton, I just want to add the animations together. The problem comes when each bone has its translations, and when these get added together, the model gets bigger. So I can't just add all the translations together. But if a bone is animated to move up and down, I still want to mix that in with any other animation.

Lets say I have an a waving and a walking animation. If I blend them and play them each 50/50, they each move half as much. If I use each animation's transforms 100/100 then the model gets twice as big.

[Edited by - M4573R on September 12, 2009 5:51:51 AM]

Share this post


Link to post
Share on other sites
you are additively blending the animations, which has the effects you are seeing. Typically you'll mask off a set of bones to ensure the addition only affects a few bones out of the model (it's rare to see it applied to every bone because 95% of the time it just looks plain wrong).

Most commercial animation engines do not support scale - because it's a royal pita (multiply the bones transform by the inverse parents scale matrix to correctly fix the weird scale problems - or better yet, remove it completely).

Mind you, the effects shouldn't be 'that' noticeable if you are doing the blending in local space?

Share this post


Link to post
Share on other sites
Well I'm actually not using scale. It just has the effect of scaling. Since each bone has it's own offset from its parent, adding animations together will give each bone twice the offset, essentially scaling it up. I'm only using translation and rotation when creating my bone matrices. I may need to change the way I export my bone matrices. I tried fixing the problem by only adding in changes from the bind position. However I found out that my bind matrices are much different from the keyframe matrices on the first frame of the animations. I could mask the effects, but I like having the power to add any animations together that I want. Is this easier to fix when it's a translations problem? Or does it actually become a scale problem when I add all the transform matrices together for each bone?

Share this post


Link to post
Share on other sites
Have you tried computing averages instead of adding? Each animation will have a rotation at each joint plus an "alpha" value that is a soft mask indicating what parts of the body are affected by the animation. For each joint, take the rotation indicated by each animation and blend them together with weights proportional to the alpha values.

In order to blend together several rotations, you'll probably get better results using nlerp with quaternions. In any case, make sure you normalize the quaternion or orthonormalize the rotation matrix at the end, or you'll get shrinking and enlarging models.

Share this post


Link to post
Share on other sites
Quote:
Original post by rouncED
When I always thought about animating models, I never thought of transforming the same bone by 2 different animations, id keep each animation for each separate part of the body and never mix them into a single bone.

So the running frames only include the legs, and gun pointing or weapon pointing frames never touch the legs.

Theyd do all sorts of strange things if you combined them together, i probably would never do it.


Combining them together is done often in commercial games. For instance, you can blend from one animation to another to get rid of that "poppy" effect that happens when you abruptly change animations :P

But hey, to the OP:

what you might try doing is keeping your translations, scales, and rotations around, add them together (or blend, or do whatever you want to do) and then AFTER all that stuff is done, then make matrices out of them.

It's a lot easier to blend translations, scales, and rotations seperately then trying to blend a matrix (:

Share this post


Link to post
Share on other sites
Quote:
Original post by Atrix256
But hey, to the OP:

what you might try doing is keeping your translations, scales, and rotations around, add them together (or blend, or do whatever you want to do) and then AFTER all that stuff is done, then make matrices out of them.

It's a lot easier to blend translations, scales, and rotations seperately then trying to blend a matrix (:


That's actually what I changed it to. Although I'm still getting the same problem. Perhaps I need to normalize the quaternions like alvaro said. But won't the position offsets from the parent of each bone still add together and cause the model to grow?

Share this post


Link to post
Share on other sites
the translations (like the scale and rotations) are local to the joint (ie depend on the parent) so that won't be a problem.

You might have to subtract out the reference skeleton while blending... I'm not 100% on that though sorry :/

One thing that might help you too is make an animation with only one of the components (scaling, rotating, translating) and get that working, and then move onto the next one just to isolate them into individual problems.

Share this post


Link to post
Share on other sites
I agree that if I were to start with the bind values, and then only add in changes from the bind values, it would work. However, my bind values on in world space, and and the animation transforms are all in local space. This is just the way my FBX exporter is working right now. If I can get the bind position in local space, I think this could world perfectly.

Edit: Is there a way to reconstruct parent/child transformation relationships knowing the bone hierarchy and their world transforms(my current bind transforms)?

[Edited by - M4573R on September 14, 2009 8:51:12 PM]

Share this post


Link to post
Share on other sites
Quote:
If I can get the bind position in local space, I think this could world perfectly.


If your skinning is working without the additive blending, then it is working. period. Getting the bind pose in local space, and then converting back into world space (which is the only space in which the bind pose can ever work) is not going to help matters. It sounds like you are doing everything correctly, but are surprised that additive blending looks crap. Strange warping and character distortion are fairly common artifacts.

If you just want the upper body using one anim, the lower using another. either:

a) split the character in two, and only set 1 matrix per bone (from one of the 2 anims).
b) Use a masked blend.

Quote:
Original post by M4573R
Edit: Is there a way to reconstruct parent/child transformation relationships knowing the bone hierarchy and their world transforms(my current bind transforms)?


yes. Leave them as local space (and compute the WS transforms at the very last opportunity prior to rendering). All blending occurs in local space. If you're doing anything other than that, you're doing it wrong ;)

As i said before - additive blending is really sucky. Use a masked blend instead (i.e. mask out the bones, with a specific per-bone wieght for the anim, and slerp those normally). In 95% of all cases, additive blending just looks wrong. It's extremely rare that you want to use it.

One of the really annoying aspects of Fbx is it's insistence on storing the bind pose in world space - which is a royal Pita to convert back to LS due to the various pre/post rotations and pivots etc. It is do-able. The best docs i'm aware of on the subject are in the Maya API docs for MFnTransform.

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