Пример #1
0
 private void Calibrate()
 {
     var settings = new VRIKCalibrator.Settings { };
     Transform headTracker = handler.HMDObject.transform;// AddCalibrateTransform(handler.HMDObject.transform, TrackerNums.Zero);
     var controllerTransforms = (new Transform[] { handler.LeftControllerObject.transform, handler.RightControllerObject.transform }).Select((d, i) => new { index = i, pos = headTracker.InverseTransformDirection(d.transform.position - headTracker.position), transform = d.transform }).OrderBy(d => d.pos.x).Select(d => d.transform);
     leftHandTracker = controllerTransforms.ElementAtOrDefault(0);// AddCalibrateTransform(handler.LeftControllerObject.transform, TrackerNums.Zero);
     rightHandTracker = controllerTransforms.ElementAtOrDefault(1);// AddCalibrateTransform(handler.RightControllerObject.transform, TrackerNums.Zero);
     var trackerTransforms = handler.Trackers.Select((d, i) => new { index = i, pos = headTracker.InverseTransformDirection(d.transform.position - headTracker.position), transform = d.transform }).ToList();
     if (handler.Trackers.Count >= 3)
     {
         //トラッカー3つ以上あれば腰も設定
         bodyTracker = trackerTransforms.OrderByDescending(d => d.pos.y).Select(d => d.transform).First();// handler.Trackers[0].transform;// AddCalibrateTransform(handler.Trackers[0].transform, TrackerNums.Zero);
         leftFootTracker = trackerTransforms.OrderBy(d => d.pos.y).Take(2).OrderBy(d => d.pos.x).Select(d => d.transform).First();// handler.Trackers[2].transform;// AddCalibrateTransform(handler.Trackers[2].transform, TrackerNums.Zero);
         rightFootTracker = trackerTransforms.OrderBy(d => d.pos.y).Take(2).OrderByDescending(d => d.pos.x).Select(d => d.transform).First();// handler.Trackers[1].transform;// AddCalibrateTransform(handler.Trackers[1].transform, TrackerNums.Zero);
     }
     else if (handler.Trackers.Count >= 2)
     {
         //トラッカーが2つだけなら両足
         leftFootTracker = trackerTransforms.OrderBy(d => d.pos.y).Take(2).OrderBy(d => d.pos.x).Select(d => d.transform).First();// handler.Trackers[1].transform;// AddCalibrateTransform(handler.Trackers[1].transform, TrackerNums.Zero);
         rightFootTracker = trackerTransforms.OrderBy(d => d.pos.y).Take(2).OrderByDescending(d => d.pos.x).Select(d => d.transform).First();// handler.Trackers[0].transform;// AddCalibrateTransform(handler.Trackers[0].transform, TrackerNums.Zero);
     }
     else if (handler.Trackers.Count >= 1)
     {
         //トラッカーが1つだけなら腰だけ
         bodyTracker = handler.Trackers[0].transform;// AddCalibrateTransform(handler.Trackers[0].transform, TrackerNums.Zero);
     }
     //DoCalibrate(vrik, headTracker, bodyTracker, leftHandTracker, rightHandTracker, leftFootTracker, rightFootTracker);
     //DoCalibrate2(vrik, headTracker, bodyTracker, leftHandTracker, rightHandTracker, leftFootTracker, rightFootTracker);
     vrik.solver.IKPositionWeight = 1.0f;
     VRIKCalibrator.Calibrate(vrik, new VRIKCalibrator.Settings() { headOffset = new Vector3(0f, -0.15f, -0.15f), handOffset = new Vector3(0f, -0.03f, -0.07f) }, headTracker, bodyTracker, leftHandTracker, rightHandTracker, leftFootTracker, rightFootTracker);
     VRIKCalibrator.Calibrate(vrik, new VRIKCalibrator.Settings() { headOffset = new Vector3(0f, -0.15f, -0.15f), handOffset = new Vector3(0f, -0.03f, -0.07f) }, headTracker, bodyTracker, leftHandTracker, rightHandTracker, leftFootTracker, rightFootTracker);
     VRIKCalibrator.Calibrate(vrik, new VRIKCalibrator.Settings() { headOffset = new Vector3(0f, -0.15f, -0.15f), handOffset = new Vector3(0f, -0.03f, -0.07f) }, headTracker, bodyTracker, leftHandTracker, rightHandTracker, leftFootTracker, rightFootTracker);
     if (handler.Trackers.Count == 1)
     {
         vrik.solver.plantFeet = true;
         vrik.solver.locomotion.weight = 1.0f;
         var rootController = vrik.references.root.GetComponent<VRIKRootController>();
         if (rootController != null) GameObject.Destroy(rootController);
     }
     CurrentSettings.headTracker = StoreTransform.Create(headTracker);
     CurrentSettings.bodyTracker = StoreTransform.Create(bodyTracker);
     CurrentSettings.leftHandTracker = StoreTransform.Create(leftHandTracker);
     CurrentSettings.rightHandTracker = StoreTransform.Create(rightHandTracker);
     CurrentSettings.leftFootTracker = StoreTransform.Create(leftFootTracker);
     CurrentSettings.rightFootTracker = StoreTransform.Create(rightFootTracker);
 }
Пример #2
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);
                    }
                }
            }
        }
Пример #3
0
        void LateUpdate()
        {
            if (Input.GetKeyDown(KeyCode.C))
            {
                // Calibrate the character, store data of the calibration
                data = VRIKCalibrator.Calibrate(ik, settings, headTracker, bodyTracker, leftHandTracker, rightHandTracker, leftFootTracker, rightFootTracker);
            }

            /*
             * calling Calibrate with settings will return a VRIKCalibrator.CalibrationData, which can be used to calibrate that same character again exactly the same in another scene (just pass data instead of settings),
             * without being dependent on the pose of the player at calibration time.
             * Calibration data still depends on bone orientations though, so the data is valid only for the character that it was calibrated to or characters with identical bone structures.
             * If you wish to use more than one character, it would be best to calibrate them all at once and store the CalibrationData for each one.
             * */
            if (Input.GetKeyDown(KeyCode.D))
            {
                if (data.scale == 0f)
                {
                    Debug.LogError("No Calibration Data to calibrate to, please calibrate with settings first.");
                }
                else
                {
                    // Use data from a previous calibration to calibrate that same character again.
                    VRIKCalibrator.Calibrate(ik, data, headTracker, bodyTracker, leftHandTracker, rightHandTracker, leftFootTracker, rightFootTracker);
                }
            }

            // Recalibrates avatar scale only. Can be called only if the avatar has been calibrated already.
            if (Input.GetKeyDown(KeyCode.S))
            {
                if (data.scale == 0f)
                {
                    Debug.LogError("Avatar needs to be calibrated before RecalibrateScale is called.");
                }
                VRIKCalibrator.RecalibrateScale(ik, settings);
            }
        }
Пример #4
0
        private IEnumerator Initialize()
        {
            messagesUI.message = "Preparing 3D Model: Setting bvhRecorder";

            isReadyToRecordFrame = false;

            yield return(new WaitForSeconds(1.0f));

            skeleton.GenerateBoneMap(skeletonAnimator);

            yield return(new WaitForEndOfFrame());

            bvhRecorder.targetAvatar         = skeletonAnimator;
            bvhRecorder.enforceHumanoidBones = true;
            bvhRecorder.scripted             = true;

            yield return(new WaitForSeconds(1.0f));

            // Retarget bones
            bvhRecorder.bones = new List <Transform>();
            for (int i = 0; i < skeleton.BoneNumber; i++)
            {
                HumanoidBone bone = skeleton.GetBoneByIndex(i);
                if (bone != null)
                {
                    bvhRecorder.bones.Add(bone.BoneTransform);
                }
            }

            yield return(new WaitForSeconds(1.0f));

            bvhRecorder.buildSkeleton();
            bvhRecorder.genHierarchy();

            bvhRecorder.blender = false;

            yield return(new WaitForEndOfFrame());

            bvhRecorder.targetAvatar         = skeletonAnimator;
            bvhRecorder.enforceHumanoidBones = true;
            bvhRecorder.scripted             = true;

            // Retarget bones
            bvhRecorder.bones = new List <Transform>();
            for (int i = 0; i < skeleton.BoneNumber; i++)
            {
                HumanoidBone bone = skeleton.GetBoneByIndex(i);
                if (bone != null)
                {
                    bvhRecorder.bones.Add(bone.BoneTransform);
                }
            }

            messagesUI.message = "Preparing 3D Model: Mapping bones";

            // Always record full body
            bvhRecorder.InitializeBonesToRecord(skeleton.fullBodyBones);
            bvhRecorder.buildSkeleton();
            bvhRecorder.genHierarchy();

            framesCaptured = 0;



            messagesUI.message = "Preparing 3D Model: Calibrating Final IK with 3D Model";

            finalIk.enabled = true;

            yield return(new WaitForEndOfFrame());

            settingsCalibrationData = new VRIKCalibrator.Settings();

            VRIKCalibrator.Calibrate(finalIk, settingsCalibrationData,
                                     headTracker,
                                     hipTracker,
                                     leftHandTracker,
                                     rightHandTracker,
                                     leftFootTracker,
                                     rigthFootTracker);

            yield return(new WaitForEndOfFrame());

            isReadyToRecordFrame = true;
            messagesUI.message   = "3D Model ready!";
        }
Пример #5
0
 void Calibrate()
 {
     VRIKCalibrator.Calibrate(ik, settings, headTracker, bodyTracker, leftHandTracker, rightHandTracker, leftFootTracker, rightFootTracker);
 }
Пример #6
0
 public void BodyCalibrate(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource)
 {
     // Calibrate the character, store data of the calibration
     data = VRIKCalibrator.Calibrate(ik, settings, headTracker, bodyTracker, leftHandTracker, rightHandTracker, leftFootTracker, rightFootTracker);
 }