コード例 #1
0
        /// <summary>
        /// Gets the offset between the head target and the actual head bone. Avoids issues when using
        /// the Head transform for calculations.
        /// </summary>
        private Vector3 GetHeadTargetOffset()
        {
            Transform headReference = null;
            Transform headTarget    = null;

            #pragma warning disable 618
            VRIK              vrik              = gameObject.GetComponentInChildren <VRIK>();
            IKManager         ikManager         = gameObject.GetComponentInChildren <IKManager>();
            IKManagerAdvanced ikManagerAdvanced = gameObject.GetComponentInChildren <IKManagerAdvanced>();
            #pragma warning restore 618

            VRIKManager vrikManager = gameObject.GetComponentInChildren <VRIKManager>();

            if (vrikManager)
            {
                if (!vrikManager.references_head)
                {
                    vrikManager.AutoDetectReferences();
                }

                headReference = vrikManager.references_head;
                headTarget    = vrikManager.solver_spine_headTarget;
            }
            else if (vrik)
            {
                vrik.AutoDetectReferences();
                headReference = vrik.references.head;

                if (ikManagerAdvanced)
                {
                    headTarget = ikManagerAdvanced.HeadTarget;
                }
                else if (ikManager)
                {
                    headTarget = ikManager.HeadTarget;
                }
            }

            if (!headReference)
            {
                Plugin.logger.Warn("Could not find head reference; height adjust may be broken");
                return(Vector3.zero);
            }

            if (!headTarget)
            {
                Plugin.logger.Warn("Could not find head target; height adjust may be broken");
                return(Vector3.zero);
            }

            return(headTarget.position - headReference.position);
        }
コード例 #2
0
    void SetupVRIK(VRIK vrik)
    {
        vrik.AutoDetectReferences();

        vrik.solver.leftLeg.positionWeight  = 0.99f;
        vrik.solver.leftLeg.rotationWeight  = 0.99f;
        vrik.solver.rightLeg.positionWeight = 0.99f;
        vrik.solver.rightLeg.rotationWeight = 0.99f;

        vrik.solver.leftLeg.swivelOffset  = -35;
        vrik.solver.rightLeg.swivelOffset = 35;

        vrik.solver.leftArm.swivelOffset  = 23;
        vrik.solver.rightArm.swivelOffset = -23;

        vrik.solver.spine.pelvisPositionWeight = 0.99f;
        vrik.solver.spine.pelvisRotationWeight = 0.99f;

        vrik.solver.locomotion.weight = 0;
    }
コード例 #3
0
        void SetupTarget()
        {
            if (m_target != null)
            {
                m_target.Source     = m_source;
                m_target.SourceType = UniHumanoid.HumanPoseTransfer.HumanPoseTransferSourceType.HumanPoseTransfer;

                m_blendShape = m_target.GetComponent <VRMBlendShapeProxy>();

                m_firstPerson = m_target.GetComponent <VRMFirstPerson>();

                var animator = m_target.GetComponent <Animator>();
                if (animator != null)
                {
                    animator.runtimeAnimatorController = m_animationController;
                    VRIK m_vrik = m_target.gameObject.AddComponent <VRIK>();
                    m_vrik.AutoDetectReferences();
                    m_vrik.solver.spine.headTarget      = m_headTarget;
                    m_vrik.solver.leftArm.target        = m_leftHandTarget;
                    m_vrik.solver.rightArm.target       = m_rightHandTarget;
                    m_vrik.solver.leftArm.stretchCurve  = new AnimationCurve();
                    m_vrik.solver.rightArm.stretchCurve = new AnimationCurve();
                    IKSolverVR.Locomotion m_vrikLoco = m_vrik.solver.locomotion;
                    m_vrikLoco.footDistance  = 0.1f;
                    m_vrikLoco.stepThreshold = 0.2f;

                    VRIKCalibrator.Calibrate(m_vrik, null, m_headTarget, null, m_leftHandTarget, m_rightHandTarget, null, null);

                    m_firstPerson.Setup();

                    _handPoseController.SetAnimaor(animator);
                    if (m_faceCamera != null)
                    {
                        m_faceCamera.Target = animator.GetBoneTransform(HumanBodyBones.Head);
                    }
                }
            }
        }
コード例 #4
0
    protected virtual void _SetupVRIK()
    {
        vrIK.AutoDetectReferences();
        vrIK.solver.plantFeet = false;

        vrIK.solver.spine.headTarget     = targetHead.transform;
        vrIK.solver.spine.positionWeight = 1.0F;
        vrIK.solver.spine.rotationWeight = 1.0F;

        //vrIK.solver.leftArm.positionWeight = 0.0F;
        //vrIK.solver.leftArm.rotationWeight = 0.0F;
        //vrIK.solver.rightArm.positionWeight = 0.0F;
        //vrIK.solver.rightArm.rotationWeight = 0.0F;

        vrIK.solver.leftArm.target         = targetLeftArm.transform;
        vrIK.solver.leftArm.stretchCurve   = new AnimationCurve();
        vrIK.solver.leftArm.positionWeight = 1.0F;
        vrIK.solver.leftArm.rotationWeight = 1.0F;

        vrIK.solver.rightArm.target         = targetRightArm.transform;
        vrIK.solver.rightArm.stretchCurve   = new AnimationCurve();
        vrIK.solver.rightArm.positionWeight = 1.0F;
        vrIK.solver.rightArm.rotationWeight = 1.0F;


        vrIK.solver.leftLeg.target         = targetLeftLeg.transform;
        vrIK.solver.leftLeg.stretchCurve   = new AnimationCurve();
        vrIK.solver.leftLeg.positionWeight = 1.0F;
        vrIK.solver.leftLeg.rotationWeight = 0.0F;

        vrIK.solver.rightLeg.target         = targetRightLeg.transform;
        vrIK.solver.rightLeg.stretchCurve   = new AnimationCurve();
        vrIK.solver.rightLeg.positionWeight = 1.0F;
        vrIK.solver.rightLeg.rotationWeight = 0.0F;

        vrIK.solver.locomotion.weight = 1.0F;
    }
コード例 #5
0
    private void AvatarSetup()
    {
        //Animator animator = _avatar.AddComponent<Animator>();
        //animator.runtimeAnimatorController = _controller;

        _vrik = _avatar.AddComponent <VRIK>();
        Debug.Log("AddComponent<VRIK>");

        _vrik.AutoDetectReferences();

        _vrik.GuessHandOrientations();
        Debug.Log("solver.leftArm.wristToPalmAxis= " + _vrik.solver.leftArm.wristToPalmAxis);
        Debug.Log("solver.leftArm.palmToThumbAxix= " + _vrik.solver.leftArm.palmToThumbAxis);
        Debug.Log("solver.rightArm.wristToPalmAxis= " + _vrik.solver.rightArm.wristToPalmAxis);
        Debug.Log("solver.rightArm.palmToThumbAxix= " + _vrik.solver.rightArm.palmToThumbAxis);

        _leftHandIKTarget.transform.localPosition  = Vector3.zero;
        _rightHandIKTarget.transform.localPosition = Vector3.zero;

        Quaternion leftWristRot = Quaternion.FromToRotation(_vrik.solver.leftArm.wristToPalmAxis, Vector3.forward);

        _leftHandIKTarget.transform.localRotation = leftWristRot * Quaternion.identity;

        float leftPalmRotAngle = Vector3.Angle(leftWristRot * _vrik.solver.leftArm.palmToThumbAxis, Vector3.right);

        Debug.Log("leftPalmRotAngle = " + leftPalmRotAngle);
        Quaternion leftPalmRot = Quaternion.AngleAxis(leftPalmRotAngle, Vector3.forward);

        _leftHandIKTarget.transform.localRotation = leftPalmRot * _leftHandIKTarget.transform.localRotation;

        Vector3 leftThumbDirRotated = leftPalmRot * (leftWristRot * _vrik.solver.leftArm.palmToThumbAxis);

        if (Vector3.Dot(leftThumbDirRotated, Vector3.right) < 0)
        {
            _leftHandIKTarget.transform.localRotation = Quaternion.AngleAxis(180, Vector3.forward) * _leftHandIKTarget.transform.localRotation;
            Debug.Log("leftThumb re-rotated");
        }

        _leftHandIKTarget.transform.localPosition -= _handOffset * Vector3.forward;


        Quaternion rightWristRot = Quaternion.FromToRotation(_vrik.solver.rightArm.wristToPalmAxis, Vector3.forward);

        _rightHandIKTarget.transform.localRotation = rightWristRot * Quaternion.identity;

        float rightPalmAngle = Vector3.Angle(rightWristRot * _vrik.solver.rightArm.palmToThumbAxis, Vector3.left);

        Debug.Log("rightPalmRotAngle = " + rightPalmAngle);
        Quaternion rightPalmRot = Quaternion.AngleAxis(rightPalmAngle, Vector3.forward);

        _rightHandIKTarget.transform.localRotation = rightPalmRot * _rightHandIKTarget.transform.localRotation;

        Vector3 rightThumbDirRoted = rightPalmRot * (rightWristRot * _vrik.solver.rightArm.palmToThumbAxis);

        if (Vector3.Dot(rightThumbDirRoted, Vector3.left) < 0)
        {
            _rightHandIKTarget.transform.localRotation = Quaternion.AngleAxis(180, Vector3.forward) * _rightHandIKTarget.transform.localRotation;
            Debug.Log("rightThumb re-rotated");
        }

        _rightHandIKTarget.transform.localPosition -= _handOffset * Vector3.forward;



        _vrik.solver.leftArm.stretchCurve  = new AnimationCurve();
        _vrik.solver.rightArm.stretchCurve = new AnimationCurve();

        _vrik.solver.spine.headTarget = HeadTransform;

        _vrik.solver.spine.pelvisTarget = _targetPelvis.transform;

        _vrik.solver.leftLeg.target    = _targetLeftLeg.transform;
        _vrik.solver.leftLeg.bendGoal  = _targetLeftLeg_BendGoal.transform;
        _vrik.solver.rightLeg.target   = _targetRightLeg.transform;
        _vrik.solver.rightLeg.bendGoal = _targetRightLeg_BendGoal.transform;

        SittingMode();
        HandsfreeMode();

        _playerControl.Calibration(_playerControl.HeadCamera, _playerControl.CameraResetPos);

        StartCoroutine("Blink");
    }