AttributeNode.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { Node } from './Node.js';
  2. class AttributeNode extends Node {
  3. constructor( name, type ) {
  4. super( type );
  5. this.name = name;
  6. }
  7. getAttributeType( builder ) {
  8. return typeof this.type === 'number' ? builder.getConstructorFromLength( this.type ) : this.type;
  9. }
  10. getType( builder ) {
  11. const type = this.getAttributeType( builder );
  12. return builder.getTypeByFormat( type );
  13. }
  14. generate( builder, output ) {
  15. const type = this.getAttributeType( builder );
  16. const attribute = builder.getAttribute( this.name, type ),
  17. name = builder.isShader( 'vertex' ) ? this.name : attribute.varying.name;
  18. return builder.format( name, this.getType( builder ), output );
  19. }
  20. copy( source ) {
  21. super.copy( source );
  22. this.type = source.type;
  23. return this;
  24. }
  25. toJSON( meta ) {
  26. let data = this.getJSONNode( meta );
  27. if ( ! data ) {
  28. data = this.createJSONNode( meta );
  29. data.type = this.type;
  30. }
  31. return data;
  32. }
  33. }
  34. AttributeNode.prototype.nodeType = 'Attribute';
  35. export { AttributeNode };