소스 검색

refactor to use the existing this.vrDevice

Trevor Baron 7 년 전
부모
커밋
3fde4ca695
1개의 변경된 파일26개의 추가작업 그리고 23개의 파일을 삭제
  1. 26 23
      src/Cameras/VR/babylon.webVRCamera.ts

+ 26 - 23
src/Cameras/VR/babylon.webVRCamera.ts

@@ -57,9 +57,6 @@ module BABYLON {
         private _deviceRoomRotationQuaternion = Quaternion.Identity();
 
         private _standingMatrix: Nullable<Matrix> = null;
-        private _useStandingMatrix: boolean = false;
-
-        private _useStandingMatrixCallback: Function;
 
         // Represents device position and rotation in babylon space
         public devicePosition = Vector3.Zero();
@@ -128,22 +125,6 @@ module BABYLON {
                 if (this._attached) {
                     this.getEngine().enableVR();
                 }
-                if(this._useStandingMatrix){
-                    if (!this._vrDevice.stageParameters.sittingToStandingTransform) {
-                        this._useStandingMatrixCallback(false);
-                    }else{
-                        this._standingMatrix = new Matrix();
-                        Matrix.FromFloat32ArrayToRefScaled(this._vrDevice.stageParameters.sittingToStandingTransform, 0, 1, this._standingMatrix);
-                        if (!this.getScene().useRightHandedSystem) {
-                            [2, 6, 8, 9, 14].forEach((num) => {
-                                if (this._standingMatrix) {
-                                    this._standingMatrix.m[num] *= -1;
-                                }
-                            });
-                        }
-                        this._useStandingMatrixCallback(true)
-                    }
-                }
             });
 
             if (typeof (VRFrameData) !== "undefined")
@@ -194,10 +175,32 @@ module BABYLON {
         }
 
         public useStandingMatrix = (callback = (bool: boolean) => { }) => {
-            this._useStandingMatrix = true;
-            this._useStandingMatrixCallback = callback;
-            if (!this._vrDevice) {
-                this.getEngine().enableVR();
+            var webVRInitobserver: Nullable<Observable<{ vrDisplay: any, vrSupported: any }>> = null;
+            var setStandingMatrix = ()=>{
+                if (!this._vrDevice || !this._vrDevice.stageParameters||!this._vrDevice.stageParameters.sittingToStandingTransform) {
+                    callback(false);
+                } else {
+                    this._standingMatrix = new Matrix();
+                    Matrix.FromFloat32ArrayToRefScaled(this._vrDevice.stageParameters.sittingToStandingTransform, 0, 1, this._standingMatrix);
+                    if (!this.getScene().useRightHandedSystem) {
+                        [2, 6, 8, 9, 14].forEach((num) => {
+                            if (this._standingMatrix) {
+                                this._standingMatrix.m[num] *= -1;
+                            }
+                        });
+                    }
+                    callback(true)
+                }
+                if(webVRInitobserver){
+                    webVRInitobserver.removeCallback(setStandingMatrix)
+                }
+            }
+
+            if(this._vrDevice){
+                setStandingMatrix();
+            }else{
+                webVRInitobserver = this.getEngine().initWebVR();
+                webVRInitobserver.add(setStandingMatrix);
             }
         }