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

WebXRManager: Removed getCamera() and added setUserCamera(). #26041

Merged
merged 6 commits into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
Binary file modified examples/screenshots/webxr_vr_handinput_pointerclick.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webxr_vr_handinput_pointerdrag.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webxr_vr_handinput_pressbutton.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 2 additions & 6 deletions examples/webxr_vr_handinput_pointerclick.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@

import { World, System, Component, TagComponent, Types } from 'three/addons/libs/ecsy.module.js';

THREE.ColorManagement.enabled = false; // TODO: Consider enabling color management.

class Object3D extends Component { }

Object3D.schema = {
Expand Down Expand Up @@ -305,7 +303,7 @@
camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 0.1, 10 );
camera.position.set( 0, 1.2, 0.3 );

scene.add( new THREE.HemisphereLight( 0x808080, 0x606060 ) );
scene.add( new THREE.HemisphereLight( 0xcccccc, 0x999999 ) );

const light = new THREE.DirectionalLight( 0xffffff );
light.position.set( 0, 6, 0 );
Expand All @@ -322,8 +320,7 @@
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.shadowMap.enabled = true;
renderer.xr.enabled = true;
renderer.xr.cameraAutoUpdate = false;

renderer.xr.setUserCamera( camera );
container.appendChild( renderer.domElement );

document.body.appendChild( VRButton.createButton( renderer ) );
Expand Down Expand Up @@ -518,7 +515,6 @@

const delta = clock.getDelta();
const elapsedTime = clock.elapsedTime;
renderer.xr.updateCamera( camera );
world.execute( delta, elapsedTime );
renderer.render( scene, camera );

Expand Down
15 changes: 5 additions & 10 deletions examples/webxr_vr_handinput_pointerdrag.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@

import { World, System, Component, TagComponent, Types } from 'three/addons/libs/ecsy.module.js';

THREE.ColorManagement.enabled = false; // TODO: Consider enabling color management.

class Object3D extends Component { }

Object3D.schema = {
Expand Down Expand Up @@ -312,10 +310,9 @@

const offset = entity.getComponent( OffsetFromCamera );
const object = entity.getComponent( Object3D ).object;
const xrCamera = this.renderer.xr.getCamera();
object.position.x = xrCamera.position.x + offset.x;
object.position.y = xrCamera.position.y + offset.y;
object.position.z = xrCamera.position.z + offset.z;
object.position.x = camera.position.x + offset.x;
object.position.y = camera.position.y + offset.y;
object.position.z = camera.position.z + offset.z;
entity.removeComponent( NeedCalibration );

}
Expand Down Expand Up @@ -408,7 +405,7 @@
camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 0.1, 10 );
camera.position.set( 0, 1.2, 0.3 );

scene.add( new THREE.HemisphereLight( 0x808080, 0x606060 ) );
scene.add( new THREE.HemisphereLight( 0xcccccc, 0x999999 ) );

const light = new THREE.DirectionalLight( 0xffffff );
light.position.set( 0, 6, 0 );
Expand All @@ -425,8 +422,7 @@
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.shadowMap.enabled = true;
renderer.xr.enabled = true;
renderer.xr.cameraAutoUpdate = false;

renderer.xr.setUserCamera( camera );
container.appendChild( renderer.domElement );

document.body.appendChild( VRButton.createButton( renderer ) );
Expand Down Expand Up @@ -596,7 +592,6 @@

const delta = clock.getDelta();
const elapsedTime = clock.elapsedTime;
renderer.xr.updateCamera( camera );
world.execute( delta, elapsedTime );
renderer.render( scene, camera );

Expand Down
25 changes: 10 additions & 15 deletions examples/webxr_vr_handinput_pressbutton.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@

import { World, System, Component, TagComponent, Types } from 'three/addons/libs/ecsy.module.js';

THREE.ColorManagement.enabled = false; // TODO: Consider enabling color management.

class Object3D extends Component { }

Object3D.schema = {
Expand Down Expand Up @@ -75,11 +73,6 @@
let buttonPressSound, buttonReleaseSound;
if ( this.renderer.xr.getSession() && ! this.soundAdded ) {

const xrCamera = this.renderer.xr.getCamera();

const listener = new THREE.AudioListener();
xrCamera.add( listener );

// create a global audio source
buttonPressSound = new THREE.Audio( listener );
buttonReleaseSound = new THREE.Audio( listener );
Expand Down Expand Up @@ -316,10 +309,9 @@

const offset = entity.getComponent( OffsetFromCamera );
const object = entity.getComponent( Object3D ).object;
const xrCamera = this.renderer.xr.getCamera();
object.position.x = xrCamera.position.x + offset.x;
object.position.y = xrCamera.position.y + offset.y;
object.position.z = xrCamera.position.z + offset.z;
object.position.x = camera.position.x + offset.x;
object.position.y = camera.position.y + offset.y;
object.position.z = camera.position.z + offset.z;
entity.removeComponent( NeedCalibration );

}
Expand All @@ -338,7 +330,9 @@

const world = new World();
const clock = new THREE.Clock();

let camera, scene, renderer;
let listener;

init();
animate();
Expand All @@ -365,7 +359,10 @@
camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 0.1, 10 );
camera.position.set( 0, 1.2, 0.3 );

scene.add( new THREE.HemisphereLight( 0x808080, 0x606060 ) );
listener = new THREE.AudioListener();
camera.add( listener );

scene.add( new THREE.HemisphereLight( 0xcccccc, 0x999999 ) );

const light = new THREE.DirectionalLight( 0xffffff );
light.position.set( 0, 6, 0 );
Expand All @@ -382,8 +379,7 @@
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.shadowMap.enabled = true;
renderer.xr.enabled = true;
renderer.xr.cameraAutoUpdate = false;

renderer.xr.setUserCamera( camera );
container.appendChild( renderer.domElement );

document.body.appendChild( VRButton.createButton( renderer ) );
Expand Down Expand Up @@ -575,7 +571,6 @@

const delta = clock.getDelta();
const elapsedTime = clock.elapsedTime;
renderer.xr.updateCamera( camera );
world.execute( delta, elapsedTime );
renderer.render( scene, camera );

Expand Down
19 changes: 10 additions & 9 deletions examples/webxr_vr_rollercoaster.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@

let mesh, material, geometry;

const renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.xr.enabled = true;
renderer.xr.setReferenceSpaceType( 'local' );
document.body.appendChild( renderer.domElement );

document.body.appendChild( VRButton.createButton( renderer ) );

//

const scene = new THREE.Scene();
Expand Down Expand Up @@ -188,6 +179,16 @@

//

const renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.xr.enabled = true;
renderer.xr.setReferenceSpaceType( 'local' );
renderer.xr.setUserCamera( camera );
document.body.appendChild( renderer.domElement );

document.body.appendChild( VRButton.createButton( renderer ) );

window.addEventListener( 'resize', onWindowResize );

function onWindowResize() {
Expand Down
4 changes: 1 addition & 3 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1048,9 +1048,7 @@ class WebGLRenderer {

if ( xr.enabled === true && xr.isPresenting === true ) {

if ( xr.cameraAutoUpdate === true ) xr.updateCamera( camera );

camera = xr.getCamera(); // use XR camera for rendering
camera = xr.updateCameraXR( camera ); // use XR camera for rendering

}

Expand Down
Loading