Browse Source

fixing a bug with edge

Raanan Weber 5 years ago
parent
commit
ea805f379e
2 changed files with 12 additions and 4 deletions
  1. 4 4
      src/Cameras/VR/vrExperienceHelper.ts
  2. 8 0
      src/Engines/Extensions/engine.webVR.ts

+ 4 - 4
src/Cameras/VR/vrExperienceHelper.ts

@@ -776,7 +776,7 @@ export class VRExperienceHelper {
                 if (!this.isInVRMode) {
                     this.enterVR();
                 } else {
-                    this.exitVR();
+                    this._scene.getEngine().disableVR();
                 }
             });
         }
@@ -1107,9 +1107,6 @@ export class VRExperienceHelper {
             if (this._deviceOrientationCamera) {
                 this._deviceOrientationCamera.position = this._position;
                 this._scene.activeCamera = this._deviceOrientationCamera;
-                if (this._inputElement) {
-                    this._scene.activeCamera.attachControl(this._inputElement);
-                }
 
                 // Restore angular sensibility
                 if (this._cachedAngularSensibility.angularSensibilityX) {
@@ -1127,6 +1124,9 @@ export class VRExperienceHelper {
             } else if (this._existingCamera) {
                 this._existingCamera.position = this._position;
                 this._scene.activeCamera = this._existingCamera;
+                if (this._inputElement) {
+                    this._scene.activeCamera.attachControl(this._inputElement);
+                }
 
                 // Restore angular sensibility
                 if (this._cachedAngularSensibility.angularSensibilityX) {

+ 8 - 0
src/Engines/Extensions/engine.webVR.ts

@@ -269,6 +269,14 @@ Engine.prototype._connectVREvents = function(canvas?: HTMLCanvasElement, documen
     };
 
     this._onVRDisplayPointerUnrestricted = () => {
+        // Edge fix - for some reason document is not present and this is window
+        if (!document) {
+            let hostWindow = this.getHostWindow()!;
+            if (hostWindow.document && hostWindow.document.exitPointerLock) {
+                hostWindow.document.exitPointerLock();
+            }
+            return;
+        }
         if (!document.exitPointerLock) {
             return;
         }