@johnmorrisdotca/chikyu-earth 0.41.0 → 0.43.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 +15 -1
- package/README.md +5 -3
- package/dist/element.d.ts +15 -0
- package/dist/element.js +21 -2
- package/dist/globe.js +7 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/markers/here-city-host.d.ts +30 -0
- package/dist/markers/here-city-host.js +105 -0
- package/dist/markers/here-city.d.ts +128 -0
- package/dist/markers/here-city.js +107 -0
- package/dist/markers/index.d.ts +1 -0
- package/dist/markers/index.js +1 -0
- package/dist/realistic/earth.d.ts +3 -0
- package/dist/realistic/earth.js +14 -0
- package/dist/realistic/element-base.d.ts +73 -1
- package/dist/realistic/element-base.js +163 -8
- package/dist/route/layer.d.ts +32 -0
- package/dist/route/layer.js +74 -0
- package/dist/route.d.ts +171 -0
- package/dist/route.js +315 -0
- package/dist/satellites/index.d.ts +1 -0
- package/dist/satellites/index.js +1 -0
- package/dist/satellites/nearest.d.ts +162 -0
- package/dist/satellites/nearest.js +249 -0
- package/dist/space/element-base.d.ts +85 -11
- package/dist/space/element-base.js +178 -12
- package/dist/space/satellite-focus.d.ts +90 -0
- package/dist/space/satellite-focus.js +109 -0
- package/dist/space/satellite-layer.d.ts +34 -3
- package/dist/space/satellite-layer.js +95 -29
- package/dist/space/scene.d.ts +14 -0
- package/dist/space/scene.js +152 -15
- package/dist/types.d.ts +5 -0
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { MAX_SATELLITE_SPEED } from "../satellites/limits.js";
|
|
2
|
-
|
|
2
|
+
import { satelliteEmphasis } from "./satellite-focus.js";
|
|
3
|
+
export const newSatelliteState = () => ({ groups: new Map(), selected: null, marked: new Set(), pinned: [], orbitTint: false, focus: null, drawn: { placed: 0, segments: 0, tooFast: false, dotScale: 1, updateMs: 0, maxUpdateMs: 0, updates: 0, totalMs: 0 } });
|
|
3
4
|
/** The most orbits a group may draw all at once, one line each. */
|
|
4
5
|
export const MAX_ORBIT_GROUP = 40;
|
|
5
6
|
const ORBIT_POINTS = 120;
|
|
@@ -7,12 +8,13 @@ const ORBIT_REFRESH_GAME_MS = 30 * 60_000;
|
|
|
7
8
|
const ORBIT_REFRESH_WALL_MS = 1000;
|
|
8
9
|
const POINT_VERT = /* glsl */ `
|
|
9
10
|
uniform float size;
|
|
11
|
+
uniform float groupDim;
|
|
10
12
|
attribute float dim;
|
|
11
13
|
attribute vec3 cls;
|
|
12
14
|
varying float vDim;
|
|
13
15
|
varying vec3 vCls;
|
|
14
16
|
void main() {
|
|
15
|
-
vDim = dim;
|
|
17
|
+
vDim = max(dim, groupDim);
|
|
16
18
|
vCls = cls;
|
|
17
19
|
gl_PointSize = size;
|
|
18
20
|
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
@@ -68,6 +70,40 @@ export function pinPlan(count, next, elapsedMs) {
|
|
|
68
70
|
runs.push([0, slice - part]);
|
|
69
71
|
return { runs, next: (first + slice) % count };
|
|
70
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Which edge of a box a point lies beyond. A corner goes to the edge it passes by more. Inside the box, `null`.
|
|
75
|
+
*
|
|
76
|
+
* @param x - CSS pixels from the left.
|
|
77
|
+
* @param y - CSS pixels from the top.
|
|
78
|
+
* @param width - The box width.
|
|
79
|
+
* @param height - The box height.
|
|
80
|
+
* @returns The edge, or `null` when the point is inside.
|
|
81
|
+
*/
|
|
82
|
+
export function screenEdge(x, y, width, height) {
|
|
83
|
+
const left = Math.max(0, -x);
|
|
84
|
+
const right = Math.max(0, x - width);
|
|
85
|
+
const top = Math.max(0, -y);
|
|
86
|
+
const bottom = Math.max(0, y - height);
|
|
87
|
+
const dx = Math.max(left, right);
|
|
88
|
+
const dy = Math.max(top, bottom);
|
|
89
|
+
if (dx === 0 && dy === 0)
|
|
90
|
+
return null;
|
|
91
|
+
if (dx >= dy)
|
|
92
|
+
return left > 0 ? "left" : "right";
|
|
93
|
+
return top > 0 ? "top" : "bottom";
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Which edge a point lies beyond, from the camera's own axes: `x` to the right, `y` up. Used when the point is behind the camera, whose picture would otherwise mirror it.
|
|
97
|
+
*
|
|
98
|
+
* @param x - To the camera's right.
|
|
99
|
+
* @param y - Up, in the camera's axes.
|
|
100
|
+
* @returns The edge.
|
|
101
|
+
*/
|
|
102
|
+
export function edgeBeyondCamera(x, y) {
|
|
103
|
+
if (Math.abs(x) >= Math.abs(y))
|
|
104
|
+
return x < 0 ? "left" : "right";
|
|
105
|
+
return y >= 0 ? "top" : "bottom";
|
|
106
|
+
}
|
|
71
107
|
export function createSatelliteLayer(three, scene, state, ratio) {
|
|
72
108
|
if (!three.Points)
|
|
73
109
|
throw new Error("Satellites need `Points` from three.js: add it to the parts the three loader hands over (see setThreeLoader)");
|
|
@@ -89,7 +125,7 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
89
125
|
const ink = new three.Color();
|
|
90
126
|
let basis = 0;
|
|
91
127
|
let lastGame = 0;
|
|
92
|
-
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 } }, transparent: true, depthWrite: false });
|
|
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 });
|
|
93
129
|
const selectedPosition = new Float32Array(3);
|
|
94
130
|
const selectedGeometry = new three.BufferGeometry();
|
|
95
131
|
selectedGeometry.setAttribute("position", new three.BufferAttribute(selectedPosition, 3));
|
|
@@ -190,7 +226,7 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
190
226
|
const dim = new three.BufferAttribute(group.satellites.dimmed, 1);
|
|
191
227
|
geometry.setAttribute("dim", dim);
|
|
192
228
|
geometry.setAttribute("cls", new three.BufferAttribute(group.satellites.classColour, 3));
|
|
193
|
-
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 } }, transparent: true, depthWrite: false });
|
|
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 });
|
|
194
230
|
const points = new Points(geometry, material);
|
|
195
231
|
points.frustumCulled = false;
|
|
196
232
|
points.renderOrder = 5;
|
|
@@ -234,15 +270,21 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
234
270
|
if (entry.streak)
|
|
235
271
|
entry.streak.geometry.getAttribute("color").needsUpdate = true;
|
|
236
272
|
}
|
|
237
|
-
const
|
|
273
|
+
const choice = satelliteEmphasis(name, group.visible, state.focus);
|
|
274
|
+
const show = choice.drawn;
|
|
275
|
+
entry.material.uniforms["groupDim"].value = choice.dim;
|
|
238
276
|
entry.points.visible = show;
|
|
239
277
|
if (!show) {
|
|
278
|
+
group.placed = 0;
|
|
240
279
|
if (entry.streak)
|
|
241
280
|
entry.streak.visible = false;
|
|
242
281
|
for (const line of entry.lines)
|
|
243
282
|
line.loop.visible = false;
|
|
244
283
|
continue;
|
|
245
284
|
}
|
|
285
|
+
const dimmed = choice.dim > 0;
|
|
286
|
+
if (entry.streak)
|
|
287
|
+
entry.streak.material.opacity = dimmed ? 0.3 : 0.95;
|
|
246
288
|
if (tooFast) {
|
|
247
289
|
// 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,
|
|
248
290
|
// so SGP4 never runs for the whole group (17,000 satellites take about 12 ms) in one frame
|
|
@@ -274,6 +316,7 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
274
316
|
for (const line of entry.lines)
|
|
275
317
|
line.loop.visible = false;
|
|
276
318
|
placed += n;
|
|
319
|
+
group.placed = n;
|
|
277
320
|
if (entry.streak)
|
|
278
321
|
segments += n;
|
|
279
322
|
}
|
|
@@ -289,12 +332,18 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
289
332
|
entry.dim.needsUpdate = true;
|
|
290
333
|
}
|
|
291
334
|
placed += group.satellites.placed;
|
|
335
|
+
group.placed = group.satellites.placed;
|
|
292
336
|
orbitsOf(entry, group, time, started);
|
|
337
|
+
const opacity = dimmed ? 0.15 : 0.45;
|
|
338
|
+
for (const line of entry.lines)
|
|
339
|
+
line.loop.material.opacity = opacity;
|
|
293
340
|
}
|
|
294
341
|
}
|
|
295
342
|
const chosen = state.selected;
|
|
343
|
+
const chosenGroup = chosen ? state.groups.get(chosen.group) : undefined;
|
|
344
|
+
const chosenDrawn = chosen !== null && chosenGroup !== undefined && satelliteEmphasis(chosen.group, chosenGroup.visible, state.focus).drawn;
|
|
296
345
|
const set = chosen ? find(chosen) : undefined;
|
|
297
|
-
if (chosen && set && set.exact(chosen.index, time, tmp)) {
|
|
346
|
+
if (chosen && set && chosenDrawn && set.exact(chosen.index, time, tmp)) {
|
|
298
347
|
selectedPosition[0] = tmp[0];
|
|
299
348
|
selectedPosition[1] = tmp[1];
|
|
300
349
|
selectedPosition[2] = tmp[2];
|
|
@@ -397,32 +446,49 @@ export function createSatelliteLayer(three, scene, state, ratio) {
|
|
|
397
446
|
const i = ref.index * 3;
|
|
398
447
|
world.set(p[i], p[i + 1], p[i + 2]).applyMatrix4(scene.matrixWorld);
|
|
399
448
|
const heightKm = (Math.hypot(p[i], p[i + 1], p[i + 2]) - 1) * 6371;
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
return null;
|
|
403
|
-
const x = ((projected.x + 1) / 2) * size.width;
|
|
404
|
-
const y = ((1 - projected.y) / 2) * size.height;
|
|
449
|
+
// the camera looks down its own -z, so a point in front has a negative z. A point behind would be mirrored by the picture, so its edge is read from these axes.
|
|
450
|
+
view.copy(world).applyMatrix4(camera.matrixWorldInverse);
|
|
405
451
|
const ortho = camera.isOrthographicCamera === true;
|
|
406
|
-
const
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
452
|
+
const behind = !ortho && view.z > 0;
|
|
453
|
+
projected.copy(world).project(camera);
|
|
454
|
+
let x = Number.isFinite(projected.x) ? ((projected.x + 1) / 2) * size.width : size.width / 2;
|
|
455
|
+
let y = Number.isFinite(projected.y) ? ((1 - projected.y) / 2) * size.height : size.height / 2;
|
|
456
|
+
const edge = behind ? edgeBeyondCamera(view.x, view.y) : screenEdge(x, y, size.width, size.height);
|
|
457
|
+
if (behind) {
|
|
458
|
+
if (edge === "left")
|
|
459
|
+
x = -1;
|
|
460
|
+
else if (edge === "right")
|
|
461
|
+
x = size.width + 1;
|
|
462
|
+
else if (edge === "top")
|
|
463
|
+
y = -1;
|
|
464
|
+
else
|
|
465
|
+
y = size.height + 1;
|
|
412
466
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
467
|
+
const c = camera.position;
|
|
468
|
+
let hidden = false;
|
|
469
|
+
if (!behind) {
|
|
470
|
+
if (ortho) {
|
|
471
|
+
const right = view.x;
|
|
472
|
+
const up = view.y;
|
|
473
|
+
const depth = view.z;
|
|
474
|
+
const centreDepth = world.set(0, 0, 0).applyMatrix4(camera.matrixWorldInverse).z;
|
|
475
|
+
hidden = depth < centreDepth && right * right + up * up < 0.996;
|
|
476
|
+
world.set(p[i], p[i + 1], p[i + 2]).applyMatrix4(scene.matrixWorld);
|
|
477
|
+
}
|
|
478
|
+
else {
|
|
479
|
+
// behind the Earth: the line from the camera to the satellite passes through the unit sphere before it gets there
|
|
480
|
+
const px = world.x - c.x;
|
|
481
|
+
const py = world.y - c.y;
|
|
482
|
+
const pz = world.z - c.z;
|
|
483
|
+
const len2 = px * px + py * py + pz * pz;
|
|
484
|
+
const t = Math.max(0, Math.min(1, -(c.x * px + c.y * py + c.z * pz) / len2));
|
|
485
|
+
const nx = c.x + px * t;
|
|
486
|
+
const ny = c.y + py * t;
|
|
487
|
+
const nz = c.z + pz * t;
|
|
488
|
+
hidden = nx * nx + ny * ny + nz * nz < 0.998;
|
|
489
|
+
}
|
|
424
490
|
}
|
|
425
|
-
return { x, y, visible: !
|
|
491
|
+
return { x, y, visible: !behind && !hidden && edge === null, heightKm, edge, behind };
|
|
426
492
|
},
|
|
427
493
|
place(camera, size) {
|
|
428
494
|
if (!selectedPoints.visible)
|
package/dist/space/scene.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ import { type BodyLabelState } from "../realistic/body-label.ts";
|
|
|
18
18
|
import { type MeteorState } from "../meteors/layer.ts";
|
|
19
19
|
import { type BorderState } from "../borders/layer.ts";
|
|
20
20
|
import { type GridState } from "../grid/layer.ts";
|
|
21
|
+
import { type RouteState } from "../route/layer.ts";
|
|
21
22
|
type Three = ThreeParts;
|
|
22
23
|
/** 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. */
|
|
23
24
|
export declare const DEFAULT_EARTH_SIZE = 0.9;
|
|
@@ -53,6 +54,15 @@ export declare function fitDistance(size: number, aspect: number): number;
|
|
|
53
54
|
export type CameraMode = "ground" | "space" | "sun";
|
|
54
55
|
/** A moon that has been out of sight this long is let go (its pictures too). */
|
|
55
56
|
export declare const MOON_KEEP_MS = 4000;
|
|
57
|
+
/**
|
|
58
|
+
* A body of the Sun, the Moon and the planets is made by the painter (and so gets its mapped picture) only when it is in the view and at least this many CSS pixels across its radius; a smaller one, or one out of the view, is a plain sphere of the right colour (the Moon, the view's own Moon).
|
|
59
|
+
* It is let go (its pictures with it) once it has been smaller than `BODY_LET_GO_PX`, or out of the view, for `BODY_KEEP_MS`.
|
|
60
|
+
*/
|
|
61
|
+
export declare const BODY_MAKE_PX = 6;
|
|
62
|
+
export declare const BODY_LET_GO_PX = 3;
|
|
63
|
+
export declare const BODY_KEEP_MS = 4000;
|
|
64
|
+
/** For a reader who asked for reduced motion, the pictures that arrive within this time of one that was drawn ask for one draw between them (none at all while the clock steps). */
|
|
65
|
+
export declare const ARRIVAL_GATHER_MS = 1000;
|
|
56
66
|
/**
|
|
57
67
|
* The eleven bodies the space view places, names and lets a reader choose: the Earth, the Sun, the Moon, the seven other planets and Pluto.
|
|
58
68
|
*
|
|
@@ -159,6 +169,8 @@ export interface SpaceModel {
|
|
|
159
169
|
held: number;
|
|
160
170
|
moon: boolean;
|
|
161
171
|
tiles: number;
|
|
172
|
+
mapped: number;
|
|
173
|
+
pending: number;
|
|
162
174
|
};
|
|
163
175
|
/** How many times astronomy-engine has been asked for a frame. */
|
|
164
176
|
lookups: number;
|
|
@@ -174,6 +186,8 @@ export interface SpaceModel {
|
|
|
174
186
|
borders: BorderState;
|
|
175
187
|
/** The meridians and parallels on the Earth (src/grid/layer.ts): off unless the element switches them on. */
|
|
176
188
|
grid: GridState;
|
|
189
|
+
/** A route between two places, on the Earth (src/route/layer.ts): off unless the element sets it. */
|
|
190
|
+
route: RouteState;
|
|
177
191
|
/** The body or satellite the camera rides along with, or null. */
|
|
178
192
|
ride: RideState | null;
|
|
179
193
|
/** Set at each draw: the target of the ride could not be placed (a satellite whose elements are too old, or that is gone), so the ordinary camera was used. */
|
package/dist/space/scene.js
CHANGED
|
@@ -16,6 +16,7 @@ import { createBodyLabelLayer, newBodyLabelState } from "../realistic/body-label
|
|
|
16
16
|
import { createMeteorLayer, newMeteorState } from "../meteors/layer.js";
|
|
17
17
|
import { createBorderLayer, newBorderState } from "../borders/layer.js";
|
|
18
18
|
import { createGridLayer, newGridState } from "../grid/layer.js";
|
|
19
|
+
import { createRouteLayer, newRouteState } from "../route/layer.js";
|
|
19
20
|
import { subsolarPoint, unitVector } from "../realistic/sun.js";
|
|
20
21
|
/** The most satellites ringed and named at once, over all the labelled groups. */
|
|
21
22
|
const MAX_MARKED = 80;
|
|
@@ -48,6 +49,15 @@ const MOON_MIN_PLANET_PX = 4;
|
|
|
48
49
|
const MOON_MIN_PX = 2.2;
|
|
49
50
|
/** A moon that has been out of sight this long is let go (its pictures too). */
|
|
50
51
|
export const MOON_KEEP_MS = 4000;
|
|
52
|
+
/**
|
|
53
|
+
* A body of the Sun, the Moon and the planets is made by the painter (and so gets its mapped picture) only when it is in the view and at least this many CSS pixels across its radius; a smaller one, or one out of the view, is a plain sphere of the right colour (the Moon, the view's own Moon).
|
|
54
|
+
* It is let go (its pictures with it) once it has been smaller than `BODY_LET_GO_PX`, or out of the view, for `BODY_KEEP_MS`.
|
|
55
|
+
*/
|
|
56
|
+
export const BODY_MAKE_PX = 6;
|
|
57
|
+
export const BODY_LET_GO_PX = 3;
|
|
58
|
+
export const BODY_KEEP_MS = MOON_KEEP_MS;
|
|
59
|
+
/** For a reader who asked for reduced motion, the pictures that arrive within this time of one that was drawn ask for one draw between them (none at all while the clock steps). */
|
|
60
|
+
export const ARRIVAL_GATHER_MS = 1000;
|
|
51
61
|
const PLAIN_COLOR = (name) => (name === "Sun" ? "#ffb347" : COLORS[name] ?? "#9a948b");
|
|
52
62
|
/**
|
|
53
63
|
* The eleven bodies the space view places, names and lets a reader choose: the Earth, the Sun, the Moon, the seven other planets and Pluto.
|
|
@@ -80,7 +90,7 @@ export const newSpaceModel = () => ({
|
|
|
80
90
|
bodies: "",
|
|
81
91
|
light: "sun",
|
|
82
92
|
drawn: null,
|
|
83
|
-
painted: { bodies: 0, moons: 0, held: 0, moon: false, tiles: 0 },
|
|
93
|
+
painted: { bodies: 0, moons: 0, held: 0, moon: false, tiles: 0, mapped: 0, pending: 0 },
|
|
84
94
|
lookups: 0,
|
|
85
95
|
speed: 1,
|
|
86
96
|
ride: null,
|
|
@@ -98,6 +108,7 @@ export const newSpaceModel = () => ({
|
|
|
98
108
|
bodyLabel: newBodyLabelState(),
|
|
99
109
|
borders: newBorderState(),
|
|
100
110
|
grid: newGridState(),
|
|
111
|
+
route: newRouteState(),
|
|
101
112
|
pick: null,
|
|
102
113
|
placeSatellite: null,
|
|
103
114
|
followModel: null,
|
|
@@ -168,11 +179,42 @@ export function createSpaceItem(model, deps) {
|
|
|
168
179
|
key: "chikyu-earth:space",
|
|
169
180
|
async build({ three, width, height }) {
|
|
170
181
|
let size = { width, height };
|
|
182
|
+
let ended = false;
|
|
183
|
+
// Pictures arrive one by one (the Earth's maps, its finer tiles, a body's), each asking for a draw. For a reader who asked for reduced motion they are gathered, to at most one draw a second: while the clock steps
|
|
184
|
+
// (at least once a second) the next step shows them, so they ask for nothing; at rest, one after a quiet second is drawn at once and those that follow within the second ask for one draw when it ends.
|
|
185
|
+
let arrivalAt = Number.NEGATIVE_INFINITY;
|
|
186
|
+
let arrivalTimer;
|
|
187
|
+
const arrivalDraw = () => {
|
|
188
|
+
if (!(typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches)) {
|
|
189
|
+
deps.invalidate();
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
// real time steps once a minute unless something rides, so it is gathered like rest
|
|
193
|
+
if (model.speed !== 0 && (model.speed !== 1 || model.ride !== null))
|
|
194
|
+
return;
|
|
195
|
+
if (arrivalTimer !== undefined)
|
|
196
|
+
return;
|
|
197
|
+
const now = performance.now();
|
|
198
|
+
if (now - arrivalAt >= ARRIVAL_GATHER_MS) {
|
|
199
|
+
arrivalAt = now;
|
|
200
|
+
deps.invalidate();
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
model.painted.pending += 1;
|
|
204
|
+
arrivalTimer = setTimeout(() => {
|
|
205
|
+
arrivalTimer = undefined;
|
|
206
|
+
if (ended)
|
|
207
|
+
return;
|
|
208
|
+
model.painted.pending -= 1;
|
|
209
|
+
arrivalAt = performance.now();
|
|
210
|
+
deps.invalidate();
|
|
211
|
+
}, arrivalAt + ARRIVAL_GATHER_MS - now);
|
|
212
|
+
};
|
|
171
213
|
const textures = await createTextureSet(three, LAYERS, {
|
|
172
214
|
assets: deps.assets,
|
|
173
215
|
textureBase: deps.textureBase,
|
|
174
216
|
cap: deps.cap,
|
|
175
|
-
invalidate:
|
|
217
|
+
invalidate: arrivalDraw,
|
|
176
218
|
...(deps.onError ? { onError: deps.onError } : {}),
|
|
177
219
|
...(deps.onTier ? { onTier: deps.onTier } : {}),
|
|
178
220
|
});
|
|
@@ -210,7 +252,7 @@ export function createSpaceItem(model, deps) {
|
|
|
210
252
|
});
|
|
211
253
|
const earth = new three.Mesh(grid, earthMaterial);
|
|
212
254
|
// the finer map tiles, laid over the Earth's own picture where the camera is near enough to need them (they turn with the Earth: they are its children)
|
|
213
|
-
const tiles = createTileSet(three, earth, { sunDir: sunEarth, lights: earthMaterial.uniforms["lights"], boost: earthMaterial.uniforms["boost"], ortho: earthMaterial.uniforms["ortho"], water: uniform.water, night: uniform.night, extra: { cloudMap: uniform.clouds, sunLocal, cloudShift } }, { assets: deps.assets, sources: () => deps.sources?.() ?? {}, cap: deps.cap, invalidate:
|
|
255
|
+
const tiles = createTileSet(three, earth, { sunDir: sunEarth, lights: earthMaterial.uniforms["lights"], boost: earthMaterial.uniforms["boost"], ortho: earthMaterial.uniforms["ortho"], water: uniform.water, night: uniform.night, extra: { cloudMap: uniform.clouds, sunLocal, cloudShift } }, { assets: deps.assets, sources: () => deps.sources?.() ?? {}, cap: deps.cap, invalidate: arrivalDraw, ...(deps.onTiles ? { onManifest: deps.onTiles } : {}) });
|
|
214
256
|
model.tiles = tiles;
|
|
215
257
|
const clouds = new three.Mesh(grid, cloudMaterial);
|
|
216
258
|
clouds.scale.setScalar(1.006);
|
|
@@ -224,9 +266,20 @@ export function createSpaceItem(model, deps) {
|
|
|
224
266
|
const painter = deps.painter ?? plainPainter;
|
|
225
267
|
const scene = new three.Scene();
|
|
226
268
|
scene.add(earth, clouds, glow, moon);
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
const
|
|
269
|
+
const newSlot = (name) => ({ name, drawing: undefined, look: null, token: 0, plain: false, small: true, bigAt: 0, mapped: false });
|
|
270
|
+
/** How many drawings the painter's pictures are on now: told to the element, which writes the painter's credit only while there are any. */
|
|
271
|
+
const tally = () => {
|
|
272
|
+
let mapped = sunSlot.mapped ? 1 : 0;
|
|
273
|
+
if (moonSlot.mapped)
|
|
274
|
+
mapped += 1;
|
|
275
|
+
for (const p of planets.values())
|
|
276
|
+
if (p.slot.mapped)
|
|
277
|
+
mapped += 1;
|
|
278
|
+
for (const held of moonSlots.values())
|
|
279
|
+
if (held.slot.mapped)
|
|
280
|
+
mapped += 1;
|
|
281
|
+
model.painted.mapped = mapped;
|
|
282
|
+
};
|
|
230
283
|
const lookNow = () => model.bodies || painter.looks?.[0] || "";
|
|
231
284
|
const empty = (slot) => {
|
|
232
285
|
slot.token += 1;
|
|
@@ -235,23 +288,28 @@ export function createSpaceItem(model, deps) {
|
|
|
235
288
|
scene.remove(slot.drawing.object);
|
|
236
289
|
slot.drawing.dispose();
|
|
237
290
|
slot.drawing = undefined;
|
|
291
|
+
slot.mapped = false;
|
|
238
292
|
};
|
|
239
293
|
const fill = (slot, isMoon = false) => {
|
|
240
294
|
const look = lookNow();
|
|
241
|
-
|
|
295
|
+
const key = slot.small && !isMoon ? `small|${look}` : look;
|
|
296
|
+
if (slot.look === key)
|
|
242
297
|
return;
|
|
243
298
|
empty(slot);
|
|
244
|
-
slot.look =
|
|
299
|
+
slot.look = key;
|
|
245
300
|
const token = slot.token;
|
|
301
|
+
const viaPainter = !(slot.plain || look === "plain" || (slot.small && !isMoon));
|
|
246
302
|
const arrive = (made) => {
|
|
247
303
|
if (ended || slot.token !== token) {
|
|
248
304
|
made.dispose();
|
|
249
305
|
return;
|
|
250
306
|
}
|
|
251
307
|
slot.drawing = made;
|
|
308
|
+
slot.mapped = viaPainter;
|
|
252
309
|
scene.add(made.object);
|
|
310
|
+
tally();
|
|
253
311
|
deps.onBodies?.();
|
|
254
|
-
|
|
312
|
+
arrivalDraw();
|
|
255
313
|
};
|
|
256
314
|
const fail = (error) => {
|
|
257
315
|
if (ended || slot.token !== token)
|
|
@@ -264,9 +322,20 @@ export function createSpaceItem(model, deps) {
|
|
|
264
322
|
}
|
|
265
323
|
};
|
|
266
324
|
try {
|
|
267
|
-
const made = (
|
|
268
|
-
if (typeof made.then === "function")
|
|
269
|
-
|
|
325
|
+
const made = (viaPainter ? painter : plainPainter).make(three, slot.name, { look, invalidate: () => (deps.onBodies?.(), arrivalDraw()), ratio: model.ratio(), maxTexture: deps.cap(), mapped: true });
|
|
326
|
+
if (typeof made.then === "function") {
|
|
327
|
+
// a picture asked for and not yet here is counted, so a page (a test) can tell that more draws are still to come
|
|
328
|
+
model.painted.pending += 1;
|
|
329
|
+
made.then((drawing) => {
|
|
330
|
+
if (!ended)
|
|
331
|
+
model.painted.pending -= 1;
|
|
332
|
+
arrive(drawing);
|
|
333
|
+
}, (error) => {
|
|
334
|
+
if (!ended)
|
|
335
|
+
model.painted.pending -= 1;
|
|
336
|
+
fail(error);
|
|
337
|
+
});
|
|
338
|
+
}
|
|
270
339
|
else
|
|
271
340
|
arrive(made);
|
|
272
341
|
}
|
|
@@ -289,12 +358,15 @@ export function createSpaceItem(model, deps) {
|
|
|
289
358
|
}
|
|
290
359
|
const moonSlots = new Map();
|
|
291
360
|
let releaseTimer;
|
|
361
|
+
/** Asks for one more draw when a body that has shrunk or gone from the view is due to be let go (a view at rest draws nothing, so it would be kept for ever). */
|
|
362
|
+
let bodyTimer;
|
|
292
363
|
let meteors = null;
|
|
293
364
|
let meteorTimer;
|
|
294
365
|
let nameOn = null;
|
|
295
366
|
let borders = null;
|
|
296
367
|
const placeRings = { sprites: null, tried: false };
|
|
297
368
|
let gridLayer = null;
|
|
369
|
+
let routeLayer = null;
|
|
298
370
|
let marksTold = false;
|
|
299
371
|
// the followed satellite's model: which satellite it is for, the drawing once it is made, and a count so that a model made for a satellite no longer followed is let go
|
|
300
372
|
const modelSlot = { key: "", drawing: null, turn: 0, parts: 0 };
|
|
@@ -379,11 +451,13 @@ export function createSpaceItem(model, deps) {
|
|
|
379
451
|
for (const name of PLANETS)
|
|
380
452
|
pos[name] = placeAround(mode, sunPos, helioOf(frame.planets[name]));
|
|
381
453
|
const radiusOf = (name) => (name === "Earth" ? 1 : RADIUS[name][mode]);
|
|
382
|
-
if (deps.painter && lookNow() !== "plain")
|
|
454
|
+
if (deps.painter && lookNow() !== "plain" && !moonSlot.small)
|
|
383
455
|
fill(moonSlot, true);
|
|
384
456
|
else if (moonSlot.look !== null) {
|
|
385
457
|
empty(moonSlot);
|
|
386
458
|
moonSlot.look = null;
|
|
459
|
+
tally();
|
|
460
|
+
deps.onBodies?.();
|
|
387
461
|
}
|
|
388
462
|
const paintedMoon = moonSlot.drawing;
|
|
389
463
|
if (paintedMoon) {
|
|
@@ -600,6 +674,44 @@ export function createSpaceItem(model, deps) {
|
|
|
600
674
|
px[name] = radiusPxOf(name);
|
|
601
675
|
model.drawn = { frame, distance, radiusPx: px.Earth };
|
|
602
676
|
layer?.resize(px.Earth);
|
|
677
|
+
// which bodies get their mapped pictures: those in the view and big enough to show a map. The others are plain spheres (the Moon, the view's own) and the painter is not asked for them, so it loads and holds nothing for a body too small to see.
|
|
678
|
+
// The choice is made here, from this draw's sizes, and acted on at the next (a body that changes asks for it); a body that has shrunk or gone is let go after `BODY_KEEP_MS`, so one that comes and goes is not made again and again.
|
|
679
|
+
{
|
|
680
|
+
const at = performance.now();
|
|
681
|
+
let changed = false;
|
|
682
|
+
let soonest = Number.POSITIVE_INFINITY;
|
|
683
|
+
const judge = (name, slot) => {
|
|
684
|
+
projected.set(pos[name][0], pos[name][1], pos[name][2]).project(camera);
|
|
685
|
+
const reach = Math.min(px[name], 1e5);
|
|
686
|
+
const inView = reach >= 1e5 || (projected.z > -1 && projected.z < 1 && Math.abs(projected.x) * (size.width / 2) <= size.width / 2 + reach && Math.abs(projected.y) * (size.height / 2) <= size.height / 2 + reach);
|
|
687
|
+
if (slot.small) {
|
|
688
|
+
if (inView && px[name] >= BODY_MAKE_PX) {
|
|
689
|
+
slot.small = false;
|
|
690
|
+
slot.bigAt = at;
|
|
691
|
+
changed = true;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
else if (inView && px[name] >= BODY_LET_GO_PX)
|
|
695
|
+
slot.bigAt = at;
|
|
696
|
+
else if (at - slot.bigAt > BODY_KEEP_MS) {
|
|
697
|
+
slot.small = true;
|
|
698
|
+
changed = true;
|
|
699
|
+
}
|
|
700
|
+
else
|
|
701
|
+
soonest = Math.min(soonest, slot.bigAt + BODY_KEEP_MS - at);
|
|
702
|
+
};
|
|
703
|
+
if (deps.painter && lookNow() !== "plain") {
|
|
704
|
+
judge("Sun", sunSlot);
|
|
705
|
+
judge("Moon", moonSlot);
|
|
706
|
+
for (const name of PLANETS)
|
|
707
|
+
judge(name, planets.get(name).slot);
|
|
708
|
+
}
|
|
709
|
+
if (bodyTimer !== undefined)
|
|
710
|
+
clearTimeout(bodyTimer);
|
|
711
|
+
bodyTimer = soonest < Number.POSITIVE_INFINITY ? setTimeout(() => deps.invalidate(), soonest + 50) : undefined;
|
|
712
|
+
if (changed)
|
|
713
|
+
deps.invalidate();
|
|
714
|
+
}
|
|
603
715
|
// the finer map tiles: the camera as the Earth's own axes have it, so a camera a few kilometres up asks for the tiles under it at the level its height needs
|
|
604
716
|
{
|
|
605
717
|
// the Earth is turned about the y axis and sits at the origin, so its own axes are the world's turned back by that angle
|
|
@@ -640,7 +752,7 @@ export function createSpaceItem(model, deps) {
|
|
|
640
752
|
for (const drawing of [sunSlot.drawing, moonSlot.drawing, ...[...planets.values()].map((p) => p.slot.drawing), ...[...moonSlots.values()].map((held) => held.slot.drawing)])
|
|
641
753
|
if (drawing?.tiles?.shown != null)
|
|
642
754
|
tiled += 1;
|
|
643
|
-
model.painted = { bodies: paintedBodies, moons: paintedMoons, held: 0, moon: paintedMoon !== undefined, tiles: tiled };
|
|
755
|
+
model.painted = { bodies: paintedBodies, moons: paintedMoons, held: 0, moon: paintedMoon !== undefined, tiles: tiled, mapped: model.painted.mapped, pending: model.painted.pending };
|
|
644
756
|
// 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
|
|
645
757
|
const satellitePainter = deps.satellitePainter?.();
|
|
646
758
|
const group = followed ? model.satellites.groups.get(followed.ref.group) : undefined;
|
|
@@ -766,7 +878,7 @@ export function createSpaceItem(model, deps) {
|
|
|
766
878
|
// the ringed satellites first, so their names are laid out with the places' in this same draw
|
|
767
879
|
model.placeSatellite = layer ? (ref) => layer.placeOf(ref, camera, size) : null;
|
|
768
880
|
if (deps.onSatelliteMarks) {
|
|
769
|
-
if (layer && model.satellites.marked.size > 0) {
|
|
881
|
+
if (layer && (model.satellites.marked.size > 0 || model.satellites.pinned.length > 0)) {
|
|
770
882
|
const marks = [];
|
|
771
883
|
for (const name of model.satellites.marked) {
|
|
772
884
|
const group = model.satellites.groups.get(name);
|
|
@@ -779,6 +891,15 @@ export function createSpaceItem(model, deps) {
|
|
|
779
891
|
marks.push({ ref, ...at });
|
|
780
892
|
}
|
|
781
893
|
}
|
|
894
|
+
for (const ref of model.satellites.pinned) {
|
|
895
|
+
if (marks.length >= MAX_MARKED)
|
|
896
|
+
break;
|
|
897
|
+
if (marks.some((mark) => mark.ref.group === ref.group && mark.ref.index === ref.index))
|
|
898
|
+
continue;
|
|
899
|
+
const at = layer.placeOf(ref, camera, size);
|
|
900
|
+
if (at)
|
|
901
|
+
marks.push({ ref, ...at });
|
|
902
|
+
}
|
|
782
903
|
marksTold = true;
|
|
783
904
|
deps.onSatelliteMarks(marks);
|
|
784
905
|
}
|
|
@@ -950,6 +1071,16 @@ export function createSpaceItem(model, deps) {
|
|
|
950
1071
|
}
|
|
951
1072
|
}
|
|
952
1073
|
gridLayer?.sync(Math.min(px.Earth, 1e5));
|
|
1074
|
+
if ((model.route.ends || routeLayer) && !routeLayer && !model.route.failed) {
|
|
1075
|
+
try {
|
|
1076
|
+
routeLayer = createRouteLayer(three, earth, model.route);
|
|
1077
|
+
}
|
|
1078
|
+
catch (error) {
|
|
1079
|
+
model.route.failed = true;
|
|
1080
|
+
console.warn(error instanceof Error ? error.message : error);
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
routeLayer?.sync();
|
|
953
1084
|
if (model.rideLost)
|
|
954
1085
|
deps.onRideLost?.();
|
|
955
1086
|
if (model.transition)
|
|
@@ -962,6 +1093,10 @@ export function createSpaceItem(model, deps) {
|
|
|
962
1093
|
dispose() {
|
|
963
1094
|
if (releaseTimer !== undefined)
|
|
964
1095
|
clearTimeout(releaseTimer);
|
|
1096
|
+
if (bodyTimer !== undefined)
|
|
1097
|
+
clearTimeout(bodyTimer);
|
|
1098
|
+
if (arrivalTimer !== undefined)
|
|
1099
|
+
clearTimeout(arrivalTimer);
|
|
965
1100
|
if (meteorTimer !== undefined)
|
|
966
1101
|
clearTimeout(meteorTimer);
|
|
967
1102
|
meteors?.dispose();
|
|
@@ -969,6 +1104,7 @@ export function createSpaceItem(model, deps) {
|
|
|
969
1104
|
borders?.dispose();
|
|
970
1105
|
placeRings.sprites?.dispose();
|
|
971
1106
|
gridLayer?.dispose();
|
|
1107
|
+
routeLayer?.dispose();
|
|
972
1108
|
modelSlot.turn += 1;
|
|
973
1109
|
dropModel();
|
|
974
1110
|
layer?.dispose();
|
|
@@ -978,6 +1114,7 @@ export function createSpaceItem(model, deps) {
|
|
|
978
1114
|
tiles.dispose();
|
|
979
1115
|
textures.dispose();
|
|
980
1116
|
ended = true;
|
|
1117
|
+
model.painted.pending = 0;
|
|
981
1118
|
empty(sunSlot);
|
|
982
1119
|
empty(moonSlot);
|
|
983
1120
|
for (const held of moonSlots.values())
|
package/dist/types.d.ts
CHANGED
|
@@ -86,4 +86,9 @@ export interface GlobeOptions {
|
|
|
86
86
|
style?: StyleName;
|
|
87
87
|
/** Draw a light graticule under the countries. Default false. */
|
|
88
88
|
graticule?: boolean;
|
|
89
|
+
/** A route between two places, drawn over the countries. Absent, none. */
|
|
90
|
+
route?: {
|
|
91
|
+
from: GeoPoint;
|
|
92
|
+
to: GeoPoint;
|
|
93
|
+
} | null;
|
|
89
94
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/chikyu-earth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.43.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",
|