@johnmorrisdotca/chikyu-earth 0.29.0 → 0.31.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 +8 -0
- package/NOTICE.md +4 -0
- package/README.md +55 -2
- package/dist/data-door.d.ts +357 -0
- package/dist/data-door.js +393 -0
- package/dist/door/book.d.ts +118 -0
- package/dist/door/book.js +211 -0
- package/dist/door/elements.d.ts +96 -0
- package/dist/door/elements.js +108 -0
- package/dist/door/host.d.ts +30 -0
- package/dist/door/host.js +44 -0
- package/dist/door/index.d.ts +6 -0
- package/dist/door/index.js +10 -0
- package/dist/door/map.d.ts +165 -0
- package/dist/door/map.js +182 -0
- package/dist/door/own.d.ts +36 -0
- package/dist/door/own.js +75 -0
- package/dist/meteors/index.d.ts +1 -0
- package/dist/meteors/index.js +1 -0
- package/dist/meteors/layer.d.ts +6 -2
- package/dist/meteors/layer.js +26 -9
- package/dist/meteors/strength.d.ts +26 -0
- package/dist/meteors/strength.js +35 -0
- package/dist/passes/element.d.ts +18 -0
- package/dist/passes/element.js +67 -5
- package/dist/realistic/earth.d.ts +5 -3
- package/dist/realistic/earth.js +2 -1
- package/dist/realistic/element.d.ts +27 -0
- package/dist/realistic/element.js +81 -5
- package/dist/realistic/tile-set.d.ts +27 -2
- package/dist/realistic/tile-set.js +155 -49
- package/dist/space/element.d.ts +8 -0
- package/dist/space/element.js +19 -2
- package/package.json +6 -1
package/dist/passes/element.js
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
// Nothing runs on a timer: it works the passes out when something it shows changes, and reads the clock once, when it first comes into a page (or never, when `from` is given).
|
|
3
3
|
import { adoptStyles } from "../adopt.js";
|
|
4
4
|
import { fetchElements } from "../satellites/source.js";
|
|
5
|
+
import { creditLine } from "../data-door.js";
|
|
6
|
+
import { createDoorHost } from "../door/host.js";
|
|
7
|
+
import { mergeElementSets } from "../door/elements.js";
|
|
5
8
|
import { DEFAULT_DIM_AFTER_DAYS } from "../satellites/limits.js";
|
|
6
9
|
import { findPasses, passPath } from "./passes.js";
|
|
7
10
|
import { skySvg } from "./sky.js";
|
|
@@ -169,8 +172,14 @@ const number = (value, fallback) => (value === null || value.trim() === "" || !N
|
|
|
169
172
|
* ```
|
|
170
173
|
*/
|
|
171
174
|
export class ChikyuPasses extends HTMLElement {
|
|
172
|
-
static observedAttributes = ["latitude", "longitude", "height", "days", "show", "sky", "satellite", "from", "min-altitude", "lang", "time-zone", "utc-offset", "selected", "elements-src", "credit"];
|
|
175
|
+
static observedAttributes = ["latitude", "longitude", "height", "days", "show", "sky", "satellite", "from", "min-altitude", "lang", "time-zone", "utc-offset", "selected", "elements-src", "credit", "data"];
|
|
173
176
|
#sets = [];
|
|
177
|
+
/** The element sets the passes are worked out from: the page's own (`elements`, `elements-src`) and those of the sources of the data door, one set a satellite, the newest epoch winning. */
|
|
178
|
+
#all = [];
|
|
179
|
+
/** Which source each satellite's set came from (`null`: the page's own sets), by NORAD number. */
|
|
180
|
+
#origin = new Map();
|
|
181
|
+
/** The data door: the outside sources of orbital elements, and whose data is on the screen. */
|
|
182
|
+
#door = createDoorHost(this, { own: () => [], used: () => this.#used() }, { kinds: ["records"] }, () => this.#schedule());
|
|
174
183
|
#passes = [];
|
|
175
184
|
#chosen;
|
|
176
185
|
#problem = "";
|
|
@@ -190,6 +199,49 @@ export class ChikyuPasses extends HTMLElement {
|
|
|
190
199
|
this.#problem = "";
|
|
191
200
|
this.#schedule();
|
|
192
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* The outside sources of orbital elements (the data door): each carries its own licence and credit (`elementsFrom` makes one of an address), is read once when it is added, and its sets are worked out with the page's own.
|
|
204
|
+
* Assign a list to replace them; a source that is refused throws a `TypeError` and nothing changes. A property, never an attribute: data is not text.
|
|
205
|
+
*/
|
|
206
|
+
get sources() {
|
|
207
|
+
return this.#door.sources();
|
|
208
|
+
}
|
|
209
|
+
set sources(list) {
|
|
210
|
+
this.#door.setSources(list);
|
|
211
|
+
}
|
|
212
|
+
/** Adds a source of orbital elements: checked at once (a `TypeError` for one that is refused). Returns the function that takes it away. */
|
|
213
|
+
addSource(source) {
|
|
214
|
+
return this.#door.book.addSource(source);
|
|
215
|
+
}
|
|
216
|
+
/** Takes a source away by its id. Returns whether there was one. */
|
|
217
|
+
removeSource(id) {
|
|
218
|
+
return this.#door.book.removeSource(id);
|
|
219
|
+
}
|
|
220
|
+
/** Switches a source off (`false`) or on again, and keeps it in the element. The attribute `data="own"` ignores every outside source at once. */
|
|
221
|
+
enableSource(id, on) {
|
|
222
|
+
this.#door.book.enableSource(id, on);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Whose orbit data is in the list now: each source of the data door that gave a satellite to a pass listed, with how many satellites (`used`). `creditLine(credits, "en" | "ja")` from `@johnmorrisdotca/chikyu-earth/door` writes them
|
|
226
|
+
* as a line with the licences, and the element shows that line under the list (after the text of the `credit` attribute, which stays). `chikyu-creditschange` fires when this set changes, with `detail: { credits }`.
|
|
227
|
+
*/
|
|
228
|
+
credits() {
|
|
229
|
+
return this.#door.credits();
|
|
230
|
+
}
|
|
231
|
+
/** How many satellites of the passes listed came from each source of the door, by id. */
|
|
232
|
+
#used() {
|
|
233
|
+
const seen = new Set();
|
|
234
|
+
const used = new Map();
|
|
235
|
+
for (const pass of this.#passes) {
|
|
236
|
+
if (seen.has(pass.noradId))
|
|
237
|
+
continue;
|
|
238
|
+
seen.add(pass.noradId);
|
|
239
|
+
const id = this.#origin.get(pass.noradId);
|
|
240
|
+
if (id !== null && id !== undefined)
|
|
241
|
+
used.set(id, (used.get(id) ?? 0) + 1);
|
|
242
|
+
}
|
|
243
|
+
return used;
|
|
244
|
+
}
|
|
193
245
|
/** The passes listed now, earliest first. */
|
|
194
246
|
get passes() {
|
|
195
247
|
return this.#passes;
|
|
@@ -216,12 +268,15 @@ export class ChikyuPasses extends HTMLElement {
|
|
|
216
268
|
connectedCallback() {
|
|
217
269
|
const root = this.shadowRoot ?? this.attachShadow({ mode: "open" });
|
|
218
270
|
adoptStyles(root, CSS, this.getAttribute("nonce") ?? "");
|
|
271
|
+
this.#door.book.ownOnly(this.getAttribute("data") === "own");
|
|
219
272
|
this.#load();
|
|
220
273
|
this.#schedule();
|
|
221
274
|
}
|
|
222
275
|
attributeChangedCallback(name) {
|
|
223
276
|
if (!this.isConnected)
|
|
224
277
|
return;
|
|
278
|
+
if (name === "data")
|
|
279
|
+
this.#door.book.ownOnly(this.getAttribute("data") === "own");
|
|
225
280
|
if (name === "elements-src")
|
|
226
281
|
this.#load();
|
|
227
282
|
this.#schedule();
|
|
@@ -326,8 +381,13 @@ export class ChikyuPasses extends HTMLElement {
|
|
|
326
381
|
holder.innerHTML = `<p class="empty" role="status">${escape(say("unreadable", { why: this.#problem }))}</p>`;
|
|
327
382
|
return;
|
|
328
383
|
}
|
|
384
|
+
const lists = this.#door.book.elementLists();
|
|
385
|
+
// with no source the page's own sets are used as they are, every one
|
|
386
|
+
const merged = lists.length === 0 ? this.#sets.map((set) => ({ set, id: null })) : mergeElementSets([{ id: null, sets: this.#sets }, ...lists]);
|
|
387
|
+
this.#all = merged.map((one) => one.set);
|
|
388
|
+
this.#origin = new Map(merged.map((one) => [one.set.NORAD_CAT_ID, one.id]));
|
|
329
389
|
const chosenSet = this.getAttribute("satellite");
|
|
330
|
-
const sets = chosenSet ? this.#
|
|
390
|
+
const sets = chosenSet ? this.#all.filter((one) => String(one.NORAD_CAT_ID) === chosenSet) : this.#all;
|
|
331
391
|
if (this.#waiting && sets.length === 0) {
|
|
332
392
|
holder.innerHTML = `<p class="empty" role="status">${escape(say("waiting"))}</p>`;
|
|
333
393
|
return;
|
|
@@ -363,7 +423,8 @@ export class ChikyuPasses extends HTMLElement {
|
|
|
363
423
|
ages.set(pass.noradId, pass);
|
|
364
424
|
const oldest = Math.max(0, ...[...ages.values()].map((one) => one.elementAgeDays));
|
|
365
425
|
const note = `<p class="note">${escape(f.zone)} ${escape(say("reboost"))}${oldest > DEFAULT_DIM_AFTER_DAYS ? ` ${escape(say("stale"))}${lang === "ja" ? "。" : "."}` : ""}</p>`;
|
|
366
|
-
|
|
426
|
+
// the `credit` attribute stays as the page's own words; the sources of the door add their credit line, with the licences, after it
|
|
427
|
+
const credit = [this.getAttribute("credit") ?? "", creditLine(this.#door.credits(), lang)].filter((part) => part.trim() !== "").join(" ");
|
|
367
428
|
const list = this.#passes.length === 0 ? `<p class="empty" role="status">${escape(say(all ? "noneAll" : "none", { days }))}</p>` : `<ul class="list" aria-label="${escape(say("list"))}">${rows}</ul>`;
|
|
368
429
|
holder.innerHTML = `${note}<div class="layout"><div>${list}</div><div class="detail">${this.#chosen ? this.#detail(this.#chosen, f, say, lang) : ""}</div></div>${credit ? `<p class="credit">${escape(credit)}</p>` : ""}`;
|
|
369
430
|
this.dispatchEvent(new CustomEvent("chikyu-passes", { detail: { passes: this.#passes, ageDays: oldest }, bubbles: true, composed: true }));
|
|
@@ -371,11 +432,12 @@ export class ChikyuPasses extends HTMLElement {
|
|
|
371
432
|
const shown = this.#chosen?.highest.ms;
|
|
372
433
|
if (shown !== this.#announced) {
|
|
373
434
|
this.#announced = shown;
|
|
374
|
-
this.dispatchEvent(new CustomEvent("chikyu-pass-select", { detail: { pass: this.#chosen, set: this.#chosen ? this.#
|
|
435
|
+
this.dispatchEvent(new CustomEvent("chikyu-pass-select", { detail: { pass: this.#chosen, set: this.#chosen ? this.#all.find((one) => one.NORAD_CAT_ID === this.#chosen.noradId) : undefined }, bubbles: true, composed: true }));
|
|
375
436
|
}
|
|
437
|
+
this.#door.announce();
|
|
376
438
|
}
|
|
377
439
|
#detail(pass, f, say, lang) {
|
|
378
|
-
const set = this.#
|
|
440
|
+
const set = this.#all.find((one) => one.NORAD_CAT_ID === pass.noradId);
|
|
379
441
|
const place = { latitude: number(this.getAttribute("latitude"), 0), longitude: number(this.getAttribute("longitude"), 0), heightM: number(this.getAttribute("height"), 0) };
|
|
380
442
|
const short = SHORT[pass.noradId]?.[lang] ?? pass.name;
|
|
381
443
|
const labels = { north: say("skyN"), east: say("skyE"), south: say("skyS"), west: say("skyW"), start: say("skyStart"), highest: say("skyHighest"), end: say("skyEnd"), zenith: say("skyZenith") };
|
|
@@ -6,7 +6,7 @@ import { lookAt } from "../view.ts";
|
|
|
6
6
|
import { type SatelliteState } from "../space/satellite-layer.ts";
|
|
7
7
|
import type { Layer } from "./tiers.ts";
|
|
8
8
|
import { type ThreeParts } from "./textures.ts";
|
|
9
|
-
import { type TileSet } from "./tile-set.ts";
|
|
9
|
+
import { type TileSet, type TileSources } from "./tile-set.ts";
|
|
10
10
|
import { type MeteorState } from "../meteors/layer.ts";
|
|
11
11
|
export type { ThreeParts };
|
|
12
12
|
type Three = ThreeParts;
|
|
@@ -92,8 +92,8 @@ export interface EarthDeps {
|
|
|
92
92
|
textureBase: () => string;
|
|
93
93
|
/** The widest texture, 4096 at most. */
|
|
94
94
|
cap: () => number;
|
|
95
|
-
/**
|
|
96
|
-
|
|
95
|
+
/** The map source of each layer now (the data door's: a source a page added, else the `tiles` folder), or none: the Earth then keeps the package's own pictures. */
|
|
96
|
+
sources?: () => TileSources;
|
|
97
97
|
/** Told once when the tile set has been read: the width in pixels of the finest level of each of its layers. */
|
|
98
98
|
onTiles?: (layers: Record<string, number>) => void;
|
|
99
99
|
invalidate: () => void;
|
|
@@ -103,6 +103,8 @@ export interface EarthDeps {
|
|
|
103
103
|
air?: () => "full" | "light";
|
|
104
104
|
/** The satellites could not be drawn (the three.js parts handed over lack `Points`). */
|
|
105
105
|
onSatellitesError?: (error: unknown) => void;
|
|
106
|
+
/** Told after the tiles were put right for a draw: what the draw shows from each source is known now. */
|
|
107
|
+
onTiled?: () => void;
|
|
106
108
|
/** Told at the start of every draw, before anything is read for it. */
|
|
107
109
|
onDraw?: () => void;
|
|
108
110
|
/** Told at every draw where the disc is, for what is laid over it (markers). */
|
package/dist/realistic/earth.js
CHANGED
|
@@ -159,7 +159,7 @@ export function createEarthItem(model, deps) {
|
|
|
159
159
|
});
|
|
160
160
|
const turned = new three.Group();
|
|
161
161
|
const earth = new three.Mesh(grid, surface);
|
|
162
|
-
const tiles = createTileSet(three, turned, { sunDir, lights: surface.uniforms["lights"], boost: surface.uniforms["boost"], ortho: surface.uniforms["ortho"], water: uniform.water, night: uniform.night, extra: { cloudMap: uniform.clouds, sunLocal, cloudShift } }, { assets: deps.assets,
|
|
162
|
+
const tiles = createTileSet(three, turned, { sunDir, lights: surface.uniforms["lights"], boost: surface.uniforms["boost"], ortho: surface.uniforms["ortho"], water: uniform.water, night: uniform.night, extra: { cloudMap: uniform.clouds, sunLocal, cloudShift } }, { assets: deps.assets, sources: () => deps.sources?.() ?? {}, cap: deps.cap, invalidate: deps.invalidate, ...(deps.onTiles ? { onManifest: deps.onTiles } : {}) });
|
|
163
163
|
model.tiles = tiles;
|
|
164
164
|
const clouds = new three.Mesh(grid, cloudMaterial);
|
|
165
165
|
clouds.scale.setScalar(CLOUD_RADIUS);
|
|
@@ -226,6 +226,7 @@ export function createEarthItem(model, deps) {
|
|
|
226
226
|
model.drawn = { view: { ...view }, time: model.time, radius, centre: { ...centre } };
|
|
227
227
|
textures.sync(radius * model.ratio());
|
|
228
228
|
tiles.sync({ lon: look.lon, lat: look.lat, width: size.width, height: size.height, panX: view.panX, panY: view.panY, radius }, [sunDir.value.x, sunDir.value.y, sunDir.value.z], true, model.ratio());
|
|
229
|
+
deps.onTiled?.();
|
|
229
230
|
deps.onPose?.({ lon: look.lon, lat: look.lat, radius, cx: size.width / 2 + view.panX, cy: size.height / 2 + view.panY, width: size.width, height: size.height });
|
|
230
231
|
if (model.meteors.on && !meteors)
|
|
231
232
|
meteors = createMeteorLayer(three, turned, model.meteors);
|
|
@@ -3,6 +3,7 @@ import type { GeoPoint, GlobeView } from "../types.ts";
|
|
|
3
3
|
import { type CameraMode, type LightMode } from "./earth.ts";
|
|
4
4
|
import type { SatelliteInfo, SatelliteRef, Satellites } from "../satellites/types.ts";
|
|
5
5
|
import { type SatelliteStyle } from "../space/satellite-layer.ts";
|
|
6
|
+
import type { Credit, DataSource } from "../data-door.ts";
|
|
6
7
|
import { setSharedRenderer, setThreeLoader } from "./shared.ts";
|
|
7
8
|
export { setSharedRenderer, setThreeLoader };
|
|
8
9
|
export type { CameraMode };
|
|
@@ -79,6 +80,7 @@ export declare const readTime: (value: string | null) => number | "now";
|
|
|
79
80
|
* where they fall, their height and the showers' dates are real (`@johnmorrisdotca/chikyu-earth/meteors`). They run while the clock runs, at any speed, and not
|
|
80
81
|
* at all while it is held, out of sight, in a hidden tab, or for a reader who prefers reduced motion until the page sets a `speed` (a Play). `chikyu-meteors`
|
|
81
82
|
* is sent when the strongest active shower changes, with `detail: { shower, zhr }` (`shower` is `null` when none is active).
|
|
83
|
+
* `meteors-strength` (0 to 1, the property `meteorsStrength`; 1 when the page says nothing) makes them subtler: fewer streaks and fainter ones, none at 0, and nothing that is real changes.
|
|
82
84
|
*
|
|
83
85
|
* @example
|
|
84
86
|
* ```ts no-run
|
|
@@ -114,8 +116,32 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
|
|
|
114
116
|
*/
|
|
115
117
|
get meteors(): boolean;
|
|
116
118
|
set meteors(value: boolean);
|
|
119
|
+
/**
|
|
120
|
+
* How strongly the meteors are drawn, from 0 to 1 (the attribute `meteors-strength`; 1, the full look, when the page says nothing): it scales how bright each streak is and how many are drawn, so 0.3 is
|
|
121
|
+
* fewer and fainter and 0 draws none. It changes nothing that is real: the rates, the showers and `chikyu-meteors` are the same at every strength, and the line under the picture still says the streaks are an illustration.
|
|
122
|
+
* A number outside the range is brought to its nearest end; setting the property writes the attribute.
|
|
123
|
+
*/
|
|
124
|
+
get meteorsStrength(): number;
|
|
125
|
+
set meteorsStrength(value: number);
|
|
117
126
|
/** The controller behind the element's own hands (`set`, `fit`, `state`), while it is in a page. */
|
|
118
127
|
get controller(): ViewController | undefined;
|
|
128
|
+
/**
|
|
129
|
+
* The outside sources of map this Earth draws from (the data door): each carries its own licence and credit, and a map source for the `day` or `night` layer takes the place of the folder of tiles for that layer. Assign a list to
|
|
130
|
+
* replace them; a source that is refused (an empty credit, no licence, a clashing id, a kind the Earth does not draw, a layer it does not know) throws a `TypeError` and nothing changes. A property, never an attribute: data is not text.
|
|
131
|
+
*/
|
|
132
|
+
get sources(): readonly DataSource[];
|
|
133
|
+
set sources(list: readonly unknown[]);
|
|
134
|
+
/** Adds an outside source of map: checked at once (a `TypeError` for one that is refused), and the Earth draws from it. Returns the function that takes it away. */
|
|
135
|
+
addSource(source: unknown): () => void;
|
|
136
|
+
/** Takes a source away by its id: its loads stop, its tiles are freed, its credit goes. Returns whether there was one. */
|
|
137
|
+
removeSource(id: string): boolean;
|
|
138
|
+
/** Switches a source off (`false`) or on again, and keeps it in the Earth: a layers panel's switch. The attribute `data="own"` ignores every outside source at once. */
|
|
139
|
+
enableSource(id: string, on: boolean): void;
|
|
140
|
+
/**
|
|
141
|
+
* Whose data is in the last drawn frame: the package's own first (its pictures; its finer tiles while a window of them is in view) and then each outside source that gave a tile, with how many (`used`). `creditLine(credits, "en" | "ja")`
|
|
142
|
+
* from `@johnmorrisdotca/chikyu-earth/door` writes them as a line with the licences. `chikyu-creditschange` fires when this set changes (not at each frame), with `detail: { credits }`.
|
|
143
|
+
*/
|
|
144
|
+
credits(): Credit[];
|
|
119
145
|
/** Where the finer map tiles are served from (a folder with `manifest.json`), or `null` for none; the attribute `tiles`. The Earth loads only the tiles in view, over its own pictures. */
|
|
120
146
|
get tiles(): string | null;
|
|
121
147
|
set tiles(value: string | null);
|
|
@@ -170,6 +196,7 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
|
|
|
170
196
|
/** The meteors: whether they are on, the streaks alive now and started so far, the streaks a second being drawn, and the strongest active shower's code and rate. */
|
|
171
197
|
meteors: {
|
|
172
198
|
on: boolean;
|
|
199
|
+
strength: number;
|
|
173
200
|
alive: number;
|
|
174
201
|
spawned: number;
|
|
175
202
|
perSecond: number;
|
|
@@ -8,7 +8,11 @@ import { NOTES_STYLE, setAirNote } from "./air-note.js";
|
|
|
8
8
|
import { cameraCentre, createEarthItem, discRadius, lookAt, newModel } from "./earth.js";
|
|
9
9
|
import { MAX_SATELLITE_SPEED } from "../satellites/limits.js";
|
|
10
10
|
import { MAX_ORBIT_GROUP } from "../space/satellite-layer.js";
|
|
11
|
+
import { readMeteorStrength } from "../meteors/strength.js";
|
|
11
12
|
import { METEOR_NOTE_STYLE, prefersLessMotion, setMeteorNote } from "../meteors/note.js";
|
|
13
|
+
import { createDoorHost } from "../door/host.js";
|
|
14
|
+
import { folderSource } from "../door/map.js";
|
|
15
|
+
import { ownCredit } from "../door/own.js";
|
|
12
16
|
import { createGate, frameCap } from "./gate.js";
|
|
13
17
|
import { setSharedRenderer, setThreeLoader, takeRenderer } from "./shared.js";
|
|
14
18
|
export { setSharedRenderer, setThreeLoader };
|
|
@@ -104,6 +108,7 @@ export const readTime = (value) => {
|
|
|
104
108
|
* where they fall, their height and the showers' dates are real (`@johnmorrisdotca/chikyu-earth/meteors`). They run while the clock runs, at any speed, and not
|
|
105
109
|
* at all while it is held, out of sight, in a hidden tab, or for a reader who prefers reduced motion until the page sets a `speed` (a Play). `chikyu-meteors`
|
|
106
110
|
* is sent when the strongest active shower changes, with `detail: { shower, zhr }` (`shower` is `null` when none is active).
|
|
111
|
+
* `meteors-strength` (0 to 1, the property `meteorsStrength`; 1 when the page says nothing) makes them subtler: fewer streaks and fainter ones, none at 0, and nothing that is real changes.
|
|
107
112
|
*
|
|
108
113
|
* @example
|
|
109
114
|
* ```ts no-run
|
|
@@ -123,7 +128,7 @@ export const readTime = (value) => {
|
|
|
123
128
|
* ```
|
|
124
129
|
*/
|
|
125
130
|
export class ChikyuEarthRealistic extends HTMLElement {
|
|
126
|
-
static observedAttributes = ["cloud-drift", "center", "time", "speed", "clouds", "lights", "light", "live-seconds", "tiles", "camera", "immersive", "meteors", "meteors-label", "air-thickness", "air-label", "lang"];
|
|
131
|
+
static observedAttributes = ["cloud-drift", "center", "time", "speed", "clouds", "lights", "light", "live-seconds", "tiles", "data", "camera", "immersive", "meteors", "meteors-label", "meteors-strength", "air-thickness", "air-label", "lang"];
|
|
127
132
|
#model = newModel();
|
|
128
133
|
#mode = "now";
|
|
129
134
|
#view;
|
|
@@ -139,6 +144,11 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
139
144
|
#state = "loading";
|
|
140
145
|
#tiers = { day: TIERS.day[0], night: TIERS.night[0], clouds: TIERS.clouds[0], water: TIERS.water[0] };
|
|
141
146
|
#taken;
|
|
147
|
+
/** The data door: the outside sources of map this Earth draws from, and whose data is on the screen. */
|
|
148
|
+
#door = createDoorHost(this, {
|
|
149
|
+
own: () => this.#ownCredits(),
|
|
150
|
+
used: () => new Map(Object.entries(this.#model.tiles?.stats.used ?? {})),
|
|
151
|
+
}, { kinds: ["tiles"] }, () => this.#gate?.soon());
|
|
142
152
|
#stage;
|
|
143
153
|
#overlay;
|
|
144
154
|
#pose = null;
|
|
@@ -168,6 +178,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
168
178
|
this.#model.camera = readCamera(this.getAttribute("camera"));
|
|
169
179
|
this.#model.cloudDrift = readDrift(this.getAttribute("cloud-drift"));
|
|
170
180
|
this.#model.airThickness = readAirThickness(this.getAttribute("air-thickness"));
|
|
181
|
+
this.#door.book.ownOnly(this.getAttribute("data") === "own");
|
|
171
182
|
this.#model.speed = this.speed;
|
|
172
183
|
if (!this.hasAttribute("role"))
|
|
173
184
|
this.setAttribute("role", "img");
|
|
@@ -182,6 +193,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
182
193
|
this.#airNote = root.getElementById("air-note");
|
|
183
194
|
this.#played = false;
|
|
184
195
|
this.#model.meteors.on = this.#meteorsAsked();
|
|
196
|
+
this.#model.meteors.strength = readMeteorStrength(this.getAttribute("meteors-strength"));
|
|
185
197
|
this.#model.meteors.running = () => this.speed !== 0 && document.visibilityState !== "hidden" && (this.#played || !prefersLessMotion());
|
|
186
198
|
this.#model.meteors.onShower = (shower, zhr) => this.dispatchEvent(new CustomEvent("chikyu-meteors", { detail: { shower, zhr } }));
|
|
187
199
|
this.#meteorNote();
|
|
@@ -204,17 +216,20 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
204
216
|
assets: taken.renderer.assets,
|
|
205
217
|
textureBase: () => this.#textureBase(),
|
|
206
218
|
cap: () => this.#textureCap(),
|
|
207
|
-
|
|
219
|
+
sources: () => this.#tileSources(),
|
|
208
220
|
onTiles: (layers) => {
|
|
209
221
|
if (!this.hasAttribute("zoom-max") || this.getAttribute("zoom-max") === this.#reach) {
|
|
210
222
|
this.#reach = TILES_ZOOM_MAX;
|
|
211
|
-
|
|
223
|
+
// not written again when it is already there: the view controls take a written attribute as a new limit and bring the view back to fit, which a change of source must not do to a reader's zoom
|
|
224
|
+
if (this.getAttribute("zoom-max") !== TILES_ZOOM_MAX)
|
|
225
|
+
this.setAttribute("zoom-max", TILES_ZOOM_MAX);
|
|
212
226
|
}
|
|
213
227
|
this.dispatchEvent(new CustomEvent("chikyu-tiles", { detail: { layers } }));
|
|
214
228
|
},
|
|
215
229
|
air: () => airFor(this.getAttribute("air")),
|
|
216
230
|
invalidate: () => this.#gate?.soon(),
|
|
217
231
|
onDraw: () => this.#gate?.drawn(),
|
|
232
|
+
onTiled: () => this.#door.announce(),
|
|
218
233
|
onPose: (pose) => {
|
|
219
234
|
if (this.#hands)
|
|
220
235
|
this.#hands.controller.grabRadius = discRadius(pose.width, pose.height, 1);
|
|
@@ -288,6 +303,8 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
288
303
|
this.#startTick();
|
|
289
304
|
else if (name === "tiles")
|
|
290
305
|
this.#gate?.soon();
|
|
306
|
+
else if (name === "data")
|
|
307
|
+
this.#door.book.ownOnly(value === "own");
|
|
291
308
|
else if (name === "camera")
|
|
292
309
|
this.camera = readCamera(value);
|
|
293
310
|
else if (name === "cloud-drift") {
|
|
@@ -296,6 +313,10 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
296
313
|
}
|
|
297
314
|
else if (name === "meteors")
|
|
298
315
|
this.meteors = this.#meteorsAsked();
|
|
316
|
+
else if (name === "meteors-strength") {
|
|
317
|
+
this.#model.meteors.strength = readMeteorStrength(value);
|
|
318
|
+
this.#gate?.soon();
|
|
319
|
+
}
|
|
299
320
|
else if (name === "air-thickness") {
|
|
300
321
|
this.#model.airThickness = readAirThickness(value);
|
|
301
322
|
this.#gate?.soon();
|
|
@@ -340,10 +361,65 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
340
361
|
this.#meteorNote();
|
|
341
362
|
this.#gate?.soon();
|
|
342
363
|
}
|
|
364
|
+
/**
|
|
365
|
+
* How strongly the meteors are drawn, from 0 to 1 (the attribute `meteors-strength`; 1, the full look, when the page says nothing): it scales how bright each streak is and how many are drawn, so 0.3 is
|
|
366
|
+
* fewer and fainter and 0 draws none. It changes nothing that is real: the rates, the showers and `chikyu-meteors` are the same at every strength, and the line under the picture still says the streaks are an illustration.
|
|
367
|
+
* A number outside the range is brought to its nearest end; setting the property writes the attribute.
|
|
368
|
+
*/
|
|
369
|
+
get meteorsStrength() {
|
|
370
|
+
return this.#model.meteors.strength;
|
|
371
|
+
}
|
|
372
|
+
set meteorsStrength(value) {
|
|
373
|
+
this.setAttribute("meteors-strength", String(value));
|
|
374
|
+
}
|
|
343
375
|
/** The controller behind the element's own hands (`set`, `fit`, `state`), while it is in a page. */
|
|
344
376
|
get controller() {
|
|
345
377
|
return this.#hands?.controller;
|
|
346
378
|
}
|
|
379
|
+
/** The map source of each layer now: the last one a page added for it, else the folder of the `tiles` attribute. */
|
|
380
|
+
#tileSources() {
|
|
381
|
+
const folder = this.tiles === null ? undefined : folderSource(this.tiles);
|
|
382
|
+
const day = this.#door.book.mapSources("day")[0] ?? folder;
|
|
383
|
+
const night = this.#door.book.mapSources("night")[0] ?? folder;
|
|
384
|
+
return { ...(day ? { day } : {}), ...(night ? { night } : {}) };
|
|
385
|
+
}
|
|
386
|
+
/** The package's own credits for the last drawn frame: its pictures while it is drawn, and its finer tiles when a window of them is in view (unless a page added the folder itself, which the door counts). */
|
|
387
|
+
#ownCredits() {
|
|
388
|
+
const used = this.#model.tiles?.stats.used ?? {};
|
|
389
|
+
const own = [ownCredit("chikyu-pictures", this.#state === "live" ? 1 : 0)];
|
|
390
|
+
if (this.#door.book.get("chikyu-tiles") === undefined)
|
|
391
|
+
own.push(ownCredit("chikyu-tiles", used["chikyu-tiles"] ?? 0));
|
|
392
|
+
return own;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* The outside sources of map this Earth draws from (the data door): each carries its own licence and credit, and a map source for the `day` or `night` layer takes the place of the folder of tiles for that layer. Assign a list to
|
|
396
|
+
* replace them; a source that is refused (an empty credit, no licence, a clashing id, a kind the Earth does not draw, a layer it does not know) throws a `TypeError` and nothing changes. A property, never an attribute: data is not text.
|
|
397
|
+
*/
|
|
398
|
+
get sources() {
|
|
399
|
+
return this.#door.sources();
|
|
400
|
+
}
|
|
401
|
+
set sources(list) {
|
|
402
|
+
this.#door.setSources(list);
|
|
403
|
+
}
|
|
404
|
+
/** Adds an outside source of map: checked at once (a `TypeError` for one that is refused), and the Earth draws from it. Returns the function that takes it away. */
|
|
405
|
+
addSource(source) {
|
|
406
|
+
return this.#door.book.addSource(source);
|
|
407
|
+
}
|
|
408
|
+
/** Takes a source away by its id: its loads stop, its tiles are freed, its credit goes. Returns whether there was one. */
|
|
409
|
+
removeSource(id) {
|
|
410
|
+
return this.#door.book.removeSource(id);
|
|
411
|
+
}
|
|
412
|
+
/** Switches a source off (`false`) or on again, and keeps it in the Earth: a layers panel's switch. The attribute `data="own"` ignores every outside source at once. */
|
|
413
|
+
enableSource(id, on) {
|
|
414
|
+
this.#door.book.enableSource(id, on);
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Whose data is in the last drawn frame: the package's own first (its pictures; its finer tiles while a window of them is in view) and then each outside source that gave a tile, with how many (`used`). `creditLine(credits, "en" | "ja")`
|
|
418
|
+
* from `@johnmorrisdotca/chikyu-earth/door` writes them as a line with the licences. `chikyu-creditschange` fires when this set changes (not at each frame), with `detail: { credits }`.
|
|
419
|
+
*/
|
|
420
|
+
credits() {
|
|
421
|
+
return this.#door.credits();
|
|
422
|
+
}
|
|
347
423
|
/** Where the finer map tiles are served from (a folder with `manifest.json`), or `null` for none; the attribute `tiles`. The Earth loads only the tiles in view, over its own pictures. */
|
|
348
424
|
get tiles() {
|
|
349
425
|
const given = this.getAttribute("tiles");
|
|
@@ -468,12 +544,12 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
468
544
|
state: this.#state,
|
|
469
545
|
tiers: { ...this.#tiers },
|
|
470
546
|
satellites: this.#satelliteStats(),
|
|
471
|
-
tiles: this.#model.tiles?.stats ?? { ready: false, level: null, held: 0, shown: 0, loading: 0, failed: 0, requested: 0 },
|
|
547
|
+
tiles: this.#model.tiles?.stats ?? { ready: false, level: null, held: 0, shown: 0, loading: 0, failed: 0, requested: 0, heldBytes: 0, refused: 0, used: {} },
|
|
472
548
|
draws: stats?.draws ?? 0,
|
|
473
549
|
contexts: stats?.contexts ?? 0,
|
|
474
550
|
canvas: stats?.canvas ?? { width: 0, height: 0, pixels: 0 },
|
|
475
551
|
assets: { entries: stats?.assets.entries ?? 0, refs: stats?.assets.refs ?? 0 },
|
|
476
|
-
meteors: { on: this.#model.meteors.on, ...this.#model.meteors.drawn },
|
|
552
|
+
meteors: { on: this.#model.meteors.on, strength: this.#model.meteors.strength, ...this.#model.meteors.drawn },
|
|
477
553
|
};
|
|
478
554
|
}
|
|
479
555
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type * as THREE from "three";
|
|
2
2
|
import type { AssetCache } from "@johnmorrisdotca/kazoku-ui/renderer";
|
|
3
|
+
import { type EarthMapSource } from "../door/map.ts";
|
|
3
4
|
import type { ThreeParts } from "./textures.ts";
|
|
4
5
|
import { type TileCamera } from "./tiles.ts";
|
|
5
6
|
/**
|
|
@@ -24,6 +25,18 @@ export declare const TILE_LIMIT = 48;
|
|
|
24
25
|
* ```
|
|
25
26
|
*/
|
|
26
27
|
export declare const TILE_KEEP_MS = 4000;
|
|
28
|
+
/**
|
|
29
|
+
* The bytes of decoded tiles the view holds, all sources together: 72 MB, which is the 48 tiles it has always held (`TILE_LIMIT`, a 512 pixel square with its mipmaps is 1.4 MB). A tile that arrives when the view needs every tile it holds,
|
|
30
|
+
* and does not fit, is refused and counted (`stats.refused`): the view draws what it holds.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { TILE_BUDGET } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
35
|
+
*
|
|
36
|
+
* console.log(TILE_BUDGET / 1024 / 1024);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare const TILE_BUDGET: number;
|
|
27
40
|
type Three = ThreeParts;
|
|
28
41
|
type Uniform<T> = {
|
|
29
42
|
value: T;
|
|
@@ -40,10 +53,17 @@ export interface TileShared {
|
|
|
40
53
|
/** More uniforms the surface program reads (the cloud picture and where the Sun is in the Earth's axes), shared with the sphere's own. */
|
|
41
54
|
extra?: Record<string, Uniform<unknown>>;
|
|
42
55
|
}
|
|
56
|
+
/** The map source each layer is drawn from now, or none: read at every draw. A layer's tiles come from its source alone, and the night tiles go with day tiles (no day source, no tiles). */
|
|
57
|
+
export type TileSources = {
|
|
58
|
+
day?: EarthMapSource;
|
|
59
|
+
night?: EarthMapSource;
|
|
60
|
+
};
|
|
43
61
|
export interface TileSetDeps {
|
|
44
62
|
assets: AssetCache;
|
|
45
|
-
/**
|
|
46
|
-
|
|
63
|
+
/** The sources of the layers now (the data door's: a source a page added, else the `tiles` folder). Read at every draw; the objects are the same while nothing changed. */
|
|
64
|
+
sources: () => TileSources;
|
|
65
|
+
/** The bytes of decoded tiles held, all sources together: `TILE_BUDGET` where left out. */
|
|
66
|
+
budgetBytes?: number;
|
|
47
67
|
/** The widest picture this device holds: tiles are only used where the day picture reaches 4096. */
|
|
48
68
|
cap: () => number;
|
|
49
69
|
/** Ask for one draw. */
|
|
@@ -67,6 +87,11 @@ export interface TileStats {
|
|
|
67
87
|
failed: number;
|
|
68
88
|
/** Tile fetches made. */
|
|
69
89
|
requested: number;
|
|
90
|
+
/** The bytes of decoded tiles held, which never pass the budget except by tiles the view needs now, and tiles that arrived and did not fit, which are not held. */
|
|
91
|
+
heldBytes: number;
|
|
92
|
+
refused: number;
|
|
93
|
+
/** The tiles in view that came from each source, by the source's id: what a credit line counts. */
|
|
94
|
+
used: Record<string, number>;
|
|
70
95
|
}
|
|
71
96
|
export interface TileSet {
|
|
72
97
|
sync(camera: TileCamera, sun: readonly [number, number, number], night: boolean, ratio: number): void;
|