@johnmorrisdotca/chikyu-earth 0.43.0 → 0.46.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 +16 -0
- package/NOTICE.md +15 -5
- package/README.md +4 -4
- package/dist/door/map.js +5 -1
- package/dist/element.d.ts +30 -0
- package/dist/element.js +82 -2
- package/dist/markers/here-city-host.d.ts +3 -1
- package/dist/markers/here-city-host.js +67 -5
- package/dist/markers/here-city.d.ts +94 -1
- package/dist/markers/here-city.js +69 -1
- package/dist/markers/index.d.ts +1 -1
- package/dist/markers/index.js +1 -1
- package/dist/realistic/element-base.d.ts +37 -0
- package/dist/realistic/element-base.js +86 -14
- package/dist/realistic/index.d.ts +1 -0
- package/dist/realistic/index.js +1 -0
- package/dist/realistic/zoom-reach.d.ts +29 -0
- package/dist/realistic/zoom-reach.js +30 -0
- package/dist/satellites/catalogue.d.ts +52 -1
- package/dist/satellites/catalogue.js +96 -5
- package/dist/satellites/index.d.ts +1 -1
- package/dist/satellites/index.js +1 -1
- package/dist/satellites/track.js +18 -3
- package/dist/satellites/types.d.ts +2 -2
- package/dist/sea-names/features.d.ts +12 -0
- package/dist/sea-names/features.js +46 -0
- package/dist/sea-names/geometry.d.ts +121 -0
- package/dist/sea-names/geometry.js +135 -0
- package/dist/sea-names/host.d.ts +46 -0
- package/dist/sea-names/host.js +111 -0
- package/dist/space/element-base.d.ts +48 -1
- package/dist/space/element-base.js +109 -9
- package/dist/space/generic-satellite.d.ts +46 -0
- package/dist/space/generic-satellite.js +96 -0
- package/dist/space/index.d.ts +2 -1
- package/dist/space/index.js +2 -1
- package/dist/space/ride.d.ts +45 -0
- package/dist/space/ride.js +38 -0
- package/dist/space/satellite-layer.d.ts +37 -0
- package/dist/space/satellite-layer.js +96 -14
- package/dist/space/scene.d.ts +3 -1
- package/dist/space/scene.js +54 -25
- package/package.json +3 -3
package/dist/space/ride.d.ts
CHANGED
|
@@ -162,6 +162,51 @@ export interface RidePose {
|
|
|
162
162
|
fov: number;
|
|
163
163
|
earthRadiusDegrees: number;
|
|
164
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Where a ride puts the camera: `outside` (the default) a little way off the satellite, behind and above it, so the satellite is in the picture; `inside` at the satellite itself, looking out of it, as a ride always was.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```ts
|
|
170
|
+
* import type { RideViewpoint } from "@johnmorrisdotca/chikyu-earth/space";
|
|
171
|
+
*
|
|
172
|
+
* const viewpoints: RideViewpoint[] = ["outside", "inside"];
|
|
173
|
+
* console.log(viewpoints.join(" or "));
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
export type RideViewpoint = "outside" | "inside";
|
|
177
|
+
/**
|
|
178
|
+
* How far an outside ride keeps the camera from the satellite, in kilometres. The satellite itself is a few metres across, so it is drawn far larger than life (a model about a fifth of the picture's height across): not to scale, and the page says so in its caption.
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```ts
|
|
182
|
+
* import { OUTSIDE_KM } from "@johnmorrisdotca/chikyu-earth/space";
|
|
183
|
+
*
|
|
184
|
+
* console.log(OUTSIDE_KM);
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
export declare const OUTSIDE_KM = 25;
|
|
188
|
+
/**
|
|
189
|
+
* The camera of an outside ride: the pose `ridePose` works out for a camera at the satellite, moved to `OUTSIDE_KM` back along its own line of sight so the satellite is in front of it. Looking along the way it goes (`look: "horizon"`) the satellite sits a little below the middle of the picture, so the camera is behind and above it; looking
|
|
190
|
+
* down (`look: "down"`) it is at the middle, with the camera straight above it. Where the satellite sits in the picture does not change with the zoom. Which way the camera looks and which way is up are the pose's own, so the look-around is the same as from the satellite itself; the camera goes round the satellite as it looks about. Pure. Never nearer the ground than half the satellite's height.
|
|
191
|
+
*
|
|
192
|
+
* @param pose - The pose from `ridePose` for the camera at the satellite.
|
|
193
|
+
* @param look - The look the pose was made with.
|
|
194
|
+
* @returns The pose moved back from the satellite, with how far the camera is from it in Earth radii and how many degrees below the middle of the picture the satellite is.
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```ts
|
|
198
|
+
* import { outsidePose, ridePose } from "@johnmorrisdotca/chikyu-earth/space";
|
|
199
|
+
*
|
|
200
|
+
* const at = ridePose({ position: [1.066, 0, 0], velocity: [0, 0, -7.66], look: "horizon", yaw: 0, tilt: 0, zoom: 1 });
|
|
201
|
+
* const out = outsidePose(at, "horizon");
|
|
202
|
+
* console.log(out.distance.toFixed(4), out.below.toFixed(1), out.pose.position.map((n) => n.toFixed(4)).join(","));
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
export declare function outsidePose(pose: RidePose, look: RideLook): {
|
|
206
|
+
pose: RidePose;
|
|
207
|
+
distance: number;
|
|
208
|
+
below: number;
|
|
209
|
+
};
|
|
165
210
|
/**
|
|
166
211
|
* The camera of a body-borne view: at `position`, looking at the Earth, with the way the body is going at the top of the picture. `look: "horizon"` tips it forward until the horizon is a little above the middle. A drag looks about from there on the spot:
|
|
167
212
|
* `yaw` turns the camera to its left and `tilt` tips it towards the bottom of its picture, so the ground follows the pointer (right for a drag right, up for a drag up); the angle for each pixel of the drag is the field of view's, so the pace is the same at any zoom.
|
package/dist/space/ride.js
CHANGED
|
@@ -121,6 +121,44 @@ const unit = (a) => {
|
|
|
121
121
|
const n = norm(a);
|
|
122
122
|
return n === 0 ? [0, 0, 0] : [a[0] / n, a[1] / n, a[2] / n];
|
|
123
123
|
};
|
|
124
|
+
/**
|
|
125
|
+
* How far an outside ride keeps the camera from the satellite, in kilometres. The satellite itself is a few metres across, so it is drawn far larger than life (a model about a fifth of the picture's height across): not to scale, and the page says so in its caption.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* import { OUTSIDE_KM } from "@johnmorrisdotca/chikyu-earth/space";
|
|
130
|
+
*
|
|
131
|
+
* console.log(OUTSIDE_KM);
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
export const OUTSIDE_KM = 25;
|
|
135
|
+
/** How far below the middle of the picture the satellite is drawn in an outside ride that looks along the way it goes, as a share of half the picture's height (0.56: about a fifth of the height below the middle). */
|
|
136
|
+
const OUTSIDE_LOW = 0.56;
|
|
137
|
+
/**
|
|
138
|
+
* The camera of an outside ride: the pose `ridePose` works out for a camera at the satellite, moved to `OUTSIDE_KM` back along its own line of sight so the satellite is in front of it. Looking along the way it goes (`look: "horizon"`) the satellite sits a little below the middle of the picture, so the camera is behind and above it; looking
|
|
139
|
+
* down (`look: "down"`) it is at the middle, with the camera straight above it. Where the satellite sits in the picture does not change with the zoom. Which way the camera looks and which way is up are the pose's own, so the look-around is the same as from the satellite itself; the camera goes round the satellite as it looks about. Pure. Never nearer the ground than half the satellite's height.
|
|
140
|
+
*
|
|
141
|
+
* @param pose - The pose from `ridePose` for the camera at the satellite.
|
|
142
|
+
* @param look - The look the pose was made with.
|
|
143
|
+
* @returns The pose moved back from the satellite, with how far the camera is from it in Earth radii and how many degrees below the middle of the picture the satellite is.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* import { outsidePose, ridePose } from "@johnmorrisdotca/chikyu-earth/space";
|
|
148
|
+
*
|
|
149
|
+
* const at = ridePose({ position: [1.066, 0, 0], velocity: [0, 0, -7.66], look: "horizon", yaw: 0, tilt: 0, zoom: 1 });
|
|
150
|
+
* const out = outsidePose(at, "horizon");
|
|
151
|
+
* console.log(out.distance.toFixed(4), out.below.toFixed(1), out.pose.position.map((n) => n.toFixed(4)).join(","));
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
export function outsidePose(pose, look) {
|
|
155
|
+
const height = Math.max(0, norm(pose.position) - 1);
|
|
156
|
+
const distance = Math.max(1e-5, Math.min(OUTSIDE_KM / 6371, height * 0.5));
|
|
157
|
+
const below = look === "horizon" ? Math.atan(OUTSIDE_LOW * Math.tan((pose.fov / 2) * RAD)) : 0;
|
|
158
|
+
// the satellite is along the line of sight turned `below` down (towards the bottom of the picture): the camera is back along that line
|
|
159
|
+
const line = add(scale(pose.forward, Math.cos(below)), scale(pose.up, -Math.sin(below)));
|
|
160
|
+
return { pose: { ...pose, position: add(pose.position, scale(line, -distance)) }, distance, below: below / RAD };
|
|
161
|
+
}
|
|
124
162
|
/**
|
|
125
163
|
* The camera of a body-borne view: at `position`, looking at the Earth, with the way the body is going at the top of the picture. `look: "horizon"` tips it forward until the horizon is a little above the middle. A drag looks about from there on the spot:
|
|
126
164
|
* `yaw` turns the camera to its left and `tilt` tips it towards the bottom of its picture, so the ground follows the pointer (right for a drag right, up for a drag up); the angle for each pixel of the drag is the field of view's, so the pace is the same at any zoom.
|
|
@@ -28,17 +28,54 @@ export interface SatelliteState {
|
|
|
28
28
|
orbitTint: boolean;
|
|
29
29
|
/** One group shown on its own. `null` leaves every group as the page set it. */
|
|
30
30
|
focus: SatelliteFocus | null;
|
|
31
|
+
/**
|
|
32
|
+
* 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.
|
|
33
|
+
* 0 draws the whole stretch one frame spans, however long that is.
|
|
34
|
+
*/
|
|
35
|
+
streakMax: number;
|
|
31
36
|
drawn: {
|
|
32
37
|
placed: number;
|
|
33
38
|
segments: number;
|
|
34
39
|
tooFast: boolean;
|
|
35
40
|
dotScale: number;
|
|
41
|
+
longestStreakPx: number;
|
|
42
|
+
streakCapPx: number;
|
|
43
|
+
weight: number;
|
|
44
|
+
fade: number;
|
|
45
|
+
earthPx: number;
|
|
36
46
|
updateMs: number;
|
|
37
47
|
maxUpdateMs: number;
|
|
38
48
|
updates: number;
|
|
39
49
|
totalMs: number;
|
|
40
50
|
};
|
|
41
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* 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
|
|
54
|
+
* 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.
|
|
55
|
+
*/
|
|
56
|
+
export declare const STREAK_REACH = 0.025;
|
|
57
|
+
/** The Earth's drawn radius, in CSS pixels, below which the satellites' dark rims and streaks are faded out (no weight at 40) and from which they have their whole weight (150). */
|
|
58
|
+
export declare const WEIGHT_FROM = 40;
|
|
59
|
+
export declare const WEIGHT_FULL = 150;
|
|
60
|
+
/** How much of its weight a mark has at an Earth `radiusPx` on the screen, from 0 to 1: a smooth step from {@link WEIGHT_FROM} to {@link WEIGHT_FULL}. Many small dark marks on a small Earth would blacken it. */
|
|
61
|
+
export declare function markWeight(radiusPx: number): number;
|
|
62
|
+
/**
|
|
63
|
+
* The share of the near side of a small Earth that the marks may cover at full strength before they are drawn fainter in proportion: a crowd of marks on a small Earth is a haze over it, not a set of satellites. Dots are lighter ink
|
|
64
|
+
* than streaks are (a dot is opaque and a streak a pixel wide), so they get the smaller share.
|
|
65
|
+
*/
|
|
66
|
+
export declare const CROWD_COVER_DOTS = 0.06;
|
|
67
|
+
export declare const CROWD_COVER_STREAKS = 0.35;
|
|
68
|
+
/**
|
|
69
|
+
* How strongly each mark is drawn so a crowd does not wash a small Earth, from 0 to 1: the share of the near side they would cover (`marks`, half of them on this side, each `area` square pixels, over the disc of an Earth `radiusPx` in radius),
|
|
70
|
+
* and `limit` over that when it is more. With `byWeight` (the default, for dots) it acts only as the Earth gets small (see {@link markWeight}): none at all from 150 pixels, so a whole Earth is drawn as it was however many satellites there are. Without it (streaks) the limit holds at every size: a streak is as wide as it is long, so the same number of satellites covers a half Earth twice over, and 16,000 of them leave a small Earth no more washed than a whole one.
|
|
71
|
+
*/
|
|
72
|
+
export declare function crowdFade(marks: number, area: number, radiusPx: number, limit: number, byWeight?: boolean): number;
|
|
73
|
+
/** The longest a streak is by default: the stretch a low satellite covers in one frame at 10 minutes a second, on a whole Earth with a radius of about 300 pixels: a few millimetres on the screen. */
|
|
74
|
+
export declare const DEFAULT_STREAK_MAX = 8;
|
|
75
|
+
/** Read `satellite-streak-max`: a number of CSS pixels, `off` or 0 for no cap, and the default for nothing, a negative number or anything else. */
|
|
76
|
+
export declare function readStreakMax(value: string | null): number;
|
|
77
|
+
/** The longest streak, in CSS pixels, among the first `count` of `segments` (6 numbers each), with the Earth's radius `earthPx` on the screen: a length in Earth radii times the radius. */
|
|
78
|
+
export declare function longestStreak(segments: Float32Array, count: number, earthPx: number): number;
|
|
42
79
|
export declare const newSatelliteState: () => SatelliteState;
|
|
43
80
|
/** The most orbits a group may draw all at once, one line each. */
|
|
44
81
|
export declare const MAX_ORBIT_GROUP = 40;
|
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
import { MAX_SATELLITE_SPEED } from "../satellites/limits.js";
|
|
2
2
|
import { satelliteEmphasis } from "./satellite-focus.js";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* 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
|
+
* 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.
|
|
6
|
+
*/
|
|
7
|
+
export const STREAK_REACH = 0.025;
|
|
8
|
+
/** The Earth's drawn radius, in CSS pixels, below which the satellites' dark rims and streaks are faded out (no weight at 40) and from which they have their whole weight (150). */
|
|
9
|
+
export const WEIGHT_FROM = 40;
|
|
10
|
+
export const WEIGHT_FULL = 150;
|
|
11
|
+
/** How much of its weight a mark has at an Earth `radiusPx` on the screen, from 0 to 1: a smooth step from {@link WEIGHT_FROM} to {@link WEIGHT_FULL}. Many small dark marks on a small Earth would blacken it. */
|
|
12
|
+
export function markWeight(radiusPx) {
|
|
13
|
+
const t = Math.min(1, Math.max(0, (radiusPx - WEIGHT_FROM) / (WEIGHT_FULL - WEIGHT_FROM)));
|
|
14
|
+
return t * t * (3 - 2 * t);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The share of the near side of a small Earth that the marks may cover at full strength before they are drawn fainter in proportion: a crowd of marks on a small Earth is a haze over it, not a set of satellites. Dots are lighter ink
|
|
18
|
+
* than streaks are (a dot is opaque and a streak a pixel wide), so they get the smaller share.
|
|
19
|
+
*/
|
|
20
|
+
export const CROWD_COVER_DOTS = 0.06;
|
|
21
|
+
export const CROWD_COVER_STREAKS = 0.35;
|
|
22
|
+
/**
|
|
23
|
+
* How strongly each mark is drawn so a crowd does not wash a small Earth, from 0 to 1: the share of the near side they would cover (`marks`, half of them on this side, each `area` square pixels, over the disc of an Earth `radiusPx` in radius),
|
|
24
|
+
* and `limit` over that when it is more. With `byWeight` (the default, for dots) it acts only as the Earth gets small (see {@link markWeight}): none at all from 150 pixels, so a whole Earth is drawn as it was however many satellites there are. Without it (streaks) the limit holds at every size: a streak is as wide as it is long, so the same number of satellites covers a half Earth twice over, and 16,000 of them leave a small Earth no more washed than a whole one.
|
|
25
|
+
*/
|
|
26
|
+
export function crowdFade(marks, area, radiusPx, limit, byWeight = true) {
|
|
27
|
+
const disc = Math.PI * radiusPx * radiusPx;
|
|
28
|
+
if (!(disc > 0) || !(marks > 0))
|
|
29
|
+
return 1;
|
|
30
|
+
const cover = (0.5 * marks * area) / disc;
|
|
31
|
+
const crowd = cover <= limit ? 1 : limit / cover;
|
|
32
|
+
return byWeight ? 1 - (1 - crowd) * (1 - markWeight(radiusPx)) : crowd;
|
|
33
|
+
}
|
|
34
|
+
/** The longest a streak is by default: the stretch a low satellite covers in one frame at 10 minutes a second, on a whole Earth with a radius of about 300 pixels: a few millimetres on the screen. */
|
|
35
|
+
export const DEFAULT_STREAK_MAX = 8;
|
|
36
|
+
/** Read `satellite-streak-max`: a number of CSS pixels, `off` or 0 for no cap, and the default for nothing, a negative number or anything else. */
|
|
37
|
+
export function readStreakMax(value) {
|
|
38
|
+
if (value === null || value.trim() === "")
|
|
39
|
+
return DEFAULT_STREAK_MAX;
|
|
40
|
+
const text = value.trim().toLowerCase();
|
|
41
|
+
if (text === "off")
|
|
42
|
+
return 0;
|
|
43
|
+
const number = Number(text);
|
|
44
|
+
return Number.isFinite(number) && number >= 0 ? number : DEFAULT_STREAK_MAX;
|
|
45
|
+
}
|
|
46
|
+
/** The longest streak, in CSS pixels, among the first `count` of `segments` (6 numbers each), with the Earth's radius `earthPx` on the screen: a length in Earth radii times the radius. */
|
|
47
|
+
export function longestStreak(segments, count, earthPx) {
|
|
48
|
+
let longest = 0;
|
|
49
|
+
for (let i = 0; i < count; i += 1) {
|
|
50
|
+
const w = i * 6;
|
|
51
|
+
const length = Math.hypot(segments[w + 3] - segments[w], segments[w + 4] - segments[w + 1], segments[w + 5] - segments[w + 2]);
|
|
52
|
+
if (length > longest)
|
|
53
|
+
longest = length;
|
|
54
|
+
}
|
|
55
|
+
return longest * earthPx;
|
|
56
|
+
}
|
|
57
|
+
export const newSatelliteState = () => ({ groups: new Map(), selected: null, marked: new Set(), pinned: [], orbitTint: false, focus: 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 } });
|
|
4
58
|
/** The most orbits a group may draw all at once, one line each. */
|
|
5
59
|
export const MAX_ORBIT_GROUP = 40;
|
|
6
60
|
const ORBIT_POINTS = 120;
|
|
@@ -23,6 +77,8 @@ const POINT_FRAG = /* glsl */ `
|
|
|
23
77
|
uniform vec3 tint;
|
|
24
78
|
uniform float ring;
|
|
25
79
|
uniform float byClass;
|
|
80
|
+
uniform float rim;
|
|
81
|
+
uniform float fade;
|
|
26
82
|
varying float vDim;
|
|
27
83
|
varying vec3 vCls;
|
|
28
84
|
void main() {
|
|
@@ -33,10 +89,10 @@ void main() {
|
|
|
33
89
|
float a = smoothstep(0.30, 0.38, d) * (1.0 - smoothstep(0.44, 0.5, d));
|
|
34
90
|
gl_FragColor = vec4(ink, a * (1.0 - 0.7 * vDim));
|
|
35
91
|
} else {
|
|
36
|
-
float
|
|
37
|
-
vec3 colour = mix(ink, vec3(0.04, 0.05, 0.08), rim);
|
|
92
|
+
float rimEdge = smoothstep(0.28, 0.42, d);
|
|
93
|
+
vec3 colour = mix(ink, vec3(0.04, 0.05, 0.08), rimEdge * rim);
|
|
38
94
|
float a = smoothstep(0.50, 0.40, d);
|
|
39
|
-
gl_FragColor = vec4(colour, a * (1.0 - 0.7 * vDim));
|
|
95
|
+
gl_FragColor = vec4(colour, a * (1.0 - 0.7 * vDim) * fade);
|
|
40
96
|
}
|
|
41
97
|
}`;
|
|
42
98
|
/** How long, in milliseconds of wall time, a satellite's place is kept before SGP4 places it again when the clock is too fast to interpolate: about once a second. */
|
|
@@ -124,8 +180,8 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
124
180
|
const view = new three.Vector3();
|
|
125
181
|
const ink = new three.Color();
|
|
126
182
|
let basis = 0;
|
|
127
|
-
let
|
|
128
|
-
const selectedMaterial = new three.ShaderMaterial({ vertexShader: POINT_VERT, fragmentShader: POINT_FRAG, uniforms: { size: { value: 14 }, tint: { value: new three.Color("#ffffff") }, ring: { value: 1 }, byClass: { value: 0 }, groupDim: { value: 0 } }, transparent: true, depthWrite: false });
|
|
183
|
+
let lastEarthPx = 0;
|
|
184
|
+
const selectedMaterial = new three.ShaderMaterial({ vertexShader: POINT_VERT, fragmentShader: POINT_FRAG, uniforms: { size: { value: 14 }, tint: { value: new three.Color("#ffffff") }, ring: { value: 1 }, byClass: { value: 0 }, rim: { value: 1 }, fade: { value: 1 }, groupDim: { value: 0 } }, transparent: true, depthWrite: false });
|
|
129
185
|
const selectedPosition = new Float32Array(3);
|
|
130
186
|
const selectedGeometry = new three.BufferGeometry();
|
|
131
187
|
selectedGeometry.setAttribute("position", new three.BufferAttribute(selectedPosition, 3));
|
|
@@ -203,10 +259,26 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
203
259
|
if (basis === 0 && earthPx > 0)
|
|
204
260
|
basis = earthPx;
|
|
205
261
|
const dotScale = basis > 0 && earthPx > 0 ? Math.min(2.5, Math.max(0.45, Math.sqrt(earthPx / basis))) : 1;
|
|
206
|
-
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
|
|
262
|
+
// One frame at the pace the picture is held to (30 a second), whatever the frames really take: a streak that grew with a slow frame would grow with a slow computer
|
|
263
|
+
const span = tooFast ? speed * (1000 / 30) : 0;
|
|
264
|
+
if (earthPx > 0)
|
|
265
|
+
lastEarthPx = earthPx;
|
|
266
|
+
const radius = earthPx > 0 ? earthPx : lastEarthPx > 0 ? lastEarthPx : 150;
|
|
267
|
+
// the cap is a share of the Earth's drawn radius with a ceiling in pixels, so in Earth radii it is the pixels over the Earth's radius in pixels: a zoomed-out Earth allows a longer stretch of orbit than a zoomed-in one
|
|
268
|
+
const capLength = state.streakMax > 0 ? Math.min(STREAK_REACH, state.streakMax / radius) : 0;
|
|
269
|
+
const weight = markWeight(radius);
|
|
270
|
+
// how crowded the near side of the Earth is with marks: the dots at their size and, above the interpolation limit, the streaks (a pixel wide) at the longest they may be
|
|
271
|
+
let marks = 0;
|
|
272
|
+
let dotArea = 0;
|
|
273
|
+
for (const group of state.groups.values()) {
|
|
274
|
+
if (!group.visible)
|
|
275
|
+
continue;
|
|
276
|
+
marks += group.satellites.count;
|
|
277
|
+
dotArea += group.satellites.count * (group.size * dotScale) ** 2;
|
|
278
|
+
}
|
|
279
|
+
const dotFade = marks > 0 ? crowdFade(marks, dotArea / marks, radius, CROWD_COVER_DOTS) : 1;
|
|
280
|
+
const streakFade = tooFast && capLength > 0 ? crowdFade(marks, Math.max(1, capLength * radius), radius, CROWD_COVER_STREAKS, false) : 1;
|
|
281
|
+
let longest = 0;
|
|
210
282
|
for (const [name, entry] of drawn) {
|
|
211
283
|
if (state.groups.get(name)?.satellites !== entry.source) {
|
|
212
284
|
drop(entry);
|
|
@@ -226,7 +298,7 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
226
298
|
const dim = new three.BufferAttribute(group.satellites.dimmed, 1);
|
|
227
299
|
geometry.setAttribute("dim", dim);
|
|
228
300
|
geometry.setAttribute("cls", new three.BufferAttribute(group.satellites.classColour, 3));
|
|
229
|
-
const material = new three.ShaderMaterial({ vertexShader: POINT_VERT, fragmentShader: POINT_FRAG, uniforms: { size: { value: group.size * ratio() }, tint: { value: new three.Color(group.color) }, ring: { value: 0 }, byClass: { value: 0 }, groupDim: { value: 0 } }, transparent: true, depthWrite: false });
|
|
301
|
+
const material = new three.ShaderMaterial({ vertexShader: POINT_VERT, fragmentShader: POINT_FRAG, uniforms: { size: { value: group.size * ratio() }, tint: { value: new three.Color(group.color) }, ring: { value: 0 }, byClass: { value: 0 }, rim: { value: 1 }, fade: { value: 1 }, groupDim: { value: 0 } }, transparent: true, depthWrite: false });
|
|
230
302
|
const points = new Points(geometry, material);
|
|
231
303
|
points.frustumCulled = false;
|
|
232
304
|
points.renderOrder = 5;
|
|
@@ -283,8 +355,11 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
283
355
|
continue;
|
|
284
356
|
}
|
|
285
357
|
const dimmed = choice.dim > 0;
|
|
358
|
+
// the streaks are fainter and the dark rims of the dots fade as the Earth is drawn smaller, so thousands of marks do not darken a small Earth
|
|
286
359
|
if (entry.streak)
|
|
287
|
-
entry.streak.material.opacity = dimmed ? 0.3 : 0.95;
|
|
360
|
+
entry.streak.material.opacity = (dimmed ? 0.3 : 0.95) * (0.4 + 0.6 * weight) * streakFade;
|
|
361
|
+
entry.material.uniforms["rim"].value = weight;
|
|
362
|
+
entry.material.uniforms["fade"].value = dotFade;
|
|
288
363
|
if (tooFast) {
|
|
289
364
|
// pinned whole at the first frame and when the time jumped (a date typed in, a scrub), so a place is never turned across days; after that a slice a frame, each satellite again about once a second,
|
|
290
365
|
// so SGP4 never runs for the whole group (17,000 satellites take about 12 ms) in one frame
|
|
@@ -301,7 +376,7 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
301
376
|
}
|
|
302
377
|
entry.pinWall = started;
|
|
303
378
|
entry.pinTime = time;
|
|
304
|
-
const n = group.satellites.arc(time, span, entry.positions, entry.streakPositions);
|
|
379
|
+
const n = group.satellites.arc(time, span, entry.positions, entry.streakPositions, capLength);
|
|
305
380
|
entry.attribute.needsUpdate = true;
|
|
306
381
|
if (entry.streak) {
|
|
307
382
|
entry.streakAttribute.needsUpdate = true;
|
|
@@ -317,8 +392,10 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
317
392
|
line.loop.visible = false;
|
|
318
393
|
placed += n;
|
|
319
394
|
group.placed = n;
|
|
320
|
-
if (entry.streak)
|
|
395
|
+
if (entry.streak) {
|
|
321
396
|
segments += n;
|
|
397
|
+
longest = Math.max(longest, longestStreak(entry.streakPositions, total, radius));
|
|
398
|
+
}
|
|
322
399
|
}
|
|
323
400
|
else {
|
|
324
401
|
if (entry.streak)
|
|
@@ -367,6 +444,11 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
367
444
|
}
|
|
368
445
|
state.drawn.placed = placed;
|
|
369
446
|
state.drawn.segments = segments;
|
|
447
|
+
state.drawn.longestStreakPx = longest;
|
|
448
|
+
state.drawn.streakCapPx = capLength * radius;
|
|
449
|
+
state.drawn.weight = weight;
|
|
450
|
+
state.drawn.fade = Math.min(dotFade, streakFade);
|
|
451
|
+
state.drawn.earthPx = radius;
|
|
370
452
|
state.drawn.dotScale = dotScale;
|
|
371
453
|
state.drawn.tooFast = tooFast;
|
|
372
454
|
state.drawn.updateMs = performance.now() - started;
|
package/dist/space/scene.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { LightMode } from "../realistic/earth.ts";
|
|
|
7
7
|
import { type Frame, type PlanetName, type Vec3 } from "./ephemeris.ts";
|
|
8
8
|
import { type ScaleMode } from "./scale.ts";
|
|
9
9
|
import type { SatelliteRef } from "../satellites/types.ts";
|
|
10
|
-
import { type RideFace, type RideLook } from "./ride.ts";
|
|
10
|
+
import { type RideFace, type RideLook, type RideViewpoint } from "./ride.ts";
|
|
11
11
|
import type { SkyFrame } from "../sky/frame.ts";
|
|
12
12
|
import type { PlaceView } from "../markers/places.ts";
|
|
13
13
|
import { type PlaceSpriteData } from "../markers/place-sprites.ts";
|
|
@@ -107,6 +107,8 @@ export interface RideState {
|
|
|
107
107
|
face: RideFace | null;
|
|
108
108
|
/** For `follow` a satellite: how far the camera keeps, in kilometres. */
|
|
109
109
|
distanceKm: number;
|
|
110
|
+
/** `outside`: a ridden satellite is in the picture (the camera a little behind and above it in `from`, a drawing of it where the page has no model); `inside`: as a ride was before, the camera at the satellite and no drawing of it where the page has no model. */
|
|
111
|
+
viewpoint: RideViewpoint;
|
|
110
112
|
}
|
|
111
113
|
/** The camera as the last draw left it, for the next one to start from when the ride changes. */
|
|
112
114
|
export interface Pose {
|
package/dist/space/scene.js
CHANGED
|
@@ -5,7 +5,8 @@ import { createTextureSet } from "../realistic/textures.js";
|
|
|
5
5
|
import { createTileSet } from "../realistic/tile-set.js";
|
|
6
6
|
import { createTrack, orbitPath, PLANETS } from "./ephemeris.js";
|
|
7
7
|
import { placeAround, placeMoon, placeSun, RADIUS } from "./scale.js";
|
|
8
|
-
import { faceOffset, ridePose } from "./ride.js";
|
|
8
|
+
import { faceOffset, outsidePose, ridePose } from "./ride.js";
|
|
9
|
+
import { genericSatellite, satelliteKind } from "./generic-satellite.js";
|
|
9
10
|
import { coverBody, covers } from "../sky/cover.js";
|
|
10
11
|
import { beginPlaceSprites, createPlaceSprites } from "../markers/place-sprites.js";
|
|
11
12
|
import { aboveAxes, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
|
|
@@ -22,6 +23,8 @@ import { subsolarPoint, unitVector } from "../realistic/sun.js";
|
|
|
22
23
|
const MAX_MARKED = 80;
|
|
23
24
|
const RAD = Math.PI / 180;
|
|
24
25
|
const FOV = 35;
|
|
26
|
+
/** How big a satellite seen from outside by a ride from itself is drawn: its radius is this share of the height of the view (a model about a fifth of the height across; the satellite is a few metres, so this is not to scale). */
|
|
27
|
+
const OUTSIDE_RADIUS_SHARE = 0.09;
|
|
25
28
|
/** How much of the view's shorter side the Earth's disc fills at zoom 1 when the page does not say: 0.9, so the atmosphere's glow (8% beyond the disc) is inside the view and never cut. */
|
|
26
29
|
export const DEFAULT_EARTH_SIZE = 0.9;
|
|
27
30
|
/**
|
|
@@ -516,6 +519,8 @@ export function createSpaceItem(model, deps) {
|
|
|
516
519
|
let focusRadius = radiusOf(focus);
|
|
517
520
|
let rideFrom = null;
|
|
518
521
|
let followed = null;
|
|
522
|
+
// a satellite ridden from itself: where it is, so that an outside ride can show it
|
|
523
|
+
let ridden = null;
|
|
519
524
|
model.rideLost = false;
|
|
520
525
|
model.lookBase = null;
|
|
521
526
|
model.rideMotion = 0;
|
|
@@ -543,8 +548,10 @@ export function createSpaceItem(model, deps) {
|
|
|
543
548
|
focusRadius = Math.max(1e-4, ride.distanceKm / 6371 / fit);
|
|
544
549
|
followed = { place, velocity: [rideState[3], rideState[4], rideState[5]], ref: ride.target };
|
|
545
550
|
}
|
|
546
|
-
else
|
|
551
|
+
else {
|
|
547
552
|
rideFrom = { position: place, velocity: [rideState[3], rideState[4], rideState[5]], hidden: null, gameSeconds: 0 };
|
|
553
|
+
ridden = { place, velocity: rideFrom.velocity, ref: ride.target };
|
|
554
|
+
}
|
|
548
555
|
}
|
|
549
556
|
else
|
|
550
557
|
model.rideLost = true;
|
|
@@ -561,14 +568,21 @@ export function createSpaceItem(model, deps) {
|
|
|
561
568
|
let fovNow = FOV;
|
|
562
569
|
let distance = 0;
|
|
563
570
|
if (rideFrom) {
|
|
564
|
-
|
|
571
|
+
let pose = ridePose({ position: rideFrom.position, velocity: rideFrom.velocity, look: ride.look, yaw: model.view.yaw, tilt: model.view.tilt, zoom: model.view.zoom, turn: model.rideTurn, ...(ride.face ? { face: ride.face } : {}) });
|
|
565
572
|
model.rideDistance = Math.hypot(...rideFrom.position);
|
|
573
|
+
// an outside ride: the same look, from a little way back along it, so the satellite is in the picture
|
|
574
|
+
let outsideAway = Infinity;
|
|
575
|
+
if (ridden && ride.viewpoint === "outside") {
|
|
576
|
+
const out = outsidePose(pose, ride.look);
|
|
577
|
+
pose = out.pose;
|
|
578
|
+
outsideAway = out.distance;
|
|
579
|
+
}
|
|
566
580
|
camera.position.set(pose.position[0], pose.position[1], pose.position[2]);
|
|
567
581
|
camera.up.set(pose.up[0], pose.up[1], pose.up[2]);
|
|
568
582
|
camera.lookAt(pose.position[0] + pose.forward[0], pose.position[1] + pose.forward[1], pose.position[2] + pose.forward[2]);
|
|
569
583
|
fovNow = pose.fov;
|
|
570
584
|
const away = Math.hypot(...rideFrom.position);
|
|
571
|
-
camera.near = Math.max(0.0008, Math.min(0.05, (away - 1) * 0.1));
|
|
585
|
+
camera.near = outsideAway < Infinity ? Math.max(1e-5, outsideAway * 0.1) : Math.max(0.0008, Math.min(0.05, (away - 1) * 0.1));
|
|
572
586
|
camera.far = Math.max(2000, 400 + (mode === "true" ? 40 * 23_481 : 0));
|
|
573
587
|
// how fast the ground goes by under the camera, in pixels a second at 1x: the speed over the height for a satellite, the turn of the direction to the Earth for a body
|
|
574
588
|
const focal = (size.height / 2) / Math.tan((fovNow / 2) * RAD);
|
|
@@ -755,14 +769,36 @@ export function createSpaceItem(model, deps) {
|
|
|
755
769
|
model.painted = { bodies: paintedBodies, moons: paintedMoons, held: 0, moon: paintedMoon !== undefined, tiles: tiled, mapped: model.painted.mapped, pending: model.painted.pending };
|
|
756
770
|
// the followed satellite as a model, when the page has one for it: made once, placed where the satellite is, pointed the way it flies, sized to read and lit by the Sun
|
|
757
771
|
const satellitePainter = deps.satellitePainter?.();
|
|
758
|
-
|
|
759
|
-
const
|
|
760
|
-
const
|
|
772
|
+
// the satellite to draw: the one followed or seen from above, or (an outside ride from the satellite itself) the one ridden
|
|
773
|
+
const candidate = followed ?? ridden;
|
|
774
|
+
const shownSat = followed ?? (ride?.viewpoint === "outside" ? ridden : null);
|
|
775
|
+
const group = candidate ? model.satellites.groups.get(candidate.ref.group) : undefined;
|
|
776
|
+
const set = candidate && group ? group.satellites.sets[candidate.ref.index] : undefined;
|
|
777
|
+
const norad = set?.NORAD_CAT_ID;
|
|
778
|
+
// a model the page made for it, drawn only while the camera is outside it (followed or above it, or an outside ride); else the package's own small drawing by kind, kept (hidden) while the ride stays on the satellite, and let go when it ends
|
|
779
|
+
const painted = norad !== undefined && satellitePainter?.has(norad) === true;
|
|
780
|
+
const genericKey = set ? `generic:${satelliteKind(set.OBJECT_NAME ?? "")}` : "";
|
|
781
|
+
const modelKey = set === undefined || norad === undefined ? "" : painted ? (shownSat ? String(norad) : "") : ride?.viewpoint === "outside" || modelSlot.key === genericKey ? genericKey : "";
|
|
761
782
|
if (modelKey !== modelSlot.key) {
|
|
762
783
|
dropModel();
|
|
763
784
|
modelSlot.key = modelKey;
|
|
764
785
|
const turn = (modelSlot.turn += 1);
|
|
765
|
-
|
|
786
|
+
const adopt = (made) => {
|
|
787
|
+
made.object.matrixAutoUpdate = false;
|
|
788
|
+
made.object.visible = false;
|
|
789
|
+
scene.add(made.object);
|
|
790
|
+
modelSlot.drawing = made;
|
|
791
|
+
// how many meshes the model is made of: a draw call each, which a test of the draw budget adds to the scene's own
|
|
792
|
+
modelSlot.parts = 0;
|
|
793
|
+
made.object.traverse((part) => {
|
|
794
|
+
if (part.isMesh)
|
|
795
|
+
modelSlot.parts += 1;
|
|
796
|
+
});
|
|
797
|
+
deps.invalidate();
|
|
798
|
+
};
|
|
799
|
+
if (modelKey.startsWith("generic:"))
|
|
800
|
+
adopt(genericSatellite(three, modelKey.slice(8)));
|
|
801
|
+
else if (modelKey && satellitePainter && norad !== undefined) {
|
|
766
802
|
void Promise.resolve(satellitePainter.make(three, norad, { look: "", invalidate: () => deps.invalidate(), ratio: model.ratio(), maxTexture: deps.cap() }))
|
|
767
803
|
.then((made) => {
|
|
768
804
|
if (!made)
|
|
@@ -771,32 +807,25 @@ export function createSpaceItem(model, deps) {
|
|
|
771
807
|
made.dispose();
|
|
772
808
|
return;
|
|
773
809
|
}
|
|
774
|
-
made
|
|
775
|
-
made.object.visible = false;
|
|
776
|
-
scene.add(made.object);
|
|
777
|
-
modelSlot.drawing = made;
|
|
778
|
-
// how many meshes the model is made of: a draw call each, which a test of the draw budget adds to the scene's own
|
|
779
|
-
modelSlot.parts = 0;
|
|
780
|
-
made.object.traverse((part) => {
|
|
781
|
-
if (part.isMesh)
|
|
782
|
-
modelSlot.parts += 1;
|
|
783
|
-
});
|
|
784
|
-
deps.invalidate();
|
|
810
|
+
adopt(made);
|
|
785
811
|
})
|
|
786
812
|
.catch((error) => deps.onPainterError?.(error));
|
|
787
813
|
}
|
|
788
814
|
}
|
|
789
|
-
const axes =
|
|
790
|
-
|
|
815
|
+
const axes = shownSat ? satelliteAxes(shownSat.place, shownSat.velocity) : null;
|
|
816
|
+
// a generic drawing is for an outside ride only; a page's model is drawn wherever the camera is not at the satellite
|
|
817
|
+
const drawn = shownSat !== null && (ride?.viewpoint === "outside" || (followed !== null && painted));
|
|
818
|
+
if (modelSlot.drawing && shownSat && axes && drawn) {
|
|
791
819
|
const object = modelSlot.drawing.object;
|
|
792
|
-
const away = Math.hypot(
|
|
793
|
-
|
|
820
|
+
const away = Math.hypot(shownSat.place[0] - camera.position.x, shownSat.place[1] - camera.position.y, shownSat.place[2] - camera.position.z);
|
|
821
|
+
const share = followed ? MODEL_RADIUS_SHARE : OUTSIDE_RADIUS_SHARE;
|
|
822
|
+
object.matrix.set(...modelMatrix(shownSat.place, axes, modelRadius(away, half, share, 1e-9)));
|
|
794
823
|
object.matrixWorldNeedsUpdate = true;
|
|
795
824
|
object.visible = true;
|
|
796
825
|
const toSunNow = unit(frame.sun);
|
|
797
826
|
modelSlot.drawing.light?.(toSunNow);
|
|
798
|
-
modelSlot.drawing.update?.({ toSun: toSunNow, ms: model.time, radiusPx: size.height *
|
|
799
|
-
projected.set(
|
|
827
|
+
modelSlot.drawing.update?.({ toSun: toSunNow, ms: model.time, radiusPx: size.height * share });
|
|
828
|
+
projected.set(shownSat.place[0], shownSat.place[1], shownSat.place[2]).project(camera);
|
|
800
829
|
model.followModel = { x: ((projected.x + 1) / 2) * size.width, y: ((1 - projected.y) / 2) * size.height, shown: true, parts: modelSlot.parts };
|
|
801
830
|
}
|
|
802
831
|
else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/chikyu-earth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.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",
|
|
@@ -220,7 +220,7 @@
|
|
|
220
220
|
},
|
|
221
221
|
"peerDependencies": {
|
|
222
222
|
"@johnmorrisdotca/hoshi-stars": ">=0.30.0",
|
|
223
|
-
"@johnmorrisdotca/kuni": ">=1.
|
|
223
|
+
"@johnmorrisdotca/kuni": ">=1.8.0",
|
|
224
224
|
"@johnmorrisdotca/wakusei-planets": ">=0.5.0",
|
|
225
225
|
"astronomy-engine": ">=2.1.0",
|
|
226
226
|
"satellite.js": ">=6.0.0",
|
|
@@ -254,7 +254,7 @@
|
|
|
254
254
|
"@eslint/js": "^9.0.0",
|
|
255
255
|
"@johnmorrisdotca/hata": "^1.8.0",
|
|
256
256
|
"@johnmorrisdotca/hoshi-stars": "^0.30.0",
|
|
257
|
-
"@johnmorrisdotca/kuni": "^1.
|
|
257
|
+
"@johnmorrisdotca/kuni": "^1.8.0",
|
|
258
258
|
"@johnmorrisdotca/wakusei-planets": "^0.39.0",
|
|
259
259
|
"@playwright/test": "1.64.0",
|
|
260
260
|
"@sveltejs/vite-plugin-svelte": "^7.3.1",
|