@holoscript/core 6.0.4 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1 -1
- package/dist/compiler/index.d.ts +82 -0
- package/dist/constants.d.ts +3 -2
- package/dist/coordinators/index.d.ts +189 -0
- package/dist/index.d.ts +501 -19
- package/dist/paper-0c-spike/index.d.ts +29 -0
- package/dist/reconstruction/index.d.ts +78 -0
- package/dist/tools/index.d.ts +22 -1
- package/dist/traitDocs/traitDocs.d.ts +69 -0
- package/dist/traits/index.d.ts +61 -0
- package/package.json +105 -57
- package/dist/GLTFPipeline-DEN36VNK.js +0 -12
- package/dist/GLTFPipeline-YPCAK236.cjs +0 -33
- package/dist/HoloScriptPlusParser-BN6KVRCM.js +0 -692
- package/dist/HoloScriptPlusParser-NC5FE6AL.cjs +0 -697
- package/dist/USDZExporter-NTMBNTDB.js +0 -707
- package/dist/USDZExporter-UWGWNMMD.cjs +0 -709
- package/dist/chunk-27LWW5FU.cjs +0 -410
- package/dist/chunk-2CWOLHTE.js +0 -69
- package/dist/chunk-33LSUQDD.cjs +0 -835
- package/dist/chunk-3FJCK5XA.js +0 -2232
- package/dist/chunk-3FXV5S25.cjs +0 -633
- package/dist/chunk-3FYZOR7S.cjs +0 -69
- package/dist/chunk-3SAK5KFL.cjs +0 -83
- package/dist/chunk-4XSNJCLC.cjs +0 -1859
- package/dist/chunk-54FHG2MX.js +0 -655
- package/dist/chunk-56IF4NTA.js +0 -56
- package/dist/chunk-5BGSECRJ.cjs +0 -2237
- package/dist/chunk-5GLCTO44.js +0 -161
- package/dist/chunk-5O6TQC6M.cjs +0 -1871
- package/dist/chunk-5OEOHAAW.cjs +0 -682
- package/dist/chunk-5TOFIR6L.js +0 -407
- package/dist/chunk-5WUNN6ZN.cjs +0 -428
- package/dist/chunk-6TZPZCOJ.cjs +0 -1404
- package/dist/chunk-6UEHYZ7V.cjs +0 -773
- package/dist/chunk-6XSERL6L.js +0 -5678
- package/dist/chunk-72EQECGT.cjs +0 -908
- package/dist/chunk-7AGYRWKW.cjs +0 -507
- package/dist/chunk-7LCYLPW2.cjs +0 -663
- package/dist/chunk-A7PIMZGU.js +0 -263
- package/dist/chunk-ATSKSYVE.cjs +0 -51683
- package/dist/chunk-B5TCIAPQ.cjs +0 -117
- package/dist/chunk-BF2235SI.cjs +0 -5714
- package/dist/chunk-BKIGPPVM.js +0 -629
- package/dist/chunk-BND3ST2K.cjs +0 -662
- package/dist/chunk-BU7VWW2K.js +0 -2522
- package/dist/chunk-BWFJEM5A.js +0 -5419
- package/dist/chunk-CAUCGUEA.cjs +0 -130
- package/dist/chunk-CBJSLA2E.cjs +0 -5423
- package/dist/chunk-CDPGV4DN.js +0 -114
- package/dist/chunk-CLYEIWA5.cjs +0 -408
- package/dist/chunk-CS2EMTGF.js +0 -1966
- package/dist/chunk-DMG7C4H2.js +0 -975
- package/dist/chunk-DXJQDCFL.js +0 -468
- package/dist/chunk-E3FWRT3Z.js +0 -608
- package/dist/chunk-E3UALNFA.js +0 -421
- package/dist/chunk-EONILVMF.js +0 -762
- package/dist/chunk-EQV4R3EV.cjs +0 -769
- package/dist/chunk-F3HH56EB.cjs +0 -5538
- package/dist/chunk-F4IULT7N.js +0 -1488
- package/dist/chunk-FF3Q7ADR.js +0 -380
- package/dist/chunk-FFKU7BTK.cjs +0 -1046
- package/dist/chunk-FHQVYCH2.js +0 -70
- package/dist/chunk-FSF7EQVA.cjs +0 -1974
- package/dist/chunk-G4VZTCIB.js +0 -659
- package/dist/chunk-G7CT3EMP.cjs +0 -1002
- package/dist/chunk-GGHSW2NN.js +0 -51334
- package/dist/chunk-GVUR45UF.cjs +0 -777
- package/dist/chunk-H5Z7NASB.js +0 -9662
- package/dist/chunk-HE7ULERA.cjs +0 -697
- package/dist/chunk-HJJLD366.js +0 -1169
- package/dist/chunk-HPS76H7Q.js +0 -309
- package/dist/chunk-HQUEA5R6.cjs +0 -424
- package/dist/chunk-HYNTS5CP.js +0 -422
- package/dist/chunk-I6XZ5DZF.cjs +0 -488
- package/dist/chunk-IBDG74G2.cjs +0 -1219
- package/dist/chunk-IFNQFCTM.js +0 -3098
- package/dist/chunk-IHOUYQIA.js +0 -406
- package/dist/chunk-ILRBGFVD.cjs +0 -72
- package/dist/chunk-IWI6J7FX.js +0 -421
- package/dist/chunk-K3JDKWGI.cjs +0 -270
- package/dist/chunk-K6EKD26I.js +0 -630
- package/dist/chunk-KCQ5NDYC.cjs +0 -3172
- package/dist/chunk-KED34ILP.js +0 -832
- package/dist/chunk-KSGXLT74.cjs +0 -457
- package/dist/chunk-L4G4RLXX.js +0 -767
- package/dist/chunk-LDP5OK6G.js +0 -1216
- package/dist/chunk-LGGRPKTV.cjs +0 -735
- package/dist/chunk-LK5IAVH6.cjs +0 -1173
- package/dist/chunk-LSW7P7ML.js +0 -3675
- package/dist/chunk-LXJ4667L.cjs +0 -3874
- package/dist/chunk-LZ266PCM.cjs +0 -4499
- package/dist/chunk-MD6KDHVE.cjs +0 -237
- package/dist/chunk-MEASWI2Y.js +0 -126
- package/dist/chunk-MPXBVFHQ.js +0 -768
- package/dist/chunk-N5FTS757.cjs +0 -415
- package/dist/chunk-NCUKG4SK.cjs +0 -3075
- package/dist/chunk-NDQNIJEH.js +0 -1715
- package/dist/chunk-NOZZ46QU.js +0 -168
- package/dist/chunk-OFKWH2IP.js +0 -449
- package/dist/chunk-PHENW4MQ.js +0 -65
- package/dist/chunk-PMGODDJA.cjs +0 -319
- package/dist/chunk-Q4QX3AET.cjs +0 -1505
- package/dist/chunk-Q56TT7IL.js +0 -483
- package/dist/chunk-Q5JT3YML.cjs +0 -129
- package/dist/chunk-Q5SJOGHQ.cjs +0 -4256
- package/dist/chunk-QGKNANZ3.js +0 -3071
- package/dist/chunk-QLEAOI3Q.cjs +0 -424
- package/dist/chunk-R7MA7QWV.js +0 -732
- package/dist/chunk-RVYPEYPX.js +0 -678
- package/dist/chunk-S2N5TNMA.js +0 -1855
- package/dist/chunk-S565K7NK.js +0 -752
- package/dist/chunk-SDAMZIRE.js +0 -765
- package/dist/chunk-T36DDXSF.js +0 -4250
- package/dist/chunk-T4NKMBDL.js +0 -5474
- package/dist/chunk-T7LEXZUZ.cjs +0 -2526
- package/dist/chunk-TEWCN33Y.js +0 -694
- package/dist/chunk-TQSZUOW5.cjs +0 -793
- package/dist/chunk-TSH3MSQU.cjs +0 -129
- package/dist/chunk-UERJ3YJV.js +0 -504
- package/dist/chunk-UPJBDCVF.js +0 -1395
- package/dist/chunk-V3NN3HPP.js +0 -4462
- package/dist/chunk-VJ3L7CHT.cjs +0 -169
- package/dist/chunk-WB4Z63GG.js +0 -229
- package/dist/chunk-WDW67DZB.cjs +0 -9728
- package/dist/chunk-WGMEAYBG.js +0 -126
- package/dist/chunk-X4ZF6CNE.cjs +0 -473
- package/dist/chunk-X6SEAXAX.cjs +0 -3681
- package/dist/chunk-XCWFGZAA.js +0 -1043
- package/dist/chunk-XD6IYDUX.js +0 -903
- package/dist/chunk-XG23EUQX.cjs +0 -1717
- package/dist/chunk-XRKWN5PL.cjs +0 -173
- package/dist/chunk-XUILI4KB.cjs +0 -430
- package/dist/chunk-XUTX5CBW.js +0 -126
- package/dist/chunk-XWPNTWDN.cjs +0 -755
- package/dist/chunk-XXINBTZK.cjs +0 -633
- package/dist/chunk-YCXFCXDS.js +0 -1868
- package/dist/chunk-YQK5JNFK.js +0 -3725
- package/dist/chunk-YYXH45E2.js +0 -426
- package/dist/chunk-Z34RLXRA.cjs +0 -612
- package/dist/chunk-ZP4D3CSX.cjs +0 -72
- package/dist/cli/holoscript-runner.cjs +0 -2259
- package/dist/cli/holoscript-runner.js +0 -2234
- package/dist/codebase/index.cjs +0 -336
- package/dist/codebase/index.js +0 -331
- package/dist/compiler/agent-inference.cjs +0 -28
- package/dist/compiler/agent-inference.js +0 -5
- package/dist/compiler/android-xr.cjs +0 -19
- package/dist/compiler/android-xr.js +0 -9
- package/dist/compiler/android.cjs +0 -20
- package/dist/compiler/android.js +0 -10
- package/dist/compiler/ar.cjs +0 -20
- package/dist/compiler/ar.js +0 -8
- package/dist/compiler/babylon.cjs +0 -17
- package/dist/compiler/babylon.js +0 -11
- package/dist/compiler/coco.cjs +0 -27
- package/dist/compiler/coco.js +0 -4
- package/dist/compiler/domain-block-utils.cjs +0 -602
- package/dist/compiler/domain-block-utils.js +0 -8
- package/dist/compiler/dtdl.cjs +0 -24
- package/dist/compiler/dtdl.js +0 -8
- package/dist/compiler/gltf-pipeline.cjs +0 -39
- package/dist/compiler/gltf-pipeline.js +0 -4
- package/dist/compiler/godot.cjs +0 -15
- package/dist/compiler/godot.js +0 -9
- package/dist/compiler/incremental.cjs +0 -29
- package/dist/compiler/incremental.js +0 -4
- package/dist/compiler/index.cjs +0 -2578
- package/dist/compiler/index.js +0 -2383
- package/dist/compiler/ios.cjs +0 -20
- package/dist/compiler/ios.js +0 -10
- package/dist/compiler/multi-layer.cjs +0 -20
- package/dist/compiler/multi-layer.js +0 -11
- package/dist/compiler/nodetoy.cjs +0 -23
- package/dist/compiler/nodetoy.js +0 -4
- package/dist/compiler/openxr.cjs +0 -15
- package/dist/compiler/openxr.js +0 -9
- package/dist/compiler/playcanvas.cjs +0 -16
- package/dist/compiler/playcanvas.js +0 -10
- package/dist/compiler/r3f.cjs +0 -34
- package/dist/compiler/r3f.js +0 -12
- package/dist/compiler/remotion.cjs +0 -23
- package/dist/compiler/remotion.js +0 -4
- package/dist/compiler/reproducibility.cjs +0 -39
- package/dist/compiler/reproducibility.js +0 -4
- package/dist/compiler/sdf.cjs +0 -21
- package/dist/compiler/sdf.js +0 -9
- package/dist/compiler/semantic-scene.cjs +0 -31
- package/dist/compiler/semantic-scene.js +0 -4
- package/dist/compiler/state.cjs +0 -17
- package/dist/compiler/state.js +0 -7
- package/dist/compiler/trait-composition.cjs +0 -26
- package/dist/compiler/trait-composition.js +0 -5
- package/dist/compiler/unity.cjs +0 -15
- package/dist/compiler/unity.js +0 -9
- package/dist/compiler/unreal.cjs +0 -19
- package/dist/compiler/unreal.js +0 -9
- package/dist/compiler/urdf.cjs +0 -45
- package/dist/compiler/urdf.js +0 -9
- package/dist/compiler/usd-physics.cjs +0 -23
- package/dist/compiler/usd-physics.js +0 -6
- package/dist/compiler/visionos.cjs +0 -15
- package/dist/compiler/visionos.js +0 -9
- package/dist/compiler/vrchat.cjs +0 -19
- package/dist/compiler/vrchat.js +0 -9
- package/dist/compiler/vrr.cjs +0 -21
- package/dist/compiler/vrr.js +0 -9
- package/dist/compiler/wasm.cjs +0 -33
- package/dist/compiler/wasm.js +0 -9
- package/dist/compiler/webgpu.cjs +0 -15
- package/dist/compiler/webgpu.js +0 -9
- package/dist/debugger.cjs +0 -21
- package/dist/debugger.js +0 -8
- package/dist/entries/interop.cjs +0 -62
- package/dist/entries/interop.js +0 -5
- package/dist/entries/scripting.cjs +0 -68
- package/dist/entries/scripting.js +0 -11
- package/dist/index.cjs +0 -40921
- package/dist/index.js +0 -37763
- package/dist/math/vec3.cjs +0 -57
- package/dist/math/vec3.js +0 -4
- package/dist/ml-dsa-PHCWUBPX.cjs +0 -1178
- package/dist/ml-dsa-WYLJHJO6.js +0 -1178
- package/dist/parser.cjs +0 -27
- package/dist/parser.js +0 -10
- package/dist/playwright-5OSAPTNH.js +0 -98660
- package/dist/playwright-RL6GY4F7.cjs +0 -98673
- package/dist/runtime.cjs +0 -16
- package/dist/runtime.js +0 -7
- package/dist/storage/index.cjs +0 -37
- package/dist/storage/index.js +0 -4
- package/dist/traits/index.cjs +0 -14649
- package/dist/traits/index.js +0 -12243
- package/dist/type-checker.cjs +0 -18
- package/dist/type-checker.js +0 -5
package/dist/chunk-BND3ST2K.cjs
DELETED
|
@@ -1,662 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var chunkLXJ4667L_cjs = require('./chunk-LXJ4667L.cjs');
|
|
4
|
-
var chunkBF2235SI_cjs = require('./chunk-BF2235SI.cjs');
|
|
5
|
-
var chunk3SAK5KFL_cjs = require('./chunk-3SAK5KFL.cjs');
|
|
6
|
-
var platform = require('@holoscript/platform');
|
|
7
|
-
|
|
8
|
-
// src/compiler/WebGPUCompiler.ts
|
|
9
|
-
var WebGPUCompiler_exports = {};
|
|
10
|
-
chunk3SAK5KFL_cjs.__export(WebGPUCompiler_exports, {
|
|
11
|
-
WebGPUCompiler: () => exports.WebGPUCompiler
|
|
12
|
-
});
|
|
13
|
-
exports.WebGPUCompiler = void 0;
|
|
14
|
-
var init_WebGPUCompiler = chunk3SAK5KFL_cjs.__esm({
|
|
15
|
-
"src/compiler/WebGPUCompiler.ts"() {
|
|
16
|
-
chunkBF2235SI_cjs.init_CompilerBase();
|
|
17
|
-
chunkLXJ4667L_cjs.init_DomainBlockCompilerMixin();
|
|
18
|
-
exports.WebGPUCompiler = class extends chunkBF2235SI_cjs.CompilerBase {
|
|
19
|
-
constructor(options = {}) {
|
|
20
|
-
super();
|
|
21
|
-
this.compilerName = "WebGPUCompiler";
|
|
22
|
-
this.lines = [];
|
|
23
|
-
this.indentLevel = 0;
|
|
24
|
-
this.objectIndex = 0;
|
|
25
|
-
this.options = {
|
|
26
|
-
entryPoint: options.entryPoint || "main",
|
|
27
|
-
enableCompute: options.enableCompute ?? true,
|
|
28
|
-
msaa: options.msaa || 4,
|
|
29
|
-
indent: options.indent || " "
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
getRequiredCapability() {
|
|
33
|
-
return platform.ANSCapabilityPath.WEBGPU;
|
|
34
|
-
}
|
|
35
|
-
compile(composition, agentToken, outputPath) {
|
|
36
|
-
this.validateCompilerAccess(agentToken, outputPath);
|
|
37
|
-
this.lines = [];
|
|
38
|
-
this.indentLevel = 0;
|
|
39
|
-
this.objectIndex = 0;
|
|
40
|
-
this.emit("// Auto-generated by HoloScript WebGPUCompiler");
|
|
41
|
-
this.emit(
|
|
42
|
-
`// Source: composition "${this.escapeStringValue(composition.name, "TypeScript")}"`
|
|
43
|
-
);
|
|
44
|
-
this.emit("// Do not edit manually \u2014 regenerate from .holo source");
|
|
45
|
-
this.emit("");
|
|
46
|
-
this.emitDeviceInit();
|
|
47
|
-
if (composition.environment) this.emitEnvironment(composition.environment);
|
|
48
|
-
if (composition.objects) {
|
|
49
|
-
for (const obj of composition.objects) this.emitObject(obj);
|
|
50
|
-
}
|
|
51
|
-
if (composition.spatialGroups) {
|
|
52
|
-
for (const group of composition.spatialGroups) this.emitGroup(group);
|
|
53
|
-
}
|
|
54
|
-
if (composition.lights) {
|
|
55
|
-
for (const light of composition.lights) this.emitLight(light);
|
|
56
|
-
}
|
|
57
|
-
if (composition.camera) this.emitCamera(composition.camera);
|
|
58
|
-
if (this.options.enableCompute) this.emitComputeShaders(composition);
|
|
59
|
-
this.emitWebGPUDomainBlocks(composition);
|
|
60
|
-
this.emitShaderSources();
|
|
61
|
-
this.emitRenderLoop(composition);
|
|
62
|
-
return this.lines.join("\n");
|
|
63
|
-
}
|
|
64
|
-
emitWebGPUDomainBlocks(composition) {
|
|
65
|
-
const domainBlocks = composition.domainBlocks ?? [];
|
|
66
|
-
if (domainBlocks.length === 0) return;
|
|
67
|
-
this.emit("");
|
|
68
|
-
this.emit("// === v4.2 Domain Blocks ===");
|
|
69
|
-
let blockIdx = 0;
|
|
70
|
-
const compiled = chunkLXJ4667L_cjs.compileDomainBlocks(
|
|
71
|
-
domainBlocks,
|
|
72
|
-
{
|
|
73
|
-
material: (block) => {
|
|
74
|
-
const mat = chunkLXJ4667L_cjs.compileMaterialBlock(block);
|
|
75
|
-
return chunkLXJ4667L_cjs.materialToWebGPU(mat, `db${blockIdx++}`);
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
(block) => `// Domain block: ${block.domain}/${block.keyword} "${this.escapeStringValue(block.name, "TypeScript")}"`
|
|
79
|
-
);
|
|
80
|
-
for (const line of compiled) {
|
|
81
|
-
for (const l of line.split("\n")) {
|
|
82
|
-
this.emit(l);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
// ─── Device Init ──────────────────────────────────────────────────────────
|
|
87
|
-
emitDeviceInit() {
|
|
88
|
-
this.emit("// === WebGPU Device Initialization ===");
|
|
89
|
-
this.emit('const canvas = document.querySelector("canvas") as HTMLCanvasElement;');
|
|
90
|
-
this.emit("const adapter = await navigator.gpu.requestAdapter();");
|
|
91
|
-
this.emit('if (!adapter) throw new Error("WebGPU not supported");');
|
|
92
|
-
this.emit("const device = await adapter.requestDevice();");
|
|
93
|
-
this.emit('const context = canvas.getContext("webgpu") as GPUCanvasContext;');
|
|
94
|
-
this.emit("const format = navigator.gpu.getPreferredCanvasFormat();");
|
|
95
|
-
this.emit('context.configure({ device, format, alphaMode: "premultiplied" });');
|
|
96
|
-
this.emit(`const MSAA_COUNT = ${this.options.msaa};`);
|
|
97
|
-
this.emit(
|
|
98
|
-
"const msaaTexture = device.createTexture({ size: [canvas.width, canvas.height], sampleCount: MSAA_COUNT, format, usage: GPUTextureUsage.RENDER_ATTACHMENT });"
|
|
99
|
-
);
|
|
100
|
-
this.emit(
|
|
101
|
-
'const depthTexture = device.createTexture({ size: [canvas.width, canvas.height], sampleCount: MSAA_COUNT, format: "depth24plus", usage: GPUTextureUsage.RENDER_ATTACHMENT });'
|
|
102
|
-
);
|
|
103
|
-
this.emit("");
|
|
104
|
-
this.emit(
|
|
105
|
-
"function createBuffer(device: GPUDevice, data: Float32Array, usage: number): GPUBuffer {"
|
|
106
|
-
);
|
|
107
|
-
this.indent();
|
|
108
|
-
this.emit(
|
|
109
|
-
"const buf = device.createBuffer({ size: data.byteLength, usage: usage | GPUBufferUsage.COPY_DST });"
|
|
110
|
-
);
|
|
111
|
-
this.emit("device.queue.writeBuffer(buf, 0, data); return buf;");
|
|
112
|
-
this.dedent();
|
|
113
|
-
this.emit("}");
|
|
114
|
-
this.emit("function createStorageBuffer(device: GPUDevice, size: number): GPUBuffer {");
|
|
115
|
-
this.indent();
|
|
116
|
-
this.emit(
|
|
117
|
-
"return device.createBuffer({ size, usage: GPUBufferUsage.STORAGE | GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST });"
|
|
118
|
-
);
|
|
119
|
-
this.dedent();
|
|
120
|
-
this.emit("}");
|
|
121
|
-
this.emit("");
|
|
122
|
-
}
|
|
123
|
-
// ─── Environment ──────────────────────────────────────────────────────────
|
|
124
|
-
emitEnvironment(env) {
|
|
125
|
-
this.emit("// === Environment ===");
|
|
126
|
-
const envData = {};
|
|
127
|
-
for (const prop of env.properties) envData[prop.key] = prop.value;
|
|
128
|
-
const bg = envData.background || envData.skybox || "#000000";
|
|
129
|
-
const bgColor = this.parseColor(bg);
|
|
130
|
-
this.emit(
|
|
131
|
-
`const clearColor: GPUColor = { r: ${bgColor[0]}, g: ${bgColor[1]}, b: ${bgColor[2]}, a: 1.0 };`
|
|
132
|
-
);
|
|
133
|
-
if (envData.fog && typeof envData.fog === "object") {
|
|
134
|
-
const fog = envData.fog;
|
|
135
|
-
const fc = this.parseColor(fog.color || "#cccccc");
|
|
136
|
-
this.emit(
|
|
137
|
-
`const fogUniforms = createBuffer(device, new Float32Array([${fc[0]}, ${fc[1]}, ${fc[2]}, 1.0, ${fog.near ?? 10}, ${fog.far ?? 100}, 0.0, 0.0]), GPUBufferUsage.UNIFORM);`
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
if (envData.ambient_light !== void 0) {
|
|
141
|
-
this.emit(
|
|
142
|
-
`const ambientIntensity = ${typeof envData.ambient_light === "number" ? envData.ambient_light : 0.5};`
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
this.emit("");
|
|
146
|
-
}
|
|
147
|
-
// ─── Object ───────────────────────────────────────────────────────────────
|
|
148
|
-
emitObject(obj) {
|
|
149
|
-
this.objectIndex++;
|
|
150
|
-
const v = this.sanitizeName(obj.name);
|
|
151
|
-
const meshType = this.findObjProp(obj, "geometry") || this.findObjProp(obj, "mesh") || this.findObjProp(obj, "type") || "cube";
|
|
152
|
-
const modelSrc = this.findObjProp(obj, "source") || this.findObjProp(obj, "src") || this.findObjProp(obj, "model");
|
|
153
|
-
const isModel = meshType === "model" || !!modelSrc;
|
|
154
|
-
const traits = obj.traits || [];
|
|
155
|
-
this.emit(`// Object: ${this.escapeStringValue(obj.name, "TypeScript")}`);
|
|
156
|
-
const isGaussianSplat = traits.some((t) => t.name === "gaussian_splat");
|
|
157
|
-
const isPointCloud = traits.some((t) => t.name === "point_cloud");
|
|
158
|
-
const isGpuParticle = traits.some((t) => t.name === "gpu_particle");
|
|
159
|
-
if (isModel && modelSrc) {
|
|
160
|
-
this.emit(`const ${v}Model = await assetLoader.load("${modelSrc}");`);
|
|
161
|
-
const pos = this.findObjProp(obj, "position");
|
|
162
|
-
const [px, py, pz] = Array.isArray(pos) ? pos : [0, 0, 0];
|
|
163
|
-
this.emit(
|
|
164
|
-
`const ${v}ModelMatrix = createBuffer(device, new Float32Array([1,0,0,0, 0,1,0,0, 0,0,1,0, ${px},${py},${pz},1]), GPUBufferUsage.UNIFORM);`
|
|
165
|
-
);
|
|
166
|
-
} else if (isModel) {
|
|
167
|
-
this.emit(`// WARNING: geometry "model" without source URL \u2014 placeholder cube`);
|
|
168
|
-
this.emitMeshObject(v, obj, "cube");
|
|
169
|
-
} else if (isGaussianSplat) {
|
|
170
|
-
this.emitGaussianSplatObject(v, obj);
|
|
171
|
-
} else if (isPointCloud) {
|
|
172
|
-
this.emitPointCloudObject(v, obj);
|
|
173
|
-
} else if (isGpuParticle) {
|
|
174
|
-
this.emitGpuParticleObject(v, obj);
|
|
175
|
-
} else {
|
|
176
|
-
this.emitMeshObject(v, obj, meshType);
|
|
177
|
-
}
|
|
178
|
-
if (traits.some((t) => t.name === "gpu_physics")) {
|
|
179
|
-
this.emit(`const ${v}PhysicsBuf = createStorageBuffer(device, 1024 * 16); // gpu_physics`);
|
|
180
|
-
}
|
|
181
|
-
if (traits.some((t) => t.name === "compute" || t.name === "gpu_buffer")) {
|
|
182
|
-
const ct = traits.find((t) => t.name === "compute" || t.name === "gpu_buffer");
|
|
183
|
-
this.emit(
|
|
184
|
-
`const ${v}ComputeBuf = createStorageBuffer(device, ${ct?.config?.buffer_size || 4096});`
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
this.emit("");
|
|
188
|
-
if (obj.children) {
|
|
189
|
-
for (const child of obj.children) this.emitObject(child);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
emitMeshObject(v, obj, meshType) {
|
|
193
|
-
this.emit(`const ${v}Vertices = ${this.geometryVertexDataFn(meshType)};`);
|
|
194
|
-
this.emit(`const ${v}VBO = createBuffer(device, ${v}Vertices, GPUBufferUsage.VERTEX);`);
|
|
195
|
-
this.emit(`const ${v}VertexCount = ${v}Vertices.length / 6;`);
|
|
196
|
-
const pos = this.findObjProp(obj, "position");
|
|
197
|
-
const scale = this.findObjProp(obj, "scale") || this.findObjProp(obj, "size");
|
|
198
|
-
const [px, py, pz] = Array.isArray(pos) ? pos : [0, 0, 0];
|
|
199
|
-
const [sx, sy, sz] = Array.isArray(scale) ? scale : typeof scale === "number" ? [scale, scale, scale] : [1, 1, 1];
|
|
200
|
-
this.emit(
|
|
201
|
-
`const ${v}Model = createBuffer(device, new Float32Array([${sx},0,0,0, 0,${sy},0,0, 0,0,${sz},0, ${px},${py},${pz},1]), GPUBufferUsage.UNIFORM);`
|
|
202
|
-
);
|
|
203
|
-
const material = this.findObjProp(obj, "material");
|
|
204
|
-
const color = this.findObjProp(obj, "color");
|
|
205
|
-
const [cr, cg, cb] = this.extractMaterialColor(material, color);
|
|
206
|
-
const rough = this.extractMaterialProp(material, "roughness", 0.5);
|
|
207
|
-
const metal = this.extractMaterialProp(material, "metalness", 0);
|
|
208
|
-
this.emit(
|
|
209
|
-
`const ${v}Mat = createBuffer(device, new Float32Array([${cr},${cg},${cb},1.0, ${rough},${metal},0,0]), GPUBufferUsage.UNIFORM);`
|
|
210
|
-
);
|
|
211
|
-
this.emit(`const ${v}Pipeline = device.createRenderPipeline({`);
|
|
212
|
-
this.indent();
|
|
213
|
-
this.emit('layout: "auto",');
|
|
214
|
-
this.emit(
|
|
215
|
-
'vertex: { module: device.createShaderModule({ code: WGSL_VERTEX }), entryPoint: "vs_main",'
|
|
216
|
-
);
|
|
217
|
-
this.emit(
|
|
218
|
-
' buffers: [{ arrayStride: 24, attributes: [{ shaderLocation: 0, offset: 0, format: "float32x3" }, { shaderLocation: 1, offset: 12, format: "float32x3" }] }] },'
|
|
219
|
-
);
|
|
220
|
-
this.emit(
|
|
221
|
-
'fragment: { module: device.createShaderModule({ code: WGSL_FRAGMENT }), entryPoint: "fs_main", targets: [{ format }] },'
|
|
222
|
-
);
|
|
223
|
-
this.emit('primitive: { topology: "triangle-list", cullMode: "back" },');
|
|
224
|
-
this.emit(
|
|
225
|
-
`depthStencil: { format: "depth24plus", depthWriteEnabled: true, depthCompare: "less" }, multisample: { count: MSAA_COUNT },`
|
|
226
|
-
);
|
|
227
|
-
this.dedent();
|
|
228
|
-
this.emit("});");
|
|
229
|
-
this.emit(
|
|
230
|
-
`const ${v}Bind = device.createBindGroup({ layout: ${v}Pipeline.getBindGroupLayout(0), entries: [`
|
|
231
|
-
);
|
|
232
|
-
this.emit(
|
|
233
|
-
` { binding: 0, resource: { buffer: ${v}Model } }, { binding: 1, resource: { buffer: ${v}Mat } }] });`
|
|
234
|
-
);
|
|
235
|
-
}
|
|
236
|
-
emitGaussianSplatObject(v, obj) {
|
|
237
|
-
const trait = obj.traits?.find((t) => t.name === "gaussian_splat");
|
|
238
|
-
const src = trait?.config?.src || "scene.ply";
|
|
239
|
-
const max = trait?.config?.max_splats || 5e5;
|
|
240
|
-
const sorted = trait?.config?.sorted !== false;
|
|
241
|
-
this.emit(`// Gaussian Splat \u2014 source: ${src} (${sorted ? "radix-sorted" : "unsorted"})`);
|
|
242
|
-
if (sorted) {
|
|
243
|
-
this.emit(
|
|
244
|
-
`// === Wait-Free Radix Sort Pipeline (4x 8-bit Blelloch scan, no global atomics) ===`
|
|
245
|
-
);
|
|
246
|
-
this.emit(`import { GaussianSplatSorter } from '@holoscript/core/gpu/GaussianSplatSorter';`);
|
|
247
|
-
this.emit(`const ${v}Sorter = new GaussianSplatSorter(device, {`);
|
|
248
|
-
this.indent();
|
|
249
|
-
this.emit(`maxSplats: ${max},`);
|
|
250
|
-
this.emit(`canvasWidth: canvas.width,`);
|
|
251
|
-
this.emit(`canvasHeight: canvas.height,`);
|
|
252
|
-
this.dedent();
|
|
253
|
-
this.emit(`});`);
|
|
254
|
-
this.emit(`await ${v}Sorter.initialize();`);
|
|
255
|
-
this.emit(`const ${v}SplatCount = { value: 0 };`);
|
|
256
|
-
} else {
|
|
257
|
-
this.emit(`const ${v}SplatBuf = createStorageBuffer(device, ${max} * 32);`);
|
|
258
|
-
this.emit(`const ${v}SplatCount = { value: 0 };`);
|
|
259
|
-
this.emit(`const ${v}SplatPipeline = device.createRenderPipeline({`);
|
|
260
|
-
this.indent();
|
|
261
|
-
this.emit('layout: "auto",');
|
|
262
|
-
this.emit(
|
|
263
|
-
'vertex: { module: device.createShaderModule({ code: WGSL_SPLAT }), entryPoint: "vs_splat", buffers: [] },'
|
|
264
|
-
);
|
|
265
|
-
this.emit(
|
|
266
|
-
'fragment: { module: device.createShaderModule({ code: WGSL_SPLAT }), entryPoint: "fs_splat",'
|
|
267
|
-
);
|
|
268
|
-
this.emit(
|
|
269
|
-
' targets: [{ format, blend: { color: { srcFactor: "one", dstFactor: "one-minus-src-alpha", operation: "add" }, alpha: { srcFactor: "one", dstFactor: "one-minus-src-alpha", operation: "add" } } }] },'
|
|
270
|
-
);
|
|
271
|
-
this.emit('primitive: { topology: "triangle-strip" },');
|
|
272
|
-
this.emit(
|
|
273
|
-
'depthStencil: { format: "depth24plus", depthWriteEnabled: false, depthCompare: "less" },'
|
|
274
|
-
);
|
|
275
|
-
this.dedent();
|
|
276
|
-
this.emit("});");
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
emitPointCloudObject(v, obj) {
|
|
280
|
-
const trait = obj.traits?.find((t) => t.name === "point_cloud");
|
|
281
|
-
const max = trait?.config?.max_points || 1e5;
|
|
282
|
-
this.emit(`// Point Cloud (${max} max points)`);
|
|
283
|
-
this.emit(`const ${v}PointBuf = createStorageBuffer(device, ${max} * 16);`);
|
|
284
|
-
this.emit(`const ${v}PointCount = { value: 0 };`);
|
|
285
|
-
this.emit(`const ${v}PointPipeline = device.createRenderPipeline({`);
|
|
286
|
-
this.indent();
|
|
287
|
-
this.emit('layout: "auto",');
|
|
288
|
-
this.emit(
|
|
289
|
-
'vertex: { module: device.createShaderModule({ code: WGSL_POINT }), entryPoint: "vs_point",'
|
|
290
|
-
);
|
|
291
|
-
this.emit(
|
|
292
|
-
' buffers: [{ arrayStride: 16, attributes: [{ shaderLocation: 0, offset: 0, format: "float32x3" }, { shaderLocation: 1, offset: 12, format: "unorm8x4" }] }] },'
|
|
293
|
-
);
|
|
294
|
-
this.emit(
|
|
295
|
-
'fragment: { module: device.createShaderModule({ code: WGSL_POINT }), entryPoint: "fs_point", targets: [{ format }] },'
|
|
296
|
-
);
|
|
297
|
-
this.emit(
|
|
298
|
-
`primitive: { topology: "point-list" }, depthStencil: { format: "depth24plus", depthWriteEnabled: true, depthCompare: "less" }, multisample: { count: MSAA_COUNT },`
|
|
299
|
-
);
|
|
300
|
-
this.dedent();
|
|
301
|
-
this.emit("});");
|
|
302
|
-
}
|
|
303
|
-
emitGpuParticleObject(v, obj) {
|
|
304
|
-
const trait = obj.traits?.find((t) => t.name === "gpu_particle");
|
|
305
|
-
const count = trait?.config?.count || 1e4;
|
|
306
|
-
this.emit(`// GPU Particles (${count})`);
|
|
307
|
-
this.emit(`const ${v}ParticleCount = ${count};`);
|
|
308
|
-
this.emit(`const ${v}ParticleBufA = createStorageBuffer(device, ${v}ParticleCount * 32);`);
|
|
309
|
-
this.emit(`const ${v}ParticleBufB = createStorageBuffer(device, ${v}ParticleCount * 32);`);
|
|
310
|
-
this.emit(`const ${v}ParticlePipeline = device.createRenderPipeline({`);
|
|
311
|
-
this.indent();
|
|
312
|
-
this.emit('layout: "auto",');
|
|
313
|
-
this.emit(
|
|
314
|
-
'vertex: { module: device.createShaderModule({ code: WGSL_PARTICLE_RENDER }), entryPoint: "vs_particle",'
|
|
315
|
-
);
|
|
316
|
-
this.emit(
|
|
317
|
-
' buffers: [{ arrayStride: 32, attributes: [{ shaderLocation: 0, offset: 0, format: "float32x3" }, { shaderLocation: 1, offset: 12, format: "float32x3" }, { shaderLocation: 2, offset: 24, format: "float32" }] }] },'
|
|
318
|
-
);
|
|
319
|
-
this.emit(
|
|
320
|
-
'fragment: { module: device.createShaderModule({ code: WGSL_PARTICLE_RENDER }), entryPoint: "fs_particle",'
|
|
321
|
-
);
|
|
322
|
-
this.emit(
|
|
323
|
-
' targets: [{ format, blend: { color: { srcFactor: "src-alpha", dstFactor: "one", operation: "add" }, alpha: { srcFactor: "zero", dstFactor: "one", operation: "add" } } }] },'
|
|
324
|
-
);
|
|
325
|
-
this.emit(
|
|
326
|
-
'primitive: { topology: "point-list" }, depthStencil: { format: "depth24plus", depthWriteEnabled: false, depthCompare: "less" },'
|
|
327
|
-
);
|
|
328
|
-
this.dedent();
|
|
329
|
-
this.emit("});");
|
|
330
|
-
}
|
|
331
|
-
// ─── Spatial Group ────────────────────────────────────────────────────────
|
|
332
|
-
emitGroup(group) {
|
|
333
|
-
const v = this.sanitizeName(group.name);
|
|
334
|
-
this.emit(`// Spatial Group: ${this.escapeStringValue(group.name, "TypeScript")}`);
|
|
335
|
-
const pos = group.properties.find((p) => p.key === "position")?.value;
|
|
336
|
-
const [px, py, pz] = Array.isArray(pos) ? pos : [0, 0, 0];
|
|
337
|
-
this.emit(
|
|
338
|
-
`const ${v}GroupXform = createBuffer(device, new Float32Array([1,0,0,0, 0,1,0,0, 0,0,1,0, ${px},${py},${pz},1]), GPUBufferUsage.UNIFORM);`
|
|
339
|
-
);
|
|
340
|
-
for (const obj of group.objects) this.emitObject(obj);
|
|
341
|
-
if (group.groups) {
|
|
342
|
-
for (const sub of group.groups) this.emitGroup(sub);
|
|
343
|
-
}
|
|
344
|
-
this.emit("");
|
|
345
|
-
}
|
|
346
|
-
// ─── Light ────────────────────────────────────────────────────────────────
|
|
347
|
-
emitLight(light) {
|
|
348
|
-
const v = this.sanitizeName(light.name);
|
|
349
|
-
let color = [1, 1, 1], intensity = 1, pos = [0, 10, 0], dir = [0, -1, 0];
|
|
350
|
-
for (const prop of light.properties) {
|
|
351
|
-
if (prop.key === "color") color = this.parseColor(prop.value);
|
|
352
|
-
else if (prop.key === "intensity") intensity = prop.value;
|
|
353
|
-
else if (prop.key === "position" && Array.isArray(prop.value)) pos = prop.value;
|
|
354
|
-
else if (prop.key === "direction" && Array.isArray(prop.value)) dir = prop.value;
|
|
355
|
-
}
|
|
356
|
-
const ti = { directional: 0, point: 1, spot: 2, hemisphere: 3, ambient: 4, area: 5 }[light.lightType] ?? 0;
|
|
357
|
-
this.emit(
|
|
358
|
-
`// Light: ${this.escapeStringValue(light.name, "TypeScript")} (${light.lightType})`
|
|
359
|
-
);
|
|
360
|
-
this.emit(
|
|
361
|
-
`const ${v}Light = createBuffer(device, new Float32Array([${color[0] * intensity},${color[1] * intensity},${color[2] * intensity},${ti}, ${pos[0]},${pos[1]},${pos[2]},0, ${dir[0]},${dir[1]},${dir[2]},0]), GPUBufferUsage.UNIFORM);`
|
|
362
|
-
);
|
|
363
|
-
this.emit("");
|
|
364
|
-
}
|
|
365
|
-
// ─── Camera ───────────────────────────────────────────────────────────────
|
|
366
|
-
emitCamera(cam) {
|
|
367
|
-
this.emit("// === Camera ===");
|
|
368
|
-
let fov = 60, near = 0.1, far = 1e3, pos = [0, 1, 5], lookAt = [0, 0, 0];
|
|
369
|
-
for (const prop of cam.properties) {
|
|
370
|
-
if (prop.key === "fov" || prop.key === "field_of_view") fov = prop.value;
|
|
371
|
-
else if (prop.key === "near") near = prop.value;
|
|
372
|
-
else if (prop.key === "far") far = prop.value;
|
|
373
|
-
else if (prop.key === "position" && Array.isArray(prop.value)) pos = prop.value;
|
|
374
|
-
else if ((prop.key === "look_at" || prop.key === "lookAt") && Array.isArray(prop.value))
|
|
375
|
-
lookAt = prop.value;
|
|
376
|
-
}
|
|
377
|
-
this.emit(`const cameraFov = ${fov} * Math.PI / 180;`);
|
|
378
|
-
this.emit(`const cameraNear = ${near}, cameraFar = ${far};`);
|
|
379
|
-
this.emit(`const cameraPos = new Float32Array([${pos.join(",")}]);`);
|
|
380
|
-
this.emit(`const cameraTarget = new Float32Array([${lookAt.join(",")}]);`);
|
|
381
|
-
this.emit("const aspect = canvas.width / canvas.height;");
|
|
382
|
-
this.emit("function buildViewProjection(): Float32Array {");
|
|
383
|
-
this.indent();
|
|
384
|
-
this.emit("const f = 1.0 / Math.tan(cameraFov / 2), ri = 1.0 / (cameraNear - cameraFar);");
|
|
385
|
-
this.emit(
|
|
386
|
-
"return new Float32Array([f/aspect,0,0,0, 0,f,0,0, 0,0,(cameraNear+cameraFar)*ri,-1, 0,0,cameraNear*cameraFar*ri*2,0]);"
|
|
387
|
-
);
|
|
388
|
-
this.dedent();
|
|
389
|
-
this.emit("}");
|
|
390
|
-
this.emit(
|
|
391
|
-
"const vpUniform = createBuffer(device, buildViewProjection(), GPUBufferUsage.UNIFORM);"
|
|
392
|
-
);
|
|
393
|
-
this.emit("");
|
|
394
|
-
}
|
|
395
|
-
// ─── Compute Pipelines ────────────────────────────────────────────────────
|
|
396
|
-
emitComputeShaders(composition) {
|
|
397
|
-
const gpuObjs = (composition.objects || []).filter(
|
|
398
|
-
(o) => o.traits?.some(
|
|
399
|
-
(t) => t.name === "gpu_particle" || t.name === "gpu_physics" || t.name === "compute"
|
|
400
|
-
)
|
|
401
|
-
);
|
|
402
|
-
if (gpuObjs.length === 0) return;
|
|
403
|
-
this.emit("// === Compute Pipelines ===");
|
|
404
|
-
for (const obj of gpuObjs) {
|
|
405
|
-
const v = this.sanitizeName(obj.name);
|
|
406
|
-
const traits = obj.traits || [];
|
|
407
|
-
if (traits.some((t) => t.name === "gpu_particle")) {
|
|
408
|
-
const count = traits.find((t) => t.name === "gpu_particle")?.config?.count || 1e4;
|
|
409
|
-
this.emit(
|
|
410
|
-
`const ${v}ParticleCompute = device.createComputePipeline({ layout: "auto", compute: { module: device.createShaderModule({ code: WGSL_PARTICLE_COMPUTE }), entryPoint: "cs_particle_update" } });`
|
|
411
|
-
);
|
|
412
|
-
this.emit(`const ${v}ComputeDispatches = ${Math.ceil(count / 64)};`);
|
|
413
|
-
}
|
|
414
|
-
if (traits.some((t) => t.name === "gpu_physics")) {
|
|
415
|
-
this.emit(
|
|
416
|
-
`const ${v}PhysicsCompute = device.createComputePipeline({ layout: "auto", compute: { module: device.createShaderModule({ code: WGSL_PHYSICS_COMPUTE }), entryPoint: "cs_physics_step" } });`
|
|
417
|
-
);
|
|
418
|
-
}
|
|
419
|
-
if (traits.some((t) => t.name === "compute")) {
|
|
420
|
-
const ct = traits.find((t) => t.name === "compute");
|
|
421
|
-
const entry = ct?.config?.shader || "custom_compute";
|
|
422
|
-
const wg = ct?.config?.workgroups || [64, 1, 1];
|
|
423
|
-
this.emit(
|
|
424
|
-
`const ${v}CustomCompute = device.createComputePipeline({ layout: "auto", compute: { module: device.createShaderModule({ code: WGSL_CUSTOM_${v.toUpperCase()} }), entryPoint: "${entry}" } });`
|
|
425
|
-
);
|
|
426
|
-
this.emit(`const ${v}Workgroups: [number, number, number] = [${wg}];`);
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
this.emit("");
|
|
430
|
-
}
|
|
431
|
-
// ─── WGSL Shader Sources ──────────────────────────────────────────────────
|
|
432
|
-
emitShaderSources() {
|
|
433
|
-
this.emit("// === WGSL Shader Sources ===");
|
|
434
|
-
this.emit("const WGSL_VERTEX = /* wgsl */`");
|
|
435
|
-
this.emit("struct Uniforms { model: mat4x4<f32> };");
|
|
436
|
-
this.emit("@group(0) @binding(0) var<uniform> u: Uniforms;");
|
|
437
|
-
this.emit("struct VIn { @location(0) pos: vec3<f32>, @location(1) norm: vec3<f32> };");
|
|
438
|
-
this.emit(
|
|
439
|
-
"struct VOut { @builtin(position) clip: vec4<f32>, @location(0) wNorm: vec3<f32>, @location(1) wPos: vec3<f32> };"
|
|
440
|
-
);
|
|
441
|
-
this.emit("@vertex fn vs_main(i: VIn) -> VOut {");
|
|
442
|
-
this.emit(" var o: VOut; let w = u.model * vec4<f32>(i.pos, 1.0);");
|
|
443
|
-
this.emit(
|
|
444
|
-
" o.clip = w; o.wNorm = (u.model * vec4<f32>(i.norm, 0.0)).xyz; o.wPos = w.xyz; return o; }`;"
|
|
445
|
-
);
|
|
446
|
-
this.emit("");
|
|
447
|
-
this.emit("const WGSL_FRAGMENT = /* wgsl */`");
|
|
448
|
-
this.emit("struct Mat { color: vec4<f32>, rm: vec4<f32> };");
|
|
449
|
-
this.emit("@group(0) @binding(1) var<uniform> mat: Mat;");
|
|
450
|
-
this.emit("struct FIn { @location(0) wNorm: vec3<f32>, @location(1) wPos: vec3<f32> };");
|
|
451
|
-
this.emit("@fragment fn fs_main(i: FIn) -> @location(0) vec4<f32> {");
|
|
452
|
-
this.emit(" let N = normalize(i.wNorm); let L = normalize(vec3<f32>(1.0, 2.0, 1.5));");
|
|
453
|
-
this.emit(" let d = max(dot(N, L), 0.0) * (1.0 - mat.rm.x * 0.5);");
|
|
454
|
-
this.emit(" return vec4<f32>(mat.color.rgb * (0.15 + d), mat.color.a); }`;");
|
|
455
|
-
this.emit("");
|
|
456
|
-
this.emit("const WGSL_SPLAT = /* wgsl */`");
|
|
457
|
-
this.emit(
|
|
458
|
-
"struct Splat { center: vec3<f32>, opacity: f32, cov: array<f32,6>, sh: vec3<f32> };"
|
|
459
|
-
);
|
|
460
|
-
this.emit("@group(0) @binding(0) var<storage, read> splats: array<Splat>;");
|
|
461
|
-
this.emit(
|
|
462
|
-
"struct SO { @builtin(position) p: vec4<f32>, @location(0) c: vec4<f32>, @location(1) uv: vec2<f32> };"
|
|
463
|
-
);
|
|
464
|
-
this.emit(
|
|
465
|
-
"@vertex fn vs_splat(@builtin(vertex_index) vi: u32, @builtin(instance_index) ii: u32) -> SO {"
|
|
466
|
-
);
|
|
467
|
-
this.emit(" var q = array<vec2<f32>,4>(vec2(-1,-1),vec2(1,-1),vec2(-1,1),vec2(1,1));");
|
|
468
|
-
this.emit(
|
|
469
|
-
" var o: SO; let s = splats[ii]; o.p = vec4<f32>(s.center.xy + q[vi]*0.01, s.center.z, 1.0);"
|
|
470
|
-
);
|
|
471
|
-
this.emit(" o.c = vec4<f32>(s.sh, s.opacity); o.uv = q[vi]; return o; }");
|
|
472
|
-
this.emit("@fragment fn fs_splat(i: SO) -> @location(0) vec4<f32> {");
|
|
473
|
-
this.emit(" let a = i.c.a * exp(-dot(i.uv, i.uv) * 4.0); if (a < 0.01) { discard; }");
|
|
474
|
-
this.emit(" return vec4<f32>(i.c.rgb * a, a); }`;");
|
|
475
|
-
this.emit("");
|
|
476
|
-
this.emit("const WGSL_POINT = /* wgsl */`");
|
|
477
|
-
this.emit("struct PO { @builtin(position) p: vec4<f32>, @location(0) c: vec4<f32> };");
|
|
478
|
-
this.emit(
|
|
479
|
-
"@vertex fn vs_point(@location(0) pos: vec3<f32>, @location(1) col: vec4<f32>) -> PO { var o: PO; o.p = vec4<f32>(pos, 1.0); o.c = col; return o; }"
|
|
480
|
-
);
|
|
481
|
-
this.emit("@fragment fn fs_point(i: PO) -> @location(0) vec4<f32> { return i.c; }`;");
|
|
482
|
-
this.emit("");
|
|
483
|
-
this.emit("const WGSL_PARTICLE_RENDER = /* wgsl */`");
|
|
484
|
-
this.emit("struct PVO { @builtin(position) p: vec4<f32>, @location(0) life: f32 };");
|
|
485
|
-
this.emit(
|
|
486
|
-
"@vertex fn vs_particle(@location(0) pos: vec3<f32>, @location(1) vel: vec3<f32>, @location(2) life: f32) -> PVO { var o: PVO; o.p = vec4<f32>(pos, 1.0); o.life = life; return o; }"
|
|
487
|
-
);
|
|
488
|
-
this.emit("@fragment fn fs_particle(i: PVO) -> @location(0) vec4<f32> {");
|
|
489
|
-
this.emit(
|
|
490
|
-
" let t = clamp(i.life, 0.0, 1.0); return vec4<f32>(mix(vec3(1.0,0.2,0.0), vec3(1.0,1.0,0.5), t), t*0.8); }`;"
|
|
491
|
-
);
|
|
492
|
-
this.emit("");
|
|
493
|
-
this.emit("const WGSL_PARTICLE_COMPUTE = /* wgsl */`");
|
|
494
|
-
this.emit("struct P { pos: vec3<f32>, _p0: f32, vel: vec3<f32>, life: f32 };");
|
|
495
|
-
this.emit("@group(0) @binding(0) var<storage, read> pin: array<P>;");
|
|
496
|
-
this.emit("@group(0) @binding(1) var<storage, read_write> pout: array<P>;");
|
|
497
|
-
this.emit("@group(0) @binding(2) var<uniform> dt: f32;");
|
|
498
|
-
this.emit(
|
|
499
|
-
"@compute @workgroup_size(64) fn cs_particle_update(@builtin(global_invocation_id) gid: vec3<u32>) {"
|
|
500
|
-
);
|
|
501
|
-
this.emit(" let i = gid.x; if (i >= arrayLength(&pin)) { return; } var p = pin[i];");
|
|
502
|
-
this.emit(" p.vel.y -= 9.81 * dt; p.pos += p.vel * dt; p.life -= dt;");
|
|
503
|
-
this.emit(
|
|
504
|
-
" if (p.life <= 0.0) { p.pos = vec3(0.0); p.vel = vec3(0.0, 5.0, 0.0); p.life = 2.0; }"
|
|
505
|
-
);
|
|
506
|
-
this.emit(" pout[i] = p; }`;");
|
|
507
|
-
this.emit("");
|
|
508
|
-
this.emit("const WGSL_PHYSICS_COMPUTE = /* wgsl */`");
|
|
509
|
-
this.emit("struct Body { pos: vec3<f32>, mass: f32, vel: vec3<f32>, _p: f32 };");
|
|
510
|
-
this.emit("@group(0) @binding(0) var<storage, read_write> bodies: array<Body>;");
|
|
511
|
-
this.emit("@group(0) @binding(1) var<uniform> dt: f32;");
|
|
512
|
-
this.emit(
|
|
513
|
-
"@compute @workgroup_size(64) fn cs_physics_step(@builtin(global_invocation_id) gid: vec3<u32>) {"
|
|
514
|
-
);
|
|
515
|
-
this.emit(" let i = gid.x; if (i >= arrayLength(&bodies)) { return; } var b = bodies[i];");
|
|
516
|
-
this.emit(" b.vel.y -= 9.81 * dt; b.pos += b.vel * dt;");
|
|
517
|
-
this.emit(
|
|
518
|
-
" if (b.pos.y < 0.0) { b.pos.y = 0.0; b.vel.y = -b.vel.y * 0.6; } bodies[i] = b; }`;"
|
|
519
|
-
);
|
|
520
|
-
this.emit("");
|
|
521
|
-
}
|
|
522
|
-
// ─── Render Loop ──────────────────────────────────────────────────────────
|
|
523
|
-
emitRenderLoop(composition) {
|
|
524
|
-
this.emit("// === Render Loop ===");
|
|
525
|
-
this.emit("let frameCount = 0;");
|
|
526
|
-
this.emit("const t0 = performance.now();");
|
|
527
|
-
this.emit("function frame() {");
|
|
528
|
-
this.indent();
|
|
529
|
-
this.emit("frameCount++;");
|
|
530
|
-
this.emit("const time = (performance.now() - t0) / 1000.0;");
|
|
531
|
-
this.emit("const enc = device.createCommandEncoder();");
|
|
532
|
-
const gpuObjs = (composition.objects || []).filter(
|
|
533
|
-
(o) => o.traits?.some(
|
|
534
|
-
(t) => t.name === "gpu_particle" || t.name === "gpu_physics" || t.name === "compute"
|
|
535
|
-
)
|
|
536
|
-
);
|
|
537
|
-
if (gpuObjs.length > 0 && this.options.enableCompute) {
|
|
538
|
-
this.emit("const cp = enc.beginComputePass();");
|
|
539
|
-
for (const obj of gpuObjs) {
|
|
540
|
-
const v = this.sanitizeName(obj.name);
|
|
541
|
-
if (obj.traits?.some((t) => t.name === "gpu_particle")) {
|
|
542
|
-
this.emit(
|
|
543
|
-
`cp.setPipeline(${v}ParticleCompute); cp.dispatchWorkgroups(${v}ComputeDispatches);`
|
|
544
|
-
);
|
|
545
|
-
}
|
|
546
|
-
if (obj.traits?.some((t) => t.name === "gpu_physics")) {
|
|
547
|
-
this.emit(`cp.setPipeline(${v}PhysicsCompute); cp.dispatchWorkgroups(16);`);
|
|
548
|
-
}
|
|
549
|
-
if (obj.traits?.some((t) => t.name === "compute")) {
|
|
550
|
-
this.emit(`cp.setPipeline(${v}CustomCompute); cp.dispatchWorkgroups(...${v}Workgroups);`);
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
this.emit("cp.end();");
|
|
554
|
-
}
|
|
555
|
-
this.emit("const rp = enc.beginRenderPass({");
|
|
556
|
-
this.indent();
|
|
557
|
-
this.emit(
|
|
558
|
-
'colorAttachments: [{ view: msaaTexture.createView(), resolveTarget: context.getCurrentTexture().createView(), clearValue: clearColor, loadOp: "clear", storeOp: "store" }],'
|
|
559
|
-
);
|
|
560
|
-
this.emit(
|
|
561
|
-
'depthStencilAttachment: { view: depthTexture.createView(), depthClearValue: 1.0, depthLoadOp: "clear", depthStoreOp: "store" },'
|
|
562
|
-
);
|
|
563
|
-
this.dedent();
|
|
564
|
-
this.emit("});");
|
|
565
|
-
if (composition.objects) {
|
|
566
|
-
for (const obj of composition.objects) this.emitDrawCall(obj);
|
|
567
|
-
}
|
|
568
|
-
if (composition.spatialGroups) {
|
|
569
|
-
for (const group of composition.spatialGroups) {
|
|
570
|
-
for (const obj of group.objects) this.emitDrawCall(obj);
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
this.emit("rp.end();");
|
|
574
|
-
this.emit("device.queue.submit([enc.finish()]);");
|
|
575
|
-
this.emit("requestAnimationFrame(frame);");
|
|
576
|
-
this.dedent();
|
|
577
|
-
this.emit("}");
|
|
578
|
-
this.emit("requestAnimationFrame(frame);");
|
|
579
|
-
}
|
|
580
|
-
emitDrawCall(obj) {
|
|
581
|
-
const v = this.sanitizeName(obj.name);
|
|
582
|
-
const traits = obj.traits || [];
|
|
583
|
-
if (traits.some((t) => t.name === "gaussian_splat")) {
|
|
584
|
-
this.emit(`rp.setPipeline(${v}SplatPipeline); rp.draw(4, ${v}SplatCount.value);`);
|
|
585
|
-
} else if (traits.some((t) => t.name === "point_cloud")) {
|
|
586
|
-
this.emit(`rp.setPipeline(${v}PointPipeline); rp.draw(${v}PointCount.value);`);
|
|
587
|
-
} else if (traits.some((t) => t.name === "gpu_particle")) {
|
|
588
|
-
this.emit(
|
|
589
|
-
`rp.setPipeline(${v}ParticlePipeline); rp.setVertexBuffer(0, ${v}ParticleBufA); rp.draw(${v}ParticleCount);`
|
|
590
|
-
);
|
|
591
|
-
} else {
|
|
592
|
-
this.emit(
|
|
593
|
-
`rp.setPipeline(${v}Pipeline); rp.setBindGroup(0, ${v}Bind); rp.setVertexBuffer(0, ${v}VBO); rp.draw(${v}VertexCount);`
|
|
594
|
-
);
|
|
595
|
-
}
|
|
596
|
-
if (obj.children) {
|
|
597
|
-
for (const child of obj.children) this.emitDrawCall(child);
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
// ─── Helpers ──────────────────────────────────────────────────────────────
|
|
601
|
-
emit(line) {
|
|
602
|
-
this.lines.push(this.options.indent.repeat(this.indentLevel) + line);
|
|
603
|
-
}
|
|
604
|
-
indent() {
|
|
605
|
-
this.indentLevel++;
|
|
606
|
-
}
|
|
607
|
-
dedent() {
|
|
608
|
-
this.indentLevel = Math.max(0, this.indentLevel - 1);
|
|
609
|
-
}
|
|
610
|
-
sanitizeName(name) {
|
|
611
|
-
return name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
612
|
-
}
|
|
613
|
-
findObjProp(obj, key) {
|
|
614
|
-
return obj.properties?.find((p) => p.key === key)?.value;
|
|
615
|
-
}
|
|
616
|
-
parseColor(value) {
|
|
617
|
-
if (typeof value === "string" && value.startsWith("#")) {
|
|
618
|
-
const h = value.slice(1);
|
|
619
|
-
return [
|
|
620
|
-
parseFloat((parseInt(h.substring(0, 2), 16) / 255).toFixed(4)),
|
|
621
|
-
parseFloat((parseInt(h.substring(2, 4), 16) / 255).toFixed(4)),
|
|
622
|
-
parseFloat((parseInt(h.substring(4, 6), 16) / 255).toFixed(4))
|
|
623
|
-
];
|
|
624
|
-
}
|
|
625
|
-
if (Array.isArray(value) && value.length >= 3) return [value[0], value[1], value[2]];
|
|
626
|
-
return [1, 1, 1];
|
|
627
|
-
}
|
|
628
|
-
extractMaterialColor(material, color) {
|
|
629
|
-
if (color) return this.parseColor(color);
|
|
630
|
-
if (material && typeof material === "object" && !Array.isArray(material)) {
|
|
631
|
-
const m = material;
|
|
632
|
-
if (m.color) return this.parseColor(m.color);
|
|
633
|
-
}
|
|
634
|
-
return [0.8, 0.8, 0.8];
|
|
635
|
-
}
|
|
636
|
-
extractMaterialProp(material, key, fallback) {
|
|
637
|
-
if (material && typeof material === "object" && !Array.isArray(material)) {
|
|
638
|
-
const m = material;
|
|
639
|
-
if (m[key] !== void 0) return m[key];
|
|
640
|
-
}
|
|
641
|
-
return fallback;
|
|
642
|
-
}
|
|
643
|
-
geometryVertexDataFn(meshType) {
|
|
644
|
-
const map = {
|
|
645
|
-
sphere: "generateSphereVertices(0.5, 16, 16)",
|
|
646
|
-
orb: "generateSphereVertices(0.5, 16, 16)",
|
|
647
|
-
plane: "generatePlaneVertices(1.0, 1.0)",
|
|
648
|
-
cylinder: "generateCylinderVertices(0.5, 1.0, 16)",
|
|
649
|
-
cone: "generateConeVertices(0.5, 1.0, 16)",
|
|
650
|
-
pyramid: "generateConeVertices(0.5, 1.0, 16)",
|
|
651
|
-
torus: "generateTorusVertices(0.5, 0.15, 16, 32)"
|
|
652
|
-
};
|
|
653
|
-
return map[meshType] || "generateCubeVertices(1.0)";
|
|
654
|
-
}
|
|
655
|
-
};
|
|
656
|
-
}
|
|
657
|
-
});
|
|
658
|
-
|
|
659
|
-
exports.WebGPUCompiler_exports = WebGPUCompiler_exports;
|
|
660
|
-
exports.init_WebGPUCompiler = init_WebGPUCompiler;
|
|
661
|
-
//# sourceMappingURL=chunk-BND3ST2K.cjs.map
|
|
662
|
-
//# sourceMappingURL=chunk-BND3ST2K.cjs.map
|