AttributeNode.js 1.3 KB

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