AttributeNode.js 1.3 KB

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