Skip to content

Commit

Permalink
Adds new logic to restore camera fov and zoom in WebXRManager
Browse files Browse the repository at this point in the history
WebGLRender has been restored, now it is not involved at all.
  • Loading branch information
ramonmata committed Jan 23, 2025
1 parent bd9b321 commit bc7c13b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
10 changes: 0 additions & 10 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1151,16 +1151,6 @@ class WebGLRenderer {

if ( scene.matrixWorldAutoUpdate === true ) scene.updateMatrixWorld();

// Restore original camera fov

if ( xr.enabled === true && xr.isPresenting === false && camera.userData.previousFov !== undefined ) {

camera.fov = camera.userData.previousFov;
delete camera.userData.previousFov;
camera.updateProjectionMatrix();

}

// update camera matrices and frustum

if ( camera.parent === null && camera.matrixWorldAutoUpdate === true ) camera.updateMatrixWorld();
Expand Down
23 changes: 21 additions & 2 deletions src/renderers/webxr/WebXRManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class WebXRManager extends EventDispatcher {

//

let updatedCameraProperties = null;

this.cameraAutoUpdate = true;
this.enabled = false;

Expand Down Expand Up @@ -182,6 +184,17 @@ class WebXRManager extends EventDispatcher {

scope.isPresenting = false;

if ( updatedCameraProperties !== null ) {

const camera = updatedCameraProperties.camera;
camera.fov = updatedCameraProperties.fov;
camera.zoom = updatedCameraProperties.zoom;
camera.updateProjectionMatrix();

updatedCameraProperties = null;

}

renderer.setPixelRatio( currentPixelRatio );
renderer.setSize( currentSize.width, currentSize.height, false );

Expand Down Expand Up @@ -363,6 +376,8 @@ class WebXRManager extends EventDispatcher {

scope.isPresenting = true;

updatedCameraProperties = null;

scope.dispatchEvent( { type: 'sessionstart' } );

}
Expand Down Expand Up @@ -633,9 +648,13 @@ class WebXRManager extends EventDispatcher {

if ( camera.isPerspectiveCamera ) {

if ( camera.userData.previousFov === undefined ) {
if ( updatedCameraProperties === null ) {

camera.userData.previousFov = camera.fov;
updatedCameraProperties = {
camera: camera,
fov: camera.fov,
zoom: camera.zoom,
};

}

Expand Down

0 comments on commit bc7c13b

Please sign in to comment.