Page 1 of 1

[SOLVED] Animation blendmask not working correctly

Posted: Wed Jan 16, 2013 12:14 pm
by TheSHEEEP
Hey there,

I am animating a character with some walk/dance animations.
At the same time, I want to play a speak animation. Now this speak animation should be limited to a certain number of bones.
I figured BlendMasks would be the way to go here (as I have no possibility of exporting the speak anim affecting only those bones).

Here is what I do:

Code: Select all

// Play lip animations
Ogre::AnimationState* animState = _characterEntity->getAnimationState("speak_mouth_open");
		
animState->createBlendMask(_characterEntity->getSkeleton()->getNumBones(), 0.0f);
Ogre::Bone* bone = _characterEntity->getSkeleton()->getBone("upper_lip_center_speak");
animState->setBlendMaskEntry(bone->getHandle(), 1.0f);
bone = _characterEntity->getSkeleton()->getBone("lower_lip_center_speak");
animState->setBlendMaskEntry(bone->getHandle(), 1.0f);	
animState->setEnabled(true);
animState->setTimePosition(0.0f);
But this leads to the complete "speak_mouth_open" animation being applied, not only the two target bones.
As soon as I add any BlendMaskEntry, the whole animation is applied. When I do not set any entries, the animation is not shown at all, which is correct, due to the initial weight of 0.0f.

Any ideas what could be wrong here?
Neither of these bones are parents to other bones.

If it is of any importance, I add the "speak_mouth_open" animation via _mergeSkeletonAnimations from an extra exported .skeleton file.
All of our animations are exported into an extra .skeleton file and merged with the "master" skeleton (which simply is the first of the external ones which is loaded in a different way).

Re: Animation blendmask not working correctly

Posted: Wed Jan 16, 2013 1:05 pm
by Jabberwocky
Your code looks right to me.
Which means:
1. We're missing something, and your code is wrong somehow.
2. blendmasks are broken in your version of ogre (annoyingly, it looks like there is no BlendMask sample).
3. the _mergeSkeletonAnimations thing is causing problems.
3. the blending is working, but you're just misinterpreting the visual result.

I guess that's all pretty obvious, but I'd work on trying to eliminate each one by doing some tests.

Re: Animation blendmask not working correctly

Posted: Wed Jan 16, 2013 1:21 pm
by TheSHEEEP
Well, I had a look at the resulting .mesh and .skeleton files we export.

I converted them to XML and...
There are no vertex bone assignments in the mesh xml. Also not in the skeleton xml files.
But the animations in the skeleton files work perfectly.
How is that even possible? Or does the ogreXMLConverter simply not output the vertex bone assignemnts?

Besides of that mystery, would there probably be another possibility to limit an animation to certain bones?

I don't think the _mergeSkeletonAnimations is causing problems as all other animations work well.
I've also tried using addLinkedSkeletonAnimationSource instead of mergeSkeletonAnimations to add all animations to the mesh. The result was the same.

Re: Animation blendmask not working correctly

Posted: Wed Jan 16, 2013 4:19 pm
by TheSHEEEP
I was able to resolve the issue of the missing vertex bone assignments (was an error in the exporter).
Unfortunately, that didn't help with the issue that the blendmask doesn't work.

Re: Animation blendmask not working correctly

Posted: Wed Jan 16, 2013 4:44 pm
by al2950
The last time I checked blend masks were working fine in V1.8. When you say the speak_mouth_open animation applies to all bones and not just the target bones, what exactly happens?

Also are you applying another animation, ie a standard pose? I am not sure what would happen if you only apply a single animation to a skeleton with a blend mask. As in what are the other bones set to, I believe their transforms are set to 0, but you never know!

If you want to debug and check to what values are being applied to the other bones, if any, you want to debug Animation::apply function (the blend mask version)

Re: Animation blendmask not working correctly

Posted: Wed Jan 16, 2013 5:00 pm
by TheSHEEEP
Well, I plan to have several animations running at once. One "main" animation, like walking or dancing, and several facial animations.
So, I have two animations running at once at the moment.

What you see is that the facial animation somehow "forces" the character into the bind pose, so you see a mixture between the dancing animation and the bind pose.

That is why I want to limit the facial animation to affect only the correct facial bones.
But as soon as I apply the blend mask, the described effect happens.

Edit:
I just tried to replace the exported facial animation with one created at runtime (which does nothing but setting one bone to some value).
And the effect is the same. So the described effect seems to happen as soon as I play any two animations at once.

Code: Select all

// Create lip animation
Ogre::Animation* anim = 
		_characterEntity->getSkeleton()->createAnimation("mouth_anim", 0.04f);
Ogre::Bone* targetBone = _characterEntity->getSkeleton()->getBone("upper_lip_center_speak");
Ogre::NodeAnimationTrack* nodeTrack = anim->createNodeTrack(0, targetBone);
Ogre::TransformKeyFrame* keyFrame = nodeTrack->createNodeKeyFrame(0.0f);
keyFrame->setTranslate(Ogre::Vector3(0.0f, 0.10829f, 0.0f));
		
targetBone = _characterEntity->getSkeleton()->getBone("lower_lip_center_speak");
nodeTrack = anim->createNodeTrack(1, targetBone);
keyFrame = nodeTrack->createNodeKeyFrame(0.0f);
keyFrame->setTranslate(Ogre::Vector3(0.0f, -0.224384, 0.0f));
		
_characterEntity->refreshAvailableAnimationState();
		
Ogre::AnimationState* animState = _characterEntity->getAnimationState("mouth_anim");
animState->setEnabled(true);
animState->setTimePosition(0.0f);
animState->setWeight(0.5f);
Setting the weight increases/decreases the described effect, so if I set it to 1.0f, the "bind pose" is pretty much dominating, while setting it to 0.1f makes the dancing animation dominate.
Strange... How can this "mouth_anim" even affect anything beyond its assigned bones? As I said, the bones I used are no parents to any other bones.

Re: Animation blendmask not working correctly

Posted: Wed Jan 16, 2013 5:11 pm
by Zonder
You probably have seen these but I though would post just in case.

http://ogre3d.org/forums/viewtopic.php?f=11&t=64515

(This is the original one that is mentioned in the above link)
http://ogre3d.org/forums/viewtopic.php?f=11&t=45260

Re: Animation blendmask not working correctly

Posted: Wed Jan 16, 2013 5:30 pm
by al2950
Well it certainly sounds like its not working at all! I worked on the initial blend mask system for TecnoFreak so I know the system fairly well. All I can suggest is debug the mentioned function and also check the blend mask data in Ogre::AnimationState to make sure it is correct.

Re: Animation blendmask not working correctly

Posted: Wed Jan 16, 2013 7:10 pm
by TheSHEEEP
al2950 wrote:Well it certainly sounds like its not working at all! I worked on the initial blend mask system for TecnoFreak so I know the system fairly well. All I can suggest is debug the mentioned function and also check the blend mask data in Ogre::AnimationState to make sure it is correct.
Yup, but if you take a look at my last post, you will see that the described effect even happens when I create a new animation from scratch at runtime that does not touch any bone but the desired two.
It is as if an animation that does not touch a bone is "pulling" the bone towards the bind pose.
I'll certainly debug the apply function to see what is happening here.

Re: Animation blendmask not working correctly

Posted: Wed Jan 16, 2013 7:28 pm
by Jabberwocky
I think I know what's going on. Are you using ANIMBLEND_CUMULATIVE or ANIMBLEND_AVERAGE? (I bet it's ANIMBLEND_AVERAGE.)

You need to use ANIMBLEND_CUMULATIVE if you want to make use of blendmasks.

Code: Select all

      pEntity->getSkeleton()->setBlendMode( ANIMBLEND_CUMULATIVE );

Re: Animation blendmask not working correctly

Posted: Thu Jan 17, 2013 9:20 am
by TheSHEEEP
That was it, thanks!
With the cumulative mode, I don't even need the blend mask any more. I thought I needed it as it looked like the facial animation was also "touching" non-face bones. Oh, well.
Now I just have to make sure that our exporter exports skeletons with the correct mode.

Guess I would have found that sooner or later, but you sure saved me a day or two :D

Re: Animation blendmask not working correctly

Posted: Thu Jan 17, 2013 9:54 am
by al2950
Jabberwocky wrote:I think I know what's going on. Are you using ANIMBLEND_CUMULATIVE or ANIMBLEND_AVERAGE? (I bet it's ANIMBLEND_AVERAGE.)

You need to use ANIMBLEND_CUMULATIVE if you want to make use of blendmasks.

Code: Select all

      pEntity->getSkeleton()->setBlendMode( ANIMBLEND_CUMULATIVE );
I never realised that :oops: . You learn something new everyday!

Re: [SOLVED] Animation blendmask not working correctly

Posted: Thu Jan 17, 2013 2:29 pm
by TheSHEEEP
Too true :D