@johnmorrisdotca/chikyu-earth 0.33.2 → 0.34.1

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 (41) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +23 -5
  3. package/dist/cities/geometry.d.ts +233 -0
  4. package/dist/cities/geometry.js +174 -0
  5. package/dist/cities/host.d.ts +73 -0
  6. package/dist/cities/host.js +240 -0
  7. package/dist/element.d.ts +1 -1
  8. package/dist/element.js +3 -14
  9. package/dist/markers/index.d.ts +1 -0
  10. package/dist/markers/index.js +1 -0
  11. package/dist/markers/labels.d.ts +7 -1
  12. package/dist/markers/labels.js +12 -1
  13. package/dist/markers/place-layer.d.ts +43 -0
  14. package/dist/markers/place-layer.js +238 -0
  15. package/dist/markers/places.d.ts +279 -0
  16. package/dist/markers/places.js +213 -0
  17. package/dist/passes/element.js +2 -5
  18. package/dist/realistic/body-label.js +19 -11
  19. package/dist/realistic/earth.js +1 -1
  20. package/dist/realistic/element.d.ts +35 -0
  21. package/dist/realistic/element.js +94 -11
  22. package/dist/realistic/index.d.ts +2 -0
  23. package/dist/realistic/index.js +2 -0
  24. package/dist/satellites/index.d.ts +1 -0
  25. package/dist/satellites/index.js +1 -0
  26. package/dist/satellites/names.d.ts +14 -0
  27. package/dist/satellites/names.js +16 -0
  28. package/dist/sky/cover.d.ts +48 -0
  29. package/dist/sky/cover.js +100 -0
  30. package/dist/sky/host.js +48 -18
  31. package/dist/space/element.d.ts +103 -1
  32. package/dist/space/element.js +219 -3
  33. package/dist/space/index.d.ts +3 -1
  34. package/dist/space/index.js +1 -0
  35. package/dist/space/satellite-layer.d.ts +26 -0
  36. package/dist/space/satellite-layer.js +37 -1
  37. package/dist/space/satellite-model.d.ts +72 -0
  38. package/dist/space/satellite-model.js +82 -0
  39. package/dist/space/scene.d.ts +44 -1
  40. package/dist/space/scene.js +154 -2
  41. package/package.json +7 -3
@@ -0,0 +1,72 @@
1
+ import type { Vec3 } from "./ephemeris.ts";
2
+ /**
3
+ * How big a followed satellite's model is drawn: its radius is this share of the height of the view (0.17), so it reads at any distance the camera keeps.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * import { MODEL_RADIUS_SHARE } from "@johnmorrisdotca/chikyu-earth/space";
8
+ *
9
+ * console.log(MODEL_RADIUS_SHARE);
10
+ * ```
11
+ */
12
+ export declare const MODEL_RADIUS_SHARE = 0.17;
13
+ /**
14
+ * The axes of a satellite flying: `x` along the way it goes (its velocity, taken level with the ground below it), `z` straight away from the Earth's centre, and `y` to complete them (`z` cross `x`, so it points to the left of the way it goes).
15
+ * The family's convention for a model: its nose or long axis along +x, its top (the side that faces space) along +z.
16
+ *
17
+ * @param position - Where the satellite is, from the Earth's centre, in any unit.
18
+ * @param velocity - The way it is going, in any unit.
19
+ * @returns Three unit vectors, `x`, `y` and `z`, in the scene's axes; `null` when the position is the centre or the satellite does not move.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import { satelliteAxes } from "@johnmorrisdotca/chikyu-earth/space";
24
+ *
25
+ * const axes = satelliteAxes([1.066, 0, 0], [0, 0, -7.66]);
26
+ * console.log(axes?.x, axes?.z);
27
+ * ```
28
+ */
29
+ export declare function satelliteAxes(position: Vec3, velocity: Vec3): {
30
+ x: Vec3;
31
+ y: Vec3;
32
+ z: Vec3;
33
+ } | null;
34
+ /**
35
+ * The 4 by 4 matrix, row by row (what three.js's `Matrix4.set` takes), that puts a model of radius 1 at a place, turned to the satellite's axes and scaled: its columns are the axes times the scale, then the place.
36
+ *
37
+ * @param place - Where the model's middle goes, in the scene's units.
38
+ * @param axes - The satellite's axes (`satelliteAxes`).
39
+ * @param scale - The model's radius in the scene's units.
40
+ * @returns Sixteen numbers, row by row.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * import { modelMatrix, satelliteAxes } from "@johnmorrisdotca/chikyu-earth/space";
45
+ *
46
+ * const axes = satelliteAxes([1.066, 0, 0], [0, 0, -7.66])!;
47
+ * console.log(modelMatrix([1.066, 0, 0], axes, 0.01));
48
+ * ```
49
+ */
50
+ export declare function modelMatrix(place: Vec3, axes: {
51
+ x: Vec3;
52
+ y: Vec3;
53
+ z: Vec3;
54
+ }, scale: number): number[];
55
+ /**
56
+ * The radius to draw a model at so that it is `share` of the height of the view across its radius, seen from `away` with the half field of view `half` (the tangent of half the field, as the view uses it): the model grows with the distance, so it reads
57
+ * at any distance the camera keeps. Never under `real`, its true size, so a camera that comes in close still sees it as big as it is.
58
+ *
59
+ * @param away - The camera's distance from the satellite, in the scene's units.
60
+ * @param half - The tangent of half the field of view.
61
+ * @param share - The share of the view's height that the radius should take (`MODEL_RADIUS_SHARE`).
62
+ * @param real - The model's true radius, in the same units.
63
+ * @returns The radius to draw it at.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * import { MODEL_RADIUS_SHARE, modelRadius } from "@johnmorrisdotca/chikyu-earth/space";
68
+ *
69
+ * console.log(modelRadius(0.5, Math.tan((35 / 2) * (Math.PI / 180)), MODEL_RADIUS_SHARE, 1e-8));
70
+ * ```
71
+ */
72
+ export declare function modelRadius(away: number, half: number, share: number, real: number): number;
@@ -0,0 +1,82 @@
1
+ /**
2
+ * How big a followed satellite's model is drawn: its radius is this share of the height of the view (0.17), so it reads at any distance the camera keeps.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { MODEL_RADIUS_SHARE } from "@johnmorrisdotca/chikyu-earth/space";
7
+ *
8
+ * console.log(MODEL_RADIUS_SHARE);
9
+ * ```
10
+ */
11
+ export const MODEL_RADIUS_SHARE = 0.17;
12
+ /**
13
+ * The axes of a satellite flying: `x` along the way it goes (its velocity, taken level with the ground below it), `z` straight away from the Earth's centre, and `y` to complete them (`z` cross `x`, so it points to the left of the way it goes).
14
+ * The family's convention for a model: its nose or long axis along +x, its top (the side that faces space) along +z.
15
+ *
16
+ * @param position - Where the satellite is, from the Earth's centre, in any unit.
17
+ * @param velocity - The way it is going, in any unit.
18
+ * @returns Three unit vectors, `x`, `y` and `z`, in the scene's axes; `null` when the position is the centre or the satellite does not move.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import { satelliteAxes } from "@johnmorrisdotca/chikyu-earth/space";
23
+ *
24
+ * const axes = satelliteAxes([1.066, 0, 0], [0, 0, -7.66]);
25
+ * console.log(axes?.x, axes?.z);
26
+ * ```
27
+ */
28
+ export function satelliteAxes(position, velocity) {
29
+ const length = Math.hypot(position[0], position[1], position[2]);
30
+ if (!(length > 0))
31
+ return null;
32
+ const z = [position[0] / length, position[1] / length, position[2] / length];
33
+ // the velocity without the part that points up or down
34
+ const along = velocity[0] * z[0] + velocity[1] * z[1] + velocity[2] * z[2];
35
+ const level = [velocity[0] - along * z[0], velocity[1] - along * z[1], velocity[2] - along * z[2]];
36
+ const speed = Math.hypot(level[0], level[1], level[2]);
37
+ if (!(speed > 1e-12))
38
+ return null;
39
+ const x = [level[0] / speed, level[1] / speed, level[2] / speed];
40
+ const y = [z[1] * x[2] - z[2] * x[1], z[2] * x[0] - z[0] * x[2], z[0] * x[1] - z[1] * x[0]];
41
+ return { x, y, z };
42
+ }
43
+ /**
44
+ * The 4 by 4 matrix, row by row (what three.js's `Matrix4.set` takes), that puts a model of radius 1 at a place, turned to the satellite's axes and scaled: its columns are the axes times the scale, then the place.
45
+ *
46
+ * @param place - Where the model's middle goes, in the scene's units.
47
+ * @param axes - The satellite's axes (`satelliteAxes`).
48
+ * @param scale - The model's radius in the scene's units.
49
+ * @returns Sixteen numbers, row by row.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * import { modelMatrix, satelliteAxes } from "@johnmorrisdotca/chikyu-earth/space";
54
+ *
55
+ * const axes = satelliteAxes([1.066, 0, 0], [0, 0, -7.66])!;
56
+ * console.log(modelMatrix([1.066, 0, 0], axes, 0.01));
57
+ * ```
58
+ */
59
+ export function modelMatrix(place, axes, scale) {
60
+ const { x, y, z } = axes;
61
+ return [x[0] * scale, y[0] * scale, z[0] * scale, place[0], x[1] * scale, y[1] * scale, z[1] * scale, place[1], x[2] * scale, y[2] * scale, z[2] * scale, place[2], 0, 0, 0, 1];
62
+ }
63
+ /**
64
+ * The radius to draw a model at so that it is `share` of the height of the view across its radius, seen from `away` with the half field of view `half` (the tangent of half the field, as the view uses it): the model grows with the distance, so it reads
65
+ * at any distance the camera keeps. Never under `real`, its true size, so a camera that comes in close still sees it as big as it is.
66
+ *
67
+ * @param away - The camera's distance from the satellite, in the scene's units.
68
+ * @param half - The tangent of half the field of view.
69
+ * @param share - The share of the view's height that the radius should take (`MODEL_RADIUS_SHARE`).
70
+ * @param real - The model's true radius, in the same units.
71
+ * @returns The radius to draw it at.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * import { MODEL_RADIUS_SHARE, modelRadius } from "@johnmorrisdotca/chikyu-earth/space";
76
+ *
77
+ * console.log(modelRadius(0.5, Math.tan((35 / 2) * (Math.PI / 180)), MODEL_RADIUS_SHARE, 1e-8));
78
+ * ```
79
+ */
80
+ export function modelRadius(away, half, share, real) {
81
+ return Math.max(real, away * half * share * 2);
82
+ }
@@ -8,7 +8,9 @@ import { type ScaleMode } from "./scale.ts";
8
8
  import type { SatelliteRef } from "../satellites/types.ts";
9
9
  import { type RideLook } from "./ride.ts";
10
10
  import type { SkyFrame } from "../sky/frame.ts";
11
- import { type SatelliteState } from "./satellite-layer.ts";
11
+ import type { PlaceView } from "../markers/places.ts";
12
+ import type { CityFrame } from "../cities/geometry.ts";
13
+ import { type SatelliteScreen, type SatelliteState } from "./satellite-layer.ts";
12
14
  import { type BodyLabelState } from "../realistic/body-label.ts";
13
15
  import { type MeteorState } from "../meteors/layer.ts";
14
16
  type Three = ThreeParts;
@@ -44,6 +46,8 @@ export declare function fitDistance(size: number, aspect: number): number;
44
46
  * ```
45
47
  */
46
48
  export type CameraMode = "ground" | "space" | "sun";
49
+ /** A moon that has been out of sight this long is let go (its pictures too). */
50
+ export declare const MOON_KEEP_MS = 4000;
47
51
  /**
48
52
  * The eleven bodies the space view places, names and lets a reader choose: the Earth, the Sun, the Moon, the seven other planets and Pluto.
49
53
  *
@@ -186,6 +190,14 @@ export interface SpaceModel {
186
190
  rideDistance: number | null;
187
191
  /** The satellite at a point of the view (CSS pixels), within a radius, if a draw has been made and one is there. */
188
192
  pick: ((x: number, y: number, radius: number) => SatelliteRef | null) | null;
193
+ /** The followed satellite's model, when there is one drawn: where its middle is on the screen (CSS pixels), as of the last draw. */
194
+ followModel: {
195
+ x: number;
196
+ y: number;
197
+ shown: boolean;
198
+ } | null;
199
+ /** Where a satellite of a shown group is on the screen as of the last draw (`placeSatellite`), or `null`. */
200
+ placeSatellite: ((ref: SatelliteRef) => SatelliteScreen | null) | null;
189
201
  ratio(): number;
190
202
  }
191
203
  export declare const newSpaceModel: () => SpaceModel;
@@ -220,6 +232,23 @@ export interface BodyDrawing {
220
232
  billboard?: boolean;
221
233
  dispose(): void;
222
234
  }
235
+ /**
236
+ * The seam for drawing a followed satellite as a 3D model: the package ships no model, the page supplies them. `has` says whether there is a model for a satellite (by NORAD number: `25544` is the ISS); `make` makes it as a drawing of radius 1
237
+ * (its middle at the origin, its long axis along +x, its top, the side that faces space, along +z, and its left along +y), at once or later (a promise); the view places it where the satellite is, points it the way it flies, sizes it to read and
238
+ * gives it the Sun's direction (`light`, `update`). `null` from `make` is no model: the satellite stays a dot.
239
+ *
240
+ * @example
241
+ * ```ts no-run
242
+ * import type { SatellitePainter } from "@johnmorrisdotca/chikyu-earth/space";
243
+ *
244
+ * const painter: SatellitePainter = { has: (norad) => norad === 25544, make: async () => null };
245
+ * console.log(painter.has(25544));
246
+ * ```
247
+ */
248
+ export interface SatellitePainter {
249
+ has(noradId: number): boolean;
250
+ make(three: Three, noradId: number, context: PaintContext): BodyDrawing | null | Promise<BodyDrawing | null>;
251
+ }
223
252
  /**
224
253
  * What the scene tells a painter when it makes a body.
225
254
  *
@@ -290,6 +319,10 @@ export interface SpaceDeps {
290
319
  onLabels?: (places: Record<BodyName, BodyPlace | null>) => void;
291
320
  /** Where the sky falls on the screen at this draw, and the bodies that cover it (the names of the stars and the constellation lines are laid over it). Called at each draw. */
292
321
  onSky?: (frame: SkyFrame) => void;
322
+ /** Where points of the Earth's surface fall on the screen at this draw, for the places drawn on it. Called at each draw. */
323
+ onPlaces?: (view: PlaceView) => void;
324
+ /** Where the Earth is on the screen and how to find a place on it, for the names of cities. Called at each draw, with `null` while no Earth is shown. */
325
+ onCities?: (frame: CityFrame | null) => void;
293
326
  /** The name written on the Earth could not be made. */
294
327
  onLabelError?: (error: unknown) => void;
295
328
  /** Where the chosen satellite is on the screen, or null. Called at each draw while a satellite is chosen (and once when it is let go). */
@@ -297,6 +330,14 @@ export interface SpaceDeps {
297
330
  x: number;
298
331
  y: number;
299
332
  } | null) => void;
333
+ /** Where each member of a labelled group is on the screen at this draw (the groups of `model.satellites.marked`); an empty list once when the last group is let go. */
334
+ onSatelliteMarks?: (marks: {
335
+ ref: SatelliteRef;
336
+ x: number;
337
+ y: number;
338
+ visible: boolean;
339
+ heightKm: number;
340
+ }[]) => void;
300
341
  /** Called at the end of a draw while the camera is moving from one ride to another, so the next frame is asked for (at the page's frame cap). */
301
342
  onMoving?: () => void;
302
343
  /** The target of the ride could not be placed at this draw. */
@@ -305,6 +346,8 @@ export interface SpaceDeps {
305
346
  onSatellitesError?: (error: unknown) => void;
306
347
  /** How the Sun, the planets and their moons are drawn; left out, plain spheres in the right colours (see `BodyPainter`). */
307
348
  painter?: BodyPainter;
349
+ /** The models of large satellites, for a followed satellite (see `SatellitePainter`); none, and a satellite is a dot. */
350
+ satellitePainter?: () => SatellitePainter | undefined;
308
351
  /** The painter could not make a body (the three.js parts handed over lack something it needs); the body is drawn plain instead. */
309
352
  onPainterError?: (error: unknown) => void;
310
353
  }
@@ -6,10 +6,13 @@ import { createTrack, orbitPath, PLANETS } from "./ephemeris.js";
6
6
  import { placeAround, placeMoon, placeSun, RADIUS } from "./scale.js";
7
7
  import { ridePose } from "./ride.js";
8
8
  import { coverBody, covers } from "../sky/cover.js";
9
+ import { MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
9
10
  import { createSatelliteLayer, newSatelliteState } from "./satellite-layer.js";
10
11
  import { createBodyLabelLayer, newBodyLabelState } from "../realistic/body-label.js";
11
12
  import { createMeteorLayer, newMeteorState } from "../meteors/layer.js";
12
13
  import { subsolarPoint, unitVector } from "../realistic/sun.js";
14
+ /** The most satellites ringed and named at once, over all the labelled groups. */
15
+ const MAX_MARKED = 80;
13
16
  const RAD = Math.PI / 180;
14
17
  const FOV = 35;
15
18
  /** 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. */
@@ -38,7 +41,7 @@ const LAYERS = ["day", "night", "clouds", "water", "moon"];
38
41
  const MOON_MIN_PLANET_PX = 4;
39
42
  const MOON_MIN_PX = 2.2;
40
43
  /** A moon that has been out of sight this long is let go (its pictures too). */
41
- const MOON_KEEP_MS = 4000;
44
+ export const MOON_KEEP_MS = 4000;
42
45
  const PLAIN_COLOR = (name) => (name === "Sun" ? "#ffb347" : COLORS[name] ?? "#9a948b");
43
46
  /**
44
47
  * The eleven bodies the space view places, names and lets a reader choose: the Earth, the Sun, the Moon, the seven other planets and Pluto.
@@ -87,6 +90,8 @@ export const newSpaceModel = () => ({
87
90
  meteors: newMeteorState(),
88
91
  bodyLabel: newBodyLabelState(),
89
92
  pick: null,
93
+ placeSatellite: null,
94
+ followModel: null,
90
95
  ratio: () => Math.min(globalThis.devicePixelRatio || 1, 2),
91
96
  });
92
97
  /** An inertial direction from the Earth's centre, in scene axes, for right ascension and declination in degrees. */
@@ -269,6 +274,16 @@ export function createSpaceItem(model, deps) {
269
274
  let meteors = null;
270
275
  let meteorTimer;
271
276
  let nameOn = null;
277
+ let marksTold = false;
278
+ // the followed satellite's model: which satellite it is for, the drawing once it is made, and a count so that a model made for a satellite no longer followed is let go
279
+ const modelSlot = { key: "", drawing: null, turn: 0 };
280
+ const dropModel = () => {
281
+ if (!modelSlot.drawing)
282
+ return;
283
+ scene.remove(modelSlot.drawing.object);
284
+ modelSlot.drawing.dispose();
285
+ modelSlot.drawing = null;
286
+ };
272
287
  let layer;
273
288
  const rideState = new Float64Array(6);
274
289
  let selectedShown = false;
@@ -383,6 +398,7 @@ export function createSpaceItem(model, deps) {
383
398
  let focusPos = pos[focus];
384
399
  let focusRadius = radiusOf(focus);
385
400
  let rideFrom = null;
401
+ let followed = null;
386
402
  model.rideLost = false;
387
403
  model.rideMotion = 0;
388
404
  model.rideDistance = null;
@@ -407,6 +423,7 @@ export function createSpaceItem(model, deps) {
407
423
  if (ride.view === "follow") {
408
424
  focusPos = place;
409
425
  focusRadius = Math.max(1e-4, ride.distanceKm / 6371 / fit);
426
+ followed = { place, velocity: [rideState[3], rideState[4], rideState[5]], ref: ride.target };
410
427
  }
411
428
  else
412
429
  rideFrom = { position: place, velocity: [rideState[3], rideState[4], rideState[5]], hidden: null, gameSeconds: 0 };
@@ -527,6 +544,51 @@ export function createSpaceItem(model, deps) {
527
544
  if (held.slot.drawing?.object.visible)
528
545
  paintedMoons += 1;
529
546
  model.painted = { bodies: paintedBodies, moons: paintedMoons };
547
+ // 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
548
+ const satellitePainter = deps.satellitePainter?.();
549
+ const group = followed ? model.satellites.groups.get(followed.ref.group) : undefined;
550
+ const norad = followed && group ? group.satellites.sets[followed.ref.index]?.NORAD_CAT_ID : undefined;
551
+ const modelKey = norad !== undefined && satellitePainter?.has(norad) ? String(norad) : "";
552
+ if (modelKey !== modelSlot.key) {
553
+ dropModel();
554
+ modelSlot.key = modelKey;
555
+ const turn = (modelSlot.turn += 1);
556
+ if (modelKey && satellitePainter && norad !== undefined) {
557
+ void Promise.resolve(satellitePainter.make(three, norad, { look: "", invalidate: () => deps.invalidate(), ratio: model.ratio(), maxTexture: deps.cap() }))
558
+ .then((made) => {
559
+ if (!made)
560
+ return;
561
+ if (ended || modelSlot.turn !== turn) {
562
+ made.dispose();
563
+ return;
564
+ }
565
+ made.object.matrixAutoUpdate = false;
566
+ made.object.visible = false;
567
+ scene.add(made.object);
568
+ modelSlot.drawing = made;
569
+ deps.invalidate();
570
+ })
571
+ .catch((error) => deps.onPainterError?.(error));
572
+ }
573
+ }
574
+ const axes = followed ? satelliteAxes(followed.place, followed.velocity) : null;
575
+ if (modelSlot.drawing && followed && axes) {
576
+ const object = modelSlot.drawing.object;
577
+ const away = Math.hypot(followed.place[0] - camera.position.x, followed.place[1] - camera.position.y, followed.place[2] - camera.position.z);
578
+ object.matrix.set(...modelMatrix(followed.place, axes, modelRadius(away, half, MODEL_RADIUS_SHARE, 1e-9)));
579
+ object.matrixWorldNeedsUpdate = true;
580
+ object.visible = true;
581
+ const toSunNow = unit(frame.sun);
582
+ modelSlot.drawing.light?.(toSunNow);
583
+ modelSlot.drawing.update?.({ toSun: toSunNow, ms: model.time, radiusPx: size.height * MODEL_RADIUS_SHARE });
584
+ projected.set(followed.place[0], followed.place[1], followed.place[2]).project(camera);
585
+ model.followModel = { x: ((projected.x + 1) / 2) * size.width, y: ((1 - projected.y) / 2) * size.height, shown: true };
586
+ }
587
+ else {
588
+ if (modelSlot.drawing)
589
+ modelSlot.drawing.object.visible = false;
590
+ model.followModel = null;
591
+ }
530
592
  const sunToSun = unit([-frame.sun[0], -frame.sun[1], -frame.sun[2]]);
531
593
  sunDrawing?.update?.({ toSun: sunToSun, ms: model.time, radiusPx: px.Sun });
532
594
  for (const name of PLANETS) {
@@ -595,6 +657,65 @@ export function createSpaceItem(model, deps) {
595
657
  }
596
658
  deps.onLabels(places);
597
659
  }
660
+ // the ringed satellites first, so their names are laid out with the places' in this same draw
661
+ model.placeSatellite = layer ? (ref) => layer.placeOf(ref, camera, size) : null;
662
+ if (deps.onSatelliteMarks) {
663
+ if (layer && model.satellites.marked.size > 0) {
664
+ const marks = [];
665
+ for (const name of model.satellites.marked) {
666
+ const group = model.satellites.groups.get(name);
667
+ if (!group)
668
+ continue;
669
+ for (let index = 0; index < group.satellites.count && marks.length < MAX_MARKED; index += 1) {
670
+ const ref = { group: name, index };
671
+ const at = layer.placeOf(ref, camera, size);
672
+ if (at)
673
+ marks.push({ ref, ...at });
674
+ }
675
+ }
676
+ marksTold = true;
677
+ deps.onSatelliteMarks(marks);
678
+ }
679
+ else if (marksTold) {
680
+ marksTold = false;
681
+ deps.onSatelliteMarks([]);
682
+ }
683
+ }
684
+ if (deps.onPlaces) {
685
+ // a place on the ground, turned with the Earth into the scene's axes, seen through the camera: where it falls, which way its upright points on the screen, and whether it faces the camera
686
+ const turn = earth.rotation.y;
687
+ const cos = Math.cos(turn);
688
+ const sin = Math.sin(turn);
689
+ const eye = camera.position;
690
+ deps.onPlaces({
691
+ width: size.width,
692
+ height: size.height,
693
+ at(lon, lat, out) {
694
+ const la = lat * RAD;
695
+ const lo = lon * RAD;
696
+ const lx = Math.cos(la) * Math.sin(lo);
697
+ const lz = Math.cos(la) * Math.cos(lo);
698
+ const wx = lx * cos + lz * sin;
699
+ const wy = Math.sin(la);
700
+ const wz = -lx * sin + lz * cos;
701
+ const away = Math.hypot(eye.x - wx, eye.y - wy, eye.z - wz) || 1;
702
+ out.facing = (wx * (eye.x - wx) + wy * (eye.y - wy) + wz * (eye.z - wz)) / away;
703
+ projected.set(wx, wy, wz).project(camera);
704
+ if (projected.z > 1 || projected.z < -1)
705
+ return false;
706
+ out.x = ((projected.x + 1) / 2) * size.width;
707
+ out.y = ((1 - projected.y) / 2) * size.height;
708
+ projected.set(wx * 1.001, wy * 1.001, wz * 1.001).project(camera);
709
+ const dx = ((projected.x + 1) / 2) * size.width - out.x;
710
+ const dy = ((1 - projected.y) / 2) * size.height - out.y;
711
+ const seen = Math.hypot(dx, dy);
712
+ const side = Math.sqrt(Math.max(0, 1 - out.facing * out.facing));
713
+ out.upX = seen > 0 ? (dx / seen) * side : 0;
714
+ out.upY = seen > 0 ? (dy / seen) * side : 0;
715
+ return true;
716
+ },
717
+ });
718
+ }
598
719
  // the name written on the Earth: made the first time the settings ask for it; none while a ride along a body hides the Earth
599
720
  if (model.bodyLabel.settings && !nameOn)
600
721
  nameOn = createBodyLabelLayer(three, earth, model.bodyLabel, { invalidate: () => deps.invalidate(), ...(deps.onLabelError ? { onError: deps.onLabelError } : {}) });
@@ -613,7 +734,7 @@ export function createSpaceItem(model, deps) {
613
734
  }
614
735
  // a body covers the sky where the ray through a pixel passes within the body's angular radius of its centre: exact for any field of view, where a circle on the screen is right only on the axis
615
736
  const ray = new three.Vector3();
616
- const bodies = ["Earth", "Moon", "Sun"].map((name) => coverBody(pos[name], [camera.position.x, camera.position.y, camera.position.z], radiusOf(name)));
737
+ const bodies = ["Earth", "Moon", "Sun"].map((name) => coverBody(pos[name], [camera.position.x, camera.position.y, camera.position.z], name === "Earth" ? radiusOf(name) * airTop(model.airThickness) : radiusOf(name)));
617
738
  deps.onSky({
618
739
  width: size.width,
619
740
  height: size.height,
@@ -636,6 +757,34 @@ export function createSpaceItem(model, deps) {
636
757
  },
637
758
  });
638
759
  }
760
+ if (deps.onCities) {
761
+ if (hidden === "Earth")
762
+ deps.onCities(null);
763
+ else {
764
+ // a place on the ground, turned with the Earth (the Earth is at the middle, one unit in radius): in sight when the viewer is above its horizon, found through the camera
765
+ const ground = new three.Vector3();
766
+ const eye = camera.position;
767
+ const turned = earth.quaternion;
768
+ deps.onCities({
769
+ width: size.width,
770
+ height: size.height,
771
+ radius: Math.min(px.Earth, 1e5),
772
+ project(lon, lat, out) {
773
+ const phi = lat * RAD;
774
+ const lambda = lon * RAD;
775
+ ground.set(Math.cos(phi) * Math.sin(lambda), Math.sin(phi), Math.cos(phi) * Math.cos(lambda)).applyQuaternion(turned);
776
+ const dx = eye.x - ground.x;
777
+ const dy = eye.y - ground.y;
778
+ const dz = eye.z - ground.z;
779
+ const facing = (ground.x * dx + ground.y * dy + ground.z * dz) / (Math.hypot(dx, dy, dz) || 1);
780
+ ground.project(camera);
781
+ out.x = ((ground.x + 1) / 2) * size.width;
782
+ out.y = ((1 - ground.y) / 2) * size.height;
783
+ return ground.z > 1 || ground.z < -1 ? -1 : facing;
784
+ },
785
+ });
786
+ }
787
+ }
639
788
  if (layer && deps.onSelected) {
640
789
  const at = model.satellites.selected ? layer.place(camera, size) : null;
641
790
  if (at || selectedShown)
@@ -672,8 +821,11 @@ export function createSpaceItem(model, deps) {
672
821
  clearTimeout(meteorTimer);
673
822
  meteors?.dispose();
674
823
  nameOn?.dispose();
824
+ modelSlot.turn += 1;
825
+ dropModel();
675
826
  layer?.dispose();
676
827
  model.pick = null;
828
+ model.placeSatellite = null;
677
829
  textures.dispose();
678
830
  ended = true;
679
831
  empty(sunSlot);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/chikyu-earth",
3
- "version": "0.33.2",
4
- "description": "Chikyu Earth 地球 — A line-drawn globe for the web: country outlines that turn at the Earth's own rate, centred on where you are, 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.",
3
+ "version": "0.34.1",
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",
7
7
  "globe",
@@ -200,6 +200,7 @@
200
200
  },
201
201
  "peerDependencies": {
202
202
  "@johnmorrisdotca/hoshi-stars": ">=0.30.0",
203
+ "@johnmorrisdotca/kuni": ">=1.6.1",
203
204
  "@johnmorrisdotca/wakusei-planets": ">=0.5.0",
204
205
  "astronomy-engine": ">=2.1.0",
205
206
  "satellite.js": ">=6.0.0",
@@ -220,6 +221,9 @@
220
221
  },
221
222
  "@johnmorrisdotca/hoshi-stars": {
222
223
  "optional": true
224
+ },
225
+ "@johnmorrisdotca/kuni": {
226
+ "optional": true
223
227
  }
224
228
  },
225
229
  "devDependencies": {
@@ -230,7 +234,7 @@
230
234
  "@eslint/js": "^9.0.0",
231
235
  "@johnmorrisdotca/hata": "^1.8.0",
232
236
  "@johnmorrisdotca/hoshi-stars": "^0.30.0",
233
- "@johnmorrisdotca/kuni": "^1.5.0",
237
+ "@johnmorrisdotca/kuni": "^1.6.1",
234
238
  "@johnmorrisdotca/wakusei-planets": "^0.5.0",
235
239
  "@playwright/test": "1.64.0",
236
240
  "@sveltejs/vite-plugin-svelte": "^7.3.1",