Skip to content

Commit

Permalink
Bugfix: Some v1 skeleton animations would not playback properly as v2…
Browse files Browse the repository at this point in the history
… items due

to a wrap around behavior in v1::AnimationTrack::getKeyFramesAtTime which v2 doesn't perform.
  • Loading branch information
darksylinc committed Feb 25, 2020
1 parent 9afe697 commit d35259e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion OgreMain/src/Animation/OgreSkeletonAnimationDef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ namespace Ogre

if( track->getNumKeyFrames() > 0 )
{
// Old V1 skeletons would wrap around to keyframe[0] if keyframe[n-1] did not
// cover until the end of the animation. We need to mimic that behavior.
// (See v1::AnimationTrack::getKeyFramesAtTime)
const bool extraKeyFrameAtEnd =
track->getKeyFrame( track->getNumKeyFrames() - 1u )->getTime() <
animation->getLength();

uint32 slotIdx = boneToSlot[boneIdx];
uint32 blockIdx = SkeletonDef::slotToBlockIdx( slotIdx );

Expand All @@ -104,7 +111,7 @@ namespace Ogre
std::make_pair( (size_t)blockIdx, emptyVec ) ).first;
}

itKeyframes->second.reserve( track->getNumKeyFrames() );
itKeyframes->second.reserve( track->getNumKeyFrames() + (size_t)extraKeyFrameAtEnd );

for( size_t i=0; i<track->getNumKeyFrames(); ++i )
{
Expand All @@ -115,6 +122,16 @@ namespace Ogre
if( it == itKeyframes->second.end() || *it != timestamp )
itKeyframes->second.insert( it, timestamp );
}

if( extraKeyFrameAtEnd )
{
Real timestamp = animation->getLength();
TimestampVec::iterator it = std::lower_bound( itKeyframes->second.begin(),
itKeyframes->second.end(),
timestamp );
if( it == itKeyframes->second.end() || *it != timestamp )
itKeyframes->second.insert( it, timestamp );
}
}
}

Expand Down

0 comments on commit d35259e

Please sign in to comment.