UniformsGroup.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { EventDispatcher } from './EventDispatcher.js';
  2. import { StaticDrawUsage } from '../constants.js';
  3. let id = 0;
  4. class UniformsGroup extends EventDispatcher {
  5. constructor() {
  6. super();
  7. this.isUniformsGroup = true;
  8. Object.defineProperty( this, 'id', { value: id ++ } );
  9. this.name = '';
  10. this.usage = StaticDrawUsage;
  11. this.uniforms = [];
  12. }
  13. add( uniform ) {
  14. this.uniforms.push( uniform );
  15. return this;
  16. }
  17. remove( uniform ) {
  18. const index = this.uniforms.indexOf( uniform );
  19. if ( index !== - 1 ) this.uniforms.splice( index, 1 );
  20. return this;
  21. }
  22. setName( name ) {
  23. this.name = name;
  24. return this;
  25. }
  26. setUsage( value ) {
  27. this.usage = value;
  28. return this;
  29. }
  30. dispose() {
  31. this.dispatchEvent( { type: 'dispose' } );
  32. return this;
  33. }
  34. copy( source ) {
  35. this.name = source.name;
  36. this.usage = source.usage;
  37. const uniformsSource = source.uniforms;
  38. this.uniforms.length = 0;
  39. for ( let i = 0, l = uniformsSource.length; i < l; i ++ ) {
  40. this.uniforms.push( uniformsSource[ i ].clone() );
  41. }
  42. return this;
  43. }
  44. clone() {
  45. return new this.constructor().copy( this );
  46. }
  47. }
  48. export { UniformsGroup };
粤ICP备19079148号