@johnmorrisdotca/wakusei-planets 0.35.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.
@@ -10,9 +10,12 @@ import { arrowSites, ARROWS_PER_ORBIT, chevron, MAX_ARROWS_PER_ORBIT, spinArrow
10
10
  import { besideMoon } from "./beside.js";
11
11
  import { coveredBy } from "./covered.js";
12
12
  import { spinAxis } from "./spin.js";
13
- 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";
14
15
  import { ridePose } from "./ride.js";
15
- 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";
16
19
  const RAD = Math.PI / 180;
17
20
  /** The camera's distance, in radii of the body it looks at, at which that body fills the view at zoom 1. */
18
21
  export const FIT_DISTANCE = 4.1;
@@ -38,6 +41,16 @@ const MOON_MIN_PX = 2.2;
38
41
  const MOON_MIN_SYSTEM_PX = 30;
39
42
  /** A moon that has been out of sight this long is let go (its pictures too). */
40
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;
41
54
  /**
42
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.
43
56
  *
@@ -58,6 +71,7 @@ export const newSpaceModel = () => ({
58
71
  orbits: true,
59
72
  labels: true,
60
73
  stepMs: 1000,
74
+ speed: 1,
61
75
  focus: "earth",
62
76
  light: "sun",
63
77
  look: "realistic",
@@ -70,6 +84,12 @@ export const newSpaceModel = () => ({
70
84
  helpThrough: false,
71
85
  arrowPx: 0,
72
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 },
73
93
  label: null,
74
94
  labelVersion: 0,
75
95
  labelsDrawn: { count: 0, focus: null },
@@ -83,6 +103,9 @@ export const newSpaceModel = () => ({
83
103
  ride: null,
84
104
  rideLost: false,
85
105
  transition: null,
106
+ travelling: null,
107
+ region: null,
108
+ regionDrawn: null,
86
109
  pose: { p: [0, 0, 0], q: [0, 0, 0, 1], fov: FOV, valid: false },
87
110
  rideMotion: 0,
88
111
  ratio: () => Math.min(globalThis.devicePixelRatio || 1, 2),
@@ -124,8 +147,11 @@ export function createSpaceItem(model, deps) {
124
147
  const camera = new three.PerspectiveCamera(FOV, width / Math.max(1, height), 0.05, 1000);
125
148
  const target = new three.Vector3();
126
149
  const projected = new three.Vector3();
127
- const desiredQ = camera.quaternion.clone();
128
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;
129
155
  let ended = false;
130
156
  const slots = new Map();
131
157
  const empty = (slot) => {
@@ -219,6 +245,42 @@ export function createSpaceItem(model, deps) {
219
245
  }
220
246
  const moonSlots = new Map();
221
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
+ };
222
284
  const labelFor = (v) => {
223
285
  projected.set(v[0], v[1], v[2]).project(camera);
224
286
  if (projected.z > 1 || projected.z < -1)
@@ -409,26 +471,104 @@ export function createSpaceItem(model, deps) {
409
471
  const across = focusRadius * (FRAMED[focus] ?? 1) * Math.max(1, size.height / Math.max(1, size.width));
410
472
  distance = Math.max(1.05 * focusRadius, (FIT_DISTANCE * across) / Math.max(1e-9, model.view.zoom));
411
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
+ }
412
484
  camera.position.set(target.x + aim[0] * distance, target.y + aim[1] * distance, target.z + aim[2] * distance);
413
485
  camera.up.set(0, 1, 0);
414
486
  camera.lookAt(target);
415
487
  camera.near = Math.max(0.0005, distance * 0.02 - focusRadius * 0.5, focusRadius * 0.01);
416
488
  camera.far = Math.max(2000, distance * 4 + (mode === "true" ? 40 * 23_481 : 400));
417
489
  }
418
- // 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
419
492
  const glide = model.transition;
493
+ model.travelling = null;
420
494
  if (glide) {
421
- const k = Math.min(1, (performance.now() - glide.start) / glide.duration);
422
- const ease = k * k * (3 - 2 * k);
423
- desiredQ.copy(camera.quaternion);
424
- // the pose the last draw left is absolute (from the Earth's centre); the scene is now relative to the new origin
425
- const [fx, fy, fz] = [glide.from.p[0] - origin[0], glide.from.p[1] - origin[1], glide.from.p[2] - origin[2]];
426
- camera.position.set(fx + (camera.position.x - fx) * ease, fy + (camera.position.y - fy) * ease, fz + (camera.position.z - fz) * ease);
427
- fromQ.set(glide.from.q[0], glide.from.q[1], glide.from.q[2], glide.from.q[3]);
428
- camera.quaternion.copy(fromQ.slerp(desiredQ, ease));
429
- fovNow = glide.from.fov + (fovNow - glide.from.fov) * ease;
430
- 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) {
431
569
  model.transition = null;
570
+ model.travelling = null;
571
+ }
432
572
  }
433
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
434
574
  if (model.view.roll !== 0)
@@ -547,6 +687,99 @@ export function createSpaceItem(model, deps) {
547
687
  miss[id] = distanceToLine(pos[id], line) / radius;
548
688
  }
549
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 };
550
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)
551
784
  const e = camera.matrixWorld.elements;
552
785
  const camRight = [e[0], e[1], e[2]];
@@ -730,6 +963,18 @@ export function createSpaceItem(model, deps) {
730
963
  const drawing = slots.get(id)?.drawing;
731
964
  places[id] = at ? { x: at.x, y: at.y, r: px[id], named: drawing !== undefined && drawing.object.visible && drawing.label?.shown === true } : null;
732
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
+ }
733
978
  // a body behind another: its place is inside a nearer body's disc
734
979
  const entries = [];
735
980
  for (const [id, at] of Object.entries(places)) {
@@ -767,10 +1012,18 @@ export function createSpaceItem(model, deps) {
767
1012
  o.line.geometry.dispose();
768
1013
  o.line.material.dispose();
769
1014
  }
770
- for (const lines of [arrowLines, helpLines]) {
1015
+ for (const lines of [arrowLines, helpLines, roadsterLine]) {
771
1016
  lines.geometry.dispose();
772
1017
  lines.material.dispose();
773
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();
774
1027
  },
775
1028
  };
776
1029
  },
@@ -0,0 +1,256 @@
1
+ import { type Vec3 } from "../vec.ts";
2
+ /**
3
+ * How a move is made. The names and their order are the same as `Transition` in `glide.ts` (the list the space view's `transition` takes), so one value serves both: `turn-travel` (the default: turn or back
4
+ * up until the destination is in the picture, approach it directly, settle), `direct` (a straight glide with a slow launch, turning evenly on the way), `look-back` (the same straight glide, watching the body
5
+ * being left and turning to the destination over the last part), `auto` (`turn-travel`, which already goes straight at a destination that is in view) and `cut` (the last view at once).
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import type { TravelKind } from "@johnmorrisdotca/wakusei-planets/space";
10
+ *
11
+ * const kind: TravelKind = "turn-travel";
12
+ * console.log(kind);
13
+ * ```
14
+ */
15
+ export type TravelKind = "turn-travel" | "direct" | "look-back" | "auto" | "cut";
16
+ /**
17
+ * How near a move may come to a body, in that body's radii above its surface: 1, so a body passed is never more than 60 degrees across. A move that starts or ends nearer than one and a half times that keeps two thirds of the nearer distance.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { TRAVEL_CLEARANCE } from "@johnmorrisdotca/wakusei-planets/space";
22
+ *
23
+ * console.log(TRAVEL_CLEARANCE);
24
+ * ```
25
+ */
26
+ export declare const TRAVEL_CLEARANCE = 1;
27
+ /**
28
+ * A camera: where it is, the unit vectors it looks along and has up in the picture, and its vertical field of view in degrees. The same four as `besideMoon` and `ridePose` give.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * import type { TravelView } from "@johnmorrisdotca/wakusei-planets/space";
33
+ *
34
+ * const view: TravelView = { position: [0, 0, 4.1], forward: [0, 0, -1], up: [0, 1, 0], fov: 35 };
35
+ * console.log(view.fov);
36
+ * ```
37
+ */
38
+ export interface TravelView {
39
+ position: Vec3;
40
+ forward: Vec3;
41
+ up: Vec3;
42
+ fov: number;
43
+ }
44
+ /**
45
+ * A body of a move: where it is when the move starts (`from`) and when it ends (`to`, the same place when left out), and its radius, all in the scene's unit for the scale in use. Places are given at the two
46
+ * ends, not as a function, so the input is plain data and the same input always gives the same camera; between the ends a body goes in a straight line, which over the seconds of a move is its orbit to well
47
+ * under a pixel. `reach` marks a view of a region round the body (the radius of the outermost orbit in the picture).
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * import type { TravelBody } from "@johnmorrisdotca/wakusei-planets/space";
52
+ *
53
+ * const moon: TravelBody = { from: [60.3, 0, 0], to: [60.3, 0, 0.01], radius: 0.273 };
54
+ * console.log(moon.radius);
55
+ * ```
56
+ */
57
+ export interface TravelBody {
58
+ from: Vec3;
59
+ to?: Vec3;
60
+ radius: number;
61
+ /** Set for a view of a region round this body, from `regionView`: how far out the region goes. The move is then a straight pull back or push in. */
62
+ reach?: number;
63
+ }
64
+ /**
65
+ * What `travelPose` and `travelPlan` are asked: the camera now (`start`) and the framed view to end in (`end`, worked out for the destination's place at the end of the move), the body being left and the
66
+ * destination, the planet when both are of one planet's family, any other body to keep clear of, and the picture's width over its height.
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * import type { TravelInput } from "@johnmorrisdotca/wakusei-planets/space";
71
+ *
72
+ * const input: TravelInput = {
73
+ * start: { position: [0, 0, 4.1], forward: [0, 0, -1], up: [0, 1, 0], fov: 35 },
74
+ * end: { position: [300, 0, 1], forward: [1, 0, -0.2], up: [0, 1, 0], fov: 35 },
75
+ * leaving: { from: [0, 0, 0], radius: 1 },
76
+ * destination: { from: [303, 0, 0.4], radius: 0.5 },
77
+ * aspect: 16 / 9,
78
+ * };
79
+ * console.log(input.aspect.toFixed(2));
80
+ * ```
81
+ */
82
+ export interface TravelInput {
83
+ start: TravelView;
84
+ end: TravelView;
85
+ /** The body the camera is at when the move starts. */
86
+ leaving: TravelBody;
87
+ /** The body the move goes to. For a view of a region, the body at its middle, with `reach`. */
88
+ destination: TravelBody;
89
+ /** The planet, when both ends are of one planet's family (two of its moons, or the planet and one of its moons; pass the planet itself then): the camera circles it and it stays in the picture the whole way. */
90
+ around?: TravelBody;
91
+ /** Any other body the path could pass: the Sun, the planets, the Moon, the dwarf planets and the small bodies of the view, as they go by their `to`. They are only kept clear of. */
92
+ others?: readonly TravelBody[];
93
+ /** The picture's width over its height. */
94
+ aspect: number;
95
+ /** How to move: `turn-travel` when left out. */
96
+ kind?: TravelKind;
97
+ /** True for a reader who asked for reduced motion: the move is a `cut` whatever `kind` says. */
98
+ reduced?: boolean;
99
+ /** Scales the suggested length of the move: 2 is twice as slow. 1 when left out. */
100
+ pace?: number;
101
+ /** How near the path may come to a body, in its radii above its surface: `TRAVEL_CLEARANCE` when left out. */
102
+ clearance?: number;
103
+ }
104
+ /**
105
+ * Where a body is in the picture at one moment: `inside` when its centre (the place of its marker) is within the frame, `x` and `y` from -1 at the left and bottom edges to 1 at the right and top, and `radius`,
106
+ * its angular radius in degrees. A body behind the camera is not inside, and its `x` and `y` say which side it is off.
107
+ *
108
+ * @example
109
+ * ```ts
110
+ * import type { TravelSight } from "@johnmorrisdotca/wakusei-planets/space";
111
+ *
112
+ * const marker = (sight: TravelSight): string => (sight.inside ? `${(50 + 50 * sight.x).toFixed(0)}% across` : "off the picture");
113
+ * console.log(marker({ inside: true, x: 0.2, y: 0, radius: 0.01 }));
114
+ * ```
115
+ */
116
+ export interface TravelSight {
117
+ inside: boolean;
118
+ x: number;
119
+ y: number;
120
+ radius: number;
121
+ }
122
+ /**
123
+ * The camera at one moment of a move, with the stage the move is in and where the two bodies (and the planet circled, when one was given) are in the picture, so a page can mark a body too small to see.
124
+ *
125
+ * @example
126
+ * ```ts
127
+ * import type { TravelSample } from "@johnmorrisdotca/wakusei-planets/space";
128
+ *
129
+ * const say = (sample: TravelSample): string => `${sample.stage}: destination ${sample.destination.inside ? "in" : "out of"} the picture`;
130
+ * console.log(typeof say);
131
+ * ```
132
+ */
133
+ export interface TravelSample extends TravelView {
134
+ stage: "turn" | "travel" | "arrive";
135
+ leaving: TravelSight;
136
+ destination: TravelSight;
137
+ around?: TravelSight;
138
+ }
139
+ /**
140
+ * What `travelPlan` works out: the way the move is made, the share of its time each stage takes (they add up to 1), how long it should last in milliseconds (from how far the picture turns and how many times
141
+ * over the distances change, never under 1200 or over 9000 before `pace`; a page may use any length of its own), the angle the look direction turns through in degrees, and how each stage is eased.
142
+ * `route` is the worked-out path for `travelPose`: hand the plan back to it to save working it out at every frame.
143
+ *
144
+ * @example
145
+ * ```ts
146
+ * import type { TravelPlan } from "@johnmorrisdotca/wakusei-planets/space";
147
+ *
148
+ * const seconds = (plan: TravelPlan): string => (plan.duration / 1000).toFixed(1);
149
+ * console.log(typeof seconds);
150
+ * ```
151
+ */
152
+ export interface TravelPlan {
153
+ /** What the move really is: `auto` reads `turn-travel`, and a reduced move reads `cut`. */
154
+ kind: Exclude<TravelKind, "auto">;
155
+ /** `pivot` (turn beside the body left, then go), `circle` (round the planet of one family), `line` (one straight line), `cut`. */
156
+ path: "pivot" | "circle" | "line" | "cut";
157
+ stages: {
158
+ turn: number;
159
+ travel: number;
160
+ arrive: number;
161
+ };
162
+ duration: number;
163
+ /** The angle between the first and the last look directions, in degrees: the least any move must turn. */
164
+ turn: number;
165
+ /** Turning follows a smooth step of its stage's time; distance grows geometrically out of the start and shrinks geometrically into the end, under a smooth step of the time. */
166
+ easing: {
167
+ turn: "smooth-step";
168
+ distance: "geometric";
169
+ };
170
+ /** The angle the camera turns round the destination as it arrives, in degrees: 0 when the whole turn is made before the way on. */
171
+ settle: number;
172
+ /** The path itself, for `travelPose`. */
173
+ route: unknown;
174
+ }
175
+ /**
176
+ * The plan of a move: its stages and the share of the time each takes, how long it should last, and how it is eased. The length is a suggestion from how far the picture changes (16 milliseconds a degree
177
+ * turned, 320 for each time the distance changes by a factor of e, between 1.2 and 9 seconds, times `pace`); a page may use its own, since `travelPose` takes the moment as a share of the move.
178
+ *
179
+ * @param input - The two views, the bodies and the picture's shape.
180
+ * @returns The plan. Hand it to `travelPose` as its third argument to save working the path out at every frame.
181
+ *
182
+ * @example
183
+ * ```ts
184
+ * import { travelPlan } from "@johnmorrisdotca/wakusei-planets/space";
185
+ *
186
+ * const plan = travelPlan({
187
+ * start: { position: [0, 0, 4.1], forward: [0, 0, -1], up: [0, 1, 0], fov: 35 },
188
+ * end: { position: [297.6, 0, 0], forward: [1, 0, 0], up: [0, 1, 0], fov: 35 },
189
+ * leaving: { from: [0, 0, 0], radius: 1 },
190
+ * destination: { from: [300, 0, 0], radius: 0.6 },
191
+ * aspect: 16 / 9,
192
+ * });
193
+ * console.log(plan.path, plan.duration, plan.stages.turn.toFixed(2));
194
+ * ```
195
+ */
196
+ export declare function travelPlan(input: TravelInput): TravelPlan;
197
+ /**
198
+ * The camera at the moment `t` of a move, from 0 (the first view) to 1 (the last view), with where the two bodies are in the picture. The same input and moment always give the same camera. The default move,
199
+ * `turn-travel`, never shows an empty picture between two framed views: the body being left (or the planet circled) is held in the picture through the turn, and the destination from the end of the turn on,
200
+ * where it only grows; the look direction turns one way only; no place is nearer a body than `TRAVEL_CLEARANCE`. `direct` and `look-back` are a straight eased glide and promise only the clearance. `cut`, or
201
+ * `reduced`, gives the last view for every `t` above 0.
202
+ *
203
+ * The bodies' places are taken at the two ends of the move (`from` and `to`): work out `end` for the destination's place at the end, and start a new move if the clock's speed changes on the way.
204
+ *
205
+ * @param input - The two views, the bodies and the picture's shape.
206
+ * @param t - The moment, as a share of the move from 0 to 1.
207
+ * @param plan - The plan from `travelPlan(input)`, to save working it out again.
208
+ * @returns The camera, the stage, and where the bodies are in the picture.
209
+ *
210
+ * @example
211
+ * ```ts
212
+ * import { travelPlan, travelPose, type TravelInput } from "@johnmorrisdotca/wakusei-planets/space";
213
+ *
214
+ * const input: TravelInput = {
215
+ * start: { position: [0, 0, 4.1], forward: [0, 0, -1], up: [0, 1, 0], fov: 35 },
216
+ * end: { position: [297.6, 0, 0], forward: [1, 0, 0], up: [0, 1, 0], fov: 35 },
217
+ * leaving: { from: [0, 0, 0], radius: 1 },
218
+ * destination: { from: [300, 0, 0], radius: 0.6 },
219
+ * aspect: 16 / 9,
220
+ * };
221
+ * const plan = travelPlan(input);
222
+ * for (const t of [0, 0.25, 0.5, 0.75, 1]) {
223
+ * const camera = travelPose(input, t, plan);
224
+ * console.log(camera.stage, camera.leaving.inside || camera.destination.inside);
225
+ * }
226
+ * ```
227
+ */
228
+ export declare function travelPose(input: TravelInput, t: number, plan?: TravelPlan): TravelSample;
229
+ /**
230
+ * A framed view of a whole body to arrive at, from the side the move comes from, so the approach is straight and nothing has to be turned back: the camera stands on the line towards `from`, moved round
231
+ * towards the Sun where that side would show less than about three fifths of the body lit (never more than 75 degrees off the Sun's direction), at `fit` radii away (4.1, and as much again as a tall picture is
232
+ * taller than wide), looking at the body with `north` up.
233
+ *
234
+ * @param input - The body's place and radius, where the move comes from, the Sun's place (left out for the Sun itself), the picture's shape, and optionally `fov`, `fit` and `north`.
235
+ * @returns The view, and `lit`, the share of the disc that is lit from there (1 when no Sun is given).
236
+ *
237
+ * @example
238
+ * ```ts
239
+ * import { travelArrival } from "@johnmorrisdotca/wakusei-planets/space";
240
+ *
241
+ * const view = travelArrival({ body: [300, 0, 0], radius: 0.6, from: [0, 0, 0], sun: [100, 0, 150], aspect: 16 / 9 });
242
+ * console.log(view.position.map((n) => n.toFixed(1)).join(", "), view.lit.toFixed(2));
243
+ * ```
244
+ */
245
+ export declare function travelArrival(input: {
246
+ body: Vec3;
247
+ radius: number;
248
+ from: Vec3;
249
+ sun?: Vec3;
250
+ aspect: number;
251
+ fov?: number;
252
+ fit?: number;
253
+ north?: Vec3;
254
+ }): TravelView & {
255
+ lit: number;
256
+ };