@johnmorrisdotca/chikyu-earth 0.34.1 → 0.35.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 +7 -0
- package/README.md +1 -1
- package/dist/realistic/element.d.ts +19 -0
- package/dist/realistic/element.js +26 -1
- package/dist/realistic/index.d.ts +1 -0
- package/dist/sky/culture-lines.d.ts +56 -0
- package/dist/sky/culture-lines.js +82 -0
- package/dist/sky/figure-pick.d.ts +75 -0
- package/dist/sky/figure-pick.js +200 -0
- package/dist/sky/host.d.ts +17 -1
- package/dist/sky/host.js +615 -71
- package/dist/sky/keep-clear.d.ts +63 -0
- package/dist/sky/keep-clear.js +55 -0
- package/dist/space/element.d.ts +24 -3
- package/dist/space/element.js +29 -2
- package/dist/space/index.d.ts +1 -1
- package/dist/space/index.js +1 -1
- package/dist/space/satellite-model.d.ts +22 -0
- package/dist/space/satellite-model.js +38 -0
- package/dist/space/scene.d.ts +3 -2
- package/dist/space/scene.js +36 -15
- package/package.json +1 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A place where the sky's names must not go, as the property `keepClear` of `<chikyu-space>` and `<chikyu-earth-realistic>` takes it: a rectangle in the element's own CSS pixels from its top left, or an element of the page whose box is read (on a resize, not every frame).
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import type { SkyKeepClear } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
7
|
+
*
|
|
8
|
+
* const areas: SkyKeepClear[] = [{ x: 24, y: 40, width: 480, height: 220 }];
|
|
9
|
+
* console.log(areas.length);
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export type SkyKeepClear = {
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
17
|
+
} | {
|
|
18
|
+
getBoundingClientRect(): {
|
|
19
|
+
left: number;
|
|
20
|
+
top: number;
|
|
21
|
+
right: number;
|
|
22
|
+
bottom: number;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
/** A keep-clear area as the layer holds it: its edges, from the picture's top left, in CSS pixels. */
|
|
26
|
+
export interface KeepBox {
|
|
27
|
+
l: number;
|
|
28
|
+
t: number;
|
|
29
|
+
r: number;
|
|
30
|
+
b: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The edges of a keep-clear area, from the picture's top left.
|
|
34
|
+
*
|
|
35
|
+
* @param area - A rectangle in the picture's own pixels, or an element of the page.
|
|
36
|
+
* @param own - The picture's box on the page (`getBoundingClientRect`), to read an element's box against.
|
|
37
|
+
* @param into - The box to write, or one is made.
|
|
38
|
+
* @returns The box.
|
|
39
|
+
*/
|
|
40
|
+
export declare function keepBox(area: SkyKeepClear, own: {
|
|
41
|
+
left: number;
|
|
42
|
+
top: number;
|
|
43
|
+
}, into?: KeepBox): KeepBox;
|
|
44
|
+
/**
|
|
45
|
+
* Whether a box touches any of the keep-clear areas.
|
|
46
|
+
*
|
|
47
|
+
* @param areas - The areas, from `keepBox`.
|
|
48
|
+
* @param left - The box's left.
|
|
49
|
+
* @param top - The top.
|
|
50
|
+
* @param right - The right.
|
|
51
|
+
* @param bottom - The bottom.
|
|
52
|
+
* @returns True where the box and an area overlap.
|
|
53
|
+
*/
|
|
54
|
+
export declare function touchesKeep(areas: readonly KeepBox[], left: number, top: number, right: number, bottom: number): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Whether a point is inside any of the keep-clear areas.
|
|
57
|
+
*
|
|
58
|
+
* @param areas - The areas, from `keepBox`.
|
|
59
|
+
* @param x - The point's x.
|
|
60
|
+
* @param y - The point's y.
|
|
61
|
+
* @returns True where the point is in an area.
|
|
62
|
+
*/
|
|
63
|
+
export declare function inKeep(areas: readonly KeepBox[], x: number, y: number): boolean;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Places on the picture where the sky's names must not go: a page's own text laid over the element. Types and pure helpers; `host.ts` measures and uses them.
|
|
2
|
+
/**
|
|
3
|
+
* The edges of a keep-clear area, from the picture's top left.
|
|
4
|
+
*
|
|
5
|
+
* @param area - A rectangle in the picture's own pixels, or an element of the page.
|
|
6
|
+
* @param own - The picture's box on the page (`getBoundingClientRect`), to read an element's box against.
|
|
7
|
+
* @param into - The box to write, or one is made.
|
|
8
|
+
* @returns The box.
|
|
9
|
+
*/
|
|
10
|
+
export function keepBox(area, own, into = { l: 0, t: 0, r: 0, b: 0 }) {
|
|
11
|
+
if ("getBoundingClientRect" in area) {
|
|
12
|
+
const rect = area.getBoundingClientRect();
|
|
13
|
+
into.l = rect.left - own.left;
|
|
14
|
+
into.t = rect.top - own.top;
|
|
15
|
+
into.r = rect.right - own.left;
|
|
16
|
+
into.b = rect.bottom - own.top;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
into.l = area.x;
|
|
20
|
+
into.t = area.y;
|
|
21
|
+
into.r = area.x + area.width;
|
|
22
|
+
into.b = area.y + area.height;
|
|
23
|
+
}
|
|
24
|
+
return into;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Whether a box touches any of the keep-clear areas.
|
|
28
|
+
*
|
|
29
|
+
* @param areas - The areas, from `keepBox`.
|
|
30
|
+
* @param left - The box's left.
|
|
31
|
+
* @param top - The top.
|
|
32
|
+
* @param right - The right.
|
|
33
|
+
* @param bottom - The bottom.
|
|
34
|
+
* @returns True where the box and an area overlap.
|
|
35
|
+
*/
|
|
36
|
+
export function touchesKeep(areas, left, top, right, bottom) {
|
|
37
|
+
for (const a of areas)
|
|
38
|
+
if (left < a.r && right > a.l && top < a.b && bottom > a.t)
|
|
39
|
+
return true;
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Whether a point is inside any of the keep-clear areas.
|
|
44
|
+
*
|
|
45
|
+
* @param areas - The areas, from `keepBox`.
|
|
46
|
+
* @param x - The point's x.
|
|
47
|
+
* @param y - The point's y.
|
|
48
|
+
* @returns True where the point is in an area.
|
|
49
|
+
*/
|
|
50
|
+
export function inKeep(areas, x, y) {
|
|
51
|
+
for (const a of areas)
|
|
52
|
+
if (x >= a.l && x <= a.r && y >= a.t && y <= a.b)
|
|
53
|
+
return true;
|
|
54
|
+
return false;
|
|
55
|
+
}
|
package/dist/space/element.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ViewController } from "@johnmorrisdotca/kazoku-ui/view-controls";
|
|
2
2
|
import type { GeoPoint } from "../types.ts";
|
|
3
3
|
import { type BodyLabelSettings } from "../realistic/body-label.ts";
|
|
4
|
+
import type { SkyKeepClear } from "../sky/keep-clear.ts";
|
|
4
5
|
import type { SkyLabelStyle } from "../sky/style.ts";
|
|
5
6
|
import { type Place, type PlaceLook } from "../markers/places.ts";
|
|
6
7
|
import { type CityNamesStyle } from "../cities/host.ts";
|
|
@@ -87,7 +88,8 @@ export type SpaceState = "loading" | "live" | "unavailable" | "lost" | "idle";
|
|
|
87
88
|
export type SpacePreset = "earth" | "moon" | "sun" | "inner" | "solar-system" | `${Exclude<PlanetName, "Mercury" | "Venus">}-moons`;
|
|
88
89
|
/**
|
|
89
90
|
* 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,
|
|
90
|
-
* for a satellite; a planet or the Moon is kept at the distance the zoom says); `
|
|
91
|
+
* for a satellite; a planet or the Moon is kept at the distance the zoom says); `above` (a satellite only; a body is followed) puts it on the line from the Earth's centre through the satellite, `distanceKm` (divided by the zoom) above it, looking straight down at it with the way it is going at the top
|
|
92
|
+
* of the picture, the satellite held in the middle while the Earth turns beneath (a drag turns the picture about the satellite and tips the camera back or ahead of it); `look` `down` (the default) or `horizon` is where a camera at the body points; `smooth` (the default) glides
|
|
91
93
|
* 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.
|
|
92
94
|
*
|
|
93
95
|
* @example
|
|
@@ -99,7 +101,7 @@ export type SpacePreset = "earth" | "moon" | "sun" | "inner" | "solar-system" |
|
|
|
99
101
|
* ```
|
|
100
102
|
*/
|
|
101
103
|
export interface RideOptions {
|
|
102
|
-
view?: "from" | "follow";
|
|
104
|
+
view?: "from" | "follow" | "above";
|
|
103
105
|
look?: RideLook;
|
|
104
106
|
distanceKm?: number;
|
|
105
107
|
smooth?: boolean;
|
|
@@ -117,7 +119,7 @@ export interface RideOptions {
|
|
|
117
119
|
*/
|
|
118
120
|
export interface Riding {
|
|
119
121
|
target: RideTarget;
|
|
120
|
-
view: "from" | "follow";
|
|
122
|
+
view: "from" | "follow" | "above";
|
|
121
123
|
look: RideLook;
|
|
122
124
|
distanceKm: number;
|
|
123
125
|
}
|
|
@@ -196,6 +198,20 @@ export declare class ChikyuSpace extends HTMLElement {
|
|
|
196
198
|
*/
|
|
197
199
|
get skyStyle(): Partial<SkyLabelStyle>;
|
|
198
200
|
set skyStyle(value: Partial<SkyLabelStyle>);
|
|
201
|
+
/**
|
|
202
|
+
* The constellation that is picked, by its IAU abbreviation (`Ori`), or `null`. A reader picks one by a click or a tap on its lines or inside its figure (and with the key `C`, or `Shift`+`C` for the previous, while the element has the focus); a click on empty sky, or `Escape`, lets it go. The picked figure's lines are lit and its name is
|
|
203
|
+
* shown at the middle of the part of it in view, until another is picked or it is let go. A page sets the property to pick one itself, which sends no event. `chikyu-constellation-pick` is sent at each pick of the reader's, with `detail` `{ abbreviation, id, name, english, japanese, kind, culture }` (`culture` is `iau` unless `constellation-culture` names another), and `null` when it is let go; `chikyu-constellation-hover` is sent the same way as a mouse rests on a figure and leaves it.
|
|
204
|
+
* Needs `constellation-lines` set. `constellation-culture` (`iau` by default, `western`, `japanese` or `chinese`; each is fetched only when asked for, and the value is exactly what the page sets) makes the figures, the pick and the names those of that sky culture. The attribute `constellation-names` (off by default) writes the name of every figure in view at the middle of the part of it that is on the picture, quieter than the star names and clear of them, of the Earth, the Moon, the Sun, the places and satellites named, and of the places kept clear (`keepClear`).
|
|
205
|
+
*/
|
|
206
|
+
get constellation(): string | null;
|
|
207
|
+
set constellation(value: string | null);
|
|
208
|
+
/**
|
|
209
|
+
* Places on the picture where the sky's names must not go: a page's own text laid over the element, say. Each is a rectangle in the element's own CSS pixels from its top left (`{ x, y, width, height }`), or an element of the page whose box is read. A star name whose box touches
|
|
210
|
+
* one is left out, and so is a star whose point is in one (the next star is named instead); the picked constellation's name is moved clear of it. The lines are still drawn. The boxes are read when the list changes, when the page or an element is resized or scrolled, and not at each frame: a
|
|
211
|
+
* page that moves its text without resizing it sets the property again. The attribute `keep-clear` takes a CSS selector for the same (`keep-clear=".hero h1, .hero .lead"`). Nothing is redrawn at rest.
|
|
212
|
+
*/
|
|
213
|
+
get keepClear(): SkyKeepClear[];
|
|
214
|
+
set keepClear(value: readonly SkyKeepClear[] | null);
|
|
199
215
|
/**
|
|
200
216
|
* Places marked on the Earth (the attribute `places`, a JSON array): each `{ id, lon, lat, label, kind }`, `kind` being `here` (where the reader is: drawn bright and taller, with a quiet pulse) or `favourite`
|
|
201
217
|
* (the default: quieter). Each stands up out of the ground, turns with the Earth, is hidden on its far side and keeps its size in pixels at any zoom. Names go at the top, `here` first, and never overlap
|
|
@@ -425,6 +441,10 @@ export declare class ChikyuSpace extends HTMLElement {
|
|
|
425
441
|
names: number;
|
|
426
442
|
figures: number;
|
|
427
443
|
picked: string | null;
|
|
444
|
+
pick: string | null;
|
|
445
|
+
hover: string | null;
|
|
446
|
+
constellations: number;
|
|
447
|
+
culture: string;
|
|
428
448
|
renders: number;
|
|
429
449
|
lang: string;
|
|
430
450
|
stars: {
|
|
@@ -438,6 +458,7 @@ export declare class ChikyuSpace extends HTMLElement {
|
|
|
438
458
|
x: number;
|
|
439
459
|
y: number;
|
|
440
460
|
shown: boolean;
|
|
461
|
+
parts: number;
|
|
441
462
|
} | null;
|
|
442
463
|
/** The places: how many were handed over, how many are drawn and named at the last draw, and how many times they were laid out. */
|
|
443
464
|
places: {
|
package/dist/space/element.js
CHANGED
|
@@ -135,6 +135,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
135
135
|
/** The names of the stars and the constellation lines (`star-names`, `constellation-lines`), and the look of the names. */
|
|
136
136
|
#sky;
|
|
137
137
|
#skyStyle = {};
|
|
138
|
+
#keepClear = [];
|
|
138
139
|
/** The names of cities on the Earth (`city-names`), and the look of the names. */
|
|
139
140
|
#cities;
|
|
140
141
|
#citiesStyle = {};
|
|
@@ -201,6 +202,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
201
202
|
loadFont: loadMichroma,
|
|
202
203
|
});
|
|
203
204
|
this.#sky.setStyle(this.#skyStyle);
|
|
205
|
+
this.#sky.setKeepClear(this.#keepClear);
|
|
204
206
|
this.#placeLayer = createPlaceLayer(root.getElementById("places"));
|
|
205
207
|
this.#placeList = readPlaces(this.getAttribute("places"));
|
|
206
208
|
this.#placeLayer.set(this.#placeList);
|
|
@@ -433,6 +435,29 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
433
435
|
this.#skyStyle = { ...value };
|
|
434
436
|
this.#sky?.setStyle(this.#skyStyle);
|
|
435
437
|
}
|
|
438
|
+
/**
|
|
439
|
+
* The constellation that is picked, by its IAU abbreviation (`Ori`), or `null`. A reader picks one by a click or a tap on its lines or inside its figure (and with the key `C`, or `Shift`+`C` for the previous, while the element has the focus); a click on empty sky, or `Escape`, lets it go. The picked figure's lines are lit and its name is
|
|
440
|
+
* shown at the middle of the part of it in view, until another is picked or it is let go. A page sets the property to pick one itself, which sends no event. `chikyu-constellation-pick` is sent at each pick of the reader's, with `detail` `{ abbreviation, id, name, english, japanese, kind, culture }` (`culture` is `iau` unless `constellation-culture` names another), and `null` when it is let go; `chikyu-constellation-hover` is sent the same way as a mouse rests on a figure and leaves it.
|
|
441
|
+
* Needs `constellation-lines` set. `constellation-culture` (`iau` by default, `western`, `japanese` or `chinese`; each is fetched only when asked for, and the value is exactly what the page sets) makes the figures, the pick and the names those of that sky culture. The attribute `constellation-names` (off by default) writes the name of every figure in view at the middle of the part of it that is on the picture, quieter than the star names and clear of them, of the Earth, the Moon, the Sun, the places and satellites named, and of the places kept clear (`keepClear`).
|
|
442
|
+
*/
|
|
443
|
+
get constellation() {
|
|
444
|
+
return this.#sky?.picked ?? null;
|
|
445
|
+
}
|
|
446
|
+
set constellation(value) {
|
|
447
|
+
this.#sky?.pick(value);
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Places on the picture where the sky's names must not go: a page's own text laid over the element, say. Each is a rectangle in the element's own CSS pixels from its top left (`{ x, y, width, height }`), or an element of the page whose box is read. A star name whose box touches
|
|
451
|
+
* one is left out, and so is a star whose point is in one (the next star is named instead); the picked constellation's name is moved clear of it. The lines are still drawn. The boxes are read when the list changes, when the page or an element is resized or scrolled, and not at each frame: a
|
|
452
|
+
* page that moves its text without resizing it sets the property again. The attribute `keep-clear` takes a CSS selector for the same (`keep-clear=".hero h1, .hero .lead"`). Nothing is redrawn at rest.
|
|
453
|
+
*/
|
|
454
|
+
get keepClear() {
|
|
455
|
+
return [...this.#keepClear];
|
|
456
|
+
}
|
|
457
|
+
set keepClear(value) {
|
|
458
|
+
this.#keepClear = value ? [...value] : [];
|
|
459
|
+
this.#sky?.setKeepClear(this.#keepClear);
|
|
460
|
+
}
|
|
436
461
|
/**
|
|
437
462
|
* Places marked on the Earth (the attribute `places`, a JSON array): each `{ id, lon, lat, label, kind }`, `kind` being `here` (where the reader is: drawn bright and taller, with a quiet pulse) or `favourite`
|
|
438
463
|
* (the default: quieter). Each stands up out of the ground, turns with the Earth, is hidden on its far side and keeps its size in pixels at any zoom. Names go at the top, `here` first, and never overlap
|
|
@@ -714,7 +739,9 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
714
739
|
this.#focusBeforeRide = model.focus;
|
|
715
740
|
// the heading starts from the yaw the controls already hold (an address that carries `yaw` is read before the ride begins), so a ride opened from the address looks where the one that was dragged there looked
|
|
716
741
|
model.rideTurn = rideTurnDegrees(model.view.yaw, model.view.zoom);
|
|
717
|
-
const
|
|
742
|
+
const asked = options.view ?? "from";
|
|
743
|
+
// above a body is meant for a satellite: a body is followed
|
|
744
|
+
const view = typeof target === "string" && (target === "Earth" || asked === "above") ? "follow" : asked;
|
|
718
745
|
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) };
|
|
719
746
|
if (typeof target === "string" && view === "follow")
|
|
720
747
|
model.focus = target;
|
|
@@ -978,7 +1005,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
978
1005
|
bodies: { look: this.#model.bodies || painter?.looks?.[0] || "plain", painted: this.#model.painted.bodies, moons: this.#model.painted.moons },
|
|
979
1006
|
meteors: { on: this.#model.meteors.on, strength: this.#model.meteors.strength, ...this.#model.meteors.drawn },
|
|
980
1007
|
bodyLabel: { on: this.#model.bodyLabel.settings !== null, text: this.#model.bodyLabel.text, ...this.#model.bodyLabel.drawn },
|
|
981
|
-
sky: this.#sky?.stats ?? { on: false, loaded: false, names: 0, figures: 0, picked: null, renders: 0, lang: "", stars: [] },
|
|
1008
|
+
sky: this.#sky?.stats ?? { on: false, loaded: false, names: 0, figures: 0, picked: null, pick: null, hover: null, constellations: 0, culture: "iau", renders: 0, lang: "", stars: [] },
|
|
982
1009
|
followModel: this.#model.followModel,
|
|
983
1010
|
places: { ...(this.#placeLayer?.stats ?? { places: 0, shown: 0, labels: 0, renders: 0, rings: 0, satelliteNames: 0 }) },
|
|
984
1011
|
cityNames: this.#cities?.stats ?? { on: false, max: 0, radius: 0, tiers: [], cities: 0, names: 0, renders: 0 },
|
package/dist/space/index.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ export { compress, MOON_COMPRESSED, placeAround, placeMoon, placeSun, RADIUS, SU
|
|
|
3
3
|
export { fitDistance, plainPainter, type BodyDrawing, type BodyMoon, type BodyPainter, type PaintContext, type SatellitePainter } from "./scene.ts";
|
|
4
4
|
export { RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees, type RideInput, type RideLook, type RidePose } from "./ride.ts";
|
|
5
5
|
export type { SatelliteScreen } from "./satellite-layer.ts";
|
|
6
|
-
export { MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.ts";
|
|
6
|
+
export { aboveAxes, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.ts";
|
package/dist/space/index.js
CHANGED
|
@@ -4,4 +4,4 @@ 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 { RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees } from "./ride.js";
|
|
7
|
-
export { MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
|
|
7
|
+
export { aboveAxes, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
|
|
@@ -31,6 +31,28 @@ export declare function satelliteAxes(position: Vec3, velocity: Vec3): {
|
|
|
31
31
|
y: Vec3;
|
|
32
32
|
z: Vec3;
|
|
33
33
|
} | null;
|
|
34
|
+
/**
|
|
35
|
+
* The camera of the view above a satellite: where it stands from the satellite (a unit vector, to be multiplied by the height) and the way its picture's top points. With no turn and no tip the camera is straight above the satellite, looking straight down at it, the way the satellite is going at the top of
|
|
36
|
+
* the picture. `yaw` turns the picture about the satellite (the top points the other way round the satellite); `tilt` tips the camera back (positive) or ahead of the satellite (negative), so it looks down at it from behind or in front.
|
|
37
|
+
*
|
|
38
|
+
* @param position - The satellite's place from the Earth's centre.
|
|
39
|
+
* @param velocity - Its velocity.
|
|
40
|
+
* @param yaw - The turn of the picture about the satellite, in radians.
|
|
41
|
+
* @param tilt - How far the camera is tipped back from straight above, in radians.
|
|
42
|
+
* @returns The unit offset of the camera from the satellite, and the unit vector at the top of its picture.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { aboveAxes } from "@johnmorrisdotca/chikyu-earth/space";
|
|
47
|
+
*
|
|
48
|
+
* const view = aboveAxes([1.07, 0, 0], [0, 0, 1], 0, 0);
|
|
49
|
+
* console.log(view.offset, view.up);
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function aboveAxes(position: Vec3, velocity: Vec3, yaw: number, tilt: number): {
|
|
53
|
+
offset: Vec3;
|
|
54
|
+
up: Vec3;
|
|
55
|
+
};
|
|
34
56
|
/**
|
|
35
57
|
* The 4 by 4 matrix, row by row (what three.js's `Matrix4.set` takes), that puts a model of radius 1 at a place, turned to the satellite's axes and scaled: its columns are the axes times the scale, then the place.
|
|
36
58
|
*
|
|
@@ -40,6 +40,44 @@ export function satelliteAxes(position, velocity) {
|
|
|
40
40
|
const y = [z[1] * x[2] - z[2] * x[1], z[2] * x[0] - z[0] * x[2], z[0] * x[1] - z[1] * x[0]];
|
|
41
41
|
return { x, y, z };
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* The camera of the view above a satellite: where it stands from the satellite (a unit vector, to be multiplied by the height) and the way its picture's top points. With no turn and no tip the camera is straight above the satellite, looking straight down at it, the way the satellite is going at the top of
|
|
45
|
+
* the picture. `yaw` turns the picture about the satellite (the top points the other way round the satellite); `tilt` tips the camera back (positive) or ahead of the satellite (negative), so it looks down at it from behind or in front.
|
|
46
|
+
*
|
|
47
|
+
* @param position - The satellite's place from the Earth's centre.
|
|
48
|
+
* @param velocity - Its velocity.
|
|
49
|
+
* @param yaw - The turn of the picture about the satellite, in radians.
|
|
50
|
+
* @param tilt - How far the camera is tipped back from straight above, in radians.
|
|
51
|
+
* @returns The unit offset of the camera from the satellite, and the unit vector at the top of its picture.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* import { aboveAxes } from "@johnmorrisdotca/chikyu-earth/space";
|
|
56
|
+
*
|
|
57
|
+
* const view = aboveAxes([1.07, 0, 0], [0, 0, 1], 0, 0);
|
|
58
|
+
* console.log(view.offset, view.up);
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export function aboveAxes(position, velocity, yaw, tilt) {
|
|
62
|
+
let axes = satelliteAxes(position, velocity);
|
|
63
|
+
if (!axes) {
|
|
64
|
+
// no way it is going (or no place): any level direction will do
|
|
65
|
+
const length = Math.hypot(position[0], position[1], position[2]);
|
|
66
|
+
const z = length > 0 ? [position[0] / length, position[1] / length, position[2] / length] : [1, 0, 0];
|
|
67
|
+
const from = Math.abs(z[1]) < 0.9 ? [0, 1, 0] : [1, 0, 0];
|
|
68
|
+
const cross = [from[1] * z[2] - from[2] * z[1], from[2] * z[0] - from[0] * z[2], from[0] * z[1] - from[1] * z[0]];
|
|
69
|
+
const size = Math.hypot(cross[0], cross[1], cross[2]) || 1;
|
|
70
|
+
const x = [cross[0] / size, cross[1] / size, cross[2] / size];
|
|
71
|
+
axes = { x, y: [z[1] * x[2] - z[2] * x[1], z[2] * x[0] - z[0] * x[2], z[0] * x[1] - z[1] * x[0]], z };
|
|
72
|
+
}
|
|
73
|
+
const { x, y, z } = axes;
|
|
74
|
+
const cy = Math.cos(yaw);
|
|
75
|
+
const sy = Math.sin(yaw);
|
|
76
|
+
const top = [cy * x[0] + sy * y[0], cy * x[1] + sy * y[1], cy * x[2] + sy * y[2]];
|
|
77
|
+
const ct = Math.cos(tilt);
|
|
78
|
+
const st = Math.sin(tilt);
|
|
79
|
+
return { offset: [ct * z[0] - st * top[0], ct * z[1] - st * top[1], ct * z[2] - st * top[2]], up: top };
|
|
80
|
+
}
|
|
43
81
|
/**
|
|
44
82
|
* The 4 by 4 matrix, row by row (what three.js's `Matrix4.set` takes), that puts a model of radius 1 at a place, turned to the satellite's axes and scaled: its columns are the axes times the scale, then the place.
|
|
45
83
|
*
|
package/dist/space/scene.d.ts
CHANGED
|
@@ -85,8 +85,8 @@ export type BodyName = (typeof BODY_NAMES)[number];
|
|
|
85
85
|
export type RideTarget = BodyName | SatelliteRef;
|
|
86
86
|
export interface RideState {
|
|
87
87
|
target: RideTarget;
|
|
88
|
-
/** `from`: the camera is at the body, looking at the Earth. `follow`: the camera keeps a fixed distance from it, looking at it. */
|
|
89
|
-
view: "from" | "follow";
|
|
88
|
+
/** `from`: the camera is at the body, looking at the Earth. `follow`: the camera keeps a fixed distance from it, looking at it. `above` (a satellite): the camera is on the line from the Earth's centre through the satellite, looking straight down. */
|
|
89
|
+
view: "from" | "follow" | "above";
|
|
90
90
|
look: RideLook;
|
|
91
91
|
/** For `follow` a satellite: how far the camera keeps, in kilometres. */
|
|
92
92
|
distanceKm: number;
|
|
@@ -195,6 +195,7 @@ export interface SpaceModel {
|
|
|
195
195
|
x: number;
|
|
196
196
|
y: number;
|
|
197
197
|
shown: boolean;
|
|
198
|
+
parts: number;
|
|
198
199
|
} | null;
|
|
199
200
|
/** Where a satellite of a shown group is on the screen as of the last draw (`placeSatellite`), or `null`. */
|
|
200
201
|
placeSatellite: ((ref: SatelliteRef) => SatelliteScreen | null) | null;
|
package/dist/space/scene.js
CHANGED
|
@@ -6,7 +6,7 @@ import { createTrack, orbitPath, PLANETS } from "./ephemeris.js";
|
|
|
6
6
|
import { placeAround, placeMoon, placeSun, RADIUS } from "./scale.js";
|
|
7
7
|
import { ridePose } from "./ride.js";
|
|
8
8
|
import { coverBody, covers } from "../sky/cover.js";
|
|
9
|
-
import { MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
|
|
9
|
+
import { aboveAxes, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
|
|
10
10
|
import { createSatelliteLayer, newSatelliteState } from "./satellite-layer.js";
|
|
11
11
|
import { createBodyLabelLayer, newBodyLabelState } from "../realistic/body-label.js";
|
|
12
12
|
import { createMeteorLayer, newMeteorState } from "../meteors/layer.js";
|
|
@@ -276,7 +276,7 @@ export function createSpaceItem(model, deps) {
|
|
|
276
276
|
let nameOn = null;
|
|
277
277
|
let marksTold = false;
|
|
278
278
|
// the followed satellite's model: which satellite it is for, the drawing once it is made, and a count so that a model made for a satellite no longer followed is let go
|
|
279
|
-
const modelSlot = { key: "", drawing: null, turn: 0 };
|
|
279
|
+
const modelSlot = { key: "", drawing: null, turn: 0, parts: 0 };
|
|
280
280
|
const dropModel = () => {
|
|
281
281
|
if (!modelSlot.drawing)
|
|
282
282
|
return;
|
|
@@ -420,7 +420,7 @@ export function createSpaceItem(model, deps) {
|
|
|
420
420
|
}
|
|
421
421
|
else if (layer?.exact(ride.target, model.time, rideState)) {
|
|
422
422
|
const place = [rideState[0], rideState[1], rideState[2]];
|
|
423
|
-
if (ride.view === "follow") {
|
|
423
|
+
if (ride.view === "follow" || ride.view === "above") {
|
|
424
424
|
focusPos = place;
|
|
425
425
|
focusRadius = Math.max(1e-4, ride.distanceKm / 6371 / fit);
|
|
426
426
|
followed = { place, velocity: [rideState[3], rideState[4], rideState[5]], ref: ride.target };
|
|
@@ -473,14 +473,28 @@ export function createSpaceItem(model, deps) {
|
|
|
473
473
|
const lon = model.centre.lon - way * model.view.yaw;
|
|
474
474
|
const lat = Math.max(-90, Math.min(90, baseLat - way * model.view.tilt));
|
|
475
475
|
const aim = direction(spin + lon, lat);
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
476
|
+
if (followed && ride && ride.view === "above") {
|
|
477
|
+
// above the satellite: on the line from the Earth's centre through it, looking straight down at it, the way it is going at the top of the picture; the satellite stays in the middle and the Earth turns beneath.
|
|
478
|
+
// A drag turns the picture about the satellite (yaw) and tips the camera back or ahead of it (tilt).
|
|
479
|
+
distance = Math.max(1e-4, ride.distanceKm / 6371 / Math.max(1e-9, model.view.zoom));
|
|
480
|
+
const up = aboveAxes(followed.place, followed.velocity, model.view.yaw * RAD, Math.max(-80, Math.min(80, model.view.tilt)) * RAD);
|
|
481
|
+
target.set(focusPos[0], focusPos[1], focusPos[2]);
|
|
482
|
+
camera.position.set(target.x + up.offset[0] * distance, target.y + up.offset[1] * distance, target.z + up.offset[2] * distance);
|
|
483
|
+
camera.up.set(up.up[0], up.up[1], up.up[2]);
|
|
484
|
+
camera.lookAt(target);
|
|
485
|
+
camera.near = Math.max(1e-4, distance * 0.02);
|
|
486
|
+
camera.far = Math.max(2000, distance * 4 + (mode === "true" ? 40 * 23_481 : 400));
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
distance = Math.max(1.05 * focusRadius, (fit * focusRadius) / Math.max(1e-9, model.view.zoom));
|
|
490
|
+
target.set(focusPos[0], focusPos[1], focusPos[2]);
|
|
491
|
+
camera.position.set(target.x + aim[0] * distance, target.y + aim[1] * distance, target.z + aim[2] * distance);
|
|
492
|
+
camera.up.set(0, 1, 0);
|
|
493
|
+
camera.lookAt(target);
|
|
494
|
+
camera.near = Math.max(0.0005, distance * 0.02 - focusRadius * 0.5, focusRadius * 0.01);
|
|
495
|
+
camera.far = Math.max(2000, distance * 4 + (mode === "true" ? 40 * 23_481 : 400));
|
|
496
|
+
}
|
|
497
|
+
if (ride && (ride.view === "follow" || ride.view === "above") && typeof ride.target !== "string") {
|
|
484
498
|
const focal = (size.height / 2) / Math.tan((fovNow / 2) * RAD);
|
|
485
499
|
model.rideMotion = (Math.hypot(rideState[3], rideState[4], rideState[5]) / Math.max(50, ride.distanceKm / Math.max(1e-9, model.view.zoom))) * focal;
|
|
486
500
|
}
|
|
@@ -500,9 +514,10 @@ export function createSpaceItem(model, deps) {
|
|
|
500
514
|
}
|
|
501
515
|
camera.fov = fovNow;
|
|
502
516
|
camera.aspect = size.width / Math.max(1, size.height);
|
|
503
|
-
// the Earth's place in the view: the picture is moved, not the camera (a camera riding from a body keeps the middle)
|
|
504
|
-
const
|
|
505
|
-
const
|
|
517
|
+
// 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)
|
|
518
|
+
const centred = rideFrom !== null || (ride?.view === "above" && followed !== null);
|
|
519
|
+
const shiftX = centred ? 0 : (model.earth.x - 0.5) * size.width;
|
|
520
|
+
const shiftY = centred ? 0 : (model.earth.y - 0.5) * size.height;
|
|
506
521
|
if (shiftX !== 0 || shiftY !== 0)
|
|
507
522
|
camera.setViewOffset(size.width, size.height, -shiftX, -shiftY, size.width, size.height);
|
|
508
523
|
else if (camera.view)
|
|
@@ -566,6 +581,12 @@ export function createSpaceItem(model, deps) {
|
|
|
566
581
|
made.object.visible = false;
|
|
567
582
|
scene.add(made.object);
|
|
568
583
|
modelSlot.drawing = made;
|
|
584
|
+
// how many meshes the model is made of: a draw call each, which a test of the draw budget adds to the scene's own
|
|
585
|
+
modelSlot.parts = 0;
|
|
586
|
+
made.object.traverse((part) => {
|
|
587
|
+
if (part.isMesh)
|
|
588
|
+
modelSlot.parts += 1;
|
|
589
|
+
});
|
|
569
590
|
deps.invalidate();
|
|
570
591
|
})
|
|
571
592
|
.catch((error) => deps.onPainterError?.(error));
|
|
@@ -582,7 +603,7 @@ export function createSpaceItem(model, deps) {
|
|
|
582
603
|
modelSlot.drawing.light?.(toSunNow);
|
|
583
604
|
modelSlot.drawing.update?.({ toSun: toSunNow, ms: model.time, radiusPx: size.height * MODEL_RADIUS_SHARE });
|
|
584
605
|
projected.set(followed.place[0], followed.place[1], followed.place[2]).project(camera);
|
|
585
|
-
model.followModel = { x: ((projected.x + 1) / 2) * size.width, y: ((1 - projected.y) / 2) * size.height, shown: true };
|
|
606
|
+
model.followModel = { x: ((projected.x + 1) / 2) * size.width, y: ((1 - projected.y) / 2) * size.height, shown: true, parts: modelSlot.parts };
|
|
586
607
|
}
|
|
587
608
|
else {
|
|
588
609
|
if (modelSlot.drawing)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/chikyu-earth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.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",
|