2
0
Эх сурвалжийг харах

WebXRManager: Use async/await in setSession().

Mugen87 4 жил өмнө
parent
commit
6ff1d1bd71

+ 2 - 2
examples/jsm/webxr/ARButton.js

@@ -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;

+ 2 - 2
examples/jsm/webxr/VRButton.js

@@ -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;

+ 10 - 19
src/renderers/webxr/WebXRManager.js

@@ -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;
@@ -177,7 +164,7 @@ function WebXRManager( renderer, gl ) {
 
 	};
 
-	this.setSession = function ( value ) {
+	this.setSession = async function ( value ) {
 
 		session = value;
 
@@ -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();
 
 			}
 
@@ -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;