You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.1 KiB
56 lines
1.1 KiB
2 years ago
|
import {
|
||
|
StereoCamera,
|
||
|
Vector2
|
||
|
} from '../../../build/three.module.js';
|
||
|
|
||
|
class StereoEffect {
|
||
|
|
||
|
constructor( renderer ) {
|
||
|
|
||
|
const _stereo = new StereoCamera();
|
||
|
_stereo.aspect = 0.5;
|
||
|
const size = new Vector2();
|
||
|
|
||
|
this.setEyeSeparation = function ( eyeSep ) {
|
||
|
|
||
|
_stereo.eyeSep = eyeSep;
|
||
|
|
||
|
};
|
||
|
|
||
|
this.setSize = function ( width, height ) {
|
||
|
|
||
|
renderer.setSize( width, height );
|
||
|
|
||
|
};
|
||
|
|
||
|
this.render = function ( scene, camera ) {
|
||
|
|
||
|
scene.updateMatrixWorld();
|
||
|
|
||
|
if ( camera.parent === null ) camera.updateMatrixWorld();
|
||
|
|
||
|
_stereo.update( camera );
|
||
|
|
||
|
renderer.getSize( size );
|
||
|
|
||
|
if ( renderer.autoClear ) renderer.clear();
|
||
|
renderer.setScissorTest( true );
|
||
|
|
||
|
renderer.setScissor( 0, 0, size.width / 2, size.height );
|
||
|
renderer.setViewport( 0, 0, size.width / 2, size.height );
|
||
|
renderer.render( scene, _stereo.cameraL );
|
||
|
|
||
|
renderer.setScissor( size.width / 2, 0, size.width / 2, size.height );
|
||
|
renderer.setViewport( size.width / 2, 0, size.width / 2, size.height );
|
||
|
renderer.render( scene, _stereo.cameraR );
|
||
|
|
||
|
renderer.setScissorTest( false );
|
||
|
|
||
|
};
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
export { StereoEffect };
|