private void Start() { _limb = gameObject.AddComponent <LimbIK>(); _limb.solver = solver; solver.bone1.transform = CreateTransform(); solver.bone2.transform = CreateTransform(); solver.bone3.transform = CreateTransform(); }
private void CheckArm() { if (arm != null) { return; } arm = GetComponentInParent <LimbIK>(); isArm = arm != null; }
void Start() { ikPos = new GameObject().transform; ikPos.position = target.position; ik = GetComponent <LimbIK>(); ik.solver.target = ikPos.transform; targetPos = ikPos.position; targetRot = ikPos.rotation; }
private LimbIK CreateIKChain(Transform bone1, Transform bone2, Transform bone3, Transform root, GameObject container, Transform target, Transform bendTarget) { LimbIK ik = container.AddComponent <LimbIK>(); ik.solver.SetChain(bone1, bone2, bone3, root); ik.solver.bendModifier = IKSolverLimb.BendModifier.Goal; ik.solver.target = target; ik.solver.bendGoal = bendTarget; return(ik); }
public void CreateCharacterIK() { if (ikGenerated) { return; } ikGenerated = true; IKExecutionOrder order = ikContainer.AddComponent <IKExecutionOrder>(); order.animator = animator; List <IK> ikComponents = new List <IK>(); ikComponents.Add(hipIK = ikContainer.AddComponent <SingleBoneIK>()); hipIK.solver.SetChain(bones.main.bone, bones.main.bone); hipIK.solver.target = targets.hip; spineIK = new LimbIK[bones.body.spine.Length]; spineIKWeight = new float[bones.body.spine.Length]; for (int i = 0; i < bones.body.spine.Length; i++) { ikComponents.Add(spineIK[i] = CreateIKChain(bones.main.bone, bones.body.spine[i].bone, bones.head.head.bone, bones.main.bone, ikContainer, targets.head.GetChild(0), targets.spine)); spineIK[i].solver.IKPositionWeight = (1 - 0.2f) / bones.body.spine.Length * (i + 1); spineIKWeight[i] = (1 - 0.2f) / bones.body.spine.Length * (i + 1); } ikComponents.Add(neckIK = CreateIKChain(bones.main.bone, bones.head.neck.bone, bones.head.head.bone, bones.main.bone, ikContainer, targets.head, targets.spine)); ikComponents.Add(leftArmIK = CreateIKChain(bones.armLeft.upperArm.bone, bones.armLeft.lowerArm.bone, bones.armLeft.hand.wrist.bone, bones.main.bone, ikContainer, targets.leftHand, targets.leftElbow)); ikComponents.Add(rightArmIK = CreateIKChain(bones.armRight.upperArm.bone, bones.armRight.lowerArm.bone, bones.armRight.hand.wrist.bone, bones.main.bone, ikContainer, targets.rightHand, targets.rightElbow)); ikComponents.Add(leftLegIK = CreateIKChain(bones.legLeft.upperLeg.bone, bones.legLeft.lowerLeg.bone, bones.legLeft.foot.bone, bones.main.bone, ikContainer, targets.leftFoot, targets.leftKnee)); ikComponents.Add(rightLegIK = CreateIKChain(bones.legRight.upperLeg.bone, bones.legRight.lowerLeg.bone, bones.legRight.foot.bone, bones.main.bone, ikContainer, targets.rightFoot, targets.rightKnee)); order.IKComponents = ikComponents.ToArray(); // Body functions hipIK.solver.OnPreUpdate += OnHipPreIK; hipIK.solver.OnPostUpdate += OnHipPostIK; // Leg functions leftLegIK.solver.OnPostUpdate += OnLeftLegPostIK; rightLegIK.solver.OnPostUpdate += OnRightLegPostIK; // Arm functions leftArmIK.solver.OnPostUpdate += OnLeftArmPostIK; rightArmIK.solver.OnPostUpdate += OnRightArmPostIK; }
void Awake() { _timeToActivateInput = Time.time + 0.5f; _owner = GetComponent <FirstPersonMover>(); if (_owner == null) { throw new MissingComponentException("VR player must be on the same GameObject as a FirstPersonMover"); } _head = _owner.GetBodyPart(MechBodyPartType.Head).transform.parent.gameObject; _head.SetActive(false); _rightHand = _owner.GetBodyPart(MechBodyPartType.RightArm).transform.parent.gameObject; _leftHand = _owner.GetBodyPart(MechBodyPartType.LeftArm).transform.parent.gameObject; _owner.AddDeathListener(OnPlayerDeath); if (_rightHand == null) { throw new Exception("Right hand is null"); } if (_leftHand == null) { throw new Exception("Left hand is null"); } Transform armLowerL = _leftHand.transform.parent; Transform armUpperL = armLowerL.parent; Transform armLowerR = _rightHand.transform.parent; Transform armUpperR = armLowerR.parent; Transform ArmsRoot = armUpperL.parent; _leftArmIK = armUpperL.gameObject.AddComponent <LimbIK>(); _leftArmIK.solver.SetChain(armUpperL, armLowerL, _leftHand.transform, ArmsRoot); _rightArmIK = armUpperR.gameObject.AddComponent <LimbIK>(); _rightArmIK.solver.SetChain(armUpperR, armLowerR, _rightHand.transform, ArmsRoot); VRManager.Instance.Player.Scale = transform.localScale.y * 1.4f; }
private void SetWeightOfAllIK(float value) { hipIK.solver.IKPositionWeight = value; hipIK.solver.IKRotationWeight = value; neckIK.solver.IKPositionWeight = value; neckIK.solver.IKRotationWeight = value; leftArmIK.solver.IKPositionWeight = value; leftArmIK.solver.IKRotationWeight = value; rightArmIK.solver.IKPositionWeight = value; rightArmIK.solver.IKRotationWeight = value; leftLegIK.solver.IKPositionWeight = value; leftLegIK.solver.IKRotationWeight = value; rightLegIK.solver.IKPositionWeight = value; rightLegIK.solver.IKRotationWeight = value; for (var i = 0; i < spineIK.Length; i++) { LimbIK ik = spineIK[i]; ik.solver.IKPositionWeight = value * spineIKWeight[i]; ik.solver.IKRotationWeight = value * spineIKWeight[i]; } }
public BodyIK( FullBodyIK fullBodyIK, LimbIK[] limbIK ) { Assert( fullBodyIK != null ); _limbIK = limbIK; _settings = fullBodyIK.settings; _internalValues = fullBodyIK.internalValues; _hipsBone = _PrepareBone( fullBodyIK.bodyBones.hips ); _neckBone = _PrepareBone( fullBodyIK.headBones.neck ); _headBone = _PrepareBone( fullBodyIK.headBones.head ); _hipsEffector = fullBodyIK.bodyEffectors.hips; _neckEffector = fullBodyIK.headEffectors.neck; _headEffector = fullBodyIK.headEffectors.head; _eyesEffector = fullBodyIK.headEffectors.eyes; _armEffectors[0] = fullBodyIK.leftArmEffectors.arm; _armEffectors[1] = fullBodyIK.rightArmEffectors.arm; _elbowEffectors[0] = fullBodyIK.leftArmEffectors.elbow; _elbowEffectors[1] = fullBodyIK.rightArmEffectors.elbow; _wristEffectors[0] = fullBodyIK.leftArmEffectors.wrist; _wristEffectors[1] = fullBodyIK.rightArmEffectors.wrist; _kneeEffectors[0] = fullBodyIK.leftLegEffectors.knee; _kneeEffectors[1] = fullBodyIK.rightLegEffectors.knee; _footEffectors[0] = fullBodyIK.leftLegEffectors.foot; _footEffectors[1] = fullBodyIK.rightLegEffectors.foot; _spineBones = _PrepareSpineBones( fullBodyIK.bones ); if( _spineBones != null && _spineBones.Length > 0 ) { int spineLength = _spineBones.Length; _spineBone = _spineBones[0]; _spineUBone = _spineBones[spineLength - 1]; _spineEnabled = new bool[spineLength]; } // Memo: These should be pair bones.(Necessary each side bones.) _kneeBones = _PrepareBones( fullBodyIK.leftLegBones.knee, fullBodyIK.rightLegBones.knee ); _elbowBones = _PrepareBones( fullBodyIK.leftArmBones.elbow, fullBodyIK.rightArmBones.elbow ); _legBones = _PrepareBones( fullBodyIK.leftLegBones.leg, fullBodyIK.rightLegBones.leg ); _armBones = _PrepareBones( fullBodyIK.leftArmBones.arm, fullBodyIK.rightArmBones.arm ); _shoulderBones = _PrepareBones( fullBodyIK.leftArmBones.shoulder, fullBodyIK.rightArmBones.shoulder ); _nearArmBones = (_shoulderBones != null) ? _shoulderBones : _nearArmBones; _Prepare( fullBodyIK ); }
// - Wakeup for solvers. // - Require to setup each transforms. public bool Prepare() { _Prefix(); if( _isPrepared ) { return false; } _isPrepared = true; Assert( rootTransform != null ); if( rootTransform != null ) { // Failsafe. internalValues.defaultRootPosition = rootTransform.position; internalValues.defaultRootBasis = Matrix3x3.FromColumn( rootTransform.right, rootTransform.up, rootTransform.forward ); internalValues.defaultRootBasisInv = internalValues.defaultRootBasis.transpose; internalValues.defaultRootRotation = rootTransform.rotation; } if( _bones != null ) { int boneLength = _bones.Length; for( int i = 0; i != boneLength; ++i ) { Assert( _bones[i] != null ); if( _bones[i] != null ) { _bones[i].Prepare( this ); } } for( int i = 0; i != boneLength; ++i ) { if( _bones[i] != null ) { _bones[i].PostPrepare(); } } } boneCaches.Prepare( this ); if( _effectors != null ) { int effectorLength = _effectors.Length; for( int i = 0; i != effectorLength; ++i ) { Assert( _effectors[i] != null ); if( _effectors[i] != null ) { _effectors[i].Prepare( this ); } } } if( _limbIK == null || _limbIK.Length != (int)LimbIKLocation.Max ) { _limbIK = new LimbIK[(int)LimbIKLocation.Max]; } for( int i = 0; i != (int)LimbIKLocation.Max; ++i ) { _limbIK[i] = new LimbIK( this, (LimbIKLocation)i ); } _bodyIK = new BodyIK( this, _limbIK ); _headIK = new HeadIK( this ); if( _fingerIK == null || _fingerIK.Length != (int)FingerIKType.Max ) { _fingerIK = new FingerIK[(int)FingerIKType.Max]; } for( int i = 0; i != (int)FingerIKType.Max; ++i ) { _fingerIK[i] = new FingerIK( this, (FingerIKType)i ); } { Bone neckBone = headBones.neck; Bone leftShoulder = leftArmBones.shoulder; Bone rightShoulder = rightArmBones.shoulder; if( leftShoulder != null && leftShoulder.transformIsAlive && rightShoulder != null && rightShoulder.transformIsAlive && neckBone != null && neckBone.transformIsAlive ) { if( leftShoulder.transform.parent == neckBone.transform && rightShoulder.transform.parent == neckBone.transform ) { _isNeedFixShoulderWorldTransform = true; } } } return true; }