wallhammer-web 0.0.0-stage → 0.4.1

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 (408) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +92 -2
  3. package/dist/base/data.d.ts +67 -0
  4. package/dist/base/data.js +10 -0
  5. package/dist/base/destructible.d.ts +167 -0
  6. package/dist/base/destructible.js +47 -0
  7. package/dist/base/env-slot.d.ts +101 -0
  8. package/dist/base/env-slot.js +8 -0
  9. package/dist/base/frames.d.ts +138 -0
  10. package/dist/base/frames.js +459 -0
  11. package/dist/base/index.d.ts +21 -0
  12. package/dist/base/index.js +11 -0
  13. package/dist/base/mat34.d.ts +46 -0
  14. package/dist/base/mat34.js +173 -0
  15. package/dist/base/material.d.ts +87 -0
  16. package/dist/base/material.js +6 -0
  17. package/dist/base/math.d.ts +27 -0
  18. package/dist/base/math.js +60 -0
  19. package/dist/base/progress.d.ts +38 -0
  20. package/dist/base/progress.js +81 -0
  21. package/dist/base/rig.d.ts +177 -0
  22. package/dist/base/rig.js +97 -0
  23. package/dist/base/trig.d.ts +29 -0
  24. package/dist/base/trig.js +169 -0
  25. package/dist/base/up.d.ts +26 -0
  26. package/dist/base/up.js +40 -0
  27. package/dist/base/view.d.ts +128 -0
  28. package/dist/base/view.js +136 -0
  29. package/dist/camera/camera.d.ts +99 -0
  30. package/dist/camera/camera.js +228 -0
  31. package/dist/camera/follow.d.ts +120 -0
  32. package/dist/camera/follow.js +320 -0
  33. package/dist/camera/free.d.ts +153 -0
  34. package/dist/camera/free.js +359 -0
  35. package/dist/camera/index.d.ts +10 -0
  36. package/dist/camera/index.js +6 -0
  37. package/dist/camera/orbit.d.ts +93 -0
  38. package/dist/camera/orbit.js +261 -0
  39. package/dist/camera/path.d.ts +48 -0
  40. package/dist/camera/path.js +179 -0
  41. package/dist/core/ballistic.d.ts +66 -0
  42. package/dist/core/ballistic.js +104 -0
  43. package/dist/core/bodies.d.ts +77 -0
  44. package/dist/core/bodies.js +125 -0
  45. package/dist/core/clock.d.ts +37 -0
  46. package/dist/core/clock.js +87 -0
  47. package/dist/core/cover-fade.d.ts +14 -0
  48. package/dist/core/cover-fade.js +38 -0
  49. package/dist/core/index.d.ts +13 -0
  50. package/dist/core/index.js +8 -0
  51. package/dist/core/kepler.d.ts +74 -0
  52. package/dist/core/kepler.js +108 -0
  53. package/dist/core/level-fade.d.ts +66 -0
  54. package/dist/core/level-fade.js +123 -0
  55. package/dist/core/palette.d.ts +15 -0
  56. package/dist/core/palette.js +47 -0
  57. package/dist/env/atmosphere.d.ts +129 -0
  58. package/dist/env/atmosphere.js +707 -0
  59. package/dist/env/cloud-field.d.ts +44 -0
  60. package/dist/env/cloud-field.js +111 -0
  61. package/dist/env/environment.d.ts +217 -0
  62. package/dist/env/environment.js +441 -0
  63. package/dist/env/frame-block.d.ts +29 -0
  64. package/dist/env/frame-block.js +152 -0
  65. package/dist/env/glsl.d.ts +35 -0
  66. package/dist/env/glsl.js +246 -0
  67. package/dist/env/index.d.ts +13 -0
  68. package/dist/env/index.js +9 -0
  69. package/dist/env/sky.d.ts +48 -0
  70. package/dist/env/sky.js +227 -0
  71. package/dist/env/sun.d.ts +31 -0
  72. package/dist/env/sun.js +42 -0
  73. package/dist/gen-arch/build.d.ts +17 -0
  74. package/dist/gen-arch/build.js +414 -0
  75. package/dist/gen-arch/damage/damaged.d.ts +44 -0
  76. package/dist/gen-arch/damage/damaged.js +1119 -0
  77. package/dist/gen-arch/damage/fall-material.d.ts +10 -0
  78. package/dist/gen-arch/damage/fall-material.js +47 -0
  79. package/dist/gen-arch/damage/fall.d.ts +78 -0
  80. package/dist/gen-arch/damage/fall.js +797 -0
  81. package/dist/gen-arch/damage/rubble.d.ts +22 -0
  82. package/dist/gen-arch/damage/rubble.js +188 -0
  83. package/dist/gen-arch/index.d.ts +25 -0
  84. package/dist/gen-arch/index.js +16 -0
  85. package/dist/gen-arch/interior/interior-plan.d.ts +114 -0
  86. package/dist/gen-arch/interior/interior-plan.js +615 -0
  87. package/dist/gen-arch/interior/interior.d.ts +97 -0
  88. package/dist/gen-arch/interior/interior.js +966 -0
  89. package/dist/gen-arch/structure/building-shader.d.ts +25 -0
  90. package/dist/gen-arch/structure/building-shader.js +946 -0
  91. package/dist/gen-arch/structure/buildings.d.ts +248 -0
  92. package/dist/gen-arch/structure/buildings.js +294 -0
  93. package/dist/gen-arch/structure/dims.d.ts +77 -0
  94. package/dist/gen-arch/structure/dims.js +39 -0
  95. package/dist/gen-arch/structure/distant.d.ts +62 -0
  96. package/dist/gen-arch/structure/distant.js +316 -0
  97. package/dist/gen-arch/structure/env-slots.d.ts +18 -0
  98. package/dist/gen-arch/structure/env-slots.js +47 -0
  99. package/dist/gen-arch/structure/facade.d.ts +193 -0
  100. package/dist/gen-arch/structure/facade.js +159 -0
  101. package/dist/gen-arch/structure/parts.d.ts +31 -0
  102. package/dist/gen-arch/structure/parts.js +69 -0
  103. package/dist/gen-arch/structure/roof.d.ts +76 -0
  104. package/dist/gen-arch/structure/roof.js +568 -0
  105. package/dist/gen-arch/structure/structure-material.d.ts +23 -0
  106. package/dist/gen-arch/structure/structure-material.js +55 -0
  107. package/dist/gen-arch/structure/writer.d.ts +94 -0
  108. package/dist/gen-arch/structure/writer.js +195 -0
  109. package/dist/gen-core/cell.d.ts +138 -0
  110. package/dist/gen-core/cell.js +150 -0
  111. package/dist/gen-core/cube-sphere.d.ts +57 -0
  112. package/dist/gen-core/cube-sphere.js +159 -0
  113. package/dist/gen-core/field.d.ts +55 -0
  114. package/dist/gen-core/field.js +154 -0
  115. package/dist/gen-core/geometry.d.ts +31 -0
  116. package/dist/gen-core/geometry.js +231 -0
  117. package/dist/gen-core/hash.d.ts +18 -0
  118. package/dist/gen-core/hash.js +58 -0
  119. package/dist/gen-core/height-field.d.ts +33 -0
  120. package/dist/gen-core/height-field.js +137 -0
  121. package/dist/gen-core/index.d.ts +22 -0
  122. package/dist/gen-core/index.js +17 -0
  123. package/dist/gen-core/instance-cells.d.ts +37 -0
  124. package/dist/gen-core/instance-cells.js +72 -0
  125. package/dist/gen-core/near-scatter.d.ts +56 -0
  126. package/dist/gen-core/near-scatter.js +120 -0
  127. package/dist/gen-core/noise.d.ts +23 -0
  128. package/dist/gen-core/noise.js +72 -0
  129. package/dist/gen-core/occupancy.d.ts +21 -0
  130. package/dist/gen-core/occupancy.js +104 -0
  131. package/dist/gen-core/sphere-patch.d.ts +138 -0
  132. package/dist/gen-core/sphere-patch.js +544 -0
  133. package/dist/gen-core/strip-surface.d.ts +34 -0
  134. package/dist/gen-core/strip-surface.js +246 -0
  135. package/dist/gen-core/strip.d.ts +102 -0
  136. package/dist/gen-core/strip.js +817 -0
  137. package/dist/gen-ground/env-slots.d.ts +48 -0
  138. package/dist/gen-ground/env-slots.js +78 -0
  139. package/dist/gen-ground/ground.d.ts +78 -0
  140. package/dist/gen-ground/ground.js +208 -0
  141. package/dist/gen-ground/index.d.ts +9 -0
  142. package/dist/gen-ground/index.js +7 -0
  143. package/dist/gen-ground/markings.d.ts +46 -0
  144. package/dist/gen-ground/markings.js +124 -0
  145. package/dist/gen-ground/materials.d.ts +18 -0
  146. package/dist/gen-ground/materials.js +22 -0
  147. package/dist/gen-ground/terrain-shader.d.ts +5 -0
  148. package/dist/gen-ground/terrain-shader.js +151 -0
  149. package/dist/gen-mesh/bare-shapes.d.ts +194 -0
  150. package/dist/gen-mesh/bare-shapes.js +596 -0
  151. package/dist/gen-mesh/bisect-surface.d.ts +47 -0
  152. package/dist/gen-mesh/bisect-surface.js +261 -0
  153. package/dist/gen-mesh/box.d.ts +18 -0
  154. package/dist/gen-mesh/box.js +2 -0
  155. package/dist/gen-mesh/cell-morph-mesh.d.ts +52 -0
  156. package/dist/gen-mesh/cell-morph-mesh.js +258 -0
  157. package/dist/gen-mesh/cell-surface-mesh.d.ts +32 -0
  158. package/dist/gen-mesh/cell-surface-mesh.js +140 -0
  159. package/dist/gen-mesh/chunk-mesh.d.ts +25 -0
  160. package/dist/gen-mesh/chunk-mesh.js +112 -0
  161. package/dist/gen-mesh/drape-mesh.d.ts +36 -0
  162. package/dist/gen-mesh/drape-mesh.js +98 -0
  163. package/dist/gen-mesh/height-field-mesh.d.ts +14 -0
  164. package/dist/gen-mesh/height-field-mesh.js +98 -0
  165. package/dist/gen-mesh/index.d.ts +26 -0
  166. package/dist/gen-mesh/index.js +15 -0
  167. package/dist/gen-mesh/line-mesh.d.ts +25 -0
  168. package/dist/gen-mesh/line-mesh.js +62 -0
  169. package/dist/gen-mesh/mesh-builder.d.ts +115 -0
  170. package/dist/gen-mesh/mesh-builder.js +315 -0
  171. package/dist/gen-mesh/packed-mesh.d.ts +53 -0
  172. package/dist/gen-mesh/packed-mesh.js +205 -0
  173. package/dist/gen-mesh/prism-mesh.d.ts +33 -0
  174. package/dist/gen-mesh/prism-mesh.js +176 -0
  175. package/dist/gen-mesh/rig-mesh.d.ts +9 -0
  176. package/dist/gen-mesh/rig-mesh.js +135 -0
  177. package/dist/gen-mesh/strip-mesh.d.ts +45 -0
  178. package/dist/gen-mesh/strip-mesh.js +258 -0
  179. package/dist/gen-plan/drain.d.ts +58 -0
  180. package/dist/gen-plan/drain.js +270 -0
  181. package/dist/gen-plan/grid.d.ts +37 -0
  182. package/dist/gen-plan/grid.js +182 -0
  183. package/dist/gen-plan/horizon.d.ts +50 -0
  184. package/dist/gen-plan/horizon.js +185 -0
  185. package/dist/gen-plan/index.d.ts +15 -0
  186. package/dist/gen-plan/index.js +13 -0
  187. package/dist/gen-plan/line-tiles.d.ts +35 -0
  188. package/dist/gen-plan/line-tiles.js +190 -0
  189. package/dist/gen-plan/lines.d.ts +31 -0
  190. package/dist/gen-plan/lines.js +183 -0
  191. package/dist/gen-plan/plots.d.ts +40 -0
  192. package/dist/gen-plan/plots.js +282 -0
  193. package/dist/gen-plan/route.d.ts +55 -0
  194. package/dist/gen-plan/route.js +297 -0
  195. package/dist/gen-plan/sites.d.ts +32 -0
  196. package/dist/gen-plan/sites.js +209 -0
  197. package/dist/gen-tex/code-stamp.d.ts +31 -0
  198. package/dist/gen-tex/code-stamp.js +137 -0
  199. package/dist/gen-tex/index.d.ts +7 -0
  200. package/dist/gen-tex/index.js +5 -0
  201. package/dist/gen-tex/light-horizon.d.ts +47 -0
  202. package/dist/gen-tex/light-horizon.js +180 -0
  203. package/dist/gen-tex/textures.d.ts +8 -0
  204. package/dist/gen-tex/textures.js +49 -0
  205. package/dist/gen-tex/value-textures.d.ts +46 -0
  206. package/dist/gen-tex/value-textures.js +102 -0
  207. package/dist/gen-vegetation/env-slots.d.ts +20 -0
  208. package/dist/gen-vegetation/env-slots.js +29 -0
  209. package/dist/gen-vegetation/index.d.ts +8 -0
  210. package/dist/gen-vegetation/index.js +7 -0
  211. package/dist/gen-vegetation/materials.d.ts +7 -0
  212. package/dist/gen-vegetation/materials.js +17 -0
  213. package/dist/gen-vegetation/planting.d.ts +170 -0
  214. package/dist/gen-vegetation/planting.js +363 -0
  215. package/dist/gen-vegetation/tree-shader.d.ts +23 -0
  216. package/dist/gen-vegetation/tree-shader.js +229 -0
  217. package/dist/gen-vegetation/trees.d.ts +59 -0
  218. package/dist/gen-vegetation/trees.js +329 -0
  219. package/dist/gpu/device.d.ts +286 -0
  220. package/dist/gpu/device.js +1157 -0
  221. package/dist/gpu/gl.d.ts +134 -0
  222. package/dist/gpu/gl.js +276 -0
  223. package/dist/gpu/index.d.ts +4 -0
  224. package/dist/gpu/index.js +3 -0
  225. package/dist/index.d.ts +11 -0
  226. package/dist/index.js +13 -0
  227. package/dist/motion/graph.d.ts +244 -0
  228. package/dist/motion/graph.js +739 -0
  229. package/dist/motion/index.d.ts +8 -0
  230. package/dist/motion/index.js +8 -0
  231. package/dist/motion/pose-ops.d.ts +30 -0
  232. package/dist/motion/pose-ops.js +232 -0
  233. package/dist/motion/reach.d.ts +45 -0
  234. package/dist/motion/reach.js +264 -0
  235. package/dist/motion/skeleton.d.ts +49 -0
  236. package/dist/motion/skeleton.js +99 -0
  237. package/dist/platform/byte-store.d.ts +21 -0
  238. package/dist/platform/byte-store.js +137 -0
  239. package/dist/platform/canvas.d.ts +29 -0
  240. package/dist/platform/canvas.js +76 -0
  241. package/dist/platform/context-loss.d.ts +8 -0
  242. package/dist/platform/context-loss.js +17 -0
  243. package/dist/platform/free-input.d.ts +51 -0
  244. package/dist/platform/free-input.js +100 -0
  245. package/dist/platform/index.d.ts +18 -0
  246. package/dist/platform/index.js +10 -0
  247. package/dist/platform/input.d.ts +48 -0
  248. package/dist/platform/input.js +117 -0
  249. package/dist/platform/keys.d.ts +12 -0
  250. package/dist/platform/keys.js +29 -0
  251. package/dist/platform/loop.d.ts +41 -0
  252. package/dist/platform/loop.js +84 -0
  253. package/dist/platform/walk-input.d.ts +74 -0
  254. package/dist/platform/walk-input.js +226 -0
  255. package/dist/platform/worker.d.ts +51 -0
  256. package/dist/platform/worker.js +170 -0
  257. package/dist/render/bone-instances.d.ts +24 -0
  258. package/dist/render/bone-instances.js +74 -0
  259. package/dist/render/cells.d.ts +70 -0
  260. package/dist/render/cells.js +144 -0
  261. package/dist/render/glsl.d.ts +66 -0
  262. package/dist/render/glsl.js +173 -0
  263. package/dist/render/index.d.ts +26 -0
  264. package/dist/render/index.js +16 -0
  265. package/dist/render/instance-sets.d.ts +97 -0
  266. package/dist/render/instance-sets.js +241 -0
  267. package/dist/render/near-instances.d.ts +75 -0
  268. package/dist/render/near-instances.js +219 -0
  269. package/dist/render/particles.d.ts +63 -0
  270. package/dist/render/particles.js +215 -0
  271. package/dist/render/pieces.d.ts +57 -0
  272. package/dist/render/pieces.js +151 -0
  273. package/dist/render/point-lights.d.ts +97 -0
  274. package/dist/render/point-lights.js +243 -0
  275. package/dist/render/renderer.d.ts +447 -0
  276. package/dist/render/renderer.js +1100 -0
  277. package/dist/render/rig.d.ts +74 -0
  278. package/dist/render/rig.js +576 -0
  279. package/dist/render/shadow-areas.d.ts +49 -0
  280. package/dist/render/shadow-areas.js +125 -0
  281. package/dist/render/shadow-glsl.d.ts +12 -0
  282. package/dist/render/shadow-glsl.js +146 -0
  283. package/dist/render/transient.d.ts +61 -0
  284. package/dist/render/transient.js +213 -0
  285. package/dist/render/value-glsl.d.ts +17 -0
  286. package/dist/render/value-glsl.js +208 -0
  287. package/dist/render/value-layers.d.ts +180 -0
  288. package/dist/render/value-layers.js +333 -0
  289. package/dist/runtime/atmosphere.d.ts +37 -0
  290. package/dist/runtime/atmosphere.js +304 -0
  291. package/dist/runtime/cloud-shell.d.ts +29 -0
  292. package/dist/runtime/cloud-shell.js +158 -0
  293. package/dist/runtime/engine.d.ts +155 -0
  294. package/dist/runtime/engine.js +305 -0
  295. package/dist/runtime/environment-link.d.ts +22 -0
  296. package/dist/runtime/environment-link.js +49 -0
  297. package/dist/runtime/index.d.ts +13 -0
  298. package/dist/runtime/index.js +12 -0
  299. package/dist/runtime/precipitation-glsl.d.ts +2 -0
  300. package/dist/runtime/precipitation-glsl.js +70 -0
  301. package/dist/runtime/precipitation.d.ts +11 -0
  302. package/dist/runtime/precipitation.js +78 -0
  303. package/dist/runtime/sky.d.ts +30 -0
  304. package/dist/runtime/sky.js +114 -0
  305. package/dist/runtime/streaming.d.ts +245 -0
  306. package/dist/runtime/streaming.js +602 -0
  307. package/dist/sim/agenda.d.ts +167 -0
  308. package/dist/sim/agenda.js +425 -0
  309. package/dist/sim/bytes.d.ts +34 -0
  310. package/dist/sim/bytes.js +125 -0
  311. package/dist/sim/destruction/apply.d.ts +59 -0
  312. package/dist/sim/destruction/apply.js +243 -0
  313. package/dist/sim/destruction/cell-states.d.ts +54 -0
  314. package/dist/sim/destruction/cell-states.js +198 -0
  315. package/dist/sim/destruction/index.d.ts +11 -0
  316. package/dist/sim/destruction/index.js +10 -0
  317. package/dist/sim/destruction/int-geometry.d.ts +17 -0
  318. package/dist/sim/destruction/int-geometry.js +131 -0
  319. package/dist/sim/destruction/pick.d.ts +13 -0
  320. package/dist/sim/destruction/pick.js +59 -0
  321. package/dist/sim/destruction/rubble.d.ts +8 -0
  322. package/dist/sim/destruction/rubble.js +159 -0
  323. package/dist/sim/destruction/state.d.ts +15 -0
  324. package/dist/sim/destruction/state.js +83 -0
  325. package/dist/sim/destruction/structure.d.ts +30 -0
  326. package/dist/sim/destruction/structure.js +139 -0
  327. package/dist/sim/events.d.ts +37 -0
  328. package/dist/sim/events.js +106 -0
  329. package/dist/sim/fixed.d.ts +21 -0
  330. package/dist/sim/fixed.js +64 -0
  331. package/dist/sim/flow-probe.d.ts +58 -0
  332. package/dist/sim/flow-probe.js +158 -0
  333. package/dist/sim/flow.d.ts +257 -0
  334. package/dist/sim/flow.js +967 -0
  335. package/dist/sim/index.d.ts +28 -0
  336. package/dist/sim/index.js +20 -0
  337. package/dist/sim/interlock.d.ts +47 -0
  338. package/dist/sim/interlock.js +252 -0
  339. package/dist/sim/movers.d.ts +228 -0
  340. package/dist/sim/movers.js +1083 -0
  341. package/dist/sim/nav.d.ts +72 -0
  342. package/dist/sim/nav.js +292 -0
  343. package/dist/sim/paths.d.ts +80 -0
  344. package/dist/sim/paths.js +197 -0
  345. package/dist/sim/regions.d.ts +87 -0
  346. package/dist/sim/regions.js +517 -0
  347. package/dist/sim/simulation.d.ts +114 -0
  348. package/dist/sim/simulation.js +291 -0
  349. package/dist/sim/states.d.ts +23 -0
  350. package/dist/sim/states.js +54 -0
  351. package/dist/sim/table.d.ts +49 -0
  352. package/dist/sim/table.js +126 -0
  353. package/dist/sim/zones.d.ts +11 -0
  354. package/dist/sim/zones.js +196 -0
  355. package/dist/tools/collision-lines.d.ts +12 -0
  356. package/dist/tools/collision-lines.js +50 -0
  357. package/dist/tools/data-view-glsl.d.ts +3 -0
  358. package/dist/tools/data-view-glsl.js +63 -0
  359. package/dist/tools/data-view-layers.d.ts +20 -0
  360. package/dist/tools/data-view-layers.js +60 -0
  361. package/dist/tools/debug-view.d.ts +30 -0
  362. package/dist/tools/debug-view.js +4 -0
  363. package/dist/tools/index.d.ts +10 -0
  364. package/dist/tools/index.js +7 -0
  365. package/dist/tools/mesh-checks.d.ts +67 -0
  366. package/dist/tools/mesh-checks.js +188 -0
  367. package/dist/tools/profile.d.ts +85 -0
  368. package/dist/tools/profile.js +173 -0
  369. package/dist/world/cell-cache.d.ts +32 -0
  370. package/dist/world/cell-cache.js +60 -0
  371. package/dist/world/cell-format.d.ts +25 -0
  372. package/dist/world/cell-format.js +232 -0
  373. package/dist/world/collide.d.ts +192 -0
  374. package/dist/world/collide.js +822 -0
  375. package/dist/world/index.d.ts +16 -0
  376. package/dist/world/index.js +12 -0
  377. package/dist/world/mesh-solids.d.ts +48 -0
  378. package/dist/world/mesh-solids.js +169 -0
  379. package/dist/world/pick.d.ts +34 -0
  380. package/dist/world/pick.js +177 -0
  381. package/dist/world/providers.d.ts +66 -0
  382. package/dist/world/providers.js +83 -0
  383. package/dist/world/sphere.d.ts +69 -0
  384. package/dist/world/sphere.js +271 -0
  385. package/dist/world/streaming.d.ts +288 -0
  386. package/dist/world/streaming.js +801 -0
  387. package/dist/world/walker.d.ts +145 -0
  388. package/dist/world/walker.js +502 -0
  389. package/docs/architecture.md +111 -0
  390. package/docs/cameras.md +302 -0
  391. package/docs/concepts.md +123 -0
  392. package/docs/destruction.md +127 -0
  393. package/docs/frames.md +199 -0
  394. package/docs/generators.md +575 -0
  395. package/docs/getting-started.md +123 -0
  396. package/docs/headless.md +50 -0
  397. package/docs/motion.md +160 -0
  398. package/docs/planet.md +152 -0
  399. package/docs/recipes.md +521 -0
  400. package/docs/reference.md +364 -0
  401. package/docs/rendering.md +823 -0
  402. package/docs/rigs.md +203 -0
  403. package/docs/simulation.md +235 -0
  404. package/docs/streaming.md +590 -0
  405. package/docs/system.md +166 -0
  406. package/docs/tools.md +175 -0
  407. package/docs/walking.md +262 -0
  408. package/package.json +131 -3
@@ -0,0 +1,77 @@
1
+ import type { Vec3 } from '../base/math.ts';
2
+ import { FrameSet } from '../base/frames.ts';
3
+ import type { Orbit, OrbitElements, Spin, SpinElements } from './kepler.ts';
4
+ /** Reach of a body when `BodyDef.influence` is not given, in radii. */
5
+ export declare const BODY_INFLUENCE_RADII = 5;
6
+ /** One body of a system. */
7
+ export interface BodyDef {
8
+ /** Unique name. */
9
+ name: string;
10
+ /** Name of the body this one goes round; it must come earlier in the list. Omitted: the centre of the system. */
11
+ parent?: string;
12
+ /** Mean radius in metres. */
13
+ radius: number;
14
+ /** Path round the parent. Omitted: the body stays at the parent's centre. */
15
+ orbit?: OrbitElements;
16
+ /** Turning about its own axis. Omitted: it does not turn and its axes are those of the system. */
17
+ spin?: SpinElements;
18
+ /** Radius of the sphere within which positions are best kept in this body's frames. Default `BODY_INFLUENCE_RADII` radii. */
19
+ influence?: number;
20
+ }
21
+ /** A body of a built system. */
22
+ export interface Body {
23
+ readonly index: number;
24
+ readonly name: string;
25
+ /** Index of the parent body, −1 at the centre of the system. */
26
+ readonly parent: number;
27
+ readonly radius: number;
28
+ readonly influence: number;
29
+ readonly orbit: Orbit | null;
30
+ readonly spin: Spin;
31
+ /** Frame at the body's centre with the axes of the system. */
32
+ readonly carriedFrame: number;
33
+ /** Frame at the body's centre that turns with the body; +y is its axis. */
34
+ readonly turningFrame: number;
35
+ }
36
+ /** Latitude and longitude on a body under another frame's origin, and the way to it. */
37
+ export interface SubPoint {
38
+ latitudeDeg: number;
39
+ longitudeDeg: number;
40
+ /** Unit direction from the body's centre in its turning frame. */
41
+ direction: Vec3;
42
+ /** Distance between the two centres. */
43
+ distance: number;
44
+ }
45
+ export declare class BodySystem {
46
+ /** All frames of the system. Further frames (patches, moving things) may be added under the body frames. */
47
+ readonly frames: FrameSet;
48
+ /** The top frame of the whole system. */
49
+ readonly root: number;
50
+ readonly bodies: readonly Body[];
51
+ private readonly byName;
52
+ private now;
53
+ constructor(defs: readonly BodyDef[]);
54
+ /** The body with this name; throws when there is none. */
55
+ body(name: string): Body;
56
+ /** Time the frames are placed for (seconds). */
57
+ get time(): number;
58
+ /** Places every body frame for time `t` (seconds). The result depends on `t` alone. */
59
+ setTime(t: number): void;
60
+ /** Places the frames for a whole tick of a clock with `hz` ticks per second. */
61
+ setTick(tick: number, hz: number): void;
62
+ /**
63
+ * The body whose reach holds the point `p` of frame `frame`: the most deeply nested one, and of several equally
64
+ * deep the one the point is relatively nearest to. −1 when the point is within no reach. `reach` scales every
65
+ * influence radius; pass a little more than 1 when asking whether to leave a body, so the answer does not flip
66
+ * on the boundary.
67
+ */
68
+ dominantBody(p: readonly [number, number, number], frame: number, reach?: number): number;
69
+ /**
70
+ * The point of body `body` that has the origin of frame `target` straight overhead. With the frame of the light
71
+ * as the target, the latitude is the season (it swings between plus and minus the tilt over one round) and the
72
+ * longitude is where it is noon.
73
+ */
74
+ subPoint(body: number, target: number): SubPoint;
75
+ /** Digest of every frame of the system at the current time (`FrameSet.fingerprint`). */
76
+ fingerprint(): number;
77
+ }
@@ -0,0 +1,125 @@
1
+ // A system of bodies on rails, laid out as nested frames. Each body gets two frames in a `FrameSet`:
2
+ // - a carried frame: its origin is the centre of the body, its axes stay parallel to the axes of the whole system;
3
+ // bodies that go round this body hang under it, so they do not turn with it;
4
+ // - a turning frame under it: the same origin, turned by the body's spin; what stands on the body hangs under it.
5
+ // `setTime` places every frame from the time alone (`kepler.ts`), so the state at a time T does not depend on how
6
+ // the clock got there. Keep the time as a whole number of ticks and divide (`setTick`); a sum of fractional steps
7
+ // would itself differ between a stepped and a jumped run.
8
+ //
9
+ // Day, night and seasons need no code of their own: the direction from a point of a turning frame to the frame of
10
+ // the light (`FrameSet.directionTo`) changes with the spin, and the latitude under the light (`subPoint`) swings
11
+ // with the tilt over one round.
12
+ import { FrameSet, directionToDeg } from '../base/frames.js';
13
+ import { orbitPosition, orbitVelocity, prepareOrbit, prepareSpin, spinRate, spinRotation } from './kepler.js';
14
+ /** Reach of a body when `BodyDef.influence` is not given, in radii. */
15
+ export const BODY_INFLUENCE_RADII = 5;
16
+ export class BodySystem {
17
+ /** All frames of the system. Further frames (patches, moving things) may be added under the body frames. */
18
+ frames = new FrameSet();
19
+ /** The top frame of the whole system. */
20
+ root;
21
+ bodies;
22
+ byName = new Map();
23
+ now = 0;
24
+ constructor(defs) {
25
+ this.root = this.frames.add('system');
26
+ const bodies = [];
27
+ for (const def of defs) {
28
+ if (this.byName.has(def.name))
29
+ throw new Error(`bodies: two bodies are named "${def.name}"`);
30
+ if (!(def.radius > 0))
31
+ throw new Error(`bodies: "${def.name}" needs a positive radius`);
32
+ const parent = def.parent === undefined ? null : this.byName.get(def.parent);
33
+ if (parent === undefined)
34
+ throw new Error(`bodies: parent "${def.parent}" of "${def.name}" is not defined before it`);
35
+ const carriedFrame = this.frames.add(def.name, parent ? parent.carriedFrame : this.root);
36
+ const turningFrame = this.frames.add(`${def.name}/turning`, carriedFrame);
37
+ const body = {
38
+ index: bodies.length,
39
+ name: def.name,
40
+ parent: parent ? parent.index : -1,
41
+ radius: def.radius,
42
+ influence: def.influence ?? def.radius * BODY_INFLUENCE_RADII,
43
+ orbit: def.orbit ? prepareOrbit(def.orbit) : null,
44
+ spin: prepareSpin(def.spin),
45
+ carriedFrame,
46
+ turningFrame,
47
+ };
48
+ bodies.push(body);
49
+ this.byName.set(body.name, body);
50
+ }
51
+ this.bodies = bodies;
52
+ this.setTime(0);
53
+ }
54
+ /** The body with this name; throws when there is none. */
55
+ body(name) {
56
+ const b = this.byName.get(name);
57
+ if (!b)
58
+ throw new Error(`bodies: no body "${name}"`);
59
+ return b;
60
+ }
61
+ /** Time the frames are placed for (seconds). */
62
+ get time() {
63
+ return this.now;
64
+ }
65
+ /** Places every body frame for time `t` (seconds). The result depends on `t` alone. */
66
+ setTime(t) {
67
+ this.now = t;
68
+ const p = [0, 0, 0];
69
+ const v = [0, 0, 0];
70
+ const w = [0, 0, 0];
71
+ for (const b of this.bodies) {
72
+ if (b.orbit) {
73
+ this.frames.setOrigin(b.carriedFrame, orbitPosition(b.orbit, t, p));
74
+ this.frames.setMotion(b.carriedFrame, orbitVelocity(b.orbit, t, v));
75
+ }
76
+ this.frames.setRotation(b.turningFrame, spinRotation(b.spin, t));
77
+ this.frames.setMotion(b.turningFrame, [0, 0, 0], spinRate(b.spin, w));
78
+ }
79
+ }
80
+ /** Places the frames for a whole tick of a clock with `hz` ticks per second. */
81
+ setTick(tick, hz) {
82
+ this.setTime(tick / hz);
83
+ }
84
+ /**
85
+ * The body whose reach holds the point `p` of frame `frame`: the most deeply nested one, and of several equally
86
+ * deep the one the point is relatively nearest to. −1 when the point is within no reach. `reach` scales every
87
+ * influence radius; pass a little more than 1 when asking whether to leave a body, so the answer does not flip
88
+ * on the boundary.
89
+ */
90
+ dominantBody(p, frame, reach = 1) {
91
+ let best = -1;
92
+ let bestDepth = -1;
93
+ let bestShare = 0;
94
+ const local = [0, 0, 0];
95
+ for (const b of this.bodies) {
96
+ this.frames.convertPoint(p, frame, b.carriedFrame, local);
97
+ const share = Math.sqrt(local[0] * local[0] + local[1] * local[1] + local[2] * local[2]) / (b.influence * reach);
98
+ if (share > 1)
99
+ continue;
100
+ const depth = this.frames.depth(b.carriedFrame);
101
+ if (depth > bestDepth || (depth === bestDepth && share < bestShare)) {
102
+ best = b.index;
103
+ bestDepth = depth;
104
+ bestShare = share;
105
+ }
106
+ }
107
+ return best;
108
+ }
109
+ /**
110
+ * The point of body `body` that has the origin of frame `target` straight overhead. With the frame of the light
111
+ * as the target, the latitude is the season (it swings between plus and minus the tilt over one round) and the
112
+ * longitude is where it is noon.
113
+ */
114
+ subPoint(body, target) {
115
+ const b = this.bodies[body];
116
+ if (!b)
117
+ throw new Error(`bodies: no body ${body}`);
118
+ const { direction, distance } = this.frames.directionTo(target, b.turningFrame);
119
+ return { ...directionToDeg(direction), direction, distance };
120
+ }
121
+ /** Digest of every frame of the system at the current time (`FrameSet.fingerprint`). */
122
+ fingerprint() {
123
+ return this.frames.fingerprint();
124
+ }
125
+ }
@@ -0,0 +1,37 @@
1
+ export interface ClockOptions {
2
+ /** Initial value. */
3
+ time?: number;
4
+ /** How many clock units pass per second of real time. */
5
+ rate?: number;
6
+ playing?: boolean;
7
+ /** When given, the value is kept in the range 0 to wrap (hour of day: 24). */
8
+ wrap?: number;
9
+ }
10
+ export declare class Clock {
11
+ private value;
12
+ private speed;
13
+ private running;
14
+ private readonly wrap;
15
+ private readonly listeners;
16
+ constructor(options?: ClockOptions);
17
+ private fold;
18
+ private changed;
19
+ /** Current clock value. */
20
+ get time(): number;
21
+ get rate(): number;
22
+ get playing(): boolean;
23
+ /** Does the value change on its own? Only then is continuous drawing needed. */
24
+ get animating(): boolean;
25
+ play(): void;
26
+ pause(): void;
27
+ toggle(): void;
28
+ setRate(rate: number): void;
29
+ /** Sets an exact value. Does not change running or speed. */
30
+ set(time: number): void;
31
+ /** Advances the clock by a fixed step in its units, even when stopped. */
32
+ step(delta: number): void;
33
+ /** Feeds a piece of real time into the clock. Called by the frame loop. Returns true when the value changed. */
34
+ advance(realSeconds: number): boolean;
35
+ /** Reports every change from outside (setting, start, stop, speed). Returns an unsubscribe function. */
36
+ onChange(listener: () => void): () => void;
37
+ }
@@ -0,0 +1,87 @@
1
+ // Animation clock. The single source of time for everything that moves in the scene: it runs, stops, can be sped up,
2
+ // set to an exact value and advanced by a fixed step. Real time is fed in only by the frame loop
3
+ // (loop.ts), so the same clock value always gives the same image and a frame of a specific moment can be reproduced.
4
+ export class Clock {
5
+ value;
6
+ speed;
7
+ running;
8
+ wrap;
9
+ listeners = new Set();
10
+ constructor(options = {}) {
11
+ this.wrap = options.wrap ?? 0;
12
+ this.value = this.fold(options.time ?? 0);
13
+ this.speed = options.rate ?? 1;
14
+ this.running = options.playing ?? false;
15
+ }
16
+ fold(t) {
17
+ if (this.wrap <= 0)
18
+ return t;
19
+ return ((t % this.wrap) + this.wrap) % this.wrap;
20
+ }
21
+ changed() {
22
+ for (const l of this.listeners)
23
+ l();
24
+ }
25
+ /** Current clock value. */
26
+ get time() {
27
+ return this.value;
28
+ }
29
+ get rate() {
30
+ return this.speed;
31
+ }
32
+ get playing() {
33
+ return this.running;
34
+ }
35
+ /** Does the value change on its own? Only then is continuous drawing needed. */
36
+ get animating() {
37
+ return this.running && this.speed !== 0;
38
+ }
39
+ play() {
40
+ if (this.running)
41
+ return;
42
+ this.running = true;
43
+ this.changed();
44
+ }
45
+ pause() {
46
+ if (!this.running)
47
+ return;
48
+ this.running = false;
49
+ this.changed();
50
+ }
51
+ toggle() {
52
+ if (this.running)
53
+ this.pause();
54
+ else
55
+ this.play();
56
+ }
57
+ setRate(rate) {
58
+ if (rate === this.speed)
59
+ return;
60
+ this.speed = rate;
61
+ this.changed();
62
+ }
63
+ /** Sets an exact value. Does not change running or speed. */
64
+ set(time) {
65
+ const t = this.fold(time);
66
+ if (t === this.value)
67
+ return;
68
+ this.value = t;
69
+ this.changed();
70
+ }
71
+ /** Advances the clock by a fixed step in its units, even when stopped. */
72
+ step(delta) {
73
+ this.set(this.value + delta);
74
+ }
75
+ /** Feeds a piece of real time into the clock. Called by the frame loop. Returns true when the value changed. */
76
+ advance(realSeconds) {
77
+ if (!this.animating || realSeconds <= 0)
78
+ return false;
79
+ this.value = this.fold(this.value + realSeconds * this.speed);
80
+ return true;
81
+ }
82
+ /** Reports every change from outside (setting, start, stop, speed). Returns an unsubscribe function. */
83
+ onChange(listener) {
84
+ this.listeners.add(listener);
85
+ return () => this.listeners.delete(listener);
86
+ }
87
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Share of the far look, 0–1, for content whose objects exist in cells of the level `objectLevel` and finer.
3
+ * `cellLevel` is the level of the cell being drawn and `morph` its blend factor toward its parent (0 = own shape,
4
+ * 1 = the parent's). Finer cells give 0, coarser cells 1, and the cells of `objectLevel` follow their blend.
5
+ */
6
+ export declare function coverFade(objectLevel: number, cellLevel: number, morph: number): number;
7
+ /**
8
+ * Size of one object, 0–1, at a share of the far look. `order` is a number 0–1 fixed per object: objects with a low
9
+ * one leave first, and each shrinks over a tenth of the band before it is gone. At `fade` 0 every object is whole,
10
+ * at 1 none is left, and in between about `1 − fade` of them remain.
11
+ */
12
+ export declare function coverKeep(fade: number, order: number): number;
13
+ /** GLSL of `coverFade` and `coverKeep` (any shader stage; needs nothing before it). */
14
+ export declare const COVER_FADE_GLSL = "\nfloat coverFade(float objectLevel, float cellLevel, float morph) {\n return clamp(objectLevel - cellLevel + morph, 0.0, 1.0);\n}\nfloat coverKeep(float fade, float order) {\n return clamp((order * 0.9 + 0.1 - fade) * 10.0, 0.0, 1.0);\n}\n";
@@ -0,0 +1,38 @@
1
+ // Content that is drawn as separate objects near the viewer and carried by the colour of the surface farther away.
2
+ //
3
+ // A streamed world keeps objects only in its finest levels of cells. Beyond them the surface itself must look as the
4
+ // objects did from afar: its vertices carry a "cover" baked by the generator (a colour and the share of the surface
5
+ // the objects hide, see `coverAt` of the sphere patch), and the surface shader mixes it in. The change is spread
6
+ // over the band in which the cells of the coarsest level with objects blend into their parent's shape (the morph
7
+ // factor of the streamed world): across that band the objects leave one by one while the cover comes in by the same
8
+ // share, so nothing appears or vanishes at once, and an area covered with objects keeps its colour and its outline
9
+ // at any distance. The engine does not know what the objects are; the content decides the share and the colour.
10
+ //
11
+ // `coverFade` is the share of the far look, `coverKeep` the size of one object at that share. Both exist here as
12
+ // functions and, with the same names and arithmetic, as GLSL.
13
+ const clamp01 = (v) => Math.min(1, Math.max(0, v));
14
+ /**
15
+ * Share of the far look, 0–1, for content whose objects exist in cells of the level `objectLevel` and finer.
16
+ * `cellLevel` is the level of the cell being drawn and `morph` its blend factor toward its parent (0 = own shape,
17
+ * 1 = the parent's). Finer cells give 0, coarser cells 1, and the cells of `objectLevel` follow their blend.
18
+ */
19
+ export function coverFade(objectLevel, cellLevel, morph) {
20
+ return clamp01(objectLevel - cellLevel + morph);
21
+ }
22
+ /**
23
+ * Size of one object, 0–1, at a share of the far look. `order` is a number 0–1 fixed per object: objects with a low
24
+ * one leave first, and each shrinks over a tenth of the band before it is gone. At `fade` 0 every object is whole,
25
+ * at 1 none is left, and in between about `1 − fade` of them remain.
26
+ */
27
+ export function coverKeep(fade, order) {
28
+ return clamp01((order * 0.9 + 0.1 - fade) * 10);
29
+ }
30
+ /** GLSL of `coverFade` and `coverKeep` (any shader stage; needs nothing before it). */
31
+ export const COVER_FADE_GLSL = /* glsl */ `
32
+ float coverFade(float objectLevel, float cellLevel, float morph) {
33
+ return clamp(objectLevel - cellLevel + morph, 0.0, 1.0);
34
+ }
35
+ float coverKeep(float fade, float order) {
36
+ return clamp((order * 0.9 + 0.1 - fade) * 10.0, 0.0, 1.0);
37
+ }
38
+ `;
@@ -0,0 +1,13 @@
1
+ export { Clock } from './clock.ts';
2
+ export type { ClockOptions } from './clock.ts';
3
+ export { PALETTE_CAPACITY, definePalette } from './palette.ts';
4
+ export type { Palette } from './palette.ts';
5
+ export { TRACK_CRUMBLE_S, TRACK_FLOATS, TRACK_GLSL, TRACK_GRAVITY, TRACK_MAX_FLIGHT_S, trackAttribs, trackFlightTime, trackLifetime, trackPose, writeTrack } from './ballistic.ts';
6
+ export type { BallisticTrack, DustPuff, TrackPose } from './ballistic.ts';
7
+ export { ORBIT_MAX_ECCENTRICITY, ORBIT_SOLVER_STEPS, orbitPosition, orbitVelocity, prepareOrbit, prepareSpin, solveKepler, spinRate, spinRotation } from './kepler.ts';
8
+ export type { Orbit, OrbitElements, Spin, SpinElements } from './kepler.ts';
9
+ export { BODY_INFLUENCE_RADII, BodySystem } from './bodies.ts';
10
+ export type { Body, BodyDef, SubPoint } from './bodies.ts';
11
+ export { FADE_GLSL, LevelFade, fadeFragment, withFade } from './level-fade.ts';
12
+ export type { LevelFadeOptions } from './level-fade.ts';
13
+ export { COVER_FADE_GLSL, coverFade, coverKeep } from './cover-fade.ts';
@@ -0,0 +1,8 @@
1
+ // Layer 2, core: clocks and the palette mechanism.
2
+ export { Clock } from './clock.js';
3
+ export { PALETTE_CAPACITY, definePalette } from './palette.js';
4
+ export { TRACK_CRUMBLE_S, TRACK_FLOATS, TRACK_GLSL, TRACK_GRAVITY, TRACK_MAX_FLIGHT_S, trackAttribs, trackFlightTime, trackLifetime, trackPose, writeTrack } from './ballistic.js';
5
+ export { ORBIT_MAX_ECCENTRICITY, ORBIT_SOLVER_STEPS, orbitPosition, orbitVelocity, prepareOrbit, prepareSpin, solveKepler, spinRate, spinRotation } from './kepler.js';
6
+ export { BODY_INFLUENCE_RADII, BodySystem } from './bodies.js';
7
+ export { FADE_GLSL, LevelFade, fadeFragment, withFade } from './level-fade.js';
8
+ export { COVER_FADE_GLSL, coverFade, coverKeep } from './cover-fade.js';
@@ -0,0 +1,74 @@
1
+ import type { Vec3 } from '../base/math.ts';
2
+ import type { Quat } from '../base/frames.ts';
3
+ /**
4
+ * Newton steps of the ellipse solver. Always all of them: the result must not depend on a convergence test. Six
5
+ * steps reach the last bit over the whole allowed range of eccentricity; two more are a reserve.
6
+ */
7
+ export declare const ORBIT_SOLVER_STEPS = 8;
8
+ /** Largest eccentricity the fixed number of steps solves to full precision; `prepareOrbit` rejects more. */
9
+ export declare const ORBIT_MAX_ECCENTRICITY = 0.9;
10
+ /** A Kepler ellipse round the origin of the parent frame. Angles in degrees, lengths in metres, time in seconds. */
11
+ export interface OrbitElements {
12
+ /** Half of the long axis of the ellipse. */
13
+ semiMajorAxis: number;
14
+ /** Time of one round. Negative goes round the other way. */
15
+ periodS: number;
16
+ /** 0 is a circle; at most `ORBIT_MAX_ECCENTRICITY`. Default 0. */
17
+ eccentricity?: number;
18
+ /** Tilt of the orbit plane against the reference plane. Default 0. */
19
+ inclinationDeg?: number;
20
+ /** Longitude at which the orbit rises through the reference plane. Default 0. */
21
+ ascendingNodeDeg?: number;
22
+ /** Angle in the orbit plane from the ascending node to the point nearest the parent. Default 0. */
23
+ periapsisDeg?: number;
24
+ /** Where on the round the body is at time 0, in turns of mean anomaly (0 = nearest the parent). Default 0. */
25
+ phase?: number;
26
+ }
27
+ /** An orbit prepared for evaluation: the two axes of the ellipse as vectors and its timing. */
28
+ export interface Orbit {
29
+ /** From the centre of attraction toward the nearest point, length = semi-major axis. */
30
+ readonly major: Vec3;
31
+ /** A quarter turn ahead in the orbit plane, length = semi-minor axis. */
32
+ readonly minor: Vec3;
33
+ readonly eccentricity: number;
34
+ readonly periodS: number;
35
+ readonly phase: number;
36
+ }
37
+ /** Checks the elements and works out the constant part of the orbit. */
38
+ export declare function prepareOrbit(el: OrbitElements): Orbit;
39
+ /**
40
+ * Solves Kepler's equation E − e·sin E = M for the mean anomaly given in turns, with exactly `ORBIT_SOLVER_STEPS`
41
+ * Newton steps. Returns `[sin E, cos E, E]` (E in radians, −π … π).
42
+ */
43
+ export declare function solveKepler(meanTurns: number, eccentricity: number, out?: [number, number, number]): [number, number, number];
44
+ /** Position on the orbit at time `t` (seconds), in the parent frame, relative to the centre of attraction. */
45
+ export declare function orbitPosition(o: Orbit, t: number, out?: Vec3): Vec3;
46
+ /** Velocity on the orbit at time `t` (m/s), the exact derivative of `orbitPosition`. */
47
+ export declare function orbitVelocity(o: Orbit, t: number, out?: Vec3): Vec3;
48
+ /** Turning of a body about its own axis. Angles in degrees, time in seconds. */
49
+ export interface SpinElements {
50
+ /** Time of one turn against the fixed directions of the parent. Negative turns the other way; omitted or 0 does not turn. */
51
+ periodS?: number;
52
+ /** Angle between the axis and the parent's +y. Default 0. */
53
+ tiltDeg?: number;
54
+ /** Longitude toward which the +y end of the axis leans. Default 0. */
55
+ tiltLongitudeDeg?: number;
56
+ /** Turn at time 0, in turns. Default 0. */
57
+ phase?: number;
58
+ }
59
+ /** A spin prepared for evaluation. */
60
+ export interface Spin {
61
+ /** Unit axis in the parent frame; the body's own +y. */
62
+ readonly axis: Vec3;
63
+ /** The rotation that tilts +y onto the axis. */
64
+ readonly tilt: Quat;
65
+ /** 0 when the body does not turn. */
66
+ readonly periodS: number;
67
+ readonly phase: number;
68
+ }
69
+ /** Works out the constant part of a spin. */
70
+ export declare function prepareSpin(el?: SpinElements): Spin;
71
+ /** Rotation of the body in its parent at time `t` (seconds): the turn about its own +y, then the tilt. */
72
+ export declare function spinRotation(s: Spin, t: number): Quat;
73
+ /** Angular velocity of the body in its parent (rad/s, along the axis). */
74
+ export declare function spinRate(s: Spin, out?: Vec3): Vec3;
@@ -0,0 +1,108 @@
1
+ // Motion "on rails": where a body is and how it is turned are closed-form functions of time. A body goes round its
2
+ // parent on a Kepler ellipse and turns about a fixed, tilted axis. Nothing is integrated and nothing is carried from
3
+ // one call to the next, so stepping through time and jumping straight to a moment give the same bits, and the clock
4
+ // can run at any rate or backwards.
5
+ //
6
+ // The ellipse is solved with a fixed number of Newton steps and with the reproducible sine and cosine of
7
+ // `base/trig.ts`; the only other operations are + − × ÷ and `Math.sqrt`. The same input therefore gives the same
8
+ // 64-bit result on every machine.
9
+ //
10
+ // Axes: y is up, the reference plane of an orbit is the xz plane. Longitudes are measured in that plane from +x
11
+ // toward −z, which is anticlockwise seen from +y. A body with a positive period goes round and turns that way.
12
+ import { detSinCos, detSinCosTurns, RAD_PER_TURN } from '../base/trig.js';
13
+ import { quatAxisTurns, quatMul } from '../base/frames.js';
14
+ /**
15
+ * Newton steps of the ellipse solver. Always all of them: the result must not depend on a convergence test. Six
16
+ * steps reach the last bit over the whole allowed range of eccentricity; two more are a reserve.
17
+ */
18
+ export const ORBIT_SOLVER_STEPS = 8;
19
+ /** Largest eccentricity the fixed number of steps solves to full precision; `prepareOrbit` rejects more. */
20
+ export const ORBIT_MAX_ECCENTRICITY = 0.9;
21
+ /** Checks the elements and works out the constant part of the orbit. */
22
+ export function prepareOrbit(el) {
23
+ const e = el.eccentricity ?? 0;
24
+ if (!(el.semiMajorAxis > 0))
25
+ throw new Error('orbit: semiMajorAxis must be positive');
26
+ if (el.periodS === 0 || el.periodS !== el.periodS)
27
+ throw new Error('orbit: periodS must be a number other than 0');
28
+ if (!(e >= 0 && e <= ORBIT_MAX_ECCENTRICITY))
29
+ throw new Error(`orbit: eccentricity must be 0 … ${ORBIT_MAX_ECCENTRICITY}`);
30
+ const [sinI, cosI] = detSinCosTurns((el.inclinationDeg ?? 0) / 360);
31
+ const [sinN, cosN] = detSinCosTurns((el.ascendingNodeDeg ?? 0) / 360);
32
+ const [sinP, cosP] = detSinCosTurns((el.periapsisDeg ?? 0) / 360);
33
+ // The usual perifocal axes for a reference plane XY with Z up, then (X, Y, Z) → (x, −z, y).
34
+ const a = el.semiMajorAxis;
35
+ const b = a * Math.sqrt((1 - e) * (1 + e));
36
+ const major = [a * (cosN * cosP - sinN * sinP * cosI), a * (sinP * sinI), -a * (sinN * cosP + cosN * sinP * cosI)];
37
+ const minor = [b * (-cosN * sinP - sinN * cosP * cosI), b * (cosP * sinI), -b * (-sinN * sinP + cosN * cosP * cosI)];
38
+ return { major, minor, eccentricity: e, periodS: el.periodS, phase: el.phase ?? 0 };
39
+ }
40
+ /**
41
+ * Solves Kepler's equation E − e·sin E = M for the mean anomaly given in turns, with exactly `ORBIT_SOLVER_STEPS`
42
+ * Newton steps. Returns `[sin E, cos E, E]` (E in radians, −π … π).
43
+ */
44
+ export function solveKepler(meanTurns, eccentricity, out = [0, 0, 0]) {
45
+ const e = eccentricity;
46
+ const f = meanTurns - Math.floor(meanTurns);
47
+ // Half a round is solved, the other half is its mirror image.
48
+ const mirrored = f > 0.5;
49
+ const m = (mirrored ? 1 - f : f) * RAD_PER_TURN; // 0 … π
50
+ // The function is convex on 0 … π and not negative at this start, so every step comes down toward the root.
51
+ let E = m + e;
52
+ if (E > Math.PI)
53
+ E = Math.PI;
54
+ const sc = [0, 0];
55
+ for (let i = 0; i < ORBIT_SOLVER_STEPS; i++) {
56
+ detSinCos(E, sc);
57
+ E -= (E - e * sc[0] - m) / (1 - e * sc[1]);
58
+ }
59
+ detSinCos(E, sc);
60
+ out[0] = mirrored ? -sc[0] : sc[0];
61
+ out[1] = sc[1];
62
+ out[2] = mirrored ? -E : E;
63
+ return out;
64
+ }
65
+ /** Position on the orbit at time `t` (seconds), in the parent frame, relative to the centre of attraction. */
66
+ export function orbitPosition(o, t, out = [0, 0, 0]) {
67
+ const [sinE, cosE] = solveKepler(o.phase + t / o.periodS, o.eccentricity);
68
+ const x = cosE - o.eccentricity;
69
+ out[0] = o.major[0] * x + o.minor[0] * sinE;
70
+ out[1] = o.major[1] * x + o.minor[1] * sinE;
71
+ out[2] = o.major[2] * x + o.minor[2] * sinE;
72
+ return out;
73
+ }
74
+ /** Velocity on the orbit at time `t` (m/s), the exact derivative of `orbitPosition`. */
75
+ export function orbitVelocity(o, t, out = [0, 0, 0]) {
76
+ const [sinE, cosE] = solveKepler(o.phase + t / o.periodS, o.eccentricity);
77
+ const rate = RAD_PER_TURN / o.periodS / (1 - o.eccentricity * cosE); // dE/dt
78
+ const vx = -sinE * rate;
79
+ const vy = cosE * rate;
80
+ out[0] = o.major[0] * vx + o.minor[0] * vy;
81
+ out[1] = o.major[1] * vx + o.minor[1] * vy;
82
+ out[2] = o.major[2] * vx + o.minor[2] * vy;
83
+ return out;
84
+ }
85
+ /** Works out the constant part of a spin. */
86
+ export function prepareSpin(el = {}) {
87
+ const periodS = el.periodS ?? 0;
88
+ if (periodS !== periodS)
89
+ throw new Error('spin: periodS is not a number');
90
+ const [sinL, cosL] = detSinCosTurns((el.tiltLongitudeDeg ?? 0) / 360);
91
+ const [sinT, cosT] = detSinCosTurns((el.tiltDeg ?? 0) / 360);
92
+ // +y is tilted toward the horizontal direction (cos L, 0, −sin L) by turning about (+y) × (that direction).
93
+ const tilt = quatAxisTurns([-sinL, 0, -cosL], (el.tiltDeg ?? 0) / 360);
94
+ return { axis: [sinT * cosL, cosT, -sinT * sinL], tilt, periodS, phase: el.phase ?? 0 };
95
+ }
96
+ /** Rotation of the body in its parent at time `t` (seconds): the turn about its own +y, then the tilt. */
97
+ export function spinRotation(s, t) {
98
+ const turns = s.periodS === 0 ? s.phase : s.phase + t / s.periodS;
99
+ return quatMul(s.tilt, quatAxisTurns([0, 1, 0], turns));
100
+ }
101
+ /** Angular velocity of the body in its parent (rad/s, along the axis). */
102
+ export function spinRate(s, out = [0, 0, 0]) {
103
+ const w = s.periodS === 0 ? 0 : RAD_PER_TURN / s.periodS;
104
+ out[0] = s.axis[0] * w;
105
+ out[1] = s.axis[1] * w;
106
+ out[2] = s.axis[2] * w;
107
+ return out;
108
+ }
@@ -0,0 +1,66 @@
1
+ import type { MaterialDesc, Uniforms } from '../base/index.ts';
2
+ export interface LevelFadeOptions {
3
+ /**
4
+ * Thresholds in descending order. Level 0 is the most detailed; level k + 1 takes over once the value drops below
5
+ * `below[k]`. There are `below.length + 1` levels.
6
+ */
7
+ below: readonly number[];
8
+ /** Dead band around a threshold as a share of it (default 0.15): coarser below `t × (1 − h)`, finer above `t × (1 + h)`. */
9
+ hysteresis?: number;
10
+ /** Seconds a transition between two neighbouring levels takes (default 0.35). 0 switches at once. */
11
+ seconds?: number;
12
+ }
13
+ /**
14
+ * Chooses a level from a value and moves a continuous position towards it. Position 1.3 means: 30 % of the way from
15
+ * level 1 to level 2. What is drawn at a position comes from `fade` (the `u_fade` value of a layer) and `shown`.
16
+ */
17
+ export declare class LevelFade {
18
+ /** Number of levels. */
19
+ readonly count: number;
20
+ /** Highest level that may be shown now. Lower it while a coarser level is not ready; the position follows. */
21
+ limit: number;
22
+ private readonly below;
23
+ private readonly hysteresis;
24
+ private readonly seconds;
25
+ private target;
26
+ private pos;
27
+ private started;
28
+ constructor(o: LevelFadeOptions);
29
+ /** The level the value asks for (ignores `limit` and the transition). */
30
+ get level(): number;
31
+ /** Where the transition is: a whole number when at rest, between two levels while moving. */
32
+ get position(): number;
33
+ /** Whether a transition is under way. */
34
+ get moving(): boolean;
35
+ /**
36
+ * Takes the current value and the time since the last call. The first call places the position on its level without
37
+ * a transition. Returns whether the position still has to move, that is, whether another frame is needed.
38
+ */
39
+ update(value: number, dtSeconds: number): boolean;
40
+ /** Ends the transition at once (after a jump of the view, for example). */
41
+ snap(): void;
42
+ /** Whether anything drawn on the levels `first`…`last` is visible at the current position. */
43
+ shown(first: number, last?: number): boolean;
44
+ /**
45
+ * `u_fade` of something drawn on the levels `first`…`last`: x the share of fragments left out (0 inside the span,
46
+ * growing to 1 one level away), y the side of the pattern (0 when leaving towards coarser levels, 1 towards finer
47
+ * ones). Two neighbouring spans get complementary patterns, so together they cover every fragment exactly once.
48
+ */
49
+ fade(first: number, last?: number): [number, number];
50
+ /** The same as a uniform set: `{ u_fade }`. */
51
+ uniforms(first: number, last?: number): Uniforms;
52
+ }
53
+ /**
54
+ * GLSL of the screen-door fade (fragment shader): `uniform vec2 u_fade` (x share of fragments left out 0–1, y > 0.5
55
+ * the complementary side of the pattern) and `bool fadeHidden(vec2 frag)`, called with `gl_FragCoord.xy`. A uniform
56
+ * that is never set is zero: everything is drawn. The threshold is interleaved gradient noise of the fragment
57
+ * position, so the pattern is even at every share and the same in every program.
58
+ */
59
+ export declare const FADE_GLSL = "uniform vec2 u_fade;\nbool fadeHidden(vec2 frag) {\n float t = fract(52.9829189 * fract(dot(floor(frag), vec2(0.06711056, 0.00583715))));\n return (u_fade.y > 0.5 ? 1.0 - t : t) < u_fade.x;\n}\n";
60
+ /** A fragment shader with the screen-door fade added in front of everything else in `main`. */
61
+ export declare function fadeFragment(fs: string): string;
62
+ /**
63
+ * The material with the screen-door fade in every pass that has its own program (`u_fade`, see `FADE_GLSL`). A pass
64
+ * drawn by the plain depth program (`'depth'`) stays as it is. The original description is not touched.
65
+ */
66
+ export declare function withFade(desc: MaterialDesc): MaterialDesc;