StereoEffect.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. * @authod mrdoob / http://mrdoob.com/
  4. * @authod arodic / http://aleksandarrodic.com/
  5. * @authod fonserbc / http://fonserbc.github.io/
  6. */
  7. import {
  8. StereoCamera,
  9. Vector2
  10. } from "../../../build/three.module.js";
  11. var StereoEffect = function ( renderer ) {
  12. var _stereo = new StereoCamera();
  13. _stereo.aspect = 0.5;
  14. var size = new Vector2();
  15. this.setEyeSeparation = function ( eyeSep ) {
  16. _stereo.eyeSep = eyeSep;
  17. };
  18. this.setSize = function ( width, height ) {
  19. renderer.setSize( width, height );
  20. };
  21. this.render = function ( scene, camera ) {
  22. scene.updateMatrixWorld();
  23. if ( camera.parent === null ) camera.updateMatrixWorld();
  24. _stereo.update( camera );
  25. renderer.getSize( size );
  26. if ( renderer.autoClear ) renderer.clear();
  27. renderer.setScissorTest( true );
  28. renderer.setScissor( 0, 0, size.width / 2, size.height );
  29. renderer.setViewport( 0, 0, size.width / 2, size.height );
  30. renderer.render( scene, _stereo.cameraL );
  31. renderer.setScissor( size.width / 2, 0, size.width / 2, size.height );
  32. renderer.setViewport( size.width / 2, 0, size.width / 2, size.height );
  33. renderer.render( scene, _stereo.cameraR );
  34. renderer.setScissorTest( false );
  35. };
  36. };
  37. export { StereoEffect };