Problem with Animation Blend mask, Attached Objects and LOD

Problems building or running the engine, queries about how to use features etc.
BradJ
Kobold
Posts: 32
Joined: Fri Sep 17, 2010 1:43 am
Location: Australia
x 6

Problem with Animation Blend mask, Attached Objects and LOD

Post by BradJ »

I have encountered some issues using LOD, with attached objects and with animation blend masks. I am adding a bag to the hand of a character and overriding the arms animation to one that is a carry animation, instead of whatever the rest of the body is doing.

Just want to confirm that what I am doing is correct.

First I attach the bag to the characters hand bone

Code: Select all

  entity->attachObjectToBone( m_AttachBoneName, m_Bag, rotation, m_Offset );
Then I set the blend mode for the skeleton to Cumulative, as I am using a percentage for the animation blending; and zero for any part not affected by the animation. The first problem I found was I need to manually set the blend mode for all lod levels.

Code: Select all

  entity->getSkeleton()->setBlendMode( Ogre::ANIMBLEND_CUMULATIVE );
  size_t count = entity->getNumManualLodLevels();
  for ( size_t i = 0; i < count; ++i )
  {
	entity->getManualLodLevel( i )->getSkeleton()->setBlendMode( Ogre::ANIMBLEND_CUMULATIVE );
  }
Then I found that Ogre doesn't copy the blend mask data between LOD levels, so I added code to do so.

Code: Select all

  //---------------------------------------------------------------------
  void AnimationState::copyStateFrom(const AnimationState& animState)
  {
       // the new code to copy the blend mask data
       if ( !mBlendMask && animState.hasBlendMask() )
   	   _setBlendMask( animState.mBlendMask );
	    else if ( mBlendMask )
		{
			if ( animState.hasBlendMask() )
				_setBlendMaskData( &(*animState.mBlendMask)[0] );
			else
				destroyBlendMask();
		}
        mTimePos = animState.mTimePos;
        mLength = animState.mLength;
        mWeight = animState.mWeight;
        mEnabled = animState.mEnabled;
        mLoop = animState.mLoop;
	    mParent->_notifyDirty();
  }
Lastly I found that the bags position wasn't updated when LODing. So I have to manually update the animation for the base mesh to update the bags position.

Code: Select all

  int index = entity->getCurrentLodIndex() - 1;
  if ( index > -1 )
  {
      entity->_updateAnimation();
  }
Can anyone confirm that these are oversights / bugs in Ogre or am I going about this the wrong way?
Last edited by BradJ on Mon Apr 11, 2011 6:23 am, edited 1 time in total.
User avatar
so0os
Bugbear
Posts: 833
Joined: Thu Apr 15, 2010 7:42 am
Location: Poznan, Poland
x 33

Re: Problem with Animation Blend mask, Attached Objects and

Post by so0os »

Ogre should do that IMO. Since you posted the code, a papercut would do.
Sos Sosowski :)
http://www.sos.gd
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5505
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1371

Re: Problem with Animation Blend mask, Attached Objects and

Post by dark_sylinc »

Are you using manual Lods or automatically generated ones?
BradJ
Kobold
Posts: 32
Joined: Fri Sep 17, 2010 1:43 am
Location: Australia
x 6

Re: Problem with Animation Blend mask, Attached Objects and

Post by BradJ »

I am using manual LODs.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5505
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1371

Re: Problem with Animation Blend mask, Attached Objects and

Post by dark_sylinc »

Oh, it's a known issue with manual LODs (unfortunately an old one). It has nothing to do with the fact you're using blend masks.

Basically, because each LOD may be using a different skeleton, each one has it's own instance. Therefore when you switch LODs, you switch the skeleton instance; which may not be at the same animation position.

This doesn't happen with automatic LODs.

See this post.
mySunSet
Gnoblar
Posts: 4
Joined: Thu Sep 22, 2011 9:31 am

Re: Problem with Animation Blend mask, Attached Objects and

Post by mySunSet »

I make frequent use of this one http://www.ogre3d.org/docs/manual/manual_71.html