@johnmorrisdotca/wakusei-planets 0.39.0 → 0.40.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.40.0] - 2026-11-13
6
+
7
+ - **Paint an orbiter's path on the Moon or Mars** (MODULES-1168). `space.paint = { id, length, swath }` on `<wakusei-space>` paints that craft's ground track on the body it goes round (`id` such as `lro` or `mro`; `length` `1d` by default, or `1w`, `1m`, in the clock's time; `swath` `track` by default, or `coverage`, the ground where the craft is at least 10° up). `clearPaint()` takes it off, and another craft clears the old trail. Parts older than `length` fade and are dropped. The line is filled between frames, including backwards. One upload a frame while time moves, nothing at rest, and nothing while paint is off, when the picture and its sphere are freed on the graphics card. The craft's place is sampled at most a third of a trip apart, so a fast clock follows the orbit; a clock run backwards lays down the older end; a `coverage` swath over the date line is painted on both edges. The date-line split, the pole split and the swath radius are `@johnmorrisdotca/wakusei-planets/ground-track` (no DOM, no three.js). The space page has Paint, Clear, and 1 day, 1 week, 1 month.
8
+ - **Ride Off puts the demo's clock back** (the space page). A ride along starts the clock, and Off used to leave it running, at 3,600 times real time, with the view drawing every frame. Off now holds the clock again when the ride started it, and leaves it running at its own speed when it was already playing. Demo only.
9
+ - **The freeze test of the space view holds the clock** (MODULES-1187). "Changes to the space view give back what they took" read 183 graphics objects against a limit of 182 in the image: the rides in its round started the demo's clock, so the moons came and went with the time and the count was of a different moment each round. The round now holds the clock after the rides and waits for 30 frames with no draw before it counts. Test only.
10
+ - **The travel test watches a move on the page** (MODULES-1186). `e2e/space-travel.demo.ts` counted the draws of a move from the test, one round trip for each reading, so a loaded machine saw 6 frames of a move it needs more than 6 of. It now records each new draw at every animation frame on the page until the move ends. Test only.
11
+
5
12
  ## [0.39.0] - 2026-11-13
6
13
 
7
14
  - **The portrait builder's credit names each body's picture** (MODULES-1157). It was one fixed public-domain sentence for every painted scene; it is now `picturesCredit` for the bodies in the scene, so Saturn names Solar System Scope, Nestaeric, CC BY 4.0 and the changes. The builder's browser test now expects the source names of the body it shows, not the old public-domain sentence.
package/README.md CHANGED
@@ -19,7 +19,7 @@ Wakusei Planets runs in the browser of a phone, a tablet or a computer: nothing
19
19
 
20
20
  <p align="center"><img alt="The demo on a desk: Saturn in the painted look, turning in the big view, with the page's links to the portrait builder, the colouring sheets, the space view, the star page and the size line-up above it, and the choice of body and its moons below" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/main/docs/images/home-desk.webp" width="620"> <img alt="The same page on a phone: the same links in rows, and Saturn in the painted look below them" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/main/docs/images/home-phone.webp" width="200"></p>
21
21
 
22
- <p align="center"><img alt="Every body at one scale, the Earth among them: each small body has a magnified picture joined by a line, and the Sun shows only its edge" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.39.0/docs/images/lineup-desk.png" width="640"></p>
22
+ <p align="center"><img alt="Every body at one scale, the Earth among them: each small body has a magnified picture joined by a line, and the Sun shows only its edge" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.40.0/docs/images/lineup-desk.png" width="640"></p>
23
23
 
24
24
  ## Who it is for
25
25
 
@@ -388,7 +388,7 @@ The tiles of every body share one 48 MB budget, six loads at a time for a source
388
388
 
389
389
  ## The portrait builder
390
390
 
391
- <p align="center"><img alt="The Sun and the planets in an arc, painted, with their names, in the portrait builder" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.39.0/docs/images/portrait-family.png" width="640"></p>
391
+ <p align="center"><img alt="The Sun and the planets in an arc, painted, with their names, in the portrait builder" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.40.0/docs/images/portrait-family.png" width="640"></p>
392
392
 
393
393
  [The portrait builder](https://johnmorrisdotca.github.io/wakusei-planets/portrait.html) puts any bodies in one picture: drag them, size them, turn them, order them front to back, arrange them in a row, an arc, a grid or at true orbit distance (true or readable sizes, a planet's moons round it in orbit order), light them from one direction, and take the code, a PNG or an SVG. The scene is kept in the address, and every body is drawn in one WebGL scene, so the page holds one WebGL context. [The portrait builder](docs/guides/portrait-builder.md) is its guide.
394
394
 
@@ -534,7 +534,7 @@ BODIES.pluto.kind; // "dwarf-planet"
534
534
 
535
535
  If this package helps a paper, a talk or a class, please cite it as software. GitHub's "Cite this repository" button reads [CITATION.cff](CITATION.cff) and gives BibTeX and APA; in plain text:
536
536
 
537
- > Morris, J. (2026). *Wakusei Planets* (version 0.39.0) [Computer software]. https://github.com/johnmorrisdotca/wakusei-planets
537
+ > Morris, J. (2026). *Wakusei Planets* (version 0.40.0) [Computer software]. https://github.com/johnmorrisdotca/wakusei-planets
538
538
 
539
539
  Cite the version you used (`npm ls @johnmorrisdotca/wakusei-planets`), and cite the sources of the numbers you use as well: [NOTICE.md](NOTICE.md) names each one, with the paper or the page it was read from (the IAU working group's report for sizes and poles, VSOP87B, ELP2000-82B, L1.2 and TASS1.7 for positions, and NASA's JPL Horizons for the fits and the spacecraft).
540
540
 
@@ -0,0 +1,80 @@
1
+ /**
2
+ * A point on a body: longitude and latitude in degrees. Longitude runs from −180 to 180.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { splitDateLine, type GroundPoint } from "@johnmorrisdotca/wakusei-planets/ground-track";
7
+ *
8
+ * const point: GroundPoint = { lon: 170, lat: 10 };
9
+ * console.log(splitDateLine(point, { lon: -170, lat: 12 }).length);
10
+ * ```
11
+ */
12
+ export interface GroundPoint {
13
+ lon: number;
14
+ lat: number;
15
+ }
16
+ /**
17
+ * The angle at the body's centre, in radians, out to where a craft `heightKm` above the surface is `elevationDeg` above the horizon (10 when left out).
18
+ * 0 when the craft is on the surface or below, or so low that it is never that high. `radiusKm` is the body's radius.
19
+ *
20
+ * @param heightKm - Height above the surface, in kilometres.
21
+ * @param radiusKm - The body's radius, in kilometres.
22
+ * @param elevationDeg - The elevation that still counts, in degrees. 10 when left out.
23
+ * @returns The angle, in radians.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * import { coverageAngleRad } from "@johnmorrisdotca/wakusei-planets/ground-track";
28
+ *
29
+ * console.log(coverageAngleRad(400, 6371) > coverageAngleRad(50, 1737.4));
30
+ * ```
31
+ */
32
+ export declare function coverageAngleRad(heightKm: number, radiusKm: number, elevationDeg?: number): number;
33
+ /**
34
+ * Points from `a` to `b` along the great circle, about `stepDeg` apart, including both ends. A fast clock stays a continuous line.
35
+ *
36
+ * @param a - The start.
37
+ * @param b - The end.
38
+ * @param stepDeg - The longest step, in degrees.
39
+ * @returns The points, including both ends.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * import { trackSteps } from "@johnmorrisdotca/wakusei-planets/ground-track";
44
+ *
45
+ * console.log(trackSteps({ lon: 0, lat: 0 }, { lon: 10, lat: 0 }, 2).length > 2);
46
+ * ```
47
+ */
48
+ export declare function trackSteps(a: GroundPoint, b: GroundPoint, stepDeg: number): GroundPoint[];
49
+ /**
50
+ * One segment, or two when the short way from `a` to `b` crosses the date line, so an equirectangular line does not cross the whole map.
51
+ * Longitude is degrees, −180 to 180. This is the same split chikyu-earth uses for a satellite over the Earth.
52
+ *
53
+ * @param a - The start.
54
+ * @param b - The end.
55
+ * @returns One segment, or two that meet at ±180.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * import { splitDateLine } from "@johnmorrisdotca/wakusei-planets/ground-track";
60
+ *
61
+ * console.log(splitDateLine({ lon: 170, lat: 0 }, { lon: -170, lat: 0 }).length);
62
+ * ```
63
+ */
64
+ export declare function splitDateLine(a: GroundPoint, b: GroundPoint): [GroundPoint, GroundPoint][];
65
+ /**
66
+ * `splitDateLine`, and a split at a pole when the short way between two high-latitude points would cross the pole.
67
+ * Each piece is safe to draw as a straight line on an equirectangular map.
68
+ *
69
+ * @param a - The start.
70
+ * @param b - The end.
71
+ * @returns The pieces, in order.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * import { splitTrail } from "@johnmorrisdotca/wakusei-planets/ground-track";
76
+ *
77
+ * console.log(splitTrail({ lon: 10, lat: 80 }, { lon: 170, lat: 75 }).length > 1);
78
+ * ```
79
+ */
80
+ export declare function splitTrail(a: GroundPoint, b: GroundPoint): [GroundPoint, GroundPoint][];
@@ -0,0 +1,137 @@
1
+ // The ground track of a craft over a body: the date line, the poles, and the circle where the craft stands 10° up.
2
+ // Pure: no DOM, no three.js, no clock. chikyu-earth can import this later. Its Earth-only `coverageAngleRad(heightKm)` matches `coverageAngleRad(heightKm, 6371)`.
3
+ const RAD = Math.PI / 180;
4
+ /**
5
+ * The angle at the body's centre, in radians, out to where a craft `heightKm` above the surface is `elevationDeg` above the horizon (10 when left out).
6
+ * 0 when the craft is on the surface or below, or so low that it is never that high. `radiusKm` is the body's radius.
7
+ *
8
+ * @param heightKm - Height above the surface, in kilometres.
9
+ * @param radiusKm - The body's radius, in kilometres.
10
+ * @param elevationDeg - The elevation that still counts, in degrees. 10 when left out.
11
+ * @returns The angle, in radians.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { coverageAngleRad } from "@johnmorrisdotca/wakusei-planets/ground-track";
16
+ *
17
+ * console.log(coverageAngleRad(400, 6371) > coverageAngleRad(50, 1737.4));
18
+ * ```
19
+ */
20
+ export function coverageAngleRad(heightKm, radiusKm, elevationDeg = 10) {
21
+ const r = radiusKm + heightKm;
22
+ if (!(r > radiusKm) || !(radiusKm > 0))
23
+ return 0;
24
+ const elevation = elevationDeg * RAD;
25
+ const cosAlpha = (radiusKm / r) * Math.cos(elevation);
26
+ if (!(cosAlpha < 1))
27
+ return 0;
28
+ const alpha = Math.acos(Math.max(-1, cosAlpha));
29
+ return Math.max(0, alpha - elevation);
30
+ }
31
+ /** A unit vector for a longitude and latitude (+z at longitude 0, +x east, +y north). */
32
+ const unitOf = (point) => {
33
+ const lon = point.lon * RAD;
34
+ const lat = point.lat * RAD;
35
+ const c = Math.cos(lat);
36
+ return [c * Math.sin(lon), Math.sin(lat), c * Math.cos(lon)];
37
+ };
38
+ const fromUnit = (x, y, z) => {
39
+ const length = Math.hypot(x, y, z) || 1;
40
+ return { lon: (Math.atan2(x, z) * 180) / Math.PI, lat: (Math.asin(Math.max(-1, Math.min(1, y / length))) * 180) / Math.PI };
41
+ };
42
+ /**
43
+ * Points from `a` to `b` along the great circle, about `stepDeg` apart, including both ends. A fast clock stays a continuous line.
44
+ *
45
+ * @param a - The start.
46
+ * @param b - The end.
47
+ * @param stepDeg - The longest step, in degrees.
48
+ * @returns The points, including both ends.
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * import { trackSteps } from "@johnmorrisdotca/wakusei-planets/ground-track";
53
+ *
54
+ * console.log(trackSteps({ lon: 0, lat: 0 }, { lon: 10, lat: 0 }, 2).length > 2);
55
+ * ```
56
+ */
57
+ export function trackSteps(a, b, stepDeg) {
58
+ const u = unitOf(a);
59
+ const v = unitOf(b);
60
+ const dot = Math.max(-1, Math.min(1, u[0] * v[0] + u[1] * v[1] + u[2] * v[2]));
61
+ const angle = Math.acos(dot);
62
+ const step = Math.max(0.25, stepDeg) * RAD;
63
+ if (!(angle > step))
64
+ return [a, b];
65
+ const count = Math.ceil(angle / step);
66
+ const sin = Math.sin(angle) || 1;
67
+ const out = [];
68
+ for (let i = 0; i <= count; i += 1) {
69
+ const t = i / count;
70
+ const left = Math.sin((1 - t) * angle) / sin;
71
+ const right = Math.sin(t * angle) / sin;
72
+ out.push(fromUnit(u[0] * left + v[0] * right, u[1] * left + v[1] * right, u[2] * left + v[2] * right));
73
+ }
74
+ return out;
75
+ }
76
+ /**
77
+ * One segment, or two when the short way from `a` to `b` crosses the date line, so an equirectangular line does not cross the whole map.
78
+ * Longitude is degrees, −180 to 180. This is the same split chikyu-earth uses for a satellite over the Earth.
79
+ *
80
+ * @param a - The start.
81
+ * @param b - The end.
82
+ * @returns One segment, or two that meet at ±180.
83
+ *
84
+ * @example
85
+ * ```ts
86
+ * import { splitDateLine } from "@johnmorrisdotca/wakusei-planets/ground-track";
87
+ *
88
+ * console.log(splitDateLine({ lon: 170, lat: 0 }, { lon: -170, lat: 0 }).length);
89
+ * ```
90
+ */
91
+ export function splitDateLine(a, b) {
92
+ let delta = b.lon - a.lon;
93
+ if (delta > 180)
94
+ delta -= 360;
95
+ if (delta < -180)
96
+ delta += 360;
97
+ const end = a.lon + delta;
98
+ if (end <= 180 && end >= -180)
99
+ return [[a, { lon: end, lat: b.lat }]];
100
+ const edge = end > 180 ? 180 : -180;
101
+ const span = end - a.lon;
102
+ const t = span === 0 ? 0 : (edge - a.lon) / span;
103
+ const lat = a.lat + (b.lat - a.lat) * t;
104
+ const other = edge === 180 ? -180 : 180;
105
+ const rest = end > 180 ? end - 360 : end + 360;
106
+ return [
107
+ [a, { lon: edge, lat }],
108
+ [{ lon: other, lat }, { lon: rest, lat: b.lat }],
109
+ ];
110
+ }
111
+ /**
112
+ * `splitDateLine`, and a split at a pole when the short way between two high-latitude points would cross the pole.
113
+ * Each piece is safe to draw as a straight line on an equirectangular map.
114
+ *
115
+ * @param a - The start.
116
+ * @param b - The end.
117
+ * @returns The pieces, in order.
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * import { splitTrail } from "@johnmorrisdotca/wakusei-planets/ground-track";
122
+ *
123
+ * console.log(splitTrail({ lon: 10, lat: 80 }, { lon: 170, lat: 75 }).length > 1);
124
+ * ```
125
+ */
126
+ export function splitTrail(a, b) {
127
+ let delta = b.lon - a.lon;
128
+ if (delta > 180)
129
+ delta -= 360;
130
+ if (delta < -180)
131
+ delta += 360;
132
+ if (Math.abs(delta) > 90 && Math.abs(a.lat) > 45 && Math.abs(b.lat) > 45 && Math.sign(a.lat) === Math.sign(b.lat)) {
133
+ const pole = a.lat > 0 ? 90 : -90;
134
+ return [...splitDateLine(a, { lon: a.lon, lat: pole }), ...splitDateLine({ lon: b.lon, lat: pole }, b)];
135
+ }
136
+ return splitDateLine(a, b);
137
+ }
@@ -0,0 +1,80 @@
1
+ import { type BodyId } from "../facts.ts";
2
+ import { type GroundPoint } from "../ground-track.ts";
3
+ import { type Vec3 } from "../vec.ts";
4
+ export type PaintLength = "1d" | "1w" | "1m";
5
+ export type PaintSwath = "track" | "coverage";
6
+ /**
7
+ * What to paint: which craft, how long the trail is kept, and whether it is the line under the craft or the ground where it stands 10° up.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import type { PaintSpec } from "@johnmorrisdotca/wakusei-planets/space/element";
12
+ *
13
+ * const spec: PaintSpec = { id: "lro", length: "1d", swath: "track" };
14
+ * console.log(spec.id);
15
+ * ```
16
+ */
17
+ export interface PaintSpec {
18
+ /** An orbiter id, such as `lro` or `mro`. */
19
+ id: string;
20
+ /** How long the trail is kept, in simulated time. `1d` when left out. */
21
+ length?: PaintLength;
22
+ /** `track` paints the point under the craft (the default). `coverage` paints where it is at least 10° above the horizon. */
23
+ swath?: PaintSwath;
24
+ }
25
+ /** Equirectangular, north at the first row, longitude −180 at the first column. */
26
+ export declare const PAINT_W = 1024;
27
+ export declare const PAINT_H = 512;
28
+ export declare const paintLengthOf: (length: PaintLength | undefined) => PaintLength;
29
+ export declare const paintSwathOf: (swath: PaintSwath | undefined) => PaintSwath;
30
+ /** Ticks since the epoch, in 16 bits. One tick is two minutes, so a month fits in a signed 16-bit age. */
31
+ export declare const paintMinute: (ms: number) => number;
32
+ /**
33
+ * Where a craft is on a body's surface. `eclipticKm` is from the body's centre, ecliptic J2000, the same axes `/orbiters` uses.
34
+ *
35
+ * @param body - The body the craft goes round.
36
+ * @param eclipticKm - The place, in kilometres from the body's centre.
37
+ * @param ms - The instant, so the body has turned under the craft.
38
+ * @returns Longitude, latitude and height.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * import { orientation } from "@johnmorrisdotca/wakusei-planets/painter";
43
+ *
44
+ * console.log(orientation("moon", Date.UTC(2026, 10, 11)).pole.length === 3);
45
+ * ```
46
+ */
47
+ export declare function groundUnder(body: BodyId, eclipticKm: Vec3, ms: number): GroundPoint & {
48
+ heightKm: number;
49
+ };
50
+ export interface PaintTrail {
51
+ readonly data: Uint8Array;
52
+ readonly width: number;
53
+ readonly height: number;
54
+ readonly pixels: number;
55
+ readonly on: boolean;
56
+ readonly length: PaintLength;
57
+ readonly swath: PaintSwath;
58
+ readonly id: string;
59
+ readonly spanMinutes: number;
60
+ set(spec: PaintSpec | null): void;
61
+ clear(): void;
62
+ /**
63
+ * Stamp the ground crossed since the last call, and drop what has fallen out of the length. Returns true when `data` changed and should be uploaded. At rest, or with painting off, false.
64
+ * `periodMs` is one trip of the craft: samples are taken often enough that the line between two follows the orbit, however fast the clock. A clock run backwards fills in the older end of the length.
65
+ */
66
+ step(ms: number, radiusKm: number, sample: (ms: number) => (GroundPoint & {
67
+ heightKm: number;
68
+ }) | null, periodMs?: number): boolean;
69
+ }
70
+ /**
71
+ * The trail buffer. One for a view. `set` with another craft clears what was painted.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * import { splitDateLine } from "@johnmorrisdotca/wakusei-planets/ground-track";
76
+ *
77
+ * console.log(splitDateLine({ lon: 170, lat: 0 }, { lon: -170, lat: 4 }).length === 2);
78
+ * ```
79
+ */
80
+ export declare function createPaintTrail(): PaintTrail;
@@ -0,0 +1,322 @@
1
+ // One fixed equirectangular buffer for a craft's ground track. A frame stamps only the ground just crossed.
2
+ // The picture fades a stamp by the minute stored in it. Nothing is rebuilt at rest and the buffer never grows.
3
+ import { BODIES } from "../facts.js";
4
+ import { coverageAngleRad, splitTrail, trackSteps } from "../ground-track.js";
5
+ import { orientation } from "../scene/orient.js";
6
+ import { eclipticToScene } from "../space/frame.js";
7
+ import { cross, dot } from "../vec.js";
8
+ const DAY = 86_400_000;
9
+ const LENGTH_MS = { "1d": DAY, "1w": 7 * DAY, "1m": 30 * DAY };
10
+ /** Two minutes a tick, so a month (21,600 ticks) fits in a signed 16-bit age. */
11
+ const TICK = 120_000;
12
+ /** Equirectangular, north at the first row, longitude −180 at the first column. */
13
+ export const PAINT_W = 1024;
14
+ export const PAINT_H = 512;
15
+ export const paintLengthOf = (length) => (length === "1w" || length === "1m" ? length : "1d");
16
+ export const paintSwathOf = (swath) => (swath === "coverage" ? "coverage" : "track");
17
+ /** Ticks since the epoch, in 16 bits. One tick is two minutes, so a month fits in a signed 16-bit age. */
18
+ export const paintMinute = (ms) => Math.round(ms / TICK) & 0xffff;
19
+ /**
20
+ * Where a craft is on a body's surface. `eclipticKm` is from the body's centre, ecliptic J2000, the same axes `/orbiters` uses.
21
+ *
22
+ * @param body - The body the craft goes round.
23
+ * @param eclipticKm - The place, in kilometres from the body's centre.
24
+ * @param ms - The instant, so the body has turned under the craft.
25
+ * @returns Longitude, latitude and height.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * import { orientation } from "@johnmorrisdotca/wakusei-planets/painter";
30
+ *
31
+ * console.log(orientation("moon", Date.UTC(2026, 10, 11)).pole.length === 3);
32
+ * ```
33
+ */
34
+ export function groundUnder(body, eclipticKm, ms) {
35
+ const scene = eclipticToScene(eclipticKm);
36
+ const { pole, meridian } = orientation(body, ms);
37
+ const east = cross(pole, meridian);
38
+ const x = dot(scene, east);
39
+ const y = dot(scene, pole);
40
+ const z = dot(scene, meridian);
41
+ const radius = Math.hypot(x, y, z) || 1;
42
+ return {
43
+ lon: (Math.atan2(x, z) * 180) / Math.PI,
44
+ lat: (Math.asin(Math.max(-1, Math.min(1, y / radius))) * 180) / Math.PI,
45
+ heightKm: radius - BODIES[body].radiusKm,
46
+ };
47
+ }
48
+ const paintPixel = (lon, lat) => {
49
+ const u = lon / 360 + 0.5;
50
+ const v = 0.5 - lat / 180;
51
+ return { x: Math.max(0, Math.min(PAINT_W - 1, Math.floor(u * PAINT_W))), y: Math.max(0, Math.min(PAINT_H - 1, Math.floor(v * PAINT_H))) };
52
+ };
53
+ const write = (data, x, y, minute) => {
54
+ if (x < 0 || y < 0 || x >= PAINT_W || y >= PAINT_H)
55
+ return false;
56
+ const i = (y * PAINT_W + x) * 4;
57
+ const fresh = data[i + 3] === 0;
58
+ data[i] = (minute >> 8) & 255;
59
+ data[i + 1] = minute & 255;
60
+ data[i + 2] = 255;
61
+ data[i + 3] = 255;
62
+ return fresh;
63
+ };
64
+ const stampDot = (data, point, minute) => {
65
+ const at = paintPixel(point.lon, point.lat);
66
+ return write(data, at.x, at.y, minute) ? 1 : 0;
67
+ };
68
+ const stampLine = (data, a, b, minute) => {
69
+ const from = paintPixel(a.lon, a.lat);
70
+ const to = paintPixel(b.lon, b.lat);
71
+ if (Math.abs(to.x - from.x) > PAINT_W / 2)
72
+ return 0;
73
+ let added = 0;
74
+ let x = from.x;
75
+ let y = from.y;
76
+ const dx = Math.abs(to.x - x);
77
+ const dy = Math.abs(to.y - y);
78
+ const sx = x < to.x ? 1 : -1;
79
+ const sy = y < to.y ? 1 : -1;
80
+ let err = dx - dy;
81
+ for (;;) {
82
+ if (write(data, x, y, minute))
83
+ added += 1;
84
+ if (x === to.x && y === to.y)
85
+ break;
86
+ const e2 = 2 * err;
87
+ if (e2 > -dy) {
88
+ err -= dy;
89
+ x += sx;
90
+ }
91
+ if (e2 < dx) {
92
+ err += dx;
93
+ y += sy;
94
+ }
95
+ }
96
+ return added;
97
+ };
98
+ const RAD = Math.PI / 180;
99
+ /** Every pixel within `theta` radians of `point`, row by row: each row's half-width in longitude is worked out, and a cap over the date line wraps to the other edge. */
100
+ const stampCap = (data, point, theta, minute) => {
101
+ if (!(theta > 0))
102
+ return stampDot(data, point, minute);
103
+ const deg = theta / RAD;
104
+ const sin1 = Math.sin(point.lat * RAD);
105
+ const cos1 = Math.cos(point.lat * RAD);
106
+ const cosTheta = Math.cos(theta);
107
+ const y0 = paintPixel(0, Math.min(90, point.lat + deg)).y;
108
+ const y1 = paintPixel(0, Math.max(-90, point.lat - deg)).y;
109
+ let added = 0;
110
+ for (let y = y0; y <= y1; y += 1) {
111
+ const lat = (90 - ((y + 0.5) / PAINT_H) * 180) * RAD;
112
+ const denominator = cos1 * Math.cos(lat);
113
+ const need = cosTheta - sin1 * Math.sin(lat);
114
+ let half;
115
+ if (denominator < 1e-9) {
116
+ if (need > 0)
117
+ continue;
118
+ half = 180;
119
+ }
120
+ else {
121
+ const ratio = need / denominator;
122
+ if (ratio > 1)
123
+ continue;
124
+ half = ratio <= -1 ? 180 : Math.acos(ratio) / RAD;
125
+ }
126
+ const first = Math.floor(((point.lon - half + 180) / 360) * PAINT_W);
127
+ const last = Math.floor(((point.lon + half + 180) / 360) * PAINT_W);
128
+ if (last - first >= PAINT_W - 1) {
129
+ for (let x = 0; x < PAINT_W; x += 1)
130
+ if (write(data, x, y, minute))
131
+ added += 1;
132
+ }
133
+ else {
134
+ for (let x = first; x <= last; x += 1)
135
+ if (write(data, ((x % PAINT_W) + PAINT_W) % PAINT_W, y, minute))
136
+ added += 1;
137
+ }
138
+ }
139
+ return added;
140
+ };
141
+ const stampGround = (data, swath, ground, radiusKm, previous, minute) => {
142
+ const theta = swath === "coverage" ? coverageAngleRad(ground.heightKm, radiusKm) : 0;
143
+ // a line is made of steps a third of a degree long; a swath of caps that overlap, a step of about seven tenths of the cap's radius
144
+ const points = previous === null ? [ground] : trackSteps(previous, ground, swath === "coverage" ? Math.max(1, (theta / RAD) * 0.7) : 0.35);
145
+ let added = 0;
146
+ let cursor = previous;
147
+ for (const point of points) {
148
+ if (swath === "coverage")
149
+ added += stampCap(data, point, theta, minute);
150
+ else if (cursor === null)
151
+ added += stampDot(data, point, minute);
152
+ else
153
+ for (const [from, to] of splitTrail(cursor, point))
154
+ added += stampLine(data, from, to, minute);
155
+ cursor = point;
156
+ }
157
+ return { added, at: ground };
158
+ };
159
+ const ageOf = (then, now) => {
160
+ let age = now - then;
161
+ if (age < -32768)
162
+ age += 65536;
163
+ if (age > 32768)
164
+ age -= 65536;
165
+ return age;
166
+ };
167
+ /** The longest gap between two samples of the craft's place, so a line between them is the short way round the same great circle: a twentieth of a trip, and no more than four minutes (the body turns under it). */
168
+ const MAX_GAP = 240_000;
169
+ const MIN_GAP = 30_000;
170
+ /** Samples taken at most in one frame, and at most to lay down a whole length at once (a swath costs more a sample than a line). A gap is never more than a third of a trip, however many that takes. */
171
+ const FRAME_SAMPLES = 600;
172
+ const REBUILD_SAMPLES = { track: 4000, coverage: 1500 };
173
+ const gapOf = (periodMs) => (periodMs !== undefined && periodMs > 0 ? Math.max(MIN_GAP, Math.min(MAX_GAP, periodMs / 20)) : TICK);
174
+ /**
175
+ * The trail buffer. One for a view. `set` with another craft clears what was painted.
176
+ *
177
+ * @example
178
+ * ```ts
179
+ * import { splitDateLine } from "@johnmorrisdotca/wakusei-planets/ground-track";
180
+ *
181
+ * console.log(splitDateLine({ lon: 170, lat: 0 }, { lon: -170, lat: 4 }).length === 2);
182
+ * ```
183
+ */
184
+ export function createPaintTrail() {
185
+ // the two megabytes are taken when the first craft is painted, not when the view is made
186
+ let buffer = null;
187
+ const grab = () => (buffer ??= new Uint8Array(PAINT_W * PAINT_H * 4));
188
+ let spec = null;
189
+ let pixels = 0;
190
+ let lastMs = Number.NaN;
191
+ /** The last point stamped and the way the clock was going then, so a line carries on from it. */
192
+ let previous = null;
193
+ let heading = 0;
194
+ /** The buffer was emptied since the last step: the picture must be sent even if nothing new was stamped. */
195
+ let stale = false;
196
+ const reset = () => {
197
+ buffer?.fill(0);
198
+ pixels = 0;
199
+ lastMs = Number.NaN;
200
+ previous = null;
201
+ heading = 0;
202
+ stale = true;
203
+ };
204
+ const dropOld = (data, now, span) => {
205
+ for (let i = 0; i < data.length; i += 4) {
206
+ if (data[i + 3] === 0)
207
+ continue;
208
+ const then = ((data[i] ?? 0) << 8) | (data[i + 1] ?? 0);
209
+ const age = ageOf(then, now);
210
+ // a tick of slack at each end, for the rounding of the stamp's minute
211
+ if (age > span + 1 || age < -1) {
212
+ data[i] = 0;
213
+ data[i + 1] = 0;
214
+ data[i + 2] = 0;
215
+ data[i + 3] = 0;
216
+ pixels -= 1;
217
+ }
218
+ }
219
+ };
220
+ const self = {
221
+ get data() {
222
+ return grab();
223
+ },
224
+ width: PAINT_W,
225
+ height: PAINT_H,
226
+ get pixels() {
227
+ return pixels;
228
+ },
229
+ get on() {
230
+ return spec !== null;
231
+ },
232
+ get length() {
233
+ return spec?.length ?? "1d";
234
+ },
235
+ get swath() {
236
+ return spec?.swath ?? "track";
237
+ },
238
+ get id() {
239
+ return spec?.id ?? "";
240
+ },
241
+ get spanMinutes() {
242
+ return LENGTH_MS[spec?.length ?? "1d"] / TICK;
243
+ },
244
+ set(next) {
245
+ if (!next) {
246
+ self.clear();
247
+ return;
248
+ }
249
+ const id = String(next.id);
250
+ const length = paintLengthOf(next.length);
251
+ const swath = paintSwathOf(next.swath);
252
+ if (spec && spec.id === id && spec.length === length && spec.swath === swath)
253
+ return;
254
+ reset();
255
+ spec = { id, length, swath };
256
+ },
257
+ clear() {
258
+ reset();
259
+ spec = null;
260
+ },
261
+ step(ms, radiusKm, sample, periodMs) {
262
+ if (!spec) {
263
+ const upload = stale;
264
+ stale = false;
265
+ return upload;
266
+ }
267
+ if (!Number.isFinite(ms))
268
+ return false;
269
+ if (Number.isFinite(lastMs) && ms === lastMs) {
270
+ const upload = stale;
271
+ stale = false;
272
+ return upload;
273
+ }
274
+ const data = grab();
275
+ const length = LENGTH_MS[spec.length];
276
+ const gap = gapOf(periodMs);
277
+ let dirty = stale;
278
+ stale = false;
279
+ /** Stamp the craft's place at each of `times`, one line from the one before. */
280
+ const lay = (times, way) => {
281
+ if (way !== heading)
282
+ previous = null;
283
+ heading = way;
284
+ for (const at of times) {
285
+ const ground = sample(at);
286
+ if (!ground) {
287
+ previous = null;
288
+ continue;
289
+ }
290
+ const stamped = stampGround(data, spec.swath, ground, radiusKm, previous, paintMinute(at));
291
+ pixels += stamped.added;
292
+ previous = stamped.at;
293
+ dirty = true;
294
+ }
295
+ };
296
+ const between = (from, to, cap) => {
297
+ const span = Math.abs(to - from);
298
+ const count = Math.max(Math.min(cap, Math.max(1, Math.ceil(span / gap))), periodMs === undefined ? 1 : Math.ceil(span / (periodMs / 3)));
299
+ return Array.from({ length: count + 1 }, (_, i) => from + ((to - from) * i) / count);
300
+ };
301
+ if (!Number.isFinite(lastMs) || Math.abs(ms - lastMs) > length) {
302
+ // the first moment, or a jump: the whole length is laid down again, oldest first
303
+ data.fill(0);
304
+ pixels = 0;
305
+ previous = null;
306
+ heading = 1;
307
+ lay(between(ms - length, ms, REBUILD_SAMPLES[spec.swath]), 1);
308
+ }
309
+ else if (ms > lastMs) {
310
+ lay(between(lastMs, ms, FRAME_SAMPLES), 1);
311
+ }
312
+ else {
313
+ // backwards: the newer end falls away below, and the older end, which the clock has just uncovered, is laid down
314
+ lay(between(lastMs - length, ms - length, FRAME_SAMPLES), -1);
315
+ }
316
+ dropOld(data, paintMinute(ms), length / TICK);
317
+ lastMs = ms;
318
+ return dirty || pixels > 0;
319
+ },
320
+ };
321
+ return self;
322
+ }
@@ -11,7 +11,7 @@ import { type BodyMapSource } from "../door/map.ts";
11
11
  * console.log(TEXTURE_BASE);
12
12
  * ```
13
13
  */
14
- export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@0.39.0/dist/textures/";
14
+ export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@0.40.0/dist/textures/";
15
15
  /**
16
16
  * Where the sharpest surface pictures are: the files of this exact version in the repository, on jsDelivr's GitHub address. The npm package holds only the two smaller widths, so a page that
17
17
  * never zooms in never fetches them. Set `texture-far-base` on an element to serve them yourself.
@@ -23,7 +23,7 @@ export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdot
23
23
  * console.log(TEXTURE_FAR_BASE);
24
24
  * ```
25
25
  */
26
- export declare const TEXTURE_FAR_BASE = "https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v0.39.0/textures/";
26
+ export declare const TEXTURE_FAR_BASE = "https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v0.40.0/textures/";
27
27
  /**
28
28
  * Where the finer map tiles are by default: the demo site's `tiles/` folder (GitHub Pages sends `access-control-allow-origin: *`). The tiles are made by `scripts/make-body-tiles.py` and are in no package and no repository:
29
29
  * a page that serves its own gives the folder in the `tiles` attribute, and `tiles="off"` turns them off. A page that sets `texture-base` (it serves its own pictures) has none unless it says where they are.
@@ -17,6 +17,8 @@ import { type Place } from "../places.ts";
17
17
  import { type PlaceLayer } from "../place-marks.ts";
18
18
  import { type EarthPlace, type EarthPlaceLook, type EarthPlaceMark } from "../scene/earth-places.ts";
19
19
  import { SPACE_BODIES, type BodyPlace, type RidePoint, type RideState, type RideTarget, type SpaceBody, type SpaceLight } from "./scene.ts";
20
+ import { type PaintSpec } from "../paint/trail.ts";
21
+ export type { PaintSpec };
20
22
  export { setPlacesLoader } from "../scene/place-layer.ts";
21
23
  export { EARTH_PLACE_LOOKS, EARTH_PLACE_MARKS, type EarthPlace, type EarthPlaceKind, type EarthPlaceLook, type EarthPlaceMark } from "../scene/earth-places.ts";
22
24
  export { setThreeLoader, SPACE_BODIES, type RidePoint, type RideTarget, type Sight, type SightEdge, type SpaceBody, type SpaceLight };
@@ -279,6 +281,27 @@ export declare class WakuseiSpace extends HTMLElement {
279
281
  */
280
282
  get orbiters(): boolean;
281
283
  set orbiters(value: boolean);
284
+ /**
285
+ * Paint one orbiter's path on the body it goes round. `id` is an orbiter such as `lro` or `mro`. `length` is how long the trail is kept, in simulated time (`1d` when left out, or `1w`, `1m`).
286
+ * `swath` is `track` (the point under the craft, the default) or `coverage` (where it is at least 10° above the horizon). Setting another craft clears the trail. `null` clears it.
287
+ * The trail is drawn only while time is moving, one upload a frame, and nothing at rest.
288
+ *
289
+ * @example
290
+ * ```ts no-run
291
+ * import type { WakuseiSpace } from "@johnmorrisdotca/wakusei-planets/space/element";
292
+ *
293
+ * const paint = (space: WakuseiSpace): void => {
294
+ * space.paint = { id: "lro", length: "1d", swath: "track" };
295
+ * };
296
+ * console.log(typeof paint);
297
+ * ```
298
+ */
299
+ get paint(): PaintSpec | null;
300
+ set paint(value: PaintSpec | null);
301
+ /** Take the painted trail off the body. */
302
+ clearPaint(): void;
303
+ /** Texels the trail has painted. 0 after `clearPaint`, and again when the painted craft changes. */
304
+ get paintPixels(): number;
282
305
  /**
283
306
  * Show Starman and the Tesla Roadster (the attribute `roadster`; off by default): a small marked body where `/roadster` puts the car on the date shown, on its orbit line (about one trip round the Sun), with its name
284
307
  * (`Starman`, `スターマン`) beside it, from the launch in 2018 to the end of 2035. Its path (a 20 kB table) is loaded the first time it is shown, and never when it is not. `stats.roadster` says what was drawn.
@@ -28,6 +28,7 @@ import { createPlaceLayer, onPlacesLoader, placesLoader } from "../scene/place-l
28
28
  import { createEarthPlaceLayer, EARTH_PLACE_MARKS, EARTH_PLACES_FROM_PX, earthPlacesLayout, onEarthPlacesLayout, readEarthPlaceLook } from "../scene/earth-places.js";
29
29
  import { cross, dot } from "../vec.js";
30
30
  import { createSpaceItem, FIT_DISTANCE, newSpaceModel, SPACE_BODIES } from "./scene.js";
31
+ import { paintLengthOf, paintSwathOf } from "../paint/trail.js";
31
32
  export { setPlacesLoader } from "../scene/place-layer.js";
32
33
  export { EARTH_PLACE_LOOKS, EARTH_PLACE_MARKS } from "../scene/earth-places.js";
33
34
  export { setThreeLoader, SPACE_BODIES };
@@ -775,6 +776,46 @@ export class WakuseiSpace extends HTMLElement {
775
776
  }
776
777
  this.#gate?.request();
777
778
  }
779
+ /**
780
+ * Paint one orbiter's path on the body it goes round. `id` is an orbiter such as `lro` or `mro`. `length` is how long the trail is kept, in simulated time (`1d` when left out, or `1w`, `1m`).
781
+ * `swath` is `track` (the point under the craft, the default) or `coverage` (where it is at least 10° above the horizon). Setting another craft clears the trail. `null` clears it.
782
+ * The trail is drawn only while time is moving, one upload a frame, and nothing at rest.
783
+ *
784
+ * @example
785
+ * ```ts no-run
786
+ * import type { WakuseiSpace } from "@johnmorrisdotca/wakusei-planets/space/element";
787
+ *
788
+ * const paint = (space: WakuseiSpace): void => {
789
+ * space.paint = { id: "lro", length: "1d", swath: "track" };
790
+ * };
791
+ * console.log(typeof paint);
792
+ * ```
793
+ */
794
+ get paint() {
795
+ const spec = this.#model.paint;
796
+ return spec === null ? null : { id: spec.id, length: paintLengthOf(spec.length), swath: paintSwathOf(spec.swath) };
797
+ }
798
+ set paint(value) {
799
+ if (value === null) {
800
+ this.#model.paint = null;
801
+ this.#model.paintTrail.clear();
802
+ }
803
+ else {
804
+ const next = { id: String(value.id), length: paintLengthOf(value.length), swath: paintSwathOf(value.swath) };
805
+ this.#model.paint = next;
806
+ this.#model.paintTrail.set(next);
807
+ this.orbiters = true;
808
+ }
809
+ this.#gate?.request();
810
+ }
811
+ /** Take the painted trail off the body. */
812
+ clearPaint() {
813
+ this.paint = null;
814
+ }
815
+ /** Texels the trail has painted. 0 after `clearPaint`, and again when the painted craft changes. */
816
+ get paintPixels() {
817
+ return this.#model.paintTrail.pixels;
818
+ }
778
819
  #roadsterLoading = false;
779
820
  /**
780
821
  * Show Starman and the Tesla Roadster (the attribute `roadster`; off by default): a small marked body where `/roadster` puts the car on the date shown, on its orbit line (about one trip round the Sun), with its name
@@ -0,0 +1,11 @@
1
+ import type * as THREE from "three";
2
+ import type { ThreeParts } from "../scene/body.ts";
3
+ /**
4
+ * The trail drawn on a body. `show` parents it to that body's oriented mesh. `hide` draws nothing and gives the picture's and the sphere's copies on the graphics card back, so a view with paint off
5
+ * holds none of it. `dispose` frees the geometry, the material and the texture for good.
6
+ */
7
+ export declare function createPaintOverlay(three: ThreeParts, data: Uint8Array): {
8
+ show(host: THREE.Object3D, nowMinute: number, spanMinutes: number, upload: boolean): void;
9
+ hide(): void;
10
+ dispose(): void;
11
+ };
@@ -0,0 +1,84 @@
1
+ import { PAINT_H, PAINT_W } from "../paint/trail.js";
2
+ const VERTEX = /* glsl */ `
3
+ varying vec3 vLocal;
4
+ void main() {
5
+ vLocal = normalize(position);
6
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
7
+ }
8
+ `;
9
+ const FRAGMENT = /* glsl */ `
10
+ uniform sampler2D uMap;
11
+ uniform float uNow;
12
+ uniform float uSpan;
13
+ varying vec3 vLocal;
14
+ void main() {
15
+ float lat = asin(clamp(vLocal.y, -1.0, 1.0));
16
+ float lon = atan(vLocal.x, vLocal.z);
17
+ vec2 uv = vec2(lon / 6.2831853 + 0.5, 0.5 - lat / 3.14159265);
18
+ vec4 stamp = texture2D(uMap, uv);
19
+ float then = floor(stamp.r * 255.0 + 0.5) * 256.0 + floor(stamp.g * 255.0 + 0.5);
20
+ float age = uNow - then;
21
+ if (age < -32768.0) age += 65536.0;
22
+ if (age > 32768.0) age -= 65536.0;
23
+ float show = stamp.a * step(-1.0, age) * (1.0 - smoothstep(uSpan * 0.82, uSpan, max(age, 0.0)));
24
+ if (show < 0.04) discard;
25
+ gl_FragColor = vec4(1.0, 0.55, 0.12, clamp(show, 0.0, 0.9));
26
+ }
27
+ `;
28
+ /**
29
+ * The trail drawn on a body. `show` parents it to that body's oriented mesh. `hide` draws nothing and gives the picture's and the sphere's copies on the graphics card back, so a view with paint off
30
+ * holds none of it. `dispose` frees the geometry, the material and the texture for good.
31
+ */
32
+ export function createPaintOverlay(three, data) {
33
+ const texture = new three.DataTexture(data, PAINT_W, PAINT_H, three.RGBAFormat);
34
+ texture.flipY = false;
35
+ texture.magFilter = three.LinearFilter;
36
+ texture.minFilter = three.LinearFilter;
37
+ texture.generateMipmaps = false;
38
+ texture.colorSpace = three.NoColorSpace;
39
+ texture.needsUpdate = false;
40
+ const geometry = new three.SphereGeometry(1.004, 64, 32);
41
+ const material = new three.ShaderMaterial({
42
+ vertexShader: VERTEX,
43
+ fragmentShader: FRAGMENT,
44
+ transparent: true,
45
+ depthWrite: false,
46
+ uniforms: { uMap: { value: texture }, uNow: { value: 0 }, uSpan: { value: 1440 } },
47
+ });
48
+ const mesh = new three.Mesh(geometry, material);
49
+ mesh.name = "ground-track";
50
+ mesh.frustumCulled = false;
51
+ mesh.renderOrder = 3;
52
+ mesh.visible = false;
53
+ /** Whether the texture or the sphere may be on the graphics card. */
54
+ let held = false;
55
+ return {
56
+ show(host, nowMinute, spanMinutes, upload) {
57
+ if (mesh.parent !== host)
58
+ host.add(mesh);
59
+ mesh.visible = true;
60
+ if (!held) {
61
+ held = true;
62
+ texture.needsUpdate = true;
63
+ }
64
+ material.uniforms.uNow.value = nowMinute;
65
+ material.uniforms.uSpan.value = spanMinutes;
66
+ if (upload)
67
+ texture.needsUpdate = true;
68
+ },
69
+ hide() {
70
+ mesh.visible = false;
71
+ if (held) {
72
+ held = false;
73
+ texture.dispose();
74
+ geometry.dispose();
75
+ }
76
+ },
77
+ dispose() {
78
+ mesh.parent?.remove(mesh);
79
+ geometry.dispose();
80
+ material.dispose();
81
+ texture.dispose();
82
+ },
83
+ };
84
+ }
@@ -11,6 +11,7 @@ import { type Vec3 } from "../vec.ts";
11
11
  import { type OrbitArrow } from "./arrows.ts";
12
12
  import type { SightInput } from "./sight.ts";
13
13
  import { type SpaceFrame, type SpaceVec3 } from "./frame.ts";
14
+ import { type PaintSpec, type PaintTrail } from "../paint/trail.ts";
14
15
  import { type RideLook } from "./ride.ts";
15
16
  import { type ScaleMode } from "./scale.ts";
16
17
  import { type SunRegion } from "./regions.ts";
@@ -218,6 +219,10 @@ export interface SpaceModel {
218
219
  lines: number;
219
220
  track: number;
220
221
  };
222
+ /** The craft whose ground track is painted on its body, or null. */
223
+ paint: PaintSpec | null;
224
+ /** The trail buffer the element and the scene share. */
225
+ paintTrail: PaintTrail;
221
226
  /** Show Starman and the Roadster: a small marked body on its orbit line, named. Off by default; its path is loaded when it is first shown. */
222
227
  roadster: boolean;
223
228
  roadsterPath: RoadsterPath | null;
@@ -14,6 +14,8 @@ import { besideMoon } from "./beside.js";
14
14
  import { coveredBy } from "./covered.js";
15
15
  import { spinAxis } from "./spin.js";
16
16
  import { createTrack, eclipticToScene, frameAt, moonOrbit, planetOrbit, SPACE_DWARFS, SPACE_MINORS, SPACE_PLANETS } from "./frame.js";
17
+ import { createPaintOverlay } from "./paint-overlay.js";
18
+ import { createPaintTrail, groundUnder, paintMinute } from "../paint/trail.js";
17
19
  import { BALL_FRAGMENT, VERTEX } from "../scene/glsl.js";
18
20
  import { ridePose } from "./ride.js";
19
21
  import { moonDistance, orbitLine, placeAround, placeBodies, placeMoon, radiusIn } from "./scale.js";
@@ -98,6 +100,8 @@ export const newSpaceModel = () => ({
98
100
  orbiterLines: "all",
99
101
  orbiterTrack: false,
100
102
  orbitersDrawn: { count: 0, status: {}, dim: [], lines: 0, track: 0 },
103
+ paint: null,
104
+ paintTrail: createPaintTrail(),
101
105
  roadster: false,
102
106
  roadsterPath: null,
103
107
  roadsterDrawn: { shown: false, position: null, radiusPx: 0 },
@@ -179,6 +183,8 @@ export function createSpaceItem(model, deps) {
179
183
  const scratchB = new three.Vector3();
180
184
  // the orbit lines of a stage out from the Sun, kept while the stage, the scale and the day are the same
181
185
  let regionLines = null;
186
+ // made when the first trail is shown: a view that never paints holds none of it
187
+ let paintOverlay = null;
182
188
  let ended = false;
183
189
  const slots = new Map();
184
190
  const empty = (slot) => {
@@ -913,6 +919,24 @@ export function createSpaceItem(model, deps) {
913
919
  if (trackDrawn === 0)
914
920
  trackLine.visible = false;
915
921
  model.orbitersDrawn = { count: Object.keys(orbiterPlaces).length, status: orbiterStatus, dim: orbitersDim, lines: linesDrawn, track: trackDrawn };
922
+ // the painted trail: stepped and uploaded only while the painted craft's body is drawn, and only when the shown moment moved
923
+ const paintedCraft = model.paint;
924
+ const paintSet = model.orbiterSet;
925
+ const paintBody = paintedCraft !== null && paintSet !== null && paintSet.ids.includes(paintedCraft.id) ? slots.get(paintSet.centre(paintedCraft.id))?.drawing : undefined;
926
+ const paintHost = paintBody !== undefined && paintBody.object.visible ? paintBody.object.children[0] : undefined;
927
+ if (paintedCraft !== null && paintSet !== null && paintHost !== undefined) {
928
+ const centre = paintSet.centre(paintedCraft.id);
929
+ const period = paintSet.period(paintedCraft.id);
930
+ const trail = model.paintTrail;
931
+ const upload = trail.step(model.time, BODIES[centre].radiusKm, (at) => {
932
+ const there = paintSet.position(paintedCraft.id, at);
933
+ return there === null ? null : groundUnder(centre, there, at);
934
+ }, period === null ? undefined : period * 86_400_000);
935
+ (paintOverlay ??= createPaintOverlay(three, model.paintTrail.data)).show(paintHost, paintMinute(model.time), trail.spanMinutes, upload);
936
+ }
937
+ else {
938
+ paintOverlay?.hide();
939
+ }
916
940
  model.roadsterDrawn = { shown: roadsterAt !== null, position: roadsterAt === null ? null : [roadsterAt[0] + origin[0], roadsterAt[1] + origin[1], roadsterAt[2] + origin[2]], radiusPx: roadsterPx };
917
941
  // 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)
918
942
  const e = camera.matrixWorld.elements;
@@ -1169,6 +1193,7 @@ export function createSpaceItem(model, deps) {
1169
1193
  dots?.dispose();
1170
1194
  oortGeometry.dispose();
1171
1195
  oortLines.material.dispose();
1196
+ paintOverlay?.dispose();
1172
1197
  if (releaseTimer !== undefined)
1173
1198
  clearTimeout(releaseTimer);
1174
1199
  ended = true;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.39.0";
1
+ export declare const VERSION = "0.40.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "0.39.0";
1
+ export const VERSION = "0.40.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/wakusei-planets",
3
- "version": "0.39.0",
3
+ "version": "0.40.0",
4
4
  "description": "Wakusei Planets 惑星 — The Sun, planets and moons for the web: each as a clean line drawing, a shaded realistic drawing or a painted surface map, with real sizes, axial tilt and rotation as data, and positions of the moons for any date and time. SVG for the lines, three.js (optional) for the rest.",
5
5
  "keywords": [
6
6
  "planets",
@@ -370,6 +370,11 @@
370
370
  "import": "./dist/orbiters.js",
371
371
  "default": "./dist/orbiters.js"
372
372
  },
373
+ "./ground-track": {
374
+ "types": "./dist/ground-track.d.ts",
375
+ "import": "./dist/ground-track.js",
376
+ "default": "./dist/ground-track.js"
377
+ },
373
378
  "./suncalc": {
374
379
  "types": "./dist/suncalc.d.ts",
375
380
  "import": "./dist/suncalc.js",