@johnmorrisdotca/wakusei-planets 0.35.0 → 0.37.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 +18 -0
- package/NOTICE.md +31 -1
- package/README.md +5 -4
- package/dist/data/moon-catalogue.d.ts +31 -0
- package/dist/data/moon-catalogue.js +471 -0
- package/dist/data/orbiters.d.ts +368 -0
- package/dist/data/orbiters.js +370 -0
- package/dist/data/places-planned.d.ts +3 -0
- package/dist/data/places-planned.js +51 -0
- package/dist/element.d.ts +28 -0
- package/dist/element.js +172 -1
- package/dist/moon-catalogue.d.ts +296 -0
- package/dist/moon-catalogue.js +234 -0
- package/dist/orbiter-facts.d.ts +480 -0
- package/dist/orbiter-facts.js +189 -0
- package/dist/orbiters.d.ts +256 -0
- package/dist/orbiters.js +275 -0
- package/dist/place-marks.d.ts +182 -0
- package/dist/place-marks.js +194 -0
- package/dist/places/mars.d.ts +1 -1
- package/dist/places/mars.js +4 -2
- package/dist/places/moon.d.ts +1 -1
- package/dist/places/moon.js +4 -2
- package/dist/places.d.ts +4 -2
- package/dist/places.js +2 -0
- package/dist/scene/place-layer.d.ts +68 -0
- package/dist/scene/place-layer.js +213 -0
- package/dist/scene/textures.d.ts +2 -2
- package/dist/space/all-moons.d.ts +30 -0
- package/dist/space/all-moons.js +61 -0
- package/dist/space/bodies.d.ts +18 -0
- package/dist/space/bodies.js +18 -0
- package/dist/space/element.d.ts +182 -6
- package/dist/space/element.js +763 -26
- package/dist/space/frame.d.ts +14 -0
- package/dist/space/frame.js +16 -0
- package/dist/space/index.d.ts +5 -2
- package/dist/space/index.js +5 -2
- package/dist/space/regions.d.ts +111 -0
- package/dist/space/regions.js +84 -0
- package/dist/space/scene.d.ts +131 -8
- package/dist/space/scene.js +312 -15
- package/dist/space/sight.d.ts +106 -0
- package/dist/space/sight.js +84 -0
- package/dist/space/travel.d.ts +256 -0
- package/dist/space/travel.js +597 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +13 -2
package/dist/space/frame.d.ts
CHANGED
|
@@ -124,6 +124,20 @@ export interface SpaceFrame {
|
|
|
124
124
|
/** The minor bodies: Vesta, Pallas, Chiron, Pholus and Halley's comet, from tables fitted to Horizons (outside their years, from osculating elements). */
|
|
125
125
|
minors: Record<SpaceMinor, Vec3>;
|
|
126
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* An ecliptic J2000 vector in the scene's axes (equatorial J2000, y north): what `frameAt` does to every heliocentric place, for a place of your own (the Roadster's, from `/roadster`).
|
|
129
|
+
*
|
|
130
|
+
* @param v - A vector in ecliptic J2000 axes.
|
|
131
|
+
* @returns The same vector in the scene's axes.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* import { eclipticToScene } from "@johnmorrisdotca/wakusei-planets/space";
|
|
136
|
+
*
|
|
137
|
+
* console.log(eclipticToScene([0, 1, 0]).map((n) => n.toFixed(3)).join(", "));
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export declare function eclipticToScene(v: Vec3): Vec3;
|
|
127
141
|
/**
|
|
128
142
|
* The state of the sky at `ms`: the Sun, the Moon and eight planets as seen from the Earth's centre, worked out by this package's own models in a fraction of a millisecond.
|
|
129
143
|
*
|
package/dist/space/frame.js
CHANGED
|
@@ -64,6 +64,22 @@ export const SPACE_DWARFS = DWARF_IDS;
|
|
|
64
64
|
* ```
|
|
65
65
|
*/
|
|
66
66
|
export const SPACE_MINORS = MINOR_IDS;
|
|
67
|
+
/**
|
|
68
|
+
* An ecliptic J2000 vector in the scene's axes (equatorial J2000, y north): what `frameAt` does to every heliocentric place, for a place of your own (the Roadster's, from `/roadster`).
|
|
69
|
+
*
|
|
70
|
+
* @param v - A vector in ecliptic J2000 axes.
|
|
71
|
+
* @returns The same vector in the scene's axes.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* import { eclipticToScene } from "@johnmorrisdotca/wakusei-planets/space";
|
|
76
|
+
*
|
|
77
|
+
* console.log(eclipticToScene([0, 1, 0]).map((n) => n.toFixed(3)).join(", "));
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export function eclipticToScene(v) {
|
|
81
|
+
return scene(v);
|
|
82
|
+
}
|
|
67
83
|
/** An ecliptic J2000 vector in the scene's axes (equatorial J2000, y north). */
|
|
68
84
|
const scene = (v) => {
|
|
69
85
|
const c = Math.cos(OBLIQUITY * RAD);
|
package/dist/space/index.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, moonOrbit, planetOrbit, SPACE_DWARFS, SPACE_MINORS, SPACE_PLANETS, type SpaceDwarf, type SpaceFrame, type SpaceMinor, type SpacePlanet, type SpaceVec3 } from "./frame.ts";
|
|
1
|
+
export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, eclipticToScene, frameAt, moonOrbit, planetOrbit, SPACE_DWARFS, SPACE_MINORS, SPACE_PLANETS, type SpaceDwarf, type SpaceFrame, type SpaceMinor, type SpacePlanet, type SpaceVec3 } from "./frame.ts";
|
|
2
2
|
export { compress, MOON_COMPRESSED, moonDistance, orbitLine, placeAround, placeBodies, placeMoon, placeSun, radiusIn, SUN_COMPRESSED, truePosition, type ScaleMode } from "./scale.ts";
|
|
3
3
|
export { groundDirection } from "./aim.ts";
|
|
4
4
|
export { RIDE_FOV, ridePose, type RideInput, type RideLook, type RidePose } from "./ride.ts";
|
|
5
5
|
export { chooseLabels, LABEL_GAP, type LabelBox } from "./labels.ts";
|
|
6
|
-
export { bodyKindOf, findBody, HOP_ORDER, hopFrom, hostOf, type SpaceKind } from "./bodies.ts";
|
|
6
|
+
export { bodyKindOf, findBody, HOP_ORDER, hopFrom, hostOf, systemOf, type SpaceKind } from "./bodies.ts";
|
|
7
7
|
export { besideMoon, BESIDE_RADII, type BesideCamera, type BesideInput } from "./beside.ts";
|
|
8
8
|
export { ARROWS_PER_ORBIT, arrowCount, arrowSites, MAX_ARROWS_PER_ORBIT, chevron, spinArrow, type OrbitArrow } from "./arrows.ts";
|
|
9
9
|
export { spinAxis, type SpinAxis } from "./spin.ts";
|
|
10
10
|
export { COVER_ARROW_GAP, COVER_MIN_PX, coverArrows, coveredBy, type CoverArrow, type CoverEntry } from "./covered.ts";
|
|
11
|
+
export { TRAVEL_CLEARANCE, travelArrival, travelPlan, travelPose, type TravelBody, type TravelInput, type TravelKind, type TravelPlan, type TravelSample, type TravelSight, type TravelView } from "./travel.ts";
|
|
12
|
+
export { regionOrbits, regionView, SUN_REGIONS, type SunRegion } from "./regions.ts";
|
|
13
|
+
export { SIGHT_STEP_PX, sightChanged, sightOf, type Sight, type SightEdge, type SightInput } from "./sight.ts";
|
package/dist/space/index.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
// The space view's pure parts: where the bodies are (this package's own models), the two scales and, for riding along, where a camera looks. They import on a server. The element is `@johnmorrisdotca/wakusei-planets/space/element`.
|
|
2
|
-
export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, moonOrbit, planetOrbit, SPACE_DWARFS, SPACE_MINORS, SPACE_PLANETS } from "./frame.js";
|
|
2
|
+
export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, eclipticToScene, frameAt, moonOrbit, planetOrbit, SPACE_DWARFS, SPACE_MINORS, SPACE_PLANETS } from "./frame.js";
|
|
3
3
|
export { compress, MOON_COMPRESSED, moonDistance, orbitLine, placeAround, placeBodies, placeMoon, placeSun, radiusIn, SUN_COMPRESSED, truePosition } from "./scale.js";
|
|
4
4
|
export { groundDirection } from "./aim.js";
|
|
5
5
|
export { RIDE_FOV, ridePose } from "./ride.js";
|
|
6
6
|
export { chooseLabels, LABEL_GAP } from "./labels.js";
|
|
7
|
-
export { bodyKindOf, findBody, HOP_ORDER, hopFrom, hostOf } from "./bodies.js";
|
|
7
|
+
export { bodyKindOf, findBody, HOP_ORDER, hopFrom, hostOf, systemOf } from "./bodies.js";
|
|
8
8
|
export { besideMoon, BESIDE_RADII } from "./beside.js";
|
|
9
9
|
export { ARROWS_PER_ORBIT, arrowCount, arrowSites, MAX_ARROWS_PER_ORBIT, chevron, spinArrow } from "./arrows.js";
|
|
10
10
|
export { spinAxis } from "./spin.js";
|
|
11
11
|
export { COVER_ARROW_GAP, COVER_MIN_PX, coverArrows, coveredBy } from "./covered.js";
|
|
12
|
+
export { TRAVEL_CLEARANCE, travelArrival, travelPlan, travelPose } from "./travel.js";
|
|
13
|
+
export { regionOrbits, regionView, SUN_REGIONS } from "./regions.js";
|
|
14
|
+
export { SIGHT_STEP_PX, sightChanged, sightOf } from "./sight.js";
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { Vec3 } from "../vec.ts";
|
|
2
|
+
import { type ScaleMode } from "./scale.ts";
|
|
3
|
+
import type { TravelView } from "./travel.ts";
|
|
4
|
+
/**
|
|
5
|
+
* The stages a view steps out through from the Sun, nearest first: each has an `id`, a name in English and Japanese for a button or a step, and the bodies whose orbits make it. The inner planets are Mercury
|
|
6
|
+
* to Mars; the asteroid belt is Vesta, Ceres and Pallas, whose orbits reach its outer edge; the outer planets are Jupiter to Neptune; the Kuiper belt is Pluto and the dwarf planets out to Eris; the whole
|
|
7
|
+
* system is every orbit the space view draws, Sedna's and Halley's among them.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { SUN_REGIONS } from "@johnmorrisdotca/wakusei-planets/space";
|
|
12
|
+
*
|
|
13
|
+
* console.log(SUN_REGIONS.map((region) => `${region.id}: ${region.name.en} / ${region.name.ja}`).join("\n"));
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare const SUN_REGIONS: readonly [{
|
|
17
|
+
readonly id: "inner-planets";
|
|
18
|
+
readonly name: {
|
|
19
|
+
readonly en: "Inner planets";
|
|
20
|
+
readonly ja: "内太陽系";
|
|
21
|
+
};
|
|
22
|
+
readonly bodies: readonly ["mercury", "venus", "earth", "mars"];
|
|
23
|
+
}, {
|
|
24
|
+
readonly id: "asteroid-belt";
|
|
25
|
+
readonly name: {
|
|
26
|
+
readonly en: "Asteroid belt";
|
|
27
|
+
readonly ja: "小惑星帯";
|
|
28
|
+
};
|
|
29
|
+
readonly bodies: readonly ["vesta", "ceres", "pallas"];
|
|
30
|
+
}, {
|
|
31
|
+
readonly id: "outer-planets";
|
|
32
|
+
readonly name: {
|
|
33
|
+
readonly en: "Outer planets";
|
|
34
|
+
readonly ja: "外太陽系";
|
|
35
|
+
};
|
|
36
|
+
readonly bodies: readonly ["jupiter", "saturn", "uranus", "neptune"];
|
|
37
|
+
}, {
|
|
38
|
+
readonly id: "kuiper-belt";
|
|
39
|
+
readonly name: {
|
|
40
|
+
readonly en: "Kuiper belt";
|
|
41
|
+
readonly ja: "カイパーベルト";
|
|
42
|
+
};
|
|
43
|
+
readonly bodies: readonly ["pluto", "orcus", "haumea", "quaoar", "makemake", "gonggong", "eris"];
|
|
44
|
+
}, {
|
|
45
|
+
readonly id: "whole-system";
|
|
46
|
+
readonly name: {
|
|
47
|
+
readonly en: "Whole solar system";
|
|
48
|
+
readonly ja: "太陽系全体";
|
|
49
|
+
};
|
|
50
|
+
readonly bodies: readonly ["earth", "mercury", "venus", "mars", "jupiter", "saturn", "uranus", "neptune", "pluto", "ceres", "orcus", "haumea", "quaoar", "makemake", "gonggong", "eris", "sedna", "vesta", "pallas", "chiron", "pholus", "halley"];
|
|
51
|
+
}];
|
|
52
|
+
/**
|
|
53
|
+
* The `id` of one of the stages in `SUN_REGIONS`.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* import type { SunRegion } from "@johnmorrisdotca/wakusei-planets/space";
|
|
58
|
+
*
|
|
59
|
+
* const stage: SunRegion = "asteroid-belt";
|
|
60
|
+
* console.log(stage);
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export type SunRegion = (typeof SUN_REGIONS)[number]["id"];
|
|
64
|
+
/**
|
|
65
|
+
* The orbit lines of a stage as the space view draws them at `ms`: one line of points for each of its bodies, in the scene's unit (Earth radii from the Earth's centre) for the scale asked, from `planetOrbit`
|
|
66
|
+
* and the same mapping that places the bodies.
|
|
67
|
+
*
|
|
68
|
+
* @param region - The stage's `id`.
|
|
69
|
+
* @param mode - The scale.
|
|
70
|
+
* @param ms - The moment, in milliseconds since the Unix epoch.
|
|
71
|
+
* @param count - How many segments each orbit is cut into.
|
|
72
|
+
* @returns One line for each body of the stage.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* import { regionOrbits } from "@johnmorrisdotca/wakusei-planets/space";
|
|
77
|
+
*
|
|
78
|
+
* const lines = regionOrbits("inner-planets", "compressed", Date.UTC(2026, 10, 11));
|
|
79
|
+
* console.log(lines.length, lines[0]!.length);
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare function regionOrbits(region: SunRegion, mode: ScaleMode, ms: number, count?: number): Vec3[][];
|
|
83
|
+
/**
|
|
84
|
+
* The view that fits a region: the camera looks at `centre` along `forward` with `up` up (pass the view's own, so stepping out or in does not swing the picture), from the nearest distance at which every point
|
|
85
|
+
* of `orbits` is inside the picture with `margin` of its half width and height to spare (0.9 when left out). `reach` is how far the farthest point is from the centre: give it to the `TravelBody` of the
|
|
86
|
+
* centre so `travelPose` makes the move a straight pull back or push in.
|
|
87
|
+
*
|
|
88
|
+
* @param input - The centre's place, the orbit lines, the picture's width over its height, the direction to look along and its up, and optionally the field of view in degrees (35) and the margin.
|
|
89
|
+
* @returns The camera, and the region's `reach`.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* import { frameAt, placeSun, regionOrbits, regionView } from "@johnmorrisdotca/wakusei-planets/space";
|
|
94
|
+
*
|
|
95
|
+
* const ms = Date.UTC(2026, 10, 11);
|
|
96
|
+
* const sun = placeSun("compressed", frameAt(ms).sun);
|
|
97
|
+
* const view = regionView({ centre: sun, orbits: regionOrbits("outer-planets", "compressed", ms), aspect: 16 / 9, forward: [0, -0.6, -0.8], up: [0, 0.8, -0.6] });
|
|
98
|
+
* console.log(view.reach.toFixed(0), view.fov);
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export declare function regionView(input: {
|
|
102
|
+
centre: Vec3;
|
|
103
|
+
orbits: readonly (readonly Vec3[])[];
|
|
104
|
+
aspect: number;
|
|
105
|
+
forward: Vec3;
|
|
106
|
+
up: Vec3;
|
|
107
|
+
fov?: number;
|
|
108
|
+
margin?: number;
|
|
109
|
+
}): TravelView & {
|
|
110
|
+
reach: number;
|
|
111
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { cross, dot, length, sub, unit } from "../vec.js";
|
|
2
|
+
import { frameAt, planetOrbit, SPACE_DWARFS, SPACE_MINORS, SPACE_PLANETS } from "./frame.js";
|
|
3
|
+
import { placeAround, placeSun } from "./scale.js";
|
|
4
|
+
/**
|
|
5
|
+
* The stages a view steps out through from the Sun, nearest first: each has an `id`, a name in English and Japanese for a button or a step, and the bodies whose orbits make it. The inner planets are Mercury
|
|
6
|
+
* to Mars; the asteroid belt is Vesta, Ceres and Pallas, whose orbits reach its outer edge; the outer planets are Jupiter to Neptune; the Kuiper belt is Pluto and the dwarf planets out to Eris; the whole
|
|
7
|
+
* system is every orbit the space view draws, Sedna's and Halley's among them.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { SUN_REGIONS } from "@johnmorrisdotca/wakusei-planets/space";
|
|
12
|
+
*
|
|
13
|
+
* console.log(SUN_REGIONS.map((region) => `${region.id}: ${region.name.en} / ${region.name.ja}`).join("\n"));
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export const SUN_REGIONS = [
|
|
17
|
+
{ id: "inner-planets", name: { en: "Inner planets", ja: "内太陽系" }, bodies: ["mercury", "venus", "earth", "mars"] },
|
|
18
|
+
{ id: "asteroid-belt", name: { en: "Asteroid belt", ja: "小惑星帯" }, bodies: ["vesta", "ceres", "pallas"] },
|
|
19
|
+
{ id: "outer-planets", name: { en: "Outer planets", ja: "外太陽系" }, bodies: ["jupiter", "saturn", "uranus", "neptune"] },
|
|
20
|
+
{ id: "kuiper-belt", name: { en: "Kuiper belt", ja: "カイパーベルト" }, bodies: ["pluto", "orcus", "haumea", "quaoar", "makemake", "gonggong", "eris"] },
|
|
21
|
+
{ id: "whole-system", name: { en: "Whole solar system", ja: "太陽系全体" }, bodies: ["earth", ...SPACE_PLANETS, ...SPACE_DWARFS, ...SPACE_MINORS] },
|
|
22
|
+
];
|
|
23
|
+
/**
|
|
24
|
+
* The orbit lines of a stage as the space view draws them at `ms`: one line of points for each of its bodies, in the scene's unit (Earth radii from the Earth's centre) for the scale asked, from `planetOrbit`
|
|
25
|
+
* and the same mapping that places the bodies.
|
|
26
|
+
*
|
|
27
|
+
* @param region - The stage's `id`.
|
|
28
|
+
* @param mode - The scale.
|
|
29
|
+
* @param ms - The moment, in milliseconds since the Unix epoch.
|
|
30
|
+
* @param count - How many segments each orbit is cut into.
|
|
31
|
+
* @returns One line for each body of the stage.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { regionOrbits } from "@johnmorrisdotca/wakusei-planets/space";
|
|
36
|
+
*
|
|
37
|
+
* const lines = regionOrbits("inner-planets", "compressed", Date.UTC(2026, 10, 11));
|
|
38
|
+
* console.log(lines.length, lines[0]!.length);
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export function regionOrbits(region, mode, ms, count = 96) {
|
|
42
|
+
const sun = placeSun(mode, frameAt(ms).sun);
|
|
43
|
+
const bodies = SUN_REGIONS.find((entry) => entry.id === region).bodies;
|
|
44
|
+
return bodies.map((id) => planetOrbit(id, ms, count).map((p) => placeAround(mode, sun, p)));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The view that fits a region: the camera looks at `centre` along `forward` with `up` up (pass the view's own, so stepping out or in does not swing the picture), from the nearest distance at which every point
|
|
48
|
+
* of `orbits` is inside the picture with `margin` of its half width and height to spare (0.9 when left out). `reach` is how far the farthest point is from the centre: give it to the `TravelBody` of the
|
|
49
|
+
* centre so `travelPose` makes the move a straight pull back or push in.
|
|
50
|
+
*
|
|
51
|
+
* @param input - The centre's place, the orbit lines, the picture's width over its height, the direction to look along and its up, and optionally the field of view in degrees (35) and the margin.
|
|
52
|
+
* @returns The camera, and the region's `reach`.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { frameAt, placeSun, regionOrbits, regionView } from "@johnmorrisdotca/wakusei-planets/space";
|
|
57
|
+
*
|
|
58
|
+
* const ms = Date.UTC(2026, 10, 11);
|
|
59
|
+
* const sun = placeSun("compressed", frameAt(ms).sun);
|
|
60
|
+
* const view = regionView({ centre: sun, orbits: regionOrbits("outer-planets", "compressed", ms), aspect: 16 / 9, forward: [0, -0.6, -0.8], up: [0, 0.8, -0.6] });
|
|
61
|
+
* console.log(view.reach.toFixed(0), view.fov);
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export function regionView(input) {
|
|
65
|
+
const forward = unit(input.forward);
|
|
66
|
+
const lifted = sub(input.up, [forward[0] * dot(input.up, forward), forward[1] * dot(input.up, forward), forward[2] * dot(input.up, forward)]);
|
|
67
|
+
const up = unit(length(lifted) < 1e-9 ? cross(Math.abs(forward[1]) < 0.9 ? cross(forward, [0, 1, 0]) : cross(forward, [1, 0, 0]), forward) : lifted);
|
|
68
|
+
const right = cross(forward, up);
|
|
69
|
+
const fov = input.fov ?? 35;
|
|
70
|
+
const margin = input.margin ?? 0.9;
|
|
71
|
+
const tv = Math.tan((fov / 2) * (Math.PI / 180)) * margin;
|
|
72
|
+
const th = tv * Math.max(1e-3, input.aspect);
|
|
73
|
+
let distance = 0;
|
|
74
|
+
let reach = 0;
|
|
75
|
+
for (const line of input.orbits) {
|
|
76
|
+
for (const point of line) {
|
|
77
|
+
const v = sub(point, input.centre);
|
|
78
|
+
reach = Math.max(reach, length(v));
|
|
79
|
+
// the camera is `distance` back along the line of sight: the point is inside when its offset across and up is within the frame at its depth
|
|
80
|
+
distance = Math.max(distance, Math.abs(dot(v, right)) / th - dot(v, forward), Math.abs(dot(v, up)) / tv - dot(v, forward));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return { position: [input.centre[0] - forward[0] * distance, input.centre[1] - forward[1] * distance, input.centre[2] - forward[2] * distance], forward, up, fov, reach };
|
|
84
|
+
}
|
package/dist/space/scene.d.ts
CHANGED
|
@@ -3,13 +3,17 @@ import type { Item3D } from "@johnmorrisdotca/kazoku-ui/renderer";
|
|
|
3
3
|
import { type BodyId, type MoonId } from "../facts.ts";
|
|
4
4
|
import type { ThreeParts } from "../scene/body.ts";
|
|
5
5
|
import type { SourceBook } from "../door/book.ts";
|
|
6
|
+
import { type MoonDot } from "./all-moons.ts";
|
|
6
7
|
import { type PaintLabel, type WakuseiPainter } from "../scene/painter.ts";
|
|
7
8
|
import "../bodies/all.ts";
|
|
8
9
|
import type { Vec3 } from "../vec.ts";
|
|
9
10
|
import { type OrbitArrow } from "./arrows.ts";
|
|
11
|
+
import type { SightInput } from "./sight.ts";
|
|
10
12
|
import { type SpaceFrame, type SpaceVec3 } from "./frame.ts";
|
|
11
13
|
import { type RideLook } from "./ride.ts";
|
|
12
14
|
import { type ScaleMode } from "./scale.ts";
|
|
15
|
+
import { type SunRegion } from "./regions.ts";
|
|
16
|
+
import { type TravelInput, type TravelKind, type TravelPlan } from "./travel.ts";
|
|
13
17
|
/** The parts of three.js the space view uses: the bodies' and a perspective camera. */
|
|
14
18
|
export type SpaceThree = ThreeParts & Pick<typeof THREE, "PerspectiveCamera">;
|
|
15
19
|
/** The camera's distance, in radii of the body it looks at, at which that body fills the view at zoom 1. */
|
|
@@ -97,6 +101,34 @@ export interface CameraPose {
|
|
|
97
101
|
fov: number;
|
|
98
102
|
valid: boolean;
|
|
99
103
|
}
|
|
104
|
+
/** The Roadster's path as the view needs it: from `/roadster`, loaded only when the Roadster is shown. */
|
|
105
|
+
export interface RoadsterPath {
|
|
106
|
+
/** Where the car is at a moment, in au from the Sun, ecliptic J2000 axes. */
|
|
107
|
+
positionAu(ms: number): Vec3;
|
|
108
|
+
/** The span the path covers, in milliseconds since 1970. */
|
|
109
|
+
record: {
|
|
110
|
+
start: number;
|
|
111
|
+
end: number;
|
|
112
|
+
};
|
|
113
|
+
/** The car's name, in English and Japanese. */
|
|
114
|
+
name: {
|
|
115
|
+
en: string;
|
|
116
|
+
ja: string;
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/** The orbiters as the view needs them: from `/orbiters`, loaded only when they are shown. */
|
|
120
|
+
export interface OrbiterSet {
|
|
121
|
+
ids: readonly string[];
|
|
122
|
+
centre(id: string): "moon" | "mars";
|
|
123
|
+
/** Kilometres from the body's centre, ecliptic J2000; `null` for a craft with no path. */
|
|
124
|
+
position(id: string, ms: number): Vec3 | null;
|
|
125
|
+
path(id: string, ms: number, points: number): Vec3[];
|
|
126
|
+
status(id: string, ms: number): "tracked" | "predicted" | "modelled" | "none";
|
|
127
|
+
name(id: string): {
|
|
128
|
+
en: string;
|
|
129
|
+
ja: string;
|
|
130
|
+
};
|
|
131
|
+
}
|
|
100
132
|
export interface SpaceModel {
|
|
101
133
|
/** Moment shown, milliseconds since the epoch. */
|
|
102
134
|
time: number;
|
|
@@ -119,8 +151,13 @@ export interface SpaceModel {
|
|
|
119
151
|
anchor: number | null;
|
|
120
152
|
orbits: boolean;
|
|
121
153
|
labels: boolean;
|
|
154
|
+
/** The catalogue's moons to draw as dots at a moment (`all-moons`), or null for none; and how many were drawn at the last draw. */
|
|
155
|
+
allMoons: ((ms: number) => readonly MoonDot[]) | null;
|
|
156
|
+
moonDots: number;
|
|
122
157
|
/** Milliseconds of game time one second of wall time covers (the ephemeris is looked up once per such span). */
|
|
123
158
|
stepMs: number;
|
|
159
|
+
/** Game seconds for each second of wall time, with its sign (0 when the clock holds): the places a move is worked out for are those the clock reaches by its end. */
|
|
160
|
+
speed: number;
|
|
124
161
|
/** 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). */
|
|
125
162
|
focus: BodyId;
|
|
126
163
|
light: SpaceLight;
|
|
@@ -159,6 +196,23 @@ export interface SpaceModel {
|
|
|
159
196
|
helpThrough: boolean;
|
|
160
197
|
/** How many arrowheads each orbit line carries: 0 to `MAX_ARROWS_PER_ORBIT`, two by default. */
|
|
161
198
|
arrowCount: number;
|
|
199
|
+
/** Show the spacecraft in orbit round the Moon and Mars: a dot each on its orbit line, named, once its body is big enough on the screen. Off by default; their paths are loaded when first shown. */
|
|
200
|
+
orbiters: boolean;
|
|
201
|
+
orbiterSet: OrbiterSet | null;
|
|
202
|
+
/** The orbiters at the last draw: how many were drawn, and each drawn one's status. */
|
|
203
|
+
orbitersDrawn: {
|
|
204
|
+
count: number;
|
|
205
|
+
status: Record<string, "tracked" | "predicted" | "modelled" | "none">;
|
|
206
|
+
};
|
|
207
|
+
/** 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. */
|
|
208
|
+
roadster: boolean;
|
|
209
|
+
roadsterPath: RoadsterPath | null;
|
|
210
|
+
/** What the Roadster drew at the last draw: whether it was drawn (shown, its path in, and the moment within the record), its place in Earth radii from the Earth's centre, and its radius on the screen. */
|
|
211
|
+
roadsterDrawn: {
|
|
212
|
+
shown: boolean;
|
|
213
|
+
position: [number, number, number] | null;
|
|
214
|
+
radiusPx: number;
|
|
215
|
+
};
|
|
162
216
|
/** 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. */
|
|
163
217
|
label: PaintLabel | null;
|
|
164
218
|
labelVersion: number;
|
|
@@ -212,21 +266,63 @@ export interface SpaceModel {
|
|
|
212
266
|
ride: RideState | null;
|
|
213
267
|
/** Set at each draw: the target of the ride could not be placed, so the ordinary camera was used. */
|
|
214
268
|
rideLost: boolean;
|
|
215
|
-
/** A camera move in progress from where the last draw left
|
|
216
|
-
transition:
|
|
217
|
-
|
|
269
|
+
/** A camera move in progress from where the last draw left the camera to the view set up for the new target: see `SpaceTransition`. */
|
|
270
|
+
transition: SpaceTransition | null;
|
|
271
|
+
/** What the move is doing at this draw, or null when the camera is still: the kind and path of the move, its stage, how far along it is (0 to 1), its length, and whether the body left and the one gone to are in the picture. */
|
|
272
|
+
travelling: {
|
|
273
|
+
kind: Exclude<TravelKind, "auto">;
|
|
274
|
+
path: TravelPlan["path"];
|
|
275
|
+
stage: "turn" | "travel" | "arrive";
|
|
276
|
+
progress: number;
|
|
218
277
|
duration: number;
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
278
|
+
leaving: boolean;
|
|
279
|
+
destination: boolean;
|
|
280
|
+
} | null;
|
|
281
|
+
/** The stage out from the Sun the view is framed on (`SUN_REGIONS`), or null for an ordinary view of the body looked at. */
|
|
282
|
+
region: SunRegion | null;
|
|
283
|
+
/** The region as the last draw framed it: how far out it reaches from the Sun and how far the camera stood back, in Earth radii. */
|
|
284
|
+
regionDrawn: {
|
|
285
|
+
id: SunRegion;
|
|
286
|
+
reach: number;
|
|
287
|
+
distance: number;
|
|
224
288
|
} | null;
|
|
225
289
|
pose: CameraPose;
|
|
226
290
|
/** Pixels a game-second that riding makes things move on the screen (0 when not riding): the draw rate follows it. */
|
|
227
291
|
rideMotion: number;
|
|
228
292
|
ratio(): number;
|
|
229
293
|
}
|
|
294
|
+
/**
|
|
295
|
+
* A camera move from one view to the next, as the element asks for it: when it began (ms of the page's clock), the length a page asked for (0 to take the plan's own), the pace, the kind of move, where the
|
|
296
|
+
* last draw left the camera, and the body being left and the one gone to (for the path to keep in the picture; null when unknown). The scene builds the path at the move's first draw (`input`, `plan`), from
|
|
297
|
+
* that camera to the view it has just set up for the new target, and then draws `travelPose` of it until the move is over.
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* ```ts no-run
|
|
301
|
+
* import type { SpaceTransition } from "@johnmorrisdotca/wakusei-planets/space/scene";
|
|
302
|
+
*
|
|
303
|
+
* const describe = (move: SpaceTransition): string => `${move.kind} from ${move.leaving ?? "?"} to ${move.destination ?? "?"}`;
|
|
304
|
+
* console.log(typeof describe);
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
export interface SpaceTransition {
|
|
308
|
+
start: number;
|
|
309
|
+
duration: number;
|
|
310
|
+
pace: number;
|
|
311
|
+
kind: TravelKind;
|
|
312
|
+
from: {
|
|
313
|
+
p: SpaceVec3;
|
|
314
|
+
q: [number, number, number, number];
|
|
315
|
+
fov: number;
|
|
316
|
+
};
|
|
317
|
+
leaving: BodyId | null;
|
|
318
|
+
destination: BodyId | null;
|
|
319
|
+
/** How far the region being left reached from the Sun, when the move leaves a stage out from the Sun (a straight push in or pull back then). */
|
|
320
|
+
leavingReach: number;
|
|
321
|
+
input: TravelInput | null;
|
|
322
|
+
plan: TravelPlan | null;
|
|
323
|
+
/** The scene's origin (the place of the body looked at) when the path was worked out: the path is in places relative to it. */
|
|
324
|
+
origin: Vec3;
|
|
325
|
+
}
|
|
230
326
|
export declare const newSpaceModel: () => SpaceModel;
|
|
231
327
|
/**
|
|
232
328
|
* Where a body is on the screen: its centre and its apparent radius, in CSS pixels in the box.
|
|
@@ -258,6 +354,33 @@ export interface SpaceDeps {
|
|
|
258
354
|
advance?: () => void;
|
|
259
355
|
/** Where each body is on the screen, in CSS pixels in the box, or null when it is behind the camera. Called at each draw. */
|
|
260
356
|
onLabels?: (places: Record<string, BodyPlace | null>) => void;
|
|
357
|
+
/** What the camera sees of each body at each draw, by id: the Sun, the planets and the other bodies of `SPACE_BODIES`, the moons of the body looked at, and any other moon drawn; with the picture's size and the point straight ahead of the camera. Not the body the camera rides on. */
|
|
358
|
+
onSight?: (bodies: Record<string, SightInput>, frame: {
|
|
359
|
+
width: number;
|
|
360
|
+
height: number;
|
|
361
|
+
axis: {
|
|
362
|
+
x: number;
|
|
363
|
+
y: number;
|
|
364
|
+
};
|
|
365
|
+
}) => void;
|
|
366
|
+
/** Whether `onSight` is wanted at this draw (left out, it always is): the page has asked for it. */
|
|
367
|
+
wantSight?: () => boolean;
|
|
368
|
+
/** The body looked at, as this draw left it, for marks laid on its surface: its centre and radius in the scene, its pole and prime meridian, the camera's place, the projection to CSS pixels and its radius on the screen. Not while the camera rides. */
|
|
369
|
+
onSurface?: (body: {
|
|
370
|
+
id: BodyId;
|
|
371
|
+
centre: Vec3;
|
|
372
|
+
radius: number;
|
|
373
|
+
pole: Vec3;
|
|
374
|
+
meridian: Vec3;
|
|
375
|
+
eye: Vec3;
|
|
376
|
+
project(point: Vec3): {
|
|
377
|
+
x: number;
|
|
378
|
+
y: number;
|
|
379
|
+
} | null;
|
|
380
|
+
width: number;
|
|
381
|
+
height: number;
|
|
382
|
+
radiusPx: number;
|
|
383
|
+
} | null) => void;
|
|
261
384
|
/** Called at the end of a draw while the camera is moving from one ride to another, so the next frame is asked for (at the page's frame cap). */
|
|
262
385
|
onMoving?: () => void;
|
|
263
386
|
/** The target of the ride could not be placed at this draw. */
|