@johnmorrisdotca/wakusei-planets 0.48.0 → 0.50.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 +1 -1
- package/README.md +3 -3
- package/dist/scene/textures.d.ts +2 -2
- package/dist/surface/drive.d.ts +181 -0
- package/dist/surface/drive.js +247 -0
- package/dist/surface/dust.d.ts +46 -0
- package/dist/surface/dust.js +96 -0
- package/dist/surface/element.d.ts +46 -0
- package/dist/surface/element.js +426 -6
- package/dist/surface/glsl.d.ts +6 -0
- package/dist/surface/glsl.js +56 -1
- package/dist/surface/index.d.ts +4 -1
- package/dist/surface/index.js +4 -1
- package/dist/surface/land.d.ts +6 -0
- package/dist/surface/land.js +8 -0
- package/dist/surface/landing.d.ts +134 -0
- package/dist/surface/landing.js +237 -0
- package/dist/surface/scene.d.ts +16 -0
- package/dist/surface/scene.js +292 -3
- package/dist/surface/shapes.d.ts +16 -2
- package/dist/surface/shapes.js +42 -9
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/surface/element.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { createGate, frameCap } from "../gate.js";
|
|
2
2
|
import { setThreeLoader, takeRenderer } from "../scene/shared.js";
|
|
3
3
|
import { TILES_BASE } from "../scene/textures.js";
|
|
4
|
-
import { madeGround, setKeepOut, standingPlace } from "./detail.js";
|
|
4
|
+
import { madeGround, rocksAround, setKeepOut, standingPlace } from "./detail.js";
|
|
5
|
+
import { driveStep, driveView, ROVER, startDrive, toWorld } from "./drive.js";
|
|
6
|
+
import { DustField } from "./dust.js";
|
|
7
|
+
import { calloutsBy, clockText, LANDING, landingAt } from "./landing.js";
|
|
5
8
|
import { drop, groundAt } from "./height.js";
|
|
6
9
|
import { loadTerrain } from "./load.js";
|
|
7
10
|
import { createSurfaceItem } from "./scene.js";
|
|
@@ -25,10 +28,20 @@ const TEMPLATE = `<style>
|
|
|
25
28
|
.label[aria-pressed="true"] { background: rgba(255, 255, 255, 0.85); color: #10141c; }
|
|
26
29
|
#about { position: absolute; left: 8px; right: 8px; top: 8px; margin: 0; padding: 6px 10px; border-radius: 8px; background: rgba(0, 0, 0, 0.62); color: #e8ecf2; font: 400 12px/1.4 system-ui, sans-serif; pointer-events: none; max-width: 32em; }
|
|
27
30
|
#about[hidden] { display: none; }
|
|
31
|
+
#landing { position: absolute; inset: 8px; margin: 0; color: #e8ecf2; font: 400 12px/1.4 system-ui, sans-serif; text-shadow: 0 1px 2px #000; pointer-events: none; }
|
|
32
|
+
#landing[hidden] { display: none; }
|
|
33
|
+
#clock { margin: 0 0 4px; font-weight: 600; }
|
|
34
|
+
#callouts { margin: 0; padding: 0; list-style: none; }
|
|
35
|
+
#callouts li { opacity: 0.75; }
|
|
36
|
+
#callouts li:last-child { opacity: 1; font-weight: 600; }
|
|
37
|
+
#marker { position: absolute; left: 0; top: 0; width: 24px; height: 24px; margin: -12px 0 0 -12px; box-sizing: border-box; border: 1.5px solid rgba(255, 255, 255, 0.9); border-radius: 50%; box-shadow: 0 0 3px #000; pointer-events: none; will-change: transform; }
|
|
38
|
+
#markerText { position: absolute; left: 0; top: 0; margin: 0; font: 600 11px/1.2 system-ui, sans-serif; color: #fff; text-shadow: 0 0 3px #000, 0 0 3px #000; white-space: nowrap; pointer-events: none; will-change: transform; }
|
|
39
|
+
#marker[hidden], #markerText[hidden] { display: none; }
|
|
40
|
+
#curve { position: absolute; left: 0; right: 0; bottom: 50px; margin: 0; font-size: 11px; color: #c8ccd4; }
|
|
28
41
|
#stick { position: absolute; left: 18px; bottom: 44px; width: 104px; height: 104px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.4); background: rgba(255, 255, 255, 0.08); touch-action: none; }
|
|
29
42
|
#stick[hidden] { display: none; }
|
|
30
43
|
#knob { position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%; background: rgba(255, 255, 255, 0.55); pointer-events: none; }
|
|
31
|
-
</style><div id="stage"></div><p id="note"></p><p id="status" role="status"></p><div id="labels"></div><p id="about" role="status" hidden></p><div id="stick" part="stick" role="group" aria-label="Walk" hidden><div id="knob"></div></div>`;
|
|
44
|
+
</style><div id="stage"></div><p id="note"></p><p id="status" role="status"></p><div id="labels"></div><div id="landing" hidden><span id="marker" hidden></span><span id="markerText" hidden></span><p id="clock"></p><ul id="callouts"></ul><p id="curve"></p></div><p id="about" role="status" hidden></p><div id="stick" part="stick" role="group" aria-label="Walk" hidden><div id="knob"></div></div>`;
|
|
32
45
|
const num = (value, fallback) => {
|
|
33
46
|
const n = value === null || value.trim() === "" ? NaN : Number(value);
|
|
34
47
|
return Number.isFinite(n) ? n : fallback;
|
|
@@ -53,7 +66,7 @@ const num = (value, fallback) => {
|
|
|
53
66
|
* ```
|
|
54
67
|
*/
|
|
55
68
|
export class WakuseiSurface extends HTMLElement {
|
|
56
|
-
static observedAttributes = ["quality", "shadows", "detail", "exposure", "site", "time", "heading", "pitch", "fov", "tiles", "lang", "body", "standby", "scale", "stick", "objects"];
|
|
69
|
+
static observedAttributes = ["quality", "shadows", "detail", "exposure", "site", "time", "heading", "pitch", "fov", "tiles", "lang", "body", "standby", "scale", "stick", "objects", "drive", "drive-camera", "watch", "watch-from", "watch-camera"];
|
|
57
70
|
#root;
|
|
58
71
|
#stage;
|
|
59
72
|
#noteEl;
|
|
@@ -99,6 +112,20 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
99
112
|
#objects = [];
|
|
100
113
|
#labelEls = new Map();
|
|
101
114
|
#chosen;
|
|
115
|
+
/** 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
|
+
#vehicle;
|
|
117
|
+
#driveCamera = "chase";
|
|
118
|
+
#camOffset = { azimuth: 0, pitch: 0 };
|
|
119
|
+
#driveEyeUp = 0;
|
|
120
|
+
#trail = [];
|
|
121
|
+
#dust = new DustField(900, 17);
|
|
122
|
+
#blockers = [];
|
|
123
|
+
#blockersAt;
|
|
124
|
+
/** The descent being watched (`watch="landing"`): the clock in seconds from ignition, whether it runs, how fast, which camera, where the ground camera stands, and how far the callouts have got. */
|
|
125
|
+
#landing;
|
|
126
|
+
#landingTimer;
|
|
127
|
+
#landingAt = 0;
|
|
128
|
+
#landingEyeUp = 0;
|
|
102
129
|
#stickPointer = -1;
|
|
103
130
|
#pointers = new Map();
|
|
104
131
|
#pinch = 0;
|
|
@@ -150,7 +177,7 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
150
177
|
/** Numbers for a test or a status line: the draws, the tiles, the renderer's own counts, the mesh, the quality of the last draw and the milliseconds of the last measured one. */
|
|
151
178
|
get stats() {
|
|
152
179
|
const scene = this.#view?.scene;
|
|
153
|
-
return { state: this.#state, draws: this.#draws, tiles: this.#progress, renderer: this.#renderer?.stats, mesh: scene?.mesh, quality: this.#quality(), scale: this.#drawScale, scaled: this.#scaled, drawMs: scene?.drawMs ?? this.#drawMs, rocks: scene?.rocks ?? 0 };
|
|
180
|
+
return { state: this.#state, draws: this.#draws, tiles: this.#progress, renderer: this.#renderer?.stats, mesh: scene?.mesh, quality: this.#quality(), scale: this.#drawScale, scaled: this.#scaled, landing: this.landing, vehicle: this.#vehicle === undefined ? undefined : { ...this.#vehicle, spin: [...this.#vehicle.spin] }, drawMs: scene?.drawMs ?? this.#drawMs, rocks: scene?.rocks ?? 0 };
|
|
154
181
|
}
|
|
155
182
|
/** The quality of the next draw: the `quality` attribute, or in `auto` the quality of motion while the view moves and the machine's own quality of rest otherwise. */
|
|
156
183
|
#quality() {
|
|
@@ -206,6 +233,7 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
206
233
|
this.#abort?.abort();
|
|
207
234
|
clearTimeout(this.#flush);
|
|
208
235
|
this.#flush = undefined;
|
|
236
|
+
clearTimeout(this.#landingTimer);
|
|
209
237
|
this.#gate?.cancel();
|
|
210
238
|
clearTimeout(this.#walkTimer);
|
|
211
239
|
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]])
|
|
@@ -219,6 +247,18 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
219
247
|
attributeChangedCallback(name) {
|
|
220
248
|
if (!this.isConnected)
|
|
221
249
|
return;
|
|
250
|
+
if (name === "drive") {
|
|
251
|
+
this.#syncDrive();
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
if (name === "watch" || name === "watch-from" || name === "watch-camera") {
|
|
255
|
+
this.#syncLanding(name !== "watch");
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if (name === "drive-camera") {
|
|
259
|
+
this.driveCamera = this.getAttribute("drive-camera") === "seat" ? "seat" : "chase";
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
222
262
|
if (name === "stick") {
|
|
223
263
|
this.#showStick();
|
|
224
264
|
return;
|
|
@@ -305,6 +345,8 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
305
345
|
const stand = this.getAttribute("detail") === "off" ? { x: 0, y: 0 } : standingPlace(0, 0);
|
|
306
346
|
this.#at = { east: stand.x, north: stand.y };
|
|
307
347
|
this.#placed = true;
|
|
348
|
+
this.#syncDrive();
|
|
349
|
+
this.#syncLanding();
|
|
308
350
|
}
|
|
309
351
|
if (this.#view === undefined) {
|
|
310
352
|
if (this.#renderer === undefined) {
|
|
@@ -392,6 +434,10 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
392
434
|
}
|
|
393
435
|
/** 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. */
|
|
394
436
|
#eyeUp() {
|
|
437
|
+
if (this.#vehicle !== undefined)
|
|
438
|
+
return this.#driveEyeUp;
|
|
439
|
+
if (this.#landing !== undefined)
|
|
440
|
+
return this.#landingEyeUp;
|
|
395
441
|
return this.#groundAt(this.#at.east, this.#at.north) + EYE_HEIGHT;
|
|
396
442
|
}
|
|
397
443
|
/** Ask for a draw. A change of the view (`moving`, the default) is drawn at the quality of motion and followed, a moment after the last, by one at the quality of rest. */
|
|
@@ -446,11 +492,371 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
446
492
|
this.#measured += 1;
|
|
447
493
|
if (this.#drawScale < 1)
|
|
448
494
|
this.#scaled += 1;
|
|
449
|
-
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.getAttribute("detail") !== "off", exposure: num(this.getAttribute("exposure"), 1.6), quality: this.#quality(), scale: this.#drawScale, objects: this.#objects.length > 0, measure: measure || this.getAttribute("measure") !== null });
|
|
495
|
+
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.getAttribute("detail") !== "off", exposure: num(this.getAttribute("exposure"), 1.6), quality: this.#quality(), scale: this.#drawScale, objects: this.#objects.length > 0, ...(this.#vehicle === undefined ? {} : { vehicle: this.#vehicle, trail: this.#trail, dust: this.#dust.position }), ...(this.#landing === undefined ? {} : { lander: this.#landerState(), dust: this.#dust.position }), measure: measure || this.getAttribute("measure") !== null });
|
|
450
496
|
this.#view.invalidate();
|
|
451
497
|
this.#draws += 1;
|
|
452
498
|
this.#placeLabels();
|
|
453
499
|
}
|
|
500
|
+
// --- driving the rover (`drive="on"`) ---------------------------------------------------------------------------------------------------------------
|
|
501
|
+
/** Which view of the rover: `chase` (from behind and above, the default) or `seat` (the commander's). The key C turns from one to the other. */
|
|
502
|
+
get driveCamera() {
|
|
503
|
+
return this.#driveCamera;
|
|
504
|
+
}
|
|
505
|
+
set driveCamera(value) {
|
|
506
|
+
this.#driveCamera = value === "seat" ? "seat" : "chase";
|
|
507
|
+
this.#syncDriveCamera();
|
|
508
|
+
this.#changed();
|
|
509
|
+
}
|
|
510
|
+
/** The rover being driven, or `undefined` when it is not. */
|
|
511
|
+
get vehicle() {
|
|
512
|
+
return this.#vehicle === undefined ? undefined : { ...this.#vehicle, spin: [...this.#vehicle.spin] };
|
|
513
|
+
}
|
|
514
|
+
/** Start or stop driving as the `drive` attribute says: the rover starts at its published place (where its last traverse ends), looking along its heading from behind; stopping puts the eyes back on the ground there. */
|
|
515
|
+
#syncDrive() {
|
|
516
|
+
const on = this.getAttribute("drive") === "on" && this.#terrain !== undefined && this.#placed;
|
|
517
|
+
if (!on) {
|
|
518
|
+
if (this.#vehicle === undefined)
|
|
519
|
+
return;
|
|
520
|
+
const v = this.#vehicle;
|
|
521
|
+
this.#vehicle = undefined;
|
|
522
|
+
this.#trail = [];
|
|
523
|
+
this.#at = { east: v.east, north: v.north };
|
|
524
|
+
this.#changed();
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
if (this.#vehicle !== undefined)
|
|
528
|
+
return;
|
|
529
|
+
const rover = this.#objects.find((o) => o.kind === "rover");
|
|
530
|
+
const [east, north, heading] = rover === undefined ? [this.#at.east, this.#at.north, this.#look.azimuth] : [rover.east, rover.north, rover.heading ?? 0];
|
|
531
|
+
this.#driveCamera = this.getAttribute("drive-camera") === "seat" ? "seat" : "chase";
|
|
532
|
+
this.#vehicle = startDrive(east, north, heading, this.#groundAt(east, north));
|
|
533
|
+
this.#trail = [east, north];
|
|
534
|
+
this.#dust = new DustField(900, 17);
|
|
535
|
+
this.#camOffset = { azimuth: 0, pitch: 0 };
|
|
536
|
+
this.#blockersAt = undefined;
|
|
537
|
+
for (const el of this.#labelEls.values())
|
|
538
|
+
el.hidden = true;
|
|
539
|
+
this.choose(undefined);
|
|
540
|
+
this.#syncDriveCamera();
|
|
541
|
+
this.#changed();
|
|
542
|
+
}
|
|
543
|
+
/** The eyes where the view of the rover puts them. */
|
|
544
|
+
#syncDriveCamera() {
|
|
545
|
+
const v = this.#vehicle;
|
|
546
|
+
if (v === undefined)
|
|
547
|
+
return;
|
|
548
|
+
const view = driveView(v, this.#driveCamera, this.#camOffset, (e, n) => this.#groundAt(e, n));
|
|
549
|
+
this.#at = { east: view.eye.east, north: view.eye.north };
|
|
550
|
+
this.#driveEyeUp = view.eye.up;
|
|
551
|
+
this.#look = clampLook({ azimuth: view.azimuth, pitch: view.pitch, fov: this.#look.fov });
|
|
552
|
+
}
|
|
553
|
+
/** The big rocks and the things near the rover, as circles it cannot enter (found again when it has gone 8 m from where they were found). */
|
|
554
|
+
#obstacles() {
|
|
555
|
+
const v = this.#vehicle;
|
|
556
|
+
if (this.#blockersAt === undefined || Math.hypot(v.east - this.#blockersAt.east, v.north - this.#blockersAt.north) > 8) {
|
|
557
|
+
this.#blockersAt = { east: v.east, north: v.north };
|
|
558
|
+
const list = [];
|
|
559
|
+
if (this.getAttribute("detail") !== "off")
|
|
560
|
+
for (const rock of rocksAround(v.east, v.north, 28, 0.0024))
|
|
561
|
+
if (rock.size >= 0.6)
|
|
562
|
+
list.push({ x: rock.x, y: rock.y, r: rock.size * 0.5 + 1.1 });
|
|
563
|
+
const near = { lander: 6, flag: 1.6, station: 2.8, instrument: 1.8, rover: 0 };
|
|
564
|
+
for (const o of this.#objects)
|
|
565
|
+
if (near[o.kind] > 0)
|
|
566
|
+
list.push({ x: o.east, y: o.north, r: near[o.kind] });
|
|
567
|
+
this.#blockers = list;
|
|
568
|
+
}
|
|
569
|
+
return this.#blockers;
|
|
570
|
+
}
|
|
571
|
+
/** Advance the rover by `seconds` (in steps of at most a sixtieth), throwing dust from the wheels that are down and leaving tracks. */
|
|
572
|
+
#advance(seconds, input) {
|
|
573
|
+
let v = this.#vehicle;
|
|
574
|
+
const ground = (e, n) => this.#groundAt(e, n);
|
|
575
|
+
const blockers = this.#obstacles();
|
|
576
|
+
const blocked = (e, n) => blockers.some((b) => (e - b.x) ** 2 + (n - b.y) ** 2 < b.r * b.r);
|
|
577
|
+
const steps = Math.max(1, Math.ceil(seconds * 60));
|
|
578
|
+
const dt = seconds / steps;
|
|
579
|
+
for (let i = 0; i < steps; i += 1) {
|
|
580
|
+
v = driveStep(v, input, dt, ground, blocked);
|
|
581
|
+
// each wheel on the ground throws grains up and back: the faster, the more
|
|
582
|
+
if (!v.airborne && Math.abs(v.speed) > 0.6) {
|
|
583
|
+
const h = (v.heading * Math.PI) / 180;
|
|
584
|
+
const [fx, fz] = [Math.sin(h), Math.cos(h)];
|
|
585
|
+
const grains = Math.abs(v.speed) * dt * 26;
|
|
586
|
+
const [rx, rz] = [Math.cos(h), -Math.sin(h)];
|
|
587
|
+
for (const [wx, , wz] of ROVER.wheels) {
|
|
588
|
+
const w = toWorld(v, [wx, 0, wz]);
|
|
589
|
+
for (let k = 0; k < grains + Math.random() * 0.999; k += 1) {
|
|
590
|
+
// thrown up and back from the tyre in a fan: the faster the rover, the wider and farther
|
|
591
|
+
const back = -Math.sign(v.speed) * Math.abs(v.speed) * (0.3 + 0.3 * Math.random());
|
|
592
|
+
const side = (Math.random() - 0.5) * 1.6 * Math.min(1, Math.abs(v.speed));
|
|
593
|
+
this.#dust.emit([w[0], w[1] + 0.05, w[2]], [fx * back + rx * side, 0.5 + 0.18 * Math.abs(v.speed), fz * back + rz * side], 2);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
this.#dust.step(dt, ground);
|
|
598
|
+
}
|
|
599
|
+
this.#vehicle = v;
|
|
600
|
+
// the tracks: a point every 1.2 m
|
|
601
|
+
const last = this.#trail.length >= 2 ? [this.#trail[this.#trail.length - 2], this.#trail[this.#trail.length - 1]] : [Infinity, Infinity];
|
|
602
|
+
if (Math.hypot(v.east - last[0], v.north - last[1]) >= 1.2 && this.#trail.length < 12_000)
|
|
603
|
+
this.#trail.push(v.east, v.north);
|
|
604
|
+
this.#syncDriveCamera();
|
|
605
|
+
}
|
|
606
|
+
/** While a key or the stick is asked for, and while the rover is still rolling, settling on its springs or throwing dust: a step at most thirty times a second, and nothing once it is at rest. */
|
|
607
|
+
#driveTick() {
|
|
608
|
+
const k = this.#keys;
|
|
609
|
+
const now = performance.now();
|
|
610
|
+
const dt = Math.min(0.1, (now - this.#walkAt) / 1000);
|
|
611
|
+
this.#walkAt = now;
|
|
612
|
+
const throttle = Math.max(-1, Math.min(1, (k.has("w") || k.has("ArrowUp") ? 1 : 0) - (k.has("s") || k.has("ArrowDown") ? 1 : 0) + this.#push.y));
|
|
613
|
+
const steer = Math.max(-1, Math.min(1, (k.has("d") || k.has("ArrowRight") ? 1 : 0) - (k.has("a") || k.has("ArrowLeft") ? 1 : 0) + this.#push.x));
|
|
614
|
+
this.#advance(dt, { throttle, steer });
|
|
615
|
+
this.#changed();
|
|
616
|
+
const v = this.#vehicle;
|
|
617
|
+
const rolling = Math.abs(v.speed) > 0.01 || v.airborne || Math.abs(v.vy) > 0.02 || Math.abs(v.steer) > 0.005 || this.#dust.live > 0;
|
|
618
|
+
if (throttle !== 0 || steer !== 0 || rolling)
|
|
619
|
+
this.#walkTimer = setTimeout(this.#walkTick, 33);
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* Drive by a set time, whatever the clock says: advance the rover `seconds` with the throttle and steering given (each -1 to 1) and draw. For a test or a sequence of pictures taken one step at a time; the keys and the
|
|
623
|
+
* stick do the same by the real time between frames.
|
|
624
|
+
*
|
|
625
|
+
* @param seconds - How long to drive.
|
|
626
|
+
* @param input - The throttle and the steering.
|
|
627
|
+
* @returns Whether the element is driving.
|
|
628
|
+
*/
|
|
629
|
+
driveFor(seconds, input = { throttle: 0, steer: 0 }) {
|
|
630
|
+
if (this.#vehicle === undefined)
|
|
631
|
+
return false;
|
|
632
|
+
this.#advance(seconds, input);
|
|
633
|
+
this.#changed();
|
|
634
|
+
return true;
|
|
635
|
+
}
|
|
636
|
+
// --- watching the landing (`watch="landing"`): Apollo 17's powered descent from the lunar module's window or from the ground ---------------------------------------------------------------------
|
|
637
|
+
/** 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. */
|
|
638
|
+
get landing() {
|
|
639
|
+
const l = this.#landing;
|
|
640
|
+
if (l === undefined)
|
|
641
|
+
return undefined;
|
|
642
|
+
const pose = landingAt(l.t);
|
|
643
|
+
return { t: l.t, playing: l.playing, rate: l.rate, camera: l.camera, altitude: pose.altitude, speed: pose.speed, descent: pose.descent };
|
|
644
|
+
}
|
|
645
|
+
/** The clock of the descent, in seconds from ignition (0 to 725). Setting it goes there at once, whether it runs or not. */
|
|
646
|
+
get landingTime() {
|
|
647
|
+
return this.#landing?.t ?? 0;
|
|
648
|
+
}
|
|
649
|
+
set landingTime(value) {
|
|
650
|
+
const l = this.#landing;
|
|
651
|
+
if (l === undefined)
|
|
652
|
+
return;
|
|
653
|
+
const old = l.t;
|
|
654
|
+
l.t = Math.min(LANDING.duration, Math.max(0, value));
|
|
655
|
+
// a seek forward announces the latest moment it passes (the picture lists the last three); a step of a second or less carries the dust on, a jump or a step back starts it afresh
|
|
656
|
+
const delta = l.t - old;
|
|
657
|
+
if (delta < 0 || delta > 1)
|
|
658
|
+
this.#dust = new DustField(20000, 17);
|
|
659
|
+
this.#landingAt = performance.now();
|
|
660
|
+
this.#landingFrame(delta > 0 && delta <= 1 ? delta : 0, true);
|
|
661
|
+
}
|
|
662
|
+
/** How fast the descent runs: 1 is the real time of it (12 minutes 5 seconds); 2, 4 and 8 are quicker. */
|
|
663
|
+
get landingRate() {
|
|
664
|
+
return this.#landing?.rate ?? 1;
|
|
665
|
+
}
|
|
666
|
+
set landingRate(value) {
|
|
667
|
+
if (this.#landing !== undefined)
|
|
668
|
+
this.#landing.rate = Math.min(16, Math.max(0.25, value));
|
|
669
|
+
}
|
|
670
|
+
/** Run the descent from where the clock is (from the start again if it had ended). */
|
|
671
|
+
playLanding() {
|
|
672
|
+
const l = this.#landing;
|
|
673
|
+
if (l === undefined)
|
|
674
|
+
return;
|
|
675
|
+
if (l.t >= LANDING.duration)
|
|
676
|
+
this.landingTime = l.camera === "ground" ? 540 : LANDING.viewStart;
|
|
677
|
+
l.playing = true;
|
|
678
|
+
this.#landingAt = performance.now();
|
|
679
|
+
this.#landingTick();
|
|
680
|
+
}
|
|
681
|
+
/** Hold the descent where it is. */
|
|
682
|
+
pauseLanding() {
|
|
683
|
+
if (this.#landing === undefined)
|
|
684
|
+
return;
|
|
685
|
+
this.#landing.playing = false;
|
|
686
|
+
clearTimeout(this.#landingTimer);
|
|
687
|
+
this.#landingFrame(0, true);
|
|
688
|
+
}
|
|
689
|
+
/** The touchdown point: where the lunar module stands at Apollo 17 (the published place), or the site point where it has none. */
|
|
690
|
+
#touchdown() {
|
|
691
|
+
const lm = this.#objects.find((o) => o.kind === "lander");
|
|
692
|
+
return lm === undefined ? { east: 0, north: 0 } : { east: lm.east, north: lm.north };
|
|
693
|
+
}
|
|
694
|
+
/** The lunar module as the scene draws it now: its place, its height over the ground under it, its heading and its thrust. */
|
|
695
|
+
#landerState() {
|
|
696
|
+
const l = this.#landing;
|
|
697
|
+
const pose = landingAt(l.t);
|
|
698
|
+
const td = this.#touchdown();
|
|
699
|
+
return { east: td.east + pose.east, north: td.north + pose.north, altitude: pose.altitude, heading: pose.heading, throttle: l.t >= LANDING.duration ? 0 : pose.throttle, inside: l.camera === "lander" };
|
|
700
|
+
}
|
|
701
|
+
/** Start or stop watching as the `watch` attribute says; `again` re-reads the camera and the place the ground camera stands at. */
|
|
702
|
+
#syncLanding(again = false) {
|
|
703
|
+
const on = this.getAttribute("watch") === "landing" && this.#terrain !== undefined && this.#placed;
|
|
704
|
+
if (!on) {
|
|
705
|
+
if (this.#landing === undefined)
|
|
706
|
+
return;
|
|
707
|
+
this.#landing = undefined;
|
|
708
|
+
clearTimeout(this.#landingTimer);
|
|
709
|
+
this.#root.getElementById("landing").hidden = true;
|
|
710
|
+
this.#readAttributes();
|
|
711
|
+
const td = this.#touchdown();
|
|
712
|
+
this.#at = { east: td.east, north: td.north };
|
|
713
|
+
this.#changed();
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
const camera = this.getAttribute("watch-camera") === "ground" ? "ground" : "lander";
|
|
717
|
+
const [distance, bearing] = (this.getAttribute("watch-from") ?? "150 0").split(/[\s,]+/).map(Number);
|
|
718
|
+
const from = { distance: Number.isFinite(distance) ? distance : 150, bearing: Number.isFinite(bearing) ? bearing : 0 };
|
|
719
|
+
if (this.#landing !== undefined) {
|
|
720
|
+
if (!again)
|
|
721
|
+
return;
|
|
722
|
+
if (this.#landing.camera !== camera)
|
|
723
|
+
this.#look = clampLook({ ...this.#look, fov: camera === "ground" ? 27 : 74 });
|
|
724
|
+
this.#landing.camera = camera;
|
|
725
|
+
this.#landing.from = from;
|
|
726
|
+
this.#camOffset = { azimuth: 0, pitch: 0 };
|
|
727
|
+
this.#landingFrame(0, true);
|
|
728
|
+
return;
|
|
729
|
+
}
|
|
730
|
+
this.#landing = { t: camera === "ground" ? 540 : LANDING.viewStart, playing: true, rate: 1, camera, from, passed: 0, second: -1 };
|
|
731
|
+
this.#landing.passed = calloutsBy(this.#landing.t).length;
|
|
732
|
+
this.#dust = new DustField(20000, 17);
|
|
733
|
+
this.#camOffset = { azimuth: 0, pitch: 0 };
|
|
734
|
+
for (const el of this.#labelEls.values())
|
|
735
|
+
el.hidden = true;
|
|
736
|
+
this.choose(undefined);
|
|
737
|
+
this.#root.getElementById("landing").hidden = false;
|
|
738
|
+
this.#root.getElementById("curve").textContent = this.#lang() === "ja" ? "報告された時刻のあいだの高度と速度は、こちらで作った滑らかな曲線です。" : "Altitude and speed between the reported moments are a smooth curve of ours.";
|
|
739
|
+
if (camera === "ground")
|
|
740
|
+
this.#look = clampLook({ ...this.#look, fov: 27 });
|
|
741
|
+
this.#landingAt = performance.now();
|
|
742
|
+
this.#landingFrame(0, true);
|
|
743
|
+
this.#landingTick();
|
|
744
|
+
}
|
|
745
|
+
/** The frame of the descent at the clock: the eyes of the chosen camera, the sky of that real moment, the dust of the blast, the words on the picture and the event for a page; `seconds` is how far the clock has just moved. */
|
|
746
|
+
#landingFrame(seconds, announce) {
|
|
747
|
+
const l = this.#landing;
|
|
748
|
+
if (l === undefined)
|
|
749
|
+
return;
|
|
750
|
+
const pose = landingAt(l.t);
|
|
751
|
+
const td = this.#touchdown();
|
|
752
|
+
const ground = (e, n) => this.#groundAt(e, n);
|
|
753
|
+
const [lx, ly] = [td.east + pose.east, td.north + pose.north];
|
|
754
|
+
const lz = ground(lx, ly);
|
|
755
|
+
this.#time = LANDING.ignition + l.t * 1000;
|
|
756
|
+
// the dust of the blast: from the altitude the Commander first saw it (60 to 70 ft), outward along the ground from under the engine, faster the nearer the ground
|
|
757
|
+
if (seconds > 0 && pose.altitude < 21.3 && l.t < LANDING.duration) {
|
|
758
|
+
// the report's dust is a low sheet driven outward along the ground, thickest in the last metres: most grains leave nearly flat and fast, a few higher
|
|
759
|
+
const strength = Math.pow(1 - pose.altitude / 21.3, 0.7) * pose.throttle;
|
|
760
|
+
const grains = strength * 12000 * seconds;
|
|
761
|
+
for (let k = 0; k < grains + Math.random() * 0.999; k += 1) {
|
|
762
|
+
const a = Math.random() * Math.PI * 2;
|
|
763
|
+
const r0 = 1.5 + Math.random() * 3;
|
|
764
|
+
const v = 6 + Math.random() * 26;
|
|
765
|
+
const lift = Math.random() < 0.85 ? 0.35 + Math.random() * 0.9 : 1.2 + Math.random() * 3;
|
|
766
|
+
const [e, n] = [lx + Math.sin(a) * r0, ly + Math.cos(a) * r0];
|
|
767
|
+
this.#dust.emit([e, ground(e, n) + 0.3, n], [Math.sin(a) * v, lift, Math.cos(a) * v], 4);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
if (seconds > 0)
|
|
771
|
+
this.#dust.step(seconds, ground);
|
|
772
|
+
if (l.camera === "lander") {
|
|
773
|
+
this.#at = { east: lx, north: ly };
|
|
774
|
+
this.#landingEyeUp = lz + pose.altitude + 4;
|
|
775
|
+
this.#look = clampLook({ azimuth: (((pose.heading + this.#camOffset.azimuth) % 360) + 360) % 360, pitch: pose.pitch + this.#camOffset.pitch, fov: this.#look.fov });
|
|
776
|
+
}
|
|
777
|
+
else {
|
|
778
|
+
const b = (l.from.bearing * Math.PI) / 180;
|
|
779
|
+
const [ox, oy] = [td.east + Math.sin(b) * l.from.distance, td.north + Math.cos(b) * l.from.distance];
|
|
780
|
+
this.#at = { east: ox, north: oy };
|
|
781
|
+
this.#landingEyeUp = ground(ox, oy) + 1.7;
|
|
782
|
+
const horizontal = Math.hypot(lx - ox, ly - oy) || 1;
|
|
783
|
+
const azimuth = ((Math.atan2(lx - ox, ly - oy) * 180) / Math.PI + 360) % 360;
|
|
784
|
+
const pitch = (Math.atan2(lz + pose.altitude + 3.4 - this.#landingEyeUp, horizontal) * 180) / Math.PI;
|
|
785
|
+
this.#look = clampLook({ azimuth: azimuth + this.#camOffset.azimuth, pitch: pitch + this.#camOffset.pitch, fov: this.#look.fov });
|
|
786
|
+
}
|
|
787
|
+
// the marker: while the stage is smaller than about 6 pixels in the ground camera a ring and its height mark where it is, fading out as it grows
|
|
788
|
+
const ring = this.#root.getElementById("marker");
|
|
789
|
+
const ringText = this.#root.getElementById("markerText");
|
|
790
|
+
let showRing = false;
|
|
791
|
+
if (l.camera === "ground") {
|
|
792
|
+
const box = this.getBoundingClientRect();
|
|
793
|
+
const [w, h] = [box.width, box.height];
|
|
794
|
+
const vp = viewProjection([this.#at.east, this.#landingEyeUp, -this.#at.north], this.#look, w / Math.max(1, h));
|
|
795
|
+
const [x, y, z] = [lx, lz + pose.altitude + 3.4, -ly];
|
|
796
|
+
const cw = vp[3] * x + vp[7] * y + vp[11] * z + vp[15];
|
|
797
|
+
const px = cw > 0 ? (7 * h) / 2 / (cw * Math.tan((this.#look.fov * Math.PI) / 360)) : 0;
|
|
798
|
+
const fade = Math.min(1, Math.max(0, (9 - px) / 5));
|
|
799
|
+
if (cw > 0 && fade > 0) {
|
|
800
|
+
const nx = (vp[0] * x + vp[4] * y + vp[8] * z + vp[12]) / cw;
|
|
801
|
+
const ny = (vp[1] * x + vp[5] * y + vp[9] * z + vp[13]) / cw;
|
|
802
|
+
if (Math.abs(nx) < 1 && Math.abs(ny) < 1) {
|
|
803
|
+
showRing = true;
|
|
804
|
+
const [sx, sy] = [((nx + 1) / 2) * w, ((1 - ny) / 2) * h];
|
|
805
|
+
ring.style.transform = `translate(${sx}px, ${sy}px)`;
|
|
806
|
+
ring.style.opacity = String(fade);
|
|
807
|
+
ringText.textContent = `${Math.round(pose.altitude).toLocaleString(this.#lang() === "ja" ? "ja-JP" : "en-US")} m`;
|
|
808
|
+
ringText.style.transform = `translate(${sx + 16}px, ${sy - 7}px)`;
|
|
809
|
+
ringText.style.opacity = String(fade);
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
ring.hidden = !showRing;
|
|
814
|
+
ringText.hidden = !showRing;
|
|
815
|
+
// the words: the clock and what the lunar module is doing, and the reported moments as they pass
|
|
816
|
+
const clock = clockText(l.t);
|
|
817
|
+
const ja = this.#lang() === "ja";
|
|
818
|
+
const metres = (v) => Math.round(v).toLocaleString(ja ? "ja-JP" : "en-US");
|
|
819
|
+
this.#root.getElementById("clock").textContent = `${clock.t} · ${clock.get} ${ja ? "ミッション経過時間" : "ground elapsed"} · ${ja ? "高度" : "altitude"} ${metres(pose.altitude)} m · ${ja ? "対地速度" : "speed"} ${metres(pose.speed)} m/s`;
|
|
820
|
+
const passed = calloutsBy(l.t);
|
|
821
|
+
const list = this.#root.getElementById("callouts");
|
|
822
|
+
if (announce || passed.length !== l.passed) {
|
|
823
|
+
const show = passed.slice(-3);
|
|
824
|
+
list.replaceChildren(...show.map((c) => {
|
|
825
|
+
const li = document.createElement("li");
|
|
826
|
+
li.textContent = `${clockText(c.t).t} ${ja ? c.ja : c.en}${c.reported ? "" : ja ? "(時刻はこちらの曲線による)" : " (the time is from our curve)"}`;
|
|
827
|
+
return li;
|
|
828
|
+
}));
|
|
829
|
+
}
|
|
830
|
+
const newest = passed.length > l.passed ? passed[passed.length - 1] : undefined;
|
|
831
|
+
l.passed = passed.length;
|
|
832
|
+
const second = Math.floor(l.t);
|
|
833
|
+
if (announce || newest !== undefined || second !== l.second) {
|
|
834
|
+
l.second = second;
|
|
835
|
+
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 }));
|
|
836
|
+
}
|
|
837
|
+
this.#changed(l.playing);
|
|
838
|
+
}
|
|
839
|
+
/** 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. */
|
|
840
|
+
#landingTick = () => {
|
|
841
|
+
clearTimeout(this.#landingTimer);
|
|
842
|
+
const l = this.#landing;
|
|
843
|
+
if (l === undefined || !l.playing)
|
|
844
|
+
return;
|
|
845
|
+
const now = performance.now();
|
|
846
|
+
const dt = Math.min(0.25, (now - this.#landingAt) / 1000);
|
|
847
|
+
this.#landingAt = now;
|
|
848
|
+
const seconds = Math.min(dt * l.rate, LANDING.duration - l.t);
|
|
849
|
+
l.t += seconds;
|
|
850
|
+
if (l.t >= LANDING.duration - 1e-6) {
|
|
851
|
+
l.t = LANDING.duration;
|
|
852
|
+
l.playing = false;
|
|
853
|
+
}
|
|
854
|
+
this.#landingFrame(seconds, false);
|
|
855
|
+
if (l.playing)
|
|
856
|
+
this.#landingTimer = setTimeout(this.#landingTick, 33);
|
|
857
|
+
else
|
|
858
|
+
this.#changed(true);
|
|
859
|
+
};
|
|
454
860
|
// --- the things at the site: a small button on each, which goes to it and says what it is ----------------------------------------------------------------------------------------------------
|
|
455
861
|
/** The things at the site, at their published places (none where the site has none or `objects="off"`). */
|
|
456
862
|
get objects() {
|
|
@@ -489,7 +895,7 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
489
895
|
}
|
|
490
896
|
/** Put each button on its thing in the picture, or hide it behind the viewer, off the picture or too far to tell. Done at each draw: nothing moves by itself. */
|
|
491
897
|
#placeLabels() {
|
|
492
|
-
if (this.#labelEls.size === 0)
|
|
898
|
+
if (this.#labelEls.size === 0 || this.#vehicle !== undefined || this.#landing !== undefined)
|
|
493
899
|
return;
|
|
494
900
|
const box = this.getBoundingClientRect();
|
|
495
901
|
const [w, h] = [box.width, box.height];
|
|
@@ -516,6 +922,8 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
516
922
|
* @returns Whether there is such a thing here.
|
|
517
923
|
*/
|
|
518
924
|
choose(id) {
|
|
925
|
+
if (this.#vehicle !== undefined || this.#landing !== undefined)
|
|
926
|
+
return false; // the rover is being driven or the landing watched: the eyes are not ours to move
|
|
519
927
|
const about = this.#root.getElementById("about");
|
|
520
928
|
const o = id === undefined ? undefined : this.#objects.find((x) => x.id === id);
|
|
521
929
|
if (id !== undefined && o === undefined)
|
|
@@ -616,6 +1024,12 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
616
1024
|
}
|
|
617
1025
|
const box = this.getBoundingClientRect();
|
|
618
1026
|
const perPixel = this.#look.fov / Math.max(1, box.height);
|
|
1027
|
+
if (this.#vehicle !== undefined) {
|
|
1028
|
+
this.#camOffset = { azimuth: this.#camOffset.azimuth - (event.clientX - was.x) * perPixel, pitch: Math.max(-60, Math.min(60, this.#camOffset.pitch + (event.clientY - was.y) * perPixel)) };
|
|
1029
|
+
this.#syncDriveCamera();
|
|
1030
|
+
this.#changed();
|
|
1031
|
+
return;
|
|
1032
|
+
}
|
|
619
1033
|
this.#look = clampLook({ ...this.#look, azimuth: this.#look.azimuth - (event.clientX - was.x) * perPixel, pitch: this.#look.pitch + (event.clientY - was.y) * perPixel });
|
|
620
1034
|
this.#changed();
|
|
621
1035
|
};
|
|
@@ -641,6 +1055,10 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
641
1055
|
};
|
|
642
1056
|
#onKeyDown = (event) => {
|
|
643
1057
|
const key = event.key.length === 1 ? event.key.toLowerCase() : event.key;
|
|
1058
|
+
if (key === "c" && this.#vehicle !== undefined) {
|
|
1059
|
+
this.driveCamera = this.#driveCamera === "chase" ? "seat" : "chase";
|
|
1060
|
+
return;
|
|
1061
|
+
}
|
|
644
1062
|
if (key === "+" || key === "=")
|
|
645
1063
|
return this.#zoom(0.85);
|
|
646
1064
|
if (key === "-" || key === "_")
|
|
@@ -663,6 +1081,8 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
663
1081
|
/** While a key is held: a step every frame at a walking pace (and a turn at a quarter turn a second), at most thirty a second; nothing when no key is held. */
|
|
664
1082
|
#walkTick = () => {
|
|
665
1083
|
clearTimeout(this.#walkTimer);
|
|
1084
|
+
if (this.#vehicle !== undefined)
|
|
1085
|
+
return this.#driveTick();
|
|
666
1086
|
if (this.#keys.size === 0 && this.#push.x === 0 && this.#push.y === 0)
|
|
667
1087
|
return;
|
|
668
1088
|
const now = performance.now();
|
package/dist/surface/glsl.d.ts
CHANGED
|
@@ -24,3 +24,9 @@ export declare const TRACK_FRAGMENT = "\nprecision highp float;\nvarying vec2 vU
|
|
|
24
24
|
/** The things at a site: the rocks' light, with a flat colour for each corner (the gold of the lunar module's foil, the grey of the rover's frame). */
|
|
25
25
|
export declare const OBJECT_VERTEX: string;
|
|
26
26
|
export declare const OBJECT_FRAGMENT: string;
|
|
27
|
+
/** A grain of dust in flight: a small square that always faces the viewer, at a place in the site's plane, its size in metres. */
|
|
28
|
+
export declare const DUST_VERTEX = "\nprecision highp float;\n// position (declared by three.js) is the grain's place; the corner of its square is in uv, -1 to 1\nuniform mat4 uVP;\nuniform vec3 uRight;\nuniform vec3 uUp;\nuniform float uSize;\nuniform vec3 uEyeWorld;\nuniform float uMinAngle; // the least a grain shows as, in radians (a blast seen from far off)\nvarying vec2 vUv;\nvoid main() {\n vUv = uv * 2.0 - 1.0;\n vec3 c = vec3(position.x, position.y, -position.z);\n float size = max(uSize, distance(c, uEyeWorld) * uMinAngle);\n vec3 w = c + (uRight * vUv.x + uUp * vUv.y) * size;\n gl_Position = uVP * vec4(w, 1.0);\n}\n";
|
|
29
|
+
export declare const DUST_FRAGMENT = "\nprecision highp float;\nvarying vec2 vUv;\nvoid main() {\n float r = length(vUv);\n if (r > 1.0) discard;\n gl_FragColor = vec4(vec3(0.62), 0.32 * (1.0 - r * r));\n}\n";
|
|
30
|
+
/** The engine's plume: a cone below the bell, its place and size in uniforms, faint and warm, widest at its end (a vacuum lets a plume spread). position.x is the angle round it (0 to 1), position.y the way along it (0 to 1). */
|
|
31
|
+
export declare const PLUME_VERTEX = "\nprecision highp float;\nuniform mat4 uVP;\nuniform vec3 uBell; // the bell's exit, in the site's plane (east, up, north)\nuniform float uLength;\nuniform float uRadius;\nvarying float vAlong;\nvoid main() {\n float a = position.x * 6.2831853;\n float u = position.y;\n float r = 0.7 + (uRadius - 0.7) * pow(u, 0.6);\n vec3 w = uBell + vec3(cos(a) * r, -u * uLength, sin(a) * r);\n vAlong = u;\n gl_Position = uVP * vec4(w.x, w.y, -w.z, 1.0);\n}\n";
|
|
32
|
+
export declare const PLUME_FRAGMENT = "\nprecision highp float;\nuniform float uPlume; // the share of full thrust\nvarying float vAlong;\nvoid main() {\n float a = uPlume * 0.38 * (1.0 - vAlong) * (1.0 - vAlong);\n if (a < 0.003) discard;\n gl_FragColor = vec4(1.0, 0.92, 0.78, a);\n}\n";
|
package/dist/surface/glsl.js
CHANGED
|
@@ -454,4 +454,59 @@ void main() {
|
|
|
454
454
|
`;
|
|
455
455
|
/** The things at a site: the rocks' light, with a flat colour for each corner (the gold of the lunar module's foil, the grey of the rover's frame). */
|
|
456
456
|
export const OBJECT_VERTEX = ROCK_VERTEX.replace("attribute float tone;", "attribute float tone;\nattribute vec3 tint;").replace("varying float vTone;", "varying float vTone;\nvarying vec3 vTint;").replace("vTone = tone;", "vTone = tone;\n vTint = tint;");
|
|
457
|
-
export const OBJECT_FRAGMENT = ROCK_FRAGMENT.replace("varying float vTone;", "varying float vTone;\nvarying vec3 vTint;").replace("gl_FragColor = vec4(vec3(pow(clamp(light, 0.0, 1.0), 1.0 / 2.2)), 1.0);", "gl_FragColor = vec4(pow(clamp(vec3(light) * vTint, 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);");
|
|
457
|
+
export const OBJECT_FRAGMENT = ROCK_FRAGMENT.replace("varying float vTone;", "varying float vTone;\nvarying vec3 vTint;").replace("uAlbedo * 1.1 * vTone * (shine + 0.12 * (n.y * 0.5 + 0.5))", "uAlbedo * 2.4 * vTone * (shine + 0.3 * (n.y * 0.5 + 0.5))").replace("gl_FragColor = vec4(vec3(pow(clamp(light, 0.0, 1.0), 1.0 / 2.2)), 1.0);", "gl_FragColor = vec4(pow(clamp(vec3(light) * vTint, 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);");
|
|
458
|
+
/** A grain of dust in flight: a small square that always faces the viewer, at a place in the site's plane, its size in metres. */
|
|
459
|
+
export const DUST_VERTEX = /* glsl */ `
|
|
460
|
+
precision highp float;
|
|
461
|
+
// position (declared by three.js) is the grain's place; the corner of its square is in uv, -1 to 1
|
|
462
|
+
uniform mat4 uVP;
|
|
463
|
+
uniform vec3 uRight;
|
|
464
|
+
uniform vec3 uUp;
|
|
465
|
+
uniform float uSize;
|
|
466
|
+
uniform vec3 uEyeWorld;
|
|
467
|
+
uniform float uMinAngle; // the least a grain shows as, in radians (a blast seen from far off)
|
|
468
|
+
varying vec2 vUv;
|
|
469
|
+
void main() {
|
|
470
|
+
vUv = uv * 2.0 - 1.0;
|
|
471
|
+
vec3 c = vec3(position.x, position.y, -position.z);
|
|
472
|
+
float size = max(uSize, distance(c, uEyeWorld) * uMinAngle);
|
|
473
|
+
vec3 w = c + (uRight * vUv.x + uUp * vUv.y) * size;
|
|
474
|
+
gl_Position = uVP * vec4(w, 1.0);
|
|
475
|
+
}
|
|
476
|
+
`;
|
|
477
|
+
export const DUST_FRAGMENT = /* glsl */ `
|
|
478
|
+
precision highp float;
|
|
479
|
+
varying vec2 vUv;
|
|
480
|
+
void main() {
|
|
481
|
+
float r = length(vUv);
|
|
482
|
+
if (r > 1.0) discard;
|
|
483
|
+
gl_FragColor = vec4(vec3(0.62), 0.32 * (1.0 - r * r));
|
|
484
|
+
}
|
|
485
|
+
`;
|
|
486
|
+
/** The engine's plume: a cone below the bell, its place and size in uniforms, faint and warm, widest at its end (a vacuum lets a plume spread). position.x is the angle round it (0 to 1), position.y the way along it (0 to 1). */
|
|
487
|
+
export const PLUME_VERTEX = /* glsl */ `
|
|
488
|
+
precision highp float;
|
|
489
|
+
uniform mat4 uVP;
|
|
490
|
+
uniform vec3 uBell; // the bell's exit, in the site's plane (east, up, north)
|
|
491
|
+
uniform float uLength;
|
|
492
|
+
uniform float uRadius;
|
|
493
|
+
varying float vAlong;
|
|
494
|
+
void main() {
|
|
495
|
+
float a = position.x * 6.2831853;
|
|
496
|
+
float u = position.y;
|
|
497
|
+
float r = 0.7 + (uRadius - 0.7) * pow(u, 0.6);
|
|
498
|
+
vec3 w = uBell + vec3(cos(a) * r, -u * uLength, sin(a) * r);
|
|
499
|
+
vAlong = u;
|
|
500
|
+
gl_Position = uVP * vec4(w.x, w.y, -w.z, 1.0);
|
|
501
|
+
}
|
|
502
|
+
`;
|
|
503
|
+
export const PLUME_FRAGMENT = /* glsl */ `
|
|
504
|
+
precision highp float;
|
|
505
|
+
uniform float uPlume; // the share of full thrust
|
|
506
|
+
varying float vAlong;
|
|
507
|
+
void main() {
|
|
508
|
+
float a = uPlume * 0.38 * (1.0 - vAlong) * (1.0 - vAlong);
|
|
509
|
+
if (a < 0.003) discard;
|
|
510
|
+
gl_FragColor = vec4(1.0, 0.92, 0.78, a);
|
|
511
|
+
}
|
|
512
|
+
`;
|
package/dist/surface/index.d.ts
CHANGED
|
@@ -4,7 +4,10 @@ export { EYE_HEIGHT, FOV_LIMITS, WALK_SPEED, clampLook, forward, stepOver, viewP
|
|
|
4
4
|
export { decodeHeight, drop, emptyLevel, fillFromCoarser, groundAt, sampleLevel, tileAddress, type HeightLevel, type HeightLevelInfo, type TerrainManifest } from "./height.ts";
|
|
5
5
|
export { loadPlan, loadTerrain, type LoadJob, type LoadOptions, type Terrain, type TerrainProgress } from "./load.ts";
|
|
6
6
|
export type { SurfaceState } from "./element.ts";
|
|
7
|
-
export { landerParts, roverParts } from "./shapes.ts";
|
|
7
|
+
export { ascentParts, landerParts, roverParts } from "./shapes.ts";
|
|
8
|
+
export { calloutsBy, CALLOUTS, clockText, LANDING, landingAt, type Callout, type LandingPose } from "./landing.ts";
|
|
9
|
+
export { DustField } from "./dust.ts";
|
|
10
|
+
export { driveParts, driveStep, driveView, startDrive, ROVER, type DriveInput, type DriveState, type DriveView } from "./drive.ts";
|
|
8
11
|
export { keepAway, objectParts, objectsOf, partShadows, traverseOf, KEEP_OUT, type Part, type SiteObject } from "./objects.ts";
|
|
9
12
|
export { craterIn, craterProfile, madeGround, setKeepOut, rimBoost, rocksAround, standingPlace, type Crater, type Rock } from "./detail.ts";
|
|
10
13
|
export { rockMesh, type RockMesh } from "./rocks.ts";
|
package/dist/surface/index.js
CHANGED
|
@@ -4,7 +4,10 @@ export { SURFACE_SITES, siteById } from "./site.js";
|
|
|
4
4
|
export { EYE_HEIGHT, FOV_LIMITS, WALK_SPEED, clampLook, forward, stepOver, viewProjection } from "./view.js";
|
|
5
5
|
export { decodeHeight, drop, emptyLevel, fillFromCoarser, groundAt, sampleLevel, tileAddress } from "./height.js";
|
|
6
6
|
export { loadPlan, loadTerrain } from "./load.js";
|
|
7
|
-
export { landerParts, roverParts } from "./shapes.js";
|
|
7
|
+
export { ascentParts, landerParts, roverParts } from "./shapes.js";
|
|
8
|
+
export { calloutsBy, CALLOUTS, clockText, LANDING, landingAt } from "./landing.js";
|
|
9
|
+
export { DustField } from "./dust.js";
|
|
10
|
+
export { driveParts, driveStep, driveView, startDrive, ROVER } from "./drive.js";
|
|
8
11
|
export { keepAway, objectParts, objectsOf, partShadows, traverseOf, KEEP_OUT } from "./objects.js";
|
|
9
12
|
export { craterIn, craterProfile, madeGround, setKeepOut, rimBoost, rocksAround, standingPlace } from "./detail.js";
|
|
10
13
|
export { rockMesh } from "./rocks.js";
|