StackNode.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import Node from './Node.js';
  2. import { select } from '../math/ConditionalNode.js';
  3. import { ShaderNode, nodeProxy, getCurrentStack, setCurrentStack } from '../tsl/TSLBase.js';
  4. class StackNode extends Node {
  5. static get type() {
  6. return 'StackNode';
  7. }
  8. constructor( parent = null ) {
  9. super();
  10. this.nodes = [];
  11. this.outputNode = null;
  12. this.parent = parent;
  13. this._currentCond = null;
  14. this.isStackNode = true;
  15. }
  16. getNodeType( builder ) {
  17. return this.outputNode ? this.outputNode.getNodeType( builder ) : 'void';
  18. }
  19. add( node ) {
  20. this.nodes.push( node );
  21. return this;
  22. }
  23. If( boolNode, method ) {
  24. const methodNode = new ShaderNode( method );
  25. this._currentCond = select( boolNode, methodNode );
  26. return this.add( this._currentCond );
  27. }
  28. ElseIf( boolNode, method ) {
  29. const methodNode = new ShaderNode( method );
  30. const ifNode = select( boolNode, methodNode );
  31. this._currentCond.elseNode = ifNode;
  32. this._currentCond = ifNode;
  33. return this;
  34. }
  35. Else( method ) {
  36. this._currentCond.elseNode = new ShaderNode( method );
  37. return this;
  38. }
  39. build( builder, ...params ) {
  40. const previousStack = getCurrentStack();
  41. setCurrentStack( this );
  42. for ( const node of this.nodes ) {
  43. node.build( builder, 'void' );
  44. }
  45. setCurrentStack( previousStack );
  46. return this.outputNode ? this.outputNode.build( builder, ...params ) : super.build( builder, ...params );
  47. }
  48. //
  49. else( ...params ) { // @deprecated, r168
  50. console.warn( 'TSL.StackNode: .else() has been renamed to .Else().' );
  51. return this.Else( ...params );
  52. }
  53. elseif( ...params ) { // @deprecated, r168
  54. console.warn( 'TSL.StackNode: .elseif() has been renamed to .ElseIf().' );
  55. return this.ElseIf( ...params );
  56. }
  57. }
  58. export default StackNode;
  59. export const stack = /*@__PURE__*/ nodeProxy( StackNode );
粤ICP备19079148号