@johnmorrisdotca/chikyu-earth 0.8.0 → 0.9.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 +21 -0
- package/README.md +8 -0
- package/dist/space/element.d.ts +69 -4
- package/dist/space/element.js +76 -6
- package/dist/space/ephemeris.d.ts +3 -1
- package/dist/space/ephemeris.js +5 -1
- package/dist/space/index.d.ts +1 -0
- package/dist/space/index.js +1 -0
- package/dist/space/ride.d.ts +83 -0
- package/dist/space/ride.js +57 -0
- package/dist/space/scene.d.ts +56 -0
- package/dist/space/scene.js +124 -16
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.9.0
|
|
4
|
+
|
|
5
|
+
Ride along: the camera on the ISS, a Starlink satellite, the Moon or a planet, looking at the Earth.
|
|
6
|
+
|
|
7
|
+
- **`element.ride(target, options)`** on `<chikyu-space>`: the camera sits at a moving body at its real place for the moment shown and looks at the Earth, with the way the body is going at the top of the picture; the Earth turns and slides beneath it as the body goes along its orbit
|
|
8
|
+
(an ISS view goes round in about 93 minutes). `target` is a body name (`"Moon"`, `"Mars"`, ...) or a satellite of a group (`{ group, index }`). Options: `view: "from"` (the default) or `"follow"` (a fixed distance from the body, looking at it; `distanceKm` for a satellite), `look: "down"` (the default) or
|
|
9
|
+
`"horizon"` (tipped forward until the horizon is a little above the middle), and `smooth`. The shared controls' tilt tips the camera further, their yaw turns it round the straight-down line, their zoom narrows the 60 degree field of view. Time is the page's clock, forwards, backwards, faster or slower.
|
|
10
|
+
`element.riding`, the `chikyu-ride` event, and `chikyu-ride-lost` (the satellite could not be placed on this date: its elements are too old; the ordinary camera comes back). A ridden satellite is placed exactly, one SGP4 call a frame, at any speed, even where its group is hidden.
|
|
11
|
+
- **Switching is smooth**: another `ride` call glides the camera's place, its turn (spherical interpolation) and its field of view from where the last draw left them to the new camera over 1.2 seconds, eased; reduced motion jumps. `ride(null)` stops.
|
|
12
|
+
- **`ridePose(input)`** (`@johnmorrisdotca/chikyu-earth/space`, pure, no browser): where the camera looks, for a place, a way of travel, a look and the controls' yaw, tilt and zoom. Unit-tested (looking down at the Earth's centre, the way it goes at the top, the horizon look, tilt, yaw, zoom, no way of travel).
|
|
13
|
+
- **Budget, each line tested** (`e2e/ride.gl.ts`): the camera is within 1 km of satellite.js's own place for the ISS and 420 km up; at 60 times real time it goes round the Earth at the ISS's rate (301 game seconds: 19.4 degrees, 19.4 expected); riding the Moon puts it 10 Earth radii away in the compressed scale and 55 to 66 in the true one;
|
|
14
|
+
it animates continuously but at most 30 frames a second (the ISS at real time 6.5 a second, at 60 times 28.5, Mars at a day a second 28.5); paused, 0 GL draws and 0 frame requests; scrolled away or in a hidden tab, 0 GL draws at 60 times; reduced motion 1.00 frames a second at 60 times, and a jump instead of a glide; the glide from the ISS to the Moon takes 1.4 s
|
|
15
|
+
and then rests; a satellite too old for the date gives `chikyu-ride-lost`; two more rounds of six switches add no buffers, textures or vertex arrays; a lost context comes back with the ride. The freeze test has a fourth look, the space view riding the ISS (and the look-changing rounds ride the ISS and the Moon). The ten-minute soak rides every
|
|
16
|
+
way (the ISS, Tiangong, a Starlink satellite, the Moon, Mars, from it and behind it, down and at the horizon) while it adds, removes and chooses satellites: 965 steps, JS heap 14.35 to 14.51 MB after garbage collection, GPU objects 123 to 123, one WebGL context, no error.
|
|
17
|
+
- **The Auto-turn of the controls no longer draws thirty times a second in the space view.** Its turn at the Earth's own rate moves nothing visible in seconds, but every frame of it asked the space view for a draw. `setView(view, final = true)` now keeps a turn that moves less than half a pixel for the next draw and does not draw for it unless `final` is true:
|
|
18
|
+
8 seconds of Auto-turn now make 0 draws (the controls ask for 480 animation frames in that time). This holds for the Earth's views, for riding, and for satellites.
|
|
19
|
+
- **Demo**: a "Ride along" row in the space look (ISS, Tiangong, a Starlink satellite, Moon, Mars, Stop; View: From it or Behind it; Looking: Straight down or At the horizon), with a line saying what is ridden, in English and Japanese (the Japanese page is tested for English words left in a control). The choices are kept in the address (`ride`, `rview`, `rlook`).
|
|
20
|
+
The embed takes `ride=iss|css|starlink|Moon|Mars`, `rview=follow` and `rlook=horizon`; its test: one context, the ISS's height, nothing drawn at rest, a Moon ride at a day a second capped.
|
|
21
|
+
- **Docs**: a ride-along guide in English and Japanese, a page for it (docs/ride-along.md) and every new export with TSDoc and an example, usage examples run by `pnpm test:usage` (a Vite page that rides the ISS and is opened in a browser; `ridePose` in Node), README section, screenshots. The space view has no markers (those belong to the flat and the realistic globes), so the ticket's "markers stay on the ground" has nothing to do here.
|
|
22
|
+
- The names beside the bodies are not drawn for the body being ridden (the camera is inside it) and the Earth's is not drawn when riding at a body.
|
|
23
|
+
|
|
3
24
|
## 0.8.0
|
|
4
25
|
|
|
5
26
|
Satellites on the space view, the space view in the embed, and the demo's space controls in Japanese.
|
package/README.md
CHANGED
|
@@ -149,6 +149,14 @@ const elements: ElementSet[] = await (await fetch("/my-celestrak-copy.json")).js
|
|
|
149
149
|
document.querySelector("chikyu-space")!.setSatellites("stations", createSatellites(elements), { orbits: true });
|
|
150
150
|
```
|
|
151
151
|
|
|
152
|
+
## Riding along
|
|
153
|
+
|
|
154
|
+
<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>
|
|
155
|
+
|
|
156
|
+
`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
|
|
157
|
+
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. It animates continuously, so it keeps to the
|
|
158
|
+
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).
|
|
159
|
+
|
|
152
160
|
## Markers
|
|
153
161
|
|
|
154
162
|
Mark any place at `[lon, lat]` with a label, colour or icon, in groups you can show or hide, on either look. Chikyu ships no places; yours move with the globe, fade on the far side, make room
|
package/dist/space/element.d.ts
CHANGED
|
@@ -2,9 +2,10 @@ import type { GeoPoint } from "../types.ts";
|
|
|
2
2
|
import { setThreeLoader } from "../realistic/shared.ts";
|
|
3
3
|
import type { SatelliteInfo, SatelliteRef, Satellites } from "../satellites/types.ts";
|
|
4
4
|
import { type SatelliteStyle } from "./satellite-layer.ts";
|
|
5
|
+
import type { RideLook } from "./ride.ts";
|
|
5
6
|
import { type ScaleMode } from "./scale.ts";
|
|
6
|
-
import { BODY_NAMES, type BodyName, type BodyPainter } from "./scene.ts";
|
|
7
|
-
export { BODY_NAMES, type BodyName };
|
|
7
|
+
import { BODY_NAMES, type BodyName, type BodyPainter, type RideTarget } from "./scene.ts";
|
|
8
|
+
export { BODY_NAMES, type BodyName, type RideTarget };
|
|
8
9
|
/**
|
|
9
10
|
* Change how the Sun and the planets are drawn (before the first element connects): the space view keeps their places, sizes, light, names and orbits and asks
|
|
10
11
|
* the painter only for what to draw at each place (see `BodyPainter`). Left alone, they are plain spheres in the right colours.
|
|
@@ -63,6 +64,42 @@ export type SpaceState = "loading" | "live" | "unavailable" | "lost" | "idle";
|
|
|
63
64
|
* ```
|
|
64
65
|
*/
|
|
65
66
|
export type SpacePreset = "earth" | "moon" | "sun" | "inner" | "solar-system";
|
|
67
|
+
/**
|
|
68
|
+
* How a ride along is done: `view` `from` (the default) puts the camera at the body looking at the Earth, `follow` keeps it a fixed distance from the body looking at it (`distanceKm`, 3000 by default,
|
|
69
|
+
* for a satellite; a planet or the Moon is kept at the distance the zoom says); `look` `down` (the default) or `horizon` is where a camera at the body points; `smooth` (the default) glides
|
|
70
|
+
* from the old camera to the new one in about a second and a bit, and jumps instead for a reader who asked for reduced motion.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts no-run
|
|
74
|
+
* import type { RideOptions } from "@johnmorrisdotca/chikyu-earth/space/element";
|
|
75
|
+
*
|
|
76
|
+
* const options: RideOptions = { view: "from", look: "horizon" };
|
|
77
|
+
* console.log(options.look);
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export interface RideOptions {
|
|
81
|
+
view?: "from" | "follow";
|
|
82
|
+
look?: RideLook;
|
|
83
|
+
distanceKm?: number;
|
|
84
|
+
smooth?: boolean;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* What the camera is riding along with now: the body or satellite, how (`from` or `follow`), where it looks, and the distance kept for a satellite.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts no-run
|
|
91
|
+
* import type { Riding } from "@johnmorrisdotca/chikyu-earth/space/element";
|
|
92
|
+
*
|
|
93
|
+
* const describe = (ride: Riding | null): string => (ride ? `${ride.view} ${typeof ride.target === "string" ? ride.target : ride.target.group}` : "not riding");
|
|
94
|
+
* console.log(typeof describe);
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export interface Riding {
|
|
98
|
+
target: RideTarget;
|
|
99
|
+
view: "from" | "follow";
|
|
100
|
+
look: RideLook;
|
|
101
|
+
distanceKm: number;
|
|
102
|
+
}
|
|
66
103
|
type SatelliteStats = {
|
|
67
104
|
groups: number;
|
|
68
105
|
placed: number;
|
|
@@ -108,15 +145,33 @@ export declare class ChikyuSpace extends HTMLElement {
|
|
|
108
145
|
set labels(value: boolean);
|
|
109
146
|
get orbits(): boolean;
|
|
110
147
|
set orbits(value: boolean);
|
|
111
|
-
/**
|
|
148
|
+
/**
|
|
149
|
+
* The shared controls' camera: yaw and tilt turn the view, zoom brings the camera in (1 shows the Earth, less shows the sky round it). Pan is not used. A turn that moves nothing on the screen by half a pixel is kept
|
|
150
|
+
* for the next draw but does not cause one unless `final` is true (the default), so an Auto-turn at the Earth's own rate costs a draw every half minute, not thirty a second.
|
|
151
|
+
*
|
|
152
|
+
* @param view - The controls' yaw and tilt in degrees and zoom.
|
|
153
|
+
* @param final - False for the frames of a turn that is still going on (Auto-turn, a drag); true when it has settled.
|
|
154
|
+
*/
|
|
112
155
|
setView(view: {
|
|
113
156
|
yaw: number;
|
|
114
157
|
tilt: number;
|
|
115
158
|
zoom: number;
|
|
116
|
-
}): void;
|
|
159
|
+
}, final?: boolean): void;
|
|
117
160
|
/** The body the camera looks at: at zoom 1 it fills the view; the yaw and tilt turn the camera round it. */
|
|
118
161
|
get body(): BodyName;
|
|
119
162
|
set body(name: BodyName);
|
|
163
|
+
/**
|
|
164
|
+
* 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
|
|
165
|
+
* Earth turns and slides beneath as it moves along its orbit (an ISS view goes round about every 90 minutes). The shared controls' yaw and tilt turn the view and tip it towards the horizon, their zoom narrows it.
|
|
166
|
+
* 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
|
|
167
|
+
* 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.
|
|
168
|
+
*
|
|
169
|
+
* @param target - A body name (`"Moon"`, `"Mars"`, ...) or a satellite `{ group, index }`, or `null` to stop.
|
|
170
|
+
* @param options - `view`, `look`, `distanceKm`, `smooth` (see `RideOptions`).
|
|
171
|
+
*/
|
|
172
|
+
ride(target: RideTarget | null, options?: RideOptions): void;
|
|
173
|
+
/** What the camera is riding along with now, or null. */
|
|
174
|
+
get riding(): Riding | null;
|
|
120
175
|
/**
|
|
121
176
|
* Show a group of satellites (made by `createSatellites`) under a name, or take the group away with `null`. A group is one draw call however many satellites it holds. Giving the name of a group
|
|
122
177
|
* that is already shown replaces it. `style`: `color` and `size` (CSS pixels) of the dots, and `orbits` to draw every orbit (only for a group of 40 or fewer, such as the stations).
|
|
@@ -170,6 +225,16 @@ export declare class ChikyuSpace extends HTMLElement {
|
|
|
170
225
|
time: number;
|
|
171
226
|
lookups: number;
|
|
172
227
|
satellites: SatelliteStats;
|
|
228
|
+
ride: {
|
|
229
|
+
riding: boolean;
|
|
230
|
+
lost: boolean;
|
|
231
|
+
gliding: boolean;
|
|
232
|
+
};
|
|
233
|
+
/** The camera as the last draw left it: its place in Earth radii from the Earth's centre, and its field of view in degrees. */
|
|
234
|
+
camera: {
|
|
235
|
+
position: [number, number, number];
|
|
236
|
+
fov: number;
|
|
237
|
+
};
|
|
173
238
|
};
|
|
174
239
|
}
|
|
175
240
|
declare global {
|
package/dist/space/element.js
CHANGED
|
@@ -78,6 +78,8 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
78
78
|
#pool = new Map();
|
|
79
79
|
#places;
|
|
80
80
|
#chosenLabel;
|
|
81
|
+
#focusBeforeRide = "Earth";
|
|
82
|
+
#lostTold = false;
|
|
81
83
|
#names = {};
|
|
82
84
|
#hint = "choose to look at it";
|
|
83
85
|
#tiers = {};
|
|
@@ -120,6 +122,8 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
120
122
|
},
|
|
121
123
|
onLabels: (places) => this.#placeLabels(places),
|
|
122
124
|
onSelected: (place) => this.#placeChosen(place),
|
|
125
|
+
onMoving: () => this.#gate?.request(),
|
|
126
|
+
onRideLost: () => this.#rideLost(),
|
|
123
127
|
onSatellitesError: (error) => this.dispatchEvent(new CustomEvent("chikyu-satellites-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
|
|
124
128
|
...(painter ? { painter } : {}),
|
|
125
129
|
});
|
|
@@ -219,12 +223,24 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
219
223
|
this.#model.orbits = value;
|
|
220
224
|
this.#gate?.request();
|
|
221
225
|
}
|
|
222
|
-
/**
|
|
223
|
-
|
|
226
|
+
/**
|
|
227
|
+
* The shared controls' camera: yaw and tilt turn the view, zoom brings the camera in (1 shows the Earth, less shows the sky round it). Pan is not used. A turn that moves nothing on the screen by half a pixel is kept
|
|
228
|
+
* for the next draw but does not cause one unless `final` is true (the default), so an Auto-turn at the Earth's own rate costs a draw every half minute, not thirty a second.
|
|
229
|
+
*
|
|
230
|
+
* @param view - The controls' yaw and tilt in degrees and zoom.
|
|
231
|
+
* @param final - False for the frames of a turn that is still going on (Auto-turn, a drag); true when it has settled.
|
|
232
|
+
*/
|
|
233
|
+
setView(view, final = true) {
|
|
224
234
|
const now = this.#model.view;
|
|
225
235
|
if (view.yaw === now.yaw && view.tilt === now.tilt && view.zoom === now.zoom)
|
|
226
236
|
return;
|
|
227
237
|
this.#model.view = { yaw: view.yaw, tilt: view.tilt, zoom: view.zoom };
|
|
238
|
+
const drawn = this.#model.drawnView;
|
|
239
|
+
if (drawn && !final && view.zoom === drawn.zoom) {
|
|
240
|
+
const turned = Math.max(Math.abs(view.yaw - drawn.yaw), Math.abs(view.tilt - drawn.tilt)) * RAD;
|
|
241
|
+
if (turned * (this.#model.heightPx / 2) < 0.5)
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
228
244
|
this.#gate?.request();
|
|
229
245
|
}
|
|
230
246
|
/** The body the camera looks at: at zoom 1 it fills the view; the yaw and tilt turn the camera round it. */
|
|
@@ -237,6 +253,57 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
237
253
|
this.#model.focus = name;
|
|
238
254
|
this.#gate?.request();
|
|
239
255
|
}
|
|
256
|
+
// --- riding along -------------------------------------------------------------------------------------------------------------------------------
|
|
257
|
+
/**
|
|
258
|
+
* 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
|
|
259
|
+
* Earth turns and slides beneath as it moves along its orbit (an ISS view goes round about every 90 minutes). The shared controls' yaw and tilt turn the view and tip it towards the horizon, their zoom narrows it.
|
|
260
|
+
* 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
|
|
261
|
+
* 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.
|
|
262
|
+
*
|
|
263
|
+
* @param target - A body name (`"Moon"`, `"Mars"`, ...) or a satellite `{ group, index }`, or `null` to stop.
|
|
264
|
+
* @param options - `view`, `look`, `distanceKm`, `smooth` (see `RideOptions`).
|
|
265
|
+
*/
|
|
266
|
+
ride(target, options = {}) {
|
|
267
|
+
const model = this.#model;
|
|
268
|
+
const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
269
|
+
const wasRiding = model.ride !== null;
|
|
270
|
+
if (target === null) {
|
|
271
|
+
model.ride = null;
|
|
272
|
+
model.focus = this.#focusBeforeRide;
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
if (typeof target === "string" && !BODY_NAMES.includes(target))
|
|
276
|
+
return;
|
|
277
|
+
if (typeof target !== "string" && !model.satellites.groups.get(target.group))
|
|
278
|
+
return;
|
|
279
|
+
if (!wasRiding)
|
|
280
|
+
this.#focusBeforeRide = model.focus;
|
|
281
|
+
const view = typeof target === "string" && target === "Earth" ? "follow" : (options.view ?? "from");
|
|
282
|
+
model.ride = { target: typeof target === "string" ? target : { group: target.group, index: target.index }, view, look: options.look ?? "down", distanceKm: Math.max(100, options.distanceKm ?? 3000) };
|
|
283
|
+
if (typeof target === "string" && view === "follow")
|
|
284
|
+
model.focus = target;
|
|
285
|
+
else if (wasRiding)
|
|
286
|
+
model.focus = this.#focusBeforeRide;
|
|
287
|
+
}
|
|
288
|
+
this.#lostTold = false;
|
|
289
|
+
const pose = model.pose;
|
|
290
|
+
model.transition = (options.smooth ?? true) && !reduced && pose.valid ? { start: performance.now(), duration: 1200, from: { p: [pose.p[0], pose.p[1], pose.p[2]], q: [pose.q[0], pose.q[1], pose.q[2], pose.q[3]], fov: pose.fov } } : null;
|
|
291
|
+
this.#last = performance.now();
|
|
292
|
+
this.#schedule();
|
|
293
|
+
this.#gate?.request();
|
|
294
|
+
this.dispatchEvent(new CustomEvent("chikyu-ride", { detail: this.riding }));
|
|
295
|
+
}
|
|
296
|
+
/** What the camera is riding along with now, or null. */
|
|
297
|
+
get riding() {
|
|
298
|
+
const ride = this.#model.ride;
|
|
299
|
+
return ride ? { ...ride, target: typeof ride.target === "string" ? ride.target : { ...ride.target } } : null;
|
|
300
|
+
}
|
|
301
|
+
#rideLost() {
|
|
302
|
+
if (this.#lostTold)
|
|
303
|
+
return;
|
|
304
|
+
this.#lostTold = true;
|
|
305
|
+
this.dispatchEvent(new CustomEvent("chikyu-ride-lost", { detail: this.riding }));
|
|
306
|
+
}
|
|
240
307
|
// --- satellites ---------------------------------------------------------------------------------------------------------------------------------
|
|
241
308
|
/**
|
|
242
309
|
* Show a group of satellites (made by `createSatellites`) under a name, or take the group away with `null`. A group is one draw call however many satellites it holds. Giving the name of a group
|
|
@@ -351,6 +418,8 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
351
418
|
time: this.#model.time,
|
|
352
419
|
lookups: this.#model.lookups,
|
|
353
420
|
satellites: this.#satelliteStats(),
|
|
421
|
+
ride: { riding: this.#model.ride !== null, lost: this.#model.rideLost, gliding: this.#model.transition !== null },
|
|
422
|
+
camera: { position: [this.#model.pose.p[0], this.#model.pose.p[1], this.#model.pose.p[2]], fov: this.#model.pose.fov },
|
|
354
423
|
};
|
|
355
424
|
}
|
|
356
425
|
#satelliteStats() {
|
|
@@ -380,19 +449,20 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
380
449
|
return true;
|
|
381
450
|
return false;
|
|
382
451
|
}
|
|
383
|
-
/** While time runs, draw as often as it shows: real time once a minute; faster time as often as the Earth's turn moves a pixel (1 to 30 times a second). Satellites go round in 90 minutes, so with
|
|
452
|
+
/** While time runs, draw as often as it shows: real time once a minute; faster time as often as the Earth's turn moves a pixel (1 to 30 times a second). Satellites go round in 90 minutes and a ride along moves the whole picture, so with either on show real time draws about as often as a pixel moves (once a second at least), and a reader who asked for reduced motion gets one step a second. */
|
|
384
453
|
#schedule() {
|
|
385
454
|
clearTimeout(this.#timer);
|
|
386
455
|
this.#timer = undefined;
|
|
387
456
|
if (!this.isConnected || this.#speed === 0)
|
|
388
457
|
return;
|
|
389
458
|
const satellites = this.#satellitesMoving();
|
|
459
|
+
const riding = this.#model.ride !== null;
|
|
390
460
|
const radius = this.#model.drawn?.radiusPx ?? 200;
|
|
391
|
-
const pixelsPerSecond = (satellites ? SATELLITE_RATE : EARTH_RATE) * RAD * Math.abs(this.#speed) * radius;
|
|
461
|
+
const pixelsPerSecond = Math.max((satellites ? SATELLITE_RATE : EARTH_RATE) * RAD * Math.abs(this.#speed) * radius, this.#model.rideMotion * Math.abs(this.#speed));
|
|
392
462
|
let perSecond = Math.min(30, Math.max(1, pixelsPerSecond));
|
|
393
|
-
if (satellites && matchMedia("(prefers-reduced-motion: reduce)").matches)
|
|
463
|
+
if ((satellites || riding) && matchMedia("(prefers-reduced-motion: reduce)").matches)
|
|
394
464
|
perSecond = 1;
|
|
395
|
-
const wait = !satellites && this.#speed === 1 ? REAL_TIME_TICK_MS : 1000 / perSecond;
|
|
465
|
+
const wait = !satellites && !riding && this.#speed === 1 ? REAL_TIME_TICK_MS : 1000 / perSecond;
|
|
396
466
|
this.#timer = setTimeout(this.#tick, wait);
|
|
397
467
|
}
|
|
398
468
|
#tick = () => {
|
|
@@ -112,7 +112,7 @@ export declare function blend(a: Frame, b: Frame, t: number): Frame;
|
|
|
112
112
|
* `stepMs` ahead, so playing time at a steady rate costs one pair of lookups every `stepMs` and every draw in between is arithmetic.
|
|
113
113
|
*
|
|
114
114
|
* @param initialStepMs - How far ahead the second answer looks, in milliseconds.
|
|
115
|
-
* @returns A track: `at(ms)` for a frame, `lookups` for how many times the ephemeris was asked, `reset()` and `setStep(ms)`.
|
|
115
|
+
* @returns A track: `at(ms)` for a frame, `lookups` for how many times the ephemeris was asked, `ends()` for the two answers it is between (undefined before the first `at`), `reset()` and `setStep(ms)`.
|
|
116
116
|
*
|
|
117
117
|
* @example
|
|
118
118
|
* ```ts
|
|
@@ -126,6 +126,8 @@ export declare function blend(a: Frame, b: Frame, t: number): Frame;
|
|
|
126
126
|
*/
|
|
127
127
|
export declare function createTrack(initialStepMs?: number): {
|
|
128
128
|
at(ms: number): Frame;
|
|
129
|
+
/** The two answers the track is between now (undefined before the first), for working out which way something is going. */
|
|
130
|
+
ends(): [Frame, Frame] | undefined;
|
|
129
131
|
/** How many times astronomy-engine has been asked for a frame. */
|
|
130
132
|
readonly lookups: number;
|
|
131
133
|
reset(): void;
|
package/dist/space/ephemeris.js
CHANGED
|
@@ -95,7 +95,7 @@ export function blend(a, b, t) {
|
|
|
95
95
|
* `stepMs` ahead, so playing time at a steady rate costs one pair of lookups every `stepMs` and every draw in between is arithmetic.
|
|
96
96
|
*
|
|
97
97
|
* @param initialStepMs - How far ahead the second answer looks, in milliseconds.
|
|
98
|
-
* @returns A track: `at(ms)` for a frame, `lookups` for how many times the ephemeris was asked, `reset()` and `setStep(ms)`.
|
|
98
|
+
* @returns A track: `at(ms)` for a frame, `lookups` for how many times the ephemeris was asked, `ends()` for the two answers it is between (undefined before the first `at`), `reset()` and `setStep(ms)`.
|
|
99
99
|
*
|
|
100
100
|
* @example
|
|
101
101
|
* ```ts
|
|
@@ -121,6 +121,10 @@ export function createTrack(initialStepMs = 1000) {
|
|
|
121
121
|
}
|
|
122
122
|
return blend(a, b, (ms - a.ms) / (b.ms - a.ms));
|
|
123
123
|
},
|
|
124
|
+
/** The two answers the track is between now (undefined before the first), for working out which way something is going. */
|
|
125
|
+
ends() {
|
|
126
|
+
return a && b ? [a, b] : undefined;
|
|
127
|
+
},
|
|
124
128
|
/** How many times astronomy-engine has been asked for a frame. */
|
|
125
129
|
get lookups() {
|
|
126
130
|
return lookups;
|
package/dist/space/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, orbitPath, PLANETS, type Frame, type PlanetName, type Vec3 } from "./ephemeris.ts";
|
|
2
2
|
export { compress, MOON_COMPRESSED, placeAround, placeMoon, placeSun, RADIUS, SUN_COMPRESSED, truePosition, type ScaleMode } from "./scale.ts";
|
|
3
3
|
export { plainPainter, type BodyDrawing, type BodyPainter } from "./scene.ts";
|
|
4
|
+
export { RIDE_FOV, ridePose, type RideInput, type RideLook, type RidePose } from "./ride.ts";
|
package/dist/space/index.js
CHANGED
|
@@ -3,3 +3,4 @@
|
|
|
3
3
|
export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, orbitPath, PLANETS } from "./ephemeris.js";
|
|
4
4
|
export { compress, MOON_COMPRESSED, placeAround, placeMoon, placeSun, RADIUS, SUN_COMPRESSED, truePosition } from "./scale.js";
|
|
5
5
|
export { plainPainter } from "./scene.js";
|
|
6
|
+
export { RIDE_FOV, ridePose } from "./ride.js";
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { Vec3 } from "./ephemeris.ts";
|
|
2
|
+
/**
|
|
3
|
+
* The field of view, in degrees, of a camera riding along at zoom 1 (the Earth's view from outside is 35).
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { RIDE_FOV } from "@johnmorrisdotca/chikyu-earth/space";
|
|
8
|
+
*
|
|
9
|
+
* console.log(RIDE_FOV);
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare const RIDE_FOV = 60;
|
|
13
|
+
/**
|
|
14
|
+
* Where a riding camera looks: `down` straight at the Earth's centre (the ground goes by under the camera), or `horizon` tipped forward along the way it is going until the horizon
|
|
15
|
+
* is a little above the middle of the view.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import type { RideLook } from "@johnmorrisdotca/chikyu-earth/space";
|
|
20
|
+
*
|
|
21
|
+
* const looks: RideLook[] = ["down", "horizon"];
|
|
22
|
+
* console.log(looks.join(" or "));
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export type RideLook = "down" | "horizon";
|
|
26
|
+
/**
|
|
27
|
+
* What `ridePose` is asked: the camera's place and its way of travel (any length), where it looks, and the shared controls' yaw, tilt and zoom.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import type { RideInput } from "@johnmorrisdotca/chikyu-earth/space";
|
|
32
|
+
*
|
|
33
|
+
* const input: RideInput = { position: [1.066, 0, 0], velocity: [0, 0, -7.66], look: "down", yaw: 0, tilt: 0, zoom: 1 };
|
|
34
|
+
* console.log(input.look);
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export interface RideInput {
|
|
38
|
+
/** The camera's place in Earth radii from the Earth's centre, in the scene's axes. */
|
|
39
|
+
position: Vec3;
|
|
40
|
+
/** Its direction of travel, in any unit: only the direction is used. */
|
|
41
|
+
velocity: Vec3;
|
|
42
|
+
look: RideLook;
|
|
43
|
+
/** Degrees: turns the view round the straight-down line (0 has the way it is going at the top of the picture). */
|
|
44
|
+
yaw: number;
|
|
45
|
+
/** Degrees: tips the view forward from where `look` puts it, towards the horizon and beyond. */
|
|
46
|
+
tilt: number;
|
|
47
|
+
/** 1 is the natural view; more narrows the field of view. */
|
|
48
|
+
zoom: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The camera `ridePose` works out: where it is, which way it looks, which way is up in the picture, its field of view in degrees, and how big the Earth looks from there (its angular radius in degrees).
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* import type { RidePose } from "@johnmorrisdotca/chikyu-earth/space";
|
|
56
|
+
*
|
|
57
|
+
* const describe = (pose: RidePose): string => `looking ${pose.forward.map((n) => n.toFixed(2)).join(",")} with a ${pose.fov} degree view`;
|
|
58
|
+
* console.log(typeof describe);
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export interface RidePose {
|
|
62
|
+
position: Vec3;
|
|
63
|
+
forward: Vec3;
|
|
64
|
+
up: Vec3;
|
|
65
|
+
fov: number;
|
|
66
|
+
earthRadiusDegrees: number;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The camera of a body-borne view: at `position`, looking at the Earth, with the way the body is going at the top of the picture. `look: "horizon"` tips it forward until the
|
|
70
|
+
* horizon is a little above the middle; `tilt` tips it further, `yaw` turns it round the straight-down line, and `zoom` narrows the field of view.
|
|
71
|
+
*
|
|
72
|
+
* @param input - The camera's place, its way of travel, the look, and the shared controls' yaw, tilt and zoom.
|
|
73
|
+
* @returns The camera's place, forward and up directions (unit vectors), its field of view, and the Earth's angular radius from there.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* import { ridePose } from "@johnmorrisdotca/chikyu-earth/space";
|
|
78
|
+
*
|
|
79
|
+
* const pose = ridePose({ position: [1.066, 0, 0], velocity: [0, 0, -7.66], look: "down", yaw: 0, tilt: 0, zoom: 1 });
|
|
80
|
+
* console.log(pose.forward.map((n) => n.toFixed(2)).join(","), pose.earthRadiusDegrees.toFixed(0));
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function ridePose(input: RideInput): RidePose;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const RAD = Math.PI / 180;
|
|
2
|
+
/**
|
|
3
|
+
* The field of view, in degrees, of a camera riding along at zoom 1 (the Earth's view from outside is 35).
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { RIDE_FOV } from "@johnmorrisdotca/chikyu-earth/space";
|
|
8
|
+
*
|
|
9
|
+
* console.log(RIDE_FOV);
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export const RIDE_FOV = 60;
|
|
13
|
+
const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
14
|
+
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]];
|
|
15
|
+
const scale = (a, k) => [a[0] * k, a[1] * k, a[2] * k];
|
|
16
|
+
const add = (a, b) => [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
|
|
17
|
+
const norm = (a) => Math.hypot(a[0], a[1], a[2]);
|
|
18
|
+
const unit = (a) => {
|
|
19
|
+
const n = norm(a);
|
|
20
|
+
return n === 0 ? [0, 0, 0] : [a[0] / n, a[1] / n, a[2] / n];
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* The camera of a body-borne view: at `position`, looking at the Earth, with the way the body is going at the top of the picture. `look: "horizon"` tips it forward until the
|
|
24
|
+
* horizon is a little above the middle; `tilt` tips it further, `yaw` turns it round the straight-down line, and `zoom` narrows the field of view.
|
|
25
|
+
*
|
|
26
|
+
* @param input - The camera's place, its way of travel, the look, and the shared controls' yaw, tilt and zoom.
|
|
27
|
+
* @returns The camera's place, forward and up directions (unit vectors), its field of view, and the Earth's angular radius from there.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { ridePose } from "@johnmorrisdotca/chikyu-earth/space";
|
|
32
|
+
*
|
|
33
|
+
* const pose = ridePose({ position: [1.066, 0, 0], velocity: [0, 0, -7.66], look: "down", yaw: 0, tilt: 0, zoom: 1 });
|
|
34
|
+
* console.log(pose.forward.map((n) => n.toFixed(2)).join(","), pose.earthRadiusDegrees.toFixed(0));
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export function ridePose(input) {
|
|
38
|
+
const distance = Math.max(1e-9, norm(input.position));
|
|
39
|
+
const nadir = scale(input.position, -1 / distance);
|
|
40
|
+
let ahead = add(input.velocity, scale(nadir, -dot(input.velocity, nadir)));
|
|
41
|
+
if (norm(ahead) < 1e-12 * Math.max(1, norm(input.velocity))) {
|
|
42
|
+
// no way of travel to go by (or it is straight at the Earth): north, or east where north is straight down
|
|
43
|
+
const north = [0, 1, 0];
|
|
44
|
+
ahead = add(north, scale(nadir, -dot(north, nadir)));
|
|
45
|
+
if (norm(ahead) < 1e-9)
|
|
46
|
+
ahead = cross([1, 0, 0], nadir);
|
|
47
|
+
}
|
|
48
|
+
ahead = unit(ahead);
|
|
49
|
+
const turn = input.yaw * RAD;
|
|
50
|
+
ahead = add(scale(ahead, Math.cos(turn)), scale(cross(nadir, ahead), Math.sin(turn)));
|
|
51
|
+
const earthRadiusDegrees = distance <= 1 ? 90 : Math.asin(1 / distance) / RAD;
|
|
52
|
+
const base = input.look === "horizon" ? Math.max(0, earthRadiusDegrees - 12) : 0;
|
|
53
|
+
const pitch = Math.min(150, Math.max(0, base + input.tilt)) * RAD;
|
|
54
|
+
const forward = add(scale(nadir, Math.cos(pitch)), scale(ahead, Math.sin(pitch)));
|
|
55
|
+
const up = add(scale(ahead, Math.cos(pitch)), scale(nadir, -Math.sin(pitch)));
|
|
56
|
+
return { position: [input.position[0], input.position[1], input.position[2]], forward, up, fov: Math.min(100, Math.max(5, RIDE_FOV / Math.max(0.05, input.zoom))), earthRadiusDegrees };
|
|
57
|
+
}
|
package/dist/space/scene.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { Layer } from "../realistic/tiers.ts";
|
|
|
5
5
|
import { type Frame, type PlanetName, type Vec3 } from "./ephemeris.ts";
|
|
6
6
|
import { type ScaleMode } from "./scale.ts";
|
|
7
7
|
import type { SatelliteRef } from "../satellites/types.ts";
|
|
8
|
+
import { type RideLook } from "./ride.ts";
|
|
8
9
|
import { type SatelliteState } from "./satellite-layer.ts";
|
|
9
10
|
type Three = ThreeParts;
|
|
10
11
|
/** The camera's distance, in Earth radii, at which the Earth fills the view at zoom 1. */
|
|
@@ -32,6 +33,33 @@ export declare const BODY_NAMES: readonly ["Earth", "Sun", "Moon", "Mercury", "V
|
|
|
32
33
|
* ```
|
|
33
34
|
*/
|
|
34
35
|
export type BodyName = (typeof BODY_NAMES)[number];
|
|
36
|
+
/**
|
|
37
|
+
* What a camera can ride along with: the name of one of the bodies, or a satellite of a group (`{ group, index }`).
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts no-run
|
|
41
|
+
* import type { RideTarget } from "@johnmorrisdotca/chikyu-earth/space/element";
|
|
42
|
+
*
|
|
43
|
+
* const targets: RideTarget[] = ["Moon", { group: "stations", index: 0 }];
|
|
44
|
+
* console.log(targets.length);
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export type RideTarget = BodyName | SatelliteRef;
|
|
48
|
+
export interface RideState {
|
|
49
|
+
target: RideTarget;
|
|
50
|
+
/** `from`: the camera is at the body, looking at the Earth. `follow`: the camera keeps a fixed distance from it, looking at it. */
|
|
51
|
+
view: "from" | "follow";
|
|
52
|
+
look: RideLook;
|
|
53
|
+
/** For `follow` a satellite: how far the camera keeps, in kilometres. */
|
|
54
|
+
distanceKm: number;
|
|
55
|
+
}
|
|
56
|
+
/** The camera as the last draw left it, for the next one to start from when the ride changes. */
|
|
57
|
+
export interface Pose {
|
|
58
|
+
p: Vec3;
|
|
59
|
+
q: [number, number, number, number];
|
|
60
|
+
fov: number;
|
|
61
|
+
valid: boolean;
|
|
62
|
+
}
|
|
35
63
|
export interface SpaceModel {
|
|
36
64
|
/** Moment shown, milliseconds since the epoch. */
|
|
37
65
|
time: number;
|
|
@@ -67,6 +95,30 @@ export interface SpaceModel {
|
|
|
67
95
|
speed: number;
|
|
68
96
|
/** The satellites shown, the one chosen, and what the last draw did with them. */
|
|
69
97
|
satellites: SatelliteState;
|
|
98
|
+
/** The body or satellite the camera rides along with, or null. */
|
|
99
|
+
ride: RideState | null;
|
|
100
|
+
/** 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. */
|
|
101
|
+
rideLost: boolean;
|
|
102
|
+
/** 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. */
|
|
103
|
+
transition: {
|
|
104
|
+
start: number;
|
|
105
|
+
duration: number;
|
|
106
|
+
from: {
|
|
107
|
+
p: Vec3;
|
|
108
|
+
q: [number, number, number, number];
|
|
109
|
+
fov: number;
|
|
110
|
+
};
|
|
111
|
+
} | null;
|
|
112
|
+
/** The shared controls' view as the last draw used it, and how tall the view was (CSS pixels): `setView` skips a draw for a turn that moves nothing by half a pixel. */
|
|
113
|
+
drawnView: {
|
|
114
|
+
yaw: number;
|
|
115
|
+
tilt: number;
|
|
116
|
+
zoom: number;
|
|
117
|
+
} | null;
|
|
118
|
+
heightPx: number;
|
|
119
|
+
pose: Pose;
|
|
120
|
+
/** Pixels a second that riding makes things move on the screen at 1x clock speed (0 when not riding): the draw rate follows it. */
|
|
121
|
+
rideMotion: number;
|
|
70
122
|
/** The satellite at a point of the view (CSS pixels), within a radius, if a draw has been made and one is there. */
|
|
71
123
|
pick: ((x: number, y: number, radius: number) => SatelliteRef | null) | null;
|
|
72
124
|
ratio(): number;
|
|
@@ -126,6 +178,10 @@ export interface SpaceDeps {
|
|
|
126
178
|
x: number;
|
|
127
179
|
y: number;
|
|
128
180
|
} | null) => void;
|
|
181
|
+
/** 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). */
|
|
182
|
+
onMoving?: () => void;
|
|
183
|
+
/** The target of the ride could not be placed at this draw. */
|
|
184
|
+
onRideLost?: () => void;
|
|
129
185
|
/** The satellites could not be drawn (the three.js parts handed over lack `Points`). */
|
|
130
186
|
onSatellitesError?: (error: unknown) => void;
|
|
131
187
|
/** How the Sun and the planets are drawn; left out, plain spheres in the right colours (see `BodyPainter`). */
|
package/dist/space/scene.js
CHANGED
|
@@ -3,6 +3,7 @@ import { ATMOSPHERE_FRAG, ATMOSPHERE_VERT, BODY_FRAG, CLOUD_FRAG, GLOW_FRAG, GLO
|
|
|
3
3
|
import { createTextureSet } from "../realistic/textures.js";
|
|
4
4
|
import { createTrack, orbitPath, PLANETS } from "./ephemeris.js";
|
|
5
5
|
import { placeAround, placeMoon, placeSun, RADIUS } from "./scale.js";
|
|
6
|
+
import { ridePose } from "./ride.js";
|
|
6
7
|
import { createSatelliteLayer, newSatelliteState } from "./satellite-layer.js";
|
|
7
8
|
const RAD = Math.PI / 180;
|
|
8
9
|
/** The camera's distance, in Earth radii, at which the Earth fills the view at zoom 1. */
|
|
@@ -36,6 +37,13 @@ export const newSpaceModel = () => ({
|
|
|
36
37
|
drawn: null,
|
|
37
38
|
lookups: 0,
|
|
38
39
|
speed: 1,
|
|
40
|
+
ride: null,
|
|
41
|
+
rideLost: false,
|
|
42
|
+
transition: null,
|
|
43
|
+
drawnView: null,
|
|
44
|
+
heightPx: 420,
|
|
45
|
+
pose: { p: [0, 0, 0], q: [0, 0, 0, 1], fov: FOV, valid: false },
|
|
46
|
+
rideMotion: 0,
|
|
39
47
|
satellites: newSatelliteState(),
|
|
40
48
|
pick: null,
|
|
41
49
|
ratio: () => Math.min(globalThis.devicePixelRatio || 1, 2),
|
|
@@ -167,10 +175,20 @@ export function createSpaceItem(model, deps) {
|
|
|
167
175
|
planets.set(name, { drawing, orbit, positions, samples: [], epoch: Number.NaN });
|
|
168
176
|
}
|
|
169
177
|
let layer;
|
|
178
|
+
const rideState = new Float64Array(6);
|
|
170
179
|
let selectedShown = false;
|
|
171
180
|
const camera = new three.PerspectiveCamera(FOV, width / Math.max(1, height), 0.05, 1000);
|
|
172
181
|
const target = new three.Vector3();
|
|
182
|
+
const desiredQ = camera.quaternion.clone();
|
|
183
|
+
const fromQ = camera.quaternion.clone();
|
|
173
184
|
const projected = new three.Vector3();
|
|
185
|
+
const placeAll = (at) => {
|
|
186
|
+
const sunAt = placeSun(model.mode, at.sun);
|
|
187
|
+
const all = { Earth: [0, 0, 0], Moon: placeMoon(model.mode, at.moon), Sun: sunAt };
|
|
188
|
+
for (const name of PLANETS)
|
|
189
|
+
all[name] = placeAround(model.mode, sunAt, [at.planets[name][0] - at.sun[0], at.planets[name][1] - at.sun[1], at.planets[name][2] - at.sun[2]]);
|
|
190
|
+
return all;
|
|
191
|
+
};
|
|
174
192
|
const labelFor = (v) => {
|
|
175
193
|
projected.set(v[0], v[1], v[2]).project(camera);
|
|
176
194
|
if (projected.z > 1 || projected.z < -1)
|
|
@@ -246,26 +264,112 @@ export function createSpaceItem(model, deps) {
|
|
|
246
264
|
}
|
|
247
265
|
layer?.update(model.time, model.speed);
|
|
248
266
|
model.pick = layer ? (x, y, radius) => layer.pick(x, y, camera, size, radius) : null;
|
|
249
|
-
// the camera: looks at the focus body from the direction the sky was in when it was last moved, turned by yaw and tilt, as far as the zoom says
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
267
|
+
// the camera: looks at the focus body from the direction the sky was in when it was last moved, turned by yaw and tilt, as far as the zoom says; or, riding along, sits at the
|
|
268
|
+
// body and looks at the Earth
|
|
269
|
+
let focus = model.focus;
|
|
270
|
+
let focusPos = pos[focus];
|
|
271
|
+
let focusRadius = radiusOf(focus);
|
|
272
|
+
let rideFrom = null;
|
|
273
|
+
model.rideLost = false;
|
|
274
|
+
model.rideMotion = 0;
|
|
275
|
+
const ride = model.ride;
|
|
276
|
+
if (ride) {
|
|
277
|
+
if (typeof ride.target === "string") {
|
|
278
|
+
if (ride.view === "follow") {
|
|
279
|
+
focus = ride.target;
|
|
280
|
+
focusPos = pos[focus];
|
|
281
|
+
focusRadius = radiusOf(focus);
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
const ends = track.ends();
|
|
285
|
+
const was = ends ? placeAll(ends[0])[ride.target] : pos[ride.target];
|
|
286
|
+
const will = ends ? placeAll(ends[1])[ride.target] : pos[ride.target];
|
|
287
|
+
const seconds = ends ? Math.max(1e-3, (ends[1].ms - ends[0].ms) / 1000) : 1;
|
|
288
|
+
rideFrom = { position: pos[ride.target], velocity: [will[0] - was[0], will[1] - was[1], will[2] - was[2]], hidden: ride.target, gameSeconds: seconds };
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
else if (layer?.exact(ride.target, model.time, rideState)) {
|
|
292
|
+
const place = [rideState[0], rideState[1], rideState[2]];
|
|
293
|
+
if (ride.view === "follow") {
|
|
294
|
+
focusPos = place;
|
|
295
|
+
focusRadius = Math.max(1e-4, ride.distanceKm / 6371 / FIT_DISTANCE);
|
|
296
|
+
}
|
|
297
|
+
else
|
|
298
|
+
rideFrom = { position: place, velocity: [rideState[3], rideState[4], rideState[5]], hidden: null, gameSeconds: 0 };
|
|
299
|
+
}
|
|
300
|
+
else
|
|
301
|
+
model.rideLost = true;
|
|
302
|
+
}
|
|
303
|
+
const hidden = rideFrom?.hidden ?? null;
|
|
304
|
+
moon.visible = hidden !== "Moon";
|
|
305
|
+
sunDrawing.object.visible = hidden !== "Sun";
|
|
306
|
+
for (const [name, p] of planets)
|
|
307
|
+
p.drawing.object.visible = hidden !== name;
|
|
308
|
+
let fovNow = FOV;
|
|
309
|
+
let distance = 0;
|
|
310
|
+
if (rideFrom) {
|
|
311
|
+
const pose = ridePose({ position: rideFrom.position, velocity: rideFrom.velocity, look: ride.look, yaw: model.view.yaw, tilt: model.view.tilt, zoom: model.view.zoom });
|
|
312
|
+
camera.position.set(pose.position[0], pose.position[1], pose.position[2]);
|
|
313
|
+
camera.up.set(pose.up[0], pose.up[1], pose.up[2]);
|
|
314
|
+
camera.lookAt(pose.position[0] + pose.forward[0], pose.position[1] + pose.forward[1], pose.position[2] + pose.forward[2]);
|
|
315
|
+
fovNow = pose.fov;
|
|
316
|
+
const away = Math.hypot(...rideFrom.position);
|
|
317
|
+
camera.near = Math.max(0.0008, Math.min(0.05, (away - 1) * 0.1));
|
|
318
|
+
camera.far = Math.max(2000, 400 + (mode === "true" ? 40 * 23_481 : 0));
|
|
319
|
+
// how fast the ground goes by under the camera, in pixels a second at 1x: the speed over the height for a satellite, the turn of the direction to the Earth for a body
|
|
320
|
+
const focal = (size.height / 2) / Math.tan((fovNow / 2) * RAD);
|
|
321
|
+
const speed = Math.hypot(...rideFrom.velocity);
|
|
322
|
+
model.rideMotion = typeof ride.target === "string" ? ((speed / Math.max(1e-9, away)) / rideFrom.gameSeconds) * focal : (speed / Math.max(50, (away - 1) * 6371)) * focal;
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
const spin = model.cameraSpin ?? frame.spin;
|
|
326
|
+
const lon = model.centre.lon - model.view.yaw;
|
|
327
|
+
const lat = Math.max(-90, Math.min(90, model.centre.lat + model.view.tilt));
|
|
328
|
+
const aim = direction(spin + lon, lat);
|
|
329
|
+
distance = Math.max(1.05 * focusRadius, (FIT_DISTANCE * focusRadius) / Math.max(1e-9, model.view.zoom));
|
|
330
|
+
target.set(focusPos[0], focusPos[1], focusPos[2]);
|
|
331
|
+
camera.position.set(target.x + aim[0] * distance, target.y + aim[1] * distance, target.z + aim[2] * distance);
|
|
332
|
+
camera.up.set(0, 1, 0);
|
|
333
|
+
camera.lookAt(target);
|
|
334
|
+
camera.near = Math.max(0.0005, distance * 0.02 - focusRadius * 0.5, focusRadius * 0.01);
|
|
335
|
+
camera.far = Math.max(2000, distance * 4 + (mode === "true" ? 40 * 23_481 : 400));
|
|
336
|
+
if (ride && ride.view === "follow" && typeof ride.target !== "string") {
|
|
337
|
+
const focal = (size.height / 2) / Math.tan((fovNow / 2) * RAD);
|
|
338
|
+
model.rideMotion = (Math.hypot(rideState[3], rideState[4], rideState[5]) / Math.max(50, ride.distanceKm / Math.max(1e-9, model.view.zoom))) * focal;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
// a ride that changed: glide from where the last draw left the camera (a jump for a reader who asked for reduced motion; the element does not start one then)
|
|
342
|
+
const glide = model.transition;
|
|
343
|
+
if (glide) {
|
|
344
|
+
const k = Math.min(1, (performance.now() - glide.start) / glide.duration);
|
|
345
|
+
const ease = k * k * (3 - 2 * k);
|
|
346
|
+
desiredQ.copy(camera.quaternion);
|
|
347
|
+
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);
|
|
348
|
+
fromQ.set(glide.from.q[0], glide.from.q[1], glide.from.q[2], glide.from.q[3]);
|
|
349
|
+
camera.quaternion.copy(fromQ.slerp(desiredQ, ease));
|
|
350
|
+
fovNow = glide.from.fov + (fovNow - glide.from.fov) * ease;
|
|
351
|
+
if (k >= 1)
|
|
352
|
+
model.transition = null;
|
|
353
|
+
}
|
|
354
|
+
camera.fov = fovNow;
|
|
263
355
|
camera.aspect = size.width / Math.max(1, size.height);
|
|
264
356
|
camera.updateProjectionMatrix();
|
|
265
357
|
camera.updateMatrixWorld();
|
|
266
358
|
sunView.value.copy(sunEarth.value).transformDirection(camera.matrixWorldInverse);
|
|
359
|
+
const pose = model.pose;
|
|
360
|
+
pose.p[0] = camera.position.x;
|
|
361
|
+
pose.p[1] = camera.position.y;
|
|
362
|
+
pose.p[2] = camera.position.z;
|
|
363
|
+
pose.q[0] = camera.quaternion.x;
|
|
364
|
+
pose.q[1] = camera.quaternion.y;
|
|
365
|
+
pose.q[2] = camera.quaternion.z;
|
|
366
|
+
pose.q[3] = camera.quaternion.w;
|
|
367
|
+
pose.fov = fovNow;
|
|
368
|
+
pose.valid = true;
|
|
369
|
+
model.drawnView = { yaw: model.view.yaw, tilt: model.view.tilt, zoom: model.view.zoom };
|
|
370
|
+
model.heightPx = size.height;
|
|
267
371
|
// how many pixels across each body is: for the pictures the Earth and the Moon need, and for what is chosen
|
|
268
|
-
const half = Math.tan((
|
|
372
|
+
const half = Math.tan((fovNow / 2) * RAD);
|
|
269
373
|
const radiusPxOf = (name) => {
|
|
270
374
|
const d = Math.hypot(pos[name][0] - camera.position.x, pos[name][1] - camera.position.y, pos[name][2] - camera.position.z);
|
|
271
375
|
const r = radiusOf(name);
|
|
@@ -281,7 +385,7 @@ export function createSpaceItem(model, deps) {
|
|
|
281
385
|
if (deps.onLabels && model.labels) {
|
|
282
386
|
const places = {};
|
|
283
387
|
for (const name of BODY_NAMES) {
|
|
284
|
-
const at = labelFor(pos[name]);
|
|
388
|
+
const at = name === hidden || (rideFrom && name === "Earth") ? null : labelFor(pos[name]);
|
|
285
389
|
places[name] = at ? { x: at.x, y: at.y, r: px[name] } : null;
|
|
286
390
|
}
|
|
287
391
|
deps.onLabels(places);
|
|
@@ -292,6 +396,10 @@ export function createSpaceItem(model, deps) {
|
|
|
292
396
|
deps.onSelected(at);
|
|
293
397
|
selectedShown = at !== null;
|
|
294
398
|
}
|
|
399
|
+
if (model.rideLost)
|
|
400
|
+
deps.onRideLost?.();
|
|
401
|
+
if (model.transition)
|
|
402
|
+
deps.onMoving?.();
|
|
295
403
|
return false;
|
|
296
404
|
},
|
|
297
405
|
resize(w, h) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/chikyu-earth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.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 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.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"earth",
|