@holoscript/core 6.0.4 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1 -1
- package/dist/compiler/index.d.ts +82 -0
- package/dist/constants.d.ts +3 -2
- package/dist/coordinators/index.d.ts +189 -0
- package/dist/index.d.ts +501 -19
- package/dist/paper-0c-spike/index.d.ts +29 -0
- package/dist/reconstruction/index.d.ts +78 -0
- package/dist/tools/index.d.ts +22 -1
- package/dist/traitDocs/traitDocs.d.ts +69 -0
- package/dist/traits/index.d.ts +61 -0
- package/package.json +105 -57
- package/dist/GLTFPipeline-DEN36VNK.js +0 -12
- package/dist/GLTFPipeline-YPCAK236.cjs +0 -33
- package/dist/HoloScriptPlusParser-BN6KVRCM.js +0 -692
- package/dist/HoloScriptPlusParser-NC5FE6AL.cjs +0 -697
- package/dist/USDZExporter-NTMBNTDB.js +0 -707
- package/dist/USDZExporter-UWGWNMMD.cjs +0 -709
- package/dist/chunk-27LWW5FU.cjs +0 -410
- package/dist/chunk-2CWOLHTE.js +0 -69
- package/dist/chunk-33LSUQDD.cjs +0 -835
- package/dist/chunk-3FJCK5XA.js +0 -2232
- package/dist/chunk-3FXV5S25.cjs +0 -633
- package/dist/chunk-3FYZOR7S.cjs +0 -69
- package/dist/chunk-3SAK5KFL.cjs +0 -83
- package/dist/chunk-4XSNJCLC.cjs +0 -1859
- package/dist/chunk-54FHG2MX.js +0 -655
- package/dist/chunk-56IF4NTA.js +0 -56
- package/dist/chunk-5BGSECRJ.cjs +0 -2237
- package/dist/chunk-5GLCTO44.js +0 -161
- package/dist/chunk-5O6TQC6M.cjs +0 -1871
- package/dist/chunk-5OEOHAAW.cjs +0 -682
- package/dist/chunk-5TOFIR6L.js +0 -407
- package/dist/chunk-5WUNN6ZN.cjs +0 -428
- package/dist/chunk-6TZPZCOJ.cjs +0 -1404
- package/dist/chunk-6UEHYZ7V.cjs +0 -773
- package/dist/chunk-6XSERL6L.js +0 -5678
- package/dist/chunk-72EQECGT.cjs +0 -908
- package/dist/chunk-7AGYRWKW.cjs +0 -507
- package/dist/chunk-7LCYLPW2.cjs +0 -663
- package/dist/chunk-A7PIMZGU.js +0 -263
- package/dist/chunk-ATSKSYVE.cjs +0 -51683
- package/dist/chunk-B5TCIAPQ.cjs +0 -117
- package/dist/chunk-BF2235SI.cjs +0 -5714
- package/dist/chunk-BKIGPPVM.js +0 -629
- package/dist/chunk-BND3ST2K.cjs +0 -662
- package/dist/chunk-BU7VWW2K.js +0 -2522
- package/dist/chunk-BWFJEM5A.js +0 -5419
- package/dist/chunk-CAUCGUEA.cjs +0 -130
- package/dist/chunk-CBJSLA2E.cjs +0 -5423
- package/dist/chunk-CDPGV4DN.js +0 -114
- package/dist/chunk-CLYEIWA5.cjs +0 -408
- package/dist/chunk-CS2EMTGF.js +0 -1966
- package/dist/chunk-DMG7C4H2.js +0 -975
- package/dist/chunk-DXJQDCFL.js +0 -468
- package/dist/chunk-E3FWRT3Z.js +0 -608
- package/dist/chunk-E3UALNFA.js +0 -421
- package/dist/chunk-EONILVMF.js +0 -762
- package/dist/chunk-EQV4R3EV.cjs +0 -769
- package/dist/chunk-F3HH56EB.cjs +0 -5538
- package/dist/chunk-F4IULT7N.js +0 -1488
- package/dist/chunk-FF3Q7ADR.js +0 -380
- package/dist/chunk-FFKU7BTK.cjs +0 -1046
- package/dist/chunk-FHQVYCH2.js +0 -70
- package/dist/chunk-FSF7EQVA.cjs +0 -1974
- package/dist/chunk-G4VZTCIB.js +0 -659
- package/dist/chunk-G7CT3EMP.cjs +0 -1002
- package/dist/chunk-GGHSW2NN.js +0 -51334
- package/dist/chunk-GVUR45UF.cjs +0 -777
- package/dist/chunk-H5Z7NASB.js +0 -9662
- package/dist/chunk-HE7ULERA.cjs +0 -697
- package/dist/chunk-HJJLD366.js +0 -1169
- package/dist/chunk-HPS76H7Q.js +0 -309
- package/dist/chunk-HQUEA5R6.cjs +0 -424
- package/dist/chunk-HYNTS5CP.js +0 -422
- package/dist/chunk-I6XZ5DZF.cjs +0 -488
- package/dist/chunk-IBDG74G2.cjs +0 -1219
- package/dist/chunk-IFNQFCTM.js +0 -3098
- package/dist/chunk-IHOUYQIA.js +0 -406
- package/dist/chunk-ILRBGFVD.cjs +0 -72
- package/dist/chunk-IWI6J7FX.js +0 -421
- package/dist/chunk-K3JDKWGI.cjs +0 -270
- package/dist/chunk-K6EKD26I.js +0 -630
- package/dist/chunk-KCQ5NDYC.cjs +0 -3172
- package/dist/chunk-KED34ILP.js +0 -832
- package/dist/chunk-KSGXLT74.cjs +0 -457
- package/dist/chunk-L4G4RLXX.js +0 -767
- package/dist/chunk-LDP5OK6G.js +0 -1216
- package/dist/chunk-LGGRPKTV.cjs +0 -735
- package/dist/chunk-LK5IAVH6.cjs +0 -1173
- package/dist/chunk-LSW7P7ML.js +0 -3675
- package/dist/chunk-LXJ4667L.cjs +0 -3874
- package/dist/chunk-LZ266PCM.cjs +0 -4499
- package/dist/chunk-MD6KDHVE.cjs +0 -237
- package/dist/chunk-MEASWI2Y.js +0 -126
- package/dist/chunk-MPXBVFHQ.js +0 -768
- package/dist/chunk-N5FTS757.cjs +0 -415
- package/dist/chunk-NCUKG4SK.cjs +0 -3075
- package/dist/chunk-NDQNIJEH.js +0 -1715
- package/dist/chunk-NOZZ46QU.js +0 -168
- package/dist/chunk-OFKWH2IP.js +0 -449
- package/dist/chunk-PHENW4MQ.js +0 -65
- package/dist/chunk-PMGODDJA.cjs +0 -319
- package/dist/chunk-Q4QX3AET.cjs +0 -1505
- package/dist/chunk-Q56TT7IL.js +0 -483
- package/dist/chunk-Q5JT3YML.cjs +0 -129
- package/dist/chunk-Q5SJOGHQ.cjs +0 -4256
- package/dist/chunk-QGKNANZ3.js +0 -3071
- package/dist/chunk-QLEAOI3Q.cjs +0 -424
- package/dist/chunk-R7MA7QWV.js +0 -732
- package/dist/chunk-RVYPEYPX.js +0 -678
- package/dist/chunk-S2N5TNMA.js +0 -1855
- package/dist/chunk-S565K7NK.js +0 -752
- package/dist/chunk-SDAMZIRE.js +0 -765
- package/dist/chunk-T36DDXSF.js +0 -4250
- package/dist/chunk-T4NKMBDL.js +0 -5474
- package/dist/chunk-T7LEXZUZ.cjs +0 -2526
- package/dist/chunk-TEWCN33Y.js +0 -694
- package/dist/chunk-TQSZUOW5.cjs +0 -793
- package/dist/chunk-TSH3MSQU.cjs +0 -129
- package/dist/chunk-UERJ3YJV.js +0 -504
- package/dist/chunk-UPJBDCVF.js +0 -1395
- package/dist/chunk-V3NN3HPP.js +0 -4462
- package/dist/chunk-VJ3L7CHT.cjs +0 -169
- package/dist/chunk-WB4Z63GG.js +0 -229
- package/dist/chunk-WDW67DZB.cjs +0 -9728
- package/dist/chunk-WGMEAYBG.js +0 -126
- package/dist/chunk-X4ZF6CNE.cjs +0 -473
- package/dist/chunk-X6SEAXAX.cjs +0 -3681
- package/dist/chunk-XCWFGZAA.js +0 -1043
- package/dist/chunk-XD6IYDUX.js +0 -903
- package/dist/chunk-XG23EUQX.cjs +0 -1717
- package/dist/chunk-XRKWN5PL.cjs +0 -173
- package/dist/chunk-XUILI4KB.cjs +0 -430
- package/dist/chunk-XUTX5CBW.js +0 -126
- package/dist/chunk-XWPNTWDN.cjs +0 -755
- package/dist/chunk-XXINBTZK.cjs +0 -633
- package/dist/chunk-YCXFCXDS.js +0 -1868
- package/dist/chunk-YQK5JNFK.js +0 -3725
- package/dist/chunk-YYXH45E2.js +0 -426
- package/dist/chunk-Z34RLXRA.cjs +0 -612
- package/dist/chunk-ZP4D3CSX.cjs +0 -72
- package/dist/cli/holoscript-runner.cjs +0 -2259
- package/dist/cli/holoscript-runner.js +0 -2234
- package/dist/codebase/index.cjs +0 -336
- package/dist/codebase/index.js +0 -331
- package/dist/compiler/agent-inference.cjs +0 -28
- package/dist/compiler/agent-inference.js +0 -5
- package/dist/compiler/android-xr.cjs +0 -19
- package/dist/compiler/android-xr.js +0 -9
- package/dist/compiler/android.cjs +0 -20
- package/dist/compiler/android.js +0 -10
- package/dist/compiler/ar.cjs +0 -20
- package/dist/compiler/ar.js +0 -8
- package/dist/compiler/babylon.cjs +0 -17
- package/dist/compiler/babylon.js +0 -11
- package/dist/compiler/coco.cjs +0 -27
- package/dist/compiler/coco.js +0 -4
- package/dist/compiler/domain-block-utils.cjs +0 -602
- package/dist/compiler/domain-block-utils.js +0 -8
- package/dist/compiler/dtdl.cjs +0 -24
- package/dist/compiler/dtdl.js +0 -8
- package/dist/compiler/gltf-pipeline.cjs +0 -39
- package/dist/compiler/gltf-pipeline.js +0 -4
- package/dist/compiler/godot.cjs +0 -15
- package/dist/compiler/godot.js +0 -9
- package/dist/compiler/incremental.cjs +0 -29
- package/dist/compiler/incremental.js +0 -4
- package/dist/compiler/index.cjs +0 -2578
- package/dist/compiler/index.js +0 -2383
- package/dist/compiler/ios.cjs +0 -20
- package/dist/compiler/ios.js +0 -10
- package/dist/compiler/multi-layer.cjs +0 -20
- package/dist/compiler/multi-layer.js +0 -11
- package/dist/compiler/nodetoy.cjs +0 -23
- package/dist/compiler/nodetoy.js +0 -4
- package/dist/compiler/openxr.cjs +0 -15
- package/dist/compiler/openxr.js +0 -9
- package/dist/compiler/playcanvas.cjs +0 -16
- package/dist/compiler/playcanvas.js +0 -10
- package/dist/compiler/r3f.cjs +0 -34
- package/dist/compiler/r3f.js +0 -12
- package/dist/compiler/remotion.cjs +0 -23
- package/dist/compiler/remotion.js +0 -4
- package/dist/compiler/reproducibility.cjs +0 -39
- package/dist/compiler/reproducibility.js +0 -4
- package/dist/compiler/sdf.cjs +0 -21
- package/dist/compiler/sdf.js +0 -9
- package/dist/compiler/semantic-scene.cjs +0 -31
- package/dist/compiler/semantic-scene.js +0 -4
- package/dist/compiler/state.cjs +0 -17
- package/dist/compiler/state.js +0 -7
- package/dist/compiler/trait-composition.cjs +0 -26
- package/dist/compiler/trait-composition.js +0 -5
- package/dist/compiler/unity.cjs +0 -15
- package/dist/compiler/unity.js +0 -9
- package/dist/compiler/unreal.cjs +0 -19
- package/dist/compiler/unreal.js +0 -9
- package/dist/compiler/urdf.cjs +0 -45
- package/dist/compiler/urdf.js +0 -9
- package/dist/compiler/usd-physics.cjs +0 -23
- package/dist/compiler/usd-physics.js +0 -6
- package/dist/compiler/visionos.cjs +0 -15
- package/dist/compiler/visionos.js +0 -9
- package/dist/compiler/vrchat.cjs +0 -19
- package/dist/compiler/vrchat.js +0 -9
- package/dist/compiler/vrr.cjs +0 -21
- package/dist/compiler/vrr.js +0 -9
- package/dist/compiler/wasm.cjs +0 -33
- package/dist/compiler/wasm.js +0 -9
- package/dist/compiler/webgpu.cjs +0 -15
- package/dist/compiler/webgpu.js +0 -9
- package/dist/debugger.cjs +0 -21
- package/dist/debugger.js +0 -8
- package/dist/entries/interop.cjs +0 -62
- package/dist/entries/interop.js +0 -5
- package/dist/entries/scripting.cjs +0 -68
- package/dist/entries/scripting.js +0 -11
- package/dist/index.cjs +0 -40921
- package/dist/index.js +0 -37763
- package/dist/math/vec3.cjs +0 -57
- package/dist/math/vec3.js +0 -4
- package/dist/ml-dsa-PHCWUBPX.cjs +0 -1178
- package/dist/ml-dsa-WYLJHJO6.js +0 -1178
- package/dist/parser.cjs +0 -27
- package/dist/parser.js +0 -10
- package/dist/playwright-5OSAPTNH.js +0 -98660
- package/dist/playwright-RL6GY4F7.cjs +0 -98673
- package/dist/runtime.cjs +0 -16
- package/dist/runtime.js +0 -7
- package/dist/storage/index.cjs +0 -37
- package/dist/storage/index.js +0 -4
- package/dist/traits/index.cjs +0 -14649
- package/dist/traits/index.js +0 -12243
- package/dist/type-checker.cjs +0 -18
- package/dist/type-checker.js +0 -5
package/dist/chunk-KED34ILP.js
DELETED
|
@@ -1,832 +0,0 @@
|
|
|
1
|
-
import { init_ProvenanceSemiring, ProvenanceSemiring } from './chunk-A7PIMZGU.js';
|
|
2
|
-
import { init_TraitCompositor, TraitCompositor } from './chunk-DXJQDCFL.js';
|
|
3
|
-
import { init_DomainBlockCompilerMixin, compileDomainBlocks, compileWeatherBlock, compileAudioSourceBlock, audioSourceToBabylon, compilePostProcessingBlock, postProcessingToBabylon, compileParticleBlock, particlesToBabylon, compilePhysicsBlock, physicsToBabylon, compileMaterialBlock, materialToBabylon } from './chunk-YQK5JNFK.js';
|
|
4
|
-
import { init_CompilerBase, CompilerBase } from './chunk-6XSERL6L.js';
|
|
5
|
-
import { __export, __esm } from './chunk-2CWOLHTE.js';
|
|
6
|
-
import { ANSCapabilityPath } from '@holoscript/platform';
|
|
7
|
-
|
|
8
|
-
// src/compiler/BabylonCompiler.ts
|
|
9
|
-
var BabylonCompiler_exports = {};
|
|
10
|
-
__export(BabylonCompiler_exports, {
|
|
11
|
-
BabylonCompiler: () => BabylonCompiler
|
|
12
|
-
});
|
|
13
|
-
var SHAPE_TO_MESH, BabylonCompiler;
|
|
14
|
-
var init_BabylonCompiler = __esm({
|
|
15
|
-
"src/compiler/BabylonCompiler.ts"() {
|
|
16
|
-
init_TraitCompositor();
|
|
17
|
-
init_ProvenanceSemiring();
|
|
18
|
-
init_CompilerBase();
|
|
19
|
-
init_DomainBlockCompilerMixin();
|
|
20
|
-
SHAPE_TO_MESH = {
|
|
21
|
-
sphere: "CreateSphere",
|
|
22
|
-
orb: "CreateSphere",
|
|
23
|
-
cube: "CreateBox",
|
|
24
|
-
box: "CreateBox",
|
|
25
|
-
cylinder: "CreateCylinder",
|
|
26
|
-
cone: "CreateCylinder",
|
|
27
|
-
pyramid: "CreateCylinder",
|
|
28
|
-
plane: "CreateGround",
|
|
29
|
-
ground: "CreateGround",
|
|
30
|
-
torus: "CreateTorus",
|
|
31
|
-
ring: "CreateTorus",
|
|
32
|
-
capsule: "CreateCapsule",
|
|
33
|
-
disc: "CreateDisc"
|
|
34
|
-
};
|
|
35
|
-
BabylonCompiler = class extends CompilerBase {
|
|
36
|
-
constructor(options = {}) {
|
|
37
|
-
super();
|
|
38
|
-
this.compilerName = "BabylonCompiler";
|
|
39
|
-
this.lines = [];
|
|
40
|
-
this.indentLevel = 0;
|
|
41
|
-
this.options = {
|
|
42
|
-
className: options.className || "GeneratedScene",
|
|
43
|
-
useHavok: options.useHavok ?? true,
|
|
44
|
-
enableXR: options.enableXR ?? false,
|
|
45
|
-
indent: options.indent || " "
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
getRequiredCapability() {
|
|
49
|
-
return ANSCapabilityPath.BABYLON;
|
|
50
|
-
}
|
|
51
|
-
compile(composition, agentToken, outputPath) {
|
|
52
|
-
this.validateCompilerAccess(agentToken, outputPath);
|
|
53
|
-
this.lines = [];
|
|
54
|
-
this.indentLevel = 0;
|
|
55
|
-
this.emit("// Auto-generated by HoloScript BabylonCompiler");
|
|
56
|
-
this.emit(
|
|
57
|
-
`// Source: composition "${this.escapeStringValue(composition.name, "TypeScript")}"`
|
|
58
|
-
);
|
|
59
|
-
this.emit("");
|
|
60
|
-
this.emitImports(composition);
|
|
61
|
-
this.emit("");
|
|
62
|
-
this.emit(`export class ${this.options.className} {`);
|
|
63
|
-
this.indent();
|
|
64
|
-
this.emit("private engine: BABYLON.Engine;");
|
|
65
|
-
this.emit("private scene: BABYLON.Scene;");
|
|
66
|
-
this.emit("private canvas: HTMLCanvasElement;");
|
|
67
|
-
this.emit("");
|
|
68
|
-
this.emit("constructor(canvas: HTMLCanvasElement) {");
|
|
69
|
-
this.indent();
|
|
70
|
-
this.emit("this.canvas = canvas;");
|
|
71
|
-
this.emit(
|
|
72
|
-
"this.engine = new BABYLON.Engine(canvas, true, { preserveDrawingBuffer: true, stencil: true });"
|
|
73
|
-
);
|
|
74
|
-
this.emit("this.scene = new BABYLON.Scene(this.engine);");
|
|
75
|
-
this.dedent();
|
|
76
|
-
this.emit("}");
|
|
77
|
-
this.emit("");
|
|
78
|
-
this.emit("async build(): Promise<void> {");
|
|
79
|
-
this.indent();
|
|
80
|
-
this.emitSceneSetup(composition);
|
|
81
|
-
if (composition.environment) this.emitEnvironment(composition.environment);
|
|
82
|
-
if (composition.lights?.length) {
|
|
83
|
-
for (const light of composition.lights) this.emitLight(light);
|
|
84
|
-
} else {
|
|
85
|
-
this.emit(
|
|
86
|
-
'const defaultLight = new BABYLON.HemisphericLight("defaultLight", new BABYLON.Vector3(0, 1, 0), this.scene);'
|
|
87
|
-
);
|
|
88
|
-
this.emit("defaultLight.intensity = 0.7;");
|
|
89
|
-
this.emit("");
|
|
90
|
-
}
|
|
91
|
-
if (composition.camera) this.emitCamera(composition.camera);
|
|
92
|
-
else {
|
|
93
|
-
this.emit(
|
|
94
|
-
'const camera = new BABYLON.ArcRotateCamera("defaultCamera", -Math.PI / 2, Math.PI / 3, 10, BABYLON.Vector3.Zero(), this.scene);'
|
|
95
|
-
);
|
|
96
|
-
this.emit("camera.attachControl(this.canvas, true);");
|
|
97
|
-
this.emit("");
|
|
98
|
-
}
|
|
99
|
-
if (composition.objects?.length) for (const obj of composition.objects) this.emitObject(obj);
|
|
100
|
-
if (composition.spatialGroups?.length)
|
|
101
|
-
for (const g of composition.spatialGroups) this.emitGroup(g);
|
|
102
|
-
if (composition.timelines?.length)
|
|
103
|
-
for (const tl of composition.timelines) this.emitTimeline(tl);
|
|
104
|
-
if (composition.audio?.length) for (const a of composition.audio) this.emitAudio(a);
|
|
105
|
-
if (composition.zones?.length) for (const z of composition.zones) this.emitZone(z);
|
|
106
|
-
if (composition.ui) this.emitUI(composition.ui);
|
|
107
|
-
if (composition.effects) this.emitEffects(composition.effects);
|
|
108
|
-
if (composition.transitions?.length)
|
|
109
|
-
for (const t of composition.transitions) this.emitTransition(t);
|
|
110
|
-
if (this.options.enableXR) this.emitXRSetup();
|
|
111
|
-
this.compileBabylonDomainBlocks(composition);
|
|
112
|
-
this.emitRenderLoop();
|
|
113
|
-
this.dedent();
|
|
114
|
-
this.emit("}");
|
|
115
|
-
this.emit("");
|
|
116
|
-
this.emit("dispose(): void { this.scene.dispose(); this.engine.dispose(); }");
|
|
117
|
-
this.dedent();
|
|
118
|
-
this.emit("}");
|
|
119
|
-
return this.lines.join("\n");
|
|
120
|
-
}
|
|
121
|
-
compileBabylonDomainBlocks(composition) {
|
|
122
|
-
const domainBlocks = composition.domainBlocks ?? [];
|
|
123
|
-
if (domainBlocks.length === 0) return;
|
|
124
|
-
this.emit("");
|
|
125
|
-
this.emit("// === v4.2 Domain Blocks ===");
|
|
126
|
-
let blockIdx = 0;
|
|
127
|
-
const compiled = compileDomainBlocks(
|
|
128
|
-
domainBlocks,
|
|
129
|
-
{
|
|
130
|
-
material: (block) => {
|
|
131
|
-
const mat = compileMaterialBlock(block);
|
|
132
|
-
return materialToBabylon(mat, `db${blockIdx++}`);
|
|
133
|
-
},
|
|
134
|
-
physics: (block) => {
|
|
135
|
-
const phys = compilePhysicsBlock(block);
|
|
136
|
-
return physicsToBabylon(phys, `db${blockIdx++}`);
|
|
137
|
-
},
|
|
138
|
-
vfx: (block) => {
|
|
139
|
-
const ps = compileParticleBlock(block);
|
|
140
|
-
return particlesToBabylon(ps, `db${blockIdx++}`);
|
|
141
|
-
},
|
|
142
|
-
postfx: (block) => {
|
|
143
|
-
const pp = compilePostProcessingBlock(block);
|
|
144
|
-
return postProcessingToBabylon(pp);
|
|
145
|
-
},
|
|
146
|
-
audio: (block) => {
|
|
147
|
-
const audio = compileAudioSourceBlock(block);
|
|
148
|
-
return audioSourceToBabylon(audio, `db${blockIdx++}`);
|
|
149
|
-
},
|
|
150
|
-
weather: (block) => {
|
|
151
|
-
const weather = compileWeatherBlock(block);
|
|
152
|
-
const layers = weather.layers.map((l) => `// Layer: ${l.type} \u2014 ${JSON.stringify(l.properties)}`).join("\n");
|
|
153
|
-
return `// Weather: ${weather.keyword} "${weather.name || ""}" \u2014 implement via Babylon.js particle systems
|
|
154
|
-
${layers}`;
|
|
155
|
-
}
|
|
156
|
-
},
|
|
157
|
-
(block) => `// Domain block: ${block.domain}/${block.keyword} "${this.escapeStringValue(block.name, "TypeScript")}"`
|
|
158
|
-
);
|
|
159
|
-
for (const line of compiled) {
|
|
160
|
-
for (const l of line.split("\n")) {
|
|
161
|
-
this.emit(l);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
// --- Imports ---
|
|
166
|
-
emitImports(composition) {
|
|
167
|
-
this.emit('import * as BABYLON from "@babylonjs/core";');
|
|
168
|
-
if (composition.ui) this.emit('import * as GUI from "@babylonjs/gui";');
|
|
169
|
-
if (this.options.useHavok) this.emit('import HavokPhysics from "@babylonjs/havok";');
|
|
170
|
-
if (this.options.enableXR) this.emit('import "@babylonjs/loaders";');
|
|
171
|
-
}
|
|
172
|
-
// --- Scene Setup ---
|
|
173
|
-
emitSceneSetup(_composition) {
|
|
174
|
-
this.emit("this.scene.clearColor = new BABYLON.Color4(0.05, 0.05, 0.1, 1);");
|
|
175
|
-
if (this.options.useHavok) {
|
|
176
|
-
this.emit("const havokInstance = await HavokPhysics();");
|
|
177
|
-
this.emit("const havokPlugin = new BABYLON.HavokPlugin(true, havokInstance);");
|
|
178
|
-
this.emit("this.scene.enablePhysics(new BABYLON.Vector3(0, -9.81, 0), havokPlugin);");
|
|
179
|
-
}
|
|
180
|
-
this.emit("");
|
|
181
|
-
}
|
|
182
|
-
// --- Environment ---
|
|
183
|
-
emitEnvironment(env) {
|
|
184
|
-
for (const prop of env.properties) {
|
|
185
|
-
if (prop.key === "skybox" || prop.key === "preset") {
|
|
186
|
-
this.emit(
|
|
187
|
-
`const skybox = BABYLON.MeshBuilder.CreateBox("skyBox", { size: 1000 }, this.scene);`
|
|
188
|
-
);
|
|
189
|
-
this.emit(`const skyMat = new BABYLON.StandardMaterial("skyMat", this.scene);`);
|
|
190
|
-
this.emit(`skyMat.backFaceCulling = false;`);
|
|
191
|
-
this.emit(
|
|
192
|
-
`skyMat.reflectionTexture = new BABYLON.CubeTexture("textures/${prop.value}", this.scene);`
|
|
193
|
-
);
|
|
194
|
-
this.emit(`skyMat.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;`);
|
|
195
|
-
this.emit(`skyMat.disableLighting = true;`);
|
|
196
|
-
this.emit(`skybox.material = skyMat; skybox.infiniteDistance = true;`);
|
|
197
|
-
} else if (prop.key === "fog" && typeof prop.value === "object") {
|
|
198
|
-
const fog = prop.value;
|
|
199
|
-
this.emit(`this.scene.fogMode = BABYLON.Scene.FOGMODE_LINEAR;`);
|
|
200
|
-
if (fog.color) this.emit(`this.scene.fogColor = ${this.toBabylonColor3(fog.color)};`);
|
|
201
|
-
if (fog.near !== void 0) this.emit(`this.scene.fogStart = ${fog.near};`);
|
|
202
|
-
if (fog.far !== void 0) this.emit(`this.scene.fogEnd = ${fog.far};`);
|
|
203
|
-
} else if (prop.key === "ambient_light") {
|
|
204
|
-
this.emit(
|
|
205
|
-
`this.scene.ambientColor = new BABYLON.Color3(${prop.value}, ${prop.value}, ${prop.value});`
|
|
206
|
-
);
|
|
207
|
-
} else if (prop.key === "ground") {
|
|
208
|
-
this.emit(
|
|
209
|
-
`const ground = BABYLON.MeshBuilder.CreateGround("ground", { width: 100, height: 100 }, this.scene);`
|
|
210
|
-
);
|
|
211
|
-
if (typeof prop.value === "object" && prop.value !== null) {
|
|
212
|
-
const g = prop.value;
|
|
213
|
-
if (g.color) {
|
|
214
|
-
this.emit(`const groundMat = new BABYLON.PBRMaterial("groundMat", this.scene);`);
|
|
215
|
-
this.emit(
|
|
216
|
-
`groundMat.albedoColor = ${this.toBabylonColor3(g.color)}; groundMat.roughness = 0.8;`
|
|
217
|
-
);
|
|
218
|
-
this.emit(`ground.material = groundMat;`);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
this.emit(`ground.receiveShadows = true;`);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
this.emit("");
|
|
225
|
-
}
|
|
226
|
-
// --- Objects ---
|
|
227
|
-
emitObject(obj, parentVar) {
|
|
228
|
-
const v = this.sanitizeName(obj.name);
|
|
229
|
-
let geom = "cube", modelSrc, textContent;
|
|
230
|
-
let position, rotation, scale, size;
|
|
231
|
-
const mat = {};
|
|
232
|
-
for (const p of obj.properties) {
|
|
233
|
-
switch (p.key) {
|
|
234
|
-
case "geometry":
|
|
235
|
-
case "mesh":
|
|
236
|
-
case "type":
|
|
237
|
-
if (typeof p.value === "string") geom = p.value;
|
|
238
|
-
break;
|
|
239
|
-
case "position":
|
|
240
|
-
if (Array.isArray(p.value)) position = p.value;
|
|
241
|
-
break;
|
|
242
|
-
case "rotation":
|
|
243
|
-
if (Array.isArray(p.value)) rotation = p.value;
|
|
244
|
-
break;
|
|
245
|
-
case "scale":
|
|
246
|
-
scale = p.value;
|
|
247
|
-
break;
|
|
248
|
-
case "size":
|
|
249
|
-
size = p.value;
|
|
250
|
-
break;
|
|
251
|
-
case "color":
|
|
252
|
-
mat.color = p.value;
|
|
253
|
-
break;
|
|
254
|
-
case "roughness":
|
|
255
|
-
mat.roughness = p.value;
|
|
256
|
-
break;
|
|
257
|
-
case "metalness":
|
|
258
|
-
case "metallic":
|
|
259
|
-
mat.metalness = p.value;
|
|
260
|
-
break;
|
|
261
|
-
case "opacity":
|
|
262
|
-
mat.opacity = p.value;
|
|
263
|
-
break;
|
|
264
|
-
case "emissive":
|
|
265
|
-
mat.emissive = p.value;
|
|
266
|
-
break;
|
|
267
|
-
case "emissive_intensity":
|
|
268
|
-
case "emissiveIntensity":
|
|
269
|
-
mat.emissiveIntensity = p.value;
|
|
270
|
-
break;
|
|
271
|
-
case "material":
|
|
272
|
-
if (typeof p.value === "object" && p.value !== null)
|
|
273
|
-
Object.assign(mat, p.value);
|
|
274
|
-
break;
|
|
275
|
-
case "model":
|
|
276
|
-
case "src":
|
|
277
|
-
case "source":
|
|
278
|
-
if (typeof p.value === "string") modelSrc = p.value;
|
|
279
|
-
break;
|
|
280
|
-
case "text":
|
|
281
|
-
if (typeof p.value === "string") textContent = p.value;
|
|
282
|
-
break;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
this.emit(`// Object: ${this.escapeStringValue(obj.name, "TypeScript")}`);
|
|
286
|
-
if (modelSrc) {
|
|
287
|
-
this.emit(
|
|
288
|
-
`const ${v} = await BABYLON.SceneLoader.ImportMeshAsync("", "${modelSrc}", "", this.scene);`
|
|
289
|
-
);
|
|
290
|
-
} else if (geom === "text" || textContent) {
|
|
291
|
-
this.emit(
|
|
292
|
-
`const ${v} = BABYLON.MeshBuilder.CreatePlane("${this.escapeStringValue(obj.name, "TypeScript")}", { width: 2, height: 1 }, this.scene);`
|
|
293
|
-
);
|
|
294
|
-
this.emit(
|
|
295
|
-
`const ${v}Tex = new BABYLON.DynamicTexture("${v}Tex", { width: 512, height: 256 }, this.scene);`
|
|
296
|
-
);
|
|
297
|
-
this.emit(
|
|
298
|
-
`${v}Tex.drawText("${textContent || ""}", null, null, "bold 48px Arial", "#ffffff", "#00000000", true);`
|
|
299
|
-
);
|
|
300
|
-
this.emit(`const ${v}Mat = new BABYLON.StandardMaterial("${v}Mat", this.scene);`);
|
|
301
|
-
this.emit(
|
|
302
|
-
`${v}Mat.diffuseTexture = ${v}Tex; ${v}Mat.emissiveColor = BABYLON.Color3.White();`
|
|
303
|
-
);
|
|
304
|
-
this.emit(`${v}.material = ${v}Mat;`);
|
|
305
|
-
} else {
|
|
306
|
-
this.emit(
|
|
307
|
-
`const ${v} = BABYLON.MeshBuilder.${this.mapShapeToMesh(geom)}("${this.escapeStringValue(obj.name, "TypeScript")}", ${this.meshBuilderOptions(geom, size)}, this.scene);`
|
|
308
|
-
);
|
|
309
|
-
if (Object.keys(mat).length > 0) {
|
|
310
|
-
this.emit(`const ${v}Mat = new BABYLON.PBRMaterial("${v}Mat", this.scene);`);
|
|
311
|
-
if (mat.color) this.emit(`${v}Mat.albedoColor = ${this.toBabylonColor3(mat.color)};`);
|
|
312
|
-
if (mat.roughness !== void 0) this.emit(`${v}Mat.roughness = ${mat.roughness};`);
|
|
313
|
-
if (mat.metalness !== void 0) this.emit(`${v}Mat.metallic = ${mat.metalness};`);
|
|
314
|
-
if (mat.opacity !== void 0 && mat.opacity < 1)
|
|
315
|
-
this.emit(`${v}Mat.alpha = ${mat.opacity};`);
|
|
316
|
-
if (mat.emissive)
|
|
317
|
-
this.emit(`${v}Mat.emissiveColor = ${this.toBabylonColor3(mat.emissive)};`);
|
|
318
|
-
if (mat.emissiveIntensity !== void 0)
|
|
319
|
-
this.emit(`${v}Mat.emissiveIntensity = ${mat.emissiveIntensity};`);
|
|
320
|
-
this.emit(`${v}.material = ${v}Mat;`);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
if (position) this.emit(`${v}.position = ${this.toBabylonVector(position)};`);
|
|
324
|
-
if (rotation) this.emit(`${v}.rotation = ${this.toBabylonVector(rotation)};`);
|
|
325
|
-
if (scale) {
|
|
326
|
-
this.emit(
|
|
327
|
-
Array.isArray(scale) ? `${v}.scaling = ${this.toBabylonVector(scale)};` : `${v}.scaling = new BABYLON.Vector3(${scale}, ${scale}, ${scale});`
|
|
328
|
-
);
|
|
329
|
-
}
|
|
330
|
-
if (parentVar) this.emit(`${v}.parent = ${parentVar};`);
|
|
331
|
-
const physicsTraits = (obj.traits || []).filter(
|
|
332
|
-
(t) => t.name === "physics" || t.name === "collidable"
|
|
333
|
-
);
|
|
334
|
-
if (physicsTraits.length > 0) {
|
|
335
|
-
const semiring = new ProvenanceSemiring();
|
|
336
|
-
const applications = physicsTraits.map((t) => ({
|
|
337
|
-
name: t.name,
|
|
338
|
-
config: t.config || {},
|
|
339
|
-
context: obj.provenance?.context
|
|
340
|
-
}));
|
|
341
|
-
const { config: physicsConfig } = semiring.add(applications);
|
|
342
|
-
const mt = (physicsConfig.type || "dynamic") === "static" ? "STATIC" : "DYNAMIC";
|
|
343
|
-
this.emit(
|
|
344
|
-
`const ${v}Body = new BABYLON.PhysicsBody(${v}, BABYLON.PhysicsMotionType.${mt}, false, this.scene);`
|
|
345
|
-
);
|
|
346
|
-
this.emit(`${v}Body.shape = new BABYLON.PhysicsShapeConvexHull(${v}, this.scene);`);
|
|
347
|
-
this.emit(`${v}Body.setMassProperties({ mass: ${physicsConfig.mass ?? 1} });`);
|
|
348
|
-
}
|
|
349
|
-
for (const trait of obj.traits || []) {
|
|
350
|
-
if (trait.name === "physics" || trait.name === "collidable") {
|
|
351
|
-
continue;
|
|
352
|
-
} else if (trait.name === "grabbable") {
|
|
353
|
-
this.emit(`${v}.actionManager = new BABYLON.ActionManager(this.scene);`);
|
|
354
|
-
this.emit(
|
|
355
|
-
`${v}.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickTrigger, () => { console.log("Picked: ${this.escapeStringValue(obj.name, "TypeScript")}"); }));`
|
|
356
|
-
);
|
|
357
|
-
} else if (trait.name === "gaussian_splat") {
|
|
358
|
-
this.emit(`const ${v}PCS = new BABYLON.PointsCloudSystem("${v}PCS", 2, this.scene);`);
|
|
359
|
-
this.emit(`${v}PCS.addPoints(10000); await ${v}PCS.buildMeshAsync();`);
|
|
360
|
-
} else if (trait.name === "shadow") {
|
|
361
|
-
this.emit(`${v}.receiveShadows = true;`);
|
|
362
|
-
} else if (trait.name === "hoverable") {
|
|
363
|
-
this.emit(
|
|
364
|
-
`${v}.actionManager = ${v}.actionManager || new BABYLON.ActionManager(this.scene);`
|
|
365
|
-
);
|
|
366
|
-
this.emit(
|
|
367
|
-
`${v}.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPointerOverTrigger, () => { ${v}.renderOverlay = true; ${v}.overlayColor = BABYLON.Color3.White(); }));`
|
|
368
|
-
);
|
|
369
|
-
this.emit(
|
|
370
|
-
`${v}.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPointerOutTrigger, () => { ${v}.renderOverlay = false; }));`
|
|
371
|
-
);
|
|
372
|
-
} else if (trait.name === "accessible") {
|
|
373
|
-
this.emit(
|
|
374
|
-
`${v}.accessibilityTag = { description: "${this.escapeStringValue(obj.name, "TypeScript")}", role: "${trait.config?.role || "generic"}" };`
|
|
375
|
-
);
|
|
376
|
-
} else if (trait.name === "object_tracking") {
|
|
377
|
-
this.emit(
|
|
378
|
-
`// @object_tracking \u2014 WebXR hit-test or custom tracker for "${this.escapeStringValue(obj.name, "TypeScript")}"`
|
|
379
|
-
);
|
|
380
|
-
} else if (trait.name === "scene_reconstruction") {
|
|
381
|
-
this.emit(
|
|
382
|
-
`// @scene_reconstruction \u2014 WebXR mesh detection for "${this.escapeStringValue(obj.name, "TypeScript")}"`
|
|
383
|
-
);
|
|
384
|
-
} else if (trait.name === "eye_tracked") {
|
|
385
|
-
this.emit(`// @eye_tracked \u2014 WebXR eye tracking (requires 'eye-tracking' feature)`);
|
|
386
|
-
} else if (trait.name === "eye_hand_fusion") {
|
|
387
|
-
this.emit(`// @eye_hand_fusion \u2014 combine WebXR hand + eye tracking`);
|
|
388
|
-
} else if (trait.name === "controlnet") {
|
|
389
|
-
this.emit(
|
|
390
|
-
`// @controlnet(model: "${trait.config?.model || "canny"}") \u2014 route to inference API`
|
|
391
|
-
);
|
|
392
|
-
} else if (trait.name === "ai_texture_gen") {
|
|
393
|
-
this.emit(`// @ai_texture_gen \u2014 apply generated texture to ${v}.material`);
|
|
394
|
-
} else if (trait.name === "neural_animation") {
|
|
395
|
-
this.emit(`// @neural_animation \u2014 BabylonJS AnimationGroup + neural pose predictor`);
|
|
396
|
-
} else if (trait.name === "ai_npc_brain") {
|
|
397
|
-
this.emit(
|
|
398
|
-
`// @ai_npc_brain(model: "${trait.config?.model || "llm"}") \u2014 external LLM/NPC API`
|
|
399
|
-
);
|
|
400
|
-
} else {
|
|
401
|
-
this.emit(
|
|
402
|
-
`// @${this.escapeStringValue(trait.name, "TypeScript")}: ${JSON.stringify(trait.config || {})}`
|
|
403
|
-
);
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
if (obj.traits && Array.isArray(obj.traits) && obj.traits.length > 0) {
|
|
407
|
-
const traitNames = obj.traits.map((t) => t.name);
|
|
408
|
-
const compositor = new TraitCompositor();
|
|
409
|
-
const composed = compositor.compose(traitNames);
|
|
410
|
-
if (Object.keys(composed).length > 0) {
|
|
411
|
-
const matVar = `${v}ComposedMat`;
|
|
412
|
-
this.emit(`// TraitCompositor: composed ${traitNames.join(" + ")}`);
|
|
413
|
-
this.emit(
|
|
414
|
-
`const ${matVar} = ${v}.material as BABYLON.PBRMaterial || new BABYLON.PBRMaterial("${matVar}", this.scene);`
|
|
415
|
-
);
|
|
416
|
-
if (composed.color)
|
|
417
|
-
this.emit(`${matVar}.albedoColor = ${this.toBabylonColor3(composed.color)};`);
|
|
418
|
-
if (composed.roughness !== void 0)
|
|
419
|
-
this.emit(`${matVar}.roughness = ${composed.roughness};`);
|
|
420
|
-
if (composed.metalness !== void 0)
|
|
421
|
-
this.emit(`${matVar}.metallic = ${composed.metalness};`);
|
|
422
|
-
if (composed.opacity !== void 0 && composed.opacity < 1)
|
|
423
|
-
this.emit(`${matVar}.alpha = ${composed.opacity};`);
|
|
424
|
-
if (composed.emissive)
|
|
425
|
-
this.emit(`${matVar}.emissiveColor = ${this.toBabylonColor3(composed.emissive)};`);
|
|
426
|
-
if (composed.emissiveIntensity !== void 0)
|
|
427
|
-
this.emit(`${matVar}.emissiveIntensity = ${composed.emissiveIntensity};`);
|
|
428
|
-
this.emit(`${v}.material = ${matVar};`);
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
if (obj.children?.length) for (const child of obj.children) this.emitObject(child, v);
|
|
432
|
-
this.emit("");
|
|
433
|
-
}
|
|
434
|
-
// --- Groups ---
|
|
435
|
-
emitGroup(group, parentVar) {
|
|
436
|
-
const v = this.sanitizeName(group.name);
|
|
437
|
-
this.emit(
|
|
438
|
-
`const ${v} = new BABYLON.TransformNode("${this.escapeStringValue(group.name, "TypeScript")}", this.scene);`
|
|
439
|
-
);
|
|
440
|
-
for (const p of group.properties) {
|
|
441
|
-
if (p.key === "position" && Array.isArray(p.value))
|
|
442
|
-
this.emit(`${v}.position = ${this.toBabylonVector(p.value)};`);
|
|
443
|
-
else if (p.key === "rotation" && Array.isArray(p.value))
|
|
444
|
-
this.emit(`${v}.rotation = ${this.toBabylonVector(p.value)};`);
|
|
445
|
-
else if (p.key === "scale") {
|
|
446
|
-
this.emit(
|
|
447
|
-
Array.isArray(p.value) ? `${v}.scaling = ${this.toBabylonVector(p.value)};` : `${v}.scaling = new BABYLON.Vector3(${p.value}, ${p.value}, ${p.value});`
|
|
448
|
-
);
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
if (parentVar) this.emit(`${v}.parent = ${parentVar};`);
|
|
452
|
-
for (const obj of group.objects) this.emitObject(obj, v);
|
|
453
|
-
if (group.groups) for (const sub of group.groups) this.emitGroup(sub, v);
|
|
454
|
-
this.emit("");
|
|
455
|
-
}
|
|
456
|
-
// --- Lights ---
|
|
457
|
-
emitLight(light) {
|
|
458
|
-
const v = this.sanitizeName(light.name);
|
|
459
|
-
let pos, color, intensity;
|
|
460
|
-
let dir, castShadow = false, angle, dist;
|
|
461
|
-
for (const p of light.properties) {
|
|
462
|
-
if (p.key === "position" && Array.isArray(p.value)) pos = p.value;
|
|
463
|
-
else if (p.key === "color") color = p.value;
|
|
464
|
-
else if (p.key === "intensity") intensity = p.value;
|
|
465
|
-
else if (p.key === "direction" && Array.isArray(p.value)) dir = p.value;
|
|
466
|
-
else if (p.key === "cast_shadow" || p.key === "castShadow") castShadow = !!p.value;
|
|
467
|
-
else if (p.key === "angle") angle = p.value;
|
|
468
|
-
else if (p.key === "distance") dist = p.value;
|
|
469
|
-
}
|
|
470
|
-
const posV = pos ? this.toBabylonVector(pos) : "new BABYLON.Vector3(0, 1, 0)";
|
|
471
|
-
const dirV = dir ? this.toBabylonVector(dir) : "new BABYLON.Vector3(0, -1, 0)";
|
|
472
|
-
switch (light.lightType) {
|
|
473
|
-
case "hemisphere":
|
|
474
|
-
case "ambient":
|
|
475
|
-
this.emit(
|
|
476
|
-
`const ${v} = new BABYLON.HemisphericLight("${this.escapeStringValue(light.name, "TypeScript")}", ${posV}, this.scene);`
|
|
477
|
-
);
|
|
478
|
-
break;
|
|
479
|
-
case "directional":
|
|
480
|
-
this.emit(
|
|
481
|
-
`const ${v} = new BABYLON.DirectionalLight("${this.escapeStringValue(light.name, "TypeScript")}", ${dirV}, this.scene);`
|
|
482
|
-
);
|
|
483
|
-
if (pos) this.emit(`${v}.position = ${posV};`);
|
|
484
|
-
break;
|
|
485
|
-
case "point":
|
|
486
|
-
this.emit(
|
|
487
|
-
`const ${v} = new BABYLON.PointLight("${this.escapeStringValue(light.name, "TypeScript")}", ${posV}, this.scene);`
|
|
488
|
-
);
|
|
489
|
-
break;
|
|
490
|
-
case "spot":
|
|
491
|
-
this.emit(
|
|
492
|
-
`const ${v} = new BABYLON.SpotLight("${this.escapeStringValue(light.name, "TypeScript")}", ${posV}, ${dirV}, ${angle ?? Math.PI / 4}, 2, this.scene);`
|
|
493
|
-
);
|
|
494
|
-
break;
|
|
495
|
-
case "area":
|
|
496
|
-
this.emit(`// Area light fallback`);
|
|
497
|
-
this.emit(
|
|
498
|
-
`const ${v} = new BABYLON.PointLight("${this.escapeStringValue(light.name, "TypeScript")}", ${posV}, this.scene);`
|
|
499
|
-
);
|
|
500
|
-
break;
|
|
501
|
-
default:
|
|
502
|
-
this.emit(
|
|
503
|
-
`const ${v} = new BABYLON.HemisphericLight("${this.escapeStringValue(light.name, "TypeScript")}", ${posV}, this.scene);`
|
|
504
|
-
);
|
|
505
|
-
break;
|
|
506
|
-
}
|
|
507
|
-
if (color) this.emit(`${v}.diffuse = ${this.toBabylonColor3(color)};`);
|
|
508
|
-
if (intensity !== void 0) this.emit(`${v}.intensity = ${intensity};`);
|
|
509
|
-
if (dist !== void 0) this.emit(`${v}.range = ${dist};`);
|
|
510
|
-
if (castShadow && ["directional", "spot", "point"].includes(light.lightType)) {
|
|
511
|
-
this.emit(`const ${v}SG = new BABYLON.ShadowGenerator(2048, ${v});`);
|
|
512
|
-
this.emit(`${v}SG.useBlurExponentialShadowMap = true;`);
|
|
513
|
-
}
|
|
514
|
-
this.emit("");
|
|
515
|
-
}
|
|
516
|
-
// --- Camera ---
|
|
517
|
-
emitCamera(cam) {
|
|
518
|
-
let fov, pos, lookAt;
|
|
519
|
-
let near, far;
|
|
520
|
-
for (const p of cam.properties) {
|
|
521
|
-
if (p.key === "fov" || p.key === "field_of_view") fov = p.value;
|
|
522
|
-
else if (p.key === "position" && Array.isArray(p.value)) pos = p.value;
|
|
523
|
-
else if ((p.key === "look_at" || p.key === "lookAt") && Array.isArray(p.value))
|
|
524
|
-
lookAt = p.value;
|
|
525
|
-
else if (p.key === "near") near = p.value;
|
|
526
|
-
else if (p.key === "far") far = p.value;
|
|
527
|
-
}
|
|
528
|
-
const target = lookAt ? this.toBabylonVector(lookAt) : "BABYLON.Vector3.Zero()";
|
|
529
|
-
if (cam.cameraType === "orthographic") {
|
|
530
|
-
this.emit(
|
|
531
|
-
`const camera = new BABYLON.FreeCamera("camera", ${pos ? this.toBabylonVector(pos) : "new BABYLON.Vector3(0, 5, -10)"}, this.scene);`
|
|
532
|
-
);
|
|
533
|
-
this.emit(`camera.mode = BABYLON.Camera.ORTHOGRAPHIC_CAMERA;`);
|
|
534
|
-
this.emit(`camera.setTarget(${target});`);
|
|
535
|
-
} else {
|
|
536
|
-
this.emit(
|
|
537
|
-
`const camera = new BABYLON.ArcRotateCamera("camera", -Math.PI / 2, Math.PI / 3, 10, ${target}, this.scene);`
|
|
538
|
-
);
|
|
539
|
-
if (pos) this.emit(`camera.setPosition(${this.toBabylonVector(pos)});`);
|
|
540
|
-
}
|
|
541
|
-
if (fov !== void 0) this.emit(`camera.fov = ${fov * (Math.PI / 180)};`);
|
|
542
|
-
if (near !== void 0) this.emit(`camera.minZ = ${near};`);
|
|
543
|
-
if (far !== void 0) this.emit(`camera.maxZ = ${far};`);
|
|
544
|
-
this.emit("camera.attachControl(this.canvas, true);");
|
|
545
|
-
this.emit("");
|
|
546
|
-
}
|
|
547
|
-
// --- Timeline ---
|
|
548
|
-
emitTimeline(timeline) {
|
|
549
|
-
const v = this.sanitizeName(timeline.name);
|
|
550
|
-
this.emit(
|
|
551
|
-
`const ${v}Group = new BABYLON.AnimationGroup("${this.escapeStringValue(timeline.name, "TypeScript")}", this.scene);`
|
|
552
|
-
);
|
|
553
|
-
const fps = 30;
|
|
554
|
-
for (const entry of timeline.entries) {
|
|
555
|
-
const a = entry.action;
|
|
556
|
-
if (a.kind === "animate") {
|
|
557
|
-
const frame = Math.round(entry.time * fps);
|
|
558
|
-
for (const [key, value] of Object.entries(a.properties)) {
|
|
559
|
-
const n = `${v}_${this.sanitizeName(a.target)}_${key}`;
|
|
560
|
-
const animType = Array.isArray(value) ? "ANIMATIONTYPE_VECTOR3" : "ANIMATIONTYPE_FLOAT";
|
|
561
|
-
const valStr = Array.isArray(value) ? this.toBabylonVector(value) : String(value);
|
|
562
|
-
this.emit(
|
|
563
|
-
`const ${n} = new BABYLON.Animation("${n}", "${this.mapAnimProperty(key)}", ${fps}, BABYLON.Animation.${animType}, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);`
|
|
564
|
-
);
|
|
565
|
-
this.emit(
|
|
566
|
-
`${n}.setKeys([{ frame: 0, value: ${valStr} }, { frame: ${frame}, value: ${valStr} }]);`
|
|
567
|
-
);
|
|
568
|
-
}
|
|
569
|
-
} else if (a.kind === "emit") {
|
|
570
|
-
this.emit(
|
|
571
|
-
`// @${entry.time}s: emit "${this.escapeStringValue(a.event, "TypeScript")}"`
|
|
572
|
-
);
|
|
573
|
-
} else if (a.kind === "call") {
|
|
574
|
-
this.emit(
|
|
575
|
-
`// @${entry.time}s: call ${this.escapeStringValue(a.method, "TypeScript")}()`
|
|
576
|
-
);
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
if (timeline.autoplay) this.emit(`${v}Group.play(${timeline.loop ? "true" : "false"});`);
|
|
580
|
-
this.emit("");
|
|
581
|
-
}
|
|
582
|
-
// --- Audio ---
|
|
583
|
-
emitAudio(audio) {
|
|
584
|
-
const v = this.sanitizeName(audio.name);
|
|
585
|
-
let src = "", volume = 1, loop = false, spatial = false;
|
|
586
|
-
let position, dist;
|
|
587
|
-
for (const p of audio.properties) {
|
|
588
|
-
if (p.key === "src" || p.key === "source") src = String(p.value);
|
|
589
|
-
else if (p.key === "volume") volume = p.value;
|
|
590
|
-
else if (p.key === "loop") loop = !!p.value;
|
|
591
|
-
else if (p.key === "spatial") spatial = !!p.value;
|
|
592
|
-
else if (p.key === "position" && Array.isArray(p.value)) position = p.value;
|
|
593
|
-
else if (p.key === "distance") dist = p.value;
|
|
594
|
-
}
|
|
595
|
-
const opts = ["autoplay: true"];
|
|
596
|
-
if (loop) opts.push("loop: true");
|
|
597
|
-
if (volume !== 1) opts.push(`volume: ${volume}`);
|
|
598
|
-
if (spatial) opts.push("spatialSound: true");
|
|
599
|
-
if (dist !== void 0) opts.push(`maxDistance: ${dist}`);
|
|
600
|
-
this.emit(
|
|
601
|
-
`const ${v} = new BABYLON.Sound("${this.escapeStringValue(audio.name, "TypeScript")}", "${src}", this.scene, null, { ${opts.join(", ")} });`
|
|
602
|
-
);
|
|
603
|
-
if (spatial && position) this.emit(`${v}.setPosition(${this.toBabylonVector(position)});`);
|
|
604
|
-
this.emit("");
|
|
605
|
-
}
|
|
606
|
-
// --- Zone ---
|
|
607
|
-
emitZone(zone) {
|
|
608
|
-
const v = this.sanitizeName(zone.name);
|
|
609
|
-
let shape = "box", position, size, radius;
|
|
610
|
-
for (const p of zone.properties) {
|
|
611
|
-
if (p.key === "shape") shape = String(p.value);
|
|
612
|
-
else if (p.key === "position" && Array.isArray(p.value)) position = p.value;
|
|
613
|
-
else if (p.key === "size") size = p.value;
|
|
614
|
-
else if (p.key === "radius") radius = p.value;
|
|
615
|
-
}
|
|
616
|
-
if (shape === "sphere") {
|
|
617
|
-
this.emit(
|
|
618
|
-
`const ${v} = BABYLON.MeshBuilder.CreateSphere("${this.escapeStringValue(zone.name, "TypeScript")}", { diameter: ${(radius || 5) * 2} }, this.scene);`
|
|
619
|
-
);
|
|
620
|
-
} else {
|
|
621
|
-
const s = Array.isArray(size) ? size : [size || 5, size || 5, size || 5];
|
|
622
|
-
this.emit(
|
|
623
|
-
`const ${v} = BABYLON.MeshBuilder.CreateBox("${this.escapeStringValue(zone.name, "TypeScript")}", { width: ${s[0]}, height: ${s[1]}, depth: ${s[2]} }, this.scene);`
|
|
624
|
-
);
|
|
625
|
-
}
|
|
626
|
-
if (position) this.emit(`${v}.position = ${this.toBabylonVector(position)};`);
|
|
627
|
-
this.emit(`${v}.isVisible = false; ${v}.checkCollisions = true;`);
|
|
628
|
-
if (zone.handlers?.length) {
|
|
629
|
-
this.emit(`${v}.actionManager = new BABYLON.ActionManager(this.scene);`);
|
|
630
|
-
for (const h of zone.handlers) {
|
|
631
|
-
const trigger = h.event === "on_enter" ? "OnIntersectionEnterTrigger" : h.event === "on_exit" ? "OnIntersectionExitTrigger" : `NothingTrigger /* ${this.escapeStringValue(h.event, "TypeScript")} */`;
|
|
632
|
-
this.emit(
|
|
633
|
-
`${v}.actionManager.registerAction(new BABYLON.ExecuteCodeAction({ trigger: BABYLON.ActionManager.${trigger} }, () => { /* ${this.escapeStringValue(h.event, "TypeScript")} */ }));`
|
|
634
|
-
);
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
this.emit("");
|
|
638
|
-
}
|
|
639
|
-
// --- UI ---
|
|
640
|
-
emitUI(ui) {
|
|
641
|
-
this.emit('const advancedTexture = GUI.AdvancedDynamicTexture.CreateFullscreenUI("UI");');
|
|
642
|
-
for (const el of ui.elements) {
|
|
643
|
-
const v = this.sanitizeName(el.name);
|
|
644
|
-
let elType = "text", text = "", fontSize = 24, color = "#ffffff", bg;
|
|
645
|
-
for (const p of el.properties) {
|
|
646
|
-
if (p.key === "type") elType = String(p.value);
|
|
647
|
-
else if (p.key === "text") text = String(p.value);
|
|
648
|
-
else if (p.key === "font_size" || p.key === "fontSize") fontSize = p.value;
|
|
649
|
-
else if (p.key === "color") color = String(p.value);
|
|
650
|
-
else if (p.key === "background") bg = String(p.value);
|
|
651
|
-
}
|
|
652
|
-
if (elType === "button") {
|
|
653
|
-
this.emit(
|
|
654
|
-
`const ${v} = GUI.Button.CreateSimpleButton("${this.escapeStringValue(el.name, "TypeScript")}", "${text}");`
|
|
655
|
-
);
|
|
656
|
-
this.emit(
|
|
657
|
-
`${v}.width = "150px"; ${v}.height = "40px"; ${v}.color = "${color}"; ${v}.fontSize = ${fontSize};`
|
|
658
|
-
);
|
|
659
|
-
if (bg) this.emit(`${v}.background = "${bg}";`);
|
|
660
|
-
this.emit(`advancedTexture.addControl(${v});`);
|
|
661
|
-
} else if (elType === "progress") {
|
|
662
|
-
this.emit(
|
|
663
|
-
`const ${v} = new GUI.StackPanel("${this.escapeStringValue(el.name, "TypeScript")}");`
|
|
664
|
-
);
|
|
665
|
-
this.emit(`${v}.width = "200px"; ${v}.height = "20px"; advancedTexture.addControl(${v});`);
|
|
666
|
-
} else {
|
|
667
|
-
this.emit(
|
|
668
|
-
`const ${v} = new GUI.TextBlock("${this.escapeStringValue(el.name, "TypeScript")}", "${text}");`
|
|
669
|
-
);
|
|
670
|
-
this.emit(
|
|
671
|
-
`${v}.color = "${color}"; ${v}.fontSize = ${fontSize}; advancedTexture.addControl(${v});`
|
|
672
|
-
);
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
this.emit("");
|
|
676
|
-
}
|
|
677
|
-
// --- Effects ---
|
|
678
|
-
emitEffects(effects) {
|
|
679
|
-
this.emit(
|
|
680
|
-
'const pipeline = new BABYLON.DefaultRenderingPipeline("defaultPipeline", true, this.scene);'
|
|
681
|
-
);
|
|
682
|
-
for (const fx of effects.effects) {
|
|
683
|
-
const p = fx.properties;
|
|
684
|
-
switch (fx.effectType) {
|
|
685
|
-
case "bloom":
|
|
686
|
-
this.emit("pipeline.bloomEnabled = true;");
|
|
687
|
-
if (p.intensity !== void 0) this.emit(`pipeline.bloomWeight = ${p.intensity};`);
|
|
688
|
-
if (p.threshold !== void 0) this.emit(`pipeline.bloomThreshold = ${p.threshold};`);
|
|
689
|
-
break;
|
|
690
|
-
case "dof":
|
|
691
|
-
this.emit("pipeline.depthOfFieldEnabled = true;");
|
|
692
|
-
if (p.focalLength !== void 0)
|
|
693
|
-
this.emit(`pipeline.depthOfField.focalLength = ${p.focalLength};`);
|
|
694
|
-
if (p.fStop !== void 0) this.emit(`pipeline.depthOfField.fStop = ${p.fStop};`);
|
|
695
|
-
break;
|
|
696
|
-
case "ssao":
|
|
697
|
-
this.emit(
|
|
698
|
-
'const ssao = new BABYLON.SSAO2RenderingPipeline("ssao", this.scene, { ssaoRatio: 0.5, blurRatio: 0.5 });'
|
|
699
|
-
);
|
|
700
|
-
if (p.radius !== void 0) this.emit(`ssao.radius = ${p.radius};`);
|
|
701
|
-
break;
|
|
702
|
-
case "vignette":
|
|
703
|
-
this.emit("pipeline.imageProcessing.vignetteEnabled = true;");
|
|
704
|
-
if (p.weight !== void 0)
|
|
705
|
-
this.emit(`pipeline.imageProcessing.vignetteWeight = ${p.weight};`);
|
|
706
|
-
break;
|
|
707
|
-
case "chromatic_aberration":
|
|
708
|
-
this.emit("pipeline.chromaticAberrationEnabled = true;");
|
|
709
|
-
if (p.amount !== void 0)
|
|
710
|
-
this.emit(`pipeline.chromaticAberration.aberrationAmount = ${p.amount};`);
|
|
711
|
-
break;
|
|
712
|
-
case "tone_mapping":
|
|
713
|
-
this.emit("pipeline.imageProcessingEnabled = true;");
|
|
714
|
-
this.emit("pipeline.imageProcessing.toneMappingEnabled = true;");
|
|
715
|
-
break;
|
|
716
|
-
default:
|
|
717
|
-
this.emit(`// Effect "${fx.effectType}": ${JSON.stringify(p)}`);
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
this.emit("");
|
|
721
|
-
}
|
|
722
|
-
// --- Transition ---
|
|
723
|
-
emitTransition(tr) {
|
|
724
|
-
let target, effect, duration;
|
|
725
|
-
for (const p of tr.properties) {
|
|
726
|
-
if (p.key === "target") target = String(p.value);
|
|
727
|
-
else if (p.key === "effect") effect = String(p.value);
|
|
728
|
-
else if (p.key === "duration") duration = p.value;
|
|
729
|
-
}
|
|
730
|
-
this.emit(
|
|
731
|
-
`// Transition "${this.escapeStringValue(tr.name, "TypeScript")}": navigate to "${target || "?"}" with ${effect || "fade"} over ${duration || 1}s`
|
|
732
|
-
);
|
|
733
|
-
}
|
|
734
|
-
// --- XR ---
|
|
735
|
-
emitXRSetup() {
|
|
736
|
-
this.emit("const xr = await this.scene.createDefaultXRExperienceAsync({");
|
|
737
|
-
this.indent();
|
|
738
|
-
this.emit('floorMeshes: this.scene.meshes.filter(m => m.name.includes("ground")),');
|
|
739
|
-
this.dedent();
|
|
740
|
-
this.emit("});");
|
|
741
|
-
this.emit("");
|
|
742
|
-
}
|
|
743
|
-
// --- Render Loop ---
|
|
744
|
-
emitRenderLoop() {
|
|
745
|
-
this.emit("this.engine.runRenderLoop(() => { this.scene.render(); });");
|
|
746
|
-
this.emit('window.addEventListener("resize", () => { this.engine.resize(); });');
|
|
747
|
-
}
|
|
748
|
-
// --- Value Conversion Helpers ---
|
|
749
|
-
toBabylonColor3(value) {
|
|
750
|
-
if (typeof value === "string" && value.startsWith("#")) {
|
|
751
|
-
const h = value.slice(1);
|
|
752
|
-
const r = parseInt(h.substring(0, 2), 16) / 255;
|
|
753
|
-
const g = parseInt(h.substring(2, 4), 16) / 255;
|
|
754
|
-
const b = parseInt(h.substring(4, 6), 16) / 255;
|
|
755
|
-
return `new BABYLON.Color3(${r.toFixed(3)}, ${g.toFixed(3)}, ${b.toFixed(3)})`;
|
|
756
|
-
}
|
|
757
|
-
if (typeof value === "object" && value !== null && "r" in value) {
|
|
758
|
-
const c = value;
|
|
759
|
-
const r = c.r > 1 ? c.r / 255 : c.r;
|
|
760
|
-
const g = c.g > 1 ? c.g / 255 : c.g;
|
|
761
|
-
const b = c.b > 1 ? c.b / 255 : c.b;
|
|
762
|
-
return `new BABYLON.Color3(${r.toFixed(3)}, ${g.toFixed(3)}, ${b.toFixed(3)})`;
|
|
763
|
-
}
|
|
764
|
-
return "BABYLON.Color3.White()";
|
|
765
|
-
}
|
|
766
|
-
toBabylonVector(arr) {
|
|
767
|
-
if (arr.length >= 3) return `new BABYLON.Vector3(${arr[0]}, ${arr[1]}, ${arr[2]})`;
|
|
768
|
-
if (arr.length === 2) return `new BABYLON.Vector2(${arr[0]}, ${arr[1]})`;
|
|
769
|
-
return `new BABYLON.Vector3(${arr[0]}, ${arr[0]}, ${arr[0]})`;
|
|
770
|
-
}
|
|
771
|
-
mapShapeToMesh(type) {
|
|
772
|
-
return SHAPE_TO_MESH[type] || "CreateBox";
|
|
773
|
-
}
|
|
774
|
-
meshBuilderOptions(type, size) {
|
|
775
|
-
const s = typeof size === "number" ? size : 1;
|
|
776
|
-
switch (type) {
|
|
777
|
-
case "sphere":
|
|
778
|
-
case "orb":
|
|
779
|
-
return `{ diameter: ${s}, segments: 32 }`;
|
|
780
|
-
case "cube":
|
|
781
|
-
case "box":
|
|
782
|
-
return `{ size: ${s} }`;
|
|
783
|
-
case "cylinder":
|
|
784
|
-
return `{ diameter: ${s}, height: ${s * 2}, tessellation: 32 }`;
|
|
785
|
-
case "cone":
|
|
786
|
-
case "pyramid":
|
|
787
|
-
return `{ diameterTop: 0, diameterBottom: ${s}, height: ${s * 2}, tessellation: ${type === "pyramid" ? 4 : 32} }`;
|
|
788
|
-
case "plane":
|
|
789
|
-
case "ground":
|
|
790
|
-
return `{ width: ${s}, height: ${s} }`;
|
|
791
|
-
case "torus":
|
|
792
|
-
case "ring":
|
|
793
|
-
return `{ diameter: ${s}, thickness: ${s * 0.3}, tessellation: 32 }`;
|
|
794
|
-
case "capsule":
|
|
795
|
-
return `{ radius: ${s * 0.3}, height: ${s} }`;
|
|
796
|
-
case "disc":
|
|
797
|
-
return `{ radius: ${s * 0.5}, tessellation: 32 }`;
|
|
798
|
-
default:
|
|
799
|
-
return `{ size: ${s} }`;
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
mapAnimProperty(key) {
|
|
803
|
-
const m = {
|
|
804
|
-
position: "position",
|
|
805
|
-
rotation: "rotation",
|
|
806
|
-
scale: "scaling",
|
|
807
|
-
color: "material.albedoColor",
|
|
808
|
-
opacity: "material.alpha",
|
|
809
|
-
emissive: "material.emissiveColor"
|
|
810
|
-
};
|
|
811
|
-
return m[key] || key;
|
|
812
|
-
}
|
|
813
|
-
// --- Emit Helpers ---
|
|
814
|
-
emit(line) {
|
|
815
|
-
this.lines.push(this.options.indent.repeat(this.indentLevel) + line);
|
|
816
|
-
}
|
|
817
|
-
indent() {
|
|
818
|
-
this.indentLevel++;
|
|
819
|
-
}
|
|
820
|
-
dedent() {
|
|
821
|
-
this.indentLevel = Math.max(0, this.indentLevel - 1);
|
|
822
|
-
}
|
|
823
|
-
sanitizeName(name) {
|
|
824
|
-
return name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
825
|
-
}
|
|
826
|
-
};
|
|
827
|
-
}
|
|
828
|
-
});
|
|
829
|
-
|
|
830
|
-
export { BabylonCompiler, BabylonCompiler_exports, init_BabylonCompiler };
|
|
831
|
-
//# sourceMappingURL=chunk-KED34ILP.js.map
|
|
832
|
-
//# sourceMappingURL=chunk-KED34ILP.js.map
|