From bd2993d2a0124b8cd3981db791e067edbb977b39 Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Wed, 7 Feb 2024 10:21:39 +0100 Subject: [PATCH 1/2] VRButton: Add `sessionInit` parameter. --- examples/jsm/webxr/VRButton.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/examples/jsm/webxr/VRButton.js b/examples/jsm/webxr/VRButton.js index 54d4c63a677e23..7a4282ed17f0d3 100644 --- a/examples/jsm/webxr/VRButton.js +++ b/examples/jsm/webxr/VRButton.js @@ -1,6 +1,6 @@ class VRButton { - static createButton( renderer ) { + static createButton( renderer, sessionInit = {} ) { const button = document.createElement( 'button' ); @@ -46,7 +46,16 @@ class VRButton { // ('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' ] }; + const sessionOptions = { + ...sessionInit, + optionalFeatures: [ + 'local-floor', + 'bounded-floor', + 'hand-tracking', + 'layers', + ...( sessionInit.optionalFeatures || [] ) + ], + }; button.onmouseenter = function () { @@ -64,7 +73,7 @@ class VRButton { if ( currentSession === null ) { - navigator.xr.requestSession( 'immersive-vr', sessionInit ).then( onSessionStarted ); + navigator.xr.requestSession( 'immersive-vr', sessionOptions ).then( onSessionStarted ); } else { @@ -72,7 +81,7 @@ class VRButton { if ( navigator.xr.offerSession !== undefined ) { - navigator.xr.offerSession( 'immersive-vr', sessionInit ) + navigator.xr.offerSession( 'immersive-vr', sessionOptions ) .then( onSessionStarted ) .catch( ( err ) => { @@ -88,7 +97,7 @@ class VRButton { if ( navigator.xr.offerSession !== undefined ) { - navigator.xr.offerSession( 'immersive-vr', sessionInit ) + navigator.xr.offerSession( 'immersive-vr', sessionOptions ) .then( onSessionStarted ) .catch( ( err ) => { From f6260384f6c45a36c7e959b97a113aca3e47e3af Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Wed, 7 Feb 2024 10:22:15 +0100 Subject: [PATCH 2/2] WebXR: Don't request `hand-tracking` feature by default. --- examples/jsm/webxr/VRButton.js | 1 - examples/jsm/webxr/XRButton.js | 1 - examples/webxr_vr_handinput.html | 6 +++++- examples/webxr_vr_handinput_cubes.html | 6 +++++- examples/webxr_vr_handinput_pointerclick.html | 6 +++++- examples/webxr_vr_handinput_pointerdrag.html | 6 +++++- examples/webxr_vr_handinput_pressbutton.html | 6 +++++- examples/webxr_vr_handinput_profiles.html | 6 +++++- 8 files changed, 30 insertions(+), 8 deletions(-) diff --git a/examples/jsm/webxr/VRButton.js b/examples/jsm/webxr/VRButton.js index 7a4282ed17f0d3..10c362eb86a867 100644 --- a/examples/jsm/webxr/VRButton.js +++ b/examples/jsm/webxr/VRButton.js @@ -51,7 +51,6 @@ class VRButton { optionalFeatures: [ 'local-floor', 'bounded-floor', - 'hand-tracking', 'layers', ...( sessionInit.optionalFeatures || [] ) ], diff --git a/examples/jsm/webxr/XRButton.js b/examples/jsm/webxr/XRButton.js index a43d5319c5a767..34e5d868057dd3 100644 --- a/examples/jsm/webxr/XRButton.js +++ b/examples/jsm/webxr/XRButton.js @@ -45,7 +45,6 @@ class XRButton { optionalFeatures: [ 'local-floor', 'bounded-floor', - 'hand-tracking', 'layers', ...( sessionInit.optionalFeatures || [] ) ], diff --git a/examples/webxr_vr_handinput.html b/examples/webxr_vr_handinput.html index 5fe18158c86881..effdbc7fad00e7 100644 --- a/examples/webxr_vr_handinput.html +++ b/examples/webxr_vr_handinput.html @@ -85,7 +85,11 @@ container.appendChild( renderer.domElement ); - document.body.appendChild( VRButton.createButton( renderer ) ); + const sessionInit = { + optionalFeatures: [ 'hand-tracking' ] + }; + + document.body.appendChild( VRButton.createButton( renderer, sessionInit ) ); // controllers diff --git a/examples/webxr_vr_handinput_cubes.html b/examples/webxr_vr_handinput_cubes.html index 0f1b120ed8cd30..bd794a196c2e4c 100644 --- a/examples/webxr_vr_handinput_cubes.html +++ b/examples/webxr_vr_handinput_cubes.html @@ -98,7 +98,11 @@ container.appendChild( renderer.domElement ); - document.body.appendChild( VRButton.createButton( renderer ) ); + const sessionInit = { + optionalFeatures: [ 'hand-tracking' ] + }; + + document.body.appendChild( VRButton.createButton( renderer, sessionInit ) ); // controllers diff --git a/examples/webxr_vr_handinput_pointerclick.html b/examples/webxr_vr_handinput_pointerclick.html index ad4d695358cc53..6960e286096049 100644 --- a/examples/webxr_vr_handinput_pointerclick.html +++ b/examples/webxr_vr_handinput_pointerclick.html @@ -320,7 +320,11 @@ container.appendChild( renderer.domElement ); - document.body.appendChild( VRButton.createButton( renderer ) ); + const sessionInit = { + optionalFeatures: [ 'hand-tracking' ] + }; + + document.body.appendChild( VRButton.createButton( renderer, sessionInit ) ); // controllers const controller1 = renderer.xr.getController( 0 ); diff --git a/examples/webxr_vr_handinput_pointerdrag.html b/examples/webxr_vr_handinput_pointerdrag.html index 39a297827a0ca3..914cc4b899096c 100644 --- a/examples/webxr_vr_handinput_pointerdrag.html +++ b/examples/webxr_vr_handinput_pointerdrag.html @@ -423,7 +423,11 @@ container.appendChild( renderer.domElement ); - document.body.appendChild( VRButton.createButton( renderer ) ); + const sessionInit = { + optionalFeatures: [ 'hand-tracking' ] + }; + + document.body.appendChild( VRButton.createButton( renderer, sessionInit ) ); // controllers const controller1 = renderer.xr.getController( 0 ); diff --git a/examples/webxr_vr_handinput_pressbutton.html b/examples/webxr_vr_handinput_pressbutton.html index fa632ebf8f29f9..a911a62a22781f 100644 --- a/examples/webxr_vr_handinput_pressbutton.html +++ b/examples/webxr_vr_handinput_pressbutton.html @@ -380,7 +380,11 @@ container.appendChild( renderer.domElement ); - document.body.appendChild( VRButton.createButton( renderer ) ); + const sessionInit = { + optionalFeatures: [ 'hand-tracking' ] + }; + + document.body.appendChild( VRButton.createButton( renderer, sessionInit ) ); // controllers const controller1 = renderer.xr.getController( 0 ); diff --git a/examples/webxr_vr_handinput_profiles.html b/examples/webxr_vr_handinput_profiles.html index 40c3407edfe7ca..7ac39420a7f29e 100644 --- a/examples/webxr_vr_handinput_profiles.html +++ b/examples/webxr_vr_handinput_profiles.html @@ -92,7 +92,11 @@ container.appendChild( renderer.domElement ); - document.body.appendChild( VRButton.createButton( renderer ) ); + const sessionInit = { + optionalFeatures: [ 'hand-tracking' ] + }; + + document.body.appendChild( VRButton.createButton( renderer, sessionInit ) ); // controllers