public void Prepare( FullBodyIK fullBodyIK )
{
Assert( fullBodyIK != null );
_transformIsAlive = -1;
_localAxisBasis = Matrix3x3.identity;
_isWritebackWorldPosition = false;
_parentBone = null;
// Find transform alive parent bone.
if( this.transformIsAlive ) {
for( Bone temp = _parentBoneLocationBased; temp != null; temp = temp._parentBoneLocationBased ) {
if( temp.transformIsAlive ) {
_parentBone = temp;
break;
}
}
}
#if SAFULLBODYIK_DEBUG
if( _boneType != BoneType.Hips && _boneType != BoneType.Eye ) {
if( this.transformIsAlive && _parentBone == null ) {
DebugLogError( "parentBone is not found. " + _boneLocation + " (" + _boneType + ") parentBoneLocationBased: " + ((_parentBoneLocationBased != null) ? _parentBoneLocationBased.name : "") );
}
}
#endif
if( _boneLocation == BoneLocation.Hips ) {
if( this.transformIsAlive ) {
_isWritebackWorldPosition = true;
}
} else if( _boneLocation == BoneLocation.Spine ) {
if( this.transformIsAlive ) {
if( _parentBone != null && _parentBone.transformIsAlive ) {
if( IsParentOfRecusively( _parentBone.transform, this.transform ) ) {
_isWritebackWorldPosition = true;
}
}
}
}
if( _boneType == BoneType.Eye ) {
if( fullBodyIK._IsHiddenCustomEyes() ) {
_isWritebackWorldPosition = true;
}
}
// Get defaultPosition / defaultRotation
if( this.transformIsAlive ) {
_defaultPosition = this.transform.position;
_defaultRotation = this.transform.rotation;
SAFBIKMatSetRot( out _defaultBasis, ref _defaultRotation );
if( _parentBone != null ) { // Always _parentBone.transformIsAlive == true
_defaultLocalTranslate = _defaultPosition - _parentBone._defaultPosition;
_defaultLocalLength = FastLength.FromVector3( ref _defaultLocalTranslate );
if( _defaultLocalLength.length > FLOAT_EPSILON ) {
float lengthInv = (1.0f / _defaultLocalLength.length);
_defaultLocalDirection.x = _defaultLocalTranslate.x * lengthInv;
_defaultLocalDirection.y = _defaultLocalTranslate.y * lengthInv;
_defaultLocalDirection.z = _defaultLocalTranslate.z * lengthInv;
}
}
SAFBIKMatMultInv0( out _worldToBaseBasis, ref _defaultBasis, ref fullBodyIK.internalValues.defaultRootBasis );
_baseToWorldBasis = _worldToBaseBasis.transpose;
SAFBIKMatGetRot( out _worldToBaseRotation, ref _worldToBaseBasis );
_baseToWorldRotation = Inverse( _worldToBaseRotation );
} else {
_defaultPosition = Vector3.zero;
_defaultRotation = Quaternion.identity;
_defaultBasis = Matrix3x3.identity;
_defaultLocalTranslate = Vector3.zero;
_defaultLocalLength = new FastLength();
_defaultLocalDirection = Vector3.zero;
_worldToBaseBasis = Matrix3x3.identity;
_baseToWorldBasis = Matrix3x3.identity;
_worldToBaseRotation = Quaternion.identity;
_baseToWorldRotation = Quaternion.identity;
}
_ComputeLocalAxis( fullBodyIK ); // Require PostPrepare()
}