-
Notifications
You must be signed in to change notification settings - Fork 9
/
StereoEffect.js
84 lines (54 loc) · 1.75 KB
/
StereoEffect.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
var THREE = require('three');
/**
* @author alteredq / http://alteredqualia.com/
* @authod mrdoob / http://mrdoob.com/
* @authod arodic / http://aleksandarrodic.com/
*/
THREE.StereoEffect = function ( renderer ) {
// API
this.separation = 2;
// internals
var _width, _height;
var _position = new THREE.Vector3();
var _quaternion = new THREE.Quaternion();
var _scale = new THREE.Vector3();
var _cameraL = new THREE.PerspectiveCamera();
var _cameraR = new THREE.PerspectiveCamera();
// initialization
renderer.autoClear = false;
this.setSize = function ( width, height ) {
_width = width / 2;
_height = height;
renderer.setSize( width, height );
};
this.render = function ( scene, camera ) {
scene.updateMatrixWorld();
if ( camera.parent === undefined ) camera.updateMatrixWorld();
camera.matrixWorld.decompose( _position, _quaternion, _scale );
// left
_cameraL.fov = camera.fov;
_cameraL.aspect = 0.5 * camera.aspect;
_cameraL.near = camera.near;
_cameraL.far = camera.far;
_cameraL.updateProjectionMatrix();
_cameraL.position.copy( _position );
_cameraL.quaternion.copy( _quaternion );
_cameraL.translateX( - this.separation );
_cameraL.updateMatrixWorld();
// right
_cameraR.near = camera.near;
_cameraR.far = camera.far;
_cameraR.projectionMatrix = _cameraL.projectionMatrix;
_cameraR.position.copy( _position );
_cameraR.quaternion.copy( _quaternion );
_cameraR.translateX( this.separation );
_cameraR.updateMatrixWorld();
//
renderer.setViewport( 0, 0, _width * 2, _height );
renderer.clear();
renderer.setViewport( 0, 0, _width, _height );
renderer.render( scene, _cameraL );
renderer.setViewport( _width, 0, _width, _height );
renderer.render( scene, _cameraR );
};
};