Procházet zdrojové kódy

Merge pull request #7399 from RaananW/xr-state-fix

WebXR camera initialized on first frame
David Catuhe před 5 roky
rodič
revize
dffdd08d75

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

@@ -188,6 +188,7 @@
 - Teleportation and controller selection are now WebXR features. ([#7290](https://github.com/BabylonJS/Babylon.js/issues/7290)) ([RaananW](https://github.com/RaananW/))
 - Teleportation allows selecting direction before teleporting when using thumbstick/touchpad. ([#7290](https://github.com/BabylonJS/Babylon.js/issues/7290)) ([RaananW](https://github.com/RaananW/))
 - It is now possible to force a certain profile type for the controllers ([#7348](https://github.com/BabylonJS/Babylon.js/issues/7375)) ([RaananW](https://github.com/RaananW/))
+- WebXR camera is initialized on the first frame ([#7389](https://github.com/BabylonJS/Babylon.js/issues/7389)) ([RaananW](https://github.com/RaananW/))
 
 ### Ray
 

+ 9 - 10
src/Cameras/XR/webXRCamera.ts

@@ -43,14 +43,16 @@ export class WebXRCamera extends FreeCamera {
             this._referenceQuaternion.copyFromFloats(0, 0, 0, 1);
             // first frame - camera's y position should be 0 for the correct offset
             this._firstFrame = true;
+
         });
 
         // Check transformation changes on each frame. Callback is added to be first so that the transformation will be
         // applied to the rest of the elements using the referenceSpace object
         this._xrSessionManager.onXRFrameObservable.add((frame) => {
-            if (!this._firstFrame) {
-                this._updateReferenceSpace();
+            if (this._firstFrame) {
+                this._updateFromXRSession();
             }
+            this._updateReferenceSpace();
             this._updateFromXRSession();
         }, undefined, true);
     }
@@ -83,16 +85,14 @@ export class WebXRCamera extends FreeCamera {
         this.rigCameras[1].outputRenderTarget = null;
     }
 
-    private _updateReferenceSpace(): boolean {
+    private _updateReferenceSpace() {
         // were position & rotation updated OUTSIDE of the xr update loop
         if (!this.position.equals(this._referencedPosition) || !this.rotationQuaternion.equals(this._referenceQuaternion)) {
             this.position.subtractToRef(this._referencedPosition, this._referencedPosition);
             this._referenceQuaternion.conjugateInPlace();
             this._referenceQuaternion.multiplyToRef(this.rotationQuaternion, this._referenceQuaternion);
             this._updateReferenceSpaceOffset(this._referencedPosition, this._referenceQuaternion.normalize());
-            return true;
         }
-        return false;
     }
 
     private _updateReferenceSpaceOffset(positionOffset: Vector3, rotationOffset?: Quaternion, ignoreHeight: boolean = false) {
@@ -180,12 +180,11 @@ export class WebXRCamera extends FreeCamera {
                 this._referenceQuaternion.copyFromFloats(0, 0, 0, 1);
                 // update the reference space so that the position will be correct
 
-                return this.update();
-
             }
-
-            this.rotationQuaternion.copyFrom(this._referenceQuaternion);
-            this.position.copyFrom(this._referencedPosition);
+            else {
+                this.rotationQuaternion.copyFrom(this._referenceQuaternion);
+                this.position.copyFrom(this._referencedPosition);
+            }
         }
 
         // Update camera rigs

+ 1 - 3
src/Cameras/XR/webXRController.ts

@@ -20,8 +20,6 @@ export class WebXRController {
      * Pointer which can be used to select objects or attach a visible laser to
      */
     public pointer: AbstractMesh;
-
-    private _gamepadMode = false;
     /**
      * If available, this is the gamepad object related to this controller.
      * Using this object it is possible to get click events and trackpad changes of the
@@ -145,7 +143,7 @@ export class WebXRController {
         if (this.grip) {
             this.grip.dispose();
         }
-        if (this.gamepadController && this._gamepadMode) {
+        if (this.gamepadController) {
             this.gamepadController.dispose();
         }
         this.pointer.dispose();