소스 검색

update webVR camera's cache prior to getting each eye's viewmatrix to avoid controller and eyes going out of sync

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

+ 7 - 5
src/Cameras/VR/babylon.webVRCamera.ts

@@ -531,7 +531,7 @@ module BABYLON {
 
 
                 // Update the gamepad to ensure the mesh is updated on the same frame as camera
                 // Update the gamepad to ensure the mesh is updated on the same frame as camera
                 this.controllers.forEach((controller) => {
                 this.controllers.forEach((controller) => {
-                    controller._deviceToWorld = this._deviceToWorld;
+                    controller._deviceToWorld.copyFrom(this._deviceToWorld);
                     controller.update();
                     controller.update();
                 });
                 });
             }
             }
@@ -570,9 +570,13 @@ module BABYLON {
          * 'this' is the left or right camera (and NOT (!!!) the WebVRFreeCamera instance)
          * 'this' is the left or right camera (and NOT (!!!) the WebVRFreeCamera instance)
          */
          */
         protected _getWebVRViewMatrix(): Matrix {
         protected _getWebVRViewMatrix(): Matrix {
+            // Update the parent camera prior to using a child camera to avoid desynchronization
+            let parentCamera: WebVRFreeCamera = this._cameraRigParams["parentCamera"];
+            parentCamera._updateCache();
+
             //WebVR 1.1
             //WebVR 1.1
             var viewArray = this._cameraRigParams["left"] ? this._cameraRigParams["frameData"].leftViewMatrix : this._cameraRigParams["frameData"].rightViewMatrix;
             var viewArray = this._cameraRigParams["left"] ? this._cameraRigParams["frameData"].leftViewMatrix : this._cameraRigParams["frameData"].rightViewMatrix;
-
+            
             Matrix.FromArrayToRef(viewArray, 0, this._webvrViewMatrix);
             Matrix.FromArrayToRef(viewArray, 0, this._webvrViewMatrix);
 
 
             if (!this.getScene().useRightHandedSystem) {
             if (!this.getScene().useRightHandedSystem) {
@@ -588,8 +592,6 @@ module BABYLON {
             // Computing target and final matrix
             // Computing target and final matrix
             this.position.addToRef(this._transformedReferencePoint, this._currentTarget);
             this.position.addToRef(this._transformedReferencePoint, this._currentTarget);
 
 
-            let parentCamera: WebVRFreeCamera = this._cameraRigParams["parentCamera"];
-
             // should the view matrix be updated with scale and position offset?
             // should the view matrix be updated with scale and position offset?
             if (parentCamera.deviceScaleFactor !== 1) {
             if (parentCamera.deviceScaleFactor !== 1) {
                 this._webvrViewMatrix.invert();
                 this._webvrViewMatrix.invert();
@@ -661,7 +663,7 @@ module BABYLON {
             this._onGamepadConnectedObserver = manager.onGamepadConnectedObservable.add((gamepad) => {
             this._onGamepadConnectedObserver = manager.onGamepadConnectedObservable.add((gamepad) => {
                 if (gamepad.type === Gamepad.POSE_ENABLED) {
                 if (gamepad.type === Gamepad.POSE_ENABLED) {
                     let webVrController: WebVRController = <WebVRController>gamepad;
                     let webVrController: WebVRController = <WebVRController>gamepad;
-                    webVrController._deviceToWorld = this._deviceToWorld;
+                    webVrController._deviceToWorld.copyFrom(this._deviceToWorld);
                     if (this.webVROptions.controllerMeshes) {
                     if (this.webVROptions.controllerMeshes) {
                         if (webVrController.defaultModel) {
                         if (webVrController.defaultModel) {
                             webVrController.defaultModel.setEnabled(true);
                             webVrController.defaultModel.setEnabled(true);