@johnmorrisdotca/wakusei-planets 0.41.0 → 0.43.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 +14 -0
- package/README.md +3 -3
- package/dist/scene/textures.d.ts +2 -2
- package/dist/space/element.d.ts +28 -3
- package/dist/space/element.js +156 -20
- package/dist/space/index.d.ts +2 -2
- package/dist/space/index.js +2 -2
- package/dist/space/scale.d.ts +27 -0
- package/dist/space/scale.js +49 -0
- package/dist/space/scene.d.ts +45 -1
- package/dist/space/scene.js +103 -3
- package/dist/space/travel.d.ts +55 -4
- package/dist/space/travel.js +105 -16
- package/dist/spacecraft-facts.d.ts +11 -5
- package/dist/spacecraft-facts.js +20 -3
- package/dist/spacecraft.d.ts +15 -1
- package/dist/spacecraft.js +50 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/space/scene.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ import "../bodies/all.ts";
|
|
|
10
10
|
import { type Vec3 } from "../vec.ts";
|
|
11
11
|
import { type OrbitArrow } from "./arrows.ts";
|
|
12
12
|
import type { SightInput } from "./sight.ts";
|
|
13
|
-
import { type SpaceFrame, type SpaceVec3 } from "./frame.ts";
|
|
13
|
+
import { type SpaceDwarf, type SpaceFrame, type SpacePlanet, type SpaceVec3 } from "./frame.ts";
|
|
14
14
|
import { type PaintSpec, type PaintTrail } from "../paint/trail.ts";
|
|
15
15
|
import { type RideLook } from "./ride.ts";
|
|
16
16
|
import { type ScaleMode } from "./scale.ts";
|
|
@@ -166,6 +166,15 @@ export interface SpaceModel {
|
|
|
166
166
|
speed: number;
|
|
167
167
|
/** The body the camera looks at, and (in `zoom`) fills the view with at 1x: any body the package knows that the view can place (the eleven of `SPACE_BODIES` and the moons of the planets). */
|
|
168
168
|
focus: BodyId;
|
|
169
|
+
/** The body kept in the picture beside the one arrived at, or null. Its name is not dropped for a clash. */
|
|
170
|
+
companion: string | null;
|
|
171
|
+
/** How many times larger than life the squeezed view draws moons. Ignored at true distances. 2 by default. */
|
|
172
|
+
moonSize: number;
|
|
173
|
+
/** The factor actually used for the system in the middle, and whether a limit cut the one asked for. */
|
|
174
|
+
moonDrawn: {
|
|
175
|
+
factor: number;
|
|
176
|
+
clamped: boolean;
|
|
177
|
+
};
|
|
169
178
|
light: SpaceLight;
|
|
170
179
|
/** How the painter draws the bodies (`realistic` or `painted`). */
|
|
171
180
|
look: string;
|
|
@@ -232,6 +241,21 @@ export interface SpaceModel {
|
|
|
232
241
|
position: [number, number, number] | null;
|
|
233
242
|
radiusPx: number;
|
|
234
243
|
};
|
|
244
|
+
/** Places of the deep-space craft for this frame, or null when they are off. `au` is null when the date is outside that craft's record. */
|
|
245
|
+
/** Off, every craft, or the ids asked for. */
|
|
246
|
+
craftShow: null | "all" | readonly string[];
|
|
247
|
+
craftIds: readonly string[];
|
|
248
|
+
craftNames: ((id: string, lang: "en" | "ja") => string) | null;
|
|
249
|
+
craftPlaces: ((ms: number) => {
|
|
250
|
+
id: string;
|
|
251
|
+
au: [number, number, number] | null;
|
|
252
|
+
}[]) | null;
|
|
253
|
+
/** What the last draw did with those craft. */
|
|
254
|
+
craftDrawn: {
|
|
255
|
+
count: number;
|
|
256
|
+
status: Record<string, "drawn" | "outside">;
|
|
257
|
+
drawn: string[];
|
|
258
|
+
};
|
|
235
259
|
/** The name written on each body's globe, or null for none; `labelVersion` goes up whenever it (or the language) changes, so each body is told once. */
|
|
236
260
|
label: PaintLabel | null;
|
|
237
261
|
labelVersion: number;
|
|
@@ -436,4 +460,24 @@ export interface SpaceDeps {
|
|
|
436
460
|
/** The painter could not make a body (the three.js parts handed over lack something it needs). */
|
|
437
461
|
onPainterError?: (error: unknown) => void;
|
|
438
462
|
}
|
|
463
|
+
/**
|
|
464
|
+
* The factor the squeezed view draws the moons of one planet at (1 at true distances), worked out from the planet's moons as the drawing does, so a camera that frames a moon frames the size it is drawn.
|
|
465
|
+
*
|
|
466
|
+
* @param mode - The scale.
|
|
467
|
+
* @param host - The planet or dwarf planet the moons go round.
|
|
468
|
+
* @param size - The `moon-size` asked for.
|
|
469
|
+
* @param time - The moment, in milliseconds, that sets where the moons are.
|
|
470
|
+
* @returns The factor used, and whether a limit cut it.
|
|
471
|
+
*
|
|
472
|
+
* @example
|
|
473
|
+
* ```ts no-run
|
|
474
|
+
* import { moonScaleFor } from "@johnmorrisdotca/wakusei-planets/space/element";
|
|
475
|
+
*
|
|
476
|
+
* console.log(moonScaleFor("compressed", "jupiter", 4, Date.UTC(2026, 10, 11)).factor);
|
|
477
|
+
* ```
|
|
478
|
+
*/
|
|
479
|
+
export declare function moonScaleFor(mode: ScaleMode, host: SpacePlanet | SpaceDwarf, size: number, time: number): {
|
|
480
|
+
factor: number;
|
|
481
|
+
clamped: boolean;
|
|
482
|
+
};
|
|
439
483
|
export declare function createSpaceItem(model: SpaceModel, deps: SpaceDeps): Item3D<ThreeParts>;
|
package/dist/space/scene.js
CHANGED
|
@@ -18,7 +18,7 @@ import { createPaintOverlay } from "./paint-overlay.js";
|
|
|
18
18
|
import { createPaintTrail, groundUnder, paintMinute } from "../paint/trail.js";
|
|
19
19
|
import { BALL_FRAGMENT, VERTEX } from "../scene/glsl.js";
|
|
20
20
|
import { ridePose } from "./ride.js";
|
|
21
|
-
import { moonDistance, orbitLine, placeAround, placeBodies, placeMoon, radiusIn } from "./scale.js";
|
|
21
|
+
import { moonDistance, moonSizeFactor, orbitLine, placeAround, placeBodies, placeMoon, radiusIn } from "./scale.js";
|
|
22
22
|
import { regionOrbits, regionView } from "./regions.js";
|
|
23
23
|
import { travelPlan, travelPose } from "./travel.js";
|
|
24
24
|
const RAD = Math.PI / 180;
|
|
@@ -83,6 +83,9 @@ export const newSpaceModel = () => ({
|
|
|
83
83
|
stepMs: 1000,
|
|
84
84
|
speed: 1,
|
|
85
85
|
focus: "earth",
|
|
86
|
+
companion: null,
|
|
87
|
+
moonSize: 2,
|
|
88
|
+
moonDrawn: { factor: 1, clamped: false },
|
|
86
89
|
light: "sun",
|
|
87
90
|
look: "realistic",
|
|
88
91
|
drawn: null,
|
|
@@ -105,6 +108,11 @@ export const newSpaceModel = () => ({
|
|
|
105
108
|
roadster: false,
|
|
106
109
|
roadsterPath: null,
|
|
107
110
|
roadsterDrawn: { shown: false, position: null, radiusPx: 0 },
|
|
111
|
+
craftShow: null,
|
|
112
|
+
craftIds: [],
|
|
113
|
+
craftNames: null,
|
|
114
|
+
craftPlaces: null,
|
|
115
|
+
craftDrawn: { count: 0, status: {}, drawn: [] },
|
|
108
116
|
label: null,
|
|
109
117
|
labelVersion: 0,
|
|
110
118
|
labelsDrawn: { count: 0, focus: null },
|
|
@@ -128,6 +136,29 @@ export const newSpaceModel = () => ({
|
|
|
128
136
|
ratio: () => Math.min(globalThis.devicePixelRatio || 1, 2),
|
|
129
137
|
});
|
|
130
138
|
const minus = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
139
|
+
/**
|
|
140
|
+
* The factor the squeezed view draws the moons of one planet at (1 at true distances), worked out from the planet's moons as the drawing does, so a camera that frames a moon frames the size it is drawn.
|
|
141
|
+
*
|
|
142
|
+
* @param mode - The scale.
|
|
143
|
+
* @param host - The planet or dwarf planet the moons go round.
|
|
144
|
+
* @param size - The `moon-size` asked for.
|
|
145
|
+
* @param time - The moment, in milliseconds, that sets where the moons are.
|
|
146
|
+
* @returns The factor used, and whether a limit cut it.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts no-run
|
|
150
|
+
* import { moonScaleFor } from "@johnmorrisdotca/wakusei-planets/space/element";
|
|
151
|
+
*
|
|
152
|
+
* console.log(moonScaleFor("compressed", "jupiter", 4, Date.UTC(2026, 10, 11)).factor);
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
export function moonScaleFor(mode, host, size, time) {
|
|
156
|
+
const moons = (MOONS_OF[host] ?? []).map((moon) => {
|
|
157
|
+
const offset = moonOffset(moon, time);
|
|
158
|
+
return { radius: BODIES[moon].radiusKm / BODIES[host].radiusKm, orbit: moonDistance(mode, host, Math.hypot(offset[0], offset[1], offset[2])) };
|
|
159
|
+
});
|
|
160
|
+
return moonSizeFactor(mode, host, size, moons);
|
|
161
|
+
}
|
|
131
162
|
/** How far a place is from the nearest point of a line through `points`, in the line's units. */
|
|
132
163
|
const plus = (a, b) => [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
|
|
133
164
|
function distanceToLine(place, points) {
|
|
@@ -292,6 +323,20 @@ export function createSpaceItem(model, deps) {
|
|
|
292
323
|
roadsterLine.visible = false;
|
|
293
324
|
roadsterLine.frustumCulled = false;
|
|
294
325
|
scene.add(roadsterLine);
|
|
326
|
+
const CRAFT_DOTS = 19;
|
|
327
|
+
const craftPositions = new Float32Array(CRAFT_DOTS * 3);
|
|
328
|
+
const craftGeometry = new three.BufferGeometry();
|
|
329
|
+
const craftAttribute = new three.BufferAttribute(craftPositions, 3);
|
|
330
|
+
craftGeometry.setAttribute("position", craftAttribute);
|
|
331
|
+
craftGeometry.setDrawRange(0, 0);
|
|
332
|
+
const CraftPoints = three;
|
|
333
|
+
const craftMaterial = typeof CraftPoints.PointsMaterial === "function" ? new CraftPoints.PointsMaterial({ color: 0x9fd0ff, size: 4, sizeAttenuation: false, depthWrite: false }) : null;
|
|
334
|
+
const craftPoints = craftMaterial !== null && typeof CraftPoints.Points === "function" ? new CraftPoints.Points(craftGeometry, craftMaterial) : null;
|
|
335
|
+
if (craftPoints !== null) {
|
|
336
|
+
craftPoints.frustumCulled = false;
|
|
337
|
+
craftPoints.visible = false;
|
|
338
|
+
scene.add(craftPoints);
|
|
339
|
+
}
|
|
295
340
|
const roadsterOrbit = { samples: [], epoch: Number.NaN };
|
|
296
341
|
const orbiterDrawings = new Map();
|
|
297
342
|
const orbiterGeometry = new three.SphereGeometry(1, 16, 8);
|
|
@@ -391,7 +436,8 @@ export function createSpaceItem(model, deps) {
|
|
|
391
436
|
const offset = moonSite(focus, model.time, host);
|
|
392
437
|
const hostRadius = radiusOf(host);
|
|
393
438
|
focusPos = [pos[host][0] + offset[0] * hostRadius, pos[host][1] + offset[1] * hostRadius, pos[host][2] + offset[2] * hostRadius];
|
|
394
|
-
|
|
439
|
+
// a moon the view draws larger than life is framed at the size it is drawn
|
|
440
|
+
focusRadius = Math.max(1e-9, (BODIES[focus].radiusKm / BODIES[host].radiusKm) * hostRadius * moonScaleFor(mode, host, model.moonSize, model.time).factor);
|
|
395
441
|
}
|
|
396
442
|
let aimWay = 1;
|
|
397
443
|
let besideIn = null;
|
|
@@ -826,6 +872,42 @@ export function createSpaceItem(model, deps) {
|
|
|
826
872
|
roadsterMesh.visible = false;
|
|
827
873
|
roadsterLine.visible = false;
|
|
828
874
|
}
|
|
875
|
+
// the deep-space craft: one points draw, a dot each, no path line. A date outside a craft's record draws nothing for it.
|
|
876
|
+
const craftAts = [];
|
|
877
|
+
const craftStatus = {};
|
|
878
|
+
const craftDrawn = [];
|
|
879
|
+
const craftList = model.craftPlaces?.(model.time) ?? [];
|
|
880
|
+
if (craftPoints !== null) {
|
|
881
|
+
let n = 0;
|
|
882
|
+
for (const craft of craftList) {
|
|
883
|
+
// the Roadster has its own drawing when `roadster` is on: it is not drawn twice
|
|
884
|
+
if (craft.id === "roadster" && model.roadster)
|
|
885
|
+
continue;
|
|
886
|
+
if (craft.au === null) {
|
|
887
|
+
craftStatus[craft.id] = "outside";
|
|
888
|
+
continue;
|
|
889
|
+
}
|
|
890
|
+
if (n >= CRAFT_DOTS)
|
|
891
|
+
break;
|
|
892
|
+
const at = placeAround(mode, sunPos, eclipticToScene(craft.au));
|
|
893
|
+
craftPositions[n * 3] = at[0];
|
|
894
|
+
craftPositions[n * 3 + 1] = at[1];
|
|
895
|
+
craftPositions[n * 3 + 2] = at[2];
|
|
896
|
+
const away = Math.hypot(at[0] - camera.position.x, at[1] - camera.position.y, at[2] - camera.position.z);
|
|
897
|
+
const drawn = (away * half * 4) / (size.height / 2);
|
|
898
|
+
const dotPx = away <= drawn ? 1e5 : ((size.height / 2) * (drawn / Math.sqrt(Math.max(away * away - drawn * drawn, 1e-12)))) / half;
|
|
899
|
+
craftAts.push({ id: craft.id, at, px: dotPx });
|
|
900
|
+
craftStatus[craft.id] = "drawn";
|
|
901
|
+
craftDrawn.push(craft.id);
|
|
902
|
+
n += 1;
|
|
903
|
+
}
|
|
904
|
+
craftAttribute.needsUpdate = true;
|
|
905
|
+
craftGeometry.setDrawRange(0, n);
|
|
906
|
+
craftPoints.visible = n > 0;
|
|
907
|
+
model.craftDrawn = { count: n, status: craftStatus, drawn: craftDrawn };
|
|
908
|
+
}
|
|
909
|
+
else
|
|
910
|
+
model.craftDrawn = { count: 0, status: craftStatus, drawn: [] };
|
|
829
911
|
// 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
|
|
830
912
|
const orbiterSet = model.orbiters ? model.orbiterSet : null;
|
|
831
913
|
const orbiterPlaces = {};
|
|
@@ -1020,6 +1102,9 @@ export function createSpaceItem(model, deps) {
|
|
|
1020
1102
|
if (!planet)
|
|
1021
1103
|
continue;
|
|
1022
1104
|
const sites = (MOONS_OF[id] ?? []).map((moon) => ({ name: moon, offset: moonOffset(moon, model.time), radius: BODIES[moon].radiusKm / BODIES[id].radiusKm }));
|
|
1105
|
+
const sized = moonSizeFactor(mode, id, model.moonSize, sites.map((site) => ({ radius: site.radius, orbit: moonDistance(mode, id, Math.hypot(site.offset[0], site.offset[1], site.offset[2])) })));
|
|
1106
|
+
if (id === model.focus || hostOf(model.focus) === id)
|
|
1107
|
+
model.moonDrawn = { factor: sized.factor, clamped: sized.clamped };
|
|
1023
1108
|
// the moons are shown once the planet is a few pixels across, or the system round it is wide enough on the screen to tell its moons from the planet, or one of its moons is the body looked at
|
|
1024
1109
|
let spread = 1;
|
|
1025
1110
|
for (const site of sites)
|
|
@@ -1048,7 +1133,12 @@ export function createSpaceItem(model, deps) {
|
|
|
1048
1133
|
if (!drawing)
|
|
1049
1134
|
continue;
|
|
1050
1135
|
const away = Math.hypot(at[0] - camera.position.x, at[1] - camera.position.y, at[2] - camera.position.z);
|
|
1051
|
-
const
|
|
1136
|
+
const floor = (away * half * MOON_MIN_PX) / (size.height / 2);
|
|
1137
|
+
const wanted = Math.max(site.radius * radius, floor) * sized.factor;
|
|
1138
|
+
const cap = 0.25 * radius;
|
|
1139
|
+
const drawn = Math.min(wanted, cap);
|
|
1140
|
+
if (drawn + 1e-4 < wanted && (id === model.focus || hostOf(model.focus) === id))
|
|
1141
|
+
model.moonDrawn = { factor: sized.factor, clamped: true };
|
|
1052
1142
|
drawing.object.visible = true;
|
|
1053
1143
|
drawing.object.position.set(at[0], at[1], at[2]);
|
|
1054
1144
|
drawing.object.scale.setScalar(drawn);
|
|
@@ -1134,6 +1224,12 @@ export function createSpaceItem(model, deps) {
|
|
|
1134
1224
|
if (spot)
|
|
1135
1225
|
moonDistances["roadster"] = Math.hypot(roadsterAt[0] - camera.position.x, roadsterAt[1] - camera.position.y, roadsterAt[2] - camera.position.z);
|
|
1136
1226
|
}
|
|
1227
|
+
for (const craft of craftAts) {
|
|
1228
|
+
const spot = labelFor(craft.at);
|
|
1229
|
+
places[craft.id] = spot ? { x: spot.x, y: spot.y, r: craft.px } : null;
|
|
1230
|
+
if (spot)
|
|
1231
|
+
moonDistances[craft.id] = Math.hypot(craft.at[0] - camera.position.x, craft.at[1] - camera.position.y, craft.at[2] - camera.position.z);
|
|
1232
|
+
}
|
|
1137
1233
|
// a body behind another: its place is inside a nearer body's disc
|
|
1138
1234
|
const entries = [];
|
|
1139
1235
|
for (const [id, at] of Object.entries(places)) {
|
|
@@ -1176,6 +1272,8 @@ export function createSpaceItem(model, deps) {
|
|
|
1176
1272
|
for (const id of moons)
|
|
1177
1273
|
if (id !== hiddenMoon && !SPACE_BODIES.includes(id))
|
|
1178
1274
|
sight(id, absoluteSite(id), moonPlaces[id]?.r ?? 0);
|
|
1275
|
+
for (const craft of craftAts)
|
|
1276
|
+
sight(craft.id, craft.at, craft.px);
|
|
1179
1277
|
projected.set(0, 0, -1).applyMatrix4(camera.projectionMatrix);
|
|
1180
1278
|
deps.onSight(sights, { width: size.width, height: size.height, axis: { x: ((projected.x + 1) / 2) * size.width, y: ((1 - projected.y) / 2) * size.height } });
|
|
1181
1279
|
}
|
|
@@ -1213,6 +1311,8 @@ export function createSpaceItem(model, deps) {
|
|
|
1213
1311
|
}
|
|
1214
1312
|
roadsterGeometry.dispose();
|
|
1215
1313
|
roadsterMaterial.dispose();
|
|
1314
|
+
craftGeometry.dispose();
|
|
1315
|
+
craftMaterial?.dispose();
|
|
1216
1316
|
for (const drawing of orbiterDrawings.values()) {
|
|
1217
1317
|
drawing.material.dispose();
|
|
1218
1318
|
drawing.line.geometry.dispose();
|
package/dist/space/travel.d.ts
CHANGED
|
@@ -226,13 +226,62 @@ export declare function travelPlan(input: TravelInput): TravelPlan;
|
|
|
226
226
|
* ```
|
|
227
227
|
*/
|
|
228
228
|
export declare function travelPose(input: TravelInput, t: number, plan?: TravelPlan): TravelSample;
|
|
229
|
+
/**
|
|
230
|
+
* One body that might keep an arrival from being an empty black picture: where it is, and which rule it belongs to.
|
|
231
|
+
* `1` is the body's own moon, or its planet when the body is a moon. `2` is the body the camera came from, or the nearest planet in that direction. `3` is the Sun.
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```ts
|
|
235
|
+
* import type { ArrivalCompanion } from "@johnmorrisdotca/wakusei-planets/space";
|
|
236
|
+
*
|
|
237
|
+
* const moon: ArrivalCompanion = { id: "io", at: [10, 0, 0], rank: 1 };
|
|
238
|
+
* console.log(moon.rank);
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
export interface ArrivalCompanion {
|
|
242
|
+
/** A name the page can put on the marker. Left out, the side is still chosen. */
|
|
243
|
+
id?: string;
|
|
244
|
+
at: Vec3;
|
|
245
|
+
rank: 1 | 2 | 3;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* The side of a body to stand on so a companion is in the picture, and the body stays at least half lit.
|
|
249
|
+
* Companions are tried in rank order (1, then 2, then 3). The first rank that fits wins; within a rank the side nearest the approach is kept.
|
|
250
|
+
* A side more than 90 degrees from the Sun is refused, so a lit globe is never traded for a black one. With no companion that fits, the side is the
|
|
251
|
+
* approach, swung toward the Sun when it would show less than about three fifths of the body lit (never more than 75 degrees off the Sun).
|
|
252
|
+
*
|
|
253
|
+
* @param input - The body, where the move comes from, the Sun, and the companions in rank order.
|
|
254
|
+
* @returns A unit side from the body toward the camera, how much of the disc is lit, and the companion's id (null when none was framed).
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* ```ts
|
|
258
|
+
* import { arrivalSide } from "@johnmorrisdotca/wakusei-planets/space";
|
|
259
|
+
*
|
|
260
|
+
* const side = arrivalSide({ body: [0, 0, 0], radius: 1, from: [0, 0, 20], sun: [0, 0, 100], companions: [{ id: "io", at: [8, 1, 0], rank: 1 }] });
|
|
261
|
+
* console.log(side.companion, side.lit >= 0.5);
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
264
|
+
export declare function arrivalSide(input: {
|
|
265
|
+
body: Vec3;
|
|
266
|
+
radius: number;
|
|
267
|
+
from: Vec3;
|
|
268
|
+
sun?: Vec3;
|
|
269
|
+
companions?: readonly ArrivalCompanion[];
|
|
270
|
+
fov?: number;
|
|
271
|
+
aspect?: number;
|
|
272
|
+
fit?: number;
|
|
273
|
+
}): {
|
|
274
|
+
side: Vec3;
|
|
275
|
+
lit: number;
|
|
276
|
+
companion: string | null;
|
|
277
|
+
};
|
|
229
278
|
/**
|
|
230
279
|
* 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),
|
|
232
|
-
* taller than wide), looking at the body with `north` up.
|
|
280
|
+
* 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), and further round, still at least half lit, when that puts a
|
|
281
|
+
* companion in the picture (`arrivalSide`). It stands at `fit` radii away (4.1, and as much again as a tall picture is taller than wide), looking at the body with `north` up.
|
|
233
282
|
*
|
|
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,
|
|
283
|
+
* @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, the companions to keep in the picture, and optionally `fov`, `fit` and `north`.
|
|
284
|
+
* @returns The view, `lit` (the share of the disc that is lit from there, 1 when no Sun is given), and `companion` (the id framed beside it, or null).
|
|
236
285
|
*
|
|
237
286
|
* @example
|
|
238
287
|
* ```ts
|
|
@@ -251,6 +300,8 @@ export declare function travelArrival(input: {
|
|
|
251
300
|
fov?: number;
|
|
252
301
|
fit?: number;
|
|
253
302
|
north?: Vec3;
|
|
303
|
+
companions?: readonly ArrivalCompanion[];
|
|
254
304
|
}): TravelView & {
|
|
255
305
|
lit: number;
|
|
306
|
+
companion: string | null;
|
|
256
307
|
};
|
package/dist/space/travel.js
CHANGED
|
@@ -561,13 +561,111 @@ export function travelPose(input, t, plan) {
|
|
|
561
561
|
sample.around = sightOf(input.around, time, view.position, o, frame);
|
|
562
562
|
return sample;
|
|
563
563
|
}
|
|
564
|
+
/**
|
|
565
|
+
* The side of a body to stand on so a companion is in the picture, and the body stays at least half lit.
|
|
566
|
+
* Companions are tried in rank order (1, then 2, then 3). The first rank that fits wins; within a rank the side nearest the approach is kept.
|
|
567
|
+
* A side more than 90 degrees from the Sun is refused, so a lit globe is never traded for a black one. With no companion that fits, the side is the
|
|
568
|
+
* approach, swung toward the Sun when it would show less than about three fifths of the body lit (never more than 75 degrees off the Sun).
|
|
569
|
+
*
|
|
570
|
+
* @param input - The body, where the move comes from, the Sun, and the companions in rank order.
|
|
571
|
+
* @returns A unit side from the body toward the camera, how much of the disc is lit, and the companion's id (null when none was framed).
|
|
572
|
+
*
|
|
573
|
+
* @example
|
|
574
|
+
* ```ts
|
|
575
|
+
* import { arrivalSide } from "@johnmorrisdotca/wakusei-planets/space";
|
|
576
|
+
*
|
|
577
|
+
* const side = arrivalSide({ body: [0, 0, 0], radius: 1, from: [0, 0, 20], sun: [0, 0, 100], companions: [{ id: "io", at: [8, 1, 0], rank: 1 }] });
|
|
578
|
+
* console.log(side.companion, side.lit >= 0.5);
|
|
579
|
+
* ```
|
|
580
|
+
*/
|
|
581
|
+
export function arrivalSide(input) {
|
|
582
|
+
let approach = sub(input.from, input.body);
|
|
583
|
+
approach = length(approach) < 1e-9 ? [0, 0, 1] : unit(approach);
|
|
584
|
+
const sunFar = input.sun ? sub(input.sun, input.body) : null;
|
|
585
|
+
const sunDir = sunFar && length(sunFar) > 1e-9 ? unit(sunFar) : null;
|
|
586
|
+
const litOf = (side) => (sunDir ? (1 + Math.cos(Math.min(Math.PI, angleOf(side, sunDir)))) / 2 : 1);
|
|
587
|
+
const swing = (side) => {
|
|
588
|
+
if (!sunDir)
|
|
589
|
+
return side;
|
|
590
|
+
const off = angleOf(side, sunDir);
|
|
591
|
+
const most = 75 * RAD;
|
|
592
|
+
return off > most ? arc(side, sunDir, (off - most) / off) : side;
|
|
593
|
+
};
|
|
594
|
+
const distance = Math.max(1e-6, input.radius) * (input.fit ?? 4.1) * Math.max(1, 1 / Math.max(1e-3, input.aspect ?? 1));
|
|
595
|
+
const fov = ((input.fov ?? 35) / 2) * RAD;
|
|
596
|
+
const tv = Math.tan(fov);
|
|
597
|
+
const aspect = Math.max(1e-3, input.aspect ?? 1);
|
|
598
|
+
const frames = (side, at) => {
|
|
599
|
+
const forward = scale(side, -1);
|
|
600
|
+
const north = sub([0, 1, 0], scale(forward, forward[1]));
|
|
601
|
+
const up = length(north) < 1e-6 ? squareTo(forward) : unit(north);
|
|
602
|
+
const camera = add(input.body, scale(side, distance));
|
|
603
|
+
const v = sub(at, camera);
|
|
604
|
+
const z = dot(v, forward);
|
|
605
|
+
if (!(z > 0))
|
|
606
|
+
return false;
|
|
607
|
+
if (Math.abs(dot(v, cross(forward, up))) > 0.92 * tv * aspect * z)
|
|
608
|
+
return false;
|
|
609
|
+
if (Math.abs(dot(v, up)) > 0.92 * tv * z)
|
|
610
|
+
return false;
|
|
611
|
+
const limb = Math.atan(input.radius / distance);
|
|
612
|
+
return angleOf(forward, unit(v)) > limb * 1.15;
|
|
613
|
+
};
|
|
614
|
+
const found = [];
|
|
615
|
+
const half = Math.PI / 2 + 1e-4;
|
|
616
|
+
const companions = input.companions ?? [];
|
|
617
|
+
const consider = (side) => {
|
|
618
|
+
const u = length(side) < 1e-9 ? approach : unit(side);
|
|
619
|
+
if (sunDir && angleOf(u, sunDir) > half)
|
|
620
|
+
return;
|
|
621
|
+
let rank = 99;
|
|
622
|
+
let id = null;
|
|
623
|
+
for (const companion of companions) {
|
|
624
|
+
if (companion.rank < rank && frames(u, companion.at)) {
|
|
625
|
+
rank = companion.rank;
|
|
626
|
+
id = companion.id ?? null;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
if (rank === 99)
|
|
630
|
+
return;
|
|
631
|
+
const near = angleOf(u, approach);
|
|
632
|
+
const top = found[0];
|
|
633
|
+
if (top === undefined || rank < top.rank || (rank === top.rank && near < top.near - 1e-6))
|
|
634
|
+
found[0] = { side: u, rank, near, id };
|
|
635
|
+
};
|
|
636
|
+
consider(approach);
|
|
637
|
+
for (const companion of companions) {
|
|
638
|
+
const away = sub(input.body, companion.at);
|
|
639
|
+
if (length(away) < 1e-6)
|
|
640
|
+
continue;
|
|
641
|
+
const u = unit(away);
|
|
642
|
+
const perp = Math.abs(u[1]) < 0.9 ? unit(cross(u, [0, 1, 0])) : unit(cross(u, [1, 0, 0]));
|
|
643
|
+
const perp2 = unit(cross(u, perp));
|
|
644
|
+
for (const deg of [8, 14, 22, 32, 48, 70]) {
|
|
645
|
+
const e = deg * RAD;
|
|
646
|
+
for (const axis of [perp, perp2]) {
|
|
647
|
+
consider(add(scale(u, Math.cos(e)), scale(axis, Math.sin(e))));
|
|
648
|
+
consider(add(scale(u, Math.cos(e)), scale(axis, -Math.sin(e))));
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
for (let lat = -75; lat <= 75; lat += 15) {
|
|
653
|
+
for (let lon = 0; lon < 360; lon += 15) {
|
|
654
|
+
const c = Math.cos(lat * RAD);
|
|
655
|
+
consider([c * Math.cos(lon * RAD), Math.sin(lat * RAD), c * Math.sin(lon * RAD)]);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
const picked = found[0];
|
|
659
|
+
const side = picked?.side ?? swing(approach);
|
|
660
|
+
return { side, lit: litOf(side), companion: picked?.id ?? null };
|
|
661
|
+
}
|
|
564
662
|
/**
|
|
565
663
|
* 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
|
|
566
|
-
* 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),
|
|
567
|
-
* taller than wide), looking at the body with `north` up.
|
|
664
|
+
* 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), and further round, still at least half lit, when that puts a
|
|
665
|
+
* companion in the picture (`arrivalSide`). It stands at `fit` radii away (4.1, and as much again as a tall picture is taller than wide), looking at the body with `north` up.
|
|
568
666
|
*
|
|
569
|
-
* @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`.
|
|
570
|
-
* @returns The view,
|
|
667
|
+
* @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, the companions to keep in the picture, and optionally `fov`, `fit` and `north`.
|
|
668
|
+
* @returns The view, `lit` (the share of the disc that is lit from there, 1 when no Sun is given), and `companion` (the id framed beside it, or null).
|
|
571
669
|
*
|
|
572
670
|
* @example
|
|
573
671
|
* ```ts
|
|
@@ -578,20 +676,11 @@ export function travelPose(input, t, plan) {
|
|
|
578
676
|
* ```
|
|
579
677
|
*/
|
|
580
678
|
export function travelArrival(input) {
|
|
581
|
-
|
|
582
|
-
side =
|
|
583
|
-
let lit = 1;
|
|
584
|
-
if (input.sun && length(sub(input.sun, input.body)) > 1e-12) {
|
|
585
|
-
const sun = unit(sub(input.sun, input.body));
|
|
586
|
-
const off = angleOf(side, sun);
|
|
587
|
-
const most = 75 * RAD;
|
|
588
|
-
if (off > most)
|
|
589
|
-
side = arc(side, sun, (off - most) / off);
|
|
590
|
-
lit = (1 + Math.cos(Math.min(off, most))) / 2;
|
|
591
|
-
}
|
|
679
|
+
const picked = arrivalSide(input);
|
|
680
|
+
const side = picked.side;
|
|
592
681
|
const distance = input.radius * (input.fit ?? 4.1) * Math.max(1, 1 / Math.max(1e-3, input.aspect));
|
|
593
682
|
const forward = scale(side, -1);
|
|
594
683
|
const north = input.north ?? [0, 1, 0];
|
|
595
684
|
const across = sub(north, scale(forward, dot(north, forward)));
|
|
596
|
-
return { position: add(input.body, scale(side, distance)), forward, up: length(across) < 1e-6 ? squareTo(forward) : unit(across), fov: input.fov ?? 35, lit };
|
|
685
|
+
return { position: add(input.body, scale(side, distance)), forward, up: length(across) < 1e-6 ? squareTo(forward) : unit(across), fov: input.fov ?? 35, lit: picked.lit, companion: picked.companion };
|
|
597
686
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PlanetId } from "./facts.ts";
|
|
2
2
|
/**
|
|
3
|
-
* The
|
|
3
|
+
* The nineteen craft: `voyager1`, `voyager2`, `newhorizons`, `pioneer10`, `pioneer11`, `cassini`, `galileo`, `juno`, `parker`, `webb`, `bepicolombo`, `psyche`, `europaclipper`, `lucy`, `juice`, `hayabusa2`, `osirisapex`, `solarorbiter` and `roadster` (Starman, the Tesla Roadster).
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
6
|
* ```ts
|
|
@@ -9,7 +9,7 @@ import type { PlanetId } from "./facts.ts";
|
|
|
9
9
|
* console.log(SPACECRAFT_IDS.join(", "));
|
|
10
10
|
* ```
|
|
11
11
|
*/
|
|
12
|
-
export declare const SPACECRAFT_IDS: readonly ["voyager1", "voyager2", "newhorizons", "pioneer10", "pioneer11", "cassini", "galileo", "juno", "parker", "webb", "bepicolombo", "psyche", "europaclipper", "lucy", "juice", "hayabusa2", "osirisapex", "solarorbiter"];
|
|
12
|
+
export declare const SPACECRAFT_IDS: readonly ["voyager1", "voyager2", "newhorizons", "pioneer10", "pioneer11", "cassini", "galileo", "juno", "parker", "webb", "bepicolombo", "psyche", "europaclipper", "lucy", "juice", "hayabusa2", "osirisapex", "solarorbiter", "roadster"];
|
|
13
13
|
/**
|
|
14
14
|
* The name of a craft: `voyager1`, `cassini`, `webb`...
|
|
15
15
|
*
|
|
@@ -34,8 +34,8 @@ export type SpacecraftId = (typeof SPACECRAFT_IDS)[number];
|
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
36
|
export interface SpacecraftEvent {
|
|
37
|
-
/** What happened: the launch, a flyby, going into orbit round a planet, getting to the place the craft works from,
|
|
38
|
-
kind: "launch" | "flyby" | "orbit-insertion" | "arrival" | "end";
|
|
37
|
+
/** What happened: the launch, a flyby, going into orbit round a planet, getting to the place the craft works from, the end of the mission, or (the Roadster) a perihelion or an aphelion. */
|
|
38
|
+
kind: "launch" | "flyby" | "orbit-insertion" | "arrival" | "end" | "perihelion" | "aphelion";
|
|
39
39
|
/** The moment, in milliseconds since 1970 (UTC). Where `precision` is "day", only the date is known: this is that day's noon. */
|
|
40
40
|
date: number;
|
|
41
41
|
/** "minute" where the page gives a time, "day" where it gives only a date. */
|
|
@@ -68,6 +68,12 @@ export interface SpacecraftFacts {
|
|
|
68
68
|
en: string;
|
|
69
69
|
ja: string;
|
|
70
70
|
};
|
|
71
|
+
/** Other names a search should find. Left off when the craft has none. */
|
|
72
|
+
otherNames?: readonly string[];
|
|
73
|
+
/**
|
|
74
|
+
* What sort of craft it is. Left off for a probe. `observatory` is a telescope that stays put (the James Webb Space Telescope). `other` is the Roadster: a car, not a probe.
|
|
75
|
+
*/
|
|
76
|
+
kind?: "probe" | "observatory" | "other";
|
|
71
77
|
/** The agency or agencies. */
|
|
72
78
|
agency: string;
|
|
73
79
|
/** The launch: when, from where and on what. */
|
|
@@ -102,7 +108,7 @@ export interface SpacecraftFacts {
|
|
|
102
108
|
events: readonly SpacecraftEvent[];
|
|
103
109
|
}
|
|
104
110
|
/**
|
|
105
|
-
* The
|
|
111
|
+
* The nineteen craft and their facts, keyed by id.
|
|
106
112
|
*
|
|
107
113
|
* @example
|
|
108
114
|
* ```ts
|
package/dist/spacecraft-facts.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
2
|
+
* The nineteen craft: `voyager1`, `voyager2`, `newhorizons`, `pioneer10`, `pioneer11`, `cassini`, `galileo`, `juno`, `parker`, `webb`, `bepicolombo`, `psyche`, `europaclipper`, `lucy`, `juice`, `hayabusa2`, `osirisapex`, `solarorbiter` and `roadster` (Starman, the Tesla Roadster).
|
|
3
3
|
*
|
|
4
4
|
* @example
|
|
5
5
|
* ```ts
|
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
* console.log(SPACECRAFT_IDS.join(", "));
|
|
9
9
|
* ```
|
|
10
10
|
*/
|
|
11
|
-
export const SPACECRAFT_IDS = ["voyager1", "voyager2", "newhorizons", "pioneer10", "pioneer11", "cassini", "galileo", "juno", "parker", "webb", "bepicolombo", "psyche", "europaclipper", "lucy", "juice", "hayabusa2", "osirisapex", "solarorbiter"];
|
|
11
|
+
export const SPACECRAFT_IDS = ["voyager1", "voyager2", "newhorizons", "pioneer10", "pioneer11", "cassini", "galileo", "juno", "parker", "webb", "bepicolombo", "psyche", "europaclipper", "lucy", "juice", "hayabusa2", "osirisapex", "solarorbiter", "roadster"];
|
|
12
12
|
const T = Date.UTC;
|
|
13
13
|
const noon = (y, m, d) => T(y, m - 1, d, 12);
|
|
14
14
|
const ev = (kind, date, precision, en, ja, more = {}) => ({ kind, date, precision, name: { en, ja }, ...more });
|
|
15
15
|
const flyby = (date, precision, en, ja, body, distanceKm) => ev("flyby", date, precision, en, ja, { ...(body === undefined ? {} : { body }), ...(distanceKm === undefined ? {} : { distanceKm }) });
|
|
16
16
|
/**
|
|
17
|
-
* The
|
|
17
|
+
* The nineteen craft and their facts, keyed by id.
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
20
|
* ```ts
|
|
@@ -198,6 +198,7 @@ export const SPACECRAFT = {
|
|
|
198
198
|
},
|
|
199
199
|
webb: {
|
|
200
200
|
id: "webb",
|
|
201
|
+
kind: "observatory",
|
|
201
202
|
name: { en: "James Webb Space Telescope", ja: "ジェイムズ・ウェッブ宇宙望遠鏡" },
|
|
202
203
|
agency: "NASA, ESA, CSA",
|
|
203
204
|
launch: { date: T(2021, 11, 25, 12, 20), precision: "minute", site: { en: "Kourou, French Guiana (ELA-3)", ja: "クールー (フランス領ギアナ) ELA-3" }, vehicle: "Ariane 5" },
|
|
@@ -367,4 +368,20 @@ export const SPACECRAFT = {
|
|
|
367
368
|
flyby(noon(2030, 9, 3), "day", "Sixth Venus flyby", "6回目の金星フライバイ", "venus"),
|
|
368
369
|
],
|
|
369
370
|
},
|
|
371
|
+
roadster: {
|
|
372
|
+
id: "roadster",
|
|
373
|
+
name: { en: "Starman", ja: "スターマン" },
|
|
374
|
+
otherNames: ["Tesla Roadster", "Starman", "Tesla"],
|
|
375
|
+
kind: "other",
|
|
376
|
+
agency: "SpaceX",
|
|
377
|
+
launch: { date: T(2018, 1, 6, 20, 45), precision: "minute", site: { en: "Kennedy Space Center, Launch Complex 39A", ja: "ケネディ宇宙センター 39A発射施設" }, vehicle: "Falcon Heavy" },
|
|
378
|
+
end: undefined,
|
|
379
|
+
status: "active",
|
|
380
|
+
url: "https://ssd.jpl.nasa.gov/api/horizons.api",
|
|
381
|
+
horizons: "-143205",
|
|
382
|
+
// filled from ROADSTER.record when the path is loaded, so this file does not carry the 20 kB table
|
|
383
|
+
record: { start: 0, end: 0 },
|
|
384
|
+
joins: [],
|
|
385
|
+
events: [ev("launch", T(2018, 1, 6, 20, 45), "minute", "Launch", "打ち上げ")],
|
|
386
|
+
},
|
|
370
387
|
};
|
package/dist/spacecraft.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export type { When } from "./when.ts";
|
|
|
7
7
|
* Load the fitted paths of some spacecraft (or all of them), each a table of its own that nothing else imports: about 6 kB gzipped for the Voyagers, the Pioneers, New Horizons and JWST, and more for the craft that orbited a planet or fly past many.
|
|
8
8
|
* Call it once before the other functions; it is safe to call again.
|
|
9
9
|
*
|
|
10
|
-
* @param ids - The craft to load; none means all
|
|
10
|
+
* @param ids - The craft to load; none means all nineteen.
|
|
11
11
|
* @returns A promise that settles when every table is registered.
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
@@ -199,3 +199,17 @@ export interface SpacecraftStats {
|
|
|
199
199
|
* ```
|
|
200
200
|
*/
|
|
201
201
|
export declare function spacecraftStats(id: SpacecraftId, when: When): SpacecraftStats;
|
|
202
|
+
/**
|
|
203
|
+
* The craft a search matches: the id, either name, or an `otherNames` entry, with case, letter width, spaces and punctuation folded. `voyager` matches both Voyagers. An empty string matches nothing.
|
|
204
|
+
*
|
|
205
|
+
* @param text - What was typed.
|
|
206
|
+
* @returns The matching ids, in the order of `SPACECRAFT_IDS`.
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```ts
|
|
210
|
+
* import { findSpacecraft } from "@johnmorrisdotca/wakusei-planets/spacecraft";
|
|
211
|
+
*
|
|
212
|
+
* console.log(findSpacecraft("tesla").join(","), findSpacecraft("スターマン").join(","));
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
export declare function findSpacecraft(text: string): SpacecraftId[];
|