Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore original camera FOV and Zoom after XR presentation ends #30374

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,16 @@ 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
6 changes: 6 additions & 0 deletions src/renderers/webxr/WebXRManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,12 @@ class WebXRManager extends EventDispatcher {

if ( camera.isPerspectiveCamera ) {

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

camera.userData.previousFov = camera.fov;

}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Camera fov and zoom should be memoized at the top-level of this class and overriden/restored on sessionstart and sessionend. You will find this for renderer properties, and it would be the same here.

camera.fov = RAD2DEG * 2 * Math.atan( 1 / camera.projectionMatrix.elements[ 5 ] );
camera.zoom = 1;

Expand Down
Loading