PositionNode.js 744 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import Node from '../core/Node.js';
  2. import AttributeNode from '../core/AttributeNode.js';
  3. class PositionNode extends Node {
  4. static LOCAL = 'local';
  5. constructor( scope = PositionNode.POSITION ) {
  6. super( 'vec3' );
  7. this.scope = scope;
  8. }
  9. generate( builder, output ) {
  10. const type = this.getType( builder );
  11. const nodeData = builder.getDataFromNode( this, builder.shaderStage );
  12. let positionNode = nodeData.positionNode;
  13. if ( positionNode === undefined ) {
  14. positionNode = new AttributeNode( 'position', 'vec3' );
  15. nodeData.positionNode = positionNode;
  16. }
  17. const positionSnipped = positionNode.build( builder, type );
  18. return builder.format( positionSnipped, type, output );
  19. }
  20. }
  21. export default PositionNode;