diff --git a/examples/js/controls/VRControls.js b/examples/js/controls/VRControls.js index 6dfe937ed884dd520c72bc12affd5fcf838e5bfe..17b1455c2fc6a1782c87b77fa54fe40c6ca1bae4 100644 --- a/examples/js/controls/VRControls.js +++ b/examples/js/controls/VRControls.js @@ -9,18 +9,46 @@ THREE.VRControls = function ( object, onError ) { var vrInputs = []; + function filterInvalidDevices( devices ) { + + var + OculusDeviceId = 'HMDInfo-dev-0x421e7eb800', + CardboardDeviceId = 'HMDInfo-dev-0x421e7ecc00'; + + + // Exclude Cardboard position sensor if Oculus exists. + var oculusDevices = devices.filter( function ( device ) { + + return device.deviceId === OculusDeviceId; + + } ); + + if ( oculusDevices.length >= 1 ) { + + return devices.filter( function ( device ) { + + return device.deviceId !== CardboardDeviceId; + + } ); + + } else { + + return devices; + + } + + } + function gotVRDevices( devices ) { - for ( var i = 0; i < devices.length; i ++ ) { + devices = filterInvalidDevices( devices ); - var device = devices[ i ]; + for ( var i = 0; i < devices.length; i ++ ) { - if ( device instanceof PositionSensorVRDevice ) { + if ( devices[ i ] instanceof PositionSensorVRDevice ) { vrInputs.push( devices[ i ] ); - break; // We keep the first we encounter - } }