File tree Expand file tree Collapse file tree 6 files changed +30
-86
lines changed Expand file tree Collapse file tree 6 files changed +30
-86
lines changed Original file line number Diff line number Diff line change @@ -94,7 +94,9 @@ class ContextNode extends Node {
94
94
95
95
analyze ( builder ) {
96
96
97
- const previousContext = builder . addContext ( this . value ) ;
97
+ const previousContext = builder . getContext ( ) ;
98
+
99
+ builder . setContext ( { ...builder . context , ...this . value } ) ;
98
100
99
101
this . node . build ( builder ) ;
100
102
@@ -104,7 +106,9 @@ class ContextNode extends Node {
104
106
105
107
setup ( builder ) {
106
108
107
- const previousContext = builder . addContext ( this . value ) ;
109
+ const previousContext = builder . getContext ( ) ;
110
+
111
+ builder . setContext ( { ...builder . context , ...this . value } ) ;
108
112
109
113
this . node . build ( builder ) ;
110
114
@@ -114,7 +118,9 @@ class ContextNode extends Node {
114
118
115
119
generate ( builder , output ) {
116
120
117
- const previousContext = builder . addContext ( this . value ) ;
121
+ const previousContext = builder . getContext ( ) ;
122
+
123
+ builder . setContext ( { ...builder . context , ...this . value } ) ;
118
124
119
125
const snippet = this . node . build ( builder , output ) ;
120
126
Original file line number Diff line number Diff line change @@ -899,22 +899,6 @@ class NodeBuilder {
899
899
900
900
}
901
901
902
- /**
903
- * Adds context data to the builder's current context.
904
- *
905
- * @param {Object } context - The context to add.
906
- * @return {Object } The previous context.
907
- */
908
- addContext ( context ) {
909
-
910
- const previousContext = this . getContext ( ) ;
911
-
912
- this . setContext ( { ...this . context , ...context } ) ;
913
-
914
- return previousContext ;
915
-
916
- }
917
-
918
902
/**
919
903
* Gets a context used in shader construction that can be shared across different materials.
920
904
* This is necessary since the renderer cache can reuse shaders generated in one material and use them in another.
Original file line number Diff line number Diff line change @@ -261,9 +261,15 @@ class StackNode extends Node {
261
261
262
262
for ( const childNode of this . getChildren ( ) ) {
263
263
264
- if ( childNode . isVarNode && childNode . isAssign ( builder ) ! == true ) {
264
+ if ( childNode . isVarNode && childNode . intent = == true ) {
265
265
266
- continue ;
266
+ const properties = builder . getNodeProperties ( childNode ) ;
267
+
268
+ if ( properties . assign !== true ) {
269
+
270
+ continue ;
271
+
272
+ }
267
273
268
274
}
269
275
@@ -296,9 +302,15 @@ class StackNode extends Node {
296
302
297
303
for ( const node of this . nodes ) {
298
304
299
- if ( node . isVarNode && node . isAssign ( builder ) ! == true ) {
305
+ if ( node . isVarNode && node . intent = == true ) {
300
306
301
- continue ;
307
+ const properties = builder . getNodeProperties ( node ) ;
308
+
309
+ if ( properties . assign !== true ) {
310
+
311
+ continue ;
312
+
313
+ }
302
314
303
315
}
304
316
Original file line number Diff line number Diff line change @@ -146,53 +146,14 @@ class VarNode extends Node {
146
146
147
147
}
148
148
149
- isAssign ( builder ) {
150
-
151
- if ( this . intent !== true ) return true ;
152
-
153
- //
154
-
155
- const properties = builder . getNodeProperties ( this ) ;
156
-
157
- let assign = properties . assign ;
158
-
159
- if ( assign !== true ) {
160
-
161
- if ( this . node . isShaderCallNodeInternal && this . node . shaderNode . getLayout ( ) === null ) {
162
-
163
- if ( builder . context . fnCall && builder . context . fnCall . shaderNode ) {
164
-
165
- const nodeType = this . node . getNodeType ( builder ) ;
166
-
167
- if ( nodeType !== 'void' ) {
168
-
169
- const shaderNodeData = builder . getDataFromNode ( this . node . shaderNode ) ;
170
-
171
- if ( shaderNodeData . hasLoop ) {
172
-
173
- assign = true ;
174
-
175
- }
176
-
177
- }
178
-
179
- }
180
-
181
- }
182
-
183
- }
184
-
185
- return assign ;
186
-
187
- }
188
-
189
149
build ( ...params ) {
190
150
191
151
if ( this . intent === true ) {
192
152
193
153
const builder = params [ 0 ] ;
154
+ const properties = builder . getNodeProperties ( this ) ;
194
155
195
- if ( this . isAssign ( builder ) !== true ) {
156
+ if ( properties . assign !== true ) {
196
157
197
158
return this . node . build ( ...params ) ;
198
159
Original file line number Diff line number Diff line change @@ -488,7 +488,6 @@ class ShaderCallNodeInternal extends Node {
488
488
//
489
489
490
490
const previousSubBuildFn = builder . subBuildFn ;
491
- const previousContext = builder . addContext ( { fnCall : this } ) ;
492
491
493
492
builder . subBuildFn = subBuild ;
494
493
@@ -566,7 +565,6 @@ class ShaderCallNodeInternal extends Node {
566
565
}
567
566
568
567
builder . subBuildFn = previousSubBuildFn ;
569
- builder . setContext ( previousContext ) ;
570
568
571
569
if ( shaderNode . once ) {
572
570
@@ -610,8 +608,6 @@ class ShaderCallNodeInternal extends Node {
610
608
const subBuildOutput = builder . getSubBuildOutput ( this ) ;
611
609
const outputNode = this . getOutputNode ( builder ) ;
612
610
613
- const previousContext = builder . addContext ( { fnCall : this } ) ;
614
-
615
611
if ( buildStage === 'setup' ) {
616
612
617
613
const subBuildInitialized = builder . getSubBuildProperty ( 'initialized' , this ) ;
@@ -659,8 +655,6 @@ class ShaderCallNodeInternal extends Node {
659
655
660
656
}
661
657
662
- builder . setContext ( previousContext ) ;
663
-
664
658
return result ;
665
659
666
660
}
@@ -794,15 +788,9 @@ class ShaderNodeInternal extends Node {
794
788
795
789
}
796
790
797
- getLayout ( ) {
798
-
799
- return this . layout ;
800
-
801
- }
802
-
803
791
call ( rawInputs = null ) {
804
792
805
- return new ShaderCallNodeInternal ( this , rawInputs ) ;
793
+ return nodeObject ( new ShaderCallNodeInternal ( this , rawInputs ) ) ;
806
794
807
795
}
808
796
Original file line number Diff line number Diff line change 1
1
import Node from '../core/Node.js' ;
2
2
import { expression } from '../code/ExpressionNode.js' ;
3
- import { nodeArray , Fn } from '../tsl/TSLBase.js' ;
3
+ import { nodeObject , nodeArray , Fn } from '../tsl/TSLBase.js' ;
4
4
import { error } from '../../utils.js' ;
5
5
6
6
/**
@@ -139,13 +139,6 @@ class LoopNode extends Node {
139
139
140
140
this . getProperties ( builder ) ;
141
141
142
- if ( builder . context . fnCall ) {
143
-
144
- const shaderNodeData = builder . getDataFromNode ( builder . context . fnCall . shaderNode ) ;
145
- shaderNodeData . hasLoop = true ;
146
-
147
- }
148
-
149
142
}
150
143
151
144
generate ( builder ) {
@@ -340,7 +333,7 @@ export default LoopNode;
340
333
* @param {...any } params - A list of parameters.
341
334
* @returns {LoopNode }
342
335
*/
343
- export const Loop = ( ...params ) => new LoopNode ( nodeArray ( params , 'int' ) ) . toStack ( ) ;
336
+ export const Loop = ( ...params ) => nodeObject ( new LoopNode ( nodeArray ( params , 'int' ) ) ) . toStack ( ) ;
344
337
345
338
/**
346
339
* TSL function for creating a `Continue()` expression.
You can’t perform that action at this time.
0 commit comments