@johnmorrisdotca/wakusei-planets 0.38.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 +13 -0
- package/NOTICE.md +2 -2
- package/README.md +4 -4
- package/dist/door/own.js +4 -2
- package/dist/embed.d.ts +4 -1
- package/dist/embed.js +21 -10
- package/dist/ground-track.d.ts +80 -0
- package/dist/ground-track.js +137 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/paint/trail.d.ts +80 -0
- package/dist/paint/trail.js +322 -0
- package/dist/picture-credits.d.ts +78 -0
- package/dist/picture-credits.js +120 -0
- package/dist/scene/painter.d.ts +11 -0
- package/dist/scene/painter.js +30 -2
- package/dist/scene/textures.d.ts +2 -2
- package/dist/space/element.d.ts +23 -0
- package/dist/space/element.js +41 -0
- package/dist/space/paint-overlay.d.ts +11 -0
- package/dist/space/paint-overlay.js +84 -0
- package/dist/space/scene.d.ts +5 -0
- package/dist/space/scene.js +25 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +6 -1
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { type BodyId } from "./facts.ts";
|
|
2
|
+
/**
|
|
3
|
+
* One body's surface picture: who made the map, the licence named in `NOTICE.md`, and, for a CC BY 4.0 map, what this package changed.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { PICTURE_CREDITS, type PictureCredit } from "@johnmorrisdotca/wakusei-planets";
|
|
8
|
+
*
|
|
9
|
+
* const jupiter: PictureCredit = PICTURE_CREDITS.find((row) => row.id === "jupiter")!;
|
|
10
|
+
* console.log(jupiter.licence);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export interface PictureCredit {
|
|
14
|
+
/** The body, as `BODY_IDS` names it. */
|
|
15
|
+
readonly id: BodyId;
|
|
16
|
+
/** The licence of that body's map in `NOTICE.md`: `CC BY 4.0` or `Public domain`. */
|
|
17
|
+
readonly licence: "CC BY 4.0" | "Public domain";
|
|
18
|
+
/** The credit column of `NOTICE.md` for this picture, in English, and the same fact in Japanese. */
|
|
19
|
+
readonly credit: {
|
|
20
|
+
readonly en: string;
|
|
21
|
+
readonly ja: string;
|
|
22
|
+
};
|
|
23
|
+
/** What this package changed, from the table's "What was done" column. Present for a CC BY 4.0 map, which asks that changes be named. */
|
|
24
|
+
readonly changes?: {
|
|
25
|
+
readonly en: string;
|
|
26
|
+
readonly ja: string;
|
|
27
|
+
};
|
|
28
|
+
/** Another picture drawn with the body (Saturn's rings), with its own credit and licence. */
|
|
29
|
+
readonly also?: {
|
|
30
|
+
readonly en: string;
|
|
31
|
+
readonly ja: string;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The surface picture of every body that has one, in the order of the table in `NOTICE.md`. A body with no row is drawn from numbers and has no picture to credit.
|
|
36
|
+
* The English of a CC BY 4.0 row is that table's credit column. Jupiter and Uranus keep the authors' own attribution sentences, including the spelling of the name.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { PICTURE_CREDITS } from "@johnmorrisdotca/wakusei-planets";
|
|
41
|
+
*
|
|
42
|
+
* console.log(PICTURE_CREDITS.filter((row) => row.licence === "CC BY 4.0").map((row) => row.id).join(","));
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare const PICTURE_CREDITS: readonly PictureCredit[];
|
|
46
|
+
/**
|
|
47
|
+
* The credit for Mercury's finer map tiles. Their detail is a public-domain map, and their colour is the 2048 picture, which is CC BY 4.0, so the tiles carry that credit too.
|
|
48
|
+
* The words are the Mercury row of `NOTICE.md`'s "Finer map tiles" table.
|
|
49
|
+
*
|
|
50
|
+
* @param lang - `en` or `ja`.
|
|
51
|
+
* @returns The one sentence.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* import { mercuryTilesCredit } from "@johnmorrisdotca/wakusei-planets";
|
|
56
|
+
*
|
|
57
|
+
* console.log(mercuryTilesCredit("en").includes("CC BY 4.0"));
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function mercuryTilesCredit(lang: "en" | "ja"): string;
|
|
61
|
+
/**
|
|
62
|
+
* The credit line for the surface pictures of the named bodies, in one language. A name is a body id in any case (`Jupiter`, `moon`). A body with no picture is left out.
|
|
63
|
+
* Only the named bodies are credited: Jupiter names Nestaeric and CC BY 4.0, and the Moon and Mars, whose maps are public domain, name no CC BY 4.0 source.
|
|
64
|
+
* An empty list, or a list of bodies with no pictures, is an empty string.
|
|
65
|
+
*
|
|
66
|
+
* @param bodies - The bodies a page is showing.
|
|
67
|
+
* @param lang - `en` or `ja`.
|
|
68
|
+
* @returns The line, or `""` when none of the bodies has a picture.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* import { picturesCredit } from "@johnmorrisdotca/wakusei-planets";
|
|
73
|
+
*
|
|
74
|
+
* console.log(picturesCredit(["Jupiter"], "en").includes("Nestaeric"));
|
|
75
|
+
* console.log(picturesCredit(["Moon", "Mars"], "en").includes("CC BY") === false);
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare function picturesCredit(bodies: readonly string[], lang: "en" | "ja"): string;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// Which body's surface picture comes from which source, written from the rows of NOTICE.md (the "Surface pictures" table). Pure: no DOM, no three.js.
|
|
2
|
+
// A page that shows a body names only that body's row. The English credit is the table's credit column, unchanged; the Japanese says the same fact.
|
|
3
|
+
import { BODIES } from "./facts.js";
|
|
4
|
+
const cc = (id, en, ja, changesEn, changesJa, also) => ({
|
|
5
|
+
id,
|
|
6
|
+
licence: "CC BY 4.0",
|
|
7
|
+
credit: { en, ja },
|
|
8
|
+
changes: { en: changesEn, ja: changesJa },
|
|
9
|
+
...(also === undefined ? {} : { also: { en: also.en, ja: also.ja } }),
|
|
10
|
+
});
|
|
11
|
+
const pd = (id, en, ja) => ({ id, licence: "Public domain", credit: { en, ja } });
|
|
12
|
+
/**
|
|
13
|
+
* The surface picture of every body that has one, in the order of the table in `NOTICE.md`. A body with no row is drawn from numbers and has no picture to credit.
|
|
14
|
+
* The English of a CC BY 4.0 row is that table's credit column. Jupiter and Uranus keep the authors' own attribution sentences, including the spelling of the name.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { PICTURE_CREDITS } from "@johnmorrisdotca/wakusei-planets";
|
|
19
|
+
*
|
|
20
|
+
* console.log(PICTURE_CREDITS.filter((row) => row.licence === "CC BY 4.0").map((row) => row.id).join(","));
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export const PICTURE_CREDITS = [
|
|
24
|
+
cc("mercury", "Shady Tex and Solar System Scope", "Shady TexとSolar System Scope", "Natural grey, resized to 512, 1024 and 2048. The normal map is not used.", "自然な灰色にし、512、1024、2048に縮小しました。法線マップは使っていません。"),
|
|
25
|
+
cc("venus", "Solar System Scope", "Solar System Scope", "Equirectangular surface map, resized to 512, 1024 and 2048.", "正距円筒図法の表面の地図を、512、1024、2048に縮小しました。"),
|
|
26
|
+
pd("mars", "NASA / Jet Propulsion Lab / USGS", "NASA / Jet Propulsion Lab / USGS"),
|
|
27
|
+
cc("jupiter", 'This work is based on "Jupiter" (https://sketchfab.com/3d-models/jupiter-6380860bdb4247b98b30643615c3afab) by Nestaeric (https://sketchfab.com/Nestaeric) licensed under CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/)', "Nestaeric(https://sketchfab.com/Nestaeric)による「Jupiter」(https://sketchfab.com/3d-models/jupiter-6380860bdb4247b98b30643615c3afab)をもとにしています。ライセンスは CC-BY-4.0(http://creativecommons.org/licenses/by/4.0/)です", "The band half of the texture, with the Great Red Spot and turbulent detail, resized to 512, 1024 and 2048.", "大赤斑と細かい乱れのある帯の半分を使い、512、1024、2048に縮小しました。"),
|
|
28
|
+
cc("saturn", "Solar System Scope; pole caps by Nestaeric", "Solar System Scope。極の冠はNestaeric", "The bands are Solar System Scope's map. The last 20 degrees at each pole are reprojected from Nestaeric's caps, and the north cap has the hexagon.", "縞はSolar System Scopeの地図です。両極の端の20度はNestaericの冠を張り直し、北の冠には六角形があります。", {
|
|
29
|
+
en: "Rings: NASA / JPL / Space Science Institute (public domain).",
|
|
30
|
+
ja: "環:NASA / JPL / Space Science Institute(パブリックドメイン)。",
|
|
31
|
+
}),
|
|
32
|
+
cc("uranus", 'This work is based on "Uranus" (https://sketchfab.com/3d-models/uranus-0009a69dbace44608c0bd09af9ba20db) by NestaEric (https://sketchfab.com/Nestaeric) licensed under CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/)', "NestaEric(https://sketchfab.com/Nestaeric)による「Uranus」(https://sketchfab.com/3d-models/uranus-0009a69dbace44608c0bd09af9ba20db)をもとにしています。ライセンスは CC-BY-4.0(http://creativecommons.org/licenses/by/4.0/)です", "The band half of the texture, which has a bright spot, resized to 512, 1024 and 2048.", "明るい斑のある帯の半分を使い、512、1024、2048に縮小しました。"),
|
|
33
|
+
cc("neptune", "Solar System Scope", "Solar System Scope", "Equirectangular map, resized to 512, 1024 and 2048.", "正距円筒図法の地図を、512、1024、2048に縮小しました。"),
|
|
34
|
+
pd("pluto", "NASA / Johns Hopkins University Applied Physics Laboratory / Southwest Research Institute", "NASA / Johns Hopkins University Applied Physics Laboratory / Southwest Research Institute"),
|
|
35
|
+
cc("sun", "Solar System Scope", "Solar System Scope", "Equirectangular map, resized to 512, 1024 and 2048.", "正距円筒図法の地図を、512、1024、2048に縮小しました。"),
|
|
36
|
+
pd("moon", "NASA's Scientific Visualization Studio (Ernie Wright, Noah Petro); Lunar Reconnaissance Orbiter Camera", "NASA Scientific Visualization Studio(Ernie Wright、Noah Petro)、Lunar Reconnaissance Orbiter Camera"),
|
|
37
|
+
pd("io", "NASA / JPL (Galileo SSI and Voyager images); the file page names no author", "NASA / JPL(Galileo SSIとVoyagerの画像)。ファイルのページに作者の名はありません"),
|
|
38
|
+
pd("europa", "U.S. Geological Survey / Planetary Data System / Tammy Becker", "U.S. Geological Survey / Planetary Data System / Tammy Becker"),
|
|
39
|
+
pd("ganymede", "USGS", "USGS"),
|
|
40
|
+
pd("callisto", "USGS", "USGS"),
|
|
41
|
+
pd("titan", "NASA / JPL / Space Science Institute", "NASA / JPL / Space Science Institute"),
|
|
42
|
+
pd("earth", "NASA Earth Observatory (Reto Stockli), Blue Marble", "NASA Earth Observatory(Reto Stockli)、Blue Marble"),
|
|
43
|
+
pd("rhea", "NASA/JPL-Caltech/Space Science Institute/Lunar and Planetary Institute", "NASA/JPL-Caltech/Space Science Institute/Lunar and Planetary Institute"),
|
|
44
|
+
pd("enceladus", "NASA/JPL-Caltech/Space Science Institute/Lunar and Planetary Institute", "NASA/JPL-Caltech/Space Science Institute/Lunar and Planetary Institute"),
|
|
45
|
+
pd("mimas", "NASA/JPL/Space Science Institute", "NASA/JPL/Space Science Institute"),
|
|
46
|
+
pd("ceres", "NASA/JPL-Caltech/UCLA/MPS/DLR/IDA", "NASA/JPL-Caltech/UCLA/MPS/DLR/IDA"),
|
|
47
|
+
pd("vesta", "NASA/JPL-Caltech/UCLA/MPS/DLR/IDA (as the file page gives it; hosted by the USGS Astrogeology Science Center's Gazetteer of Planetary Nomenclature)", "NASA/JPL-Caltech/UCLA/MPS/DLR/IDA(ファイルのページの表記。USGS Astrogeology Science CenterのGazetteer of Planetary Nomenclatureが公開)"),
|
|
48
|
+
pd("tethys", "NASA/JPL-Caltech/Space Science Institute/Lunar and Planetary Institute", "NASA/JPL-Caltech/Space Science Institute/Lunar and Planetary Institute"),
|
|
49
|
+
pd("dione", "NASA/JPL-Caltech/Space Science Institute/Lunar and Planetary Institute", "NASA/JPL-Caltech/Space Science Institute/Lunar and Planetary Institute"),
|
|
50
|
+
pd("iapetus", "NASA/JPL-Caltech/Space Science Institute/Lunar and Planetary Institute", "NASA/JPL-Caltech/Space Science Institute/Lunar and Planetary Institute"),
|
|
51
|
+
pd("triton", "NASA/JPL-Caltech/Lunar & Planetary Institute (Paul Schenk; Voyager 2 images)", "NASA/JPL-Caltech/Lunar & Planetary Institute(Paul Schenk、Voyager 2の画像)"),
|
|
52
|
+
pd("charon", "NASA/Johns Hopkins University Applied Physics Laboratory/Southwest Research Institute (via the IAU)", "NASA/Johns Hopkins University Applied Physics Laboratory/Southwest Research Institute(IAU経由)"),
|
|
53
|
+
];
|
|
54
|
+
const BY_ID = new Map(PICTURE_CREDITS.map((row) => [row.id, row]));
|
|
55
|
+
/**
|
|
56
|
+
* The credit for Mercury's finer map tiles. Their detail is a public-domain map, and their colour is the 2048 picture, which is CC BY 4.0, so the tiles carry that credit too.
|
|
57
|
+
* The words are the Mercury row of `NOTICE.md`'s "Finer map tiles" table.
|
|
58
|
+
*
|
|
59
|
+
* @param lang - `en` or `ja`.
|
|
60
|
+
* @returns The one sentence.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* import { mercuryTilesCredit } from "@johnmorrisdotca/wakusei-planets";
|
|
65
|
+
*
|
|
66
|
+
* console.log(mercuryTilesCredit("en").includes("CC BY 4.0"));
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export function mercuryTilesCredit(lang) {
|
|
70
|
+
return lang === "ja"
|
|
71
|
+
? "水星の細かい地図のタイルの色は、2048の絵(Solar System Scopeの地図、CC BY 4.0)の色です。タイルもその出典を持ちます。"
|
|
72
|
+
: "The colour of Mercury's finer map tiles is the 2048 picture's (Solar System Scope's map, CC BY 4.0), so these tiles carry that credit too.";
|
|
73
|
+
}
|
|
74
|
+
const phrase = (row, lang) => {
|
|
75
|
+
const name = BODIES[row.id].name[lang];
|
|
76
|
+
if (lang === "ja") {
|
|
77
|
+
const licence = row.licence === "CC BY 4.0" ? "CC BY 4.0" : "パブリックドメイン";
|
|
78
|
+
const changes = row.changes === undefined ? "" : `変更:${row.changes.ja}`;
|
|
79
|
+
const also = row.also === undefined ? "" : row.also.ja;
|
|
80
|
+
return `${name}:${row.credit.ja}(${licence})。${changes}${also}`;
|
|
81
|
+
}
|
|
82
|
+
const licence = row.licence === "CC BY 4.0" ? "CC BY 4.0" : "public domain";
|
|
83
|
+
const changes = row.changes === undefined ? "" : ` Changes made: ${row.changes.en}`;
|
|
84
|
+
const also = row.also === undefined ? "" : ` ${row.also.en}`;
|
|
85
|
+
return `${name}: ${row.credit.en} (${licence}).${changes}${also}`;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* The credit line for the surface pictures of the named bodies, in one language. A name is a body id in any case (`Jupiter`, `moon`). A body with no picture is left out.
|
|
89
|
+
* Only the named bodies are credited: Jupiter names Nestaeric and CC BY 4.0, and the Moon and Mars, whose maps are public domain, name no CC BY 4.0 source.
|
|
90
|
+
* An empty list, or a list of bodies with no pictures, is an empty string.
|
|
91
|
+
*
|
|
92
|
+
* @param bodies - The bodies a page is showing.
|
|
93
|
+
* @param lang - `en` or `ja`.
|
|
94
|
+
* @returns The line, or `""` when none of the bodies has a picture.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* import { picturesCredit } from "@johnmorrisdotca/wakusei-planets";
|
|
99
|
+
*
|
|
100
|
+
* console.log(picturesCredit(["Jupiter"], "en").includes("Nestaeric"));
|
|
101
|
+
* console.log(picturesCredit(["Moon", "Mars"], "en").includes("CC BY") === false);
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export function picturesCredit(bodies, lang) {
|
|
105
|
+
const seen = new Set();
|
|
106
|
+
const rows = [];
|
|
107
|
+
for (const name of bodies) {
|
|
108
|
+
const id = name.toLowerCase();
|
|
109
|
+
if (seen.has(id))
|
|
110
|
+
continue;
|
|
111
|
+
seen.add(id);
|
|
112
|
+
const row = BY_ID.get(id);
|
|
113
|
+
if (row !== undefined)
|
|
114
|
+
rows.push(row);
|
|
115
|
+
}
|
|
116
|
+
if (rows.length === 0)
|
|
117
|
+
return "";
|
|
118
|
+
const head = lang === "ja" ? "表面の地図:" : "Surface pictures: ";
|
|
119
|
+
return head + rows.map((row) => phrase(row, lang)).join(lang === "ja" ? "" : " ");
|
|
120
|
+
}
|
package/dist/scene/painter.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { moonOffset, orientation } from "./orient.ts";
|
|
|
8
8
|
import { type NameLabelOptions } from "./name-label.ts";
|
|
9
9
|
export { moonOffset, orientation };
|
|
10
10
|
export { nameLabelText, readNameLabel, setBodyLabelFontUrl, type NameLabelOptions } from "./name-label.ts";
|
|
11
|
+
export { mercuryTilesCredit, PICTURE_CREDITS, picturesCredit, type PictureCredit } from "../picture-credits.ts";
|
|
11
12
|
/**
|
|
12
13
|
* The looks the painter draws: `realistic` (shaded from the body's real colours and features) and `painted` (a public-domain surface map, with the shaded look until it arrives).
|
|
13
14
|
*
|
|
@@ -201,6 +202,16 @@ export interface PainterOptions {
|
|
|
201
202
|
export interface WakuseiPainter {
|
|
202
203
|
/** The looks `make` takes in `context.look`. */
|
|
203
204
|
readonly looks: readonly PainterLook[];
|
|
205
|
+
/**
|
|
206
|
+
* The credit for the pictures this painter is drawing, in English and Japanese, written from `PICTURE_CREDITS` and from `OWN_SOURCES`.
|
|
207
|
+
* Until `make` has been called it names every surface picture the painter can draw, because it does not yet know which a page will show. After `make` it names only the bodies it has made in a look that draws the map
|
|
208
|
+
* (`painted`, or a body whose look is mapped). A shaded body with no map is left out, so the Moon and Mars name no CC BY 4.0 source. While a window of finer map tiles is on a body, the `wakusei-tiles` credit is added;
|
|
209
|
+
* Mercury's tiles also say that their colour is the CC BY 4.0 map.
|
|
210
|
+
*/
|
|
211
|
+
readonly credit: {
|
|
212
|
+
readonly en: string;
|
|
213
|
+
readonly ja: string;
|
|
214
|
+
};
|
|
204
215
|
/** Make a body: `Sun`, a planet, `Pluto` or a moon, in any case. Throws for a name it does not know. */
|
|
205
216
|
/** `three` is the three.js module (or a subset of it holding the parts `PainterThree` names); it is typed loosely so that another package can hand over its own subset. */
|
|
206
217
|
make(three: object, name: string, context?: PaintContext): Painting;
|
package/dist/scene/painter.js
CHANGED
|
@@ -3,6 +3,8 @@ import { BODIES, MOONS_OF } from "../facts.js";
|
|
|
3
3
|
import { writeBasis } from "./basis.js";
|
|
4
4
|
import { TEXTURE_BASE, TEXTURE_FAR_BASE, TILES_BASE, slash, loadImage, mapSourceFor, tilesAllowed } from "./textures.js";
|
|
5
5
|
import { createSourceBook } from "../door/book.js";
|
|
6
|
+
import { OWN_BY_ID } from "../door/own.js";
|
|
7
|
+
import { mercuryTilesCredit, PICTURE_CREDITS, picturesCredit } from "../picture-credits.js";
|
|
6
8
|
import { cross } from "../vec.js";
|
|
7
9
|
import { bodyFragment, GLOW_FRAGMENT, GLOW_VERTEX, PAINTED_SURFACE, PAINTED_SURFACE_WINDOWED, RING_FRAGMENT_WORLD, RING_VERTEX_WORLD, VERTEX_WORLD } from "./glsl.js";
|
|
8
10
|
import { fallbackLook } from "./fallback.js";
|
|
@@ -14,6 +16,7 @@ import { ringStrip } from "./rings.js";
|
|
|
14
16
|
import { createNameLabel, nameLabelText } from "./name-label.js";
|
|
15
17
|
export { moonOffset, orientation };
|
|
16
18
|
export { nameLabelText, readNameLabel, setBodyLabelFontUrl } from "./name-label.js";
|
|
19
|
+
export { mercuryTilesCredit, PICTURE_CREDITS, picturesCredit } from "../picture-credits.js";
|
|
17
20
|
/**
|
|
18
21
|
* The looks the painter draws: `realistic` (shaded from the body's real colours and features) and `painted` (a public-domain surface map, with the shaded look until it arrives).
|
|
19
22
|
*
|
|
@@ -92,7 +95,7 @@ function sightOf(T, view) {
|
|
|
92
95
|
},
|
|
93
96
|
};
|
|
94
97
|
}
|
|
95
|
-
function paint(T, id, context, bases) {
|
|
98
|
+
function paint(T, id, context, bases, hold) {
|
|
96
99
|
const facts = BODIES[id];
|
|
97
100
|
const look = lookOf(id) ?? fallbackLook(facts);
|
|
98
101
|
const wantPainted = (context.look === "painted" || look.mapped === true || context.mapped === true) && look.painted !== undefined;
|
|
@@ -373,6 +376,7 @@ function paint(T, id, context, bases) {
|
|
|
373
376
|
};
|
|
374
377
|
if (context.label)
|
|
375
378
|
setLabel(context.label);
|
|
379
|
+
const drop = hold?.({ id, picture: wantPainted, tiles: () => detail?.stats.shown != null });
|
|
376
380
|
return {
|
|
377
381
|
object: group,
|
|
378
382
|
setLabel,
|
|
@@ -433,6 +437,7 @@ function paint(T, id, context, bases) {
|
|
|
433
437
|
},
|
|
434
438
|
dispose() {
|
|
435
439
|
gone = true;
|
|
440
|
+
drop?.();
|
|
436
441
|
setLabel(null);
|
|
437
442
|
if (windowUniforms !== undefined) {
|
|
438
443
|
windowUniforms.uDetailOn.value = 0;
|
|
@@ -471,9 +476,32 @@ export function createPainter(options = {}) {
|
|
|
471
476
|
const own = options.tiles;
|
|
472
477
|
const tiles = own === "off" || own === "none" || own === "" ? undefined : own !== undefined ? slash(own) : options.textureBase !== undefined ? undefined : TILES_BASE;
|
|
473
478
|
const book = options.book ?? createSourceBook({ kinds: ["tiles"] });
|
|
479
|
+
let made = false;
|
|
480
|
+
const live = new Set();
|
|
481
|
+
const creditLine = (lang) => {
|
|
482
|
+
const ids = made ? [...live].filter((body) => body.picture).map((body) => body.id) : PICTURE_CREDITS.map((row) => row.id);
|
|
483
|
+
const parts = [picturesCredit(ids, lang)];
|
|
484
|
+
const tiled = [...live].filter((body) => body.tiles());
|
|
485
|
+
if (tiled.length > 0) {
|
|
486
|
+
parts.push(OWN_BY_ID.get("wakusei-tiles").credit[lang]);
|
|
487
|
+
if (tiled.some((body) => body.id === "mercury"))
|
|
488
|
+
parts.push(mercuryTilesCredit(lang));
|
|
489
|
+
}
|
|
490
|
+
return parts.filter((part) => part !== "").join(" ");
|
|
491
|
+
};
|
|
474
492
|
return {
|
|
475
493
|
looks: LOOKS,
|
|
476
|
-
|
|
494
|
+
get credit() {
|
|
495
|
+
return { en: creditLine("en"), ja: creditLine("ja") };
|
|
496
|
+
},
|
|
497
|
+
make: (three, name, context = {}) => {
|
|
498
|
+
const id = idOf(name);
|
|
499
|
+
made = true;
|
|
500
|
+
return paint(three, id, context, { near, far, tiles, book, shared: options.book !== undefined }, (body) => {
|
|
501
|
+
live.add(body);
|
|
502
|
+
return () => live.delete(body);
|
|
503
|
+
});
|
|
504
|
+
},
|
|
477
505
|
moons(planet, ms) {
|
|
478
506
|
const radius = BODIES[idOf(planet)]?.radiusKm;
|
|
479
507
|
if (radius === undefined)
|
package/dist/scene/textures.d.ts
CHANGED
|
@@ -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.
|
|
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.
|
|
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.
|