@johnmorrisdotca/chikyu-earth 0.34.1 → 0.36.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 +20 -0
- package/NOTICE.md +23 -1
- package/README.md +20 -2
- package/dist/borders/layer.d.ts +75 -0
- package/dist/borders/layer.js +136 -0
- package/dist/borders/lines.d.ts +138 -0
- package/dist/borders/lines.js +227 -0
- package/dist/cities/host.d.ts +9 -0
- package/dist/cities/host.js +14 -2
- package/dist/country-names/geometry.d.ts +264 -0
- package/dist/country-names/geometry.js +372 -0
- package/dist/country-names/host.d.ts +82 -0
- package/dist/country-names/host.js +212 -0
- package/dist/grid/layer.d.ts +45 -0
- package/dist/grid/layer.js +66 -0
- package/dist/grid/lines.d.ts +85 -0
- package/dist/grid/lines.js +113 -0
- package/dist/markers/go-to-place.d.ts +27 -0
- package/dist/markers/go-to-place.js +35 -0
- package/dist/markers/index.d.ts +2 -1
- package/dist/markers/index.js +2 -1
- package/dist/markers/layer.d.ts +7 -0
- package/dist/markers/layer.js +7 -0
- package/dist/markers/place-layer.d.ts +58 -7
- package/dist/markers/place-layer.js +326 -64
- package/dist/markers/place-sprites.d.ts +33 -0
- package/dist/markers/place-sprites.js +161 -0
- package/dist/markers/places.d.ts +91 -6
- package/dist/markers/places.js +135 -6
- package/dist/realistic/earth.d.ts +11 -0
- package/dist/realistic/earth.js +54 -0
- package/dist/realistic/element.d.ts +84 -4
- package/dist/realistic/element.js +224 -27
- package/dist/realistic/immersive.d.ts +7 -0
- package/dist/realistic/immersive.js +17 -0
- package/dist/realistic/index.d.ts +7 -0
- package/dist/realistic/index.js +3 -0
- package/dist/realistic/textures.d.ts +3 -0
- package/dist/sky/culture-lines.d.ts +56 -0
- package/dist/sky/culture-lines.js +82 -0
- package/dist/sky/figure-pick.d.ts +75 -0
- package/dist/sky/figure-pick.js +200 -0
- package/dist/sky/host.d.ts +17 -1
- package/dist/sky/host.js +615 -71
- package/dist/sky/keep-clear.d.ts +63 -0
- package/dist/sky/keep-clear.js +55 -0
- package/dist/space/element.d.ts +105 -10
- package/dist/space/element.js +275 -18
- package/dist/space/index.d.ts +2 -2
- package/dist/space/index.js +1 -1
- package/dist/space/satellite-model.d.ts +22 -0
- package/dist/space/satellite-model.js +38 -0
- package/dist/space/scene.d.ts +56 -7
- package/dist/space/scene.js +124 -23
- package/package.json +3 -3
package/dist/space/scene.d.ts
CHANGED
|
@@ -9,10 +9,14 @@ import type { SatelliteRef } from "../satellites/types.ts";
|
|
|
9
9
|
import { type RideLook } from "./ride.ts";
|
|
10
10
|
import type { SkyFrame } from "../sky/frame.ts";
|
|
11
11
|
import type { PlaceView } from "../markers/places.ts";
|
|
12
|
-
import type
|
|
12
|
+
import { type PlaceSpriteData } from "../markers/place-sprites.ts";
|
|
13
|
+
import type { CountryFrame } from "../country-names/geometry.ts";
|
|
14
|
+
import type { GeoPoint } from "../types.ts";
|
|
13
15
|
import { type SatelliteScreen, type SatelliteState } from "./satellite-layer.ts";
|
|
14
16
|
import { type BodyLabelState } from "../realistic/body-label.ts";
|
|
15
17
|
import { type MeteorState } from "../meteors/layer.ts";
|
|
18
|
+
import { type BorderState } from "../borders/layer.ts";
|
|
19
|
+
import { type GridState } from "../grid/layer.ts";
|
|
16
20
|
type Three = ThreeParts;
|
|
17
21
|
/** 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. */
|
|
18
22
|
export declare const DEFAULT_EARTH_SIZE = 0.9;
|
|
@@ -85,8 +89,8 @@ export type BodyName = (typeof BODY_NAMES)[number];
|
|
|
85
89
|
export type RideTarget = BodyName | SatelliteRef;
|
|
86
90
|
export interface RideState {
|
|
87
91
|
target: RideTarget;
|
|
88
|
-
/** `from`: the camera is at the body, looking at the Earth. `follow`: the camera keeps a fixed distance from it, looking at it. */
|
|
89
|
-
view: "from" | "follow";
|
|
92
|
+
/** `from`: the camera is at the body, looking at the Earth. `follow`: the camera keeps a fixed distance from it, looking at it. `above` (a satellite): the camera is on the line from the Earth's centre through the satellite, looking straight down. */
|
|
93
|
+
view: "from" | "follow" | "above";
|
|
90
94
|
look: RideLook;
|
|
91
95
|
/** For `follow` a satellite: how far the camera keeps, in kilometres. */
|
|
92
96
|
distanceKm: number;
|
|
@@ -145,10 +149,13 @@ export interface SpaceModel {
|
|
|
145
149
|
distance: number;
|
|
146
150
|
radiusPx: number;
|
|
147
151
|
} | null;
|
|
148
|
-
/** What the painter has made now: the Sun and planets with a drawing, and the moons shown (set at each draw). */
|
|
152
|
+
/** What the painter has made now: the Sun and planets with a drawing, the moons shown and the moons held (shown, or gone from the view for less than `MOON_KEEP_MS`), whether the Moon is the painter's, and the bodies with finer map tiles on them (set at each draw). */
|
|
149
153
|
painted: {
|
|
150
154
|
bodies: number;
|
|
151
155
|
moons: number;
|
|
156
|
+
held: number;
|
|
157
|
+
moon: boolean;
|
|
158
|
+
tiles: number;
|
|
152
159
|
};
|
|
153
160
|
/** How many times astronomy-engine has been asked for a frame. */
|
|
154
161
|
lookups: number;
|
|
@@ -160,6 +167,10 @@ export interface SpaceModel {
|
|
|
160
167
|
meteors: MeteorState;
|
|
161
168
|
/** The name written on the Earth (src/realistic/body-label.ts): off unless the element sets it. */
|
|
162
169
|
bodyLabel: BodyLabelState;
|
|
170
|
+
/** The borders of the countries and of their regions, on the Earth (src/borders/layer.ts): off unless the element switches them on. */
|
|
171
|
+
borders: BorderState;
|
|
172
|
+
/** The meridians and parallels on the Earth (src/grid/layer.ts): off unless the element switches them on. */
|
|
173
|
+
grid: GridState;
|
|
163
174
|
/** The body or satellite the camera rides along with, or null. */
|
|
164
175
|
ride: RideState | null;
|
|
165
176
|
/** 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. */
|
|
@@ -180,6 +191,8 @@ export interface SpaceModel {
|
|
|
180
191
|
tilt: number;
|
|
181
192
|
zoom: number;
|
|
182
193
|
} | null;
|
|
194
|
+
/** The point of the ground the view would look at with yaw and tilt 0, as of the last draw (the middle of the view is this less the yaw and tilt), or null while the camera rides or looks at another body. */
|
|
195
|
+
lookBase: GeoPoint | null;
|
|
183
196
|
heightPx: number;
|
|
184
197
|
pose: Pose;
|
|
185
198
|
/** Pixels a second that riding makes things move on the screen at 1x clock speed (0 when not riding): the draw rate follows it. */
|
|
@@ -195,6 +208,7 @@ export interface SpaceModel {
|
|
|
195
208
|
x: number;
|
|
196
209
|
y: number;
|
|
197
210
|
shown: boolean;
|
|
211
|
+
parts: number;
|
|
198
212
|
} | null;
|
|
199
213
|
/** Where a satellite of a shown group is on the screen as of the last draw (`placeSatellite`), or `null`. */
|
|
200
214
|
placeSatellite: ((ref: SatelliteRef) => SatelliteScreen | null) | null;
|
|
@@ -222,16 +236,40 @@ export interface BodyDrawing {
|
|
|
222
236
|
object: THREE.Object3D;
|
|
223
237
|
/** Told at each draw the unit direction from the body to the Sun, in scene axes (x to the vernal equinox, y north). */
|
|
224
238
|
light?(toSun: Vec3): void;
|
|
225
|
-
/**
|
|
239
|
+
/**
|
|
240
|
+
* Told at each draw, after the object is placed and scaled: the direction to the Sun, the moment shown, how many CSS pixels across its radius the body is (a sharper picture is worth fetching only for a big one), and the
|
|
241
|
+
* camera with the size of the view in CSS pixels (`view`), so a body big in the view can lay finer map tiles over the part of it that is seen, and a glow can face the camera.
|
|
242
|
+
*/
|
|
226
243
|
update?(info: {
|
|
227
244
|
toSun: Vec3;
|
|
228
245
|
ms: number;
|
|
229
246
|
radiusPx: number;
|
|
247
|
+
view?: BodyView;
|
|
230
248
|
}): void;
|
|
249
|
+
/** What the window of finer map tiles on the body is doing (`shown` is the level on it now, or `null`), for a drawing that has one. */
|
|
250
|
+
readonly tiles?: {
|
|
251
|
+
shown: number | null;
|
|
252
|
+
} | undefined;
|
|
231
253
|
/** True to have the scene turn the object to face the camera (a disc or a glow). */
|
|
232
254
|
billboard?: boolean;
|
|
233
255
|
dispose(): void;
|
|
234
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* The camera that draws the bodies and the size of its view in CSS pixels, as the space view tells a drawing at each draw. The camera's matrices are current.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```ts no-run
|
|
262
|
+
* import type { BodyView } from "@johnmorrisdotca/chikyu-earth/space";
|
|
263
|
+
*
|
|
264
|
+
* const across = (view: BodyView): number => view.width;
|
|
265
|
+
* console.log(typeof across);
|
|
266
|
+
* ```
|
|
267
|
+
*/
|
|
268
|
+
export interface BodyView {
|
|
269
|
+
camera: THREE.Camera;
|
|
270
|
+
width: number;
|
|
271
|
+
height: number;
|
|
272
|
+
}
|
|
235
273
|
/**
|
|
236
274
|
* The seam for drawing a followed satellite as a 3D model: the package ships no model, the page supplies them. `has` says whether there is a model for a satellite (by NORAD number: `25544` is the ISS); `make` makes it as a drawing of radius 1
|
|
237
275
|
* (its middle at the origin, its long axis along +x, its top, the side that faces space, along +z, and its left along +y), at once or later (a promise); the view places it where the satellite is, points it the way it flies, sizes it to read and
|
|
@@ -269,6 +307,8 @@ export interface PaintContext {
|
|
|
269
307
|
ratio: number;
|
|
270
308
|
/** The widest picture, in pixels, the GPU should be given. */
|
|
271
309
|
maxTexture: number;
|
|
310
|
+
/** True to draw every body that has a surface picture from it, in any look but `plain`: the space view asks for this, so a planet or the Moon is never shown shaded where it has a real map. */
|
|
311
|
+
mapped?: boolean;
|
|
272
312
|
}
|
|
273
313
|
/**
|
|
274
314
|
* One moon of a planet at a moment: its name, where it is from the planet's centre and how big it is, both in radii of the planet, in scene axes.
|
|
@@ -305,6 +345,11 @@ export interface BodyPainter {
|
|
|
305
345
|
make(three: ThreeParts, name: string, context?: PaintContext): BodyDrawing | Promise<BodyDrawing>;
|
|
306
346
|
moons?(planet: PlanetName, ms: number): readonly BodyMoon[];
|
|
307
347
|
looks?: readonly string[];
|
|
348
|
+
/** Whose pictures the painter draws, in English and Japanese: the space view writes it under the picture while the painter draws the bodies. */
|
|
349
|
+
credit?: {
|
|
350
|
+
en: string;
|
|
351
|
+
ja: string;
|
|
352
|
+
};
|
|
308
353
|
}
|
|
309
354
|
export interface SpaceDeps {
|
|
310
355
|
assets: AssetCache;
|
|
@@ -321,8 +366,12 @@ export interface SpaceDeps {
|
|
|
321
366
|
onSky?: (frame: SkyFrame) => void;
|
|
322
367
|
/** Where points of the Earth's surface fall on the screen at this draw, for the places drawn on it. Called at each draw. */
|
|
323
368
|
onPlaces?: (view: PlaceView) => void;
|
|
324
|
-
/**
|
|
325
|
-
|
|
369
|
+
/** The rings the places' layer wants drawn in one draw call, read right after `onPlaces`. */
|
|
370
|
+
placeSprites?: () => PlaceSpriteData | null;
|
|
371
|
+
/** 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`). */
|
|
372
|
+
onPlaceRings?: (drawn: boolean) => void;
|
|
373
|
+
/** Where the Earth is on the screen (its disc) and how to find a place on it, for the names of cities and countries. Called at each draw, with `null` while no Earth is shown. */
|
|
374
|
+
onCities?: (frame: CountryFrame | null) => void;
|
|
326
375
|
/** The name written on the Earth could not be made. */
|
|
327
376
|
onLabelError?: (error: unknown) => void;
|
|
328
377
|
/** Where the chosen satellite is on the screen, or null. Called at each draw while a satellite is chosen (and once when it is let go). */
|
package/dist/space/scene.js
CHANGED
|
@@ -6,10 +6,13 @@ import { createTrack, orbitPath, PLANETS } from "./ephemeris.js";
|
|
|
6
6
|
import { placeAround, placeMoon, placeSun, RADIUS } from "./scale.js";
|
|
7
7
|
import { ridePose } from "./ride.js";
|
|
8
8
|
import { coverBody, covers } from "../sky/cover.js";
|
|
9
|
-
import {
|
|
9
|
+
import { createPlaceSprites } from "../markers/place-sprites.js";
|
|
10
|
+
import { aboveAxes, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
|
|
10
11
|
import { createSatelliteLayer, newSatelliteState } from "./satellite-layer.js";
|
|
11
12
|
import { createBodyLabelLayer, newBodyLabelState } from "../realistic/body-label.js";
|
|
12
13
|
import { createMeteorLayer, newMeteorState } from "../meteors/layer.js";
|
|
14
|
+
import { createBorderLayer, newBorderState } from "../borders/layer.js";
|
|
15
|
+
import { createGridLayer, newGridState } from "../grid/layer.js";
|
|
13
16
|
import { subsolarPoint, unitVector } from "../realistic/sun.js";
|
|
14
17
|
/** The most satellites ringed and named at once, over all the labelled groups. */
|
|
15
18
|
const MAX_MARKED = 80;
|
|
@@ -74,13 +77,14 @@ export const newSpaceModel = () => ({
|
|
|
74
77
|
bodies: "",
|
|
75
78
|
light: "sun",
|
|
76
79
|
drawn: null,
|
|
77
|
-
painted: { bodies: 0, moons: 0 },
|
|
80
|
+
painted: { bodies: 0, moons: 0, held: 0, moon: false, tiles: 0 },
|
|
78
81
|
lookups: 0,
|
|
79
82
|
speed: 1,
|
|
80
83
|
ride: null,
|
|
81
84
|
rideLost: false,
|
|
82
85
|
transition: null,
|
|
83
86
|
drawnView: null,
|
|
87
|
+
lookBase: null,
|
|
84
88
|
heightPx: 420,
|
|
85
89
|
pose: { p: [0, 0, 0], q: [0, 0, 0, 1], fov: FOV, valid: false },
|
|
86
90
|
rideMotion: 0,
|
|
@@ -89,6 +93,8 @@ export const newSpaceModel = () => ({
|
|
|
89
93
|
satellites: newSatelliteState(),
|
|
90
94
|
meteors: newMeteorState(),
|
|
91
95
|
bodyLabel: newBodyLabelState(),
|
|
96
|
+
borders: newBorderState(),
|
|
97
|
+
grid: newGridState(),
|
|
92
98
|
pick: null,
|
|
93
99
|
placeSatellite: null,
|
|
94
100
|
followModel: null,
|
|
@@ -248,7 +254,7 @@ export function createSpaceItem(model, deps) {
|
|
|
248
254
|
}
|
|
249
255
|
};
|
|
250
256
|
try {
|
|
251
|
-
const made = (slot.plain || look === "plain" ? plainPainter : painter).make(three, slot.name, { look, invalidate: () => deps.invalidate(), ratio: model.ratio(), maxTexture: deps.cap() });
|
|
257
|
+
const made = (slot.plain || look === "plain" ? plainPainter : painter).make(three, slot.name, { look, invalidate: () => deps.invalidate(), ratio: model.ratio(), maxTexture: deps.cap(), mapped: true });
|
|
252
258
|
if (typeof made.then === "function")
|
|
253
259
|
made.then(arrive, fail);
|
|
254
260
|
else
|
|
@@ -259,6 +265,8 @@ export function createSpaceItem(model, deps) {
|
|
|
259
265
|
}
|
|
260
266
|
};
|
|
261
267
|
const sunSlot = newSlot("Sun");
|
|
268
|
+
// the Moon from the painter when there is one (its picture, and finer tiles where it has them); the view's own Moon until it arrives, and if it cannot be made
|
|
269
|
+
const moonSlot = newSlot("Moon");
|
|
262
270
|
const planets = new Map();
|
|
263
271
|
for (const name of PLANETS) {
|
|
264
272
|
const positions = new Float32Array(96 * 3);
|
|
@@ -274,9 +282,13 @@ export function createSpaceItem(model, deps) {
|
|
|
274
282
|
let meteors = null;
|
|
275
283
|
let meteorTimer;
|
|
276
284
|
let nameOn = null;
|
|
285
|
+
let borders = null;
|
|
286
|
+
let placeSprites = null;
|
|
287
|
+
let placeSpritesTried = false;
|
|
288
|
+
let gridLayer = null;
|
|
277
289
|
let marksTold = false;
|
|
278
290
|
// 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
|
|
279
|
-
const modelSlot = { key: "", drawing: null, turn: 0 };
|
|
291
|
+
const modelSlot = { key: "", drawing: null, turn: 0, parts: 0 };
|
|
280
292
|
const dropModel = () => {
|
|
281
293
|
if (!modelSlot.drawing)
|
|
282
294
|
return;
|
|
@@ -348,6 +360,18 @@ export function createSpaceItem(model, deps) {
|
|
|
348
360
|
for (const name of PLANETS)
|
|
349
361
|
pos[name] = placeAround(mode, sunPos, helioOf(frame.planets[name]));
|
|
350
362
|
const radiusOf = (name) => (name === "Earth" ? 1 : RADIUS[name][mode]);
|
|
363
|
+
if (deps.painter && lookNow() !== "plain")
|
|
364
|
+
fill(moonSlot, true);
|
|
365
|
+
else if (moonSlot.look !== null) {
|
|
366
|
+
empty(moonSlot);
|
|
367
|
+
moonSlot.look = null;
|
|
368
|
+
}
|
|
369
|
+
const paintedMoon = moonSlot.drawing;
|
|
370
|
+
if (paintedMoon) {
|
|
371
|
+
paintedMoon.object.position.set(moonPos[0], moonPos[1], moonPos[2]);
|
|
372
|
+
paintedMoon.object.scale.setScalar(RADIUS["Moon"][mode]);
|
|
373
|
+
paintedMoon.light?.(moonToSun);
|
|
374
|
+
}
|
|
351
375
|
// the Sun and the planets, drawn by the painter, and the planets' orbits round the Sun
|
|
352
376
|
fill(sunSlot);
|
|
353
377
|
const sunDrawing = sunSlot.drawing;
|
|
@@ -400,6 +424,7 @@ export function createSpaceItem(model, deps) {
|
|
|
400
424
|
let rideFrom = null;
|
|
401
425
|
let followed = null;
|
|
402
426
|
model.rideLost = false;
|
|
427
|
+
model.lookBase = null;
|
|
403
428
|
model.rideMotion = 0;
|
|
404
429
|
model.rideDistance = null;
|
|
405
430
|
const ride = model.ride;
|
|
@@ -420,7 +445,7 @@ export function createSpaceItem(model, deps) {
|
|
|
420
445
|
}
|
|
421
446
|
else if (layer?.exact(ride.target, model.time, rideState)) {
|
|
422
447
|
const place = [rideState[0], rideState[1], rideState[2]];
|
|
423
|
-
if (ride.view === "follow") {
|
|
448
|
+
if (ride.view === "follow" || ride.view === "above") {
|
|
424
449
|
focusPos = place;
|
|
425
450
|
focusRadius = Math.max(1e-4, ride.distanceKm / 6371 / fit);
|
|
426
451
|
followed = { place, velocity: [rideState[3], rideState[4], rideState[5]], ref: ride.target };
|
|
@@ -432,7 +457,9 @@ export function createSpaceItem(model, deps) {
|
|
|
432
457
|
model.rideLost = true;
|
|
433
458
|
}
|
|
434
459
|
const hidden = rideFrom?.hidden ?? null;
|
|
435
|
-
moon.visible = hidden !== "Moon";
|
|
460
|
+
moon.visible = hidden !== "Moon" && !paintedMoon;
|
|
461
|
+
if (paintedMoon)
|
|
462
|
+
paintedMoon.object.visible = hidden !== "Moon";
|
|
436
463
|
if (sunDrawing)
|
|
437
464
|
sunDrawing.object.visible = hidden !== "Sun";
|
|
438
465
|
for (const [name, p] of planets)
|
|
@@ -473,14 +500,30 @@ export function createSpaceItem(model, deps) {
|
|
|
473
500
|
const lon = model.centre.lon - way * model.view.yaw;
|
|
474
501
|
const lat = Math.max(-90, Math.min(90, baseLat - way * model.view.tilt));
|
|
475
502
|
const aim = direction(spin + lon, lat);
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
503
|
+
if (followed && ride && ride.view === "above") {
|
|
504
|
+
// above the satellite: on the line from the Earth's centre through it, looking straight down at it, the way it is going at the top of the picture; the satellite stays in the middle and the Earth turns beneath.
|
|
505
|
+
// A drag turns the picture about the satellite (yaw) and tips the camera back or ahead of it (tilt).
|
|
506
|
+
distance = Math.max(1e-4, ride.distanceKm / 6371 / Math.max(1e-9, model.view.zoom));
|
|
507
|
+
const up = aboveAxes(followed.place, followed.velocity, model.view.yaw * RAD, Math.max(-80, Math.min(80, model.view.tilt)) * RAD);
|
|
508
|
+
target.set(focusPos[0], focusPos[1], focusPos[2]);
|
|
509
|
+
camera.position.set(target.x + up.offset[0] * distance, target.y + up.offset[1] * distance, target.z + up.offset[2] * distance);
|
|
510
|
+
camera.up.set(up.up[0], up.up[1], up.up[2]);
|
|
511
|
+
camera.lookAt(target);
|
|
512
|
+
camera.near = Math.max(1e-4, distance * 0.02);
|
|
513
|
+
camera.far = Math.max(2000, distance * 4 + (mode === "true" ? 40 * 23_481 : 400));
|
|
514
|
+
}
|
|
515
|
+
else {
|
|
516
|
+
if (way === 1 && focus === "Earth")
|
|
517
|
+
model.lookBase = { lon: model.centre.lon + spin - frame.spin, lat: baseLat };
|
|
518
|
+
distance = Math.max(1.05 * focusRadius, (fit * focusRadius) / Math.max(1e-9, model.view.zoom));
|
|
519
|
+
target.set(focusPos[0], focusPos[1], focusPos[2]);
|
|
520
|
+
camera.position.set(target.x + aim[0] * distance, target.y + aim[1] * distance, target.z + aim[2] * distance);
|
|
521
|
+
camera.up.set(0, 1, 0);
|
|
522
|
+
camera.lookAt(target);
|
|
523
|
+
camera.near = Math.max(0.0005, distance * 0.02 - focusRadius * 0.5, focusRadius * 0.01);
|
|
524
|
+
camera.far = Math.max(2000, distance * 4 + (mode === "true" ? 40 * 23_481 : 400));
|
|
525
|
+
}
|
|
526
|
+
if (ride && (ride.view === "follow" || ride.view === "above") && typeof ride.target !== "string") {
|
|
484
527
|
const focal = (size.height / 2) / Math.tan((fovNow / 2) * RAD);
|
|
485
528
|
model.rideMotion = (Math.hypot(rideState[3], rideState[4], rideState[5]) / Math.max(50, ride.distanceKm / Math.max(1e-9, model.view.zoom))) * focal;
|
|
486
529
|
}
|
|
@@ -500,9 +543,10 @@ export function createSpaceItem(model, deps) {
|
|
|
500
543
|
}
|
|
501
544
|
camera.fov = fovNow;
|
|
502
545
|
camera.aspect = size.width / Math.max(1, size.height);
|
|
503
|
-
// the Earth's place in the view: the picture is moved, not the camera (a camera riding from a body keeps the middle)
|
|
504
|
-
const
|
|
505
|
-
const
|
|
546
|
+
// the Earth's place in the view: the picture is moved, not the camera (a camera riding from a body, or above a satellite, keeps the middle)
|
|
547
|
+
const centred = rideFrom !== null || (ride?.view === "above" && followed !== null);
|
|
548
|
+
const shiftX = centred ? 0 : (model.earth.x - 0.5) * size.width;
|
|
549
|
+
const shiftY = centred ? 0 : (model.earth.y - 0.5) * size.height;
|
|
506
550
|
if (shiftX !== 0 || shiftY !== 0)
|
|
507
551
|
camera.setViewOffset(size.width, size.height, -shiftX, -shiftY, size.width, size.height);
|
|
508
552
|
else if (camera.view)
|
|
@@ -543,7 +587,11 @@ export function createSpaceItem(model, deps) {
|
|
|
543
587
|
for (const held of moonSlots.values())
|
|
544
588
|
if (held.slot.drawing?.object.visible)
|
|
545
589
|
paintedMoons += 1;
|
|
546
|
-
|
|
590
|
+
let tiled = 0;
|
|
591
|
+
for (const drawing of [sunSlot.drawing, moonSlot.drawing, ...[...planets.values()].map((p) => p.slot.drawing), ...[...moonSlots.values()].map((held) => held.slot.drawing)])
|
|
592
|
+
if (drawing?.tiles?.shown != null)
|
|
593
|
+
tiled += 1;
|
|
594
|
+
model.painted = { bodies: paintedBodies, moons: paintedMoons, held: 0, moon: paintedMoon !== undefined, tiles: tiled };
|
|
547
595
|
// 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
|
|
548
596
|
const satellitePainter = deps.satellitePainter?.();
|
|
549
597
|
const group = followed ? model.satellites.groups.get(followed.ref.group) : undefined;
|
|
@@ -566,6 +614,12 @@ export function createSpaceItem(model, deps) {
|
|
|
566
614
|
made.object.visible = false;
|
|
567
615
|
scene.add(made.object);
|
|
568
616
|
modelSlot.drawing = made;
|
|
617
|
+
// how many meshes the model is made of: a draw call each, which a test of the draw budget adds to the scene's own
|
|
618
|
+
modelSlot.parts = 0;
|
|
619
|
+
made.object.traverse((part) => {
|
|
620
|
+
if (part.isMesh)
|
|
621
|
+
modelSlot.parts += 1;
|
|
622
|
+
});
|
|
569
623
|
deps.invalidate();
|
|
570
624
|
})
|
|
571
625
|
.catch((error) => deps.onPainterError?.(error));
|
|
@@ -582,7 +636,7 @@ export function createSpaceItem(model, deps) {
|
|
|
582
636
|
modelSlot.drawing.light?.(toSunNow);
|
|
583
637
|
modelSlot.drawing.update?.({ toSun: toSunNow, ms: model.time, radiusPx: size.height * MODEL_RADIUS_SHARE });
|
|
584
638
|
projected.set(followed.place[0], followed.place[1], followed.place[2]).project(camera);
|
|
585
|
-
model.followModel = { x: ((projected.x + 1) / 2) * size.width, y: ((1 - projected.y) / 2) * size.height, shown: true };
|
|
639
|
+
model.followModel = { x: ((projected.x + 1) / 2) * size.width, y: ((1 - projected.y) / 2) * size.height, shown: true, parts: modelSlot.parts };
|
|
586
640
|
}
|
|
587
641
|
else {
|
|
588
642
|
if (modelSlot.drawing)
|
|
@@ -590,10 +644,12 @@ export function createSpaceItem(model, deps) {
|
|
|
590
644
|
model.followModel = null;
|
|
591
645
|
}
|
|
592
646
|
const sunToSun = unit([-frame.sun[0], -frame.sun[1], -frame.sun[2]]);
|
|
593
|
-
|
|
647
|
+
const bodyView = { camera, width: size.width, height: size.height };
|
|
648
|
+
sunDrawing?.update?.({ toSun: sunToSun, ms: model.time, radiusPx: px.Sun, view: bodyView });
|
|
649
|
+
paintedMoon?.update?.({ toSun: moonToSun, ms: model.time, radiusPx: px.Moon, view: bodyView });
|
|
594
650
|
for (const name of PLANETS) {
|
|
595
651
|
const p = planets.get(name);
|
|
596
|
-
p.slot.drawing?.update?.({ toSun: p.toSun, ms: model.time, radiusPx: px[name] });
|
|
652
|
+
p.slot.drawing?.update?.({ toSun: p.toSun, ms: model.time, radiusPx: px[name], view: bodyView });
|
|
597
653
|
}
|
|
598
654
|
if (painter.moons && lookNow() !== "plain") {
|
|
599
655
|
const now = performance.now();
|
|
@@ -625,7 +681,7 @@ export function createSpaceItem(model, deps) {
|
|
|
625
681
|
drawing.object.scale.setScalar(drawn);
|
|
626
682
|
const moonPx = away <= drawn * 1.001 ? 1e5 : ((size.height / 2) * (drawn / Math.sqrt(away * away - drawn * drawn))) / half;
|
|
627
683
|
drawing.light?.(p.toSun);
|
|
628
|
-
drawing.update?.({ toSun: p.toSun, ms: model.time, radiusPx: moonPx });
|
|
684
|
+
drawing.update?.({ toSun: p.toSun, ms: model.time, radiusPx: moonPx, view: bodyView });
|
|
629
685
|
}
|
|
630
686
|
}
|
|
631
687
|
let soonest = Number.POSITIVE_INFINITY;
|
|
@@ -646,9 +702,10 @@ export function createSpaceItem(model, deps) {
|
|
|
646
702
|
clearTimeout(releaseTimer);
|
|
647
703
|
releaseTimer = soonest < Number.POSITIVE_INFINITY ? setTimeout(() => deps.invalidate(), soonest + 50) : undefined;
|
|
648
704
|
}
|
|
705
|
+
model.painted.held = moonSlots.size;
|
|
649
706
|
const ratio = model.ratio();
|
|
650
707
|
const earthPx = Math.min(px.Earth, 1e5) * ratio;
|
|
651
|
-
textures.sync({ day: earthPx, night: earthPx, clouds: earthPx, water: earthPx, moon: Math.min(px.Moon, 1e5) * ratio });
|
|
708
|
+
textures.sync({ day: earthPx, night: earthPx, clouds: earthPx, water: earthPx, moon: paintedMoon ? 0 : Math.min(px.Moon, 1e5) * ratio });
|
|
652
709
|
if (deps.onLabels && model.labels) {
|
|
653
710
|
const places = {};
|
|
654
711
|
for (const name of BODY_NAMES) {
|
|
@@ -690,6 +747,7 @@ export function createSpaceItem(model, deps) {
|
|
|
690
747
|
deps.onPlaces({
|
|
691
748
|
width: size.width,
|
|
692
749
|
height: size.height,
|
|
750
|
+
radius: hidden === "Earth" || rideFrom ? 0 : Math.min(px.Earth, 1e5),
|
|
693
751
|
at(lon, lat, out) {
|
|
694
752
|
const la = lat * RAD;
|
|
695
753
|
const lo = lon * RAD;
|
|
@@ -716,6 +774,14 @@ export function createSpaceItem(model, deps) {
|
|
|
716
774
|
},
|
|
717
775
|
});
|
|
718
776
|
}
|
|
777
|
+
const spriteData = deps.placeSprites?.() ?? null;
|
|
778
|
+
if (spriteData && !placeSprites && !placeSpritesTried) {
|
|
779
|
+
placeSprites = createPlaceSprites(three, earth, sunEarth);
|
|
780
|
+
placeSpritesTried = true;
|
|
781
|
+
// told once: without `Points` the page's layer draws these rings itself
|
|
782
|
+
deps.onPlaceRings?.(placeSprites !== null);
|
|
783
|
+
}
|
|
784
|
+
placeSprites?.sync(spriteData, model.ratio(), size.width, size.height, model.light === "lit");
|
|
719
785
|
// the name written on the Earth: made the first time the settings ask for it; none while a ride along a body hides the Earth
|
|
720
786
|
if (model.bodyLabel.settings && !nameOn)
|
|
721
787
|
nameOn = createBodyLabelLayer(three, earth, model.bodyLabel, { invalidate: () => deps.invalidate(), ...(deps.onLabelError ? { onError: deps.onLabelError } : {}) });
|
|
@@ -765,10 +831,13 @@ export function createSpaceItem(model, deps) {
|
|
|
765
831
|
const ground = new three.Vector3();
|
|
766
832
|
const eye = camera.position;
|
|
767
833
|
const turned = earth.quaternion;
|
|
834
|
+
ground.set(0, 0, 0).project(camera);
|
|
835
|
+
const disc = { x: ((ground.x + 1) / 2) * size.width, y: ((1 - ground.y) / 2) * size.height, radius: Math.min(px.Earth, 1e5) };
|
|
768
836
|
deps.onCities({
|
|
769
837
|
width: size.width,
|
|
770
838
|
height: size.height,
|
|
771
839
|
radius: Math.min(px.Earth, 1e5),
|
|
840
|
+
...(ground.z > -1 && ground.z < 1 ? { disc } : {}),
|
|
772
841
|
project(lon, lat, out) {
|
|
773
842
|
const phi = lat * RAD;
|
|
774
843
|
const lambda = lon * RAD;
|
|
@@ -805,6 +874,34 @@ export function createSpaceItem(model, deps) {
|
|
|
805
874
|
clearTimeout(meteorTimer);
|
|
806
875
|
meteorTimer = Number.isFinite(wait) ? setTimeout(() => deps.invalidate(), wait) : undefined;
|
|
807
876
|
}
|
|
877
|
+
// the borders, on the Earth: made the first time a set is switched on, above the clouds and under the air; the view's middle is the point under the camera, as far round as its horizon
|
|
878
|
+
if ((model.borders.countries || model.borders.regions) && !borders && !model.borders.stats.failed) {
|
|
879
|
+
try {
|
|
880
|
+
borders = createBorderLayer(three, earth, model.borders, () => deps.invalidate(), 3.5);
|
|
881
|
+
}
|
|
882
|
+
catch (error) {
|
|
883
|
+
model.borders.stats.failed = true;
|
|
884
|
+
model.borders.onError?.(error);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
if (borders) {
|
|
888
|
+
const turn = earth.rotation.y;
|
|
889
|
+
const fx = camera.position.x * Math.cos(turn) - camera.position.z * Math.sin(turn);
|
|
890
|
+
const fz = camera.position.x * Math.sin(turn) + camera.position.z * Math.cos(turn);
|
|
891
|
+
const far = Math.hypot(fx, camera.position.y, fz) || 1;
|
|
892
|
+
borders.sync({ points: [{ lon: Math.atan2(fx, fz) / RAD, lat: Math.asin(Math.max(-1, Math.min(1, camera.position.y / far))) / RAD }], angle: Math.acos(Math.min(1, 1 / far)) / RAD, radius: Math.min(px.Earth, 1e5) });
|
|
893
|
+
}
|
|
894
|
+
// the grid, on the Earth: made the first time it is switched on, over the ground and under the clouds
|
|
895
|
+
if (model.grid.on && !gridLayer && !model.grid.stats.failed) {
|
|
896
|
+
try {
|
|
897
|
+
gridLayer = createGridLayer(three, earth, model.grid, sunEarth, 2.5);
|
|
898
|
+
}
|
|
899
|
+
catch (error) {
|
|
900
|
+
model.grid.stats.failed = true;
|
|
901
|
+
model.grid.onError?.(error);
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
gridLayer?.sync(Math.min(px.Earth, 1e5));
|
|
808
905
|
if (model.rideLost)
|
|
809
906
|
deps.onRideLost?.();
|
|
810
907
|
if (model.transition)
|
|
@@ -821,6 +918,9 @@ export function createSpaceItem(model, deps) {
|
|
|
821
918
|
clearTimeout(meteorTimer);
|
|
822
919
|
meteors?.dispose();
|
|
823
920
|
nameOn?.dispose();
|
|
921
|
+
borders?.dispose();
|
|
922
|
+
placeSprites?.dispose();
|
|
923
|
+
gridLayer?.dispose();
|
|
824
924
|
modelSlot.turn += 1;
|
|
825
925
|
dropModel();
|
|
826
926
|
layer?.dispose();
|
|
@@ -829,6 +929,7 @@ export function createSpaceItem(model, deps) {
|
|
|
829
929
|
textures.dispose();
|
|
830
930
|
ended = true;
|
|
831
931
|
empty(sunSlot);
|
|
932
|
+
empty(moonSlot);
|
|
832
933
|
for (const held of moonSlots.values())
|
|
833
934
|
empty(held.slot);
|
|
834
935
|
moonSlots.clear();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/chikyu-earth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.36.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",
|
|
@@ -195,7 +195,7 @@
|
|
|
195
195
|
},
|
|
196
196
|
"dependencies": {
|
|
197
197
|
"@johnmorrisdotca/chizu": "^1.6.0",
|
|
198
|
-
"@johnmorrisdotca/kazoku-ui": "^0.
|
|
198
|
+
"@johnmorrisdotca/kazoku-ui": "^0.41.0",
|
|
199
199
|
"d3-geo": "^3.1.1"
|
|
200
200
|
},
|
|
201
201
|
"peerDependencies": {
|
|
@@ -235,7 +235,7 @@
|
|
|
235
235
|
"@johnmorrisdotca/hata": "^1.8.0",
|
|
236
236
|
"@johnmorrisdotca/hoshi-stars": "^0.30.0",
|
|
237
237
|
"@johnmorrisdotca/kuni": "^1.6.1",
|
|
238
|
-
"@johnmorrisdotca/wakusei-planets": "^0.
|
|
238
|
+
"@johnmorrisdotca/wakusei-planets": "^0.37.1",
|
|
239
239
|
"@playwright/test": "1.64.0",
|
|
240
240
|
"@sveltejs/vite-plugin-svelte": "^7.3.1",
|
|
241
241
|
"@types/d3-geo": "^3.1.0",
|