protected void CacheBoneMatrices()
{
ulong currentFrameCount = Root.Instance.CurrentFrameCount;
if ( this.frameBonesLastUpdated[ 0 ] == currentFrameCount )
{
return;
}
// Get the appropriate meshes skeleton here
// Can use lower LOD mesh skeleton if mesh LOD is manual
// We make the assumption that lower LOD meshes will have
// fewer bones than the full LOD, therefore marix stack will be
// big enough.
// Check for LOD usage
if ( this.mesh.IsLodManual && this.meshLodIndex > 1 )
{
// use lower detail skeleton
Mesh lodMesh = this.mesh.GetLodLevel( this.meshLodIndex ).ManualMesh;
if ( !lodMesh.HasSkeleton )
{
this.numBoneMatrices = 0;
return;
}
}
this.skeletonInstance.SetAnimationState( this.animationState );
this.skeletonInstance.GetBoneMatrices( this.boneMatrices );
this.frameBonesLastUpdated[ 0 ] = currentFrameCount;
// TODO: Skeleton instance sharing
// update the child object's transforms
foreach ( MovableObject child in this.childObjectList.Values )
{
child.ParentNode.Update( true, true );
}
// apply the current world transforms to these too, since these are used as
// replacement world matrices
Matrix4 worldXform = this.ParentNodeFullTransform;
this.numBoneMatrices = this.skeletonInstance.BoneCount;
for ( int i = 0; i < this.numBoneMatrices; i++ )
{
this.boneMatrices[ i ] = worldXform * this.boneMatrices[ i ];
}
}