1
1
import Node from './Node.js' ;
2
- import { addMethodChaining , nodeProxy } from '../tsl/TSLCore.js' ;
2
+ import { addMethodChaining , getCurrentStack , nodeProxy } from '../tsl/TSLCore.js' ;
3
3
4
4
/**
5
5
* Class for representing shader variables as nodes. Variables are created from
@@ -81,6 +81,45 @@ class VarNode extends Node {
81
81
*/
82
82
this . parents = true ;
83
83
84
+ /**
85
+ * This flag is used to indicate that this node is used for intent.
86
+ *
87
+ * @type {boolean }
88
+ * @default false
89
+ */
90
+ this . intent = false ;
91
+
92
+ }
93
+
94
+ /**
95
+ * Sets the intent flag for this node.
96
+ *
97
+ * This flag is used to indicate that this node is used for intent
98
+ * and should not be built directly. Instead, it is used to indicate that
99
+ * the node should be treated as a variable intent.
100
+ *
101
+ * It's useful for assigning variables without needing creating a new variable node.
102
+ *
103
+ * @param {boolean } value - The value to set for the intent flag.
104
+ * @returns {VarNode } This node.
105
+ */
106
+ setIntent ( value ) {
107
+
108
+ this . intent = value ;
109
+
110
+ return this ;
111
+
112
+ }
113
+
114
+ /**
115
+ * Returns the intent flag of this node.
116
+ *
117
+ * @return {boolean } The intent flag.
118
+ */
119
+ getIntent ( ) {
120
+
121
+ return this . intent ;
122
+
84
123
}
85
124
86
125
getMemberType ( builder , name ) {
@@ -101,6 +140,31 @@ class VarNode extends Node {
101
140
102
141
}
103
142
143
+ getArrayCount ( builder ) {
144
+
145
+ return this . node . getArrayCount ( builder ) ;
146
+
147
+ }
148
+
149
+ build ( ...params ) {
150
+
151
+ if ( this . intent === true ) {
152
+
153
+ const builder = params [ 0 ] ;
154
+ const properties = builder . getNodeProperties ( this ) ;
155
+
156
+ if ( properties . assign !== true ) {
157
+
158
+ return this . node . build ( ...params ) ;
159
+
160
+ }
161
+
162
+ }
163
+
164
+ return super . build ( ...params ) ;
165
+
166
+ }
167
+
104
168
generate ( builder ) {
105
169
106
170
const { node, name, readOnly } = this ;
@@ -138,7 +202,7 @@ class VarNode extends Node {
138
202
139
203
} else {
140
204
141
- const count = builder . getArrayCount ( node ) ;
205
+ const count = node . getArrayCount ( builder ) ;
142
206
143
207
declarationPrefix = `const ${ builder . getVar ( nodeVar . type , propertyName , count ) } ` ;
144
208
@@ -189,10 +253,35 @@ export const Var = ( node, name = null ) => createVar( node, name ).toStack();
189
253
*/
190
254
export const Const = ( node , name = null ) => createVar ( node , name , true ) . toStack ( ) ;
191
255
256
+ //
257
+ //
258
+
259
+ /**
260
+ * TSL function for creating a var intent node.
261
+ *
262
+ * @tsl
263
+ * @function
264
+ * @param {Node } node - The node for which a variable should be created.
265
+ * @param {?string } name - The name of the variable in the shader.
266
+ * @returns {VarNode }
267
+ */
268
+ export const VarIntent = ( node ) => {
269
+
270
+ if ( getCurrentStack ( ) === null ) {
271
+
272
+ return node ;
273
+
274
+ }
275
+
276
+ return createVar ( node ) . setIntent ( true ) . toStack ( ) ;
277
+
278
+ } ;
279
+
192
280
// Method chaining
193
281
194
282
addMethodChaining ( 'toVar' , Var ) ;
195
283
addMethodChaining ( 'toConst' , Const ) ;
284
+ addMethodChaining ( 'toVarIntent' , VarIntent ) ;
196
285
197
286
// Deprecated
198
287
0 commit comments