Пример #1
0
        /// <summary>
        /// Guesses the hand bones orientations ('Wrist To Palm Axis' and "Palm To Thumb Axis" of the arms) based on the provided references. if onlyIfZero is true, will only guess an orientation axis if it is Vector3.zero.
        /// </summary>
        public void GuessHandOrientations(VRIK.References references, bool onlyIfZero)
        {
            if (!references.isFilled)
            {
                Debug.LogWarning("VRIK References are not filled in, can not guess hand orientations. Right-click on VRIK header and slect 'Guess Hand Orientations' when you have filled in the References.", references.root);
                return;
            }

            if (leftArm.wristToPalmAxis == Vector3.zero || !onlyIfZero)
            {
                leftArm.wristToPalmAxis = VRIKCalibrator.GuessWristToPalmAxis(references.leftHand, references.leftForearm);
            }

            if (leftArm.palmToThumbAxis == Vector3.zero || !onlyIfZero)
            {
                leftArm.palmToThumbAxis = VRIKCalibrator.GuessPalmToThumbAxis(references.leftHand, references.leftForearm);
            }

            if (rightArm.wristToPalmAxis == Vector3.zero || !onlyIfZero)
            {
                rightArm.wristToPalmAxis = VRIKCalibrator.GuessWristToPalmAxis(references.rightHand, references.rightForearm);
            }

            if (rightArm.palmToThumbAxis == Vector3.zero || !onlyIfZero)
            {
                rightArm.palmToThumbAxis = VRIKCalibrator.GuessPalmToThumbAxis(references.rightHand, references.rightForearm);
            }
        }
Пример #2
0
        private static void CalibrateHand(Transform hand, Transform forearm, Transform target, Transform anchor, Vector3 positionOffset, Vector3 rotationOffset, bool isLeft)
        {
            if (isLeft)
            {
                positionOffset.x = -positionOffset.x;
                rotationOffset.y = -rotationOffset.y;
                rotationOffset.z = -rotationOffset.z;
            }

            Vector3    forward          = VRIKCalibrator.GuessWristToPalmAxis(hand, forearm);
            Vector3    up               = VRIKCalibrator.GuessPalmToThumbAxis(hand, forearm);
            Quaternion handSpace        = Quaternion.LookRotation(forward, up);
            Vector3    anchorPos        = hand.position + hand.rotation * handSpace * positionOffset;
            Quaternion anchorRot        = hand.rotation * handSpace * Quaternion.Euler(rotationOffset);
            Quaternion anchorRotInverse = Quaternion.Inverse(anchorRot);

            target.parent        = anchor;
            target.localPosition = anchorRotInverse * (hand.position - anchorPos);
            target.localRotation = anchorRotInverse * hand.rotation;
        }
Пример #3
0
        private static void CalibrateHand(VRIK ik, Transform anchor, Vector3 positionOffset, Vector3 rotationOffset, bool isLeft)
        {
            if (isLeft)
            {
                positionOffset.x = -positionOffset.x;
                rotationOffset.y = -rotationOffset.y;
                rotationOffset.z = -rotationOffset.z;
            }

            var hand    = isLeft ? ik.references.leftHand : ik.references.rightHand;
            var forearm = isLeft ? ik.references.leftForearm : ik.references.rightForearm;
            var target  = isLeft ? ik.solver.leftArm.target : ik.solver.rightArm.target;

            Vector3 forward = isLeft ? ik.solver.leftArm.wristToPalmAxis : ik.solver.rightArm.wristToPalmAxis;

            if (forward == Vector3.zero)
            {
                forward = VRIKCalibrator.GuessWristToPalmAxis(hand, forearm);
            }

            Vector3 up = isLeft ? ik.solver.leftArm.palmToThumbAxis : ik.solver.rightArm.palmToThumbAxis;

            if (up == Vector3.zero)
            {
                up = VRIKCalibrator.GuessPalmToThumbAxis(hand, forearm);
            }

            Quaternion handSpace        = Quaternion.LookRotation(forward, up);
            Vector3    anchorPos        = hand.position + hand.rotation * handSpace * positionOffset;
            Quaternion anchorRot        = hand.rotation * handSpace * Quaternion.Euler(rotationOffset);
            Quaternion anchorRotInverse = Quaternion.Inverse(anchorRot);

            target.parent        = anchor;
            target.localPosition = anchorRotInverse * (hand.position - anchorPos);
            target.localRotation = anchorRotInverse * hand.rotation;
        }