示例#1
0
        void Update()
        {
            if (weight <= 0f)
            {
                return;
            }

            for (int x = 0; x < Fingers.Length; x++)
            {
                BoneObject finger = Fingers[x];

                if (finger == null)
                {
                    continue;
                }

                for (int i = 0; i < finger.destinationBones.Length - 1; i++)
                {
                    // Get the relative rotation from the current rotation to the target rotation
                    Quaternion f = Quaternion.Inverse(finger.destinationBones[i].rotation) * finger.targetBones[i].rotation;

                    // Weight blending
                    if (weight < 1f)
                    {
                        f = Quaternion.Slerp(Quaternion.identity, f, weight);
                    }

                    // Append relative rotation
                    finger.destinationBones[i].rotation *= f;
                }
            }
        }
        void Update()
        {
            if (weight <= 0f)
            {
                return;
            }

            for (int x = 0; x < Fingers.Length; x++)
            {
                BoneObject finger = Fingers[x];

                if (finger == null)
                {
                    continue;
                }

                for (int i = 0; i < finger.destinationBones.Length - 1; i++)
                {
                    // Get the Quaternion to rotate the current finger bone towards the next target bone position.
                    Quaternion f = Quaternion.FromToRotation(finger.destinationBones[i + 1].position - finger.destinationBones[i].position, finger.targetBones[i + 1].position - finger.destinationBones[i].position);

                    // Weight blending
                    if (weight < 1f)
                    {
                        f = Quaternion.Slerp(Quaternion.identity, f, weight);
                    }

                    // Rotate this finger bone
                    finger.destinationBones[i].rotation = f * finger.destinationBones[i].rotation;
                }
            }
        }
示例#3
0
        void OnDrawGizmos()
        {
            if (!ShowGizmos || Fingers == null)
            {
                return;
            }

            for (int x = 0; x < Fingers.Length; x++)
            {
                BoneObject finger = Fingers[x];

                for (int i = 0; i < finger.targetBones.Length; i++)
                {
                    if (finger.targetBones[i] == null)
                    {
                        continue;
                    }

                    // Target Bones
                    Gizmos.color = Color.red;
                    Gizmos.DrawSphere(finger.targetBones[i].position, 0.003f);

                    if (i < finger.targetBones.Length - 1)
                    {
                        if (finger.targetBones[i] == null || finger.targetBones[i + 1] == null)
                        {
                            continue;
                        }
                        Gizmos.DrawLine(finger.targetBones[i].position, finger.targetBones[i + 1].position);
                    }
                }

                for (int i = 0; i < finger.destinationBones.Length; i++)
                {
                    // Reference may have been removed from inspector
                    if (finger.destinationBones[i] == null)
                    {
                        continue;
                    }

                    // Avatar Bones
                    Gizmos.color = Color.yellow;
                    Gizmos.DrawSphere(finger.destinationBones[i].position, 0.003f);

                    if (i < finger.destinationBones.Length - 1)
                    {
                        if (finger.destinationBones[i] == null || finger.destinationBones[i + 1] == null)
                        {
                            continue;
                        }
                        Gizmos.DrawLine(finger.destinationBones[i].position, finger.destinationBones[i + 1].position);
                    }
                }
            }
        }