@@ -13,14 +13,11 @@ function initWebVR() {
13
13
// Set up Three.js
14
14
initThreeJS ( ) ;
15
15
16
- // Set up VR rendering
17
- initVREffect ( ) ;
18
-
19
16
// Create the scene content
20
17
initScene ( ) ;
21
18
22
- // Set up VR camera controls
23
- initVRControls ( ) ;
19
+ // Set up VR rendering and camera controls (if available)
20
+ initVR ( ) ;
24
21
25
22
// Set the viewport size and aspect ratio
26
23
refreshSize ( ) ;
@@ -43,7 +40,12 @@ function run(time) {
43
40
lastTime = time ;
44
41
45
42
// Render the scene
46
- effect . render ( scene , camera ) ;
43
+ if ( effect ) {
44
+ effect . render ( scene , camera ) ;
45
+ }
46
+ else {
47
+ renderer . render ( scene , camera ) ;
48
+ }
47
49
48
50
// Update the VR camera controls
49
51
controls . update ( ) ;
@@ -66,41 +68,6 @@ function initThreeJS() {
66
68
67
69
window . addEventListener ( 'resize' , refreshSize , false ) ;
68
70
69
- if ( navigator . getVRDisplays ) {
70
- navigator . getVRDisplays ( ) . then ( function ( displays ) {
71
- if ( displays . length > 0 ) {
72
- vrDisplay = displays [ 0 ] ;
73
-
74
- /* initWebGL(true);
75
-
76
- if (vrDisplay.stageParameters) {
77
- // If we have stageParameters use that to resize our scene to
78
- // match the users available space more closely.
79
- cubeIsland.resize(vrDisplay.stageParameters.sizeX, vrDisplay.stageParameters.sizeZ);
80
- } else {
81
- VRSamplesUtil.addInfo("VRDisplay did not report stageParameters", 3000);
82
- // Resetting the pose in standing space isn't useful, because the
83
- // headset should always be relative to the physical room.
84
- VRSamplesUtil.addButton("Reset Pose", "R", null, function () { vrDisplay.resetPose(); });
85
- }
86
-
87
- if (vrDisplay.capabilities.canPresent)
88
- vrPresentButton = VRSamplesUtil.addButton("Enter VR", "E", "media/icons/cardboard64.png", onVRRequestPresent);
89
-
90
- window.addEventListener('vrdisplaypresentchange', onVRPresentChange, false);*/
91
- } else {
92
- /*initWebGL(false);
93
- VRSamplesUtil.addInfo("WebVR supported, but no VRDisplays found.", 3000);*/
94
- }
95
- } ) ;
96
- } else if ( navigator . getVRDevices ) {
97
- // initWebGL(false);
98
- console . log ( "Your browser supports WebVR but not the latest version. See <a href='http://webvr.info'>webvr.info</a> for more info." ) ;
99
- } else {
100
- // initWebGL(false);
101
- console . log ( "Your browser does not support WebVR. See <a href='http://webvr.info'>webvr.info</a> for assistance." ) ;
102
- }
103
-
104
71
}
105
72
106
73
function refreshSize ( ) {
@@ -152,6 +119,50 @@ function refreshSize ( ) {
152
119
153
120
}
154
121
122
+ function initScene ( ) {
123
+ // Create a new Three.js scene
124
+ scene = new THREE . Scene ( ) ;
125
+
126
+ // Add a camera so we can view the scene
127
+ // Note that this camera's FOV is ignored in favor of the
128
+ // Oculus-supplied FOV for each used inside VREffect.
129
+ // See VREffect.js h/t Michael Blix
130
+ camera = new THREE . PerspectiveCamera ( 90 , window . innerWidth / window . innerHeight , 0.01 , 4000 ) ;
131
+ camera . position . z = 5 ; //NOTE: this will be ignored if there is a valid VR device but is needed on desktop view
132
+ scene . add ( camera ) ;
133
+ }
134
+
135
+ function initVR ( ) {
136
+
137
+ var gotVR = false ;
138
+
139
+ if ( navigator . getVRDisplays ) {
140
+ navigator . getVRDisplays ( ) . then ( function ( displays ) {
141
+ if ( displays . length > 0 ) {
142
+ vrDisplay = displays [ 0 ] ;
143
+
144
+ initVREffect ( ) ;
145
+ initVRControls ( ) ;
146
+ } else {
147
+ console . log ( "WebVR supported, but no VRDisplays found." ) ;
148
+ }
149
+
150
+ } ) ;
151
+
152
+ gotVR = true ;
153
+ } else if ( navigator . getVRDevices ) {
154
+ // initWebGL(false);
155
+ console . log ( "Your browser supports WebVR but not the latest version. See <a href='http://webvr.info'>webvr.info</a> for more info." ) ;
156
+ } else {
157
+ // initWebGL(false);
158
+ console . log ( "Your browser does not support WebVR. See <a href='http://webvr.info'>webvr.info</a> for assistance." ) ;
159
+ }
160
+
161
+ if ( ! gotVR ) {
162
+ initOrbitControls ( ) ;
163
+ }
164
+ }
165
+
155
166
function initVREffect ( ) {
156
167
157
168
// Set up Oculus renderer
@@ -183,19 +194,6 @@ function initVREffect() {
183
194
} ) ;
184
195
}
185
196
186
- function initScene ( ) {
187
- // Create a new Three.js scene
188
- scene = new THREE . Scene ( ) ;
189
-
190
- // Add a camera so we can view the scene
191
- // Note that this camera's FOV is ignored in favor of the
192
- // Oculus-supplied FOV for each used inside VREffect.
193
- // See VREffect.js h/t Michael Blix
194
- camera = new THREE . PerspectiveCamera ( 90 , window . innerWidth / window . innerHeight , 0.01 , 4000 ) ;
195
- camera . position . z = 5 ; //NOTE: this will be ignored if there is a valid VR device but is needed on desktop view
196
- scene . add ( camera ) ;
197
- }
198
-
199
197
function initVRControls ( ) {
200
198
201
199
// Set up VR camera controls
@@ -207,4 +205,10 @@ function initVRControls() {
207
205
console . log ( "Created VRControls: " , controls ) ;
208
206
}
209
207
} ) ;
208
+ }
209
+
210
+ function initOrbitControls ( ) {
211
+
212
+ controls = new THREE . OrbitControls ( this . camera , renderer . domElement ) ;
213
+
210
214
}
0 commit comments