@johnmorrisdotca/chikyu-earth 0.47.0 → 0.48.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 +5 -0
- package/README.md +1 -1
- package/dist/realistic/earth.d.ts +3 -0
- package/dist/realistic/earth.js +4 -1
- package/dist/realistic/element-base.d.ts +71 -0
- package/dist/realistic/element-base.js +122 -2
- package/dist/sky/claim.d.ts +4 -0
- package/dist/sky/claim.js +8 -0
- package/dist/sky/host.js +5 -0
- package/dist/space/element-base.d.ts +71 -0
- package/dist/space/element-base.js +123 -1
- package/dist/space/path-controls.d.ts +56 -0
- package/dist/space/path-controls.js +121 -0
- package/dist/space/path-ribbons.d.ts +25 -0
- package/dist/space/path-ribbons.js +165 -0
- package/dist/space/paths.d.ts +119 -0
- package/dist/space/paths.js +163 -0
- package/dist/space/satellite-layer.d.ts +28 -2
- package/dist/space/satellite-layer.js +145 -28
- package/dist/space/scene.d.ts +3 -0
- package/dist/space/scene.js +5 -1
- package/package.json +1 -1
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { SatelliteRef, Satellites } from "../satellites/types.ts";
|
|
2
|
+
/** How a path is drawn: its colour, its width in CSS pixels, how opaque it is and its dashes (a dash and a gap, in CSS pixels, or `null` for a solid line). */
|
|
3
|
+
export interface PathStyle {
|
|
4
|
+
/** Any CSS colour. */
|
|
5
|
+
color: string;
|
|
6
|
+
/** CSS pixels, 0.5 to 8. */
|
|
7
|
+
width: number;
|
|
8
|
+
/** 0 to 1. */
|
|
9
|
+
opacity: number;
|
|
10
|
+
/** `[dash, gap]` in CSS pixels, each 1 to 64, measured along the orbit at the Earth's drawn size; `null` is a solid line. */
|
|
11
|
+
dash: [number, number] | null;
|
|
12
|
+
}
|
|
13
|
+
/** One path to draw: the satellite, by NORAD catalogue number or by `group:index` (`stations:0`), and its look, as the name of an entry of the style table or as a partial look over the `path` entry. */
|
|
14
|
+
export interface PathRequest {
|
|
15
|
+
id: number | string;
|
|
16
|
+
style?: string | Partial<PathStyle>;
|
|
17
|
+
}
|
|
18
|
+
/** A path that is drawn: the request, the satellite it resolved to and the look it has. */
|
|
19
|
+
export interface PathInfo {
|
|
20
|
+
id: number | string;
|
|
21
|
+
ref: SatelliteRef;
|
|
22
|
+
/** The name of the style, or `custom` for a look given in the request itself. */
|
|
23
|
+
style: string;
|
|
24
|
+
}
|
|
25
|
+
/** The path under a point on the picture. */
|
|
26
|
+
export interface PathHit extends PathInfo {
|
|
27
|
+
/** CSS pixels from the element's left and top edges: the point on the path nearest to the pointer. */
|
|
28
|
+
x: number;
|
|
29
|
+
y: number;
|
|
30
|
+
/** How far, in CSS pixels, the pointer is from that point. */
|
|
31
|
+
distancePx: number;
|
|
32
|
+
/** What pointed: a mouse, a touch or a pen. */
|
|
33
|
+
pointer: "mouse" | "touch" | "pen";
|
|
34
|
+
}
|
|
35
|
+
/** The most extra paths drawn at once. A longer list keeps the last of it (the most recent). */
|
|
36
|
+
export declare const MAX_PATHS = 16;
|
|
37
|
+
/** The path hit radius in CSS pixels when the page does not say (`path-hit`), and its range. A touch is given twice as much, and at least {@link TOUCH_HIT_MIN}. */
|
|
38
|
+
export declare const DEFAULT_PATH_HIT = 8;
|
|
39
|
+
export declare const MAX_PATH_HIT = 40;
|
|
40
|
+
export declare const TOUCH_HIT_MIN = 16;
|
|
41
|
+
export declare const MIN_PATH_WIDTH = 0.5;
|
|
42
|
+
export declare const MAX_PATH_WIDTH = 8;
|
|
43
|
+
/** The look of each name before a page overrides any. They differ in width and dash, not only in colour. */
|
|
44
|
+
export declare const BUILT_IN_PATH_STYLES: Readonly<Record<string, PathStyle>>;
|
|
45
|
+
/**
|
|
46
|
+
* Take a look a page gave and make a whole one: what is missing or out of range is taken from `base` (a number is held to its range, a dash that is not two numbers of 1 to 64 is `base`'s dash, `null` is a solid line).
|
|
47
|
+
*
|
|
48
|
+
* @param given - The page's look, any part of it.
|
|
49
|
+
* @param base - The look to fall back on.
|
|
50
|
+
* @returns A look with every part set.
|
|
51
|
+
*/
|
|
52
|
+
export declare function completeStyle(given: Partial<PathStyle> | null | undefined, base: PathStyle): PathStyle;
|
|
53
|
+
/**
|
|
54
|
+
* The table of looks in use: the built-in ones with the page's own laid over them, name by name. An override is a partial look over the built-in of that name (or over `path` for a new name);
|
|
55
|
+
* `null` takes a page's override away.
|
|
56
|
+
*
|
|
57
|
+
* @param overrides - The page's entries.
|
|
58
|
+
* @returns The whole table, a new object.
|
|
59
|
+
*/
|
|
60
|
+
export declare function styleTable(overrides: Readonly<Record<string, Partial<PathStyle> | null>>): Record<string, PathStyle>;
|
|
61
|
+
/** The part of a list that is drawn and how much was left out: the last {@link MAX_PATHS}, in their order. */
|
|
62
|
+
export declare function capPaths<T>(list: readonly T[]): {
|
|
63
|
+
kept: T[];
|
|
64
|
+
dropped: number;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Find the satellite an id names among the groups shown: a NORAD number, or `group:index` (`group/index` is read the same). `null` when nothing matches.
|
|
68
|
+
*
|
|
69
|
+
* @param id - The id from a path request.
|
|
70
|
+
* @param groups - The groups, by name.
|
|
71
|
+
* @returns The satellite, or `null`.
|
|
72
|
+
*/
|
|
73
|
+
export declare function resolvePathId(id: number | string, groups: ReadonlyMap<string, {
|
|
74
|
+
satellites: Satellites;
|
|
75
|
+
}>): SatelliteRef | null;
|
|
76
|
+
/** The radius a pointer finds a path within: the page's `path-hit` for a mouse or a pen, twice it (at least {@link TOUCH_HIT_MIN}) for a touch, and 0 (no test) when `path-hit` is 0. */
|
|
77
|
+
export declare function hitRadius(base: number, pointer: PathHit["pointer"]): number;
|
|
78
|
+
/** Read `path-hit`: a number of CSS pixels from 0 to {@link MAX_PATH_HIT}, `off` for 0, and the default for nothing or anything else. */
|
|
79
|
+
export declare function readPathHit(value: string | null): number;
|
|
80
|
+
/** The look of the path of a request: a name in the table, a partial look over `path`, or `path` itself. A name the table does not have is `path`. */
|
|
81
|
+
export declare function styleOf(request: PathRequest, table: Readonly<Record<string, PathStyle>>): {
|
|
82
|
+
name: string;
|
|
83
|
+
style: PathStyle;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* How far a point is from a line segment, and the point on it nearest. All in the same units (CSS pixels on the picture).
|
|
87
|
+
*
|
|
88
|
+
* @param px - The point's x.
|
|
89
|
+
* @param py - The point's y.
|
|
90
|
+
* @param ax - The segment's start x.
|
|
91
|
+
* @param ay - The segment's start y.
|
|
92
|
+
* @param bx - The segment's end x.
|
|
93
|
+
* @param by - The segment's end y.
|
|
94
|
+
* @returns The distance and the nearest point.
|
|
95
|
+
*/
|
|
96
|
+
export declare function nearestOnSegment(px: number, py: number, ax: number, ay: number, bx: number, by: number): {
|
|
97
|
+
distance: number;
|
|
98
|
+
x: number;
|
|
99
|
+
y: number;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* The nearest of several closed loops of screen points to a point, within `radius`. A segment is left out when either end is flagged hidden (behind the Earth, behind the camera or off the picture's depth).
|
|
103
|
+
*
|
|
104
|
+
* @param px - The point's x.
|
|
105
|
+
* @param py - The point's y.
|
|
106
|
+
* @param loops - Each loop's screen points (`xy`, two numbers each) and a flag for each point (`ok`: 1 when the point can be seen, else 0).
|
|
107
|
+
* @param radius - The most the point may be from a loop.
|
|
108
|
+
* @returns The loop's index, the distance and the nearest point, or `null` when no loop is within the radius.
|
|
109
|
+
*/
|
|
110
|
+
export declare function nearestLoop(px: number, py: number, loops: readonly {
|
|
111
|
+
xy: Float32Array | Float64Array;
|
|
112
|
+
ok: Uint8Array;
|
|
113
|
+
count: number;
|
|
114
|
+
}[], radius: number): {
|
|
115
|
+
index: number;
|
|
116
|
+
distance: number;
|
|
117
|
+
x: number;
|
|
118
|
+
y: number;
|
|
119
|
+
} | null;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/** The most extra paths drawn at once. A longer list keeps the last of it (the most recent). */
|
|
2
|
+
export const MAX_PATHS = 16;
|
|
3
|
+
/** The path hit radius in CSS pixels when the page does not say (`path-hit`), and its range. A touch is given twice as much, and at least {@link TOUCH_HIT_MIN}. */
|
|
4
|
+
export const DEFAULT_PATH_HIT = 8;
|
|
5
|
+
export const MAX_PATH_HIT = 40;
|
|
6
|
+
export const TOUCH_HIT_MIN = 16;
|
|
7
|
+
export const MIN_PATH_WIDTH = 0.5;
|
|
8
|
+
export const MAX_PATH_WIDTH = 8;
|
|
9
|
+
/** The look of each name before a page overrides any. They differ in width and dash, not only in colour. */
|
|
10
|
+
export const BUILT_IN_PATH_STYLES = {
|
|
11
|
+
selected: { color: "#ffffff", width: 2, opacity: 0.85, dash: null },
|
|
12
|
+
hovered: { color: "#ffffff", width: 1.5, opacity: 0.6, dash: [6, 4] },
|
|
13
|
+
favourite: { color: "#ffd166", width: 1.75, opacity: 0.85, dash: [3, 4] },
|
|
14
|
+
path: { color: "#ffffff", width: 1.5, opacity: 0.8, dash: null },
|
|
15
|
+
};
|
|
16
|
+
const clamp = (value, low, high) => Math.min(high, Math.max(low, value));
|
|
17
|
+
/**
|
|
18
|
+
* Take a look a page gave and make a whole one: what is missing or out of range is taken from `base` (a number is held to its range, a dash that is not two numbers of 1 to 64 is `base`'s dash, `null` is a solid line).
|
|
19
|
+
*
|
|
20
|
+
* @param given - The page's look, any part of it.
|
|
21
|
+
* @param base - The look to fall back on.
|
|
22
|
+
* @returns A look with every part set.
|
|
23
|
+
*/
|
|
24
|
+
export function completeStyle(given, base) {
|
|
25
|
+
const out = { ...base, dash: base.dash ? [...base.dash] : null };
|
|
26
|
+
if (!given || typeof given !== "object")
|
|
27
|
+
return out;
|
|
28
|
+
if (typeof given.color === "string" && given.color.trim() !== "")
|
|
29
|
+
out.color = given.color.trim();
|
|
30
|
+
if (typeof given.width === "number" && Number.isFinite(given.width))
|
|
31
|
+
out.width = clamp(given.width, MIN_PATH_WIDTH, MAX_PATH_WIDTH);
|
|
32
|
+
if (typeof given.opacity === "number" && Number.isFinite(given.opacity))
|
|
33
|
+
out.opacity = clamp(given.opacity, 0, 1);
|
|
34
|
+
if (given.dash === null)
|
|
35
|
+
out.dash = null;
|
|
36
|
+
else if (Array.isArray(given.dash) && given.dash.length === 2 && given.dash.every((n) => typeof n === "number" && Number.isFinite(n)))
|
|
37
|
+
out.dash = [clamp(given.dash[0], 1, 64), clamp(given.dash[1], 1, 64)];
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The table of looks in use: the built-in ones with the page's own laid over them, name by name. An override is a partial look over the built-in of that name (or over `path` for a new name);
|
|
42
|
+
* `null` takes a page's override away.
|
|
43
|
+
*
|
|
44
|
+
* @param overrides - The page's entries.
|
|
45
|
+
* @returns The whole table, a new object.
|
|
46
|
+
*/
|
|
47
|
+
export function styleTable(overrides) {
|
|
48
|
+
const table = {};
|
|
49
|
+
for (const [name, style] of Object.entries(BUILT_IN_PATH_STYLES))
|
|
50
|
+
table[name] = completeStyle(null, style);
|
|
51
|
+
for (const [name, given] of Object.entries(overrides)) {
|
|
52
|
+
if (given === null || name === "")
|
|
53
|
+
continue;
|
|
54
|
+
table[name] = completeStyle(given, table[name] ?? BUILT_IN_PATH_STYLES["path"]);
|
|
55
|
+
}
|
|
56
|
+
return table;
|
|
57
|
+
}
|
|
58
|
+
/** The part of a list that is drawn and how much was left out: the last {@link MAX_PATHS}, in their order. */
|
|
59
|
+
export function capPaths(list) {
|
|
60
|
+
const dropped = Math.max(0, list.length - MAX_PATHS);
|
|
61
|
+
return { kept: list.slice(dropped), dropped };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Find the satellite an id names among the groups shown: a NORAD number, or `group:index` (`group/index` is read the same). `null` when nothing matches.
|
|
65
|
+
*
|
|
66
|
+
* @param id - The id from a path request.
|
|
67
|
+
* @param groups - The groups, by name.
|
|
68
|
+
* @returns The satellite, or `null`.
|
|
69
|
+
*/
|
|
70
|
+
export function resolvePathId(id, groups) {
|
|
71
|
+
if (typeof id === "string") {
|
|
72
|
+
const at = Math.max(id.lastIndexOf(":"), id.lastIndexOf("/"));
|
|
73
|
+
if (at > 0) {
|
|
74
|
+
const group = id.slice(0, at);
|
|
75
|
+
const index = Number(id.slice(at + 1));
|
|
76
|
+
const found = groups.get(group);
|
|
77
|
+
return found && Number.isInteger(index) && index >= 0 && index < found.satellites.count ? { group, index } : null;
|
|
78
|
+
}
|
|
79
|
+
const number = Number(id);
|
|
80
|
+
if (id.trim() === "" || !Number.isInteger(number))
|
|
81
|
+
return null;
|
|
82
|
+
return resolvePathId(number, groups);
|
|
83
|
+
}
|
|
84
|
+
if (!Number.isInteger(id))
|
|
85
|
+
return null;
|
|
86
|
+
for (const [group, found] of groups) {
|
|
87
|
+
const sets = found.satellites.sets;
|
|
88
|
+
for (let index = 0; index < found.satellites.count; index += 1)
|
|
89
|
+
if (sets[index]?.NORAD_CAT_ID === id)
|
|
90
|
+
return { group, index };
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
/** The radius a pointer finds a path within: the page's `path-hit` for a mouse or a pen, twice it (at least {@link TOUCH_HIT_MIN}) for a touch, and 0 (no test) when `path-hit` is 0. */
|
|
95
|
+
export function hitRadius(base, pointer) {
|
|
96
|
+
if (!(base > 0))
|
|
97
|
+
return 0;
|
|
98
|
+
return pointer === "touch" ? Math.max(TOUCH_HIT_MIN, base * 2) : base;
|
|
99
|
+
}
|
|
100
|
+
/** Read `path-hit`: a number of CSS pixels from 0 to {@link MAX_PATH_HIT}, `off` for 0, and the default for nothing or anything else. */
|
|
101
|
+
export function readPathHit(value) {
|
|
102
|
+
if (value === null || value.trim() === "")
|
|
103
|
+
return DEFAULT_PATH_HIT;
|
|
104
|
+
const text = value.trim().toLowerCase();
|
|
105
|
+
if (text === "off")
|
|
106
|
+
return 0;
|
|
107
|
+
const number = Number(text);
|
|
108
|
+
return Number.isFinite(number) && number >= 0 ? Math.min(MAX_PATH_HIT, number) : DEFAULT_PATH_HIT;
|
|
109
|
+
}
|
|
110
|
+
/** The look of the path of a request: a name in the table, a partial look over `path`, or `path` itself. A name the table does not have is `path`. */
|
|
111
|
+
export function styleOf(request, table) {
|
|
112
|
+
const given = request.style;
|
|
113
|
+
const base = table["path"] ?? BUILT_IN_PATH_STYLES["path"];
|
|
114
|
+
if (given === undefined)
|
|
115
|
+
return { name: "path", style: base };
|
|
116
|
+
if (typeof given === "string")
|
|
117
|
+
return table[given] ? { name: given, style: table[given] } : { name: "path", style: base };
|
|
118
|
+
return { name: "custom", style: completeStyle(given, base) };
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* How far a point is from a line segment, and the point on it nearest. All in the same units (CSS pixels on the picture).
|
|
122
|
+
*
|
|
123
|
+
* @param px - The point's x.
|
|
124
|
+
* @param py - The point's y.
|
|
125
|
+
* @param ax - The segment's start x.
|
|
126
|
+
* @param ay - The segment's start y.
|
|
127
|
+
* @param bx - The segment's end x.
|
|
128
|
+
* @param by - The segment's end y.
|
|
129
|
+
* @returns The distance and the nearest point.
|
|
130
|
+
*/
|
|
131
|
+
export function nearestOnSegment(px, py, ax, ay, bx, by) {
|
|
132
|
+
const dx = bx - ax;
|
|
133
|
+
const dy = by - ay;
|
|
134
|
+
const len2 = dx * dx + dy * dy;
|
|
135
|
+
const t = len2 > 0 ? clamp(((px - ax) * dx + (py - ay) * dy) / len2, 0, 1) : 0;
|
|
136
|
+
const x = ax + dx * t;
|
|
137
|
+
const y = ay + dy * t;
|
|
138
|
+
return { distance: Math.hypot(px - x, py - y), x, y };
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* The nearest of several closed loops of screen points to a point, within `radius`. A segment is left out when either end is flagged hidden (behind the Earth, behind the camera or off the picture's depth).
|
|
142
|
+
*
|
|
143
|
+
* @param px - The point's x.
|
|
144
|
+
* @param py - The point's y.
|
|
145
|
+
* @param loops - Each loop's screen points (`xy`, two numbers each) and a flag for each point (`ok`: 1 when the point can be seen, else 0).
|
|
146
|
+
* @param radius - The most the point may be from a loop.
|
|
147
|
+
* @returns The loop's index, the distance and the nearest point, or `null` when no loop is within the radius.
|
|
148
|
+
*/
|
|
149
|
+
export function nearestLoop(px, py, loops, radius) {
|
|
150
|
+
let best = null;
|
|
151
|
+
for (let l = 0; l < loops.length; l += 1) {
|
|
152
|
+
const { xy, ok, count } = loops[l];
|
|
153
|
+
for (let i = 0; i < count; i += 1) {
|
|
154
|
+
const j = (i + 1) % count;
|
|
155
|
+
if (!ok[i] || !ok[j])
|
|
156
|
+
continue;
|
|
157
|
+
const near = nearestOnSegment(px, py, xy[i * 2], xy[i * 2 + 1], xy[j * 2], xy[j * 2 + 1]);
|
|
158
|
+
if (near.distance <= radius && (best === null || near.distance < best.distance))
|
|
159
|
+
best = { index: l, distance: near.distance, x: near.x, y: near.y };
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return best;
|
|
163
|
+
}
|
|
@@ -2,6 +2,7 @@ import type * as THREE from "three";
|
|
|
2
2
|
import type { SatelliteRef, Satellites } from "../satellites/types.ts";
|
|
3
3
|
import type { ThreeParts } from "../realistic/textures.ts";
|
|
4
4
|
import { type SatelliteFocus } from "./satellite-focus.ts";
|
|
5
|
+
import { type PathHit, type PathInfo, type PathRequest, type PathStyle } from "./paths.ts";
|
|
5
6
|
type Three = ThreeParts;
|
|
6
7
|
/** How a group looks: the colour of its dots and their size in CSS pixels, and whether every orbit is drawn (only for a small group). */
|
|
7
8
|
export interface SatelliteStyle {
|
|
@@ -39,6 +40,21 @@ export interface SatelliteState {
|
|
|
39
40
|
color: string;
|
|
40
41
|
opacity: number;
|
|
41
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* The extra paths a page asked for (`setPaths`), the look table (`setPathStyles`: the page's entries over the built-in ones), whether the chosen satellite's own orbit is drawn (`selected-path`), and a number that goes up at each change so the layer
|
|
45
|
+
* rewrites its buffers only when something changed. `info` is what the last draw resolved and kept: the paths drawn, in order; `dropped` how many the cap left out and `unresolved` how many matched no satellite.
|
|
46
|
+
*/
|
|
47
|
+
paths: {
|
|
48
|
+
requests: PathRequest[];
|
|
49
|
+
overrides: Record<string, Partial<PathStyle> | null>;
|
|
50
|
+
selectedOn: boolean;
|
|
51
|
+
version: number;
|
|
52
|
+
info: PathInfo[];
|
|
53
|
+
dropped: number;
|
|
54
|
+
unresolved: number;
|
|
55
|
+
};
|
|
56
|
+
/** Set at each draw by the view: the satellite a ride is on, whose own orbit is drawn in the `selected` look while `selected-path` is on. `null` when none rides a satellite. */
|
|
57
|
+
ridden: SatelliteRef | null;
|
|
42
58
|
/**
|
|
43
59
|
* The pixel ceiling of a streak's length on the screen above the interpolation limit, in CSS pixels at the Earth's own distance (`satellite-streak-max`). A streak is also never longer than {@link STREAK_REACH} Earth radii, so it shrinks with the Earth.
|
|
44
60
|
* 0 draws the whole stretch one frame spans, however long that is.
|
|
@@ -64,6 +80,8 @@ export interface SatelliteState {
|
|
|
64
80
|
hoverPath: boolean;
|
|
65
81
|
hoverOpacity: number;
|
|
66
82
|
selectedOpacity: number;
|
|
83
|
+
pathsDrawn: number;
|
|
84
|
+
pathDraws: number;
|
|
67
85
|
};
|
|
68
86
|
}
|
|
69
87
|
/**
|
|
@@ -97,7 +115,7 @@ export declare const newSatelliteState: () => SatelliteState;
|
|
|
97
115
|
/** The most orbits a group may draw all at once, one line each. */
|
|
98
116
|
export declare const MAX_ORBIT_GROUP = 40;
|
|
99
117
|
/** How bright the chosen satellite's orbit is. The orbit under the pointer is about a third of this, so the two are told apart at a glance. */
|
|
100
|
-
export declare const SELECTED_PATH_OPACITY
|
|
118
|
+
export declare const SELECTED_PATH_OPACITY: number;
|
|
101
119
|
/** The orbit under the pointer, before it fades. A page may set another with `--chikyu-hover-path-opacity`. */
|
|
102
120
|
export declare const HOVER_PATH_OPACITY: number;
|
|
103
121
|
/** How long the faint orbit takes to go after the pointer leaves, in milliseconds. Reduced motion takes it away at once. */
|
|
@@ -211,7 +229,10 @@ export interface SatelliteLayer {
|
|
|
211
229
|
height: number;
|
|
212
230
|
}): SatelliteScreen | null;
|
|
213
231
|
/** Place every shown group for `model.time` and the chosen satellite exactly. `earthPx` is the Earth's radius on the screen, so a dot grows as the view zooms in. */
|
|
214
|
-
update(time: number, speed: number, earthPx?: number
|
|
232
|
+
update(time: number, speed: number, earthPx?: number, size?: {
|
|
233
|
+
width: number;
|
|
234
|
+
height: number;
|
|
235
|
+
}): void;
|
|
215
236
|
/** Set the dot size from the Earth's radius on the screen for this frame, after the camera is known. */
|
|
216
237
|
resize(earthPx: number): void;
|
|
217
238
|
/** The satellite nearest to a point of the view (CSS pixels) within `radius`, if one is in front of the Earth. */
|
|
@@ -219,6 +240,11 @@ export interface SatelliteLayer {
|
|
|
219
240
|
width: number;
|
|
220
241
|
height: number;
|
|
221
242
|
}, radius: number): SatelliteRef | null;
|
|
243
|
+
/** The path nearest to a point of the view (CSS pixels) within `radius`, if one is drawn there and not hidden by the Earth: the extra paths and the chosen satellite's own. */
|
|
244
|
+
pathAt(x: number, y: number, camera: THREE.Camera, size: {
|
|
245
|
+
width: number;
|
|
246
|
+
height: number;
|
|
247
|
+
}, radius: number): Omit<PathHit, "pointer"> | null;
|
|
222
248
|
/** Where the chosen satellite is in the view, if it is. */
|
|
223
249
|
place(camera: THREE.Camera, size: {
|
|
224
250
|
width: number;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { MAX_SATELLITE_SPEED } from "../satellites/limits.js";
|
|
2
2
|
import { satelliteEmphasis } from "./satellite-focus.js";
|
|
3
|
+
import { BUILT_IN_PATH_STYLES, capPaths, nearestLoop, resolvePathId, styleOf, styleTable } from "./paths.js";
|
|
4
|
+
import { createPathRibbons } from "./path-ribbons.js";
|
|
3
5
|
/**
|
|
4
6
|
* The longest a streak may be along its orbit, in Earth radii: 0.025, about 160 km, which is what a low satellite covers in a frame at 10 minutes a second (150 km). On the screen that is a share of the Earth's drawn radius, so a streak
|
|
5
7
|
* is a few millimetres when the Earth fills the view, half as long when the Earth is half as large, and a dot when the Earth is tiny. A cap of so many pixels alone would leave the same length on a small Earth, where it looks long.
|
|
@@ -54,12 +56,12 @@ export function longestStreak(segments, count, earthPx) {
|
|
|
54
56
|
}
|
|
55
57
|
return longest * earthPx;
|
|
56
58
|
}
|
|
57
|
-
export const newSatelliteState = () => ({ groups: new Map(), selected: null, marked: new Set(), pinned: [], orbitTint: false, focus: null, modelOver: null, hover: { ref: null, fade: 0, enabled: true, color: "#ffffff", opacity: HOVER_PATH_OPACITY }, streakMax: DEFAULT_STREAK_MAX, drawn: { placed: 0, segments: 0, tooFast: false, dotScale: 1, longestStreakPx: 0, streakCapPx: 0, weight: 1, fade: 1, earthPx: 0, updateMs: 0, maxUpdateMs: 0, updates: 0, totalMs: 0, selectedRing: false, hoverPath: false, hoverOpacity: 0, selectedOpacity: 0 } });
|
|
59
|
+
export const newSatelliteState = () => ({ groups: new Map(), selected: null, marked: new Set(), pinned: [], orbitTint: false, focus: null, modelOver: null, hover: { ref: null, fade: 0, enabled: true, color: "#ffffff", opacity: HOVER_PATH_OPACITY }, paths: { requests: [], overrides: {}, selectedOn: true, version: 0, info: [], dropped: 0, unresolved: 0 }, ridden: null, streakMax: DEFAULT_STREAK_MAX, drawn: { placed: 0, segments: 0, tooFast: false, dotScale: 1, longestStreakPx: 0, streakCapPx: 0, weight: 1, fade: 1, earthPx: 0, updateMs: 0, maxUpdateMs: 0, updates: 0, totalMs: 0, selectedRing: false, hoverPath: false, hoverOpacity: 0, selectedOpacity: 0, pathsDrawn: 0, pathDraws: 0 } });
|
|
58
60
|
/** The most orbits a group may draw all at once, one line each. */
|
|
59
61
|
export const MAX_ORBIT_GROUP = 40;
|
|
60
62
|
const ORBIT_POINTS = 120;
|
|
61
63
|
/** How bright the chosen satellite's orbit is. The orbit under the pointer is about a third of this, so the two are told apart at a glance. */
|
|
62
|
-
export const SELECTED_PATH_OPACITY =
|
|
64
|
+
export const SELECTED_PATH_OPACITY = BUILT_IN_PATH_STYLES["selected"].opacity;
|
|
63
65
|
/** The orbit under the pointer, before it fades. A page may set another with `--chikyu-hover-path-opacity`. */
|
|
64
66
|
export const HOVER_PATH_OPACITY = SELECTED_PATH_OPACITY / 3;
|
|
65
67
|
/** How long the faint orbit takes to go after the pointer leaves, in milliseconds. Reduced motion takes it away at once. */
|
|
@@ -247,15 +249,15 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
247
249
|
hoverLoop.renderOrder = 4;
|
|
248
250
|
scene.add(hoverLoop);
|
|
249
251
|
let hoverKey = "";
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
let
|
|
257
|
-
let
|
|
258
|
-
let
|
|
252
|
+
// The page's paths and the chosen satellite's own orbit: one mesh, one draw call, buffers made once (see path-ribbons.ts).
|
|
253
|
+
const ribbons = createPathRibbons(three, scene);
|
|
254
|
+
let slots = [];
|
|
255
|
+
let slotsSignature = "";
|
|
256
|
+
let resolvedFor = [];
|
|
257
|
+
let resolvedVersion = -1;
|
|
258
|
+
let resolved = [];
|
|
259
|
+
let pathDrawn = false;
|
|
260
|
+
let table = styleTable({});
|
|
259
261
|
const drop = (entry) => {
|
|
260
262
|
scene.remove(entry.points);
|
|
261
263
|
entry.geometry.dispose();
|
|
@@ -306,8 +308,99 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
306
308
|
entry.linesWall = wall;
|
|
307
309
|
};
|
|
308
310
|
const find = (ref) => state.groups.get(ref.group)?.satellites;
|
|
311
|
+
const refKey = (ref) => `${ref.group}:${ref.index}`;
|
|
312
|
+
const cleanRef = (ref) => {
|
|
313
|
+
if (!ref)
|
|
314
|
+
return null;
|
|
315
|
+
const group = state.groups.get(ref.group);
|
|
316
|
+
return group && ref.index >= 0 && ref.index < group.satellites.count && satelliteEmphasis(ref.group, group.visible, state.focus).drawn ? ref : null;
|
|
317
|
+
};
|
|
318
|
+
/**
|
|
319
|
+
* The paths to draw now: the page's (the last 16 that match a satellite, in order), then the chosen satellite's own orbit and the ridden one's in the `selected` look, last, so they lie over the rest. The orbits are
|
|
320
|
+
* computed once for a satellite and again only when the clock has moved half an hour and a second has passed, as the chosen orbit always was. The buffers are rewritten only when the list, a look or an orbit changed.
|
|
321
|
+
*/
|
|
322
|
+
const syncPaths = (time, wall, chosen) => {
|
|
323
|
+
const pathState = state.paths;
|
|
324
|
+
const sources = [...state.groups.values()].map((group) => group.satellites);
|
|
325
|
+
const same = sources.length === resolvedFor.length && sources.every((source, i) => source === resolvedFor[i]);
|
|
326
|
+
if (!same || resolvedVersion !== pathState.version) {
|
|
327
|
+
resolvedFor = sources;
|
|
328
|
+
resolvedVersion = pathState.version;
|
|
329
|
+
table = styleTable(pathState.overrides);
|
|
330
|
+
resolved = pathState.requests.map((request) => ({ request, ref: resolvePathId(request.id, state.groups) }));
|
|
331
|
+
}
|
|
332
|
+
// a satellite asked for twice is drawn once, in the place and look of the later request
|
|
333
|
+
const byRef = new Map();
|
|
334
|
+
for (const one of resolved) {
|
|
335
|
+
if (!one.ref)
|
|
336
|
+
continue;
|
|
337
|
+
byRef.delete(refKey(one.ref));
|
|
338
|
+
byRef.set(refKey(one.ref), { request: one.request, ref: one.ref });
|
|
339
|
+
}
|
|
340
|
+
const matched = [...byRef.values()];
|
|
341
|
+
const capped = capPaths(matched);
|
|
342
|
+
const wanted = [];
|
|
343
|
+
for (const one of capped.kept) {
|
|
344
|
+
const ref = cleanRef(one.ref);
|
|
345
|
+
if (!ref)
|
|
346
|
+
continue;
|
|
347
|
+
const look = styleOf(one.request, table);
|
|
348
|
+
wanted.push({ id: one.request.id, ref, name: look.name, style: look.style });
|
|
349
|
+
}
|
|
350
|
+
if (pathState.selectedOn) {
|
|
351
|
+
const own = [chosen, state.ridden].map(cleanRef);
|
|
352
|
+
const seen = new Set();
|
|
353
|
+
for (const ref of own) {
|
|
354
|
+
if (!ref || seen.has(refKey(ref)))
|
|
355
|
+
continue;
|
|
356
|
+
seen.add(refKey(ref));
|
|
357
|
+
const norad = find(ref)?.sets[ref.index]?.NORAD_CAT_ID;
|
|
358
|
+
wanted.push({ id: norad ?? refKey(ref), ref, name: "selected", style: table["selected"] });
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
const signature = wanted.map((w) => `${refKey(w.ref)}|${w.name}|${w.style.color}|${w.style.width}|${w.style.opacity}|${w.style.dash ? w.style.dash.join(",") : "-"}`).join(";");
|
|
362
|
+
let dirty = signature !== slotsSignature;
|
|
363
|
+
const old = new Map(slots.map((slot) => [slot.key, slot]));
|
|
364
|
+
let empty = 0;
|
|
365
|
+
const next = [];
|
|
366
|
+
for (const w of wanted) {
|
|
367
|
+
const key = `${refKey(w.ref)}|${w.name}`;
|
|
368
|
+
let slot = old.get(key);
|
|
369
|
+
const set = find(w.ref);
|
|
370
|
+
if (!slot) {
|
|
371
|
+
slot = { key, info: { id: w.id, ref: w.ref, style: w.name }, style: w.style, positions: new Float32Array(ORBIT_POINTS * 3), screen: new Float32Array(ORBIT_POINTS * 2), seen: new Uint8Array(ORBIT_POINTS), at: Number.NaN, wall: 0, empty: false };
|
|
372
|
+
dirty = true;
|
|
373
|
+
}
|
|
374
|
+
old.delete(key);
|
|
375
|
+
slot.info = { id: w.id, ref: w.ref, style: w.name };
|
|
376
|
+
slot.style = w.style;
|
|
377
|
+
if (Number.isNaN(slot.at) || (Math.abs(time - slot.at) > ORBIT_REFRESH_GAME_MS && wall - slot.wall > ORBIT_REFRESH_WALL_MS)) {
|
|
378
|
+
slot.at = time;
|
|
379
|
+
slot.wall = wall;
|
|
380
|
+
slot.positions.set(set.orbit(w.ref.index, time, ORBIT_POINTS).subarray(0, ORBIT_POINTS * 3));
|
|
381
|
+
slot.empty = slot.positions.every((v) => v === 0);
|
|
382
|
+
dirty = true;
|
|
383
|
+
}
|
|
384
|
+
if (slot.empty)
|
|
385
|
+
empty += 1;
|
|
386
|
+
next.push(slot);
|
|
387
|
+
}
|
|
388
|
+
slots = next;
|
|
389
|
+
if (dirty) {
|
|
390
|
+
slotsSignature = signature;
|
|
391
|
+
ribbons.set(slots.filter((slot) => !slot.empty).map((slot) => ({ positions: slot.positions, style: slot.style })));
|
|
392
|
+
}
|
|
393
|
+
const own = wanted.filter((w) => w.name === "selected" && pathState.selectedOn);
|
|
394
|
+
pathState.info = slots.filter((slot) => !slot.empty).map((slot) => ({ ...slot.info }));
|
|
395
|
+
pathState.dropped = capped.dropped;
|
|
396
|
+
pathState.unresolved = resolved.length - matched.length + empty;
|
|
397
|
+
pathDrawn = ribbons.mesh.visible;
|
|
398
|
+
state.drawn.pathsDrawn = ribbons.count;
|
|
399
|
+
state.drawn.pathDraws = pathDrawn ? 1 : 0;
|
|
400
|
+
state.drawn.selectedOpacity = own.length > 0 ? own[0].style.opacity : 0;
|
|
401
|
+
};
|
|
309
402
|
return {
|
|
310
|
-
update(time, speed, earthPx = 0) {
|
|
403
|
+
update(time, speed, earthPx = 0, size) {
|
|
311
404
|
const started = performance.now();
|
|
312
405
|
const tooFast = Math.abs(speed) > MAX_SATELLITE_SPEED;
|
|
313
406
|
const step = Math.min(60_000, Math.max(1000, Math.abs(speed) * 1000));
|
|
@@ -471,6 +564,8 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
471
564
|
line.loop.material.opacity = opacity;
|
|
472
565
|
}
|
|
473
566
|
}
|
|
567
|
+
if (size)
|
|
568
|
+
ribbons.frame(size.width, size.height, radius);
|
|
474
569
|
const chosen = state.selected;
|
|
475
570
|
const chosenGroup = chosen ? state.groups.get(chosen.group) : undefined;
|
|
476
571
|
const chosenDrawn = chosen !== null && chosenGroup !== undefined && satelliteEmphasis(chosen.group, chosenGroup.visible, state.focus).drawn;
|
|
@@ -483,25 +578,13 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
483
578
|
const over = state.modelOver !== null && state.modelOver.group === chosen.group && state.modelOver.index === chosen.index;
|
|
484
579
|
selectedPoints.visible = !over;
|
|
485
580
|
state.drawn.selectedRing = !over;
|
|
486
|
-
const key = `${chosen.group}:${chosen.index}`;
|
|
487
|
-
if (key !== selectedKey || (Math.abs(time - selectedAt) > ORBIT_REFRESH_GAME_MS && started - selectedWall > ORBIT_REFRESH_WALL_MS)) {
|
|
488
|
-
selectedKey = key;
|
|
489
|
-
selectedAt = time;
|
|
490
|
-
selectedWall = started;
|
|
491
|
-
selectedLine.positions.set(set.orbit(chosen.index, time, ORBIT_POINTS).subarray(0, ORBIT_POINTS * 3));
|
|
492
|
-
selectedLine.geometry.getAttribute("position").needsUpdate = true;
|
|
493
|
-
}
|
|
494
|
-
selectedLoop.visible = true;
|
|
495
581
|
selectedMaterial.uniforms["size"].value = 14 * ratio();
|
|
496
|
-
state.drawn.selectedOpacity = selectedLine.material.opacity;
|
|
497
582
|
}
|
|
498
583
|
else {
|
|
499
584
|
selectedPoints.visible = false;
|
|
500
585
|
state.drawn.selectedRing = false;
|
|
501
|
-
selectedLoop.visible = false;
|
|
502
|
-
selectedKey = "";
|
|
503
|
-
state.drawn.selectedOpacity = 0;
|
|
504
586
|
}
|
|
587
|
+
syncPaths(time, started, chosen !== null && set !== undefined && chosenDrawn ? chosen : null);
|
|
505
588
|
// The faint orbit: one path at a time, computed once from the elements already loaded, hidden while it is the chosen satellite's own orbit.
|
|
506
589
|
const hover = state.hover;
|
|
507
590
|
const hoverRef = hover.enabled && hover.fade > 0 ? hover.ref : null;
|
|
@@ -635,6 +718,41 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
635
718
|
}
|
|
636
719
|
return { x, y, visible: !behind && !hidden && edge === null, heightKm, edge, behind, occluded: hidden };
|
|
637
720
|
},
|
|
721
|
+
pathAt(x, y, camera, size, radius) {
|
|
722
|
+
if (!(radius > 0))
|
|
723
|
+
return null;
|
|
724
|
+
const c = camera.position;
|
|
725
|
+
const ortho = camera.isOrthographicCamera === true;
|
|
726
|
+
const centreDepth = ortho ? view.set(0, 0, 0).applyMatrix4(camera.matrixWorldInverse).z : 0;
|
|
727
|
+
const loops = [];
|
|
728
|
+
const drawn = slots.filter((slot) => !slot.empty);
|
|
729
|
+
// the topmost look is the last drawn, so on a tie the later slot wins: walk them in reverse
|
|
730
|
+
const order = drawn.map((slot, i) => ({ slot, i })).reverse();
|
|
731
|
+
for (const { slot } of order) {
|
|
732
|
+
for (let i = 0; i < ORBIT_POINTS; i += 1) {
|
|
733
|
+
world.set(slot.positions[i * 3], slot.positions[i * 3 + 1], slot.positions[i * 3 + 2]).applyMatrix4(scene.matrixWorld);
|
|
734
|
+
projected.copy(world).project(camera);
|
|
735
|
+
slot.screen[i * 2] = ((projected.x + 1) / 2) * size.width;
|
|
736
|
+
slot.screen[i * 2 + 1] = ((1 - projected.y) / 2) * size.height;
|
|
737
|
+
let seen = projected.z <= 1 && projected.z >= -1 && Number.isFinite(projected.x) && Number.isFinite(projected.y);
|
|
738
|
+
if (seen) {
|
|
739
|
+
if (ortho) {
|
|
740
|
+
view.copy(world).applyMatrix4(camera.matrixWorldInverse);
|
|
741
|
+
seen = !earthHidesDisc(view.x, view.y, view.z, centreDepth);
|
|
742
|
+
}
|
|
743
|
+
else
|
|
744
|
+
seen = !earthHides(c, world);
|
|
745
|
+
}
|
|
746
|
+
slot.seen[i] = seen ? 1 : 0;
|
|
747
|
+
}
|
|
748
|
+
loops.push({ xy: slot.screen, ok: slot.seen, count: ORBIT_POINTS });
|
|
749
|
+
}
|
|
750
|
+
const best = nearestLoop(x, y, loops, radius);
|
|
751
|
+
if (!best)
|
|
752
|
+
return null;
|
|
753
|
+
const slot = order[best.index].slot;
|
|
754
|
+
return { ...slot.info, ref: { ...slot.info.ref }, x: best.x, y: best.y, distancePx: best.distance };
|
|
755
|
+
},
|
|
638
756
|
place(camera, size) {
|
|
639
757
|
if (!selectedPoints.visible)
|
|
640
758
|
return null;
|
|
@@ -650,11 +768,10 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
650
768
|
for (const entry of drawn.values())
|
|
651
769
|
drop(entry);
|
|
652
770
|
drawn.clear();
|
|
653
|
-
scene.remove(selectedPoints,
|
|
771
|
+
scene.remove(selectedPoints, hoverLoop);
|
|
772
|
+
ribbons.dispose();
|
|
654
773
|
selectedGeometry.dispose();
|
|
655
774
|
selectedMaterial.dispose();
|
|
656
|
-
selectedLine.geometry.dispose();
|
|
657
|
-
selectedLine.material.dispose();
|
|
658
775
|
hoverLine.geometry.dispose();
|
|
659
776
|
hoverLine.material.dispose();
|
|
660
777
|
},
|
package/dist/space/scene.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ import type { PlaceView } from "../markers/places.ts";
|
|
|
13
13
|
import { type PlaceSpriteData } from "../markers/place-sprites.ts";
|
|
14
14
|
import type { CountryFrame } from "../country-names/geometry.ts";
|
|
15
15
|
import type { GeoPoint } from "../types.ts";
|
|
16
|
+
import type { PathHit } from "./paths.ts";
|
|
16
17
|
import { type SatelliteScreen, type SatelliteState } from "./satellite-layer.ts";
|
|
17
18
|
import { type BodyLabelState } from "../realistic/body-label.ts";
|
|
18
19
|
import { type MeteorState } from "../meteors/layer.ts";
|
|
@@ -253,6 +254,8 @@ export interface SpaceModel {
|
|
|
253
254
|
tall: number;
|
|
254
255
|
} | null;
|
|
255
256
|
};
|
|
257
|
+
/** The page's path under a point of the view (CSS pixels), within a radius (`paths`, and the chosen satellite's own orbit), if a draw has been made and one is there. */
|
|
258
|
+
pathAt: ((x: number, y: number, radius: number) => Omit<PathHit, "pointer"> | null) | null;
|
|
256
259
|
/** The satellite at a point of the view (CSS pixels), within a radius, if a draw has been made and one is there. */
|
|
257
260
|
pick: ((x: number, y: number, radius: number) => SatelliteRef | null) | null;
|
|
258
261
|
/** The followed satellite's model, when there is one drawn: where its middle is on the screen (CSS pixels), as of the last draw. */
|
package/dist/space/scene.js
CHANGED
|
@@ -138,6 +138,7 @@ export const newSpaceModel = () => ({
|
|
|
138
138
|
beam: newBeamState(),
|
|
139
139
|
route: newRouteState(),
|
|
140
140
|
pick: null,
|
|
141
|
+
pathAt: null,
|
|
141
142
|
placeSatellite: null,
|
|
142
143
|
followModel: null,
|
|
143
144
|
rideFrame: { share: null, seat: null, fresh: true, ms: 400, moving: false, share_: newEase(), seat_: newEase(), weight_: newEase(), groundKm: null },
|
|
@@ -572,9 +573,11 @@ export function createSpaceItem(model, deps) {
|
|
|
572
573
|
over = riding.target;
|
|
573
574
|
}
|
|
574
575
|
model.satellites.modelOver = over;
|
|
576
|
+
model.satellites.ridden = riding && typeof riding.target === "object" ? riding.target : null;
|
|
575
577
|
}
|
|
576
|
-
layer?.update(model.time, model.speed, model.drawn?.radiusPx ?? 0);
|
|
578
|
+
layer?.update(model.time, model.speed, model.drawn?.radiusPx ?? 0, size);
|
|
577
579
|
model.pick = layer ? (x, y, radius) => layer.pick(x, y, camera, size, radius) : null;
|
|
580
|
+
model.pathAt = layer ? (x, y, radius) => layer.pathAt(x, y, camera, size, radius) : null;
|
|
578
581
|
// 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
|
|
579
582
|
// body and looks at the Earth
|
|
580
583
|
let focus = model.focus;
|
|
@@ -1248,6 +1251,7 @@ export function createSpaceItem(model, deps) {
|
|
|
1248
1251
|
dropModel();
|
|
1249
1252
|
layer?.dispose();
|
|
1250
1253
|
model.pick = null;
|
|
1254
|
+
model.pathAt = null;
|
|
1251
1255
|
model.placeSatellite = null;
|
|
1252
1256
|
model.tiles = null;
|
|
1253
1257
|
tiles.dispose();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/chikyu-earth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.48.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",
|