SA.FullBodyIK.ConfigureBoneTransforms C# (CSharp) Method

ConfigureBoneTransforms() public method

public ConfigureBoneTransforms ( ) : void
return void
		public void ConfigureBoneTransforms()
		{
			_Prefix();

			Assert( settings != null && rootTransform != null );
			if( settings.automaticPrepareHumanoid && rootTransform != null ) {
				Animator animator = rootTransform.GetComponent<Animator>();
				if( animator != null && animator.isHuman ) {
					Transform hips = animator.GetBoneTransform( HumanBodyBones.Hips );
					Transform spine = animator.GetBoneTransform( HumanBodyBones.Spine );
					Transform spine2 = animator.GetBoneTransform( HumanBodyBones.Chest );
					Transform spine3 = null;
					Transform spine4 = null;
					Transform neck = animator.GetBoneTransform( HumanBodyBones.Neck );
					Transform head = animator.GetBoneTransform( HumanBodyBones.Head );
					Transform leftEye = animator.GetBoneTransform( HumanBodyBones.LeftEye );
					Transform rightEye = animator.GetBoneTransform( HumanBodyBones.RightEye );
					Transform leftLeg = animator.GetBoneTransform( HumanBodyBones.LeftUpperLeg );
					Transform rightLeg = animator.GetBoneTransform( HumanBodyBones.RightUpperLeg );
					Transform leftKnee = animator.GetBoneTransform( HumanBodyBones.LeftLowerLeg );
					Transform rightKnee = animator.GetBoneTransform( HumanBodyBones.RightLowerLeg );
					Transform leftFoot = animator.GetBoneTransform( HumanBodyBones.LeftFoot );
					Transform rightFoot = animator.GetBoneTransform( HumanBodyBones.RightFoot );
					Transform leftShoulder = animator.GetBoneTransform( HumanBodyBones.LeftShoulder );
					Transform rightShoulder = animator.GetBoneTransform( HumanBodyBones.RightShoulder );
					Transform leftArm = animator.GetBoneTransform( HumanBodyBones.LeftUpperArm );
					Transform rightArm = animator.GetBoneTransform( HumanBodyBones.RightUpperArm );
					Transform leftElbow = animator.GetBoneTransform( HumanBodyBones.LeftLowerArm );
					Transform rightElbow = animator.GetBoneTransform( HumanBodyBones.RightLowerArm );
					Transform leftWrist = animator.GetBoneTransform( HumanBodyBones.LeftHand );
					Transform rightWrist = animator.GetBoneTransform( HumanBodyBones.RightHand );
					Transform[,] leftFingers = new Transform[5, 4];
					Transform[,] rightFingers = new Transform[5, 4];
					for( int n = 0; n != 2; ++n ) {
						int humanBodyBones = ((n == 0) ? (int)HumanBodyBones.LeftThumbProximal : (int)HumanBodyBones.RightThumbProximal);
						Transform[,] fingers = ((n == 0) ? leftFingers : rightFingers);
						for( int i = 0; i != 5; ++i ) {
							for( int j = 0; j != 3; ++j, ++humanBodyBones ) {
								fingers[i, j] = animator.GetBoneTransform( (HumanBodyBones)humanBodyBones );
							}
							// Fix for tips.
							if( fingers[i, 2] != null && fingers[i, 2].childCount != 0 ) {
								fingers[i, 3] = fingers[i, 2].GetChild( 0 );
							}
						}
					}

					if( neck == null ) {
						if( head != null ) {
							Transform t = head.parent;
							if( t != null && _IsNeck( t ) ) {
								neck = t;
							} else {
								neck = head; // Failsafe.
							}
						}
					}

					if( leftEye == null ) {
						leftEye = _FindEye( head, false );
					}
					if( rightEye == null ) {
						rightEye = _FindEye( head, true );
					}

					if( settings.automaticConfigureSpineEnabled ) {
						if( spine != null && neck != null ) {
							var spines = new List<Transform>();
							for( Transform trn = neck.parent; trn != null && trn != spine; trn = trn.parent ) {
								if( _IsSpine( trn ) ) {
									spines.Insert( 0, trn );
								}
                            }

							spines.Insert( 0, spine );

							int spineMaxLength = (int)BoneLocation.SpineU - (int)BoneLocation.Spine + 1;
							if( spines.Count > spineMaxLength ) {
								spines.RemoveRange( spineMaxLength, spines.Count - spineMaxLength );
							}

							spine2 = (spines.Count >= 2) ? spines[1] : null;
							spine3 = (spines.Count >= 3) ? spines[2] : null;
							spine4 = (spines.Count >= 4) ? spines[3] : null;
						}
					}

					_SetBoneTransform( ref bodyBones.hips, hips );
					_SetBoneTransform( ref bodyBones.spine, spine );
					_SetBoneTransform( ref bodyBones.spine2, spine2 );
					_SetBoneTransform( ref bodyBones.spine3, spine3 );
					_SetBoneTransform( ref bodyBones.spine4, spine4 );

					_SetBoneTransform( ref headBones.neck, neck );
					_SetBoneTransform( ref headBones.head, head );
					_SetBoneTransform( ref headBones.leftEye, leftEye );
					_SetBoneTransform( ref headBones.rightEye, rightEye );

					_SetBoneTransform( ref leftLegBones.leg, leftLeg );
					_SetBoneTransform( ref leftLegBones.knee, leftKnee );
					_SetBoneTransform( ref leftLegBones.foot, leftFoot );
					_SetBoneTransform( ref rightLegBones.leg, rightLeg );
					_SetBoneTransform( ref rightLegBones.knee, rightKnee );
					_SetBoneTransform( ref rightLegBones.foot, rightFoot );

					_SetBoneTransform( ref leftArmBones.shoulder, leftShoulder );
					_SetBoneTransform( ref leftArmBones.arm, leftArm );
					_SetBoneTransform( ref leftArmBones.elbow, leftElbow );
					_SetBoneTransform( ref leftArmBones.wrist, leftWrist );
					_SetBoneTransform( ref rightArmBones.shoulder, rightShoulder );
					_SetBoneTransform( ref rightArmBones.arm, rightArm );
					_SetBoneTransform( ref rightArmBones.elbow, rightElbow );
					_SetBoneTransform( ref rightArmBones.wrist, rightWrist );

					_SetFingerBoneTransform( ref leftHandFingersBones.thumb, leftFingers, 0 );
					_SetFingerBoneTransform( ref leftHandFingersBones.index, leftFingers, 1 );
					_SetFingerBoneTransform( ref leftHandFingersBones.middle, leftFingers, 2 );
					_SetFingerBoneTransform( ref leftHandFingersBones.ring, leftFingers, 3 );
					_SetFingerBoneTransform( ref leftHandFingersBones.little, leftFingers, 4 );

					_SetFingerBoneTransform( ref rightHandFingersBones.thumb, rightFingers, 0 );
					_SetFingerBoneTransform( ref rightHandFingersBones.index, rightFingers, 1 );
					_SetFingerBoneTransform( ref rightHandFingersBones.middle, rightFingers, 2 );
					_SetFingerBoneTransform( ref rightHandFingersBones.ring, rightFingers, 3 );
					_SetFingerBoneTransform( ref rightHandFingersBones.little, rightFingers, 4 );
				}
			}

			if( settings.automaticConfigureRollBonesEnabled ) {
				var tempBones = new List<Transform>();

				for( int side = 0; side != 2; ++side ) {
					var armBones = (side == 0) ? leftArmBones : rightArmBones;
					if( armBones != null &&
						armBones.arm != null && armBones.arm.transform != null &&
						armBones.elbow != null && armBones.elbow.transform != null &&
						armBones.wrist != null && armBones.wrist.transform != null ) {

						_ConfigureRollBones( armBones.armRoll, tempBones, armBones.arm.transform, armBones.elbow.transform, (Side)side, true );
						_ConfigureRollBones( armBones.elbowRoll, tempBones, armBones.elbow.transform, armBones.wrist.transform, (Side)side, false );
					}
				}
			}
		}
FullBodyIK