소스 검색

set transformation from other camera

Raanan Weber 5 년 전
부모
커밋
192d5fedc1
2개의 변경된 파일19개의 추가작업 그리고 7개의 파일을 삭제
  1. 17 0
      src/Cameras/XR/webXRCamera.ts
  2. 2 7
      src/Cameras/XR/webXRExperienceHelper.ts

+ 17 - 0
src/Cameras/XR/webXRCamera.ts

@@ -73,6 +73,23 @@ export class WebXRCamera extends FreeCamera {
         }
     }
 
+    /**
+     * Sets this camera's transformation based on a non-vr camera
+     * @param otherCamera the non-vr camera to copy the transformation from
+     * @param resetToBaseReferenceSpace should XR reset to the base reference space
+     */
+    public setTransformationFromNonVRCamera(otherCamera: Camera, resetToBaseReferenceSpace: boolean = true) {
+        const mat = otherCamera.computeWorldMatrix();
+        mat.decompose(undefined, this.rotationQuaternion, this.position);
+        // set the ground level
+        this.position.y = 0;
+        Quaternion.FromEulerAnglesToRef(0, this.rotationQuaternion.toEulerAngles().y, 0, this.rotationQuaternion);
+        this._firstFrame = true;
+        if (resetToBaseReferenceSpace) {
+            this._xrSessionManager.resetReferenceSpace();
+        }
+    }
+
     /** @hidden */
     public _updateForDualEyeDebugging(/*pupilDistance = 0.01*/) {
         // Create initial camera rigs

+ 2 - 7
src/Cameras/XR/webXRExperienceHelper.ts

@@ -1,7 +1,6 @@
 import { Nullable } from "../../types";
 import { Observable } from "../../Misc/observable";
 import { IDisposable, Scene } from "../../scene";
-import { Quaternion } from "../../Maths/math.vector";
 import { Camera } from "../../Cameras/camera";
 import { WebXRSessionManager } from "./webXRSessionManager";
 import { WebXRCamera } from "./webXRCamera";
@@ -161,17 +160,13 @@ export class WebXRExperienceHelper implements IDisposable {
     public dispose() {
         this.camera.dispose();
         this.onStateChangedObservable.clear();
+        this.onInitialXRPoseSetObservable.clear();
         this.sessionManager.dispose();
     }
 
     private _nonXRToXRCamera() {
         this.scene.activeCamera = this.camera;
-        const mat = this._nonVRCamera!.computeWorldMatrix();
-        mat.decompose(undefined, this.camera.rotationQuaternion, this.camera.position);
-        // set the ground level
-        this.camera.position.y = 0;
-        Quaternion.FromEulerAnglesToRef(0, this.camera.rotationQuaternion.toEulerAngles().y, 0, this.camera.rotationQuaternion);
-
+        this.camera.setTransformationFromNonVRCamera(this._nonVRCamera!);
         this.onInitialXRPoseSetObservable.notifyObservers(this.camera);
     }
 }