@johnmorrisdotca/chikyu-earth 0.10.0 → 0.12.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 +39 -11
- package/NOTICE.md +3 -2
- package/README.md +207 -5
- package/dist/element.d.ts +5 -2
- package/dist/element.js +26 -5
- package/dist/realistic/earth.d.ts +15 -0
- package/dist/realistic/earth.js +6 -2
- package/dist/realistic/element.d.ts +4 -0
- package/dist/realistic/element.js +14 -1
- package/dist/realistic/index.d.ts +1 -1
- package/dist/realistic/shaders.d.ts +1 -1
- package/dist/realistic/shaders.js +2 -0
- package/dist/satellites/catalogue.d.ts +109 -0
- package/dist/satellites/catalogue.js +249 -0
- package/dist/satellites/index.d.ts +1 -0
- package/dist/satellites/index.js +1 -0
- package/dist/space/element.d.ts +21 -2
- package/dist/space/element.js +43 -3
- package/dist/space/ephemeris.d.ts +2 -2
- package/dist/space/ephemeris.js +2 -2
- package/dist/space/index.d.ts +1 -1
- package/dist/space/scale.js +1 -0
- package/dist/space/scene.d.ts +69 -7
- package/dist/space/scene.js +165 -22
- package/package.json +8 -3
package/dist/space/scene.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type * as THREE from "three";
|
|
|
2
2
|
import type { AssetCache, Item3D } from "@johnmorrisdotca/kazoku-ui/renderer";
|
|
3
3
|
import { type ThreeParts } from "../realistic/textures.ts";
|
|
4
4
|
import type { Layer } from "../realistic/tiers.ts";
|
|
5
|
+
import type { LightMode } from "../realistic/earth.ts";
|
|
5
6
|
import { type Frame, type PlanetName, type Vec3 } from "./ephemeris.ts";
|
|
6
7
|
import { type ScaleMode } from "./scale.ts";
|
|
7
8
|
import type { SatelliteRef } from "../satellites/types.ts";
|
|
@@ -11,7 +12,7 @@ type Three = ThreeParts;
|
|
|
11
12
|
/** The camera's distance, in Earth radii, at which the Earth fills the view at zoom 1. */
|
|
12
13
|
export declare const FIT_DISTANCE = 3.4;
|
|
13
14
|
/**
|
|
14
|
-
* The
|
|
15
|
+
* 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.
|
|
15
16
|
*
|
|
16
17
|
* @example
|
|
17
18
|
* ```ts no-run
|
|
@@ -20,7 +21,7 @@ export declare const FIT_DISTANCE = 3.4;
|
|
|
20
21
|
* console.log(BODY_NAMES.join(", "));
|
|
21
22
|
* ```
|
|
22
23
|
*/
|
|
23
|
-
export declare const BODY_NAMES: readonly ["Earth", "Sun", "Moon", "Mercury", "Venus", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"];
|
|
24
|
+
export declare const BODY_NAMES: readonly ["Earth", "Sun", "Moon", "Mercury", "Venus", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"];
|
|
24
25
|
/**
|
|
25
26
|
* The name of one of the bodies in `BODY_NAMES`.
|
|
26
27
|
*
|
|
@@ -83,12 +84,21 @@ export interface SpaceModel {
|
|
|
83
84
|
stepMs: number;
|
|
84
85
|
/** The body the camera looks at, and (in `zoom`) fills the view with at 1x. */
|
|
85
86
|
focus: BodyName;
|
|
87
|
+
/** How the Earth is lit (see `LightMode`); the Sun, the Moon and the planets keep their true places either way. */
|
|
88
|
+
light: LightMode;
|
|
89
|
+
/** How the painter draws the Sun, the planets and their moons (one of its `looks`, or `plain` for the sphere in the right colour); empty for its first. */
|
|
90
|
+
bodies: string;
|
|
86
91
|
/** Filled at each draw. */
|
|
87
92
|
drawn: {
|
|
88
93
|
frame: Frame;
|
|
89
94
|
distance: number;
|
|
90
95
|
radiusPx: number;
|
|
91
96
|
} | null;
|
|
97
|
+
/** What the painter has made now: the Sun and planets with a drawing, and the moons shown (set at each draw). */
|
|
98
|
+
painted: {
|
|
99
|
+
bodies: number;
|
|
100
|
+
moons: number;
|
|
101
|
+
};
|
|
92
102
|
/** How many times astronomy-engine has been asked for a frame. */
|
|
93
103
|
lookups: number;
|
|
94
104
|
/** Game seconds a second (the clock's speed). */
|
|
@@ -145,13 +155,59 @@ export interface BodyDrawing {
|
|
|
145
155
|
object: THREE.Object3D;
|
|
146
156
|
/** Told at each draw the unit direction from the body to the Sun, in scene axes (x to the vernal equinox, y north). */
|
|
147
157
|
light?(toSun: Vec3): void;
|
|
158
|
+
/** Told at each draw, after the object is placed and scaled: the direction to the Sun, the moment shown, and how many CSS pixels across its radius the body is (a sharper picture is worth fetching only for a big one). */
|
|
159
|
+
update?(info: {
|
|
160
|
+
toSun: Vec3;
|
|
161
|
+
ms: number;
|
|
162
|
+
radiusPx: number;
|
|
163
|
+
}): void;
|
|
148
164
|
/** True to have the scene turn the object to face the camera (a disc or a glow). */
|
|
149
165
|
billboard?: boolean;
|
|
150
166
|
dispose(): void;
|
|
151
167
|
}
|
|
152
168
|
/**
|
|
153
|
-
*
|
|
154
|
-
*
|
|
169
|
+
* What the scene tells a painter when it makes a body.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts no-run
|
|
173
|
+
* import type { PaintContext } from "@johnmorrisdotca/chikyu-earth/space";
|
|
174
|
+
*
|
|
175
|
+
* const context: PaintContext = { look: "painted", invalidate: () => undefined, ratio: 2, maxTexture: 2048 };
|
|
176
|
+
* console.log(context.look);
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
export interface PaintContext {
|
|
180
|
+
/** The look asked for: one of the painter's `looks`, or empty for its first. */
|
|
181
|
+
look: string;
|
|
182
|
+
/** Ask for a new draw (a picture has arrived). */
|
|
183
|
+
invalidate(): void;
|
|
184
|
+
/** Device pixels to a CSS pixel. */
|
|
185
|
+
ratio: number;
|
|
186
|
+
/** The widest picture, in pixels, the GPU should be given. */
|
|
187
|
+
maxTexture: number;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* 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.
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```ts no-run
|
|
194
|
+
* import type { BodyMoon } from "@johnmorrisdotca/chikyu-earth/space";
|
|
195
|
+
*
|
|
196
|
+
* const io: BodyMoon = { name: "Io", offset: [5.9, 0, 0], radius: 0.0255 };
|
|
197
|
+
* console.log(io.name);
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
export interface BodyMoon {
|
|
201
|
+
name: string;
|
|
202
|
+
offset: Readonly<Vec3>;
|
|
203
|
+
radius: number;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* The seam for drawing the Sun, the planets and their moons. The space view places them, sizes them, lights them and labels them; a painter only makes what is drawn at
|
|
207
|
+
* each place. The default (`plainPainter`) is a sphere in the body's colour, and a glow for the Sun. Another package can supply better looking ones:
|
|
208
|
+
* `@johnmorrisdotca/wakusei-planets/painter` draws the real Sun, planets, Pluto and moons.
|
|
209
|
+
* `make` may return a drawing at once or later (a promise); a drawing may update itself and ask for a redraw when a picture arrives. `moons` is optional: the moons the painter can
|
|
210
|
+
* draw for a planet at a moment, which the view shows round the planet when it is near enough to see them. `looks` names what `context.look` may be.
|
|
155
211
|
*
|
|
156
212
|
* @example
|
|
157
213
|
* ```ts no-run
|
|
@@ -162,7 +218,9 @@ export interface BodyDrawing {
|
|
|
162
218
|
* ```
|
|
163
219
|
*/
|
|
164
220
|
export interface BodyPainter {
|
|
165
|
-
make(three: ThreeParts, name:
|
|
221
|
+
make(three: ThreeParts, name: string, context?: PaintContext): BodyDrawing | Promise<BodyDrawing>;
|
|
222
|
+
moons?(planet: PlanetName, ms: number): readonly BodyMoon[];
|
|
223
|
+
looks?: readonly string[];
|
|
166
224
|
}
|
|
167
225
|
export interface SpaceDeps {
|
|
168
226
|
assets: AssetCache;
|
|
@@ -184,8 +242,10 @@ export interface SpaceDeps {
|
|
|
184
242
|
onRideLost?: () => void;
|
|
185
243
|
/** The satellites could not be drawn (the three.js parts handed over lack `Points`). */
|
|
186
244
|
onSatellitesError?: (error: unknown) => void;
|
|
187
|
-
/** How the Sun
|
|
245
|
+
/** How the Sun, the planets and their moons are drawn; left out, plain spheres in the right colours (see `BodyPainter`). */
|
|
188
246
|
painter?: BodyPainter;
|
|
247
|
+
/** The painter could not make a body (the three.js parts handed over lack something it needs); the body is drawn plain instead. */
|
|
248
|
+
onPainterError?: (error: unknown) => void;
|
|
189
249
|
}
|
|
190
250
|
/**
|
|
191
251
|
* The default look: a sphere in the planet's colour, lit by the Sun, and for the Sun a glowing disc.
|
|
@@ -197,6 +257,8 @@ export interface SpaceDeps {
|
|
|
197
257
|
* console.log(typeof plainPainter.make);
|
|
198
258
|
* ```
|
|
199
259
|
*/
|
|
200
|
-
export declare const plainPainter:
|
|
260
|
+
export declare const plainPainter: {
|
|
261
|
+
make(three: ThreeParts, name: string): BodyDrawing;
|
|
262
|
+
} & BodyPainter;
|
|
201
263
|
export declare function createSpaceItem(model: SpaceModel, deps: SpaceDeps): Item3D<Three>;
|
|
202
264
|
export {};
|
package/dist/space/scene.js
CHANGED
|
@@ -10,9 +10,14 @@ const RAD = Math.PI / 180;
|
|
|
10
10
|
export const FIT_DISTANCE = 3.4;
|
|
11
11
|
const FOV = 35;
|
|
12
12
|
const LAYERS = ["day", "night", "clouds", "water", "moon"];
|
|
13
|
-
|
|
13
|
+
/** The moons of a planet are shown once the planet is this many CSS pixels across its radius, and each is drawn at least this many pixels across its radius. */
|
|
14
|
+
const MOON_MIN_PLANET_PX = 4;
|
|
15
|
+
const MOON_MIN_PX = 2.2;
|
|
16
|
+
/** A moon that has been out of sight this long is let go (its pictures too). */
|
|
17
|
+
const MOON_KEEP_MS = 4000;
|
|
18
|
+
const PLAIN_COLOR = (name) => (name === "Sun" ? "#ffb347" : COLORS[name] ?? "#9a948b");
|
|
14
19
|
/**
|
|
15
|
-
* The
|
|
20
|
+
* 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.
|
|
16
21
|
*
|
|
17
22
|
* @example
|
|
18
23
|
* ```ts no-run
|
|
@@ -22,8 +27,8 @@ const PLAIN_COLOR = (name) => (name === "Sun" ? "#ffb347" : COLORS[name]);
|
|
|
22
27
|
* ```
|
|
23
28
|
*/
|
|
24
29
|
export const BODY_NAMES = ["Earth", "Sun", "Moon", ...PLANETS];
|
|
25
|
-
const COLORS = { Mercury: "#a79f96", Venus: "#e3c98a", Mars: "#c1593a", Jupiter: "#d2b48c", Saturn: "#e4d4a0", Uranus: "#9fd6dc", Neptune: "#4a6bd6" };
|
|
26
|
-
const ORBIT_COLORS = { Mercury: "#6b655f", Venus: "#8c7c55", Mars: "#7a4034", Jupiter: "#85735a", Saturn: "#8d8567", Uranus: "#5f8a8e", Neptune: "#34499a" };
|
|
30
|
+
const COLORS = { Mercury: "#a79f96", Venus: "#e3c98a", Mars: "#c1593a", Jupiter: "#d2b48c", Saturn: "#e4d4a0", Uranus: "#9fd6dc", Neptune: "#4a6bd6", Pluto: "#c9b8a6" };
|
|
31
|
+
const ORBIT_COLORS = { Mercury: "#6b655f", Venus: "#8c7c55", Mars: "#7a4034", Jupiter: "#85735a", Saturn: "#8d8567", Uranus: "#5f8a8e", Neptune: "#34499a", Pluto: "#7d7468" };
|
|
27
32
|
export const newSpaceModel = () => ({
|
|
28
33
|
time: Date.now(),
|
|
29
34
|
mode: "compressed",
|
|
@@ -34,7 +39,10 @@ export const newSpaceModel = () => ({
|
|
|
34
39
|
labels: true,
|
|
35
40
|
stepMs: 1000,
|
|
36
41
|
focus: "Earth",
|
|
42
|
+
bodies: "",
|
|
43
|
+
light: "sun",
|
|
37
44
|
drawn: null,
|
|
45
|
+
painted: { bodies: 0, moons: 0 },
|
|
38
46
|
lookups: 0,
|
|
39
47
|
speed: 1,
|
|
40
48
|
ride: null,
|
|
@@ -130,7 +138,7 @@ export function createSpaceItem(model, deps) {
|
|
|
130
138
|
const earthMaterial = new three.ShaderMaterial({
|
|
131
139
|
vertexShader: SURFACE_VERT,
|
|
132
140
|
fragmentShader: SURFACE_FRAG,
|
|
133
|
-
uniforms: { dayMap: uniform.day, nightMap: uniform.night, waterMap: uniform.water, sunDir: sunEarth, lights: { value: 1 }, ortho: { value: 0 } },
|
|
141
|
+
uniforms: { dayMap: uniform.day, nightMap: uniform.night, waterMap: uniform.water, sunDir: sunEarth, lights: { value: 1 }, boost: { value: 0 }, ortho: { value: 0 } },
|
|
134
142
|
});
|
|
135
143
|
const cloudShift = { value: 0 };
|
|
136
144
|
const cloudMaterial = new three.ShaderMaterial({
|
|
@@ -161,19 +169,68 @@ export function createSpaceItem(model, deps) {
|
|
|
161
169
|
const painter = deps.painter ?? plainPainter;
|
|
162
170
|
const scene = new three.Scene();
|
|
163
171
|
scene.add(earth, clouds, glow, moon);
|
|
164
|
-
|
|
165
|
-
|
|
172
|
+
// the Sun, the planets and the moons are made by the painter, one slot each: a slot is filled again when the look changes, and may be filled later (a painter may be slow)
|
|
173
|
+
let ended = false;
|
|
174
|
+
const newSlot = (name) => ({ name, drawing: undefined, look: null, token: 0, plain: false });
|
|
175
|
+
const lookNow = () => model.bodies || painter.looks?.[0] || "";
|
|
176
|
+
const empty = (slot) => {
|
|
177
|
+
slot.token += 1;
|
|
178
|
+
if (!slot.drawing)
|
|
179
|
+
return;
|
|
180
|
+
scene.remove(slot.drawing.object);
|
|
181
|
+
slot.drawing.dispose();
|
|
182
|
+
slot.drawing = undefined;
|
|
183
|
+
};
|
|
184
|
+
const fill = (slot, isMoon = false) => {
|
|
185
|
+
const look = lookNow();
|
|
186
|
+
if (slot.look === look)
|
|
187
|
+
return;
|
|
188
|
+
empty(slot);
|
|
189
|
+
slot.look = look;
|
|
190
|
+
const token = slot.token;
|
|
191
|
+
const arrive = (made) => {
|
|
192
|
+
if (ended || slot.token !== token) {
|
|
193
|
+
made.dispose();
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
slot.drawing = made;
|
|
197
|
+
scene.add(made.object);
|
|
198
|
+
deps.invalidate();
|
|
199
|
+
};
|
|
200
|
+
const fail = (error) => {
|
|
201
|
+
if (ended || slot.token !== token)
|
|
202
|
+
return;
|
|
203
|
+
deps.onPainterError?.(error);
|
|
204
|
+
if (!isMoon && !slot.plain) {
|
|
205
|
+
slot.plain = true;
|
|
206
|
+
slot.look = null;
|
|
207
|
+
fill(slot);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
try {
|
|
211
|
+
const made = (slot.plain || look === "plain" ? plainPainter : painter).make(three, slot.name, { look, invalidate: () => deps.invalidate(), ratio: model.ratio(), maxTexture: deps.cap() });
|
|
212
|
+
if (typeof made.then === "function")
|
|
213
|
+
made.then(arrive, fail);
|
|
214
|
+
else
|
|
215
|
+
arrive(made);
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
fail(error);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
const sunSlot = newSlot("Sun");
|
|
166
222
|
const planets = new Map();
|
|
167
223
|
for (const name of PLANETS) {
|
|
168
|
-
const drawing = painter.make(three, name);
|
|
169
224
|
const positions = new Float32Array(96 * 3);
|
|
170
225
|
const lineGeometry = new three.BufferGeometry();
|
|
171
226
|
lineGeometry.setAttribute("position", new three.BufferAttribute(positions, 3));
|
|
172
227
|
const orbit = new three.LineLoop(lineGeometry, new three.LineBasicMaterial({ color: ORBIT_COLORS[name], transparent: true, opacity: 0.7 }));
|
|
173
228
|
orbit.frustumCulled = false;
|
|
174
|
-
scene.add(
|
|
175
|
-
planets.set(name, {
|
|
229
|
+
scene.add(orbit);
|
|
230
|
+
planets.set(name, { slot: newSlot(name), orbit, positions, samples: [], epoch: Number.NaN, toSun: [1, 0, 0] });
|
|
176
231
|
}
|
|
232
|
+
const moonSlots = new Map();
|
|
233
|
+
let releaseTimer;
|
|
177
234
|
let layer;
|
|
178
235
|
const rideState = new Float64Array(6);
|
|
179
236
|
let selectedShown = false;
|
|
@@ -215,7 +272,8 @@ export function createSpaceItem(model, deps) {
|
|
|
215
272
|
const toSun = unit(frame.sun);
|
|
216
273
|
sunEarth.value.set(toSun[0], toSun[1], toSun[2]);
|
|
217
274
|
cloudShift.value = -(((model.time / 3_600_000) * 1.5) % 360) / 360;
|
|
218
|
-
earthMaterial.uniforms["lights"].value = 1;
|
|
275
|
+
earthMaterial.uniforms["lights"].value = model.light === "lit" ? 0 : 1;
|
|
276
|
+
earthMaterial.uniforms["boost"].value = model.light === "boost" ? 1 : 0;
|
|
219
277
|
// the Moon, with its near side to the Earth
|
|
220
278
|
moon.position.set(moonPos[0], moonPos[1], moonPos[2]);
|
|
221
279
|
moon.scale.setScalar(RADIUS["Moon"][mode]);
|
|
@@ -229,15 +287,23 @@ export function createSpaceItem(model, deps) {
|
|
|
229
287
|
pos[name] = placeAround(mode, sunPos, helioOf(frame.planets[name]));
|
|
230
288
|
const radiusOf = (name) => (name === "Earth" ? 1 : RADIUS[name][mode]);
|
|
231
289
|
// the Sun and the planets, drawn by the painter, and the planets' orbits round the Sun
|
|
232
|
-
|
|
233
|
-
sunDrawing.
|
|
234
|
-
if (sunDrawing
|
|
235
|
-
sunDrawing.object.
|
|
290
|
+
fill(sunSlot);
|
|
291
|
+
const sunDrawing = sunSlot.drawing;
|
|
292
|
+
if (sunDrawing) {
|
|
293
|
+
sunDrawing.object.position.set(sunPos[0], sunPos[1], sunPos[2]);
|
|
294
|
+
sunDrawing.object.scale.setScalar(radiusOf("Sun"));
|
|
295
|
+
if (sunDrawing.billboard)
|
|
296
|
+
sunDrawing.object.quaternion.copy(camera.quaternion);
|
|
297
|
+
}
|
|
236
298
|
for (const name of PLANETS) {
|
|
237
299
|
const p = planets.get(name);
|
|
238
|
-
p.
|
|
239
|
-
p.
|
|
240
|
-
p.drawing
|
|
300
|
+
fill(p.slot);
|
|
301
|
+
p.toSun = unit([frame.sun[0] - frame.planets[name][0], frame.sun[1] - frame.planets[name][1], frame.sun[2] - frame.planets[name][2]]);
|
|
302
|
+
if (p.slot.drawing) {
|
|
303
|
+
p.slot.drawing.object.position.set(pos[name][0], pos[name][1], pos[name][2]);
|
|
304
|
+
p.slot.drawing.object.scale.setScalar(radiusOf(name));
|
|
305
|
+
p.slot.drawing.light?.(p.toSun);
|
|
306
|
+
}
|
|
241
307
|
p.orbit.visible = model.orbits;
|
|
242
308
|
if (model.orbits) {
|
|
243
309
|
if (!Number.isFinite(p.epoch) || Math.abs(model.time - p.epoch) > 365 * 86_400_000) {
|
|
@@ -302,9 +368,11 @@ export function createSpaceItem(model, deps) {
|
|
|
302
368
|
}
|
|
303
369
|
const hidden = rideFrom?.hidden ?? null;
|
|
304
370
|
moon.visible = hidden !== "Moon";
|
|
305
|
-
sunDrawing
|
|
371
|
+
if (sunDrawing)
|
|
372
|
+
sunDrawing.object.visible = hidden !== "Sun";
|
|
306
373
|
for (const [name, p] of planets)
|
|
307
|
-
p.drawing
|
|
374
|
+
if (p.slot.drawing)
|
|
375
|
+
p.slot.drawing.object.visible = hidden !== name;
|
|
308
376
|
let fovNow = FOV;
|
|
309
377
|
let distance = 0;
|
|
310
378
|
if (rideFrom) {
|
|
@@ -357,6 +425,9 @@ export function createSpaceItem(model, deps) {
|
|
|
357
425
|
camera.aspect = size.width / Math.max(1, size.height);
|
|
358
426
|
camera.updateProjectionMatrix();
|
|
359
427
|
camera.updateMatrixWorld();
|
|
428
|
+
// always lit: the light comes from the camera's side of the Earth (the Sun, Moon and planets stay where they are)
|
|
429
|
+
if (model.light === "lit")
|
|
430
|
+
sunEarth.value.set(camera.position.x, camera.position.y, camera.position.z).normalize();
|
|
360
431
|
sunView.value.copy(sunEarth.value).transformDirection(camera.matrixWorldInverse);
|
|
361
432
|
const pose = model.pose;
|
|
362
433
|
pose.p[0] = camera.position.x;
|
|
@@ -381,6 +452,72 @@ export function createSpaceItem(model, deps) {
|
|
|
381
452
|
for (const name of BODY_NAMES)
|
|
382
453
|
px[name] = radiusPxOf(name);
|
|
383
454
|
model.drawn = { frame, distance, radiusPx: px.Earth };
|
|
455
|
+
let paintedBodies = sunSlot.drawing ? 1 : 0;
|
|
456
|
+
for (const p of planets.values())
|
|
457
|
+
if (p.slot.drawing)
|
|
458
|
+
paintedBodies += 1;
|
|
459
|
+
let paintedMoons = 0;
|
|
460
|
+
for (const held of moonSlots.values())
|
|
461
|
+
if (held.slot.drawing?.object.visible)
|
|
462
|
+
paintedMoons += 1;
|
|
463
|
+
model.painted = { bodies: paintedBodies, moons: paintedMoons };
|
|
464
|
+
const sunToSun = unit([-frame.sun[0], -frame.sun[1], -frame.sun[2]]);
|
|
465
|
+
sunDrawing?.update?.({ toSun: sunToSun, ms: model.time, radiusPx: px.Sun });
|
|
466
|
+
for (const name of PLANETS) {
|
|
467
|
+
const p = planets.get(name);
|
|
468
|
+
p.slot.drawing?.update?.({ toSun: p.toSun, ms: model.time, radiusPx: px[name] });
|
|
469
|
+
}
|
|
470
|
+
if (painter.moons && lookNow() !== "plain") {
|
|
471
|
+
const now = performance.now();
|
|
472
|
+
const seen = new Set();
|
|
473
|
+
for (const name of PLANETS) {
|
|
474
|
+
const p = planets.get(name);
|
|
475
|
+
const planet = p.slot.drawing;
|
|
476
|
+
if (!planet || !planet.object.visible || px[name] < MOON_MIN_PLANET_PX)
|
|
477
|
+
continue;
|
|
478
|
+
const radius = radiusOf(name);
|
|
479
|
+
for (const site of painter.moons(name, model.time)) {
|
|
480
|
+
const at = [pos[name][0] + site.offset[0] * radius, pos[name][1] + site.offset[1] * radius, pos[name][2] + site.offset[2] * radius];
|
|
481
|
+
projected.set(at[0], at[1], at[2]).project(camera);
|
|
482
|
+
if (projected.z > 1 || Math.abs(projected.x) > 1.25 || Math.abs(projected.y) > 1.25)
|
|
483
|
+
continue;
|
|
484
|
+
let held = moonSlots.get(site.name);
|
|
485
|
+
if (!held)
|
|
486
|
+
moonSlots.set(site.name, (held = { slot: newSlot(site.name), seen: now }));
|
|
487
|
+
held.seen = now;
|
|
488
|
+
seen.add(site.name);
|
|
489
|
+
fill(held.slot, true);
|
|
490
|
+
const drawing = held.slot.drawing;
|
|
491
|
+
if (!drawing)
|
|
492
|
+
continue;
|
|
493
|
+
const away = Math.hypot(at[0] - camera.position.x, at[1] - camera.position.y, at[2] - camera.position.z);
|
|
494
|
+
const drawn = Math.max(site.radius * radius, (away * half * MOON_MIN_PX) / (size.height / 2));
|
|
495
|
+
drawing.object.visible = true;
|
|
496
|
+
drawing.object.position.set(at[0], at[1], at[2]);
|
|
497
|
+
drawing.object.scale.setScalar(drawn);
|
|
498
|
+
const moonPx = away <= drawn * 1.001 ? 1e5 : ((size.height / 2) * (drawn / Math.sqrt(away * away - drawn * drawn))) / half;
|
|
499
|
+
drawing.light?.(p.toSun);
|
|
500
|
+
drawing.update?.({ toSun: p.toSun, ms: model.time, radiusPx: moonPx });
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
let soonest = Number.POSITIVE_INFINITY;
|
|
504
|
+
for (const [key, held] of moonSlots) {
|
|
505
|
+
if (seen.has(key))
|
|
506
|
+
continue;
|
|
507
|
+
if (held.slot.drawing)
|
|
508
|
+
held.slot.drawing.object.visible = false;
|
|
509
|
+
if (now - held.seen > MOON_KEEP_MS) {
|
|
510
|
+
empty(held.slot);
|
|
511
|
+
moonSlots.delete(key);
|
|
512
|
+
}
|
|
513
|
+
else
|
|
514
|
+
soonest = Math.min(soonest, held.seen + MOON_KEEP_MS - now);
|
|
515
|
+
}
|
|
516
|
+
// a view that is at rest draws nothing, so a moon that has gone from the view would be kept for ever: ask for one more draw when the first of them is due to be let go
|
|
517
|
+
if (releaseTimer !== undefined)
|
|
518
|
+
clearTimeout(releaseTimer);
|
|
519
|
+
releaseTimer = soonest < Number.POSITIVE_INFINITY ? setTimeout(() => deps.invalidate(), soonest + 50) : undefined;
|
|
520
|
+
}
|
|
384
521
|
const ratio = model.ratio();
|
|
385
522
|
const earthPx = Math.min(px.Earth, 1e5) * ratio;
|
|
386
523
|
textures.sync({ day: earthPx, night: earthPx, clouds: earthPx, water: earthPx, moon: Math.min(px.Moon, 1e5) * ratio });
|
|
@@ -408,12 +545,18 @@ export function createSpaceItem(model, deps) {
|
|
|
408
545
|
size = { width: w, height: h };
|
|
409
546
|
},
|
|
410
547
|
dispose() {
|
|
548
|
+
if (releaseTimer !== undefined)
|
|
549
|
+
clearTimeout(releaseTimer);
|
|
411
550
|
layer?.dispose();
|
|
412
551
|
model.pick = null;
|
|
413
552
|
textures.dispose();
|
|
414
|
-
|
|
553
|
+
ended = true;
|
|
554
|
+
empty(sunSlot);
|
|
555
|
+
for (const held of moonSlots.values())
|
|
556
|
+
empty(held.slot);
|
|
557
|
+
moonSlots.clear();
|
|
415
558
|
for (const p of planets.values()) {
|
|
416
|
-
p.
|
|
559
|
+
empty(p.slot);
|
|
417
560
|
p.orbit.geometry.dispose();
|
|
418
561
|
p.orbit.material.dispose();
|
|
419
562
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/chikyu-earth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.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 where you are, 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",
|
|
@@ -146,7 +146,8 @@
|
|
|
146
146
|
"@johnmorrisdotca/kazoku-ui": ">=0.9.0",
|
|
147
147
|
"three": ">=0.160.0",
|
|
148
148
|
"astronomy-engine": ">=2.1.0",
|
|
149
|
-
"satellite.js": ">=6.0.0"
|
|
149
|
+
"satellite.js": ">=6.0.0",
|
|
150
|
+
"@johnmorrisdotca/wakusei-planets": ">=0.5.0"
|
|
150
151
|
},
|
|
151
152
|
"peerDependenciesMeta": {
|
|
152
153
|
"@johnmorrisdotca/kazoku-ui": {
|
|
@@ -160,6 +161,9 @@
|
|
|
160
161
|
},
|
|
161
162
|
"satellite.js": {
|
|
162
163
|
"optional": true
|
|
164
|
+
},
|
|
165
|
+
"@johnmorrisdotca/wakusei-planets": {
|
|
166
|
+
"optional": true
|
|
163
167
|
}
|
|
164
168
|
},
|
|
165
169
|
"devDependencies": {
|
|
@@ -168,7 +172,8 @@
|
|
|
168
172
|
"@angular/core": "^22.2.4",
|
|
169
173
|
"@angular/platform-browser": "^22.2.4",
|
|
170
174
|
"@eslint/js": "^9.0.0",
|
|
171
|
-
"@johnmorrisdotca/kazoku-ui": "^0.
|
|
175
|
+
"@johnmorrisdotca/kazoku-ui": "^0.12.0",
|
|
176
|
+
"@johnmorrisdotca/wakusei-planets": "^0.5.0",
|
|
172
177
|
"@playwright/test": "1.64.0",
|
|
173
178
|
"@sveltejs/vite-plugin-svelte": "^7.3.1",
|
|
174
179
|
"@types/d3-geo": "^3.1.0",
|