@johnmorrisdotca/wakusei-planets 0.34.0 → 0.36.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 (215) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/NOTICE.md +64 -0
  3. package/README.md +21 -3
  4. package/dist/approaches.d.ts +276 -0
  5. package/dist/approaches.js +255 -0
  6. package/dist/asteroids.d.ts +397 -0
  7. package/dist/asteroids.js +338 -0
  8. package/dist/comets.d.ts +316 -0
  9. package/dist/comets.js +404 -0
  10. package/dist/craft/bepicolombo.d.ts +1 -0
  11. package/dist/craft/bepicolombo.js +923 -0
  12. package/dist/craft/europaclipper.d.ts +1 -0
  13. package/dist/craft/europaclipper.js +342 -0
  14. package/dist/craft/hayabusa2.d.ts +1 -0
  15. package/dist/craft/hayabusa2.js +73 -0
  16. package/dist/craft/juice.d.ts +1 -0
  17. package/dist/craft/juice.js +40 -0
  18. package/dist/craft/lucy.d.ts +1 -0
  19. package/dist/craft/lucy.js +42 -0
  20. package/dist/craft/osirisapex.d.ts +1 -0
  21. package/dist/craft/osirisapex.js +69 -0
  22. package/dist/craft/psyche.d.ts +1 -0
  23. package/dist/craft/psyche.js +30 -0
  24. package/dist/craft/solarorbiter.d.ts +1 -0
  25. package/dist/craft/solarorbiter.js +94 -0
  26. package/dist/data/approaches.d.ts +17 -0
  27. package/dist/data/approaches.js +4192 -0
  28. package/dist/data/asteroids.d.ts +3 -0
  29. package/dist/data/asteroids.js +107 -0
  30. package/dist/data/comets.d.ts +2 -0
  31. package/dist/data/comets.js +36 -0
  32. package/dist/data/orbiters.d.ts +368 -0
  33. package/dist/data/orbiters.js +370 -0
  34. package/dist/data/places-67p.d.ts +27 -0
  35. package/dist/data/places-67p.js +2 -0
  36. package/dist/data/places-ariel.d.ts +602 -0
  37. package/dist/data/places-ariel.js +27 -0
  38. package/dist/data/places-bennu.d.ts +25 -0
  39. package/dist/data/places-bennu.js +2 -0
  40. package/dist/data/places-callisto.d.ts +3547 -0
  41. package/dist/data/places-callisto.js +155 -0
  42. package/dist/data/places-ceres.d.ts +3436 -0
  43. package/dist/data/places-ceres.js +150 -0
  44. package/dist/data/places-charon.d.ts +349 -0
  45. package/dist/data/places-charon.js +16 -0
  46. package/dist/data/places-dimorphos.d.ts +23 -0
  47. package/dist/data/places-dimorphos.js +2 -0
  48. package/dist/data/places-dione.d.ts +2258 -0
  49. package/dist/data/places-dione.js +99 -0
  50. package/dist/data/places-enceladus.d.ts +2009 -0
  51. package/dist/data/places-enceladus.js +88 -0
  52. package/dist/data/places-eros.d.ts +26 -0
  53. package/dist/data/places-eros.js +2 -0
  54. package/dist/data/places-europa.d.ts +2977 -0
  55. package/dist/data/places-europa.js +130 -0
  56. package/dist/data/places-ganymede.d.ts +4518 -0
  57. package/dist/data/places-ganymede.js +197 -0
  58. package/dist/data/places-iapetus.d.ts +1616 -0
  59. package/dist/data/places-iapetus.js +71 -0
  60. package/dist/data/places-io.d.ts +6012 -0
  61. package/dist/data/places-io.js +262 -0
  62. package/dist/data/places-jupiter.d.ts +46 -0
  63. package/dist/data/places-jupiter.js +3 -0
  64. package/dist/data/places-mars.d.ts +20701 -0
  65. package/dist/data/places-mars.js +942 -0
  66. package/dist/data/places-mercury.d.ts +9256 -0
  67. package/dist/data/places-mercury.js +403 -0
  68. package/dist/data/places-mimas.d.ts +968 -0
  69. package/dist/data/places-mimas.js +43 -0
  70. package/dist/data/places-miranda.d.ts +419 -0
  71. package/dist/data/places-miranda.js +19 -0
  72. package/dist/data/places-moon.d.ts +18849 -0
  73. package/dist/data/places-moon.js +861 -0
  74. package/dist/data/places-oberon.d.ts +235 -0
  75. package/dist/data/places-oberon.js +11 -0
  76. package/dist/data/places-pluto.d.ts +1687 -0
  77. package/dist/data/places-pluto.js +74 -0
  78. package/dist/data/places-rhea.d.ts +3317 -0
  79. package/dist/data/places-rhea.js +145 -0
  80. package/dist/data/places-ryugu.d.ts +87 -0
  81. package/dist/data/places-ryugu.js +5 -0
  82. package/dist/data/places-saturn.d.ts +25 -0
  83. package/dist/data/places-saturn.js +2 -0
  84. package/dist/data/places-tempel-1.d.ts +25 -0
  85. package/dist/data/places-tempel-1.js +2 -0
  86. package/dist/data/places-tethys.d.ts +1222 -0
  87. package/dist/data/places-tethys.js +54 -0
  88. package/dist/data/places-titan.d.ts +7031 -0
  89. package/dist/data/places-titan.js +306 -0
  90. package/dist/data/places-titania.d.ts +418 -0
  91. package/dist/data/places-titania.js +19 -0
  92. package/dist/data/places-triton.d.ts +1457 -0
  93. package/dist/data/places-triton.js +64 -0
  94. package/dist/data/places-umbriel.d.ts +303 -0
  95. package/dist/data/places-umbriel.js +14 -0
  96. package/dist/data/places-venus.d.ts +9290 -0
  97. package/dist/data/places-venus.js +405 -0
  98. package/dist/data/places-vesta.d.ts +2444 -0
  99. package/dist/data/places-vesta.js +107 -0
  100. package/dist/data/roadster.d.ts +8 -0
  101. package/dist/data/roadster.js +686 -0
  102. package/dist/element.js +17 -3
  103. package/dist/orbiter-facts.d.ts +480 -0
  104. package/dist/orbiter-facts.js +189 -0
  105. package/dist/orbiters.d.ts +256 -0
  106. package/dist/orbiters.js +275 -0
  107. package/dist/places/67p.d.ts +13 -0
  108. package/dist/places/67p.js +14 -0
  109. package/dist/places/ariel.d.ts +13 -0
  110. package/dist/places/ariel.js +14 -0
  111. package/dist/places/bennu.d.ts +13 -0
  112. package/dist/places/bennu.js +14 -0
  113. package/dist/places/callisto.d.ts +13 -0
  114. package/dist/places/callisto.js +14 -0
  115. package/dist/places/ceres.d.ts +13 -0
  116. package/dist/places/ceres.js +14 -0
  117. package/dist/places/charon.d.ts +13 -0
  118. package/dist/places/charon.js +14 -0
  119. package/dist/places/dimorphos.d.ts +13 -0
  120. package/dist/places/dimorphos.js +14 -0
  121. package/dist/places/dione.d.ts +13 -0
  122. package/dist/places/dione.js +14 -0
  123. package/dist/places/enceladus.d.ts +13 -0
  124. package/dist/places/enceladus.js +14 -0
  125. package/dist/places/eros.d.ts +13 -0
  126. package/dist/places/eros.js +14 -0
  127. package/dist/places/europa.d.ts +13 -0
  128. package/dist/places/europa.js +14 -0
  129. package/dist/places/ganymede.d.ts +13 -0
  130. package/dist/places/ganymede.js +14 -0
  131. package/dist/places/iapetus.d.ts +13 -0
  132. package/dist/places/iapetus.js +14 -0
  133. package/dist/places/io.d.ts +13 -0
  134. package/dist/places/io.js +14 -0
  135. package/dist/places/jupiter.d.ts +13 -0
  136. package/dist/places/jupiter.js +14 -0
  137. package/dist/places/mars.d.ts +12 -0
  138. package/dist/places/mars.js +13 -0
  139. package/dist/places/mercury.d.ts +13 -0
  140. package/dist/places/mercury.js +14 -0
  141. package/dist/places/mimas.d.ts +13 -0
  142. package/dist/places/mimas.js +14 -0
  143. package/dist/places/miranda.d.ts +13 -0
  144. package/dist/places/miranda.js +14 -0
  145. package/dist/places/moon.d.ts +12 -0
  146. package/dist/places/moon.js +13 -0
  147. package/dist/places/oberon.d.ts +13 -0
  148. package/dist/places/oberon.js +14 -0
  149. package/dist/places/pluto.d.ts +13 -0
  150. package/dist/places/pluto.js +14 -0
  151. package/dist/places/rhea.d.ts +13 -0
  152. package/dist/places/rhea.js +14 -0
  153. package/dist/places/ryugu.d.ts +13 -0
  154. package/dist/places/ryugu.js +14 -0
  155. package/dist/places/saturn.d.ts +13 -0
  156. package/dist/places/saturn.js +14 -0
  157. package/dist/places/tempel-1.d.ts +13 -0
  158. package/dist/places/tempel-1.js +14 -0
  159. package/dist/places/tethys.d.ts +13 -0
  160. package/dist/places/tethys.js +14 -0
  161. package/dist/places/titan.d.ts +13 -0
  162. package/dist/places/titan.js +14 -0
  163. package/dist/places/titania.d.ts +13 -0
  164. package/dist/places/titania.js +14 -0
  165. package/dist/places/triton.d.ts +13 -0
  166. package/dist/places/triton.js +14 -0
  167. package/dist/places/umbriel.d.ts +13 -0
  168. package/dist/places/umbriel.js +14 -0
  169. package/dist/places/venus.d.ts +13 -0
  170. package/dist/places/venus.js +14 -0
  171. package/dist/places/vesta.d.ts +13 -0
  172. package/dist/places/vesta.js +14 -0
  173. package/dist/places.d.ts +354 -0
  174. package/dist/places.js +357 -0
  175. package/dist/plan/element.d.ts +52 -0
  176. package/dist/plan/element.js +258 -0
  177. package/dist/plan/index.d.ts +2 -0
  178. package/dist/plan/index.js +2 -0
  179. package/dist/plan/layout.d.ts +230 -0
  180. package/dist/plan/layout.js +229 -0
  181. package/dist/plan/svg.d.ts +125 -0
  182. package/dist/plan/svg.js +185 -0
  183. package/dist/roadster.d.ts +415 -0
  184. package/dist/roadster.js +496 -0
  185. package/dist/scene/body.js +10 -9
  186. package/dist/scene/painter.d.ts +1 -1
  187. package/dist/scene/painter.js +23 -7
  188. package/dist/scene/textures.d.ts +2 -2
  189. package/dist/space/beside.d.ts +4 -1
  190. package/dist/space/beside.js +47 -6
  191. package/dist/space/covered.d.ts +102 -0
  192. package/dist/space/covered.js +98 -0
  193. package/dist/space/element.d.ts +101 -5
  194. package/dist/space/element.js +474 -30
  195. package/dist/space/frame.d.ts +14 -0
  196. package/dist/space/frame.js +16 -0
  197. package/dist/space/index.d.ts +4 -1
  198. package/dist/space/index.js +4 -1
  199. package/dist/space/regions.d.ts +111 -0
  200. package/dist/space/regions.js +84 -0
  201. package/dist/space/scale.d.ts +2 -1
  202. package/dist/space/scale.js +13 -2
  203. package/dist/space/scene.d.ts +109 -8
  204. package/dist/space/scene.js +313 -37
  205. package/dist/space/travel.d.ts +256 -0
  206. package/dist/space/travel.js +597 -0
  207. package/dist/spacecraft-facts.d.ts +4 -4
  208. package/dist/spacecraft-facts.js +158 -3
  209. package/dist/spacecraft.d.ts +69 -2
  210. package/dist/spacecraft.js +45 -2
  211. package/dist/textures/mimas-1024.webp +0 -0
  212. package/dist/textures/mimas-512.webp +0 -0
  213. package/dist/version.d.ts +1 -1
  214. package/dist/version.js +1 -1
  215. package/package.json +208 -1
@@ -1,17 +1,21 @@
1
1
  import { BODIES, MOONS_OF } from "../facts.js";
2
2
  import { createSmallBodyPoints } from "../door/points.js";
3
3
  import { toTerrestrialTime } from "../clock.js";
4
- import { moonOffset } from "../scene/orient.js";
4
+ import { moonOffset, orientation } from "../scene/orient.js";
5
5
  import {} from "../scene/painter.js";
6
6
  import "../bodies/all.js";
7
7
  import { groundDirection } from "./aim.js";
8
8
  import { hostOf } from "./bodies.js";
9
9
  import { arrowSites, ARROWS_PER_ORBIT, chevron, MAX_ARROWS_PER_ORBIT, spinArrow } from "./arrows.js";
10
10
  import { besideMoon } from "./beside.js";
11
+ import { coveredBy } from "./covered.js";
11
12
  import { spinAxis } from "./spin.js";
12
- import { createTrack, moonOrbit, planetOrbit, SPACE_DWARFS, SPACE_MINORS, SPACE_PLANETS } from "./frame.js";
13
+ import { createTrack, eclipticToScene, frameAt, moonOrbit, planetOrbit, SPACE_DWARFS, SPACE_MINORS, SPACE_PLANETS } from "./frame.js";
14
+ import { BALL_FRAGMENT, VERTEX } from "../scene/glsl.js";
13
15
  import { ridePose } from "./ride.js";
14
- import { moonDistance, orbitLine, placeBodies, placeMoon, radiusIn } from "./scale.js";
16
+ import { moonDistance, orbitLine, placeAround, placeBodies, placeMoon, radiusIn } from "./scale.js";
17
+ import { regionOrbits, regionView } from "./regions.js";
18
+ import { travelPlan, travelPose } from "./travel.js";
15
19
  const RAD = Math.PI / 180;
16
20
  /** The camera's distance, in radii of the body it looks at, at which that body fills the view at zoom 1. */
17
21
  export const FIT_DISTANCE = 4.1;
@@ -37,6 +41,16 @@ const MOON_MIN_PX = 2.2;
37
41
  const MOON_MIN_SYSTEM_PX = 30;
38
42
  /** A moon that has been out of sight this long is let go (its pictures too). */
39
43
  const MOON_KEEP_MS = 4000;
44
+ /** An orbiter is drawn as a dot this many CSS pixels across its radius, once its body is at least `ORBITER_HOST_PX` across its radius on the screen (nearer, the dots would all sit on the body's own dot). */
45
+ const ORBITER_PX = 2.2;
46
+ const ORBITER_HOST_PX = 24;
47
+ /** An orbiter's orbit line is worked out again when the moment has moved this far from the line's epoch (the node and periapsis drift a little a day). */
48
+ const ORBITER_LINE_KEEP_MS = 86_400_000;
49
+ /** The Roadster is drawn as a dot this many CSS pixels across its radius: a car is nothing at any scale of the view. */
50
+ const ROADSTER_PX = 3;
51
+ /** The Roadster's orbit line spans this long round the moment shown (about one trip round the Sun), and is worked out again when the moment has moved this far from the line's middle. */
52
+ const ROADSTER_ORBIT_MS = 560 * 86_400_000;
53
+ const ROADSTER_ORBIT_KEEP_MS = 30 * 86_400_000;
40
54
  /**
41
55
  * The twenty-four bodies the space view places, names and lets a reader choose: the Earth, the Sun, the Moon, the seven other planets, Pluto, the eight other dwarf planets and the five minor bodies (Vesta, Pallas, Chiron, Pholus and Halley). The moons of the planets and of the dwarf planets are placed round their hosts.
42
56
  *
@@ -57,6 +71,7 @@ export const newSpaceModel = () => ({
57
71
  orbits: true,
58
72
  labels: true,
59
73
  stepMs: 1000,
74
+ speed: 1,
60
75
  focus: "earth",
61
76
  light: "sun",
62
77
  look: "realistic",
@@ -66,8 +81,15 @@ export const newSpaceModel = () => ({
66
81
  rings: { drawn: [], miss: {}, hidden: [] },
67
82
  arrows: {},
68
83
  help: false,
84
+ helpThrough: false,
69
85
  arrowPx: 0,
70
86
  arrowCount: ARROWS_PER_ORBIT,
87
+ orbiters: false,
88
+ orbiterSet: null,
89
+ orbitersDrawn: { count: 0, status: {} },
90
+ roadster: false,
91
+ roadsterPath: null,
92
+ roadsterDrawn: { shown: false, position: null, radiusPx: 0 },
71
93
  label: null,
72
94
  labelVersion: 0,
73
95
  labelsDrawn: { count: 0, focus: null },
@@ -77,10 +99,13 @@ export const newSpaceModel = () => ({
77
99
  motion: 0,
78
100
  drawnView: null,
79
101
  heightPx: 420,
80
- camera: { position: [0, 0, 0], fov: FOV },
102
+ camera: { position: [0, 0, 0], fov: FOV, up: [0, 1, 0], forward: [0, 0, -1] },
81
103
  ride: null,
82
104
  rideLost: false,
83
105
  transition: null,
106
+ travelling: null,
107
+ region: null,
108
+ regionDrawn: null,
84
109
  pose: { p: [0, 0, 0], q: [0, 0, 0, 1], fov: FOV, valid: false },
85
110
  rideMotion: 0,
86
111
  ratio: () => Math.min(globalThis.devicePixelRatio || 1, 2),
@@ -122,8 +147,11 @@ export function createSpaceItem(model, deps) {
122
147
  const camera = new three.PerspectiveCamera(FOV, width / Math.max(1, height), 0.05, 1000);
123
148
  const target = new three.Vector3();
124
149
  const projected = new three.Vector3();
125
- const desiredQ = camera.quaternion.clone();
126
150
  const fromQ = camera.quaternion.clone();
151
+ const scratchA = new three.Vector3();
152
+ const scratchB = new three.Vector3();
153
+ // the orbit lines of a stage out from the Sun, kept while the stage, the scale and the day are the same
154
+ let regionLines = null;
127
155
  let ended = false;
128
156
  const slots = new Map();
129
157
  const empty = (slot) => {
@@ -217,6 +245,42 @@ export function createSpaceItem(model, deps) {
217
245
  }
218
246
  const moonSlots = new Map();
219
247
  let releaseTimer;
248
+ // Starman and the Roadster: a dot (a shaded ball, lit by the Sun) on its own orbit line, in the car's warm red; made once, shown only while the view asks for it
249
+ const roadsterGeometry = new three.SphereGeometry(1, 24, 12);
250
+ const roadsterMaterial = new three.ShaderMaterial({ vertexShader: VERTEX, fragmentShader: BALL_FRAGMENT, uniforms: { uLight: { value: new three.Vector3(0, 0, 1) }, uColour: { value: new three.Vector3(0.93, 0.28, 0.2) } } });
251
+ const roadsterMesh = new three.Mesh(roadsterGeometry, roadsterMaterial);
252
+ roadsterMesh.visible = false;
253
+ roadsterMesh.frustumCulled = false;
254
+ scene.add(roadsterMesh);
255
+ const roadsterPositions = new Float32Array((ORBIT_POINTS + 1) * 3);
256
+ const roadsterLineGeometry = new three.BufferGeometry();
257
+ roadsterLineGeometry.setAttribute("position", new three.BufferAttribute(roadsterPositions, 3));
258
+ const roadsterLine = new three.Line(roadsterLineGeometry, new three.LineBasicMaterial({ color: 0xe8705a, transparent: true, opacity: 0.55 }));
259
+ roadsterLine.visible = false;
260
+ roadsterLine.frustumCulled = false;
261
+ scene.add(roadsterLine);
262
+ const roadsterOrbit = { samples: [], epoch: Number.NaN };
263
+ const orbiterDrawings = new Map();
264
+ const orbiterGeometry = new three.SphereGeometry(1, 16, 8);
265
+ const orbiterDrawing = (id) => {
266
+ let drawing = orbiterDrawings.get(id);
267
+ if (drawing !== undefined)
268
+ return drawing;
269
+ const material = new three.ShaderMaterial({ vertexShader: VERTEX, fragmentShader: BALL_FRAGMENT, uniforms: { uLight: { value: new three.Vector3(0, 0, 1) }, uColour: { value: new three.Vector3(0.75, 0.9, 1) } } });
270
+ const mesh = new three.Mesh(orbiterGeometry, material);
271
+ mesh.frustumCulled = false;
272
+ scene.add(mesh);
273
+ const positions = new Float32Array((ORBIT_POINTS + 1) * 3);
274
+ const geometry = new three.BufferGeometry();
275
+ geometry.setAttribute("position", new three.BufferAttribute(positions, 3));
276
+ const lineMaterial = new three.LineBasicMaterial({ color: 0x9fd0ff, transparent: true, opacity: 0.45 });
277
+ const line = new three.Line(geometry, lineMaterial);
278
+ line.frustumCulled = false;
279
+ scene.add(line);
280
+ drawing = { mesh, material, line, lineMaterial, positions, epoch: Number.NaN };
281
+ orbiterDrawings.set(id, drawing);
282
+ return drawing;
283
+ };
220
284
  const labelFor = (v) => {
221
285
  projected.set(v[0], v[1], v[2]).project(camera);
222
286
  if (projected.z > 1 || projected.z < -1)
@@ -305,7 +369,7 @@ export function createSpaceItem(model, deps) {
305
369
  if (ride.view === "beside") {
306
370
  // beyond the Moon and off the line to the Earth, the Earth in view behind it
307
371
  if (id === "moon")
308
- besideIn = { moon: pos.moon, moonRadius: radiusOf("moon"), host: pos.earth, hostRadius: radiusOf("earth"), sun: pos.sun };
372
+ besideIn = { moon: pos.moon, moonRadius: radiusOf("moon"), host: pos.earth, hostRadius: radiusOf("earth"), sun: pos.sun, north: orientation("earth", model.time).pole };
309
373
  focus = id;
310
374
  focusPos = pos[id];
311
375
  focusRadius = radiusOf(id);
@@ -333,7 +397,7 @@ export function createSpaceItem(model, deps) {
333
397
  if (ride.view === "beside") {
334
398
  const there = [centre[0] + offset[0] * unitWorld, centre[1] + offset[1] * unitWorld, centre[2] + offset[2] * unitWorld];
335
399
  const radius = Math.max(1e-6, (BODIES[id].radiusKm / BODIES[around].radiusKm) * unitWorld);
336
- besideIn = { moon: there, moonRadius: radius, host: centre, hostRadius: unitWorld, sun: pos.sun };
400
+ besideIn = { moon: there, moonRadius: radius, host: centre, hostRadius: unitWorld, sun: pos.sun, north: orientation(around, model.time).pole };
337
401
  focus = id;
338
402
  focusPos = there;
339
403
  focusRadius = radius;
@@ -407,26 +471,104 @@ export function createSpaceItem(model, deps) {
407
471
  const across = focusRadius * (FRAMED[focus] ?? 1) * Math.max(1, size.height / Math.max(1, size.width));
408
472
  distance = Math.max(1.05 * focusRadius, (FIT_DISTANCE * across) / Math.max(1e-9, model.view.zoom));
409
473
  target.set(focusPos[0], focusPos[1], focusPos[2]);
474
+ model.regionDrawn = null;
475
+ if (model.region !== null && focus === "sun") {
476
+ // a stage out from the Sun: the camera stands back along the same line of sight until every orbit of the stage is in the picture, whatever the zoom says
477
+ if (regionLines === null || regionLines.id !== model.region || regionLines.mode !== mode || Math.abs(model.time - regionLines.epoch) > 86_400_000) {
478
+ regionLines = { id: model.region, mode, epoch: model.time, lines: regionOrbits(model.region, mode, model.time).map((line) => line.map((p) => minus(p, origin))) };
479
+ }
480
+ const framed = regionView({ centre: focusPos, orbits: regionLines.lines, aspect: size.width / Math.max(1, size.height), forward: [-aim[0], -aim[1], -aim[2]], up: [0, 1, 0] });
481
+ distance = Math.hypot(framed.position[0] - focusPos[0], framed.position[1] - focusPos[1], framed.position[2] - focusPos[2]);
482
+ model.regionDrawn = { id: model.region, reach: framed.reach, distance };
483
+ }
410
484
  camera.position.set(target.x + aim[0] * distance, target.y + aim[1] * distance, target.z + aim[2] * distance);
411
485
  camera.up.set(0, 1, 0);
412
486
  camera.lookAt(target);
413
487
  camera.near = Math.max(0.0005, distance * 0.02 - focusRadius * 0.5, focusRadius * 0.01);
414
488
  camera.far = Math.max(2000, distance * 4 + (mode === "true" ? 40 * 23_481 : 400));
415
489
  }
416
- // a ride that changed: glide from where the last draw left the camera
490
+ // a move to a new target: the camera travels from where the last draw left it to the view just set up, along the path `travelPose` gives (the body left kept in the picture through the
491
+ // turn, the destination from then on, nothing passed close), worked out once at the move's first draw
417
492
  const glide = model.transition;
493
+ model.travelling = null;
418
494
  if (glide) {
419
- const k = Math.min(1, (performance.now() - glide.start) / glide.duration);
420
- const ease = k * k * (3 - 2 * k);
421
- desiredQ.copy(camera.quaternion);
422
- // the pose the last draw left is absolute (from the Earth's centre); the scene is now relative to the new origin
423
- const [fx, fy, fz] = [glide.from.p[0] - origin[0], glide.from.p[1] - origin[1], glide.from.p[2] - origin[2]];
424
- camera.position.set(fx + (camera.position.x - fx) * ease, fy + (camera.position.y - fy) * ease, fz + (camera.position.z - fz) * ease);
425
- fromQ.set(glide.from.q[0], glide.from.q[1], glide.from.q[2], glide.from.q[3]);
426
- camera.quaternion.copy(fromQ.slerp(desiredQ, ease));
427
- fovNow = glide.from.fov + (fovNow - glide.from.fov) * ease;
428
- if (k >= 1)
495
+ if (glide.input === null) {
496
+ // the pose the last draw left is absolute (from the Earth's centre); the scene is now relative to the new origin
497
+ const from = [glide.from.p[0] - origin[0], glide.from.p[1] - origin[1], glide.from.p[2] - origin[2]];
498
+ fromQ.set(glide.from.q[0], glide.from.q[1], glide.from.q[2], glide.from.q[3]);
499
+ const sf = scratchA.set(0, 0, -1).applyQuaternion(fromQ);
500
+ const su = scratchB.set(0, 1, 0).applyQuaternion(fromQ);
501
+ const start = { position: from, forward: [sf.x, sf.y, sf.z], up: [su.x, su.y, su.z], fov: glide.from.fov };
502
+ const ef = scratchA.set(0, 0, -1).applyQuaternion(camera.quaternion);
503
+ const eu = scratchB.set(0, 1, 0).applyQuaternion(camera.quaternion);
504
+ const radiusOfAny = (id) => {
505
+ if (SPACE_BODIES.includes(id))
506
+ return radiusOf(id);
507
+ const host = (hostOf(id) ?? "earth");
508
+ return Math.max(1e-6, (BODIES[id].radiusKm / BODIES[host].radiusKm) * radiusOf(host));
509
+ };
510
+ // every body is where the clock puts it as the move starts and where it puts it as the move ends (`later`, in the scene's places as of this draw): a clock that runs moves them, the Moon about three
511
+ // Earth radii in five game hours
512
+ const familyOf = (id) => (id === null ? null : id === "moon" ? "earth" : hostOf(id) ?? id);
513
+ const family = familyOf(glide.leaving);
514
+ const around = family !== null && family === familyOf(glide.destination) && (glide.leaving !== glide.destination) && (glide.leaving !== family || glide.destination !== family) ? family : null;
515
+ const build = (ms) => {
516
+ const later = ms === model.time ? pos : placeBodies(mode, frameAt(ms));
517
+ if (later !== pos)
518
+ for (const id of Object.keys(later))
519
+ later[id] = minus(later[id], origin);
520
+ const siteAt = (id, table, at) => {
521
+ if (SPACE_BODIES.includes(id))
522
+ return table[id];
523
+ const host = (hostOf(id) ?? "earth");
524
+ const offset = moonSite(id, at, host);
525
+ const hostRadius = radiusOf(host);
526
+ return [table[host][0] + offset[0] * hostRadius, table[host][1] + offset[1] * hostRadius, table[host][2] + offset[2] * hostRadius];
527
+ };
528
+ const bodyOf = (id) => (id === null ? null : { from: siteAt(id, pos, model.time), to: siteAt(id, later, ms), radius: radiusOfAny(id) });
529
+ const destination = bodyOf(glide.destination) ?? { from: focusPos, to: focusPos, radius: focusRadius };
530
+ if (model.regionDrawn !== null && glide.destination === "sun")
531
+ destination.reach = model.regionDrawn.reach;
532
+ const leaving = bodyOf(glide.leaving) ?? { ...destination };
533
+ if (glide.leavingReach > 0 && glide.leaving === "sun")
534
+ leaving.reach = glide.leavingReach;
535
+ // the last view is the one framed for the destination where it is now: it moves with the destination
536
+ const shift = destination.to === undefined ? [0, 0, 0] : [destination.to[0] - destination.from[0], destination.to[1] - destination.from[1], destination.to[2] - destination.from[2]];
537
+ const end = { position: [camera.position.x + shift[0], camera.position.y + shift[1], camera.position.z + shift[2]], forward: [ef.x, ef.y, ef.z], up: [eu.x, eu.y, eu.z], fov: fovNow };
538
+ // every body of the view is kept clear of, the two ends of the move and the planet circled aside
539
+ const others = SPACE_BODIES.filter((id) => id !== glide.leaving && id !== glide.destination && id !== family).map((id) => bodyOf(id));
540
+ const input = { start, end, leaving, destination, others, aspect: size.width / Math.max(1, size.height), kind: glide.kind, pace: glide.pace };
541
+ if (around !== null)
542
+ input.around = bodyOf(around);
543
+ return { input, plan: travelPlan(input) };
544
+ };
545
+ // the length of the move is worked out for bodies that stand still, then the move is worked out again for where the clock takes them in that time (once: the length may change a little)
546
+ let built = build(model.time);
547
+ if (model.speed !== 0) {
548
+ const duration = glide.duration > 0 ? glide.duration : built.plan.duration;
549
+ built = build(model.time + duration * model.speed);
550
+ }
551
+ glide.input = built.input;
552
+ glide.plan = built.plan;
553
+ glide.origin = origin;
554
+ if (glide.duration <= 0)
555
+ glide.duration = glide.plan.duration;
556
+ }
557
+ const k = Math.min(1, (performance.now() - glide.start) / Math.max(1, glide.duration));
558
+ const sample = travelPose(glide.input, k, glide.plan);
559
+ // the path is in the scene's places as of the move's first draw: the scene's origin moves with the body looked at, so the camera is moved by as much
560
+ const [ox, oy, oz] = [glide.origin[0] - origin[0], glide.origin[1] - origin[1], glide.origin[2] - origin[2]];
561
+ camera.position.set(sample.position[0] + ox, sample.position[1] + oy, sample.position[2] + oz);
562
+ camera.up.set(sample.up[0], sample.up[1], sample.up[2]);
563
+ target.set(camera.position.x + sample.forward[0], camera.position.y + sample.forward[1], camera.position.z + sample.forward[2]);
564
+ camera.lookAt(target);
565
+ fovNow = sample.fov;
566
+ model.travelling = { kind: glide.plan.kind, path: glide.plan.path, stage: sample.stage, progress: k, duration: glide.duration, leaving: sample.leaving.inside, destination: sample.destination.inside };
567
+ // the move is over at its last draw: nothing is travelling after it
568
+ if (k >= 1) {
429
569
  model.transition = null;
570
+ model.travelling = null;
571
+ }
430
572
  }
431
573
  // the controls' roll turns the picture clockwise about the line of sight, and a pan moves everything by that many CSS pixels at any depth: the window of the projection moves the other way
432
574
  if (model.view.roll !== 0)
@@ -441,7 +583,8 @@ export function createSpaceItem(model, deps) {
441
583
  camera.updateMatrixWorld();
442
584
  const hiddenBody = rideFrom?.hiddenBody ?? null;
443
585
  const hiddenMoon = rideFrom?.hiddenMoon ?? null;
444
- model.camera = { position: [camera.position.x + origin[0], camera.position.y + origin[1], camera.position.z + origin[2]], fov: fovNow };
586
+ const e2 = camera.matrixWorld.elements;
587
+ model.camera = { position: [camera.position.x + origin[0], camera.position.y + origin[1], camera.position.z + origin[2]], fov: fovNow, up: [e2[4], e2[5], e2[6]], forward: [-e2[8], -e2[9], -e2[10]] };
445
588
  model.pose = { p: [camera.position.x + origin[0], camera.position.y + origin[1], camera.position.z + origin[2]], q: [camera.quaternion.x, camera.quaternion.y, camera.quaternion.z, camera.quaternion.w], fov: fovNow, valid: true };
446
589
  model.drawnView = { yaw: model.view.yaw, tilt: model.view.tilt, zoom: model.view.zoom, roll: model.view.roll, panX: model.view.panX, panY: model.view.panY };
447
590
  model.heightPx = size.height;
@@ -544,6 +687,99 @@ export function createSpaceItem(model, deps) {
544
687
  miss[id] = distanceToLine(pos[id], line) / radius;
545
688
  }
546
689
  model.rings = { drawn: drawnRings, miss, hidden: hiddenRings };
690
+ // Starman and the Roadster: where the table puts the car, in the same mapping as the planets, as a dot a few pixels across, on its orbit line (about one trip round the Sun, from the table, worked out again every month)
691
+ const path = model.roadster ? model.roadsterPath : null;
692
+ let roadsterAt = null;
693
+ let roadsterPx = 0;
694
+ if (path !== null && model.time >= path.record.start && model.time <= path.record.end) {
695
+ roadsterAt = placeAround(mode, sunPos, eclipticToScene(path.positionAu(model.time)));
696
+ const away = Math.hypot(roadsterAt[0] - camera.position.x, roadsterAt[1] - camera.position.y, roadsterAt[2] - camera.position.z);
697
+ const drawn = (away * half * ROADSTER_PX) / (size.height / 2);
698
+ roadsterPx = away <= drawn ? 1e5 : ((size.height / 2) * (drawn / Math.sqrt(away * away - drawn * drawn))) / half;
699
+ roadsterMesh.visible = true;
700
+ roadsterMesh.position.set(roadsterAt[0], roadsterAt[1], roadsterAt[2]);
701
+ roadsterMesh.scale.setScalar(drawn);
702
+ roadsterMaterial.uniforms.uLight.value.set(...unit(minus(sunPos, roadsterAt)));
703
+ if (!Number.isFinite(roadsterOrbit.epoch) || Math.abs(model.time - roadsterOrbit.epoch) > ROADSTER_ORBIT_KEEP_MS) {
704
+ roadsterOrbit.samples = [];
705
+ for (let i = 0; i <= ORBIT_POINTS; i += 1) {
706
+ const t = Math.max(path.record.start, Math.min(path.record.end, model.time - ROADSTER_ORBIT_MS / 2 + (ROADSTER_ORBIT_MS * i) / ORBIT_POINTS));
707
+ roadsterOrbit.samples.push(eclipticToScene(path.positionAu(t)));
708
+ }
709
+ roadsterOrbit.epoch = model.time;
710
+ }
711
+ const line = orbitLine(mode, sunPos, roadsterOrbit.samples);
712
+ for (let i = 0; i <= ORBIT_POINTS; i += 1) {
713
+ roadsterPositions[i * 3] = line[i][0];
714
+ roadsterPositions[i * 3 + 1] = line[i][1];
715
+ roadsterPositions[i * 3 + 2] = line[i][2];
716
+ }
717
+ roadsterLineGeometry.getAttribute("position").needsUpdate = true;
718
+ roadsterLine.visible = model.orbits && !closeUp;
719
+ }
720
+ else {
721
+ roadsterMesh.visible = false;
722
+ roadsterLine.visible = false;
723
+ }
724
+ // the orbiters round the Moon and Mars: each a dot at the table's place, scaled with its body's drawn radius, on its orbit line, once its body is big enough on the screen; a modelled path is drawn dim
725
+ const orbiterSet = model.orbiters ? model.orbiterSet : null;
726
+ const orbiterPlaces = {};
727
+ const orbiterStatus = {};
728
+ if (orbiterSet !== null) {
729
+ for (const id of orbiterSet.ids) {
730
+ const centre = orbiterSet.centre(id);
731
+ const hostPx = px[centre];
732
+ const km = BODIES[centre].radiusKm;
733
+ const at = hostPx >= ORBITER_HOST_PX ? orbiterSet.position(id, model.time) : null;
734
+ const drawing = orbiterDrawings.get(id) ?? (at === null ? undefined : orbiterDrawing(id));
735
+ if (drawing === undefined)
736
+ continue;
737
+ if (at === null) {
738
+ drawing.mesh.visible = false;
739
+ drawing.line.visible = false;
740
+ continue;
741
+ }
742
+ const status = orbiterSet.status(id, model.time);
743
+ const hostRadius = radiusOf(centre);
744
+ const here = eclipticToScene(at);
745
+ const place = [pos[centre][0] + (here[0] / km) * hostRadius, pos[centre][1] + (here[1] / km) * hostRadius, pos[centre][2] + (here[2] / km) * hostRadius];
746
+ const away = Math.hypot(place[0] - camera.position.x, place[1] - camera.position.y, place[2] - camera.position.z);
747
+ const drawn = (away * half * ORBITER_PX) / (size.height / 2);
748
+ const dotPx = away <= drawn ? 1e5 : ((size.height / 2) * (drawn / Math.sqrt(away * away - drawn * drawn))) / half;
749
+ drawing.mesh.visible = true;
750
+ drawing.mesh.position.set(place[0], place[1], place[2]);
751
+ drawing.mesh.scale.setScalar(drawn);
752
+ drawing.material.uniforms.uLight.value.set(...toSunOf(centre));
753
+ const dim = status === "modelled" || status === "predicted";
754
+ drawing.material.uniforms.uColour.value.set(dim ? 0.55 : 0.75, dim ? 0.6 : 0.9, dim ? 0.65 : 1);
755
+ if (!Number.isFinite(drawing.epoch) || Math.abs(model.time - drawing.epoch) > ORBITER_LINE_KEEP_MS) {
756
+ const points = orbiterSet.path(id, model.time, ORBIT_POINTS);
757
+ for (let i = 0; i <= ORBIT_POINTS; i += 1) {
758
+ const p = eclipticToScene(points[i] ?? [0, 0, 0]);
759
+ drawing.positions[i * 3] = p[0] / km;
760
+ drawing.positions[i * 3 + 1] = p[1] / km;
761
+ drawing.positions[i * 3 + 2] = p[2] / km;
762
+ }
763
+ drawing.line.geometry.getAttribute("position").needsUpdate = true;
764
+ drawing.epoch = model.time;
765
+ }
766
+ // the line is in the body's radii round the origin: placed and scaled with the body
767
+ drawing.line.position.set(pos[centre][0], pos[centre][1], pos[centre][2]);
768
+ drawing.line.scale.setScalar(hostRadius);
769
+ drawing.lineMaterial.opacity = dim ? 0.25 : 0.45;
770
+ drawing.line.visible = model.orbits;
771
+ orbiterPlaces[id] = { at: place, px: dotPx };
772
+ orbiterStatus[id] = status;
773
+ }
774
+ }
775
+ else {
776
+ for (const drawing of orbiterDrawings.values()) {
777
+ drawing.mesh.visible = false;
778
+ drawing.line.visible = false;
779
+ }
780
+ }
781
+ model.orbitersDrawn = { count: Object.keys(orbiterPlaces).length, status: orbiterStatus };
782
+ model.roadsterDrawn = { shown: roadsterAt !== null, position: roadsterAt === null ? null : [roadsterAt[0] + origin[0], roadsterAt[1] + origin[1], roadsterAt[2] + origin[2]], radiusPx: roadsterPx };
547
783
  // the arrowheads on the lines: small in screen pixels at the place, pointing the way the body goes (the lines run from the body once round in the order it goes, whichever way the clock runs)
548
784
  const e = camera.matrixWorld.elements;
549
785
  const camRight = [e[0], e[1], e[2]];
@@ -589,6 +825,8 @@ export function createSpaceItem(model, deps) {
589
825
  arrowGeometry.getAttribute("color").needsUpdate = true;
590
826
  // help mode: on the body looked at, the line of its axis and a curved arrow round it the way it turns
591
827
  helpLines.visible = model.help;
828
+ // by default the lines are hidden where the globe covers them: the depth test against the body, whose own drawing writes depth
829
+ helpLines.material.depthTest = !model.helpThrough;
592
830
  model.helpDrawn = null;
593
831
  if (model.help) {
594
832
  const turn = spinAxis(focus, model.time);
@@ -618,6 +856,7 @@ export function createSpaceItem(model, deps) {
618
856
  const now = performance.now();
619
857
  const seen = new Set();
620
858
  const moonPlaces = {};
859
+ const moonDistances = {};
621
860
  for (const id of [...SPACE_PLANETS, ...SPACE_DWARFS]) {
622
861
  const planet = slotOf(id).drawing;
623
862
  if (!planet)
@@ -658,8 +897,10 @@ export function createSpaceItem(model, deps) {
658
897
  const moonPx = away <= drawn * 1.001 ? 1e5 : ((size.height / 2) * (drawn / Math.sqrt(away * away - drawn * drawn))) / half;
659
898
  drawing.update({ toSun: model.light === "lit" ? unit([camera.position.x - at[0], camera.position.y - at[1], camera.position.z - at[2]]) : toSunOf(id), ms: model.time, radiusPx: moonPx, view: { camera, width: size.width, height: size.height } });
660
899
  const spot = labelFor(at);
661
- if (spot)
662
- moonPlaces[key] = { x: spot.x, y: spot.y, r: moonPx };
900
+ if (spot) {
901
+ moonPlaces[key] = { x: spot.x, y: spot.y, r: moonPx, named: drawing.label?.shown === true };
902
+ moonDistances[key] = away;
903
+ }
663
904
  }
664
905
  }
665
906
  let soonest = Number.POSITIVE_INFINITY;
@@ -685,29 +926,32 @@ export function createSpaceItem(model, deps) {
685
926
  paintedMoons += 1;
686
927
  model.painted.moons = paintedMoons;
687
928
  model.painted.held = moonSlots.size;
929
+ // one pass over every drawing (the bodies, then the moons): the names drawn, the tile windows summed, and the sources whose tiles are on a body
688
930
  let labelsDrawn = 0;
689
- for (const painting of [...[...slots.values()].map((slot) => slot.drawing), ...[...moonSlots.values()].map((held) => held.slot.drawing)])
690
- if (painting?.object.visible && painting.label?.shown)
691
- labelsDrawn += 1;
692
- model.labelsDrawn = { count: labelsDrawn, focus: (slots.get(focus)?.drawing ?? moonSlots.get(focus)?.slot.drawing)?.label ?? null };
693
931
  const tiles = { requested: 0, loading: 0, failed: 0, shown: null };
694
- for (const painting of [...[...slots.values()].map((slot) => slot.drawing), ...[...moonSlots.values()].map((held) => held.slot.drawing)]) {
695
- const stats = painting?.tiles;
932
+ const used = {};
933
+ const tally = (painting) => {
934
+ if (painting === undefined)
935
+ return;
936
+ if (painting.object.visible && painting.label?.shown)
937
+ labelsDrawn += 1;
938
+ const stats = painting.tiles;
696
939
  if (stats === undefined)
697
- continue;
940
+ return;
698
941
  tiles.requested += stats.requested;
699
942
  tiles.loading += stats.loading;
700
943
  tiles.failed += stats.failed;
701
944
  if (stats.shown !== null)
702
945
  tiles.shown = Math.max(tiles.shown ?? 0, stats.shown);
703
- }
946
+ if (stats.source !== undefined)
947
+ used[stats.source.id] = (used[stats.source.id] ?? 0) + stats.used;
948
+ };
949
+ for (const slot of slots.values())
950
+ tally(slot.drawing);
951
+ for (const held of moonSlots.values())
952
+ tally(held.slot.drawing);
953
+ model.labelsDrawn = { count: labelsDrawn, focus: (slots.get(focus)?.drawing ?? moonSlots.get(focus)?.slot.drawing)?.label ?? null };
704
954
  model.tiles = tiles;
705
- const used = {};
706
- for (const painting of [...[...slots.values()].map((slot) => slot.drawing), ...[...moonSlots.values()].map((held) => held.slot.drawing)]) {
707
- const shown = painting?.tiles;
708
- if (shown?.source !== undefined)
709
- used[shown.source.id] = (used[shown.source.id] ?? 0) + shown.used;
710
- }
711
955
  if (points !== undefined && deps.book !== undefined && points.count > 0)
712
956
  for (const [id, read] of deps.book.recordReads())
713
957
  used[id] = read.records.length;
@@ -716,8 +960,32 @@ export function createSpaceItem(model, deps) {
716
960
  const places = { ...moonPlaces };
717
961
  for (const id of SPACE_BODIES) {
718
962
  const at = id === hiddenBody || (rideFrom && id === rideFrom.around) ? null : labelFor(pos[id]);
719
- places[id] = at ? { x: at.x, y: at.y, r: px[id] } : null;
963
+ const drawing = slots.get(id)?.drawing;
964
+ places[id] = at ? { x: at.x, y: at.y, r: px[id], named: drawing !== undefined && drawing.object.visible && drawing.label?.shown === true } : null;
720
965
  }
966
+ for (const [id, { at, px: dotPx }] of Object.entries(orbiterPlaces)) {
967
+ const spot = labelFor(at);
968
+ places[id] = spot ? { x: spot.x, y: spot.y, r: dotPx } : null;
969
+ if (spot)
970
+ moonDistances[id] = Math.hypot(at[0] - camera.position.x, at[1] - camera.position.y, at[2] - camera.position.z);
971
+ }
972
+ if (roadsterAt !== null) {
973
+ const spot = labelFor(roadsterAt);
974
+ places["roadster"] = spot ? { x: spot.x, y: spot.y, r: roadsterPx } : null;
975
+ if (spot)
976
+ moonDistances["roadster"] = Math.hypot(roadsterAt[0] - camera.position.x, roadsterAt[1] - camera.position.y, roadsterAt[2] - camera.position.z);
977
+ }
978
+ // a body behind another: its place is inside a nearer body's disc
979
+ const entries = [];
980
+ for (const [id, at] of Object.entries(places)) {
981
+ if (at === null)
982
+ continue;
983
+ const distance = SPACE_BODIES.includes(id) ? Math.hypot(pos[id][0] - camera.position.x, pos[id][1] - camera.position.y, pos[id][2] - camera.position.z) : moonDistances[id];
984
+ if (distance !== undefined)
985
+ entries.push({ id, x: at.x, y: at.y, r: at.r, distance });
986
+ }
987
+ for (const [id, cover] of coveredBy(entries))
988
+ places[id].behind = cover;
721
989
  deps.onLabels(places);
722
990
  }
723
991
  if (model.rideLost)
@@ -744,10 +1012,18 @@ export function createSpaceItem(model, deps) {
744
1012
  o.line.geometry.dispose();
745
1013
  o.line.material.dispose();
746
1014
  }
747
- for (const lines of [arrowLines, helpLines]) {
1015
+ for (const lines of [arrowLines, helpLines, roadsterLine]) {
748
1016
  lines.geometry.dispose();
749
1017
  lines.material.dispose();
750
1018
  }
1019
+ roadsterGeometry.dispose();
1020
+ roadsterMaterial.dispose();
1021
+ for (const drawing of orbiterDrawings.values()) {
1022
+ drawing.material.dispose();
1023
+ drawing.line.geometry.dispose();
1024
+ drawing.lineMaterial.dispose();
1025
+ }
1026
+ orbiterGeometry.dispose();
751
1027
  },
752
1028
  };
753
1029
  },