Exemple #1
0
        /// <summary>
        /// Returns an array of positions/rotations that represent the state of each bone in a reference pose.
        /// </summary>
        /// <param name="referencePose">Which reference pose to return</param>
        public void ForceToReferencePose(EVRSkeletalReferencePose referencePose)
        {
            bool temporarySession = false;

            if (Application.isEditor && Application.isPlaying == false)
            {
                temporarySession = SteamVR.InitializeTemporarySession(true);
                Awake();
                //skeletonAction.Initialize(true);
                //skeletonAction.actionSet.Initialize(true);

#if UNITY_EDITOR
                //gotta wait a bit for steamvr input to startup //todo: implement steamvr_input.isready
                string title     = "SteamVR";
                string text      = "Getting reference pose...";
                float  msToWait  = 3000;
                float  increment = 100;
                for (float timer = 0; timer < msToWait; timer += increment)
                {
                    bool cancel = UnityEditor.EditorUtility.DisplayCancelableProgressBar(title, text, timer / msToWait);
                    if (cancel)
                    {
                        UnityEditor.EditorUtility.ClearProgressBar();

                        if (temporarySession)
                        {
                            SteamVR.ExitTemporarySession();
                        }
                        return;
                    }
                    System.Threading.Thread.Sleep((int)increment);
                }
                UnityEditor.EditorUtility.ClearProgressBar();
#endif

                skeletonAction.actionSet.Activate();

                SteamVR_ActionSet_Manager.UpdateActionStates(true);

                skeletonAction.UpdateValueWithoutEvents();
            }

            SteamVR_Utils.RigidTransform[] transforms = skeletonAction.GetReferenceTransforms(EVRSkeletalTransformSpace.Parent, referencePose);

            if (transforms == null || transforms.Length == 0)
            {
                Debug.LogError("<b>[SteamVR Input</b> Unable to get the reference transform for " + inputSource.ToString() + ". Please make sure SteamVR is open and both controllers are connected.");
            }

            for (int boneIndex = 0; boneIndex < transforms.Length; boneIndex++)
            {
                bones[boneIndex].localPosition = transforms[boneIndex].pos;
                bones[boneIndex].localRotation = transforms[boneIndex].rot;
            }

            if (temporarySession)
            {
                SteamVR.ExitTemporarySession();
            }
        }
Exemple #2
0
        /// <summary>
        /// Returns an array of positions/rotations that represent the state of each bone in a reference pose.
        /// </summary>
        /// <param name="referencePose">Which reference pose to return</param>
        public void ForceToReferencePose(EVRSkeletalReferencePose referencePose)
        {
            bool temporarySession = false;

            if (Application.isEditor && Application.isPlaying == false)
            {
                temporarySession = SteamVR.InitializeTemporarySession(true);
                Awake();

                skeletonAction.actionSet.Activate();

                SteamVR_ActionSet_Manager.UpdateActionStates(true);

                skeletonAction.UpdateValueWithoutEvents();
            }

            if (skeletonAction.active == false)
            {
                Debug.LogError("<b>[SteamVR_Standalone Input]</b> Please turn on your " + inputSource.ToString() + " controller and ensure SteamVR_Standalone is open.", this);
                return;
            }

            SteamVR_Utils.RigidTransform[] transforms = skeletonAction.GetReferenceTransforms(EVRSkeletalTransformSpace.Parent, referencePose);

            if (transforms == null || transforms.Length == 0)
            {
                Debug.LogError("<b>[SteamVR_Standalone Input]</b> Unable to get the reference transform for " + inputSource.ToString() + ". Please make sure SteamVR_Standalone is open and both controllers are connected.", this);
            }

            if (mirroring == MirrorType.LeftToRight || mirroring == MirrorType.RightToLeft)
            {
                for (int boneIndex = 0; boneIndex < transforms.Length; boneIndex++)
                {
                    bones[boneIndex].localPosition = MirrorPosition(boneIndex, transforms[boneIndex].pos);
                    bones[boneIndex].localRotation = MirrorRotation(boneIndex, transforms[boneIndex].rot);
                }
            }
            else
            {
                for (int boneIndex = 0; boneIndex < transforms.Length; boneIndex++)
                {
                    bones[boneIndex].localPosition = transforms[boneIndex].pos;
                    bones[boneIndex].localRotation = transforms[boneIndex].rot;
                }
            }

            if (temporarySession)
            {
                SteamVR.ExitTemporarySession();
            }
        }