Skip to content

Commit

Permalink
patch THREE.VRController
Browse files Browse the repository at this point in the history
  • Loading branch information
audionerd committed Jun 3, 2019
1 parent e9db8fe commit 8df4c4e
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/js/express-xr/src/lib/VRController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/**
* @author Stewart Smith / http://stewartsmith.io
* @author Moar Technologies Corp / https://moar.io
* @author Jeff Nusz / http://custom-logic.com
Expand Down Expand Up @@ -661,7 +661,7 @@ THREE.VRController.verbosity = 0//0.5 or 0.7 are good...
// and have some connection / disconnection handlers.

THREE.VRController.controllers = []
THREE.VRController.onGamepadConnect = function( gamepad ){
THREE.VRController.onGamepadConnect = function( gamepad, index ){


// Let’s create a new controller object
Expand All @@ -675,10 +675,10 @@ THREE.VRController.onGamepadConnect = function( gamepad ){


// We also need to store this reference somewhere so that we have a list
// controllers that we know need updating, and by using the gamepad.index
// controllers that we know need updating, and by using the index
// as the key we also know which gamepads have already been found.

scope.controllers[ gamepad.index ] = controller
scope.controllers[ index ] = controller


// Now we’ll broadcast a global connection event.
Expand All @@ -695,7 +695,7 @@ THREE.VRController.onGamepadConnect = function( gamepad ){

}, 500 )
}
THREE.VRController.onGamepadDisconnect = function( gamepad ){
THREE.VRController.onGamepadDisconnect = function( index ){


// We need to find the controller that holds the reference to this gamepad.
Expand All @@ -707,11 +707,11 @@ THREE.VRController.onGamepadDisconnect = function( gamepad ){

var
scope = THREE.VRController,
controller = scope.controllers[ gamepad.index ]
controller = scope.controllers[ index ]

if( scope.verbosity >= 0.5 ) console.log( 'vr controller disconnected', controller )
controller.dispatchEvent({ type: 'disconnected', controller: controller })
scope.controllers[ gamepad.index ] = undefined
scope.controllers[ index ] = undefined
}


Expand Down Expand Up @@ -780,7 +780,7 @@ THREE.VRController.update = function(){

if( gamepad.pose.orientation !== null || gamepad.pose.position !== null ){

if( this.controllers[ i ] === undefined ) THREE.VRController.onGamepadConnect( gamepad )
if( this.controllers[ i ] === undefined ) THREE.VRController.onGamepadConnect( gamepad, i )
this.controllers[ i ].update()
}

Expand All @@ -791,8 +791,10 @@ THREE.VRController.update = function(){
// the controller! (At least in Chromium.) That doesn’t seem like
// the API’s intended behavior but it’s what I see in practice.

else if( this.controllers[ i ] !== undefined ) THREE.VRController.onGamepadDisconnect( gamepad )
else if( this.controllers[ i ] !== undefined ) THREE.VRController.onGamepadDisconnect( i )
}
// If the controller is disconnected and remove then we should update this.controllers accordingly
else if( this.controllers[ i ] !== undefined ) THREE.VRController.onGamepadDisconnect( i );
}
}
THREE.VRController.inspect = function(){
Expand Down

0 comments on commit 8df4c4e

Please sign in to comment.