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