QuadMesh.js 970 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { BufferGeometry, Float32BufferAttribute, Mesh, OrthographicCamera } from 'three';
  2. // Helper for passes that need to fill the viewport with a single quad.
  3. const _camera = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  4. // https://github.com/mrdoob/three.js/pull/21358
  5. class QuadGeometry extends BufferGeometry {
  6. constructor( flipY = false ) {
  7. super();
  8. const uv = flipY === false ? [ 0, - 1, 0, 1, 2, 1 ] : [ 0, 2, 0, 0, 2, 0 ];
  9. this.setAttribute( 'position', new Float32BufferAttribute( [ - 1, 3, 0, - 1, - 1, 0, 3, - 1, 0 ], 3 ) );
  10. this.setAttribute( 'uv', new Float32BufferAttribute( uv, 2 ) );
  11. }
  12. }
  13. const _geometry = new QuadGeometry();
  14. class QuadMesh extends Mesh {
  15. constructor( material = null ) {
  16. super( _geometry, material );
  17. this.camera = _camera;
  18. }
  19. renderAsync( renderer ) {
  20. return renderer.renderAsync( this, _camera );
  21. }
  22. render( renderer ) {
  23. renderer.render( this, _camera );
  24. }
  25. }
  26. export default QuadMesh;