@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
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { DEFAULT_LEVELS, tileKeyParts, tilePlace } from "../door/map.js";
|
|
1
2
|
import { TILE_FRAG, TILE_VERT } from "./shaders.js";
|
|
2
3
|
import { MAX_TEXTURE, TIERS } from "./tiers.js";
|
|
3
|
-
import { coveringTile,
|
|
4
|
+
import { coveringTile, tileColumns, tileLevel, tileRect, tileRows, tilesInView } from "./tiles.js";
|
|
4
5
|
/**
|
|
5
6
|
* The most tiles held at once, day and night together, about a megabyte and a third of graphics memory each (a 512 pixel square with its mipmaps).
|
|
6
7
|
*
|
|
@@ -23,13 +24,51 @@ export const TILE_LIMIT = 48;
|
|
|
23
24
|
* ```
|
|
24
25
|
*/
|
|
25
26
|
export const TILE_KEEP_MS = 4000;
|
|
27
|
+
/**
|
|
28
|
+
* 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,
|
|
29
|
+
* and does not fit, is refused and counted (`stats.refused`): the view draws what it holds.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { TILE_BUDGET } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
34
|
+
*
|
|
35
|
+
* console.log(TILE_BUDGET / 1024 / 1024);
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export const TILE_BUDGET = 72 * 1024 * 1024;
|
|
26
39
|
const IN_FLIGHT = 6;
|
|
27
40
|
const NEW_PER_DRAW = 8;
|
|
28
|
-
const RETRY_MS = 30_000;
|
|
29
41
|
// the day mix reaches full light at 0.22: a tile whose darkest point is brighter than that never shows the night picture
|
|
30
42
|
const NIGHT_BELOW = 0.25;
|
|
31
43
|
const GRID = 16;
|
|
32
44
|
const keyOf = (layer, id) => `${layer}/${id.level}/${id.col}/${id.row}`;
|
|
45
|
+
const tags = new WeakMap();
|
|
46
|
+
let tagged = 0;
|
|
47
|
+
/** A name for a source object, so that two sources with the same id never share a tile in the page's cache. */
|
|
48
|
+
const tagOf = (source) => {
|
|
49
|
+
let tag = tags.get(source);
|
|
50
|
+
if (tag === undefined)
|
|
51
|
+
tags.set(source, (tag = tagged += 1));
|
|
52
|
+
return tag;
|
|
53
|
+
};
|
|
54
|
+
/** The levels a source says it has, kept to those the pyramid's rule allows: a tile's place on the sphere would be wrong otherwise. */
|
|
55
|
+
function cleanLayer(given) {
|
|
56
|
+
if (typeof given !== "object" || given === null)
|
|
57
|
+
return undefined;
|
|
58
|
+
const levels = [];
|
|
59
|
+
for (const entry of given.levels instanceof Array ? given.levels : []) {
|
|
60
|
+
if (typeof entry?.level !== "number" || !Number.isInteger(entry.level) || entry.level < 0 || entry.level > 8 || entry.width !== 1024 * 2 ** entry.level)
|
|
61
|
+
continue;
|
|
62
|
+
levels.push({ level: entry.level, width: entry.width });
|
|
63
|
+
}
|
|
64
|
+
return levels.length > 0 ? { tileSize: 512, levels: levels.sort((a, b) => a.level - b.level) } : undefined;
|
|
65
|
+
}
|
|
66
|
+
const isTile = (tile) => {
|
|
67
|
+
if (typeof tile !== "object" || tile === null)
|
|
68
|
+
return false;
|
|
69
|
+
const one = tile;
|
|
70
|
+
return typeof one.width === "number" && one.width > 0 && Number.isFinite(one.width) && typeof one.height === "number" && one.height > 0 && Number.isFinite(one.height) && typeof one.image === "object" && one.image !== null;
|
|
71
|
+
};
|
|
33
72
|
/** A 0 to 1 grid, the same for every tile: the vertex shader puts it on the sphere. */
|
|
34
73
|
function patch(three) {
|
|
35
74
|
const positions = new Float32Array((GRID + 1) * (GRID + 1) * 3);
|
|
@@ -62,25 +101,33 @@ function patch(three) {
|
|
|
62
101
|
/** Make the set that puts tiles on `parent`, a group that turns with the Earth. */
|
|
63
102
|
export function createTileSet(three, parent, shared, deps) {
|
|
64
103
|
const limit = deps.limit ?? TILE_LIMIT;
|
|
104
|
+
const budget = deps.budgetBytes ?? TILE_BUDGET;
|
|
65
105
|
const clock = deps.now ?? (() => performance.now());
|
|
66
106
|
const geometry = patch(three);
|
|
67
107
|
const entries = new Map();
|
|
68
108
|
const failed = new Map();
|
|
69
109
|
let queue = [];
|
|
70
110
|
let wantedKeys = new Set();
|
|
71
|
-
|
|
111
|
+
/** The sources the levels were read for. */
|
|
112
|
+
let current = {};
|
|
113
|
+
/** Counts the times the sources changed: an answer for an earlier set of them is let go. */
|
|
114
|
+
let generation = 0;
|
|
115
|
+
let refused = 0;
|
|
72
116
|
let manifest;
|
|
73
117
|
let manifestFetch;
|
|
74
118
|
let inFlight = 0;
|
|
75
119
|
let requested = 0;
|
|
76
120
|
let wantedLevel = null;
|
|
77
121
|
let shown = 0;
|
|
122
|
+
/** The tiles in view from each source, by the source's id, as of the last placing. */
|
|
123
|
+
let used = new Map();
|
|
78
124
|
let timer;
|
|
79
125
|
let last;
|
|
80
126
|
let disposed = false;
|
|
81
127
|
const baseDay = TIERS.day[TIERS.day.length - 1];
|
|
82
128
|
const baseNight = TIERS.night[TIERS.night.length - 1];
|
|
83
|
-
const
|
|
129
|
+
const accountOf = (source, key) => `chikyu-earth:tile:${tagOf(source)}:${key}`;
|
|
130
|
+
const take = (layer, id, source) => deps.assets.acquire(accountOf(source, keyOf(layer, id)), () => {
|
|
84
131
|
const texture = new three.Texture();
|
|
85
132
|
texture.wrapS = three.ClampToEdgeWrapping;
|
|
86
133
|
texture.wrapT = three.ClampToEdgeWrapping;
|
|
@@ -88,19 +135,33 @@ export function createTileSet(three, parent, shared, deps) {
|
|
|
88
135
|
texture.magFilter = three.LinearFilter;
|
|
89
136
|
texture.anisotropy = 8;
|
|
90
137
|
const controller = new AbortController();
|
|
91
|
-
const made = { texture, closed: false, ready: Promise.resolve(), release: () => undefined };
|
|
92
|
-
made.ready =
|
|
93
|
-
.then((
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
138
|
+
const made = { texture, bytes: 0, closed: false, ready: Promise.resolve(), release: () => undefined };
|
|
139
|
+
made.ready = Promise.resolve()
|
|
140
|
+
.then(() => {
|
|
141
|
+
// the source names its tiles: the one for this place is the key of the pyramid's tile that matches
|
|
142
|
+
const key = source.need({ ...tilePlace(id), layer }, 1024 * 2 ** id.level).find((one) => {
|
|
143
|
+
const parts = tileKeyParts(one);
|
|
144
|
+
return parts !== undefined && parts.level === id.level && parts.col === id.col && parts.row === id.row;
|
|
145
|
+
});
|
|
146
|
+
if (key === undefined)
|
|
147
|
+
throw new Error(`${keyOf(layer, id)}: the source "${source.info.id}" names no tile for this place`);
|
|
148
|
+
return source.load(key, controller.signal);
|
|
97
149
|
})
|
|
98
|
-
.then((
|
|
99
|
-
|
|
150
|
+
.then((tile) => {
|
|
151
|
+
if (!isTile(tile)) {
|
|
152
|
+
tile?.image?.close?.();
|
|
153
|
+
throw new TypeError(`${keyOf(layer, id)}: the source "${source.info.id}" gave something that is not a picture`);
|
|
154
|
+
}
|
|
155
|
+
const bytes = source.bytes(tile);
|
|
156
|
+
if (typeof bytes !== "number" || !Number.isFinite(bytes) || bytes < 0) {
|
|
157
|
+
tile.image.close?.();
|
|
158
|
+
throw new TypeError(`${keyOf(layer, id)}: the source "${source.info.id}" gave a tile with a size that is not a number`);
|
|
159
|
+
}
|
|
100
160
|
if (made.closed)
|
|
101
|
-
|
|
161
|
+
tile.image.close?.();
|
|
102
162
|
else {
|
|
103
|
-
|
|
163
|
+
made.bytes = bytes;
|
|
164
|
+
texture.image = tile.image;
|
|
104
165
|
texture.needsUpdate = true;
|
|
105
166
|
}
|
|
106
167
|
});
|
|
@@ -119,8 +180,15 @@ export function createTileSet(three, parent, shared, deps) {
|
|
|
119
180
|
parent.remove(entry.mesh);
|
|
120
181
|
entry.mesh.material.dispose();
|
|
121
182
|
}
|
|
122
|
-
|
|
123
|
-
|
|
183
|
+
deps.assets.release(accountOf(entry.source, entry.key));
|
|
184
|
+
};
|
|
185
|
+
/** The bytes of the tiles that have arrived and are held. */
|
|
186
|
+
const heldBytes = () => {
|
|
187
|
+
let sum = 0;
|
|
188
|
+
for (const entry of entries.values())
|
|
189
|
+
if (entry.ready)
|
|
190
|
+
sum += entry.asset.bytes;
|
|
191
|
+
return sum;
|
|
124
192
|
};
|
|
125
193
|
const reset = () => {
|
|
126
194
|
for (const entry of [...entries.values()])
|
|
@@ -133,37 +201,49 @@ export function createTileSet(three, parent, shared, deps) {
|
|
|
133
201
|
manifest = undefined;
|
|
134
202
|
wantedLevel = null;
|
|
135
203
|
shown = 0;
|
|
204
|
+
used = new Map();
|
|
205
|
+
generation += 1;
|
|
136
206
|
};
|
|
137
|
-
|
|
207
|
+
/** Asks each layer's source for its levels, once, when the sources change: a source that has no `levels` has `DEFAULT_LEVELS`, and one that cannot say leaves the layer without tiles. */
|
|
208
|
+
const readManifest = (set) => {
|
|
138
209
|
manifest = undefined;
|
|
139
210
|
const controller = new AbortController();
|
|
140
211
|
manifestFetch = controller;
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if (
|
|
145
|
-
return;
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
if (read) {
|
|
149
|
-
deps.onManifest?.(Object.fromEntries(Object.entries(read.layers).map(([name, layer]) => [name, layer.levels[layer.levels.length - 1].width])));
|
|
150
|
-
deps.invalidate();
|
|
212
|
+
const turn = generation;
|
|
213
|
+
const ask = async (layer) => {
|
|
214
|
+
const source = set[layer];
|
|
215
|
+
if (source === undefined)
|
|
216
|
+
return undefined;
|
|
217
|
+
try {
|
|
218
|
+
return cleanLayer(source.levels === undefined ? DEFAULT_LEVELS : await source.levels(layer, controller.signal));
|
|
151
219
|
}
|
|
152
|
-
|
|
153
|
-
|
|
220
|
+
catch {
|
|
221
|
+
return undefined;
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
void Promise.all([ask("day"), ask("night")]).then(([day, night]) => {
|
|
225
|
+
if (disposed || generation !== turn || manifestFetch !== controller)
|
|
226
|
+
return;
|
|
227
|
+
if (day === undefined) {
|
|
154
228
|
manifest = null;
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const layers = night === undefined ? { day } : { day, night };
|
|
232
|
+
manifest = { layers };
|
|
233
|
+
deps.onManifest?.(Object.fromEntries(Object.entries(layers).map(([name, layer]) => [name, layer.levels[layer.levels.length - 1].width])));
|
|
234
|
+
deps.invalidate();
|
|
155
235
|
});
|
|
156
236
|
};
|
|
157
237
|
const pump = () => {
|
|
158
|
-
const base = current;
|
|
159
|
-
if (base === undefined)
|
|
160
|
-
return;
|
|
161
238
|
while (inFlight < IN_FLIGHT && queue.length > 0) {
|
|
162
239
|
const next = queue.shift();
|
|
163
240
|
const key = keyOf(next.layer, next.id);
|
|
164
241
|
if (entries.has(key))
|
|
165
242
|
continue;
|
|
166
|
-
const
|
|
243
|
+
const source = current[next.layer];
|
|
244
|
+
if (source === undefined)
|
|
245
|
+
continue;
|
|
246
|
+
const entry = { key, layer: next.layer, id: next.id, source, asset: take(next.layer, next.id, source), ready: false, integrated: false, lastWanted: clock() };
|
|
167
247
|
entries.set(key, entry);
|
|
168
248
|
inFlight += 1;
|
|
169
249
|
requested += 1;
|
|
@@ -174,7 +254,16 @@ export function createTileSet(three, parent, shared, deps) {
|
|
|
174
254
|
entry.asset.ready.then(() => {
|
|
175
255
|
if (entries.get(key) === entry) {
|
|
176
256
|
entry.ready = true;
|
|
177
|
-
|
|
257
|
+
// a tile that does not fit under the budget even when everything not needed is let go is refused, and counted: the view draws what it holds
|
|
258
|
+
if (heldBytes() > budget)
|
|
259
|
+
sweep(true);
|
|
260
|
+
if (heldBytes() > budget) {
|
|
261
|
+
refused += 1;
|
|
262
|
+
failed.set(key, clock());
|
|
263
|
+
drop(entry);
|
|
264
|
+
}
|
|
265
|
+
else
|
|
266
|
+
deps.invalidate();
|
|
178
267
|
}
|
|
179
268
|
settled();
|
|
180
269
|
}, () => {
|
|
@@ -283,6 +372,11 @@ export function createTileSet(three, parent, shared, deps) {
|
|
|
283
372
|
};
|
|
284
373
|
const place = (camera, visible) => {
|
|
285
374
|
shown = 0;
|
|
375
|
+
used = new Map();
|
|
376
|
+
const nightBy = new Map();
|
|
377
|
+
for (const entry of entries.values())
|
|
378
|
+
if (entry.layer === "night" && entry.integrated && entry.ready)
|
|
379
|
+
nightBy.set(entry.asset.texture, entry);
|
|
286
380
|
for (const entry of entries.values()) {
|
|
287
381
|
if (!entry.mesh)
|
|
288
382
|
continue;
|
|
@@ -292,18 +386,26 @@ export function createTileSet(three, parent, shared, deps) {
|
|
|
292
386
|
visible.set(entry.id.level, set);
|
|
293
387
|
}
|
|
294
388
|
entry.mesh.visible = set.has(entry.id.row * tileColumns(entry.id.level) + entry.id.col);
|
|
295
|
-
if (entry.mesh.visible)
|
|
389
|
+
if (entry.mesh.visible) {
|
|
296
390
|
shown += 1;
|
|
391
|
+
used.set(entry.source.info.id, (used.get(entry.source.info.id) ?? 0) + 1);
|
|
392
|
+
// a night tile is in view when a day tile in view reads it
|
|
393
|
+
const dark = entry.nightMap?.value ? nightBy.get(entry.nightMap.value) : undefined;
|
|
394
|
+
if (dark)
|
|
395
|
+
used.set(dark.source.info.id, (used.get(dark.source.info.id) ?? 0) + 1);
|
|
396
|
+
}
|
|
297
397
|
}
|
|
298
398
|
};
|
|
299
|
-
/** Free what is no longer wanted: past its time, or the oldest first when over the limit. True when something on the sphere went. */
|
|
300
|
-
const sweep = () => {
|
|
399
|
+
/** Free what is no longer wanted: past its time, or the oldest first when over the limit or the budget (`all`: everything not wanted, for room). True when something on the sphere went. */
|
|
400
|
+
const sweep = (all = false) => {
|
|
301
401
|
const now = clock();
|
|
302
402
|
let changed = false;
|
|
303
403
|
const unwanted = [...entries.values()].filter((entry) => !wantedKeys.has(entry.key)).sort((a, b) => a.lastWanted - b.lastWanted);
|
|
304
404
|
for (const entry of unwanted) {
|
|
305
|
-
if (now - entry.lastWanted < TILE_KEEP_MS && entries.size <= limit)
|
|
405
|
+
if (!all && now - entry.lastWanted < TILE_KEEP_MS && entries.size <= limit && heldBytes() <= budget)
|
|
306
406
|
continue;
|
|
407
|
+
if (all && heldBytes() <= budget)
|
|
408
|
+
break;
|
|
307
409
|
if (entry.mesh?.visible || entry.integrated)
|
|
308
410
|
changed = true;
|
|
309
411
|
drop(entry);
|
|
@@ -339,32 +441,36 @@ export function createTileSet(three, parent, shared, deps) {
|
|
|
339
441
|
loading: [...entries.values()].filter((entry) => !entry.ready).length,
|
|
340
442
|
failed: failed.size,
|
|
341
443
|
requested,
|
|
444
|
+
heldBytes: heldBytes(),
|
|
445
|
+
refused,
|
|
446
|
+
used: Object.fromEntries(used),
|
|
342
447
|
};
|
|
343
448
|
},
|
|
344
449
|
sync(camera, sun, night, ratio) {
|
|
345
450
|
if (disposed)
|
|
346
451
|
return;
|
|
347
|
-
const
|
|
348
|
-
if (
|
|
452
|
+
const now = deps.sources();
|
|
453
|
+
if (now.day !== current.day || now.night !== current.night) {
|
|
349
454
|
reset();
|
|
350
|
-
current =
|
|
351
|
-
if (
|
|
352
|
-
readManifest(
|
|
455
|
+
current = { ...(now.day ? { day: now.day } : {}), ...(now.night ? { night: now.night } : {}) };
|
|
456
|
+
if (current.day !== undefined)
|
|
457
|
+
readManifest(current);
|
|
353
458
|
}
|
|
354
459
|
last = { camera };
|
|
355
|
-
if (current === undefined || !manifest)
|
|
460
|
+
if (current.day === undefined || !manifest)
|
|
356
461
|
return;
|
|
357
|
-
const
|
|
462
|
+
const at = clock();
|
|
358
463
|
const wanted = choose(camera, sun, night, ratio);
|
|
359
464
|
wantedLevel = wanted.level;
|
|
360
465
|
wantedKeys = new Set([...wanted.day.map((tile) => keyOf("day", tile)), ...wanted.night.map((id) => keyOf("night", id))]);
|
|
361
|
-
for (
|
|
362
|
-
|
|
466
|
+
// a tile that failed is asked for again only after it has left the view and come back (the view changed), never on a timer and never while it stays in view: at rest the door sends nothing
|
|
467
|
+
for (const key of [...failed.keys()])
|
|
468
|
+
if (!wantedKeys.has(key))
|
|
363
469
|
failed.delete(key);
|
|
364
470
|
for (const key of wantedKeys) {
|
|
365
471
|
const entry = entries.get(key);
|
|
366
472
|
if (entry)
|
|
367
|
-
entry.lastWanted =
|
|
473
|
+
entry.lastWanted = at;
|
|
368
474
|
}
|
|
369
475
|
queue = [...wanted.day.map((tile) => ({ layer: "day", id: { level: tile.level, col: tile.col, row: tile.row } })), ...wanted.night.map((id) => ({ layer: "night", id }))].filter((item) => !failed.has(keyOf(item.layer, item.id)) && !entries.has(keyOf(item.layer, item.id)));
|
|
370
476
|
pump();
|
|
@@ -397,7 +503,7 @@ export function createTileSet(three, parent, shared, deps) {
|
|
|
397
503
|
clearTimeout(timer);
|
|
398
504
|
timer = undefined;
|
|
399
505
|
reset();
|
|
400
|
-
current =
|
|
506
|
+
current = {};
|
|
401
507
|
geometry.dispose();
|
|
402
508
|
},
|
|
403
509
|
};
|
package/dist/space/element.d.ts
CHANGED
|
@@ -155,6 +155,13 @@ export declare class ChikyuSpace extends HTMLElement {
|
|
|
155
155
|
*/
|
|
156
156
|
get meteors(): boolean;
|
|
157
157
|
set meteors(value: boolean);
|
|
158
|
+
/**
|
|
159
|
+
* 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
|
|
160
|
+
* 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.
|
|
161
|
+
* A number outside the range is brought to its nearest end; setting the property writes the attribute.
|
|
162
|
+
*/
|
|
163
|
+
get meteorsStrength(): number;
|
|
164
|
+
set meteorsStrength(value: number);
|
|
158
165
|
/**
|
|
159
166
|
* How many times its real thickness the air is drawn, from 1 (the true thickness) to 5 (the attribute `air-thickness`; 3 when the page says nothing): see `<chikyu-earth-realistic>`. While it is above 1 the element says so in a line
|
|
160
167
|
* under the picture (`air-label="off"` takes the line away, for a page that says it itself).
|
|
@@ -301,6 +308,7 @@ export declare class ChikyuSpace extends HTMLElement {
|
|
|
301
308
|
/** 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. */
|
|
302
309
|
meteors: {
|
|
303
310
|
on: boolean;
|
|
311
|
+
strength: number;
|
|
304
312
|
alive: number;
|
|
305
313
|
spawned: number;
|
|
306
314
|
perSecond: number;
|
package/dist/space/element.js
CHANGED
|
@@ -4,6 +4,7 @@ import { airFor, readAirThickness } from "../realistic/air.js";
|
|
|
4
4
|
import { createGate, frameCap } from "../realistic/gate.js";
|
|
5
5
|
import { setThreeLoader, takeRenderer } from "../realistic/shared.js";
|
|
6
6
|
import { NOTES_STYLE, setAirNote } from "../realistic/air-note.js";
|
|
7
|
+
import { readMeteorStrength } from "../meteors/strength.js";
|
|
7
8
|
import { METEOR_NOTE_STYLE, prefersLessMotion, setMeteorNote } from "../meteors/note.js";
|
|
8
9
|
import { MAX_TEXTURE } from "../realistic/tiers.js";
|
|
9
10
|
import { MAX_SATELLITE_SPEED } from "../satellites/limits.js";
|
|
@@ -99,7 +100,7 @@ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:h
|
|
|
99
100
|
* ```
|
|
100
101
|
*/
|
|
101
102
|
export class ChikyuSpace extends HTMLElement {
|
|
102
|
-
static observedAttributes = ["cloud-drift", "camera", "earth-size", "earth-x", "earth-y", "center", "time", "speed", "scale", "labels", "orbits", "bodies", "light", "meteors", "meteors-label", "air-thickness", "air-label", "lang"];
|
|
103
|
+
static observedAttributes = ["cloud-drift", "camera", "earth-size", "earth-x", "earth-y", "center", "time", "speed", "scale", "labels", "orbits", "bodies", "light", "meteors", "meteors-label", "meteors-strength", "air-thickness", "air-label", "lang"];
|
|
103
104
|
#model = newSpaceModel();
|
|
104
105
|
#mode = "now";
|
|
105
106
|
#speed = 1;
|
|
@@ -160,6 +161,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
160
161
|
setAirNote(this.#airNote, this, this.#model.airThickness);
|
|
161
162
|
this.#played = false;
|
|
162
163
|
this.#model.meteors.on = this.#meteorsAsked();
|
|
164
|
+
this.#model.meteors.strength = readMeteorStrength(this.getAttribute("meteors-strength"));
|
|
163
165
|
this.#model.meteors.running = () => this.#speed !== 0 && document.visibilityState !== "hidden" && (this.#played || !prefersLessMotion());
|
|
164
166
|
this.#model.meteors.onShower = (shower, zhr) => this.dispatchEvent(new CustomEvent("chikyu-meteors", { detail: { shower, zhr } }));
|
|
165
167
|
setMeteorNote(this.#note, this, this.#model.meteors.on);
|
|
@@ -253,6 +255,10 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
253
255
|
this.earthY = readNumber(value, 0.5, -2, 3);
|
|
254
256
|
else if (name === "meteors")
|
|
255
257
|
this.meteors = this.#meteorsAsked();
|
|
258
|
+
else if (name === "meteors-strength") {
|
|
259
|
+
this.#model.meteors.strength = readMeteorStrength(value);
|
|
260
|
+
this.#gate?.request();
|
|
261
|
+
}
|
|
256
262
|
else if (name === "air-thickness") {
|
|
257
263
|
this.#model.airThickness = readAirThickness(value);
|
|
258
264
|
this.#gate?.request();
|
|
@@ -286,6 +292,17 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
286
292
|
setMeteorNote(this.#note, this, value);
|
|
287
293
|
this.#gate?.request();
|
|
288
294
|
}
|
|
295
|
+
/**
|
|
296
|
+
* 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
|
|
297
|
+
* 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.
|
|
298
|
+
* A number outside the range is brought to its nearest end; setting the property writes the attribute.
|
|
299
|
+
*/
|
|
300
|
+
get meteorsStrength() {
|
|
301
|
+
return this.#model.meteors.strength;
|
|
302
|
+
}
|
|
303
|
+
set meteorsStrength(value) {
|
|
304
|
+
this.setAttribute("meteors-strength", String(value));
|
|
305
|
+
}
|
|
289
306
|
/**
|
|
290
307
|
* How many times its real thickness the air is drawn, from 1 (the true thickness) to 5 (the attribute `air-thickness`; 3 when the page says nothing): see `<chikyu-earth-realistic>`. While it is above 1 the element says so in a line
|
|
291
308
|
* under the picture (`air-label="off"` takes the line away, for a page that says it itself).
|
|
@@ -643,7 +660,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
643
660
|
ride: { riding: this.#model.ride !== null, lost: this.#model.rideLost, gliding: this.#model.transition !== null },
|
|
644
661
|
camera: { position: [this.#model.pose.p[0], this.#model.pose.p[1], this.#model.pose.p[2]], fov: this.#model.pose.fov },
|
|
645
662
|
bodies: { look: this.#model.bodies || painter?.looks?.[0] || "plain", painted: this.#model.painted.bodies, moons: this.#model.painted.moons },
|
|
646
|
-
meteors: { on: this.#model.meteors.on, ...this.#model.meteors.drawn },
|
|
663
|
+
meteors: { on: this.#model.meteors.on, strength: this.#model.meteors.strength, ...this.#model.meteors.drawn },
|
|
647
664
|
};
|
|
648
665
|
}
|
|
649
666
|
#satelliteStats() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/chikyu-earth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.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",
|
|
@@ -119,6 +119,11 @@
|
|
|
119
119
|
"import": "./dist/space/element.js",
|
|
120
120
|
"default": "./dist/space/element.js"
|
|
121
121
|
},
|
|
122
|
+
"./door": {
|
|
123
|
+
"types": "./dist/door/index.d.ts",
|
|
124
|
+
"import": "./dist/door/index.js",
|
|
125
|
+
"default": "./dist/door/index.js"
|
|
126
|
+
},
|
|
122
127
|
"./meteors": {
|
|
123
128
|
"types": "./dist/meteors/index.d.ts",
|
|
124
129
|
"import": "./dist/meteors/index.js",
|