@johnmorrisdotca/wakusei-planets 0.60.0 → 0.62.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 +9 -0
- package/README.md +18 -3
- package/dist/belts/filter.d.ts +128 -0
- package/dist/belts/filter.js +117 -0
- package/dist/belts/index.d.ts +2 -0
- package/dist/belts/index.js +1 -0
- package/dist/bodies/earth.js +22 -1
- package/dist/data/places-moon.d.ts +12 -9
- package/dist/data/places-moon.js +3 -3
- package/dist/element.d.ts +1 -1
- package/dist/flat/system-define.d.ts +3 -0
- package/dist/flat/system-define.js +6 -0
- package/dist/flat/system-element.d.ts +133 -0
- package/dist/flat/system-element.js +1435 -0
- package/dist/flat/system-words.d.ts +28 -0
- package/dist/flat/system-words.js +102 -0
- package/dist/flat/system.d.ts +440 -0
- package/dist/flat/system.js +521 -0
- package/dist/landing-sites.js +6 -6
- package/dist/space/travel.js +36 -5
- package/dist/surface/drive.d.ts +8 -4
- package/dist/surface/drive.js +18 -19
- package/dist/surface/dust.d.ts +2 -1
- package/dist/surface/dust.js +3 -2
- package/dist/surface/element.d.ts +41 -4
- package/dist/surface/element.js +173 -25
- package/dist/surface/flat.d.ts +34 -0
- package/dist/surface/flat.js +63 -0
- package/dist/surface/glsl.d.ts +6 -3
- package/dist/surface/glsl.js +35 -2
- package/dist/surface/height.d.ts +1 -1
- package/dist/surface/index.d.ts +4 -2
- package/dist/surface/index.js +4 -2
- package/dist/surface/land.d.ts +7 -5
- package/dist/surface/land.js +10 -8
- package/dist/surface/model.d.ts +54 -0
- package/dist/surface/model.js +147 -0
- package/dist/surface/rig.d.ts +125 -0
- package/dist/surface/rig.js +107 -0
- package/dist/surface/scene.d.ts +9 -2
- package/dist/surface/scene.js +63 -5
- package/dist/surface/site.d.ts +32 -3
- package/dist/surface/site.js +99 -2
- package/dist/surface/sky.d.ts +92 -1
- package/dist/surface/sky.js +78 -4
- package/package.json +26 -2
package/dist/surface/element.js
CHANGED
|
@@ -9,7 +9,8 @@ import { drop, groundAt } from "./height.js";
|
|
|
9
9
|
import { loadTerrain } from "./load.js";
|
|
10
10
|
import { createSurfaceItem } from "./scene.js";
|
|
11
11
|
import { objectsOf, traverseOf } from "./objects.js";
|
|
12
|
-
import {
|
|
12
|
+
import { standSky } from "./sky.js";
|
|
13
|
+
import { flatTerrain } from "./flat.js";
|
|
13
14
|
import { siteById } from "./site.js";
|
|
14
15
|
import { clampLook, EYE_HEIGHT, stepOver, viewProjection, WALK_SPEED } from "./view.js";
|
|
15
16
|
export { setThreeLoader };
|
|
@@ -49,7 +50,7 @@ const num = (value, fallback) => {
|
|
|
49
50
|
/**
|
|
50
51
|
* The `<wakusei-surface>` custom element: standing on a body.
|
|
51
52
|
*
|
|
52
|
-
* Attributes: `body` (`moon
|
|
53
|
+
* Attributes: `body` (`moon`; the site's own body is the one used), `site` (a name from `SURFACE_SITES`: `apollo-17`, `apollo-15`, `apollo-16`, `chang-e-3`, `chang-e-4`, `perseverance`, `curiosity`; all but `apollo-17` stand on a flat stand-in ground until a height model is added), `time` (an ISO date and time, or milliseconds since 1970; the site's own landing moment when left out; `now` for the real time),
|
|
53
54
|
* `heading` (degrees clockwise from north to look toward), `pitch` (degrees up), `fov` (the view's height in degrees: zoom), `tiles` (the folder the height tiles are served from; the demo site's `tiles/` by default),
|
|
54
55
|
* `lang` (`en` or `ja`: the words on the picture).
|
|
55
56
|
*
|
|
@@ -66,7 +67,7 @@ const num = (value, fallback) => {
|
|
|
66
67
|
* ```
|
|
67
68
|
*/
|
|
68
69
|
export class WakuseiSurface extends HTMLElement {
|
|
69
|
-
static observedAttributes = ["quality", "shadows", "detail", "exposure", "site", "time", "heading", "pitch", "fov", "tiles", "lang", "body", "standby", "scale", "stick", "objects", "drive", "drive-camera", "drive-drag", "watch", "watch-from", "watch-camera"];
|
|
70
|
+
static observedAttributes = ["quality", "shadows", "detail", "exposure", "site", "time", "heading", "pitch", "fov", "tiles", "lang", "body", "standby", "scale", "stick", "objects", "drive", "drive-camera", "drive-drag", "drive-model", "watch", "watch-from", "watch-camera"];
|
|
70
71
|
#root;
|
|
71
72
|
#stage;
|
|
72
73
|
#noteEl;
|
|
@@ -114,6 +115,10 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
114
115
|
#chosen;
|
|
115
116
|
/** The rover being driven (`drive="on"`), the view of it, the driver's own turn of the view, the path left, the dust thrown, and the places it cannot go. */
|
|
116
117
|
#vehicle;
|
|
118
|
+
/** The rover model asked for with `drive-model`, once it has loaded, and the address it was asked for at. */
|
|
119
|
+
#model;
|
|
120
|
+
#modelUrl = "";
|
|
121
|
+
#modelAbort;
|
|
117
122
|
#driveCamera = "chase";
|
|
118
123
|
#camOffset = { azimuth: 0, pitch: 0 };
|
|
119
124
|
#driveEyeUp = 0;
|
|
@@ -236,6 +241,7 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
236
241
|
clearTimeout(this.#landingTimer);
|
|
237
242
|
this.#gate?.cancel();
|
|
238
243
|
clearTimeout(this.#walkTimer);
|
|
244
|
+
this.#dropModel();
|
|
239
245
|
for (const [type, fn] of [["pointerdown", this.#onPointerDown], ["pointermove", this.#onPointerMove], ["pointerup", this.#onPointerUp], ["pointercancel", this.#onPointerUp], ["wheel", this.#onWheel], ["keydown", this.#onKeyDown], ["keyup", this.#onKeyUp], ["blur", this.#onBlur]])
|
|
240
246
|
this.removeEventListener(type, fn);
|
|
241
247
|
this.#view?.dispose();
|
|
@@ -255,6 +261,10 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
255
261
|
this.#syncLanding(name !== "watch");
|
|
256
262
|
return;
|
|
257
263
|
}
|
|
264
|
+
if (name === "drive-model") {
|
|
265
|
+
this.#syncModel();
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
258
268
|
if (name === "drive-camera") {
|
|
259
269
|
this.driveCamera = this.getAttribute("drive-camera") === "seat" ? "seat" : "chase";
|
|
260
270
|
return;
|
|
@@ -302,6 +312,14 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
302
312
|
#site() {
|
|
303
313
|
return siteById(this.getAttribute("site") ?? "apollo-17");
|
|
304
314
|
}
|
|
315
|
+
/** The body's surface gravity at the site, m/s2. */
|
|
316
|
+
#gravity() {
|
|
317
|
+
return this.#site()?.gravity ?? 1.62;
|
|
318
|
+
}
|
|
319
|
+
/** True where no made detail is drawn: the page said `detail="off"`, or the site's ground is a flat stand-in, which has no relief to make detail on (made craters and rocks would be relief that is not there). */
|
|
320
|
+
#noDetail() {
|
|
321
|
+
return this.getAttribute("detail") === "off" || this.#site()?.ground === "flat";
|
|
322
|
+
}
|
|
305
323
|
#readAttributes() {
|
|
306
324
|
const site = this.#site();
|
|
307
325
|
if (site === undefined) {
|
|
@@ -314,8 +332,9 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
314
332
|
this.#time = time === null || time === "" ? site.time : time === "now" ? Date.now() : Number.isFinite(Number(time)) ? Number(time) : Date.parse(time);
|
|
315
333
|
if (!Number.isFinite(this.#time))
|
|
316
334
|
this.#time = site.time;
|
|
317
|
-
this.#sky =
|
|
318
|
-
|
|
335
|
+
this.#sky = standSky(site.body, site.lat, site.lon, this.#time);
|
|
336
|
+
const onMars = site.body === "mars";
|
|
337
|
+
this.setAttribute("aria-label", `${site.name[this.#lang()]}: ${this.#lang() === "ja" ? (onMars ? "火星表面に立った視点" : "月面に立った視点") : onMars ? "standing on Mars" : "standing on the Moon"}`);
|
|
319
338
|
}
|
|
320
339
|
#lang() {
|
|
321
340
|
return this.getAttribute("lang") === "ja" ? "ja" : "en";
|
|
@@ -349,7 +368,7 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
349
368
|
setKeepOut(this.#objects);
|
|
350
369
|
if (!this.#placed) {
|
|
351
370
|
// a step or two from the landing point, out of any made crater
|
|
352
|
-
const stand = this
|
|
371
|
+
const stand = this.#noDetail() ? { x: 0, y: 0 } : standingPlace(0, 0);
|
|
353
372
|
this.#at = { east: stand.x, north: stand.y };
|
|
354
373
|
this.#placed = true;
|
|
355
374
|
this.#syncDrive();
|
|
@@ -382,6 +401,12 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
382
401
|
this.#abort?.abort();
|
|
383
402
|
this.#abort = new AbortController();
|
|
384
403
|
try {
|
|
404
|
+
if (this.#site()?.ground === "flat") {
|
|
405
|
+
// a flat stand-in: nothing to fetch, the ground is whole at once
|
|
406
|
+
this.#terrain = flatTerrain(this.#site());
|
|
407
|
+
this.setAttribute("data-loading", "done");
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
385
410
|
const base = this.getAttribute("tiles");
|
|
386
411
|
const folder = base === null || base === "" ? TILES_BASE : base;
|
|
387
412
|
this.#terrain = await loadTerrain(folder, body, site, {
|
|
@@ -427,7 +452,9 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
427
452
|
const m = this.#terrain?.manifest;
|
|
428
453
|
if (m === undefined)
|
|
429
454
|
return "";
|
|
430
|
-
|
|
455
|
+
if (this.#site()?.ground === "flat")
|
|
456
|
+
return this.#lang() === "ja" ? "地面: 高さのデータが追加されるまでの平らな代用です。ここには、実測した起伏も作った起伏もありません。太陽、空、重力は、この場所と時刻の実際のとおりです。" : "Ground: flat stand-in until a DTM is added. There is no relief here, measured or made. The Sun, sky and gravity are the real ones for this place and time.";
|
|
457
|
+
const made = this.#noDetail() ? "" : this.#lang() === "ja" ? "5 m より細かい地形(小さなクレーター、砂塵、岩)は計算で作ったもので、実測ではありません。" : "Detail finer than the 5 m grid (small craters, dust, rocks) is made, not measured.";
|
|
431
458
|
const things = this.#objects.length === 0 ? "" : this.#lang() === "ja" ? " 地面の物は、公表された座標の位置にこのパッケージが置いたもので、形は簡単な絵です。" : " The things on the ground are placed by this package at published positions, as plain drawings.";
|
|
432
459
|
const picture = m.picture === null || m.picture === undefined ? "" : ` ${m.picture.credit}.`;
|
|
433
460
|
return this.#lang() === "ja" ? `高さの実測: ${m.accuracy}。${m.credit}。${made}${things}` : `Heights measured: ${m.accuracy}. ${m.credit}.${picture} ${made}${things}`;
|
|
@@ -436,7 +463,7 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
436
463
|
#groundAt(east, north) {
|
|
437
464
|
const t = this.#terrain;
|
|
438
465
|
const h = groundAt(t.levels, t.manifest.height, east, north) ?? t.manifest.ground;
|
|
439
|
-
const made = this
|
|
466
|
+
const made = this.#noDetail() ? 0 : madeGround(east, north, 0.35).h;
|
|
440
467
|
return h - t.manifest.ground - drop(Math.hypot(east, north), t.manifest.radius) + made;
|
|
441
468
|
}
|
|
442
469
|
/** The eyes' height over the site's origin: the ground under them (the made craters too: the feet follow them) and a person's height. */
|
|
@@ -468,7 +495,7 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
468
495
|
const site = this.#site();
|
|
469
496
|
if (site === undefined)
|
|
470
497
|
return;
|
|
471
|
-
this.#sky =
|
|
498
|
+
this.#sky = standSky(site.body, site.lat, site.lon, this.#time);
|
|
472
499
|
// `auto`: a draw at rest is timed now and then, and a machine that takes too long at rest steps down (a card does a draw at full quality in a few milliseconds; a phone may not)
|
|
473
500
|
const auto = this.getAttribute("quality") === null || this.getAttribute("quality") === "auto";
|
|
474
501
|
const was = scene.drawMs;
|
|
@@ -499,7 +526,7 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
499
526
|
this.#measured += 1;
|
|
500
527
|
if (this.#drawScale < 1)
|
|
501
528
|
this.#scaled += 1;
|
|
502
|
-
scene.apply({ eye: { east: this.#at.east, north: this.#at.north, up: this.#eyeUp() }, look: this.#look, sky: this.#sky, shadows: this.getAttribute("shadows") !== "off", detail: this
|
|
529
|
+
scene.apply({ eye: { east: this.#at.east, north: this.#at.north, up: this.#eyeUp() }, look: this.#look, sky: this.#sky, shadows: this.getAttribute("shadows") !== "off", detail: !this.#noDetail(), exposure: num(this.getAttribute("exposure"), this.#site()?.body === "mars" ? 1.5 : 1.6), quality: this.#quality(), scale: this.#drawScale, objects: this.#objects.length > 0, ...(this.#vehicle === undefined ? {} : { vehicle: this.#vehicle, ...(this.#model === undefined ? {} : { model: this.#model }), trail: this.#trail, dust: this.#dust.position }), ...(this.#landing === undefined ? {} : { lander: this.#landerState(), dust: this.#dust.position }), measure: measure || this.getAttribute("measure") !== null });
|
|
503
530
|
this.#view.invalidate();
|
|
504
531
|
this.#draws += 1;
|
|
505
532
|
this.#placeLabels();
|
|
@@ -545,6 +572,7 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
545
572
|
const v = this.#vehicle;
|
|
546
573
|
this.#vehicle = undefined;
|
|
547
574
|
this.#trail = [];
|
|
575
|
+
this.#dropModel();
|
|
548
576
|
this.#at = { east: v.east, north: v.north };
|
|
549
577
|
this.#changed();
|
|
550
578
|
return;
|
|
@@ -562,15 +590,78 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
562
590
|
for (const el of this.#labelEls.values())
|
|
563
591
|
el.hidden = true;
|
|
564
592
|
this.choose(undefined);
|
|
593
|
+
this.#syncModel();
|
|
565
594
|
this.#syncDriveCamera();
|
|
566
595
|
this.#changed();
|
|
567
596
|
}
|
|
597
|
+
/** The vehicle's measures: a loaded model's, or the lunar rover's. */
|
|
598
|
+
#rig() {
|
|
599
|
+
return this.#model?.rig ?? ROVER;
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* The rover model being drawn in place of the shapes, with the node names it has and the angles its wheels and pivots were last set to; `undefined` while none is asked for (`drive-model`), while it loads or when it could not be loaded.
|
|
603
|
+
*
|
|
604
|
+
* @example
|
|
605
|
+
* ```ts no-run
|
|
606
|
+
* const surface = document.querySelector("wakusei-surface") as HTMLElement & { driveModel?: { url: string; nodes: readonly string[] } };
|
|
607
|
+
* surface.addEventListener("wakusei-model", () => console.log(surface.driveModel?.nodes.join(" ")));
|
|
608
|
+
* surface.setAttribute("drive-model", "/models/perseverance.glb");
|
|
609
|
+
* ```
|
|
610
|
+
*/
|
|
611
|
+
get driveModel() {
|
|
612
|
+
const m = this.#model;
|
|
613
|
+
return m === undefined ? undefined : { url: this.#modelUrl, nodes: m.nodes, angles: { ...m.angles }, rig: m.rig, renders: m.renders };
|
|
614
|
+
}
|
|
615
|
+
#dropModel() {
|
|
616
|
+
this.#modelAbort?.abort();
|
|
617
|
+
this.#modelAbort = undefined;
|
|
618
|
+
this.#model?.dispose();
|
|
619
|
+
this.#model = undefined;
|
|
620
|
+
this.#modelUrl = "";
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Load the model `drive-model` names, once the rover is being driven: its file is fetched and its loader imported only then. Until it is in (or if it cannot be loaded) the shapes are drawn; `wakusei-model` is sent when it is
|
|
624
|
+
* drawn, with `detail.url` and `detail.nodes`, and `wakusei-model-error` with `detail.url` and `detail.reason` when it cannot be.
|
|
625
|
+
*/
|
|
626
|
+
#syncModel() {
|
|
627
|
+
const url = this.getAttribute("drive-model") ?? "";
|
|
628
|
+
if (this.#vehicle === undefined || url === "") {
|
|
629
|
+
this.#dropModel();
|
|
630
|
+
if (this.#vehicle !== undefined)
|
|
631
|
+
this.#changed();
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
if (url === this.#modelUrl)
|
|
635
|
+
return;
|
|
636
|
+
this.#dropModel();
|
|
637
|
+
this.#modelUrl = url;
|
|
638
|
+
const abort = new AbortController();
|
|
639
|
+
this.#modelAbort = abort;
|
|
640
|
+
void import("./model.js")
|
|
641
|
+
.then((m) => m.loadVehicleModel(url, { signal: abort.signal }))
|
|
642
|
+
.then((model) => {
|
|
643
|
+
if (abort.signal.aborted) {
|
|
644
|
+
model.dispose();
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
this.#model = model;
|
|
648
|
+
this.#syncDriveCamera();
|
|
649
|
+
this.#changed();
|
|
650
|
+
this.dispatchEvent(new CustomEvent("wakusei-model", { detail: { url, nodes: model.nodes }, bubbles: true, composed: true }));
|
|
651
|
+
})
|
|
652
|
+
.catch((error) => {
|
|
653
|
+
if (abort.signal.aborted)
|
|
654
|
+
return;
|
|
655
|
+
this.#modelUrl = "";
|
|
656
|
+
this.dispatchEvent(new CustomEvent("wakusei-model-error", { detail: { url, reason: error instanceof Error ? error.message : String(error) }, bubbles: true, composed: true }));
|
|
657
|
+
});
|
|
658
|
+
}
|
|
568
659
|
/** The eyes where the view of the rover puts them. */
|
|
569
660
|
#syncDriveCamera() {
|
|
570
661
|
const v = this.#vehicle;
|
|
571
662
|
if (v === undefined)
|
|
572
663
|
return;
|
|
573
|
-
const view = driveView(v, this.#driveCamera, this.#camOffset, (e, n) => this.#groundAt(e, n), this.driveDrag);
|
|
664
|
+
const view = driveView(v, this.#driveCamera, this.#camOffset, (e, n) => this.#groundAt(e, n), this.driveDrag, this.#rig());
|
|
574
665
|
this.#at = { east: view.eye.east, north: view.eye.north };
|
|
575
666
|
this.#driveEyeUp = view.eye.up;
|
|
576
667
|
this.#look = clampLook({ azimuth: view.azimuth, pitch: view.pitch, fov: this.#look.fov });
|
|
@@ -581,7 +672,7 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
581
672
|
if (this.#blockersAt === undefined || Math.hypot(v.east - this.#blockersAt.east, v.north - this.#blockersAt.north) > 8) {
|
|
582
673
|
this.#blockersAt = { east: v.east, north: v.north };
|
|
583
674
|
const list = [];
|
|
584
|
-
if (this
|
|
675
|
+
if (!this.#noDetail())
|
|
585
676
|
for (const rock of rocksAround(v.east, v.north, 28, 0.0024))
|
|
586
677
|
if (rock.size >= 0.6)
|
|
587
678
|
list.push({ x: rock.x, y: rock.y, r: rock.size * 0.5 + 1.1 });
|
|
@@ -599,17 +690,18 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
599
690
|
const ground = (e, n) => this.#groundAt(e, n);
|
|
600
691
|
const blockers = this.#obstacles();
|
|
601
692
|
const blocked = (e, n) => blockers.some((b) => (e - b.x) ** 2 + (n - b.y) ** 2 < b.r * b.r);
|
|
693
|
+
const rig = this.#rig();
|
|
602
694
|
const steps = Math.max(1, Math.ceil(seconds * 60));
|
|
603
695
|
const dt = seconds / steps;
|
|
604
696
|
for (let i = 0; i < steps; i += 1) {
|
|
605
|
-
v = driveStep(v, input, dt, ground, blocked);
|
|
697
|
+
v = driveStep(v, input, dt, ground, blocked, rig, this.#gravity());
|
|
606
698
|
// each wheel on the ground throws grains up and back: the faster, the more
|
|
607
699
|
if (!v.airborne && Math.abs(v.speed) > 0.6) {
|
|
608
700
|
const h = (v.heading * Math.PI) / 180;
|
|
609
701
|
const [fx, fz] = [Math.sin(h), Math.cos(h)];
|
|
610
702
|
const grains = Math.abs(v.speed) * dt * 26;
|
|
611
703
|
const [rx, rz] = [Math.cos(h), -Math.sin(h)];
|
|
612
|
-
for (const [wx, , wz] of
|
|
704
|
+
for (const [wx, , wz] of rig.wheels) {
|
|
613
705
|
const w = toWorld(v, [wx, 0, wz]);
|
|
614
706
|
for (let k = 0; k < grains + Math.random() * 0.999; k += 1) {
|
|
615
707
|
// thrown up and back from the tyre in a fan: the faster the rover, the wider and farther
|
|
@@ -619,7 +711,7 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
619
711
|
}
|
|
620
712
|
}
|
|
621
713
|
}
|
|
622
|
-
this.#dust.step(dt, ground);
|
|
714
|
+
this.#dust.step(dt, ground, this.#gravity());
|
|
623
715
|
}
|
|
624
716
|
this.#vehicle = v;
|
|
625
717
|
// the tracks: a point every 1.2 m
|
|
@@ -659,7 +751,26 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
659
751
|
return true;
|
|
660
752
|
}
|
|
661
753
|
// --- watching the landing (`watch="landing"`): Apollo 17's powered descent from the lunar module's window or from the ground ---------------------------------------------------------------------
|
|
662
|
-
/**
|
|
754
|
+
/**
|
|
755
|
+
* The descent being watched: its clock in seconds from ignition, whether it runs, the camera and what the lunar module is doing at that moment; `undefined` when it is not watched.
|
|
756
|
+
*
|
|
757
|
+
* Two events say what happens to it, both bubbling and composed. `wakusei-landing-state` is sent when it starts or stops running (`playLanding()`, `pauseLanding()`, and the clock reaching the touchdown),
|
|
758
|
+
* when `landingRate` changes and when `watch-camera` changes; its `detail` is `{ t, playing, rate, camera, ended }` (`t` in seconds from ignition, `ended` true at the touchdown), so a page can keep the pause
|
|
759
|
+
* state without reading `landing` every second. `wakusei-landing-ended` is sent once each time the clock arrives at the touchdown (T+12:05, 725 s), by running or by a seek; its `detail` is
|
|
760
|
+
* `{ t: 725, rate, camera }`, and it is sent again only after the clock has left the touchdown and come back.
|
|
761
|
+
*
|
|
762
|
+
* @example
|
|
763
|
+
* ```ts no-run
|
|
764
|
+
* import type { WakuseiSurface } from "@johnmorrisdotca/wakusei-planets/surface/element";
|
|
765
|
+
*
|
|
766
|
+
* const view = document.querySelector("wakusei-surface") as WakuseiSurface;
|
|
767
|
+
* view.addEventListener("wakusei-landing-state", (event) => {
|
|
768
|
+
* const { playing, rate, camera } = (event as CustomEvent).detail;
|
|
769
|
+
* location.hash = `${playing ? "play" : "pause"}-${rate}-${camera}`;
|
|
770
|
+
* });
|
|
771
|
+
* view.addEventListener("wakusei-landing-ended", () => console.log("the lunar module is down"));
|
|
772
|
+
* ```
|
|
773
|
+
*/
|
|
663
774
|
get landing() {
|
|
664
775
|
const l = this.#landing;
|
|
665
776
|
if (l === undefined)
|
|
@@ -689,8 +800,14 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
689
800
|
return this.#landing?.rate ?? 1;
|
|
690
801
|
}
|
|
691
802
|
set landingRate(value) {
|
|
692
|
-
|
|
693
|
-
|
|
803
|
+
const l = this.#landing;
|
|
804
|
+
if (l === undefined)
|
|
805
|
+
return;
|
|
806
|
+
const rate = Math.min(16, Math.max(0.25, value));
|
|
807
|
+
if (rate === l.rate)
|
|
808
|
+
return;
|
|
809
|
+
l.rate = rate;
|
|
810
|
+
this.#landingAnnounce();
|
|
694
811
|
}
|
|
695
812
|
/** Run the descent from where the clock is (from the start again if it had ended). */
|
|
696
813
|
playLanding() {
|
|
@@ -699,17 +816,31 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
699
816
|
return;
|
|
700
817
|
if (l.t >= LANDING.duration)
|
|
701
818
|
this.landingTime = l.camera === "ground" ? 540 : LANDING.viewStart;
|
|
819
|
+
const was = l.playing;
|
|
702
820
|
l.playing = true;
|
|
703
821
|
this.#landingAt = performance.now();
|
|
822
|
+
if (!was)
|
|
823
|
+
this.#landingAnnounce();
|
|
704
824
|
this.#landingTick();
|
|
705
825
|
}
|
|
706
826
|
/** Hold the descent where it is. */
|
|
707
827
|
pauseLanding() {
|
|
708
|
-
|
|
828
|
+
const l = this.#landing;
|
|
829
|
+
if (l === undefined)
|
|
709
830
|
return;
|
|
710
|
-
|
|
831
|
+
const was = l.playing;
|
|
832
|
+
l.playing = false;
|
|
711
833
|
clearTimeout(this.#landingTimer);
|
|
712
834
|
this.#landingFrame(0, true);
|
|
835
|
+
if (was)
|
|
836
|
+
this.#landingAnnounce();
|
|
837
|
+
}
|
|
838
|
+
/** Tell a page the descent's state changed: `wakusei-landing-state` with the clock, whether it runs, the rate, the camera and whether it has ended. */
|
|
839
|
+
#landingAnnounce() {
|
|
840
|
+
const l = this.#landing;
|
|
841
|
+
if (l === undefined)
|
|
842
|
+
return;
|
|
843
|
+
this.dispatchEvent(new CustomEvent("wakusei-landing-state", { detail: { t: l.t, playing: l.playing, rate: l.rate, camera: l.camera, ended: l.t >= LANDING.duration }, bubbles: true, composed: true }));
|
|
713
844
|
}
|
|
714
845
|
/** The touchdown point: where the lunar module stands at Apollo 17 (the published place), or the site point where it has none. */
|
|
715
846
|
#touchdown() {
|
|
@@ -746,13 +877,16 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
746
877
|
return;
|
|
747
878
|
if (this.#landing.camera !== camera)
|
|
748
879
|
this.#look = clampLook({ ...this.#look, fov: camera === "ground" ? 27 : 74 });
|
|
880
|
+
const changed = this.#landing.camera !== camera;
|
|
749
881
|
this.#landing.camera = camera;
|
|
750
882
|
this.#landing.from = from;
|
|
751
883
|
this.#camOffset = { azimuth: 0, pitch: 0 };
|
|
752
884
|
this.#landingFrame(0, true);
|
|
885
|
+
if (changed)
|
|
886
|
+
this.#landingAnnounce();
|
|
753
887
|
return;
|
|
754
888
|
}
|
|
755
|
-
this.#landing = { t: camera === "ground" ? 540 : LANDING.viewStart, playing: true, rate: 1, camera, from, passed: 0, second: -1 };
|
|
889
|
+
this.#landing = { t: camera === "ground" ? 540 : LANDING.viewStart, playing: true, rate: 1, camera, from, passed: 0, second: -1, ended: false };
|
|
756
890
|
this.#landing.passed = calloutsBy(this.#landing.t).length;
|
|
757
891
|
this.#dust = new DustField(20000, 17);
|
|
758
892
|
this.#camOffset = { azimuth: 0, pitch: 0 };
|
|
@@ -772,6 +906,13 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
772
906
|
const l = this.#landing;
|
|
773
907
|
if (l === undefined)
|
|
774
908
|
return;
|
|
909
|
+
// arriving at the touchdown, by running or by a seek, stops the clock
|
|
910
|
+
const atEnd = l.t >= LANDING.duration;
|
|
911
|
+
const stopped = atEnd && l.playing;
|
|
912
|
+
if (stopped) {
|
|
913
|
+
l.playing = false;
|
|
914
|
+
clearTimeout(this.#landingTimer);
|
|
915
|
+
}
|
|
775
916
|
const pose = landingAt(l.t);
|
|
776
917
|
const td = this.#touchdown();
|
|
777
918
|
const ground = (e, n) => this.#groundAt(e, n);
|
|
@@ -793,7 +934,7 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
793
934
|
}
|
|
794
935
|
}
|
|
795
936
|
if (seconds > 0)
|
|
796
|
-
this.#dust.step(seconds, ground);
|
|
937
|
+
this.#dust.step(seconds, ground, this.#gravity());
|
|
797
938
|
if (l.camera === "lander") {
|
|
798
939
|
this.#at = { east: lx, north: ly };
|
|
799
940
|
this.#landingEyeUp = lz + pose.altitude + 4;
|
|
@@ -859,6 +1000,15 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
859
1000
|
l.second = second;
|
|
860
1001
|
this.dispatchEvent(new CustomEvent("wakusei-landing-clock", { detail: { t: l.t, clock, altitude: pose.altitude, speed: pose.speed, descent: pose.descent, playing: l.playing, callout: newest === undefined ? undefined : { id: newest.id, t: newest.t, en: newest.en, ja: newest.ja, reported: newest.reported } }, bubbles: true, composed: true }));
|
|
861
1002
|
}
|
|
1003
|
+
if (stopped)
|
|
1004
|
+
this.#landingAnnounce();
|
|
1005
|
+
// the descent ends once each time the clock arrives at the touchdown; a seek back or a play from the start makes it ready to end again
|
|
1006
|
+
if (atEnd && !l.ended) {
|
|
1007
|
+
l.ended = true;
|
|
1008
|
+
this.dispatchEvent(new CustomEvent("wakusei-landing-ended", { detail: { t: l.t, rate: l.rate, camera: l.camera }, bubbles: true, composed: true }));
|
|
1009
|
+
}
|
|
1010
|
+
else if (!atEnd)
|
|
1011
|
+
l.ended = false;
|
|
862
1012
|
this.#changed(l.playing);
|
|
863
1013
|
}
|
|
864
1014
|
/** While the descent runs: the clock moves by the real time between frames (times the rate), at most thirty times a second; at the touchdown, or paused, nothing is drawn. */
|
|
@@ -872,10 +1022,8 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
872
1022
|
this.#landingAt = now;
|
|
873
1023
|
const seconds = Math.min(dt * l.rate, LANDING.duration - l.t);
|
|
874
1024
|
l.t += seconds;
|
|
875
|
-
if (l.t >= LANDING.duration - 1e-6)
|
|
1025
|
+
if (l.t >= LANDING.duration - 1e-6)
|
|
876
1026
|
l.t = LANDING.duration;
|
|
877
|
-
l.playing = false;
|
|
878
|
-
}
|
|
879
1027
|
this.#landingFrame(seconds, false);
|
|
880
1028
|
if (l.playing)
|
|
881
1029
|
this.#landingTimer = setTimeout(this.#landingTick, 33);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { TerrainManifest } from "./height.ts";
|
|
2
|
+
import type { Terrain } from "./load.ts";
|
|
3
|
+
import type { SurfaceSite } from "./site.ts";
|
|
4
|
+
/**
|
|
5
|
+
* The manifest of a flat stand-in for a site: the same shape as a measured site's, with one tile to a level (the ground does not change, so a wider step costs nothing), no picture and no baked horizon, and the ground
|
|
6
|
+
* at the datum (height 0). Its credit and accuracy lines say it is not measured.
|
|
7
|
+
*
|
|
8
|
+
* @param site - A site (any, though only a `flat` one is drawn from it).
|
|
9
|
+
* @returns The manifest.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { flatManifest, siteById } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
14
|
+
*
|
|
15
|
+
* const manifest = flatManifest(siteById("perseverance")!);
|
|
16
|
+
* console.log(manifest.body, manifest.radius, manifest.levels.length, manifest.accuracy);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function flatManifest(site: SurfaceSite): TerrainManifest;
|
|
20
|
+
/**
|
|
21
|
+
* The terrain of a flat stand-in, whole at once with nothing fetched: every level is the datum.
|
|
22
|
+
*
|
|
23
|
+
* @param site - The site.
|
|
24
|
+
* @returns The terrain, as `loadTerrain` gives it (`complete` is already settled, no bytes were fetched).
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { flatTerrain, groundAt, siteById } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
29
|
+
*
|
|
30
|
+
* const terrain = flatTerrain(siteById("curiosity")!);
|
|
31
|
+
* console.log(terrain.bytes, groundAt(terrain.levels, terrain.manifest.height, 120, -40));
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function flatTerrain(site: SurfaceSite): Terrain;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** The mean radii the heights are measured from, in metres: the Moon's from LRO (1737.4 km, as the tiles of `make-moon-terrain.py`), Mars's the IAU mean (NASA's fact sheet, 3389.5 km). */
|
|
2
|
+
const RADIUS = { moon: 1_737_400, mars: 3_389_500 };
|
|
3
|
+
const TILE = 256;
|
|
4
|
+
/** The extent each level covers, as a half side in metres: the four levels of a measured site (5 m a sample over 8 tiles, 20 m, 80 m, and the far ground at 480 m over 4), here one tile each at a wider step. */
|
|
5
|
+
const LEVELS = [
|
|
6
|
+
{ id: "h5", half: 5120 },
|
|
7
|
+
{ id: "h20", half: 20_480 },
|
|
8
|
+
{ id: "h80", half: 81_920 },
|
|
9
|
+
{ id: "far", half: 245_760 },
|
|
10
|
+
];
|
|
11
|
+
/**
|
|
12
|
+
* The manifest of a flat stand-in for a site: the same shape as a measured site's, with one tile to a level (the ground does not change, so a wider step costs nothing), no picture and no baked horizon, and the ground
|
|
13
|
+
* at the datum (height 0). Its credit and accuracy lines say it is not measured.
|
|
14
|
+
*
|
|
15
|
+
* @param site - A site (any, though only a `flat` one is drawn from it).
|
|
16
|
+
* @returns The manifest.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { flatManifest, siteById } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
21
|
+
*
|
|
22
|
+
* const manifest = flatManifest(siteById("perseverance")!);
|
|
23
|
+
* console.log(manifest.body, manifest.radius, manifest.levels.length, manifest.accuracy);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export function flatManifest(site) {
|
|
27
|
+
return {
|
|
28
|
+
version: 1,
|
|
29
|
+
body: site.body,
|
|
30
|
+
site: site.id,
|
|
31
|
+
name: site.name,
|
|
32
|
+
lat: site.lat,
|
|
33
|
+
lon: site.lon,
|
|
34
|
+
radius: RADIUS[site.body],
|
|
35
|
+
tile: TILE,
|
|
36
|
+
height: { min: 0, range: 1 },
|
|
37
|
+
ground: 0,
|
|
38
|
+
levels: LEVELS.map((level) => ({ id: level.id, res: (2 * level.half) / TILE, tiles: 1, half: level.half })),
|
|
39
|
+
picture: null,
|
|
40
|
+
horizon: null,
|
|
41
|
+
credit: "no height model for this site yet",
|
|
42
|
+
accuracy: "ground: flat stand-in until a DTM is added; there is no relief here, measured or made",
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The terrain of a flat stand-in, whole at once with nothing fetched: every level is the datum.
|
|
47
|
+
*
|
|
48
|
+
* @param site - The site.
|
|
49
|
+
* @returns The terrain, as `loadTerrain` gives it (`complete` is already settled, no bytes were fetched).
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* import { flatTerrain, groundAt, siteById } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
54
|
+
*
|
|
55
|
+
* const terrain = flatTerrain(siteById("curiosity")!);
|
|
56
|
+
* console.log(terrain.bytes, groundAt(terrain.levels, terrain.manifest.height, 120, -40));
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export function flatTerrain(site) {
|
|
60
|
+
const manifest = flatManifest(site);
|
|
61
|
+
const levels = manifest.levels.map((info) => ({ ...info, size: TILE, data: new Uint8Array(TILE * TILE * 4) }));
|
|
62
|
+
return { manifest, levels, pictures: [], horizons: [], bytes: 0, firstBytes: 0, complete: Promise.resolve() };
|
|
63
|
+
}
|