public void ShareSkeletonInstanceWith( Entity entity )
{
if ( entity.Mesh.Skeleton != this.Mesh.Skeleton )
{
throw new AxiomException( "The supplied entity has a different skeleton." );
}
if ( this.skeletonInstance == null )
{
throw new AxiomException( "This entity has no skeleton." );
}
if ( this.sharedSkeletonInstances != null && entity.sharedSkeletonInstances != null )
{
throw new AxiomException( "Both entities already share their SkeletonInstances! At least one of the instances must not share it's instance." );
}
//check if we already share our skeletoninstance, we don't want to delete it if so
if ( this.sharedSkeletonInstances != null )
{
entity.ShareSkeletonInstanceWith( this );
}
else
{
// Clear current skeleton
this.skeletonInstance.Dispose();
this.skeletonInstance = null;
this.animationState = null;
this.frameBonesLastUpdated = null;
//copy Skeleton from sharer
this.skeletonInstance = entity.skeletonInstance;
this.animationState = entity.animationState;
this.frameBonesLastUpdated = entity.frameBonesLastUpdated;
// notify of shareing
if ( entity.sharedSkeletonInstances == null )
{
entity.sharedSkeletonInstances = new EntityList();
entity.sharedSkeletonInstances.Add( entity );
}
this.sharedSkeletonInstances = entity.sharedSkeletonInstances;
this.sharedSkeletonInstances.Add( this );
}
}