[SOLVED] Animation blendmask not working correctly

Problems building or running the engine, queries about how to use features etc.
TheSHEEEP
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 972
Joined: Mon Jun 02, 2008 6:52 pm
Location: Berlin
x 65

[SOLVED] Animation blendmask not working correctly

Post 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).
My site! - Have a look :)
Also on Twitter - extra fluffy
User avatar
Jabberwocky
OGRE Moderator
OGRE Moderator
Posts: 2819
Joined: Mon Mar 05, 2007 11:17 pm
Location: Canada
x 218

Re: Animation blendmask not working correctly

Post 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.
Image
TheSHEEEP
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 972
Joined: Mon Jun 02, 2008 6:52 pm
Location: Berlin
x 65

Re: Animation blendmask not working correctly

Post 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.
My site! - Have a look :)
Also on Twitter - extra fluffy
TheSHEEEP
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 972
Joined: Mon Jun 02, 2008 6:52 pm
Location: Berlin
x 65

Re: Animation blendmask not working correctly

Post 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.
My site! - Have a look :)
Also on Twitter - extra fluffy
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: Animation blendmask not working correctly

Post 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)
TheSHEEEP
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 972
Joined: Mon Jun 02, 2008 6:52 pm
Location: Berlin
x 65

Re: Animation blendmask not working correctly

Post 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.
My site! - Have a look :)
Also on Twitter - extra fluffy
User avatar
Zonder
Ogre Magi
Posts: 1172
Joined: Mon Aug 04, 2008 7:51 pm
Location: Manchester - England
x 76

Re: Animation blendmask not working correctly

Post 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
There are 10 types of people in the world: Those who understand binary, and those who don't...
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: Animation blendmask not working correctly

Post 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.
TheSHEEEP
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 972
Joined: Mon Jun 02, 2008 6:52 pm
Location: Berlin
x 65

Re: Animation blendmask not working correctly

Post 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.
My site! - Have a look :)
Also on Twitter - extra fluffy
User avatar
Jabberwocky
OGRE Moderator
OGRE Moderator
Posts: 2819
Joined: Mon Mar 05, 2007 11:17 pm
Location: Canada
x 218

Re: Animation blendmask not working correctly

Post 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 );
Image
TheSHEEEP
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 972
Joined: Mon Jun 02, 2008 6:52 pm
Location: Berlin
x 65

Re: Animation blendmask not working correctly

Post 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
My site! - Have a look :)
Also on Twitter - extra fluffy
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: Animation blendmask not working correctly

Post 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!
TheSHEEEP
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 972
Joined: Mon Jun 02, 2008 6:52 pm
Location: Berlin
x 65

Re: [SOLVED] Animation blendmask not working correctly

Post by TheSHEEEP »

Too true :D
My site! - Have a look :)
Also on Twitter - extra fluffy