Jelajahi Sumber

VREffects/VRControls: Reverted internal vrdisplays removal so it doesn't break backward compatibility.

Mr.doob 8 tahun lalu
induk
melakukan
6c622248fd
2 mengubah file dengan 47 tambahan dan 4 penghapusan
  1. 23 1
      examples/js/controls/VRControls.js
  2. 24 3
      examples/js/effects/VREffect.js

+ 23 - 1
examples/js/controls/VRControls.js

@@ -7,7 +7,7 @@ THREE.VRControls = function ( object, onError ) {
 
 	var scope = this;
 
-	var vrDisplay;
+	var vrDisplay, vrDisplays;
 
 	var standingMatrix = new THREE.Matrix4();
 
@@ -16,6 +16,28 @@ THREE.VRControls = function ( object, onError ) {
 		frameData = new VRFrameData();
 	}
 
+	function gotVRDisplays( displays ) {
+
+		vrDisplays = displays;
+
+		if ( displays.length > 0 ) {
+
+			vrDisplay = displays[ 0 ];
+
+		} else {
+
+			if ( onError ) onError( 'VR input not available.' );
+
+		}
+
+	}
+
+	if ( navigator.getVRDisplays ) {
+
+		navigator.getVRDisplays().then( gotVRDisplays );
+
+	}
+
 	// the Rift SDK returns the position in meters
 	// this scale factor allows the user to define how meters
 	// are converted to scene units.

+ 24 - 3
examples/js/effects/VREffect.js

@@ -9,10 +9,9 @@
  *
  */
 
-THREE.VREffect = function ( renderer ) {
-
-	var vrDisplay;
+THREE.VREffect = function ( renderer, onError ) {
 
+	var vrDisplay, vrDisplays;
 	var eyeTranslationL = new THREE.Vector3();
 	var eyeTranslationR = new THREE.Vector3();
 	var renderRectL, renderRectR;
@@ -24,6 +23,28 @@ THREE.VREffect = function ( renderer ) {
 
 	}
 
+	function gotVRDisplays( displays ) {
+
+		vrDisplays = displays;
+
+		if ( displays.length > 0 ) {
+
+			vrDisplay = displays[ 0 ];
+
+		} else {
+
+			if ( onError ) onError( 'HMD not available' );
+
+		}
+
+	}
+
+	if ( navigator.getVRDisplays ) {
+
+		navigator.getVRDisplays().then( gotVRDisplays );
+
+	}
+
 	//
 
 	this.isPresenting = false;