|
@@ -22855,13 +22855,7 @@ function WebXRManager( renderer, gl ) {
|
|
|
var pose = null;
|
|
|
|
|
|
var controllers = [];
|
|
|
- var sortedInputSources = [];
|
|
|
-
|
|
|
- function isPresenting() {
|
|
|
-
|
|
|
- return session !== null && referenceSpace !== null;
|
|
|
-
|
|
|
- }
|
|
|
+ var inputSourcesMap = new Map();
|
|
|
|
|
|
//
|
|
|
|
|
@@ -22881,6 +22875,8 @@ function WebXRManager( renderer, gl ) {
|
|
|
|
|
|
this.enabled = false;
|
|
|
|
|
|
+ this.isPresenting = false;
|
|
|
+
|
|
|
this.getController = function ( id ) {
|
|
|
|
|
|
var controller = controllers[ id ];
|
|
@@ -22903,13 +22899,11 @@ function WebXRManager( renderer, gl ) {
|
|
|
|
|
|
function onSessionEvent( event ) {
|
|
|
|
|
|
- for ( var i = 0; i < controllers.length; i ++ ) {
|
|
|
+ var controller = inputSourcesMap.get( event.inputSource );
|
|
|
|
|
|
- if ( sortedInputSources[ i ] === event.inputSource ) {
|
|
|
+ if ( controller ) {
|
|
|
|
|
|
- controllers[ i ].dispatchEvent( { type: event.type } );
|
|
|
-
|
|
|
- }
|
|
|
+ controller.dispatchEvent( { type: event.type } );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -22917,12 +22911,24 @@ function WebXRManager( renderer, gl ) {
|
|
|
|
|
|
function onSessionEnd() {
|
|
|
|
|
|
+ inputSourcesMap.forEach( function ( controller, inputSource ) {
|
|
|
+
|
|
|
+ controller.dispatchEvent( { type: 'disconnected', data: inputSource } );
|
|
|
+
|
|
|
+ } );
|
|
|
+
|
|
|
+ inputSourcesMap.clear();
|
|
|
+
|
|
|
+ //
|
|
|
+
|
|
|
renderer.setFramebuffer( null );
|
|
|
renderer.setRenderTarget( renderer.getRenderTarget() ); // Hack #15830
|
|
|
animation.stop();
|
|
|
|
|
|
scope.dispatchEvent( { type: 'sessionend' } );
|
|
|
|
|
|
+ scope.isPresenting = false;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
function onRequestReferenceSpace( value ) {
|
|
@@ -22934,6 +22940,8 @@ function WebXRManager( renderer, gl ) {
|
|
|
|
|
|
scope.dispatchEvent( { type: 'sessionstart' } );
|
|
|
|
|
|
+ scope.isPresenting = true;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
this.setFramebufferScaleFactor = function ( /* value */ ) {
|
|
@@ -22988,33 +22996,52 @@ function WebXRManager( renderer, gl ) {
|
|
|
|
|
|
session.addEventListener( 'inputsourceschange', updateInputSources );
|
|
|
|
|
|
- updateInputSources();
|
|
|
-
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
- function updateInputSources() {
|
|
|
+ function updateInputSources( event ) {
|
|
|
+
|
|
|
+ console.log( 'inputsourceschange', event, session.inputSources );
|
|
|
+
|
|
|
+ var inputSources = session.inputSources;
|
|
|
+
|
|
|
+ // Assign inputSources to available controllers
|
|
|
|
|
|
for ( var i = 0; i < controllers.length; i ++ ) {
|
|
|
|
|
|
- sortedInputSources[ i ] = findInputSource( i );
|
|
|
+ inputSourcesMap.set( inputSources[ i ], controllers[ i ] );
|
|
|
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ // Notify disconnected
|
|
|
|
|
|
- function findInputSource( id ) {
|
|
|
+ for ( var i = 0; i < event.removed.length; i ++ ) {
|
|
|
|
|
|
- var inputSources = session.inputSources;
|
|
|
+ var inputSource = event.removed[ i ];
|
|
|
+ var controller = inputSourcesMap.get( inputSource );
|
|
|
|
|
|
- for ( var i = 0; i < inputSources.length; i ++ ) {
|
|
|
+ if ( controller ) {
|
|
|
|
|
|
- var inputSource = inputSources[ i ];
|
|
|
- var handedness = inputSource.handedness;
|
|
|
+ controller.dispatchEvent( { type: 'disconnected', data: inputSource } );
|
|
|
+ inputSourcesMap.delete( inputSource );
|
|
|
|
|
|
- if ( id === 0 && ( handedness === 'none' || handedness === 'right' ) ) return inputSource;
|
|
|
- if ( id === 1 && ( handedness === 'left' ) ) return inputSource;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // Notify connected
|
|
|
+
|
|
|
+ for ( var i = 0; i < event.added.length; i ++ ) {
|
|
|
+
|
|
|
+ var inputSource = event.added[ i ];
|
|
|
+ var controller = inputSourcesMap.get( inputSource );
|
|
|
+
|
|
|
+ if ( controller ) {
|
|
|
+
|
|
|
+ controller.dispatchEvent( { type: 'connected', data: inputSource } );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -23129,8 +23156,6 @@ function WebXRManager( renderer, gl ) {
|
|
|
|
|
|
};
|
|
|
|
|
|
- this.isPresenting = isPresenting;
|
|
|
-
|
|
|
// Animation Loop
|
|
|
|
|
|
var onAnimationFrameCallback = null;
|
|
@@ -23169,11 +23194,13 @@ function WebXRManager( renderer, gl ) {
|
|
|
|
|
|
//
|
|
|
|
|
|
+ var inputSources = session.inputSources;
|
|
|
+
|
|
|
for ( var i = 0; i < controllers.length; i ++ ) {
|
|
|
|
|
|
var controller = controllers[ i ];
|
|
|
|
|
|
- var inputSource = sortedInputSources[ i ];
|
|
|
+ var inputSource = inputSources[ i ];
|
|
|
|
|
|
if ( inputSource ) {
|
|
|
|
|
@@ -23183,12 +23210,7 @@ function WebXRManager( renderer, gl ) {
|
|
|
|
|
|
controller.matrix.fromArray( inputPose.transform.matrix );
|
|
|
controller.matrix.decompose( controller.position, controller.rotation, controller.scale );
|
|
|
-
|
|
|
- if ( inputSource.targetRayMode === 'pointing' ) {
|
|
|
-
|
|
|
- controller.visible = true;
|
|
|
-
|
|
|
- }
|
|
|
+ controller.visible = true;
|
|
|
|
|
|
continue;
|
|
|
|
|
@@ -23559,7 +23581,7 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
this.setSize = function ( width, height, updateStyle ) {
|
|
|
|
|
|
- if ( xr.isPresenting() ) {
|
|
|
+ if ( xr.isPresenting ) {
|
|
|
|
|
|
console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
|
|
|
return;
|
|
@@ -24264,7 +24286,7 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
function onAnimationFrame( time ) {
|
|
|
|
|
|
- if ( xr.isPresenting() ) return;
|
|
|
+ if ( xr.isPresenting ) return;
|
|
|
if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
|
|
|
|
|
|
}
|
|
@@ -24328,7 +24350,7 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
if ( camera.parent === null ) camera.updateMatrixWorld();
|
|
|
|
|
|
- if ( xr.enabled && xr.isPresenting() ) {
|
|
|
+ if ( xr.enabled && xr.isPresenting ) {
|
|
|
|
|
|
camera = xr.getCamera( camera );
|
|
|
|