@johnmorrisdotca/chikyu-earth 0.47.0 → 0.49.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 +9 -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 +91 -0
- package/dist/realistic/element-base.js +165 -4
- package/dist/satellites/source.js +1 -1
- package/dist/satellites/track.d.ts +5 -0
- package/dist/satellites/track.js +66 -5
- package/dist/satellites/types.d.ts +14 -0
- 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 +91 -0
- package/dist/space/element-base.js +168 -5
- 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 +31 -2
- package/dist/space/satellite-layer.js +159 -32
- package/dist/space/scene.d.ts +3 -0
- package/dist/space/scene.js +5 -1
- package/package.json +1 -1
|
@@ -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;
|
|
@@ -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,9 @@ export interface SatelliteState {
|
|
|
64
80
|
hoverPath: boolean;
|
|
65
81
|
hoverOpacity: number;
|
|
66
82
|
selectedOpacity: number;
|
|
83
|
+
pathsDrawn: number;
|
|
84
|
+
pathDraws: number;
|
|
85
|
+
estimated: number;
|
|
67
86
|
};
|
|
68
87
|
}
|
|
69
88
|
/**
|
|
@@ -97,7 +116,7 @@ export declare const newSatelliteState: () => SatelliteState;
|
|
|
97
116
|
/** The most orbits a group may draw all at once, one line each. */
|
|
98
117
|
export declare const MAX_ORBIT_GROUP = 40;
|
|
99
118
|
/** 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
|
|
119
|
+
export declare const SELECTED_PATH_OPACITY: number;
|
|
101
120
|
/** The orbit under the pointer, before it fades. A page may set another with `--chikyu-hover-path-opacity`. */
|
|
102
121
|
export declare const HOVER_PATH_OPACITY: number;
|
|
103
122
|
/** How long the faint orbit takes to go after the pointer leaves, in milliseconds. Reduced motion takes it away at once. */
|
|
@@ -203,6 +222,8 @@ export interface SatelliteScreen {
|
|
|
203
222
|
behind: boolean;
|
|
204
223
|
/** The Earth hides the satellite: the line from the camera meets the globe before the satellite. False at the limb, in front, and when the satellite is only behind the camera. */
|
|
205
224
|
occluded: boolean;
|
|
225
|
+
/** Its place is an estimate (`estimate-far`): the moment shown is beyond `maxAgeDays` from its elements. */
|
|
226
|
+
estimated: boolean;
|
|
206
227
|
}
|
|
207
228
|
export interface SatelliteLayer {
|
|
208
229
|
/** Where one satellite of a shown group is on the screen as of the last update, or `null` when its group is not shown or it is not placed (its elements are too old). A satellite outside the picture or behind the camera is still returned, with `visible` false. */
|
|
@@ -211,7 +232,10 @@ export interface SatelliteLayer {
|
|
|
211
232
|
height: number;
|
|
212
233
|
}): SatelliteScreen | null;
|
|
213
234
|
/** 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
|
|
235
|
+
update(time: number, speed: number, earthPx?: number, size?: {
|
|
236
|
+
width: number;
|
|
237
|
+
height: number;
|
|
238
|
+
}): void;
|
|
215
239
|
/** Set the dot size from the Earth's radius on the screen for this frame, after the camera is known. */
|
|
216
240
|
resize(earthPx: number): void;
|
|
217
241
|
/** The satellite nearest to a point of the view (CSS pixels) within `radius`, if one is in front of the Earth. */
|
|
@@ -219,6 +243,11 @@ export interface SatelliteLayer {
|
|
|
219
243
|
width: number;
|
|
220
244
|
height: number;
|
|
221
245
|
}, radius: number): SatelliteRef | null;
|
|
246
|
+
/** 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. */
|
|
247
|
+
pathAt(x: number, y: number, camera: THREE.Camera, size: {
|
|
248
|
+
width: number;
|
|
249
|
+
height: number;
|
|
250
|
+
}, radius: number): Omit<PathHit, "pointer"> | null;
|
|
222
251
|
/** Where the chosen satellite is in the view, if it is. */
|
|
223
252
|
place(camera: THREE.Camera, size: {
|
|
224
253
|
width: number;
|