@johnmorrisdotca/chikyu-earth 0.36.0 → 0.38.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/NOTICE.md +6 -1
  3. package/README.md +1 -1
  4. package/dist/catalogue/index.d.ts +1 -0
  5. package/dist/catalogue/index.js +3 -2
  6. package/dist/catalogue/pack.js +3 -0
  7. package/dist/cities/host.js +38 -8
  8. package/dist/markers/place-layer.d.ts +12 -1
  9. package/dist/markers/place-layer.js +88 -18
  10. package/dist/markers/place-sprites.d.ts +5 -0
  11. package/dist/markers/place-sprites.js +8 -0
  12. package/dist/paint/buffer.d.ts +53 -0
  13. package/dist/paint/buffer.js +238 -0
  14. package/dist/paint/math.d.ts +24 -0
  15. package/dist/paint/math.js +94 -0
  16. package/dist/paint/texture.d.ts +24 -0
  17. package/dist/paint/texture.js +33 -0
  18. package/dist/realistic/earth.d.ts +9 -0
  19. package/dist/realistic/earth.js +20 -11
  20. package/dist/realistic/element.d.ts +36 -3
  21. package/dist/realistic/element.js +82 -14
  22. package/dist/realistic/shaders.js +13 -0
  23. package/dist/realistic/textures.d.ts +2 -0
  24. package/dist/satellites/index.d.ts +1 -0
  25. package/dist/satellites/index.js +1 -0
  26. package/dist/satellites/limits.d.ts +1 -1
  27. package/dist/satellites/limits.js +1 -1
  28. package/dist/satellites/owners.d.ts +26 -0
  29. package/dist/satellites/owners.js +164 -0
  30. package/dist/satellites/source.js +3 -0
  31. package/dist/satellites/track.d.ts +5 -0
  32. package/dist/satellites/track.js +146 -3
  33. package/dist/satellites/types.d.ts +22 -1
  34. package/dist/space/element.d.ts +56 -6
  35. package/dist/space/element.js +171 -16
  36. package/dist/space/index.d.ts +1 -1
  37. package/dist/space/index.js +1 -1
  38. package/dist/space/ride.d.ts +42 -0
  39. package/dist/space/ride.js +45 -3
  40. package/dist/space/satellite-layer.d.ts +32 -2
  41. package/dist/space/satellite-layer.js +178 -19
  42. package/dist/space/scene.d.ts +12 -1
  43. package/dist/space/scene.js +27 -16
  44. package/package.json +1 -1
@@ -0,0 +1,238 @@
1
+ import { coverageAngleRad, groundUnder, PAINT_H, PAINT_W, paintPixel, splitDateLine, trackSteps } from "./math.js";
2
+ const MINUTE = 60_000;
3
+ const DAY = 86_400_000;
4
+ const LENGTH_MS = { "1d": DAY, "1w": 7 * DAY, "1m": 30 * DAY };
5
+ export const paintLengthOf = (length) => (length === "1w" || length === "1m" ? length : "1d");
6
+ export const paintSwathOf = (swath) => (swath === "coverage" ? "coverage" : "track");
7
+ /** Minutes since the epoch, in 16 bits: the trail is at most a month, and 16 bits hold 45 days. */
8
+ export const paintMinute = (ms) => Math.round(ms / MINUTE) & 0xffff;
9
+ const write = (data, x, y, minute) => {
10
+ if (x < 0 || y < 0 || x >= PAINT_W || y >= PAINT_H)
11
+ return false;
12
+ const i = (y * PAINT_W + x) * 4;
13
+ const fresh = data[i + 3] === 0;
14
+ data[i] = (minute >> 8) & 255;
15
+ data[i + 1] = minute & 255;
16
+ data[i + 2] = 255;
17
+ data[i + 3] = 255;
18
+ return fresh;
19
+ };
20
+ const stampDot = (data, point, minute, radius) => {
21
+ const at = paintPixel(point.lon, point.lat);
22
+ let added = 0;
23
+ for (let dy = -radius; dy <= radius; dy += 1) {
24
+ for (let dx = -radius; dx <= radius; dx += 1) {
25
+ if (dx * dx + dy * dy > radius * radius)
26
+ continue;
27
+ if (write(data, at.x + dx, at.y + dy, minute))
28
+ added += 1;
29
+ }
30
+ }
31
+ return added;
32
+ };
33
+ const stampLine = (data, a, b, minute) => {
34
+ const from = paintPixel(a.lon, a.lat);
35
+ const to = paintPixel(b.lon, b.lat);
36
+ if (Math.abs(to.x - from.x) > PAINT_W / 2)
37
+ return 0;
38
+ let added = 0;
39
+ let x = from.x;
40
+ let y = from.y;
41
+ const dx = Math.abs(to.x - x);
42
+ const dy = Math.abs(to.y - y);
43
+ const sx = x < to.x ? 1 : -1;
44
+ const sy = y < to.y ? 1 : -1;
45
+ let err = dx - dy;
46
+ for (;;) {
47
+ if (write(data, x, y, minute))
48
+ added += 1;
49
+ if (write(data, x + 1, y, minute))
50
+ added += 1;
51
+ if (x === to.x && y === to.y)
52
+ break;
53
+ const e2 = 2 * err;
54
+ if (e2 > -dy) {
55
+ err -= dy;
56
+ x += sx;
57
+ }
58
+ if (e2 < dx) {
59
+ err += dx;
60
+ y += sy;
61
+ }
62
+ }
63
+ return added;
64
+ };
65
+ const angular = (a, b) => {
66
+ const lat1 = a.lat * Math.PI / 180;
67
+ const lat2 = b.lat * Math.PI / 180;
68
+ const dLat = lat2 - lat1;
69
+ const dLon = (b.lon - a.lon) * Math.PI / 180;
70
+ const h = Math.sin(dLat / 2) ** 2 + Math.cos(lat1) * Math.cos(lat2) * Math.sin(dLon / 2) ** 2;
71
+ return 2 * Math.atan2(Math.sqrt(h), Math.sqrt(Math.max(0, 1 - h)));
72
+ };
73
+ const stampCap = (data, point, theta, minute) => {
74
+ if (!(theta > 0))
75
+ return stampDot(data, point, minute, 1);
76
+ const deg = theta * 180 / Math.PI;
77
+ const cosLat = Math.max(0.15, Math.cos(point.lat * Math.PI / 180));
78
+ const dLon = Math.min(180, deg / cosLat);
79
+ const pole = Math.abs(point.lat) + deg >= 90;
80
+ const west = pole ? -180 : point.lon - dLon;
81
+ const east = pole ? 180 : point.lon + dLon;
82
+ const south = Math.max(-90, point.lat - deg);
83
+ const north = Math.min(90, point.lat + deg);
84
+ const a = paintPixel(west, north);
85
+ const b = paintPixel(east, south);
86
+ let added = 0;
87
+ const x0 = pole ? 0 : Math.max(0, Math.min(a.x, b.x));
88
+ const x1 = pole ? PAINT_W - 1 : Math.min(PAINT_W - 1, Math.max(a.x, b.x));
89
+ const y0 = Math.max(0, Math.min(a.y, b.y));
90
+ const y1 = Math.min(PAINT_H - 1, Math.max(a.y, b.y));
91
+ for (let y = y0; y <= y1; y += 1) {
92
+ const lat = 90 - (y + 0.5) / PAINT_H * 180;
93
+ for (let x = x0; x <= x1; x += 1) {
94
+ let lon = (x + 0.5) / PAINT_W * 360 - 180;
95
+ if (!pole && west < -180)
96
+ lon = lon > 0 ? lon - 360 : lon;
97
+ if (angular(point, { lon, lat }) <= theta && write(data, x, y, minute))
98
+ added += 1;
99
+ }
100
+ }
101
+ return added;
102
+ };
103
+ const stampGround = (data, swath, ground, previous, minute) => {
104
+ if (swath === "coverage")
105
+ return { added: stampCap(data, ground, coverageAngleRad(ground.heightKm), minute), at: ground };
106
+ if (!previous)
107
+ return { added: stampDot(data, ground, minute, 1), at: ground };
108
+ let added = 0;
109
+ let cursor = previous;
110
+ for (const point of trackSteps(previous, ground, 0.4)) {
111
+ for (const [from, to] of splitDateLine(cursor, point))
112
+ added += stampLine(data, from, to, minute);
113
+ cursor = point;
114
+ }
115
+ return { added, at: cursor };
116
+ };
117
+ export function createPaintState() {
118
+ const data = new Uint8Array(PAINT_W * PAINT_H * 4);
119
+ let spec = null;
120
+ let pixels = 0;
121
+ let lastMs = Number.NaN;
122
+ let previous = null;
123
+ let uploadClear = false;
124
+ const self = {
125
+ data,
126
+ width: PAINT_W,
127
+ height: PAINT_H,
128
+ get pixels() {
129
+ return pixels;
130
+ },
131
+ get on() {
132
+ return spec !== null;
133
+ },
134
+ get length() {
135
+ return spec?.length ?? "1d";
136
+ },
137
+ get swath() {
138
+ return spec?.swath ?? "track";
139
+ },
140
+ get id() {
141
+ return spec?.id ?? "";
142
+ },
143
+ get spanMinutes() {
144
+ return LENGTH_MS[spec?.length ?? "1d"] / MINUTE;
145
+ },
146
+ set(next) {
147
+ if (!next) {
148
+ self.clear();
149
+ return;
150
+ }
151
+ const id = String(next.id);
152
+ const length = paintLengthOf(next.length);
153
+ const swath = paintSwathOf(next.swath);
154
+ if (spec && spec.id === id && spec.length === length && spec.swath === swath)
155
+ return;
156
+ data.fill(0);
157
+ pixels = 0;
158
+ lastMs = Number.NaN;
159
+ previous = null;
160
+ spec = { id, length, swath };
161
+ },
162
+ clear() {
163
+ data.fill(0);
164
+ pixels = 0;
165
+ lastMs = Number.NaN;
166
+ previous = null;
167
+ spec = null;
168
+ uploadClear = true;
169
+ },
170
+ step(ms, sample) {
171
+ if (!spec) {
172
+ const upload = uploadClear;
173
+ uploadClear = false;
174
+ return upload;
175
+ }
176
+ if (!Number.isFinite(ms))
177
+ return false;
178
+ if (Number.isFinite(lastMs) && ms === lastMs)
179
+ return false;
180
+ const length = LENGTH_MS[spec.length];
181
+ let dirty = false;
182
+ const put = (at) => {
183
+ const ground = sample(at);
184
+ if (!ground)
185
+ return;
186
+ const stamped = stampGround(data, spec.swath, ground, previous, paintMinute(at));
187
+ pixels += stamped.added;
188
+ previous = stamped.at;
189
+ dirty = true;
190
+ };
191
+ if (!Number.isFinite(lastMs) || Math.abs(ms - lastMs) > length) {
192
+ data.fill(0);
193
+ pixels = 0;
194
+ previous = null;
195
+ const steps = Math.min(240, Math.max(1, Math.ceil(length / 60_000)));
196
+ for (let i = steps; i >= 0; i -= 1)
197
+ put(ms - (length * i) / steps);
198
+ }
199
+ else {
200
+ const span = ms - lastMs;
201
+ const steps = Math.min(96, Math.max(1, Math.ceil(Math.abs(span) / 20_000)));
202
+ for (let i = 1; i <= steps; i += 1)
203
+ put(lastMs + (span * i) / steps);
204
+ }
205
+ lastMs = ms;
206
+ return dirty;
207
+ },
208
+ };
209
+ return self;
210
+ }
211
+ /** The satellite `id` names, in the groups now set: a NORAD number, or `group:index`. */
212
+ export function findPainted(groups, id) {
213
+ const cut = id.indexOf(":");
214
+ if (cut > 0) {
215
+ for (const [name, group] of groups) {
216
+ const index = Number(id.slice(cut + 1));
217
+ if (name === id.slice(0, cut) && index >= 0 && index < group.satellites.count)
218
+ return { satellites: group.satellites, index };
219
+ }
220
+ }
221
+ const norad = Number(id);
222
+ if (!Number.isFinite(norad))
223
+ return null;
224
+ for (const [, group] of groups) {
225
+ const index = group.satellites.sets.findIndex((set) => set.NORAD_CAT_ID === norad);
226
+ if (index >= 0)
227
+ return { satellites: group.satellites, index };
228
+ }
229
+ return null;
230
+ }
231
+ const scratch = new Float64Array(6);
232
+ /** The ground under the painted satellite at `ms`, or null when it cannot be placed. */
233
+ export function paintedGround(groups, id, ms) {
234
+ const found = findPainted(groups, id);
235
+ if (!found || !found.satellites.exact(found.index, ms, scratch))
236
+ return null;
237
+ return groundUnder(scratch[0], scratch[1], scratch[2], ms);
238
+ }
@@ -0,0 +1,24 @@
1
+ /** Mean Earth radius, kilometres, the same unit the satellite positions use. */
2
+ export declare const PAINT_EARTH_KM = 6371;
3
+ /** The painted texture: equirectangular, north at the first row, longitude −180 at the first column. */
4
+ export declare const PAINT_W = 1024;
5
+ export declare const PAINT_H = 512;
6
+ export interface LonLat {
7
+ lon: number;
8
+ lat: number;
9
+ }
10
+ /** Earth-central angle, in radians, where a satellite `heightKm` up is at least `elevationDeg` above the horizon (10 when left out). 0 when it never is. */
11
+ export declare function coverageAngleRad(heightKm: number, elevationDeg?: number): number;
12
+ /** The ground under a satellite. `x, y, z` are what `Satellites.exact` writes (Earth radii, x to the vernal equinox, y north). `ms` turns the Earth under that place. */
13
+ export declare function groundUnder(x: number, y: number, z: number, ms: number): LonLat & {
14
+ heightKm: number;
15
+ };
16
+ /** Points from `a` to `b` along the great circle, about `stepDeg` apart, including both ends. A fast clock stays a continuous line, and a pole or the date line is many short steps. */
17
+ export declare function trackSteps(a: LonLat, b: LonLat, stepDeg: number): LonLat[];
18
+ /** One segment, or two when the short way from `a` to `b` crosses the date line, so an equirectangular line does not cross the whole map. Longitude is degrees, −180 to 180. */
19
+ export declare function splitDateLine(a: LonLat, b: LonLat): [LonLat, LonLat][];
20
+ /** Where a longitude and latitude fall on the painted texture, column and row. */
21
+ export declare function paintPixel(lon: number, lat: number): {
22
+ x: number;
23
+ y: number;
24
+ };
@@ -0,0 +1,94 @@
1
+ // Pure geometry for a satellite's painted ground track: the point under it, the date line, and the circle where it stands 10° up.
2
+ import { greenwichSidereal } from "../realistic/sun.js";
3
+ const RAD = Math.PI / 180;
4
+ /** Mean Earth radius, kilometres, the same unit the satellite positions use. */
5
+ export const PAINT_EARTH_KM = 6371;
6
+ /** The painted texture: equirectangular, north at the first row, longitude −180 at the first column. */
7
+ export const PAINT_W = 1024;
8
+ export const PAINT_H = 512;
9
+ /** Earth-central angle, in radians, where a satellite `heightKm` up is at least `elevationDeg` above the horizon (10 when left out). 0 when it never is. */
10
+ export function coverageAngleRad(heightKm, elevationDeg = 10) {
11
+ const r = PAINT_EARTH_KM + heightKm;
12
+ if (!(r > PAINT_EARTH_KM))
13
+ return 0;
14
+ const elevation = elevationDeg * RAD;
15
+ const cosAlpha = (PAINT_EARTH_KM / r) * Math.cos(elevation);
16
+ if (!(cosAlpha < 1))
17
+ return 0;
18
+ const alpha = Math.acos(Math.max(-1, cosAlpha));
19
+ return Math.max(0, alpha - elevation);
20
+ }
21
+ /** A unit vector for a longitude and latitude, in the Earth's own axes (+z at longitude 0, +x east, +y north). */
22
+ const unitOf = (point) => {
23
+ const lon = point.lon * RAD;
24
+ const lat = point.lat * RAD;
25
+ const c = Math.cos(lat);
26
+ return [c * Math.sin(lon), Math.sin(lat), c * Math.cos(lon)];
27
+ };
28
+ const fromUnit = (x, y, z) => {
29
+ const length = Math.hypot(x, y, z) || 1;
30
+ return { lon: Math.atan2(x, z) / RAD, lat: Math.asin(Math.max(-1, Math.min(1, y / length))) / RAD };
31
+ };
32
+ /** The ground under a satellite. `x, y, z` are what `Satellites.exact` writes (Earth radii, x to the vernal equinox, y north). `ms` turns the Earth under that place. */
33
+ export function groundUnder(x, y, z, ms) {
34
+ const theta = greenwichSidereal(ms) * RAD;
35
+ const cos = Math.cos(theta);
36
+ const sin = Math.sin(theta);
37
+ const temeX = x;
38
+ const temeY = -z;
39
+ const temeZ = y;
40
+ const east = -temeX * sin + temeY * cos;
41
+ const north = temeZ;
42
+ const prime = temeX * cos + temeY * sin;
43
+ const ground = fromUnit(east, north, prime);
44
+ return { ...ground, heightKm: (Math.hypot(x, y, z) - 1) * PAINT_EARTH_KM };
45
+ }
46
+ /** Points from `a` to `b` along the great circle, about `stepDeg` apart, including both ends. A fast clock stays a continuous line, and a pole or the date line is many short steps. */
47
+ export function trackSteps(a, b, stepDeg) {
48
+ const u = unitOf(a);
49
+ const v = unitOf(b);
50
+ const dot = Math.max(-1, Math.min(1, u[0] * v[0] + u[1] * v[1] + u[2] * v[2]));
51
+ const angle = Math.acos(dot);
52
+ const step = Math.max(0.25, stepDeg) * RAD;
53
+ if (!(angle > step))
54
+ return [a, b];
55
+ const count = Math.ceil(angle / step);
56
+ const sin = Math.sin(angle) || 1;
57
+ const out = [];
58
+ for (let i = 0; i <= count; i += 1) {
59
+ const t = i / count;
60
+ const left = Math.sin((1 - t) * angle) / sin;
61
+ const right = Math.sin(t * angle) / sin;
62
+ out.push(fromUnit(u[0] * left + v[0] * right, u[1] * left + v[1] * right, u[2] * left + v[2] * right));
63
+ }
64
+ return out;
65
+ }
66
+ /** One segment, or two when the short way from `a` to `b` crosses the date line, so an equirectangular line does not cross the whole map. Longitude is degrees, −180 to 180. */
67
+ export function splitDateLine(a, b) {
68
+ let delta = b.lon - a.lon;
69
+ if (delta > 180)
70
+ delta -= 360;
71
+ if (delta < -180)
72
+ delta += 360;
73
+ const end = a.lon + delta;
74
+ if (end <= 180 && end >= -180)
75
+ return [[a, { lon: end, lat: b.lat }]];
76
+ const edge = end > 180 ? 180 : -180;
77
+ const span = end - a.lon;
78
+ const t = span === 0 ? 0 : (edge - a.lon) / span;
79
+ const lat = a.lat + (b.lat - a.lat) * t;
80
+ const other = edge === 180 ? -180 : 180;
81
+ const rest = end > 180 ? end - 360 : end + 360;
82
+ return [
83
+ [a, { lon: edge, lat }],
84
+ [{ lon: other, lat }, { lon: rest, lat: b.lat }],
85
+ ];
86
+ }
87
+ /** Where a longitude and latitude fall on the painted texture, column and row. */
88
+ export function paintPixel(lon, lat) {
89
+ const u = lon / 360 + 0.5;
90
+ const v = 0.5 - lat / 180;
91
+ const x = Math.max(0, Math.min(PAINT_W - 1, Math.floor(u * PAINT_W)));
92
+ const y = Math.max(0, Math.min(PAINT_H - 1, Math.floor(v * PAINT_H)));
93
+ return { x, y };
94
+ }
@@ -0,0 +1,24 @@
1
+ import type * as THREE from "three";
2
+ import type { ThreeParts } from "../realistic/textures.ts";
3
+ export interface PaintTexture {
4
+ texture: THREE.Texture;
5
+ uniforms: {
6
+ paintMap: {
7
+ value: THREE.Texture;
8
+ };
9
+ paintNow: {
10
+ value: number;
11
+ };
12
+ paintSpan: {
13
+ value: number;
14
+ };
15
+ paintOn: {
16
+ value: number;
17
+ };
18
+ };
19
+ /** Upload `data` on the next draw. */
20
+ upload(): void;
21
+ dispose(): void;
22
+ }
23
+ /** A texture over `data` (equirectangular, north in the first row). The same uniforms go on the sphere and on any tile laid over it. */
24
+ export declare function createPaintTexture(three: ThreeParts, data: Uint8Array, width?: number, height?: number): PaintTexture;
@@ -0,0 +1,33 @@
1
+ import { PAINT_H, PAINT_W } from "./math.js";
2
+ /** A texture over `data` (equirectangular, north in the first row). The same uniforms go on the sphere and on any tile laid over it. */
3
+ export function createPaintTexture(three, data, width = PAINT_W, height = PAINT_H) {
4
+ const DataTexture = three.DataTexture;
5
+ const texture = DataTexture ? new DataTexture(data, width, height) : new three.Texture();
6
+ if (!DataTexture)
7
+ texture.image = { data, width, height };
8
+ texture.generateMipmaps = false;
9
+ texture.flipY = false;
10
+ texture.magFilter = three.LinearFilter;
11
+ texture.minFilter = three.LinearFilter;
12
+ texture.wrapS = three.ClampToEdgeWrapping;
13
+ texture.wrapT = three.ClampToEdgeWrapping;
14
+ const space = three.NoColorSpace;
15
+ if (space)
16
+ texture.colorSpace = space;
17
+ texture.needsUpdate = true;
18
+ return {
19
+ texture,
20
+ uniforms: {
21
+ paintMap: { value: texture },
22
+ paintNow: { value: 0 },
23
+ paintSpan: { value: 1440 },
24
+ paintOn: { value: 0 },
25
+ },
26
+ upload() {
27
+ texture.needsUpdate = true;
28
+ },
29
+ dispose() {
30
+ texture.dispose();
31
+ },
32
+ };
33
+ }
@@ -136,6 +136,15 @@ export interface EarthDeps {
136
136
  placeSprites?: () => PlaceSpriteData | null;
137
137
  /** Told once, when the rings of the places that are not markers of their own were first wanted: whether the picture can draw them (false when the three.js parts handed over lack `Points`). */
138
138
  onPlaceRings?: (drawn: boolean) => void;
139
+ /** The painted satellite trail, when the element has one. Read at every draw; nothing is uploaded while `step` returns false. */
140
+ paint?: {
141
+ data: Uint8Array;
142
+ width: number;
143
+ height: number;
144
+ step(ms: number): boolean;
145
+ span(): number;
146
+ on(): boolean;
147
+ };
139
148
  }
140
149
  export declare const newModel: () => EarthModel;
141
150
  /**
@@ -6,11 +6,13 @@ import { createSatelliteLayer, newSatelliteState } from "../space/satellite-laye
6
6
  import { createTextureSet } from "./textures.js";
7
7
  import { createTileSet } from "./tile-set.js";
8
8
  import { createBodyLabelLayer, newBodyLabelState } from "./body-label.js";
9
- import { createPlaceSprites } from "../markers/place-sprites.js";
9
+ import { beginPlaceSprites, createPlaceSprites } from "../markers/place-sprites.js";
10
10
  import { createMeteorLayer, newMeteorState } from "../meteors/layer.js";
11
11
  import { createBorderLayer, newBorderState } from "../borders/layer.js";
12
12
  import { createGridLayer, newGridState } from "../grid/layer.js";
13
13
  import { pointOnEarth } from "./tiles.js";
14
+ import { paintMinute } from "../paint/buffer.js";
15
+ import { createPaintTexture } from "../paint/texture.js";
14
16
  const RAD = Math.PI / 180;
15
17
  /**
16
18
  * The glow reaches this many radii from the centre; the globe at 1x is drawn to fit inside it.
@@ -149,6 +151,8 @@ export function createEarthItem(model, deps) {
149
151
  fragmentShader: SURFACE_FRAG,
150
152
  uniforms: { dayMap: uniform.day, nightMap: uniform.night, waterMap: uniform.water, cloudMap: uniform.clouds, sunDir, sunLocal, cloudShift, lights: { value: 1 }, boost: { value: 0 }, ortho: { value: 1 } },
151
153
  });
154
+ const paint = createPaintTexture(three, deps.paint?.data ?? new Uint8Array(4), deps.paint?.width ?? 1, deps.paint?.height ?? 1);
155
+ Object.assign(surface.uniforms, paint.uniforms);
152
156
  const cloudMaterial = new three.ShaderMaterial({
153
157
  vertexShader: SURFACE_VERT,
154
158
  fragmentShader: CLOUD_FRAG,
@@ -167,7 +171,7 @@ export function createEarthItem(model, deps) {
167
171
  });
168
172
  const turned = new three.Group();
169
173
  const earth = new three.Mesh(grid, surface);
170
- const tiles = createTileSet(three, turned, { sunDir, lights: surface.uniforms["lights"], boost: surface.uniforms["boost"], ortho: surface.uniforms["ortho"], water: uniform.water, night: uniform.night, extra: { cloudMap: uniform.clouds, sunLocal, cloudShift } }, { assets: deps.assets, sources: () => deps.sources?.() ?? {}, cap: deps.cap, invalidate: deps.invalidate, ...(deps.onTiles ? { onManifest: deps.onTiles } : {}) });
174
+ const tiles = createTileSet(three, turned, { sunDir, lights: surface.uniforms["lights"], boost: surface.uniforms["boost"], ortho: surface.uniforms["ortho"], water: uniform.water, night: uniform.night, extra: { cloudMap: uniform.clouds, sunLocal, cloudShift, ...paint.uniforms } }, { assets: deps.assets, sources: () => deps.sources?.() ?? {}, cap: deps.cap, invalidate: deps.invalidate, ...(deps.onTiles ? { onManifest: deps.onTiles } : {}) });
171
175
  model.tiles = tiles;
172
176
  const clouds = new three.Mesh(grid, cloudMaterial);
173
177
  clouds.scale.setScalar(CLOUD_RADIUS);
@@ -193,8 +197,7 @@ export function createEarthItem(model, deps) {
193
197
  let meteorTimer;
194
198
  let nameOn = null;
195
199
  let borders = null;
196
- let placeSprites = null;
197
- let placeSpritesTried = false;
200
+ const placeRings = { sprites: null, tried: false };
198
201
  let gridLayer = null;
199
202
  return {
200
203
  scene,
@@ -234,7 +237,7 @@ export function createEarthItem(model, deps) {
234
237
  deps.onSatellitesError?.(error);
235
238
  }
236
239
  }
237
- layer?.update(model.time, model.speed);
240
+ layer?.update(model.time, model.speed, radius);
238
241
  model.pick = layer ? (x, y, radius) => layer.pick(x, y, camera, size, radius) : null;
239
242
  model.drawn = { view: { ...view }, time: model.time, radius, centre: { ...centre } };
240
243
  textures.sync(radius * model.ratio());
@@ -289,13 +292,11 @@ export function createEarthItem(model, deps) {
289
292
  borders.sync({ points: points.length > 0 ? points : [look], angle: Math.asin(Math.min(1, (1.4 * Math.hypot(size.width, size.height)) / 8 / radius)) / RAD, radius });
290
293
  }
291
294
  const spriteData = deps.placeSprites?.() ?? null;
292
- if (spriteData && !placeSprites && !placeSpritesTried) {
293
- placeSprites = createPlaceSprites(three, turned, sunDir);
294
- placeSpritesTried = true;
295
+ if (beginPlaceSprites(placeRings, spriteData, () => createPlaceSprites(three, turned, sunDir))) {
295
296
  // told once: without `Points` the page's layer draws these rings itself
296
- deps.onPlaceRings?.(placeSprites !== null);
297
+ deps.onPlaceRings?.(placeRings.sprites !== null);
297
298
  }
298
- placeSprites?.sync(spriteData, model.ratio(), size.width, size.height, model.light === "lit");
299
+ placeRings.sprites?.sync(spriteData, model.ratio(), size.width, size.height, model.light === "lit");
299
300
  // the grid: made the first time it is switched on, over the ground and under the clouds
300
301
  if (model.grid.on && !gridLayer && !model.grid.stats.failed) {
301
302
  try {
@@ -307,6 +308,13 @@ export function createEarthItem(model, deps) {
307
308
  }
308
309
  }
309
310
  gridLayer?.sync(radius);
311
+ if (deps.paint) {
312
+ if (deps.paint.step(model.time))
313
+ paint.upload();
314
+ paint.uniforms.paintNow.value = paintMinute(model.time);
315
+ paint.uniforms.paintSpan.value = deps.paint.span();
316
+ paint.uniforms.paintOn.value = deps.paint.on() ? 1 : 0;
317
+ }
310
318
  if (model.meteors.on && !meteors)
311
319
  meteors = createMeteorLayer(three, turned, model.meteors);
312
320
  if (meteors) {
@@ -326,12 +334,13 @@ export function createEarthItem(model, deps) {
326
334
  meteors?.dispose();
327
335
  nameOn?.dispose();
328
336
  borders?.dispose();
329
- placeSprites?.dispose();
337
+ placeRings.sprites?.dispose();
330
338
  gridLayer?.dispose();
331
339
  model.tiles = null;
332
340
  tiles.dispose();
333
341
  textures.dispose();
334
342
  grid.dispose();
343
+ paint.dispose();
335
344
  surface.dispose();
336
345
  cloudMaterial.dispose();
337
346
  atmosphere.dispose();
@@ -1,6 +1,7 @@
1
1
  import { type ViewController } from "@johnmorrisdotca/kazoku-ui/view-controls";
2
2
  import type { GeoPoint, GlobeView } from "../types.ts";
3
3
  import { type CameraMode, type LightMode } from "./earth.ts";
4
+ import { type PaintSpec } from "../paint/buffer.ts";
4
5
  import type { SatelliteInfo, SatelliteRef, Satellites } from "../satellites/types.ts";
5
6
  import { type SatelliteStyle } from "../space/satellite-layer.ts";
6
7
  import type { Credit, DataSource } from "../data-door.ts";
@@ -35,7 +36,10 @@ export type EarthState = "loading" | "live" | "unavailable" | "lost" | "idle";
35
36
  type SatelliteStats = {
36
37
  groups: number;
37
38
  placed: number;
39
+ segments: number;
38
40
  tooFast: boolean;
41
+ dotScale: number;
42
+ epochMs: number;
39
43
  propagations: number;
40
44
  lastBatchMs: number;
41
45
  maxBatchMs: number;
@@ -108,6 +112,9 @@ export declare const readTime: (value: string | null) => number | "now";
108
112
  * earth.setAttribute("texture-base", "/textures/");
109
113
  * earth.setAttribute("tiles", "/tiles/");
110
114
  * earth.setAttribute("speed", "86400");
115
+ * earth.placeGroups = false; // place-groups="off": every place keeps its own ring
116
+ * earth.paint = { id: "25544", length: "1d", swath: "track" };
117
+ * earth.clearPaint();
111
118
  * earth.addEventListener("chikyu-timechange", (event) => {
112
119
  * const { time, running } = (event as CustomEvent<{ time: number; running: boolean }>).detail;
113
120
  * console.log(new Date(time).toISOString(), running ? "running" : "held");
@@ -193,6 +200,17 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
193
200
  }): Promise<Place | undefined>;
194
201
  /**
195
202
  * Whether places that crowd are gathered into one ring with their count (the attribute `place-groups`): on by default, `off` leaves every place its own ring. Setting the property writes the attribute.
203
+ *
204
+ * @example
205
+ * ```ts no-run
206
+ * import type { ChikyuEarthRealistic } from "@johnmorrisdotca/chikyu-earth/realistic/element";
207
+ *
208
+ * const earth = document.querySelector("chikyu-earth-realistic") as ChikyuEarthRealistic;
209
+ * earth.placeGroups = false;
210
+ * earth.getAttribute("place-groups"); // "off"
211
+ * earth.placeGroups = true;
212
+ * earth.hasAttribute("place-groups"); // false
213
+ * ```
196
214
  */
197
215
  get placeGroups(): boolean;
198
216
  set placeGroups(value: boolean);
@@ -331,7 +349,7 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
331
349
  y: number;
332
350
  }[];
333
351
  };
334
- /** The places: how many were handed over, how many are drawn and named at the last draw, and how many times they were laid out. */
352
+ /** The places: how many were handed over, how many are drawn and named at the last draw, and how many times they were laid out. `sprites` is the rings in the picture's one draw call (0 when it cannot draw them); `dots` is the circles drawn in the page instead. */
335
353
  places: {
336
354
  places: number;
337
355
  shown: number;
@@ -340,6 +358,7 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
340
358
  marks: number;
341
359
  groups: number;
342
360
  sprites: number;
361
+ dots: number;
343
362
  omitted: number;
344
363
  };
345
364
  /** The names of cities: whether `city-names` is set and the most it asks for, the Earth's radius on the screen, the tiers of kuni's cities that have arrived and how many cities, the names shown at the last draw and how many times the layer was drawn. */
@@ -364,15 +383,29 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
364
383
  * and draws are at most 30 a second.
365
384
  */
366
385
  setView(view: GlobeView, final?: boolean): void;
386
+ /**
387
+ * Colour each satellite by its orbit class (low, medium, geostationary, highly elliptical, other). Off by default, so a group keeps the colour it was given. The attribute is `satellite-tint="orbit"`.
388
+ */
389
+ get satelliteTint(): "off" | "orbit";
390
+ set satelliteTint(value: "off" | "orbit");
367
391
  /**
368
392
  * Show a group of satellites (made by `createSatellites`) under a name, or take the group away with `null`. A group is one draw call however many satellites it holds, so every group of the catalogue can be shown at once. Giving the name of a group
369
393
  * that is already shown replaces it. `style`: `color` and `size` (CSS pixels) of the dots, and `orbits` to draw every orbit (only for a group of 40 or fewer, such as the stations). The groups are placed by SGP4 about once a second and interpolated
370
- * between, are hidden while the clock runs faster than `MAX_SATELLITE_SPEED`, are hidden by the Earth when they are behind it, and draw at most 30 times a second and not at all while the clock holds.
394
+ * between. Above `MAX_SATELLITE_SPEED` each satellite is a short streak along its orbit instead of being hidden. They are hidden by the Earth when they are behind it, and draw at most 30 times a second and not at all while the clock holds.
371
395
  *
372
396
  * @param group - The group's name, for `showSatellites`, `selectSatellite` and the events.
373
397
  * @param satellites - The group, or `null` to remove it.
374
398
  * @param style - How to draw it.
375
399
  */
400
+ /**
401
+ * Paint one satellite's path on the Earth. `id` is a NORAD catalogue number or `group:index`. `length` is how long the trail is kept, in simulated time (`1d` when left out, or `1w`, `1m`). `swath` is `track` (the point under the satellite, the default) or `coverage` (where it is at least 10° above the horizon). Setting another satellite clears the trail. `null` clears it.
402
+ */
403
+ get paint(): PaintSpec | null;
404
+ set paint(value: PaintSpec | null);
405
+ /** Take the painted trail off the Earth. */
406
+ clearPaint(): void;
407
+ /** Texels the trail has painted. 0 after `clearPaint`, and again when the painted satellite changes. */
408
+ get paintPixels(): number;
376
409
  setSatellites(group: string, satellites: Satellites | null, style?: Partial<SatelliteStyle>): void;
377
410
  /** Show or hide a group without losing it. */
378
411
  showSatellites(group: string, on: boolean): void;
@@ -386,7 +419,7 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
386
419
  selectSatellite(ref: SatelliteRef | null): void;
387
420
  /** The satellite marked by `selectSatellite` or by a press on it, if any. */
388
421
  get selectedSatellite(): SatelliteRef | null;
389
- /** Facts about one satellite at the moment shown (name, number, element age, height, speed, period); undefined if it cannot be placed then. */
422
+ /** Facts about one satellite at the moment shown (name, number, element age, height, speed, period, and `ownerCountry` when the owner is one country); undefined if it cannot be placed then. */
390
423
  satelliteInfo(ref: SatelliteRef): SatelliteInfo | undefined;
391
424
  /** The view as it is (for a page that wants to read it back). */
392
425
  get view(): GlobeView;