Преглед изворни кода

Add support for offerSession (#27359)

Rik Cabanier пре 1 година
родитељ
комит
11ad176ef5
3 измењених фајлова са 41 додато и 19 уклоњено
  1. 7 0
      examples/jsm/webxr/ARButton.js
  2. 16 8
      examples/jsm/webxr/VRButton.js
  3. 18 11
      examples/jsm/webxr/XRButton.js

+ 7 - 0
examples/jsm/webxr/ARButton.js

@@ -108,6 +108,13 @@ class ARButton {
 
 			};
 
+			if ( navigator.xr.offerSession !== undefined ) {
+
+				navigator.xr.offerSession( 'immersive-ar', sessionInit )
+					.then( onSessionStarted );
+
+			}
+
 		}
 
 		function disableButton() {

+ 16 - 8
examples/jsm/webxr/VRButton.js

@@ -39,6 +39,15 @@ class VRButton {
 
 			button.textContent = 'ENTER VR';
 
+			// WebXR's requestReferenceSpace only works if the corresponding feature
+			// was requested at session creation time. For simplicity, just ask for
+			// the interesting ones as optional features, but be aware that the
+			// requestReferenceSpace call will fail if it turns out to be unavailable.
+			// ('local' is always available for immersive sessions and doesn't need to
+			// be requested separately.)
+
+			const sessionInit = { optionalFeatures: [ 'local-floor', 'bounded-floor', 'hand-tracking', 'layers' ] };
+
 			button.onmouseenter = function () {
 
 				button.style.opacity = '1.0';
@@ -55,14 +64,6 @@ class VRButton {
 
 				if ( currentSession === null ) {
 
-					// WebXR's requestReferenceSpace only works if the corresponding feature
-					// was requested at session creation time. For simplicity, just ask for
-					// the interesting ones as optional features, but be aware that the
-					// requestReferenceSpace call will fail if it turns out to be unavailable.
-					// ('local' is always available for immersive sessions and doesn't need to
-					// be requested separately.)
-
-					const sessionInit = { optionalFeatures: [ 'local-floor', 'bounded-floor', 'hand-tracking', 'layers' ] };
 					navigator.xr.requestSession( 'immersive-vr', sessionInit ).then( onSessionStarted );
 
 				} else {
@@ -73,6 +74,13 @@ class VRButton {
 
 			};
 
+			if ( navigator.xr.offerSession !== undefined ) {
+
+				navigator.xr.offerSession( 'immersive-vr', sessionInit )
+					.then( onSessionStarted );
+
+			}
+
 		}
 
 		function disableButton() {

+ 18 - 11
examples/jsm/webxr/XRButton.js

@@ -40,6 +40,17 @@ class XRButton {
 
 			button.textContent = 'START XR';
 
+			const sessionOptions = {
+				...sessionInit,
+				optionalFeatures: [
+					'local-floor',
+					'bounded-floor',
+					'hand-tracking',
+					'layers',
+					...( sessionInit.optionalFeatures || [] )
+				],
+			};
+
 			button.onmouseenter = function () {
 
 				button.style.opacity = '1.0';
@@ -56,17 +67,6 @@ class XRButton {
 
 				if ( currentSession === null ) {
 
-					const sessionOptions = {
-						...sessionInit,
-						optionalFeatures: [
-							'local-floor',
-							'bounded-floor',
-							'hand-tracking',
-							'layers',
-							...( sessionInit.optionalFeatures || [] )
-						],
-					};
-
 					navigator.xr.requestSession( mode, sessionOptions )
 						.then( onSessionStarted );
 
@@ -78,6 +78,13 @@ class XRButton {
 
 			};
 
+			if ( navigator.xr.offerSession !== undefined ) {
+
+				navigator.xr.offerSession( mode, sessionOptions )
+					.then( onSessionStarted );
+
+			}
+
 		}
 
 		function disableButton() {