@johnmorrisdotca/chikyu-earth 0.43.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 (39) hide show
  1. package/CHANGELOG.md +12 -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 +18 -0
  14. package/dist/realistic/element-base.js +59 -12
  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 +29 -1
  30. package/dist/space/element-base.js +82 -7
  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/scene.d.ts +3 -1
  38. package/dist/space/scene.js +54 -25
  39. package/package.json +3 -3
@@ -17,6 +17,8 @@ import { readRoute, routeLeg, routeText } from "../route.js";
17
17
  import { applyRoute } from "../route/layer.js";
18
18
  import { COUNTRY_NAMES_ATTRIBUTES } from "../country-names/geometry.js";
19
19
  import { COUNTRY_NAMES_STYLE, createCountryHost } from "../country-names/host.js";
20
+ import { SEA_NAMES_ATTRIBUTES, readSeaNames } from "../sea-names/geometry.js";
21
+ import { SEA_NAMES_STYLE, createSeaHost } from "../sea-names/host.js";
20
22
  import { createGate, frameCap } from "../realistic/gate.js";
21
23
  import { folderSource } from "../door/map.js";
22
24
  import { setThreeLoader, takeRenderer } from "../realistic/shared.js";
@@ -112,7 +114,7 @@ const readTime = (value) => {
112
114
  const ms = Date.parse(value);
113
115
  return Number.isFinite(ms) ? ms : "now";
114
116
  };
115
- const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden;isolation:isolate}${IMMERSIVE_STYLE}#stage,#labels{position:absolute;inset:0}#labels{pointer-events:none;overflow:hidden}.sp-label{position:absolute;left:0;top:0;margin:0;padding:0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-label:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label::before{content:"";display:inline-block;width:5px;height:5px;margin:0 5px 1px -2px;border-radius:50%;background:#fff}.sp-label[hidden]{display:none}.sp-sat{position:absolute;left:0;top:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-sat[hidden]{display:none}${PLACE_STYLE}${SKY_STYLE}${COUNTRY_NAMES_STYLE}${CITY_NAMES_STYLE}${METEOR_NOTE_STYLE}${NOTES_STYLE}`;
117
+ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden;isolation:isolate}${IMMERSIVE_STYLE}#stage,#labels{position:absolute;inset:0}#labels{pointer-events:none;overflow:hidden}.sp-label{position:absolute;left:0;top:0;margin:0;padding:0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-label:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label::before{content:"";display:inline-block;width:5px;height:5px;margin:0 5px 1px -2px;border-radius:50%;background:#fff}.sp-label[hidden]{display:none}.sp-sat{position:absolute;left:0;top:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-sat[hidden]{display:none}${PLACE_STYLE}${SKY_STYLE}${COUNTRY_NAMES_STYLE}${SEA_NAMES_STYLE}${CITY_NAMES_STYLE}${METEOR_NOTE_STYLE}${NOTES_STYLE}`;
116
118
  /**
117
119
  * The `<chikyu-space>` custom element: the Earth, the Moon, the Sun and the planets where they are at a date and time, drawn with three.js through the shared renderer. It takes `center`, `time` (`now` or an ISO date), `speed` (1 is real time, 0 holds, 86400 is a day a second, negative runs backwards), `scale` (`compressed` or `true`), `labels` and `orbits` (`off` hides them); positions are computed in the browser by astronomy-engine, an optional peer dependency. It draws only when something changes, and nothing while it is out of sight.
118
120
  *
@@ -154,7 +156,7 @@ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:h
154
156
  * ```
155
157
  */
156
158
  export class ChikyuSpace extends HTMLElement {
157
- static observedAttributes = ["cloud-drift", "camera", "earth-size", "earth-x", "earth-y", "center", "time", "speed", "scale", "labels", "orbits", "bodies", "light", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "here-city", "route", "bodies-credit", "satellite-tint", "tiles"];
159
+ static observedAttributes = ["cloud-drift", "camera", "earth-size", "earth-x", "earth-y", "center", "time", "speed", "scale", "labels", "orbits", "bodies", "light", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, ...SEA_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "here-city", "route", "bodies-credit", "satellite-tint", "tiles", "ride-viewpoint"];
158
160
  #model = newSpaceModel();
159
161
  #paint = createPaintState();
160
162
  #mode = "now";
@@ -172,6 +174,7 @@ export class ChikyuSpace extends HTMLElement {
172
174
  #citiesStyle = {};
173
175
  /** The names of the countries on the Earth (`country-names`), and the look of the names. */
174
176
  #countries;
177
+ #seas;
175
178
  #countriesStyle = {};
176
179
  #satNames = {};
177
180
  /** A ringed satellite's name, by `group:index`, for `#satLabelLang`. The name does not depend on the moment, so a frame reads it and does not propagate the orbit again. */
@@ -283,6 +286,11 @@ export class ChikyuSpace extends HTMLElement {
283
286
  onError: (error) => this.dispatchEvent(new CustomEvent("chikyu-country-names-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
284
287
  });
285
288
  this.#countries.setStyle(this.#countriesStyle);
289
+ this.#seas = createSeaHost({
290
+ root,
291
+ attribute: (name) => this.getAttribute(name),
292
+ language: () => ((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en"),
293
+ });
286
294
  this.#model.airThickness = readAirThickness(this.getAttribute("air-thickness"));
287
295
  this.#applyBodyLabel();
288
296
  setAirNote(this.#airNote, this, this.#model.airThickness);
@@ -390,10 +398,14 @@ export class ChikyuSpace extends HTMLElement {
390
398
  this.#cities?.dispose();
391
399
  this.#countries?.dispose();
392
400
  this.#countries = undefined;
401
+ this.#seas?.dispose();
402
+ this.#seas = undefined;
393
403
  this.#cities = undefined;
394
404
  }
395
405
  attributeChangedCallback(name, _old, value) {
396
- if (name === "center")
406
+ if (name === "ride-viewpoint")
407
+ this.#applyViewpoint();
408
+ else if (name === "center")
397
409
  this.centre = readCentre(value) ?? { lon: 0, lat: 0 };
398
410
  else if (name === "time")
399
411
  this.time = readTime(value);
@@ -437,6 +449,7 @@ export class ChikyuSpace extends HTMLElement {
437
449
  this.#applyBodyLabel();
438
450
  this.#sky?.refresh();
439
451
  this.#cities?.refresh();
452
+ this.#seas?.refresh();
440
453
  this.#countries?.refresh();
441
454
  this.#here?.refresh();
442
455
  }
@@ -467,6 +480,11 @@ export class ChikyuSpace extends HTMLElement {
467
480
  }
468
481
  else if (CITY_NAMES_ATTRIBUTES.includes(name))
469
482
  this.#cities?.refresh();
483
+ else if (SEA_NAMES_ATTRIBUTES.includes(name)) {
484
+ this.#seas?.refresh();
485
+ this.#seaFrame();
486
+ this.#countryFrame();
487
+ }
470
488
  else if (name === "borders") {
471
489
  Object.assign(this.#model.borders, readBorders(value));
472
490
  this.#gate?.request();
@@ -823,6 +841,7 @@ export class ChikyuSpace extends HTMLElement {
823
841
  #relayNames(cities, sky) {
824
842
  if (cities)
825
843
  this.#cities?.frame(this.#lastNameFrame, this.#boxesBeforeCities());
844
+ this.#seaFrame();
826
845
  this.#countryFrame();
827
846
  if (sky)
828
847
  this.#sky?.relayout();
@@ -842,18 +861,26 @@ export class ChikyuSpace extends HTMLElement {
842
861
  out.length = 0;
843
862
  if (!this.#lastNameFrame)
844
863
  return out;
845
- out.push(...this.#bodyNameBoxes(), ...(this.#placeLayer?.boxes ?? []), ...(this.#cities?.boxes ?? []));
864
+ out.push(...this.#bodyNameBoxes(), ...(this.#placeLayer?.boxes ?? []), ...(this.#cities?.boxes ?? []), ...(this.#seas?.boxes ?? []));
846
865
  return out;
847
866
  }
848
867
  /** The frame the names were last laid out on. */
849
868
  #lastNameFrame = null;
850
- /** Lays the countries' names out on the last frame, clear of the bodies', the places' and the cities' names as they are now. */
869
+ /** Lays the ocean, sea and continent names out on the last frame, clear of the bodies', the places' and the cities'. A city placed first keeps the space. */
870
+ #seaFrame() {
871
+ const seas = this.#seas;
872
+ if (!seas)
873
+ return;
874
+ const frame = this.#lastNameFrame;
875
+ seas.frame(frame, seas.stats.on && frame ? [...this.#bodyNameBoxes(), ...(this.#placeLayer?.boxes ?? []), ...(this.#cities?.boxes ?? [])] : []);
876
+ }
877
+ /** Lays the countries' names out on the last frame, clear of the bodies', the places', the cities' and the sea names as they are now. */
851
878
  #countryFrame() {
852
879
  const countries = this.#countries;
853
880
  if (!countries)
854
881
  return;
855
882
  const frame = this.#lastNameFrame;
856
- countries.frame(frame, countries.stats.on && frame ? [...this.#bodyNameBoxes(), ...(this.#placeLayer?.boxes ?? []), ...(this.#cities?.boxes ?? [])] : []);
883
+ countries.frame(frame, countries.stats.on && frame ? [...this.#bodyNameBoxes(), ...(this.#placeLayer?.boxes ?? []), ...(this.#cities?.boxes ?? []), ...(this.#seas?.boxes ?? [])] : []);
857
884
  }
858
885
  /** The boxes the bodies' names take beside them in the picture just drawn. */
859
886
  #bodyNameBoxes() {
@@ -908,6 +935,28 @@ export class ChikyuSpace extends HTMLElement {
908
935
  this.#countriesStyle = { ...value };
909
936
  this.#countries?.setStyle(this.#countriesStyle);
910
937
  }
938
+ /**
939
+ * Names of oceans, seas and continents (the attribute `sea-names`). Off unless set: a bare attribute is on. Oceans and continents from far out, seas once the Earth is large on the screen. A city name keeps the space where both fit only one. Nothing is drawn again at rest.
940
+ *
941
+ * @example
942
+ * ```ts no-run
943
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
944
+ *
945
+ * const space = document.querySelector("chikyu-space") as ChikyuSpace;
946
+ * space.seaNames = true;
947
+ * console.log(space.seaNames);
948
+ * space.seaNames = false;
949
+ * ```
950
+ */
951
+ get seaNames() {
952
+ return readSeaNames(this.getAttribute("sea-names"));
953
+ }
954
+ set seaNames(value) {
955
+ if (value)
956
+ this.setAttribute("sea-names", "");
957
+ else
958
+ this.removeAttribute("sea-names");
959
+ }
911
960
  /**
912
961
  * Which borders are drawn on the Earth (the attribute `borders`): the countries' at any size, and the regions' (provinces, states, prefectures) once the Earth is large enough on the screen to tell them apart.
913
962
  * Setting it writes the attribute: both sets as `borders="countries regions"`, one as its own word, none takes the attribute away.
@@ -1164,7 +1213,7 @@ export class ChikyuSpace extends HTMLElement {
1164
1213
  // a body followed (a planet, the Moon, the Earth) is looked at from round it as the view turns: it has no ways to face
1165
1214
  const faceable = !(view === "follow" && typeof target === "string");
1166
1215
  const face = faceable && options.face && RIDE_FACES.includes(options.face) ? options.face : null;
1167
- model.ride = { target: typeof target === "string" ? target : { group: target.group, index: target.index }, view, look: face && view === "from" ? "horizon" : (options.look ?? "down"), face, distanceKm: Math.max(100, options.distanceKm ?? 3000) };
1216
+ model.ride = { target: typeof target === "string" ? target : { group: target.group, index: target.index }, view, look: face && view === "from" ? "horizon" : (options.look ?? "down"), face, distanceKm: Math.max(100, options.distanceKm ?? 3000), viewpoint: options.viewpoint === "inside" || options.viewpoint === "outside" ? options.viewpoint : this.rideViewpoint };
1168
1217
  if (face) {
1169
1218
  model.view = { yaw: 0, tilt: 0, zoom: model.view.zoom };
1170
1219
  model.rideTurn = 0;
@@ -1297,6 +1346,31 @@ export class ChikyuSpace extends HTMLElement {
1297
1346
  this.ride(next.ref, { view: "follow" });
1298
1347
  return next;
1299
1348
  }
1349
+ /**
1350
+ * Where a ride puts the camera: `outside` (the default; the attribute `ride-viewpoint`) shows the satellite, `inside` puts the camera at it. It is the default for the next `ride` and, set while riding, moves the ride there in one eased glide (a jump for a reader who asked for reduced motion), keeping the ride and the clock.
1351
+ * See `RideOptions.viewpoint`.
1352
+ */
1353
+ get rideViewpoint() {
1354
+ return this.getAttribute("ride-viewpoint") === "inside" ? "inside" : "outside";
1355
+ }
1356
+ set rideViewpoint(value) {
1357
+ this.setAttribute("ride-viewpoint", value === "inside" ? "inside" : "outside");
1358
+ }
1359
+ #applyViewpoint() {
1360
+ const model = this.#model;
1361
+ const ride = model.ride;
1362
+ const next = this.rideViewpoint;
1363
+ if (!ride || ride.viewpoint === next)
1364
+ return;
1365
+ const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
1366
+ const pose = model.pose;
1367
+ model.ride = { ...ride, viewpoint: next };
1368
+ model.transition = !reduced && pose.valid ? { start: performance.now(), duration: 1200, from: { p: [pose.p[0], pose.p[1], pose.p[2]], q: [pose.q[0], pose.q[1], pose.q[2], pose.q[3]], fov: pose.fov } } : null;
1369
+ this.#last = performance.now();
1370
+ this.#schedule();
1371
+ this.#gate?.request();
1372
+ this.dispatchEvent(new CustomEvent("chikyu-ride", { detail: this.riding }));
1373
+ }
1300
1374
  /** What the camera is riding along with now, or null. */
1301
1375
  get riding() {
1302
1376
  const ride = this.#model.ride;
@@ -1633,6 +1707,7 @@ export class ChikyuSpace extends HTMLElement {
1633
1707
  grid: { ...this.#model.grid.stats },
1634
1708
  route: { ...this.#model.route.stats },
1635
1709
  countryNames: this.#countries?.stats ?? { on: false, max: 0, countries: 0, names: 0, renders: 0, failed: false },
1710
+ seaNames: this.#seas?.stats ?? { on: false, radius: 0, names: 0, renders: 0 },
1636
1711
  };
1637
1712
  }
1638
1713
  #satelliteStats() {
@@ -0,0 +1,46 @@
1
+ import type * as THREE from "three";
2
+ import type { BodyDrawing } from "./scene.ts";
3
+ /**
4
+ * What a generic drawing shows: `bus` a box with two solar panels, `communications` the same with a dish on its nadir face, `flat` a flat panel with one long solar array (the shape of a large constellation's satellites), `station` a row of modules with a truss and panels.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import type { SatelliteKind } from "@johnmorrisdotca/chikyu-earth/space";
9
+ *
10
+ * const kinds: SatelliteKind[] = ["bus", "communications", "flat", "station"];
11
+ * console.log(kinds.length);
12
+ * ```
13
+ */
14
+ export type SatelliteKind = "bus" | "communications" | "flat" | "station";
15
+ /**
16
+ * Which kind of drawing a satellite gets, from its name: a large constellation (`STARLINK`, `ONEWEB`, `KUIPER`) is `flat`, a station (`ISS`, `ZARYA`, `TIANGONG`, `CSS`) is `station`, a communications satellite (by the common operators' names) has a dish, and anything else is a plain `bus`.
17
+ *
18
+ * @param name - The satellite's name (the element set's `OBJECT_NAME`).
19
+ * @returns The kind.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import { satelliteKind } from "@johnmorrisdotca/chikyu-earth/space";
24
+ *
25
+ * console.log(satelliteKind("STARLINK-1007"), satelliteKind("ISS (ZARYA)"), satelliteKind("INTELSAT 39"), satelliteKind("NOAA 19"));
26
+ * ```
27
+ */
28
+ export declare function satelliteKind(name: string): SatelliteKind;
29
+ /**
30
+ * A generic satellite as a drawing of radius 1 about the origin, its long axis along +x (the way it flies), its top along +z and its left along +y, the family's convention for a model, with its own light that `light(toSun)` turns to the Sun. One group of a few meshes, made once and disposed with `dispose`.
31
+ *
32
+ * @param three - three.js (the parts the demo's subset holds: `Group`, `Mesh`, `BoxGeometry`, `CylinderGeometry`, `MeshLambertMaterial`, `DirectionalLight`, `AmbientLight`).
33
+ * @param kind - What to draw.
34
+ * @returns The drawing, with `light` and `dispose`.
35
+ *
36
+ * @example
37
+ * ```ts no-run
38
+ * import { genericSatellite } from "@johnmorrisdotca/chikyu-earth/space";
39
+ *
40
+ * const three = await import("three");
41
+ * const drawing = genericSatellite(three, "communications");
42
+ * console.log(drawing.object.children.length);
43
+ * drawing.dispose();
44
+ * ```
45
+ */
46
+ export declare function genericSatellite(three: typeof THREE, kind: SatelliteKind): BodyDrawing;
@@ -0,0 +1,96 @@
1
+ const COMMS = /(INTELSAT|SES-|EUTELSAT|ASTRA|ECHOSTAR|DIRECTV|TELSTAR|GALAXY|YAMAL|THURAYA|INMARSAT|IRIDIUM|GLOBALSTAR|ORBCOMM|TDRS|VIASAT|ANIK|SKYNET|MILSTAR|SAT-|SATCOM|COMSAT|OPTUS|JCSAT|SUPERBIRD|HISPASAT|ARABSAT|NILESAT|TURKSAT|KOREASAT|ASIASAT|APSTAR|EXPRESS|BADR)/i;
2
+ /**
3
+ * Which kind of drawing a satellite gets, from its name: a large constellation (`STARLINK`, `ONEWEB`, `KUIPER`) is `flat`, a station (`ISS`, `ZARYA`, `TIANGONG`, `CSS`) is `station`, a communications satellite (by the common operators' names) has a dish, and anything else is a plain `bus`.
4
+ *
5
+ * @param name - The satellite's name (the element set's `OBJECT_NAME`).
6
+ * @returns The kind.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { satelliteKind } from "@johnmorrisdotca/chikyu-earth/space";
11
+ *
12
+ * console.log(satelliteKind("STARLINK-1007"), satelliteKind("ISS (ZARYA)"), satelliteKind("INTELSAT 39"), satelliteKind("NOAA 19"));
13
+ * ```
14
+ */
15
+ export function satelliteKind(name) {
16
+ if (/^(STARLINK|ONEWEB|KUIPER)/i.test(name))
17
+ return "flat";
18
+ if (/(ISS|ZARYA|TIANGONG|CSS|TIANHE|WENTIAN|MENGTIAN)/i.test(name))
19
+ return "station";
20
+ if (COMMS.test(name))
21
+ return "communications";
22
+ return "bus";
23
+ }
24
+ /**
25
+ * A generic satellite as a drawing of radius 1 about the origin, its long axis along +x (the way it flies), its top along +z and its left along +y, the family's convention for a model, with its own light that `light(toSun)` turns to the Sun. One group of a few meshes, made once and disposed with `dispose`.
26
+ *
27
+ * @param three - three.js (the parts the demo's subset holds: `Group`, `Mesh`, `BoxGeometry`, `CylinderGeometry`, `MeshLambertMaterial`, `DirectionalLight`, `AmbientLight`).
28
+ * @param kind - What to draw.
29
+ * @returns The drawing, with `light` and `dispose`.
30
+ *
31
+ * @example
32
+ * ```ts no-run
33
+ * import { genericSatellite } from "@johnmorrisdotca/chikyu-earth/space";
34
+ *
35
+ * const three = await import("three");
36
+ * const drawing = genericSatellite(three, "communications");
37
+ * console.log(drawing.object.children.length);
38
+ * drawing.dispose();
39
+ * ```
40
+ */
41
+ export function genericSatellite(three, kind) {
42
+ const group = new three.Group();
43
+ const materials = [];
44
+ const geometries = [];
45
+ const half = Math.PI / 2;
46
+ const add = (geometry, colour, at, spin = [0, 0, 0]) => {
47
+ const material = new three.MeshLambertMaterial({ color: colour });
48
+ const mesh = new three.Mesh(geometry, material);
49
+ mesh.position.set(at[0], at[1], at[2]);
50
+ mesh.rotation.set(spin[0], spin[1], spin[2]);
51
+ group.add(mesh);
52
+ materials.push(material);
53
+ geometries.push(geometry);
54
+ };
55
+ const box = (x, y, z) => new three.BoxGeometry(x, y, z);
56
+ const tube = (radius, length) => new three.CylinderGeometry(radius, radius, length, 16);
57
+ if (kind === "flat") {
58
+ add(box(0.5, 0.36, 0.03), 0xd7dadf, [0, 0, 0]);
59
+ add(box(0.5, 1.1, 0.01), 0x1f3f7a, [0, 0.74, 0]);
60
+ }
61
+ else if (kind === "station") {
62
+ add(tube(0.07, 0.8), 0xd9dde3, [0, 0, 0], [0, 0, half]);
63
+ add(box(0.05, 1.7, 0.05), 0xb7bcc4, [-0.2, 0, 0]);
64
+ for (const y of [-0.75, 0.75])
65
+ add(box(0.3, 0.3, 0.012), 0x274a8c, [-0.2, y, 0]);
66
+ }
67
+ else {
68
+ add(box(0.5, 0.4, 0.4), 0xd7b35a, [0, 0, 0]);
69
+ for (const y of [-1, 1]) {
70
+ add(box(0.18, 0.04, 0.04), 0xb7bcc4, [0, y * 0.4, 0]);
71
+ add(box(0.36, 0.52, 0.012), 0x1f3f7a, [0, y * 0.72, 0]);
72
+ }
73
+ if (kind === "communications") {
74
+ add(tube(0.05, 0.14), 0xb7bcc4, [0.1, 0, 0.27]);
75
+ add(new three.CylinderGeometry(0.2, 0.02, 0.1, 20), 0xe8eaee, [0.1, 0, 0.36]);
76
+ }
77
+ }
78
+ const sun = new three.DirectionalLight(0xfff4e0, 3.2);
79
+ group.add(sun, new three.AmbientLight(0x6f86a8, 0.9));
80
+ return {
81
+ object: group,
82
+ light(toSun) {
83
+ // the model's axes are the columns of the matrix the view set: the direction to the Sun in them is the dot with each
84
+ const m = group.matrix.elements;
85
+ const length = Math.hypot(m[0], m[1], m[2]) || 1;
86
+ sun.position.set((m[0] * toSun[0] + m[1] * toSun[1] + m[2] * toSun[2]) / length, (m[4] * toSun[0] + m[5] * toSun[1] + m[6] * toSun[2]) / length, (m[8] * toSun[0] + m[9] * toSun[1] + m[10] * toSun[2]) / length);
87
+ },
88
+ dispose() {
89
+ for (const material of materials)
90
+ material.dispose();
91
+ for (const geometry of geometries)
92
+ geometry.dispose();
93
+ sun.dispose?.();
94
+ },
95
+ };
96
+ }
@@ -1,6 +1,7 @@
1
1
  export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, orbitPath, PLANETS, type Frame, type PlanetName, type Vec3 } from "./ephemeris.ts";
2
2
  export { compress, MOON_COMPRESSED, placeAround, placeMoon, placeSun, RADIUS, SUN_COMPRESSED, truePosition, type ScaleMode } from "./scale.ts";
3
3
  export { fitDistance, plainPainter, type BodyDrawing, type BodyMoon, type BodyPainter, type BodyView, type PaintContext, type SatellitePainter } from "./scene.ts";
4
- export { faceOffset, RIDE_FACES, RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees, type RideFace, type RideInput, type RideLook, type RidePose } from "./ride.ts";
4
+ export { faceOffset, OUTSIDE_KM, outsidePose, RIDE_FACES, RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees, type RideFace, type RideInput, type RideLook, type RidePose, type RideViewpoint } from "./ride.ts";
5
5
  export type { SatelliteScreen } from "./satellite-layer.ts";
6
6
  export { aboveAxes, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.ts";
7
+ export { genericSatellite, satelliteKind, type SatelliteKind } from "./generic-satellite.ts";
@@ -3,5 +3,6 @@
3
3
  export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, orbitPath, PLANETS } from "./ephemeris.js";
4
4
  export { compress, MOON_COMPRESSED, placeAround, placeMoon, placeSun, RADIUS, SUN_COMPRESSED, truePosition } from "./scale.js";
5
5
  export { fitDistance, plainPainter } from "./scene.js";
6
- export { faceOffset, RIDE_FACES, RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees } from "./ride.js";
6
+ export { faceOffset, OUTSIDE_KM, outsidePose, RIDE_FACES, RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees } from "./ride.js";
7
7
  export { aboveAxes, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
8
+ export { genericSatellite, satelliteKind } from "./generic-satellite.js";
@@ -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.
@@ -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 {
@@ -5,7 +5,8 @@ import { createTextureSet } from "../realistic/textures.js";
5
5
  import { createTileSet } from "../realistic/tile-set.js";
6
6
  import { createTrack, orbitPath, PLANETS } from "./ephemeris.js";
7
7
  import { placeAround, placeMoon, placeSun, RADIUS } from "./scale.js";
8
- import { faceOffset, ridePose } from "./ride.js";
8
+ import { faceOffset, outsidePose, ridePose } from "./ride.js";
9
+ import { genericSatellite, satelliteKind } from "./generic-satellite.js";
9
10
  import { coverBody, covers } from "../sky/cover.js";
10
11
  import { beginPlaceSprites, createPlaceSprites } from "../markers/place-sprites.js";
11
12
  import { aboveAxes, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
@@ -22,6 +23,8 @@ import { subsolarPoint, unitVector } from "../realistic/sun.js";
22
23
  const MAX_MARKED = 80;
23
24
  const RAD = Math.PI / 180;
24
25
  const FOV = 35;
26
+ /** How big a satellite seen from outside by a ride from itself is drawn: its radius is this share of the height of the view (a model about a fifth of the height across; the satellite is a few metres, so this is not to scale). */
27
+ const OUTSIDE_RADIUS_SHARE = 0.09;
25
28
  /** How much of the view's shorter side the Earth's disc fills at zoom 1 when the page does not say: 0.9, so the atmosphere's glow (8% beyond the disc) is inside the view and never cut. */
26
29
  export const DEFAULT_EARTH_SIZE = 0.9;
27
30
  /**
@@ -516,6 +519,8 @@ export function createSpaceItem(model, deps) {
516
519
  let focusRadius = radiusOf(focus);
517
520
  let rideFrom = null;
518
521
  let followed = null;
522
+ // a satellite ridden from itself: where it is, so that an outside ride can show it
523
+ let ridden = null;
519
524
  model.rideLost = false;
520
525
  model.lookBase = null;
521
526
  model.rideMotion = 0;
@@ -543,8 +548,10 @@ export function createSpaceItem(model, deps) {
543
548
  focusRadius = Math.max(1e-4, ride.distanceKm / 6371 / fit);
544
549
  followed = { place, velocity: [rideState[3], rideState[4], rideState[5]], ref: ride.target };
545
550
  }
546
- else
551
+ else {
547
552
  rideFrom = { position: place, velocity: [rideState[3], rideState[4], rideState[5]], hidden: null, gameSeconds: 0 };
553
+ ridden = { place, velocity: rideFrom.velocity, ref: ride.target };
554
+ }
548
555
  }
549
556
  else
550
557
  model.rideLost = true;
@@ -561,14 +568,21 @@ export function createSpaceItem(model, deps) {
561
568
  let fovNow = FOV;
562
569
  let distance = 0;
563
570
  if (rideFrom) {
564
- const pose = ridePose({ position: rideFrom.position, velocity: rideFrom.velocity, look: ride.look, yaw: model.view.yaw, tilt: model.view.tilt, zoom: model.view.zoom, turn: model.rideTurn, ...(ride.face ? { face: ride.face } : {}) });
571
+ let pose = ridePose({ position: rideFrom.position, velocity: rideFrom.velocity, look: ride.look, yaw: model.view.yaw, tilt: model.view.tilt, zoom: model.view.zoom, turn: model.rideTurn, ...(ride.face ? { face: ride.face } : {}) });
565
572
  model.rideDistance = Math.hypot(...rideFrom.position);
573
+ // an outside ride: the same look, from a little way back along it, so the satellite is in the picture
574
+ let outsideAway = Infinity;
575
+ if (ridden && ride.viewpoint === "outside") {
576
+ const out = outsidePose(pose, ride.look);
577
+ pose = out.pose;
578
+ outsideAway = out.distance;
579
+ }
566
580
  camera.position.set(pose.position[0], pose.position[1], pose.position[2]);
567
581
  camera.up.set(pose.up[0], pose.up[1], pose.up[2]);
568
582
  camera.lookAt(pose.position[0] + pose.forward[0], pose.position[1] + pose.forward[1], pose.position[2] + pose.forward[2]);
569
583
  fovNow = pose.fov;
570
584
  const away = Math.hypot(...rideFrom.position);
571
- camera.near = Math.max(0.0008, Math.min(0.05, (away - 1) * 0.1));
585
+ camera.near = outsideAway < Infinity ? Math.max(1e-5, outsideAway * 0.1) : Math.max(0.0008, Math.min(0.05, (away - 1) * 0.1));
572
586
  camera.far = Math.max(2000, 400 + (mode === "true" ? 40 * 23_481 : 0));
573
587
  // how fast the ground goes by under the camera, in pixels a second at 1x: the speed over the height for a satellite, the turn of the direction to the Earth for a body
574
588
  const focal = (size.height / 2) / Math.tan((fovNow / 2) * RAD);
@@ -755,14 +769,36 @@ export function createSpaceItem(model, deps) {
755
769
  model.painted = { bodies: paintedBodies, moons: paintedMoons, held: 0, moon: paintedMoon !== undefined, tiles: tiled, mapped: model.painted.mapped, pending: model.painted.pending };
756
770
  // the followed satellite as a model, when the page has one for it: made once, placed where the satellite is, pointed the way it flies, sized to read and lit by the Sun
757
771
  const satellitePainter = deps.satellitePainter?.();
758
- const group = followed ? model.satellites.groups.get(followed.ref.group) : undefined;
759
- const norad = followed && group ? group.satellites.sets[followed.ref.index]?.NORAD_CAT_ID : undefined;
760
- const modelKey = norad !== undefined && satellitePainter?.has(norad) ? String(norad) : "";
772
+ // the satellite to draw: the one followed or seen from above, or (an outside ride from the satellite itself) the one ridden
773
+ const candidate = followed ?? ridden;
774
+ const shownSat = followed ?? (ride?.viewpoint === "outside" ? ridden : null);
775
+ const group = candidate ? model.satellites.groups.get(candidate.ref.group) : undefined;
776
+ const set = candidate && group ? group.satellites.sets[candidate.ref.index] : undefined;
777
+ const norad = set?.NORAD_CAT_ID;
778
+ // a model the page made for it, drawn only while the camera is outside it (followed or above it, or an outside ride); else the package's own small drawing by kind, kept (hidden) while the ride stays on the satellite, and let go when it ends
779
+ const painted = norad !== undefined && satellitePainter?.has(norad) === true;
780
+ const genericKey = set ? `generic:${satelliteKind(set.OBJECT_NAME ?? "")}` : "";
781
+ const modelKey = set === undefined || norad === undefined ? "" : painted ? (shownSat ? String(norad) : "") : ride?.viewpoint === "outside" || modelSlot.key === genericKey ? genericKey : "";
761
782
  if (modelKey !== modelSlot.key) {
762
783
  dropModel();
763
784
  modelSlot.key = modelKey;
764
785
  const turn = (modelSlot.turn += 1);
765
- if (modelKey && satellitePainter && norad !== undefined) {
786
+ const adopt = (made) => {
787
+ made.object.matrixAutoUpdate = false;
788
+ made.object.visible = false;
789
+ scene.add(made.object);
790
+ modelSlot.drawing = made;
791
+ // how many meshes the model is made of: a draw call each, which a test of the draw budget adds to the scene's own
792
+ modelSlot.parts = 0;
793
+ made.object.traverse((part) => {
794
+ if (part.isMesh)
795
+ modelSlot.parts += 1;
796
+ });
797
+ deps.invalidate();
798
+ };
799
+ if (modelKey.startsWith("generic:"))
800
+ adopt(genericSatellite(three, modelKey.slice(8)));
801
+ else if (modelKey && satellitePainter && norad !== undefined) {
766
802
  void Promise.resolve(satellitePainter.make(three, norad, { look: "", invalidate: () => deps.invalidate(), ratio: model.ratio(), maxTexture: deps.cap() }))
767
803
  .then((made) => {
768
804
  if (!made)
@@ -771,32 +807,25 @@ export function createSpaceItem(model, deps) {
771
807
  made.dispose();
772
808
  return;
773
809
  }
774
- made.object.matrixAutoUpdate = false;
775
- made.object.visible = false;
776
- scene.add(made.object);
777
- modelSlot.drawing = made;
778
- // how many meshes the model is made of: a draw call each, which a test of the draw budget adds to the scene's own
779
- modelSlot.parts = 0;
780
- made.object.traverse((part) => {
781
- if (part.isMesh)
782
- modelSlot.parts += 1;
783
- });
784
- deps.invalidate();
810
+ adopt(made);
785
811
  })
786
812
  .catch((error) => deps.onPainterError?.(error));
787
813
  }
788
814
  }
789
- const axes = followed ? satelliteAxes(followed.place, followed.velocity) : null;
790
- if (modelSlot.drawing && followed && axes) {
815
+ const axes = shownSat ? satelliteAxes(shownSat.place, shownSat.velocity) : null;
816
+ // a generic drawing is for an outside ride only; a page's model is drawn wherever the camera is not at the satellite
817
+ const drawn = shownSat !== null && (ride?.viewpoint === "outside" || (followed !== null && painted));
818
+ if (modelSlot.drawing && shownSat && axes && drawn) {
791
819
  const object = modelSlot.drawing.object;
792
- const away = Math.hypot(followed.place[0] - camera.position.x, followed.place[1] - camera.position.y, followed.place[2] - camera.position.z);
793
- object.matrix.set(...modelMatrix(followed.place, axes, modelRadius(away, half, MODEL_RADIUS_SHARE, 1e-9)));
820
+ const away = Math.hypot(shownSat.place[0] - camera.position.x, shownSat.place[1] - camera.position.y, shownSat.place[2] - camera.position.z);
821
+ const share = followed ? MODEL_RADIUS_SHARE : OUTSIDE_RADIUS_SHARE;
822
+ object.matrix.set(...modelMatrix(shownSat.place, axes, modelRadius(away, half, share, 1e-9)));
794
823
  object.matrixWorldNeedsUpdate = true;
795
824
  object.visible = true;
796
825
  const toSunNow = unit(frame.sun);
797
826
  modelSlot.drawing.light?.(toSunNow);
798
- modelSlot.drawing.update?.({ toSun: toSunNow, ms: model.time, radiusPx: size.height * MODEL_RADIUS_SHARE });
799
- projected.set(followed.place[0], followed.place[1], followed.place[2]).project(camera);
827
+ modelSlot.drawing.update?.({ toSun: toSunNow, ms: model.time, radiusPx: size.height * share });
828
+ projected.set(shownSat.place[0], shownSat.place[1], shownSat.place[2]).project(camera);
800
829
  model.followModel = { x: ((projected.x + 1) / 2) * size.width, y: ((1 - projected.y) / 2) * size.height, shown: true, parts: modelSlot.parts };
801
830
  }
802
831
  else {