@@ -8180,20 +8180,10 @@ class VarNode extends Node {
81808180
81818181 build( ...params ) {
81828182
8183- const builder = params[ 0 ];
8184-
8185- if ( this._hasStack( builder ) === false && builder.buildStage === 'setup' ) {
8186-
8187- if ( builder.context.nodeLoop || builder.context.nodeBlock ) {
8188-
8189- builder.getBaseStack().addToStack( this );
8190-
8191- }
8192-
8193- }
8194-
81958183 if ( this.intent === true ) {
81968184
8185+ const builder = params[ 0 ];
8186+
81978187 if ( this.isAssign( builder ) !== true ) {
81988188
81998189 return this.node.build( ...params );
@@ -8273,14 +8263,6 @@ class VarNode extends Node {
82738263
82748264 }
82758265
8276- _hasStack( builder ) {
8277-
8278- const nodeData = builder.getDataFromNode( this );
8279-
8280- return nodeData.stack !== undefined;
8281-
8282- }
8283-
82848266}
82858267
82868268/**
@@ -8330,6 +8312,12 @@ const Const = ( node, name = null ) => createVar( node, name, true ).toStack();
83308312 */
83318313const VarIntent = ( node ) => {
83328314
8315+ if ( getCurrentStack() === null ) {
8316+
8317+ return node;
8318+
8319+ }
8320+
83338321 return createVar( node ).setIntent( true ).toStack();
83348322
83358323};
@@ -17563,7 +17551,7 @@ class LoopNode extends Node {
1756317551 */
1756417552 constructor( params = [] ) {
1756517553
17566- super( 'void' );
17554+ super();
1756717555
1756817556 this.params = params;
1756917557
@@ -17609,20 +17597,16 @@ class LoopNode extends Node {
1760917597
1761017598 }
1761117599
17612- const stack = builder.addStack();
17613-
17614- const fnCall = this.params[ this.params.length - 1 ]( inputs );
17600+ const stack = builder.addStack(); // TODO: cache() it
1761517601
17616- properties.returnsNode = fnCall.context( { nodeLoop: fnCall } );
17602+ properties.returnsNode = this.params[ this.params.length - 1 ]( inputs, builder );
1761717603 properties.stackNode = stack;
1761817604
1761917605 const baseParam = this.params[ 0 ];
1762017606
1762117607 if ( baseParam.isNode !== true && typeof baseParam.update === 'function' ) {
1762217608
17623- const fnUpdateCall = Fn( this.params[ 0 ].update )( inputs );
17624-
17625- properties.updateNode = fnUpdateCall.context( { nodeLoop: fnUpdateCall } );
17609+ properties.updateNode = Fn( this.params[ 0 ].update )( inputs );
1762617610
1762717611 }
1762817612
@@ -17632,6 +17616,20 @@ class LoopNode extends Node {
1763217616
1763317617 }
1763417618
17619+ /**
17620+ * This method is overwritten since the node type is inferred based on the loop configuration.
17621+ *
17622+ * @param {NodeBuilder} builder - The current node builder.
17623+ * @return {string} The node type.
17624+ */
17625+ getNodeType( builder ) {
17626+
17627+ const { returnsNode } = this.getProperties( builder );
17628+
17629+ return returnsNode ? returnsNode.getNodeType( builder ) : 'void';
17630+
17631+ }
17632+
1763517633 setup( builder ) {
1763617634
1763717635 // setup properties
@@ -17811,7 +17809,7 @@ class LoopNode extends Node {
1781117809
1781217810 const stackSnippet = stackNode.build( builder, 'void' );
1781317811
17814- properties.returnsNode. build( builder, 'void' ) ;
17812+ const returnsSnippet = properties.returnsNode ? properties.returnsNode. build( builder ) : '' ;
1781517813
1781617814 builder.removeFlowTab().addFlowCode( '\n' + builder.tab + stackSnippet );
1781717815
@@ -17823,6 +17821,8 @@ class LoopNode extends Node {
1782317821
1782417822 builder.addFlowTab();
1782517823
17824+ return returnsSnippet;
17825+
1782617826 }
1782717827
1782817828}
@@ -27510,7 +27510,7 @@ class VolumetricLightingModel extends LightingModel {
2751027510
2751127511 start( builder ) {
2751227512
27513- const { material } = builder;
27513+ const { material, context } = builder;
2751427514
2751527515 const startPos = property( 'vec3' );
2751627516 const endPos = property( 'vec3' );
@@ -27559,13 +27559,13 @@ class VolumetricLightingModel extends LightingModel {
2755927559
2756027560 linearDepthRay.assign( linearDepth( viewZToPerspectiveDepth( positionViewRay.z, cameraNear, cameraFar ) ) );
2756127561
27562- builder. context.sceneDepthNode = linearDepth( material.depthNode ).toVar();
27562+ context.sceneDepthNode = linearDepth( material.depthNode ).toVar();
2756327563
2756427564 }
2756527565
27566- builder. context.positionWorld = positionRay;
27567- builder. context.shadowPositionWorld = positionRay;
27568- builder. context.positionView = positionViewRay;
27566+ context.positionWorld = positionRay;
27567+ context.shadowPositionWorld = positionRay;
27568+ context.positionView = positionViewRay;
2756927569
2757027570 scatteringDensity.assign( 0 );
2757127571
@@ -32683,11 +32683,12 @@ class StackNode extends Node {
3268332683
3268432684 build( builder, ...params ) {
3268532685
32686+ const previousBuildStack = builder.currentStack;
3268632687 const previousStack = getCurrentStack();
3268732688
3268832689 setCurrentStack( this );
3268932690
32690- builder.setActiveStack( this ) ;
32691+ builder.currentStack = this ;
3269132692
3269232693 const buildStage = builder.buildStage;
3269332694
@@ -32705,9 +32706,6 @@ class StackNode extends Node {
3270532706
3270632707 if ( buildStage === 'setup' ) {
3270732708
32708- const nodeData = builder.getDataFromNode( node );
32709- nodeData.stack = this;
32710-
3271132709 node.build( builder );
3271232710
3271332711 } else if ( buildStage === 'analyze' ) {
@@ -32747,7 +32745,7 @@ class StackNode extends Node {
3274732745
3274832746 setCurrentStack( previousStack );
3274932747
32750- builder.removeActiveStack( this ) ;
32748+ builder.currentStack = previousBuildStack ;
3275132749
3275232750 return result;
3275332751
@@ -39447,11 +39445,8 @@ class RangeNode extends Node {
3944739445 */
3944839446 getVectorLength( builder ) {
3944939447
39450- const minNode = this.getConstNode( this.minNode );
39451- const maxNode = this.getConstNode( this.maxNode );
39452-
39453- const minLength = builder.getTypeLength( getValueType( minNode.value ) );
39454- const maxLength = builder.getTypeLength( getValueType( maxNode.value ) );
39448+ const minLength = builder.getTypeLength( getValueType( this.minNode.value ) );
39449+ const maxLength = builder.getTypeLength( getValueType( this.maxNode.value ) );
3945539450
3945639451 return minLength > maxLength ? minLength : maxLength;
3945739452
@@ -39469,36 +39464,6 @@ class RangeNode extends Node {
3946939464
3947039465 }
3947139466
39472- /**
39473- * Returns a constant node from the given node by traversing it.
39474- *
39475- * @param {Node} node - The node to traverse.
39476- * @returns {Node} The constant node, if found.
39477- */
39478- getConstNode( node ) {
39479-
39480- let output = null;
39481-
39482- node.traverse( n => {
39483-
39484- if ( n.isConstNode === true ) {
39485-
39486- output = n;
39487-
39488- }
39489-
39490- } );
39491-
39492- if ( output === null ) {
39493-
39494- throw new Error( 'THREE.TSL: No "ConstNode" found in node graph.' );
39495-
39496- }
39497-
39498- return output;
39499-
39500- }
39501-
3950239467 setup( builder ) {
3950339468
3950439469 const object = builder.object;
@@ -39507,11 +39472,8 @@ class RangeNode extends Node {
3950739472
3950839473 if ( object.count > 1 ) {
3950939474
39510- const minNode = this.getConstNode( this.minNode );
39511- const maxNode = this.getConstNode( this.maxNode );
39512-
39513- const minValue = minNode.value;
39514- const maxValue = maxNode.value;
39475+ const minValue = this.minNode.value;
39476+ const maxValue = this.maxNode.value;
3951539477
3951639478 const minLength = builder.getTypeLength( getValueType( minValue ) );
3951739479 const maxLength = builder.getTypeLength( getValueType( maxValue ) );
@@ -47933,13 +47895,13 @@ class NodeBuilder {
4793347895 */
4793447896 this.subBuildLayers = [];
4793547897
47936-
4793747898 /**
47938- * The active stack nodes.
47899+ * The current stack of nodes.
4793947900 *
47940- * @type {Array<StackNode>}
47901+ * @type {?StackNode}
47902+ * @default null
4794147903 */
47942- this.activeStacks = [] ;
47904+ this.currentStack = null ;
4794347905
4794447906 /**
4794547907 * The current sub-build TSL function(Fn).
@@ -49101,58 +49063,6 @@ class NodeBuilder {
4910149063
4910249064 }
4910349065
49104- /**
49105- * Adds an active stack to the internal stack.
49106- *
49107- * @param {StackNode} stack - The stack node to add.
49108- */
49109- setActiveStack( stack ) {
49110-
49111- this.activeStacks.push( stack );
49112-
49113- }
49114-
49115- /**
49116- * Removes the active stack from the internal stack.
49117- *
49118- * @param {StackNode} stack - The stack node to remove.
49119- */
49120- removeActiveStack( stack ) {
49121-
49122- if ( this.activeStacks[ this.activeStacks.length - 1 ] === stack ) {
49123-
49124- this.activeStacks.pop();
49125-
49126- } else {
49127-
49128- throw new Error( 'NodeBuilder: Invalid active stack removal.' );
49129-
49130- }
49131-
49132- }
49133-
49134- /**
49135- * Returns the active stack.
49136- *
49137- * @return {StackNode} The active stack.
49138- */
49139- getActiveStack() {
49140-
49141- return this.activeStacks[ this.activeStacks.length - 1 ];
49142-
49143- }
49144-
49145- /**
49146- * Returns the base stack.
49147- *
49148- * @return {StackNode} The base stack.
49149- */
49150- getBaseStack() {
49151-
49152- return this.activeStacks[ 0 ];
49153-
49154- }
49155-
4915649066 /**
4915749067 * Adds a stack node to the internal stack.
4915849068 *
@@ -57707,10 +57617,10 @@ class Renderer {
5770757617 * if the renderer has been initialized.
5770857618 *
5770957619 * @param {Node|Array<Node>} computeNodes - The compute node(s).
57710- * @param {number|Array<number>|IndirectStorageBufferAttribute } [dispatchSize=null]
57620+ * @param {number|Array<number>|GPUBuffer } [dispatchSize=null]
5771157621 * - A single number representing count, or
5771257622 * - An array [x, y, z] representing dispatch size, or
57713- * - A IndirectStorageBufferAttribute for indirect dispatch size.
57623+ * - A GPUBuffer for indirect dispatch size.
5771457624 * @return {Promise|undefined} A Promise that resolve when the compute has finished. Only returned when the renderer has not been initialized.
5771557625 */
5771657626 compute( computeNodes, dispatchSize = null ) {
@@ -57721,7 +57631,7 @@ class Renderer {
5772157631
5772257632 warn( 'Renderer: .compute() called before the backend is initialized. Try using .computeAsync() instead.' );
5772357633
57724- return this.computeAsync( computeNodes, dispatchSize );
57634+ return this.computeAsync( computeNodes );
5772557635
5772657636 }
5772757637
@@ -57819,10 +57729,10 @@ class Renderer {
5781957729 *
5782057730 * @async
5782157731 * @param {Node|Array<Node>} computeNodes - The compute node(s).
57822- * @param {number|Array<number>|IndirectStorageBufferAttribute } [dispatchSize=null]
57732+ * @param {number|Array<number>|GPUBuffer } [dispatchSize=null]
5782357733 * - A single number representing count, or
5782457734 * - An array [x, y, z] representing dispatch size, or
57825- * - A IndirectStorageBufferAttribute for indirect dispatch size.
57735+ * - A GPUBuffer for indirect dispatch size.
5782657736 * @return {Promise} A Promise that resolve when the compute has finished.
5782757737 */
5782857738 async computeAsync( computeNodes, dispatchSize = null ) {
@@ -66747,12 +66657,6 @@ class WebGLBackend extends Backend {
6674766657
6674866658 count = count[ 0 ];
6674966659
66750- } else if ( count && typeof count === 'object' && count.isIndirectStorageBufferAttribute ) {
66751-
66752- warnOnce( 'WebGLBackend.compute(): The count parameter must be a single number, not IndirectStorageBufferAttribute' );
66753-
66754- count = computeNode.count;
66755-
6675666660 }
6675766661
6675866662 if ( attributes[ 0 ].isStorageInstancedBufferAttribute ) {
@@ -76953,10 +76857,10 @@ class WebGPUBackend extends Backend {
7695376857 * @param {Node} computeNode - The compute node.
7695476858 * @param {Array<BindGroup>} bindings - The bindings.
7695576859 * @param {ComputePipeline} pipeline - The compute pipeline.
76956- * @param {number|Array<number>|IndirectStorageBufferAttribute } [dispatchSize=null]
76860+ * @param {number|Array<number>|GPUBuffer } [dispatchSize=null]
7695776861 * - A single number representing count, or
7695876862 * - An array [x, y, z] representing dispatch size, or
76959- * - A IndirectStorageBufferAttribute for indirect dispatch size.
76863+ * - A GPUBuffer for indirect dispatch size.
7696076864 */
7696176865 compute( computeGroup, computeNode, bindings, pipeline, dispatchSize = null ) {
7696276866
0 commit comments