|
1 | 1 | import type NodeFunction from 'three/src/nodes/core/NodeFunction.js'; |
2 | 2 | import * as THREE from 'three/webgpu'; |
3 | 3 | import * as TSL from 'three/tsl'; |
4 | | -import tgpu, { isVariable, type Namespace, type TgpuVar } from 'typegpu'; |
| 4 | +import tgpu, { type Namespace, type TgpuVar } from 'typegpu'; |
5 | 5 | import * as d from 'typegpu/data'; |
6 | 6 | import WGSLNodeBuilder from 'three/src/renderers/webgpu/nodes/WGSLNodeBuilder.js'; |
7 | 7 |
|
@@ -37,12 +37,6 @@ class GenerateStageData extends StageData { |
37 | 37 | super(stage); |
38 | 38 | this.names = new WeakMap(); |
39 | 39 | this.codeGeneratedThusFar = ''; |
40 | | - |
41 | | - this.namespace.on('name', (event) => { |
42 | | - if (isVariable(event.target)) { |
43 | | - this.names.set(event.target, event.name); |
44 | | - } |
45 | | - }); |
46 | 40 | } |
47 | 41 | } |
48 | 42 |
|
@@ -240,11 +234,17 @@ class TgpuFnNode<T> extends THREE.Node { |
240 | 234 | continue; |
241 | 235 | } |
242 | 236 |
|
243 | | - const varName = stageData.names.get(dep.var); |
244 | 237 | const varValue = dep.node.build(builder); |
245 | | - // @ts-expect-error: It's there |
246 | | - // oxlint-disable-next-line typescript/no-base-to-string |
247 | | - builder.addLineFlowCode(`${varName} = ${varValue};\n`, this); |
| 238 | + // @ts-expect-error: it's there |
| 239 | + builder.addLineFlowCode( |
| 240 | + tgpu.resolve({ |
| 241 | + names: stageData.namespace, |
| 242 | + // oxlint-disable-next-line typescript/no-base-to-string |
| 243 | + template: `$var$ = ${varValue};\n`, |
| 244 | + externals: { $var$: dep.var }, |
| 245 | + }), |
| 246 | + this, |
| 247 | + ); |
248 | 248 | } |
249 | 249 |
|
250 | 250 | return output === 'property' ? nodeData.custom.functionId : `${nodeData.custom.functionId}()`; |
|
0 commit comments