@johnmorrisdotca/chikyu-earth 0.42.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 +5 -0
- package/README.md +1 -1
- package/dist/realistic/element-base.d.ts +26 -1
- package/dist/realistic/element-base.js +69 -4
- package/dist/space/element-base.d.ts +29 -10
- package/dist/space/element-base.js +71 -6
- package/dist/space/satellite-focus.d.ts +90 -0
- package/dist/space/satellite-focus.js +109 -0
- package/dist/space/satellite-layer.d.ts +32 -3
- package/dist/space/satellite-layer.js +95 -29
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.43.0 - 2026-11-13
|
|
4
|
+
|
|
5
|
+
- **One satellite group at a time** (MODULES-1215). `focusSatelliteGroup(name, options)` on `<chikyu-space>` and `<chikyu-earth-realistic>` shows one group that has been set and deals with the others: `others` is `"dim"` (the default; the same dimming an old element set uses, so no new object) or `"hide"`. `frame` (true by default) pulls the camera back with the view's own zoom until the group's orbits fit. The distance is the greatest apogee, from mean motion and eccentricity, and it stops at 8 Earth radii. `null` restores each group's own shown state and the camera. A group that has not been set returns `{ ok: false, reason: "not-set" }` and changes nothing. `focusedSatelliteGroup` is the name or `null`. `satelliteGroups` adds `emphasis` and `placed`, and keeps `count`. `chikyu-satellite-focus` is sent with `{ group, count }` when the choice changes. The demo has a row, "One group". Nothing is drawn at rest.
|
|
6
|
+
- **A ring appears when the satellite comes into the picture** (MODULES-1213). `ringSatellites` keeps the satellites it was asked to ring. One that is outside the picture gets its ring on the first later draw that shows it, and nothing is drawn at rest just to wait. `placeSatellite` adds `edge` (`"top"`, `"right"`, `"bottom"`, `"left"` or `null`) and `behind` (true when the satellite is behind the camera), and no longer answers `null` for a satellite that is merely out of the picture: it returns the place outside the picture, so check `.visible`.
|
|
7
|
+
|
|
3
8
|
## 0.42.0 - 2026-11-13
|
|
4
9
|
|
|
5
10
|
- **The "you are here" marker can take the nearest city's name** (MODULES-1077). `here-city` on `<chikyu-space>` and `<chikyu-earth-realistic>` (off by default; the property `hereCity` is `false`, `true` or a number of kilometres) names each `kind: "here"` place with the nearest city within 100 km (`HERE_CITY_KM`; a number on the attribute is that limit, at most 20,000). The name follows the page's language. The cities are kuni's capitals, the other cities of a million and the others of 100,000, loaded only when this is on and a `here` place is set; a smaller town keeps the label the page gave. `places` itself is not changed. Nothing is drawn again at rest.
|
package/README.md
CHANGED
|
@@ -611,7 +611,7 @@ console.log(countryList().filter((country) => country.alpha2 === null).map((coun
|
|
|
611
611
|
|
|
612
612
|
## How to cite
|
|
613
613
|
|
|
614
|
-
> Morris, J. (2026). *Chikyu Earth* (version 0.
|
|
614
|
+
> Morris, J. (2026). *Chikyu Earth* (version 0.43.0) [Computer software]. https://github.com/johnmorrisdotca/chikyu-earth
|
|
615
615
|
|
|
616
616
|
GitHub's "Cite this repository" button reads [CITATION.cff](CITATION.cff) and gives BibTeX and APA. Cite the version you used (`npm ls @johnmorrisdotca/chikyu-earth`), and credit the sources behind the numbers and pictures: [NOTICE.md](NOTICE.md) says who made each one and under what terms.
|
|
617
617
|
|
|
@@ -4,6 +4,7 @@ import { type CameraMode, type LightMode } from "./earth.ts";
|
|
|
4
4
|
import { type PaintSpec } from "../paint/buffer.ts";
|
|
5
5
|
import type { SatelliteInfo, SatelliteRef, Satellites } from "../satellites/types.ts";
|
|
6
6
|
import { type SatelliteStyle } from "../space/satellite-layer.ts";
|
|
7
|
+
import { type SatelliteOthers } from "../space/satellite-focus.ts";
|
|
7
8
|
import type { Credit, DataSource } from "../data-door.ts";
|
|
8
9
|
import { type BodyLabelSettings } from "./body-label.ts";
|
|
9
10
|
import type { SkyKeepClear } from "../sky/keep-clear.ts";
|
|
@@ -462,12 +463,36 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
|
|
|
462
463
|
setSatellites(group: string, satellites: Satellites | null, style?: Partial<SatelliteStyle>): void;
|
|
463
464
|
/** Show or hide a group without losing it. */
|
|
464
465
|
showSatellites(group: string, on: boolean): void;
|
|
465
|
-
/**
|
|
466
|
+
/**
|
|
467
|
+
* The groups now set. `count` is how many satellites the group holds, `visible` is the shown state from `showSatellites` (a focus does not change it), `placed` is how many the last draw placed (0 when the group is not drawn) and `emphasis` is how a focus treats it: `focus`, `dim`, `hidden` or `plain` (no focus).
|
|
468
|
+
*/
|
|
466
469
|
get satelliteGroups(): {
|
|
467
470
|
name: string;
|
|
468
471
|
count: number;
|
|
469
472
|
visible: boolean;
|
|
473
|
+
placed: number;
|
|
474
|
+
emphasis: "focus" | "dim" | "hidden" | "plain";
|
|
470
475
|
}[];
|
|
476
|
+
/** The group `focusSatelliteGroup` is showing on its own, or `null`. */
|
|
477
|
+
get focusedSatelliteGroup(): string | null;
|
|
478
|
+
/**
|
|
479
|
+
* Show one group on its own. The others are drawn dimmer (`others: "dim"`, the default, through the same dimming an old element set uses) or not drawn (`"hide"`). `frame` (true by default) pulls the camera back, by this view's own zoom, until the group's orbits fit: the distance is the greatest apogee of the group, from each satellite's mean motion and eccentricity, and it stops at 8 Earth radii. `null` puts every group back to the shown state it had, and puts the camera back when it was moved. A name that `setSatellites` has not set returns `{ ok: false, reason: "not-set" }` and changes nothing. It does not throw. When the choice changes, `chikyu-satellite-focus` is sent with `{ group, count }`.
|
|
480
|
+
*
|
|
481
|
+
* @param name - The group's name, or `null` to clear the focus.
|
|
482
|
+
* @param options - `others` and `frame`.
|
|
483
|
+
* @returns `{ ok: true, group, count }` when the group is set (`group` is `null` and `count` is 0 when cleared). `{ ok: false, reason: "not-set" }` when it is not.
|
|
484
|
+
*/
|
|
485
|
+
focusSatelliteGroup(name: string | null, options?: {
|
|
486
|
+
others?: SatelliteOthers;
|
|
487
|
+
frame?: boolean;
|
|
488
|
+
}): {
|
|
489
|
+
ok: true;
|
|
490
|
+
group: string | null;
|
|
491
|
+
count: number;
|
|
492
|
+
} | {
|
|
493
|
+
ok: false;
|
|
494
|
+
reason: "not-set";
|
|
495
|
+
};
|
|
471
496
|
/** Mark one satellite: a larger ring round it and its orbit drawn. `null` lets it go. */
|
|
472
497
|
selectSatellite(ref: SatelliteRef | null): void;
|
|
473
498
|
/** The satellite marked by `selectSatellite` or by a press on it, if any. */
|
|
@@ -9,6 +9,7 @@ import { NOTES_STYLE, setAirNote } from "./air-note.js";
|
|
|
9
9
|
import { cameraCentre, createEarthItem, discRadius, lookAt, newModel } from "./earth.js";
|
|
10
10
|
import { createPaintState, paintedGround, paintedPeriod } from "../paint/buffer.js";
|
|
11
11
|
import { MAX_ORBIT_GROUP } from "../space/satellite-layer.js";
|
|
12
|
+
import { applySatelliteFocus, satelliteEmphasis, satelliteGroupRows, shellRadiusOf, zoomForOrthographicShell } from "../space/satellite-focus.js";
|
|
12
13
|
import { readMeteorStrength } from "../meteors/strength.js";
|
|
13
14
|
import { METEOR_NOTE_STYLE, prefersLessMotion, setMeteorNote } from "../meteors/note.js";
|
|
14
15
|
import { createDoorHost } from "../door/host.js";
|
|
@@ -199,6 +200,8 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
199
200
|
/** Counts the turns to a place, so a new one stops the one before. */
|
|
200
201
|
#placeGlide = 0;
|
|
201
202
|
#hands;
|
|
203
|
+
/** The view from before a satellite group was framed, put back when the focus is cleared. */
|
|
204
|
+
#focusView = null;
|
|
202
205
|
#reach = null;
|
|
203
206
|
/** The page has set a `speed` since the element came into the page: for a reader who prefers reduced motion, that is the Play that lets meteors start. */
|
|
204
207
|
#played = false;
|
|
@@ -1161,6 +1164,11 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
1161
1164
|
groups.delete(group);
|
|
1162
1165
|
if (this.#model.satellites.selected?.group === group)
|
|
1163
1166
|
this.#model.satellites.selected = null;
|
|
1167
|
+
if (this.#model.satellites.focus?.name === group) {
|
|
1168
|
+
this.#model.satellites.focus = null;
|
|
1169
|
+
this.#restoreFocusView();
|
|
1170
|
+
this.dispatchEvent(new CustomEvent("chikyu-satellite-focus", { detail: { group: null, count: 0 }, bubbles: true, composed: true }));
|
|
1171
|
+
}
|
|
1164
1172
|
}
|
|
1165
1173
|
else {
|
|
1166
1174
|
const was = groups.get(group);
|
|
@@ -1185,9 +1193,66 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
1185
1193
|
this.#startTick();
|
|
1186
1194
|
this.#gate?.soon();
|
|
1187
1195
|
}
|
|
1188
|
-
/**
|
|
1196
|
+
/**
|
|
1197
|
+
* The groups now set. `count` is how many satellites the group holds, `visible` is the shown state from `showSatellites` (a focus does not change it), `placed` is how many the last draw placed (0 when the group is not drawn) and `emphasis` is how a focus treats it: `focus`, `dim`, `hidden` or `plain` (no focus).
|
|
1198
|
+
*/
|
|
1189
1199
|
get satelliteGroups() {
|
|
1190
|
-
return
|
|
1200
|
+
return satelliteGroupRows(this.#model.satellites);
|
|
1201
|
+
}
|
|
1202
|
+
/** The group `focusSatelliteGroup` is showing on its own, or `null`. */
|
|
1203
|
+
get focusedSatelliteGroup() {
|
|
1204
|
+
return this.#model.satellites.focus?.name ?? null;
|
|
1205
|
+
}
|
|
1206
|
+
/**
|
|
1207
|
+
* Show one group on its own. The others are drawn dimmer (`others: "dim"`, the default, through the same dimming an old element set uses) or not drawn (`"hide"`). `frame` (true by default) pulls the camera back, by this view's own zoom, until the group's orbits fit: the distance is the greatest apogee of the group, from each satellite's mean motion and eccentricity, and it stops at 8 Earth radii. `null` puts every group back to the shown state it had, and puts the camera back when it was moved. A name that `setSatellites` has not set returns `{ ok: false, reason: "not-set" }` and changes nothing. It does not throw. When the choice changes, `chikyu-satellite-focus` is sent with `{ group, count }`.
|
|
1208
|
+
*
|
|
1209
|
+
* @param name - The group's name, or `null` to clear the focus.
|
|
1210
|
+
* @param options - `others` and `frame`.
|
|
1211
|
+
* @returns `{ ok: true, group, count }` when the group is set (`group` is `null` and `count` is 0 when cleared). `{ ok: false, reason: "not-set" }` when it is not.
|
|
1212
|
+
*/
|
|
1213
|
+
focusSatelliteGroup(name, options = {}) {
|
|
1214
|
+
const answer = applySatelliteFocus(this.#model.satellites, name, options);
|
|
1215
|
+
if (!answer.ok || answer.group === undefined || answer.count === undefined)
|
|
1216
|
+
return { ok: false, reason: "not-set" };
|
|
1217
|
+
if (answer.group === null)
|
|
1218
|
+
this.#restoreFocusView();
|
|
1219
|
+
else if (options.frame !== false)
|
|
1220
|
+
this.#frameSatelliteShell(answer.group);
|
|
1221
|
+
if (answer.changed)
|
|
1222
|
+
this.dispatchEvent(new CustomEvent("chikyu-satellite-focus", { detail: { group: answer.group, count: answer.count }, bubbles: true, composed: true }));
|
|
1223
|
+
// which groups are drawn decides how often time is drawn, so the next step is worked out again, as for `showSatellites`
|
|
1224
|
+
this.#startTick();
|
|
1225
|
+
this.#gate?.soon();
|
|
1226
|
+
return { ok: true, group: answer.group, count: answer.count };
|
|
1227
|
+
}
|
|
1228
|
+
/** The view's own zoom, far enough that the group's shell fills the picture, with the Earth back in the middle. */
|
|
1229
|
+
#frameSatelliteShell(name) {
|
|
1230
|
+
const group = this.#model.satellites.groups.get(name);
|
|
1231
|
+
if (!group)
|
|
1232
|
+
return;
|
|
1233
|
+
const box = this.getBoundingClientRect();
|
|
1234
|
+
if (box.width < 2 || box.height < 2)
|
|
1235
|
+
return;
|
|
1236
|
+
if (!this.#focusView)
|
|
1237
|
+
this.#focusView = { ...this.#model.view };
|
|
1238
|
+
const zoom = zoomForOrthographicShell(shellRadiusOf(group.satellites.sets), box.width, box.height, LIMITS.zoomMin, LIMITS.zoomMax);
|
|
1239
|
+
this.#applyCamera({ ...this.#model.view, zoom, panX: 0, panY: 0 });
|
|
1240
|
+
}
|
|
1241
|
+
/** Put back the view from before the shell was framed. */
|
|
1242
|
+
#restoreFocusView() {
|
|
1243
|
+
const saved = this.#focusView;
|
|
1244
|
+
this.#focusView = null;
|
|
1245
|
+
if (saved)
|
|
1246
|
+
this.#applyCamera(saved);
|
|
1247
|
+
}
|
|
1248
|
+
/** Hand a camera to the controls that are driving the view, or to the view itself when those are not there yet. */
|
|
1249
|
+
#applyCamera(view) {
|
|
1250
|
+
const bar = this.hasAttribute("data-kazoku-bar") && this.id ? this.getRootNode().querySelector?.(`kazoku-view-controls[for="${CSS.escape(this.id)}"]`) : null;
|
|
1251
|
+
const controls = (bar ? Reflect.get(bar, "controller") : undefined) ?? this.#hands?.controller;
|
|
1252
|
+
if (controls)
|
|
1253
|
+
controls.set(view, true, "satellites");
|
|
1254
|
+
else
|
|
1255
|
+
this.setView(view, true);
|
|
1191
1256
|
}
|
|
1192
1257
|
/** Mark one satellite: a larger ring round it and its orbit drawn. `null` lets it go. */
|
|
1193
1258
|
selectSatellite(ref) {
|
|
@@ -1266,8 +1331,8 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
1266
1331
|
}
|
|
1267
1332
|
/** Is anything on show that moves faster than the Earth turns: a group of satellites, including above the interpolation limit where they are drawn as streaks? */
|
|
1268
1333
|
#satellitesMoving() {
|
|
1269
|
-
for (const group of this.#model.satellites.groups
|
|
1270
|
-
if (group.visible && group.satellites.count > 0)
|
|
1334
|
+
for (const [name, group] of this.#model.satellites.groups)
|
|
1335
|
+
if (satelliteEmphasis(name, group.visible, this.#model.satellites.focus).drawn && group.satellites.count > 0)
|
|
1271
1336
|
return true;
|
|
1272
1337
|
return false;
|
|
1273
1338
|
}
|
|
@@ -15,7 +15,8 @@ import { setThreeLoader } from "../realistic/shared.ts";
|
|
|
15
15
|
import type { LightMode } from "../realistic/earth.ts";
|
|
16
16
|
import type { SatelliteInfo, SatelliteRef, Satellites } from "../satellites/types.ts";
|
|
17
17
|
import { type PlanetName } from "./ephemeris.ts";
|
|
18
|
-
import { type SatelliteStyle } from "./satellite-layer.ts";
|
|
18
|
+
import { type SatelliteScreen, type SatelliteStyle } from "./satellite-layer.ts";
|
|
19
|
+
import { type SatelliteOthers } from "./satellite-focus.ts";
|
|
19
20
|
import { type RideFace, type RideLook } from "./ride.ts";
|
|
20
21
|
import { type ScaleMode } from "./scale.ts";
|
|
21
22
|
import { BODY_NAMES, type CameraMode, type BodyName, type BodyPainter, type RideTarget, type SatellitePainter } from "./scene.ts";
|
|
@@ -482,12 +483,36 @@ export declare class ChikyuSpace extends HTMLElement {
|
|
|
482
483
|
setSatellites(group: string, satellites: Satellites | null, style?: Partial<SatelliteStyle>): void;
|
|
483
484
|
/** Show or hide a group without losing it. */
|
|
484
485
|
showSatellites(group: string, on: boolean): void;
|
|
485
|
-
/**
|
|
486
|
+
/**
|
|
487
|
+
* The groups now set. `count` is how many satellites the group holds, `visible` is the shown state from `showSatellites` (a focus does not change it), `placed` is how many the last draw placed (0 when the group is not drawn) and `emphasis` is how a focus treats it: `focus`, `dim`, `hidden` or `plain` (no focus).
|
|
488
|
+
*/
|
|
486
489
|
get satelliteGroups(): {
|
|
487
490
|
name: string;
|
|
488
491
|
count: number;
|
|
489
492
|
visible: boolean;
|
|
493
|
+
placed: number;
|
|
494
|
+
emphasis: "focus" | "dim" | "hidden" | "plain";
|
|
490
495
|
}[];
|
|
496
|
+
/** The group `focusSatelliteGroup` is showing on its own, or `null`. */
|
|
497
|
+
get focusedSatelliteGroup(): string | null;
|
|
498
|
+
/**
|
|
499
|
+
* Show one group on its own. The others are drawn dimmer (`others: "dim"`, the default, through the same dimming an old element set uses) or not drawn (`"hide"`). `frame` (true by default) pulls the camera back, by this view's own zoom, until the group's orbits fit: the distance is the greatest apogee of the group, from each satellite's mean motion and eccentricity, and it stops at 8 Earth radii. `null` puts every group back to the shown state it had, and puts the camera back when it was moved. A name that `setSatellites` has not set returns `{ ok: false, reason: "not-set" }` and changes nothing. It does not throw. When the choice changes, `chikyu-satellite-focus` is sent with `{ group, count }`.
|
|
500
|
+
*
|
|
501
|
+
* @param name - The group's name, or `null` to clear the focus.
|
|
502
|
+
* @param options - `others` and `frame`.
|
|
503
|
+
* @returns `{ ok: true, group, count }` when the group is set (`group` is `null` and `count` is 0 when cleared). `{ ok: false, reason: "not-set" }` when it is not.
|
|
504
|
+
*/
|
|
505
|
+
focusSatelliteGroup(name: string | null, options?: {
|
|
506
|
+
others?: SatelliteOthers;
|
|
507
|
+
frame?: boolean;
|
|
508
|
+
}): {
|
|
509
|
+
ok: true;
|
|
510
|
+
group: string | null;
|
|
511
|
+
count: number;
|
|
512
|
+
} | {
|
|
513
|
+
ok: false;
|
|
514
|
+
reason: "not-set";
|
|
515
|
+
};
|
|
491
516
|
/** Mark one satellite: a larger ring round it, its orbit drawn, and its name beside it. `null` lets it go. */
|
|
492
517
|
selectSatellite(ref: SatelliteRef | null): void;
|
|
493
518
|
/** The satellite marked by `selectSatellite` or by a press on it, if any. */
|
|
@@ -515,15 +540,9 @@ export declare class ChikyuSpace extends HTMLElement {
|
|
|
515
540
|
get satelliteNames(): Record<number, string>;
|
|
516
541
|
set satelliteNames(value: Record<number, string>);
|
|
517
542
|
/**
|
|
518
|
-
* Where a satellite is on the screen as of the last draw: `{ x, y, visible, heightKm }` in CSS pixels from the view's top left
|
|
519
|
-
* placed (its elements are too old), or it is behind the camera. It is the picture's own camera maths and its own test for the Earth in the way, so a page that draws its own rings need not repeat either.
|
|
543
|
+
* Where a satellite is on the screen as of the last draw: `{ x, y, visible, heightKm, edge, behind }` in CSS pixels from the view's top left. `visible` means it is inside the box, in front of the camera and not behind the Earth. `edge` is `top`, `right`, `bottom` or `left` when the place lies beyond that edge, and `null` when it is inside the box. `behind` is true when it is behind the camera (the picture would mirror it, so `edge` is read from the camera's own axes). `x` and `y` may lie outside the box. `null` when its group is not set or not shown, or it cannot be placed (its elements are too old). It is the picture's own camera maths and its own test for the Earth in the way, so a page that draws its own rings, or a mark on the edge, need not repeat either.
|
|
520
544
|
*/
|
|
521
|
-
placeSatellite(ref: SatelliteRef):
|
|
522
|
-
x: number;
|
|
523
|
-
y: number;
|
|
524
|
-
visible: boolean;
|
|
525
|
-
heightKm: number;
|
|
526
|
-
} | null;
|
|
545
|
+
placeSatellite(ref: SatelliteRef): SatelliteScreen | null;
|
|
527
546
|
/** Facts about one satellite at the moment shown (name, number, element age, height, speed, period, and `ownerCountry` when the owner is one country); undefined if it cannot be placed then. */
|
|
528
547
|
satelliteInfo(ref: SatelliteRef): SatelliteInfo | undefined;
|
|
529
548
|
/** The words shown beside each body, for a page in another language (`{ Mars: "火星" }`). A body left out keeps its English name. */
|
|
@@ -27,6 +27,7 @@ import { METEOR_NOTE_STYLE, prefersLessMotion, setMeteorNote } from "../meteors/
|
|
|
27
27
|
import { MAX_TEXTURE } from "../realistic/tiers.js";
|
|
28
28
|
import { AU_IN_EARTH_RADII, EARTH_RADIUS_KM, frameAt } from "./ephemeris.js";
|
|
29
29
|
import { MAX_ORBIT_GROUP } from "./satellite-layer.js";
|
|
30
|
+
import { applySatelliteFocus, satelliteEmphasis, satelliteGroupRows, shellRadiusOf, zoomForPerspectiveShell } from "./satellite-focus.js";
|
|
30
31
|
import { RIDE_FACES, rideTiltLimits, rideTurnDegrees } from "./ride.js";
|
|
31
32
|
import { placeAround, placeMoon, placeSun, RADIUS } from "./scale.js";
|
|
32
33
|
import { BODY_NAMES, createSpaceItem, DEFAULT_EARTH_SIZE, newSpaceModel } from "./scene.js";
|
|
@@ -193,6 +194,8 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
193
194
|
#places;
|
|
194
195
|
#chosenLabel;
|
|
195
196
|
#focusBeforeRide = "Earth";
|
|
197
|
+
/** The yaw, tilt and zoom from before a satellite group was framed, put back when the focus is cleared. */
|
|
198
|
+
#focusView = null;
|
|
196
199
|
#lostTold = false;
|
|
197
200
|
#names = {};
|
|
198
201
|
#hint = "choose to look at it";
|
|
@@ -1352,6 +1355,11 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
1352
1355
|
groups.delete(group);
|
|
1353
1356
|
if (this.#model.satellites.selected?.group === group)
|
|
1354
1357
|
this.#model.satellites.selected = null;
|
|
1358
|
+
if (this.#model.satellites.focus?.name === group) {
|
|
1359
|
+
this.#model.satellites.focus = null;
|
|
1360
|
+
this.#restoreFocusView();
|
|
1361
|
+
this.dispatchEvent(new CustomEvent("chikyu-satellite-focus", { detail: { group: null, count: 0 }, bubbles: true, composed: true }));
|
|
1362
|
+
}
|
|
1355
1363
|
}
|
|
1356
1364
|
else {
|
|
1357
1365
|
const was = groups.get(group);
|
|
@@ -1378,9 +1386,67 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
1378
1386
|
this.#schedule();
|
|
1379
1387
|
this.#gate?.request();
|
|
1380
1388
|
}
|
|
1381
|
-
/**
|
|
1389
|
+
/**
|
|
1390
|
+
* The groups now set. `count` is how many satellites the group holds, `visible` is the shown state from `showSatellites` (a focus does not change it), `placed` is how many the last draw placed (0 when the group is not drawn) and `emphasis` is how a focus treats it: `focus`, `dim`, `hidden` or `plain` (no focus).
|
|
1391
|
+
*/
|
|
1382
1392
|
get satelliteGroups() {
|
|
1383
|
-
return
|
|
1393
|
+
return satelliteGroupRows(this.#model.satellites);
|
|
1394
|
+
}
|
|
1395
|
+
/** The group `focusSatelliteGroup` is showing on its own, or `null`. */
|
|
1396
|
+
get focusedSatelliteGroup() {
|
|
1397
|
+
return this.#model.satellites.focus?.name ?? null;
|
|
1398
|
+
}
|
|
1399
|
+
/**
|
|
1400
|
+
* Show one group on its own. The others are drawn dimmer (`others: "dim"`, the default, through the same dimming an old element set uses) or not drawn (`"hide"`). `frame` (true by default) pulls the camera back, by this view's own zoom, until the group's orbits fit: the distance is the greatest apogee of the group, from each satellite's mean motion and eccentricity, and it stops at 8 Earth radii. `null` puts every group back to the shown state it had, and puts the camera back when it was moved. A name that `setSatellites` has not set returns `{ ok: false, reason: "not-set" }` and changes nothing. It does not throw. When the choice changes, `chikyu-satellite-focus` is sent with `{ group, count }`.
|
|
1401
|
+
*
|
|
1402
|
+
* @param name - The group's name, or `null` to clear the focus.
|
|
1403
|
+
* @param options - `others` and `frame`.
|
|
1404
|
+
* @returns `{ ok: true, group, count }` when the group is set (`group` is `null` and `count` is 0 when cleared). `{ ok: false, reason: "not-set" }` when it is not.
|
|
1405
|
+
*/
|
|
1406
|
+
focusSatelliteGroup(name, options = {}) {
|
|
1407
|
+
const answer = applySatelliteFocus(this.#model.satellites, name, options);
|
|
1408
|
+
if (!answer.ok || answer.group === undefined || answer.count === undefined)
|
|
1409
|
+
return { ok: false, reason: "not-set" };
|
|
1410
|
+
if (answer.group === null)
|
|
1411
|
+
this.#restoreFocusView();
|
|
1412
|
+
else if (options.frame !== false)
|
|
1413
|
+
this.#frameSatelliteShell(answer.group);
|
|
1414
|
+
if (answer.changed)
|
|
1415
|
+
this.dispatchEvent(new CustomEvent("chikyu-satellite-focus", { detail: { group: answer.group, count: answer.count }, bubbles: true, composed: true }));
|
|
1416
|
+
// which groups are drawn decides how often time is drawn, so the next step is worked out again, as for `showSatellites`
|
|
1417
|
+
this.#schedule();
|
|
1418
|
+
this.#gate?.request();
|
|
1419
|
+
return { ok: true, group: answer.group, count: answer.count };
|
|
1420
|
+
}
|
|
1421
|
+
/** The view's own zoom, far enough that the group's shell fills the picture. A ride is left, because the camera has to look at the Earth to see the shell. */
|
|
1422
|
+
#frameSatelliteShell(name) {
|
|
1423
|
+
const group = this.#model.satellites.groups.get(name);
|
|
1424
|
+
if (!group)
|
|
1425
|
+
return;
|
|
1426
|
+
const box = this.getBoundingClientRect();
|
|
1427
|
+
if (box.width < 2 || box.height < 2)
|
|
1428
|
+
return;
|
|
1429
|
+
if (!this.#focusView)
|
|
1430
|
+
this.#focusView = { yaw: this.#model.view.yaw, tilt: this.#model.view.tilt, zoom: this.#model.view.zoom };
|
|
1431
|
+
if (this.#model.ride)
|
|
1432
|
+
this.ride(null);
|
|
1433
|
+
const zoom = zoomForPerspectiveShell(shellRadiusOf(group.satellites.sets), this.earthSize, box.width / box.height, LIMITS.zoomMin, LIMITS.zoomMax);
|
|
1434
|
+
this.#moveView({ yaw: this.#model.view.yaw, tilt: this.#model.view.tilt, zoom });
|
|
1435
|
+
}
|
|
1436
|
+
/** Put back the yaw, tilt and zoom from before the shell was framed. */
|
|
1437
|
+
#restoreFocusView() {
|
|
1438
|
+
const saved = this.#focusView;
|
|
1439
|
+
this.#focusView = null;
|
|
1440
|
+
if (saved)
|
|
1441
|
+
this.#moveView(saved);
|
|
1442
|
+
}
|
|
1443
|
+
/** Hand a camera to the controls that are driving the view, or to the view itself when those are not there yet. */
|
|
1444
|
+
#moveView(view) {
|
|
1445
|
+
const controls = this.#controls();
|
|
1446
|
+
if (controls)
|
|
1447
|
+
controls.set(view, true, "satellites");
|
|
1448
|
+
else
|
|
1449
|
+
this.setView(view, true);
|
|
1384
1450
|
}
|
|
1385
1451
|
/** Mark one satellite: a larger ring round it, its orbit drawn, and its name beside it. `null` lets it go. */
|
|
1386
1452
|
selectSatellite(ref) {
|
|
@@ -1436,8 +1502,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
1436
1502
|
this.#gate?.request();
|
|
1437
1503
|
}
|
|
1438
1504
|
/**
|
|
1439
|
-
* Where a satellite is on the screen as of the last draw: `{ x, y, visible, heightKm }` in CSS pixels from the view's top left
|
|
1440
|
-
* placed (its elements are too old), or it is behind the camera. It is the picture's own camera maths and its own test for the Earth in the way, so a page that draws its own rings need not repeat either.
|
|
1505
|
+
* Where a satellite is on the screen as of the last draw: `{ x, y, visible, heightKm, edge, behind }` in CSS pixels from the view's top left. `visible` means it is inside the box, in front of the camera and not behind the Earth. `edge` is `top`, `right`, `bottom` or `left` when the place lies beyond that edge, and `null` when it is inside the box. `behind` is true when it is behind the camera (the picture would mirror it, so `edge` is read from the camera's own axes). `x` and `y` may lie outside the box. `null` when its group is not set or not shown, or it cannot be placed (its elements are too old). It is the picture's own camera maths and its own test for the Earth in the way, so a page that draws its own rings, or a mark on the edge, need not repeat either.
|
|
1441
1506
|
*/
|
|
1442
1507
|
placeSatellite(ref) {
|
|
1443
1508
|
return this.#model.placeSatellite?.(ref) ?? null;
|
|
@@ -1593,8 +1658,8 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
1593
1658
|
}
|
|
1594
1659
|
/** Is anything on show that moves faster than the Earth turns: a group of satellites, including above the interpolation limit where they are drawn as streaks? */
|
|
1595
1660
|
#satellitesMoving() {
|
|
1596
|
-
for (const group of this.#model.satellites.groups
|
|
1597
|
-
if (group.visible && group.satellites.count > 0)
|
|
1661
|
+
for (const [name, group] of this.#model.satellites.groups)
|
|
1662
|
+
if (satelliteEmphasis(name, group.visible, this.#model.satellites.focus).drawn && group.satellites.count > 0)
|
|
1598
1663
|
return true;
|
|
1599
1664
|
return false;
|
|
1600
1665
|
}
|
|
@@ -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
|
-
*
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
401
|
-
|
|
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
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
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
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
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: !
|
|
491
|
+
return { x, y, visible: !behind && !hidden && edge === null, heightKm, edge, behind };
|
|
426
492
|
},
|
|
427
493
|
place(camera, size) {
|
|
428
494
|
if (!selectedPoints.visible)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/chikyu-earth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.43.0",
|
|
4
4
|
"description": "Chikyu Earth 地球 — A line-drawn globe for the web: country outlines that turn at the Earth's own rate, centred on the place you give it, with an optional realistic Earth from space (three.js), the Sun, Moon and planets, satellites on their orbits, and markers for any place. A web component and an SVG string.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"earth",
|