super-three 0.169.0 → 0.169.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/three.cjs +15 -569
- package/build/three.module.js +15 -569
- package/build/three.module.min.js +1 -1
- package/package.json +1 -1
- package/src/renderers/WebGLRenderer.js +1 -9
- package/src/renderers/webvr/WebVRManager.js +0 -495
- package/src/renderers/webvr/WebVRUtils.js +0 -66
package/package.json
CHANGED
|
@@ -52,7 +52,6 @@ import { WebGLState } from './webgl/WebGLState.js';
|
|
|
52
52
|
import { WebGLTextures } from './webgl/WebGLTextures.js';
|
|
53
53
|
import { WebGLUniforms } from './webgl/WebGLUniforms.js';
|
|
54
54
|
import { WebGLUtils } from './webgl/WebGLUtils.js';
|
|
55
|
-
import { WebVRManager } from './webvr/WebVRManager.js';
|
|
56
55
|
import { WebXRManager } from './webxr/WebXRManager.js';
|
|
57
56
|
import { WebGLMaterials } from './webgl/WebGLMaterials.js';
|
|
58
57
|
import { WebGLUniformsGroups } from './webgl/WebGLUniformsGroups.js';
|
|
@@ -337,7 +336,7 @@ class WebGLRenderer {
|
|
|
337
336
|
|
|
338
337
|
// xr
|
|
339
338
|
|
|
340
|
-
const xr =
|
|
339
|
+
const xr = new WebXRManager( _this, _gl );
|
|
341
340
|
|
|
342
341
|
this.xr = xr;
|
|
343
342
|
|
|
@@ -1297,13 +1296,6 @@ class WebGLRenderer {
|
|
|
1297
1296
|
|
|
1298
1297
|
if ( scene.isScene === true ) scene.onAfterRender( _this, scene, camera );
|
|
1299
1298
|
|
|
1300
|
-
textures.runDeferredUploads();
|
|
1301
|
-
|
|
1302
|
-
if ( xr.enabled && xr.submitFrame ) {
|
|
1303
|
-
|
|
1304
|
-
xr.submitFrame();
|
|
1305
|
-
|
|
1306
|
-
}
|
|
1307
1299
|
// _gl.finish();
|
|
1308
1300
|
|
|
1309
1301
|
bindingStates.resetDefaultState();
|
|
@@ -1,495 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author mrdoob / http://mrdoob.com/
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { EventDispatcher } from '../../core/EventDispatcher.js';
|
|
6
|
-
import { Group } from '../../objects/Group.js';
|
|
7
|
-
import { Matrix4 } from '../../math/Matrix4.js';
|
|
8
|
-
import { Vector2 } from '../../math/Vector2.js';
|
|
9
|
-
import { Vector3 } from '../../math/Vector3.js';
|
|
10
|
-
import { Vector4 } from '../../math/Vector4.js';
|
|
11
|
-
import { Quaternion } from '../../math/Quaternion.js';
|
|
12
|
-
import { ArrayCamera } from '../../cameras/ArrayCamera.js';
|
|
13
|
-
import { PerspectiveCamera } from '../../cameras/PerspectiveCamera.js';
|
|
14
|
-
import { WebGLAnimation } from '../webgl/WebGLAnimation.js';
|
|
15
|
-
import { setProjectionFromUnion } from './WebVRUtils.js';
|
|
16
|
-
|
|
17
|
-
function WebVRManager( renderer ) {
|
|
18
|
-
|
|
19
|
-
var renderWidth, renderHeight;
|
|
20
|
-
var scope = this;
|
|
21
|
-
|
|
22
|
-
var device = null;
|
|
23
|
-
var frameData = null;
|
|
24
|
-
|
|
25
|
-
var poseTarget = null;
|
|
26
|
-
|
|
27
|
-
var controllers = [];
|
|
28
|
-
var standingMatrix = new Matrix4();
|
|
29
|
-
var standingMatrixInverse = new Matrix4();
|
|
30
|
-
|
|
31
|
-
var framebufferScaleFactor = 1.0;
|
|
32
|
-
|
|
33
|
-
var referenceSpaceType = 'local-floor';
|
|
34
|
-
|
|
35
|
-
if ( typeof window !== 'undefined' && 'VRFrameData' in window ) {
|
|
36
|
-
|
|
37
|
-
frameData = new window.VRFrameData();
|
|
38
|
-
window.addEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange, false );
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
var matrixWorldInverse = new Matrix4();
|
|
43
|
-
var tempQuaternion = new Quaternion();
|
|
44
|
-
var tempPosition = new Vector3();
|
|
45
|
-
|
|
46
|
-
var cameraL = new PerspectiveCamera();
|
|
47
|
-
cameraL.viewport = new Vector4();
|
|
48
|
-
cameraL.layers.enable( 1 );
|
|
49
|
-
|
|
50
|
-
var cameraR = new PerspectiveCamera();
|
|
51
|
-
cameraR.viewport = new Vector4();
|
|
52
|
-
cameraR.layers.enable( 2 );
|
|
53
|
-
|
|
54
|
-
var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
|
|
55
|
-
cameraVR.layers.enable( 1 );
|
|
56
|
-
cameraVR.layers.enable( 2 );
|
|
57
|
-
|
|
58
|
-
var currentSize = new Vector2(), currentPixelRatio;
|
|
59
|
-
|
|
60
|
-
function onVRDisplayPresentChange() {
|
|
61
|
-
|
|
62
|
-
var isPresenting = scope.isPresenting = device !== null && device.isPresenting === true;
|
|
63
|
-
|
|
64
|
-
if ( isPresenting ) {
|
|
65
|
-
|
|
66
|
-
var eyeParameters = device.getEyeParameters( 'left' );
|
|
67
|
-
renderWidth = 2 * eyeParameters.renderWidth * framebufferScaleFactor;
|
|
68
|
-
renderHeight = eyeParameters.renderHeight * framebufferScaleFactor;
|
|
69
|
-
|
|
70
|
-
currentPixelRatio = renderer.getPixelRatio();
|
|
71
|
-
renderer.getSize( currentSize );
|
|
72
|
-
|
|
73
|
-
renderer.setDrawingBufferSize( renderWidth, renderHeight, 1 );
|
|
74
|
-
|
|
75
|
-
cameraL.viewport.set( 0, 0, renderWidth / 2, renderHeight );
|
|
76
|
-
cameraR.viewport.set( renderWidth / 2, 0, renderWidth / 2, renderHeight );
|
|
77
|
-
|
|
78
|
-
animation.start();
|
|
79
|
-
|
|
80
|
-
scope.dispatchEvent( { type: 'sessionstart' } );
|
|
81
|
-
|
|
82
|
-
} else {
|
|
83
|
-
|
|
84
|
-
if ( scope.enabled ) {
|
|
85
|
-
|
|
86
|
-
renderer.setDrawingBufferSize( currentSize.width, currentSize.height, currentPixelRatio );
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
animation.stop();
|
|
91
|
-
|
|
92
|
-
scope.dispatchEvent( { type: 'sessionend' } );
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
//
|
|
99
|
-
|
|
100
|
-
var triggers = [];
|
|
101
|
-
var grips = [];
|
|
102
|
-
|
|
103
|
-
function findGamepad( id ) {
|
|
104
|
-
|
|
105
|
-
var gamepads = navigator.getGamepads && navigator.getGamepads();
|
|
106
|
-
|
|
107
|
-
for ( var i = 0, l = gamepads.length; i < l; i ++ ) {
|
|
108
|
-
|
|
109
|
-
var gamepad = gamepads[ i ];
|
|
110
|
-
|
|
111
|
-
if ( gamepad && ( gamepad.id === 'Daydream Controller' ||
|
|
112
|
-
gamepad.id === 'Gear VR Controller' || gamepad.id === 'Oculus Go Controller' ||
|
|
113
|
-
gamepad.id === 'OpenVR Gamepad' || gamepad.id.startsWith( 'Oculus Touch' ) ||
|
|
114
|
-
gamepad.id.startsWith( 'HTC Vive Focus' ) ||
|
|
115
|
-
gamepad.id.startsWith( 'Spatial Controller' ) ) ) {
|
|
116
|
-
|
|
117
|
-
var hand = gamepad.hand;
|
|
118
|
-
|
|
119
|
-
if ( id === 0 && ( hand === '' || hand === 'right' ) ) return gamepad;
|
|
120
|
-
if ( id === 1 && ( hand === 'left' ) ) return gamepad;
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function updateControllers() {
|
|
129
|
-
|
|
130
|
-
for ( var i = 0; i < controllers.length; i ++ ) {
|
|
131
|
-
|
|
132
|
-
var controller = controllers[ i ];
|
|
133
|
-
|
|
134
|
-
var gamepad = findGamepad( i );
|
|
135
|
-
|
|
136
|
-
if ( gamepad !== undefined && gamepad.pose !== undefined ) {
|
|
137
|
-
|
|
138
|
-
if ( gamepad.pose === null ) return;
|
|
139
|
-
|
|
140
|
-
// Pose
|
|
141
|
-
|
|
142
|
-
var pose = gamepad.pose;
|
|
143
|
-
|
|
144
|
-
if ( pose.hasPosition === false ) controller.position.set( 0.2, - 0.6, - 0.05 );
|
|
145
|
-
|
|
146
|
-
if ( pose.position !== null ) controller.position.fromArray( pose.position );
|
|
147
|
-
if ( pose.orientation !== null ) controller.quaternion.fromArray( pose.orientation );
|
|
148
|
-
controller.matrix.compose( controller.position, controller.quaternion, controller.scale );
|
|
149
|
-
controller.matrix.premultiply( standingMatrix );
|
|
150
|
-
controller.matrix.decompose( controller.position, controller.quaternion, controller.scale );
|
|
151
|
-
controller.matrixWorldNeedsUpdate = true;
|
|
152
|
-
controller.visible = true;
|
|
153
|
-
|
|
154
|
-
// Trigger
|
|
155
|
-
|
|
156
|
-
var buttonId = gamepad.id === 'Daydream Controller' ? 0 : 1;
|
|
157
|
-
|
|
158
|
-
if ( triggers[ i ] === undefined ) triggers[ i ] = false;
|
|
159
|
-
|
|
160
|
-
if ( triggers[ i ] !== gamepad.buttons[ buttonId ].pressed ) {
|
|
161
|
-
|
|
162
|
-
triggers[ i ] = gamepad.buttons[ buttonId ].pressed;
|
|
163
|
-
|
|
164
|
-
if ( triggers[ i ] === true ) {
|
|
165
|
-
|
|
166
|
-
controller.dispatchEvent( { type: 'selectstart' } );
|
|
167
|
-
|
|
168
|
-
} else {
|
|
169
|
-
|
|
170
|
-
controller.dispatchEvent( { type: 'selectend' } );
|
|
171
|
-
controller.dispatchEvent( { type: 'select' } );
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// Grip
|
|
178
|
-
buttonId = 2;
|
|
179
|
-
|
|
180
|
-
if ( grips[ i ] === undefined ) grips[ i ] = false;
|
|
181
|
-
|
|
182
|
-
// Skip if the grip button doesn't exist on this controller
|
|
183
|
-
if ( gamepad.buttons[ buttonId ] !== undefined ) {
|
|
184
|
-
|
|
185
|
-
if ( grips[ i ] !== gamepad.buttons[ buttonId ].pressed ) {
|
|
186
|
-
|
|
187
|
-
grips[ i ] = gamepad.buttons[ buttonId ].pressed;
|
|
188
|
-
|
|
189
|
-
if ( grips[ i ] === true ) {
|
|
190
|
-
|
|
191
|
-
controller.dispatchEvent( { type: 'squeezestart' } );
|
|
192
|
-
|
|
193
|
-
} else {
|
|
194
|
-
|
|
195
|
-
controller.dispatchEvent( { type: 'squeezeend' } );
|
|
196
|
-
controller.dispatchEvent( { type: 'squeeze' } );
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
} else {
|
|
205
|
-
|
|
206
|
-
controller.visible = false;
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function updateViewportFromBounds( viewport, bounds ) {
|
|
215
|
-
|
|
216
|
-
if ( bounds !== null && bounds.length === 4 ) {
|
|
217
|
-
|
|
218
|
-
viewport.set( bounds[ 0 ] * renderWidth, bounds[ 1 ] * renderHeight, bounds[ 2 ] * renderWidth, bounds[ 3 ] * renderHeight );
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
//
|
|
225
|
-
|
|
226
|
-
this.enabled = false;
|
|
227
|
-
|
|
228
|
-
this.getController = function ( id ) {
|
|
229
|
-
|
|
230
|
-
var controller = controllers[ id ];
|
|
231
|
-
|
|
232
|
-
if ( controller === undefined ) {
|
|
233
|
-
|
|
234
|
-
controller = new Group();
|
|
235
|
-
controller.matrixAutoUpdate = false;
|
|
236
|
-
controller.visible = false;
|
|
237
|
-
|
|
238
|
-
controllers[ id ] = controller;
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return controller;
|
|
243
|
-
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
this.getDevice = function () {
|
|
247
|
-
|
|
248
|
-
return device;
|
|
249
|
-
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
this.setDevice = function ( value ) {
|
|
253
|
-
|
|
254
|
-
if ( value !== undefined ) device = value;
|
|
255
|
-
|
|
256
|
-
animation.setContext( value );
|
|
257
|
-
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
this.setFramebufferScaleFactor = function ( value ) {
|
|
261
|
-
|
|
262
|
-
framebufferScaleFactor = value;
|
|
263
|
-
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
this.setReferenceSpaceType = function ( value ) {
|
|
267
|
-
|
|
268
|
-
referenceSpaceType = value;
|
|
269
|
-
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
this.setPoseTarget = function ( object ) {
|
|
273
|
-
|
|
274
|
-
if ( object !== undefined ) poseTarget = object;
|
|
275
|
-
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
//
|
|
279
|
-
|
|
280
|
-
this.cameraAutoUpdate = true;
|
|
281
|
-
|
|
282
|
-
this.updateCamera = function ( camera ) {
|
|
283
|
-
|
|
284
|
-
var userHeight = referenceSpaceType === 'local-floor' ? 1.6 : 0;
|
|
285
|
-
|
|
286
|
-
device.depthNear = camera.near;
|
|
287
|
-
device.depthFar = camera.far;
|
|
288
|
-
|
|
289
|
-
device.getFrameData( frameData );
|
|
290
|
-
|
|
291
|
-
//
|
|
292
|
-
|
|
293
|
-
if ( referenceSpaceType === 'local-floor' ) {
|
|
294
|
-
|
|
295
|
-
var stageParameters = device.stageParameters;
|
|
296
|
-
|
|
297
|
-
if ( stageParameters ) {
|
|
298
|
-
|
|
299
|
-
standingMatrix.fromArray( stageParameters.sittingToStandingTransform );
|
|
300
|
-
|
|
301
|
-
} else {
|
|
302
|
-
|
|
303
|
-
standingMatrix.makeTranslation( 0, userHeight, 0 );
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
var pose = frameData.pose;
|
|
311
|
-
var poseObject = poseTarget !== null ? poseTarget : camera;
|
|
312
|
-
|
|
313
|
-
// We want to manipulate poseObject by its position and quaternion components since users may rely on them.
|
|
314
|
-
poseObject.matrix.copy( standingMatrix );
|
|
315
|
-
poseObject.matrix.decompose( poseObject.position, poseObject.quaternion, poseObject.scale );
|
|
316
|
-
|
|
317
|
-
if ( pose.orientation !== null ) {
|
|
318
|
-
|
|
319
|
-
tempQuaternion.fromArray( pose.orientation );
|
|
320
|
-
poseObject.quaternion.multiply( tempQuaternion );
|
|
321
|
-
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
if ( pose.position !== null ) {
|
|
325
|
-
|
|
326
|
-
tempQuaternion.setFromRotationMatrix( standingMatrix );
|
|
327
|
-
tempPosition.fromArray( pose.position );
|
|
328
|
-
tempPosition.applyQuaternion( tempQuaternion );
|
|
329
|
-
poseObject.position.add( tempPosition );
|
|
330
|
-
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
poseObject.updateMatrixWorld();
|
|
334
|
-
|
|
335
|
-
var children = poseObject.children;
|
|
336
|
-
for ( var i = 0, l = children.length; i < l; i ++ ) {
|
|
337
|
-
|
|
338
|
-
children[ i ].updateMatrixWorld( true );
|
|
339
|
-
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
//
|
|
343
|
-
|
|
344
|
-
cameraL.near = camera.near;
|
|
345
|
-
cameraR.near = camera.near;
|
|
346
|
-
|
|
347
|
-
cameraL.far = camera.far;
|
|
348
|
-
cameraR.far = camera.far;
|
|
349
|
-
|
|
350
|
-
cameraL.matrixWorldInverse.fromArray( frameData.leftViewMatrix );
|
|
351
|
-
cameraR.matrixWorldInverse.fromArray( frameData.rightViewMatrix );
|
|
352
|
-
|
|
353
|
-
// TODO (mrdoob) Double check this code
|
|
354
|
-
|
|
355
|
-
standingMatrixInverse.copy( standingMatrix ).invert();
|
|
356
|
-
|
|
357
|
-
if ( referenceSpaceType === 'local-floor' ) {
|
|
358
|
-
|
|
359
|
-
cameraL.matrixWorldInverse.multiply( standingMatrixInverse );
|
|
360
|
-
cameraR.matrixWorldInverse.multiply( standingMatrixInverse );
|
|
361
|
-
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
var parent = poseObject.parent;
|
|
365
|
-
|
|
366
|
-
if ( parent !== null ) {
|
|
367
|
-
|
|
368
|
-
matrixWorldInverse.copy( parent.matrixWorld ).invert();
|
|
369
|
-
|
|
370
|
-
cameraL.matrixWorldInverse.multiply( matrixWorldInverse );
|
|
371
|
-
cameraR.matrixWorldInverse.multiply( matrixWorldInverse );
|
|
372
|
-
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
// envMap and Mirror needs camera.matrixWorld
|
|
376
|
-
|
|
377
|
-
cameraL.matrixWorld.copy( cameraL.matrixWorldInverse ).invert();
|
|
378
|
-
cameraR.matrixWorld.copy( cameraR.matrixWorldInverse ).invert();
|
|
379
|
-
|
|
380
|
-
cameraL.projectionMatrix.fromArray( frameData.leftProjectionMatrix );
|
|
381
|
-
cameraR.projectionMatrix.fromArray( frameData.rightProjectionMatrix );
|
|
382
|
-
|
|
383
|
-
setProjectionFromUnion( cameraVR, cameraL, cameraR );
|
|
384
|
-
|
|
385
|
-
//
|
|
386
|
-
|
|
387
|
-
var layers = device.getLayers();
|
|
388
|
-
|
|
389
|
-
if ( layers.length ) {
|
|
390
|
-
|
|
391
|
-
var layer = layers[ 0 ];
|
|
392
|
-
|
|
393
|
-
updateViewportFromBounds( cameraL.viewport, layer.leftBounds );
|
|
394
|
-
updateViewportFromBounds( cameraR.viewport, layer.rightBounds );
|
|
395
|
-
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
updateControllers();
|
|
399
|
-
|
|
400
|
-
return cameraVR;
|
|
401
|
-
|
|
402
|
-
};
|
|
403
|
-
|
|
404
|
-
this.getCamera = function () {
|
|
405
|
-
|
|
406
|
-
return cameraVR;
|
|
407
|
-
|
|
408
|
-
};
|
|
409
|
-
|
|
410
|
-
// Dummy getFoveation/setFoveation to have the same API as WebXR
|
|
411
|
-
|
|
412
|
-
this.getFoveation = function () {
|
|
413
|
-
|
|
414
|
-
return 1;
|
|
415
|
-
|
|
416
|
-
};
|
|
417
|
-
|
|
418
|
-
this.setFoveation = function ( foveation ) {
|
|
419
|
-
|
|
420
|
-
if ( foveation !== 1 ) {
|
|
421
|
-
|
|
422
|
-
console.warn( 'THREE.WebVRManager: setFoveation() not used in WebVR.' );
|
|
423
|
-
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
};
|
|
427
|
-
|
|
428
|
-
// Dummy getEnvironmentBlendMode to have the same API as WebXR
|
|
429
|
-
|
|
430
|
-
this.getEnvironmentBlendMode = function () {
|
|
431
|
-
|
|
432
|
-
if ( scope.isPresenting ) {
|
|
433
|
-
|
|
434
|
-
return 'opaque';
|
|
435
|
-
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
};
|
|
439
|
-
|
|
440
|
-
//
|
|
441
|
-
|
|
442
|
-
this.getStandingMatrix = function () {
|
|
443
|
-
|
|
444
|
-
return standingMatrix;
|
|
445
|
-
|
|
446
|
-
};
|
|
447
|
-
|
|
448
|
-
this.isPresenting = false;
|
|
449
|
-
|
|
450
|
-
// Animation Loop
|
|
451
|
-
|
|
452
|
-
var animation = new WebGLAnimation();
|
|
453
|
-
|
|
454
|
-
this.setAnimationLoop = function ( callback ) {
|
|
455
|
-
|
|
456
|
-
animation.setAnimationLoop( callback );
|
|
457
|
-
|
|
458
|
-
if ( this.isPresenting ) animation.start();
|
|
459
|
-
|
|
460
|
-
};
|
|
461
|
-
|
|
462
|
-
this.submitFrame = function () {
|
|
463
|
-
|
|
464
|
-
if ( this.isPresenting ) device.submitFrame();
|
|
465
|
-
|
|
466
|
-
};
|
|
467
|
-
|
|
468
|
-
this.dispose = function () {
|
|
469
|
-
|
|
470
|
-
if ( typeof window !== 'undefined' ) {
|
|
471
|
-
|
|
472
|
-
window.removeEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange );
|
|
473
|
-
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
};
|
|
477
|
-
|
|
478
|
-
// DEPRECATED
|
|
479
|
-
|
|
480
|
-
this.setFrameOfReferenceType = function () {
|
|
481
|
-
|
|
482
|
-
console.warn( 'THREE.WebVRManager: setFrameOfReferenceType() has been deprecated.' );
|
|
483
|
-
|
|
484
|
-
};
|
|
485
|
-
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
Object.assign( WebVRManager.prototype, {
|
|
489
|
-
addEventListener: EventDispatcher.prototype.addEventListener,
|
|
490
|
-
hasEventListener: EventDispatcher.prototype.hasEventListener,
|
|
491
|
-
removeEventListener: EventDispatcher.prototype.removeEventListener,
|
|
492
|
-
dispatchEvent: EventDispatcher.prototype.dispatchEvent
|
|
493
|
-
} );
|
|
494
|
-
|
|
495
|
-
export { WebVRManager };
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author jsantell / https://www.jsantell.com/
|
|
3
|
-
* @author mrdoob / http://mrdoob.com/
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { Vector3 } from '../../math/Vector3.js';
|
|
7
|
-
|
|
8
|
-
var cameraLPos = new Vector3();
|
|
9
|
-
var cameraRPos = new Vector3();
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Assumes 2 cameras that are parallel and share an X-axis, and that
|
|
13
|
-
* the cameras' projection and world matrices have already been set.
|
|
14
|
-
* And that near and far planes are identical for both cameras.
|
|
15
|
-
* Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
|
|
16
|
-
*/
|
|
17
|
-
function setProjectionFromUnion( camera, cameraL, cameraR ) {
|
|
18
|
-
|
|
19
|
-
cameraLPos.setFromMatrixPosition( cameraL.matrixWorld );
|
|
20
|
-
cameraRPos.setFromMatrixPosition( cameraR.matrixWorld );
|
|
21
|
-
|
|
22
|
-
var ipd = cameraLPos.distanceTo( cameraRPos );
|
|
23
|
-
|
|
24
|
-
var projL = cameraL.projectionMatrix.elements;
|
|
25
|
-
var projR = cameraR.projectionMatrix.elements;
|
|
26
|
-
|
|
27
|
-
// VR systems will have identical far and near planes, and
|
|
28
|
-
// most likely identical top and bottom frustum extents.
|
|
29
|
-
// Use the left camera for these values.
|
|
30
|
-
var near = projL[ 14 ] / ( projL[ 10 ] - 1 );
|
|
31
|
-
var far = projL[ 14 ] / ( projL[ 10 ] + 1 );
|
|
32
|
-
var topFov = ( projL[ 9 ] + 1 ) / projL[ 5 ];
|
|
33
|
-
var bottomFov = ( projL[ 9 ] - 1 ) / projL[ 5 ];
|
|
34
|
-
|
|
35
|
-
var leftFov = ( projL[ 8 ] - 1 ) / projL[ 0 ];
|
|
36
|
-
var rightFov = ( projR[ 8 ] + 1 ) / projR[ 0 ];
|
|
37
|
-
var left = near * leftFov;
|
|
38
|
-
var right = near * rightFov;
|
|
39
|
-
|
|
40
|
-
// Calculate the new camera's position offset from the
|
|
41
|
-
// left camera. xOffset should be roughly half `ipd`.
|
|
42
|
-
var zOffset = ipd / ( - leftFov + rightFov );
|
|
43
|
-
var xOffset = zOffset * - leftFov;
|
|
44
|
-
|
|
45
|
-
// TODO: Better way to apply this offset?
|
|
46
|
-
cameraL.matrixWorld.decompose( camera.position, camera.quaternion, camera.scale );
|
|
47
|
-
camera.translateX( xOffset );
|
|
48
|
-
camera.translateZ( zOffset );
|
|
49
|
-
camera.matrixWorld.compose( camera.position, camera.quaternion, camera.scale );
|
|
50
|
-
camera.matrixWorldInverse.copy( camera.matrixWorld ).invert();
|
|
51
|
-
|
|
52
|
-
// Find the union of the frustum values of the cameras and scale
|
|
53
|
-
// the values so that the near plane's position does not change in world space,
|
|
54
|
-
// although must now be relative to the new union camera.
|
|
55
|
-
var near2 = near + zOffset;
|
|
56
|
-
var far2 = far + zOffset;
|
|
57
|
-
var left2 = left - xOffset;
|
|
58
|
-
var right2 = right + ( ipd - xOffset );
|
|
59
|
-
var top2 = topFov * far / far2 * near2;
|
|
60
|
-
var bottom2 = bottomFov * far / far2 * near2;
|
|
61
|
-
|
|
62
|
-
camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 );
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export { setProjectionFromUnion };
|