public void DoRenderFrame()
{
float delta = RendererWorld.Instance.FrameRenderTimeStep;
for( int n = 0; n < activeItems.Count; n++ )
{
AnimationItem item = activeItems[ n ];
MeshObject.AnimationState animationState = item.animationState;
//time progress
animationState.AddTime( item.Velocity * delta );
//has ended?
if( !item.Loop )
{
if( animationState.TimePosition + blendingTime * 2 + .001f >=
item.animationState.Length )
{
Remove( item );
n--;
continue;
}
}
//change random animation
if( item.Loop && item.AllowRandomAnimationNumber )
{
//detect rewind
if( animationState.TimePosition < item.lastTimePosition )
{
string animationName = item.AnimationBaseName;
int number = GetRandomAnimationNumber( animationName, true );
if( number != 1 )
animationName += number.ToString();
MeshObject.AnimationState newAnimationState =
meshObject.GetAnimationState( animationName );
if( newAnimationState == null )
{
Log.Fatal( "MeshObjectAnimationController: DoRenderFrame: " +
"newAnimationState == null." );
}
animationState.Enable = false;
newAnimationState.Loop = animationState.Loop;
newAnimationState.TimePosition = animationState.TimePosition;
newAnimationState.Weight = animationState.Weight;
newAnimationState.Enable = true;
item.animationState = newAnimationState;
}
}
//update weight for blending
if( blendingTime != 0 )
{
item.blendingWeightCoefficient += delta / blendingTime;
if( item.blendingWeightCoefficient > 1 )
item.blendingWeightCoefficient = 1;
}
item.lastTimePosition = animationState.TimePosition;
}
for( int n = 0; n < removedItemsForBlending.Count; n++ )
{
AnimationItem item = removedItemsForBlending[ n ];
item.blendingWeightCoefficient -= delta / blendingTime;
if( item.blendingWeightCoefficient <= 0 )
{
item.animationState.Enable = false;
removedItemsForBlending.RemoveAt( n );
n--;
continue;
}
}
UpdateAnimationStatesWeights();
}