Skip to content

Commit 48143a5

Browse files
committed
introduce automatic use of .toVar() to assign()
1 parent 250c5f6 commit 48143a5

File tree

8 files changed

+196
-82
lines changed

8 files changed

+196
-82
lines changed

src/nodes/core/AssignNode.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ class AssignNode extends TempNode {
9797

9898
const { targetNode, sourceNode } = this;
9999

100+
const targetProperties = builder.getNodeProperties( targetNode );
101+
targetProperties.assign = true;
102+
100103
const properties = builder.getNodeProperties( this );
101104
properties.sourceNode = sourceNode;
102105
properties.targetNode = targetNode.context( { assign: true } );

src/nodes/core/NodeBuilder.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,6 +1755,8 @@ class NodeBuilder {
17551755
*/
17561756
getArrayCount( node ) {
17571757

1758+
// TODO: Move this to the node itself
1759+
17581760
let count = null;
17591761

17601762
if ( node.isArrayNode ) count = node.count;

src/nodes/core/StackNode.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,30 @@ class StackNode extends Node {
245245

246246
}
247247

248+
setup( builder ) {
249+
250+
const nodeProperties = builder.getNodeProperties( this );
251+
252+
let index = 0;
253+
254+
for ( const childNode of this.getChildren() ) {
255+
256+
if ( childNode.isVarNode && childNode.intention === true ) {
257+
258+
continue;
259+
260+
}
261+
262+
nodeProperties[ 'node' + index ++ ] = childNode;
263+
264+
}
265+
266+
// return a outputNode if exists or null
267+
268+
return nodeProperties.outputNode || null;
269+
270+
}
271+
248272
build( builder, ...params ) {
249273

250274
const previousBuildStack = builder.currentStack;
@@ -258,6 +282,18 @@ class StackNode extends Node {
258282

259283
for ( const node of this.nodes ) {
260284

285+
if ( node.isVarNode && node.intention === true ) {
286+
287+
const properties = builder.getNodeProperties( node );
288+
289+
if ( properties.assign !== true ) {
290+
291+
continue;
292+
293+
}
294+
295+
}
296+
261297
if ( buildStage === 'setup' ) {
262298

263299
node.build( builder );

src/nodes/core/VarNode.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Node from './Node.js';
2-
import { addMethodChaining, nodeProxy } from '../tsl/TSLCore.js';
2+
import { addMethodChaining, getCurrentStack, nodeProxy } from '../tsl/TSLCore.js';
33

44
/**
55
* Class for representing shader variables as nodes. Variables are created from
@@ -81,6 +81,16 @@ class VarNode extends Node {
8181
*/
8282
this.parents = true;
8383

84+
this.intention = false;
85+
86+
}
87+
88+
setIntention( value ) {
89+
90+
this.intention = value;
91+
92+
return this;
93+
8494
}
8595

8696
getMemberType( builder, name ) {
@@ -101,6 +111,25 @@ class VarNode extends Node {
101111

102112
}
103113

114+
build( ...params ) {
115+
116+
if ( this.intention === true ) {
117+
118+
const builder = params[ 0 ];
119+
const properties = builder.getNodeProperties( this );
120+
121+
if ( properties.assign !== true ) {
122+
123+
return this.node.build( ...params );
124+
125+
}
126+
127+
}
128+
129+
return super.build( ...params );
130+
131+
}
132+
104133
generate( builder ) {
105134

106135
const { node, name, readOnly } = this;
@@ -189,10 +218,26 @@ export const Var = ( node, name = null ) => createVar( node, name ).toStack();
189218
*/
190219
export const Const = ( node, name = null ) => createVar( node, name, true ).toStack();
191220

221+
//
222+
//
223+
224+
export const VarIntention = ( node ) => {
225+
226+
if ( getCurrentStack() === null ) {
227+
228+
return node;
229+
230+
}
231+
232+
return createVar( node ).setIntention( true ).toStack();
233+
234+
};
235+
192236
// Method chaining
193237

194238
addMethodChaining( 'toVar', Var );
195239
addMethodChaining( 'toConst', Const );
240+
addMethodChaining( 'toVarIntention', VarIntention );
196241

197242
// Deprecated
198243

src/nodes/math/ConditionalNode.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class ConditionalNode extends Node {
7373

7474
// fallback setup
7575

76+
// TODO: use build here
77+
7678
this.setup( builder );
7779

7880
return this.getNodeType( builder );

0 commit comments

Comments
 (0)