Skip to content

Commit 6c62224

Browse files
committed
VREffects/VRControls: Reverted internal vrdisplays removal so it doesn't break backward compatibility.
1 parent 32f62a3 commit 6c62224

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

examples/js/controls/VRControls.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ THREE.VRControls = function ( object, onError ) {
77

88
var scope = this;
99

10-
var vrDisplay;
10+
var vrDisplay, vrDisplays;
1111

1212
var standingMatrix = new THREE.Matrix4();
1313

@@ -16,6 +16,28 @@ THREE.VRControls = function ( object, onError ) {
1616
frameData = new VRFrameData();
1717
}
1818

19+
function gotVRDisplays( displays ) {
20+
21+
vrDisplays = displays;
22+
23+
if ( displays.length > 0 ) {
24+
25+
vrDisplay = displays[ 0 ];
26+
27+
} else {
28+
29+
if ( onError ) onError( 'VR input not available.' );
30+
31+
}
32+
33+
}
34+
35+
if ( navigator.getVRDisplays ) {
36+
37+
navigator.getVRDisplays().then( gotVRDisplays );
38+
39+
}
40+
1941
// the Rift SDK returns the position in meters
2042
// this scale factor allows the user to define how meters
2143
// are converted to scene units.

examples/js/effects/VREffect.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
*
1010
*/
1111

12-
THREE.VREffect = function ( renderer ) {
13-
14-
var vrDisplay;
12+
THREE.VREffect = function ( renderer, onError ) {
1513

14+
var vrDisplay, vrDisplays;
1615
var eyeTranslationL = new THREE.Vector3();
1716
var eyeTranslationR = new THREE.Vector3();
1817
var renderRectL, renderRectR;
@@ -24,6 +23,28 @@ THREE.VREffect = function ( renderer ) {
2423

2524
}
2625

26+
function gotVRDisplays( displays ) {
27+
28+
vrDisplays = displays;
29+
30+
if ( displays.length > 0 ) {
31+
32+
vrDisplay = displays[ 0 ];
33+
34+
} else {
35+
36+
if ( onError ) onError( 'HMD not available' );
37+
38+
}
39+
40+
}
41+
42+
if ( navigator.getVRDisplays ) {
43+
44+
navigator.getVRDisplays().then( gotVRDisplays );
45+
46+
}
47+
2748
//
2849

2950
this.isPresenting = false;

0 commit comments

Comments
 (0)