@holoscript/core 7.0.0 → 8.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 (345) hide show
  1. package/README.md +2 -2
  2. package/bin/holoscript.cjs +3 -0
  3. package/dist/GLTFPipeline-276GE64O.js +16 -0
  4. package/dist/GLTFPipeline-M7WSSJED.cjs +37 -0
  5. package/dist/HoloScriptPlusParser-7FBIFUFC.js +693 -0
  6. package/dist/HoloScriptPlusParser-A2W7OCN2.cjs +698 -0
  7. package/dist/HoloScriptPlusParser-F2Z56FJR.js +10 -0
  8. package/dist/HoloScriptPlusParser-WKHRIH6T.cjs +27 -0
  9. package/dist/HoloScriptRuntime-3URVTKPJ.js +10 -0
  10. package/dist/HoloScriptRuntime-SXEAEU2N.cjs +19 -0
  11. package/dist/USDZExporter-3FWJ25JI.cjs +1037 -0
  12. package/dist/USDZExporter-D2HQLQYK.js +1035 -0
  13. package/dist/agents/index.cjs +19 -0
  14. package/dist/agents/index.d.ts +100 -0
  15. package/dist/agents/index.js +17 -0
  16. package/dist/chunk-23J755AR.js +1046 -0
  17. package/dist/chunk-253GBQZY.cjs +627 -0
  18. package/dist/chunk-25IQCHTO.cjs +781 -0
  19. package/dist/chunk-2BSMSUCE.js +1941 -0
  20. package/dist/chunk-2M2DPHKB.js +762 -0
  21. package/dist/chunk-2YSNA2F2.cjs +1274 -0
  22. package/dist/chunk-3AO425MZ.cjs +886 -0
  23. package/dist/chunk-3FOKASKO.cjs +348 -0
  24. package/dist/chunk-3HYYMEXI.cjs +56578 -0
  25. package/dist/chunk-3NFFOWGG.js +4287 -0
  26. package/dist/chunk-3WZEJHUQ.cjs +116 -0
  27. package/dist/chunk-4C57PR42.js +468 -0
  28. package/dist/chunk-4N4SXXWF.js +769 -0
  29. package/dist/chunk-4PDEPEQW.cjs +41 -0
  30. package/dist/chunk-4R6SBXDB.js +45 -0
  31. package/dist/chunk-4V2E7U7Q.cjs +2015 -0
  32. package/dist/chunk-5FSKKMR7.cjs +2092 -0
  33. package/dist/chunk-5GLCTO44.js +161 -0
  34. package/dist/chunk-5JEU52DW.js +382 -0
  35. package/dist/chunk-5S7RKFGR.cjs +446 -0
  36. package/dist/chunk-5WUNN6ZN.cjs +428 -0
  37. package/dist/chunk-62FBK3B7.js +70 -0
  38. package/dist/chunk-6CTRH7HT.cjs +1985 -0
  39. package/dist/chunk-6DPSFNJB.cjs +847 -0
  40. package/dist/chunk-6EX3I5P4.cjs +130 -0
  41. package/dist/chunk-73FELZVJ.cjs +611 -0
  42. package/dist/chunk-7CUEMLDZ.cjs +6445 -0
  43. package/dist/chunk-7HIASF7S.cjs +814 -0
  44. package/dist/chunk-A6KINLZJ.js +236 -0
  45. package/dist/chunk-AIA52I7T.cjs +543 -0
  46. package/dist/chunk-ANXZFVY2.js +113 -0
  47. package/dist/chunk-AYBXB26F.js +2176 -0
  48. package/dist/chunk-B4TFTDG4.js +449 -0
  49. package/dist/chunk-BE4UJCQT.js +623 -0
  50. package/dist/chunk-BRQJKJGT.cjs +20 -0
  51. package/dist/chunk-C2A5DUMF.cjs +689 -0
  52. package/dist/chunk-C37BHB7N.cjs +636 -0
  53. package/dist/chunk-CBJY23VL.js +126 -0
  54. package/dist/chunk-CIWWXYHZ.cjs +50 -0
  55. package/dist/chunk-CXFDRBQU.cjs +672 -0
  56. package/dist/chunk-D54CNIAJ.cjs +413 -0
  57. package/dist/chunk-DAJXW4KX.js +725 -0
  58. package/dist/chunk-DTGBOSEM.cjs +319 -0
  59. package/dist/chunk-E7JP3BS3.cjs +61 -0
  60. package/dist/chunk-EKBKLK7P.js +1169 -0
  61. package/dist/chunk-EKYL4PE3.cjs +404 -0
  62. package/dist/chunk-EUDQTK7N.cjs +4310 -0
  63. package/dist/chunk-EXKSFGSX.cjs +274 -0
  64. package/dist/chunk-EXUP2BUM.cjs +1173 -0
  65. package/dist/chunk-F43YAA34.js +623 -0
  66. package/dist/chunk-FDSGHPAK.js +130 -0
  67. package/dist/chunk-FEWUHQNM.cjs +144 -0
  68. package/dist/chunk-FGGJQRLZ.js +270 -0
  69. package/dist/chunk-FHP6LXJS.js +415 -0
  70. package/dist/chunk-FJPADH77.cjs +666 -0
  71. package/dist/chunk-FYSPZT4V.cjs +169 -0
  72. package/dist/chunk-GIOYPNTH.js +5575 -0
  73. package/dist/chunk-GJNCFRJU.cjs +125 -0
  74. package/dist/chunk-GMP623FG.cjs +1508 -0
  75. package/dist/chunk-GQHQOPXZ.cjs +5580 -0
  76. package/dist/chunk-GQT4TYKY.cjs +4381 -0
  77. package/dist/chunk-GTU2Z2WW.cjs +262 -0
  78. package/dist/chunk-GYZE55MO.js +2007 -0
  79. package/dist/chunk-GZG4KA4E.js +529 -0
  80. package/dist/chunk-H652NHX5.js +600 -0
  81. package/dist/chunk-HCCQLAA4.cjs +74 -0
  82. package/dist/chunk-HINXWAOD.cjs +1049 -0
  83. package/dist/chunk-HYNTS5CP.js +422 -0
  84. package/dist/chunk-HZSPDCXV.cjs +457 -0
  85. package/dist/chunk-HZTDET3N.js +1399 -0
  86. package/dist/chunk-I6XZ5DZF.cjs +488 -0
  87. package/dist/chunk-ILRBGFVD.cjs +72 -0
  88. package/dist/chunk-IPWSXCCN.js +1183 -0
  89. package/dist/chunk-IUTY5WQ2.cjs +424 -0
  90. package/dist/chunk-IVSZDECV.js +882 -0
  91. package/dist/chunk-IVY74O6C.js +247 -0
  92. package/dist/chunk-IZM5VQZD.js +714 -0
  93. package/dist/chunk-J32ZJZJH.js +554 -0
  94. package/dist/chunk-J6M4FPK5.js +421 -0
  95. package/dist/chunk-JC5YBPSF.cjs +984 -0
  96. package/dist/chunk-JCLBKPMX.js +3813 -0
  97. package/dist/chunk-JD7CIZ33.js +1949 -0
  98. package/dist/chunk-JIYN45TV.cjs +2525 -0
  99. package/dist/chunk-JJBE3TIH.cjs +1189 -0
  100. package/dist/chunk-JX7YL6ZE.js +2252 -0
  101. package/dist/chunk-K4VVR7CN.cjs +2433 -0
  102. package/dist/chunk-KEFNV2WM.cjs +2257 -0
  103. package/dist/chunk-KH4CNH66.cjs +424 -0
  104. package/dist/chunk-KJLB4OPV.js +5731 -0
  105. package/dist/chunk-KKFZ3B6J.cjs +557 -0
  106. package/dist/chunk-KKP7JKN4.cjs +6002 -0
  107. package/dist/chunk-KPJL34Y7.cjs +186 -0
  108. package/dist/chunk-KQCN6AKJ.cjs +3042 -0
  109. package/dist/chunk-KVRSTFNH.cjs +72 -0
  110. package/dist/chunk-LICPB5HZ.cjs +1409 -0
  111. package/dist/chunk-LM2VU56C.cjs +37 -0
  112. package/dist/chunk-M56JSP4A.js +400 -0
  113. package/dist/chunk-MBOOR7X4.js +18 -0
  114. package/dist/chunk-MGE5Z4GS.js +608 -0
  115. package/dist/chunk-MXFUTKCO.js +56 -0
  116. package/dist/chunk-MYY4PMWX.cjs +264 -0
  117. package/dist/chunk-N75IH2HY.js +258 -0
  118. package/dist/chunk-NBMHU6SW.js +669 -0
  119. package/dist/chunk-NG77ATEW.cjs +778 -0
  120. package/dist/chunk-NGKREZ36.js +6384 -0
  121. package/dist/chunk-NHWSN2SD.cjs +718 -0
  122. package/dist/chunk-NV4VMVXU.js +421 -0
  123. package/dist/chunk-NW5G5FBQ.js +215 -0
  124. package/dist/chunk-NXZFOPVD.cjs +5737 -0
  125. package/dist/chunk-OBIYPYYS.cjs +1993 -0
  126. package/dist/chunk-OIQYIIO3.cjs +473 -0
  127. package/dist/chunk-OL46QLBJ.js +61 -0
  128. package/dist/chunk-OMXII44L.js +5386 -0
  129. package/dist/chunk-OR4Q2BGL.cjs +759 -0
  130. package/dist/chunk-OSYNRVOV.cjs +243 -0
  131. package/dist/chunk-PGANYCAG.cjs +220 -0
  132. package/dist/chunk-PHENW4MQ.js +65 -0
  133. package/dist/chunk-PHVRG4I2.js +844 -0
  134. package/dist/chunk-Q56TT7IL.js +483 -0
  135. package/dist/chunk-QPOQ7VPI.js +1491 -0
  136. package/dist/chunk-QPSKHBJP.js +5963 -0
  137. package/dist/chunk-QXH7QDSZ.js +1989 -0
  138. package/dist/chunk-R75BSDH7.cjs +50 -0
  139. package/dist/chunk-RARB3MBR.js +207 -0
  140. package/dist/chunk-RVBHAXFG.js +56160 -0
  141. package/dist/chunk-S3MDHNKB.cjs +490 -0
  142. package/dist/chunk-S4W6Z2MN.js +2426 -0
  143. package/dist/chunk-S6YWHCKV.cjs +410 -0
  144. package/dist/chunk-SIEXCILW.js +229 -0
  145. package/dist/chunk-SJBGLS25.cjs +2196 -0
  146. package/dist/chunk-SLU6UPJI.cjs +410 -0
  147. package/dist/chunk-SMIWS6DE.cjs +212 -0
  148. package/dist/chunk-T2QCTZMO.js +811 -0
  149. package/dist/chunk-T5J7ZKP3.cjs +4885 -0
  150. package/dist/chunk-TDCNJHWO.js +341 -0
  151. package/dist/chunk-TG7O4WBC.js +406 -0
  152. package/dist/chunk-THCK6ECW.js +2085 -0
  153. package/dist/chunk-TJHVSBP2.js +439 -0
  154. package/dist/chunk-TVHSPJ4N.cjs +606 -0
  155. package/dist/chunk-U44IKGG7.cjs +5390 -0
  156. package/dist/chunk-UJXISJBN.js +487 -0
  157. package/dist/chunk-UM6C3CGK.js +4375 -0
  158. package/dist/chunk-UMABK6SI.js +686 -0
  159. package/dist/chunk-UOIGFQXC.cjs +9750 -0
  160. package/dist/chunk-URG2SJLK.js +2521 -0
  161. package/dist/chunk-V6MKC2FZ.js +979 -0
  162. package/dist/chunk-VECQYRXL.js +474 -0
  163. package/dist/chunk-VJ3L7CHT.cjs +169 -0
  164. package/dist/chunk-VMLKSV26.js +1216 -0
  165. package/dist/chunk-VVKVQZI6.js +55 -0
  166. package/dist/chunk-W6RW64BB.cjs +1219 -0
  167. package/dist/chunk-W7VDOASB.cjs +639 -0
  168. package/dist/chunk-WDT3JTGM.cjs +483 -0
  169. package/dist/chunk-WJIHFLMJ.js +404 -0
  170. package/dist/chunk-WKX5AMOY.js +309 -0
  171. package/dist/chunk-WNNE3PO3.js +34 -0
  172. package/dist/chunk-WRKUDAZJ.js +3038 -0
  173. package/dist/chunk-WRLUBRKS.cjs +1943 -0
  174. package/dist/chunk-WRNEH5MO.js +3169 -0
  175. package/dist/chunk-WRWEX5ZF.js +658 -0
  176. package/dist/chunk-X3GJPRVK.cjs +3246 -0
  177. package/dist/chunk-XHIV6326.cjs +793 -0
  178. package/dist/chunk-XIVIE43A.cjs +729 -0
  179. package/dist/chunk-XJAN7CZG.cjs +432 -0
  180. package/dist/chunk-XKTPFXGA.js +164 -0
  181. package/dist/chunk-XL6INWKT.js +121 -0
  182. package/dist/chunk-XSFNHP2E.js +632 -0
  183. package/dist/chunk-XT6JY5W5.js +9684 -0
  184. package/dist/chunk-XUILI4KB.cjs +430 -0
  185. package/dist/chunk-XUUVDHIF.cjs +3962 -0
  186. package/dist/chunk-YF2I3MV3.js +46 -0
  187. package/dist/chunk-YIMN575O.js +4847 -0
  188. package/dist/chunk-YIVFJNYV.js +176 -0
  189. package/dist/chunk-YKGPCZEE.cjs +237 -0
  190. package/dist/chunk-YN6V7R3L.cjs +327 -0
  191. package/dist/chunk-YQELFNJV.js +39 -0
  192. package/dist/chunk-YYXH45E2.js +426 -0
  193. package/dist/chunk-ZBQXLH2L.js +756 -0
  194. package/dist/chunk-ZDSYWBIE.cjs +69 -0
  195. package/dist/chunk-ZU7NIRT6.js +325 -0
  196. package/dist/chunk-ZZ7RO2UQ.js +1243 -0
  197. package/dist/chunk-ZZEI7MV4.js +778 -0
  198. package/dist/cli/holoscript-runner.cjs +2255 -0
  199. package/dist/cli/holoscript-runner.js +2230 -0
  200. package/dist/codebase/index.cjs +336 -0
  201. package/dist/codebase/index.js +331 -0
  202. package/dist/compiler/agent-inference.cjs +31 -0
  203. package/dist/compiler/agent-inference.js +8 -0
  204. package/dist/compiler/android-xr.cjs +24 -0
  205. package/dist/compiler/android-xr.js +14 -0
  206. package/dist/compiler/android.cjs +24 -0
  207. package/dist/compiler/android.js +14 -0
  208. package/dist/compiler/ar.cjs +23 -0
  209. package/dist/compiler/ar.js +11 -0
  210. package/dist/compiler/babylon.cjs +21 -0
  211. package/dist/compiler/babylon.js +15 -0
  212. package/dist/compiler/business-quest.cjs +43 -0
  213. package/dist/compiler/business-quest.js +4 -0
  214. package/dist/compiler/coco.cjs +27 -0
  215. package/dist/compiler/coco.js +4 -0
  216. package/dist/compiler/context.cjs +25 -0
  217. package/dist/compiler/context.d.ts +28 -0
  218. package/dist/compiler/context.js +8 -0
  219. package/dist/compiler/domain-block-utils.cjs +605 -0
  220. package/dist/compiler/domain-block-utils.js +11 -0
  221. package/dist/compiler/dtdl.cjs +27 -0
  222. package/dist/compiler/dtdl.js +11 -0
  223. package/dist/compiler/gltf-pipeline.cjs +39 -0
  224. package/dist/compiler/gltf-pipeline.js +4 -0
  225. package/dist/compiler/godot.cjs +18 -0
  226. package/dist/compiler/godot.js +12 -0
  227. package/dist/compiler/incremental.cjs +34 -0
  228. package/dist/compiler/incremental.js +9 -0
  229. package/dist/compiler/index.cjs +5860 -0
  230. package/dist/compiler/index.d.ts +322 -21
  231. package/dist/compiler/index.js +5525 -0
  232. package/dist/compiler/ios.cjs +23 -0
  233. package/dist/compiler/ios.js +13 -0
  234. package/dist/compiler/llm-provider-capabilities.cjs +25 -0
  235. package/dist/compiler/llm-provider-capabilities.d.ts +43 -0
  236. package/dist/compiler/llm-provider-capabilities.js +8 -0
  237. package/dist/compiler/multi-layer.cjs +24 -0
  238. package/dist/compiler/multi-layer.js +15 -0
  239. package/dist/compiler/nodetoy.cjs +23 -0
  240. package/dist/compiler/nodetoy.js +4 -0
  241. package/dist/compiler/openxr.cjs +19 -0
  242. package/dist/compiler/openxr.js +13 -0
  243. package/dist/compiler/playcanvas.cjs +19 -0
  244. package/dist/compiler/playcanvas.js +13 -0
  245. package/dist/compiler/r3f.cjs +38 -0
  246. package/dist/compiler/r3f.d.ts +22 -0
  247. package/dist/compiler/r3f.js +16 -0
  248. package/dist/compiler/remotion.cjs +23 -0
  249. package/dist/compiler/remotion.js +4 -0
  250. package/dist/compiler/reproducibility.cjs +39 -0
  251. package/dist/compiler/reproducibility.js +4 -0
  252. package/dist/compiler/sdf.cjs +24 -0
  253. package/dist/compiler/sdf.js +12 -0
  254. package/dist/compiler/semantic-scene.cjs +31 -0
  255. package/dist/compiler/semantic-scene.js +4 -0
  256. package/dist/compiler/state.cjs +21 -0
  257. package/dist/compiler/state.js +11 -0
  258. package/dist/compiler/trait-composition.cjs +30 -0
  259. package/dist/compiler/trait-composition.js +9 -0
  260. package/dist/compiler/unity.cjs +19 -0
  261. package/dist/compiler/unity.js +13 -0
  262. package/dist/compiler/unreal.cjs +23 -0
  263. package/dist/compiler/unreal.js +13 -0
  264. package/dist/compiler/urdf.cjs +52 -0
  265. package/dist/compiler/urdf.js +12 -0
  266. package/dist/compiler/usd-physics.cjs +26 -0
  267. package/dist/compiler/usd-physics.js +9 -0
  268. package/dist/compiler/visionos.cjs +19 -0
  269. package/dist/compiler/visionos.js +13 -0
  270. package/dist/compiler/vrchat.cjs +22 -0
  271. package/dist/compiler/vrchat.js +12 -0
  272. package/dist/compiler/vrr.cjs +24 -0
  273. package/dist/compiler/vrr.js +12 -0
  274. package/dist/compiler/wasm.cjs +36 -0
  275. package/dist/compiler/wasm.js +12 -0
  276. package/dist/compiler/webgpu.cjs +18 -0
  277. package/dist/compiler/webgpu.js +12 -0
  278. package/dist/coordinators/index.cjs +1266 -0
  279. package/dist/coordinators/index.d.ts +72 -1
  280. package/dist/coordinators/index.js +1259 -0
  281. package/dist/debugger.cjs +24 -0
  282. package/dist/debugger.js +11 -0
  283. package/dist/entries/interop.cjs +64 -0
  284. package/dist/entries/interop.js +7 -0
  285. package/dist/entries/scripting.cjs +55 -0
  286. package/dist/entries/scripting.js +10 -0
  287. package/dist/hololand/index.cjs +146 -0
  288. package/dist/hololand/index.d.ts +70 -0
  289. package/dist/hololand/index.js +5 -0
  290. package/dist/index.cjs +43233 -0
  291. package/dist/index.d.ts +976 -21
  292. package/dist/index.js +39995 -0
  293. package/dist/math/tropical-spmv.cjs +45 -0
  294. package/dist/math/tropical-spmv.js +4 -0
  295. package/dist/math/vec3.cjs +57 -0
  296. package/dist/math/vec3.js +4 -0
  297. package/dist/ml-dsa-FSKBTE3W.cjs +1265 -0
  298. package/dist/ml-dsa-Z7JDKW4L.js +1265 -0
  299. package/dist/paper-0c-spike/index.cjs +150 -0
  300. package/dist/paper-0c-spike/index.js +141 -0
  301. package/dist/parser.cjs +61 -0
  302. package/dist/parser.d.ts +11 -0
  303. package/dist/parser.js +12 -0
  304. package/dist/playwright-3AT3AKTV.cjs +98673 -0
  305. package/dist/playwright-VZPDVUEQ.js +98660 -0
  306. package/dist/reconstruction/index.cjs +153 -0
  307. package/dist/reconstruction/index.d.ts +29 -2
  308. package/dist/reconstruction/index.js +8 -0
  309. package/dist/runtime.cjs +316 -0
  310. package/dist/runtime.d.ts +61 -0
  311. package/dist/runtime.js +31 -0
  312. package/dist/self-improvement/index.cjs +563 -0
  313. package/dist/self-improvement/index.js +545 -0
  314. package/dist/storage/index.cjs +38 -0
  315. package/dist/storage/index.js +5 -0
  316. package/dist/testing.cjs +25 -0
  317. package/dist/testing.d.ts +70 -0
  318. package/dist/testing.js +4 -0
  319. package/dist/traitDocs/traitDocs.cjs +33 -0
  320. package/dist/traitDocs/traitDocs.js +7 -0
  321. package/dist/traits/botanical-lotus.cjs +41 -0
  322. package/dist/traits/botanical-lotus.d.ts +172 -0
  323. package/dist/traits/botanical-lotus.js +4 -0
  324. package/dist/traits/engines/index.cjs +520 -0
  325. package/dist/traits/engines/index.js +380 -0
  326. package/dist/traits/index.cjs +24409 -0
  327. package/dist/traits/index.d.ts +171 -35
  328. package/dist/traits/index.js +21634 -0
  329. package/dist/traits/simulation-solver-factory.cjs +13 -0
  330. package/dist/traits/simulation-solver-factory.d.ts +23 -0
  331. package/dist/traits/simulation-solver-factory.js +4 -0
  332. package/dist/traits/webcam-gaze.cjs +35 -0
  333. package/dist/traits/webcam-gaze.d.ts +17 -0
  334. package/dist/traits/webcam-gaze.js +4 -0
  335. package/dist/type-checker.cjs +19 -0
  336. package/dist/type-checker.js +6 -0
  337. package/dist/world/index.cjs +947 -0
  338. package/dist/world/index.d.ts +147 -0
  339. package/dist/world/index.js +939 -0
  340. package/dist/world-model/index.cjs +1446 -0
  341. package/dist/world-model/index.d.ts +119 -0
  342. package/dist/world-model/index.js +1414 -0
  343. package/dist/wot/index.cjs +29 -0
  344. package/dist/wot/index.js +4 -0
  345. package/package.json +93 -49
@@ -0,0 +1,672 @@
1
+ 'use strict';
2
+
3
+ var chunkXUUVDHIF_cjs = require('./chunk-XUUVDHIF.cjs');
4
+ var chunkKKP7JKN4_cjs = require('./chunk-KKP7JKN4.cjs');
5
+ var chunkHCCQLAA4_cjs = require('./chunk-HCCQLAA4.cjs');
6
+ var ans = require('@holoscript/core-types/ans');
7
+
8
+ // src/compiler/WebGPUCompiler.ts
9
+ var WebGPUCompiler_exports = {};
10
+ chunkHCCQLAA4_cjs.__export(WebGPUCompiler_exports, {
11
+ WebGPUCompiler: () => exports.WebGPUCompiler
12
+ });
13
+ function isGpuParticleTraitName(name) {
14
+ return typeof name === "string" && (name === "gpu_particle" || name.startsWith("vfx_particle_"));
15
+ }
16
+ function findGpuParticleTrait(traits) {
17
+ return traits?.find((t) => isGpuParticleTraitName(t.name));
18
+ }
19
+ exports.WebGPUCompiler = void 0;
20
+ var init_WebGPUCompiler = chunkHCCQLAA4_cjs.__esm({
21
+ "src/compiler/WebGPUCompiler.ts"() {
22
+ chunkKKP7JKN4_cjs.init_CompilerBase();
23
+ chunkXUUVDHIF_cjs.init_DomainBlockCompilerMixin();
24
+ exports.WebGPUCompiler = class extends chunkKKP7JKN4_cjs.CompilerBase {
25
+ constructor(options = {}) {
26
+ super();
27
+ this.compilerName = "WebGPUCompiler";
28
+ this.lines = [];
29
+ this.indentLevel = 0;
30
+ this.objectIndex = 0;
31
+ this.options = {
32
+ entryPoint: options.entryPoint || "main",
33
+ enableCompute: options.enableCompute ?? true,
34
+ msaa: options.msaa || 4,
35
+ indent: options.indent || " ",
36
+ provenanceHash: options.provenanceHash ?? ""
37
+ };
38
+ }
39
+ getRequiredCapability() {
40
+ return ans.ANSCapabilityPath.WEBGPU;
41
+ }
42
+ compile(composition, agentToken, outputPath) {
43
+ this.validateCompilerAccess(agentToken, outputPath);
44
+ this.lines = [];
45
+ this.indentLevel = 0;
46
+ this.objectIndex = 0;
47
+ this.emit("// Auto-generated by HoloScript WebGPUCompiler");
48
+ this.emit(
49
+ `// Source: composition "${this.escapeStringValue(composition.name, "TypeScript")}"`
50
+ );
51
+ this.emit("// Do not edit manually \u2014 regenerate from .holo source");
52
+ if (this.options.provenanceHash) {
53
+ this.emit(`// Provenance Hash: ${this.options.provenanceHash}`);
54
+ }
55
+ this.emit("");
56
+ this.emitDeviceInit();
57
+ if (composition.environment) this.emitEnvironment(composition.environment);
58
+ if (composition.objects) {
59
+ for (const obj of composition.objects) this.emitObject(obj);
60
+ }
61
+ if (composition.spatialGroups) {
62
+ for (const group of composition.spatialGroups) this.emitGroup(group);
63
+ }
64
+ if (composition.lights) {
65
+ for (const light of composition.lights) this.emitLight(light);
66
+ }
67
+ if (composition.camera) this.emitCamera(composition.camera);
68
+ if (this.options.enableCompute) this.emitComputeShaders(composition);
69
+ this.emitWebGPUDomainBlocks(composition);
70
+ this.emitShaderSources();
71
+ this.emitRenderLoop(composition);
72
+ return this.lines.join("\n");
73
+ }
74
+ emitWebGPUDomainBlocks(composition) {
75
+ const domainBlocks = composition.domainBlocks ?? [];
76
+ if (domainBlocks.length === 0) return;
77
+ this.emit("");
78
+ this.emit("// === v4.2 Domain Blocks ===");
79
+ let blockIdx = 0;
80
+ const compiled = chunkXUUVDHIF_cjs.compileDomainBlocks(
81
+ domainBlocks,
82
+ {
83
+ material: (block) => {
84
+ const mat = chunkXUUVDHIF_cjs.compileMaterialBlock(block);
85
+ return chunkXUUVDHIF_cjs.materialToWebGPU(mat, `db${blockIdx++}`);
86
+ }
87
+ },
88
+ (block) => `// Domain block: ${block.domain}/${block.keyword} "${this.escapeStringValue(block.name, "TypeScript")}"`
89
+ );
90
+ for (const line of compiled) {
91
+ for (const l of line.split("\n")) {
92
+ this.emit(l);
93
+ }
94
+ }
95
+ }
96
+ // ─── Device Init ──────────────────────────────────────────────────────────
97
+ emitDeviceInit() {
98
+ this.emit("// === WebGPU Device Initialization ===");
99
+ this.emit('const canvas = document.querySelector("canvas") as HTMLCanvasElement;');
100
+ this.emit("const adapter = await navigator.gpu.requestAdapter();");
101
+ this.emit('if (!adapter) throw new Error("WebGPU not supported");');
102
+ this.emit("const device = await adapter.requestDevice();");
103
+ this.emit('const context = canvas.getContext("webgpu") as GPUCanvasContext;');
104
+ this.emit("const format = navigator.gpu.getPreferredCanvasFormat();");
105
+ this.emit('context.configure({ device, format, alphaMode: "premultiplied" });');
106
+ this.emit(`const MSAA_COUNT = ${this.options.msaa};`);
107
+ this.emit(
108
+ "const msaaTexture = device.createTexture({ size: [canvas.width, canvas.height], sampleCount: MSAA_COUNT, format, usage: GPUTextureUsage.RENDER_ATTACHMENT });"
109
+ );
110
+ this.emit(
111
+ 'const depthTexture = device.createTexture({ size: [canvas.width, canvas.height], sampleCount: MSAA_COUNT, format: "depth24plus", usage: GPUTextureUsage.RENDER_ATTACHMENT });'
112
+ );
113
+ this.emit("");
114
+ this.emit(
115
+ "function createBuffer(device: GPUDevice, data: Float32Array, usage: number): GPUBuffer {"
116
+ );
117
+ this.indent();
118
+ this.emit(
119
+ "const buf = device.createBuffer({ size: data.byteLength, usage: usage | GPUBufferUsage.COPY_DST });"
120
+ );
121
+ this.emit("device.queue.writeBuffer(buf, 0, data); return buf;");
122
+ this.dedent();
123
+ this.emit("}");
124
+ this.emit("function createStorageBuffer(device: GPUDevice, size: number): GPUBuffer {");
125
+ this.indent();
126
+ this.emit(
127
+ "return device.createBuffer({ size, usage: GPUBufferUsage.STORAGE | GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST });"
128
+ );
129
+ this.dedent();
130
+ this.emit("}");
131
+ this.emit("");
132
+ }
133
+ // ─── Environment ──────────────────────────────────────────────────────────
134
+ emitEnvironment(env) {
135
+ this.emit("// === Environment ===");
136
+ const envData = {};
137
+ for (const prop of env.properties) envData[prop.key] = prop.value;
138
+ const bg = envData.background || envData.skybox || "#000000";
139
+ const bgColor = this.parseColor(bg);
140
+ this.emit(
141
+ `const clearColor: GPUColor = { r: ${bgColor[0]}, g: ${bgColor[1]}, b: ${bgColor[2]}, a: 1.0 };`
142
+ );
143
+ if (envData.fog && typeof envData.fog === "object") {
144
+ const fog = envData.fog;
145
+ const fc = this.parseColor(fog.color || "#cccccc");
146
+ this.emit(
147
+ `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);`
148
+ );
149
+ }
150
+ if (envData.ambient_light !== void 0) {
151
+ this.emit(
152
+ `const ambientIntensity = ${typeof envData.ambient_light === "number" ? envData.ambient_light : 0.5};`
153
+ );
154
+ }
155
+ this.emit("");
156
+ }
157
+ // ─── Object ───────────────────────────────────────────────────────────────
158
+ emitObject(obj) {
159
+ this.objectIndex++;
160
+ const v = this.sanitizeName(obj.name);
161
+ const meshType = this.findObjProp(obj, "geometry") || this.findObjProp(obj, "mesh") || this.findObjProp(obj, "type") || "cube";
162
+ const modelSrc = this.findObjProp(obj, "source") || this.findObjProp(obj, "src") || this.findObjProp(obj, "model");
163
+ const isModel = meshType === "model" || !!modelSrc;
164
+ const traits = obj.traits || [];
165
+ this.emit(`// Object: ${this.escapeStringValue(obj.name, "TypeScript")}`);
166
+ const isGaussianSplat = traits.some((t) => t.name === "gaussian_splat");
167
+ const isPointCloud = traits.some((t) => t.name === "point_cloud");
168
+ const isGpuParticle = traits.some((t) => isGpuParticleTraitName(t.name));
169
+ if (isModel && modelSrc) {
170
+ this.emit(`const ${v}Model = await assetLoader.load("${modelSrc}");`);
171
+ const pos = this.findObjProp(obj, "position");
172
+ const [px, py, pz] = Array.isArray(pos) ? pos : [0, 0, 0];
173
+ this.emit(
174
+ `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);`
175
+ );
176
+ } else if (isModel) {
177
+ this.emit(`// WARNING: geometry "model" without source URL \u2014 placeholder cube`);
178
+ this.emitMeshObject(v, obj, "cube");
179
+ } else if (isGaussianSplat) {
180
+ this.emitGaussianSplatObject(v, obj);
181
+ } else if (isPointCloud) {
182
+ this.emitPointCloudObject(v, obj);
183
+ } else if (isGpuParticle) {
184
+ this.emitGpuParticleObject(v, obj);
185
+ } else {
186
+ this.emitMeshObject(v, obj, meshType);
187
+ }
188
+ if (traits.some((t) => t.name === "gpu_physics")) {
189
+ this.emit(`const ${v}PhysicsBuf = createStorageBuffer(device, 1024 * 16); // gpu_physics`);
190
+ }
191
+ if (traits.some((t) => t.name === "compute" || t.name === "gpu_buffer")) {
192
+ const ct = traits.find((t) => t.name === "compute" || t.name === "gpu_buffer");
193
+ this.emit(
194
+ `const ${v}ComputeBuf = createStorageBuffer(device, ${ct?.config?.buffer_size || 4096});`
195
+ );
196
+ }
197
+ this.emit("");
198
+ if (obj.children) {
199
+ for (const child of obj.children) this.emitObject(child);
200
+ }
201
+ }
202
+ emitMeshObject(v, obj, meshType) {
203
+ this.emit(`const ${v}Vertices = ${this.geometryVertexDataFn(meshType)};`);
204
+ this.emit(`const ${v}VBO = createBuffer(device, ${v}Vertices, GPUBufferUsage.VERTEX);`);
205
+ this.emit(`const ${v}VertexCount = ${v}Vertices.length / 6;`);
206
+ const pos = this.findObjProp(obj, "position");
207
+ const scale = this.findObjProp(obj, "scale") || this.findObjProp(obj, "size");
208
+ const [px, py, pz] = Array.isArray(pos) ? pos : [0, 0, 0];
209
+ const [sx, sy, sz] = Array.isArray(scale) ? scale : typeof scale === "number" ? [scale, scale, scale] : [1, 1, 1];
210
+ this.emit(
211
+ `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);`
212
+ );
213
+ const material = this.findObjProp(obj, "material");
214
+ const color = this.findObjProp(obj, "color");
215
+ const [cr, cg, cb] = this.extractMaterialColor(material, color);
216
+ const rough = this.extractMaterialProp(material, "roughness", 0.5);
217
+ const metal = this.extractMaterialProp(material, "metalness", 0);
218
+ this.emit(
219
+ `const ${v}Mat = createBuffer(device, new Float32Array([${cr},${cg},${cb},1.0, ${rough},${metal},0,0]), GPUBufferUsage.UNIFORM);`
220
+ );
221
+ this.emit(`const ${v}Pipeline = device.createRenderPipeline({`);
222
+ this.indent();
223
+ this.emit('layout: "auto",');
224
+ this.emit(
225
+ 'vertex: { module: device.createShaderModule({ code: WGSL_VERTEX }), entryPoint: "vs_main",'
226
+ );
227
+ this.emit(
228
+ ' buffers: [{ arrayStride: 24, attributes: [{ shaderLocation: 0, offset: 0, format: "float32x3" }, { shaderLocation: 1, offset: 12, format: "float32x3" }] }] },'
229
+ );
230
+ this.emit(
231
+ 'fragment: { module: device.createShaderModule({ code: WGSL_FRAGMENT }), entryPoint: "fs_main", targets: [{ format }] },'
232
+ );
233
+ this.emit('primitive: { topology: "triangle-list", cullMode: "back" },');
234
+ this.emit(
235
+ `depthStencil: { format: "depth24plus", depthWriteEnabled: true, depthCompare: "less" }, multisample: { count: MSAA_COUNT },`
236
+ );
237
+ this.dedent();
238
+ this.emit("});");
239
+ this.emit(
240
+ `const ${v}Bind = device.createBindGroup({ layout: ${v}Pipeline.getBindGroupLayout(0), entries: [`
241
+ );
242
+ this.emit(
243
+ ` { binding: 0, resource: { buffer: ${v}Model } }, { binding: 1, resource: { buffer: ${v}Mat } }] });`
244
+ );
245
+ }
246
+ emitGaussianSplatObject(v, obj) {
247
+ const trait = obj.traits?.find((t) => t.name === "gaussian_splat");
248
+ const src = trait?.config?.src || "scene.ply";
249
+ const max = trait?.config?.max_splats || 5e5;
250
+ const sorted = trait?.config?.sorted !== false;
251
+ this.emit(`// Gaussian Splat \u2014 source: ${src} (${sorted ? "radix-sorted" : "unsorted"})`);
252
+ if (sorted) {
253
+ this.emit(
254
+ `// === Wait-Free Radix Sort Pipeline (4x 8-bit Blelloch scan, no global atomics) ===`
255
+ );
256
+ this.emit(`import { GaussianSplatSorter } from '@holoscript/core/gpu/GaussianSplatSorter';`);
257
+ this.emit(`const ${v}Sorter = new GaussianSplatSorter(device, {`);
258
+ this.indent();
259
+ this.emit(`maxSplats: ${max},`);
260
+ this.emit(`canvasWidth: canvas.width,`);
261
+ this.emit(`canvasHeight: canvas.height,`);
262
+ this.dedent();
263
+ this.emit(`});`);
264
+ this.emit(`await ${v}Sorter.initialize();`);
265
+ this.emit(`const ${v}SplatCount = { value: 0 };`);
266
+ } else {
267
+ this.emit(`const ${v}SplatBuf = createStorageBuffer(device, ${max} * 32);`);
268
+ this.emit(`const ${v}SplatCount = { value: 0 };`);
269
+ this.emit(`const ${v}SplatPipeline = device.createRenderPipeline({`);
270
+ this.indent();
271
+ this.emit('layout: "auto",');
272
+ this.emit(
273
+ 'vertex: { module: device.createShaderModule({ code: WGSL_SPLAT }), entryPoint: "vs_splat", buffers: [] },'
274
+ );
275
+ this.emit(
276
+ 'fragment: { module: device.createShaderModule({ code: WGSL_SPLAT }), entryPoint: "fs_splat",'
277
+ );
278
+ this.emit(
279
+ ' targets: [{ format, blend: { color: { srcFactor: "one", dstFactor: "one-minus-src-alpha", operation: "add" }, alpha: { srcFactor: "one", dstFactor: "one-minus-src-alpha", operation: "add" } } }] },'
280
+ );
281
+ this.emit('primitive: { topology: "triangle-strip" },');
282
+ this.emit(
283
+ 'depthStencil: { format: "depth24plus", depthWriteEnabled: false, depthCompare: "less" },'
284
+ );
285
+ this.dedent();
286
+ this.emit("});");
287
+ }
288
+ }
289
+ emitPointCloudObject(v, obj) {
290
+ const trait = obj.traits?.find((t) => t.name === "point_cloud");
291
+ const max = trait?.config?.max_points || 1e5;
292
+ this.emit(`// Point Cloud (${max} max points)`);
293
+ this.emit(`const ${v}PointBuf = createStorageBuffer(device, ${max} * 16);`);
294
+ this.emit(`const ${v}PointCount = { value: 0 };`);
295
+ this.emit(`const ${v}PointPipeline = device.createRenderPipeline({`);
296
+ this.indent();
297
+ this.emit('layout: "auto",');
298
+ this.emit(
299
+ 'vertex: { module: device.createShaderModule({ code: WGSL_POINT }), entryPoint: "vs_point",'
300
+ );
301
+ this.emit(
302
+ ' buffers: [{ arrayStride: 16, attributes: [{ shaderLocation: 0, offset: 0, format: "float32x3" }, { shaderLocation: 1, offset: 12, format: "unorm8x4" }] }] },'
303
+ );
304
+ this.emit(
305
+ 'fragment: { module: device.createShaderModule({ code: WGSL_POINT }), entryPoint: "fs_point", targets: [{ format }] },'
306
+ );
307
+ this.emit(
308
+ `primitive: { topology: "point-list" }, depthStencil: { format: "depth24plus", depthWriteEnabled: true, depthCompare: "less" }, multisample: { count: MSAA_COUNT },`
309
+ );
310
+ this.dedent();
311
+ this.emit("});");
312
+ }
313
+ emitGpuParticleObject(v, obj) {
314
+ const trait = findGpuParticleTrait(obj.traits);
315
+ const count = trait?.config?.count || 1e4;
316
+ this.emit(`// GPU Particles (${count}) from @${trait?.name ?? "gpu_particle"}`);
317
+ this.emit(`const ${v}ParticleCount = ${count};`);
318
+ this.emit(`const ${v}ParticleBufA = createStorageBuffer(device, ${v}ParticleCount * 32);`);
319
+ this.emit(`const ${v}ParticleBufB = createStorageBuffer(device, ${v}ParticleCount * 32);`);
320
+ this.emit(`const ${v}ParticlePipeline = device.createRenderPipeline({`);
321
+ this.indent();
322
+ this.emit('layout: "auto",');
323
+ this.emit(
324
+ 'vertex: { module: device.createShaderModule({ code: WGSL_PARTICLE_RENDER }), entryPoint: "vs_particle",'
325
+ );
326
+ this.emit(
327
+ ' buffers: [{ arrayStride: 32, attributes: [{ shaderLocation: 0, offset: 0, format: "float32x3" }, { shaderLocation: 1, offset: 12, format: "float32x3" }, { shaderLocation: 2, offset: 24, format: "float32" }] }] },'
328
+ );
329
+ this.emit(
330
+ 'fragment: { module: device.createShaderModule({ code: WGSL_PARTICLE_RENDER }), entryPoint: "fs_particle",'
331
+ );
332
+ this.emit(
333
+ ' targets: [{ format, blend: { color: { srcFactor: "src-alpha", dstFactor: "one", operation: "add" }, alpha: { srcFactor: "zero", dstFactor: "one", operation: "add" } } }] },'
334
+ );
335
+ this.emit(
336
+ 'primitive: { topology: "point-list" }, depthStencil: { format: "depth24plus", depthWriteEnabled: false, depthCompare: "less" },'
337
+ );
338
+ this.dedent();
339
+ this.emit("});");
340
+ }
341
+ // ─── Spatial Group ────────────────────────────────────────────────────────
342
+ emitGroup(group) {
343
+ const v = this.sanitizeName(group.name);
344
+ this.emit(`// Spatial Group: ${this.escapeStringValue(group.name, "TypeScript")}`);
345
+ const pos = group.properties.find((p) => p.key === "position")?.value;
346
+ const [px, py, pz] = Array.isArray(pos) ? pos : [0, 0, 0];
347
+ this.emit(
348
+ `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);`
349
+ );
350
+ for (const obj of group.objects) this.emitObject(obj);
351
+ if (group.groups) {
352
+ for (const sub of group.groups) this.emitGroup(sub);
353
+ }
354
+ this.emit("");
355
+ }
356
+ // ─── Light ────────────────────────────────────────────────────────────────
357
+ emitLight(light) {
358
+ const v = this.sanitizeName(light.name);
359
+ let color = [1, 1, 1], intensity = 1, pos = [0, 10, 0], dir = [0, -1, 0];
360
+ for (const prop of light.properties) {
361
+ if (prop.key === "color") color = this.parseColor(prop.value);
362
+ else if (prop.key === "intensity") intensity = prop.value;
363
+ else if (prop.key === "position" && Array.isArray(prop.value)) pos = prop.value;
364
+ else if (prop.key === "direction" && Array.isArray(prop.value)) dir = prop.value;
365
+ }
366
+ const ti = { directional: 0, point: 1, spot: 2, hemisphere: 3, ambient: 4, area: 5 }[light.lightType] ?? 0;
367
+ this.emit(
368
+ `// Light: ${this.escapeStringValue(light.name, "TypeScript")} (${light.lightType})`
369
+ );
370
+ this.emit(
371
+ `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);`
372
+ );
373
+ this.emit("");
374
+ }
375
+ // ─── Camera ───────────────────────────────────────────────────────────────
376
+ emitCamera(cam) {
377
+ this.emit("// === Camera ===");
378
+ let fov = 60, near = 0.1, far = 1e3, pos = [0, 1, 5], lookAt = [0, 0, 0];
379
+ for (const prop of cam.properties) {
380
+ if (prop.key === "fov" || prop.key === "field_of_view") fov = prop.value;
381
+ else if (prop.key === "near") near = prop.value;
382
+ else if (prop.key === "far") far = prop.value;
383
+ else if (prop.key === "position" && Array.isArray(prop.value)) pos = prop.value;
384
+ else if ((prop.key === "look_at" || prop.key === "lookAt") && Array.isArray(prop.value))
385
+ lookAt = prop.value;
386
+ }
387
+ this.emit(`const cameraFov = ${fov} * Math.PI / 180;`);
388
+ this.emit(`const cameraNear = ${near}, cameraFar = ${far};`);
389
+ this.emit(`const cameraPos = new Float32Array([${pos.join(",")}]);`);
390
+ this.emit(`const cameraTarget = new Float32Array([${lookAt.join(",")}]);`);
391
+ this.emit("const aspect = canvas.width / canvas.height;");
392
+ this.emit("function buildViewProjection(): Float32Array {");
393
+ this.indent();
394
+ this.emit("const f = 1.0 / Math.tan(cameraFov / 2), ri = 1.0 / (cameraNear - cameraFar);");
395
+ this.emit(
396
+ "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]);"
397
+ );
398
+ this.dedent();
399
+ this.emit("}");
400
+ this.emit(
401
+ "const vpUniform = createBuffer(device, buildViewProjection(), GPUBufferUsage.UNIFORM);"
402
+ );
403
+ this.emit("");
404
+ }
405
+ // ─── Compute Pipelines ────────────────────────────────────────────────────
406
+ emitComputeShaders(composition) {
407
+ const gpuObjs = (composition.objects || []).filter(
408
+ (o) => o.traits?.some(
409
+ (t) => isGpuParticleTraitName(t.name) || t.name === "gpu_physics" || t.name === "compute"
410
+ )
411
+ );
412
+ if (gpuObjs.length === 0) return;
413
+ this.emit("// === Compute Pipelines ===");
414
+ for (const obj of gpuObjs) {
415
+ const v = this.sanitizeName(obj.name);
416
+ const traits = obj.traits || [];
417
+ if (traits.some((t) => isGpuParticleTraitName(t.name))) {
418
+ const count = findGpuParticleTrait(traits)?.config?.count || 1e4;
419
+ this.emit(
420
+ `const ${v}ParticleCompute = device.createComputePipeline({ layout: "auto", compute: { module: device.createShaderModule({ code: WGSL_PARTICLE_COMPUTE }), entryPoint: "cs_particle_update" } });`
421
+ );
422
+ this.emit(`const ${v}ComputeDispatches = ${Math.ceil(count / 64)};`);
423
+ }
424
+ if (traits.some((t) => t.name === "gpu_physics")) {
425
+ this.emit(
426
+ `const ${v}PhysicsCompute = device.createComputePipeline({ layout: "auto", compute: { module: device.createShaderModule({ code: WGSL_PHYSICS_COMPUTE }), entryPoint: "cs_physics_step" } });`
427
+ );
428
+ }
429
+ if (traits.some((t) => t.name === "compute")) {
430
+ const ct = traits.find((t) => t.name === "compute");
431
+ const entry = ct?.config?.shader || "custom_compute";
432
+ const wg = ct?.config?.workgroups || [64, 1, 1];
433
+ this.emit(
434
+ `const ${v}CustomCompute = device.createComputePipeline({ layout: "auto", compute: { module: device.createShaderModule({ code: WGSL_CUSTOM_${v.toUpperCase()} }), entryPoint: "${entry}" } });`
435
+ );
436
+ this.emit(`const ${v}Workgroups: [number, number, number] = [${wg}];`);
437
+ }
438
+ }
439
+ this.emit("");
440
+ }
441
+ // ─── WGSL Shader Sources ──────────────────────────────────────────────────
442
+ emitShaderSources() {
443
+ this.emit("// === WGSL Shader Sources ===");
444
+ this.emit("const WGSL_VERTEX = /* wgsl */`");
445
+ this.emit("struct Uniforms { model: mat4x4<f32> };");
446
+ this.emit("@group(0) @binding(0) var<uniform> u: Uniforms;");
447
+ this.emit("struct VIn { @location(0) pos: vec3<f32>, @location(1) norm: vec3<f32> };");
448
+ this.emit(
449
+ "struct VOut { @builtin(position) clip: vec4<f32>, @location(0) wNorm: vec3<f32>, @location(1) wPos: vec3<f32> };"
450
+ );
451
+ this.emit("@vertex fn vs_main(i: VIn) -> VOut {");
452
+ this.emit(" var o: VOut; let w = u.model * vec4<f32>(i.pos, 1.0);");
453
+ this.emit(
454
+ " o.clip = w; o.wNorm = (u.model * vec4<f32>(i.norm, 0.0)).xyz; o.wPos = w.xyz; return o; }`;"
455
+ );
456
+ this.emit("");
457
+ this.emit("const WGSL_FRAGMENT = /* wgsl */`");
458
+ this.emit("struct Mat { color: vec4<f32>, rm: vec4<f32> };");
459
+ this.emit("@group(0) @binding(1) var<uniform> mat: Mat;");
460
+ this.emit("struct FIn { @location(0) wNorm: vec3<f32>, @location(1) wPos: vec3<f32> };");
461
+ this.emit("@fragment fn fs_main(i: FIn) -> @location(0) vec4<f32> {");
462
+ this.emit(" let N = normalize(i.wNorm); let L = normalize(vec3<f32>(1.0, 2.0, 1.5));");
463
+ this.emit(" let d = max(dot(N, L), 0.0) * (1.0 - mat.rm[0] * 0.5);");
464
+ this.emit(" return vec4<f32>(mat.color.rgb * (0.15 + d), mat.color.a); }`;");
465
+ this.emit("");
466
+ this.emit("const WGSL_SPLAT = /* wgsl */`");
467
+ this.emit(
468
+ "struct Splat { center: vec3<f32>, opacity: f32, cov: array<f32,6>, sh: vec3<f32> };"
469
+ );
470
+ this.emit("@group(0) @binding(0) var<storage, read> splats: array<Splat>;");
471
+ this.emit(
472
+ "struct SO { @builtin(position) p: vec4<f32>, @location(0) c: vec4<f32>, @location(1) uv: vec2<f32> };"
473
+ );
474
+ this.emit(
475
+ "@vertex fn vs_splat(@builtin(vertex_index) vi: u32, @builtin(instance_index) ii: u32) -> SO {"
476
+ );
477
+ this.emit(" var q = array<vec2<f32>,4>(vec2(-1,-1),vec2(1,-1),vec2(-1,1),vec2(1,1));");
478
+ this.emit(
479
+ " var o: SO; let s = splats[ii]; o.p = vec4<f32>(s.center.xy + q[vi]*0.01, s.center[2], 1.0);"
480
+ );
481
+ this.emit(" o.c = vec4<f32>(s.sh, s.opacity); o.uv = q[vi]; return o; }");
482
+ this.emit("@fragment fn fs_splat(i: SO) -> @location(0) vec4<f32> {");
483
+ this.emit(" let a = i.c.a * exp(-dot(i.uv, i.uv) * 4.0); if (a < 0.01) { discard; }");
484
+ this.emit(" return vec4<f32>(i.c.rgb * a, a); }`;");
485
+ this.emit("");
486
+ this.emit("const WGSL_POINT = /* wgsl */`");
487
+ this.emit("struct PO { @builtin(position) p: vec4<f32>, @location(0) c: vec4<f32> };");
488
+ this.emit(
489
+ "@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; }"
490
+ );
491
+ this.emit("@fragment fn fs_point(i: PO) -> @location(0) vec4<f32> { return i.c; }`;");
492
+ this.emit("");
493
+ this.emit("const WGSL_PARTICLE_RENDER = /* wgsl */`");
494
+ this.emit("struct PVO { @builtin(position) p: vec4<f32>, @location(0) life: f32 };");
495
+ this.emit(
496
+ "@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; }"
497
+ );
498
+ this.emit("@fragment fn fs_particle(i: PVO) -> @location(0) vec4<f32> {");
499
+ this.emit(
500
+ " 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); }`;"
501
+ );
502
+ this.emit("");
503
+ this.emit("const WGSL_PARTICLE_COMPUTE = /* wgsl */`");
504
+ this.emit("struct P { pos: vec3<f32>, _p0: f32, vel: vec3<f32>, life: f32 };");
505
+ this.emit("@group(0) @binding(0) var<storage, read> pin: array<P>;");
506
+ this.emit("@group(0) @binding(1) var<storage, read_write> pout: array<P>;");
507
+ this.emit("@group(0) @binding(2) var<uniform> dt: f32;");
508
+ this.emit(
509
+ "@compute @workgroup_size(64) fn cs_particle_update(@builtin(global_invocation_id) gid: vec3<u32>) {"
510
+ );
511
+ this.emit(" let i = gid[0]; if (i >= arrayLength(&pin)) { return; } var p = pin[i];");
512
+ this.emit(" p.vel[1] -= 9.81 * dt; p.pos += p.vel * dt; p.life -= dt;");
513
+ this.emit(
514
+ " if (p.life <= 0.0) { p.pos = vec3(0.0); p.vel = vec3(0.0, 5.0, 0.0); p.life = 2.0; }"
515
+ );
516
+ this.emit(" pout[i] = p; }`;");
517
+ this.emit("");
518
+ this.emit("const WGSL_PHYSICS_COMPUTE = /* wgsl */`");
519
+ this.emit("struct Body { pos: vec3<f32>, mass: f32, vel: vec3<f32>, _p: f32 };");
520
+ this.emit("@group(0) @binding(0) var<storage, read_write> bodies: array<Body>;");
521
+ this.emit("@group(0) @binding(1) var<uniform> dt: f32;");
522
+ this.emit(
523
+ "@compute @workgroup_size(64) fn cs_physics_step(@builtin(global_invocation_id) gid: vec3<u32>) {"
524
+ );
525
+ this.emit(" let i = gid[0]; if (i >= arrayLength(&bodies)) { return; } var b = bodies[i];");
526
+ this.emit(" b.vel[1] -= 9.81 * dt; b.pos += b.vel * dt;");
527
+ this.emit(
528
+ " if (b.pos[1] < 0.0) { b.pos[1] = 0.0; b.vel[1] = -b.vel[1] * 0.6; } bodies[i] = b; }`;"
529
+ );
530
+ this.emit("");
531
+ }
532
+ // ─── Render Loop ──────────────────────────────────────────────────────────
533
+ emitRenderLoop(composition) {
534
+ this.emit("// === Render Loop ===");
535
+ this.emit("let frameCount = 0;");
536
+ this.emit("const t0 = performance.now();");
537
+ this.emit("function frame() {");
538
+ this.indent();
539
+ this.emit("frameCount++;");
540
+ this.emit("const time = (performance.now() - t0) / 1000.0;");
541
+ this.emit("const enc = device.createCommandEncoder();");
542
+ const gpuObjs = (composition.objects || []).filter(
543
+ (o) => o.traits?.some(
544
+ (t) => isGpuParticleTraitName(t.name) || t.name === "gpu_physics" || t.name === "compute"
545
+ )
546
+ );
547
+ if (gpuObjs.length > 0 && this.options.enableCompute) {
548
+ this.emit("const cp = enc.beginComputePass();");
549
+ for (const obj of gpuObjs) {
550
+ const v = this.sanitizeName(obj.name);
551
+ if (obj.traits?.some((t) => isGpuParticleTraitName(t.name))) {
552
+ this.emit(
553
+ `cp.setPipeline(${v}ParticleCompute); cp.dispatchWorkgroups(${v}ComputeDispatches);`
554
+ );
555
+ }
556
+ if (obj.traits?.some((t) => t.name === "gpu_physics")) {
557
+ this.emit(`cp.setPipeline(${v}PhysicsCompute); cp.dispatchWorkgroups(16);`);
558
+ }
559
+ if (obj.traits?.some((t) => t.name === "compute")) {
560
+ this.emit(`cp.setPipeline(${v}CustomCompute); cp.dispatchWorkgroups(...${v}Workgroups);`);
561
+ }
562
+ }
563
+ this.emit("cp.end();");
564
+ }
565
+ this.emit("const rp = enc.beginRenderPass({");
566
+ this.indent();
567
+ this.emit(
568
+ 'colorAttachments: [{ view: msaaTexture.createView(), resolveTarget: context.getCurrentTexture().createView(), clearValue: clearColor, loadOp: "clear", storeOp: "store" }],'
569
+ );
570
+ this.emit(
571
+ 'depthStencilAttachment: { view: depthTexture.createView(), depthClearValue: 1.0, depthLoadOp: "clear", depthStoreOp: "store" },'
572
+ );
573
+ this.dedent();
574
+ this.emit("});");
575
+ if (composition.objects) {
576
+ for (const obj of composition.objects) this.emitDrawCall(obj);
577
+ }
578
+ if (composition.spatialGroups) {
579
+ for (const group of composition.spatialGroups) {
580
+ for (const obj of group.objects) this.emitDrawCall(obj);
581
+ }
582
+ }
583
+ this.emit("rp.end();");
584
+ this.emit("device.queue.submit([enc.finish()]);");
585
+ this.emit("requestAnimationFrame(frame);");
586
+ this.dedent();
587
+ this.emit("}");
588
+ this.emit("requestAnimationFrame(frame);");
589
+ }
590
+ emitDrawCall(obj) {
591
+ const v = this.sanitizeName(obj.name);
592
+ const traits = obj.traits || [];
593
+ if (traits.some((t) => t.name === "gaussian_splat")) {
594
+ this.emit(`rp.setPipeline(${v}SplatPipeline); rp.draw(4, ${v}SplatCount.value);`);
595
+ } else if (traits.some((t) => t.name === "point_cloud")) {
596
+ this.emit(`rp.setPipeline(${v}PointPipeline); rp.draw(${v}PointCount.value);`);
597
+ } else if (traits.some((t) => isGpuParticleTraitName(t.name))) {
598
+ this.emit(
599
+ `rp.setPipeline(${v}ParticlePipeline); rp.setVertexBuffer(0, ${v}ParticleBufA); rp.draw(${v}ParticleCount);`
600
+ );
601
+ } else {
602
+ this.emit(
603
+ `rp.setPipeline(${v}Pipeline); rp.setBindGroup(0, ${v}Bind); rp.setVertexBuffer(0, ${v}VBO); rp.draw(${v}VertexCount);`
604
+ );
605
+ }
606
+ if (obj.children) {
607
+ for (const child of obj.children) this.emitDrawCall(child);
608
+ }
609
+ }
610
+ // ─── Helpers ──────────────────────────────────────────────────────────────
611
+ emit(line) {
612
+ this.lines.push(this.options.indent.repeat(this.indentLevel) + line);
613
+ }
614
+ indent() {
615
+ this.indentLevel++;
616
+ }
617
+ dedent() {
618
+ this.indentLevel = Math.max(0, this.indentLevel - 1);
619
+ }
620
+ sanitizeName(name) {
621
+ return name.replace(/[^a-zA-Z0-9_]/g, "_");
622
+ }
623
+ findObjProp(obj, key) {
624
+ return obj.properties?.find((p) => p.key === key)?.value;
625
+ }
626
+ parseColor(value) {
627
+ if (typeof value === "string" && value.startsWith("#")) {
628
+ const h = value.slice(1);
629
+ return [
630
+ parseFloat((parseInt(h.substring(0, 2), 16) / 255).toFixed(4)),
631
+ parseFloat((parseInt(h.substring(2, 4), 16) / 255).toFixed(4)),
632
+ parseFloat((parseInt(h.substring(4, 6), 16) / 255).toFixed(4))
633
+ ];
634
+ }
635
+ if (Array.isArray(value) && value.length >= 3) return [value[0], value[1], value[2]];
636
+ return [1, 1, 1];
637
+ }
638
+ extractMaterialColor(material, color) {
639
+ if (color) return this.parseColor(color);
640
+ if (material && typeof material === "object" && !Array.isArray(material)) {
641
+ const m = material;
642
+ if (m.color) return this.parseColor(m.color);
643
+ }
644
+ return [0.8, 0.8, 0.8];
645
+ }
646
+ extractMaterialProp(material, key, fallback) {
647
+ if (material && typeof material === "object" && !Array.isArray(material)) {
648
+ const m = material;
649
+ if (m[key] !== void 0) return m[key];
650
+ }
651
+ return fallback;
652
+ }
653
+ geometryVertexDataFn(meshType) {
654
+ const map = {
655
+ sphere: "generateSphereVertices(0.5, 16, 16)",
656
+ orb: "generateSphereVertices(0.5, 16, 16)",
657
+ plane: "generatePlaneVertices(1.0, 1.0)",
658
+ cylinder: "generateCylinderVertices(0.5, 1.0, 16)",
659
+ cone: "generateConeVertices(0.5, 1.0, 16)",
660
+ pyramid: "generateConeVertices(0.5, 1.0, 16)",
661
+ torus: "generateTorusVertices(0.5, 0.15, 16, 32)"
662
+ };
663
+ return map[meshType] || "generateCubeVertices(1.0)";
664
+ }
665
+ };
666
+ }
667
+ });
668
+
669
+ exports.WebGPUCompiler_exports = WebGPUCompiler_exports;
670
+ exports.init_WebGPUCompiler = init_WebGPUCompiler;
671
+ //# sourceMappingURL=chunk-CXFDRBQU.cjs.map
672
+ //# sourceMappingURL=chunk-CXFDRBQU.cjs.map