Skip to content

Commit 5471265

Browse files
cabanierAdaRoseCannon
authored andcommitted
Add support for offerSession (mrdoob#27359)
1 parent 21a121d commit 5471265

File tree

3 files changed

+41
-19
lines changed

3 files changed

+41
-19
lines changed

examples/jsm/webxr/ARButton.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ class ARButton {
108108

109109
};
110110

111+
if ( navigator.xr.offerSession !== undefined ) {
112+
113+
navigator.xr.offerSession( 'immersive-ar', sessionInit )
114+
.then( onSessionStarted );
115+
116+
}
117+
111118
}
112119

113120
function disableButton() {

examples/jsm/webxr/VRButton.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ class VRButton {
3939

4040
button.textContent = 'ENTER VR';
4141

42+
// WebXR's requestReferenceSpace only works if the corresponding feature
43+
// was requested at session creation time. For simplicity, just ask for
44+
// the interesting ones as optional features, but be aware that the
45+
// requestReferenceSpace call will fail if it turns out to be unavailable.
46+
// ('local' is always available for immersive sessions and doesn't need to
47+
// be requested separately.)
48+
49+
const sessionInit = { optionalFeatures: [ 'local-floor', 'bounded-floor', 'hand-tracking', 'layers' ] };
50+
4251
button.onmouseenter = function () {
4352

4453
button.style.opacity = '1.0';
@@ -55,14 +64,6 @@ class VRButton {
5564

5665
if ( currentSession === null ) {
5766

58-
// WebXR's requestReferenceSpace only works if the corresponding feature
59-
// was requested at session creation time. For simplicity, just ask for
60-
// the interesting ones as optional features, but be aware that the
61-
// requestReferenceSpace call will fail if it turns out to be unavailable.
62-
// ('local' is always available for immersive sessions and doesn't need to
63-
// be requested separately.)
64-
65-
const sessionInit = { optionalFeatures: [ 'local-floor', 'bounded-floor', 'hand-tracking', 'layers' ] };
6667
navigator.xr.requestSession( 'immersive-vr', sessionInit ).then( onSessionStarted );
6768

6869
} else {
@@ -73,6 +74,13 @@ class VRButton {
7374

7475
};
7576

77+
if ( navigator.xr.offerSession !== undefined ) {
78+
79+
navigator.xr.offerSession( 'immersive-vr', sessionInit )
80+
.then( onSessionStarted );
81+
82+
}
83+
7684
}
7785

7886
function disableButton() {

examples/jsm/webxr/XRButton.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ class XRButton {
4040

4141
button.textContent = 'START XR';
4242

43+
const sessionOptions = {
44+
...sessionInit,
45+
optionalFeatures: [
46+
'local-floor',
47+
'bounded-floor',
48+
'hand-tracking',
49+
'layers',
50+
...( sessionInit.optionalFeatures || [] )
51+
],
52+
};
53+
4354
button.onmouseenter = function () {
4455

4556
button.style.opacity = '1.0';
@@ -56,17 +67,6 @@ class XRButton {
5667

5768
if ( currentSession === null ) {
5869

59-
const sessionOptions = {
60-
...sessionInit,
61-
optionalFeatures: [
62-
'local-floor',
63-
'bounded-floor',
64-
'hand-tracking',
65-
'layers',
66-
...( sessionInit.optionalFeatures || [] )
67-
],
68-
};
69-
7070
navigator.xr.requestSession( mode, sessionOptions )
7171
.then( onSessionStarted );
7272

@@ -78,6 +78,13 @@ class XRButton {
7878

7979
};
8080

81+
if ( navigator.xr.offerSession !== undefined ) {
82+
83+
navigator.xr.offerSession( mode, sessionOptions )
84+
.then( onSessionStarted );
85+
86+
}
87+
8188
}
8289

8390
function disableButton() {

0 commit comments

Comments
 (0)