@johnmorrisdotca/chikyu-earth 0.42.0 → 0.45.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/NOTICE.md +15 -5
  3. package/README.md +4 -4
  4. package/dist/door/map.js +5 -1
  5. package/dist/element.d.ts +30 -0
  6. package/dist/element.js +82 -2
  7. package/dist/markers/here-city-host.d.ts +3 -1
  8. package/dist/markers/here-city-host.js +67 -5
  9. package/dist/markers/here-city.d.ts +94 -1
  10. package/dist/markers/here-city.js +69 -1
  11. package/dist/markers/index.d.ts +1 -1
  12. package/dist/markers/index.js +1 -1
  13. package/dist/realistic/element-base.d.ts +44 -1
  14. package/dist/realistic/element-base.js +128 -16
  15. package/dist/realistic/index.d.ts +1 -0
  16. package/dist/realistic/index.js +1 -0
  17. package/dist/realistic/zoom-reach.d.ts +29 -0
  18. package/dist/realistic/zoom-reach.js +30 -0
  19. package/dist/satellites/catalogue.d.ts +52 -1
  20. package/dist/satellites/catalogue.js +96 -5
  21. package/dist/satellites/index.d.ts +1 -1
  22. package/dist/satellites/index.js +1 -1
  23. package/dist/sea-names/features.d.ts +12 -0
  24. package/dist/sea-names/features.js +46 -0
  25. package/dist/sea-names/geometry.d.ts +121 -0
  26. package/dist/sea-names/geometry.js +135 -0
  27. package/dist/sea-names/host.d.ts +46 -0
  28. package/dist/sea-names/host.js +111 -0
  29. package/dist/space/element-base.d.ts +58 -11
  30. package/dist/space/element-base.js +153 -13
  31. package/dist/space/generic-satellite.d.ts +46 -0
  32. package/dist/space/generic-satellite.js +96 -0
  33. package/dist/space/index.d.ts +2 -1
  34. package/dist/space/index.js +2 -1
  35. package/dist/space/ride.d.ts +45 -0
  36. package/dist/space/ride.js +38 -0
  37. package/dist/space/satellite-focus.d.ts +90 -0
  38. package/dist/space/satellite-focus.js +109 -0
  39. package/dist/space/satellite-layer.d.ts +32 -3
  40. package/dist/space/satellite-layer.js +95 -29
  41. package/dist/space/scene.d.ts +3 -1
  42. package/dist/space/scene.js +54 -25
  43. package/package.json +3 -3
@@ -162,6 +162,51 @@ export interface RidePose {
162
162
  fov: number;
163
163
  earthRadiusDegrees: number;
164
164
  }
165
+ /**
166
+ * Where a ride puts the camera: `outside` (the default) a little way off the satellite, behind and above it, so the satellite is in the picture; `inside` at the satellite itself, looking out of it, as a ride always was.
167
+ *
168
+ * @example
169
+ * ```ts
170
+ * import type { RideViewpoint } from "@johnmorrisdotca/chikyu-earth/space";
171
+ *
172
+ * const viewpoints: RideViewpoint[] = ["outside", "inside"];
173
+ * console.log(viewpoints.join(" or "));
174
+ * ```
175
+ */
176
+ export type RideViewpoint = "outside" | "inside";
177
+ /**
178
+ * How far an outside ride keeps the camera from the satellite, in kilometres. The satellite itself is a few metres across, so it is drawn far larger than life (a model about a fifth of the picture's height across): not to scale, and the page says so in its caption.
179
+ *
180
+ * @example
181
+ * ```ts
182
+ * import { OUTSIDE_KM } from "@johnmorrisdotca/chikyu-earth/space";
183
+ *
184
+ * console.log(OUTSIDE_KM);
185
+ * ```
186
+ */
187
+ export declare const OUTSIDE_KM = 25;
188
+ /**
189
+ * The camera of an outside ride: the pose `ridePose` works out for a camera at the satellite, moved to `OUTSIDE_KM` back along its own line of sight so the satellite is in front of it. Looking along the way it goes (`look: "horizon"`) the satellite sits a little below the middle of the picture, so the camera is behind and above it; looking
190
+ * down (`look: "down"`) it is at the middle, with the camera straight above it. Where the satellite sits in the picture does not change with the zoom. Which way the camera looks and which way is up are the pose's own, so the look-around is the same as from the satellite itself; the camera goes round the satellite as it looks about. Pure. Never nearer the ground than half the satellite's height.
191
+ *
192
+ * @param pose - The pose from `ridePose` for the camera at the satellite.
193
+ * @param look - The look the pose was made with.
194
+ * @returns The pose moved back from the satellite, with how far the camera is from it in Earth radii and how many degrees below the middle of the picture the satellite is.
195
+ *
196
+ * @example
197
+ * ```ts
198
+ * import { outsidePose, ridePose } from "@johnmorrisdotca/chikyu-earth/space";
199
+ *
200
+ * const at = ridePose({ position: [1.066, 0, 0], velocity: [0, 0, -7.66], look: "horizon", yaw: 0, tilt: 0, zoom: 1 });
201
+ * const out = outsidePose(at, "horizon");
202
+ * console.log(out.distance.toFixed(4), out.below.toFixed(1), out.pose.position.map((n) => n.toFixed(4)).join(","));
203
+ * ```
204
+ */
205
+ export declare function outsidePose(pose: RidePose, look: RideLook): {
206
+ pose: RidePose;
207
+ distance: number;
208
+ below: number;
209
+ };
165
210
  /**
166
211
  * The camera of a body-borne view: at `position`, looking at the Earth, with the way the body is going at the top of the picture. `look: "horizon"` tips it forward until the horizon is a little above the middle. A drag looks about from there on the spot:
167
212
  * `yaw` turns the camera to its left and `tilt` tips it towards the bottom of its picture, so the ground follows the pointer (right for a drag right, up for a drag up); the angle for each pixel of the drag is the field of view's, so the pace is the same at any zoom.
@@ -121,6 +121,44 @@ const unit = (a) => {
121
121
  const n = norm(a);
122
122
  return n === 0 ? [0, 0, 0] : [a[0] / n, a[1] / n, a[2] / n];
123
123
  };
124
+ /**
125
+ * How far an outside ride keeps the camera from the satellite, in kilometres. The satellite itself is a few metres across, so it is drawn far larger than life (a model about a fifth of the picture's height across): not to scale, and the page says so in its caption.
126
+ *
127
+ * @example
128
+ * ```ts
129
+ * import { OUTSIDE_KM } from "@johnmorrisdotca/chikyu-earth/space";
130
+ *
131
+ * console.log(OUTSIDE_KM);
132
+ * ```
133
+ */
134
+ export const OUTSIDE_KM = 25;
135
+ /** How far below the middle of the picture the satellite is drawn in an outside ride that looks along the way it goes, as a share of half the picture's height (0.56: about a fifth of the height below the middle). */
136
+ const OUTSIDE_LOW = 0.56;
137
+ /**
138
+ * The camera of an outside ride: the pose `ridePose` works out for a camera at the satellite, moved to `OUTSIDE_KM` back along its own line of sight so the satellite is in front of it. Looking along the way it goes (`look: "horizon"`) the satellite sits a little below the middle of the picture, so the camera is behind and above it; looking
139
+ * down (`look: "down"`) it is at the middle, with the camera straight above it. Where the satellite sits in the picture does not change with the zoom. Which way the camera looks and which way is up are the pose's own, so the look-around is the same as from the satellite itself; the camera goes round the satellite as it looks about. Pure. Never nearer the ground than half the satellite's height.
140
+ *
141
+ * @param pose - The pose from `ridePose` for the camera at the satellite.
142
+ * @param look - The look the pose was made with.
143
+ * @returns The pose moved back from the satellite, with how far the camera is from it in Earth radii and how many degrees below the middle of the picture the satellite is.
144
+ *
145
+ * @example
146
+ * ```ts
147
+ * import { outsidePose, ridePose } from "@johnmorrisdotca/chikyu-earth/space";
148
+ *
149
+ * const at = ridePose({ position: [1.066, 0, 0], velocity: [0, 0, -7.66], look: "horizon", yaw: 0, tilt: 0, zoom: 1 });
150
+ * const out = outsidePose(at, "horizon");
151
+ * console.log(out.distance.toFixed(4), out.below.toFixed(1), out.pose.position.map((n) => n.toFixed(4)).join(","));
152
+ * ```
153
+ */
154
+ export function outsidePose(pose, look) {
155
+ const height = Math.max(0, norm(pose.position) - 1);
156
+ const distance = Math.max(1e-5, Math.min(OUTSIDE_KM / 6371, height * 0.5));
157
+ const below = look === "horizon" ? Math.atan(OUTSIDE_LOW * Math.tan((pose.fov / 2) * RAD)) : 0;
158
+ // the satellite is along the line of sight turned `below` down (towards the bottom of the picture): the camera is back along that line
159
+ const line = add(scale(pose.forward, Math.cos(below)), scale(pose.up, -Math.sin(below)));
160
+ return { pose: { ...pose, position: add(pose.position, scale(line, -distance)) }, distance, below: below / RAD };
161
+ }
124
162
  /**
125
163
  * The camera of a body-borne view: at `position`, looking at the Earth, with the way the body is going at the top of the picture. `look: "horizon"` tips it forward until the horizon is a little above the middle. A drag looks about from there on the spot:
126
164
  * `yaw` turns the camera to its left and `tilt` tips it towards the bottom of its picture, so the ground follows the pointer (right for a drag right, up for a drag up); the angle for each pixel of the drag is the field of view's, so the pace is the same at any zoom.
@@ -0,0 +1,90 @@
1
+ import type { ElementSet } from "../satellites/types.ts";
2
+ import type { SatelliteState } from "./satellite-layer.ts";
3
+ /** What happens to the groups that are not the one in focus. `dim` draws them dimmer. `hide` does not draw them. */
4
+ export type SatelliteOthers = "dim" | "hide";
5
+ /** The group a view is showing on its own, and what it does with the others. `null` when every group is as the page set it. */
6
+ export interface SatelliteFocus {
7
+ name: string;
8
+ others: SatelliteOthers;
9
+ }
10
+ /** How one group is drawn while a focus is set. `focus` is the chosen group, `dim` a group drawn dimmer, `hidden` a group not drawn, `plain` a group with no focus in force. */
11
+ export type SatelliteEmphasis = "focus" | "dim" | "hidden" | "plain";
12
+ /** What `focusSatelliteGroup` returns. `reason: "not-set"` is a group `setSatellites` has not set; the call changes nothing and does not throw. */
13
+ export interface SatelliteFocusAnswer {
14
+ ok: boolean;
15
+ group?: string | null;
16
+ count?: number;
17
+ changed?: boolean;
18
+ reason?: "not-set";
19
+ }
20
+ /**
21
+ * Whether a group is drawn, and whether its dots take the dim value, for a focus. A group the page hid stays hidden unless it is the one in focus. The page's own shown state is not an input that this changes.
22
+ *
23
+ * @param name - The group's name.
24
+ * @param ownVisible - Whether the page is showing the group (`showSatellites`).
25
+ * @param focus - The focus in force, or `null`.
26
+ * @returns `drawn` (the group is placed), `dim` (1 to draw it dimmer, 0 to leave it) and `emphasis`.
27
+ */
28
+ export declare function satelliteEmphasis(name: string, ownVisible: boolean, focus: SatelliteFocus | null): {
29
+ drawn: boolean;
30
+ dim: number;
31
+ emphasis: SatelliteEmphasis;
32
+ };
33
+ /**
34
+ * Put the focus on one group, or clear it with `null`. A name that is not a group already set is refused.
35
+ *
36
+ * @param state - The view's satellite state.
37
+ * @param name - The group's name, or `null` to clear.
38
+ * @param options - `others` is `dim` when left out. `frame` is read by the element, not here.
39
+ * @returns The answer. `changed` is false when the focus was already that.
40
+ */
41
+ export declare function applySatelliteFocus(state: SatelliteState, name: string | null, options?: {
42
+ others?: SatelliteOthers;
43
+ }): SatelliteFocusAnswer;
44
+ /** One group as `satelliteGroups` reports it: the page's own shown state, how the focus treats it, and how many the last draw placed. */
45
+ export interface SatelliteGroupRow {
46
+ name: string;
47
+ count: number;
48
+ visible: boolean;
49
+ placed: number;
50
+ emphasis: SatelliteEmphasis;
51
+ }
52
+ /**
53
+ * The groups now set, in the order they were set, with the focus applied for reading. `placed` is 0 when the group is not drawn.
54
+ *
55
+ * @param state - The view's satellite state.
56
+ * @returns One row a group.
57
+ */
58
+ export declare function satelliteGroupRows(state: SatelliteState): SatelliteGroupRow[];
59
+ /** The greatest apogee a shell is pulled out to, in Earth radii. Past this, one far satellite would shrink the Earth instead of showing the group. */
60
+ export declare const SHELL_CAP = 8;
61
+ /**
62
+ * The shell of a group, in Earth radii from the Earth's centre: the greatest apogee of its element sets, from the mean motion (revolutions a day) and the eccentricity.
63
+ * One revolution a day is 6.62 Earth radii (Kepler's third law, an Earth of 6371 km). A group with no usable set is the Earth's own radius. The result is never above {@link SHELL_CAP}.
64
+ *
65
+ * @param sets - The group's element sets.
66
+ * @returns The shell, from 1 to 8.
67
+ */
68
+ export declare function shellRadiusOf(sets: readonly Pick<ElementSet, "MEAN_MOTION" | "ECCENTRICITY">[]): number;
69
+ /**
70
+ * The zoom that puts a shell of `shell` Earth radii inside the space view. At zoom 1 the Earth fills `earthSize` of the shorter side. The shell fills about 0.92 of that side.
71
+ *
72
+ * @param shell - The shell, in Earth radii.
73
+ * @param earthSize - The share of the shorter side the Earth fills at zoom 1.
74
+ * @param aspect - The view's width over its height.
75
+ * @param min - The least zoom the view allows.
76
+ * @param max - The greatest zoom the view allows.
77
+ * @returns The zoom.
78
+ */
79
+ export declare function zoomForPerspectiveShell(shell: number, earthSize: number, aspect: number, min: number, max: number): number;
80
+ /**
81
+ * The zoom that puts a shell of `shell` Earth radii inside the realistic Earth's picture. At zoom 1 the Earth and its glow fill the shorter side (the glow is 1.08 radii). The shell fills about 0.92 of that side.
82
+ *
83
+ * @param shell - The shell, in Earth radii.
84
+ * @param width - The view's width in CSS pixels.
85
+ * @param height - The view's height in CSS pixels.
86
+ * @param min - The least zoom the view allows.
87
+ * @param max - The greatest zoom the view allows.
88
+ * @returns The zoom.
89
+ */
90
+ export declare function zoomForOrthographicShell(shell: number, width: number, height: number, min: number, max: number): number;
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Whether a group is drawn, and whether its dots take the dim value, for a focus. A group the page hid stays hidden unless it is the one in focus. The page's own shown state is not an input that this changes.
3
+ *
4
+ * @param name - The group's name.
5
+ * @param ownVisible - Whether the page is showing the group (`showSatellites`).
6
+ * @param focus - The focus in force, or `null`.
7
+ * @returns `drawn` (the group is placed), `dim` (1 to draw it dimmer, 0 to leave it) and `emphasis`.
8
+ */
9
+ export function satelliteEmphasis(name, ownVisible, focus) {
10
+ if (!focus)
11
+ return { drawn: ownVisible, dim: 0, emphasis: "plain" };
12
+ if (focus.name === name)
13
+ return { drawn: true, dim: 0, emphasis: "focus" };
14
+ if (focus.others === "hide" || !ownVisible)
15
+ return { drawn: false, dim: 0, emphasis: "hidden" };
16
+ return { drawn: true, dim: 1, emphasis: "dim" };
17
+ }
18
+ /**
19
+ * Put the focus on one group, or clear it with `null`. A name that is not a group already set is refused.
20
+ *
21
+ * @param state - The view's satellite state.
22
+ * @param name - The group's name, or `null` to clear.
23
+ * @param options - `others` is `dim` when left out. `frame` is read by the element, not here.
24
+ * @returns The answer. `changed` is false when the focus was already that.
25
+ */
26
+ export function applySatelliteFocus(state, name, options = {}) {
27
+ if (name === null) {
28
+ const changed = state.focus !== null;
29
+ state.focus = null;
30
+ return { ok: true, group: null, count: 0, changed };
31
+ }
32
+ const found = state.groups.get(name);
33
+ if (!found)
34
+ return { ok: false, reason: "not-set" };
35
+ const others = options.others === "hide" ? "hide" : "dim";
36
+ const changed = state.focus?.name !== name || state.focus.others !== others;
37
+ state.focus = { name, others };
38
+ return { ok: true, group: name, count: found.satellites.count, changed };
39
+ }
40
+ /**
41
+ * The groups now set, in the order they were set, with the focus applied for reading. `placed` is 0 when the group is not drawn.
42
+ *
43
+ * @param state - The view's satellite state.
44
+ * @returns One row a group.
45
+ */
46
+ export function satelliteGroupRows(state) {
47
+ return [...state.groups].map(([name, group]) => {
48
+ const choice = satelliteEmphasis(name, group.visible, state.focus);
49
+ return { name, count: group.satellites.count, visible: group.visible, placed: choice.drawn ? (group.placed ?? 0) : 0, emphasis: choice.emphasis };
50
+ });
51
+ }
52
+ /** The greatest apogee a shell is pulled out to, in Earth radii. Past this, one far satellite would shrink the Earth instead of showing the group. */
53
+ export const SHELL_CAP = 8;
54
+ /**
55
+ * The shell of a group, in Earth radii from the Earth's centre: the greatest apogee of its element sets, from the mean motion (revolutions a day) and the eccentricity.
56
+ * One revolution a day is 6.62 Earth radii (Kepler's third law, an Earth of 6371 km). A group with no usable set is the Earth's own radius. The result is never above {@link SHELL_CAP}.
57
+ *
58
+ * @param sets - The group's element sets.
59
+ * @returns The shell, from 1 to 8.
60
+ */
61
+ export function shellRadiusOf(sets) {
62
+ let far = 1;
63
+ for (const set of sets) {
64
+ if (!(set.MEAN_MOTION > 0) || !Number.isFinite(set.ECCENTRICITY))
65
+ continue;
66
+ const apogee = 6.62 * (1 / set.MEAN_MOTION) ** (2 / 3) * (1 + Math.max(0, set.ECCENTRICITY));
67
+ if (Number.isFinite(apogee))
68
+ far = Math.max(far, apogee);
69
+ }
70
+ return Math.min(SHELL_CAP, far);
71
+ }
72
+ /** The space view's field of view, in degrees. The same number `fitDistance` uses. */
73
+ const FOV = 35;
74
+ const RAD = Math.PI / 180;
75
+ /** The camera's distance, in radii, at which a body of radius 1 fills `size` of the view's shorter side. The same sum as `fitDistance`. */
76
+ const fitDistance = (size, aspect) => {
77
+ const across = Math.max(0.02, Math.min(50, size)) * Math.min(1, Math.max(0.05, aspect));
78
+ return Math.sqrt(1 + 1 / (across * Math.tan((FOV / 2) * RAD)) ** 2);
79
+ };
80
+ /**
81
+ * The zoom that puts a shell of `shell` Earth radii inside the space view. At zoom 1 the Earth fills `earthSize` of the shorter side. The shell fills about 0.92 of that side.
82
+ *
83
+ * @param shell - The shell, in Earth radii.
84
+ * @param earthSize - The share of the shorter side the Earth fills at zoom 1.
85
+ * @param aspect - The view's width over its height.
86
+ * @param min - The least zoom the view allows.
87
+ * @param max - The greatest zoom the view allows.
88
+ * @returns The zoom.
89
+ */
90
+ export function zoomForPerspectiveShell(shell, earthSize, aspect, min, max) {
91
+ const wanted = Math.max(1.02, shell) * fitDistance(0.92, aspect);
92
+ return Math.min(max, Math.max(min, fitDistance(earthSize, aspect) / wanted));
93
+ }
94
+ /**
95
+ * The zoom that puts a shell of `shell` Earth radii inside the realistic Earth's picture. At zoom 1 the Earth and its glow fill the shorter side (the glow is 1.08 radii). The shell fills about 0.92 of that side.
96
+ *
97
+ * @param shell - The shell, in Earth radii.
98
+ * @param width - The view's width in CSS pixels.
99
+ * @param height - The view's height in CSS pixels.
100
+ * @param min - The least zoom the view allows.
101
+ * @param max - The greatest zoom the view allows.
102
+ * @returns The zoom.
103
+ */
104
+ export function zoomForOrthographicShell(shell, width, height, min, max) {
105
+ const shorter = Math.max(1, Math.min(width, height));
106
+ const discAt1 = Math.max(1, shorter / 2 / 1.08 - 1);
107
+ const halfAt1 = shorter / 2 / discAt1;
108
+ return Math.min(max, Math.max(min, (halfAt1 * 0.92) / Math.max(1.02, shell)));
109
+ }
@@ -1,6 +1,7 @@
1
1
  import type * as THREE from "three";
2
2
  import type { SatelliteRef, Satellites } from "../satellites/types.ts";
3
3
  import type { ThreeParts } from "../realistic/textures.ts";
4
+ import { type SatelliteFocus } from "./satellite-focus.ts";
4
5
  type Three = ThreeParts;
5
6
  /** How a group looks: the colour of its dots and their size in CSS pixels, and whether every orbit is drawn (only for a small group). */
6
7
  export interface SatelliteStyle {
@@ -11,6 +12,8 @@ export interface SatelliteStyle {
11
12
  export interface SatelliteGroupState extends SatelliteStyle {
12
13
  satellites: Satellites;
13
14
  visible: boolean;
15
+ /** How many of this group the last draw placed. 0 before the first draw and when the group is not drawn. */
16
+ placed?: number;
14
17
  }
15
18
  /** The part of the space view's model the satellites read and write. */
16
19
  export interface SatelliteState {
@@ -23,6 +26,8 @@ export interface SatelliteState {
23
26
  /** Written at each draw: satellites placed, whether the clock is too fast for the groups, and the milliseconds the last update took. */
24
27
  /** Colour each dot by its orbit class. Off by default: a group keeps the one colour it was given. */
25
28
  orbitTint: boolean;
29
+ /** One group shown on its own. `null` leaves every group as the page set it. */
30
+ focus: SatelliteFocus | null;
26
31
  drawn: {
27
32
  placed: number;
28
33
  segments: number;
@@ -61,8 +66,28 @@ export declare function pinPlan(count: number, next: number, elapsedMs: number):
61
66
  runs: [number, number][];
62
67
  next: number;
63
68
  };
69
+ /** An edge of the picture a satellite lies beyond. `null` when its place is inside the box. */
70
+ export type ScreenEdge = "top" | "right" | "bottom" | "left";
64
71
  /**
65
- * Where a satellite is on the screen now: in CSS pixels in the view's box, whether it can be seen (inside the box and not behind the Earth) and how high it is.
72
+ * Which edge of a box a point lies beyond. A corner goes to the edge it passes by more. Inside the box, `null`.
73
+ *
74
+ * @param x - CSS pixels from the left.
75
+ * @param y - CSS pixels from the top.
76
+ * @param width - The box width.
77
+ * @param height - The box height.
78
+ * @returns The edge, or `null` when the point is inside.
79
+ */
80
+ export declare function screenEdge(x: number, y: number, width: number, height: number): ScreenEdge | null;
81
+ /**
82
+ * Which edge a point lies beyond, from the camera's own axes: `x` to the right, `y` up. Used when the point is behind the camera, whose picture would otherwise mirror it.
83
+ *
84
+ * @param x - To the camera's right.
85
+ * @param y - Up, in the camera's axes.
86
+ * @returns The edge.
87
+ */
88
+ export declare function edgeBeyondCamera(x: number, y: number): ScreenEdge;
89
+ /**
90
+ * Where a satellite is on the screen now: in CSS pixels from the view's top left (which may lie outside the box), whether it can be seen, which edge it lies beyond, whether it is behind the camera, and how high it is.
66
91
  *
67
92
  * @example
68
93
  * ```ts
@@ -75,13 +100,17 @@ export declare function pinPlan(count: number, next: number, elapsedMs: number):
75
100
  export interface SatelliteScreen {
76
101
  x: number;
77
102
  y: number;
78
- /** Inside the box and in front of the Earth (not hidden by it). */
103
+ /** Inside the box, in front of the camera and not hidden by the Earth. */
79
104
  visible: boolean;
80
105
  /** Height above the mean Earth radius, in kilometres, at the moment drawn. */
81
106
  heightKm: number;
107
+ /** The edge the satellite lies beyond, or `null` when its place is inside the box. Behind the camera, the edge is the way it lies in the camera's own axes, not the mirrored picture. */
108
+ edge: ScreenEdge | null;
109
+ /** The satellite is behind the camera. The picture would put it on the opposite side, so `edge` is taken from the camera's own axes. */
110
+ behind: boolean;
82
111
  }
83
112
  export interface SatelliteLayer {
84
- /** Where one satellite of a shown group is on the screen as of the last update, or `null` when its group is not shown, it is not placed (its elements are too old) or it is behind the camera. */
113
+ /** Where one satellite of a shown group is on the screen as of the last update, or `null` when its group is not shown or it is not placed (its elements are too old). A satellite outside the picture or behind the camera is still returned, with `visible` false. */
85
114
  placeOf(ref: SatelliteRef, camera: THREE.Camera, size: {
86
115
  width: number;
87
116
  height: number;
@@ -1,5 +1,6 @@
1
1
  import { MAX_SATELLITE_SPEED } from "../satellites/limits.js";
2
- export const newSatelliteState = () => ({ groups: new Map(), selected: null, marked: new Set(), pinned: [], orbitTint: false, drawn: { placed: 0, segments: 0, tooFast: false, dotScale: 1, updateMs: 0, maxUpdateMs: 0, updates: 0, totalMs: 0 } });
2
+ import { satelliteEmphasis } from "./satellite-focus.js";
3
+ export const newSatelliteState = () => ({ groups: new Map(), selected: null, marked: new Set(), pinned: [], orbitTint: false, focus: null, drawn: { placed: 0, segments: 0, tooFast: false, dotScale: 1, updateMs: 0, maxUpdateMs: 0, updates: 0, totalMs: 0 } });
3
4
  /** The most orbits a group may draw all at once, one line each. */
4
5
  export const MAX_ORBIT_GROUP = 40;
5
6
  const ORBIT_POINTS = 120;
@@ -7,12 +8,13 @@ const ORBIT_REFRESH_GAME_MS = 30 * 60_000;
7
8
  const ORBIT_REFRESH_WALL_MS = 1000;
8
9
  const POINT_VERT = /* glsl */ `
9
10
  uniform float size;
11
+ uniform float groupDim;
10
12
  attribute float dim;
11
13
  attribute vec3 cls;
12
14
  varying float vDim;
13
15
  varying vec3 vCls;
14
16
  void main() {
15
- vDim = dim;
17
+ vDim = max(dim, groupDim);
16
18
  vCls = cls;
17
19
  gl_PointSize = size;
18
20
  gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
@@ -68,6 +70,40 @@ export function pinPlan(count, next, elapsedMs) {
68
70
  runs.push([0, slice - part]);
69
71
  return { runs, next: (first + slice) % count };
70
72
  }
73
+ /**
74
+ * Which edge of a box a point lies beyond. A corner goes to the edge it passes by more. Inside the box, `null`.
75
+ *
76
+ * @param x - CSS pixels from the left.
77
+ * @param y - CSS pixels from the top.
78
+ * @param width - The box width.
79
+ * @param height - The box height.
80
+ * @returns The edge, or `null` when the point is inside.
81
+ */
82
+ export function screenEdge(x, y, width, height) {
83
+ const left = Math.max(0, -x);
84
+ const right = Math.max(0, x - width);
85
+ const top = Math.max(0, -y);
86
+ const bottom = Math.max(0, y - height);
87
+ const dx = Math.max(left, right);
88
+ const dy = Math.max(top, bottom);
89
+ if (dx === 0 && dy === 0)
90
+ return null;
91
+ if (dx >= dy)
92
+ return left > 0 ? "left" : "right";
93
+ return top > 0 ? "top" : "bottom";
94
+ }
95
+ /**
96
+ * Which edge a point lies beyond, from the camera's own axes: `x` to the right, `y` up. Used when the point is behind the camera, whose picture would otherwise mirror it.
97
+ *
98
+ * @param x - To the camera's right.
99
+ * @param y - Up, in the camera's axes.
100
+ * @returns The edge.
101
+ */
102
+ export function edgeBeyondCamera(x, y) {
103
+ if (Math.abs(x) >= Math.abs(y))
104
+ return x < 0 ? "left" : "right";
105
+ return y >= 0 ? "top" : "bottom";
106
+ }
71
107
  export function createSatelliteLayer(three, scene, state, ratio) {
72
108
  if (!three.Points)
73
109
  throw new Error("Satellites need `Points` from three.js: add it to the parts the three loader hands over (see setThreeLoader)");
@@ -89,7 +125,7 @@ export function createSatelliteLayer(three, scene, state, ratio) {
89
125
  const ink = new three.Color();
90
126
  let basis = 0;
91
127
  let lastGame = 0;
92
- const selectedMaterial = new three.ShaderMaterial({ vertexShader: POINT_VERT, fragmentShader: POINT_FRAG, uniforms: { size: { value: 14 }, tint: { value: new three.Color("#ffffff") }, ring: { value: 1 }, byClass: { value: 0 } }, transparent: true, depthWrite: false });
128
+ const selectedMaterial = new three.ShaderMaterial({ vertexShader: POINT_VERT, fragmentShader: POINT_FRAG, uniforms: { size: { value: 14 }, tint: { value: new three.Color("#ffffff") }, ring: { value: 1 }, byClass: { value: 0 }, groupDim: { value: 0 } }, transparent: true, depthWrite: false });
93
129
  const selectedPosition = new Float32Array(3);
94
130
  const selectedGeometry = new three.BufferGeometry();
95
131
  selectedGeometry.setAttribute("position", new three.BufferAttribute(selectedPosition, 3));
@@ -190,7 +226,7 @@ export function createSatelliteLayer(three, scene, state, ratio) {
190
226
  const dim = new three.BufferAttribute(group.satellites.dimmed, 1);
191
227
  geometry.setAttribute("dim", dim);
192
228
  geometry.setAttribute("cls", new three.BufferAttribute(group.satellites.classColour, 3));
193
- const material = new three.ShaderMaterial({ vertexShader: POINT_VERT, fragmentShader: POINT_FRAG, uniforms: { size: { value: group.size * ratio() }, tint: { value: new three.Color(group.color) }, ring: { value: 0 }, byClass: { value: 0 } }, transparent: true, depthWrite: false });
229
+ const material = new three.ShaderMaterial({ vertexShader: POINT_VERT, fragmentShader: POINT_FRAG, uniforms: { size: { value: group.size * ratio() }, tint: { value: new three.Color(group.color) }, ring: { value: 0 }, byClass: { value: 0 }, groupDim: { value: 0 } }, transparent: true, depthWrite: false });
194
230
  const points = new Points(geometry, material);
195
231
  points.frustumCulled = false;
196
232
  points.renderOrder = 5;
@@ -234,15 +270,21 @@ export function createSatelliteLayer(three, scene, state, ratio) {
234
270
  if (entry.streak)
235
271
  entry.streak.geometry.getAttribute("color").needsUpdate = true;
236
272
  }
237
- const show = group.visible;
273
+ const choice = satelliteEmphasis(name, group.visible, state.focus);
274
+ const show = choice.drawn;
275
+ entry.material.uniforms["groupDim"].value = choice.dim;
238
276
  entry.points.visible = show;
239
277
  if (!show) {
278
+ group.placed = 0;
240
279
  if (entry.streak)
241
280
  entry.streak.visible = false;
242
281
  for (const line of entry.lines)
243
282
  line.loop.visible = false;
244
283
  continue;
245
284
  }
285
+ const dimmed = choice.dim > 0;
286
+ if (entry.streak)
287
+ entry.streak.material.opacity = dimmed ? 0.3 : 0.95;
246
288
  if (tooFast) {
247
289
  // pinned whole at the first frame and when the time jumped (a date typed in, a scrub), so a place is never turned across days; after that a slice a frame, each satellite again about once a second,
248
290
  // so SGP4 never runs for the whole group (17,000 satellites take about 12 ms) in one frame
@@ -274,6 +316,7 @@ export function createSatelliteLayer(three, scene, state, ratio) {
274
316
  for (const line of entry.lines)
275
317
  line.loop.visible = false;
276
318
  placed += n;
319
+ group.placed = n;
277
320
  if (entry.streak)
278
321
  segments += n;
279
322
  }
@@ -289,12 +332,18 @@ export function createSatelliteLayer(three, scene, state, ratio) {
289
332
  entry.dim.needsUpdate = true;
290
333
  }
291
334
  placed += group.satellites.placed;
335
+ group.placed = group.satellites.placed;
292
336
  orbitsOf(entry, group, time, started);
337
+ const opacity = dimmed ? 0.15 : 0.45;
338
+ for (const line of entry.lines)
339
+ line.loop.material.opacity = opacity;
293
340
  }
294
341
  }
295
342
  const chosen = state.selected;
343
+ const chosenGroup = chosen ? state.groups.get(chosen.group) : undefined;
344
+ const chosenDrawn = chosen !== null && chosenGroup !== undefined && satelliteEmphasis(chosen.group, chosenGroup.visible, state.focus).drawn;
296
345
  const set = chosen ? find(chosen) : undefined;
297
- if (chosen && set && set.exact(chosen.index, time, tmp)) {
346
+ if (chosen && set && chosenDrawn && set.exact(chosen.index, time, tmp)) {
298
347
  selectedPosition[0] = tmp[0];
299
348
  selectedPosition[1] = tmp[1];
300
349
  selectedPosition[2] = tmp[2];
@@ -397,32 +446,49 @@ export function createSatelliteLayer(three, scene, state, ratio) {
397
446
  const i = ref.index * 3;
398
447
  world.set(p[i], p[i + 1], p[i + 2]).applyMatrix4(scene.matrixWorld);
399
448
  const heightKm = (Math.hypot(p[i], p[i + 1], p[i + 2]) - 1) * 6371;
400
- projected.copy(world).project(camera);
401
- if (projected.z > 1 || projected.z < -1)
402
- return null;
403
- const x = ((projected.x + 1) / 2) * size.width;
404
- const y = ((1 - projected.y) / 2) * size.height;
449
+ // the camera looks down its own -z, so a point in front has a negative z. A point behind would be mirrored by the picture, so its edge is read from these axes.
450
+ view.copy(world).applyMatrix4(camera.matrixWorldInverse);
405
451
  const ortho = camera.isOrthographicCamera === true;
406
- const c = camera.position;
407
- let hidden;
408
- if (ortho) {
409
- const centreDepth = view.set(0, 0, 0).applyMatrix4(camera.matrixWorldInverse).z;
410
- view.copy(world).applyMatrix4(camera.matrixWorldInverse);
411
- hidden = view.z < centreDepth && view.x * view.x + view.y * view.y < 0.996;
452
+ const behind = !ortho && view.z > 0;
453
+ projected.copy(world).project(camera);
454
+ let x = Number.isFinite(projected.x) ? ((projected.x + 1) / 2) * size.width : size.width / 2;
455
+ let y = Number.isFinite(projected.y) ? ((1 - projected.y) / 2) * size.height : size.height / 2;
456
+ const edge = behind ? edgeBeyondCamera(view.x, view.y) : screenEdge(x, y, size.width, size.height);
457
+ if (behind) {
458
+ if (edge === "left")
459
+ x = -1;
460
+ else if (edge === "right")
461
+ x = size.width + 1;
462
+ else if (edge === "top")
463
+ y = -1;
464
+ else
465
+ y = size.height + 1;
412
466
  }
413
- else {
414
- // behind the Earth: the line from the camera to the satellite passes through the unit sphere before it gets there
415
- const px = world.x - c.x;
416
- const py = world.y - c.y;
417
- const pz = world.z - c.z;
418
- const len2 = px * px + py * py + pz * pz;
419
- const t = Math.max(0, Math.min(1, -(c.x * px + c.y * py + c.z * pz) / len2));
420
- const nx = c.x + px * t;
421
- const ny = c.y + py * t;
422
- const nz = c.z + pz * t;
423
- hidden = nx * nx + ny * ny + nz * nz < 0.998;
467
+ const c = camera.position;
468
+ let hidden = false;
469
+ if (!behind) {
470
+ if (ortho) {
471
+ const right = view.x;
472
+ const up = view.y;
473
+ const depth = view.z;
474
+ const centreDepth = world.set(0, 0, 0).applyMatrix4(camera.matrixWorldInverse).z;
475
+ hidden = depth < centreDepth && right * right + up * up < 0.996;
476
+ world.set(p[i], p[i + 1], p[i + 2]).applyMatrix4(scene.matrixWorld);
477
+ }
478
+ else {
479
+ // behind the Earth: the line from the camera to the satellite passes through the unit sphere before it gets there
480
+ const px = world.x - c.x;
481
+ const py = world.y - c.y;
482
+ const pz = world.z - c.z;
483
+ const len2 = px * px + py * py + pz * pz;
484
+ const t = Math.max(0, Math.min(1, -(c.x * px + c.y * py + c.z * pz) / len2));
485
+ const nx = c.x + px * t;
486
+ const ny = c.y + py * t;
487
+ const nz = c.z + pz * t;
488
+ hidden = nx * nx + ny * ny + nz * nz < 0.998;
489
+ }
424
490
  }
425
- return { x, y, visible: !hidden && x >= 0 && x <= size.width && y >= 0 && y <= size.height, heightKm };
491
+ return { x, y, visible: !behind && !hidden && edge === null, heightKm, edge, behind };
426
492
  },
427
493
  place(camera, size) {
428
494
  if (!selectedPoints.visible)
@@ -7,7 +7,7 @@ import type { LightMode } from "../realistic/earth.ts";
7
7
  import { type Frame, type PlanetName, type Vec3 } from "./ephemeris.ts";
8
8
  import { type ScaleMode } from "./scale.ts";
9
9
  import type { SatelliteRef } from "../satellites/types.ts";
10
- import { type RideFace, type RideLook } from "./ride.ts";
10
+ import { type RideFace, type RideLook, type RideViewpoint } from "./ride.ts";
11
11
  import type { SkyFrame } from "../sky/frame.ts";
12
12
  import type { PlaceView } from "../markers/places.ts";
13
13
  import { type PlaceSpriteData } from "../markers/place-sprites.ts";
@@ -107,6 +107,8 @@ export interface RideState {
107
107
  face: RideFace | null;
108
108
  /** For `follow` a satellite: how far the camera keeps, in kilometres. */
109
109
  distanceKm: number;
110
+ /** `outside`: a ridden satellite is in the picture (the camera a little behind and above it in `from`, a drawing of it where the page has no model); `inside`: as a ride was before, the camera at the satellite and no drawing of it where the page has no model. */
111
+ viewpoint: RideViewpoint;
110
112
  }
111
113
  /** The camera as the last draw left it, for the next one to start from when the ride changes. */
112
114
  export interface Pose {