Skip to content

Commit

Permalink
WebXRManager: Use async/await in setSession().
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 committed Nov 24, 2020
1 parent 5f66b71 commit 6ff1d1b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
4 changes: 2 additions & 2 deletions examples/jsm/webxr/ARButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ class ARButton {

let currentSession = null;

function onSessionStarted( session ) {
async function onSessionStarted( session ) {

session.addEventListener( 'end', onSessionEnded );

renderer.xr.setReferenceSpaceType( 'local' );
renderer.xr.setSession( session );
await renderer.xr.setSession( session );
button.textContent = 'STOP AR';

currentSession = session;
Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/webxr/VRButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class VRButton {

let currentSession = null;

function onSessionStarted( session ) {
async function onSessionStarted( session ) {

session.addEventListener( 'end', onSessionEnded );

renderer.xr.setSession( session );
await renderer.xr.setSession( session );
button.textContent = 'EXIT VR';

currentSession = session;
Expand Down
29 changes: 10 additions & 19 deletions src/renderers/webxr/WebXRManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,6 @@ function WebXRManager( renderer, gl ) {

}

function onRequestReferenceSpace( value ) {

referenceSpace = value;

animation.setContext( session );
animation.start();

scope.isPresenting = true;

scope.dispatchEvent( { type: 'sessionstart' } );

}

this.setFramebufferScaleFactor = function ( value ) {

framebufferScaleFactor = value;
Expand Down Expand Up @@ -177,7 +164,7 @@ function WebXRManager( renderer, gl ) {

};

this.setSession = function ( value ) {
this.setSession = async function ( value ) {

session = value;

Expand All @@ -190,12 +177,13 @@ function WebXRManager( renderer, gl ) {
session.addEventListener( 'squeezestart', onSessionEvent );
session.addEventListener( 'squeezeend', onSessionEvent );
session.addEventListener( 'end', onSessionEnd );
session.addEventListener( 'inputsourceschange', onInputSourcesChange );

const attributes = gl.getContextAttributes();

if ( attributes.xrCompatible !== true ) {

gl.makeXRCompatible();
await gl.makeXRCompatible();

}

Expand All @@ -212,17 +200,20 @@ function WebXRManager( renderer, gl ) {

session.updateRenderState( { baseLayer: baseLayer } );

session.requestReferenceSpace( referenceSpaceType ).then( onRequestReferenceSpace );
referenceSpace = await session.requestReferenceSpace( referenceSpaceType );

animation.setContext( session );
animation.start();

//
scope.isPresenting = true;

session.addEventListener( 'inputsourceschange', updateInputSources );
scope.dispatchEvent( { type: 'sessionstart' } );

}

};

function updateInputSources( event ) {
function onInputSourcesChange( event ) {

const inputSources = session.inputSources;

Expand Down

0 comments on commit 6ff1d1b

Please sign in to comment.