QuadMesh.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 {
  15. constructor( material = null ) {
  16. this._mesh = new Mesh( _geometry, material );
  17. }
  18. dispose() {
  19. this._mesh.geometry.dispose();
  20. }
  21. render( renderer ) {
  22. renderer.render( this._mesh, _camera );
  23. }
  24. get material() {
  25. return this._mesh.material;
  26. }
  27. set material( value ) {
  28. this._mesh.material = value;
  29. }
  30. }
  31. export default QuadMesh;