Bläddra i källkod

Merge pull request #7368 from RaananW/one-frame-off-transformation

Fix single-frame flickering in WebXR
David Catuhe 5 år sedan
förälder
incheckning
be29a90a79
2 ändrade filer med 10 tillägg och 13 borttagningar
  1. 1 1
      dist/preview release/what's new.md
  2. 9 12
      src/Cameras/XR/webXRCamera.ts

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

@@ -181,7 +181,7 @@
 - WebXR teleportation can now be disabled after initialized ([RaananW](https://github.com/RaananW/))
 - New Features Manager for WebXR features ([RaananW](https://github.com/RaananW/))
 - New features - Plane detection, Hit Test, Background remover ([RaananW](https://github.com/RaananW/))
-- Camera's API works as expected (position, rotationQuaternion, world matrix etc') ([#7239](https://github.com/BabylonJS/Babylon.js/issues/7239)) ([RaananW](https://github.com/RaananW/))
+- Camera's API is Babylon-conform (position, rotationQuaternion, world matrix, direction etc') ([#7239](https://github.com/BabylonJS/Babylon.js/issues/7239)) ([RaananW](https://github.com/RaananW/))
 - XR Input now using standard profiles and completely separated from the gamepad class ([#7348](https://github.com/BabylonJS/Babylon.js/issues/7348)) ([RaananW](https://github.com/RaananW/))
 
 ### Ray

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

@@ -44,6 +44,15 @@ export class WebXRCamera extends FreeCamera {
             // 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();
+            }
+            this._updateFromXRSession();
+        }, undefined, true);
     }
 
     private _updateNumberOfRigCameras(viewCount = 1) {
@@ -74,18 +83,6 @@ export class WebXRCamera extends FreeCamera {
         this.rigCameras[1].outputRenderTarget = null;
     }
 
-    /**
-     * Updates the cameras position from the current pose information of the  XR session
-     * @param xrSessionManager the session containing pose information
-     */
-    public update() {
-        if (!this._firstFrame) {
-            this._updateReferenceSpace();
-        }
-        this._updateFromXRSession();
-        super.update();
-    }
-
     private _updateReferenceSpace(): boolean {
         // were position & rotation updated OUTSIDE of the xr update loop
         if (!this.position.equals(this._referencedPosition) || !this.rotationQuaternion.equals(this._referenceQuaternion)) {