浏览代码

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js

David Catuhe 6 年之前
父节点
当前提交
479ad2747e
共有 2 个文件被更改,包括 50 次插入0 次删除
  1. 1 0
      dist/preview release/what's new.md
  2. 49 0
      src/Cameras/VR/babylon.vrExperienceHelper.ts

+ 1 - 0
dist/preview release/what's new.md

@@ -72,6 +72,7 @@
 - CreateScreenshotUsingRenderTarget stretches mirror textures when setting both width and height ([TrevorDev](https://github.com/TrevorDev))
 - VR helper only updating vr cameras position when entering vr, rotation was missing ([TrevorDev](https://github.com/TrevorDev))
 - Fix VR controllers after gltfLoader transformNode change ([TrevorDev](https://github.com/TrevorDev))
+- VR helper would rotate non vr camera while in VR ([TrevorDev](https://github.com/TrevorDev))
 
 ### Core Engine
 - Fixed a bug with `mesh.alwaysSelectAsActiveMesh` preventing layerMask to be taken in account ([Deltakosh](https://github.com/deltakosh))

+ 49 - 0
src/Cameras/VR/babylon.vrExperienceHelper.ts

@@ -643,6 +643,7 @@ module BABYLON {
             // Create VR cameras
             if (webVROptions.createFallbackVRDeviceOrientationFreeCamera) {
                 this._vrDeviceOrientationCamera = new VRDeviceOrientationFreeCamera("VRDeviceOrientationVRHelper", this._position, this._scene);
+                this._vrDeviceOrientationCamera.angularSensibility = Number.MAX_VALUE;
             }
             this._webVRCamera = new WebVRFreeCamera("WebVRHelper", this._position, this._scene, webVROptions);
             this._webVRCamera.useStandingMatrix();
@@ -860,6 +861,7 @@ module BABYLON {
             }
         }
 
+        private _cachedAngularSensibility = {angularSensibilityX: null, angularSensibilityY: null, angularSensibility: null};
         /**
          * Attempt to enter VR. If a headset is connected and ready, will request present on that.
          * Otherwise, will use the fullscreen API.
@@ -879,6 +881,7 @@ module BABYLON {
 
                 if (this.vrDeviceOrientationCamera) {
                     this.vrDeviceOrientationCamera.rotation = BABYLON.Quaternion.FromRotationMatrix(this._scene.activeCamera.getWorldMatrix().getRotationMatrix()).toEulerAngles();
+                    this.vrDeviceOrientationCamera.angularSensibility = 2000;
                 }
                 if (this.webVRCamera) {
                     var currentYRotation = this.webVRCamera.deviceRotationQuaternion.toEulerAngles().y;
@@ -890,6 +893,20 @@ module BABYLON {
 
                 // make sure that we return to the last active camera
                 this._existingCamera = this._scene.activeCamera;
+
+                // Remove and cache angular sensability to avoid camera rotation when in VR
+                if ((<any>this._existingCamera).angularSensibilityX) {
+                    this._cachedAngularSensibility.angularSensibilityX = (<any>this._existingCamera).angularSensibilityX;
+                    (<any>this._existingCamera).angularSensibilityX = Number.MAX_VALUE;
+                }
+                if ((<any>this._existingCamera).angularSensibilityY) {
+                    this._cachedAngularSensibility.angularSensibilityY = (<any>this._existingCamera).angularSensibilityY;
+                    (<any>this._existingCamera).angularSensibilityY = Number.MAX_VALUE;
+                }
+                if ((<any>this._existingCamera).angularSensibility) {
+                    this._cachedAngularSensibility.angularSensibility = (<any>this._existingCamera).angularSensibility;
+                    (<any>this._existingCamera).angularSensibility = Number.MAX_VALUE;
+                }
             }
 
             if (this._webVRrequesting) {
@@ -945,15 +962,47 @@ module BABYLON {
 
                 }
 
+                if (this.vrDeviceOrientationCamera) {
+                    this.vrDeviceOrientationCamera.angularSensibility = Number.MAX_VALUE;
+                }
+
                 if (this._deviceOrientationCamera) {
                     this._deviceOrientationCamera.position = this._position;
                     this._scene.activeCamera = this._deviceOrientationCamera;
                     if (this._canvas) {
                         this._scene.activeCamera.attachControl(this._canvas);
                     }
+
+                    // Restore angular sensibility
+                    if (this._cachedAngularSensibility.angularSensibilityX) {
+                        (<any>this._deviceOrientationCamera).angularSensibilityX = this._cachedAngularSensibility.angularSensibilityX;
+                        this._cachedAngularSensibility.angularSensibilityX = null;
+                    }
+                    if (this._cachedAngularSensibility.angularSensibilityY) {
+                        (<any>this._deviceOrientationCamera).angularSensibilityY = this._cachedAngularSensibility.angularSensibilityY;
+                        this._cachedAngularSensibility.angularSensibilityY = null;
+                    }
+                    if (this._cachedAngularSensibility.angularSensibility) {
+                        (<any>this._deviceOrientationCamera).angularSensibility = this._cachedAngularSensibility.angularSensibility;
+                        this._cachedAngularSensibility.angularSensibility = null;
+                    }
                 } else if (this._existingCamera) {
                     this._existingCamera.position = this._position;
                     this._scene.activeCamera = this._existingCamera;
+
+                    // Restore angular sensibility
+                    if (this._cachedAngularSensibility.angularSensibilityX) {
+                        (<any>this._existingCamera).angularSensibilityX = this._cachedAngularSensibility.angularSensibilityX;
+                        this._cachedAngularSensibility.angularSensibilityX = null;
+                    }
+                    if (this._cachedAngularSensibility.angularSensibilityY) {
+                        (<any>this._existingCamera).angularSensibilityY = this._cachedAngularSensibility.angularSensibilityY;
+                        this._cachedAngularSensibility.angularSensibilityY = null;
+                    }
+                    if (this._cachedAngularSensibility.angularSensibility) {
+                        (<any>this._existingCamera).angularSensibility = this._cachedAngularSensibility.angularSensibility;
+                        this._cachedAngularSensibility.angularSensibility = null;
+                    }
                 }
 
                 this.updateButtonVisibility();