@johnmorrisdotca/chikyu-earth 0.46.6 → 0.47.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.
@@ -54,10 +54,24 @@ export function longestStreak(segments, count, earthPx) {
54
54
  }
55
55
  return longest * earthPx;
56
56
  }
57
- export const newSatelliteState = () => ({ groups: new Map(), selected: null, marked: new Set(), pinned: [], orbitTint: false, focus: null, modelOver: null, streakMax: DEFAULT_STREAK_MAX, drawn: { placed: 0, segments: 0, tooFast: false, dotScale: 1, longestStreakPx: 0, streakCapPx: 0, weight: 1, fade: 1, earthPx: 0, updateMs: 0, maxUpdateMs: 0, updates: 0, totalMs: 0, selectedRing: false } });
57
+ export const newSatelliteState = () => ({ groups: new Map(), selected: null, marked: new Set(), pinned: [], orbitTint: false, focus: null, modelOver: null, hover: { ref: null, fade: 0, enabled: true, color: "#ffffff", opacity: HOVER_PATH_OPACITY }, streakMax: DEFAULT_STREAK_MAX, drawn: { placed: 0, segments: 0, tooFast: false, dotScale: 1, longestStreakPx: 0, streakCapPx: 0, weight: 1, fade: 1, earthPx: 0, updateMs: 0, maxUpdateMs: 0, updates: 0, totalMs: 0, selectedRing: false, hoverPath: false, hoverOpacity: 0, selectedOpacity: 0 } });
58
58
  /** The most orbits a group may draw all at once, one line each. */
59
59
  export const MAX_ORBIT_GROUP = 40;
60
60
  const ORBIT_POINTS = 120;
61
+ /** How bright the chosen satellite's orbit is. The orbit under the pointer is about a third of this, so the two are told apart at a glance. */
62
+ export const SELECTED_PATH_OPACITY = 0.85;
63
+ /** The orbit under the pointer, before it fades. A page may set another with `--chikyu-hover-path-opacity`. */
64
+ export const HOVER_PATH_OPACITY = SELECTED_PATH_OPACITY / 3;
65
+ /** How long the faint orbit takes to go after the pointer leaves, in milliseconds. Reduced motion takes it away at once. */
66
+ export const HOVER_FADE_MS = 180;
67
+ /**
68
+ * How much of the faint orbit is left `elapsedMs` into its fade, from `from` (1 while the pointer rests) down to 0.
69
+ *
70
+ * @param elapsedMs - Milliseconds since the pointer left.
71
+ * @param from - The opacity share when the fade began, 0 to 1.
72
+ * @returns The share still drawn, 0 when the fade is over.
73
+ */
74
+ export const fadeLeft = (elapsedMs, from) => from * (1 - Math.min(1, Math.max(0, elapsedMs) / HOVER_FADE_MS));
61
75
  const ORBIT_REFRESH_GAME_MS = 30 * 60_000;
62
76
  const ORBIT_REFRESH_WALL_MS = 1000;
63
77
  const POINT_VERT = /* glsl */ `
@@ -160,6 +174,37 @@ export function edgeBeyondCamera(x, y) {
160
174
  return x < 0 ? "left" : "right";
161
175
  return y >= 0 ? "top" : "bottom";
162
176
  }
177
+ /**
178
+ * Whether the Earth hides a satellite. The Earth is the unit sphere at the origin. True when the line from the camera to the satellite meets that sphere before it arrives. A graze at the limb is not hidden (the line only touches the sphere), and neither is a satellite in front of the Earth. This is not the test for a satellite behind the camera.
179
+ *
180
+ * @param camera - The camera, in the same units as the sphere (Earth radii).
181
+ * @param satellite - The satellite, in those units.
182
+ * @returns True when the globe is in the way.
183
+ *
184
+ * @example
185
+ * ```ts
186
+ * import { earthHides } from "@johnmorrisdotca/chikyu-earth/space";
187
+ *
188
+ * const camera = { x: 0, y: 0, z: 4 };
189
+ * console.log(earthHides(camera, { x: 0, y: 0, z: 1.2 }));
190
+ * console.log(earthHides(camera, { x: 0, y: 0, z: -1.2 }));
191
+ * ```
192
+ */
193
+ export function earthHides(camera, satellite) {
194
+ const px = satellite.x - camera.x;
195
+ const py = satellite.y - camera.y;
196
+ const pz = satellite.z - camera.z;
197
+ const len2 = px * px + py * py + pz * pz;
198
+ if (!(len2 > 0))
199
+ return false;
200
+ const t = Math.max(0, Math.min(1, -(camera.x * px + camera.y * py + camera.z * pz) / len2));
201
+ const nx = camera.x + px * t;
202
+ const ny = camera.y + py * t;
203
+ const nz = camera.z + pz * t;
204
+ return nx * nx + ny * ny + nz * nz < 0.998;
205
+ }
206
+ /** An orthographic view: the satellite is behind the Earth's disc when it is further than the centre and inside the disc. A graze at the limb (just inside radius 1) is not hidden. */
207
+ const earthHidesDisc = (right, up, depth, centreDepth) => depth < centreDepth && right * right + up * up < 0.996;
163
208
  export function createSatelliteLayer(three, scene, state, ratio) {
164
209
  if (!three.Points)
165
210
  throw new Error("Satellites need `Points` from three.js: add it to the parts the three loader hands over (see setThreeLoader)");
@@ -192,7 +237,17 @@ export function createSatelliteLayer(three, scene, state, ratio) {
192
237
  selectedPoints.renderOrder = 6;
193
238
  selectedPoints.visible = false;
194
239
  scene.add(selectedPoints);
195
- const selectedLine = { positions: new Float32Array(ORBIT_POINTS * 3), geometry: new three.BufferGeometry(), material: new three.LineBasicMaterial({ color: "#ffffff", transparent: true, opacity: 0.85 }) };
240
+ // One line for the whole life of the layer, rewritten in place: a hover does not make a new buffer. It is about a third as bright as the chosen orbit, so it reads thinner and fainter. WebGL draws a line one pixel wide, and the chosen orbit is left as it is.
241
+ const hoverLine = { positions: new Float32Array(ORBIT_POINTS * 3), geometry: new three.BufferGeometry(), material: new three.LineBasicMaterial({ color: "#ffffff", transparent: true, opacity: HOVER_PATH_OPACITY }) };
242
+ hoverLine.geometry.setAttribute("position", new three.BufferAttribute(hoverLine.positions, 3));
243
+ const hoverLoop = new three.LineLoop(hoverLine.geometry, hoverLine.material);
244
+ hoverLoop.name = "hover-path";
245
+ hoverLoop.frustumCulled = false;
246
+ hoverLoop.visible = false;
247
+ hoverLoop.renderOrder = 4;
248
+ scene.add(hoverLoop);
249
+ let hoverKey = "";
250
+ const selectedLine = { positions: new Float32Array(ORBIT_POINTS * 3), geometry: new three.BufferGeometry(), material: new three.LineBasicMaterial({ color: "#ffffff", transparent: true, opacity: SELECTED_PATH_OPACITY }) };
196
251
  selectedLine.geometry.setAttribute("position", new three.BufferAttribute(selectedLine.positions, 3));
197
252
  const selectedLoop = new three.LineLoop(selectedLine.geometry, selectedLine.material);
198
253
  selectedLoop.frustumCulled = false;
@@ -438,13 +493,39 @@ export function createSatelliteLayer(three, scene, state, ratio) {
438
493
  }
439
494
  selectedLoop.visible = true;
440
495
  selectedMaterial.uniforms["size"].value = 14 * ratio();
496
+ state.drawn.selectedOpacity = selectedLine.material.opacity;
441
497
  }
442
498
  else {
443
499
  selectedPoints.visible = false;
444
500
  state.drawn.selectedRing = false;
445
501
  selectedLoop.visible = false;
446
502
  selectedKey = "";
503
+ state.drawn.selectedOpacity = 0;
504
+ }
505
+ // The faint orbit: one path at a time, computed once from the elements already loaded, hidden while it is the chosen satellite's own orbit.
506
+ const hover = state.hover;
507
+ const hoverRef = hover.enabled && hover.fade > 0 ? hover.ref : null;
508
+ const hoverSet = hoverRef ? find(hoverRef) : undefined;
509
+ const sameAsSelected = Boolean(hoverRef && state.selected && hoverRef.group === state.selected.group && hoverRef.index === state.selected.index);
510
+ const hoverOk = Boolean(hoverRef && hoverSet && !sameAsSelected && hoverRef.index >= 0 && hoverRef.index < hoverSet.count && hoverSet.visible(hoverRef.index));
511
+ if (hoverOk && hoverRef && hoverSet) {
512
+ const key = `${hoverRef.group}:${hoverRef.index}`;
513
+ if (key !== hoverKey) {
514
+ hoverKey = key;
515
+ hoverLine.positions.set(hoverSet.orbit(hoverRef.index, time, ORBIT_POINTS).subarray(0, ORBIT_POINTS * 3));
516
+ hoverLine.geometry.getAttribute("position").needsUpdate = true;
517
+ }
518
+ hoverLine.material.color.set(hover.color || "#ffffff");
519
+ hoverLine.material.opacity = hover.opacity * hover.fade;
520
+ hoverLoop.visible = hoverLine.material.opacity > 0;
521
+ }
522
+ else {
523
+ hoverLoop.visible = false;
524
+ if (!hoverRef)
525
+ hoverKey = "";
447
526
  }
527
+ state.drawn.hoverPath = hoverLoop.visible;
528
+ state.drawn.hoverOpacity = hoverLoop.visible ? hoverLine.material.opacity : 0;
448
529
  state.drawn.placed = placed;
449
530
  state.drawn.segments = segments;
450
531
  state.drawn.longestStreakPx = longest;
@@ -500,22 +581,11 @@ export function createSatelliteLayer(three, scene, state, ratio) {
500
581
  continue;
501
582
  if (ortho) {
502
583
  view.copy(world).applyMatrix4(camera.matrixWorldInverse);
503
- if (view.z < centreDepth && view.x * view.x + view.y * view.y < 0.996)
504
- continue;
505
- }
506
- else {
507
- // behind the Earth: the line from the camera to the satellite passes through the unit sphere before it gets there
508
- const px = world.x - c.x;
509
- const py = world.y - c.y;
510
- const pz = world.z - c.z;
511
- const len2 = px * px + py * py + pz * pz;
512
- const t = Math.max(0, Math.min(1, -(c.x * px + c.y * py + c.z * pz) / len2));
513
- const nx = c.x + px * t;
514
- const ny = c.y + py * t;
515
- const nz = c.z + pz * t;
516
- if (nx * nx + ny * ny + nz * nz < 0.998)
584
+ if (earthHidesDisc(view.x, view.y, view.z, centreDepth))
517
585
  continue;
518
586
  }
587
+ else if (earthHides(c, world))
588
+ continue;
519
589
  best = { group: name, index: i };
520
590
  bestD = d;
521
591
  }
@@ -557,23 +627,13 @@ export function createSatelliteLayer(three, scene, state, ratio) {
557
627
  const up = view.y;
558
628
  const depth = view.z;
559
629
  const centreDepth = world.set(0, 0, 0).applyMatrix4(camera.matrixWorldInverse).z;
560
- hidden = depth < centreDepth && right * right + up * up < 0.996;
630
+ hidden = earthHidesDisc(right, up, depth, centreDepth);
561
631
  world.set(p[i], p[i + 1], p[i + 2]).applyMatrix4(scene.matrixWorld);
562
632
  }
563
- else {
564
- // behind the Earth: the line from the camera to the satellite passes through the unit sphere before it gets there
565
- const px = world.x - c.x;
566
- const py = world.y - c.y;
567
- const pz = world.z - c.z;
568
- const len2 = px * px + py * py + pz * pz;
569
- const t = Math.max(0, Math.min(1, -(c.x * px + c.y * py + c.z * pz) / len2));
570
- const nx = c.x + px * t;
571
- const ny = c.y + py * t;
572
- const nz = c.z + pz * t;
573
- hidden = nx * nx + ny * ny + nz * nz < 0.998;
574
- }
633
+ else
634
+ hidden = earthHides(c, world);
575
635
  }
576
- return { x, y, visible: !behind && !hidden && edge === null, heightKm, edge, behind };
636
+ return { x, y, visible: !behind && !hidden && edge === null, heightKm, edge, behind, occluded: hidden };
577
637
  },
578
638
  place(camera, size) {
579
639
  if (!selectedPoints.visible)
@@ -590,11 +650,13 @@ export function createSatelliteLayer(three, scene, state, ratio) {
590
650
  for (const entry of drawn.values())
591
651
  drop(entry);
592
652
  drawn.clear();
593
- scene.remove(selectedPoints, selectedLoop);
653
+ scene.remove(selectedPoints, selectedLoop, hoverLoop);
594
654
  selectedGeometry.dispose();
595
655
  selectedMaterial.dispose();
596
656
  selectedLine.geometry.dispose();
597
657
  selectedLine.material.dispose();
658
+ hoverLine.geometry.dispose();
659
+ hoverLine.material.dispose();
598
660
  },
599
661
  };
600
662
  }
@@ -154,6 +154,7 @@ export declare const MODEL_HANDOVER_PX = 10;
154
154
  * Pure, so a test can ask it at any height.
155
155
  *
156
156
  * @param distanceKm - The camera's distance from the satellite, in kilometres.
157
+ * @param lowest - The share at the lowest height, `ABOVE_MODEL_SHARE` by default (a page sets it with `ride-model-share`).
157
158
  * @returns The share, from 0 to 0.17.
158
159
  *
159
160
  * @example
@@ -163,4 +164,4 @@ export declare const MODEL_HANDOVER_PX = 10;
163
164
  * console.log(aboveModelShare(150), aboveModelShare(1000) < aboveModelShare(150), aboveModelShare(6000));
164
165
  * ```
165
166
  */
166
- export declare function aboveModelShare(distanceKm: number): number;
167
+ export declare function aboveModelShare(distanceKm: number, lowest?: number): number;
@@ -180,6 +180,7 @@ export const MODEL_HANDOVER_PX = 10;
180
180
  * Pure, so a test can ask it at any height.
181
181
  *
182
182
  * @param distanceKm - The camera's distance from the satellite, in kilometres.
183
+ * @param lowest - The share at the lowest height, `ABOVE_MODEL_SHARE` by default (a page sets it with `ride-model-share`).
183
184
  * @returns The share, from 0 to 0.17.
184
185
  *
185
186
  * @example
@@ -189,10 +190,10 @@ export const MODEL_HANDOVER_PX = 10;
189
190
  * console.log(aboveModelShare(150), aboveModelShare(1000) < aboveModelShare(150), aboveModelShare(6000));
190
191
  * ```
191
192
  */
192
- export function aboveModelShare(distanceKm) {
193
+ export function aboveModelShare(distanceKm, lowest = ABOVE_MODEL_SHARE) {
193
194
  if (!(distanceKm > 0))
194
- return ABOVE_MODEL_SHARE;
195
- const base = ABOVE_MODEL_SHARE * Math.min(1, ABOVE_MODEL_KM / distanceKm);
195
+ return lowest;
196
+ const base = lowest * Math.min(1, ABOVE_MODEL_KM / distanceKm);
196
197
  const t = Math.min(1, Math.max(0, (distanceKm - MODEL_FADE_FROM_KM) / (MODEL_FADE_TO_KM - MODEL_FADE_FROM_KM)));
197
198
  return base * (1 - t * t * (3 - 2 * t));
198
199
  }
@@ -21,6 +21,14 @@ import { type GridState } from "../grid/layer.ts";
21
21
  import { type BeamState } from "../beam/layer.ts";
22
22
  import { type RouteState } from "../route/layer.ts";
23
23
  type Three = ThreeParts;
24
+ /** 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). */
25
+ /** A number easing from one value to another (the model's share, its seat, how much of it is there): `cur` is where it is. */
26
+ export interface FrameEase {
27
+ cur: number;
28
+ from: number;
29
+ to: number;
30
+ start: number;
31
+ }
24
32
  /** 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. */
25
33
  export declare const DEFAULT_EARTH_SIZE = 0.9;
26
34
  /**
@@ -143,6 +151,8 @@ export interface SpaceModel {
143
151
  cloudDrift: number;
144
152
  /** For the `space` camera: the Earth's turn against the stars (degrees) at the moment the camera was set, so it stays in the stars while the Earth turns beneath; null until the next draw sets it. */
145
153
  cameraSpin: number | null;
154
+ /** How much of the Earth's turn the space camera takes: 0 holds the stars, 1 turns with the Earth. */
155
+ follow: number;
146
156
  /** The share of the view's shorter side the Earth's disc fills at zoom 1, and where its centre is in the view (0 to 1 across and down; 0.5, 0.5 is the middle). */
147
157
  earth: {
148
158
  size: number;
@@ -225,6 +235,24 @@ export interface SpaceModel {
225
235
  rideTurn: number;
226
236
  /** How far the riding camera is from the Earth's centre in Earth radii as of the last draw, or null when none rides: the range of tilt that does something follows it. */
227
237
  rideDistance: number | null;
238
+ /**
239
+ * The framing of the ridden satellite's model (MODULES-1316): the radius as a share of the picture's height and where its middle sits (a share of the height from the top) as the page set them (`null`: the ride's own), the eased values the last
240
+ * draw used, how long a change takes (0 for reduced motion), and the ground the picture spans below the satellite as of the last draw.
241
+ */
242
+ rideFrame: {
243
+ share: number | null;
244
+ seat: number | null;
245
+ fresh: boolean;
246
+ ms: number;
247
+ moving: boolean;
248
+ share_: FrameEase;
249
+ seat_: FrameEase;
250
+ weight_: FrameEase;
251
+ groundKm: {
252
+ across: number;
253
+ tall: number;
254
+ } | null;
255
+ };
228
256
  /** The satellite at a point of the view (CSS pixels), within a radius, if a draw has been made and one is there. */
229
257
  pick: ((x: number, y: number, radius: number) => SatelliteRef | null) | null;
230
258
  /** The followed satellite's model, when there is one drawn: where its middle is on the screen (CSS pixels), as of the last draw. */
@@ -233,6 +261,9 @@ export interface SpaceModel {
233
261
  y: number;
234
262
  shown: boolean;
235
263
  parts: number;
264
+ share: number;
265
+ seat: number;
266
+ weight: number;
236
267
  radiusPx: number;
237
268
  box: {
238
269
  left: number;
@@ -417,6 +448,12 @@ export interface SpaceDeps {
417
448
  x: number;
418
449
  y: number;
419
450
  } | null) => void;
451
+ /** Where the satellite under the pointer is, or null. Called at each draw while one is under the pointer (and once when it is let go). */
452
+ onHover?: (place: {
453
+ x: number;
454
+ y: number;
455
+ visible: boolean;
456
+ } | null) => void;
420
457
  /** 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. */
421
458
  onSatelliteMarks?: (marks: {
422
459
  ref: SatelliteRef;
@@ -424,6 +461,7 @@ export interface SpaceDeps {
424
461
  y: number;
425
462
  visible: boolean;
426
463
  heightKm: number;
464
+ occluded: boolean;
427
465
  }[]) => void;
428
466
  /** 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). */
429
467
  onMoving?: () => void;
@@ -7,6 +7,7 @@ import { createTrack, orbitPath, PLANETS } from "./ephemeris.js";
7
7
  import { placeAround, placeMoon, placeSun, RADIUS } from "./scale.js";
8
8
  import { faceOffset, outsidePose, ridePose } from "./ride.js";
9
9
  import { genericSatellite, satelliteKind } from "./generic-satellite.js";
10
+ import { followSpin } from "./follow.js";
10
11
  import { coverBody, covers } from "../sky/cover.js";
11
12
  import { beginPlaceSprites, createPlaceSprites } from "../markers/place-sprites.js";
12
13
  import { ABOVE_MODEL_SHARE, aboveAxes, aboveModelShare, MODEL_HANDOVER_PX, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
@@ -24,10 +25,29 @@ import { subsolarPoint, unitVector } from "../realistic/sun.js";
24
25
  const MAX_MARKED = 80;
25
26
  const RAD = Math.PI / 180;
26
27
  const FOV = 35;
27
- /** 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). */
28
+ const newEase = () => ({ cur: Number.NaN, from: Number.NaN, to: Number.NaN, start: 0 });
29
+ /** Moves an ease towards `to`: at once when it is new or `ms` is 0 (reduced motion), else over `ms` milliseconds with a smooth step. True while it is still on its way. */
30
+ function stepEase(e, to, now, ms, fresh) {
31
+ if (fresh || !Number.isFinite(e.cur)) {
32
+ e.cur = e.from = e.to = to;
33
+ return false;
34
+ }
35
+ if (to !== e.to) {
36
+ e.from = e.cur;
37
+ e.to = to;
38
+ e.start = now;
39
+ }
40
+ const k = ms > 0 ? Math.min(1, Math.max(0, (now - e.start) / ms)) : 1;
41
+ e.cur = e.from + (e.to - e.from) * k * k * (3 - 2 * k);
42
+ if (k >= 1)
43
+ e.cur = to;
44
+ return k < 1;
45
+ }
46
+ /** The radius share and the seat the rides have when the page sets none: along the way it goes the model is large and low (0.22, 0.86), looking down it is small and in the middle. */
47
+ const ALONG_SEAT = 0.86;
28
48
  const OUTSIDE_RADIUS_SHARE = 0.1;
29
49
  /** The share of the view's height an outside ride along (looking along the way it goes) draws the satellite's radius at: it sits at the bottom middle with part of it below the bottom edge, large enough to read and to be drawn sharp (MODULES-1303). */
30
- const OUTSIDE_ALONG_SHARE = 0.17;
50
+ const OUTSIDE_ALONG_SHARE = 0.22;
31
51
  /** 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. */
32
52
  export const DEFAULT_EARTH_SIZE = 0.9;
33
53
  /**
@@ -87,6 +107,7 @@ export const newSpaceModel = () => ({
87
107
  airThickness: AIR_THICKNESS_DEFAULT,
88
108
  cloudDrift: 0,
89
109
  cameraSpin: null,
110
+ follow: 0,
90
111
  earth: { size: DEFAULT_EARTH_SIZE, x: 0.5, y: 0.5 },
91
112
  fit: fitDistance(DEFAULT_EARTH_SIZE, 1),
92
113
  orbits: true,
@@ -119,6 +140,7 @@ export const newSpaceModel = () => ({
119
140
  pick: null,
120
141
  placeSatellite: null,
121
142
  followModel: null,
143
+ rideFrame: { share: null, seat: null, fresh: true, ms: 400, moving: false, share_: newEase(), seat_: newEase(), weight_: newEase(), groundKm: null },
122
144
  tiles: null,
123
145
  ratio: () => Math.min(globalThis.devicePixelRatio || 1, 2),
124
146
  });
@@ -387,6 +409,7 @@ export function createSpaceItem(model, deps) {
387
409
  modelSlot.drawing = null;
388
410
  };
389
411
  let layer;
412
+ let hoverShown = false;
390
413
  const rideState = new Float64Array(6);
391
414
  let selectedShown = false;
392
415
  const camera = new three.PerspectiveCamera(FOV, width / Math.max(1, height), 0.05, 1000);
@@ -516,13 +539,35 @@ export function createSpaceItem(model, deps) {
516
539
  deps.onSatellitesError?.(error);
517
540
  }
518
541
  }
542
+ // the framing of the ridden satellite's model: its share of the picture, where its middle sits and how much of it there is (a switch to the view from inside fades it out over 0.4 s), each eased towards what the page set or the ride's own
543
+ let frameMoving = false;
544
+ const framing = (() => {
545
+ const riding = model.ride;
546
+ const f = model.rideFrame;
547
+ if (!riding || typeof riding.target === "string") {
548
+ f.fresh = true;
549
+ return null;
550
+ }
551
+ const along = riding.view === "from" && riding.look === "horizon";
552
+ const base = riding.view === "above" ? ABOVE_MODEL_SHARE : riding.view === "from" ? (along ? OUTSIDE_ALONG_SHARE : OUTSIDE_RADIUS_SHARE) : MODEL_RADIUS_SHARE;
553
+ const now = performance.now();
554
+ if (stepEase(f.share_, f.share ?? base, now, f.ms, f.fresh))
555
+ frameMoving = true;
556
+ if (stepEase(f.seat_, f.seat ?? (along ? ALONG_SEAT : 0.5), now, f.ms, f.fresh))
557
+ frameMoving = true;
558
+ if (stepEase(f.weight_, riding.viewpoint === "outside" ? 1 : 0, now, f.ms, f.fresh))
559
+ frameMoving = true;
560
+ f.fresh = false;
561
+ return { share: f.share_.cur, seat: f.seat_.cur, weight: f.weight_.cur };
562
+ })();
563
+ model.rideFrame.moving = frameMoving;
519
564
  // the ridden satellite is drawn as its model while the model is big enough to read; its ring and name (the page's choice of it, or the marks) are left off exactly then, and come back when the model has shrunk to the size of a ring (MODULES-1303, 1306)
520
565
  {
521
566
  const riding = model.ride;
522
567
  let over = null;
523
- if (riding && riding.viewpoint === "outside" && typeof riding.target !== "string") {
568
+ if (framing && riding && riding.viewpoint === "outside" && typeof riding.target !== "string") {
524
569
  const kmAbove = riding.distanceKm / Math.max(1e-9, model.view.zoom);
525
- const would = riding.view === "above" ? (riding.modelSize === "fixed" ? ABOVE_MODEL_SHARE : aboveModelShare(kmAbove)) : riding.view === "from" ? (riding.look === "horizon" ? OUTSIDE_ALONG_SHARE : OUTSIDE_RADIUS_SHARE) : MODEL_RADIUS_SHARE;
570
+ const would = (riding.view === "above" ? (riding.modelSize === "fixed" ? framing.share : aboveModelShare(kmAbove, framing.share)) : framing.share) * framing.weight;
526
571
  if (would * size.height >= MODEL_HANDOVER_PX)
527
572
  over = riding.target;
528
573
  }
@@ -591,7 +636,7 @@ export function createSpaceItem(model, deps) {
591
636
  // an outside ride: the same look, from a little way back along it, so the satellite is in the picture
592
637
  let outsideAway = Infinity;
593
638
  if (ridden && ride.viewpoint === "outside") {
594
- const out = outsidePose(pose, ride.look);
639
+ const out = outsidePose(pose, ride.look, framing ? (framing.seat - 0.5) / 0.5 : undefined);
595
640
  pose = out.pose;
596
641
  outsideAway = out.distance;
597
642
  }
@@ -614,7 +659,8 @@ export function createSpaceItem(model, deps) {
614
659
  if (model.camera === "space") {
615
660
  if (model.cameraSpin === null)
616
661
  model.cameraSpin = frame.spin;
617
- spin = model.cameraSpin;
662
+ // 0 holds the stars (the anchor alone, as before). 1 uses the Earth's turn now. In between, that share of the turn since the anchor.
663
+ spin = followSpin(model.cameraSpin, frame.spin, model.follow);
618
664
  }
619
665
  else if (model.camera === "sun") {
620
666
  spin = Math.atan2(-frame.sun[2], frame.sun[0]) / RAD;
@@ -669,6 +715,14 @@ export function createSpaceItem(model, deps) {
669
715
  }
670
716
  camera.fov = fovNow;
671
717
  camera.aspect = size.width / Math.max(1, size.height);
718
+ // the ground the picture spans straight below a ridden satellite, in kilometres: the height above the ground over the vertical field of view (flat-ground, to compare with a tile level's size)
719
+ if (framing) {
720
+ const heightKm = Math.max(0, (Math.hypot(camera.position.x, camera.position.y, camera.position.z) - 1) * 6371);
721
+ const tall = 2 * heightKm * Math.tan((fovNow / 2) * RAD);
722
+ model.rideFrame.groundKm = { across: tall * camera.aspect, tall };
723
+ }
724
+ else
725
+ model.rideFrame.groundKm = null;
672
726
  // the Earth's place in the view: the picture is moved, not the camera (a camera riding from a body, or above a satellite, keeps the middle)
673
727
  const centred = rideFrom !== null || (ride?.view === "above" && followed !== null);
674
728
  const shiftX = centred ? 0 : (model.earth.x - 0.5) * size.width;
@@ -790,7 +844,7 @@ export function createSpaceItem(model, deps) {
790
844
  const satellitePainter = deps.satellitePainter?.();
791
845
  // the satellite to draw: the one followed or seen from above, or (an outside ride from the satellite itself) the one ridden
792
846
  const candidate = followed ?? ridden;
793
- const shownSat = followed ?? (ride?.viewpoint === "outside" ? ridden : null);
847
+ const shownSat = followed ?? (ride?.viewpoint === "outside" || (framing !== null && framing.weight > 0.001) ? ridden : null);
794
848
  const group = candidate ? model.satellites.groups.get(candidate.ref.group) : undefined;
795
849
  const set = candidate && group ? group.satellites.sets[candidate.ref.index] : undefined;
796
850
  const norad = set?.NORAD_CAT_ID;
@@ -839,13 +893,15 @@ export function createSpaceItem(model, deps) {
839
893
  modelSlot.axes = null;
840
894
  const axes = freshAxes ?? (shownSat ? modelSlot.axes : null);
841
895
  // a generic drawing is for an outside ride only; a page's model is drawn wherever the camera is not at the satellite
842
- const drawn = shownSat !== null && (ride?.viewpoint === "outside" || (followed !== null && painted));
843
- const aboveShare = followed && ride?.view === "above" && ride.modelSize !== "fixed" ? aboveModelShare(Math.hypot(shownSat.place[0] - camera.position.x, shownSat.place[1] - camera.position.y, shownSat.place[2] - camera.position.z) * 6371) : 1;
896
+ const drawn = shownSat !== null && (ride?.viewpoint === "outside" || (framing !== null && framing.weight > 0.001) || (followed !== null && painted));
897
+ const aboveShare = followed && ride?.view === "above" && ride.modelSize !== "fixed" ? aboveModelShare(Math.hypot(shownSat.place[0] - camera.position.x, shownSat.place[1] - camera.position.y, shownSat.place[2] - camera.position.z) * 6371, framing?.share) : 1;
844
898
  // from far above the satellite is a point: the model has shrunk to nothing and the ordinary mark is all there is
845
899
  if (modelSlot.drawing && shownSat && axes && drawn && aboveShare * size.height >= 0.5) {
846
900
  const object = modelSlot.drawing.object;
847
901
  const away = Math.hypot(shownSat.place[0] - camera.position.x, shownSat.place[1] - camera.position.y, shownSat.place[2] - camera.position.z);
848
- const share = followed ? (ride?.view === "above" ? (ride.modelSize === "fixed" ? ABOVE_MODEL_SHARE : aboveModelShare(away * 6371)) : MODEL_RADIUS_SHARE) : ride?.look === "horizon" ? OUTSIDE_ALONG_SHARE : OUTSIDE_RADIUS_SHARE;
902
+ const shape = framing?.share ?? MODEL_RADIUS_SHARE;
903
+ const weight = framing ? (followed !== null && ride?.viewpoint !== "outside" && framing.weight <= 0.001 ? 1 : framing.weight) : 1;
904
+ const share = (followed !== null && ride?.view === "above" && ride.modelSize !== "fixed" ? aboveModelShare(away * 6371, shape) : shape) * weight;
849
905
  object.matrix.set(...modelMatrix(shownSat.place, axes, modelRadius(away, half, share, 1e-9)));
850
906
  object.matrixWorldNeedsUpdate = true;
851
907
  object.visible = true;
@@ -856,7 +912,7 @@ export function createSpaceItem(model, deps) {
856
912
  const sx = ((projected.x + 1) / 2) * size.width;
857
913
  const sy = ((1 - projected.y) / 2) * size.height;
858
914
  const radiusPx = size.height * share;
859
- model.followModel = { x: sx, y: sy, shown: true, parts: modelSlot.parts, radiusPx, box: { left: sx - radiusPx, top: sy - radiusPx, right: sx + radiusPx, bottom: sy + radiusPx }, axes };
915
+ model.followModel = { x: sx, y: sy, shown: true, parts: modelSlot.parts, share, seat: sy / size.height, weight, radiusPx, box: { left: sx - radiusPx, top: sy - radiusPx, right: sx + radiusPx, bottom: sy + radiusPx }, axes };
860
916
  }
861
917
  else {
862
918
  if (modelSlot.drawing)
@@ -1088,6 +1144,15 @@ export function createSpaceItem(model, deps) {
1088
1144
  deps.onSelected(at);
1089
1145
  selectedShown = at !== null;
1090
1146
  }
1147
+ if (layer && deps.onHover) {
1148
+ const hover = model.satellites.hover;
1149
+ const ref = hover.enabled && hover.ref && hover.fade > 0 ? hover.ref : null;
1150
+ const at = ref ? layer.placeOf(ref, camera, size) : null;
1151
+ const place = at ? { x: at.x, y: at.y, visible: at.visible } : null;
1152
+ if (place || hoverShown)
1153
+ deps.onHover(place);
1154
+ hoverShown = place !== null;
1155
+ }
1091
1156
  // the meteors, on the Earth: made the first time they are switched on, and asking for their own next draw while a streak is alive or one is due
1092
1157
  if (model.meteors.on && !meteors)
1093
1158
  meteors = createMeteorLayer(three, earth, model.meteors);
@@ -1156,7 +1221,7 @@ export function createSpaceItem(model, deps) {
1156
1221
  routeLayer?.sync();
1157
1222
  if (model.rideLost)
1158
1223
  deps.onRideLost?.();
1159
- if (model.transition)
1224
+ if (model.transition || frameMoving)
1160
1225
  deps.onMoving?.();
1161
1226
  return false;
1162
1227
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/chikyu-earth",
3
- "version": "0.46.6",
3
+ "version": "0.47.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",
@@ -174,6 +174,11 @@
174
174
  "import": "./dist/catalogue/index.js",
175
175
  "default": "./dist/catalogue/index.js"
176
176
  },
177
+ "./place": {
178
+ "types": "./dist/place/index.d.ts",
179
+ "import": "./dist/place/index.js",
180
+ "default": "./dist/place/index.js"
181
+ },
177
182
  "./package.json": "./package.json"
178
183
  },
179
184
  "files": [