Pārlūkot izejas kodu

Allow multiple sensors, exclude phantom Carboard

Brian Peiris 10 gadi atpakaļ
vecāks
revīzija
6a9b1ec657
1 mainītis faili ar 33 papildinājumiem un 5 dzēšanām
  1. 33 5
      examples/js/controls/VRControls.js

+ 33 - 5
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
-
 			}
 
 		}