lecodes-cli 0.19.0 → 0.20.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 (270) hide show
  1. package/README.md +1 -0
  2. package/dist/index.js +1069 -396
  3. package/package.json +14 -13
  4. package/runtime/scene-harness.json +1 -1
  5. package/runtime/sdk-types.json +1 -1
  6. package/runtime/web/assets/Roboto-Variable-DHm9jpd-.woff2 +0 -0
  7. package/runtime/web/assets/__vite-browser-external-BIHI7g3E.js +1 -0
  8. package/runtime/web/assets/basis-C64VHDVD.js +1 -0
  9. package/runtime/web/assets/basis_transcoder-VXdx5NbI.wasm +0 -0
  10. package/runtime/web/assets/createViewerLite-BvHobVhp.js +852 -0
  11. package/runtime/web/assets/draco-BiISTFcR.js +118 -0
  12. package/runtime/web/assets/draco_decoder-DsQ12WqX.wasm +0 -0
  13. package/runtime/web/assets/index-CfNCCBjN.js +2 -0
  14. package/runtime/web/assets/mapViewImpl-B2JcES8l.js +810 -0
  15. package/runtime/web/assets/maplibre-gl-worker-CJfwIrte.js +8 -0
  16. package/runtime/web/assets/neutral_ibl128-D-lzdkLN.ktx +0 -0
  17. package/runtime/web/assets/worker-Caf-yYEI.js +2 -0
  18. package/runtime/web/embed.html +32 -0
  19. package/runtime/web/embed.js +171 -0
  20. package/src/api.ts +302 -0
  21. package/src/browserAuth.ts +87 -0
  22. package/src/cmgenTool.ts +104 -0
  23. package/src/commands/app.ts +896 -0
  24. package/src/commands/appAndroid.ts +603 -0
  25. package/src/commands/appDesktop.ts +339 -0
  26. package/src/commands/appDesktopMac.ts +470 -0
  27. package/src/commands/appIcon.ts +187 -0
  28. package/src/commands/appShared.ts +542 -0
  29. package/src/commands/appTemplates.ts +907 -0
  30. package/src/commands/appTemplatesAndroid.ts +599 -0
  31. package/src/commands/appTemplatesGradlew.ts +9 -0
  32. package/src/commands/assets.ts +28 -0
  33. package/src/commands/clone.ts +60 -0
  34. package/src/commands/compile.ts +253 -0
  35. package/src/commands/create.ts +59 -0
  36. package/src/commands/design.ts +863 -0
  37. package/src/commands/designTemplates.ts +11 -0
  38. package/src/commands/desktop.ts +127 -0
  39. package/src/commands/dev.ts +236 -0
  40. package/src/commands/diff.ts +59 -0
  41. package/src/commands/init.ts +191 -0
  42. package/src/commands/install.ts +198 -0
  43. package/src/commands/lightmap.ts +290 -0
  44. package/src/commands/link.ts +147 -0
  45. package/src/commands/login.ts +24 -0
  46. package/src/commands/navmesh.ts +225 -0
  47. package/src/commands/pn.ts +305 -0
  48. package/src/commands/projectTemplates.ts +130 -0
  49. package/src/commands/pull.ts +109 -0
  50. package/src/commands/push.ts +173 -0
  51. package/src/commands/render.ts +416 -0
  52. package/src/commands/scene.ts +148 -0
  53. package/src/commands/shaders.ts +157 -0
  54. package/src/commands/status.ts +29 -0
  55. package/src/commands/test.ts +371 -0
  56. package/src/commands/thumbs.ts +178 -0
  57. package/src/commands/types.ts +87 -0
  58. package/src/commands/update.ts +190 -0
  59. package/src/compile/assetIcons.ts +214 -0
  60. package/src/compile/collect.ts +46 -0
  61. package/src/compile/collectLocal.ts +37 -0
  62. package/src/compile/designCompile.ts +104 -0
  63. package/src/compile/fonts.ts +156 -0
  64. package/src/compile/headlessBundle.ts +129 -0
  65. package/src/compile/nativeStack.ts +21 -0
  66. package/src/compile/projectCompile.ts +109 -0
  67. package/src/compile/sceneCompile.ts +113 -0
  68. package/src/compile/screenEntry.ts +127 -0
  69. package/src/compile/shaders.ts +245 -0
  70. package/src/config.ts +42 -0
  71. package/src/designMeta.ts +35 -0
  72. package/src/desktopRenderer.ts +545 -0
  73. package/src/desktopScript.ts +276 -0
  74. package/src/dev/clientTemplates.ts +160 -0
  75. package/src/dev/devServer.ts +333 -0
  76. package/src/dev/webRunner.ts +22 -0
  77. package/src/dev/wsServer.ts +144 -0
  78. package/src/distRoot.ts +20 -0
  79. package/src/ignore.ts +163 -0
  80. package/src/index.ts +494 -0
  81. package/src/lecodes-3d-editor.d.ts +41 -0
  82. package/src/lecodes-assets.d.ts +7 -0
  83. package/src/lecodes-design.d.ts +191 -0
  84. package/src/lecodes-renderer.d.ts +131 -0
  85. package/src/localFiles.ts +144 -0
  86. package/src/manifest.ts +46 -0
  87. package/src/matcTool.ts +137 -0
  88. package/src/peers.ts +40 -0
  89. package/src/project.ts +61 -0
  90. package/src/projectEnv.ts +94 -0
  91. package/src/qrcode-terminal.d.ts +9 -0
  92. package/src/releases.ts +125 -0
  93. package/src/serverDiff.ts +78 -0
  94. package/src/textDiff.ts +103 -0
  95. package/src/types.ts +0 -0
  96. package/src/util.ts +146 -0
  97. package/runtime/sdk/animate/animate.ts +0 -238
  98. package/runtime/sdk/animate/bezier.ts +0 -138
  99. package/runtime/sdk/animate/easings.ts +0 -126
  100. package/runtime/sdk/canvas/Canvas.ts +0 -305
  101. package/runtime/sdk/compile/aspectMacro.ts +0 -86
  102. package/runtime/sdk/compile/assetIconMacro.ts +0 -384
  103. package/runtime/sdk/compile/assetMacro.ts +0 -146
  104. package/runtime/sdk/compile/assetName.ts +0 -50
  105. package/runtime/sdk/compile/bundler.ts +0 -287
  106. package/runtime/sdk/compile/compileProject.ts +0 -129
  107. package/runtime/sdk/compile/detectEntry.ts +0 -128
  108. package/runtime/sdk/compile/fontMacro.ts +0 -459
  109. package/runtime/sdk/compile/fontRegistry.ts +0 -78
  110. package/runtime/sdk/compile/header.ts +0 -67
  111. package/runtime/sdk/compile/index.ts +0 -100
  112. package/runtime/sdk/compile/libraryImports.ts +0 -52
  113. package/runtime/sdk/compile/liteMaterial.ts +0 -247
  114. package/runtime/sdk/compile/sceneEditor.ts +0 -88
  115. package/runtime/sdk/compile/serverSplit.ts +0 -233
  116. package/runtime/sdk/compile/serverTypes.ts +0 -227
  117. package/runtime/sdk/compile/sfnt.ts +0 -98
  118. package/runtime/sdk/compile/shaderSchema.ts +0 -202
  119. package/runtime/sdk/compile/shaderTargets.ts +0 -81
  120. package/runtime/sdk/compile/sourcemap.ts +0 -25
  121. package/runtime/sdk/core/Aspect.ts +0 -568
  122. package/runtime/sdk/core/InspectorUI.ts +0 -212
  123. package/runtime/sdk/core/StateMachine.ts +0 -308
  124. package/runtime/sdk/core/color.ts +0 -66
  125. package/runtime/sdk/core/compWrite.ts +0 -42
  126. package/runtime/sdk/core/events.ts +0 -38
  127. package/runtime/sdk/core/fields.ts +0 -120
  128. package/runtime/sdk/core/registry.ts +0 -23
  129. package/runtime/sdk/core/signals.ts +0 -277
  130. package/runtime/sdk/core/time.ts +0 -84
  131. package/runtime/sdk/g2/Camera2D.ts +0 -40
  132. package/runtime/sdk/g2/CharacterController2D.ts +0 -276
  133. package/runtime/sdk/g2/Node2D.ts +0 -267
  134. package/runtime/sdk/g2/OneWay2D.ts +0 -66
  135. package/runtime/sdk/g2/Physics2D.ts +0 -346
  136. package/runtime/sdk/g2/Scene2D.ts +0 -209
  137. package/runtime/sdk/g2/Shape2D.ts +0 -259
  138. package/runtime/sdk/g2/Sprite.ts +0 -89
  139. package/runtime/sdk/g2/SpriteAnimation.ts +0 -171
  140. package/runtime/sdk/g2/SpriteSheet.ts +0 -166
  141. package/runtime/sdk/g2/Texture2D.ts +0 -47
  142. package/runtime/sdk/g2/Tilemap.ts +0 -41
  143. package/runtime/sdk/g2/Tileset.ts +0 -71
  144. package/runtime/sdk/g2/Trigger2D.ts +0 -77
  145. package/runtime/sdk/g2/autotile.ts +0 -433
  146. package/runtime/sdk/g2/cells.ts +0 -91
  147. package/runtime/sdk/g2/defineScene2d.ts +0 -381
  148. package/runtime/sdk/g2/groups2d.ts +0 -106
  149. package/runtime/sdk/g2/loop.ts +0 -50
  150. package/runtime/sdk/g2/scenarios2d.ts +0 -69
  151. package/runtime/sdk/g2/touch.ts +0 -83
  152. package/runtime/sdk/gl/Camera.ts +0 -160
  153. package/runtime/sdk/gl/CameraPlace.ts +0 -52
  154. package/runtime/sdk/gl/CharacterController.ts +0 -238
  155. package/runtime/sdk/gl/Gearbox.ts +0 -212
  156. package/runtime/sdk/gl/Geometry.ts +0 -279
  157. package/runtime/sdk/gl/IK.ts +0 -193
  158. package/runtime/sdk/gl/InstancedMesh.ts +0 -132
  159. package/runtime/sdk/gl/Light.ts +0 -107
  160. package/runtime/sdk/gl/Lightmap.ts +0 -256
  161. package/runtime/sdk/gl/Material.ts +0 -260
  162. package/runtime/sdk/gl/Mesh.ts +0 -83
  163. package/runtime/sdk/gl/Model.ts +0 -124
  164. package/runtime/sdk/gl/NavAgent.ts +0 -337
  165. package/runtime/sdk/gl/NavMesh.ts +0 -397
  166. package/runtime/sdk/gl/Node.ts +0 -350
  167. package/runtime/sdk/gl/Noise.ts +0 -30
  168. package/runtime/sdk/gl/Particles.ts +0 -676
  169. package/runtime/sdk/gl/Physics.ts +0 -222
  170. package/runtime/sdk/gl/Plane.ts +0 -53
  171. package/runtime/sdk/gl/Ragdoll.ts +0 -270
  172. package/runtime/sdk/gl/Ray.ts +0 -16
  173. package/runtime/sdk/gl/Scene.ts +0 -486
  174. package/runtime/sdk/gl/Shape.ts +0 -409
  175. package/runtime/sdk/gl/Terrain.ts +0 -1092
  176. package/runtime/sdk/gl/Texture.ts +0 -63
  177. package/runtime/sdk/gl/Trigger.ts +0 -45
  178. package/runtime/sdk/gl/Vehicle.ts +0 -473
  179. package/runtime/sdk/gl/Wheel.ts +0 -240
  180. package/runtime/sdk/gl/animation/AnimationClip.ts +0 -204
  181. package/runtime/sdk/gl/animation/Animator.ts +0 -120
  182. package/runtime/sdk/gl/animation/Layer.ts +0 -31
  183. package/runtime/sdk/gl/animation/Loop.ts +0 -30
  184. package/runtime/sdk/gl/animation/Playback.ts +0 -44
  185. package/runtime/sdk/gl/animation/core.ts +0 -336
  186. package/runtime/sdk/gl/controls.ts +0 -95
  187. package/runtime/sdk/gl/physicsEvents.ts +0 -20
  188. package/runtime/sdk/gl/scenarios.ts +0 -291
  189. package/runtime/sdk/gl/state.ts +0 -6
  190. package/runtime/sdk/gl/terrainMesh.ts +0 -219
  191. package/runtime/sdk/gl/touch.ts +0 -68
  192. package/runtime/sdk/inject.ts +0 -197
  193. package/runtime/sdk/math/Mathf.ts +0 -118
  194. package/runtime/sdk/math/mat4.ts +0 -278
  195. package/runtime/sdk/math/quat.ts +0 -232
  196. package/runtime/sdk/math/vec.ts +0 -255
  197. package/runtime/sdk/net/codec.ts +0 -119
  198. package/runtime/sdk/net/core.ts +0 -384
  199. package/runtime/sdk/net/index.ts +0 -181
  200. package/runtime/sdk/net/replication.ts +0 -622
  201. package/runtime/sdk/plugins/camera.ts +0 -81
  202. package/runtime/sdk/plugins/geolocation.ts +0 -123
  203. package/runtime/sdk/plugins/oauth.ts +0 -61
  204. package/runtime/sdk/plugins/permission.ts +0 -7
  205. package/runtime/sdk/plugins/push.ts +0 -132
  206. package/runtime/sdk/plugins/qr.ts +0 -73
  207. package/runtime/sdk/plugins/service.ts +0 -47
  208. package/runtime/sdk/runtime/app.ts +0 -101
  209. package/runtime/sdk/runtime/appEvents.ts +0 -54
  210. package/runtime/sdk/runtime/channel.ts +0 -61
  211. package/runtime/sdk/runtime/clipboard.ts +0 -20
  212. package/runtime/sdk/runtime/datetime.ts +0 -329
  213. package/runtime/sdk/runtime/device.ts +0 -293
  214. package/runtime/sdk/runtime/fetch.ts +0 -77
  215. package/runtime/sdk/runtime/files.ts +0 -23
  216. package/runtime/sdk/runtime/input.ts +0 -175
  217. package/runtime/sdk/runtime/media.ts +0 -111
  218. package/runtime/sdk/runtime/misc.ts +0 -16
  219. package/runtime/sdk/runtime/net.ts +0 -36
  220. package/runtime/sdk/runtime/rpc.ts +0 -218
  221. package/runtime/sdk/runtime/service.ts +0 -83
  222. package/runtime/sdk/runtime/share.ts +0 -9
  223. package/runtime/sdk/runtime/storage.ts +0 -13
  224. package/runtime/sdk/runtime/touch.ts +0 -76
  225. package/runtime/sdk/scene/defineScene.ts +0 -1353
  226. package/runtime/sdk/scene/editorPlugins.ts +0 -110
  227. package/runtime/sdk/scene/gizmos.ts +0 -148
  228. package/runtime/sdk/scene/grammar.ts +0 -120
  229. package/runtime/sdk/scene/material.ts +0 -188
  230. package/runtime/sdk/server/auth/appConfig.ts +0 -12
  231. package/runtime/sdk/server/auth/global.ts +0 -80
  232. package/runtime/sdk/server/auth/host.ts +0 -318
  233. package/runtime/sdk/server/auth/models.ts +0 -83
  234. package/runtime/sdk/server/auth/types.ts +0 -50
  235. package/runtime/sdk/server/channel.ts +0 -56
  236. package/runtime/sdk/server/context.ts +0 -36
  237. package/runtime/sdk/server/db/defineDb.ts +0 -237
  238. package/runtime/sdk/server/db/fields.ts +0 -132
  239. package/runtime/sdk/server/db/httpTransport.ts +0 -93
  240. package/runtime/sdk/server/db/index.ts +0 -7
  241. package/runtime/sdk/server/db/marci/query.ts +0 -412
  242. package/runtime/sdk/server/db/types.ts +0 -202
  243. package/runtime/sdk/server/errors.ts +0 -12
  244. package/runtime/sdk/server/host.ts +0 -74
  245. package/runtime/sdk/server/inject.ts +0 -13
  246. package/runtime/sdk/server/runtime.ts +0 -133
  247. package/runtime/sdk/server/validate.ts +0 -87
  248. package/runtime/sdk/ui/NativeView.ts +0 -142
  249. package/runtime/sdk/ui/UI.ts +0 -39
  250. package/runtime/sdk/ui/UIBottomSheet.ts +0 -139
  251. package/runtime/sdk/ui/UIButton.ts +0 -101
  252. package/runtime/sdk/ui/UIContainer.ts +0 -60
  253. package/runtime/sdk/ui/UIImage.ts +0 -83
  254. package/runtime/sdk/ui/UIInput.ts +0 -185
  255. package/runtime/sdk/ui/UIModal.ts +0 -139
  256. package/runtime/sdk/ui/UINode.ts +0 -830
  257. package/runtime/sdk/ui/UIPager.ts +0 -362
  258. package/runtime/sdk/ui/UIPopover.ts +0 -100
  259. package/runtime/sdk/ui/UIScreen.ts +0 -123
  260. package/runtime/sdk/ui/UIScrollable.ts +0 -87
  261. package/runtime/sdk/ui/UISpacer.ts +0 -14
  262. package/runtime/sdk/ui/UITabs.ts +0 -236
  263. package/runtime/sdk/ui/UIText.ts +0 -51
  264. package/runtime/sdk/ui/UIVideo.ts +0 -88
  265. package/runtime/sdk/ui/UIVirtualizedList.ts +0 -241
  266. package/runtime/sdk/ui/UIWidget.ts +0 -127
  267. package/runtime/sdk/ui/fonts.ts +0 -13
  268. package/runtime/sdk/ui/presentable.ts +0 -117
  269. package/runtime/sdk/ui/router.ts +0 -132
  270. package/runtime/sdk/ui/theme.ts +0 -84
@@ -1,486 +0,0 @@
1
- // A 3D scene: a draw set, a Camera, lights and environment. Opening a scene asks the host to bring up
2
- // the 3D engine; only the active scene renders. Grown from the Phase 0 seed. Ported from
3
- // worker/src/Scene.ts (Scene + ARScene), with the camera exposed as scene.camera.
4
- //
5
- // Lights are explicit: a scene gets image-based ambient (IBL) by default; add a Light.sun() for
6
- // direct light + shadows.
7
-
8
- import { Color, type ColorInput } from "../core/color"
9
- import { _installAspectFrames, _installTimeScale, _attachSystem, _detachSystem, _detachAllSystems, type Aspect, type AspectCtor, type FieldOf, type TargetOf } from "../core/Aspect"
10
- import { _bumpNavEpoch, _navEpoch, _navSupported, _setCurrent, Presentable, type PresentOptions } from "../ui/presentable"
11
- import { device } from "../runtime/device"
12
- import type { ClickEvent, TouchStartEvent } from "../runtime/touch"
13
- import type { FetchResponse } from "../runtime/fetch"
14
- import { _requestCameraPermission } from "../plugins/permission"
15
- import { Camera } from "./Camera"
16
- import { attachControls, type ControlsHandle, type ControlsOptions } from "./controls"
17
- import { Material } from "./Material"
18
- import { Node, nodeRegistry } from "./Node"
19
- import { glState } from "./state"
20
- import { registerTouchEndEvent, registerTouchStartEvent } from "./touch"
21
-
22
- export type AmbientOcclusionOptions = {
23
- /** Strength of the darkening (default 1). */
24
- intensity?: number
25
- /** How far the occlusion reaches, in metres (default 0.3). */
26
- radius?: number
27
- /** Falloff contrast; >1 tightens it into the crease (default 1). */
28
- power?: number
29
- /** Sample count + filtering (default 'medium'). Not the buffer resolution — that stays half. */
30
- quality?: "low" | "medium" | "high" | "ultra"
31
- }
32
-
33
- export type FogOptions = {
34
- /** A TINT on the in-scattered ambient, not an absolute colour: the engine multiplies it by the
35
- * environment luminance, so white (the default) means "fog as bright as the ambient" and the fog
36
- * brightens with `environmentIntensity`. Do NOT expect the same hex to look like it does in
37
- * `skybox` — that one IS an absolute radiance and reads roughly an order of magnitude brighter.
38
- * Tint towards the sky's hue; leave it white to sit at the ambient level. */
39
- color?: ColorInput
40
- /** Metres from the camera before the fog starts (default 0). */
41
- start?: number
42
- /** Extinction per metre at `height`; 0.01 ≈ clearly visible over ~100 m (default 0.01). */
43
- density?: number
44
- /** The fog's "sea level" in world Y (default 0). */
45
- height?: number
46
- /** How fast it thins with altitude, 1/m. 0 = uniform everywhere; higher = a ground-hugging layer
47
- * you can see over (default 0). */
48
- heightFalloff?: number
49
- /** Cap on how opaque it can get, 0–1 — keeps far shapes readable (default 1). */
50
- maxOpacity?: number
51
- /** Metres after which fog stops applying; 0 = everywhere (default 0). */
52
- cutoff?: number
53
- /** Take the colour from the environment in the view direction, tinted by `color`, instead of a
54
- * flat `color`. Convincing when the IBL is a real sky (default false). */
55
- fromEnvironment?: boolean
56
- }
57
-
58
- export type SceneOptions = {
59
- /** Image-based ambient lighting (default on). */
60
- ibl?: boolean
61
- /** IBL intensity (default 20000). */
62
- environmentIntensity?: number
63
- /** Bloom post-processing. */
64
- bloom?: boolean
65
- bloomIntensity?: number
66
- /** Tone mapping operator. `'aces'` (default, filament's ACES legacy) desaturates bright colours
67
- * towards white — HDR fire reads pale; `'neutral'` (Khronos PBR Neutral) keeps hue and
68
- * saturation until very bright; `'linear'` clips each channel (what an engine without a
69
- * tonemapper shows — saturated, Unity-without-post-processing look); `'filmic'` (Uncharted). */
70
- toneMapping?: "aces" | "neutral" | "linear" | "filmic"
71
- /** The sky. Three forms:
72
- * - a colour — a flat clear colour;
73
- * - `{ texture }` — a KTX1 **cubemap**, the sharp `<name>_skybox.ktx` that filament's `cmgen`
74
- * produces from an equirectangular .hdr/.exr. This is the one to use for a real sky. Pass an
75
- * `asset('../assets/sky.ktx')` handle or a bare staged filename;
76
- * - `'environment'` — reuse the scene's IBL cubemap. Cheapest (no second texture) but that file
77
- * is prefiltered for roughness, so the sky comes out soft; fine as a fallback, not as the goal.
78
- *
79
- * Either texture form draws through filament's own skybox pass: a full-screen pass in device
80
- * space after the opaque queue. No geometry, no meridian seam, no pole distortion — do NOT build
81
- * a sky dome or a fullscreen equirect material by hand, both are strictly worse. */
82
- skybox?: ColorInput | "environment" | { texture: string }
83
- /** Screen-space ambient occlusion — the contact darkening in creases and where props meet the
84
- * ground. Without it an IBL lights a crease exactly as brightly as an open face, so everything
85
- * reads as pasted onto the floor rather than standing on it. `true` takes defaults tuned for
86
- * human-scale props; `radius` is world-space metres and is the one knob that must follow the
87
- * scene's scale (~0.3 for objects on a table, ~0.6-1 for a yard of crates and containers). */
88
- ambientOcclusion?: boolean | AmbientOcclusionOptions
89
- /** Distance fog / aerial perspective: distant geometry loses contrast so the eye reads depth, and
90
- * the hard edge where a finite level ends against the skybox goes away. By default the fog applies
91
- * at every distance — the skybox included — so the sky itself takes the fog colour and the horizon
92
- * blends on its own; `cutoff` opts geometry beyond a distance back out. */
93
- fog?: FogOptions
94
- /** Multisample anti-aliasing: `true` = 4×, `2`/`4` = that many samples, `false` = off (FXAA
95
- * takes over). Unset keeps the host default (desktop 4×, mobile/web off). The biggest single
96
- * fill-rate cost after resolution — turn it down on big screens before anything else. */
97
- antialias?: boolean | 2 | 4
98
- /** Render the 3D at this fraction of the viewport (0.25–1) and upscale; the UI stays at native
99
- * resolution. A fixed, predictable cut of per-pixel GPU work — `0.75` is ~45 % cheaper and
100
- * barely visible in motion, `0.5` quarters it. Headless renders ignore it. */
101
- renderScale?: number
102
- /** Let the engine shrink the 3D buffers under `renderScale` only when frames run over budget
103
- * (Filament dynamic resolution, sharpened upscale) down to `min` (default 0.5). Off by default:
104
- * it makes the output frame-time dependent, so flow tests / headless renders never enable it. */
105
- dynamicResolution?: boolean | { min?: number }
106
- /** Anisotropic filtering, 1 (off) … 16. Default 2. What it buys is detail on surfaces seen at a
107
- * GRAZING angle — a first-person weapon, a floor, a wall — where the sample footprint is far
108
- * longer in one axis than the other and isotropic filtering has to pick a mip for the long one,
109
- * several levels coarser than the short axis deserves. Measured on a weapon seen from the side
110
- * (local contrast): 8.18 at 1× → 10.02 at 2× → 10.84 at 4× → 11.29 at 8×. The default is 2
111
- * because it is where the curve is steepest per unit of memory bandwidth; raise it if you have
112
- * the headroom.
113
- *
114
- * It is an ENGINE-WIDE default, not a property of this scene: a sampler is baked when its
115
- * texture is bound, so this reaches the models a scene loads AFTER it (which is every model in a
116
- * scene file — `env` is applied before the nodes build) and leaves already-loaded ones alone.
117
- * On the desktop host `CREATOR_TEXTURE_ANISOTROPY` overrides it, for tuning without a rebuild. */
118
- anisotropy?: number
119
- /** The look on an HDR display (a screen with headroom above SDR white — Apple XDR panels, the
120
- * macOS host today); ignored on SDR. `strength` 0..1 is how much of the picture reaches for the
121
- * display's headroom (0 only what SDR clipped, 1 nearly everything; default 0.35). `paperWhite`
122
- * 1..8 is where white lands as a multiple of SDR white — the "HDR brightness" of a console
123
- * calibration screen, where 1.5–2 is the norm; default 1 keeps a white wall at the UI's white,
124
- * faithful but dim next to what "HDR on" is expected to look like. Engine-wide like `anisotropy`;
125
- * `device.hdr` is the runtime form and tells you whether the display has any headroom at all. */
126
- hdr?: { strength?: number; paperWhite?: number }
127
- }
128
-
129
- // Route aspect update(dt) through the render-synced native phases (render() early = before physics,
130
- // late = after animations / before draw), so followers/cameras are in lockstep with the draw. Done from
131
- // the 3D layer (not core) so a 2D-only bundle never pulls in the 3D bridge. Installed once, lazily on
132
- // the first Scene. On an older wasm without the hooks the installer returns false → setLoop fallback.
133
- let framesInstalled = false
134
- const installRenderSyncedFrames = (): void => {
135
- if (framesInstalled) return
136
- framesInstalled = true
137
- _installAspectFrames((early, late) => {
138
- if (typeof _creator.setEarlyUpdate !== "function") return false
139
- // the frame stamp invalidates every Node's local-matrix cache once per frame (physics / character
140
- // controllers / animation rewrite transforms natively between frames)
141
- _creator.setEarlyUpdate((dt: number) => { glState.frame++; early(dt) })
142
- _creator.setLateUpdate(late)
143
- return true
144
- }, (fixed) => {
145
- // The fixed phase runs INSIDE the engine's substep loop (physics/world.cpp) when the host has the
146
- // hook; each substep moves bodies natively, so the frame stamp bumps per step too. Feature-detected:
147
- // an older host returns false and the dispatcher steps its own 1/60 accumulator.
148
- if (typeof _creator.setFixedUpdate !== "function") return false
149
- _creator.setFixedUpdate((dt: number) => { glState.frame++; fixed(dt) })
150
- return true
151
- })
152
- // Time.scale / Time.paused reach the engine's own clocks (physics, animators, particles) through
153
- // setTimeScale; a host without it keeps running its sims at wall-clock speed (feature-detected).
154
- _installTimeScale((scale) => { _creator.setTimeScale?.(scale) })
155
- }
156
-
157
- export class Scene implements Presentable {
158
- /** @internal native scene handle. */
159
- readonly _id: number
160
- /** @internal the IBL intensity this scene was built with (Lightmap.load's ambient floor). */
161
- _environmentIntensity = 20000
162
- readonly camera: Camera
163
-
164
- /** @internal touch listeners, read by the dispatch system. */
165
- readonly _clickListeners: Array<(ev: ClickEvent<Node | null>) => void> = []
166
- readonly _touchStartListeners: Array<(ev: TouchStartEvent<Node | null>) => void> = []
167
-
168
- private _material?: Material
169
-
170
- private static _active: Scene | null = null
171
- static get active(): Scene | null { return Scene._active }
172
-
173
- constructor(options: SceneOptions = {}) {
174
- installRenderSyncedFrames()
175
- const parent = (options as any)._parent as Scene | undefined
176
- if (parent) {
177
- this.camera = parent.camera
178
- this._id = _creator.createOverlayScene(parent._id)
179
- // No camera re-attach: the native createOverlayScene wires the parent's camera into the
180
- // overlay view. Re-attaching would (a) point camera._sceneId — the source for getRay /
181
- // getViewDirection / fov — at the overlay's view, whose viewport/projection aren't
182
- // maintained like the render view's, and (b) create a second native camera component on
183
- // the shared entity. (Found via the scene editor: gizmo pick rays came out distorted.)
184
- } else {
185
- this.camera = new Camera()
186
- this._id = _creator.createScene()
187
- this.camera._attach(this._id)
188
- }
189
-
190
- if (options.ibl !== false) _creator.setDefaultIbl(this._id, options.environmentIntensity ?? 20000)
191
- this._environmentIntensity = options.ibl === false ? 0 : (options.environmentIntensity ?? 20000)
192
- if (options.bloom) _creator.setBloomOptions(this._id, true, options.bloomIntensity ?? 0.2, 1)
193
- if (options.toneMapping !== undefined && options.toneMapping !== "aces") {
194
- _creator.setToneMapping?.(this._id, { neutral: 1, linear: 2, filmic: 3 }[options.toneMapping] ?? 0)
195
- }
196
- if (options.skybox !== undefined) this.skybox = options.skybox
197
- if (options.ambientOcclusion) this.setAmbientOcclusion(options.ambientOcclusion)
198
- if (options.fog) this.setFog(options.fog)
199
- if (options.antialias !== undefined) {
200
- const a = options.antialias
201
- // `false` must reach the host: desktop defaults to 4× MSAA, so an explicit off is a real change.
202
- _creator.setSceneMultiSampleAntiAliasing(this._id, a !== false, typeof a === "number" ? a : 4)
203
- }
204
- // Before anything else in this constructor that could load a texture: the value has to be in
205
- // place by the time assets bind their samplers.
206
- if (options.anisotropy !== undefined) _creator.setTextureAnisotropy?.(options.anisotropy)
207
- if (options.hdr) {
208
- if (options.hdr.strength !== undefined) device.hdr.strength = options.hdr.strength
209
- if (options.hdr.paperWhite !== undefined) device.hdr.paperWhite = options.hdr.paperWhite
210
- }
211
- if (options.renderScale !== undefined || options.dynamicResolution) {
212
- this.setRenderOptions(options.renderScale ?? 1, options.dynamicResolution ?? false)
213
- }
214
- }
215
-
216
- /** Runtime form of `renderScale` / `dynamicResolution` (a graphics-settings menu). `renderScale`
217
- * 0.25–1; older hosts without the method ignore it. */
218
- setRenderOptions(renderScale: number, dynamicResolution: boolean | { min?: number } = false): void {
219
- const min = typeof dynamicResolution === "object" ? (dynamicResolution.min ?? 0.5) : 0.5
220
- _creator.setSceneRenderOptions?.(this._id, renderScale, !!dynamicResolution, min)
221
- }
222
-
223
- /** Scene occlusion material. */
224
- get occlusionMaterial(): Material {
225
- if (!this._material) this._material = new Material(_creator.getSceneMaterial(this._id))
226
- return this._material
227
- }
228
-
229
- set skybox(sky: ColorInput | "environment" | { texture: string }) {
230
- if (sky === "environment") { _creator.setSkyboxFromEnvironment?.(this._id); return }
231
- if (typeof sky === "object" && sky !== null && "texture" in sky) {
232
- const src = sky.texture
233
- // `asset()` hands back "id:<n>" (already staged); a bare name is resolved on the spot.
234
- const id = src.startsWith("id:") ? Number(src.slice(3)) : _creatorUtils.fetchLocal(src)
235
- _creator.setSkyboxTexture?.(this._id, id)
236
- return
237
- }
238
- _creator.setSkybox(this._id, Color.toPackedRgb(sky))
239
- }
240
-
241
- /** Runtime form of `ambientOcclusion` (a graphics-settings menu). `false` turns it off. */
242
- setAmbientOcclusion(options: boolean | AmbientOcclusionOptions): void {
243
- const o: AmbientOcclusionOptions = typeof options === "object" ? options : {}
244
- const quality = { low: 0, medium: 1, high: 2, ultra: 3 }[o.quality ?? "medium"] ?? 1
245
- _creator.setAmbientOcclusionOptions?.(this._id, options !== false, o.intensity ?? 1, o.radius ?? 0.3, o.power ?? 1, quality)
246
- }
247
-
248
- /** Runtime form of `fog` (weather, entering a building). `false` turns it off. */
249
- setFog(options: FogOptions | false): void {
250
- const o: FogOptions = options === false ? {} : options
251
- _creator.setFogOptions?.(
252
- this._id, options !== false, Color.toPackedRgb(o.color ?? "#ffffff"),
253
- o.start ?? 0, o.density ?? 0.01, o.height ?? 0, o.heightFalloff ?? 0,
254
- o.maxOpacity ?? 1, o.cutoff ?? 0, o.fromEnvironment ?? false,
255
- )
256
- }
257
-
258
- setMaterialGlobalParameter(i: number, x: number, y: number, z: number, w: number): void {
259
- _creator.setMaterialGlobalParameter(this._id, i, x, y, z, w)
260
- }
261
- setAntialias(enabled: boolean, scale = 4): void {
262
- _creator.setSceneMultiSampleAntiAliasing(this._id, enabled, scale)
263
- }
264
-
265
- add(...nodes: Node[]): this {
266
- for (const n of nodes) _creator.addEntityToScene(this._id, n.id)
267
- return this
268
- }
269
- remove(...nodes: Node[]): this {
270
- for (const n of nodes) _creator.removeEntityFromScene(this._id, n.id)
271
- return this
272
- }
273
-
274
- // ---- systems: aspects of the scene (core/Aspect.ts `System`) ----
275
- /** @internal class → instance, the authoritative store (named accessors mirror this). */
276
- readonly _systems = new Map<Function, Aspect<any, any, any>>()
277
-
278
- /** Attach (and configure) a system, or reconfigure it if already present. Returns the scene typed
279
- * as now-having it (`scene.system(Hud).hud`). A `System<'x', Scene2D>` is rejected here. */
280
- // `this: Self` (not `Self & Scene`): with the intersection TS infers Self = Scene and a chain
281
- // `scene.system(A).system(B)` loses A's accessor from the result type.
282
- system<Self extends TargetOf<A>, A extends Aspect<any, any, any>>(
283
- this: Self,
284
- ctor: AspectCtor<A>,
285
- opts?: Partial<A>,
286
- ): Self & FieldOf<A> {
287
- return _attachSystem(this as unknown as Scene, ctor, opts) as unknown as Self & FieldOf<A>
288
- }
289
- /** Safe access — undefined if the system isn't attached. */
290
- get<A extends Aspect<any, any, any>>(ctor: AspectCtor<A>): A | undefined {
291
- return this._systems.get(ctor) as A | undefined
292
- }
293
- /** Existence check AND type guard: inside `if (scene.has(Hud))`, `scene.hud` is present. */
294
- has<A extends Aspect<any, any, any>>(ctor: AspectCtor<A>): this is this & FieldOf<A> {
295
- return this._systems.has(ctor)
296
- }
297
- /** Detach a system (runs its onDetach). Chainable. */
298
- removeSystem<A extends Aspect<any, any, any>>(ctor: AspectCtor<A>): this {
299
- _detachSystem(this, ctor)
300
- return this
301
- }
302
- /** Tear the scene down: every system detaches (last-attached first) and the scene closes. Nodes
303
- * are yours — destroy the ones you own; the native scene object itself is not released. */
304
- destroy(): void {
305
- _detachAllSystems(this)
306
- this.close()
307
- }
308
-
309
- createOverlay(options: SceneOptions = {}): Scene {
310
- return new Scene({ ...options, _parent: this } as any)
311
- }
312
-
313
- warmRender(): Promise<void> {
314
- return new Promise<void>((res) => _creator.warmRender(this._id, res))
315
- }
316
-
317
- // ---- Presentable (docs/navigation-presentable-plan.md) ----
318
- // A scene is a destination like a screen: opening it replaces whatever is visible (suspending
319
- // an active Router until Router.restore()), and it can be pushed onto the Router stack. The
320
- // scene graph survives while covered — only the view detaches and rendering pauses.
321
-
322
- /** @internal presentation lifecycle — fired by the host on present/dismiss (new navigation),
323
- * or synchronously by open()/close() on legacy hosts. */
324
- readonly ol: (() => void)[] = []
325
- readonly cl: (() => void)[] = []
326
- _backButtonCallback?: () => void
327
- private _vd?: object
328
-
329
- /** Fires when the scene becomes the visible destination (incl. a pop revealing it). */
330
- onOpen(callback: () => void): this {
331
- this.ol.push(callback)
332
- return this
333
- }
334
- /** Fires when the scene stops being visible (closed, replaced, or covered by a push). */
335
- onClose(callback: () => void): this {
336
- this.cl.push(callback)
337
- return this
338
- }
339
- onBackPressed(callback: () => void): this {
340
- this._backButtonCallback = callback
341
- return this
342
- }
343
-
344
- /** @internal stable wire descriptor; hosts hand it back via router onChange (`_p` = this). */
345
- _viewDesc(): object {
346
- return this._vd ??= { type: "scene3d", sceneId: this._id, _p: this }
347
- }
348
-
349
- /** Make this the active scene — shows it as the current destination (replaces a screen /
350
- * another scene; only the active scene renders). */
351
- open(options?: PresentOptions): void | Promise<void> {
352
- _bumpNavEpoch()
353
- if (_navSupported()) {
354
- // The host activates the engine (openScene) as part of presenting the destination.
355
- _creatorUI.openView!(this._viewDesc(), options?.transition ?? "none")
356
- } else {
357
- _creator.openScene(this._id)
358
- for (const cb of this.ol) cb()
359
- }
360
- Scene._active = this
361
- glState.activeScene = this
362
- _setCurrent(this)
363
- }
364
- close(): void {
365
- _bumpNavEpoch()
366
- if (_navSupported()) {
367
- _creatorUI.closeView!()
368
- } else {
369
- _creator.closeScene()
370
- for (const cb of this.cl) cb()
371
- }
372
- if (Scene._active === this) Scene._active = null
373
- if (glState.activeScene === this) glState.activeScene = null
374
- if (Presentable.current === this) _setCurrent(null)
375
- }
376
-
377
- addEventListener(channel: "click", callback: (ev: ClickEvent<Node | null>) => void): void
378
- addEventListener(channel: "touchstart", callback: (ev: TouchStartEvent<Node | null>) => void): void
379
- addEventListener(channel: "click" | "touchstart", callback: (ev: any) => void): void {
380
- if (channel === "click") {
381
- if (!this._clickListeners.includes(callback)) { this._clickListeners.push(callback); registerTouchEndEvent() }
382
- } else if (channel === "touchstart") {
383
- if (!this._touchStartListeners.includes(callback)) { this._touchStartListeners.push(callback); registerTouchStartEvent() }
384
- }
385
- }
386
- removeEventListener(channel: "click" | "touchstart", callback: (ev: any) => void): void {
387
- const list = channel === "click" ? this._clickListeners : this._touchStartListeners
388
- const i = list.indexOf(callback)
389
- if (i >= 0) list.splice(i, 1)
390
- }
391
- }
392
-
393
- // --- AR ---
394
-
395
- export type ARMode = "default" | "markers" | "arcore" | "detached"
396
-
397
- const onTrackStateChange = (entityId: number, track: boolean): void => {
398
- const node = nodeRegistry.get(entityId)
399
- if (!node) return
400
- node.isTracked = track
401
- if (track) node._dispatchEvent("track")
402
- else node._dispatchEvent("untrack")
403
- }
404
-
405
- export class ARScene<T extends ARMode = "default"> extends Scene {
406
- readonly mode: T
407
- useWarmRender = true
408
- private _root?: Node
409
-
410
- constructor(options: SceneOptions & { mode?: T } = {}) {
411
- super(options)
412
- this.mode = options.mode ?? ("default" as T)
413
- _creator.createARController(this._id, this.camera.id, this.mode, onTrackStateChange)
414
- }
415
-
416
- /** Root anchor node (not available in marker mode). */
417
- get root(): Node {
418
- if (this._root) return this._root
419
- this._root = new Node(_creator.createRootAnchor(this._id))
420
- return this._root
421
- }
422
-
423
- /** Create an anchor from a tracking source (e.g. an image target). */
424
- createAnchor(source: FetchResponse, physicalWidth = 0.2): Node {
425
- return new Node(_creator.createAnchor(this._id, physicalWidth, (source as any)._id))
426
- }
427
-
428
- /**
429
- * Let the user place & manipulate a node with touch gestures — the staple AR object-placement
430
- * interaction: ONE finger drags it across the floor (relative to where the camera looks), TWO fingers
431
- * pinch to scale and twist to rotate. Returns a handle; call `.remove()` to detach. Tunable via
432
- * options (min/max scale, and toggles for `pan` / `pinch` / `twist`).
433
- */
434
- addControls(target: Node, options: ControlsOptions = {}): ControlsHandle {
435
- return attachControls(this, target, options)
436
- }
437
-
438
- override async open(options?: PresentOptions): Promise<void> {
439
- await this._prepare()
440
- super.open(options)
441
- }
442
-
443
- /** @internal Presentable prepare hook: camera permission + warm render + AR session, all while
444
- * the previous destination (typically a loading screen) stays visible — the swap to this scene
445
- * happens only after it resolves. Warm render is headless on every platform (offscreen
446
- * swapchain), so no GL view is created here — the host mounts the scene view at present time.
447
- * Rejects on camera denial / AR launch failure, or if another navigation happened while
448
- * preparing (superseded) — in every rejection case the current destination stays visible. */
449
- async _prepare(): Promise<void> {
450
- const epoch = _navEpoch()
451
- await _requestCameraPermission()
452
- if (this.useWarmRender) await this.warmRender()
453
- await new Promise<void>((res, rej) => _creator.launchAR(this._id, res, rej))
454
- if (_navEpoch() !== epoch) {
455
- _creator.stopAR()
456
- throw new Error("ARScene.open() superseded: another destination was opened while preparing")
457
- }
458
- }
459
-
460
- override close(): void {
461
- _creator.stopAR()
462
- super.close()
463
- }
464
- }
465
-
466
- // --- VR ---
467
-
468
- /**
469
- * A 3D scene rendered in a VR headset (OpenXR — e.g. Meta Quest). The headset drives the camera:
470
- * every frame both eyes are rendered from the tracked head pose, so `scene.camera` position/lookAt
471
- * have no effect while the scene is open. The world origin is at floor level (stage space) —
472
- * author content with the ground at y = 0 and the user standing at the origin.
473
- *
474
- * `open()` rejects on hosts without a VR runtime ("VR is not supported on this device").
475
- */
476
- export class VRScene extends Scene {
477
- override async open(options?: PresentOptions): Promise<void> {
478
- await new Promise<void>((res, rej) => _creator.launchVR(this._id, res, rej))
479
- super.open(options)
480
- }
481
-
482
- override close(): void {
483
- _creator.stopVR()
484
- super.close()
485
- }
486
- }