StereoEffect.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. ( function () {
  2. class StereoEffect {
  3. constructor( renderer ) {
  4. const _stereo = new THREE.StereoCamera();
  5. _stereo.aspect = 0.5;
  6. const size = new THREE.Vector2();
  7. this.setEyeSeparation = function ( eyeSep ) {
  8. _stereo.eyeSep = eyeSep;
  9. };
  10. this.setSize = function ( width, height ) {
  11. renderer.setSize( width, height );
  12. };
  13. this.render = function ( scene, camera ) {
  14. scene.updateMatrixWorld();
  15. if ( camera.parent === null ) camera.updateMatrixWorld();
  16. _stereo.update( camera );
  17. renderer.getSize( size );
  18. if ( renderer.autoClear ) renderer.clear();
  19. renderer.setScissorTest( true );
  20. renderer.setScissor( 0, 0, size.width / 2, size.height );
  21. renderer.setViewport( 0, 0, size.width / 2, size.height );
  22. renderer.render( scene, _stereo.cameraL );
  23. renderer.setScissor( size.width / 2, 0, size.width / 2, size.height );
  24. renderer.setViewport( size.width / 2, 0, size.width / 2, size.height );
  25. renderer.render( scene, _stereo.cameraR );
  26. renderer.setScissorTest( false );
  27. };
  28. }
  29. }
  30. THREE.StereoEffect = StereoEffect;
  31. } )();