Esempio n. 1
0
        // Update the LimbIK solver and rotate the optional 3rd bone
        public void Update(float masterWeight)
        {
            if (!initiated)
            {
                return;
            }

            float w = weight * masterWeight;

            if (w <= 0f)
            {
                return;
            }

            solver.target = target;
            if (target != null)
            {
                IKPosition = target.position;
                IKRotation = target.rotation;
            }

            if (rotationDOF == DOF.One)
            {
                Quaternion q = Quaternion.FromToRotation(IKRotation * tipAxis, bone1.rotation * bone1Axis);
                IKRotation = q * IKRotation;
            }

            // Rotate the 3rd bone
            if (bone3 != null)
            {
                if (w * rotationWeight >= 1f)
                {
                    bone3.rotation = IKRotation * bone3RelativeToTarget;
                }
                else
                {
                    bone3.rotation = Quaternion.Lerp(bone3.rotation, IKRotation * bone3RelativeToTarget, w * rotationWeight);
                }
            }

            // Update the LimbIK solver
            solver.bendNormal         = -Vector3.Cross(tip.position - bone1.position, bone2.position - bone1.position);
            solver.IKPositionWeight   = w;
            solver.IKRotationWeight   = rotationWeight;
            solver.bendModifierWeight = rotationWeight;
            solver.Update();

            if (fixBone1Twist)
            {
                Quaternion bone2Rotation = bone2.rotation;
                Quaternion space         = Quaternion.LookRotation(bone1.rotation * bone1TwistAxis, bone2.position - bone1.position);
                Vector3    bone1Twist    = Quaternion.Inverse(space) * solver.bendNormal;
                float      angle         = Mathf.Atan2(bone1Twist.x, bone1Twist.z) * Mathf.Rad2Deg;
                bone1.rotation = Quaternion.AngleAxis(angle, bone2.position - bone1.position) * bone1.rotation;
                bone2.rotation = bone2Rotation;
            }
        }
Esempio n. 2
0
        // Update the LimbIK solver and rotate the optional 3rd bone
        public void Update(float masterWeight)
        {
            if (!initiated)
            {
                return;
            }

            float w = weight * masterWeight;

            if (w <= 0f)
            {
                return;
            }

            solver.target = target;
            if (target != null)
            {
                IKPosition = target.position;
                IKRotation = target.rotation;
            }

            if (rotationDOF == DOF.One)
            {
                Quaternion q = Quaternion.FromToRotation(IKRotation * tipAxis, bone1.rotation * bone1Axis);
                IKRotation = q * IKRotation;
            }

            // Rotate the 3rd bone
            if (bone3 != null)
            {
                if (w * rotationWeight >= 1f)
                {
                    bone3.rotation = IKRotation * bone3RelativeToTarget;
                }
                else
                {
                    bone3.rotation = Quaternion.Lerp(bone3.rotation, IKRotation * bone3RelativeToTarget, w * rotationWeight);
                }
            }

            // Update the LimbIK solver
            solver.IKPositionWeight   = w;
            solver.IKRotationWeight   = rotationWeight;
            solver.bendModifierWeight = rotationWeight;
            solver.Update();
        }
Esempio n. 3
0
        // Update the LimbIK solver and rotate the optional 3rd bone
        public void Update(float masterWeight)
        {
            if (!initiated)
            {
                return;
            }

            float w = weight * masterWeight;

            if (w <= 0f)
            {
                return;
            }

            solver.target = target;
            if (target != null)
            {
                IKPosition = target.position;
                IKRotation = target.rotation;
            }

            // Rotate the 3rd bone
            if (bone3 != null)
            {
                if (w >= 1f)
                {
                    bone3.rotation = IKRotation * bone3RelativeToTarget;
                }
                else
                {
                    bone3.rotation = Quaternion.Lerp(bone3.rotation, IKRotation * bone3RelativeToTarget, w);
                }
            }

            // Update the LimbIK solver
            solver.IKPositionWeight = w;
            solver.Update();
        }