@johnmorrisdotca/chikyu-earth 0.46.6 → 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 +14 -0
- package/README.md +3 -3
- package/dist/beam/layer.d.ts +1 -1
- package/dist/markers/place-layer.d.ts +4 -0
- package/dist/markers/place-layer.js +20 -6
- package/dist/place/index.d.ts +230 -0
- package/dist/place/index.js +183 -0
- package/dist/place/land.d.ts +30 -0
- package/dist/place/land.js +177 -0
- package/dist/place/water.d.ts +15 -0
- package/dist/place/water.js +63 -0
- package/dist/realistic/earth.d.ts +12 -1
- package/dist/realistic/earth.js +17 -1
- package/dist/realistic/element-base.d.ts +92 -0
- package/dist/realistic/element-base.js +179 -4
- 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 +168 -2
- package/dist/space/element-base.js +402 -8
- package/dist/space/ephemeris.d.ts +1 -1
- package/dist/space/ephemeris.js +4 -2
- package/dist/space/follow.d.ts +36 -0
- package/dist/space/follow.js +46 -0
- package/dist/space/index.d.ts +1 -1
- package/dist/space/index.js +1 -0
- 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/ride.d.ts +3 -2
- package/dist/space/ride.js +6 -4
- package/dist/space/satellite-hover.d.ts +47 -0
- package/dist/space/satellite-hover.js +183 -0
- package/dist/space/satellite-layer.d.ts +83 -2
- package/dist/space/satellite-layer.js +231 -52
- package/dist/space/satellite-model.d.ts +2 -1
- package/dist/space/satellite-model.js +4 -3
- package/dist/space/scene.d.ts +41 -0
- package/dist/space/scene.js +82 -13
- package/package.json +6 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Keep a share between 0 and 1. Anything that is not a number is 0. */
|
|
2
|
+
export declare const clampFollow: (value: number) => number;
|
|
3
|
+
/**
|
|
4
|
+
* The sidereal angle the camera uses, in degrees. `anchor` is the Earth's turn when the camera was set, `spin` is the turn now.
|
|
5
|
+
*
|
|
6
|
+
* @param anchor - The Earth's turn, in degrees, remembered for the space camera.
|
|
7
|
+
* @param spin - The Earth's turn now, in degrees.
|
|
8
|
+
* @param follow - 0 holds the stars, 1 turns with the Earth.
|
|
9
|
+
* @returns The angle added to the place the camera looks at.
|
|
10
|
+
*/
|
|
11
|
+
export declare const followSpin: (anchor: number, spin: number, follow: number) => number;
|
|
12
|
+
/**
|
|
13
|
+
* The longitude, in degrees, under the middle of the view. The same place before and after a change of `follow`.
|
|
14
|
+
*
|
|
15
|
+
* @param anchor - The Earth's turn remembered for the camera.
|
|
16
|
+
* @param spin - The Earth's turn now.
|
|
17
|
+
* @param follow - The share of that turn the camera takes.
|
|
18
|
+
* @param centreLon - The home longitude.
|
|
19
|
+
* @param yaw - The view's yaw, in degrees.
|
|
20
|
+
* @returns Longitude under the middle, in degrees.
|
|
21
|
+
*/
|
|
22
|
+
export declare const groundLongitude: (anchor: number, spin: number, follow: number, centreLon: number, yaw: number) => number;
|
|
23
|
+
/**
|
|
24
|
+
* Move the camera's anchor, and the yaw when the share becomes 1, so the longitude under the middle stays put.
|
|
25
|
+
*
|
|
26
|
+
* @param anchor - The anchor before the change.
|
|
27
|
+
* @param spin - The Earth's turn now.
|
|
28
|
+
* @param from - The share before the change.
|
|
29
|
+
* @param to - The share after the change.
|
|
30
|
+
* @param yaw - The view's yaw before the change.
|
|
31
|
+
* @returns The anchor and yaw to use with `to`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function retargetFollow(anchor: number, spin: number, from: number, to: number, yaw: number): {
|
|
34
|
+
anchor: number;
|
|
35
|
+
yaw: number;
|
|
36
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// How much of the Earth's turn the space camera takes. 0 holds the stars (the camera stays where it was set). 1 turns with the Earth.
|
|
2
|
+
// A change keeps the longitude under the middle of the view: the anchor (or, at 1, the yaw) is moved so the aim does not jump.
|
|
3
|
+
/** Keep a share between 0 and 1. Anything that is not a number is 0. */
|
|
4
|
+
export const clampFollow = (value) => (Number.isFinite(value) ? Math.min(1, Math.max(0, value)) : 0);
|
|
5
|
+
/**
|
|
6
|
+
* The sidereal angle the camera uses, in degrees. `anchor` is the Earth's turn when the camera was set, `spin` is the turn now.
|
|
7
|
+
*
|
|
8
|
+
* @param anchor - The Earth's turn, in degrees, remembered for the space camera.
|
|
9
|
+
* @param spin - The Earth's turn now, in degrees.
|
|
10
|
+
* @param follow - 0 holds the stars, 1 turns with the Earth.
|
|
11
|
+
* @returns The angle added to the place the camera looks at.
|
|
12
|
+
*/
|
|
13
|
+
export const followSpin = (anchor, spin, follow) => {
|
|
14
|
+
const share = clampFollow(follow);
|
|
15
|
+
return anchor + share * (spin - anchor);
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* The longitude, in degrees, under the middle of the view. The same place before and after a change of `follow`.
|
|
19
|
+
*
|
|
20
|
+
* @param anchor - The Earth's turn remembered for the camera.
|
|
21
|
+
* @param spin - The Earth's turn now.
|
|
22
|
+
* @param follow - The share of that turn the camera takes.
|
|
23
|
+
* @param centreLon - The home longitude.
|
|
24
|
+
* @param yaw - The view's yaw, in degrees.
|
|
25
|
+
* @returns Longitude under the middle, in degrees.
|
|
26
|
+
*/
|
|
27
|
+
export const groundLongitude = (anchor, spin, follow, centreLon, yaw) => followSpin(anchor, spin, follow) + centreLon - yaw - spin;
|
|
28
|
+
const wrap = (deg) => ((((deg + 180) % 360) + 360) % 360) - 180;
|
|
29
|
+
/**
|
|
30
|
+
* Move the camera's anchor, and the yaw when the share becomes 1, so the longitude under the middle stays put.
|
|
31
|
+
*
|
|
32
|
+
* @param anchor - The anchor before the change.
|
|
33
|
+
* @param spin - The Earth's turn now.
|
|
34
|
+
* @param from - The share before the change.
|
|
35
|
+
* @param to - The share after the change.
|
|
36
|
+
* @param yaw - The view's yaw before the change.
|
|
37
|
+
* @returns The anchor and yaw to use with `to`.
|
|
38
|
+
*/
|
|
39
|
+
export function retargetFollow(anchor, spin, from, to, yaw) {
|
|
40
|
+
const next = clampFollow(to);
|
|
41
|
+
const oldSpin = followSpin(anchor, spin, from);
|
|
42
|
+
if (next >= 1)
|
|
43
|
+
return { anchor: spin, yaw: wrap(yaw + (spin - oldSpin)) };
|
|
44
|
+
const nextAnchor = (oldSpin - next * spin) / (1 - next);
|
|
45
|
+
return { anchor: nextAnchor, yaw };
|
|
46
|
+
}
|
package/dist/space/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, orbitP
|
|
|
2
2
|
export { compress, MOON_COMPRESSED, placeAround, placeMoon, placeSun, RADIUS, SUN_COMPRESSED, truePosition, type ScaleMode } from "./scale.ts";
|
|
3
3
|
export { fitDistance, plainPainter, type BodyDrawing, type BodyMoon, type BodyPainter, type BodyView, type PaintContext, type SatellitePainter } from "./scene.ts";
|
|
4
4
|
export { faceOffset, OUTSIDE_KM, outsidePose, RIDE_FACES, RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees, type RideFace, type RideInput, type RideLook, type RidePose, type RideModelSize, type RideViewpoint } from "./ride.ts";
|
|
5
|
-
export type
|
|
5
|
+
export { earthHides, type SatelliteScreen } from "./satellite-layer.ts";
|
|
6
6
|
export { ABOVE_MODEL_KM, ABOVE_MODEL_SHARE, aboveAxes, aboveModelShare, MODEL_FADE_FROM_KM, MODEL_FADE_TO_KM, MODEL_HANDOVER_PX, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.ts";
|
|
7
7
|
export { genericSatellite, satelliteKind, type SatelliteKind } from "./generic-satellite.ts";
|
|
8
8
|
export { BEAM_ATTRIBUTES, BEAM_COLOUR, BEAM_ELEVATION, beamCells, footprintAngle, footprintKm, readBeam, type BeamCells, type BeamOptions } from "../beam/geometry.ts";
|
package/dist/space/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, orbitP
|
|
|
4
4
|
export { compress, MOON_COMPRESSED, placeAround, placeMoon, placeSun, RADIUS, SUN_COMPRESSED, truePosition } from "./scale.js";
|
|
5
5
|
export { fitDistance, plainPainter } from "./scene.js";
|
|
6
6
|
export { faceOffset, OUTSIDE_KM, outsidePose, RIDE_FACES, RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees } from "./ride.js";
|
|
7
|
+
export { earthHides } from "./satellite-layer.js";
|
|
7
8
|
export { ABOVE_MODEL_KM, ABOVE_MODEL_SHARE, aboveAxes, aboveModelShare, MODEL_FADE_FROM_KM, MODEL_FADE_TO_KM, MODEL_HANDOVER_PX, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
|
|
8
9
|
export { genericSatellite, satelliteKind } from "./generic-satellite.js";
|
|
9
10
|
export { BEAM_ATTRIBUTES, BEAM_COLOUR, BEAM_ELEVATION, beamCells, footprintAngle, footprintKm, readBeam } from "../beam/geometry.js";
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { SatelliteRef } from "../satellites/types.ts";
|
|
2
|
+
import type { SatelliteState } from "./satellite-layer.ts";
|
|
3
|
+
import { MAX_PATHS, type PathHit, type PathRequest, type PathStyle } from "./paths.ts";
|
|
4
|
+
/** The attributes the paths add to an element. */
|
|
5
|
+
export declare const PATH_ATTRIBUTES: readonly ["selected-path", "path-hit"];
|
|
6
|
+
/** What the element hands the paths. */
|
|
7
|
+
export interface PathHost {
|
|
8
|
+
element: HTMLElement;
|
|
9
|
+
state: SatelliteState;
|
|
10
|
+
/** Ask for a draw. */
|
|
11
|
+
request(): void;
|
|
12
|
+
/** The path under a point of the view within a radius, from the last draw. */
|
|
13
|
+
pathAt(x: number, y: number, radius: number): Omit<PathHit, "pointer"> | null;
|
|
14
|
+
/** The satellite whose dot is under a point, which a path never takes a press from. */
|
|
15
|
+
pick(x: number, y: number): SatelliteRef | null;
|
|
16
|
+
/** The view is a ride from a satellite: the hit test is off there unless `path-hit` is set. */
|
|
17
|
+
riding(): boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface PathStats {
|
|
20
|
+
/** Paths the page asked for. */
|
|
21
|
+
requested: number;
|
|
22
|
+
/** Paths in the one draw (the page's and the chosen satellite's own), as of the last draw. */
|
|
23
|
+
drawn: number;
|
|
24
|
+
/** Asked for beyond {@link MAX_PATHS}, so left out (the earliest). */
|
|
25
|
+
dropped: number;
|
|
26
|
+
/** Asked for but matching no satellite, or with no place. */
|
|
27
|
+
unresolved: number;
|
|
28
|
+
/** The chosen satellite's own orbit is drawn. */
|
|
29
|
+
selectedDrawn: boolean;
|
|
30
|
+
/** Draw calls the paths took at the last draw: 0 or 1. */
|
|
31
|
+
draws: number;
|
|
32
|
+
/** The path the mouse is on, by the id given, or `null`. */
|
|
33
|
+
hover: number | string | null;
|
|
34
|
+
/** `chikyu-path-click` events sent so far. */
|
|
35
|
+
hits: number;
|
|
36
|
+
}
|
|
37
|
+
export interface PathControls {
|
|
38
|
+
setPaths(list: readonly PathRequest[]): void;
|
|
39
|
+
readonly paths: PathRequest[];
|
|
40
|
+
setStyles(table: Readonly<Record<string, Partial<PathStyle> | null>>, replace?: boolean): void;
|
|
41
|
+
readonly styles: Record<string, PathStyle>;
|
|
42
|
+
/** Read `selected-path` and `path-hit` again. */
|
|
43
|
+
sync(): void;
|
|
44
|
+
readonly selectedOn: boolean;
|
|
45
|
+
readonly hit: number;
|
|
46
|
+
at(x: number, y: number, radiusPx?: number, pointer?: PathHit["pointer"]): PathHit | null;
|
|
47
|
+
/** A press that was not a drag, at a point of the element: sends `chikyu-path-click` and answers `true` when a path was under it and no dot was. */
|
|
48
|
+
press(x: number, y: number, pointer: PathHit["pointer"]): boolean;
|
|
49
|
+
stats(): PathStats;
|
|
50
|
+
stop(): void;
|
|
51
|
+
}
|
|
52
|
+
export declare const pointerOf: (event: PointerEvent) => PathHit["pointer"];
|
|
53
|
+
export declare function bindPaths(host: PathHost): PathControls;
|
|
54
|
+
export { MAX_PATHS };
|
|
55
|
+
/** The paths' numbers before the element has bound them. */
|
|
56
|
+
export declare const emptyPathStats: () => PathStats;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { capPaths, hitRadius, MAX_PATHS, readPathHit, styleTable } from "./paths.js";
|
|
2
|
+
/** The attributes the paths add to an element. */
|
|
3
|
+
export const PATH_ATTRIBUTES = ["selected-path", "path-hit"];
|
|
4
|
+
export const pointerOf = (event) => (event.pointerType === "touch" ? "touch" : event.pointerType === "pen" ? "pen" : "mouse");
|
|
5
|
+
export function bindPaths(host) {
|
|
6
|
+
const { element, state } = host;
|
|
7
|
+
let hits = 0;
|
|
8
|
+
let hovered = null;
|
|
9
|
+
let queued = false;
|
|
10
|
+
let point = null;
|
|
11
|
+
const radiusFor = (pointer) => {
|
|
12
|
+
if (host.riding() && !element.hasAttribute("path-hit"))
|
|
13
|
+
return 0;
|
|
14
|
+
return hitRadius(readPathHit(element.getAttribute("path-hit")), pointer);
|
|
15
|
+
};
|
|
16
|
+
const at = (x, y, radiusPx, pointer = "mouse") => {
|
|
17
|
+
const radius = radiusPx === undefined ? radiusFor(pointer) : Math.max(0, Math.min(radiusPx, 200));
|
|
18
|
+
const found = host.pathAt(x, y, radius);
|
|
19
|
+
return found ? { ...found, pointer } : null;
|
|
20
|
+
};
|
|
21
|
+
const detail = (hit) => ({ ...hit, ref: { ...hit.ref } });
|
|
22
|
+
const sameHit = (a, b) => (a === null && b === null) || (a !== null && b !== null && a.id === b.id && a.style === b.style && a.ref.group === b.ref.group && a.ref.index === b.ref.index);
|
|
23
|
+
const apply = () => {
|
|
24
|
+
queued = false;
|
|
25
|
+
if (!point)
|
|
26
|
+
return;
|
|
27
|
+
const dot = host.pick(point.x, point.y);
|
|
28
|
+
const hit = dot ? null : at(point.x, point.y, undefined, "mouse");
|
|
29
|
+
if (sameHit(hit, hovered)) {
|
|
30
|
+
hovered = hit;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
hovered = hit;
|
|
34
|
+
element.dispatchEvent(new CustomEvent("chikyu-path-hover", { detail: hit ? detail(hit) : null, bubbles: true, composed: true }));
|
|
35
|
+
};
|
|
36
|
+
const move = (event) => {
|
|
37
|
+
if (event.pointerType === "touch" || event.buttons !== 0)
|
|
38
|
+
return;
|
|
39
|
+
if (state.paths.info.length === 0 && hovered === null)
|
|
40
|
+
return;
|
|
41
|
+
const rect = element.getBoundingClientRect();
|
|
42
|
+
point = { x: event.clientX - rect.left, y: event.clientY - rect.top };
|
|
43
|
+
if (queued)
|
|
44
|
+
return;
|
|
45
|
+
queued = true;
|
|
46
|
+
element.ownerDocument.defaultView?.requestAnimationFrame(apply);
|
|
47
|
+
};
|
|
48
|
+
const leave = () => {
|
|
49
|
+
point = null;
|
|
50
|
+
if (hovered === null)
|
|
51
|
+
return;
|
|
52
|
+
hovered = null;
|
|
53
|
+
element.dispatchEvent(new CustomEvent("chikyu-path-hover", { detail: null, bubbles: true, composed: true }));
|
|
54
|
+
};
|
|
55
|
+
element.addEventListener("pointermove", move);
|
|
56
|
+
element.addEventListener("pointerleave", leave);
|
|
57
|
+
element.addEventListener("pointercancel", leave);
|
|
58
|
+
return {
|
|
59
|
+
setPaths(list) {
|
|
60
|
+
state.paths.requests = list.filter((one) => one && (typeof one.id === "number" || typeof one.id === "string")).map((one) => ({ id: one.id, ...(one.style === undefined ? {} : { style: typeof one.style === "string" ? one.style : { ...one.style } }) }));
|
|
61
|
+
state.paths.version += 1;
|
|
62
|
+
host.request();
|
|
63
|
+
},
|
|
64
|
+
get paths() {
|
|
65
|
+
return capPaths(state.paths.requests).kept.map((one) => ({ ...one }));
|
|
66
|
+
},
|
|
67
|
+
setStyles(table, replace = false) {
|
|
68
|
+
const next = replace ? {} : { ...state.paths.overrides };
|
|
69
|
+
for (const [name, style] of Object.entries(table)) {
|
|
70
|
+
if (style === null)
|
|
71
|
+
delete next[name];
|
|
72
|
+
else
|
|
73
|
+
next[name] = { ...style };
|
|
74
|
+
}
|
|
75
|
+
state.paths.overrides = next;
|
|
76
|
+
state.paths.version += 1;
|
|
77
|
+
host.request();
|
|
78
|
+
},
|
|
79
|
+
get styles() {
|
|
80
|
+
return styleTable(state.paths.overrides);
|
|
81
|
+
},
|
|
82
|
+
sync() {
|
|
83
|
+
const on = element.getAttribute("selected-path") !== "off";
|
|
84
|
+
if (on === state.paths.selectedOn)
|
|
85
|
+
return;
|
|
86
|
+
state.paths.selectedOn = on;
|
|
87
|
+
state.paths.version += 1;
|
|
88
|
+
host.request();
|
|
89
|
+
},
|
|
90
|
+
get selectedOn() {
|
|
91
|
+
return state.paths.selectedOn;
|
|
92
|
+
},
|
|
93
|
+
get hit() {
|
|
94
|
+
return readPathHit(element.getAttribute("path-hit"));
|
|
95
|
+
},
|
|
96
|
+
at,
|
|
97
|
+
press(x, y, pointer) {
|
|
98
|
+
if (host.pick(x, y))
|
|
99
|
+
return false;
|
|
100
|
+
const hit = at(x, y, undefined, pointer);
|
|
101
|
+
if (!hit)
|
|
102
|
+
return false;
|
|
103
|
+
hits += 1;
|
|
104
|
+
element.dispatchEvent(new CustomEvent("chikyu-path-click", { detail: detail(hit), bubbles: true, composed: true }));
|
|
105
|
+
return true;
|
|
106
|
+
},
|
|
107
|
+
stats() {
|
|
108
|
+
const info = state.paths;
|
|
109
|
+
return { requested: info.requests.length, drawn: state.drawn.pathsDrawn, dropped: info.dropped, unresolved: info.unresolved, selectedDrawn: state.drawn.selectedOpacity > 0, draws: state.drawn.pathDraws, hover: hovered ? hovered.id : null, hits };
|
|
110
|
+
},
|
|
111
|
+
stop() {
|
|
112
|
+
element.removeEventListener("pointermove", move);
|
|
113
|
+
element.removeEventListener("pointerleave", leave);
|
|
114
|
+
element.removeEventListener("pointercancel", leave);
|
|
115
|
+
hovered = null;
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
export { MAX_PATHS };
|
|
120
|
+
/** The paths' numbers before the element has bound them. */
|
|
121
|
+
export const emptyPathStats = () => ({ requested: 0, drawn: 0, dropped: 0, unresolved: 0, selectedDrawn: false, draws: 0, hover: null, hits: 0 });
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type * as THREE from "three";
|
|
2
|
+
import type { ThreeParts } from "../realistic/textures.ts";
|
|
3
|
+
import { type PathStyle } from "./paths.ts";
|
|
4
|
+
type Three = ThreeParts;
|
|
5
|
+
/** Points on each orbit loop. The same as the chosen orbit has always had. */
|
|
6
|
+
export declare const PATH_POINTS = 120;
|
|
7
|
+
/** The paths the mesh can hold: those of the page and the chosen satellite's own. */
|
|
8
|
+
export declare const PATH_SLOTS: number;
|
|
9
|
+
/** What one slot is told: the loop's points (3 numbers each, {@link PATH_POINTS} of them) and its look. */
|
|
10
|
+
export interface RibbonPath {
|
|
11
|
+
positions: Float32Array;
|
|
12
|
+
style: PathStyle;
|
|
13
|
+
}
|
|
14
|
+
export interface PathRibbons {
|
|
15
|
+
/** Write the paths into the buffers, none for an empty list. Costs nothing on the GPU until the next draw, and nothing is drawn while there are no paths. */
|
|
16
|
+
set(paths: readonly RibbonPath[]): void;
|
|
17
|
+
/** The size of the picture in CSS pixels and the Earth's radius on it, which a dash is measured against. */
|
|
18
|
+
frame(width: number, height: number, earthPx: number): void;
|
|
19
|
+
/** How many paths are in the buffers. */
|
|
20
|
+
readonly count: number;
|
|
21
|
+
readonly mesh: THREE.Mesh;
|
|
22
|
+
dispose(): void;
|
|
23
|
+
}
|
|
24
|
+
export declare function createPathRibbons(three: Three, scene: THREE.Object3D): PathRibbons;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { MAX_PATHS } from "./paths.js";
|
|
2
|
+
/** Points on each orbit loop. The same as the chosen orbit has always had. */
|
|
3
|
+
export const PATH_POINTS = 120;
|
|
4
|
+
/** The paths the mesh can hold: those of the page and the chosen satellite's own. */
|
|
5
|
+
export const PATH_SLOTS = MAX_PATHS + 1;
|
|
6
|
+
const VERT = /* glsl */ `
|
|
7
|
+
uniform vec2 res;
|
|
8
|
+
uniform float dashScale;
|
|
9
|
+
attribute vec3 other;
|
|
10
|
+
attribute vec2 corner;
|
|
11
|
+
attribute vec4 ink;
|
|
12
|
+
attribute vec4 look;
|
|
13
|
+
attribute float span;
|
|
14
|
+
varying vec4 vInk;
|
|
15
|
+
varying float vEdge;
|
|
16
|
+
varying float vHalf;
|
|
17
|
+
varying float vAlong;
|
|
18
|
+
varying vec2 vDash;
|
|
19
|
+
void main() {
|
|
20
|
+
mat4 m = projectionMatrix * modelViewMatrix;
|
|
21
|
+
vec4 a = m * vec4(position, 1.0);
|
|
22
|
+
vec4 b = m * vec4(other, 1.0);
|
|
23
|
+
float near = 0.01;
|
|
24
|
+
if (a.w < near && b.w < near) {
|
|
25
|
+
gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (a.w < near) a = mix(a, b, (near - a.w) / (b.w - a.w));
|
|
29
|
+
else if (b.w < near) b = mix(b, a, (near - b.w) / (a.w - b.w));
|
|
30
|
+
vec2 hres = res * 0.5;
|
|
31
|
+
vec2 sa = a.xy / a.w * hres;
|
|
32
|
+
vec2 sb = b.xy / b.w * hres;
|
|
33
|
+
vec2 d = sb - sa;
|
|
34
|
+
float len = length(d);
|
|
35
|
+
vec2 dir = len > 1e-4 ? d / len : vec2(1.0, 0.0);
|
|
36
|
+
vec2 normal = vec2(-dir.y, dir.x);
|
|
37
|
+
bool atB = corner.x > 0.5;
|
|
38
|
+
vec4 p = atB ? b : a;
|
|
39
|
+
vec2 s = atB ? sb : sa;
|
|
40
|
+
float reach = look.x * 0.5 + 0.5;
|
|
41
|
+
vec2 at = s + normal * corner.y * reach;
|
|
42
|
+
gl_Position = vec4(at / hres * p.w, p.z, p.w);
|
|
43
|
+
vInk = ink;
|
|
44
|
+
vEdge = corner.y * reach;
|
|
45
|
+
vHalf = look.x * 0.5;
|
|
46
|
+
vAlong = (look.w + (atB ? span : 0.0)) * dashScale;
|
|
47
|
+
vDash = look.yz;
|
|
48
|
+
}`;
|
|
49
|
+
const FRAG = /* glsl */ `
|
|
50
|
+
varying vec4 vInk;
|
|
51
|
+
varying float vEdge;
|
|
52
|
+
varying float vHalf;
|
|
53
|
+
varying float vAlong;
|
|
54
|
+
varying vec2 vDash;
|
|
55
|
+
void main() {
|
|
56
|
+
float cover = clamp(vHalf + 0.5 - abs(vEdge), 0.0, 1.0);
|
|
57
|
+
if (vDash.x > 0.0) {
|
|
58
|
+
float period = vDash.x + vDash.y;
|
|
59
|
+
float m = mod(vAlong, period);
|
|
60
|
+
float inside = m < vDash.x ? min(m, vDash.x - m) : -min(m - vDash.x, period - m);
|
|
61
|
+
cover *= clamp(inside + 0.5, 0.0, 1.0);
|
|
62
|
+
}
|
|
63
|
+
if (cover <= 0.0) discard;
|
|
64
|
+
gl_FragColor = vec4(vInk.rgb, vInk.a * cover);
|
|
65
|
+
#include <colorspace_fragment>
|
|
66
|
+
}`;
|
|
67
|
+
export function createPathRibbons(three, scene) {
|
|
68
|
+
// The quads face either way (a segment's left and right turn with its direction on the screen), so neither side is culled.
|
|
69
|
+
const verts = PATH_SLOTS * PATH_POINTS * 4;
|
|
70
|
+
const position = new Float32Array(verts * 3);
|
|
71
|
+
const other = new Float32Array(verts * 3);
|
|
72
|
+
const corner = new Float32Array(verts * 2);
|
|
73
|
+
const ink = new Float32Array(verts * 4);
|
|
74
|
+
const look = new Float32Array(verts * 4);
|
|
75
|
+
const span = new Float32Array(verts);
|
|
76
|
+
const index = new Uint16Array(PATH_SLOTS * PATH_POINTS * 6);
|
|
77
|
+
for (let q = 0; q < PATH_SLOTS * PATH_POINTS; q += 1) {
|
|
78
|
+
const v = q * 4;
|
|
79
|
+
// the quad's corners: start-left, start-right, end-left, end-right
|
|
80
|
+
corner.set([0, -1, 0, 1, 1, -1, 1, 1], v * 2);
|
|
81
|
+
index.set([v, v + 1, v + 2, v + 2, v + 1, v + 3], q * 6);
|
|
82
|
+
}
|
|
83
|
+
const geometry = new three.BufferGeometry();
|
|
84
|
+
const attributes = {
|
|
85
|
+
position: new three.BufferAttribute(position, 3),
|
|
86
|
+
other: new three.BufferAttribute(other, 3),
|
|
87
|
+
ink: new three.BufferAttribute(ink, 4),
|
|
88
|
+
look: new three.BufferAttribute(look, 4),
|
|
89
|
+
span: new three.BufferAttribute(span, 1),
|
|
90
|
+
};
|
|
91
|
+
for (const [name, attribute] of Object.entries(attributes))
|
|
92
|
+
geometry.setAttribute(name, attribute);
|
|
93
|
+
geometry.setAttribute("corner", new three.BufferAttribute(corner, 2));
|
|
94
|
+
geometry.setIndex(new three.BufferAttribute(index, 1));
|
|
95
|
+
geometry.setDrawRange(0, 0);
|
|
96
|
+
const material = new three.ShaderMaterial({ vertexShader: VERT, fragmentShader: FRAG, uniforms: { res: { value: [1, 1] }, dashScale: { value: 1 } }, transparent: true, depthWrite: false, side: three.DoubleSide });
|
|
97
|
+
const mesh = new three.Mesh(geometry, material);
|
|
98
|
+
mesh.name = "paths";
|
|
99
|
+
mesh.frustumCulled = false;
|
|
100
|
+
mesh.renderOrder = 4;
|
|
101
|
+
mesh.visible = false;
|
|
102
|
+
scene.add(mesh);
|
|
103
|
+
const colour = new three.Color();
|
|
104
|
+
let count = 0;
|
|
105
|
+
return {
|
|
106
|
+
set(paths) {
|
|
107
|
+
count = Math.min(PATH_SLOTS, paths.length);
|
|
108
|
+
for (let p = 0; p < count; p += 1) {
|
|
109
|
+
const { positions, style } = paths[p];
|
|
110
|
+
colour.set(style.color);
|
|
111
|
+
// the arc length at each point, in Earth radii, for the dashes
|
|
112
|
+
let along = 0;
|
|
113
|
+
for (let i = 0; i < PATH_POINTS; i += 1) {
|
|
114
|
+
const j = (i + 1) % PATH_POINTS;
|
|
115
|
+
const ax = positions[i * 3];
|
|
116
|
+
const ay = positions[i * 3 + 1];
|
|
117
|
+
const az = positions[i * 3 + 2];
|
|
118
|
+
const bx = positions[j * 3];
|
|
119
|
+
const by = positions[j * 3 + 1];
|
|
120
|
+
const bz = positions[j * 3 + 2];
|
|
121
|
+
const length = Math.hypot(bx - ax, by - ay, bz - az);
|
|
122
|
+
const q = p * PATH_POINTS + i;
|
|
123
|
+
for (let k = 0; k < 4; k += 1) {
|
|
124
|
+
const v = q * 4 + k;
|
|
125
|
+
position[v * 3] = ax;
|
|
126
|
+
position[v * 3 + 1] = ay;
|
|
127
|
+
position[v * 3 + 2] = az;
|
|
128
|
+
other[v * 3] = bx;
|
|
129
|
+
other[v * 3 + 1] = by;
|
|
130
|
+
other[v * 3 + 2] = bz;
|
|
131
|
+
ink[v * 4] = colour.r;
|
|
132
|
+
ink[v * 4 + 1] = colour.g;
|
|
133
|
+
ink[v * 4 + 2] = colour.b;
|
|
134
|
+
ink[v * 4 + 3] = style.opacity;
|
|
135
|
+
look[v * 4] = style.width;
|
|
136
|
+
look[v * 4 + 1] = style.dash ? style.dash[0] : 0;
|
|
137
|
+
look[v * 4 + 2] = style.dash ? style.dash[1] : 0;
|
|
138
|
+
look[v * 4 + 3] = along;
|
|
139
|
+
span[v] = length;
|
|
140
|
+
}
|
|
141
|
+
along += length;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
for (const attribute of Object.values(attributes))
|
|
145
|
+
attribute.needsUpdate = true;
|
|
146
|
+
geometry.setDrawRange(0, count * PATH_POINTS * 6);
|
|
147
|
+
mesh.visible = count > 0;
|
|
148
|
+
},
|
|
149
|
+
frame(width, height, earthPx) {
|
|
150
|
+
const value = material.uniforms["res"].value;
|
|
151
|
+
value[0] = Math.max(1, width);
|
|
152
|
+
value[1] = Math.max(1, height);
|
|
153
|
+
material.uniforms["dashScale"].value = Math.max(1, earthPx);
|
|
154
|
+
},
|
|
155
|
+
get count() {
|
|
156
|
+
return count;
|
|
157
|
+
},
|
|
158
|
+
mesh,
|
|
159
|
+
dispose() {
|
|
160
|
+
scene.remove(mesh);
|
|
161
|
+
geometry.dispose();
|
|
162
|
+
material.dispose();
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
@@ -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;
|