Skip to content

Commit

Permalink
Examples: Converted ARButton and VRButton to classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdoob committed Sep 12, 2020
1 parent 1fae7ea commit 853f445
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
19 changes: 7 additions & 12 deletions examples/jsm/webxr/ARButton.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
var ARButton = {
class ARButton {

createButton: function ( renderer, sessionInit = {} ) {
static createButton( renderer, sessionInit = {} ) {

const button = document.createElement( 'button' );

function showStartAR( /*device*/ ) {

var currentSession = null;
let currentSession = null;

function onSessionStarted( session ) {

session.addEventListener( 'end', onSessionEnded );

/*
session.updateWorldTrackingState( {
'planeDetectionState': { 'enabled': true }
} );
*/

renderer.xr.setReferenceSpaceType( 'local' );
renderer.xr.setSession( session );
button.textContent = 'STOP AR';
Expand Down Expand Up @@ -114,7 +110,6 @@ var ARButton = {

if ( 'xr' in navigator ) {

var button = document.createElement( 'button' );
button.id = 'ARButton';
button.style.display = 'none';

Expand All @@ -130,7 +125,7 @@ var ARButton = {

} else {

var message = document.createElement( 'a' );
const message = document.createElement( 'a' );

if ( window.isSecureContext === false ) {

Expand All @@ -156,6 +151,6 @@ var ARButton = {

}

};
}

export { ARButton };
15 changes: 8 additions & 7 deletions examples/jsm/webxr/VRButton.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
var VRButton = {
class VRButton {

createButton: function ( renderer, options ) {
static createButton( renderer, options ) {

if ( options ) {

console.error( 'THREE.VRButton: The "options" parameter has been removed. Please set the reference space type via renderer.xr.setReferenceSpaceType() instead.' );

}

const button = document.createElement( 'button' );

function showEnterVR( /*device*/ ) {

var currentSession = null;
let currentSession = null;

function onSessionStarted( session ) {

Expand Down Expand Up @@ -66,7 +68,7 @@ var VRButton = {
// ('local' is always available for immersive sessions and doesn't need to
// be requested separately.)

var sessionInit = { optionalFeatures: [ 'local-floor', 'bounded-floor', 'hand-tracking' ] };
const sessionInit = { optionalFeatures: [ 'local-floor', 'bounded-floor', 'hand-tracking' ] };
navigator.xr.requestSession( 'immersive-vr', sessionInit ).then( onSessionStarted );

} else {
Expand Down Expand Up @@ -121,7 +123,6 @@ var VRButton = {

if ( 'xr' in navigator ) {

var button = document.createElement( 'button' );
button.id = 'VRButton';
button.style.display = 'none';

Expand All @@ -137,7 +138,7 @@ var VRButton = {

} else {

var message = document.createElement( 'a' );
const message = document.createElement( 'a' );

if ( window.isSecureContext === false ) {

Expand All @@ -163,6 +164,6 @@ var VRButton = {

}

};
}

export { VRButton };

0 comments on commit 853f445

Please sign in to comment.