@holoscript/core 6.0.3 → 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 (244) hide show
  1. package/README.md +40 -40
  2. package/dist/codebase/index.d.ts +25 -0
  3. package/dist/compiler/index.d.ts +82 -0
  4. package/dist/constants.d.ts +4 -0
  5. package/dist/coordinators/index.d.ts +189 -0
  6. package/dist/entries/interop.d.ts +9 -0
  7. package/dist/entries/scripting.d.ts +7 -0
  8. package/dist/index.d.ts +520 -19
  9. package/dist/paper-0c-spike/index.d.ts +29 -0
  10. package/dist/reconstruction/index.d.ts +78 -0
  11. package/dist/self-improvement/index.d.ts +0 -48
  12. package/dist/storage/index.d.ts +24 -0
  13. package/dist/tools/index.d.ts +33 -0
  14. package/dist/traitDocs/traitDocs.d.ts +69 -0
  15. package/dist/traits/index.d.ts +61 -0
  16. package/package.json +102 -19
  17. package/dist/GLTFPipeline-3KLWWUQO.cjs +0 -34
  18. package/dist/GLTFPipeline-LYII2ZVQ.js +0 -13
  19. package/dist/HoloScriptPlusParser-BZR5DELQ.js +0 -692
  20. package/dist/HoloScriptPlusParser-SBMYDNXO.cjs +0 -697
  21. package/dist/USDZExporter-MHEHXZB4.cjs +0 -709
  22. package/dist/USDZExporter-YA55ZS35.js +0 -707
  23. package/dist/chunk-26TLYBFD.js +0 -309
  24. package/dist/chunk-27LWW5FU.cjs +0 -410
  25. package/dist/chunk-2UX5LRAP.cjs +0 -833
  26. package/dist/chunk-32TWR3HE.js +0 -70
  27. package/dist/chunk-3FXV5S25.cjs +0 -633
  28. package/dist/chunk-3FYZOR7S.cjs +0 -69
  29. package/dist/chunk-3KEU5QYY.cjs +0 -175
  30. package/dist/chunk-4FCZDTD5.js +0 -610
  31. package/dist/chunk-4KJ2R7VP.cjs +0 -507
  32. package/dist/chunk-4SMUJFHL.js +0 -1213
  33. package/dist/chunk-54FHG2MX.js +0 -655
  34. package/dist/chunk-56IF4NTA.js +0 -56
  35. package/dist/chunk-5GLCTO44.js +0 -161
  36. package/dist/chunk-5TOFIR6L.js +0 -407
  37. package/dist/chunk-65RFOWZI.js +0 -765
  38. package/dist/chunk-6OQBLABR.js +0 -5240
  39. package/dist/chunk-6WNCRE6F.js +0 -126
  40. package/dist/chunk-74YCHHTE.js +0 -1872
  41. package/dist/chunk-7H5UNJZD.cjs +0 -1973
  42. package/dist/chunk-7KPI4EKH.cjs +0 -701
  43. package/dist/chunk-7LCYLPW2.cjs +0 -663
  44. package/dist/chunk-7N3JIJMT.js +0 -1395
  45. package/dist/chunk-7X2IEJIE.cjs +0 -2526
  46. package/dist/chunk-A6GO3DPZ.cjs +0 -1002
  47. package/dist/chunk-AC4BSHFV.js +0 -765
  48. package/dist/chunk-AIUXRS74.cjs +0 -3681
  49. package/dist/chunk-ARNKA274.cjs +0 -130
  50. package/dist/chunk-AW7WAELW.js +0 -975
  51. package/dist/chunk-BKIGPPVM.js +0 -629
  52. package/dist/chunk-BO2OKHIY.js +0 -6055
  53. package/dist/chunk-BU5ZAFMC.js +0 -115
  54. package/dist/chunk-BY3B7ZYV.cjs +0 -457
  55. package/dist/chunk-C2QHVHZF.js +0 -4066
  56. package/dist/chunk-C7BNX4XJ.js +0 -1043
  57. package/dist/chunk-CLYEIWA5.cjs +0 -408
  58. package/dist/chunk-CMYAWUX3.js +0 -4455
  59. package/dist/chunk-CN4NOESF.cjs +0 -416
  60. package/dist/chunk-CNVM7J3M.js +0 -883
  61. package/dist/chunk-CO2VM2DK.js +0 -1965
  62. package/dist/chunk-CQDOF3G7.cjs +0 -1404
  63. package/dist/chunk-DH5G2JUA.cjs +0 -614
  64. package/dist/chunk-DIEDKX5B.cjs +0 -660
  65. package/dist/chunk-DN7UFU63.cjs +0 -172
  66. package/dist/chunk-DXVCEFZB.js +0 -2027
  67. package/dist/chunk-EGIZHYJP.cjs +0 -85
  68. package/dist/chunk-EJA7G2C4.cjs +0 -428
  69. package/dist/chunk-ELLQPFAF.js +0 -830
  70. package/dist/chunk-EMO7HAKJ.cjs +0 -1875
  71. package/dist/chunk-ENV7K6XA.js +0 -282
  72. package/dist/chunk-EPWRXL6S.js +0 -2522
  73. package/dist/chunk-EUFLX2PI.js +0 -56956
  74. package/dist/chunk-F5LVGHNT.js +0 -449
  75. package/dist/chunk-FEFHPUEM.cjs +0 -6122
  76. package/dist/chunk-FF3Q7ADR.js +0 -380
  77. package/dist/chunk-GC3YU46J.js +0 -762
  78. package/dist/chunk-H6WMMLQK.cjs +0 -4492
  79. package/dist/chunk-H7XMORZI.js +0 -2731
  80. package/dist/chunk-HAN4V3PF.cjs +0 -2037
  81. package/dist/chunk-HBZYCASG.js +0 -4208
  82. package/dist/chunk-HF4OFY25.cjs +0 -4097
  83. package/dist/chunk-HHS6FMOU.cjs +0 -3813
  84. package/dist/chunk-HJJLD366.js +0 -1169
  85. package/dist/chunk-HKCVM6OK.cjs +0 -2237
  86. package/dist/chunk-HUFNKFA6.js +0 -698
  87. package/dist/chunk-I3XGTIHM.cjs +0 -1505
  88. package/dist/chunk-I6XZ5DZF.cjs +0 -488
  89. package/dist/chunk-IHOUYQIA.js +0 -406
  90. package/dist/chunk-ILRBGFVD.cjs +0 -72
  91. package/dist/chunk-KDB6BUMB.js +0 -3666
  92. package/dist/chunk-KUJRR4FJ.js +0 -657
  93. package/dist/chunk-KYM4XRFG.js +0 -421
  94. package/dist/chunk-L3Z2HIWJ.cjs +0 -793
  95. package/dist/chunk-LBPEZQAF.js +0 -2232
  96. package/dist/chunk-LER4WXW5.cjs +0 -286
  97. package/dist/chunk-LK5IAVH6.cjs +0 -1173
  98. package/dist/chunk-M6FU6S22.js +0 -2911
  99. package/dist/chunk-MWEFR6YQ.js +0 -1857
  100. package/dist/chunk-N5FTS757.cjs +0 -415
  101. package/dist/chunk-NCUHGRTZ.js +0 -752
  102. package/dist/chunk-NKRKT6V2.js +0 -69
  103. package/dist/chunk-NLPSZT4C.js +0 -630
  104. package/dist/chunk-NRUB55IT.cjs +0 -771
  105. package/dist/chunk-NTMZSDXM.cjs +0 -633
  106. package/dist/chunk-ODGMVILH.js +0 -9662
  107. package/dist/chunk-PBA6NXCT.cjs +0 -1216
  108. package/dist/chunk-PHENW4MQ.js +0 -65
  109. package/dist/chunk-PJMOXFPR.cjs +0 -1861
  110. package/dist/chunk-PLMYCCA4.js +0 -504
  111. package/dist/chunk-PPULB4GG.cjs +0 -9728
  112. package/dist/chunk-PQLGZKMC.cjs +0 -755
  113. package/dist/chunk-Q56TT7IL.js +0 -483
  114. package/dist/chunk-QHVVVN47.cjs +0 -2033
  115. package/dist/chunk-QWKUKVRE.js +0 -2026
  116. package/dist/chunk-RE3OKSYF.cjs +0 -424
  117. package/dist/chunk-RT7LJRSF.cjs +0 -57378
  118. package/dist/chunk-SPDELRRV.cjs +0 -319
  119. package/dist/chunk-SUCBB66F.js +0 -229
  120. package/dist/chunk-TSWTWZ42.cjs +0 -4214
  121. package/dist/chunk-UITWA6DV.cjs +0 -2829
  122. package/dist/chunk-UQW6SLM5.js +0 -172
  123. package/dist/chunk-V2ILLPHK.cjs +0 -237
  124. package/dist/chunk-V42NTCFH.js +0 -3645
  125. package/dist/chunk-VJ3L7CHT.cjs +0 -169
  126. package/dist/chunk-VJVCD5T5.cjs +0 -769
  127. package/dist/chunk-VK5AXKO3.js +0 -746
  128. package/dist/chunk-VSXOIUCF.cjs +0 -473
  129. package/dist/chunk-VZNKJZTT.cjs +0 -749
  130. package/dist/chunk-W76ETJTI.js +0 -678
  131. package/dist/chunk-WFJIDI2N.cjs +0 -424
  132. package/dist/chunk-WN3YF33G.cjs +0 -118
  133. package/dist/chunk-WUXIRGZP.cjs +0 -2915
  134. package/dist/chunk-WYH4GVZ5.js +0 -1488
  135. package/dist/chunk-X4YVN7H3.cjs +0 -888
  136. package/dist/chunk-X67XRI2T.js +0 -410
  137. package/dist/chunk-XDXZM3ZP.cjs +0 -1046
  138. package/dist/chunk-XH7SE4HH.cjs +0 -72
  139. package/dist/chunk-XNMEH2BI.js +0 -126
  140. package/dist/chunk-XSF76QRU.js +0 -468
  141. package/dist/chunk-XSUZMPVQ.cjs +0 -682
  142. package/dist/chunk-XUILI4KB.cjs +0 -430
  143. package/dist/chunk-Y5MUAYTO.js +0 -167
  144. package/dist/chunk-Y7VK5TH3.cjs +0 -129
  145. package/dist/chunk-YCMQQQ5U.cjs +0 -5244
  146. package/dist/chunk-YYXH45E2.js +0 -426
  147. package/dist/chunk-ZGTGVSTZ.js +0 -422
  148. package/dist/chunk-ZL6VJ6SN.js +0 -421
  149. package/dist/cli/holoscript-runner.cjs +0 -2258
  150. package/dist/cli/holoscript-runner.js +0 -2233
  151. package/dist/codebase/index.cjs +0 -336
  152. package/dist/codebase/index.js +0 -331
  153. package/dist/compiler/agent-inference.cjs +0 -29
  154. package/dist/compiler/agent-inference.js +0 -6
  155. package/dist/compiler/android-xr.cjs +0 -20
  156. package/dist/compiler/android-xr.js +0 -10
  157. package/dist/compiler/android.cjs +0 -21
  158. package/dist/compiler/android.js +0 -11
  159. package/dist/compiler/ar.cjs +0 -21
  160. package/dist/compiler/ar.js +0 -9
  161. package/dist/compiler/babylon.cjs +0 -18
  162. package/dist/compiler/babylon.js +0 -12
  163. package/dist/compiler/coco.cjs +0 -27
  164. package/dist/compiler/coco.js +0 -4
  165. package/dist/compiler/domain-block-utils.cjs +0 -595
  166. package/dist/compiler/domain-block-utils.js +0 -9
  167. package/dist/compiler/dtdl.cjs +0 -25
  168. package/dist/compiler/dtdl.js +0 -9
  169. package/dist/compiler/gltf-pipeline.cjs +0 -39
  170. package/dist/compiler/gltf-pipeline.js +0 -4
  171. package/dist/compiler/godot.cjs +0 -16
  172. package/dist/compiler/godot.js +0 -10
  173. package/dist/compiler/incremental.cjs +0 -30
  174. package/dist/compiler/incremental.js +0 -5
  175. package/dist/compiler/index.cjs +0 -1522
  176. package/dist/compiler/index.js +0 -1321
  177. package/dist/compiler/ios.cjs +0 -21
  178. package/dist/compiler/ios.js +0 -11
  179. package/dist/compiler/multi-layer.cjs +0 -27
  180. package/dist/compiler/multi-layer.js +0 -12
  181. package/dist/compiler/nodetoy.cjs +0 -23
  182. package/dist/compiler/nodetoy.js +0 -4
  183. package/dist/compiler/openxr.cjs +0 -16
  184. package/dist/compiler/openxr.js +0 -10
  185. package/dist/compiler/playcanvas.cjs +0 -17
  186. package/dist/compiler/playcanvas.js +0 -11
  187. package/dist/compiler/r3f.cjs +0 -35
  188. package/dist/compiler/r3f.js +0 -13
  189. package/dist/compiler/remotion.cjs +0 -23
  190. package/dist/compiler/remotion.js +0 -4
  191. package/dist/compiler/reproducibility.cjs +0 -39
  192. package/dist/compiler/reproducibility.js +0 -4
  193. package/dist/compiler/sdf.cjs +0 -22
  194. package/dist/compiler/sdf.js +0 -10
  195. package/dist/compiler/semantic-scene.cjs +0 -31
  196. package/dist/compiler/semantic-scene.js +0 -4
  197. package/dist/compiler/state.cjs +0 -18
  198. package/dist/compiler/state.js +0 -8
  199. package/dist/compiler/trait-composition.cjs +0 -27
  200. package/dist/compiler/trait-composition.js +0 -6
  201. package/dist/compiler/unity.cjs +0 -16
  202. package/dist/compiler/unity.js +0 -10
  203. package/dist/compiler/unreal.cjs +0 -20
  204. package/dist/compiler/unreal.js +0 -10
  205. package/dist/compiler/urdf.cjs +0 -46
  206. package/dist/compiler/urdf.js +0 -10
  207. package/dist/compiler/usd-physics.cjs +0 -24
  208. package/dist/compiler/usd-physics.js +0 -7
  209. package/dist/compiler/visionos.cjs +0 -16
  210. package/dist/compiler/visionos.js +0 -10
  211. package/dist/compiler/vrchat.cjs +0 -20
  212. package/dist/compiler/vrchat.js +0 -10
  213. package/dist/compiler/vrr.cjs +0 -22
  214. package/dist/compiler/vrr.js +0 -10
  215. package/dist/compiler/wasm.cjs +0 -34
  216. package/dist/compiler/wasm.js +0 -10
  217. package/dist/compiler/webgpu.cjs +0 -16
  218. package/dist/compiler/webgpu.js +0 -10
  219. package/dist/debugger.cjs +0 -21
  220. package/dist/debugger.js +0 -8
  221. package/dist/entries/interop.cjs +0 -62
  222. package/dist/entries/interop.js +0 -5
  223. package/dist/entries/scripting.cjs +0 -67
  224. package/dist/entries/scripting.js +0 -10
  225. package/dist/index.cjs +0 -61703
  226. package/dist/index.js +0 -58652
  227. package/dist/math/vec3.cjs +0 -57
  228. package/dist/math/vec3.js +0 -4
  229. package/dist/parser.cjs +0 -26
  230. package/dist/parser.js +0 -9
  231. package/dist/playwright-7DTEQCBD.cjs +0 -98673
  232. package/dist/playwright-BIZXMLD2.js +0 -98660
  233. package/dist/post-quantum-JTTAAGO3.cjs +0 -6
  234. package/dist/post-quantum-RVPVDEPI.js +0 -4
  235. package/dist/runtime.cjs +0 -16
  236. package/dist/runtime.js +0 -7
  237. package/dist/storage/index.cjs +0 -37
  238. package/dist/storage/index.js +0 -4
  239. package/dist/traits/index.cjs +0 -14331
  240. package/dist/traits/index.js +0 -12126
  241. package/dist/type-checker.cjs +0 -18
  242. package/dist/type-checker.js +0 -5
  243. package/dist/wot/index.cjs +0 -29
  244. package/dist/wot/index.js +0 -4
@@ -1,657 +0,0 @@
1
- import { init_DomainBlockCompilerMixin, compileDomainBlocks, compileMaterialBlock, materialToWebGPU } from './chunk-KDB6BUMB.js';
2
- import { init_CompilerBase, init_ANSNamespace, CompilerBase, ANSCapabilityPath } from './chunk-QWKUKVRE.js';
3
- import { __export, __esm } from './chunk-32TWR3HE.js';
4
-
5
- // src/compiler/WebGPUCompiler.ts
6
- var WebGPUCompiler_exports = {};
7
- __export(WebGPUCompiler_exports, {
8
- WebGPUCompiler: () => WebGPUCompiler
9
- });
10
- var WebGPUCompiler;
11
- var init_WebGPUCompiler = __esm({
12
- "src/compiler/WebGPUCompiler.ts"() {
13
- init_CompilerBase();
14
- init_ANSNamespace();
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(`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);`);
162
- } else if (isModel) {
163
- this.emit(`// WARNING: geometry "model" without source URL \u2014 placeholder cube`);
164
- this.emitMeshObject(v, obj, "cube");
165
- } else if (isGaussianSplat) {
166
- this.emitGaussianSplatObject(v, obj);
167
- } else if (isPointCloud) {
168
- this.emitPointCloudObject(v, obj);
169
- } else if (isGpuParticle) {
170
- this.emitGpuParticleObject(v, obj);
171
- } else {
172
- this.emitMeshObject(v, obj, meshType);
173
- }
174
- if (traits.some((t) => t.name === "gpu_physics")) {
175
- this.emit(`const ${v}PhysicsBuf = createStorageBuffer(device, 1024 * 16); // gpu_physics`);
176
- }
177
- if (traits.some((t) => t.name === "compute" || t.name === "gpu_buffer")) {
178
- const ct = traits.find((t) => t.name === "compute" || t.name === "gpu_buffer");
179
- this.emit(
180
- `const ${v}ComputeBuf = createStorageBuffer(device, ${ct?.config?.buffer_size || 4096});`
181
- );
182
- }
183
- this.emit("");
184
- if (obj.children) {
185
- for (const child of obj.children) this.emitObject(child);
186
- }
187
- }
188
- emitMeshObject(v, obj, meshType) {
189
- this.emit(`const ${v}Vertices = ${this.geometryVertexDataFn(meshType)};`);
190
- this.emit(`const ${v}VBO = createBuffer(device, ${v}Vertices, GPUBufferUsage.VERTEX);`);
191
- this.emit(`const ${v}VertexCount = ${v}Vertices.length / 6;`);
192
- const pos = this.findObjProp(obj, "position");
193
- const scale = this.findObjProp(obj, "scale") || this.findObjProp(obj, "size");
194
- const [px, py, pz] = Array.isArray(pos) ? pos : [0, 0, 0];
195
- const [sx, sy, sz] = Array.isArray(scale) ? scale : typeof scale === "number" ? [scale, scale, scale] : [1, 1, 1];
196
- this.emit(
197
- `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);`
198
- );
199
- const material = this.findObjProp(obj, "material");
200
- const color = this.findObjProp(obj, "color");
201
- const [cr, cg, cb] = this.extractMaterialColor(material, color);
202
- const rough = this.extractMaterialProp(material, "roughness", 0.5);
203
- const metal = this.extractMaterialProp(material, "metalness", 0);
204
- this.emit(
205
- `const ${v}Mat = createBuffer(device, new Float32Array([${cr},${cg},${cb},1.0, ${rough},${metal},0,0]), GPUBufferUsage.UNIFORM);`
206
- );
207
- this.emit(`const ${v}Pipeline = device.createRenderPipeline({`);
208
- this.indent();
209
- this.emit('layout: "auto",');
210
- this.emit(
211
- 'vertex: { module: device.createShaderModule({ code: WGSL_VERTEX }), entryPoint: "vs_main",'
212
- );
213
- this.emit(
214
- ' buffers: [{ arrayStride: 24, attributes: [{ shaderLocation: 0, offset: 0, format: "float32x3" }, { shaderLocation: 1, offset: 12, format: "float32x3" }] }] },'
215
- );
216
- this.emit(
217
- 'fragment: { module: device.createShaderModule({ code: WGSL_FRAGMENT }), entryPoint: "fs_main", targets: [{ format }] },'
218
- );
219
- this.emit('primitive: { topology: "triangle-list", cullMode: "back" },');
220
- this.emit(
221
- `depthStencil: { format: "depth24plus", depthWriteEnabled: true, depthCompare: "less" }, multisample: { count: MSAA_COUNT },`
222
- );
223
- this.dedent();
224
- this.emit("});");
225
- this.emit(
226
- `const ${v}Bind = device.createBindGroup({ layout: ${v}Pipeline.getBindGroupLayout(0), entries: [`
227
- );
228
- this.emit(
229
- ` { binding: 0, resource: { buffer: ${v}Model } }, { binding: 1, resource: { buffer: ${v}Mat } }] });`
230
- );
231
- }
232
- emitGaussianSplatObject(v, obj) {
233
- const trait = obj.traits?.find((t) => t.name === "gaussian_splat");
234
- const src = trait?.config?.src || "scene.ply";
235
- const max = trait?.config?.max_splats || 5e5;
236
- const sorted = trait?.config?.sorted !== false;
237
- this.emit(`// Gaussian Splat \u2014 source: ${src} (${sorted ? "radix-sorted" : "unsorted"})`);
238
- if (sorted) {
239
- this.emit(
240
- `// === Wait-Free Radix Sort Pipeline (4x 8-bit Blelloch scan, no global atomics) ===`
241
- );
242
- this.emit(`import { GaussianSplatSorter } from '@holoscript/core/gpu/GaussianSplatSorter';`);
243
- this.emit(`const ${v}Sorter = new GaussianSplatSorter(device, {`);
244
- this.indent();
245
- this.emit(`maxSplats: ${max},`);
246
- this.emit(`canvasWidth: canvas.width,`);
247
- this.emit(`canvasHeight: canvas.height,`);
248
- this.dedent();
249
- this.emit(`});`);
250
- this.emit(`await ${v}Sorter.initialize();`);
251
- this.emit(`const ${v}SplatCount = { value: 0 };`);
252
- } else {
253
- this.emit(`const ${v}SplatBuf = createStorageBuffer(device, ${max} * 32);`);
254
- this.emit(`const ${v}SplatCount = { value: 0 };`);
255
- this.emit(`const ${v}SplatPipeline = device.createRenderPipeline({`);
256
- this.indent();
257
- this.emit('layout: "auto",');
258
- this.emit(
259
- 'vertex: { module: device.createShaderModule({ code: WGSL_SPLAT }), entryPoint: "vs_splat", buffers: [] },'
260
- );
261
- this.emit(
262
- 'fragment: { module: device.createShaderModule({ code: WGSL_SPLAT }), entryPoint: "fs_splat",'
263
- );
264
- this.emit(
265
- ' targets: [{ format, blend: { color: { srcFactor: "one", dstFactor: "one-minus-src-alpha", operation: "add" }, alpha: { srcFactor: "one", dstFactor: "one-minus-src-alpha", operation: "add" } } }] },'
266
- );
267
- this.emit('primitive: { topology: "triangle-strip" },');
268
- this.emit(
269
- 'depthStencil: { format: "depth24plus", depthWriteEnabled: false, depthCompare: "less" },'
270
- );
271
- this.dedent();
272
- this.emit("});");
273
- }
274
- }
275
- emitPointCloudObject(v, obj) {
276
- const trait = obj.traits?.find((t) => t.name === "point_cloud");
277
- const max = trait?.config?.max_points || 1e5;
278
- this.emit(`// Point Cloud (${max} max points)`);
279
- this.emit(`const ${v}PointBuf = createStorageBuffer(device, ${max} * 16);`);
280
- this.emit(`const ${v}PointCount = { value: 0 };`);
281
- this.emit(`const ${v}PointPipeline = device.createRenderPipeline({`);
282
- this.indent();
283
- this.emit('layout: "auto",');
284
- this.emit(
285
- 'vertex: { module: device.createShaderModule({ code: WGSL_POINT }), entryPoint: "vs_point",'
286
- );
287
- this.emit(
288
- ' buffers: [{ arrayStride: 16, attributes: [{ shaderLocation: 0, offset: 0, format: "float32x3" }, { shaderLocation: 1, offset: 12, format: "unorm8x4" }] }] },'
289
- );
290
- this.emit(
291
- 'fragment: { module: device.createShaderModule({ code: WGSL_POINT }), entryPoint: "fs_point", targets: [{ format }] },'
292
- );
293
- this.emit(
294
- `primitive: { topology: "point-list" }, depthStencil: { format: "depth24plus", depthWriteEnabled: true, depthCompare: "less" }, multisample: { count: MSAA_COUNT },`
295
- );
296
- this.dedent();
297
- this.emit("});");
298
- }
299
- emitGpuParticleObject(v, obj) {
300
- const trait = obj.traits?.find((t) => t.name === "gpu_particle");
301
- const count = trait?.config?.count || 1e4;
302
- this.emit(`// GPU Particles (${count})`);
303
- this.emit(`const ${v}ParticleCount = ${count};`);
304
- this.emit(`const ${v}ParticleBufA = createStorageBuffer(device, ${v}ParticleCount * 32);`);
305
- this.emit(`const ${v}ParticleBufB = createStorageBuffer(device, ${v}ParticleCount * 32);`);
306
- this.emit(`const ${v}ParticlePipeline = device.createRenderPipeline({`);
307
- this.indent();
308
- this.emit('layout: "auto",');
309
- this.emit(
310
- 'vertex: { module: device.createShaderModule({ code: WGSL_PARTICLE_RENDER }), entryPoint: "vs_particle",'
311
- );
312
- this.emit(
313
- ' buffers: [{ arrayStride: 32, attributes: [{ shaderLocation: 0, offset: 0, format: "float32x3" }, { shaderLocation: 1, offset: 12, format: "float32x3" }, { shaderLocation: 2, offset: 24, format: "float32" }] }] },'
314
- );
315
- this.emit(
316
- 'fragment: { module: device.createShaderModule({ code: WGSL_PARTICLE_RENDER }), entryPoint: "fs_particle",'
317
- );
318
- this.emit(
319
- ' targets: [{ format, blend: { color: { srcFactor: "src-alpha", dstFactor: "one", operation: "add" }, alpha: { srcFactor: "zero", dstFactor: "one", operation: "add" } } }] },'
320
- );
321
- this.emit(
322
- 'primitive: { topology: "point-list" }, depthStencil: { format: "depth24plus", depthWriteEnabled: false, depthCompare: "less" },'
323
- );
324
- this.dedent();
325
- this.emit("});");
326
- }
327
- // ─── Spatial Group ────────────────────────────────────────────────────────
328
- emitGroup(group) {
329
- const v = this.sanitizeName(group.name);
330
- this.emit(`// Spatial Group: ${this.escapeStringValue(group.name, "TypeScript")}`);
331
- const pos = group.properties.find((p) => p.key === "position")?.value;
332
- const [px, py, pz] = Array.isArray(pos) ? pos : [0, 0, 0];
333
- this.emit(
334
- `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);`
335
- );
336
- for (const obj of group.objects) this.emitObject(obj);
337
- if (group.groups) {
338
- for (const sub of group.groups) this.emitGroup(sub);
339
- }
340
- this.emit("");
341
- }
342
- // ─── Light ────────────────────────────────────────────────────────────────
343
- emitLight(light) {
344
- const v = this.sanitizeName(light.name);
345
- let color = [1, 1, 1], intensity = 1, pos = [0, 10, 0], dir = [0, -1, 0];
346
- for (const prop of light.properties) {
347
- if (prop.key === "color") color = this.parseColor(prop.value);
348
- else if (prop.key === "intensity") intensity = prop.value;
349
- else if (prop.key === "position" && Array.isArray(prop.value)) pos = prop.value;
350
- else if (prop.key === "direction" && Array.isArray(prop.value)) dir = prop.value;
351
- }
352
- const ti = { directional: 0, point: 1, spot: 2, hemisphere: 3, ambient: 4, area: 5 }[light.lightType] ?? 0;
353
- this.emit(
354
- `// Light: ${this.escapeStringValue(light.name, "TypeScript")} (${light.lightType})`
355
- );
356
- this.emit(
357
- `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);`
358
- );
359
- this.emit("");
360
- }
361
- // ─── Camera ───────────────────────────────────────────────────────────────
362
- emitCamera(cam) {
363
- this.emit("// === Camera ===");
364
- let fov = 60, near = 0.1, far = 1e3, pos = [0, 1, 5], lookAt = [0, 0, 0];
365
- for (const prop of cam.properties) {
366
- if (prop.key === "fov" || prop.key === "field_of_view") fov = prop.value;
367
- else if (prop.key === "near") near = prop.value;
368
- else if (prop.key === "far") far = prop.value;
369
- else if (prop.key === "position" && Array.isArray(prop.value)) pos = prop.value;
370
- else if ((prop.key === "look_at" || prop.key === "lookAt") && Array.isArray(prop.value))
371
- lookAt = prop.value;
372
- }
373
- this.emit(`const cameraFov = ${fov} * Math.PI / 180;`);
374
- this.emit(`const cameraNear = ${near}, cameraFar = ${far};`);
375
- this.emit(`const cameraPos = new Float32Array([${pos.join(",")}]);`);
376
- this.emit(`const cameraTarget = new Float32Array([${lookAt.join(",")}]);`);
377
- this.emit("const aspect = canvas.width / canvas.height;");
378
- this.emit("function buildViewProjection(): Float32Array {");
379
- this.indent();
380
- this.emit("const f = 1.0 / Math.tan(cameraFov / 2), ri = 1.0 / (cameraNear - cameraFar);");
381
- this.emit(
382
- "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]);"
383
- );
384
- this.dedent();
385
- this.emit("}");
386
- this.emit(
387
- "const vpUniform = createBuffer(device, buildViewProjection(), GPUBufferUsage.UNIFORM);"
388
- );
389
- this.emit("");
390
- }
391
- // ─── Compute Pipelines ────────────────────────────────────────────────────
392
- emitComputeShaders(composition) {
393
- const gpuObjs = (composition.objects || []).filter(
394
- (o) => o.traits?.some(
395
- (t) => t.name === "gpu_particle" || t.name === "gpu_physics" || t.name === "compute"
396
- )
397
- );
398
- if (gpuObjs.length === 0) return;
399
- this.emit("// === Compute Pipelines ===");
400
- for (const obj of gpuObjs) {
401
- const v = this.sanitizeName(obj.name);
402
- const traits = obj.traits || [];
403
- if (traits.some((t) => t.name === "gpu_particle")) {
404
- const count = traits.find((t) => t.name === "gpu_particle")?.config?.count || 1e4;
405
- this.emit(
406
- `const ${v}ParticleCompute = device.createComputePipeline({ layout: "auto", compute: { module: device.createShaderModule({ code: WGSL_PARTICLE_COMPUTE }), entryPoint: "cs_particle_update" } });`
407
- );
408
- this.emit(`const ${v}ComputeDispatches = ${Math.ceil(count / 64)};`);
409
- }
410
- if (traits.some((t) => t.name === "gpu_physics")) {
411
- this.emit(
412
- `const ${v}PhysicsCompute = device.createComputePipeline({ layout: "auto", compute: { module: device.createShaderModule({ code: WGSL_PHYSICS_COMPUTE }), entryPoint: "cs_physics_step" } });`
413
- );
414
- }
415
- if (traits.some((t) => t.name === "compute")) {
416
- const ct = traits.find((t) => t.name === "compute");
417
- const entry = ct?.config?.shader || "custom_compute";
418
- const wg = ct?.config?.workgroups || [64, 1, 1];
419
- this.emit(
420
- `const ${v}CustomCompute = device.createComputePipeline({ layout: "auto", compute: { module: device.createShaderModule({ code: WGSL_CUSTOM_${v.toUpperCase()} }), entryPoint: "${entry}" } });`
421
- );
422
- this.emit(`const ${v}Workgroups: [number, number, number] = [${wg}];`);
423
- }
424
- }
425
- this.emit("");
426
- }
427
- // ─── WGSL Shader Sources ──────────────────────────────────────────────────
428
- emitShaderSources() {
429
- this.emit("// === WGSL Shader Sources ===");
430
- this.emit("const WGSL_VERTEX = /* wgsl */`");
431
- this.emit("struct Uniforms { model: mat4x4<f32> };");
432
- this.emit("@group(0) @binding(0) var<uniform> u: Uniforms;");
433
- this.emit("struct VIn { @location(0) pos: vec3<f32>, @location(1) norm: vec3<f32> };");
434
- this.emit(
435
- "struct VOut { @builtin(position) clip: vec4<f32>, @location(0) wNorm: vec3<f32>, @location(1) wPos: vec3<f32> };"
436
- );
437
- this.emit("@vertex fn vs_main(i: VIn) -> VOut {");
438
- this.emit(" var o: VOut; let w = u.model * vec4<f32>(i.pos, 1.0);");
439
- this.emit(
440
- " o.clip = w; o.wNorm = (u.model * vec4<f32>(i.norm, 0.0)).xyz; o.wPos = w.xyz; return o; }`;"
441
- );
442
- this.emit("");
443
- this.emit("const WGSL_FRAGMENT = /* wgsl */`");
444
- this.emit("struct Mat { color: vec4<f32>, rm: vec4<f32> };");
445
- this.emit("@group(0) @binding(1) var<uniform> mat: Mat;");
446
- this.emit("struct FIn { @location(0) wNorm: vec3<f32>, @location(1) wPos: vec3<f32> };");
447
- this.emit("@fragment fn fs_main(i: FIn) -> @location(0) vec4<f32> {");
448
- this.emit(" let N = normalize(i.wNorm); let L = normalize(vec3<f32>(1.0, 2.0, 1.5));");
449
- this.emit(" let d = max(dot(N, L), 0.0) * (1.0 - mat.rm.x * 0.5);");
450
- this.emit(" return vec4<f32>(mat.color.rgb * (0.15 + d), mat.color.a); }`;");
451
- this.emit("");
452
- this.emit("const WGSL_SPLAT = /* wgsl */`");
453
- this.emit(
454
- "struct Splat { center: vec3<f32>, opacity: f32, cov: array<f32,6>, sh: vec3<f32> };"
455
- );
456
- this.emit("@group(0) @binding(0) var<storage, read> splats: array<Splat>;");
457
- this.emit(
458
- "struct SO { @builtin(position) p: vec4<f32>, @location(0) c: vec4<f32>, @location(1) uv: vec2<f32> };"
459
- );
460
- this.emit(
461
- "@vertex fn vs_splat(@builtin(vertex_index) vi: u32, @builtin(instance_index) ii: u32) -> SO {"
462
- );
463
- this.emit(" var q = array<vec2<f32>,4>(vec2(-1,-1),vec2(1,-1),vec2(-1,1),vec2(1,1));");
464
- this.emit(
465
- " var o: SO; let s = splats[ii]; o.p = vec4<f32>(s.center.xy + q[vi]*0.01, s.center.z, 1.0);"
466
- );
467
- this.emit(" o.c = vec4<f32>(s.sh, s.opacity); o.uv = q[vi]; return o; }");
468
- this.emit("@fragment fn fs_splat(i: SO) -> @location(0) vec4<f32> {");
469
- this.emit(" let a = i.c.a * exp(-dot(i.uv, i.uv) * 4.0); if (a < 0.01) { discard; }");
470
- this.emit(" return vec4<f32>(i.c.rgb * a, a); }`;");
471
- this.emit("");
472
- this.emit("const WGSL_POINT = /* wgsl */`");
473
- this.emit("struct PO { @builtin(position) p: vec4<f32>, @location(0) c: vec4<f32> };");
474
- this.emit(
475
- "@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; }"
476
- );
477
- this.emit("@fragment fn fs_point(i: PO) -> @location(0) vec4<f32> { return i.c; }`;");
478
- this.emit("");
479
- this.emit("const WGSL_PARTICLE_RENDER = /* wgsl */`");
480
- this.emit("struct PVO { @builtin(position) p: vec4<f32>, @location(0) life: f32 };");
481
- this.emit(
482
- "@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; }"
483
- );
484
- this.emit("@fragment fn fs_particle(i: PVO) -> @location(0) vec4<f32> {");
485
- this.emit(
486
- " 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); }`;"
487
- );
488
- this.emit("");
489
- this.emit("const WGSL_PARTICLE_COMPUTE = /* wgsl */`");
490
- this.emit("struct P { pos: vec3<f32>, _p0: f32, vel: vec3<f32>, life: f32 };");
491
- this.emit("@group(0) @binding(0) var<storage, read> pin: array<P>;");
492
- this.emit("@group(0) @binding(1) var<storage, read_write> pout: array<P>;");
493
- this.emit("@group(0) @binding(2) var<uniform> dt: f32;");
494
- this.emit(
495
- "@compute @workgroup_size(64) fn cs_particle_update(@builtin(global_invocation_id) gid: vec3<u32>) {"
496
- );
497
- this.emit(" let i = gid.x; if (i >= arrayLength(&pin)) { return; } var p = pin[i];");
498
- this.emit(" p.vel.y -= 9.81 * dt; p.pos += p.vel * dt; p.life -= dt;");
499
- this.emit(
500
- " if (p.life <= 0.0) { p.pos = vec3(0.0); p.vel = vec3(0.0, 5.0, 0.0); p.life = 2.0; }"
501
- );
502
- this.emit(" pout[i] = p; }`;");
503
- this.emit("");
504
- this.emit("const WGSL_PHYSICS_COMPUTE = /* wgsl */`");
505
- this.emit("struct Body { pos: vec3<f32>, mass: f32, vel: vec3<f32>, _p: f32 };");
506
- this.emit("@group(0) @binding(0) var<storage, read_write> bodies: array<Body>;");
507
- this.emit("@group(0) @binding(1) var<uniform> dt: f32;");
508
- this.emit(
509
- "@compute @workgroup_size(64) fn cs_physics_step(@builtin(global_invocation_id) gid: vec3<u32>) {"
510
- );
511
- this.emit(" let i = gid.x; if (i >= arrayLength(&bodies)) { return; } var b = bodies[i];");
512
- this.emit(" b.vel.y -= 9.81 * dt; b.pos += b.vel * dt;");
513
- this.emit(
514
- " if (b.pos.y < 0.0) { b.pos.y = 0.0; b.vel.y = -b.vel.y * 0.6; } bodies[i] = b; }`;"
515
- );
516
- this.emit("");
517
- }
518
- // ─── Render Loop ──────────────────────────────────────────────────────────
519
- emitRenderLoop(composition) {
520
- this.emit("// === Render Loop ===");
521
- this.emit("let frameCount = 0;");
522
- this.emit("const t0 = performance.now();");
523
- this.emit("function frame() {");
524
- this.indent();
525
- this.emit("frameCount++;");
526
- this.emit("const time = (performance.now() - t0) / 1000.0;");
527
- this.emit("const enc = device.createCommandEncoder();");
528
- const gpuObjs = (composition.objects || []).filter(
529
- (o) => o.traits?.some(
530
- (t) => t.name === "gpu_particle" || t.name === "gpu_physics" || t.name === "compute"
531
- )
532
- );
533
- if (gpuObjs.length > 0 && this.options.enableCompute) {
534
- this.emit("const cp = enc.beginComputePass();");
535
- for (const obj of gpuObjs) {
536
- const v = this.sanitizeName(obj.name);
537
- if (obj.traits?.some((t) => t.name === "gpu_particle")) {
538
- this.emit(
539
- `cp.setPipeline(${v}ParticleCompute); cp.dispatchWorkgroups(${v}ComputeDispatches);`
540
- );
541
- }
542
- if (obj.traits?.some((t) => t.name === "gpu_physics")) {
543
- this.emit(`cp.setPipeline(${v}PhysicsCompute); cp.dispatchWorkgroups(16);`);
544
- }
545
- if (obj.traits?.some((t) => t.name === "compute")) {
546
- this.emit(`cp.setPipeline(${v}CustomCompute); cp.dispatchWorkgroups(...${v}Workgroups);`);
547
- }
548
- }
549
- this.emit("cp.end();");
550
- }
551
- this.emit("const rp = enc.beginRenderPass({");
552
- this.indent();
553
- this.emit(
554
- 'colorAttachments: [{ view: msaaTexture.createView(), resolveTarget: context.getCurrentTexture().createView(), clearValue: clearColor, loadOp: "clear", storeOp: "store" }],'
555
- );
556
- this.emit(
557
- 'depthStencilAttachment: { view: depthTexture.createView(), depthClearValue: 1.0, depthLoadOp: "clear", depthStoreOp: "store" },'
558
- );
559
- this.dedent();
560
- this.emit("});");
561
- if (composition.objects) {
562
- for (const obj of composition.objects) this.emitDrawCall(obj);
563
- }
564
- if (composition.spatialGroups) {
565
- for (const group of composition.spatialGroups) {
566
- for (const obj of group.objects) this.emitDrawCall(obj);
567
- }
568
- }
569
- this.emit("rp.end();");
570
- this.emit("device.queue.submit([enc.finish()]);");
571
- this.emit("requestAnimationFrame(frame);");
572
- this.dedent();
573
- this.emit("}");
574
- this.emit("requestAnimationFrame(frame);");
575
- }
576
- emitDrawCall(obj) {
577
- const v = this.sanitizeName(obj.name);
578
- const traits = obj.traits || [];
579
- if (traits.some((t) => t.name === "gaussian_splat")) {
580
- this.emit(`rp.setPipeline(${v}SplatPipeline); rp.draw(4, ${v}SplatCount.value);`);
581
- } else if (traits.some((t) => t.name === "point_cloud")) {
582
- this.emit(`rp.setPipeline(${v}PointPipeline); rp.draw(${v}PointCount.value);`);
583
- } else if (traits.some((t) => t.name === "gpu_particle")) {
584
- this.emit(
585
- `rp.setPipeline(${v}ParticlePipeline); rp.setVertexBuffer(0, ${v}ParticleBufA); rp.draw(${v}ParticleCount);`
586
- );
587
- } else {
588
- this.emit(
589
- `rp.setPipeline(${v}Pipeline); rp.setBindGroup(0, ${v}Bind); rp.setVertexBuffer(0, ${v}VBO); rp.draw(${v}VertexCount);`
590
- );
591
- }
592
- if (obj.children) {
593
- for (const child of obj.children) this.emitDrawCall(child);
594
- }
595
- }
596
- // ─── Helpers ──────────────────────────────────────────────────────────────
597
- emit(line) {
598
- this.lines.push(this.options.indent.repeat(this.indentLevel) + line);
599
- }
600
- indent() {
601
- this.indentLevel++;
602
- }
603
- dedent() {
604
- this.indentLevel = Math.max(0, this.indentLevel - 1);
605
- }
606
- sanitizeName(name) {
607
- return name.replace(/[^a-zA-Z0-9_]/g, "_");
608
- }
609
- findObjProp(obj, key) {
610
- return obj.properties?.find((p) => p.key === key)?.value;
611
- }
612
- parseColor(value) {
613
- if (typeof value === "string" && value.startsWith("#")) {
614
- const h = value.slice(1);
615
- return [
616
- parseFloat((parseInt(h.substring(0, 2), 16) / 255).toFixed(4)),
617
- parseFloat((parseInt(h.substring(2, 4), 16) / 255).toFixed(4)),
618
- parseFloat((parseInt(h.substring(4, 6), 16) / 255).toFixed(4))
619
- ];
620
- }
621
- if (Array.isArray(value) && value.length >= 3) return [value[0], value[1], value[2]];
622
- return [1, 1, 1];
623
- }
624
- extractMaterialColor(material, color) {
625
- if (color) return this.parseColor(color);
626
- if (material && typeof material === "object" && !Array.isArray(material)) {
627
- const m = material;
628
- if (m.color) return this.parseColor(m.color);
629
- }
630
- return [0.8, 0.8, 0.8];
631
- }
632
- extractMaterialProp(material, key, fallback) {
633
- if (material && typeof material === "object" && !Array.isArray(material)) {
634
- const m = material;
635
- if (m[key] !== void 0) return m[key];
636
- }
637
- return fallback;
638
- }
639
- geometryVertexDataFn(meshType) {
640
- const map = {
641
- sphere: "generateSphereVertices(0.5, 16, 16)",
642
- orb: "generateSphereVertices(0.5, 16, 16)",
643
- plane: "generatePlaneVertices(1.0, 1.0)",
644
- cylinder: "generateCylinderVertices(0.5, 1.0, 16)",
645
- cone: "generateConeVertices(0.5, 1.0, 16)",
646
- pyramid: "generateConeVertices(0.5, 1.0, 16)",
647
- torus: "generateTorusVertices(0.5, 0.15, 16, 32)"
648
- };
649
- return map[meshType] || "generateCubeVertices(1.0)";
650
- }
651
- };
652
- }
653
- });
654
-
655
- export { WebGPUCompiler, WebGPUCompiler_exports, init_WebGPUCompiler };
656
- //# sourceMappingURL=chunk-KUJRR4FJ.js.map
657
- //# sourceMappingURL=chunk-KUJRR4FJ.js.map