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