浏览代码

add semicolons, move use standing matrix to a separate function

Trevor Baron 7 年之前
父节点
当前提交
e05dc5f0eb
共有 2 个文件被更改,包括 34 次插入24 次删除
  1. 5 5
      src/Cameras/VR/babylon.vrExperienceHelper.ts
  2. 29 19
      src/Cameras/VR/babylon.webVRCamera.ts

+ 5 - 5
src/Cameras/VR/babylon.vrExperienceHelper.ts

@@ -695,16 +695,16 @@ module BABYLON {
             var controllerMesh = webVRController.mesh;
             var controllerMesh = webVRController.mesh;
             if (controllerMesh) {
             if (controllerMesh) {
                 var makeNotPick = (root:AbstractMesh)=>{
                 var makeNotPick = (root:AbstractMesh)=>{
-                    root.name += " laserPointer"
+                    root.name += " laserPointer";
                     root.getChildMeshes().forEach((c)=>{
                     root.getChildMeshes().forEach((c)=>{
-                        makeNotPick(c)
-                    })
+                        makeNotPick(c);
+                    });
                 }
                 }
-                makeNotPick(controllerMesh)
+                makeNotPick(controllerMesh);
                 var childMeshes = controllerMesh.getChildMeshes();
                 var childMeshes = controllerMesh.getChildMeshes();
 
 
                 for (var i = 0; i < childMeshes.length; i++) {
                 for (var i = 0; i < childMeshes.length; i++) {
-                    if (childMeshes[i].name === "POINTING_POSE") {
+                    if (childMeshes[i].name && childMeshes[i].name.indexOf("POINTING_POSE") >= 0) {
                         controllerMesh = childMeshes[i];
                         controllerMesh = childMeshes[i];
                         break;
                         break;
                     }
                     }

+ 29 - 19
src/Cameras/VR/babylon.webVRCamera.ts

@@ -125,24 +125,6 @@ module BABYLON {
                 }
                 }
             });
             });
 
 
-            // Use standing matrix if availible
-            if(navigator && navigator.getVRDisplays){
-                navigator.getVRDisplays().then((displays:any)=>{
-                    if(!displays || !displays[0] || !displays[0].stageParameters || !displays[0].stageParameters.sittingToStandingTransform){
-                        return;
-                    }
-                    BABYLON.Matrix.FromFloat32ArrayToRefScaled(displays[0].stageParameters.sittingToStandingTransform, 0, 1, this._standingMatrix);
-                    if (!this.getScene().useRightHandedSystem) {
-                        [2, 6, 8, 9, 14].forEach((num) => {
-                            this._standingMatrix.m[num] *= -1;
-                        });
-                    }
-
-                    // Move starting headset position by standing matrix
-                    this._deviceToWorld.multiplyToRef(this._standingMatrix, this._deviceToWorld);
-                })
-            }
-
             if (typeof(VRFrameData) !== "undefined")
             if (typeof(VRFrameData) !== "undefined")
                 this._frameData = new VRFrameData();
                 this._frameData = new VRFrameData();
 
 
@@ -180,6 +162,34 @@ module BABYLON {
             });
             });
         }
         }
 
 
+        public useStandingMatrix = ()=>{
+            return new Promise<boolean>((res, rej)=>{
+                // Use standing matrix if availible
+                if(!navigator || !navigator.getVRDisplays){
+                    res(false);
+                }else{
+                    navigator.getVRDisplays().then((displays:any)=>{
+                        if(!displays || !displays[0] || !displays[0].stageParameters || !displays[0].stageParameters.sittingToStandingTransform){
+                            res(false);
+                        }else{
+                            this._standingMatrix = new BABYLON.Matrix();
+                            BABYLON.Matrix.FromFloat32ArrayToRefScaled(displays[0].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;
+                                    }
+                                });
+                            }
+    
+                            // Move starting headset position by standing matrix
+                            this._deviceToWorld.multiplyToRef(this._standingMatrix, this._deviceToWorld);
+                        }
+                    })
+                }
+            })
+        }
+
         public dispose(): void {
         public dispose(): void {
             this.getEngine().onVRRequestPresentComplete.removeCallback(this._onVREnabled);
             this.getEngine().onVRRequestPresentComplete.removeCallback(this._onVREnabled);
             super.dispose();
             super.dispose();
@@ -217,7 +227,7 @@ module BABYLON {
         
         
         public getForwardRay(length = 100): Ray {
         public getForwardRay(length = 100): Ray {
             if (this.leftCamera) {
             if (this.leftCamera) {
-                this.deviceRotationQuaternion.toRotationMatrix(this._workingMatrix)
+                this.deviceRotationQuaternion.toRotationMatrix(this._workingMatrix);
                 return super.getForwardRay(length, this._workingMatrix, this.devicePosition); // Need the actual rendered camera
                 return super.getForwardRay(length, this._workingMatrix, this.devicePosition); // Need the actual rendered camera
             }
             }
             else {
             else {