Skip to content

WebXRManager: Inherit active layers from camera #29742

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Oct 28, 2024

Conversation

mrxz
Copy link
Contributor

@mrxz mrxz commented Oct 24, 2024

Fixed #24354

Description

This PR updates the WebXRManager to copy over the layers mask to the XR cameras. The respective eye layer (1 for left, 2 for right) is always enabled in addition.

  • A default scene setup behaves identical to before
  • Calling renderer.render(scene, camera) now always respects camera.layers whether XR is active or not
  • Users that manually enabled layers on the XR cameras will now have to enable them on the main camera instead.
  • Users will have to be careful with layers 1 and 2 as these are used for the eyes (even before this PR)

This contribution is funded by Fern Solutions

Copy link

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 691.57
171.41
691.6
171.42
+26 B
+9 B
WebGPU 818.87
220.85
818.87
220.85
+0 B
+0 B
WebGPU Nodes 818.38
220.72
818.38
220.72
+0 B
+0 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 463.72
112.16
463.75
112.17
+26 B
+8 B
WebGPU 539.75
145.78
539.75
145.78
+0 B
+0 B
WebGPU Nodes 495.74
135.6
495.74
135.6
+0 B
+0 B

@Mugen87
Copy link
Collaborator

Mugen87 commented Oct 26, 2024

/cc @cabanier

@Mugen87 Mugen87 added this to the r170 milestone Oct 26, 2024
@jrjdavidson
Copy link
Contributor

Just in case it's useful, see #26340

@Mugen87 Mugen87 merged commit 6c231d8 into mrdoob:dev Oct 28, 2024
12 checks passed
@geyang
Copy link

geyang commented Mar 16, 2025

This PR causes layer=1 and layer=2 to be both activated for the XR camera. See the following two issues:

@Mugen87
Copy link
Collaborator

Mugen87 commented Mar 16, 2025

The PR just ensures to retain an existing layer configurations of the non-XR scene camera. That was a annoying issue in the past and fixed with this PR.

This PR causes layer=1 and layer=2 to be both activated for the XR camera

This was also true before this PR was merged. Do you mind explaining in more detail the regression that you are facing?

@mrxz
Copy link
Contributor Author

mrxz commented Mar 17, 2025

The cause of the issue has been found (see pmndrs/xr#398). For context, the issue lies in @react-three/xr where the XR camera is being fed back into the render call, effectively doing:

renderer.render(scene, renderer.xr.getCamera());

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configure WebXR camera layers
4 participants