File tree Expand file tree Collapse file tree 4 files changed +27
-60
lines changed Expand file tree Collapse file tree 4 files changed +27
-60
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ THREE.VRControls = function ( object, onError ) {
7
7
8
8
var scope = this ;
9
9
10
- var vrDisplay , vrDisplays ;
10
+ var vrDisplay ;
11
11
12
12
var standingMatrix = new THREE . Matrix4 ( ) ;
13
13
@@ -16,28 +16,6 @@ THREE.VRControls = function ( object, onError ) {
16
16
frameData = new VRFrameData ( ) ;
17
17
}
18
18
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
-
41
19
// the Rift SDK returns the position in meters
42
20
// this scale factor allows the user to define how meters
43
21
// are converted to scene units.
@@ -52,15 +30,15 @@ THREE.VRControls = function ( object, onError ) {
52
30
// standing=true but the VRDisplay doesn't provide stageParameters.
53
31
this . userHeight = 1.6 ;
54
32
55
- this . getVRDisplay = function ( ) {
33
+ this . setDisplay = function ( display ) {
56
34
57
- return vrDisplay ;
35
+ vrDisplay = display ;
58
36
59
37
} ;
60
38
61
- this . getVRDisplays = function ( ) {
39
+ this . getDisplay = function ( ) {
62
40
63
- return vrDisplays ;
41
+ return vrDisplay ;
64
42
65
43
} ;
66
44
Original file line number Diff line number Diff line change 9
9
*
10
10
*/
11
11
12
- THREE . VREffect = function ( renderer , onError ) {
12
+ THREE . VREffect = function ( renderer ) {
13
+
14
+ var vrDisplay ;
13
15
14
- var vrDisplay , vrDisplays ;
15
16
var eyeTranslationL = new THREE . Vector3 ( ) ;
16
17
var eyeTranslationR = new THREE . Vector3 ( ) ;
17
18
var renderRectL , renderRectR ;
@@ -23,28 +24,6 @@ THREE.VREffect = function ( renderer, onError ) {
23
24
24
25
}
25
26
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
-
48
27
//
49
28
50
29
this . isPresenting = false ;
@@ -56,15 +35,15 @@ THREE.VREffect = function ( renderer, onError ) {
56
35
var rendererUpdateStyle = false ;
57
36
var rendererPixelRatio = renderer . getPixelRatio ( ) ;
58
37
59
- this . getVRDisplay = function ( ) {
38
+ this . setDisplay = function ( display ) {
60
39
61
- return vrDisplay ;
40
+ vrDisplay = display ;
62
41
63
42
} ;
64
43
65
- this . getVRDisplays = function ( ) {
44
+ this . getDisplay = function ( ) {
66
45
67
- return vrDisplays ;
46
+ return vrDisplay ;
68
47
69
48
} ;
70
49
Original file line number Diff line number Diff line change @@ -100,6 +100,12 @@ var WEBVR = {
100
100
101
101
return button ;
102
102
103
+ } ,
104
+
105
+ getDisplays : function ( ) {
106
+
107
+ return navigator . getVRDisplays ( ) ;
108
+
103
109
}
104
110
105
111
} ;
Original file line number Diff line number Diff line change 130
130
controls = new THREE . VRControls ( camera ) ;
131
131
effect = new THREE . VREffect ( renderer ) ;
132
132
133
- if ( WEBVR . isAvailable ( ) === true ) {
134
-
135
- document . body . appendChild ( WEBVR . getButton ( effect ) ) ;
136
-
137
- }
133
+ WEBVR . getDisplays ( )
134
+ . then ( function ( displays ) {
135
+ effect . setDisplay ( displays [ 0 ] ) ;
136
+ controls . setDisplay ( displays [ 0 ] ) ;
137
+ document . body . appendChild ( WEBVR . getButton ( effect ) ) ;
138
+ } )
139
+ . catch ( function ( ) {
140
+ // no displays
141
+ } ) ;
138
142
139
143
renderer . domElement . addEventListener ( 'mousedown' , onMouseDown , false ) ;
140
144
renderer . domElement . addEventListener ( 'mouseup' , onMouseUp , false ) ;
You can’t perform that action at this time.
0 commit comments