StereoEffect.js 1.2 KB

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