AttributeNode.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import Node from './Node.js';
  2. import VaryNode from './VaryNode.js';
  3. class AttributeNode extends Node {
  4. constructor( attributeName, nodeType = null ) {
  5. super( nodeType );
  6. this._attributeName = attributeName;
  7. }
  8. getHash( builder ) {
  9. return this.getAttributeName( builder );
  10. }
  11. getNodeType( builder ) {
  12. let nodeType = super.getNodeType( builder );
  13. if ( nodeType === null ) {
  14. const attributeName = this.getAttributeName( builder );
  15. const attribute = builder.geometry.getAttribute( attributeName );
  16. nodeType = builder.getTypeFromLength( attribute.itemSize );
  17. }
  18. return nodeType;
  19. }
  20. setAttributeName( attributeName ) {
  21. this._attributeName = attributeName;
  22. return this;
  23. }
  24. getAttributeName( /*builder*/ ) {
  25. return this._attributeName;
  26. }
  27. generate( builder ) {
  28. const attribute = builder.getAttribute( this.getAttributeName( builder ), this.getNodeType( builder ) );
  29. if ( builder.isShaderStage( 'vertex' ) ) {
  30. return attribute.name;
  31. } else {
  32. const nodeVary = new VaryNode( this );
  33. return nodeVary.build( builder, attribute.type );
  34. }
  35. }
  36. }
  37. export default AttributeNode;