AttributeNode.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. console.log( attribute );
  24. return builder.format( name, this.getType( builder ), output );
  25. };
  26. AttributeNode.prototype.copy = function ( source ) {
  27. Node.prototype.copy.call( this, source );
  28. this.type = source.type;
  29. };
  30. AttributeNode.prototype.toJSON = function ( meta ) {
  31. var data = this.getJSONNode( meta );
  32. if ( ! data ) {
  33. data = this.createJSONNode( meta );
  34. data.type = this.type;
  35. }
  36. return data;
  37. };
  38. export { AttributeNode };