// Apply to IKSolverFullBodyBiped
            public void Apply(VRIK ik, AnimationCurve[] curves, float weight)
            {
                float deltaTime = Time.time - lastTime;

                lastTime = Time.time;

                if (timer >= length)
                {
                    return;
                }

                // Advance the timer
                timer = Mathf.Clamp(timer + deltaTime, 0f, length);

                // Advance the crossFader
                if (crossFadeSpeed > 0f)
                {
                    crossFader = Mathf.Clamp(crossFader + (deltaTime * crossFadeSpeed), 0f, 1f);
                }
                else
                {
                    crossFader = 1f;
                }

                // Pass this on to the hit points
                OnApply(ik, curves, weight);
            }
    private void initialize()
    {
        vrik = gameObject.AddComponent <RootMotion.FinalIK.VRIK>();
        vrik.AutoDetectReferences();
        vrik.references.leftThigh  = null;
        vrik.references.leftCalf   = null;
        vrik.references.leftFoot   = null;
        vrik.references.leftToes   = null;
        vrik.references.rightThigh = null;
        vrik.references.rightCalf  = null;
        vrik.references.rightFoot  = null;
        vrik.references.rightToes  = null;

        Transform leftHand = (new GameObject()).transform;

        leftHand.parent = leftController;
        leftHand.transform.localPosition = new Vector3(-0.0153f, 0.0662f, -0.1731f);
        leftHand.transform.localRotation = Quaternion.Euler(-8.222f, 79.485f, 142.351f);
        vrik.solver.leftArm.target       = leftHand;

        Transform rightHand = (new GameObject()).transform;

        rightHand.parent = rightController;
        rightHand.transform.localPosition = new Vector3(0.02300016f, 0.07700036f, -0.1700005f);
        rightHand.transform.localRotation = Quaternion.Euler(-4.75f, -85.497f, -145.387f);
        vrik.solver.rightArm.target       = rightHand;

        Transform head = (new GameObject()).transform;

        head.parent                    = camera;
        head.localPosition             = new Vector3(0, -0.165f, -0.085f);
        head.localRotation             = Quaternion.Euler(0, 90, 0);
        vrik.solver.spine.headTarget   = head;
        vrik.solver.spine.maxRootAngle = 180;
    }
    // Use this for initialization
    void Start()
    {
        this.targetPos = this.transform.localPosition;

#if HUMAN_NAVI_USING_FINAL_IK
        this.vrik = this.bodyWithIK.GetComponent <RootMotion.FinalIK.VRIK>();
#endif
    }
    // Use this for initialization
    void Start()
    {
        this.targetPos = this.transform.localPosition;

#if ENABLE_VRIK
        this.vrik = this.bodyWithIK.GetComponent <RootMotion.FinalIK.VRIK>();
#endif
    }
Exemple #5
0
        /// <summary>
        /// Calibrates body target to avatar pelvis position and position/rotation offsets in character root space.
        /// </summary>
        public static void CalibrateBody(VRIK ik, Transform pelvisTracker, Vector3 trackerPositionOffset, Vector3 trackerRotationOffset)
        {
            if (ik.solver.spine.pelvisTarget == null)
            {
                ik.solver.spine.pelvisTarget = new GameObject("Pelvis IK Target").transform;
            }

            ik.solver.spine.pelvisTarget.position = ik.references.pelvis.position + ik.references.root.rotation * trackerPositionOffset;
            ik.solver.spine.pelvisTarget.rotation = ik.references.root.rotation * Quaternion.Euler(trackerRotationOffset);
            ik.solver.spine.pelvisTarget.parent   = pelvisTracker;
        }
            protected override void OnApply(VRIK ik, AnimationCurve[] curves, float weight)
            {
                Vector3 a      = ik.transform.up * base.force.magnitude;
                Vector3 vector = curves[this.forceDirCurveIndex].Evaluate(base.timer) * base.force + curves[this.upDirCurveIndex].Evaluate(base.timer) * a;

                vector *= weight;
                foreach (HitReactionVRIK.PositionOffset.PositionOffsetLink positionOffsetLink in this.offsetLinks)
                {
                    positionOffsetLink.Apply(ik, vector, base.crossFader);
                }
            }
    void _Set()
    {
        if (BodyIK != _bodyIK)
        {
            Root.position = BodyIK.references.root.position;
            Root.rotation = BodyIK.references.root.rotation;

            HeadEF.position = BodyIK.references.head.position;
            HeadEF.rotation = BodyIK.references.head.rotation;
            BodyIK.solver.spine.headTarget = HeadEF;

            PelvisEF.position = BodyIK.references.pelvis.position;
            PelvisEF.rotation = BodyIK.references.pelvis.rotation;
            BodyIK.solver.spine.pelvisTarget = PelvisEF;

            LHandEF.position             = BodyIK.references.leftHand.position;
            LHandEF.rotation             = BodyIK.references.leftHand.rotation;
            BodyIK.solver.leftArm.target = LHandEF;

            RHandEF.position = BodyIK.references.rightHand.position;
            RHandEF.rotation = BodyIK.references.rightHand.rotation;
            BodyIK.solver.rightArm.target = RHandEF;

            LElbowEF.position = BodyIK.references.leftForearm.position;
            LElbowEF.rotation = BodyIK.references.leftForearm.rotation;
            BodyIK.solver.leftArm.bendGoal = LElbowEF;

            RElbowEF.position = BodyIK.references.rightForearm.position;
            RElbowEF.rotation = BodyIK.references.rightForearm.rotation;
            BodyIK.solver.rightArm.bendGoal = RElbowEF;

            LLegEF.position = BodyIK.references.leftFoot.position;
            LLegEF.rotation = BodyIK.references.leftFoot.rotation;
            BodyIK.solver.leftLeg.target = LLegEF;

            RLegEF.position = BodyIK.references.rightFoot.position;
            RLegEF.rotation = BodyIK.references.rightFoot.rotation;
            BodyIK.solver.rightLeg.target = RLegEF;


            LKneeEF.position = BodyIK.references.leftCalf.position;
            LKneeEF.rotation = BodyIK.references.leftCalf.rotation;
            BodyIK.solver.leftLeg.bendGoal = LKneeEF;

            RKneeEF.position = BodyIK.references.rightCalf.position;
            RKneeEF.rotation = BodyIK.references.rightCalf.rotation;
            BodyIK.solver.rightLeg.bendGoal = RKneeEF;



            _bodyIK = BodyIK;
        }
    }
Exemple #8
0
            protected override void OnApply(VRIK ik, AnimationCurve[] curves, float weight)
            {
                Vector3 a      = ik.transform.up * base.force.magnitude;
                Vector3 vector = curves[this.forceDirCurveIndex].Evaluate(base.timer) * base.force + curves[this.upDirCurveIndex].Evaluate(base.timer) * a;

                vector *= weight;
                HitReactionVRIK.PositionOffset.PositionOffsetLink[] array = this.offsetLinks;
                for (int i = 0; i < array.Length; i++)
                {
                    array[i].Apply(ik, vector, base.crossFader);
                }
            }
            // Calculate offset, apply to FBBIK effectors
            protected override void OnApply(VRIK ik, AnimationCurve[] curves, float weight)
            {
                Vector3 up = ik.transform.up * force.magnitude;

                Vector3 offset = (curves[forceDirCurveIndex].Evaluate(timer) * force) + (curves[upDirCurveIndex].Evaluate(timer) * up);

                offset *= weight;

                foreach (PositionOffsetLink l in offsetLinks)
                {
                    l.Apply(ik, offset, crossFader);
                }
            }
Exemple #10
0
        /// <summary>
        /// Calibrates hand IK targets to specified anchor position and rotation offsets independent of avatar bone orientations.
        /// </summary>
        public static void CalibrateHands(VRIK ik, Transform leftHandAnchor, Transform rightHandAnchor, Vector3 anchorPositionOffset, Vector3 anchorRotationOffset)
        {
            if (ik.solver.leftArm.target == null)
            {
                ik.solver.leftArm.target = new GameObject("Left Hand IK Target").transform;
            }
            if (ik.solver.rightArm.target == null)
            {
                ik.solver.rightArm.target = new GameObject("Right Hand IK Target").transform;
            }

            CalibrateHand(ik, leftHandAnchor, anchorPositionOffset, anchorRotationOffset, true);
            CalibrateHand(ik, rightHandAnchor, anchorPositionOffset, anchorRotationOffset, false);
        }
Exemple #11
0
 // Auto-assign ik
 void OnDrawGizmosSelected()
 {
     if (ik == null)
     {
         ik = GetComponent <VRIK>();
     }
     if (ik == null)
     {
         ik = GetComponentInParent <VRIK>();
     }
     if (ik == null)
     {
         ik = GetComponentInChildren <VRIK>();
     }
 }
Exemple #12
0
        /// <summary>
        /// Simple calibration to head and hands using predefined anchor position and rotation offsets.
        /// </summary>
        /// <param name="ik">The VRIK component.</param>
        /// <param name="centerEyeAnchor">HMD.</param>
        /// <param name="leftHandAnchor">Left hand controller.</param>
        /// <param name="rightHandAnchor">Right hand controller.</param>
        /// <param name="centerEyePositionOffset">Position offset of the camera from the head bone (root space).</param>
        /// <param name="centerEyeRotationOffset">Rotation offset of the camera from the head bone (root space).</param>
        /// <param name="handPositionOffset">Position offset of the hand controller from the hand bone (controller space).</param>
        /// <param name="handRotationOffset">Rotation offset of the hand controller from the hand bone (controller space).</param>
        /// <param name="scaleMlp">Multiplies the scale of the root.</param>
        /// <returns></returns>
        public static CalibrationData Calibrate(VRIK ik, Transform centerEyeAnchor, Transform leftHandAnchor, Transform rightHandAnchor, Vector3 centerEyePositionOffset, Vector3 centerEyeRotationOffset, Vector3 handPositionOffset, Vector3 handRotationOffset, float scaleMlp = 1f)
        {
            CalibrateHead(ik, centerEyeAnchor, centerEyePositionOffset, centerEyeRotationOffset);
            CalibrateHands(ik, leftHandAnchor, rightHandAnchor, handPositionOffset, handRotationOffset);
            CalibrateScale(ik, scaleMlp);

            // Fill in Calibration Data
            CalibrationData data = new CalibrationData();

            data.scale     = ik.references.root.localScale.y;
            data.head      = new CalibrationData.Target(ik.solver.spine.headTarget);
            data.leftHand  = new CalibrationData.Target(ik.solver.leftArm.target);
            data.rightHand = new CalibrationData.Target(ik.solver.rightArm.target);

            return(data);
        }
Exemple #13
0
        /// <summary>
        /// Calibrates head IK target to specified anchor position and rotation offset independent of avatar bone orientations.
        /// </summary>
        public static void CalibrateHead(VRIK ik, Transform centerEyeAnchor, Vector3 anchorPositionOffset, Vector3 anchorRotationOffset)
        {
            if (ik.solver.spine.headTarget == null)
            {
                ik.solver.spine.headTarget = new GameObject("Head IK Target").transform;
            }

            Vector3    forward   = Quaternion.Inverse(ik.references.head.rotation) * ik.references.root.forward;
            Vector3    up        = Quaternion.Inverse(ik.references.head.rotation) * ik.references.root.up;
            Quaternion headSpace = Quaternion.LookRotation(forward, up);

            Vector3    anchorPos        = ik.references.head.position + ik.references.head.rotation * headSpace * anchorPositionOffset;
            Quaternion anchorRot        = ik.references.head.rotation * headSpace * Quaternion.Euler(anchorRotationOffset);
            Quaternion anchorRotInverse = Quaternion.Inverse(anchorRot);

            ik.solver.spine.headTarget.parent        = centerEyeAnchor;
            ik.solver.spine.headTarget.localPosition = anchorRotInverse * (ik.references.head.position - anchorPos);
            ik.solver.spine.headTarget.localRotation = anchorRotInverse * ik.references.head.rotation;
        }
            public void Apply(VRIK ik, AnimationCurve[] curves, float weight)
            {
                float num = Time.time - this.lastTime;

                this.lastTime = Time.time;
                if (this.timer >= this.length)
                {
                    return;
                }
                this.timer = Mathf.Clamp(this.timer + num, 0f, this.length);
                if (this.crossFadeSpeed > 0f)
                {
                    this.crossFader = Mathf.Clamp(this.crossFader + num * this.crossFadeSpeed, 0f, 1f);
                }
                else
                {
                    this.crossFader = 1f;
                }
                this.OnApply(ik, curves, weight);
            }
 protected override void OnApply(VRIK ik, AnimationCurve[] curves, float weight)
 {
     if (this.collider == null)
     {
         Debug.LogError("No collider assigned for a HitPointBone in the HitReaction component.");
         return;
     }
     if (this.rigidbody == null)
     {
         this.rigidbody = this.collider.GetComponent <Rigidbody>();
     }
     if (this.rigidbody != null)
     {
         Vector3    axis   = Vector3.Cross(base.force, base.point - this.rigidbody.worldCenterOfMass);
         float      angle  = curves[this.curveIndex].Evaluate(base.timer) * weight;
         Quaternion offset = Quaternion.AngleAxis(angle, axis);
         foreach (HitReactionVRIK.RotationOffset.RotationOffsetLink rotationOffsetLink in this.offsetLinks)
         {
             rotationOffsetLink.Apply(ik, offset, base.crossFader);
         }
     }
 }
            // Calculate offset, apply to the bones
            protected override void OnApply(VRIK ik, AnimationCurve[] curves, float weight)
            {
                if (collider == null)
                {
                    Debug.LogError("No collider assigned for a HitPointBone in the HitReaction component.");
                    return;
                }

                if (rigidbody == null)
                {
                    rigidbody = collider.GetComponent <Rigidbody>();
                }
                if (rigidbody != null)
                {
                    float      comValue = curves[curveIndex].Evaluate(timer) * weight;
                    Quaternion offset   = Quaternion.AngleAxis(comValue, comAxis);

                    foreach (RotationOffsetLink l in offsetLinks)
                    {
                        l.Apply(ik, offset, crossFader);
                    }
                }
            }
Exemple #17
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;
        }
Exemple #18
0
        /// <summary>
        /// Calibrates VRIK to the specified trackers using CalibrationData from a previous calibration. Requires this character's bone orientations to match with the character's that was used in the previous calibration.
        /// </summary>
        /// <param name="ik">Reference to the VRIK component.</param>
        /// <param name="data">Use calibration data from a previous calibration.</param>
        /// <param name="headTracker">The HMD.</param>
        /// <param name="bodyTracker">(Optional) A tracker placed anywhere on the body of the player, preferrably close to the pelvis, on the belt area.</param>
        /// <param name="leftHandTracker">(Optional) A tracker or hand controller device placed anywhere on or in the player's left hand.</param>
        /// <param name="rightHandTracker">(Optional) A tracker or hand controller device placed anywhere on or in the player's right hand.</param>
        /// <param name="leftFootTracker">(Optional) A tracker placed anywhere on the ankle or toes of the player's left leg.</param>
        /// <param name="rightFootTracker">(Optional) A tracker placed anywhere on the ankle or toes of the player's right leg.</param>
        public static void Calibrate(VRIK ik, CalibrationData data, Transform headTracker, Transform bodyTracker = null, Transform leftHandTracker = null, Transform rightHandTracker = null, Transform leftFootTracker = null, Transform rightFootTracker = null)
        {
            if (!ik.solver.initiated)
            {
                Debug.LogError("Can not calibrate before VRIK has initiated.");
                return;
            }

            if (headTracker == null)
            {
                Debug.LogError("Can not calibrate VRIK without the head tracker.");
                return;
            }

            ik.solver.FixTransforms();

            // Head
            Transform headTarget = ik.solver.spine.headTarget == null ? (new GameObject("Head Target")).transform : ik.solver.spine.headTarget;

            headTarget.parent = headTracker;
            data.head.SetTo(headTarget);
            ik.solver.spine.headTarget = headTarget;

            // Size
            ik.references.root.localScale = data.scale * Vector3.one;

            // Body
            if (bodyTracker != null)
            {
                Transform pelvisTarget = ik.solver.spine.pelvisTarget == null ? (new GameObject("Pelvis Target")).transform : ik.solver.spine.pelvisTarget;
                pelvisTarget.parent = bodyTracker;
                data.pelvis.SetTo(pelvisTarget);
                ik.solver.spine.pelvisTarget = pelvisTarget;

                ik.solver.spine.pelvisPositionWeight = data.pelvisPositionWeight;
                ik.solver.spine.pelvisRotationWeight = data.pelvisRotationWeight;

                ik.solver.plantFeet          = false;
                ik.solver.spine.maxRootAngle = 180f;
            }
            else if (leftFootTracker != null && rightFootTracker != null)
            {
                ik.solver.spine.maxRootAngle = 0f;
            }

            // Left Hand
            if (leftHandTracker != null)
            {
                Transform leftHandTarget = ik.solver.leftArm.target == null ? (new GameObject("Left Hand Target")).transform : ik.solver.leftArm.target;
                leftHandTarget.parent = leftHandTracker;
                data.leftHand.SetTo(leftHandTarget);
                ik.solver.leftArm.target         = leftHandTarget;
                ik.solver.leftArm.positionWeight = 1f;
                ik.solver.leftArm.rotationWeight = 1f;
            }
            else
            {
                ik.solver.leftArm.positionWeight = 0f;
                ik.solver.leftArm.rotationWeight = 0f;
            }

            // Right Hand
            if (rightHandTracker != null)
            {
                Transform rightHandTarget = ik.solver.rightArm.target == null ? (new GameObject("Right Hand Target")).transform : ik.solver.rightArm.target;
                rightHandTarget.parent = rightHandTracker;
                data.rightHand.SetTo(rightHandTarget);
                ik.solver.rightArm.target         = rightHandTarget;
                ik.solver.rightArm.positionWeight = 1f;
                ik.solver.rightArm.rotationWeight = 1f;
            }
            else
            {
                ik.solver.rightArm.positionWeight = 0f;
                ik.solver.rightArm.rotationWeight = 0f;
            }

            // Legs
            if (leftFootTracker != null)
            {
                CalibrateLeg(data, leftFootTracker, ik.solver.leftLeg, (ik.references.leftToes != null ? ik.references.leftToes : ik.references.leftFoot), ik.references.root.forward, true);
            }
            if (rightFootTracker != null)
            {
                CalibrateLeg(data, rightFootTracker, ik.solver.rightLeg, (ik.references.rightToes != null ? ik.references.rightToes : ik.references.rightFoot), ik.references.root.forward, false);
            }

            // Root controller
            bool addRootController = bodyTracker != null || (leftFootTracker != null && rightFootTracker != null);
            var  rootController    = ik.references.root.GetComponent <VRIKRootController>();

            if (addRootController)
            {
                if (rootController == null)
                {
                    rootController = ik.references.root.gameObject.AddComponent <VRIKRootController>();
                }
                rootController.Calibrate(data);
            }
            else
            {
                if (rootController != null)
                {
                    GameObject.Destroy(rootController);
                }
            }

            // Additional solver settings
            ik.solver.spine.minHeadHeight = 0f;
            ik.solver.locomotion.weight   = bodyTracker == null && leftFootTracker == null && rightFootTracker == null ? 1f : 0f;
        }
                // Apply a rotational offset to this effector
                public void Apply(VRIK ik, Quaternion offset, float crossFader)
                {
                    current = Quaternion.Lerp(lastValue, Quaternion.Lerp(Quaternion.identity, offset, weight), crossFader);

                    ik.solver.AddRotationOffset(rotationOffset, current);
                }
                // Apply an offset to this effector
                public void Apply(VRIK ik, Vector3 offset, float crossFader)
                {
                    current = Vector3.Lerp(lastValue, offset * weight, crossFader);

                    ik.solver.AddPositionOffset(positionOffset, current);
                }
 public void Apply(VRIK ik, Vector3 offset, float crossFader)
 {
     this.current = Vector3.Lerp(this.lastValue, offset * this.weight, crossFader);
     ik.solver.AddPositionOffset(this.positionOffset, this.current);
 }
Exemple #22
0
                }                                              // 0x00000001802466A0-0x00000001802466B0

                // Methods
                public void Apply(VRIK ik, Vector3 offset, float crossFader)
                {
                }                                                                               // 0x00000001809C3940-0x00000001809C3A90
Exemple #23
0
 /// <summary>
 /// Calibrates only the avatar scale.
 /// </summary>
 private static void CalibrateScale(VRIK ik, Settings settings)
 {
     CalibrateScale(ik, settings.scaleMlp);
 }
Exemple #24
0
        /// <summary>
        /// Calibrates VRIK to the specified trackers using the VRIKTrackerCalibrator.Settings.
        /// </summary>
        /// <param name="ik">Reference to the VRIK component.</param>
        /// <param name="settings">Calibration settings.</param>
        /// <param name="headTracker">The HMD.</param>
        /// <param name="bodyTracker">(Optional) A tracker placed anywhere on the body of the player, preferrably close to the pelvis, on the belt area.</param>
        /// <param name="leftHandTracker">(Optional) A tracker or hand controller device placed anywhere on or in the player's left hand.</param>
        /// <param name="rightHandTracker">(Optional) A tracker or hand controller device placed anywhere on or in the player's right hand.</param>
        /// <param name="leftFootTracker">(Optional) A tracker placed anywhere on the ankle or toes of the player's left leg.</param>
        /// <param name="rightFootTracker">(Optional) A tracker placed anywhere on the ankle or toes of the player's right leg.</param>
        public static CalibrationData Calibrate(VRIK ik, Settings settings, Transform headTracker, Transform bodyTracker = null, Transform leftHandTracker = null, Transform rightHandTracker = null, Transform leftFootTracker = null, Transform rightFootTracker = null)
        {
            if (!ik.solver.initiated)
            {
                Debug.LogError("Can not calibrate before VRIK has initiated.");
                return(null);
            }

            if (headTracker == null)
            {
                Debug.LogError("Can not calibrate VRIK without the head tracker.");
                return(null);
            }

            CalibrationData data = new CalibrationData();

            ik.solver.FixTransforms();

            // Root position and rotation
            Vector3 headPos = headTracker.position + headTracker.rotation * Quaternion.LookRotation(settings.headTrackerForward, settings.headTrackerUp) * settings.headOffset;

            ik.references.root.position = new Vector3(headPos.x, ik.references.root.position.y, headPos.z);
            Vector3 headForward = headTracker.rotation * settings.headTrackerForward;

            headForward.y = 0f;
            ik.references.root.rotation = Quaternion.LookRotation(headForward);

            // Head
            Transform headTarget = ik.solver.spine.headTarget == null ? (new GameObject("Head Target")).transform : ik.solver.spine.headTarget;

            headTarget.position        = headPos;
            headTarget.rotation        = ik.references.head.rotation;
            headTarget.parent          = headTracker;
            ik.solver.spine.headTarget = headTarget;

            // Size
            float sizeF = (headTarget.position.y - ik.references.root.position.y) / (ik.references.head.position.y - ik.references.root.position.y);

            ik.references.root.localScale *= sizeF * settings.scaleMlp;

            // Body
            if (bodyTracker != null)
            {
                Transform pelvisTarget = ik.solver.spine.pelvisTarget == null ? (new GameObject("Pelvis Target")).transform : ik.solver.spine.pelvisTarget;
                pelvisTarget.position        = ik.references.pelvis.position;
                pelvisTarget.rotation        = ik.references.pelvis.rotation;
                pelvisTarget.parent          = bodyTracker;
                ik.solver.spine.pelvisTarget = pelvisTarget;

                ik.solver.spine.pelvisPositionWeight = settings.pelvisPositionWeight;
                ik.solver.spine.pelvisRotationWeight = settings.pelvisRotationWeight;

                ik.solver.plantFeet          = false;
                ik.solver.spine.maxRootAngle = 180f;
            }
            else if (leftFootTracker != null && rightFootTracker != null)
            {
                ik.solver.spine.maxRootAngle = 0f;
            }

            // Left Hand
            if (leftHandTracker != null)
            {
                Transform leftHandTarget = ik.solver.leftArm.target == null ? (new GameObject("Left Hand Target")).transform : ik.solver.leftArm.target;
                leftHandTarget.position = leftHandTracker.position + leftHandTracker.rotation * Quaternion.LookRotation(settings.handTrackerForward, settings.handTrackerUp) * settings.handOffset;
                Vector3 leftHandUp = Vector3.Cross(ik.solver.leftArm.wristToPalmAxis, ik.solver.leftArm.palmToThumbAxis);
                leftHandTarget.rotation          = QuaTools.MatchRotation(leftHandTracker.rotation * Quaternion.LookRotation(settings.handTrackerForward, settings.handTrackerUp), settings.handTrackerForward, settings.handTrackerUp, ik.solver.leftArm.wristToPalmAxis, leftHandUp);
                leftHandTarget.parent            = leftHandTracker;
                ik.solver.leftArm.target         = leftHandTarget;
                ik.solver.leftArm.positionWeight = 1f;
                ik.solver.leftArm.rotationWeight = 1f;
            }
            else
            {
                ik.solver.leftArm.positionWeight = 0f;
                ik.solver.leftArm.rotationWeight = 0f;
            }

            // Right Hand
            if (rightHandTracker != null)
            {
                Transform rightHandTarget = ik.solver.rightArm.target == null ? (new GameObject("Right Hand Target")).transform : ik.solver.rightArm.target;
                rightHandTarget.position = rightHandTracker.position + rightHandTracker.rotation * Quaternion.LookRotation(settings.handTrackerForward, settings.handTrackerUp) * settings.handOffset;
                Vector3 rightHandUp = -Vector3.Cross(ik.solver.rightArm.wristToPalmAxis, ik.solver.rightArm.palmToThumbAxis);
                rightHandTarget.rotation          = QuaTools.MatchRotation(rightHandTracker.rotation * Quaternion.LookRotation(settings.handTrackerForward, settings.handTrackerUp), settings.handTrackerForward, settings.handTrackerUp, ik.solver.rightArm.wristToPalmAxis, rightHandUp);
                rightHandTarget.parent            = rightHandTracker;
                ik.solver.rightArm.target         = rightHandTarget;
                ik.solver.rightArm.positionWeight = 1f;
                ik.solver.rightArm.rotationWeight = 1f;
            }
            else
            {
                ik.solver.rightArm.positionWeight = 0f;
                ik.solver.rightArm.rotationWeight = 0f;
            }

            // Legs
            if (leftFootTracker != null)
            {
                CalibrateLeg(settings, leftFootTracker, ik.solver.leftLeg, (ik.references.leftToes != null ? ik.references.leftToes : ik.references.leftFoot), ik.references.root.forward, true);
            }
            if (rightFootTracker != null)
            {
                CalibrateLeg(settings, rightFootTracker, ik.solver.rightLeg, (ik.references.rightToes != null ? ik.references.rightToes : ik.references.rightFoot), ik.references.root.forward, false);
            }

            // Root controller
            bool addRootController = bodyTracker != null || (leftFootTracker != null && rightFootTracker != null);
            var  rootController    = ik.references.root.GetComponent <VRIKRootController>();

            if (addRootController)
            {
                if (rootController == null)
                {
                    rootController = ik.references.root.gameObject.AddComponent <VRIKRootController>();
                }
                rootController.Calibrate();
            }
            else
            {
                if (rootController != null)
                {
                    GameObject.Destroy(rootController);
                }
            }

            // Additional solver settings
            ik.solver.spine.minHeadHeight = 0f;
            ik.solver.locomotion.weight   = bodyTracker == null && leftFootTracker == null && rightFootTracker == null ? 1f : 0f;

            // Fill in Calibration Data
            data.scale                = ik.references.root.localScale.y;
            data.head                 = new CalibrationData.Target(ik.solver.spine.headTarget);
            data.pelvis               = new CalibrationData.Target(ik.solver.spine.pelvisTarget);
            data.leftHand             = new CalibrationData.Target(ik.solver.leftArm.target);
            data.rightHand            = new CalibrationData.Target(ik.solver.rightArm.target);
            data.leftFoot             = new CalibrationData.Target(ik.solver.leftLeg.target);
            data.rightFoot            = new CalibrationData.Target(ik.solver.rightLeg.target);
            data.leftLegGoal          = new CalibrationData.Target(ik.solver.leftLeg.bendGoal);
            data.rightLegGoal         = new CalibrationData.Target(ik.solver.rightLeg.bendGoal);
            data.pelvisTargetRight    = rootController.pelvisTargetRight;
            data.pelvisPositionWeight = ik.solver.spine.pelvisPositionWeight;
            data.pelvisRotationWeight = ik.solver.spine.pelvisRotationWeight;

            return(data);
        }
Exemple #25
0
        /// <summary>
        /// Calibrates only the avatar scale.
        /// </summary>
        private static void CalibrateScale(VRIK ik, float scaleMlp = 1f)
        {
            float sizeF = (ik.solver.spine.headTarget.position.y - ik.references.root.position.y) / (ik.references.head.position.y - ik.references.root.position.y);

            ik.references.root.localScale *= sizeF * scaleMlp;
        }
 protected abstract void OnApply(VRIK ik, AnimationCurve[] curves, float weight);
Exemple #27
0
            }                                                       // 0x00000001809C42D0-0x00000001809C4330

            protected override void OnApply(VRIK ik, AnimationCurve[] curves, float weight)
            {
            }                                                                                              // 0x00000001809C4450-0x00000001809C4860
Exemple #28
0
                }                                              // 0x00000001809C4250-0x00000001809C42D0

                // Methods
                public void Apply(VRIK ik, Quaternion offset, float crossFader)
                {
                }                                                                                  // 0x00000001809C4120-0x00000001809C4240
Exemple #29
0
            }                                                                                     // 0x00000001809C3000-0x00000001809C3120

            public void Apply(VRIK ik, AnimationCurve[] curves, float weight)
            {
            }                                                                                // 0x00000001809C2E80-0x00000001809C3000
Exemple #30
0
        /// <summary>
        /// Recalibrates only the avatar scale. Can be called only if the avatar has already been calibrated.
        /// </summary>
        public static void RecalibrateScale(VRIK ik, Settings settings)
        {
            float sizeF = (ik.solver.spine.headTarget.position.y - ik.references.root.position.y) / (ik.references.head.position.y - ik.references.root.position.y);

            ik.references.root.localScale *= sizeF * settings.scaleMlp;
        }