Пример #1
0
        // Initiates the LimbIK solver
        public void Initiate(Transform hand, int index)
        {
            initiated = false;
            if (!IsValid(true, hand))
            {
                return;
            }

            solver = new IKSolverLimb();

            solver.IKPositionWeight   = weight;
            solver.bendModifier       = IKSolverLimb.BendModifier.Target;
            solver.bendModifierWeight = 1f;

            IKPosition = tip.position;
            IKRotation = tip.rotation;

            if (bone3 != null)
            {
                bone3RelativeToTarget     = Quaternion.Inverse(IKRotation) * bone3.rotation;
                bone3DefaultLocalPosition = bone3.localPosition;
                bone3DefaultLocalRotation = bone3.localRotation;
            }

            solver.SetChain(bone1, bone2, tip, hand);
            solver.Initiate(hand);

            initiated = true;
        }
Пример #2
0
        // Initiates the LimbIK solver
        public void Initiate(Transform hand, int index)
        {
            initiated = false;

            string errorMessage = string.Empty;

            if (!IsValid(ref errorMessage))
            {
                Warning.Log(errorMessage, hand, false);
                return;
            }

            solver = new IKSolverLimb();

            solver.IKPositionWeight   = weight;
            solver.bendModifier       = IKSolverLimb.BendModifier.Target;
            solver.bendModifierWeight = 1f;
            defaultBendNormal         = -Vector3.Cross(tip.position - bone1.position, bone2.position - bone1.position).normalized;
            solver.bendNormal         = defaultBendNormal;

            Vector3 axisWorld = Vector3.Cross(bone2.position - bone1.position, tip.position - bone1.position);

            bone1Axis = Quaternion.Inverse(bone1.rotation) * axisWorld;
            tipAxis   = Quaternion.Inverse(tip.rotation) * axisWorld;

            Vector3 normal  = bone2.position - bone1.position;
            Vector3 tangent = -Vector3.Cross(tip.position - bone1.position, bone2.position - bone1.position);

            Vector3.OrthoNormalize(ref normal, ref tangent);
            bone1TwistAxis = Quaternion.Inverse(bone1.rotation) * tangent;

            IKPosition = tip.position;
            IKRotation = tip.rotation;

            if (bone3 != null)
            {
                bone3RelativeToTarget     = Quaternion.Inverse(IKRotation) * bone3.rotation;
                bone3DefaultLocalPosition = bone3.localPosition;
                bone3DefaultLocalRotation = bone3.localRotation;
            }

            solver.SetChain(bone1, bone2, tip, hand);
            solver.Initiate(hand);

            initiated = true;
        }
        public void AssignReferences(BipedReferences references)
        {
            // Assigning limbs from references
            leftHand.SetChain(references.leftUpperArm, references.leftForearm, references.leftHand, references.root);
            rightHand.SetChain(references.rightUpperArm, references.rightForearm, references.rightHand, references.root);
            leftFoot.SetChain(references.leftThigh, references.leftCalf, references.leftFoot, references.root);
            rightFoot.SetChain(references.rightThigh, references.rightCalf, references.rightFoot, references.root);

            // Assigning spine bones from references
            spine.SetChain(references.spine, references.root);

            // Assigning lookAt bones from references
            lookAt.SetChain(references.spine, references.head, references.eyes, references.root);

            // Assigning Aim bones from references
            aim.SetChain(references.spine, references.root);

            leftFoot.goal  = AvatarIKGoal.LeftFoot;
            rightFoot.goal = AvatarIKGoal.RightFoot;
            leftHand.goal  = AvatarIKGoal.LeftHand;
            rightHand.goal = AvatarIKGoal.RightHand;
        }
Пример #4
0
		// Initiates the LimbIK solver
		public void Initiate(Transform hand, int index) {
			initiated = false;

			string errorMessage = string.Empty;
			if (!IsValid(ref errorMessage)) {
				Warning.Log(errorMessage, hand, false);
				return;
			}

			solver = new IKSolverLimb();

			solver.IKPositionWeight = weight;
			solver.bendModifier = IKSolverLimb.BendModifier.Target;
			solver.bendModifierWeight = 1f;

			IKPosition = tip.position;
			IKRotation = tip.rotation;

			if (bone3 != null) {
				bone3RelativeToTarget = Quaternion.Inverse(IKRotation) * bone3.rotation;
				bone3DefaultLocalPosition = bone3.localPosition;
				bone3DefaultLocalRotation = bone3.localRotation;
			}

			solver.SetChain(bone1, bone2, tip, hand);
			solver.Initiate(hand);

			initiated = true;
		}