@holoscript/core 6.0.3 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -40
- package/dist/codebase/index.d.ts +25 -0
- package/dist/compiler/index.d.ts +82 -0
- package/dist/constants.d.ts +4 -0
- package/dist/coordinators/index.d.ts +189 -0
- package/dist/entries/interop.d.ts +9 -0
- package/dist/entries/scripting.d.ts +7 -0
- package/dist/index.d.ts +520 -19
- package/dist/paper-0c-spike/index.d.ts +29 -0
- package/dist/reconstruction/index.d.ts +78 -0
- package/dist/self-improvement/index.d.ts +0 -48
- package/dist/storage/index.d.ts +24 -0
- package/dist/tools/index.d.ts +33 -0
- package/dist/traitDocs/traitDocs.d.ts +69 -0
- package/dist/traits/index.d.ts +61 -0
- package/package.json +102 -19
- package/dist/GLTFPipeline-3KLWWUQO.cjs +0 -34
- package/dist/GLTFPipeline-LYII2ZVQ.js +0 -13
- package/dist/HoloScriptPlusParser-BZR5DELQ.js +0 -692
- package/dist/HoloScriptPlusParser-SBMYDNXO.cjs +0 -697
- package/dist/USDZExporter-MHEHXZB4.cjs +0 -709
- package/dist/USDZExporter-YA55ZS35.js +0 -707
- package/dist/chunk-26TLYBFD.js +0 -309
- package/dist/chunk-27LWW5FU.cjs +0 -410
- package/dist/chunk-2UX5LRAP.cjs +0 -833
- package/dist/chunk-32TWR3HE.js +0 -70
- package/dist/chunk-3FXV5S25.cjs +0 -633
- package/dist/chunk-3FYZOR7S.cjs +0 -69
- package/dist/chunk-3KEU5QYY.cjs +0 -175
- package/dist/chunk-4FCZDTD5.js +0 -610
- package/dist/chunk-4KJ2R7VP.cjs +0 -507
- package/dist/chunk-4SMUJFHL.js +0 -1213
- package/dist/chunk-54FHG2MX.js +0 -655
- package/dist/chunk-56IF4NTA.js +0 -56
- package/dist/chunk-5GLCTO44.js +0 -161
- package/dist/chunk-5TOFIR6L.js +0 -407
- package/dist/chunk-65RFOWZI.js +0 -765
- package/dist/chunk-6OQBLABR.js +0 -5240
- package/dist/chunk-6WNCRE6F.js +0 -126
- package/dist/chunk-74YCHHTE.js +0 -1872
- package/dist/chunk-7H5UNJZD.cjs +0 -1973
- package/dist/chunk-7KPI4EKH.cjs +0 -701
- package/dist/chunk-7LCYLPW2.cjs +0 -663
- package/dist/chunk-7N3JIJMT.js +0 -1395
- package/dist/chunk-7X2IEJIE.cjs +0 -2526
- package/dist/chunk-A6GO3DPZ.cjs +0 -1002
- package/dist/chunk-AC4BSHFV.js +0 -765
- package/dist/chunk-AIUXRS74.cjs +0 -3681
- package/dist/chunk-ARNKA274.cjs +0 -130
- package/dist/chunk-AW7WAELW.js +0 -975
- package/dist/chunk-BKIGPPVM.js +0 -629
- package/dist/chunk-BO2OKHIY.js +0 -6055
- package/dist/chunk-BU5ZAFMC.js +0 -115
- package/dist/chunk-BY3B7ZYV.cjs +0 -457
- package/dist/chunk-C2QHVHZF.js +0 -4066
- package/dist/chunk-C7BNX4XJ.js +0 -1043
- package/dist/chunk-CLYEIWA5.cjs +0 -408
- package/dist/chunk-CMYAWUX3.js +0 -4455
- package/dist/chunk-CN4NOESF.cjs +0 -416
- package/dist/chunk-CNVM7J3M.js +0 -883
- package/dist/chunk-CO2VM2DK.js +0 -1965
- package/dist/chunk-CQDOF3G7.cjs +0 -1404
- package/dist/chunk-DH5G2JUA.cjs +0 -614
- package/dist/chunk-DIEDKX5B.cjs +0 -660
- package/dist/chunk-DN7UFU63.cjs +0 -172
- package/dist/chunk-DXVCEFZB.js +0 -2027
- package/dist/chunk-EGIZHYJP.cjs +0 -85
- package/dist/chunk-EJA7G2C4.cjs +0 -428
- package/dist/chunk-ELLQPFAF.js +0 -830
- package/dist/chunk-EMO7HAKJ.cjs +0 -1875
- package/dist/chunk-ENV7K6XA.js +0 -282
- package/dist/chunk-EPWRXL6S.js +0 -2522
- package/dist/chunk-EUFLX2PI.js +0 -56956
- package/dist/chunk-F5LVGHNT.js +0 -449
- package/dist/chunk-FEFHPUEM.cjs +0 -6122
- package/dist/chunk-FF3Q7ADR.js +0 -380
- package/dist/chunk-GC3YU46J.js +0 -762
- package/dist/chunk-H6WMMLQK.cjs +0 -4492
- package/dist/chunk-H7XMORZI.js +0 -2731
- package/dist/chunk-HAN4V3PF.cjs +0 -2037
- package/dist/chunk-HBZYCASG.js +0 -4208
- package/dist/chunk-HF4OFY25.cjs +0 -4097
- package/dist/chunk-HHS6FMOU.cjs +0 -3813
- package/dist/chunk-HJJLD366.js +0 -1169
- package/dist/chunk-HKCVM6OK.cjs +0 -2237
- package/dist/chunk-HUFNKFA6.js +0 -698
- package/dist/chunk-I3XGTIHM.cjs +0 -1505
- package/dist/chunk-I6XZ5DZF.cjs +0 -488
- package/dist/chunk-IHOUYQIA.js +0 -406
- package/dist/chunk-ILRBGFVD.cjs +0 -72
- package/dist/chunk-KDB6BUMB.js +0 -3666
- package/dist/chunk-KUJRR4FJ.js +0 -657
- package/dist/chunk-KYM4XRFG.js +0 -421
- package/dist/chunk-L3Z2HIWJ.cjs +0 -793
- package/dist/chunk-LBPEZQAF.js +0 -2232
- package/dist/chunk-LER4WXW5.cjs +0 -286
- package/dist/chunk-LK5IAVH6.cjs +0 -1173
- package/dist/chunk-M6FU6S22.js +0 -2911
- package/dist/chunk-MWEFR6YQ.js +0 -1857
- package/dist/chunk-N5FTS757.cjs +0 -415
- package/dist/chunk-NCUHGRTZ.js +0 -752
- package/dist/chunk-NKRKT6V2.js +0 -69
- package/dist/chunk-NLPSZT4C.js +0 -630
- package/dist/chunk-NRUB55IT.cjs +0 -771
- package/dist/chunk-NTMZSDXM.cjs +0 -633
- package/dist/chunk-ODGMVILH.js +0 -9662
- package/dist/chunk-PBA6NXCT.cjs +0 -1216
- package/dist/chunk-PHENW4MQ.js +0 -65
- package/dist/chunk-PJMOXFPR.cjs +0 -1861
- package/dist/chunk-PLMYCCA4.js +0 -504
- package/dist/chunk-PPULB4GG.cjs +0 -9728
- package/dist/chunk-PQLGZKMC.cjs +0 -755
- package/dist/chunk-Q56TT7IL.js +0 -483
- package/dist/chunk-QHVVVN47.cjs +0 -2033
- package/dist/chunk-QWKUKVRE.js +0 -2026
- package/dist/chunk-RE3OKSYF.cjs +0 -424
- package/dist/chunk-RT7LJRSF.cjs +0 -57378
- package/dist/chunk-SPDELRRV.cjs +0 -319
- package/dist/chunk-SUCBB66F.js +0 -229
- package/dist/chunk-TSWTWZ42.cjs +0 -4214
- package/dist/chunk-UITWA6DV.cjs +0 -2829
- package/dist/chunk-UQW6SLM5.js +0 -172
- package/dist/chunk-V2ILLPHK.cjs +0 -237
- package/dist/chunk-V42NTCFH.js +0 -3645
- package/dist/chunk-VJ3L7CHT.cjs +0 -169
- package/dist/chunk-VJVCD5T5.cjs +0 -769
- package/dist/chunk-VK5AXKO3.js +0 -746
- package/dist/chunk-VSXOIUCF.cjs +0 -473
- package/dist/chunk-VZNKJZTT.cjs +0 -749
- package/dist/chunk-W76ETJTI.js +0 -678
- package/dist/chunk-WFJIDI2N.cjs +0 -424
- package/dist/chunk-WN3YF33G.cjs +0 -118
- package/dist/chunk-WUXIRGZP.cjs +0 -2915
- package/dist/chunk-WYH4GVZ5.js +0 -1488
- package/dist/chunk-X4YVN7H3.cjs +0 -888
- package/dist/chunk-X67XRI2T.js +0 -410
- package/dist/chunk-XDXZM3ZP.cjs +0 -1046
- package/dist/chunk-XH7SE4HH.cjs +0 -72
- package/dist/chunk-XNMEH2BI.js +0 -126
- package/dist/chunk-XSF76QRU.js +0 -468
- package/dist/chunk-XSUZMPVQ.cjs +0 -682
- package/dist/chunk-XUILI4KB.cjs +0 -430
- package/dist/chunk-Y5MUAYTO.js +0 -167
- package/dist/chunk-Y7VK5TH3.cjs +0 -129
- package/dist/chunk-YCMQQQ5U.cjs +0 -5244
- package/dist/chunk-YYXH45E2.js +0 -426
- package/dist/chunk-ZGTGVSTZ.js +0 -422
- package/dist/chunk-ZL6VJ6SN.js +0 -421
- package/dist/cli/holoscript-runner.cjs +0 -2258
- package/dist/cli/holoscript-runner.js +0 -2233
- package/dist/codebase/index.cjs +0 -336
- package/dist/codebase/index.js +0 -331
- package/dist/compiler/agent-inference.cjs +0 -29
- package/dist/compiler/agent-inference.js +0 -6
- package/dist/compiler/android-xr.cjs +0 -20
- package/dist/compiler/android-xr.js +0 -10
- package/dist/compiler/android.cjs +0 -21
- package/dist/compiler/android.js +0 -11
- package/dist/compiler/ar.cjs +0 -21
- package/dist/compiler/ar.js +0 -9
- package/dist/compiler/babylon.cjs +0 -18
- package/dist/compiler/babylon.js +0 -12
- package/dist/compiler/coco.cjs +0 -27
- package/dist/compiler/coco.js +0 -4
- package/dist/compiler/domain-block-utils.cjs +0 -595
- package/dist/compiler/domain-block-utils.js +0 -9
- package/dist/compiler/dtdl.cjs +0 -25
- package/dist/compiler/dtdl.js +0 -9
- package/dist/compiler/gltf-pipeline.cjs +0 -39
- package/dist/compiler/gltf-pipeline.js +0 -4
- package/dist/compiler/godot.cjs +0 -16
- package/dist/compiler/godot.js +0 -10
- package/dist/compiler/incremental.cjs +0 -30
- package/dist/compiler/incremental.js +0 -5
- package/dist/compiler/index.cjs +0 -1522
- package/dist/compiler/index.js +0 -1321
- package/dist/compiler/ios.cjs +0 -21
- package/dist/compiler/ios.js +0 -11
- package/dist/compiler/multi-layer.cjs +0 -27
- package/dist/compiler/multi-layer.js +0 -12
- package/dist/compiler/nodetoy.cjs +0 -23
- package/dist/compiler/nodetoy.js +0 -4
- package/dist/compiler/openxr.cjs +0 -16
- package/dist/compiler/openxr.js +0 -10
- package/dist/compiler/playcanvas.cjs +0 -17
- package/dist/compiler/playcanvas.js +0 -11
- package/dist/compiler/r3f.cjs +0 -35
- package/dist/compiler/r3f.js +0 -13
- 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 -22
- package/dist/compiler/sdf.js +0 -10
- package/dist/compiler/semantic-scene.cjs +0 -31
- package/dist/compiler/semantic-scene.js +0 -4
- package/dist/compiler/state.cjs +0 -18
- package/dist/compiler/state.js +0 -8
- package/dist/compiler/trait-composition.cjs +0 -27
- package/dist/compiler/trait-composition.js +0 -6
- package/dist/compiler/unity.cjs +0 -16
- package/dist/compiler/unity.js +0 -10
- package/dist/compiler/unreal.cjs +0 -20
- package/dist/compiler/unreal.js +0 -10
- package/dist/compiler/urdf.cjs +0 -46
- package/dist/compiler/urdf.js +0 -10
- package/dist/compiler/usd-physics.cjs +0 -24
- package/dist/compiler/usd-physics.js +0 -7
- package/dist/compiler/visionos.cjs +0 -16
- package/dist/compiler/visionos.js +0 -10
- package/dist/compiler/vrchat.cjs +0 -20
- package/dist/compiler/vrchat.js +0 -10
- package/dist/compiler/vrr.cjs +0 -22
- package/dist/compiler/vrr.js +0 -10
- package/dist/compiler/wasm.cjs +0 -34
- package/dist/compiler/wasm.js +0 -10
- package/dist/compiler/webgpu.cjs +0 -16
- package/dist/compiler/webgpu.js +0 -10
- 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 -67
- package/dist/entries/scripting.js +0 -10
- package/dist/index.cjs +0 -61703
- package/dist/index.js +0 -58652
- package/dist/math/vec3.cjs +0 -57
- package/dist/math/vec3.js +0 -4
- package/dist/parser.cjs +0 -26
- package/dist/parser.js +0 -9
- package/dist/playwright-7DTEQCBD.cjs +0 -98673
- package/dist/playwright-BIZXMLD2.js +0 -98660
- package/dist/post-quantum-JTTAAGO3.cjs +0 -6
- package/dist/post-quantum-RVPVDEPI.js +0 -4
- 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 -14331
- package/dist/traits/index.js +0 -12126
- package/dist/type-checker.cjs +0 -18
- package/dist/type-checker.js +0 -5
- package/dist/wot/index.cjs +0 -29
- package/dist/wot/index.js +0 -4
package/dist/chunk-XDXZM3ZP.cjs
DELETED
|
@@ -1,1046 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var chunkHHS6FMOU_cjs = require('./chunk-HHS6FMOU.cjs');
|
|
4
|
-
var chunkQHVVVN47_cjs = require('./chunk-QHVVVN47.cjs');
|
|
5
|
-
var chunkEGIZHYJP_cjs = require('./chunk-EGIZHYJP.cjs');
|
|
6
|
-
|
|
7
|
-
// src/compiler/OpenXRCompiler.ts
|
|
8
|
-
var OpenXRCompiler_exports = {};
|
|
9
|
-
chunkEGIZHYJP_cjs.__export(OpenXRCompiler_exports, {
|
|
10
|
-
OpenXRCompiler: () => exports.OpenXRCompiler
|
|
11
|
-
});
|
|
12
|
-
exports.OpenXRCompiler = void 0;
|
|
13
|
-
var init_OpenXRCompiler = chunkEGIZHYJP_cjs.__esm({
|
|
14
|
-
"src/compiler/OpenXRCompiler.ts"() {
|
|
15
|
-
chunkQHVVVN47_cjs.init_CompilerBase();
|
|
16
|
-
chunkQHVVVN47_cjs.init_ANSNamespace();
|
|
17
|
-
chunkHHS6FMOU_cjs.init_DomainBlockCompilerMixin();
|
|
18
|
-
exports.OpenXRCompiler = class extends chunkQHVVVN47_cjs.CompilerBase {
|
|
19
|
-
constructor(options = {}) {
|
|
20
|
-
super();
|
|
21
|
-
this.compilerName = "OpenXRCompiler";
|
|
22
|
-
this.lines = [];
|
|
23
|
-
this.indentLevel = 0;
|
|
24
|
-
this.options = {
|
|
25
|
-
appName: options.appName || "HoloScriptApp",
|
|
26
|
-
renderBackend: options.renderBackend || "vulkan",
|
|
27
|
-
enableHandTracking: options.enableHandTracking ?? true,
|
|
28
|
-
enablePassthrough: options.enablePassthrough ?? false,
|
|
29
|
-
indent: options.indent || " "
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
getRequiredCapability() {
|
|
33
|
-
return chunkQHVVVN47_cjs.ANSCapabilityPath.OPENXR;
|
|
34
|
-
}
|
|
35
|
-
compile(composition, agentToken, outputPath) {
|
|
36
|
-
this.validateCompilerAccess(agentToken, outputPath);
|
|
37
|
-
this.lines = [];
|
|
38
|
-
this.indentLevel = 0;
|
|
39
|
-
this.emit("// Auto-generated by HoloScript OpenXRCompiler");
|
|
40
|
-
this.emit(
|
|
41
|
-
`// Source: composition "${this.escapeStringValue(composition.name, "TypeScript")}"`
|
|
42
|
-
);
|
|
43
|
-
this.emit("// Do not edit manually -- regenerate from .holo source");
|
|
44
|
-
this.emit("");
|
|
45
|
-
this.emitIncludes();
|
|
46
|
-
this.emit("");
|
|
47
|
-
this.emit(`namespace ${this.sanitizeName(composition.name)} {`);
|
|
48
|
-
this.emit("");
|
|
49
|
-
this.indent();
|
|
50
|
-
this.emit("struct LightUBO {");
|
|
51
|
-
this.indent();
|
|
52
|
-
this.emit("glm::vec4 position;");
|
|
53
|
-
this.emit("glm::vec4 color;");
|
|
54
|
-
this.emit("float intensity;");
|
|
55
|
-
this.emit("float range;");
|
|
56
|
-
this.emit("float padding[2];");
|
|
57
|
-
this.dedent();
|
|
58
|
-
this.emit("};");
|
|
59
|
-
this.emit("");
|
|
60
|
-
this.emit("XrInstance instance = XR_NULL_HANDLE;");
|
|
61
|
-
this.emit("XrSession session = XR_NULL_HANDLE;");
|
|
62
|
-
this.emit("XrSpace appSpace = XR_NULL_HANDLE;");
|
|
63
|
-
this.emit("XrSwapchain swapchain = XR_NULL_HANDLE;");
|
|
64
|
-
this.emit("XrActionSet actionSet = XR_NULL_HANDLE;");
|
|
65
|
-
this.emit("XrAction grabAction = XR_NULL_HANDLE;");
|
|
66
|
-
this.emit("XrAction triggerAction = XR_NULL_HANDLE;");
|
|
67
|
-
this.emit("XrAction aimPoseAction = XR_NULL_HANDLE;");
|
|
68
|
-
this.emit("XrAction hapticAction = XR_NULL_HANDLE;");
|
|
69
|
-
if (this.options.enableHandTracking) {
|
|
70
|
-
this.emit("XrHandTrackerEXT handTrackerLeft = XR_NULL_HANDLE;");
|
|
71
|
-
this.emit("XrHandTrackerEXT handTrackerRight = XR_NULL_HANDLE;");
|
|
72
|
-
}
|
|
73
|
-
this.emit("bool sessionRunning = false;");
|
|
74
|
-
this.emit("");
|
|
75
|
-
this.emitInstanceInit(composition);
|
|
76
|
-
this.emit("");
|
|
77
|
-
this.emitSessionInit();
|
|
78
|
-
this.emit("");
|
|
79
|
-
this.emitActionSets();
|
|
80
|
-
this.emit("");
|
|
81
|
-
if (this.options.enableHandTracking) {
|
|
82
|
-
this.emitHandTracking();
|
|
83
|
-
this.emit("");
|
|
84
|
-
}
|
|
85
|
-
this.emitRenderPass();
|
|
86
|
-
this.emit("");
|
|
87
|
-
this.emit("void setupScene() {");
|
|
88
|
-
this.indent();
|
|
89
|
-
if (composition.environment) {
|
|
90
|
-
this.emitEnvironment(composition.environment);
|
|
91
|
-
}
|
|
92
|
-
for (const light of composition.lights ?? []) {
|
|
93
|
-
this.emitLight(light);
|
|
94
|
-
}
|
|
95
|
-
for (const obj of composition.objects ?? []) {
|
|
96
|
-
this.emitObject(obj);
|
|
97
|
-
}
|
|
98
|
-
for (const group of composition.spatialGroups ?? []) {
|
|
99
|
-
this.emitGroup(group);
|
|
100
|
-
}
|
|
101
|
-
if (composition.camera) {
|
|
102
|
-
this.emitCamera(composition.camera);
|
|
103
|
-
}
|
|
104
|
-
this.dedent();
|
|
105
|
-
this.emit("}");
|
|
106
|
-
this.emit("");
|
|
107
|
-
this.emitRenderLoop(composition);
|
|
108
|
-
this.emit("");
|
|
109
|
-
this.emit("int main() {");
|
|
110
|
-
this.indent();
|
|
111
|
-
this.emit("initInstance();");
|
|
112
|
-
this.emit("initSession();");
|
|
113
|
-
this.emit("initActionSets();");
|
|
114
|
-
if (this.options.enableHandTracking) {
|
|
115
|
-
this.emit("initHandTracking();");
|
|
116
|
-
}
|
|
117
|
-
this.emit("setupScene();");
|
|
118
|
-
this.emit("renderLoop();");
|
|
119
|
-
this.emit("");
|
|
120
|
-
this.emit("// Cleanup");
|
|
121
|
-
if (this.options.enableHandTracking) {
|
|
122
|
-
this.emit("xrDestroyHandTrackerEXT(handTrackerLeft);");
|
|
123
|
-
this.emit("xrDestroyHandTrackerEXT(handTrackerRight);");
|
|
124
|
-
}
|
|
125
|
-
this.emit("xrDestroySwapchain(swapchain);");
|
|
126
|
-
this.emit("xrDestroySpace(appSpace);");
|
|
127
|
-
this.emit("xrDestroySession(session);");
|
|
128
|
-
this.emit("xrDestroyInstance(instance);");
|
|
129
|
-
this.emit("return 0;");
|
|
130
|
-
this.dedent();
|
|
131
|
-
this.emit("}");
|
|
132
|
-
const domainBlocks = composition.domainBlocks ?? [];
|
|
133
|
-
if (domainBlocks.length > 0) {
|
|
134
|
-
this.emit("");
|
|
135
|
-
this.emit("// === v4.2 Domain Blocks ===");
|
|
136
|
-
const compiled = chunkHHS6FMOU_cjs.compileDomainBlocks(
|
|
137
|
-
// @ts-expect-error During migration
|
|
138
|
-
domainBlocks,
|
|
139
|
-
{
|
|
140
|
-
material: (block) => {
|
|
141
|
-
const m = chunkHHS6FMOU_cjs.compileMaterialBlock(block);
|
|
142
|
-
return `// Material: "${this.escapeStringValue(m.name, "TypeScript")}" type=${m.type} baseColor=${m.baseColor || "none"} roughness=${m.roughness ?? "default"} metallic=${m.metallic ?? "default"}`;
|
|
143
|
-
},
|
|
144
|
-
physics: (block) => {
|
|
145
|
-
const p = chunkHHS6FMOU_cjs.compilePhysicsBlock(block);
|
|
146
|
-
return `// Physics: ${p.keyword} "${p.name || ""}" colliders=${p.colliders?.length || 0} rigidbody=${!!p.rigidbody}`;
|
|
147
|
-
},
|
|
148
|
-
vfx: (block) => {
|
|
149
|
-
const ps = chunkHHS6FMOU_cjs.compileParticleBlock(block);
|
|
150
|
-
return `// Particles: "${this.escapeStringValue(ps.name, "TypeScript")}" rate=${ps.properties.rate || "default"} modules=${ps.modules.length}`;
|
|
151
|
-
},
|
|
152
|
-
postfx: (block) => {
|
|
153
|
-
const pp = chunkHHS6FMOU_cjs.compilePostProcessingBlock(block);
|
|
154
|
-
return `// PostFX: ${pp.keyword} effects=[${pp.effects.map((e) => e.type).join(", ")}]`;
|
|
155
|
-
},
|
|
156
|
-
audio: (block) => {
|
|
157
|
-
const a = chunkHHS6FMOU_cjs.compileAudioSourceBlock(block);
|
|
158
|
-
return `// Audio: "${this.escapeStringValue(a.name, "TypeScript")}" (${a.keyword}) clip=${a.properties.clip || "none"}`;
|
|
159
|
-
},
|
|
160
|
-
weather: (block) => {
|
|
161
|
-
const w = chunkHHS6FMOU_cjs.compileWeatherBlock(block);
|
|
162
|
-
return `// Weather: ${w.keyword} layers=[${w.layers.map((l) => l.type).join(", ")}]`;
|
|
163
|
-
}
|
|
164
|
-
},
|
|
165
|
-
(block) => `// Domain block: ${block.domain}/${block.keyword} "${this.escapeStringValue(block.name, "TypeScript")}"`
|
|
166
|
-
);
|
|
167
|
-
for (const line of compiled) {
|
|
168
|
-
for (const l of line.split("\n")) this.emit(l);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
this.dedent();
|
|
172
|
-
this.emit("");
|
|
173
|
-
this.emit(`} // namespace ${this.sanitizeName(composition.name)}`);
|
|
174
|
-
return this.lines.join("\n");
|
|
175
|
-
}
|
|
176
|
-
// ---------------------------------------------------------------------------
|
|
177
|
-
// Includes
|
|
178
|
-
// ---------------------------------------------------------------------------
|
|
179
|
-
emitIncludes() {
|
|
180
|
-
this.emit("#include <openxr/openxr.h>");
|
|
181
|
-
this.emit("#include <openxr/openxr_platform.h>");
|
|
182
|
-
if (this.options.enableHandTracking) {
|
|
183
|
-
this.emit("#include <openxr/openxr_extension.h>");
|
|
184
|
-
}
|
|
185
|
-
this.emit("");
|
|
186
|
-
if (this.options.renderBackend === "vulkan") {
|
|
187
|
-
this.emit("#include <vulkan/vulkan.h>");
|
|
188
|
-
} else {
|
|
189
|
-
this.emit("#include <GLES3/gl3.h>");
|
|
190
|
-
this.emit("#include <EGL/egl.h>");
|
|
191
|
-
}
|
|
192
|
-
this.emit("");
|
|
193
|
-
this.emit("#include <glm/glm.hpp>");
|
|
194
|
-
this.emit("#include <glm/gtc/matrix_transform.hpp>");
|
|
195
|
-
this.emit("#include <glm/gtc/type_ptr.hpp>");
|
|
196
|
-
this.emit("");
|
|
197
|
-
this.emit("#include <vector>");
|
|
198
|
-
this.emit("#include <array>");
|
|
199
|
-
this.emit("#include <string>");
|
|
200
|
-
this.emit("#include <cstring>");
|
|
201
|
-
this.emit("#include <cmath>");
|
|
202
|
-
this.emit("#include <iostream>");
|
|
203
|
-
}
|
|
204
|
-
// ---------------------------------------------------------------------------
|
|
205
|
-
// Instance initialization
|
|
206
|
-
// ---------------------------------------------------------------------------
|
|
207
|
-
emitInstanceInit(composition) {
|
|
208
|
-
this.emit("void initInstance() {");
|
|
209
|
-
this.indent();
|
|
210
|
-
this.emit("std::vector<const char*> extensions = {");
|
|
211
|
-
this.indent();
|
|
212
|
-
if (this.options.renderBackend === "vulkan") {
|
|
213
|
-
this.emit("XR_KHR_VULKAN_ENABLE2_EXTENSION_NAME,");
|
|
214
|
-
} else {
|
|
215
|
-
this.emit("XR_KHR_OPENGL_ES_ENABLE_EXTENSION_NAME,");
|
|
216
|
-
}
|
|
217
|
-
if (this.options.enableHandTracking) {
|
|
218
|
-
this.emit("XR_EXT_HAND_TRACKING_EXTENSION_NAME,");
|
|
219
|
-
}
|
|
220
|
-
if (this.options.enablePassthrough) {
|
|
221
|
-
this.emit("XR_FB_PASSTHROUGH_EXTENSION_NAME,");
|
|
222
|
-
}
|
|
223
|
-
const needsAnchor = this.compositionUsesAnchor(composition);
|
|
224
|
-
if (needsAnchor) {
|
|
225
|
-
this.emit("XR_MSFT_SPATIAL_ANCHOR_EXTENSION_NAME,");
|
|
226
|
-
}
|
|
227
|
-
this.dedent();
|
|
228
|
-
this.emit("};");
|
|
229
|
-
this.emit("");
|
|
230
|
-
this.emit("XrInstanceCreateInfo createInfo{XR_TYPE_INSTANCE_CREATE_INFO};");
|
|
231
|
-
this.emit(
|
|
232
|
-
`std::strncpy(createInfo.applicationInfo.applicationName, "${this.options.appName}", XR_MAX_APPLICATION_NAME_SIZE);`
|
|
233
|
-
);
|
|
234
|
-
this.emit("createInfo.applicationInfo.apiVersion = XR_CURRENT_API_VERSION;");
|
|
235
|
-
this.emit("createInfo.enabledExtensionCount = static_cast<uint32_t>(extensions.size());");
|
|
236
|
-
this.emit("createInfo.enabledExtensionNames = extensions.data();");
|
|
237
|
-
this.emit("");
|
|
238
|
-
this.emit("XrResult result = xrCreateInstance(&createInfo, &instance);");
|
|
239
|
-
this.emit("if (XR_FAILED(result)) {");
|
|
240
|
-
this.indent();
|
|
241
|
-
this.emit('std::cerr << "Failed to create XR instance" << std::endl;');
|
|
242
|
-
this.emit("return;");
|
|
243
|
-
this.dedent();
|
|
244
|
-
this.emit("}");
|
|
245
|
-
this.dedent();
|
|
246
|
-
this.emit("}");
|
|
247
|
-
}
|
|
248
|
-
// ---------------------------------------------------------------------------
|
|
249
|
-
// Session initialization
|
|
250
|
-
// ---------------------------------------------------------------------------
|
|
251
|
-
emitSessionInit() {
|
|
252
|
-
this.emit("void initSession() {");
|
|
253
|
-
this.indent();
|
|
254
|
-
this.emit("// Get system");
|
|
255
|
-
this.emit("XrSystemId systemId = XR_NULL_SYSTEM_ID;");
|
|
256
|
-
this.emit("XrSystemGetInfo systemInfo{XR_TYPE_SYSTEM_GET_INFO};");
|
|
257
|
-
this.emit("systemInfo.formFactor = XR_FORM_FACTOR_HEAD_MOUNTED_DISPLAY;");
|
|
258
|
-
this.emit("xrGetSystem(instance, &systemInfo, &systemId);");
|
|
259
|
-
this.emit("");
|
|
260
|
-
if (this.options.renderBackend === "vulkan") {
|
|
261
|
-
this.emit("// Vulkan graphics binding");
|
|
262
|
-
this.emit("XrGraphicsBindingVulkanKHR graphicsBinding{XR_TYPE_GRAPHICS_BINDING_VULKAN_KHR};");
|
|
263
|
-
this.emit("graphicsBinding.instance = vkInstance;");
|
|
264
|
-
this.emit("graphicsBinding.physicalDevice = vkPhysicalDevice;");
|
|
265
|
-
this.emit("graphicsBinding.device = vkDevice;");
|
|
266
|
-
this.emit("graphicsBinding.queueFamilyIndex = graphicsQueueFamilyIndex;");
|
|
267
|
-
this.emit("graphicsBinding.queueIndex = 0;");
|
|
268
|
-
} else {
|
|
269
|
-
this.emit("// OpenGL ES graphics binding");
|
|
270
|
-
this.emit(
|
|
271
|
-
"XrGraphicsBindingOpenGLESAndroidKHR graphicsBinding{XR_TYPE_GRAPHICS_BINDING_OPENGL_ES_ANDROID_KHR};"
|
|
272
|
-
);
|
|
273
|
-
this.emit("graphicsBinding.display = eglDisplay;");
|
|
274
|
-
this.emit("graphicsBinding.config = eglConfig;");
|
|
275
|
-
this.emit("graphicsBinding.context = eglContext;");
|
|
276
|
-
}
|
|
277
|
-
this.emit("");
|
|
278
|
-
this.emit("// Create session");
|
|
279
|
-
this.emit("XrSessionCreateInfo sessionCreateInfo{XR_TYPE_SESSION_CREATE_INFO};");
|
|
280
|
-
this.emit("sessionCreateInfo.systemId = systemId;");
|
|
281
|
-
this.emit("sessionCreateInfo.next = &graphicsBinding;");
|
|
282
|
-
this.emit("xrCreateSession(instance, &sessionCreateInfo, &session);");
|
|
283
|
-
this.emit("");
|
|
284
|
-
this.emit("// Reference space (STAGE for room-scale)");
|
|
285
|
-
this.emit("XrReferenceSpaceCreateInfo refSpaceInfo{XR_TYPE_REFERENCE_SPACE_CREATE_INFO};");
|
|
286
|
-
this.emit("refSpaceInfo.referenceSpaceType = XR_REFERENCE_SPACE_TYPE_STAGE;");
|
|
287
|
-
this.emit("refSpaceInfo.poseInReferenceSpace.orientation = {0.0f, 0.0f, 0.0f, 1.0f};");
|
|
288
|
-
this.emit("refSpaceInfo.poseInReferenceSpace.position = {0.0f, 0.0f, 0.0f};");
|
|
289
|
-
this.emit("xrCreateReferenceSpace(session, &refSpaceInfo, &appSpace);");
|
|
290
|
-
this.emit("");
|
|
291
|
-
this.emit("// Swapchain");
|
|
292
|
-
this.emit("XrSwapchainCreateInfo swapchainInfo{XR_TYPE_SWAPCHAIN_CREATE_INFO};");
|
|
293
|
-
this.emit("swapchainInfo.usageFlags = XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT;");
|
|
294
|
-
if (this.options.renderBackend === "vulkan") {
|
|
295
|
-
this.emit("swapchainInfo.format = VK_FORMAT_R8G8B8A8_SRGB;");
|
|
296
|
-
} else {
|
|
297
|
-
this.emit("swapchainInfo.format = GL_SRGB8_ALPHA8;");
|
|
298
|
-
}
|
|
299
|
-
this.emit("swapchainInfo.sampleCount = 1;");
|
|
300
|
-
this.emit("swapchainInfo.width = 1920;");
|
|
301
|
-
this.emit("swapchainInfo.height = 1920;");
|
|
302
|
-
this.emit("swapchainInfo.faceCount = 1;");
|
|
303
|
-
this.emit("swapchainInfo.arraySize = 2; // stereo");
|
|
304
|
-
this.emit("swapchainInfo.mipCount = 1;");
|
|
305
|
-
this.emit("xrCreateSwapchain(session, &swapchainInfo, &swapchain);");
|
|
306
|
-
this.emit("");
|
|
307
|
-
this.emit("sessionRunning = true;");
|
|
308
|
-
this.dedent();
|
|
309
|
-
this.emit("}");
|
|
310
|
-
}
|
|
311
|
-
// ---------------------------------------------------------------------------
|
|
312
|
-
// Action sets (input)
|
|
313
|
-
// ---------------------------------------------------------------------------
|
|
314
|
-
emitActionSets() {
|
|
315
|
-
this.emit("void initActionSets() {");
|
|
316
|
-
this.indent();
|
|
317
|
-
this.emit("XrActionSetCreateInfo actionSetInfo{XR_TYPE_ACTION_SET_CREATE_INFO};");
|
|
318
|
-
this.emit(
|
|
319
|
-
'std::strncpy(actionSetInfo.actionSetName, "gameplay", XR_MAX_ACTION_SET_NAME_SIZE);'
|
|
320
|
-
);
|
|
321
|
-
this.emit(
|
|
322
|
-
'std::strncpy(actionSetInfo.localizedActionSetName, "Gameplay", XR_MAX_LOCALIZED_ACTION_SET_NAME_SIZE);'
|
|
323
|
-
);
|
|
324
|
-
this.emit("xrCreateActionSet(instance, &actionSetInfo, &actionSet);");
|
|
325
|
-
this.emit("");
|
|
326
|
-
const actions = [
|
|
327
|
-
{ name: "grabAction", id: "grab", localized: "Grab", type: "XR_ACTION_TYPE_FLOAT_INPUT" },
|
|
328
|
-
{
|
|
329
|
-
name: "triggerAction",
|
|
330
|
-
id: "trigger",
|
|
331
|
-
localized: "Trigger",
|
|
332
|
-
type: "XR_ACTION_TYPE_FLOAT_INPUT"
|
|
333
|
-
},
|
|
334
|
-
{
|
|
335
|
-
name: "aimPoseAction",
|
|
336
|
-
id: "aim_pose",
|
|
337
|
-
localized: "Aim Pose",
|
|
338
|
-
type: "XR_ACTION_TYPE_POSE_INPUT"
|
|
339
|
-
},
|
|
340
|
-
{
|
|
341
|
-
name: "hapticAction",
|
|
342
|
-
id: "haptic",
|
|
343
|
-
localized: "Haptic",
|
|
344
|
-
type: "XR_ACTION_TYPE_VIBRATION_OUTPUT"
|
|
345
|
-
}
|
|
346
|
-
];
|
|
347
|
-
for (const action of actions) {
|
|
348
|
-
this.emit("{");
|
|
349
|
-
this.indent();
|
|
350
|
-
this.emit("XrActionCreateInfo info{XR_TYPE_ACTION_CREATE_INFO};");
|
|
351
|
-
this.emit(`info.actionType = ${action.type};`);
|
|
352
|
-
this.emit(
|
|
353
|
-
`std::strncpy(info.actionName, "${this.escapeStringValue(action.id, "TypeScript")}", XR_MAX_ACTION_NAME_SIZE);`
|
|
354
|
-
);
|
|
355
|
-
this.emit(
|
|
356
|
-
`std::strncpy(info.localizedActionName, "${action.localized}", XR_MAX_LOCALIZED_ACTION_NAME_SIZE);`
|
|
357
|
-
);
|
|
358
|
-
this.emit("info.countSubactionPaths = 0;");
|
|
359
|
-
this.emit(
|
|
360
|
-
`xrCreateAction(actionSet, &info, &${this.escapeStringValue(action.name, "TypeScript")});`
|
|
361
|
-
);
|
|
362
|
-
this.dedent();
|
|
363
|
-
this.emit("}");
|
|
364
|
-
}
|
|
365
|
-
this.emit("");
|
|
366
|
-
this.emit("// Attach action set to session");
|
|
367
|
-
this.emit("XrSessionActionSetsAttachInfo attachInfo{XR_TYPE_SESSION_ACTION_SETS_ATTACH_INFO};");
|
|
368
|
-
this.emit("attachInfo.countActionSets = 1;");
|
|
369
|
-
this.emit("attachInfo.actionSets = &actionSet;");
|
|
370
|
-
this.emit("xrAttachSessionActionSets(session, &attachInfo);");
|
|
371
|
-
this.dedent();
|
|
372
|
-
this.emit("}");
|
|
373
|
-
}
|
|
374
|
-
// ---------------------------------------------------------------------------
|
|
375
|
-
// Environment (clear color, fog)
|
|
376
|
-
// ---------------------------------------------------------------------------
|
|
377
|
-
emitEnvironment(env) {
|
|
378
|
-
this.emit("// === Environment ===");
|
|
379
|
-
for (const prop of env.properties) {
|
|
380
|
-
if (prop.key === "preset" || prop.key === "skybox") {
|
|
381
|
-
this.emit(`// Environment preset: "${prop.value}"`);
|
|
382
|
-
} else if (prop.key === "background" || prop.key === "clear_color") {
|
|
383
|
-
const color = this.toCppColor(prop.value);
|
|
384
|
-
this.emit(`glm::vec4 clearColor = ${color};`);
|
|
385
|
-
} else if (prop.key === "fog" && typeof prop.value === "object") {
|
|
386
|
-
const fog = prop.value;
|
|
387
|
-
const fogColor = fog.color ? this.toCppColor(fog.color) : "glm::vec4(0.5f, 0.5f, 0.5f, 1.0f)";
|
|
388
|
-
this.emit(`glm::vec4 fogColor = ${fogColor};`);
|
|
389
|
-
this.emit(`float fogNear = ${fog.near ?? 10}f;`);
|
|
390
|
-
this.emit(`float fogFar = ${fog.far ?? 100}f;`);
|
|
391
|
-
} else if (prop.key === "ambient_light") {
|
|
392
|
-
const intensity = typeof prop.value === "number" ? prop.value : 0.5;
|
|
393
|
-
this.emit(`float ambientIntensity = ${intensity}f;`);
|
|
394
|
-
} else if (prop.key === "gravity" && Array.isArray(prop.value)) {
|
|
395
|
-
this.emit(`glm::vec3 gravity = ${this.toCppVec3(prop.value)};`);
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
this.emit("");
|
|
399
|
-
}
|
|
400
|
-
// ---------------------------------------------------------------------------
|
|
401
|
-
// Object emission
|
|
402
|
-
// ---------------------------------------------------------------------------
|
|
403
|
-
emitObject(obj) {
|
|
404
|
-
const varName = this.sanitizeName(obj.name);
|
|
405
|
-
this.emit(`// Object: ${this.escapeStringValue(obj.name, "TypeScript")}`);
|
|
406
|
-
this.emit("{");
|
|
407
|
-
this.indent();
|
|
408
|
-
const meshType = this.findObjProp(obj, "mesh") || this.findObjProp(obj, "type") || "cube";
|
|
409
|
-
const pos = this.findObjProp(obj, "position");
|
|
410
|
-
const scale = this.findObjProp(obj, "scale");
|
|
411
|
-
const color = this.findObjProp(obj, "color");
|
|
412
|
-
const material = this.findObjProp(obj, "material");
|
|
413
|
-
this.emit(`auto ${varName}_vertices = ${this.mapShapeToVertexData(meshType)};`);
|
|
414
|
-
this.emit("");
|
|
415
|
-
this.emit(`glm::mat4 ${varName}_model = glm::mat4(1.0f);`);
|
|
416
|
-
if (pos && Array.isArray(pos)) {
|
|
417
|
-
this.emit(`${varName}_model = glm::translate(${varName}_model, ${this.toCppVec3(pos)});`);
|
|
418
|
-
}
|
|
419
|
-
if (scale) {
|
|
420
|
-
if (Array.isArray(scale)) {
|
|
421
|
-
this.emit(`${varName}_model = glm::scale(${varName}_model, ${this.toCppVec3(scale)});`);
|
|
422
|
-
} else {
|
|
423
|
-
this.emit(`${varName}_model = glm::scale(${varName}_model, glm::vec3(${scale}f));`);
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
this.emit("");
|
|
427
|
-
if (material && typeof material === "object") {
|
|
428
|
-
const mat = material;
|
|
429
|
-
const baseColor = mat.color ? this.toCppColor(mat.color) : "glm::vec4(1.0f)";
|
|
430
|
-
this.emit(`glm::vec4 ${varName}_color = ${baseColor};`);
|
|
431
|
-
this.emit(`float ${varName}_roughness = ${mat.roughness ?? 0.5}f;`);
|
|
432
|
-
this.emit(`float ${varName}_metallic = ${mat.metalness ?? mat.metallic ?? 0}f;`);
|
|
433
|
-
} else if (color) {
|
|
434
|
-
this.emit(`glm::vec4 ${varName}_color = ${this.toCppColor(color)};`);
|
|
435
|
-
} else {
|
|
436
|
-
this.emit(`glm::vec4 ${varName}_color = glm::vec4(1.0f);`);
|
|
437
|
-
}
|
|
438
|
-
this.emit("");
|
|
439
|
-
if (this.options.renderBackend === "vulkan") {
|
|
440
|
-
this.emit(
|
|
441
|
-
`// Create Vulkan vertex buffer for ${this.escapeStringValue(obj.name, "TypeScript")}`
|
|
442
|
-
);
|
|
443
|
-
this.emit(`VkBuffer ${varName}_vbo = VK_NULL_HANDLE;`);
|
|
444
|
-
this.emit(`VkDeviceMemory ${varName}_vboMemory = VK_NULL_HANDLE;`);
|
|
445
|
-
this.emit("{");
|
|
446
|
-
this.indent();
|
|
447
|
-
this.emit("VkBufferCreateInfo bufferInfo{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO};");
|
|
448
|
-
this.emit(`bufferInfo.size = ${varName}_vertices.size() * sizeof(float);`);
|
|
449
|
-
this.emit("bufferInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;");
|
|
450
|
-
this.emit("bufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;");
|
|
451
|
-
this.emit(`vkCreateBuffer(vkDevice, &bufferInfo, nullptr, &${varName}_vbo);`);
|
|
452
|
-
this.emit("");
|
|
453
|
-
this.emit("VkMemoryRequirements memReqs;");
|
|
454
|
-
this.emit(`vkGetBufferMemoryRequirements(vkDevice, ${varName}_vbo, &memReqs);`);
|
|
455
|
-
this.emit("");
|
|
456
|
-
this.emit("VkMemoryAllocateInfo allocInfo{VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO};");
|
|
457
|
-
this.emit("allocInfo.allocationSize = memReqs.size;");
|
|
458
|
-
this.emit(
|
|
459
|
-
"allocInfo.memoryTypeIndex = findMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);"
|
|
460
|
-
);
|
|
461
|
-
this.emit(`vkAllocateMemory(vkDevice, &allocInfo, nullptr, &${varName}_vboMemory);`);
|
|
462
|
-
this.emit(`vkBindBufferMemory(vkDevice, ${varName}_vbo, ${varName}_vboMemory, 0);`);
|
|
463
|
-
this.emit("");
|
|
464
|
-
this.emit("// Upload vertex data");
|
|
465
|
-
this.emit("void* mapped = nullptr;");
|
|
466
|
-
this.emit(`vkMapMemory(vkDevice, ${varName}_vboMemory, 0, bufferInfo.size, 0, &mapped);`);
|
|
467
|
-
this.emit(`std::memcpy(mapped, ${varName}_vertices.data(), bufferInfo.size);`);
|
|
468
|
-
this.emit(`vkUnmapMemory(vkDevice, ${varName}_vboMemory);`);
|
|
469
|
-
this.dedent();
|
|
470
|
-
this.emit("}");
|
|
471
|
-
this.emit("");
|
|
472
|
-
this.emit(
|
|
473
|
-
`// Allocate descriptor set for ${this.escapeStringValue(obj.name, "TypeScript")}`
|
|
474
|
-
);
|
|
475
|
-
this.emit(`VkDescriptorSet ${varName}_desc = VK_NULL_HANDLE;`);
|
|
476
|
-
this.emit("{");
|
|
477
|
-
this.indent();
|
|
478
|
-
this.emit(
|
|
479
|
-
"VkDescriptorSetAllocateInfo descAllocInfo{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO};"
|
|
480
|
-
);
|
|
481
|
-
this.emit("descAllocInfo.descriptorPool = descriptorPool;");
|
|
482
|
-
this.emit("descAllocInfo.descriptorSetCount = 1;");
|
|
483
|
-
this.emit("descAllocInfo.pSetLayouts = &descriptorSetLayout;");
|
|
484
|
-
this.emit(`vkAllocateDescriptorSets(vkDevice, &descAllocInfo, &${varName}_desc);`);
|
|
485
|
-
this.dedent();
|
|
486
|
-
this.emit("}");
|
|
487
|
-
} else {
|
|
488
|
-
this.emit(`GLuint ${varName}_vao, ${varName}_vbo;`);
|
|
489
|
-
this.emit(`glGenVertexArrays(1, &${varName}_vao);`);
|
|
490
|
-
this.emit(`glGenBuffers(1, &${varName}_vbo);`);
|
|
491
|
-
this.emit(`glBindVertexArray(${varName}_vao);`);
|
|
492
|
-
this.emit(`glBindBuffer(GL_ARRAY_BUFFER, ${varName}_vbo);`);
|
|
493
|
-
this.emit(
|
|
494
|
-
`glBufferData(GL_ARRAY_BUFFER, ${varName}_vertices.size() * sizeof(float), ${varName}_vertices.data(), GL_STATIC_DRAW);`
|
|
495
|
-
);
|
|
496
|
-
this.emit("glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)0);");
|
|
497
|
-
this.emit("glEnableVertexAttribArray(0);");
|
|
498
|
-
this.emit(
|
|
499
|
-
"glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)(3 * sizeof(float)));"
|
|
500
|
-
);
|
|
501
|
-
this.emit("glEnableVertexAttribArray(1);");
|
|
502
|
-
}
|
|
503
|
-
if (obj.traits) {
|
|
504
|
-
for (const trait of obj.traits) {
|
|
505
|
-
if (trait.name === "hand_tracking") {
|
|
506
|
-
this.emit("");
|
|
507
|
-
this.emit(`// Trait: hand_tracking -- joint data driven via XR_EXT_hand_tracking`);
|
|
508
|
-
this.emit(`// ${varName} position will be updated from hand joint locations each frame`);
|
|
509
|
-
} else if (trait.name === "anchor") {
|
|
510
|
-
this.emit("");
|
|
511
|
-
this.emit(`// Trait: anchor -- XR_MSFT_spatial_anchor`);
|
|
512
|
-
this.emit(`XrSpatialAnchorMSFT ${varName}_anchor = XR_NULL_HANDLE;`);
|
|
513
|
-
this.emit(
|
|
514
|
-
"XrSpatialAnchorCreateInfoMSFT anchorInfo{XR_TYPE_SPATIAL_ANCHOR_CREATE_INFO_MSFT};"
|
|
515
|
-
);
|
|
516
|
-
this.emit("anchorInfo.space = appSpace;");
|
|
517
|
-
this.emit("anchorInfo.time = predictedDisplayTime;");
|
|
518
|
-
if (pos && Array.isArray(pos)) {
|
|
519
|
-
this.emit(
|
|
520
|
-
`anchorInfo.pose.position = {${pos[0] ?? 0}f, ${pos[1] ?? 0}f, ${pos[2] ?? 0}f};`
|
|
521
|
-
);
|
|
522
|
-
} else {
|
|
523
|
-
this.emit("anchorInfo.pose.position = {0.0f, 0.0f, 0.0f};");
|
|
524
|
-
}
|
|
525
|
-
this.emit("anchorInfo.pose.orientation = {0.0f, 0.0f, 0.0f, 1.0f};");
|
|
526
|
-
this.emit(`xrCreateSpatialAnchorMSFT(session, &anchorInfo, &${varName}_anchor);`);
|
|
527
|
-
} else if (trait.name === "grabbable") {
|
|
528
|
-
this.emit("");
|
|
529
|
-
this.emit(
|
|
530
|
-
`// Trait: grabbable -- detect grip action on ${this.escapeStringValue(obj.name, "TypeScript")}`
|
|
531
|
-
);
|
|
532
|
-
this.emit(`bool ${varName}_grabbed = false;`);
|
|
533
|
-
} else if (trait.name === "physics") {
|
|
534
|
-
this.emit("");
|
|
535
|
-
this.emit(`// Trait: physics -- simulated via CPU/GPU physics step`);
|
|
536
|
-
this.emit(`glm::vec3 ${varName}_velocity(0.0f);`);
|
|
537
|
-
this.emit(`float ${varName}_mass = ${trait.config?.mass ?? 1}f;`);
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
this.dedent();
|
|
542
|
-
this.emit("}");
|
|
543
|
-
this.emit("");
|
|
544
|
-
if (obj.children) {
|
|
545
|
-
for (const child of obj.children) {
|
|
546
|
-
this.emitObject(child);
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
// ---------------------------------------------------------------------------
|
|
551
|
-
// Spatial group
|
|
552
|
-
// ---------------------------------------------------------------------------
|
|
553
|
-
emitGroup(group) {
|
|
554
|
-
const varName = this.sanitizeName(group.name);
|
|
555
|
-
this.emit(`// Spatial Group: ${this.escapeStringValue(group.name, "TypeScript")}`);
|
|
556
|
-
this.emit("{");
|
|
557
|
-
this.indent();
|
|
558
|
-
this.emit(`glm::mat4 ${varName}_transform = glm::mat4(1.0f);`);
|
|
559
|
-
for (const prop of group.properties) {
|
|
560
|
-
if (prop.key === "position" && Array.isArray(prop.value)) {
|
|
561
|
-
this.emit(
|
|
562
|
-
`${varName}_transform = glm::translate(${varName}_transform, ${this.toCppVec3(prop.value)});`
|
|
563
|
-
);
|
|
564
|
-
} else if (prop.key === "rotation" && Array.isArray(prop.value)) {
|
|
565
|
-
const r = prop.value;
|
|
566
|
-
this.emit(
|
|
567
|
-
`${varName}_transform = glm::rotate(${varName}_transform, glm::radians(${r[0] ?? 0}f), glm::vec3(1,0,0));`
|
|
568
|
-
);
|
|
569
|
-
this.emit(
|
|
570
|
-
`${varName}_transform = glm::rotate(${varName}_transform, glm::radians(${r[1] ?? 0}f), glm::vec3(0,1,0));`
|
|
571
|
-
);
|
|
572
|
-
this.emit(
|
|
573
|
-
`${varName}_transform = glm::rotate(${varName}_transform, glm::radians(${r[2] ?? 0}f), glm::vec3(0,0,1));`
|
|
574
|
-
);
|
|
575
|
-
} else if (prop.key === "scale") {
|
|
576
|
-
if (Array.isArray(prop.value)) {
|
|
577
|
-
this.emit(
|
|
578
|
-
`${varName}_transform = glm::scale(${varName}_transform, ${this.toCppVec3(prop.value)});`
|
|
579
|
-
);
|
|
580
|
-
} else {
|
|
581
|
-
this.emit(
|
|
582
|
-
`${varName}_transform = glm::scale(${varName}_transform, glm::vec3(${prop.value}f));`
|
|
583
|
-
);
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
this.emit(`// Push ${varName}_transform onto model matrix stack`);
|
|
588
|
-
this.emit("");
|
|
589
|
-
for (const obj of group.objects) {
|
|
590
|
-
this.emitObject(obj);
|
|
591
|
-
}
|
|
592
|
-
if (group.groups) {
|
|
593
|
-
for (const sub of group.groups) {
|
|
594
|
-
this.emitGroup(sub);
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
this.emit("// Pop model matrix stack");
|
|
598
|
-
this.dedent();
|
|
599
|
-
this.emit("}");
|
|
600
|
-
this.emit("");
|
|
601
|
-
}
|
|
602
|
-
// ---------------------------------------------------------------------------
|
|
603
|
-
// Light
|
|
604
|
-
// ---------------------------------------------------------------------------
|
|
605
|
-
emitLight(light) {
|
|
606
|
-
const varName = this.sanitizeName(light.name);
|
|
607
|
-
this.emit(
|
|
608
|
-
`// Light: ${this.escapeStringValue(light.name, "TypeScript")} (${light.lightType})`
|
|
609
|
-
);
|
|
610
|
-
this.emit("{");
|
|
611
|
-
this.indent();
|
|
612
|
-
this.emit(`LightUBO ${varName}_ubo;`);
|
|
613
|
-
const colorProp = light.properties.find((p) => p.key === "color");
|
|
614
|
-
const intensityProp = light.properties.find((p) => p.key === "intensity");
|
|
615
|
-
const posProp = light.properties.find((p) => p.key === "position");
|
|
616
|
-
if (posProp && Array.isArray(posProp.value)) {
|
|
617
|
-
const p = posProp.value;
|
|
618
|
-
const w = light.lightType === "directional" ? 0 : 1;
|
|
619
|
-
this.emit(`${varName}_ubo.position = glm::vec4(${p[0]}f, ${p[1]}f, ${p[2]}f, ${w}f);`);
|
|
620
|
-
} else {
|
|
621
|
-
const w = light.lightType === "directional" ? 0 : 1;
|
|
622
|
-
this.emit(`${varName}_ubo.position = glm::vec4(0.0f, 5.0f, 0.0f, ${w}f);`);
|
|
623
|
-
}
|
|
624
|
-
if (colorProp) {
|
|
625
|
-
this.emit(`${varName}_ubo.color = ${this.toCppColor(colorProp.value)};`);
|
|
626
|
-
} else {
|
|
627
|
-
this.emit(`${varName}_ubo.color = glm::vec4(1.0f);`);
|
|
628
|
-
}
|
|
629
|
-
this.emit(`${varName}_ubo.intensity = ${intensityProp?.value ?? 1}f;`);
|
|
630
|
-
this.emit(`${varName}_ubo.range = ${light.lightType === "directional" ? 0 : 50}f;`);
|
|
631
|
-
this.emit(`// Upload ${varName}_ubo to uniform buffer`);
|
|
632
|
-
this.dedent();
|
|
633
|
-
this.emit("}");
|
|
634
|
-
this.emit("");
|
|
635
|
-
}
|
|
636
|
-
// ---------------------------------------------------------------------------
|
|
637
|
-
// Camera (XR view-driven)
|
|
638
|
-
// ---------------------------------------------------------------------------
|
|
639
|
-
emitCamera(cam) {
|
|
640
|
-
this.emit("// Camera: view/projection derived from xrLocateViews");
|
|
641
|
-
this.emit("{");
|
|
642
|
-
this.indent();
|
|
643
|
-
this.emit("XrViewLocateInfo viewLocateInfo{XR_TYPE_VIEW_LOCATE_INFO};");
|
|
644
|
-
this.emit("viewLocateInfo.viewConfigurationType = XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO;");
|
|
645
|
-
this.emit("viewLocateInfo.displayTime = predictedDisplayTime;");
|
|
646
|
-
this.emit("viewLocateInfo.space = appSpace;");
|
|
647
|
-
this.emit("");
|
|
648
|
-
this.emit("XrViewState viewState{XR_TYPE_VIEW_STATE};");
|
|
649
|
-
this.emit("uint32_t viewCount = 2;");
|
|
650
|
-
this.emit("std::array<XrView, 2> views;");
|
|
651
|
-
this.emit("views[0].type = XR_TYPE_VIEW;");
|
|
652
|
-
this.emit("views[1].type = XR_TYPE_VIEW;");
|
|
653
|
-
this.emit(
|
|
654
|
-
"xrLocateViews(session, &viewLocateInfo, &viewState, viewCount, &viewCount, views.data());"
|
|
655
|
-
);
|
|
656
|
-
this.emit("");
|
|
657
|
-
this.emit("// Per-eye projection and view matrices");
|
|
658
|
-
this.emit("for (uint32_t eye = 0; eye < viewCount; eye++) {");
|
|
659
|
-
this.indent();
|
|
660
|
-
this.emit("const XrFovf& fov = views[eye].fov;");
|
|
661
|
-
for (const prop of cam.properties) {
|
|
662
|
-
if (prop.key === "near" || prop.key === "near_clip") {
|
|
663
|
-
this.emit(`float nearClip = ${prop.value}f;`);
|
|
664
|
-
} else if (prop.key === "far" || prop.key === "far_clip") {
|
|
665
|
-
this.emit(`float farClip = ${prop.value}f;`);
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
this.emit("// Build asymmetric projection from fov angles + near/far");
|
|
669
|
-
this.emit("// Build view matrix from views[eye].pose");
|
|
670
|
-
this.dedent();
|
|
671
|
-
this.emit("}");
|
|
672
|
-
this.dedent();
|
|
673
|
-
this.emit("}");
|
|
674
|
-
this.emit("");
|
|
675
|
-
}
|
|
676
|
-
// ---------------------------------------------------------------------------
|
|
677
|
-
// Render pass
|
|
678
|
-
// ---------------------------------------------------------------------------
|
|
679
|
-
emitRenderPass() {
|
|
680
|
-
if (this.options.renderBackend === "vulkan") {
|
|
681
|
-
this.emit(
|
|
682
|
-
"void beginRenderPass(VkCommandBuffer cmd, VkRenderPass renderPass, VkFramebuffer framebuffer, uint32_t width, uint32_t height) {"
|
|
683
|
-
);
|
|
684
|
-
this.indent();
|
|
685
|
-
this.emit("VkRenderPassBeginInfo rpInfo{VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO};");
|
|
686
|
-
this.emit("rpInfo.renderPass = renderPass;");
|
|
687
|
-
this.emit("rpInfo.framebuffer = framebuffer;");
|
|
688
|
-
this.emit("rpInfo.renderArea.extent = {width, height};");
|
|
689
|
-
this.emit("VkClearValue clearValue{};");
|
|
690
|
-
this.emit("clearValue.color = {{0.0f, 0.0f, 0.0f, 1.0f}};");
|
|
691
|
-
this.emit("rpInfo.clearValueCount = 1;");
|
|
692
|
-
this.emit("rpInfo.pClearValues = &clearValue;");
|
|
693
|
-
this.emit("vkCmdBeginRenderPass(cmd, &rpInfo, VK_SUBPASS_CONTENTS_INLINE);");
|
|
694
|
-
this.emit("");
|
|
695
|
-
this.emit("// Bind pipeline and draw objects here");
|
|
696
|
-
this.emit("");
|
|
697
|
-
this.emit("vkCmdEndRenderPass(cmd);");
|
|
698
|
-
this.dedent();
|
|
699
|
-
this.emit("}");
|
|
700
|
-
} else {
|
|
701
|
-
this.emit("void beginRenderPass(uint32_t framebuffer, uint32_t width, uint32_t height) {");
|
|
702
|
-
this.indent();
|
|
703
|
-
this.emit("glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);");
|
|
704
|
-
this.emit("glViewport(0, 0, width, height);");
|
|
705
|
-
this.emit("glClearColor(0.0f, 0.0f, 0.0f, 1.0f);");
|
|
706
|
-
this.emit("glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);");
|
|
707
|
-
this.emit("glEnable(GL_DEPTH_TEST);");
|
|
708
|
-
this.emit("");
|
|
709
|
-
this.emit("// Bind shader program and draw objects here");
|
|
710
|
-
this.emit("");
|
|
711
|
-
this.dedent();
|
|
712
|
-
this.emit("}");
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
// ---------------------------------------------------------------------------
|
|
716
|
-
// Render loop
|
|
717
|
-
// ---------------------------------------------------------------------------
|
|
718
|
-
emitRenderLoop(composition) {
|
|
719
|
-
this.emit("void renderLoop() {");
|
|
720
|
-
this.indent();
|
|
721
|
-
this.emit("while (sessionRunning) {");
|
|
722
|
-
this.indent();
|
|
723
|
-
this.emit("// Poll OpenXR events");
|
|
724
|
-
this.emit("XrEventDataBuffer event{XR_TYPE_EVENT_DATA_BUFFER};");
|
|
725
|
-
this.emit("while (xrPollEvent(instance, &event) == XR_SUCCESS) {");
|
|
726
|
-
this.indent();
|
|
727
|
-
this.emit("if (event.type == XR_TYPE_EVENT_DATA_SESSION_STATE_CHANGED) {");
|
|
728
|
-
this.indent();
|
|
729
|
-
this.emit("auto* stateEvent = reinterpret_cast<XrEventDataSessionStateChanged*>(&event);");
|
|
730
|
-
this.emit("if (stateEvent->state == XR_SESSION_STATE_STOPPING) {");
|
|
731
|
-
this.indent();
|
|
732
|
-
this.emit("sessionRunning = false;");
|
|
733
|
-
this.dedent();
|
|
734
|
-
this.emit("}");
|
|
735
|
-
this.dedent();
|
|
736
|
-
this.emit("}");
|
|
737
|
-
this.emit("event = {XR_TYPE_EVENT_DATA_BUFFER};");
|
|
738
|
-
this.dedent();
|
|
739
|
-
this.emit("}");
|
|
740
|
-
this.emit("if (!sessionRunning) break;");
|
|
741
|
-
this.emit("");
|
|
742
|
-
this.emit("// Sync actions");
|
|
743
|
-
this.emit("XrActiveActionSet activeActionSet{actionSet, XR_NULL_PATH};");
|
|
744
|
-
this.emit("XrActionsSyncInfo syncInfo{XR_TYPE_ACTIONS_SYNC_INFO};");
|
|
745
|
-
this.emit("syncInfo.countActiveActionSets = 1;");
|
|
746
|
-
this.emit("syncInfo.activeActionSets = &activeActionSet;");
|
|
747
|
-
this.emit("xrSyncActions(session, &syncInfo);");
|
|
748
|
-
this.emit("");
|
|
749
|
-
this.emit("// Wait frame");
|
|
750
|
-
this.emit("XrFrameWaitInfo waitInfo{XR_TYPE_FRAME_WAIT_INFO};");
|
|
751
|
-
this.emit("XrFrameState frameState{XR_TYPE_FRAME_STATE};");
|
|
752
|
-
this.emit("xrWaitFrame(session, &waitInfo, &frameState);");
|
|
753
|
-
this.emit("");
|
|
754
|
-
this.emit("// Begin frame");
|
|
755
|
-
this.emit("XrFrameBeginInfo beginInfo{XR_TYPE_FRAME_BEGIN_INFO};");
|
|
756
|
-
this.emit("xrBeginFrame(session, &beginInfo);");
|
|
757
|
-
this.emit("");
|
|
758
|
-
this.emit("XrTime predictedDisplayTime = frameState.predictedDisplayTime;");
|
|
759
|
-
this.emit("");
|
|
760
|
-
if (this.options.enableHandTracking) {
|
|
761
|
-
this.emit("// Hand tracking update");
|
|
762
|
-
this.emit("updateHandTracking(predictedDisplayTime);");
|
|
763
|
-
this.emit("");
|
|
764
|
-
}
|
|
765
|
-
this.emit("// Locate views for stereo rendering");
|
|
766
|
-
this.emit("XrViewLocateInfo viewLocateInfo{XR_TYPE_VIEW_LOCATE_INFO};");
|
|
767
|
-
this.emit("viewLocateInfo.viewConfigurationType = XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO;");
|
|
768
|
-
this.emit("viewLocateInfo.displayTime = predictedDisplayTime;");
|
|
769
|
-
this.emit("viewLocateInfo.space = appSpace;");
|
|
770
|
-
this.emit("XrViewState viewState{XR_TYPE_VIEW_STATE};");
|
|
771
|
-
this.emit("uint32_t viewCount = 2;");
|
|
772
|
-
this.emit("std::array<XrView, 2> views;");
|
|
773
|
-
this.emit("views[0].type = XR_TYPE_VIEW;");
|
|
774
|
-
this.emit("views[1].type = XR_TYPE_VIEW;");
|
|
775
|
-
this.emit(
|
|
776
|
-
"xrLocateViews(session, &viewLocateInfo, &viewState, viewCount, &viewCount, views.data());"
|
|
777
|
-
);
|
|
778
|
-
this.emit("");
|
|
779
|
-
this.emit("// Acquire and render to swapchain image");
|
|
780
|
-
this.emit("XrSwapchainImageAcquireInfo acquireInfo{XR_TYPE_SWAPCHAIN_IMAGE_ACQUIRE_INFO};");
|
|
781
|
-
this.emit("uint32_t imageIndex;");
|
|
782
|
-
this.emit("xrAcquireSwapchainImage(swapchain, &acquireInfo, &imageIndex);");
|
|
783
|
-
this.emit("");
|
|
784
|
-
this.emit("XrSwapchainImageWaitInfo swapWaitInfo{XR_TYPE_SWAPCHAIN_IMAGE_WAIT_INFO};");
|
|
785
|
-
this.emit("swapWaitInfo.timeout = XR_INFINITE_DURATION;");
|
|
786
|
-
this.emit("xrWaitSwapchainImage(swapchain, &swapWaitInfo);");
|
|
787
|
-
this.emit("");
|
|
788
|
-
this.emit("// === Render scene objects ===");
|
|
789
|
-
if (this.options.renderBackend === "vulkan") {
|
|
790
|
-
this.emit(
|
|
791
|
-
"VkCommandBufferBeginInfo cmdBeginInfo{VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO};"
|
|
792
|
-
);
|
|
793
|
-
this.emit("cmdBeginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;");
|
|
794
|
-
this.emit("vkBeginCommandBuffer(commandBuffer, &cmdBeginInfo);");
|
|
795
|
-
this.emit("");
|
|
796
|
-
this.emit(
|
|
797
|
-
"beginRenderPass(commandBuffer, renderPass, framebuffers[imageIndex], 1920, 1920);"
|
|
798
|
-
);
|
|
799
|
-
this.emit("");
|
|
800
|
-
const allObjects = this.collectAllObjects(composition);
|
|
801
|
-
for (const obj of allObjects) {
|
|
802
|
-
const varName = this.sanitizeName(obj.name);
|
|
803
|
-
this.emit(`// Draw: ${this.escapeStringValue(obj.name, "TypeScript")}`);
|
|
804
|
-
this.emit(
|
|
805
|
-
`vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline);`
|
|
806
|
-
);
|
|
807
|
-
this.emit(`VkDeviceSize ${varName}_offset = 0;`);
|
|
808
|
-
this.emit(
|
|
809
|
-
`vkCmdBindVertexBuffers(commandBuffer, 0, 1, &${varName}_vbo, &${varName}_offset);`
|
|
810
|
-
);
|
|
811
|
-
this.emit(
|
|
812
|
-
`vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &${varName}_desc, 0, nullptr);`
|
|
813
|
-
);
|
|
814
|
-
this.emit(
|
|
815
|
-
`vkCmdDraw(commandBuffer, static_cast<uint32_t>(${varName}_vertices.size() / 6), 1, 0, 0);`
|
|
816
|
-
);
|
|
817
|
-
this.emit("");
|
|
818
|
-
}
|
|
819
|
-
this.emit("vkCmdEndRenderPass(commandBuffer);");
|
|
820
|
-
this.emit("vkEndCommandBuffer(commandBuffer);");
|
|
821
|
-
this.emit("");
|
|
822
|
-
this.emit("// Submit command buffer");
|
|
823
|
-
this.emit("VkSubmitInfo submitInfo{VK_STRUCTURE_TYPE_SUBMIT_INFO};");
|
|
824
|
-
this.emit("submitInfo.commandBufferCount = 1;");
|
|
825
|
-
this.emit("submitInfo.pCommandBuffers = &commandBuffer;");
|
|
826
|
-
this.emit("vkQueueSubmit(graphicsQueue, 1, &submitInfo, VK_NULL_HANDLE);");
|
|
827
|
-
this.emit("vkQueueWaitIdle(graphicsQueue);");
|
|
828
|
-
} else {
|
|
829
|
-
const allObjects = this.collectAllObjects(composition);
|
|
830
|
-
for (const obj of allObjects) {
|
|
831
|
-
const varName = this.sanitizeName(obj.name);
|
|
832
|
-
this.emit(`// Draw: ${this.escapeStringValue(obj.name, "TypeScript")}`);
|
|
833
|
-
this.emit(`glBindVertexArray(${varName}_vao);`);
|
|
834
|
-
this.emit(
|
|
835
|
-
`glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(${varName}_vertices.size() / 6));`
|
|
836
|
-
);
|
|
837
|
-
this.emit("");
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
this.emit("");
|
|
841
|
-
this.emit("XrSwapchainImageReleaseInfo releaseInfo{XR_TYPE_SWAPCHAIN_IMAGE_RELEASE_INFO};");
|
|
842
|
-
this.emit("xrReleaseSwapchainImage(swapchain, &releaseInfo);");
|
|
843
|
-
this.emit("");
|
|
844
|
-
this.emit("// End frame");
|
|
845
|
-
this.emit("XrCompositionLayerProjection layer{XR_TYPE_COMPOSITION_LAYER_PROJECTION};");
|
|
846
|
-
this.emit("layer.space = appSpace;");
|
|
847
|
-
this.emit("std::array<XrCompositionLayerProjectionView, 2> projViews;");
|
|
848
|
-
this.emit("for (uint32_t eye = 0; eye < 2; eye++) {");
|
|
849
|
-
this.indent();
|
|
850
|
-
this.emit("projViews[eye] = {XR_TYPE_COMPOSITION_LAYER_PROJECTION_VIEW};");
|
|
851
|
-
this.emit("projViews[eye].pose = views[eye].pose;");
|
|
852
|
-
this.emit("projViews[eye].fov = views[eye].fov;");
|
|
853
|
-
this.emit("projViews[eye].subImage.swapchain = swapchain;");
|
|
854
|
-
this.emit("projViews[eye].subImage.imageArrayIndex = eye;");
|
|
855
|
-
this.emit("projViews[eye].subImage.imageRect.offset = {0, 0};");
|
|
856
|
-
this.emit("projViews[eye].subImage.imageRect.extent = {1920, 1920};");
|
|
857
|
-
this.dedent();
|
|
858
|
-
this.emit("}");
|
|
859
|
-
this.emit("layer.viewCount = 2;");
|
|
860
|
-
this.emit("layer.views = projViews.data();");
|
|
861
|
-
this.emit("");
|
|
862
|
-
this.emit("const XrCompositionLayerBaseHeader* layers[] = {");
|
|
863
|
-
this.indent();
|
|
864
|
-
this.emit("reinterpret_cast<const XrCompositionLayerBaseHeader*>(&layer)");
|
|
865
|
-
this.dedent();
|
|
866
|
-
this.emit("};");
|
|
867
|
-
this.emit("XrFrameEndInfo endInfo{XR_TYPE_FRAME_END_INFO};");
|
|
868
|
-
this.emit("endInfo.displayTime = predictedDisplayTime;");
|
|
869
|
-
this.emit("endInfo.environmentBlendMode = XR_ENVIRONMENT_BLEND_MODE_OPAQUE;");
|
|
870
|
-
this.emit("endInfo.layerCount = 1;");
|
|
871
|
-
this.emit("endInfo.layers = layers;");
|
|
872
|
-
this.emit("xrEndFrame(session, &endInfo);");
|
|
873
|
-
this.dedent();
|
|
874
|
-
this.emit("}");
|
|
875
|
-
this.dedent();
|
|
876
|
-
this.emit("}");
|
|
877
|
-
}
|
|
878
|
-
// ---------------------------------------------------------------------------
|
|
879
|
-
// Hand tracking
|
|
880
|
-
// ---------------------------------------------------------------------------
|
|
881
|
-
emitHandTracking() {
|
|
882
|
-
this.emit("void initHandTracking() {");
|
|
883
|
-
this.indent();
|
|
884
|
-
this.emit("XrHandTrackerCreateInfoEXT createInfo{XR_TYPE_HAND_TRACKER_CREATE_INFO_EXT};");
|
|
885
|
-
this.emit("");
|
|
886
|
-
this.emit("createInfo.hand = XR_HAND_LEFT_EXT;");
|
|
887
|
-
this.emit("createInfo.handJointSet = XR_HAND_JOINT_SET_DEFAULT_EXT;");
|
|
888
|
-
this.emit("xrCreateHandTrackerEXT(session, &createInfo, &handTrackerLeft);");
|
|
889
|
-
this.emit("");
|
|
890
|
-
this.emit("createInfo.hand = XR_HAND_RIGHT_EXT;");
|
|
891
|
-
this.emit("xrCreateHandTrackerEXT(session, &createInfo, &handTrackerRight);");
|
|
892
|
-
this.dedent();
|
|
893
|
-
this.emit("}");
|
|
894
|
-
this.emit("");
|
|
895
|
-
this.emit("void updateHandTracking(XrTime displayTime) {");
|
|
896
|
-
this.indent();
|
|
897
|
-
this.emit("XrHandJointLocationsEXT locations{XR_TYPE_HAND_JOINT_LOCATIONS_EXT};");
|
|
898
|
-
this.emit(`std::array<XrHandJointLocationEXT, XR_HAND_JOINT_COUNT_EXT> jointLocations;`);
|
|
899
|
-
this.emit("locations.jointCount = static_cast<uint32_t>(jointLocations.size());");
|
|
900
|
-
this.emit("locations.jointLocations = jointLocations.data();");
|
|
901
|
-
this.emit("");
|
|
902
|
-
this.emit("XrHandJointsLocateInfoEXT locateInfo{XR_TYPE_HAND_JOINTS_LOCATE_INFO_EXT};");
|
|
903
|
-
this.emit("locateInfo.baseSpace = appSpace;");
|
|
904
|
-
this.emit("locateInfo.time = displayTime;");
|
|
905
|
-
this.emit("");
|
|
906
|
-
this.emit("// Left hand");
|
|
907
|
-
this.emit("xrLocateHandJointsEXT(handTrackerLeft, &locateInfo, &locations);");
|
|
908
|
-
this.emit("if (locations.isActive) {");
|
|
909
|
-
this.indent();
|
|
910
|
-
this.emit("// Process left hand joint positions");
|
|
911
|
-
this.emit("for (uint32_t j = 0; j < XR_HAND_JOINT_COUNT_EXT; j++) {");
|
|
912
|
-
this.indent();
|
|
913
|
-
this.emit("const auto& loc = jointLocations[j];");
|
|
914
|
-
this.emit("glm::vec3 pos(loc.pose.position.x, loc.pose.position.y, loc.pose.position.z);");
|
|
915
|
-
this.emit("// Update hand-tracked object transforms from joint data");
|
|
916
|
-
this.dedent();
|
|
917
|
-
this.emit("}");
|
|
918
|
-
this.dedent();
|
|
919
|
-
this.emit("}");
|
|
920
|
-
this.emit("");
|
|
921
|
-
this.emit("// Right hand");
|
|
922
|
-
this.emit("xrLocateHandJointsEXT(handTrackerRight, &locateInfo, &locations);");
|
|
923
|
-
this.emit("if (locations.isActive) {");
|
|
924
|
-
this.indent();
|
|
925
|
-
this.emit("for (uint32_t j = 0; j < XR_HAND_JOINT_COUNT_EXT; j++) {");
|
|
926
|
-
this.indent();
|
|
927
|
-
this.emit("const auto& loc = jointLocations[j];");
|
|
928
|
-
this.emit("glm::vec3 pos(loc.pose.position.x, loc.pose.position.y, loc.pose.position.z);");
|
|
929
|
-
this.emit("// Update hand-tracked object transforms from joint data");
|
|
930
|
-
this.dedent();
|
|
931
|
-
this.emit("}");
|
|
932
|
-
this.dedent();
|
|
933
|
-
this.emit("}");
|
|
934
|
-
this.dedent();
|
|
935
|
-
this.emit("}");
|
|
936
|
-
}
|
|
937
|
-
// ---------------------------------------------------------------------------
|
|
938
|
-
// Helpers
|
|
939
|
-
// ---------------------------------------------------------------------------
|
|
940
|
-
emit(line) {
|
|
941
|
-
this.lines.push(this.options.indent.repeat(this.indentLevel) + line);
|
|
942
|
-
}
|
|
943
|
-
indent() {
|
|
944
|
-
this.indentLevel++;
|
|
945
|
-
}
|
|
946
|
-
dedent() {
|
|
947
|
-
if (this.indentLevel > 0) this.indentLevel--;
|
|
948
|
-
}
|
|
949
|
-
sanitizeName(name) {
|
|
950
|
-
return name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
951
|
-
}
|
|
952
|
-
findObjProp(obj, key) {
|
|
953
|
-
return obj.properties?.find((p) => p.key === key)?.value;
|
|
954
|
-
}
|
|
955
|
-
// ---------------------------------------------------------------------------
|
|
956
|
-
// Value conversion helpers
|
|
957
|
-
// ---------------------------------------------------------------------------
|
|
958
|
-
toCppVec3(arr) {
|
|
959
|
-
if (Array.isArray(arr) && arr.length >= 3) {
|
|
960
|
-
return `glm::vec3(${arr[0]}f, ${arr[1]}f, ${arr[2]}f)`;
|
|
961
|
-
}
|
|
962
|
-
if (typeof arr === "number") {
|
|
963
|
-
return `glm::vec3(${arr}f)`;
|
|
964
|
-
}
|
|
965
|
-
return "glm::vec3(0.0f)";
|
|
966
|
-
}
|
|
967
|
-
toCppColor(hex) {
|
|
968
|
-
if (typeof hex === "string" && hex.startsWith("#")) {
|
|
969
|
-
const h = hex.slice(1);
|
|
970
|
-
const r = (parseInt(h.substring(0, 2), 16) / 255).toFixed(3);
|
|
971
|
-
const g = (parseInt(h.substring(2, 4), 16) / 255).toFixed(3);
|
|
972
|
-
const b = (parseInt(h.substring(4, 6), 16) / 255).toFixed(3);
|
|
973
|
-
return `glm::vec4(${r}f, ${g}f, ${b}f, 1.0f)`;
|
|
974
|
-
}
|
|
975
|
-
if (typeof hex === "string") {
|
|
976
|
-
return `glm::vec4(1.0f) /* ${hex} */`;
|
|
977
|
-
}
|
|
978
|
-
return "glm::vec4(1.0f)";
|
|
979
|
-
}
|
|
980
|
-
mapShapeToVertexData(type) {
|
|
981
|
-
switch (type) {
|
|
982
|
-
case "cube":
|
|
983
|
-
case "box":
|
|
984
|
-
return "generateCubeVertices()";
|
|
985
|
-
case "sphere":
|
|
986
|
-
case "orb":
|
|
987
|
-
return "generateSphereVertices(32, 32)";
|
|
988
|
-
case "plane":
|
|
989
|
-
return "generatePlaneVertices()";
|
|
990
|
-
case "cylinder":
|
|
991
|
-
return "generateCylinderVertices(32)";
|
|
992
|
-
case "cone":
|
|
993
|
-
case "pyramid":
|
|
994
|
-
return "generateConeVertices(32)";
|
|
995
|
-
case "torus":
|
|
996
|
-
return "generateTorusVertices(32, 16)";
|
|
997
|
-
default:
|
|
998
|
-
return "generateCubeVertices()";
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
// ---------------------------------------------------------------------------
|
|
1002
|
-
// Composition analysis helpers
|
|
1003
|
-
// ---------------------------------------------------------------------------
|
|
1004
|
-
compositionUsesAnchor(composition) {
|
|
1005
|
-
const check = (objs) => {
|
|
1006
|
-
if (!objs) return false;
|
|
1007
|
-
return objs.some(
|
|
1008
|
-
(o) => o.traits?.some(
|
|
1009
|
-
(t) => t.name === "anchor" || t.name === "persistent_anchor" || t.name === "shared_anchor"
|
|
1010
|
-
) || check(o.children)
|
|
1011
|
-
);
|
|
1012
|
-
};
|
|
1013
|
-
return check(composition.objects);
|
|
1014
|
-
}
|
|
1015
|
-
collectAllObjects(composition) {
|
|
1016
|
-
const result = [];
|
|
1017
|
-
const collect = (objs) => {
|
|
1018
|
-
if (!objs) return;
|
|
1019
|
-
for (const obj of objs) {
|
|
1020
|
-
result.push(obj);
|
|
1021
|
-
if (obj.children) {
|
|
1022
|
-
collect(obj.children);
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
};
|
|
1026
|
-
collect(composition.objects);
|
|
1027
|
-
const collectFromGroups = (groups) => {
|
|
1028
|
-
if (!groups) return;
|
|
1029
|
-
for (const group of groups) {
|
|
1030
|
-
collect(group.objects);
|
|
1031
|
-
if (group.groups) {
|
|
1032
|
-
collectFromGroups(group.groups);
|
|
1033
|
-
}
|
|
1034
|
-
}
|
|
1035
|
-
};
|
|
1036
|
-
collectFromGroups(composition.spatialGroups);
|
|
1037
|
-
return result;
|
|
1038
|
-
}
|
|
1039
|
-
};
|
|
1040
|
-
}
|
|
1041
|
-
});
|
|
1042
|
-
|
|
1043
|
-
exports.OpenXRCompiler_exports = OpenXRCompiler_exports;
|
|
1044
|
-
exports.init_OpenXRCompiler = init_OpenXRCompiler;
|
|
1045
|
-
//# sourceMappingURL=chunk-XDXZM3ZP.cjs.map
|
|
1046
|
-
//# sourceMappingURL=chunk-XDXZM3ZP.cjs.map
|