Skip to content

Commit eba23e3

Browse files
authored
impr (@typegpu/three): simplified variable name resolution (#2213)
1 parent ac065f2 commit eba23e3

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

packages/typegpu-three/src/typegpu-node.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type NodeFunction from 'three/src/nodes/core/NodeFunction.js';
22
import * as THREE from 'three/webgpu';
33
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';
55
import * as d from 'typegpu/data';
66
import WGSLNodeBuilder from 'three/src/renderers/webgpu/nodes/WGSLNodeBuilder.js';
77

@@ -37,12 +37,6 @@ class GenerateStageData extends StageData {
3737
super(stage);
3838
this.names = new WeakMap();
3939
this.codeGeneratedThusFar = '';
40-
41-
this.namespace.on('name', (event) => {
42-
if (isVariable(event.target)) {
43-
this.names.set(event.target, event.name);
44-
}
45-
});
4640
}
4741
}
4842

@@ -240,11 +234,17 @@ class TgpuFnNode<T> extends THREE.Node {
240234
continue;
241235
}
242236

243-
const varName = stageData.names.get(dep.var);
244237
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+
);
248248
}
249249

250250
return output === 'property' ? nodeData.custom.functionId : `${nodeData.custom.functionId}()`;

0 commit comments

Comments
 (0)