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

Match main camera layer #26340

Closed
wants to merge 5 commits into from
Closed

Conversation

jrjdavidson
Copy link
Contributor

@jrjdavidson jrjdavidson commented Jun 28, 2023

Related issue: #24354, #26322, #26041

Description

This PR sets a constant for the right and left eye layer, and also allows you to change the XRCamera layers simply by updating the main camera layer. I think matching the layers on both the XRCamera and the main camera is a intuitive behaviour, it was what I was expecting before I investigated the XRManager code.

Update

After some thought, I decided to change how I handle the XR camera layers. It seems to me that the only reason that layers are added to the individual XR cameras is to demonstrate the Mery video example. If that's case, then I think it makes senses for the XR cameras layers to match the main renderer camera up until the user request the change. That is why I suggest we introduce an API to set the individual camera layers.

I think this will simplify the way layers are handled, make for a lot less code in all cases, and it will be more consistent with the rest of the project - I believe this is the only case where the renderer reserves layers for a specific use?

e.g. currently if I want to render a specific layer in XR I have to do this ( or see :

	//hide objects in layer 0 and show objects in layer 3
	camera.layers.enable( 3 );
	camera.layers.disable( 0 );
	if ( renderer.xr.isPresenting ) {

		setVRCameras();

	} else {

		renderer.xr.addEventListener( 'sessionstart', setVRCameras, { once: true } );

	}


	function setVRCameras() {

		const cameraVR = renderer.xr.getCamera();
		cameraVR.layers.enable( 3 );
		cameraVR.layers.disable( 0 );

		setVRChildLayers();

		function setVRChildLayers() {

			// if XR camera hasn't initialised yet, try again on the next frame

			if ( ! cameraVR.cameras.length ) return setTimeout( setVRChildLayers, 16 );

			cameraVR.cameras.forEach( camera => {

				camera.layers.enable( 3 );
				camera.layers.disable( 0 );

			} );

		}

	}

after this change it will become

	camera.layers.enable( 3 );
	camera.layers.disable( 0 );

for the Mery example, you only need to add the one line:
renderer.xr.setEyeLayers( [ 0, 1 ] );

@github-actions
Copy link

📦 Bundle size

Full ESM build, minified and gzipped.

Filesize dev Filesize PR Diff
643.1 kB (159.5 kB) 643.3 kB (159.5 kB) +194 B

🌳 Bundle size after tree-shaking

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

Filesize dev Filesize PR Diff
436.4 kB (105.6 kB) 436.6 kB (105.7 kB) +141 B

@Mugen87
Copy link
Collaborator

Mugen87 commented Oct 28, 2024

Closing in favor of #29742.

@Mugen87 Mugen87 closed this Oct 28, 2024
@Mugen87 Mugen87 added this to the r170 milestone Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants