|
@@ -24,13 +24,7 @@ function WebXRManager( renderer, gl ) {
|
|
|
var pose = null;
|
|
|
|
|
|
var controllers = [];
|
|
|
- var sortedInputSources = [];
|
|
|
-
|
|
|
- function isPresenting() {
|
|
|
-
|
|
|
- return session !== null && referenceSpace !== null;
|
|
|
-
|
|
|
- }
|
|
|
+ var inputSourcesMap = new Map();
|
|
|
|
|
|
//
|
|
|
|
|
@@ -50,6 +44,8 @@ function WebXRManager( renderer, gl ) {
|
|
|
|
|
|
this.enabled = false;
|
|
|
|
|
|
+ this.isPresenting = false;
|
|
|
+
|
|
|
this.getController = function ( id ) {
|
|
|
|
|
|
var controller = controllers[ id ];
|
|
@@ -72,13 +68,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 } );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -86,12 +80,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 ) {
|
|
@@ -103,6 +109,8 @@ function WebXRManager( renderer, gl ) {
|
|
|
|
|
|
scope.dispatchEvent( { type: 'sessionstart' } );
|
|
|
|
|
|
+ scope.isPresenting = true;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
this.setFramebufferScaleFactor = function ( /* value */ ) {
|
|
@@ -157,33 +165,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 );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // Notify connected
|
|
|
+
|
|
|
+ for ( var i = 0; i < event.added.length; i ++ ) {
|
|
|
+
|
|
|
+ var inputSource = event.added[ i ];
|
|
|
+ var controller = inputSourcesMap.get( inputSource );
|
|
|
|
|
|
- if ( id === 0 && ( handedness === 'none' || handedness === 'right' ) ) return inputSource;
|
|
|
- if ( id === 1 && ( handedness === 'left' ) ) return inputSource;
|
|
|
+ if ( controller ) {
|
|
|
+
|
|
|
+ controller.dispatchEvent( { type: 'connected', data: inputSource } );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -298,8 +325,6 @@ function WebXRManager( renderer, gl ) {
|
|
|
|
|
|
};
|
|
|
|
|
|
- this.isPresenting = isPresenting;
|
|
|
-
|
|
|
// Animation Loop
|
|
|
|
|
|
var onAnimationFrameCallback = null;
|
|
@@ -338,11 +363,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 ) {
|
|
|
|
|
@@ -352,12 +379,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;
|
|
|
|