Ejemplo n.º 1
0
    public static bool GetBounds(Size size, ref HmdQuad_t pRect)
    {
        if (size == Size.Calibrated)
        {
            var initOpenVR = (!SteamVR.active && !SteamVR.usingNativeSupport);
            if (initOpenVR)
            {
                var error = EVRInitError.None;
                OpenVR.Init(ref error, EVRApplicationType.VRApplication_Utility);
            }

            var chaperone = OpenVR.Chaperone;
            Debug.Log(chaperone);
            bool success = (chaperone != null) && chaperone.GetPlayAreaRect(ref pRect);
            if (!success)
            {
                Debug.LogWarning("Failed to get Calibrated Play Area bounds!  Make sure you have tracking first, and that your space is calibrated.");
            }

            if (initOpenVR)
            {
                OpenVR.Shutdown();
            }

            return(success);
        }
        else
        {
            try
            {
                var str = size.ToString().Substring(1);
                var arr = str.Split(new char[] { 'x' }, 2);

                // convert to half size in meters (from cm)
                var x = float.Parse(arr[0]) / 200;
                var z = float.Parse(arr[1]) / 200;

                pRect.vCorners0.v0 = x;
                pRect.vCorners0.v1 = 0;
                pRect.vCorners0.v2 = -z;

                pRect.vCorners1.v0 = -x;
                pRect.vCorners1.v1 = 0;
                pRect.vCorners1.v2 = -z;

                pRect.vCorners2.v0 = -x;
                pRect.vCorners2.v1 = 0;
                pRect.vCorners2.v2 = z;

                pRect.vCorners3.v0 = x;
                pRect.vCorners3.v1 = 0;
                pRect.vCorners3.v2 = z;

                return(true);
            }
            catch {}
        }

        return(false);
    }
Ejemplo n.º 2
0
    public void ShutdownOpenVR()
    {
        OpenVR.Shutdown();
        openVRInit = false;

        Debug.Log("OpenVR - Shutdown!");
    }
        public static void UpdateTrackerIDList()
        {
            EVRInitError initError = EVRInitError.None;

            OpenVR.Init(ref initError, EVRApplicationType.VRApplication_Overlay);
            List <string> hardwareIDList = new List <string>();

            for (uint n = 0; n < Constants.MAX_OPENVR_OBJECTS; n++)
            {
                ETrackedDeviceClass deviceClass = OpenVR.System.GetTrackedDeviceClass(n);

                if (deviceClass == ETrackedDeviceClass.GenericTracker)
                {
                    hardwareIDList.Add(TrackedObjectID.GetHardwareIDFromIndex((int)n));
                }
            }

            // EditorPrefs cannot store lists but can store anything as a string, so convert the list to JSON and save that instead
            string trackerListJson = JsonUtility.ToJson(new TrackerList(hardwareIDList));

            EditorPrefs.SetString(TrackerListPrefLocation, trackerListJson);

            // Properly close reference to SteamVR so it can be access safely again later
            OpenVR.Shutdown();
        }
Ejemplo n.º 4
0
        private static void Worker()
        {
            var shouldRun = true;

            Thread.CurrentThread.IsBackground = true;
            while (shouldRun)
            {
                if (!_isConnected)
                {
                    Thread.Sleep(1000);
                    _isConnected = InitVR();
                }
                else if (_isReady)
                {
                    RunScripts(PATH_STARTFOLDER);
                    if (WeHaveScripts(PATH_STOPFOLDER))
                    {
                        WaitForQuit();
                    }
                    OpenVR.Shutdown();
                    RunScripts(PATH_STOPFOLDER);
                    shouldRun = false;
                }
                if (!shouldRun)
                {
                    LogUtils.WriteLineToCache("Application exiting, writing log");
                    LogUtils.WriteCacheToLogFile(PATH_LOGFILE, 100);
                    Environment.Exit(0);
                }
            }
        }
Ejemplo n.º 5
0
 private void Shutdown()
 {
     Console.WriteLine("SteamVR connection lost.");
     _vr_system.AcknowledgeQuit_Exiting();
     OpenVR.Shutdown();
     isConnected = false;
 }
Ejemplo n.º 6
0
    /// \brief Requests the chaperone boundaries of the SteamVR play area.  This doesn't work if you haven't performed
    ///        Room Setup.
    /// \param p0, p1, p2, p3 Points that make up the chaperone boundaries.
    ///
    /// \returns If the play area retrieval was successful
    public static bool GetChaperoneBounds(out Vector3 p0, out Vector3 p1, out Vector3 p2, out Vector3 p3)
    {
        var initOpenVR = (!SteamVR.active && !SteamVR.usingNativeSupport);

        if (initOpenVR)
        {
            var error = EVRInitError.None;
            OpenVR.Init(ref error, EVRApplicationType.VRApplication_Other);
        }

        var       chaperone = OpenVR.Chaperone;
        HmdQuad_t rect      = new HmdQuad_t();
        bool      success   = (chaperone != null) && chaperone.GetPlayAreaRect(ref rect);

        p0 = new Vector3(rect.vCorners0.v0, rect.vCorners0.v1, rect.vCorners0.v2);
        p1 = new Vector3(rect.vCorners1.v0, rect.vCorners1.v1, rect.vCorners1.v2);
        p2 = new Vector3(rect.vCorners2.v0, rect.vCorners2.v1, rect.vCorners2.v2);
        p3 = new Vector3(rect.vCorners3.v0, rect.vCorners3.v1, rect.vCorners3.v2);
        if (!success)
        {
            Debug.LogWarning("Failed to get Calibrated Play Area bounds!  Make sure you have tracking first, and that your space is calibrated.");
        }

        if (initOpenVR)
        {
            OpenVR.Shutdown();
        }

        return(success);
    }
 protected override void OnClosed(EventArgs e)
 {
     base.OnClosed(e);
     VRThread.Abort();
     OpenVR.Shutdown();
     Application.Current.Shutdown();
 }
Ejemplo n.º 8
0
    private static void ShutdownSystems()
    {
#if (UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0 || UNITY_4_5)
        Console.WriteLine("SHUTDOWN");
        OpenVR.Shutdown();
#endif
    }
Ejemplo n.º 9
0
 /// <summary>
 /// Overrides the OnDestroy method, called when plugin is destroyed (leaving Flight scene).
 /// </summary>
 void OnDestroy()
 {
     log("KerbalVrPlugin OnDestroy");
     vrSystem.ReleaseInputFocus();
     OpenVR.Shutdown();
     hmdIsInitialized = false;
 }
Ejemplo n.º 10
0
    public static object CallSystemFn(SystemFn fn, params object[] args)
    {
        object result = null;

        if (SteamVR.active)
        {
            result = fn(SteamVR.instance.hmd, args);
        }
        else
        {
            var error   = HmdError.None;
            var pSystem = OpenVR.Init(ref error);
            if (pSystem != System.IntPtr.Zero && error == HmdError.None)
            {
                // Make sure we're using the proper version
                pSystem = OpenVR.GetGenericInterface(OpenVR.IVRSystem_Version, ref error);
                if (pSystem != System.IntPtr.Zero && error == HmdError.None)
                {
                    var system = new CVRSystem(pSystem);
                    result = fn(system, args);
                }
                OpenVR.Shutdown();
            }
        }
        return(result);
    }
Ejemplo n.º 11
0
        public static void Main()
        {
            Console.WriteLine("Is Runtime Installed: {0}", OpenVR.IsRuntimeInstalled());
            var isHmdPresent = OpenVR.IsHmdPresent();

            Console.WriteLine("Is HMD Present: {0}", isHmdPresent);
            if (isHmdPresent)
            {
                try
                {
                    var err = EVRInitError.None;
                    var sys = OpenVR.Init(ref err, EVRApplicationType.VRApplication_Scene);
                    if (err != EVRInitError.None)
                    {
                        Console.WriteLine("Err {0}", err);
                    }
                    else
                    {
                        Console.WriteLine("Runtime version: {0}", sys.GetRuntimeVersion());
                        Console.WriteLine("Is display on desktop: {0}", sys.IsDisplayOnDesktop());
                        Console.WriteLine("Is input available: {0}", sys.IsInputAvailable());
                        Console.WriteLine("Is SteamVR drawing controllers: {0}", sys.IsSteamVRDrawingControllers());
                        Console.WriteLine("Should application pause: {0}", sys.ShouldApplicationPause());
                        Console.WriteLine("Should application reduce rendering work: {0}", sys.ShouldApplicationReduceRenderingWork());
                        sys.GetRecommendedRenderTargetSize(out var width, out var height);
                        Console.WriteLine("Recommended render target size: {0}x{1}", width, height);
                        Console.WriteLine("Button Name: {0}", sys.GetButtonIdNameFromEnum(EVRButtonId.k_EButton_A));
                    }
                }
                finally
                {
                    OpenVR.Shutdown();
                }
            }
        }
Ejemplo n.º 12
0
 public void Dispose()
 {
     if (needsShutdown)
     {
         OpenVR.Shutdown();
     }
 }
Ejemplo n.º 13
0
 void OnDestroy()
 {
     if (startedSteamVR)
     {
         OpenVR.Shutdown();
     }
 }
Ejemplo n.º 14
0
 public static void Shutdown()
 {
     if (Started)
     {
         OpenVR.Shutdown();
     }
 }
Ejemplo n.º 15
0
        public override Vector3 GetPlayspaceBounds()
        {
            bool initOpenVR = (!SteamVR.active && !SteamVR.usingNativeSupport);

            if (initOpenVR)
            {
                EVRInitError error = EVRInitError.None;
                OpenVR.Init(ref error, EVRApplicationType.VRApplication_Other);
            }

            CVRChaperone chaperone = OpenVR.Chaperone;

            if (chaperone != null)
            {
                chaperone.GetPlayAreaSize(ref PlayspaceBounds.x, ref PlayspaceBounds.z);
                PlayspaceBounds.y = 1;
            }

            if (initOpenVR)
            {
                OpenVR.Shutdown();
            }

            return(PlayspaceBounds);
        }
Ejemplo n.º 16
0
        void EndCurrentSession()
        {
            try
            {
                if (VRSys != null)
                {
                    // Note that there seems to be a memory leak in openvr_api.
                    // Calling shutdown apparently does not release all resources...
                    // ... that were loaded with OpenVR.Init()
                    OpenVR.Shutdown();
                }
            }
            catch (Exception e)
            {
                LastExceptionMessage = e.Message;
                if (!StopFlag)
                {
                    OpenVRConnStatus = OpenVRConnectionStatus.UnexpectedError;
                }
            }

            if (!StopFlag)
            {
                OpenVRConnStatus = OpenVRConnectionStatus.Initializing;
            }

            VRSys = null;
        }
Ejemplo n.º 17
0
        static void Main()
        {
#if DEBUG
            AllocConsole();
#endif

            var e = EVRInitError.None;
            OpenVR.Init(ref e, EVRApplicationType.VRApplication_Overlay);

            ulong handle = 0;
            var   error  = OpenVR.Overlay.CreateOverlay("pushbullet", "Pushbullet", ref handle);
            Console.WriteLine($"CreateOverlay Result: {error.ToString()}");

            var conf   = Common.Config.Read();
            var stream = new PushbulletStream(conf.PushbulletToken);

            stream.MessageReceived += (sender, push) =>
            {
                OpenVR.Overlay.SetOverlayName(handle, $"Pushbullet - {push.ApplicationName}");

                uint id = 0;

                var notifIcon = new NotificationBitmap_t();

                var bmp = push.IconAsBitmap();
                Utils.FixBitmapForOpenVR(ref bmp);
                var bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                notifIcon.m_pImageData     = bmpData.Scan0;
                notifIcon.m_nWidth         = bmpData.Width;
                notifIcon.m_nHeight        = bmpData.Height;
                notifIcon.m_nBytesPerPixel = 4;

                var notifError = OpenVR.Notifications.CreateNotification(handle, 0, EVRNotificationType.Transient, $"{push.Title.Replace("\n", " / ")}\n{push.Body.Replace("\n", " / ")}", EVRNotificationStyle.Application, ref notifIcon, ref id);
                Console.WriteLine($"CreateNotification Result: {notifError.ToString()}");
                Console.WriteLine($"Received mirror push: [{push.ApplicationName}] {push.Title}: {push.Body}");

                bmp.UnlockBits(bmpData);
            };

            stream.Start();

            var res = new ManualResetEvent(false);

            VREvent_t ev   = new VREvent_t();
            var       size = (uint)Marshal.SizeOf(typeof(VREvent_t));
            while (OpenVR.Overlay.PollNextOverlayEvent(handle, ref ev, size))
            {
                if (ev.eventType == (uint)EVREventType.VREvent_Quit)
                {
                    Console.WriteLine("SteamVR is quitting, shutting down...");
                    OpenVR.Shutdown();
                    res.Set();
                    Environment.Exit(0);
                }
            }

            res.WaitOne();
        }
Ejemplo n.º 18
0
 public static void ExitTemporarySession()
 {
     if (runningTemporarySession)
     {
         OpenVR.Shutdown();
         runningTemporarySession = false;
     }
 }
Ejemplo n.º 19
0
 private void MonitorForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (ulMainHandle != 0)
     {
         OpenVR.Overlay.DestroyOverlay(ulMainHandle);
     }
     OpenVR.Shutdown();
 }
Ejemplo n.º 20
0
        private void OnApplicationQuit()
        {
            DPSettings.SaveSettingsJson();

            OpenVR.Shutdown();

            //SteamApps.
        }
    public void DisposeSteamVRConnection()
    {
        SteamVR_ActionSet_Manager.ChangeSetPriorities(false);
        SteamVR_Input.GetActionSet("/actions/main").Deactivate();

        OpenVR.Shutdown();

        SteamVRManager.isConnected = false;
    }
 void Shutdown()
 {
     if (vr_pointer != null)
     {
         OpenVR.Shutdown();
         log.Info("Controller Tracking wurde beendet!");
         vr_pointer = null;
     }
 }
Ejemplo n.º 23
0
        private void TrackingLoop()
        {
            try
            {
                EVRInitError initError = EVRInitError.None;
                CVRSystem    cvrSystem = OpenVR.Init(ref initError, EVRApplicationType.VRApplication_Utility);
                var          chaperone = OpenVR.Chaperone;
                var          quadArea  = new HmdQuad_t();
                chaperone.GetPlayAreaRect(ref quadArea);
                _playArea = quadArea.ToPlayArea();
                if (initError != EVRInitError.None)
                {
                    throw new InvalidOperationException($"EVR init erro: {initError}");
                }
                while (_keepReading)
                {
                    TrackedDevicePose_t[] trackedDevicePoses = new TrackedDevicePose_t[OpenVR.k_unMaxTrackedDeviceCount];
                    cvrSystem.GetDeviceToAbsoluteTrackingPose(ETrackingUniverseOrigin.TrackingUniverseStanding, 0f, trackedDevicePoses);
                    for (uint trackedDeviceIndex = 0; trackedDeviceIndex < OpenVR.k_unMaxTrackedDeviceCount; trackedDeviceIndex++)
                    {
                        if (cvrSystem.IsTrackedDeviceConnected(trackedDeviceIndex))
                        {
                            ETrackedDeviceClass deviceClass = cvrSystem.GetTrackedDeviceClass(trackedDeviceIndex);
                            if (true)
                            {
                                VRControllerState_t controllerState = new VRControllerState_t();
                                cvrSystem.GetControllerState(1, ref controllerState, (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(VRControllerState_t)));
                                ETrackingResult trackingResult = trackedDevicePoses[trackedDeviceIndex].eTrackingResult;

                                bool trigger    = controllerState.rAxis1.x > 0.9f;
                                bool menuButton = (controllerState.ulButtonPressed & (1ul << (int)EVRButtonId.k_EButton_ApplicationMenu)) != 0;
                                bool gripButton = (controllerState.ulButtonPressed & (1ul << (int)EVRButtonId.k_EButton_Grip)) != 0;

                                if (trackingResult == ETrackingResult.Running_OK)
                                {
                                    HmdMatrix34_t trackingMatrix = trackedDevicePoses[trackedDeviceIndex].mDeviceToAbsoluteTracking;

                                    Vector3            speedVector    = trackedDevicePoses[trackedDeviceIndex].vVelocity.ToVelocityVector();
                                    Vector3            position       = trackingMatrix.ToPositionVector();
                                    DeviceTrackingData trackingUpdate = new DeviceTrackingData((int)trackedDeviceIndex, deviceClass.ToString(), position, trackingMatrix.ToRotationQuaternion());
                                    NewPoseUpdate?.Invoke(this, trackingUpdate);
                                }
                            }
                        }
                    }
                    Thread.Sleep(UpdatedInterval);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error: {e}");
            }
            finally
            {
                OpenVR.Shutdown();
            }
        }
Ejemplo n.º 24
0
 /// <summary>
 /// Shutsdown <see cref="OpenVR"/>
 /// </summary>
 public void Dispose()
 {
     Scripting.Update -= Update;
     if (IsConnected)
     {
         Debug.Log("[VR] System disposing");
         OpenVR.Shutdown();
     }
 }
Ejemplo n.º 25
0
 public void Dispose()
 {
     if (_instance != null)
     {
         if (!SteamVR.active)
         {
             OpenVR.Shutdown();
         }
     }
 }
 void OnApplicationQuit()
 {
     //アプリケーション終了時にOverlayハンドルを破棄する
     if (overlay != null)
     {
         overlay.DestroyOverlay(overlayHandle);
     }
     //VRシステムをシャットダウンする
     OpenVR.Shutdown();
 }
Ejemplo n.º 27
0
 public override void Dispose()
 {
     #if !UNITY_EDITOR
     if (system != null)
     {
         OpenVR.Shutdown();
         system = null;
     }
     #endif
     base.Dispose();
 }
        /// <summary>
        /// Allows for the Editor to assign the index of a SteamVR Tracked Object at Editor time.
        /// </summary>
        public void AssignIndex()
        {
            EVRInitError initError = EVRInitError.None;

            OpenVR.Init(ref initError, EVRApplicationType.VRApplication_Overlay);

            (serializedObject.targetObject as TrackedObjectID).AssignIndex();

            // Properly close reference to SteamVR so it can be access safely again later
            OpenVR.Shutdown();
        }
Ejemplo n.º 29
0
 void OnDestroy()
 {
     FindObjectOfType <InputEmulator>()?.DisableAllDeviceWorldPosOffset();
     if (XRSettings.loadedDeviceName != "None")
     {
         XRSettings.LoadDeviceByName("None");
     }
     SteamVR.SafeDispose();
     XRSettings.enabled = false;
     OpenVR.Shutdown();
 }
Ejemplo n.º 30
0
    static string[] LoadRenderModelNames()
    {
        var results = new List <string>();

        results.Add("None");

        var error = HmdError.None;

        if (!SteamVR.active)
        {
            OpenVR.Init(ref error);
            if (error != HmdError.None)
            {
                return(results.ToArray());
            }
        }

        var pRenderModels = OpenVR.GetGenericInterface(OpenVR.IVRRenderModels_Version, ref error);

        if (pRenderModels == System.IntPtr.Zero || error != HmdError.None)
        {
            if (!SteamVR.active)
            {
                OpenVR.Shutdown();
            }
            return(results.ToArray());
        }

        var renderModels = new CVRRenderModels(pRenderModels);

        uint count = renderModels.GetRenderModelCount();

        for (uint i = 0; i < count; i++)
        {
            var buffer       = new StringBuilder();
            var requiredSize = renderModels.GetRenderModelName(i, buffer, 0);
            if (requiredSize == 0)
            {
                continue;
            }

            buffer.EnsureCapacity((int)requiredSize);
            renderModels.GetRenderModelName(i, buffer, requiredSize);
            results.Add(buffer.ToString());
        }

        if (!SteamVR.active)
        {
            OpenVR.Shutdown();
        }

        return(results.ToArray());
    }