@johnmorrisdotca/chikyu-earth 0.37.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.
- package/CHANGELOG.md +7 -0
- package/NOTICE.md +2 -1
- package/README.md +1 -1
- package/dist/markers/place-layer.d.ts +12 -1
- package/dist/markers/place-layer.js +88 -18
- package/dist/markers/place-sprites.d.ts +5 -0
- package/dist/markers/place-sprites.js +8 -0
- package/dist/paint/buffer.d.ts +53 -0
- package/dist/paint/buffer.js +238 -0
- package/dist/paint/math.d.ts +24 -0
- package/dist/paint/math.js +94 -0
- package/dist/paint/texture.d.ts +24 -0
- package/dist/paint/texture.js +33 -0
- package/dist/realistic/earth.d.ts +9 -0
- package/dist/realistic/earth.js +19 -10
- package/dist/realistic/element.d.ts +26 -1
- package/dist/realistic/element.js +58 -6
- package/dist/realistic/shaders.js +13 -0
- package/dist/satellites/track.js +26 -11
- package/dist/satellites/types.d.ts +5 -2
- package/dist/space/element.d.ts +26 -1
- package/dist/space/element.js +56 -5
- package/dist/space/satellite-layer.d.ts +24 -0
- package/dist/space/satellite-layer.js +45 -5
- package/dist/space/scene.d.ts +9 -0
- package/dist/space/scene.js +18 -9
- package/package.json +1 -1
|
@@ -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
|
/**
|
package/dist/realistic/earth.js
CHANGED
|
@@ -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
|
-
|
|
197
|
-
let placeSpritesTried = false;
|
|
200
|
+
const placeRings = { sprites: null, tried: false };
|
|
198
201
|
let gridLayer = null;
|
|
199
202
|
return {
|
|
200
203
|
scene,
|
|
@@ -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
|
|
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?.(
|
|
297
|
+
deps.onPlaceRings?.(placeRings.sprites !== null);
|
|
297
298
|
}
|
|
298
|
-
|
|
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
|
-
|
|
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";
|
|
@@ -111,6 +112,9 @@ export declare const readTime: (value: string | null) => number | "now";
|
|
|
111
112
|
* earth.setAttribute("texture-base", "/textures/");
|
|
112
113
|
* earth.setAttribute("tiles", "/tiles/");
|
|
113
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();
|
|
114
118
|
* earth.addEventListener("chikyu-timechange", (event) => {
|
|
115
119
|
* const { time, running } = (event as CustomEvent<{ time: number; running: boolean }>).detail;
|
|
116
120
|
* console.log(new Date(time).toISOString(), running ? "running" : "held");
|
|
@@ -196,6 +200,17 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
|
|
|
196
200
|
}): Promise<Place | undefined>;
|
|
197
201
|
/**
|
|
198
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
|
+
* ```
|
|
199
214
|
*/
|
|
200
215
|
get placeGroups(): boolean;
|
|
201
216
|
set placeGroups(value: boolean);
|
|
@@ -334,7 +349,7 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
|
|
|
334
349
|
y: number;
|
|
335
350
|
}[];
|
|
336
351
|
};
|
|
337
|
-
/** 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. */
|
|
338
353
|
places: {
|
|
339
354
|
places: number;
|
|
340
355
|
shown: number;
|
|
@@ -343,6 +358,7 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
|
|
|
343
358
|
marks: number;
|
|
344
359
|
groups: number;
|
|
345
360
|
sprites: number;
|
|
361
|
+
dots: number;
|
|
346
362
|
omitted: number;
|
|
347
363
|
};
|
|
348
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. */
|
|
@@ -381,6 +397,15 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
|
|
|
381
397
|
* @param satellites - The group, or `null` to remove it.
|
|
382
398
|
* @param style - How to draw it.
|
|
383
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;
|
|
384
409
|
setSatellites(group: string, satellites: Satellites | null, style?: Partial<SatelliteStyle>): void;
|
|
385
410
|
/** Show or hide a group without losing it. */
|
|
386
411
|
showSatellites(group: string, on: boolean): void;
|
|
@@ -7,6 +7,7 @@ import { airFor, readAirThickness } from "./air.js";
|
|
|
7
7
|
import { IMMERSIVE_STYLE, immersiveWheel } from "./immersive.js";
|
|
8
8
|
import { NOTES_STYLE, setAirNote } from "./air-note.js";
|
|
9
9
|
import { cameraCentre, createEarthItem, discRadius, lookAt, newModel } from "./earth.js";
|
|
10
|
+
import { createPaintState, paintedGround } from "../paint/buffer.js";
|
|
10
11
|
import { MAX_ORBIT_GROUP } from "../space/satellite-layer.js";
|
|
11
12
|
import { readMeteorStrength } from "../meteors/strength.js";
|
|
12
13
|
import { METEOR_NOTE_STYLE, prefersLessMotion, setMeteorNote } from "../meteors/note.js";
|
|
@@ -16,7 +17,7 @@ import { ownCredit } from "../door/own.js";
|
|
|
16
17
|
import { BODY_LABEL_ATTRIBUTES, bodyLabelText, loadMichroma, readBodyLabel } from "./body-label.js";
|
|
17
18
|
import { createSkyHost, SKY_ATTRIBUTES, SKY_STYLE } from "../sky/host.js";
|
|
18
19
|
import { cleanPlaces, orthoView, readPlaceGroups, readPlaces } from "../markers/places.js";
|
|
19
|
-
import { createPlaceLayer, PLACE_STYLE, readPlaceLook } from "../markers/place-layer.js";
|
|
20
|
+
import { createPlaceLayer, PLACE_STYLE, placesLostNotice, readPlaceLook } from "../markers/place-layer.js";
|
|
20
21
|
import { aimAt, findPlace, glideView } from "../markers/go-to-place.js";
|
|
21
22
|
import { subsolarPoint } from "./sun.js";
|
|
22
23
|
import { CITY_NAMES_ATTRIBUTES, CITY_NAMES_STYLE, createCityHost } from "../cities/host.js";
|
|
@@ -137,6 +138,9 @@ export const readTime = (value) => {
|
|
|
137
138
|
* earth.setAttribute("texture-base", "/textures/");
|
|
138
139
|
* earth.setAttribute("tiles", "/tiles/");
|
|
139
140
|
* earth.setAttribute("speed", "86400");
|
|
141
|
+
* earth.placeGroups = false; // place-groups="off": every place keeps its own ring
|
|
142
|
+
* earth.paint = { id: "25544", length: "1d", swath: "track" };
|
|
143
|
+
* earth.clearPaint();
|
|
140
144
|
* earth.addEventListener("chikyu-timechange", (event) => {
|
|
141
145
|
* const { time, running } = (event as CustomEvent<{ time: number; running: boolean }>).detail;
|
|
142
146
|
* console.log(new Date(time).toISOString(), running ? "running" : "held");
|
|
@@ -147,6 +151,7 @@ export const readTime = (value) => {
|
|
|
147
151
|
export class ChikyuEarthRealistic extends HTMLElement {
|
|
148
152
|
static observedAttributes = ["cloud-drift", "center", "time", "speed", "clouds", "lights", "light", "live-seconds", "tiles", "data", "camera", "immersive", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "satellite-tint"];
|
|
149
153
|
#model = newModel();
|
|
154
|
+
#paint = createPaintState();
|
|
150
155
|
#mode = "now";
|
|
151
156
|
#view;
|
|
152
157
|
#gate;
|
|
@@ -177,6 +182,8 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
177
182
|
#countriesStyle = {};
|
|
178
183
|
#listeners = new Set();
|
|
179
184
|
#placeLayer;
|
|
185
|
+
/** Whether the page has been told that places in sight were left undrawn. */
|
|
186
|
+
#placesLost = { told: false };
|
|
180
187
|
#placeList = [];
|
|
181
188
|
/** Counts the turns to a place, so a new one stops the one before. */
|
|
182
189
|
#placeGlide = 0;
|
|
@@ -310,12 +317,22 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
310
317
|
finally {
|
|
311
318
|
this.#posing = false;
|
|
312
319
|
}
|
|
313
|
-
if (this.#placeLayer && (this.#placeList.length > 0 || this.#placeLayer.stats.shown > 0))
|
|
320
|
+
if (this.#placeLayer && (this.#placeList.length > 0 || this.#placeLayer.stats.shown > 0)) {
|
|
314
321
|
this.#placeLayer.frame(orthoView(pose), [], [], this.#model.light === "lit" ? null : subsolarPoint(this.#model.time));
|
|
322
|
+
this.#notePlacesLost();
|
|
323
|
+
}
|
|
315
324
|
this.#cityFrame();
|
|
316
325
|
},
|
|
317
326
|
onPlaceRings: (drawn) => this.#ringsDrawn(drawn),
|
|
318
327
|
onSatellitesError: (error) => this.dispatchEvent(new CustomEvent("chikyu-satellites-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
|
|
328
|
+
paint: {
|
|
329
|
+
data: this.#paint.data,
|
|
330
|
+
width: this.#paint.width,
|
|
331
|
+
height: this.#paint.height,
|
|
332
|
+
step: (ms) => this.#paint.step(ms, (at) => paintedGround(this.#model.satellites.groups, this.#paint.id, at)),
|
|
333
|
+
span: () => this.#paint.spanMinutes,
|
|
334
|
+
on: () => this.#paint.on,
|
|
335
|
+
},
|
|
319
336
|
onError: (error) => this.#fail(error instanceof Error ? error.message : String(error)),
|
|
320
337
|
onTier: (layer, width) => {
|
|
321
338
|
if (layer in this.#tiers)
|
|
@@ -609,6 +626,17 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
609
626
|
}
|
|
610
627
|
/**
|
|
611
628
|
* 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.
|
|
629
|
+
*
|
|
630
|
+
* @example
|
|
631
|
+
* ```ts no-run
|
|
632
|
+
* import type { ChikyuEarthRealistic } from "@johnmorrisdotca/chikyu-earth/realistic/element";
|
|
633
|
+
*
|
|
634
|
+
* const earth = document.querySelector("chikyu-earth-realistic") as ChikyuEarthRealistic;
|
|
635
|
+
* earth.placeGroups = false;
|
|
636
|
+
* earth.getAttribute("place-groups"); // "off"
|
|
637
|
+
* earth.placeGroups = true;
|
|
638
|
+
* earth.hasAttribute("place-groups"); // false
|
|
639
|
+
* ```
|
|
612
640
|
*/
|
|
613
641
|
get placeGroups() {
|
|
614
642
|
return this.#placeLayer?.grouping ?? readPlaceGroups(this.getAttribute("place-groups"));
|
|
@@ -619,15 +647,20 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
619
647
|
else
|
|
620
648
|
this.setAttribute("place-groups", "off");
|
|
621
649
|
}
|
|
622
|
-
/** The picture said whether it can draw the rings of the places that are not markers of their own. Without `Points` the places' layer draws them itself
|
|
650
|
+
/** The picture said whether it can draw the rings of the places that are not markers of their own. Without `Points` the places' layer draws them itself. */
|
|
623
651
|
#ringsDrawn(drawn) {
|
|
624
652
|
if (!this.#placeLayer || this.#placeLayer.ringsInPicture === drawn)
|
|
625
653
|
return;
|
|
626
654
|
this.#placeLayer.ringsInPicture = drawn;
|
|
627
|
-
if (!drawn)
|
|
628
|
-
this.dispatchEvent(new CustomEvent("chikyu-places-unavailable", { detail: { reason: "the three.js parts handed over lack Points: the places' rings are drawn as small circles in the page, at most 600, and stats.places.omitted counts the rest" } }));
|
|
629
655
|
this.#gate?.soon();
|
|
630
656
|
}
|
|
657
|
+
/** Tell the page once when places in sight had no room among the fallback circles. Missing `Points` alone leaves them drawn, so it says nothing. */
|
|
658
|
+
#notePlacesLost() {
|
|
659
|
+
const notice = placesLostNotice(this.#placesLost, this.#placeLayer?.stats.omitted ?? 0);
|
|
660
|
+
if (!notice)
|
|
661
|
+
return;
|
|
662
|
+
this.dispatchEvent(new CustomEvent("chikyu-places-unavailable", { detail: notice }));
|
|
663
|
+
}
|
|
631
664
|
/** How the places are drawn (the attribute `places-look`): `beam` (a light rising out of the ground with a ring at its foot, the default), `pin` (a thin stick with a round head) or `ring` (only the ring on the ground). */
|
|
632
665
|
get placesLook() {
|
|
633
666
|
return this.#placeLayer?.look ?? readPlaceLook(this.getAttribute("places-look"));
|
|
@@ -920,7 +953,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
920
953
|
meteors: { on: this.#model.meteors.on, strength: this.#model.meteors.strength, ...this.#model.meteors.drawn },
|
|
921
954
|
bodyLabel: { on: this.#model.bodyLabel.settings !== null, text: this.#model.bodyLabel.text, ...this.#model.bodyLabel.drawn },
|
|
922
955
|
sky: this.#sky?.stats ?? { on: false, loaded: false, names: 0, figures: 0, picked: null, pick: null, hover: null, constellations: 0, culture: "iau", renders: 0, lang: "", stars: [] },
|
|
923
|
-
places: { ...(this.#placeLayer?.stats ?? { places: 0, shown: 0, labels: 0, renders: 0, marks: 0, groups: 0, sprites: 0, omitted: 0 }) },
|
|
956
|
+
places: { ...(this.#placeLayer?.stats ?? { places: 0, shown: 0, labels: 0, renders: 0, marks: 0, groups: 0, sprites: 0, dots: 0, omitted: 0 }) },
|
|
924
957
|
cityNames: this.#cities?.stats ?? { on: false, max: 0, radius: 0, tiers: [], cities: 0, names: 0, renders: 0 },
|
|
925
958
|
borders: { ...this.#model.borders.stats, shown: { ...this.#model.borders.stats.shown }, loaded: [...this.#model.borders.stats.loaded] },
|
|
926
959
|
grid: { ...this.#model.grid.stats },
|
|
@@ -967,6 +1000,25 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
967
1000
|
* @param satellites - The group, or `null` to remove it.
|
|
968
1001
|
* @param style - How to draw it.
|
|
969
1002
|
*/
|
|
1003
|
+
/**
|
|
1004
|
+
* 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.
|
|
1005
|
+
*/
|
|
1006
|
+
get paint() {
|
|
1007
|
+
return this.#paint.on ? { id: this.#paint.id, length: this.#paint.length, swath: this.#paint.swath } : null;
|
|
1008
|
+
}
|
|
1009
|
+
set paint(value) {
|
|
1010
|
+
this.#paint.set(value);
|
|
1011
|
+
this.#gate?.soon();
|
|
1012
|
+
}
|
|
1013
|
+
/** Take the painted trail off the Earth. */
|
|
1014
|
+
clearPaint() {
|
|
1015
|
+
this.#paint.clear();
|
|
1016
|
+
this.#gate?.soon();
|
|
1017
|
+
}
|
|
1018
|
+
/** Texels the trail has painted. 0 after `clearPaint`, and again when the painted satellite changes. */
|
|
1019
|
+
get paintPixels() {
|
|
1020
|
+
return this.#paint.pixels;
|
|
1021
|
+
}
|
|
970
1022
|
setSatellites(group, satellites, style = {}) {
|
|
971
1023
|
const groups = this.#model.satellites.groups;
|
|
972
1024
|
if (satellites === null) {
|
|
@@ -31,6 +31,10 @@ uniform float cloudShift;
|
|
|
31
31
|
uniform float lights;
|
|
32
32
|
uniform float boost;
|
|
33
33
|
uniform float ortho;
|
|
34
|
+
uniform sampler2D paintMap;
|
|
35
|
+
uniform float paintNow;
|
|
36
|
+
uniform float paintSpan;
|
|
37
|
+
uniform float paintOn;
|
|
34
38
|
${tile ? "uniform vec4 nightRect;\nvarying vec2 vUvG;" : ""}
|
|
35
39
|
varying vec2 vUv;
|
|
36
40
|
varying vec3 vNormal;
|
|
@@ -82,6 +86,15 @@ void main() {
|
|
|
82
86
|
night += vec3(0.04, 0.08, 0.20) * smoothstep(-0.20, -0.06, ndl) * (1.0 - smoothstep(-0.06, 0.06, ndl)) * 0.28;
|
|
83
87
|
vec3 col = mix(night, lit, day);
|
|
84
88
|
col += pow(albedo, vec3(0.75)) * boost * 0.65 * (1.0 - day);
|
|
89
|
+
if (paintOn > 0.5) {
|
|
90
|
+
vec4 stamp = texture2D(paintMap, ${tile ? "vUvG" : "vUv"});
|
|
91
|
+
float then = floor(stamp.r * 255.0 + 0.5) * 256.0 + floor(stamp.g * 255.0 + 0.5);
|
|
92
|
+
float age = paintNow - then;
|
|
93
|
+
if (age < -32768.0) age += 65536.0;
|
|
94
|
+
if (age > 32768.0) age -= 65536.0;
|
|
95
|
+
float show = stamp.a * step(-1.0, age) * (1.0 - smoothstep(paintSpan * 0.82, paintSpan, age));
|
|
96
|
+
col = mix(col, vec3(1.0, 0.55, 0.12), clamp(show, 0.0, 0.92));
|
|
97
|
+
}
|
|
85
98
|
|
|
86
99
|
gl_FragColor = vec4(col, 1.0);
|
|
87
100
|
}`;
|
package/dist/satellites/track.js
CHANGED
|
@@ -123,7 +123,9 @@ export function createSatellites(sets, options = {}) {
|
|
|
123
123
|
const timing = { lastBatchMs: 0, maxBatchMs: 0 };
|
|
124
124
|
const pinned = new Float32Array(n * 3);
|
|
125
125
|
const pinOk = new Uint8Array(n);
|
|
126
|
-
|
|
126
|
+
// when each satellite was last pinned (NaN: never), so a group can be pinned a slice at a time and `arc` turns each from its own pin
|
|
127
|
+
const pinMsOf = new Float64Array(n).fill(Number.NaN);
|
|
128
|
+
let pinnedCount = 0;
|
|
127
129
|
/** Turn `x,y,z` about the unit axis `nx,ny,nz` by `ang` radians, into `out` at `at` (no allocation: it runs for every satellite on every frame). */
|
|
128
130
|
const turn = (x, y, z, nx, ny, nz, ang, out, at) => {
|
|
129
131
|
const c = Math.cos(ang);
|
|
@@ -138,10 +140,13 @@ export function createSatellites(sets, options = {}) {
|
|
|
138
140
|
const isEccentric = new Uint8Array(n);
|
|
139
141
|
for (const i of eccentric)
|
|
140
142
|
isEccentric[i] = 1;
|
|
141
|
-
/** SGP4 for
|
|
142
|
-
const sample = (buffer, ok, ms) => {
|
|
143
|
+
/** SGP4 for satellites `from` up to (not including) `to` at one moment (the whole group by default), into `buffer` in the space view's axes (TEME x, z, -y: x to the vernal equinox, y north). */
|
|
144
|
+
const sample = (buffer, ok, ms, from = 0, to = n, skipEccentric = false) => {
|
|
143
145
|
const started = performance.now();
|
|
144
|
-
for (let i =
|
|
146
|
+
for (let i = from; i < to; i += 1) {
|
|
147
|
+
// an eccentric orbit is placed by SGP4 at every frame by `arc` and never read from a pin
|
|
148
|
+
if (skipEccentric && isEccentric[i] === 1)
|
|
149
|
+
continue;
|
|
145
150
|
const epoch = epochs[i];
|
|
146
151
|
if (Math.abs(ms - epoch) > maxAgeMs) {
|
|
147
152
|
ok[i] = 0;
|
|
@@ -198,18 +203,28 @@ export function createSatellites(sets, options = {}) {
|
|
|
198
203
|
get placed() {
|
|
199
204
|
return placed;
|
|
200
205
|
},
|
|
201
|
-
pin(ms) {
|
|
206
|
+
pin(ms, first = 0, count = n) {
|
|
202
207
|
if (n === 0)
|
|
203
208
|
return;
|
|
204
|
-
|
|
205
|
-
|
|
209
|
+
const from = Math.max(0, Math.min(n, Math.floor(first)));
|
|
210
|
+
const to = Math.max(from, Math.min(n, from + Math.floor(count)));
|
|
211
|
+
if (to === from)
|
|
212
|
+
return;
|
|
213
|
+
sample(pinned, pinOk, ms, from, to, true);
|
|
214
|
+
for (let i = from; i < to; i += 1) {
|
|
215
|
+
if (Number.isNaN(pinMsOf[i]))
|
|
216
|
+
pinnedCount += 1;
|
|
217
|
+
pinMsOf[i] = ms;
|
|
218
|
+
}
|
|
206
219
|
},
|
|
207
220
|
arc(ms, spanMs, positions, segments) {
|
|
208
221
|
if (n === 0)
|
|
209
222
|
return 0;
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
223
|
+
// a satellite never pinned is pinned now, all together
|
|
224
|
+
if (pinnedCount < n) {
|
|
225
|
+
sample(pinned, pinOk, ms, 0, n, true);
|
|
226
|
+
pinMsOf.fill(ms);
|
|
227
|
+
pinnedCount = n;
|
|
213
228
|
}
|
|
214
229
|
const span = spanMs;
|
|
215
230
|
let count = 0;
|
|
@@ -258,7 +273,7 @@ export function createSatellites(sets, options = {}) {
|
|
|
258
273
|
const ny = normal[k + 1];
|
|
259
274
|
const nz = normal[k + 2];
|
|
260
275
|
const sweep = Math.max(-Math.PI, Math.min(Math.PI, rate[i] * span));
|
|
261
|
-
const along = rate[i] * (ms -
|
|
276
|
+
const along = rate[i] * (ms - pinMsOf[i]);
|
|
262
277
|
turn(pinned[k], pinned[k + 1], pinned[k + 2], nx, ny, nz, along, positions, k);
|
|
263
278
|
turn(pinned[k], pinned[k + 1], pinned[k + 2], nx, ny, nz, along - sweep, segments, w);
|
|
264
279
|
segments[w + 3] = positions[k];
|
|
@@ -168,8 +168,11 @@ export interface Satellites {
|
|
|
168
168
|
readonly classColour: Float32Array;
|
|
169
169
|
/** The game time between the two moments SGP4 is run at (1000 to 60000 ms); the space view sets it from the clock's speed. */
|
|
170
170
|
setStep(ms: number): void;
|
|
171
|
-
/**
|
|
172
|
-
|
|
171
|
+
/**
|
|
172
|
+
* Place satellites with SGP4 at `ms` and keep that place, and the time it was kept at: every satellite, or `count` of them from index `first`, so a big group can be pinned a slice a frame instead of all in one.
|
|
173
|
+
* `arc` turns each satellite along its orbit from its own last pin. No interpolation. A satellite never pinned is pinned by the first `arc`.
|
|
174
|
+
*/
|
|
175
|
+
pin(ms: number, first?: number, count?: number): void;
|
|
173
176
|
/**
|
|
174
177
|
* The place of each satellite at `ms` into `positions` (3 numbers each) and the stretch of orbit it travels over `spanMs` of game time into `segments` (6 numbers each: where it was `spanMs` earlier, then where it is).
|
|
175
178
|
* The place is the last `pin`, turned about the orbit's axis by the mean motion, so a fast clock does not run SGP4 for every satellite on every frame. A `spanMs` that would turn it more than half a revolution is cut there. An orbit with an eccentricity of 0.02 or more is placed by SGP4 itself instead (two calls a frame), because a turn at the mean motion would put it off its path.
|