@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.
Files changed (244) hide show
  1. package/README.md +40 -40
  2. package/dist/codebase/index.d.ts +25 -0
  3. package/dist/compiler/index.d.ts +82 -0
  4. package/dist/constants.d.ts +4 -0
  5. package/dist/coordinators/index.d.ts +189 -0
  6. package/dist/entries/interop.d.ts +9 -0
  7. package/dist/entries/scripting.d.ts +7 -0
  8. package/dist/index.d.ts +520 -19
  9. package/dist/paper-0c-spike/index.d.ts +29 -0
  10. package/dist/reconstruction/index.d.ts +78 -0
  11. package/dist/self-improvement/index.d.ts +0 -48
  12. package/dist/storage/index.d.ts +24 -0
  13. package/dist/tools/index.d.ts +33 -0
  14. package/dist/traitDocs/traitDocs.d.ts +69 -0
  15. package/dist/traits/index.d.ts +61 -0
  16. package/package.json +102 -19
  17. package/dist/GLTFPipeline-3KLWWUQO.cjs +0 -34
  18. package/dist/GLTFPipeline-LYII2ZVQ.js +0 -13
  19. package/dist/HoloScriptPlusParser-BZR5DELQ.js +0 -692
  20. package/dist/HoloScriptPlusParser-SBMYDNXO.cjs +0 -697
  21. package/dist/USDZExporter-MHEHXZB4.cjs +0 -709
  22. package/dist/USDZExporter-YA55ZS35.js +0 -707
  23. package/dist/chunk-26TLYBFD.js +0 -309
  24. package/dist/chunk-27LWW5FU.cjs +0 -410
  25. package/dist/chunk-2UX5LRAP.cjs +0 -833
  26. package/dist/chunk-32TWR3HE.js +0 -70
  27. package/dist/chunk-3FXV5S25.cjs +0 -633
  28. package/dist/chunk-3FYZOR7S.cjs +0 -69
  29. package/dist/chunk-3KEU5QYY.cjs +0 -175
  30. package/dist/chunk-4FCZDTD5.js +0 -610
  31. package/dist/chunk-4KJ2R7VP.cjs +0 -507
  32. package/dist/chunk-4SMUJFHL.js +0 -1213
  33. package/dist/chunk-54FHG2MX.js +0 -655
  34. package/dist/chunk-56IF4NTA.js +0 -56
  35. package/dist/chunk-5GLCTO44.js +0 -161
  36. package/dist/chunk-5TOFIR6L.js +0 -407
  37. package/dist/chunk-65RFOWZI.js +0 -765
  38. package/dist/chunk-6OQBLABR.js +0 -5240
  39. package/dist/chunk-6WNCRE6F.js +0 -126
  40. package/dist/chunk-74YCHHTE.js +0 -1872
  41. package/dist/chunk-7H5UNJZD.cjs +0 -1973
  42. package/dist/chunk-7KPI4EKH.cjs +0 -701
  43. package/dist/chunk-7LCYLPW2.cjs +0 -663
  44. package/dist/chunk-7N3JIJMT.js +0 -1395
  45. package/dist/chunk-7X2IEJIE.cjs +0 -2526
  46. package/dist/chunk-A6GO3DPZ.cjs +0 -1002
  47. package/dist/chunk-AC4BSHFV.js +0 -765
  48. package/dist/chunk-AIUXRS74.cjs +0 -3681
  49. package/dist/chunk-ARNKA274.cjs +0 -130
  50. package/dist/chunk-AW7WAELW.js +0 -975
  51. package/dist/chunk-BKIGPPVM.js +0 -629
  52. package/dist/chunk-BO2OKHIY.js +0 -6055
  53. package/dist/chunk-BU5ZAFMC.js +0 -115
  54. package/dist/chunk-BY3B7ZYV.cjs +0 -457
  55. package/dist/chunk-C2QHVHZF.js +0 -4066
  56. package/dist/chunk-C7BNX4XJ.js +0 -1043
  57. package/dist/chunk-CLYEIWA5.cjs +0 -408
  58. package/dist/chunk-CMYAWUX3.js +0 -4455
  59. package/dist/chunk-CN4NOESF.cjs +0 -416
  60. package/dist/chunk-CNVM7J3M.js +0 -883
  61. package/dist/chunk-CO2VM2DK.js +0 -1965
  62. package/dist/chunk-CQDOF3G7.cjs +0 -1404
  63. package/dist/chunk-DH5G2JUA.cjs +0 -614
  64. package/dist/chunk-DIEDKX5B.cjs +0 -660
  65. package/dist/chunk-DN7UFU63.cjs +0 -172
  66. package/dist/chunk-DXVCEFZB.js +0 -2027
  67. package/dist/chunk-EGIZHYJP.cjs +0 -85
  68. package/dist/chunk-EJA7G2C4.cjs +0 -428
  69. package/dist/chunk-ELLQPFAF.js +0 -830
  70. package/dist/chunk-EMO7HAKJ.cjs +0 -1875
  71. package/dist/chunk-ENV7K6XA.js +0 -282
  72. package/dist/chunk-EPWRXL6S.js +0 -2522
  73. package/dist/chunk-EUFLX2PI.js +0 -56956
  74. package/dist/chunk-F5LVGHNT.js +0 -449
  75. package/dist/chunk-FEFHPUEM.cjs +0 -6122
  76. package/dist/chunk-FF3Q7ADR.js +0 -380
  77. package/dist/chunk-GC3YU46J.js +0 -762
  78. package/dist/chunk-H6WMMLQK.cjs +0 -4492
  79. package/dist/chunk-H7XMORZI.js +0 -2731
  80. package/dist/chunk-HAN4V3PF.cjs +0 -2037
  81. package/dist/chunk-HBZYCASG.js +0 -4208
  82. package/dist/chunk-HF4OFY25.cjs +0 -4097
  83. package/dist/chunk-HHS6FMOU.cjs +0 -3813
  84. package/dist/chunk-HJJLD366.js +0 -1169
  85. package/dist/chunk-HKCVM6OK.cjs +0 -2237
  86. package/dist/chunk-HUFNKFA6.js +0 -698
  87. package/dist/chunk-I3XGTIHM.cjs +0 -1505
  88. package/dist/chunk-I6XZ5DZF.cjs +0 -488
  89. package/dist/chunk-IHOUYQIA.js +0 -406
  90. package/dist/chunk-ILRBGFVD.cjs +0 -72
  91. package/dist/chunk-KDB6BUMB.js +0 -3666
  92. package/dist/chunk-KUJRR4FJ.js +0 -657
  93. package/dist/chunk-KYM4XRFG.js +0 -421
  94. package/dist/chunk-L3Z2HIWJ.cjs +0 -793
  95. package/dist/chunk-LBPEZQAF.js +0 -2232
  96. package/dist/chunk-LER4WXW5.cjs +0 -286
  97. package/dist/chunk-LK5IAVH6.cjs +0 -1173
  98. package/dist/chunk-M6FU6S22.js +0 -2911
  99. package/dist/chunk-MWEFR6YQ.js +0 -1857
  100. package/dist/chunk-N5FTS757.cjs +0 -415
  101. package/dist/chunk-NCUHGRTZ.js +0 -752
  102. package/dist/chunk-NKRKT6V2.js +0 -69
  103. package/dist/chunk-NLPSZT4C.js +0 -630
  104. package/dist/chunk-NRUB55IT.cjs +0 -771
  105. package/dist/chunk-NTMZSDXM.cjs +0 -633
  106. package/dist/chunk-ODGMVILH.js +0 -9662
  107. package/dist/chunk-PBA6NXCT.cjs +0 -1216
  108. package/dist/chunk-PHENW4MQ.js +0 -65
  109. package/dist/chunk-PJMOXFPR.cjs +0 -1861
  110. package/dist/chunk-PLMYCCA4.js +0 -504
  111. package/dist/chunk-PPULB4GG.cjs +0 -9728
  112. package/dist/chunk-PQLGZKMC.cjs +0 -755
  113. package/dist/chunk-Q56TT7IL.js +0 -483
  114. package/dist/chunk-QHVVVN47.cjs +0 -2033
  115. package/dist/chunk-QWKUKVRE.js +0 -2026
  116. package/dist/chunk-RE3OKSYF.cjs +0 -424
  117. package/dist/chunk-RT7LJRSF.cjs +0 -57378
  118. package/dist/chunk-SPDELRRV.cjs +0 -319
  119. package/dist/chunk-SUCBB66F.js +0 -229
  120. package/dist/chunk-TSWTWZ42.cjs +0 -4214
  121. package/dist/chunk-UITWA6DV.cjs +0 -2829
  122. package/dist/chunk-UQW6SLM5.js +0 -172
  123. package/dist/chunk-V2ILLPHK.cjs +0 -237
  124. package/dist/chunk-V42NTCFH.js +0 -3645
  125. package/dist/chunk-VJ3L7CHT.cjs +0 -169
  126. package/dist/chunk-VJVCD5T5.cjs +0 -769
  127. package/dist/chunk-VK5AXKO3.js +0 -746
  128. package/dist/chunk-VSXOIUCF.cjs +0 -473
  129. package/dist/chunk-VZNKJZTT.cjs +0 -749
  130. package/dist/chunk-W76ETJTI.js +0 -678
  131. package/dist/chunk-WFJIDI2N.cjs +0 -424
  132. package/dist/chunk-WN3YF33G.cjs +0 -118
  133. package/dist/chunk-WUXIRGZP.cjs +0 -2915
  134. package/dist/chunk-WYH4GVZ5.js +0 -1488
  135. package/dist/chunk-X4YVN7H3.cjs +0 -888
  136. package/dist/chunk-X67XRI2T.js +0 -410
  137. package/dist/chunk-XDXZM3ZP.cjs +0 -1046
  138. package/dist/chunk-XH7SE4HH.cjs +0 -72
  139. package/dist/chunk-XNMEH2BI.js +0 -126
  140. package/dist/chunk-XSF76QRU.js +0 -468
  141. package/dist/chunk-XSUZMPVQ.cjs +0 -682
  142. package/dist/chunk-XUILI4KB.cjs +0 -430
  143. package/dist/chunk-Y5MUAYTO.js +0 -167
  144. package/dist/chunk-Y7VK5TH3.cjs +0 -129
  145. package/dist/chunk-YCMQQQ5U.cjs +0 -5244
  146. package/dist/chunk-YYXH45E2.js +0 -426
  147. package/dist/chunk-ZGTGVSTZ.js +0 -422
  148. package/dist/chunk-ZL6VJ6SN.js +0 -421
  149. package/dist/cli/holoscript-runner.cjs +0 -2258
  150. package/dist/cli/holoscript-runner.js +0 -2233
  151. package/dist/codebase/index.cjs +0 -336
  152. package/dist/codebase/index.js +0 -331
  153. package/dist/compiler/agent-inference.cjs +0 -29
  154. package/dist/compiler/agent-inference.js +0 -6
  155. package/dist/compiler/android-xr.cjs +0 -20
  156. package/dist/compiler/android-xr.js +0 -10
  157. package/dist/compiler/android.cjs +0 -21
  158. package/dist/compiler/android.js +0 -11
  159. package/dist/compiler/ar.cjs +0 -21
  160. package/dist/compiler/ar.js +0 -9
  161. package/dist/compiler/babylon.cjs +0 -18
  162. package/dist/compiler/babylon.js +0 -12
  163. package/dist/compiler/coco.cjs +0 -27
  164. package/dist/compiler/coco.js +0 -4
  165. package/dist/compiler/domain-block-utils.cjs +0 -595
  166. package/dist/compiler/domain-block-utils.js +0 -9
  167. package/dist/compiler/dtdl.cjs +0 -25
  168. package/dist/compiler/dtdl.js +0 -9
  169. package/dist/compiler/gltf-pipeline.cjs +0 -39
  170. package/dist/compiler/gltf-pipeline.js +0 -4
  171. package/dist/compiler/godot.cjs +0 -16
  172. package/dist/compiler/godot.js +0 -10
  173. package/dist/compiler/incremental.cjs +0 -30
  174. package/dist/compiler/incremental.js +0 -5
  175. package/dist/compiler/index.cjs +0 -1522
  176. package/dist/compiler/index.js +0 -1321
  177. package/dist/compiler/ios.cjs +0 -21
  178. package/dist/compiler/ios.js +0 -11
  179. package/dist/compiler/multi-layer.cjs +0 -27
  180. package/dist/compiler/multi-layer.js +0 -12
  181. package/dist/compiler/nodetoy.cjs +0 -23
  182. package/dist/compiler/nodetoy.js +0 -4
  183. package/dist/compiler/openxr.cjs +0 -16
  184. package/dist/compiler/openxr.js +0 -10
  185. package/dist/compiler/playcanvas.cjs +0 -17
  186. package/dist/compiler/playcanvas.js +0 -11
  187. package/dist/compiler/r3f.cjs +0 -35
  188. package/dist/compiler/r3f.js +0 -13
  189. package/dist/compiler/remotion.cjs +0 -23
  190. package/dist/compiler/remotion.js +0 -4
  191. package/dist/compiler/reproducibility.cjs +0 -39
  192. package/dist/compiler/reproducibility.js +0 -4
  193. package/dist/compiler/sdf.cjs +0 -22
  194. package/dist/compiler/sdf.js +0 -10
  195. package/dist/compiler/semantic-scene.cjs +0 -31
  196. package/dist/compiler/semantic-scene.js +0 -4
  197. package/dist/compiler/state.cjs +0 -18
  198. package/dist/compiler/state.js +0 -8
  199. package/dist/compiler/trait-composition.cjs +0 -27
  200. package/dist/compiler/trait-composition.js +0 -6
  201. package/dist/compiler/unity.cjs +0 -16
  202. package/dist/compiler/unity.js +0 -10
  203. package/dist/compiler/unreal.cjs +0 -20
  204. package/dist/compiler/unreal.js +0 -10
  205. package/dist/compiler/urdf.cjs +0 -46
  206. package/dist/compiler/urdf.js +0 -10
  207. package/dist/compiler/usd-physics.cjs +0 -24
  208. package/dist/compiler/usd-physics.js +0 -7
  209. package/dist/compiler/visionos.cjs +0 -16
  210. package/dist/compiler/visionos.js +0 -10
  211. package/dist/compiler/vrchat.cjs +0 -20
  212. package/dist/compiler/vrchat.js +0 -10
  213. package/dist/compiler/vrr.cjs +0 -22
  214. package/dist/compiler/vrr.js +0 -10
  215. package/dist/compiler/wasm.cjs +0 -34
  216. package/dist/compiler/wasm.js +0 -10
  217. package/dist/compiler/webgpu.cjs +0 -16
  218. package/dist/compiler/webgpu.js +0 -10
  219. package/dist/debugger.cjs +0 -21
  220. package/dist/debugger.js +0 -8
  221. package/dist/entries/interop.cjs +0 -62
  222. package/dist/entries/interop.js +0 -5
  223. package/dist/entries/scripting.cjs +0 -67
  224. package/dist/entries/scripting.js +0 -10
  225. package/dist/index.cjs +0 -61703
  226. package/dist/index.js +0 -58652
  227. package/dist/math/vec3.cjs +0 -57
  228. package/dist/math/vec3.js +0 -4
  229. package/dist/parser.cjs +0 -26
  230. package/dist/parser.js +0 -9
  231. package/dist/playwright-7DTEQCBD.cjs +0 -98673
  232. package/dist/playwright-BIZXMLD2.js +0 -98660
  233. package/dist/post-quantum-JTTAAGO3.cjs +0 -6
  234. package/dist/post-quantum-RVPVDEPI.js +0 -4
  235. package/dist/runtime.cjs +0 -16
  236. package/dist/runtime.js +0 -7
  237. package/dist/storage/index.cjs +0 -37
  238. package/dist/storage/index.js +0 -4
  239. package/dist/traits/index.cjs +0 -14331
  240. package/dist/traits/index.js +0 -12126
  241. package/dist/type-checker.cjs +0 -18
  242. package/dist/type-checker.js +0 -5
  243. package/dist/wot/index.cjs +0 -29
  244. package/dist/wot/index.js +0 -4
@@ -1,1875 +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/VisionOSTraitMap.ts
8
- function getTraitMapping(traitName) {
9
- return VISIONOS_TRAIT_MAP[traitName];
10
- }
11
- function generateTraitCode(traitName, varName, config) {
12
- const mapping = getTraitMapping(traitName);
13
- if (!mapping) {
14
- return [`// @${traitName} \u2014 no mapping defined: ${JSON.stringify(config)}`];
15
- }
16
- return mapping.generate(varName, config);
17
- }
18
- function getRequiredImports(traits) {
19
- const imports = /* @__PURE__ */ new Set();
20
- for (const trait of traits) {
21
- const mapping = getTraitMapping(trait);
22
- if (mapping?.imports) {
23
- mapping.imports.forEach((i) => imports.add(i));
24
- }
25
- }
26
- return Array.from(imports);
27
- }
28
- function getMinVisionOSVersion(traits) {
29
- let maxVersion = "1.0";
30
- for (const trait of traits) {
31
- const mapping = getTraitMapping(trait);
32
- if (mapping?.minVersion) {
33
- if (parseFloat(mapping.minVersion) > parseFloat(maxVersion)) {
34
- maxVersion = mapping.minVersion;
35
- }
36
- }
37
- }
38
- return maxVersion;
39
- }
40
- var PHYSICS_TRAIT_MAP, INTERACTION_TRAIT_MAP, AUDIO_TRAIT_MAP, AR_TRAIT_MAP, VISUAL_TRAIT_MAP, ACCESSIBILITY_TRAIT_MAP, UI_TRAIT_MAP, PORTAL_TRAIT_MAP, V43_TRAIT_MAP, VISIONOS_TRAIT_MAP;
41
- var init_VisionOSTraitMap = chunkEGIZHYJP_cjs.__esm({
42
- "src/compiler/VisionOSTraitMap.ts"() {
43
- PHYSICS_TRAIT_MAP = {
44
- collidable: {
45
- trait: "collidable",
46
- components: ["CollisionComponent"],
47
- level: "full",
48
- generate: (varName, config) => {
49
- const mode = config.mode || "default";
50
- return [
51
- `${varName}.components.set(CollisionComponent(shapes: [.generateConvex(from: ${varName}Mesh)], mode: .${mode}))`
52
- ];
53
- }
54
- },
55
- physics: {
56
- trait: "physics",
57
- components: ["CollisionComponent", "PhysicsBodyComponent"],
58
- level: "full",
59
- generate: (varName, config) => {
60
- const mass = config.mass ?? 1;
61
- const mode = config.kinematic ? "kinematic" : "dynamic";
62
- const friction = config.friction ?? 0.5;
63
- const restitution = config.restitution ?? 0.3;
64
- return [
65
- `${varName}.components.set(CollisionComponent(shapes: [.generateConvex(from: ${varName}Mesh)]))`,
66
- `var ${varName}Physics = PhysicsBodyComponent(massProperties: .init(mass: ${mass}), mode: .${mode})`,
67
- `${varName}Physics.material = .init(friction: ${friction}, restitution: ${restitution})`,
68
- `${varName}.components.set(${varName}Physics)`
69
- ];
70
- }
71
- },
72
- static: {
73
- trait: "static",
74
- components: ["CollisionComponent", "PhysicsBodyComponent"],
75
- level: "full",
76
- generate: (varName) => [
77
- `${varName}.components.set(CollisionComponent(shapes: [.generateConvex(from: ${varName}Mesh)]))`,
78
- `${varName}.components.set(PhysicsBodyComponent(mode: .static))`
79
- ]
80
- },
81
- kinematic: {
82
- trait: "kinematic",
83
- components: ["CollisionComponent", "PhysicsBodyComponent"],
84
- level: "full",
85
- generate: (varName) => [
86
- `${varName}.components.set(CollisionComponent(shapes: [.generateConvex(from: ${varName}Mesh)]))`,
87
- `${varName}.components.set(PhysicsBodyComponent(mode: .kinematic))`
88
- ]
89
- },
90
- cloth: {
91
- trait: "cloth",
92
- components: ["CollisionComponent", "PhysicsBodyComponent"],
93
- level: "partial",
94
- imports: ["RealityKit", "Metal"],
95
- generate: (varName, config) => {
96
- const stiffness = config.stiffness ?? 0.8;
97
- const damping = config.damping ?? 0.02;
98
- const iterations = config.iterations ?? 10;
99
- const gravity = config.gravity ?? -9.81;
100
- const windStrength = config.wind_strength ?? 0;
101
- return [
102
- `// @cloth \u2014 Position-Based Dynamics cloth simulation`,
103
- `var ${varName}ClothSystem = ClothSimulationComponent()`,
104
- `${varName}ClothSystem.stiffness = ${stiffness}`,
105
- `${varName}ClothSystem.damping = ${damping}`,
106
- `${varName}ClothSystem.solverIterations = ${iterations}`,
107
- `${varName}ClothSystem.gravity = SIMD3<Float>(0, ${gravity}, 0)`,
108
- ...windStrength ? [`${varName}ClothSystem.wind = SIMD3<Float>(${windStrength}, 0, 0)`] : [],
109
- `${varName}.components.set(${varName}ClothSystem)`,
110
- ``,
111
- `// Register cloth ECS system for Metal compute dispatch`,
112
- `ClothSimulationSystem.registerSystem()`,
113
- `ClothSimulationSystem.configure(device: MTLCreateSystemDefaultDevice()!)`
114
- ];
115
- }
116
- },
117
- soft_body: {
118
- trait: "soft_body",
119
- components: ["CollisionComponent", "PhysicsBodyComponent"],
120
- level: "partial",
121
- imports: ["RealityKit", "Metal"],
122
- generate: (varName, config) => {
123
- const compliance = config.compliance ?? 1e-4;
124
- const damping = config.damping ?? 0.01;
125
- const iterations = config.iterations ?? 8;
126
- const volumeStiffness = config.volume_stiffness ?? 1;
127
- const pressure = config.pressure ?? 1;
128
- return [
129
- `// @soft_body \u2014 Extended PBD (XPBD) soft body simulation`,
130
- `var ${varName}SoftBody = SoftBodyComponent()`,
131
- `${varName}SoftBody.compliance = ${compliance}`,
132
- `${varName}SoftBody.damping = ${damping}`,
133
- `${varName}SoftBody.solverIterations = ${iterations}`,
134
- `${varName}SoftBody.volumeStiffness = ${volumeStiffness}`,
135
- `${varName}SoftBody.pressure = ${pressure}`,
136
- `${varName}.components.set(${varName}SoftBody)`,
137
- `${varName}.components.set(CollisionComponent(shapes: [.generateConvex(from: ${varName}Mesh)]))`,
138
- ``,
139
- `// Register soft body ECS system`,
140
- `SoftBodySimulationSystem.registerSystem()`,
141
- `SoftBodySimulationSystem.configure(device: MTLCreateSystemDefaultDevice()!)`
142
- ];
143
- }
144
- },
145
- fluid: {
146
- trait: "fluid",
147
- components: ["CollisionComponent"],
148
- level: "partial",
149
- imports: ["RealityKit", "Metal"],
150
- generate: (varName, config) => {
151
- const particleCount = config.particle_count ?? 1e4;
152
- const viscosity = config.viscosity ?? 0.01;
153
- const restDensity = config.rest_density ?? 1e3;
154
- const smoothingRadius = config.smoothing_radius ?? 0.04;
155
- const surfaceTension = config.surface_tension ?? 0.0728;
156
- return [
157
- `// @fluid \u2014 SPH (Smoothed Particle Hydrodynamics) fluid via Metal compute`,
158
- `var ${varName}Fluid = FluidSimulationComponent()`,
159
- `${varName}Fluid.particleCount = ${particleCount}`,
160
- `${varName}Fluid.viscosity = ${viscosity}`,
161
- `${varName}Fluid.restDensity = ${restDensity}`,
162
- `${varName}Fluid.smoothingRadius = ${smoothingRadius}`,
163
- `${varName}Fluid.surfaceTension = ${surfaceTension}`,
164
- `${varName}.components.set(${varName}Fluid)`,
165
- ``,
166
- `// SPH kernel dispatch \u2014 density, pressure, viscosity, integration passes`,
167
- `FluidSimulationSystem.registerSystem()`,
168
- `FluidSimulationSystem.configure(`,
169
- ` device: MTLCreateSystemDefaultDevice()!,`,
170
- ` maxParticles: ${particleCount}`,
171
- `)`
172
- ];
173
- }
174
- }
175
- };
176
- INTERACTION_TRAIT_MAP = {
177
- grabbable: {
178
- trait: "grabbable",
179
- components: ["CollisionComponent", "PhysicsBodyComponent", "InputTargetComponent"],
180
- level: "full",
181
- generate: (varName, config) => {
182
- const mass = config.mass ?? 1;
183
- const snapToHand = config.snap_to_hand ?? false;
184
- const lines = [
185
- `${varName}.components.set(CollisionComponent(shapes: [.generateConvex(from: ${varName}Mesh)]))`,
186
- `${varName}.components.set(PhysicsBodyComponent(massProperties: .init(mass: ${mass}), mode: .dynamic))`,
187
- `${varName}.components.set(InputTargetComponent(allowedInputTypes: .indirect))`
188
- ];
189
- if (snapToHand) {
190
- lines.push(`// snap_to_hand: true \u2014 implement via DragGesture handler`);
191
- }
192
- return lines;
193
- }
194
- },
195
- hoverable: {
196
- trait: "hoverable",
197
- components: ["InputTargetComponent", "HoverEffectComponent"],
198
- level: "full",
199
- minVersion: "1.0",
200
- generate: (varName, config) => {
201
- const highlightColor = config.highlight_color || "#ffffff";
202
- return [
203
- `${varName}.components.set(InputTargetComponent())`,
204
- `${varName}.components.set(HoverEffectComponent())`,
205
- `// Highlight color: ${highlightColor} \u2014 configure via RealityKit material states`
206
- ];
207
- }
208
- },
209
- clickable: {
210
- trait: "clickable",
211
- components: ["InputTargetComponent", "CollisionComponent"],
212
- level: "full",
213
- generate: (varName) => [
214
- `${varName}.components.set(CollisionComponent(shapes: [.generateConvex(from: ${varName}Mesh)]))`,
215
- `${varName}.components.set(InputTargetComponent(allowedInputTypes: .indirect))`,
216
- `// Use .gesture(TapGesture().targetedToEntity(${varName})) for tap handling`
217
- ]
218
- },
219
- draggable: {
220
- trait: "draggable",
221
- components: ["InputTargetComponent", "CollisionComponent"],
222
- level: "full",
223
- generate: (varName, config) => {
224
- const axis = config.constrain_axis;
225
- const lines = [
226
- `${varName}.components.set(CollisionComponent(shapes: [.generateConvex(from: ${varName}Mesh)]))`,
227
- `${varName}.components.set(InputTargetComponent(allowedInputTypes: .indirect))`
228
- ];
229
- if (axis) {
230
- lines.push(`// Constrain drag to axis: ${axis}`);
231
- }
232
- return lines;
233
- }
234
- },
235
- throwable: {
236
- trait: "throwable",
237
- components: ["CollisionComponent", "PhysicsBodyComponent", "InputTargetComponent"],
238
- level: "full",
239
- generate: (varName, config) => {
240
- const maxVelocity = config.max_velocity ?? 10;
241
- return [
242
- `${varName}.components.set(CollisionComponent(shapes: [.generateConvex(from: ${varName}Mesh)]))`,
243
- `${varName}.components.set(PhysicsBodyComponent(massProperties: .init(mass: 1.0), mode: .dynamic))`,
244
- `${varName}.components.set(InputTargetComponent())`,
245
- `// Max velocity: ${maxVelocity} \u2014 clamp in gesture handler`
246
- ];
247
- }
248
- },
249
- pointable: {
250
- trait: "pointable",
251
- components: ["InputTargetComponent"],
252
- level: "full",
253
- generate: (varName) => [
254
- `${varName}.components.set(InputTargetComponent(allowedInputTypes: [.indirect, .direct]))`
255
- ]
256
- },
257
- scalable: {
258
- trait: "scalable",
259
- components: ["InputTargetComponent", "CollisionComponent"],
260
- level: "full",
261
- generate: (varName, config) => {
262
- const minScale = config.min_scale ?? 0.1;
263
- const maxScale = config.max_scale ?? 3;
264
- return [
265
- `${varName}.components.set(InputTargetComponent())`,
266
- `${varName}.components.set(CollisionComponent(shapes: [.generateConvex(from: ${varName}Mesh)]))`,
267
- `// @scalable \u2014 attach MagnifyGesture in SwiftUI view:`,
268
- `// .gesture(MagnifyGesture().targetedToEntity(${varName}).onChanged { value in`,
269
- `// let s = Float(value.magnification) * initialScale`,
270
- `// let clamped = min(max(s, ${minScale}), ${maxScale})`,
271
- `// value.entity.setScale(SIMD3<Float>(repeating: clamped), relativeTo: value.entity.parent)`,
272
- `// })`
273
- ];
274
- }
275
- },
276
- rotatable: {
277
- trait: "rotatable",
278
- components: ["InputTargetComponent", "CollisionComponent"],
279
- level: "full",
280
- generate: (varName, config) => {
281
- const axis = String(config.axis || "y");
282
- const axisMap = { x: ".x", y: ".y", z: ".z" };
283
- return [
284
- `${varName}.components.set(InputTargetComponent())`,
285
- `${varName}.components.set(CollisionComponent(shapes: [.generateConvex(from: ${varName}Mesh)]))`,
286
- `// @rotatable \u2014 attach RotateGesture3D in SwiftUI view:`,
287
- `// .gesture(RotateGesture3D(constrainedToAxis: ${axisMap[axis] || ".y"}).targetedToEntity(${varName}).onChanged { value in`,
288
- `// let rotTransform = Transform(AffineTransform3D(rotation: value.rotation))`,
289
- `// value.entity.transform.rotation = sourceRotation * rotTransform.rotation`,
290
- `// })`
291
- ];
292
- }
293
- }
294
- };
295
- AUDIO_TRAIT_MAP = {
296
- audio: {
297
- trait: "audio",
298
- components: ["AmbientAudioComponent"],
299
- level: "full",
300
- imports: ["AVFoundation"],
301
- generate: (varName, config) => {
302
- const src = config.src || config.source || "";
303
- const loop = config.loop ?? false;
304
- return [
305
- `if let audioResource = try? await AudioFileResource(named: "${src}") {`,
306
- ` let controller = ${varName}.prepareAudio(audioResource)`,
307
- loop ? ` controller.gain = .decibels(-6)` : "",
308
- ` controller.play()`,
309
- `}`
310
- ].filter(Boolean);
311
- }
312
- },
313
- spatial_audio: {
314
- trait: "spatial_audio",
315
- components: ["SpatialAudioComponent"],
316
- level: "full",
317
- generate: (varName, config) => {
318
- const refDistance = config.refDistance ?? 1;
319
- const rolloff = config.rolloff ?? 1;
320
- return [
321
- `var ${varName}SpatialAudio = SpatialAudioComponent()`,
322
- `${varName}SpatialAudio.gain = .decibels(0)`,
323
- `${varName}SpatialAudio.directivity = .beam(focus: 0.5)`,
324
- `${varName}.components.set(${varName}SpatialAudio)`,
325
- `// Reference distance: ${refDistance}, rolloff: ${rolloff}`
326
- ];
327
- }
328
- },
329
- ambisonics: {
330
- trait: "ambisonics",
331
- components: ["AmbientAudioComponent"],
332
- level: "full",
333
- generate: (varName, config) => {
334
- const src = config.src || config.source || "ambisonic_soundscape";
335
- const loop = config.loop ?? true;
336
- return [
337
- `// @ambisonics \u2014 AmbientAudioComponent renders with 3DOF (head + source rotation)`,
338
- `${varName}.components.set(AmbientAudioComponent())`,
339
- `if let resource = try? await AudioFileResource(named: "${src}", configuration: .init(shouldLoop: ${loop}, loadingStrategy: .stream)) {`,
340
- ` ${varName}.playAudio(resource)`,
341
- `}`
342
- ];
343
- }
344
- },
345
- reverb_zone: {
346
- trait: "reverb_zone",
347
- components: ["ReverbComponent"],
348
- level: "full",
349
- minVersion: "2.0",
350
- generate: (varName, config) => {
351
- const preset = String(config.preset || "largeRoom");
352
- const presetMap = {
353
- smallRoom: ".smallRoom",
354
- mediumRoom: ".mediumRoom",
355
- largeRoom: ".largeRoom",
356
- veryLargeRoom: ".veryLargeRoom",
357
- automatic: ".automatic"
358
- };
359
- return [
360
- `// @reverb_zone \u2014 one active ReverbComponent per entity hierarchy`,
361
- `${varName}.components.set(ReverbComponent(reverb: .preset(${presetMap[preset] || ".largeRoom"})))`
362
- ];
363
- }
364
- },
365
- audio_occlusion: {
366
- trait: "audio_occlusion",
367
- components: ["SpatialAudioComponent", "CollisionComponent"],
368
- level: "full",
369
- generate: (varName, config) => {
370
- const focus = config.focus ?? 0.25;
371
- return [
372
- `// @audio_occlusion \u2014 RealityKit ray-traces occlusion automatically`,
373
- `// Entities with CollisionComponent block audio from SpatialAudioComponent sources`,
374
- `var ${varName}SpatialAudio = SpatialAudioComponent()`,
375
- `${varName}SpatialAudio.directivity = .beam(focus: ${focus})`,
376
- `${varName}SpatialAudio.distanceAttenuation = .rolloff(factor: 1.0)`,
377
- `${varName}.components.set(${varName}SpatialAudio)`,
378
- `${varName}.components.set(CollisionComponent(shapes: [.generateConvex(from: ${varName}Mesh)]))`
379
- ];
380
- }
381
- },
382
- head_tracked_audio: {
383
- trait: "head_tracked_audio",
384
- components: ["SpatialAudioComponent"],
385
- level: "full",
386
- generate: (varName) => [
387
- `var ${varName}Audio = SpatialAudioComponent()`,
388
- `${varName}Audio.isHeadTracked = true`,
389
- `${varName}.components.set(${varName}Audio)`
390
- ]
391
- }
392
- };
393
- AR_TRAIT_MAP = {
394
- anchor: {
395
- trait: "anchor",
396
- components: ["AnchoringComponent"],
397
- level: "full",
398
- generate: (varName, config) => {
399
- const target = String(config.anchor_type || "plane");
400
- const targetMap = {
401
- plane: ".plane(.horizontal, classification: .any, minimumBounds: SIMD2<Float>(0.1, 0.1))",
402
- vertical: ".plane(.vertical, classification: .any, minimumBounds: SIMD2<Float>(0.1, 0.1))",
403
- image: '.image(group: "ImageTargets", name: "target")',
404
- face: ".face",
405
- hand: ".hand(.left, location: .palm)",
406
- world: ".world(transform: .identity)"
407
- };
408
- return [
409
- `${varName}.components.set(AnchoringComponent(${targetMap[target] || ".world(transform: .identity)"}))`
410
- ];
411
- }
412
- },
413
- plane_detection: {
414
- trait: "plane_detection",
415
- components: [],
416
- level: "full",
417
- imports: ["ARKit"],
418
- generate: (varName, config) => {
419
- const types = config.types || ["horizontal", "vertical"];
420
- const alignments = types.map((t) => `.${t}`).join(", ");
421
- return [
422
- `// @plane_detection \u2014 ARKit PlaneDetectionProvider (requires Full Space)`,
423
- `// Info.plist: NSWorldSensingUsageDescription`,
424
- `let ${varName}PlaneProvider = PlaneDetectionProvider(alignments: [${alignments}])`,
425
- `try await arkitSession.run([${varName}PlaneProvider])`,
426
- `Task {`,
427
- ` for await update in ${varName}PlaneProvider.anchorUpdates {`,
428
- ` let anchor = update.anchor`,
429
- ` let extent = anchor.geometry.extent`,
430
- ` switch update.event {`,
431
- ` case .added, .updated:`,
432
- ` let plane = ModelEntity(mesh: .generatePlane(width: extent.width, height: extent.height))`,
433
- ` plane.transform = Transform(matrix: anchor.originFromAnchorTransform * extent.anchorFromExtentTransform)`,
434
- ` case .removed: break`,
435
- ` }`,
436
- ` }`,
437
- `}`
438
- ];
439
- }
440
- },
441
- mesh_detection: {
442
- trait: "mesh_detection",
443
- components: [],
444
- level: "full",
445
- imports: ["ARKit"],
446
- generate: (varName) => [
447
- `// @mesh_detection \u2014 ARKit SceneReconstructionProvider (requires Full Space)`,
448
- `// Info.plist: NSWorldSensingUsageDescription`,
449
- `let ${varName}SceneProvider = SceneReconstructionProvider()`,
450
- `try await arkitSession.run([${varName}SceneProvider])`,
451
- `Task {`,
452
- ` for await update in ${varName}SceneProvider.anchorUpdates {`,
453
- ` let anchor = update.anchor`,
454
- ` switch update.event {`,
455
- ` case .added, .updated:`,
456
- ` let shape = try await ShapeResource.generateStaticMesh(from: anchor)`,
457
- ` let meshEntity = ModelEntity()`,
458
- ` meshEntity.model = .init(mesh: .generateSphere(radius: 0), materials: [OcclusionMaterial()])`,
459
- ` meshEntity.collision = CollisionComponent(shapes: [shape], isStatic: true)`,
460
- ` meshEntity.physicsBody = PhysicsBodyComponent(mode: .static)`,
461
- ` meshEntity.transform = Transform(matrix: anchor.originFromAnchorTransform)`,
462
- ` case .removed: break`,
463
- ` }`,
464
- ` }`,
465
- `}`
466
- ]
467
- },
468
- hand_tracking: {
469
- trait: "hand_tracking",
470
- components: [],
471
- level: "full",
472
- imports: ["ARKit"],
473
- generate: (varName) => [
474
- `// @hand_tracking \u2014 ARKit HandTrackingProvider (requires Full Space)`,
475
- `// Info.plist: NSHandsTrackingUsageDescription`,
476
- `let ${varName}HandProvider = HandTrackingProvider()`,
477
- `try await arkitSession.run([${varName}HandProvider])`,
478
- `Task {`,
479
- ` for await update in ${varName}HandProvider.anchorUpdates {`,
480
- ` let anchor = update.anchor`,
481
- ` guard anchor.isTracked, let skeleton = anchor.handSkeleton else { continue }`,
482
- ` let tips: [HandSkeleton.JointName] = [.thumbTip, .indexFingerTip, .middleFingerTip, .ringFingerTip, .littleFingerTip]`,
483
- ` for joint in tips {`,
484
- ` let j = skeleton.joint(joint)`,
485
- ` guard j.isTracked else { continue }`,
486
- ` let worldPos = anchor.originFromAnchorTransform * j.anchorFromJointTransform`,
487
- ` // chirality: anchor.chirality (.left / .right)`,
488
- ` }`,
489
- ` }`,
490
- `}`
491
- ]
492
- },
493
- eye_tracking: {
494
- trait: "eye_tracking",
495
- components: ["HoverEffectComponent", "InputTargetComponent", "CollisionComponent"],
496
- level: "full",
497
- generate: (varName) => [
498
- `// @eye_tracking \u2014 raw gaze data is system-private on visionOS`,
499
- `// Use HoverEffectComponent for gaze-driven visual feedback`,
500
- `${varName}.components.set(InputTargetComponent())`,
501
- `${varName}.components.set(CollisionComponent(shapes: [.generateConvex(from: ${varName}Mesh)]))`,
502
- `${varName}.components.set(HoverEffectComponent())`
503
- ]
504
- },
505
- occlusion: {
506
- trait: "occlusion",
507
- components: [],
508
- level: "full",
509
- generate: (_varName) => [
510
- `// @occlusion \u2014 RealityKit handles automatically`,
511
- `// Ensure object has ModelComponent with proper materials`
512
- ]
513
- },
514
- light_estimation: {
515
- trait: "light_estimation",
516
- components: ["ImageBasedLightComponent"],
517
- level: "full",
518
- generate: (varName) => [
519
- `// @light_estimation \u2014 ARKit provides environmental lighting automatically`,
520
- `${varName}.components.set(ImageBasedLightReceiverComponent(imageBasedLight: root))`
521
- ]
522
- },
523
- world_anchor: {
524
- trait: "world_anchor",
525
- components: ["AnchoringComponent"],
526
- level: "full",
527
- generate: (varName, config) => {
528
- const persistent = config.persistent ?? true;
529
- return [
530
- `${varName}.components.set(AnchoringComponent(.world(transform: .identity)))`,
531
- persistent ? `// Persist via WorldTrackingProvider.addAnchor()` : `// Non-persistent world anchor`
532
- ];
533
- }
534
- },
535
- geospatial: {
536
- trait: "geospatial",
537
- components: [],
538
- level: "unsupported",
539
- generate: (_, config) => [
540
- `// @geospatial \u2014 NOT available on visionOS (no GPS module on Apple Vision Pro)`,
541
- `// Latitude: ${config.latitude}, Longitude: ${config.longitude}`,
542
- `// Workaround: use WorldAnchor with GPS coordinates from a paired iPhone`
543
- ]
544
- }
545
- };
546
- VISUAL_TRAIT_MAP = {
547
- visible: {
548
- trait: "visible",
549
- components: [],
550
- level: "full",
551
- generate: (varName, config) => {
552
- const visible = config.visible ?? true;
553
- return [visible ? "" : `${varName}.isEnabled = false`].filter(Boolean);
554
- }
555
- },
556
- invisible: {
557
- trait: "invisible",
558
- components: [],
559
- level: "full",
560
- generate: (varName) => [`${varName}.isEnabled = false`]
561
- },
562
- billboard: {
563
- trait: "billboard",
564
- components: ["BillboardComponent"],
565
- level: "full",
566
- generate: (varName) => [
567
- `// @billboard \u2014 built-in RealityKit BillboardComponent (privacy-preserving)`,
568
- `${varName}.components.set(BillboardComponent())`
569
- ]
570
- },
571
- particle_emitter: {
572
- trait: "particle_emitter",
573
- components: ["ParticleEmitterComponent"],
574
- level: "full",
575
- minVersion: "2.0",
576
- generate: (varName, config) => {
577
- const rate = config.rate ?? 100;
578
- const lifetime = config.lifetime ?? 1;
579
- return [
580
- `var ${varName}Particles = ParticleEmitterComponent()`,
581
- `${varName}Particles.emitterShape = .sphere`,
582
- `${varName}Particles.birthRate = ${rate}`,
583
- `${varName}Particles.lifeSpan = ${lifetime}`,
584
- `${varName}.components.set(${varName}Particles)`
585
- ];
586
- }
587
- },
588
- animated: {
589
- trait: "animated",
590
- components: [],
591
- level: "full",
592
- generate: (varName, config) => {
593
- const clip = config.clip || "";
594
- const loop = config.loop ?? true;
595
- const speed = config.speed ?? 1;
596
- const transition = config.transition ?? 0.25;
597
- const lines = [`// @animated \u2014 play animation from USDZ or programmatic AnimationResource`];
598
- if (clip) {
599
- lines.push(
600
- `if let animation = ${varName}.availableAnimations.first(where: { $0.name == "${clip}" }) {`,
601
- ` let controller = ${varName}.playAnimation(animation${loop ? ".repeat(duration: .infinity)" : ""}, transitionDuration: ${transition})`,
602
- ` controller.speed = ${speed}`,
603
- `}`
604
- );
605
- } else {
606
- lines.push(
607
- `for animation in ${varName}.availableAnimations {`,
608
- ` let controller = ${varName}.playAnimation(animation${loop ? ".repeat(duration: .infinity)" : ""}, transitionDuration: ${transition})`,
609
- ` controller.speed = ${speed}`,
610
- `}`
611
- );
612
- }
613
- return lines;
614
- }
615
- },
616
- lod: {
617
- trait: "lod",
618
- components: [],
619
- level: "partial",
620
- generate: (varName, config) => {
621
- const distances = config.distances || [5, 15];
622
- const d = distances;
623
- return [
624
- `// @lod \u2014 no built-in LOD in RealityKit; use custom ECS System`,
625
- `// Requires WorldTrackingProvider for camera position (Full Space only)`,
626
- `struct ${varName}LODComponent: Component, Codable {`,
627
- ` var thresholds: [Float] = [${d[0] ?? 5}, ${d[1] ?? 15}]`,
628
- ` var currentLevel: Int = 0`,
629
- `}`,
630
- `// Register: ${varName}LODComponent.registerComponent()`,
631
- `// In LODSystem.update(): query camera distance, swap ModelComponent.mesh`,
632
- `${varName}.components.set(${varName}LODComponent())`
633
- ];
634
- }
635
- },
636
- shadow_caster: {
637
- trait: "shadow_caster",
638
- components: ["GroundingShadowComponent"],
639
- level: "full",
640
- generate: (varName) => [
641
- `${varName}.components.set(GroundingShadowComponent(castsShadow: true))`
642
- ]
643
- },
644
- shadow_receiver: {
645
- trait: "shadow_receiver",
646
- components: ["GroundingShadowComponent"],
647
- level: "full",
648
- generate: (varName) => [
649
- `${varName}.components.set(GroundingShadowComponent(castsShadow: false))`
650
- ]
651
- }
652
- };
653
- ACCESSIBILITY_TRAIT_MAP = {
654
- accessible: {
655
- trait: "accessible",
656
- components: ["AccessibilityComponent"],
657
- level: "full",
658
- generate: (varName, config) => {
659
- const label = config.label || "";
660
- const hint = config.hint || "";
661
- const isButton = config.isButton ?? false;
662
- const lines = [`var ${varName}Accessibility = AccessibilityComponent()`];
663
- if (label) lines.push(`${varName}Accessibility.label = "${label}"`);
664
- if (hint) lines.push(`${varName}Accessibility.hint = "${hint}"`);
665
- if (isButton) lines.push(`${varName}Accessibility.isButton = true`);
666
- lines.push(`${varName}.components.set(${varName}Accessibility)`);
667
- return lines;
668
- }
669
- },
670
- alt_text: {
671
- trait: "alt_text",
672
- components: ["AccessibilityComponent"],
673
- level: "full",
674
- generate: (varName, config) => {
675
- const text = config.text || "";
676
- return [
677
- `var ${varName}Accessibility = AccessibilityComponent()`,
678
- `${varName}Accessibility.label = "${text}"`,
679
- `${varName}.components.set(${varName}Accessibility)`
680
- ];
681
- }
682
- },
683
- high_contrast: {
684
- trait: "high_contrast",
685
- components: [],
686
- level: "full",
687
- generate: (varName) => [
688
- `// @high_contrast \u2014 SwiftUI: @Environment(\\.colorSchemeContrast) var contrast`,
689
- `// UIKit: UIAccessibility.isDarkerSystemColorsEnabled`,
690
- `if UIAccessibility.isDarkerSystemColorsEnabled {`,
691
- ` // Apply high-contrast materials (WCAG 7:1 ratio)`,
692
- ` var ${varName}Material = SimpleMaterial()`,
693
- ` ${varName}Material.color = .init(tint: .black)`,
694
- ` ${varName}.model?.materials = [${varName}Material]`,
695
- `}`
696
- ]
697
- },
698
- motion_reduced: {
699
- trait: "motion_reduced",
700
- components: [],
701
- level: "full",
702
- generate: (varName) => [
703
- `// @motion_reduced \u2014 SwiftUI: @Environment(\\.accessibilityReduceMotion) var reduceMotion`,
704
- `if UIAccessibility.isReduceMotionEnabled {`,
705
- ` // Skip animations, use instant transitions`,
706
- ` ${varName}.stopAllAnimations()`,
707
- `} else {`,
708
- ` for animation in ${varName}.availableAnimations {`,
709
- ` ${varName}.playAnimation(animation.repeat(duration: .infinity))`,
710
- ` }`,
711
- `}`
712
- ]
713
- }
714
- };
715
- UI_TRAIT_MAP = {
716
- ui_floating: {
717
- trait: "ui_floating",
718
- components: [],
719
- level: "full",
720
- generate: (varName, config) => {
721
- const distance = config.distance ?? 0.3;
722
- return [
723
- `// @ui_floating \u2014 ViewAttachmentComponent (visionOS 2.0+)`,
724
- `let ${varName}Panel = Entity()`,
725
- `${varName}Panel.components.set(ViewAttachmentComponent(rootView:`,
726
- ` VStack {`,
727
- ` Text("${config.title || "Info"}")`,
728
- ` .font(.headline)`,
729
- ` }`,
730
- ` .padding()`,
731
- ` .glassBackgroundEffect()`,
732
- `))`,
733
- `${varName}Panel.position = SIMD3<Float>(0, Float(${distance}), 0)`,
734
- `${varName}.addChild(${varName}Panel)`
735
- ];
736
- }
737
- },
738
- ui_anchored: {
739
- trait: "ui_anchored",
740
- components: ["AnchoringComponent"],
741
- level: "full",
742
- generate: (varName, config) => {
743
- const to = String(config.to || "world");
744
- const anchorMap = {
745
- world: ".world(transform: .identity)",
746
- head: ".head",
747
- left_hand: ".hand(.left, location: .palm)",
748
- right_hand: ".hand(.right, location: .palm)"
749
- };
750
- return [
751
- `${varName}.components.set(AnchoringComponent(${anchorMap[to] || ".world(transform: .identity)"}))`
752
- ];
753
- }
754
- },
755
- ui_hand_menu: {
756
- trait: "ui_hand_menu",
757
- components: ["AnchoringComponent"],
758
- level: "full",
759
- generate: (varName, config) => {
760
- const hand = config.hand || "left";
761
- const trigger = config.trigger || "palm_up";
762
- return [
763
- `${varName}.components.set(AnchoringComponent(.hand(.${hand}, location: .palm)))`,
764
- `// Trigger: ${trigger} \u2014 implement gesture detection`
765
- ];
766
- }
767
- },
768
- ui_billboard: {
769
- trait: "ui_billboard",
770
- components: ["BillboardComponent"],
771
- level: "full",
772
- generate: (varName) => [
773
- `// @ui_billboard \u2014 BillboardComponent keeps UI facing the user`,
774
- `${varName}.components.set(BillboardComponent())`
775
- ]
776
- },
777
- ui_docked: {
778
- trait: "ui_docked",
779
- components: [],
780
- level: "full",
781
- generate: (varName, config) => {
782
- const position = String(config.position || "bottom");
783
- const posMap = {
784
- bottom: ".scene(.bottom)",
785
- top: ".scene(.top)",
786
- leading: ".scene(.leading)",
787
- trailing: ".scene(.trailing)"
788
- };
789
- return [
790
- `// @ui_docked \u2014 SwiftUI .ornament() modifier on window content`,
791
- `// .ornament(visibility: .visible, attachmentAnchor: ${posMap[position] || ".scene(.bottom)"}, contentAlignment: .${position}) {`,
792
- `// HStack {`,
793
- `// // ${varName} docked controls`,
794
- `// }`,
795
- `// .padding()`,
796
- `// .glassBackgroundEffect()`,
797
- `// }`
798
- ];
799
- }
800
- }
801
- };
802
- PORTAL_TRAIT_MAP = {
803
- portal: {
804
- trait: "portal",
805
- components: ["PortalComponent", "WorldComponent"],
806
- level: "full",
807
- minVersion: "1.0",
808
- generate: (varName, config) => {
809
- config.target_world || "portalWorld";
810
- return [
811
- `let ${varName}World = Entity()`,
812
- `${varName}World.components.set(WorldComponent())`,
813
- `${varName}.components.set(PortalComponent(target: ${varName}World))`,
814
- `// Add content to ${varName}World for portal interior`
815
- ];
816
- }
817
- },
818
- volume: {
819
- trait: "volume",
820
- components: [],
821
- level: "full",
822
- generate: (varName, config) => {
823
- const size = config.size || [0.6, 0.4, 0.4];
824
- const s = size;
825
- return [
826
- `// @volume \u2014 Scene-level: add WindowGroup to your App struct`,
827
- `// WindowGroup(id: "${varName}Volume") {`,
828
- `// ${varName}VolumetricView()`,
829
- `// }`,
830
- `// .windowStyle(.volumetric)`,
831
- `// .defaultSize(width: ${s[0]}, height: ${s[1]}, depth: ${s[2]}, in: .meters)`,
832
- `//`,
833
- `// Open with: openWindow(id: "${varName}Volume")`
834
- ];
835
- }
836
- },
837
- immersive: {
838
- trait: "immersive",
839
- components: [],
840
- level: "full",
841
- generate: (varName, config) => {
842
- const style = String(config.style || "mixed");
843
- const styleMap = {
844
- mixed: ".mixed",
845
- progressive: ".progressive",
846
- full: ".full"
847
- };
848
- return [
849
- `// @immersive \u2014 Scene-level: add ImmersiveSpace to your App struct`,
850
- `// ImmersiveSpace(id: "${varName}Space") {`,
851
- `// ${varName}ImmersiveView()`,
852
- `// }`,
853
- `// .immersionStyle(selection: $immersionStyle, in: ${styleMap[style] || ".mixed"})`,
854
- `//`,
855
- `// Open: let result = await openImmersiveSpace(id: "${varName}Space")`,
856
- `// Dismiss: await dismissImmersiveSpace()`
857
- ];
858
- }
859
- }
860
- };
861
- V43_TRAIT_MAP = {
862
- spatial_persona: {
863
- trait: "spatial_persona",
864
- components: [],
865
- level: "partial",
866
- minVersion: "2.0",
867
- imports: ["GroupActivities"],
868
- generate: (varName, config) => {
869
- const style = String(config.style || "realistic");
870
- return [
871
- `// @spatial_persona \u2014 visionOS 2.0 Spatial Persona (GroupActivities)`,
872
- `// Requires SharePlay session; persona renders at ${varName} position`,
873
- `// PersonaStyle: ${style}`,
874
- `// TODO: configure SystemCoordinator and spatial template`
875
- ];
876
- }
877
- },
878
- shareplay: {
879
- trait: "shareplay",
880
- components: [],
881
- level: "partial",
882
- minVersion: "1.0",
883
- imports: ["GroupActivities"],
884
- generate: (varName, config) => {
885
- const activity = String(config.activity_type || "custom");
886
- return [
887
- `// @shareplay \u2014 SharePlay GroupActivity`,
888
- `// Activity type: ${activity}`,
889
- `// TODO: conform to GroupActivity protocol and activate session`,
890
- `// struct HoloActivity: GroupActivity { var metadata = GroupActivityMetadata() }`
891
- ];
892
- }
893
- },
894
- object_tracking: {
895
- trait: "object_tracking",
896
- components: ["AnchoringComponent"],
897
- level: "partial",
898
- minVersion: "2.0",
899
- imports: ["ARKit"],
900
- generate: (varName, config) => {
901
- const referenceObject = String(config.reference_object || "MyObject");
902
- return [
903
- `// @object_tracking \u2014 ARKit ObjectTrackingProvider (visionOS 2.0)`,
904
- `// Info.plist: NSWorldSensingUsageDescription`,
905
- `let ${varName}ObjProvider = ObjectTrackingProvider(referenceObjects: [])`,
906
- `// TODO: load ReferenceObject from .referenceobject bundle for ${referenceObject}`,
907
- `try await arkitSession.run([${varName}ObjProvider])`
908
- ];
909
- }
910
- },
911
- scene_reconstruction: {
912
- trait: "scene_reconstruction",
913
- components: [],
914
- level: "partial",
915
- minVersion: "1.0",
916
- imports: ["ARKit"],
917
- generate: (varName, config) => {
918
- const mode = String(config.mode || "mesh");
919
- return [
920
- `// @scene_reconstruction \u2014 SceneReconstructionProvider (mode: ${mode})`,
921
- `// Info.plist: NSWorldSensingUsageDescription`,
922
- `let ${varName}SceneProvider = SceneReconstructionProvider(modes: [.${mode}])`,
923
- `try await arkitSession.run([${varName}SceneProvider])`,
924
- `Task {`,
925
- ` for await update in ${varName}SceneProvider.anchorUpdates {`,
926
- ` // handle MeshAnchor updates`,
927
- ` }`,
928
- `}`
929
- ];
930
- }
931
- },
932
- volumetric_window: {
933
- trait: "volumetric_window",
934
- components: ["ModelComponent"],
935
- level: "full",
936
- minVersion: "1.0",
937
- generate: (varName, config) => {
938
- const width = Number(config.width || 0.5);
939
- const height = Number(config.height || 0.5);
940
- const depth = Number(config.depth || 0.5);
941
- return [
942
- `// @volumetric_window \u2014 WindowGroup with volumetric style`,
943
- `// In App.swift: WindowGroup { ContentView() }.windowStyle(.volumetric)`,
944
- `// .defaultSize(width: ${width}, height: ${height}, depth: ${depth}, in: .meters)`,
945
- `${varName}.components.set(ModelComponent(mesh: .generateBox(size: [${width}, ${height}, ${depth}]), materials: []))`
946
- ];
947
- }
948
- },
949
- spatial_navigation: {
950
- trait: "spatial_navigation",
951
- components: [],
952
- level: "comment",
953
- minVersion: "1.0",
954
- generate: (varName, _config) => [
955
- `// @spatial_navigation \u2014 spatial navigation for ${varName}`,
956
- `// TODO: implement NavigationSplitView or custom spatial nav`
957
- ]
958
- },
959
- eye_tracked: {
960
- trait: "eye_tracked",
961
- components: ["InputTargetComponent", "HoverEffectComponent"],
962
- level: "full",
963
- minVersion: "1.0",
964
- generate: (varName, _config) => [
965
- `${varName}.components.set(InputTargetComponent())`,
966
- `${varName}.components.set(HoverEffectComponent())`,
967
- `// Eye tracking: entity responds to gaze via SwiftUI .onHover or RealityView gesture`
968
- ]
969
- },
970
- realitykit_mesh: {
971
- trait: "realitykit_mesh",
972
- components: ["ModelComponent"],
973
- level: "full",
974
- minVersion: "1.0",
975
- generate: (varName, config) => {
976
- const shape = String(config.shape || "box");
977
- const shapeMap = {
978
- box: ".generateBox(size: [0.1, 0.1, 0.1])",
979
- sphere: ".generateSphere(radius: 0.05)",
980
- cylinder: ".generateCylinder(height: 0.1, radius: 0.05)",
981
- plane: ".generatePlane(width: 0.5, height: 0.5)"
982
- };
983
- return [
984
- `${varName}.components.set(ModelComponent(mesh: .${shapeMap[shape] || shapeMap["box"]}, materials: [SimpleMaterial()]))`
985
- ];
986
- }
987
- },
988
- eye_hand_fusion: {
989
- trait: "eye_hand_fusion",
990
- components: ["InputTargetComponent"],
991
- level: "partial",
992
- minVersion: "2.0",
993
- imports: ["ARKit"],
994
- generate: (varName, _config) => [
995
- `// @eye_hand_fusion \u2014 combined eye + hand tracking (visionOS 2.0)`,
996
- `let ${varName}HandProvider = HandTrackingProvider()`,
997
- `try await arkitSession.run([${varName}HandProvider])`,
998
- `// TODO: correlate HandAnchor joint positions with gaze raycast hit`
999
- ]
1000
- },
1001
- // AI Generation traits — comment-level stubs (GPU compute not native to RealityKit)
1002
- controlnet: {
1003
- trait: "controlnet",
1004
- components: [],
1005
- level: "comment",
1006
- generate: (_varName, config) => [
1007
- `// @controlnet \u2014 ControlNet image generation (model: ${String(config.model || "canny")})`,
1008
- `// TODO: route to CoreML / remote inference endpoint`
1009
- ]
1010
- },
1011
- ai_texture_gen: {
1012
- trait: "ai_texture_gen",
1013
- components: ["ModelComponent"],
1014
- level: "comment",
1015
- generate: (varName, config) => [
1016
- `// @ai_texture_gen \u2014 AI texture generation (style: ${String(config.style || "photorealistic")})`,
1017
- `// TODO: generate texture via CoreML or API, then assign to ${varName} ModelComponent`
1018
- ]
1019
- },
1020
- diffusion_realtime: {
1021
- trait: "diffusion_realtime",
1022
- components: [],
1023
- level: "comment",
1024
- generate: (_varName, config) => [
1025
- `// @diffusion_realtime \u2014 real-time diffusion rendering (backend: ${String(config.backend || "metal")})`,
1026
- `// TODO: integrate Metal Performance Shaders or CoreML pipeline`
1027
- ]
1028
- },
1029
- ai_upscaling: {
1030
- trait: "ai_upscaling",
1031
- components: [],
1032
- level: "comment",
1033
- generate: (_varName, config) => [
1034
- `// @ai_upscaling \u2014 AI upscaling (factor: ${String(config.factor || 2)}x)`,
1035
- `// TODO: apply CoreML super-resolution model to texture`
1036
- ]
1037
- },
1038
- ai_inpainting: {
1039
- trait: "ai_inpainting",
1040
- components: [],
1041
- level: "comment",
1042
- generate: (_varName, _config) => [
1043
- `// @ai_inpainting \u2014 AI inpainting`,
1044
- `// TODO: apply mask-based inpainting via CoreML`
1045
- ]
1046
- },
1047
- neural_link: {
1048
- trait: "neural_link",
1049
- components: [],
1050
- level: "comment",
1051
- generate: (_varName, config) => [
1052
- `// @neural_link \u2014 neural interface link (interface: ${String(config.interface_type || "bci")})`,
1053
- `// TODO: implement BCI signal processing pipeline`
1054
- ]
1055
- },
1056
- neural_forge: {
1057
- trait: "neural_forge",
1058
- components: [],
1059
- level: "comment",
1060
- generate: (_varName, _config) => [
1061
- `// @neural_forge \u2014 neural network model forge`,
1062
- `// TODO: integrate on-device CoreML model training`
1063
- ]
1064
- },
1065
- embedding_search: {
1066
- trait: "embedding_search",
1067
- components: [],
1068
- level: "comment",
1069
- generate: (_varName, config) => [
1070
- `// @embedding_search \u2014 vector embedding search (dimensions: ${String(config.dimensions || 1536)})`,
1071
- `// TODO: implement CoreData or CloudKit vector index`
1072
- ]
1073
- },
1074
- ai_npc_brain: {
1075
- trait: "ai_npc_brain",
1076
- components: [],
1077
- level: "comment",
1078
- generate: (_varName, config) => [
1079
- `// @ai_npc_brain \u2014 AI NPC brain (model: ${String(config.model || "llm")})`,
1080
- `// TODO: integrate local LLM or API-based NPC reasoning`
1081
- ]
1082
- },
1083
- vector_db: {
1084
- trait: "vector_db",
1085
- components: [],
1086
- level: "comment",
1087
- generate: (_varName, _config) => [
1088
- `// @vector_db \u2014 vector database`,
1089
- `// TODO: integrate local or remote vector store (e.g. FAISS, Pinecone)`
1090
- ]
1091
- },
1092
- vision: {
1093
- trait: "vision",
1094
- components: [],
1095
- level: "comment",
1096
- imports: ["Vision"],
1097
- generate: (_varName, config) => [
1098
- `// @vision \u2014 Vision framework (task: ${String(config.task || "classification")})`,
1099
- `// TODO: configure VNRequest pipeline for ${String(config.task || "classification")}`
1100
- ]
1101
- },
1102
- spatial_awareness: {
1103
- trait: "spatial_awareness",
1104
- components: [],
1105
- level: "comment",
1106
- minVersion: "1.0",
1107
- imports: ["ARKit"],
1108
- generate: (_varName, _config) => [
1109
- `// @spatial_awareness \u2014 spatial scene understanding`,
1110
- `// TODO: combine PlaneDetectionProvider + SceneReconstructionProvider`
1111
- ]
1112
- },
1113
- neural_animation: {
1114
- trait: "neural_animation",
1115
- components: [],
1116
- level: "comment",
1117
- generate: (_varName, config) => [
1118
- `// @neural_animation \u2014 neural network-driven animation (style: ${String(config.style || "motion_matching")})`,
1119
- `// TODO: integrate CoreML pose prediction with AnimationPlaybackController`
1120
- ]
1121
- },
1122
- ai_vision: {
1123
- trait: "ai_vision",
1124
- components: [],
1125
- level: "comment",
1126
- imports: ["Vision"],
1127
- generate: (_varName, config) => [
1128
- `// @ai_vision \u2014 AI vision processing (task: ${String(config.task || "detection")})`,
1129
- `// TODO: configure VNDetectRectanglesRequest or custom CoreML model`
1130
- ]
1131
- }
1132
- };
1133
- VISIONOS_TRAIT_MAP = {
1134
- ...PHYSICS_TRAIT_MAP,
1135
- ...INTERACTION_TRAIT_MAP,
1136
- ...AUDIO_TRAIT_MAP,
1137
- ...AR_TRAIT_MAP,
1138
- ...VISUAL_TRAIT_MAP,
1139
- ...ACCESSIBILITY_TRAIT_MAP,
1140
- ...UI_TRAIT_MAP,
1141
- ...PORTAL_TRAIT_MAP,
1142
- ...V43_TRAIT_MAP
1143
- };
1144
- }
1145
- });
1146
-
1147
- // src/compiler/VisionOSCompiler.ts
1148
- var VisionOSCompiler_exports = {};
1149
- chunkEGIZHYJP_cjs.__export(VisionOSCompiler_exports, {
1150
- VisionOSCompiler: () => exports.VisionOSCompiler
1151
- });
1152
- exports.VisionOSCompiler = void 0;
1153
- var init_VisionOSCompiler = chunkEGIZHYJP_cjs.__esm({
1154
- "src/compiler/VisionOSCompiler.ts"() {
1155
- init_VisionOSTraitMap();
1156
- chunkQHVVVN47_cjs.init_CompilerBase();
1157
- chunkQHVVVN47_cjs.init_ANSNamespace();
1158
- chunkHHS6FMOU_cjs.init_DomainBlockCompilerMixin();
1159
- exports.VisionOSCompiler = class extends chunkQHVVVN47_cjs.CompilerBase {
1160
- constructor(options = {}) {
1161
- super();
1162
- this.compilerName = "VisionOSCompiler";
1163
- this.lines = [];
1164
- this.indentLevel = 0;
1165
- this.options = {
1166
- structName: options.structName || "GeneratedScene",
1167
- indent: options.indent || " ",
1168
- useRealityComposerPro: options.useRealityComposerPro ?? false
1169
- };
1170
- }
1171
- getRequiredCapability() {
1172
- return chunkQHVVVN47_cjs.ANSCapabilityPath.VISIONOS;
1173
- }
1174
- compile(composition, agentToken, outputPath) {
1175
- this.validateCompilerAccess(agentToken, outputPath);
1176
- this.lines = [];
1177
- this.indentLevel = 0;
1178
- this.emit("// Auto-generated by HoloScript VisionOSCompiler");
1179
- this.emit(
1180
- `// Source: composition "${this.escapeStringValue(composition.name, "Swift")}"`
1181
- );
1182
- this.emit("// Do not edit manually \u2014 regenerate from .holo source");
1183
- this.emit("");
1184
- this.emit("import SwiftUI");
1185
- this.emit("import RealityKit");
1186
- this.emit("import RealityKitContent");
1187
- const allTraits = this.collectAllTraits(composition);
1188
- const requiredImports = getRequiredImports(allTraits);
1189
- for (const imp of requiredImports) {
1190
- this.emit(`import ${imp}`);
1191
- }
1192
- if (composition.audio?.length && !requiredImports.includes("AVFoundation")) {
1193
- this.emit("import AVFoundation");
1194
- }
1195
- const minVersion = getMinVisionOSVersion(allTraits);
1196
- if (minVersion !== "1.0") {
1197
- this.emit(`// Requires visionOS ${minVersion}+`);
1198
- }
1199
- this.emit("");
1200
- if (composition.state) {
1201
- this.emit("@Observable");
1202
- this.emit(`class ${this.options.structName}State {`);
1203
- this.indentLevel++;
1204
- for (const prop of composition.state.properties) {
1205
- const swiftType = this.toSwiftType(prop.value);
1206
- const swiftVal = this.toSwiftValue(prop.value);
1207
- this.emit(
1208
- `var ${this.escapeStringValue(prop.key, "Swift")}: ${swiftType} = ${swiftVal}`
1209
- );
1210
- }
1211
- this.indentLevel--;
1212
- this.emit("}");
1213
- this.emit("");
1214
- }
1215
- this.emit(`struct ${this.options.structName}: View {`);
1216
- this.indentLevel++;
1217
- if (composition.state) {
1218
- this.emit(`@State private var state = ${this.options.structName}State()`);
1219
- this.emit("");
1220
- }
1221
- this.emit("var body: some View {");
1222
- this.indentLevel++;
1223
- this.emit("RealityView { content in");
1224
- this.indentLevel++;
1225
- this.emit("let root = Entity()");
1226
- this.emit(`root.name = "${this.escapeStringValue(composition.name, "Swift")}"`);
1227
- if (composition.environment) {
1228
- this.compileEnvironment(composition.environment);
1229
- }
1230
- if (composition.lights) {
1231
- for (const light of composition.lights) {
1232
- this.compileLight(light);
1233
- }
1234
- }
1235
- if (composition.objects) {
1236
- for (const obj of composition.objects) {
1237
- this.compileObject(obj, "root");
1238
- }
1239
- }
1240
- if (composition.spatialGroups) {
1241
- for (const group of composition.spatialGroups) {
1242
- this.compileSpatialGroup(group, "root");
1243
- }
1244
- }
1245
- if (composition.audio) {
1246
- for (const audio of composition.audio) {
1247
- this.compileAudio(audio);
1248
- }
1249
- }
1250
- if (composition.zones) {
1251
- for (const zone of composition.zones) {
1252
- this.compileZone(zone);
1253
- }
1254
- }
1255
- this.emit("");
1256
- this.emit("content.add(root)");
1257
- this.indentLevel--;
1258
- this.emit("}");
1259
- const grabbables = composition.objects?.filter((o) => o.traits?.some((t) => t.name === "grabbable")) || [];
1260
- if (grabbables.length > 0) {
1261
- this.emit(".gesture(DragGesture().targetedToAnyEntity().onChanged { value in");
1262
- this.indentLevel++;
1263
- this.emit(
1264
- "value.entity.position = value.convert(value.location3D, from: .local, to: .scene)"
1265
- );
1266
- this.indentLevel--;
1267
- this.emit("})");
1268
- }
1269
- this.indentLevel--;
1270
- this.emit("}");
1271
- if (composition.timelines) {
1272
- for (const tl of composition.timelines) {
1273
- this.compileTimeline(tl);
1274
- }
1275
- }
1276
- if (composition.transitions) {
1277
- for (const tr of composition.transitions) {
1278
- this.compileTransition(tr);
1279
- }
1280
- }
1281
- this.indentLevel--;
1282
- this.emit("}");
1283
- if (composition.effects) {
1284
- this.emit("");
1285
- this.compileEffects(composition.effects);
1286
- }
1287
- this.compileVisionOSDomainBlocks(composition);
1288
- return this.lines.join("\n");
1289
- }
1290
- compileVisionOSDomainBlocks(composition) {
1291
- const domainBlocks = composition.domainBlocks ?? [];
1292
- if (domainBlocks.length === 0) return;
1293
- this.emit("");
1294
- this.emit("// === v4.2 Domain Blocks ===");
1295
- let blockIdx = 0;
1296
- const compiled = chunkHHS6FMOU_cjs.compileDomainBlocks(
1297
- domainBlocks,
1298
- {
1299
- material: (block) => {
1300
- const mat = chunkHHS6FMOU_cjs.compileMaterialBlock(block);
1301
- return chunkHHS6FMOU_cjs.materialToVisionOS(mat, `db${blockIdx++}`);
1302
- },
1303
- physics: (block) => {
1304
- const phys = chunkHHS6FMOU_cjs.compilePhysicsBlock(block);
1305
- return chunkHHS6FMOU_cjs.physicsToVisionOS(phys, `db${blockIdx++}`);
1306
- },
1307
- vfx: (block) => {
1308
- const ps = chunkHHS6FMOU_cjs.compileParticleBlock(block);
1309
- return chunkHHS6FMOU_cjs.particlesToVisionOS(ps, `db${blockIdx++}`);
1310
- },
1311
- postfx: (block) => {
1312
- const pp = chunkHHS6FMOU_cjs.compilePostProcessingBlock(block);
1313
- return `// Post-Processing: ${pp.keyword} \u2014 configure via RealityKit RenderCallbacks`;
1314
- },
1315
- audio: (block) => {
1316
- const audio = chunkHHS6FMOU_cjs.compileAudioSourceBlock(block);
1317
- return chunkHHS6FMOU_cjs.audioSourceToVisionOS(audio, `db${blockIdx++}`);
1318
- },
1319
- weather: (block) => {
1320
- const weather = chunkHHS6FMOU_cjs.compileWeatherBlock(block);
1321
- const w = weather;
1322
- const layers = w.layers.map((l) => `// Layer: ${l.type} \u2014 ${JSON.stringify(l.properties)}`).join("\n");
1323
- return `// Weather: ${w.keyword} "${w.name || ""}" \u2014 implement via custom RealityKit particles
1324
- ${layers}`;
1325
- }
1326
- },
1327
- (block) => `// Domain block: ${block.domain}/${block.keyword} "${this.escapeStringValue(block.name, "Swift")}"`
1328
- );
1329
- for (const line of compiled) {
1330
- for (const l of line.split("\n")) {
1331
- this.emit(l);
1332
- }
1333
- }
1334
- }
1335
- compileEnvironment(env) {
1336
- this.emit("");
1337
- this.emit("// === Environment ===");
1338
- for (const prop of env.properties) {
1339
- if (prop.key === "preset" || prop.key === "skybox") {
1340
- this.emit(`// Environment preset: "${prop.value}" \u2014 configure via ImageBasedLight`);
1341
- this.emit('if let iblResource = try? await EnvironmentResource(named: "IBL") {');
1342
- this.indentLevel++;
1343
- this.emit("let iblComponent = ImageBasedLightComponent(source: .single(iblResource))");
1344
- this.emit("root.components.set(iblComponent)");
1345
- this.emit("root.components.set(ImageBasedLightReceiverComponent(imageBasedLight: root))");
1346
- this.indentLevel--;
1347
- this.emit("}");
1348
- } else if (prop.key === "fog" && typeof prop.value === "object") {
1349
- this.emit(
1350
- `// Fog: ${JSON.stringify(prop.value)} \u2014 not natively supported, use post-processing`
1351
- );
1352
- } else if (prop.key === "ambient_light") {
1353
- this.emit(`// Ambient light: ${prop.value} \u2014 handled via IBL intensity`);
1354
- }
1355
- }
1356
- }
1357
- compileLight(light) {
1358
- const varName = this.sanitizeName(light.name);
1359
- this.emit("");
1360
- this.emit(`// Light: ${this.escapeStringValue(light.name, "Swift")}`);
1361
- const typeMap = {
1362
- directional: "DirectionalLightComponent",
1363
- point: "PointLightComponent",
1364
- spot: "SpotLightComponent"
1365
- };
1366
- const rkType = typeMap[light.lightType];
1367
- if (rkType) {
1368
- this.emit(`let ${varName} = Entity()`);
1369
- this.emit(
1370
- `${varName}.name = "${this.escapeStringValue(light.name, "Swift")}"`
1371
- );
1372
- const colorProp = light.properties.find((p) => p.key === "color");
1373
- const intensityProp = light.properties.find((p) => p.key === "intensity");
1374
- const posProp = light.properties.find((p) => p.key === "position");
1375
- if (light.lightType === "point") {
1376
- this.emit(`var ${varName}Light = PointLightComponent()`);
1377
- if (colorProp)
1378
- this.emit(`${varName}Light.color = .init(${this.toUIColor(colorProp.value)})`);
1379
- if (intensityProp)
1380
- this.emit(`${varName}Light.intensity = ${intensityProp.value * 1e3}`);
1381
- } else if (light.lightType === "directional") {
1382
- this.emit(`var ${varName}Light = DirectionalLightComponent()`);
1383
- if (colorProp)
1384
- this.emit(`${varName}Light.color = .init(${this.toUIColor(colorProp.value)})`);
1385
- if (intensityProp)
1386
- this.emit(`${varName}Light.intensity = ${intensityProp.value * 1e3}`);
1387
- } else if (light.lightType === "spot") {
1388
- this.emit(`var ${varName}Light = SpotLightComponent()`);
1389
- if (colorProp)
1390
- this.emit(`${varName}Light.color = .init(${this.toUIColor(colorProp.value)})`);
1391
- if (intensityProp)
1392
- this.emit(`${varName}Light.intensity = ${intensityProp.value * 1e3}`);
1393
- }
1394
- this.emit(`${varName}.components.set(${varName}Light)`);
1395
- if (posProp && Array.isArray(posProp.value)) {
1396
- this.emit(`${varName}.position = ${this.toSIMD3(posProp.value)}`);
1397
- }
1398
- this.emit(`root.addChild(${varName})`);
1399
- } else {
1400
- this.emit(`// Light type "${light.lightType}" not directly supported in RealityKit`);
1401
- }
1402
- }
1403
- compileObject(obj, parentVar) {
1404
- if (this.isUIComponent(obj)) {
1405
- this.compileUIComponent(obj, parentVar);
1406
- return;
1407
- }
1408
- const varName = this.sanitizeName(obj.name);
1409
- const meshType = this.findObjProp(obj, "mesh") || this.findObjProp(obj, "type") || "cube";
1410
- const isText = meshType === "text";
1411
- const isModel = !!this.findObjProp(obj, "model") || !!this.findObjProp(obj, "src");
1412
- const isLight = ["directional", "point", "spot", "hemisphere", "ambient", "area"].includes(
1413
- meshType
1414
- );
1415
- const isSparkles = meshType === "sparkles";
1416
- this.emit("");
1417
- this.emit(`// Object: ${this.escapeStringValue(obj.name, "Swift")}`);
1418
- if (isLight) {
1419
- this.emit(
1420
- `// Light object "${this.escapeStringValue(obj.name, "Swift")}" \u2014 handled via light components`
1421
- );
1422
- return;
1423
- }
1424
- if (isText) {
1425
- this.emit(`let ${varName} = Entity()`);
1426
- this.emit(`${varName}.name = "${this.escapeStringValue(obj.name, "Swift")}"`);
1427
- const text = this.findObjProp(obj, "text");
1428
- const fontSize = this.findObjProp(obj, "font_size") || 0.1;
1429
- if (text) {
1430
- this.emit(`let ${varName}Mesh = MeshResource.generateText("${text}",`);
1431
- this.emit(` extrusionDepth: 0.001,`);
1432
- this.emit(` font: .systemFont(ofSize: CGFloat(${fontSize * 10})),`);
1433
- this.emit(` containerFrame: .zero,`);
1434
- this.emit(` alignment: .center,`);
1435
- this.emit(` lineBreakMode: .byWordWrapping)`);
1436
- this.emit(
1437
- `${varName}.components.set(ModelComponent(mesh: ${varName}Mesh, materials: [SimpleMaterial(color: ${this.toUIColor(this.findObjProp(obj, "color") || "#ffffff")}, isMetallic: false)]))`
1438
- );
1439
- }
1440
- } else if (isModel) {
1441
- const src = this.findObjProp(obj, "model") || this.findObjProp(obj, "src");
1442
- this.emit(`let ${varName} = try! await Entity(named: "${src}", in: realityKitContentBundle)`);
1443
- this.emit(`${varName}.name = "${this.escapeStringValue(obj.name, "Swift")}"`);
1444
- } else if (isSparkles) {
1445
- this.emit(`// Sparkles: use ParticleEmitterComponent in visionOS 2.0+`);
1446
- this.emit(`let ${varName} = Entity()`);
1447
- this.emit(`${varName}.name = "${this.escapeStringValue(obj.name, "Swift")}"`);
1448
- } else {
1449
- const meshMap = {
1450
- sphere: ".generateSphere(radius: 0.5)",
1451
- box: ".generateBox(size: 1.0)",
1452
- cube: ".generateBox(size: 1.0)",
1453
- plane: ".generatePlane(width: 1.0, depth: 1.0)",
1454
- cylinder: ".generateBox(size: 1.0)",
1455
- // No cylinder in RealityKit, use box
1456
- cone: ".generateBox(size: 1.0)",
1457
- torus: ".generateBox(size: 1.0)"
1458
- };
1459
- const meshGen = meshMap[meshType] || ".generateBox(size: 1.0)";
1460
- const size = this.findObjProp(obj, "size");
1461
- const radius = this.findObjProp(obj, "radius");
1462
- let meshCall = meshGen;
1463
- if (meshType === "sphere" && radius) {
1464
- meshCall = `.generateSphere(radius: ${radius})`;
1465
- } else if ((meshType === "box" || meshType === "cube") && size) {
1466
- if (Array.isArray(size)) {
1467
- meshCall = `.generateBox(width: ${size[0]}, height: ${size[1]}, depth: ${size[2]})`;
1468
- } else {
1469
- meshCall = `.generateBox(size: ${size})`;
1470
- }
1471
- } else if (meshType === "plane" && size) {
1472
- meshCall = `.generatePlane(width: ${size}, depth: ${size})`;
1473
- }
1474
- this.emit(`let ${varName}Mesh = MeshResource${meshCall}`);
1475
- const material = this.findObjProp(obj, "material");
1476
- if (material && typeof material === "object") {
1477
- const mat = material;
1478
- this.emit(`var ${varName}Material = PhysicallyBasedMaterial()`);
1479
- if (mat.color)
1480
- this.emit(`${varName}Material.baseColor = .init(tint: ${this.toUIColor(mat.color)})`);
1481
- if (mat.roughness !== void 0)
1482
- this.emit(`${varName}Material.roughness = .init(floatLiteral: ${mat.roughness})`);
1483
- if (mat.metalness !== void 0)
1484
- this.emit(`${varName}Material.metallic = .init(floatLiteral: ${mat.metalness})`);
1485
- if (mat.emissive)
1486
- this.emit(
1487
- `${varName}Material.emissiveColor = .init(color: ${this.toUIColor(mat.emissive)})`
1488
- );
1489
- if (mat.emissiveIntensity)
1490
- this.emit(`${varName}Material.emissiveIntensity = ${mat.emissiveIntensity}`);
1491
- this.emit(
1492
- `let ${varName} = ModelEntity(mesh: ${varName}Mesh, materials: [${varName}Material])`
1493
- );
1494
- } else {
1495
- this.emit(
1496
- `let ${varName} = ModelEntity(mesh: ${varName}Mesh, materials: [SimpleMaterial()])`
1497
- );
1498
- }
1499
- this.emit(`${varName}.name = "${this.escapeStringValue(obj.name, "Swift")}"`);
1500
- if (obj.traits) {
1501
- for (const trait of obj.traits) {
1502
- const config = trait.config || {};
1503
- const traitCode = generateTraitCode(trait.name, varName, config);
1504
- for (const line of traitCode) {
1505
- if (line) this.emit(line);
1506
- }
1507
- }
1508
- }
1509
- }
1510
- const pos = this.findObjProp(obj, "position");
1511
- if (pos) this.emit(`${varName}.position = ${this.toSIMD3(pos)}`);
1512
- const rot = this.findObjProp(obj, "rotation");
1513
- if (rot && Array.isArray(rot)) {
1514
- const radX = rot[0] * Math.PI / 180;
1515
- const radY = rot[1] * Math.PI / 180;
1516
- const radZ = rot[2] * Math.PI / 180;
1517
- this.emit(
1518
- `${varName}.orientation = simd_quatf(angle: ${radX.toFixed(4)}, axis: SIMD3<Float>(1, 0, 0)) * simd_quatf(angle: ${radY.toFixed(4)}, axis: SIMD3<Float>(0, 1, 0)) * simd_quatf(angle: ${radZ.toFixed(4)}, axis: SIMD3<Float>(0, 0, 1))`
1519
- );
1520
- }
1521
- const scale = this.findObjProp(obj, "scale");
1522
- if (scale) this.emit(`${varName}.scale = ${this.toSIMD3(scale)}`);
1523
- this.emit(`${parentVar}.addChild(${varName})`);
1524
- if (obj.children) {
1525
- for (const child of obj.children) {
1526
- this.compileObject(child, varName);
1527
- }
1528
- }
1529
- }
1530
- compileSpatialGroup(group, parentVar) {
1531
- const varName = this.sanitizeName(group.name);
1532
- this.emit("");
1533
- this.emit(`// Spatial Group: ${this.escapeStringValue(group.name, "Swift")}`);
1534
- this.emit(`let ${varName} = Entity()`);
1535
- this.emit(`${varName}.name = "${this.escapeStringValue(group.name, "Swift")}"`);
1536
- for (const prop of group.properties) {
1537
- if (prop.key === "position" && Array.isArray(prop.value)) {
1538
- this.emit(`${varName}.position = ${this.toSIMD3(prop.value)}`);
1539
- }
1540
- }
1541
- this.emit(`${parentVar}.addChild(${varName})`);
1542
- for (const obj of group.objects) {
1543
- this.compileObject(obj, varName);
1544
- }
1545
- if (group.groups) {
1546
- for (const sub of group.groups) {
1547
- this.compileSpatialGroup(sub, varName);
1548
- }
1549
- }
1550
- }
1551
- compileAudio(audio) {
1552
- const varName = this.sanitizeName(audio.name);
1553
- this.emit("");
1554
- this.emit(`// Audio: ${this.escapeStringValue(audio.name, "Swift")}`);
1555
- this.emit(`let ${varName} = Entity()`);
1556
- this.emit(`${varName}.name = "${this.escapeStringValue(audio.name, "Swift")}"`);
1557
- const src = audio.properties.find((p) => p.key === "src" || p.key === "source")?.value;
1558
- const spatial = audio.properties.find((p) => p.key === "spatial")?.value;
1559
- if (src) {
1560
- this.emit(`if let audioResource = try? await AudioFileResource(named: "${src}") {`);
1561
- this.indentLevel++;
1562
- if (spatial) {
1563
- this.emit(`let audioController = ${varName}.prepareAudio(audioResource)`);
1564
- this.emit(`${varName}.components.set(SpatialAudioComponent())`);
1565
- } else {
1566
- this.emit(`let audioController = ${varName}.prepareAudio(audioResource)`);
1567
- this.emit(`${varName}.components.set(AmbientAudioComponent())`);
1568
- }
1569
- this.emit("audioController.play()");
1570
- this.indentLevel--;
1571
- this.emit("}");
1572
- }
1573
- const pos = audio.properties.find((p) => p.key === "position")?.value;
1574
- if (pos) this.emit(`${varName}.position = ${this.toSIMD3(pos)}`);
1575
- this.emit(`root.addChild(${varName})`);
1576
- }
1577
- compileZone(zone) {
1578
- const varName = this.sanitizeName(zone.name);
1579
- this.emit("");
1580
- this.emit(`// Zone: ${this.escapeStringValue(zone.name, "Swift")}`);
1581
- this.emit(`let ${varName} = Entity()`);
1582
- this.emit(`${varName}.name = "${this.escapeStringValue(zone.name, "Swift")}"`);
1583
- const shape = zone.properties.find((p) => p.key === "shape")?.value;
1584
- if (shape === "box") {
1585
- const size = zone.properties.find((p) => p.key === "size")?.value;
1586
- if (size && Array.isArray(size)) {
1587
- this.emit(
1588
- `${varName}.components.set(CollisionComponent(shapes: [.generateBox(size: ${this.toSIMD3(size)})]))`
1589
- );
1590
- }
1591
- } else if (shape === "sphere") {
1592
- const radius = zone.properties.find((p) => p.key === "radius")?.value;
1593
- if (radius) {
1594
- this.emit(
1595
- `${varName}.components.set(CollisionComponent(shapes: [.generateSphere(radius: ${radius})]))`
1596
- );
1597
- }
1598
- }
1599
- const pos = zone.properties.find((p) => p.key === "position")?.value;
1600
- if (pos) this.emit(`${varName}.position = ${this.toSIMD3(pos)}`);
1601
- this.emit(`// Zone handlers: ${zone.handlers?.map((h) => h.event).join(", ") || "none"}`);
1602
- this.emit(`root.addChild(${varName})`);
1603
- }
1604
- compileTimeline(tl) {
1605
- const varName = this.sanitizeName(tl.name);
1606
- this.emit("");
1607
- this.emit(`func play${varName}() async {`);
1608
- this.indentLevel++;
1609
- let lastTime = 0;
1610
- for (const entry of tl.entries) {
1611
- const delay = entry.time - lastTime;
1612
- if (delay > 0) {
1613
- this.emit(`try? await Task.sleep(nanoseconds: ${Math.round(delay * 1e9)})`);
1614
- }
1615
- if (entry.action.kind === "animate") {
1616
- this.emit(
1617
- `// Animate "${entry.action.target}": ${JSON.stringify(entry.action.properties)}`
1618
- );
1619
- } else if (entry.action.kind === "emit") {
1620
- this.emit(`// Emit: "${entry.action.event}"`);
1621
- } else if (entry.action.kind === "call") {
1622
- this.emit(`// Call: ${entry.action.method}`);
1623
- }
1624
- lastTime = entry.time;
1625
- }
1626
- if (tl.loop) {
1627
- this.emit(`await play${varName}() // loop`);
1628
- }
1629
- this.indentLevel--;
1630
- this.emit("}");
1631
- }
1632
- compileTransition(tr) {
1633
- const varName = this.sanitizeName(tr.name);
1634
- this.emit("");
1635
- this.emit(`func ${varName}() {`);
1636
- this.indentLevel++;
1637
- const target = tr.properties.find((p) => p.key === "target")?.value;
1638
- this.emit(`// Transition to: "${target}"`);
1639
- this.emit(`// Effect: ${tr.properties.find((p) => p.key === "effect")?.value || "default"}`);
1640
- this.indentLevel--;
1641
- this.emit("}");
1642
- }
1643
- compileEffects(effects) {
1644
- this.emit("// === Post-Processing Notes ===");
1645
- this.emit("// visionOS uses system-level rendering; post-processing is limited.");
1646
- for (const effect of effects.effects) {
1647
- this.emit(`// Effect: ${effect.effectType} \u2014 ${JSON.stringify(effect.properties)}`);
1648
- }
1649
- }
1650
- /**
1651
- * Compile UI component to SwiftUI attachment
1652
- */
1653
- compileUIComponent(obj, parentVar) {
1654
- const varName = this.sanitizeName(obj.name);
1655
- const uiType = this.findObjProp(obj, "type") || "panel";
1656
- this.emit("");
1657
- this.emit(`// UI Component: ${this.escapeStringValue(obj.name, "Swift")}`);
1658
- switch (uiType) {
1659
- case "ui_panel":
1660
- this.compileUIPanel(obj, varName, parentVar);
1661
- break;
1662
- case "ui_button":
1663
- this.compileUIButton(obj, varName, parentVar);
1664
- break;
1665
- case "ui_text":
1666
- this.compileUIText(obj, varName, parentVar);
1667
- break;
1668
- case "ui_slider":
1669
- this.compileUISlider(obj, varName, parentVar);
1670
- break;
1671
- case "ui_input":
1672
- this.compileUIInput(obj, varName, parentVar);
1673
- break;
1674
- case "ui_image":
1675
- this.compileUIImage(obj, varName, parentVar);
1676
- break;
1677
- default:
1678
- this.emit(`// Unknown UI component type: ${uiType}`);
1679
- }
1680
- }
1681
- compileUIPanel(obj, varName, parentVar) {
1682
- const width = this.findObjProp(obj, "width") || 400;
1683
- const height = this.findObjProp(obj, "height") || 300;
1684
- const pos = this.findObjProp(obj, "position");
1685
- this.emit(
1686
- `// SwiftUI Panel attachment for "${this.escapeStringValue(obj.name, "Swift")}"`
1687
- );
1688
- this.emit(`let ${varName} = Entity()`);
1689
- this.emit(`${varName}.name = "${this.escapeStringValue(obj.name, "Swift")}"`);
1690
- if (pos) {
1691
- this.emit(`${varName}.position = ${this.toSIMD3(pos)}`);
1692
- }
1693
- this.emit(`// Attach SwiftUI view via ViewAttachmentComponent`);
1694
- this.emit(`// ${varName}.components.set(ViewAttachmentComponent {`);
1695
- this.emit(`// VStack {`);
1696
- if (obj.children) {
1697
- for (const child of obj.children) {
1698
- this.emit(
1699
- `// // Child: ${this.escapeStringValue(child.name, "Swift")}`
1700
- );
1701
- }
1702
- }
1703
- this.emit(`// }`);
1704
- this.emit(`// .frame(width: ${width}, height: ${height})`);
1705
- this.emit(`// })`);
1706
- this.emit(`${parentVar}.addChild(${varName})`);
1707
- }
1708
- compileUIButton(obj, varName, parentVar) {
1709
- const text = this.findObjProp(obj, "text") || "Button";
1710
- const pos = this.findObjProp(obj, "position");
1711
- this.emit(`let ${varName} = Entity()`);
1712
- this.emit(`${varName}.name = "${this.escapeStringValue(obj.name, "Swift")}"`);
1713
- if (pos) {
1714
- this.emit(`${varName}.position = ${this.toSIMD3(pos)}`);
1715
- }
1716
- this.emit(`// SwiftUI Button: "${text}"`);
1717
- this.emit(`// Implement via ViewAttachmentComponent with Button { Text("${text}") }`);
1718
- this.emit(`${varName}.components.set(InputTargetComponent())`);
1719
- this.emit(
1720
- `${varName}.components.set(CollisionComponent(shapes: [.generateBox(size: SIMD3<Float>(0.2, 0.08, 0.01))]))`
1721
- );
1722
- this.emit(`${parentVar}.addChild(${varName})`);
1723
- }
1724
- compileUIText(obj, varName, parentVar) {
1725
- const content = this.findObjProp(obj, "content") || this.findObjProp(obj, "text") || "";
1726
- const fontSize = this.findObjProp(obj, "fontSize") || 16;
1727
- const color = this.findObjProp(obj, "color") || "#ffffff";
1728
- this.emit(`let ${varName}Mesh = MeshResource.generateText("${content}",`);
1729
- this.emit(` extrusionDepth: 0.001,`);
1730
- this.emit(` font: .systemFont(ofSize: ${fontSize}),`);
1731
- this.emit(` containerFrame: .zero,`);
1732
- this.emit(` alignment: .center,`);
1733
- this.emit(` lineBreakMode: .byWordWrapping)`);
1734
- this.emit(
1735
- `let ${varName} = ModelEntity(mesh: ${varName}Mesh, materials: [SimpleMaterial(color: ${this.toUIColor(color)}, isMetallic: false)])`
1736
- );
1737
- this.emit(`${varName}.name = "${this.escapeStringValue(obj.name, "Swift")}"`);
1738
- this.emit(`${parentVar}.addChild(${varName})`);
1739
- }
1740
- compileUISlider(obj, varName, parentVar) {
1741
- const min = this.findObjProp(obj, "min") ?? 0;
1742
- const max = this.findObjProp(obj, "max") ?? 100;
1743
- const value = this.findObjProp(obj, "value") ?? 50;
1744
- const pos = this.findObjProp(obj, "position");
1745
- this.emit(`let ${varName} = Entity()`);
1746
- this.emit(`${varName}.name = "${this.escapeStringValue(obj.name, "Swift")}"`);
1747
- if (pos) {
1748
- this.emit(`${varName}.position = ${this.toSIMD3(pos)}`);
1749
- }
1750
- this.emit(`// SwiftUI Slider: min=${min}, max=${max}, value=${value}`);
1751
- this.emit(
1752
- `// Implement via ViewAttachmentComponent with Slider(value: $value, in: ${min}...${max})`
1753
- );
1754
- this.emit(`${varName}.components.set(InputTargetComponent())`);
1755
- this.emit(`${parentVar}.addChild(${varName})`);
1756
- }
1757
- compileUIInput(obj, varName, parentVar) {
1758
- const placeholder = this.findObjProp(obj, "placeholder") || "";
1759
- const pos = this.findObjProp(obj, "position");
1760
- this.emit(`let ${varName} = Entity()`);
1761
- this.emit(`${varName}.name = "${this.escapeStringValue(obj.name, "Swift")}"`);
1762
- if (pos) {
1763
- this.emit(`${varName}.position = ${this.toSIMD3(pos)}`);
1764
- }
1765
- this.emit(`// SwiftUI TextField with placeholder: "${placeholder}"`);
1766
- this.emit(
1767
- `// Implement via ViewAttachmentComponent with TextField("${placeholder}", text: $text)`
1768
- );
1769
- this.emit(`${varName}.components.set(InputTargetComponent())`);
1770
- this.emit(`${parentVar}.addChild(${varName})`);
1771
- }
1772
- compileUIImage(obj, varName, parentVar) {
1773
- const src = this.findObjProp(obj, "src") || "";
1774
- const width = this.findObjProp(obj, "width") || 100;
1775
- const height = this.findObjProp(obj, "height") || 100;
1776
- const pos = this.findObjProp(obj, "position");
1777
- this.emit(`let ${varName} = Entity()`);
1778
- this.emit(`${varName}.name = "${this.escapeStringValue(obj.name, "Swift")}"`);
1779
- if (pos) {
1780
- this.emit(`${varName}.position = ${this.toSIMD3(pos)}`);
1781
- }
1782
- this.emit(`// Image: ${src} (${width}x${height})`);
1783
- this.emit(
1784
- `let ${varName}Mesh = MeshResource.generatePlane(width: ${width / 1e3}, depth: ${height / 1e3})`
1785
- );
1786
- this.emit(`if let texture = try? await TextureResource(named: "${src}") {`);
1787
- this.indentLevel++;
1788
- this.emit(`var ${varName}Material = UnlitMaterial()`);
1789
- this.emit(`${varName}Material.color = .init(texture: .init(texture))`);
1790
- this.emit(
1791
- `${varName}.components.set(ModelComponent(mesh: ${varName}Mesh, materials: [${varName}Material]))`
1792
- );
1793
- this.indentLevel--;
1794
- this.emit(`}`);
1795
- this.emit(`${parentVar}.addChild(${varName})`);
1796
- }
1797
- /**
1798
- * Check if object is a UI component
1799
- */
1800
- isUIComponent(obj) {
1801
- const type = this.findObjProp(obj, "type");
1802
- const uiTypes = ["ui_panel", "ui_button", "ui_text", "ui_slider", "ui_input", "ui_image"];
1803
- return uiTypes.includes(type || "");
1804
- }
1805
- /**
1806
- * Get all traits used in composition for imports
1807
- */
1808
- collectAllTraits(composition) {
1809
- const traits = [];
1810
- const collectFromObject = (obj) => {
1811
- if (obj.traits) {
1812
- for (const trait of obj.traits) {
1813
- if (!traits.includes(trait.name)) {
1814
- traits.push(trait.name);
1815
- }
1816
- }
1817
- }
1818
- if (obj.children) {
1819
- obj.children.forEach(collectFromObject);
1820
- }
1821
- };
1822
- composition.objects?.forEach(collectFromObject);
1823
- composition.spatialGroups?.forEach((group) => {
1824
- group.objects.forEach(collectFromObject);
1825
- });
1826
- return traits;
1827
- }
1828
- // ─── Helpers ───────────────────────────────────────────────────────────
1829
- emit(line) {
1830
- this.lines.push(this.options.indent.repeat(this.indentLevel) + line);
1831
- }
1832
- sanitizeName(name) {
1833
- return name.replace(/[^a-zA-Z0-9_]/g, "_");
1834
- }
1835
- toSIMD3(arr) {
1836
- if (Array.isArray(arr) && arr.length >= 3) {
1837
- return `SIMD3<Float>(${arr[0]}, ${arr[1]}, ${arr[2]})`;
1838
- }
1839
- return `SIMD3<Float>(${arr}, ${arr}, ${arr})`;
1840
- }
1841
- toUIColor(value) {
1842
- if (typeof value === "string" && value.startsWith("#")) {
1843
- const hex = value.slice(1);
1844
- const r = parseInt(hex.substring(0, 2), 16) / 255;
1845
- const g = parseInt(hex.substring(2, 4), 16) / 255;
1846
- const b = parseInt(hex.substring(4, 6), 16) / 255;
1847
- return `.init(red: ${r.toFixed(3)}, green: ${g.toFixed(3)}, blue: ${b.toFixed(3)}, alpha: 1.0)`;
1848
- }
1849
- return ".white";
1850
- }
1851
- toSwiftType(value) {
1852
- if (typeof value === "number") return Number.isInteger(value) ? "Int" : "Float";
1853
- if (typeof value === "boolean") return "Bool";
1854
- if (typeof value === "string") return "String";
1855
- if (Array.isArray(value)) return "[Any]";
1856
- return "Any";
1857
- }
1858
- toSwiftValue(value) {
1859
- if (typeof value === "number") return Number.isInteger(value) ? `${value}` : `${value}`;
1860
- if (typeof value === "boolean") return value ? "true" : "false";
1861
- if (typeof value === "string") return `"${this.escapeStringValue(value, "Swift")}"`;
1862
- if (value === null) return "nil";
1863
- return "nil";
1864
- }
1865
- findObjProp(obj, key) {
1866
- return obj.properties?.find((p) => p.key === key)?.value;
1867
- }
1868
- };
1869
- }
1870
- });
1871
-
1872
- exports.VisionOSCompiler_exports = VisionOSCompiler_exports;
1873
- exports.init_VisionOSCompiler = init_VisionOSCompiler;
1874
- //# sourceMappingURL=chunk-EMO7HAKJ.cjs.map
1875
- //# sourceMappingURL=chunk-EMO7HAKJ.cjs.map