150 if ( ( a_bForceUpdate || m_iLastUpdateStateFrame !=
g_oSystemManager.GetFrameCount() ) &&
151 m_pSkeleton->GetKeyLibraryInstance().GetLibrary() !=
TNULL )
155 const auto QInterpFn = m_pSkeleton->GetQInterpFn();
156 TFLOAT fOneOverTotalWeight = 1.0f;
158 if ( 1.0f < m_fTotalWeight )
159 fOneOverTotalWeight = 1.0f / m_fTotalWeight;
163 for (
TINT i = 0; i < m_pSkeleton->GetAutoBoneCount(); i++ )
168 auto pBone = m_pSkeleton->GetBone( i );
170 if ( m_BaseAnimations.IsEmpty() )
172 rBoneCache.Rotation = pBone->GetRotation();
173 rBoneCache.Position = pBone->GetPosition();
177 TFLOAT fWeightTotalRatio = 0.0f;
182 auto pSeq = m_pSkeleton->GetSequence( it->GetSequence() );
183 auto pSeqBone = pSeq->GetBone( i );
185 TINT iCurrentKeyframePos =
TINT( ( it->GetSeqTime() / pSeq->GetDuration() ) * 65535 );
189 TFLOAT fLerpProgress = pSeqBone->GetKeyPair( iCurrentKeyframePos, *it->GetBone( i ), iLerpFromIndex, iLerpToIndex );
191 TFLOAT fWeightRatio = it->GetWeight() * fOneOverTotalWeight;
193 if ( fWeightRatio > 0.0f && pSeqBone->GetKeyCount() != 0 )
195 auto pFromKey = pSeqBone->GetKey( iLerpFromIndex );
196 auto pToKey = pSeqBone->GetKey( iLerpToIndex );
198 auto& rKeyLibrary = m_pSkeleton->GetKeyLibraryInstance();
199 auto pFromQuat = rKeyLibrary.GetQ( pFromKey[ 1 ] );
200 auto pToQuat = rKeyLibrary.GetQ( pToKey[ 1 ] );
202 if ( it == m_BaseAnimations.Head() )
204 bBoneHasState =
TTRUE;
205 fWeightTotalRatio = fWeightRatio;
206 QInterpFn( rBoneCache.Rotation, *pFromQuat, *pToQuat, fLerpProgress );
208 if ( pSeqBone->IsTranslateAnimated() )
210 auto pFromTranslation = rKeyLibrary.GetT( pFromKey[ 2 ] );
211 auto pToTranslation = rKeyLibrary.GetT( pToKey[ 2 ] );
213 rBoneCache.Position.Lerp( *pFromTranslation, *pToTranslation, fLerpProgress );
217 rBoneCache.Position = pBone->GetPosition();
225 QInterpFn( rotation, *pFromQuat, *pToQuat, fLerpProgress );
227 if ( pSeqBone->IsTranslateAnimated() )
229 auto pFromTranslation = rKeyLibrary.GetT( pFromKey[ 2 ] );
230 auto pToTranslation = rKeyLibrary.GetT( pToKey[ 2 ] );
232 position.
Lerp3( *pFromTranslation, *pToTranslation, fLerpProgress );
235 fWeightTotalRatio += fWeightRatio;
236 QInterpFn( rBoneCache.Rotation, rBoneCache.Rotation, rotation, fWeightRatio / fWeightTotalRatio );
238 const TVector3* pLerpToVec = pSeqBone->IsTranslateAnimated() ? &position.
AsVector3() : &pBone->GetPosition();
239 rBoneCache.Position.
Lerp( *pLerpToVec, fWeightRatio / fWeightTotalRatio );
244 if ( !bBoneHasState )
246 rBoneCache.Rotation = pBone->GetRotation();
247 rBoneCache.Position = pBone->GetPosition();
253 if ( it->GetWeight() != 0.0f )
255 auto pSeq = m_pSkeleton->GetSequence( it->GetSequence() );
256 auto pSeqBone = pSeq->GetBone( i );
258 if ( !pSeqBone->IsOverlayAnimated() && pSeqBone->GetKeyCount() != 0 )
260 TINT iCurrentKeyframePos =
TINT( ( it->GetSeqTime() / pSeq->GetDuration() ) * 65535 );
264 TFLOAT fLerpProgress = pSeqBone->GetKeyPair( iCurrentKeyframePos, *it->GetBone( i ), iLerpFromIndex, iLerpToIndex );
266 auto pFromKey = pSeqBone->GetKey( iLerpFromIndex );
267 auto pToKey = pSeqBone->GetKey( iLerpToIndex );
269 auto& rKeyLibrary = m_pSkeleton->GetKeyLibraryInstance();
270 auto pFromQuat = rKeyLibrary.GetQ( pFromKey[ 1 ] );
271 auto pToQuat = rKeyLibrary.GetQ( pToKey[ 1 ] );
276 QInterpFn( rotation, rBoneCache.Rotation, *pToQuat, fLerpProgress );
277 QInterpFn( rBoneCache.Rotation, rBoneCache.Rotation, rotation, it->GetWeight() );
280 if ( pSeqBone->IsTranslateAnimated() )
282 auto pFromTranslation = rKeyLibrary.GetT( pFromKey[ 2 ] );
283 auto pToTranslation = rKeyLibrary.GetT( pToKey[ 2 ] );
285 position.
Lerp3( *pFromTranslation, *pToTranslation, fLerpProgress );
290 pLerpToVec = &pBone->GetPosition();
293 rBoneCache.Position.
Lerp( *pLerpToVec, it->GetWeight() );
300 auto iParentBone = pBone->GetParentBone();
305 rMatrix.SetFromQuaternion( rBoneCache.Rotation );
306 rMatrix.SetTranslation( rBoneCache.Position );
317 m_pBones[ i ].m_Transform.Multiply( rMatrix, pBone->GetTransformInv() );
436 if ( m_pSkeleton->GetSequenceCount() <= a_iSequenceIndex )
442 for (
auto it = m_BaseAnimations.Begin(); pAnimation !=
TNULL && it != m_BaseAnimations.End(); ++it )
444 if ( it->GetSequence() == a_iSequenceIndex )
449 for (
auto it = m_BaseAnimations.Begin(); pAnimation !=
TNULL && it != m_BaseAnimations.End(); ++it )
451 if ( it->GetSequence() == a_iSequenceIndex )
460 pAnimation = m_FreeAnimations.IsEmpty() ?
TNULL : m_FreeAnimations.Begin();
468 if ( m_BaseAnimations.IsEmpty() )
469 pIterateList = &m_OverlayAnimations;
472 pAnimation = pIterateList->
Begin();
475 for (
auto it = pIterateList->
Begin().Next(); it != pIterateList->
End(); it++ )
477 if ( it->GetWeight() < pAnimation->
GetWeight() )
483 pSkeletonInstance->RemoveAnimation( pAnimation, 0.0f );
487 pAnimation->TQList<TAnimation>::TNode::Remove();
489 if ( m_pSkeleton->GetSequence( a_iSequenceIndex )->IsBase() )
492 m_BaseAnimations.PushFront( pAnimation );
493 m_iBaseAnimationCount++;
498 m_OverlayAnimations.PushFront( pAnimation );
499 m_iOverlayAnimationCount++;
508 pAnimation->m_iSeqID = a_iSequenceIndex;
510 pAnimation->m_iUnk3 = 0;
511 pAnimation->m_fSpeed = 1.0f;
513 if ( bIsNewAnim ) pAnimation->m_fWeight = 0.0f;
516 pAnimation->m_fBlendOutSpeed = a_fBlendOutSpeed;
517 pAnimation->m_fDestWeight = a_fDestWeight;
518 pAnimation->m_fTotalTime = 0.0f;
519 pAnimation->m_fSeqTime = 0.0f;
520 pAnimation->m_fBlendInSpeed = a_fBlendInSpeed;
522 if ( a_fBlendInSpeed <= 0.0f )
524 pAnimation->m_fWeight = a_fDestWeight;
535 pAnimation->m_pSkeletonInstance =
this;
558 auto pFirstKeyTime = *
GetKey( 0 );
560 if ( a_iCurrentAnimTime < pFirstKeyTime || a_iCurrentAnimTime == pFirstKeyTime )
563 a_rCurrentKeyIndex = 0;
564 a_rLerpFromIndex = 0;
569 auto iLastKeyIndex = m_iNumKeys - 1;
570 auto pLastKeyTime = *
GetKey( iLastKeyIndex );
572 if ( pLastKeyTime <= a_iCurrentAnimTime )
575 a_rCurrentKeyIndex = iLastKeyIndex;
576 a_rLerpFromIndex = iLastKeyIndex;
577 a_rLerpToIndex = iLastKeyIndex;
581 auto pCurrentKeyTime = *
GetKey( a_rCurrentKeyIndex );
583 if ( pCurrentKeyTime < a_iCurrentAnimTime )
586 auto iNextIndex = a_rCurrentKeyIndex + 1;
587 auto iNextKeyTime = *
GetKey( iNextIndex );
589 while ( iNextKeyTime <= a_iCurrentAnimTime )
592 a_rCurrentKeyIndex = iNextIndex++;
593 iNextKeyTime = *
GetKey( iNextIndex );
596 a_rLerpFromIndex = a_rCurrentKeyIndex;
597 a_rLerpToIndex = iNextIndex;
601 if ( pCurrentKeyTime == a_iCurrentAnimTime )
604 a_rLerpFromIndex = a_rCurrentKeyIndex;
605 a_rLerpToIndex = a_rCurrentKeyIndex;
610 auto iPrevIndex = a_rCurrentKeyIndex - 1;
611 auto iPrevKeyTime = *
GetKey( iPrevIndex );
613 while ( a_iCurrentAnimTime < iPrevKeyTime || a_iCurrentAnimTime == iPrevKeyTime )
615 a_rCurrentKeyIndex = iPrevIndex--;
616 iPrevKeyTime = *
GetKey( iPrevIndex );
619 a_rLerpFromIndex = iPrevIndex;
620 a_rLerpToIndex = a_rCurrentKeyIndex;
623 auto iLerpFromTime = *
GetKey( a_rLerpFromIndex );
624 auto iLerpToTime = *
GetKey( a_rLerpToIndex );
626 return ( ( a_iCurrentAnimTime - iLerpFromTime ) * ( 1.0f / 65535 ) ) / ( ( iLerpToTime - iLerpFromTime ) * ( 1.0f / 65535 ) );