Doing Smooth Transitions between Skeletal Animations
The blender main task is to do smooth transitions between animation clips. The RED::ISkeletalAnimationBlender::BlendTo
function gives the user the ability to do that.
Let’s have a blender containing two skeletal animation clip controllers: idle and walk.
At the initialization step, we want the idle to be played:
Idle animation blend weight is set to 1 (
RED::ISkeletalAnimationController::SetBlendWeight
)Walk animation blend weight is set to 0
// RED::Object* idleController and walkController are skeletal animation clip controllers controlling the same skeleton.
RED::ISkeletalAnimationController* iidleController = idleController->As< RED::ISkeletalAnimationController >();
RED::ISkeletalAnimationController* iwalkController = walkController->As< RED::ISkeletalAnimationController >();
// Add the animations to the blender.
RED::ISkeletalAnimationBlender* iblender = blender->As< RED::ISkeletalAnimationBlender >();
RC_TEST( iblender->AddController( idleController ) );
RC_TEST( iblender->AddController( walkController ) );
// At initialization, idle animation is played.
iidleController->SetBlendWeight( 1.0 );
iwalkController->SetBlendWeight( 0.0 );
After calling the RED::ISkeletalAnimationController::Update
method, we see that only the idle animation is applied to the mesh.
Now, if we invert the blend weights, the walk animation will be played but there will be no transitions to them.
Fortunately, the blender is here to ease the task thanks to its RED::ISkeletalAnimationBlender::BlendTo
function. By calling it, the user can specify the target animation, the duration of the transition and the target blend weight. It will fade-out the currently played animations and fade-in the target animation.
// Send a message to the blender: blend to the walk animation in 0.3s.
RC_TEST( iblender->BlendTo( walkController, 0.3, 1.0 ) );
Note
The cross-fade is done on animations belonging to the same group (RED::ISkeletalAnimationController::SetGroup
).
This operation is equivalent to calling the function RED::ISkeletalAnimationController::SetFadeParameters
of both idle and walk animation controllers.