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