Browse Source

Fix VR Helper Fullscreen

sebavan 6 years ago
parent
commit
ae1a939892
2 changed files with 28 additions and 3 deletions
  1. 8 2
      src/Cameras/VR/vrExperienceHelper.ts
  2. 20 1
      src/Engines/engine.ts

+ 8 - 2
src/Cameras/VR/vrExperienceHelper.ts

@@ -607,6 +607,12 @@ export class VRExperienceHelper {
     }
 
     /**
+     * Defines wether or not Pointer lock should be requested when switching to
+     * full screen.
+     */
+    public requestPointerLockOnFullScreen = true;
+
+    /**
      * Instantiates a VRExperienceHelper.
      * Helps to quickly add VR support to an existing scene.
      * @param scene The scene the VRExperienceHelper belongs to.
@@ -756,7 +762,7 @@ export class VRExperienceHelper {
             if (this.isInVRMode) {
                 this.exitVR();
                 if (this._fullscreenVRpresenting) {
-                    this._scene.getEngine().switchFullscreen(true);
+                    this._scene.getEngine().exitFullscreen();
                 }
             }
         }, PointerEventTypes.POINTERDOUBLETAP, false);
@@ -970,7 +976,7 @@ export class VRExperienceHelper {
                 this._vrDeviceOrientationCamera.minZ = this._scene.activeCamera.minZ;
             }
             this._scene.activeCamera = this._vrDeviceOrientationCamera;
-            this._scene.getEngine().switchFullscreen(true);
+            this._scene.getEngine().enterFullscreen(this.requestPointerLockOnFullScreen);
             this.updateButtonVisibility();
         }
 

+ 20 - 1
src/Engines/engine.ts

@@ -1983,8 +1983,18 @@ export class Engine {
      */
     public switchFullscreen(requestPointerLock: boolean): void {
         if (this.isFullscreen) {
-            Tools.ExitFullscreen();
+            this.exitFullscreen();
         } else {
+            this.enterFullscreen(requestPointerLock);
+        }
+    }
+
+    /**
+     * Enters full screen mode
+     * @param requestPointerLock defines if a pointer lock should be requested from the user
+     */
+    public enterFullscreen(requestPointerLock: boolean): void {
+        if (!this.isFullscreen) {
             this._pointerLockRequested = requestPointerLock;
             if (this._renderingCanvas) {
                 Tools.RequestFullscreen(this._renderingCanvas);
@@ -1993,6 +2003,15 @@ export class Engine {
     }
 
     /**
+     * Exits full screen mode
+     */
+    public exitFullscreen(): void {
+        if (this.isFullscreen) {
+            Tools.ExitFullscreen();
+        }
+    }
+
+    /**
      * Clear the current render buffer or the current render target (if any is set up)
      * @param color defines the color to use
      * @param backBuffer defines if the back buffer must be cleared