|
@@ -3,64 +3,12 @@
|
|
* @authod mrdoob / http://mrdoob.com/
|
|
* @authod mrdoob / http://mrdoob.com/
|
|
* @authod arodic / http://aleksandarrodic.com/
|
|
* @authod arodic / http://aleksandarrodic.com/
|
|
* @authod fonserbc / http://fonserbc.github.io/
|
|
* @authod fonserbc / http://fonserbc.github.io/
|
|
- *
|
|
|
|
- * Off-axis stereoscopic effect based on http://paulbourke.net/stereographics/stereorender/
|
|
|
|
- */
|
|
|
|
|
|
+*/
|
|
|
|
|
|
THREE.StereoEffect = function ( renderer ) {
|
|
THREE.StereoEffect = function ( renderer ) {
|
|
|
|
|
|
- // API
|
|
|
|
-
|
|
|
|
- var scope = this;
|
|
|
|
-
|
|
|
|
- this.eyeSeparation = 3;
|
|
|
|
- this.focalLength = 15; // Distance to the non-parallax or projection plane
|
|
|
|
-
|
|
|
|
- Object.defineProperties( this, {
|
|
|
|
- separation: {
|
|
|
|
- get: function () {
|
|
|
|
-
|
|
|
|
- return scope.eyeSeparation;
|
|
|
|
-
|
|
|
|
- },
|
|
|
|
- set: function ( value ) {
|
|
|
|
-
|
|
|
|
- console.warn( 'THREE.StereoEffect: .separation is now .eyeSeparation.' );
|
|
|
|
- scope.eyeSeparation = value;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- targetDistance: {
|
|
|
|
- get: function () {
|
|
|
|
-
|
|
|
|
- return scope.focalLength;
|
|
|
|
-
|
|
|
|
- },
|
|
|
|
- set: function ( value ) {
|
|
|
|
-
|
|
|
|
- console.warn( 'THREE.StereoEffect: .targetDistance is now .focalLength.' );
|
|
|
|
- scope.focalLength = value;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } );
|
|
|
|
-
|
|
|
|
- // internals
|
|
|
|
-
|
|
|
|
var _width, _height;
|
|
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();
|
|
|
|
-
|
|
|
|
- var _fov;
|
|
|
|
- var _outer, _inner, _top, _bottom;
|
|
|
|
- var _ndfl, _halfFocalWidth, _halfFocalHeight;
|
|
|
|
- var _innerFactor, _outerFactor;
|
|
|
|
-
|
|
|
|
// initialization
|
|
// initialization
|
|
|
|
|
|
renderer.autoClear = false;
|
|
renderer.autoClear = false;
|
|
@@ -76,70 +24,27 @@ THREE.StereoEffect = function ( renderer ) {
|
|
|
|
|
|
this.render = function ( scene, camera ) {
|
|
this.render = function ( scene, camera ) {
|
|
|
|
|
|
- scene.updateMatrixWorld();
|
|
|
|
-
|
|
|
|
- if ( camera.parent === null ) camera.updateMatrixWorld();
|
|
|
|
-
|
|
|
|
- camera.matrixWorld.decompose( _position, _quaternion, _scale );
|
|
|
|
-
|
|
|
|
- // Effective fov of the camera
|
|
|
|
-
|
|
|
|
- _fov = THREE.Math.radToDeg( 2 * Math.atan( Math.tan( THREE.Math.degToRad( camera.fov ) * 0.5 ) / camera.zoom ) );
|
|
|
|
-
|
|
|
|
- _ndfl = camera.near / this.focalLength;
|
|
|
|
- _halfFocalHeight = Math.tan( THREE.Math.degToRad( _fov ) * 0.5 ) * this.focalLength;
|
|
|
|
- _halfFocalWidth = _halfFocalHeight * 0.5 * camera.aspect;
|
|
|
|
|
|
+ if ( camera instanceof THREE.StereoCamera === false ) {
|
|
|
|
|
|
- _top = _halfFocalHeight * _ndfl;
|
|
|
|
- _bottom = - _top;
|
|
|
|
- _innerFactor = ( _halfFocalWidth + this.eyeSeparation / 2.0 ) / ( _halfFocalWidth * 2.0 );
|
|
|
|
- _outerFactor = 1.0 - _innerFactor;
|
|
|
|
|
|
+ console.error( 'THREE.StereoCamera.render(): camera should now be an insteance of THREE.StereoCamera.' );
|
|
|
|
+ return;
|
|
|
|
|
|
- _outer = _halfFocalWidth * 2.0 * _ndfl * _outerFactor;
|
|
|
|
- _inner = _halfFocalWidth * 2.0 * _ndfl * _innerFactor;
|
|
|
|
-
|
|
|
|
- // left
|
|
|
|
-
|
|
|
|
- _cameraL.projectionMatrix.makeFrustum(
|
|
|
|
- - _outer,
|
|
|
|
- _inner,
|
|
|
|
- _bottom,
|
|
|
|
- _top,
|
|
|
|
- camera.near,
|
|
|
|
- camera.far
|
|
|
|
- );
|
|
|
|
-
|
|
|
|
- _cameraL.position.copy( _position );
|
|
|
|
- _cameraL.quaternion.copy( _quaternion );
|
|
|
|
- _cameraL.translateX( - this.eyeSeparation / 2.0 );
|
|
|
|
-
|
|
|
|
- // right
|
|
|
|
-
|
|
|
|
- _cameraR.projectionMatrix.makeFrustum(
|
|
|
|
- - _inner,
|
|
|
|
- _outer,
|
|
|
|
- _bottom,
|
|
|
|
- _top,
|
|
|
|
- camera.near,
|
|
|
|
- camera.far
|
|
|
|
- );
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- _cameraR.position.copy( _position );
|
|
|
|
- _cameraR.quaternion.copy( _quaternion );
|
|
|
|
- _cameraR.translateX( this.eyeSeparation / 2.0 );
|
|
|
|
|
|
+ scene.updateMatrixWorld();
|
|
|
|
|
|
- //
|
|
|
|
|
|
+ if ( camera.parent === null ) camera.updateMatrixWorld();
|
|
|
|
|
|
renderer.clear();
|
|
renderer.clear();
|
|
renderer.enableScissorTest( true );
|
|
renderer.enableScissorTest( true );
|
|
|
|
|
|
renderer.setScissor( 0, 0, _width, _height );
|
|
renderer.setScissor( 0, 0, _width, _height );
|
|
renderer.setViewport( 0, 0, _width, _height );
|
|
renderer.setViewport( 0, 0, _width, _height );
|
|
- renderer.render( scene, _cameraL );
|
|
|
|
|
|
+ renderer.render( scene, camera.cameraL );
|
|
|
|
|
|
renderer.setScissor( _width, 0, _width, _height );
|
|
renderer.setScissor( _width, 0, _width, _height );
|
|
renderer.setViewport( _width, 0, _width, _height );
|
|
renderer.setViewport( _width, 0, _width, _height );
|
|
- renderer.render( scene, _cameraR );
|
|
|
|
|
|
+ renderer.render( scene, camera.cameraR );
|
|
|
|
|
|
renderer.enableScissorTest( false );
|
|
renderer.enableScissorTest( false );
|
|
|
|
|