@johnmorrisdotca/chikyu-earth 0.63.0 → 0.64.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +2 -2
- package/dist/space/element-base.d.ts +2 -2
- package/dist/space/element-base.js +5 -2
- package/dist/space/index.d.ts +1 -0
- package/dist/space/index.js +1 -0
- package/dist/space/ride-glide.d.ts +78 -0
- package/dist/space/ride-glide.js +112 -0
- package/dist/space/scene.d.ts +5 -1
- package/dist/space/scene.js +14 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.64.0 - 2026-11-20
|
|
6
|
+
|
|
7
|
+
- **From one satellite to another a ride glides round the Earth** (MODULES-1735). A `ride` call that goes from one satellite to another moved the camera in a straight line, which for a satellite behind the Earth ran through the Earth (held 1 km over the ground since 0.63.0), so a page had to climb, cross and come down in steps of its own. The camera now glides along the great circle round the Earth's centre, its height going evenly from the one ride's to the other's and never under 100 km above the ground (`GLIDE_FLOOR_KM`). The look is carried along the circle and goes over from the first look to the second, so a facing (ahead, down and the rest) stays level, nothing rolls over against the local vertical, and the view turns once towards its end. The glide back is the same flight the other way.
|
|
8
|
+
- **One glide for near and far.** For a satellite in sight the circle is all but the straight line (about 10 m off half way along a 25 km hop), so the great circle is the glide between any two satellites; every other change of ride (to or from a body, the same satellite in another view, a facing, the viewpoint) is the straight glide as before.
|
|
9
|
+
- **Its length.** `glide` sets it as for any glide; with `{ minMs, maxMs }` it follows the way along the circle (`satelliteGlideKm`).
|
|
10
|
+
- **Pure parts** in `/space`: `satelliteGlide(from, to, ease, floorKm?)`, `satelliteGlideKm(from, to)`, `GLIDE_FLOOR_KM` and the types `GlidePose` and `Quat`, with unit tests (`test/ride-glide.test.ts`: behind the Earth, in sight and across the far side, facing ahead and down; the floor; the same way back; a short hop against the straight line).
|
|
11
|
+
- **Tests.** `e2e/ride-glide.gl.ts` reads every frame of a glide on a stepped clock, from the ISS to a station in sight and to one behind the Earth, outside and inside, facing ahead and down: the distance to the end only falls, the camera keeps 100 km over the ground and never rises over both ends, the view only turns towards its end, neither its up nor its line of sight rolls over against the vertical, it arrives facing the way it faced, and the glide back is the same way. It fails on 0.63.0. The ride guide in English and Japanese, `docs/ride-along.md` and the README.
|
|
12
|
+
|
|
5
13
|
## 0.63.0 - 2026-11-19
|
|
6
14
|
|
|
7
15
|
- **The view above a satellite has no facings, and a ride's camera never goes under the ground** (MODULES-1685).
|
package/README.md
CHANGED
|
@@ -359,7 +359,7 @@ Passes are only as good as the orbit data are new: each pass says how old its el
|
|
|
359
359
|
<p align="center"><img alt="Riding along with the ISS, tipped towards the horizon: the Earth's curve and atmosphere, and the orbits of the other stations in the sky" src="docs/images/space-ride-horizon.png" width="420"></p>
|
|
360
360
|
|
|
361
361
|
`space.ride({ group: "stations", index: 0 }, { look: "horizon" })` puts the camera on the ISS (or a Starlink satellite, the Moon, a planet) at its real place for the moment shown and looks at the Earth, which goes by beneath
|
|
362
|
-
as the body moves along its orbit; switch to another body and the camera glides there. Straight down or toward the horizon, from the body or following it at a distance, time faster or slower. A ridden satellite is in the picture by default (the camera a little behind and above it, a small drawing of it where the page has no model, not to scale); `ride-viewpoint="inside"` (property `rideViewpoint`, option `viewpoint`) puts the camera at the satellite instead. A drag turns the view where the camera is, like turning your head (the satellite leaves the picture as you look away); `ride-drag="orbit"` (property `rideDrag`, option `drag`) takes the camera round the satellite as before. Seen from above, the model shrinks as the ride rises and hands over to the ordinary mark by 2,000 km; `ride-model-size="fixed"` (property `rideModelSize`, option `modelSize`) keeps one size at every height. `ride-up="north"` (property `rideUp`, option `up`) puts north at the top of the view above a satellite, so it is seen to go the way it really goes; a small compass on a ride shows north and the heading (`compass="off"` hides it), `rideTrack` and `chikyu-ride-track` give the heading, ground point and whether the Sun lights it, and the chosen orbit is amber in sunlight and blue in the Earth's shadow (`path-light="off"` for one colour). `ride-model-share`, `ride-model-seat` and `ride-zoom` frame and zoom the ridden satellite (properties `rideModelShare`, `rideModelSeat`, `rideZoom`). `face("ahead")` (behind, left, right, down, up; the keys W, S, A, D, F, R) turns a ride from the satellite or following it that way; the view above a satellite looks down on it and has no facings, so there `face()` returns `false` and the camera stays as it was. In every view the camera is never under the ground: it is held at least 1 km above it. It animates continuously, so it keeps to the
|
|
362
|
+
as the body moves along its orbit; switch to another body and the camera glides there; from one satellite to another it glides round the Earth along the great circle, never through it and at least 100 km above the ground, with the facing kept level, so a satellite on the far side is reached in one smooth flight and Back is the same flight the other way. Straight down or toward the horizon, from the body or following it at a distance, time faster or slower. A ridden satellite is in the picture by default (the camera a little behind and above it, a small drawing of it where the page has no model, not to scale); `ride-viewpoint="inside"` (property `rideViewpoint`, option `viewpoint`) puts the camera at the satellite instead. A drag turns the view where the camera is, like turning your head (the satellite leaves the picture as you look away); `ride-drag="orbit"` (property `rideDrag`, option `drag`) takes the camera round the satellite as before. Seen from above, the model shrinks as the ride rises and hands over to the ordinary mark by 2,000 km; `ride-model-size="fixed"` (property `rideModelSize`, option `modelSize`) keeps one size at every height. `ride-up="north"` (property `rideUp`, option `up`) puts north at the top of the view above a satellite, so it is seen to go the way it really goes; a small compass on a ride shows north and the heading (`compass="off"` hides it), `rideTrack` and `chikyu-ride-track` give the heading, ground point and whether the Sun lights it, and the chosen orbit is amber in sunlight and blue in the Earth's shadow (`path-light="off"` for one colour). `ride-model-share`, `ride-model-seat` and `ride-zoom` frame and zoom the ridden satellite (properties `rideModelShare`, `rideModelSeat`, `rideZoom`). `face("ahead")` (behind, left, right, down, up; the keys W, S, A, D, F, R) turns a ride from the satellite or following it that way; the view above a satellite looks down on it and has no facings, so there `face()` returns `false` and the camera stays as it was. In every view the camera is never under the ground: it is held at least 1 km above it. It animates continuously, so it keeps to the
|
|
363
363
|
same budget: at most 30 frames a second (one a second for reduced motion), nothing drawn while paused, out of sight or hidden. [Ride along guide](docs/guides/ride-along.md), [docs/ride-along.md](docs/ride-along.md).
|
|
364
364
|
|
|
365
365
|
## Printable sheets
|
|
@@ -615,7 +615,7 @@ console.log(countryList().filter((country) => country.alpha2 === null).map((coun
|
|
|
615
615
|
|
|
616
616
|
## How to cite
|
|
617
617
|
|
|
618
|
-
> Morris, J. (2026). *Chikyu Earth* (version 0.
|
|
618
|
+
> Morris, J. (2026). *Chikyu Earth* (version 0.64.0) [Computer software]. https://github.com/johnmorrisdotca/chikyu-earth
|
|
619
619
|
|
|
620
620
|
GitHub's "Cite this repository" button reads [CITATION.cff](CITATION.cff) and gives BibTeX and APA. Cite the version you used (`npm ls @johnmorrisdotca/chikyu-earth`), and credit the sources behind the numbers and pictures: [NOTICE.md](NOTICE.md) says who made each one and under what terms.
|
|
621
621
|
|
|
@@ -134,7 +134,7 @@ export interface RideOptions {
|
|
|
134
134
|
up?: RideUp;
|
|
135
135
|
/** How far back the camera is kept from the satellite in an outside ride, in kilometres (`view: "from"`; the element's `ride-outside-km` when not given, else 25). It is never more than half the satellite's height. */
|
|
136
136
|
outsideKm?: number;
|
|
137
|
-
/** How long the glide to this ride lasts: a number of milliseconds (1200 by default), or `{ minMs, maxMs }` for a length that follows how far the camera has to move (`rideGlideMs`: 800 to 4000 ms by default, about 1.2 s for a 25 km hop and 3 s for 3,000 km). */
|
|
137
|
+
/** How long the glide to this ride lasts: a number of milliseconds (1200 by default), or `{ minMs, maxMs }` for a length that follows how far the camera has to move (`rideGlideMs`: 800 to 4000 ms by default, about 1.2 s for a 25 km hop and 3 s for 3,000 km; from one satellite to another, the way along the great circle, `satelliteGlideKm`). */
|
|
138
138
|
glide?: number | {
|
|
139
139
|
minMs?: number;
|
|
140
140
|
maxMs?: number;
|
|
@@ -675,7 +675,7 @@ export declare class ChikyuSpace extends HTMLElement {
|
|
|
675
675
|
/**
|
|
676
676
|
* Ride along with a body or a satellite. By default the camera sits at it and looks at the Earth, with the way it is going at the top of the picture, at its real place for the moment shown, so the
|
|
677
677
|
* Earth turns and slides beneath as it moves along its orbit (an ISS view goes round about every 90 minutes). A drag looks about from there (a drag right turns the camera to its left and a drag up tips it towards the bottom of its picture, so the ground follows the pointer), the shared controls' zoom narrows the view.
|
|
678
|
-
* A satellite is `{ group, index }` of a group set with `setSatellites`; it is placed exactly, one SGP4 call a frame, at any speed. Another call switches smoothly; `null` stops. The draw rate follows how
|
|
678
|
+
* A satellite is `{ group, index }` of a group set with `setSatellites`; it is placed exactly, one SGP4 call a frame, at any speed. Another call switches smoothly; `null` stops. From one satellite to another the glide goes round the Earth along the great circle, never through it and at least 100 km above the ground, with the look carried along so a facing stays level (`satelliteGlide`); the glide back is the same flight the other way. The draw rate follows how
|
|
679
679
|
* fast the picture moves, never more than 30 a second (one a second for a reader who asked for reduced motion), and nothing is drawn out of sight.
|
|
680
680
|
* Whatever the view, facing, drag or glide, the camera is never under the ground: one that would be lower than 1 km above it is held there. A camera that looks at a satellite comes in towards it along its line of sight, so the satellite stays where it is in the picture; any other moves out along its line from the Earth's centre.
|
|
681
681
|
*
|
|
@@ -1764,7 +1764,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
1764
1764
|
/**
|
|
1765
1765
|
* Ride along with a body or a satellite. By default the camera sits at it and looks at the Earth, with the way it is going at the top of the picture, at its real place for the moment shown, so the
|
|
1766
1766
|
* Earth turns and slides beneath as it moves along its orbit (an ISS view goes round about every 90 minutes). A drag looks about from there (a drag right turns the camera to its left and a drag up tips it towards the bottom of its picture, so the ground follows the pointer), the shared controls' zoom narrows the view.
|
|
1767
|
-
* A satellite is `{ group, index }` of a group set with `setSatellites`; it is placed exactly, one SGP4 call a frame, at any speed. Another call switches smoothly; `null` stops. The draw rate follows how
|
|
1767
|
+
* A satellite is `{ group, index }` of a group set with `setSatellites`; it is placed exactly, one SGP4 call a frame, at any speed. Another call switches smoothly; `null` stops. From one satellite to another the glide goes round the Earth along the great circle, never through it and at least 100 km above the ground, with the look carried along so a facing stays level (`satelliteGlide`); the glide back is the same flight the other way. The draw rate follows how
|
|
1768
1768
|
* fast the picture moves, never more than 30 a second (one a second for a reader who asked for reduced motion), and nothing is drawn out of sight.
|
|
1769
1769
|
* Whatever the view, facing, drag or glide, the camera is never under the ground: one that would be lower than 1 km above it is held there. A camera that looks at a satellite comes in towards it along its line of sight, so the satellite stays where it is in the picture; any other moves out along its line from the Earth's centre.
|
|
1770
1770
|
*
|
|
@@ -1775,6 +1775,9 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
1775
1775
|
const model = this.#model;
|
|
1776
1776
|
const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
1777
1777
|
const wasRiding = model.ride !== null;
|
|
1778
|
+
const was = model.ride?.target;
|
|
1779
|
+
// from one satellite to another the glide goes round the Earth along the great circle (`satelliteGlide`), never through it; any other change of ride glides in a straight line
|
|
1780
|
+
const round = !!was && typeof was !== "string" && !!target && typeof target !== "string" && (was.group !== target.group || was.index !== target.index);
|
|
1778
1781
|
model.rideFrame.share = clampFrame(options.modelShare, 0.02, 1.2) ?? this.rideModelShare;
|
|
1779
1782
|
model.rideFrame.seat = clampFrame(options.modelSeat, 0.5, 1.4) ?? this.rideModelSeat;
|
|
1780
1783
|
model.rideFrame.ms = reduced ? 0 : 400;
|
|
@@ -1814,7 +1817,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
1814
1817
|
this.#lostTold = false;
|
|
1815
1818
|
const pose = model.pose;
|
|
1816
1819
|
const glide = readGlide(options.glide);
|
|
1817
|
-
model.transition = (options.smooth ?? true) && !reduced && pose.valid ? { start: performance.now(), duration: glide.duration, ...(glide.scaled ? { scaled: glide.scaled } : {}), 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;
|
|
1820
|
+
model.transition = (options.smooth ?? true) && !reduced && pose.valid ? { start: performance.now(), duration: glide.duration, ...(glide.scaled ? { scaled: glide.scaled } : {}), ...(round ? { round } : {}), 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;
|
|
1818
1821
|
this.#last = performance.now();
|
|
1819
1822
|
this.#schedule();
|
|
1820
1823
|
this.#gate?.request();
|
package/dist/space/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, orbitP
|
|
|
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 RideTrack, type BodyMoon, type BodyPainter, type BodyView, type PaintContext, type SatellitePainter } from "./scene.ts";
|
|
4
4
|
export { faceOffset, OUTSIDE_KM, outsidePose, RIDE_FACES, RIDE_FOV, rideFov, rideGlideMs, ridePose, rideTiltLimits, rideTurnDegrees, type RideDrag, type RideFace, type RideInput, type RideLook, type RidePose, type RideModelSize, type RideViewpoint } from "./ride.ts";
|
|
5
|
+
export { GLIDE_FLOOR_KM, satelliteGlide, satelliteGlideKm, type GlidePose, type Quat } from "./ride-glide.ts";
|
|
5
6
|
export { earthHides, type SatelliteScreen } from "./satellite-layer.ts";
|
|
6
7
|
export { ABOVE_MODEL_KM, ABOVE_MODEL_SHARE, aboveAxes, aboveModelShare, MODEL_FADE_FROM_KM, MODEL_FADE_TO_KM, MODEL_HANDOVER_PX, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.ts";
|
|
7
8
|
export { localNorth, NORTH_UP_BLEND_DEG, NORTH_UP_POLE_DEG, northUpYaw, screenAngle, type RideUp } from "./north-up.ts";
|
package/dist/space/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, orbitP
|
|
|
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
6
|
export { faceOffset, OUTSIDE_KM, outsidePose, RIDE_FACES, RIDE_FOV, rideFov, rideGlideMs, ridePose, rideTiltLimits, rideTurnDegrees } from "./ride.js";
|
|
7
|
+
export { GLIDE_FLOOR_KM, satelliteGlide, satelliteGlideKm } from "./ride-glide.js";
|
|
7
8
|
export { earthHides } from "./satellite-layer.js";
|
|
8
9
|
export { ABOVE_MODEL_KM, ABOVE_MODEL_SHARE, aboveAxes, aboveModelShare, MODEL_FADE_FROM_KM, MODEL_FADE_TO_KM, MODEL_HANDOVER_PX, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
|
|
9
10
|
export { localNorth, NORTH_UP_BLEND_DEG, NORTH_UP_POLE_DEG, northUpYaw, screenAngle } from "./north-up.js";
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { Vec3 } from "./ephemeris.ts";
|
|
2
|
+
/**
|
|
3
|
+
* A rotation as a quaternion, `[x, y, z, w]` (three.js's order).
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import type { Quat } from "@johnmorrisdotca/chikyu-earth/space";
|
|
8
|
+
*
|
|
9
|
+
* const still: Quat = [0, 0, 0, 1];
|
|
10
|
+
* console.log(still[3]);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export type Quat = [number, number, number, number];
|
|
14
|
+
/**
|
|
15
|
+
* A camera's place and orientation: `p` in Earth radii from the Earth's centre, `q` the rotation from the camera's own axes (it looks down its -z, its up is +y) to the scene's.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import type { GlidePose } from "@johnmorrisdotca/chikyu-earth/space";
|
|
20
|
+
*
|
|
21
|
+
* const pose: GlidePose = { p: [1.07, 0, 0], q: [0, 0, 0, 1] };
|
|
22
|
+
* console.log(pose.p[0]);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export interface GlidePose {
|
|
26
|
+
p: Vec3;
|
|
27
|
+
q: Quat;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The least height above the ground, in km, that the glide from one satellite's ride to another's keeps between its two ends (`satelliteGlide`). Ends lower than this (a satellite coming down) are left
|
|
31
|
+
* where they are and the glide rises over the floor between them.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { GLIDE_FLOOR_KM } from "@johnmorrisdotca/chikyu-earth/space";
|
|
36
|
+
*
|
|
37
|
+
* console.log(`${GLIDE_FLOOR_KM} km`);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare const GLIDE_FLOOR_KM = 100;
|
|
41
|
+
/**
|
|
42
|
+
* Where the camera is, a share `ease` (0 to 1) along the glide from one satellite's ride to another's. It goes along the great circle round the Earth's centre from the first place to the second, its distance from
|
|
43
|
+
* the centre going evenly from the one to the other, so it never passes through the Earth or dips under the two heights; between ends lower than `floorKm` above the ground it rises over that floor in the middle.
|
|
44
|
+
* The look is carried along the circle (turned with it, as the local vertical turns) and goes over the way from the first look to the second in the same frame, so a facing along the ground stays level, a facing
|
|
45
|
+
* down stays down, nothing rolls over, and the view turns once towards its end. The glide back is the same glide the other way: `satelliteGlide(to, from, 1 - ease)` is the same pose. A short hop is all but the
|
|
46
|
+
* straight glide: the circle is about 10 m from the straight line half way along a hop of 25 km.
|
|
47
|
+
*
|
|
48
|
+
* @param from - The camera where the glide began.
|
|
49
|
+
* @param to - The camera of the ride it goes to (its pose this frame: the satellite may move).
|
|
50
|
+
* @param ease - How far along, 0 at the start and 1 at the end (eased by the caller).
|
|
51
|
+
* @param floorKm - The least height above the ground between the ends, km (`GLIDE_FLOOR_KM`).
|
|
52
|
+
* @returns The camera's place and orientation there.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { satelliteGlide } from "@johnmorrisdotca/chikyu-earth/space";
|
|
57
|
+
*
|
|
58
|
+
* // from over one side of the Earth to over the other: half way, the camera is over the Earth's edge, not inside it
|
|
59
|
+
* const mid = satelliteGlide({ p: [1.07, 0, 0], q: [0, 0, 0, 1] }, { p: [-1.07, 0, 0.01], q: [0, 0, 0, 1] }, 0.5);
|
|
60
|
+
* console.log(Math.hypot(...mid.p).toFixed(2));
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function satelliteGlide(from: GlidePose, to: GlidePose, ease: number, floorKm?: number): GlidePose;
|
|
64
|
+
/**
|
|
65
|
+
* How far, in km, the camera goes in the glide from one satellite's ride to another's (`satelliteGlide`): along the great circle, with the change of height. For a glide whose length follows the distance (`rideGlideMs`).
|
|
66
|
+
*
|
|
67
|
+
* @param from - Where the glide begins, Earth radii from the Earth's centre.
|
|
68
|
+
* @param to - Where it ends.
|
|
69
|
+
* @returns The length, km.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* import { satelliteGlideKm } from "@johnmorrisdotca/chikyu-earth/space";
|
|
74
|
+
*
|
|
75
|
+
* console.log(Math.round(satelliteGlideKm([1.07, 0, 0], [0, 1.07, 0])));
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare function satelliteGlideKm(from: Vec3, to: Vec3): number;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The least height above the ground, in km, that the glide from one satellite's ride to another's keeps between its two ends (`satelliteGlide`). Ends lower than this (a satellite coming down) are left
|
|
3
|
+
* where they are and the glide rises over the floor between them.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { GLIDE_FLOOR_KM } from "@johnmorrisdotca/chikyu-earth/space";
|
|
8
|
+
*
|
|
9
|
+
* console.log(`${GLIDE_FLOOR_KM} km`);
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export const GLIDE_FLOOR_KM = 100;
|
|
13
|
+
const EARTH_KM = 6371;
|
|
14
|
+
const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
15
|
+
const cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
|
16
|
+
const norm = (a) => Math.hypot(a[0], a[1], a[2]);
|
|
17
|
+
/** `a` then `b`: the rotation `b` followed by `a` (`a * b`). */
|
|
18
|
+
function mul(a, b) {
|
|
19
|
+
return [
|
|
20
|
+
a[3] * b[0] + a[0] * b[3] + a[1] * b[2] - a[2] * b[1],
|
|
21
|
+
a[3] * b[1] - a[0] * b[2] + a[1] * b[3] + a[2] * b[0],
|
|
22
|
+
a[3] * b[2] + a[0] * b[1] - a[1] * b[0] + a[2] * b[3],
|
|
23
|
+
a[3] * b[3] - a[0] * b[0] - a[1] * b[1] - a[2] * b[2],
|
|
24
|
+
];
|
|
25
|
+
}
|
|
26
|
+
/** The rotation by `angle` radians about the unit `axis`. */
|
|
27
|
+
const about = (axis, angle) => { const s = Math.sin(angle / 2); return [axis[0] * s, axis[1] * s, axis[2] * s, Math.cos(angle / 2)]; };
|
|
28
|
+
/** The shorter way from `a` to `b`, a share `t` along it, normalised. */
|
|
29
|
+
function slerp(a, b, t) {
|
|
30
|
+
let c = a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
|
|
31
|
+
const s = c < 0 ? -1 : 1;
|
|
32
|
+
c *= s;
|
|
33
|
+
let ka = 1 - t, kb = t * s;
|
|
34
|
+
if (c < 0.9995) {
|
|
35
|
+
const half = Math.acos(Math.min(1, c)), sin = Math.sin(half);
|
|
36
|
+
ka = Math.sin((1 - t) * half) / sin;
|
|
37
|
+
kb = (Math.sin(t * half) / sin) * s;
|
|
38
|
+
}
|
|
39
|
+
const out = [a[0] * ka + b[0] * kb, a[1] * ka + b[1] * kb, a[2] * ka + b[2] * kb, a[3] * ka + b[3] * kb];
|
|
40
|
+
const n = Math.hypot(...out) || 1;
|
|
41
|
+
return [out[0] / n, out[1] / n, out[2] / n, out[3] / n];
|
|
42
|
+
}
|
|
43
|
+
/** The great circle from the direction of `a` to that of `b` (both from the Earth's centre): the axis it turns about and the angle, radians. Opposite directions turn about a line square to `a`. */
|
|
44
|
+
function greatCircle(a, b) {
|
|
45
|
+
const c = cross(a, b), sin = norm(c), cos = dot(a, b);
|
|
46
|
+
const angle = Math.atan2(sin, cos);
|
|
47
|
+
if (sin > 1e-9 * norm(a) * norm(b))
|
|
48
|
+
return { axis: [c[0] / sin, c[1] / sin, c[2] / sin], angle };
|
|
49
|
+
if (cos >= 0)
|
|
50
|
+
return { axis: [0, 0, 1], angle: 0 };
|
|
51
|
+
const side = Math.abs(a[1]) < 0.9 * norm(a) ? cross(a, [0, 1, 0]) : cross(a, [1, 0, 0]);
|
|
52
|
+
const n = norm(side);
|
|
53
|
+
return { axis: [side[0] / n, side[1] / n, side[2] / n], angle };
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Where the camera is, a share `ease` (0 to 1) along the glide from one satellite's ride to another's. It goes along the great circle round the Earth's centre from the first place to the second, its distance from
|
|
57
|
+
* the centre going evenly from the one to the other, so it never passes through the Earth or dips under the two heights; between ends lower than `floorKm` above the ground it rises over that floor in the middle.
|
|
58
|
+
* The look is carried along the circle (turned with it, as the local vertical turns) and goes over the way from the first look to the second in the same frame, so a facing along the ground stays level, a facing
|
|
59
|
+
* down stays down, nothing rolls over, and the view turns once towards its end. The glide back is the same glide the other way: `satelliteGlide(to, from, 1 - ease)` is the same pose. A short hop is all but the
|
|
60
|
+
* straight glide: the circle is about 10 m from the straight line half way along a hop of 25 km.
|
|
61
|
+
*
|
|
62
|
+
* @param from - The camera where the glide began.
|
|
63
|
+
* @param to - The camera of the ride it goes to (its pose this frame: the satellite may move).
|
|
64
|
+
* @param ease - How far along, 0 at the start and 1 at the end (eased by the caller).
|
|
65
|
+
* @param floorKm - The least height above the ground between the ends, km (`GLIDE_FLOOR_KM`).
|
|
66
|
+
* @returns The camera's place and orientation there.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* import { satelliteGlide } from "@johnmorrisdotca/chikyu-earth/space";
|
|
71
|
+
*
|
|
72
|
+
* // from over one side of the Earth to over the other: half way, the camera is over the Earth's edge, not inside it
|
|
73
|
+
* const mid = satelliteGlide({ p: [1.07, 0, 0], q: [0, 0, 0, 1] }, { p: [-1.07, 0, 0.01], q: [0, 0, 0, 1] }, 0.5);
|
|
74
|
+
* console.log(Math.hypot(...mid.p).toFixed(2));
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export function satelliteGlide(from, to, ease, floorKm = GLIDE_FLOOR_KM) {
|
|
78
|
+
const r0 = norm(from.p), r1 = norm(to.p);
|
|
79
|
+
if (r0 < 1e-9 || r1 < 1e-9)
|
|
80
|
+
return { p: [...to.p], q: [...to.q] };
|
|
81
|
+
const { axis, angle } = greatCircle(from.p, to.p);
|
|
82
|
+
const turn = about(axis, angle * ease);
|
|
83
|
+
const along = [from.p[0] / r0, from.p[1] / r0, from.p[2] / r0];
|
|
84
|
+
const c = Math.cos(angle * ease), s = Math.sin(angle * ease), k = dot(axis, along) * (1 - c), side = cross(axis, along);
|
|
85
|
+
const u = [along[0] * c + side[0] * s + axis[0] * k, along[1] * c + side[1] * s + axis[1] * k, along[2] * c + side[2] * s + axis[2] * k];
|
|
86
|
+
const floor = 1 + Math.max(0, floorKm) / EARTH_KM;
|
|
87
|
+
const lift = Math.max(0, floor - Math.min(r0, r1)) * Math.sin(Math.PI * Math.min(1, Math.max(0, ease)));
|
|
88
|
+
const r = r0 + (r1 - r0) * ease + lift;
|
|
89
|
+
// the second look, as it would be at the first place (turned back along the circle), then the way between the two looks, turned on to where the camera is
|
|
90
|
+
const back = [-axis[0] * Math.sin(angle / 2), -axis[1] * Math.sin(angle / 2), -axis[2] * Math.sin(angle / 2), Math.cos(angle / 2)];
|
|
91
|
+
const q = mul(turn, slerp(from.q, mul(back, to.q), ease));
|
|
92
|
+
return { p: [u[0] * r, u[1] * r, u[2] * r], q };
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* How far, in km, the camera goes in the glide from one satellite's ride to another's (`satelliteGlide`): along the great circle, with the change of height. For a glide whose length follows the distance (`rideGlideMs`).
|
|
96
|
+
*
|
|
97
|
+
* @param from - Where the glide begins, Earth radii from the Earth's centre.
|
|
98
|
+
* @param to - Where it ends.
|
|
99
|
+
* @returns The length, km.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* import { satelliteGlideKm } from "@johnmorrisdotca/chikyu-earth/space";
|
|
104
|
+
*
|
|
105
|
+
* console.log(Math.round(satelliteGlideKm([1.07, 0, 0], [0, 1.07, 0])));
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export function satelliteGlideKm(from, to) {
|
|
109
|
+
const r0 = norm(from), r1 = norm(to);
|
|
110
|
+
const { angle } = greatCircle(from, to);
|
|
111
|
+
return Math.hypot(angle * (r0 + r1) / 2, r1 - r0) * EARTH_KM;
|
|
112
|
+
}
|
package/dist/space/scene.d.ts
CHANGED
|
@@ -243,7 +243,10 @@ export interface SpaceModel {
|
|
|
243
243
|
ride: RideState | null;
|
|
244
244
|
/** Set at each draw: the target of the ride could not be placed (a satellite whose elements are too old, or that is gone), so the ordinary camera was used. */
|
|
245
245
|
rideLost: boolean;
|
|
246
|
-
/**
|
|
246
|
+
/**
|
|
247
|
+
* A camera move in progress from where the last draw left it: when it began (ms of the page's clock), how long it takes. `round`: a ride that went from one satellite to another, which glides along the great circle
|
|
248
|
+
* round the Earth's centre (`satelliteGlide`); every other move is a straight line.
|
|
249
|
+
*/
|
|
247
250
|
transition: {
|
|
248
251
|
start: number;
|
|
249
252
|
duration: number;
|
|
@@ -251,6 +254,7 @@ export interface SpaceModel {
|
|
|
251
254
|
minMs: number;
|
|
252
255
|
maxMs: number;
|
|
253
256
|
};
|
|
257
|
+
round?: boolean;
|
|
254
258
|
from: {
|
|
255
259
|
p: Vec3;
|
|
256
260
|
q: [number, number, number, number];
|
package/dist/space/scene.js
CHANGED
|
@@ -7,6 +7,7 @@ import { createTileSet } from "../realistic/tile-set.js";
|
|
|
7
7
|
import { createTrack, orbitPath, PLANETS } from "./ephemeris.js";
|
|
8
8
|
import { placeAround, placeMoon, placeSun, RADIUS } from "./scale.js";
|
|
9
9
|
import { faceOffset, outsidePose, rideGlideMs, ridePose } from "./ride.js";
|
|
10
|
+
import { satelliteGlide, satelliteGlideKm } from "./ride-glide.js";
|
|
10
11
|
import { stripLights } from "./model-lights.js";
|
|
11
12
|
import { cloudFade, CLOUD_FADE_DEFAULT, CLOUD_WIDTH } from "../realistic/cloud-fade.js";
|
|
12
13
|
import { newLightFade, stepLightFade } from "../realistic/light-fade.js";
|
|
@@ -774,16 +775,24 @@ export function createSpaceItem(model, deps) {
|
|
|
774
775
|
if (glide) {
|
|
775
776
|
// a glide that follows the distance takes its length from how far the camera has to go, at its first frame
|
|
776
777
|
if (glide.scaled) {
|
|
777
|
-
const km = Math.hypot(camera.position.x - glide.from.p[0], camera.position.y - glide.from.p[1], camera.position.z - glide.from.p[2]) * 6371;
|
|
778
|
+
const km = glide.round ? satelliteGlideKm(glide.from.p, [camera.position.x, camera.position.y, camera.position.z]) : Math.hypot(camera.position.x - glide.from.p[0], camera.position.y - glide.from.p[1], camera.position.z - glide.from.p[2]) * 6371;
|
|
778
779
|
glide.duration = rideGlideMs(km, glide.scaled.minMs, glide.scaled.maxMs);
|
|
779
780
|
delete glide.scaled;
|
|
780
781
|
}
|
|
781
782
|
const k = Math.min(1, (performance.now() - glide.start) / glide.duration);
|
|
782
783
|
const ease = k * k * (3 - 2 * k);
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
784
|
+
if (glide.round) {
|
|
785
|
+
// from one satellite to another: round the Earth along the great circle, the look carried with it, so it never goes through the Earth and a facing stays level
|
|
786
|
+
const at = satelliteGlide(glide.from, { p: [camera.position.x, camera.position.y, camera.position.z], q: [camera.quaternion.x, camera.quaternion.y, camera.quaternion.z, camera.quaternion.w] }, ease);
|
|
787
|
+
camera.position.set(at.p[0], at.p[1], at.p[2]);
|
|
788
|
+
camera.quaternion.set(at.q[0], at.q[1], at.q[2], at.q[3]);
|
|
789
|
+
}
|
|
790
|
+
else {
|
|
791
|
+
desiredQ.copy(camera.quaternion);
|
|
792
|
+
camera.position.set(glide.from.p[0] + (camera.position.x - glide.from.p[0]) * ease, glide.from.p[1] + (camera.position.y - glide.from.p[1]) * ease, glide.from.p[2] + (camera.position.z - glide.from.p[2]) * ease);
|
|
793
|
+
fromQ.set(glide.from.q[0], glide.from.q[1], glide.from.q[2], glide.from.q[3]);
|
|
794
|
+
camera.quaternion.copy(fromQ.slerp(desiredQ, ease));
|
|
795
|
+
}
|
|
787
796
|
fovNow = glide.from.fov + (fovNow - glide.from.fov) * ease;
|
|
788
797
|
if (k >= 1)
|
|
789
798
|
model.transition = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/chikyu-earth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.64.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",
|