Skip to content

Commit

Permalink
fixes for WebXRManagers caching of baseReferenceFrame and teleport ex…
Browse files Browse the repository at this point in the history
…ample fix (mrdoob#24058)
  • Loading branch information
richardanaya authored and abernier committed Sep 16, 2022
1 parent 966e43d commit 8594a8d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions examples/webxr_vr_teleport.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
let controller1, controller2;
let controllerGrip1, controllerGrip2;

let room, marker, floor;
let room, marker, floor, baseReferenceSpace;

let INTERSECTION;
const tempMatrix = new THREE.Matrix4();
Expand Down Expand Up @@ -84,6 +84,7 @@
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.outputEncoding = THREE.sRGBEncoding;
renderer.xr.addEventListener( 'sessionstart', () => { baseReferenceSpace = renderer.xr.getReferenceSpace(); } )
renderer.xr.enabled = true;
document.body.appendChild( renderer.domElement );

Expand All @@ -105,7 +106,6 @@

if ( INTERSECTION ) {

const baseReferenceSpace = renderer.xr.getReferenceSpace();
const offsetPosition = { x: - INTERSECTION.x, y: - INTERSECTION.y, z: - INTERSECTION.z, w: 1 };
const offsetRotation = new THREE.Quaternion();
const transform = new XRRigidTransform( offsetPosition, offsetRotation );
Expand Down
10 changes: 10 additions & 0 deletions src/renderers/webxr/WebXRManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ class WebXRManager extends EventDispatcher {

function onSessionEnd() {

session.removeEventListener( 'select', onSessionEvent );
session.removeEventListener( 'selectstart', onSessionEvent );
session.removeEventListener( 'selectend', onSessionEvent );
session.removeEventListener( 'squeeze', onSessionEvent );
session.removeEventListener( 'squeezestart', onSessionEvent );
session.removeEventListener( 'squeezeend', onSessionEvent );
session.removeEventListener( 'end', onSessionEnd );
session.removeEventListener( 'inputsourceschange', onInputSourcesChange );

inputSourcesMap.forEach( function ( controller, inputSource ) {

if ( controller !== undefined ) {
Expand Down Expand Up @@ -321,6 +330,7 @@ class WebXRManager extends EventDispatcher {
// Set foveation to maximum.
this.setFoveation( 1.0 );

customReferenceSpace = null;
referenceSpace = await session.requestReferenceSpace( referenceSpaceType );

animation.setContext( session );
Expand Down

0 comments on commit 8594a8d

Please sign in to comment.