@johnmorrisdotca/wakusei-planets 0.45.1 → 0.47.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 +12 -0
- package/NOTICE.md +12 -0
- package/README.md +4 -3
- package/dist/scene/body.d.ts +1 -1
- package/dist/scene/textures.d.ts +2 -2
- package/dist/space/element.d.ts +7 -0
- package/dist/space/element.js +12 -0
- package/dist/surface/detail.d.ts +186 -0
- package/dist/surface/detail.js +316 -0
- package/dist/surface/element.d.ts +103 -0
- package/dist/surface/element.js +685 -0
- package/dist/surface/glsl.d.ts +26 -0
- package/dist/surface/glsl.js +457 -0
- package/dist/surface/height.d.ts +257 -0
- package/dist/surface/height.js +232 -0
- package/dist/surface/index.d.ts +10 -0
- package/dist/surface/index.js +10 -0
- package/dist/surface/land.d.ts +111 -0
- package/dist/surface/land.js +261 -0
- package/dist/surface/load.d.ts +133 -0
- package/dist/surface/load.js +183 -0
- package/dist/surface/objects-apollo-17.d.ts +4 -0
- package/dist/surface/objects-apollo-17.js +19 -0
- package/dist/surface/objects.d.ts +127 -0
- package/dist/surface/objects.js +179 -0
- package/dist/surface/rocks.d.ts +45 -0
- package/dist/surface/rocks.js +166 -0
- package/dist/surface/scene.d.ts +72 -0
- package/dist/surface/scene.js +488 -0
- package/dist/surface/shapes.d.ts +62 -0
- package/dist/surface/shapes.js +247 -0
- package/dist/surface/site.d.ts +58 -0
- package/dist/surface/site.js +38 -0
- package/dist/surface/sky.d.ts +81 -0
- package/dist/surface/sky.js +60 -0
- package/dist/surface/view.d.ts +129 -0
- package/dist/surface/view.js +139 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +23 -1
|
@@ -0,0 +1,685 @@
|
|
|
1
|
+
import { createGate, frameCap } from "../gate.js";
|
|
2
|
+
import { setThreeLoader, takeRenderer } from "../scene/shared.js";
|
|
3
|
+
import { TILES_BASE } from "../scene/textures.js";
|
|
4
|
+
import { madeGround, setKeepOut, standingPlace } from "./detail.js";
|
|
5
|
+
import { drop, groundAt } from "./height.js";
|
|
6
|
+
import { loadTerrain } from "./load.js";
|
|
7
|
+
import { createSurfaceItem } from "./scene.js";
|
|
8
|
+
import { objectsOf, traverseOf } from "./objects.js";
|
|
9
|
+
import { moonSky } from "./sky.js";
|
|
10
|
+
import { siteById } from "./site.js";
|
|
11
|
+
import { clampLook, EYE_HEIGHT, stepOver, viewProjection, WALK_SPEED } from "./view.js";
|
|
12
|
+
export { setThreeLoader };
|
|
13
|
+
const TEMPLATE = `<style>
|
|
14
|
+
:host { display: block; width: var(--wakusei-size, 960px); max-width: 100%; aspect-ratio: var(--wakusei-ratio, 16 / 9); position: relative; overflow: hidden; background: #000; contain: layout style; touch-action: none; user-select: none; cursor: grab; }
|
|
15
|
+
:host(:focus-visible) { outline: 2px solid currentColor; outline-offset: 2px; }
|
|
16
|
+
:host([data-dragging]) { cursor: grabbing; }
|
|
17
|
+
#stage { position: absolute; inset: 0; }
|
|
18
|
+
#note { position: absolute; left: 8px; right: 8px; bottom: 6px; margin: 0; font: 400 11px/1.35 system-ui, sans-serif; color: #c8ccd4; text-shadow: 0 1px 2px #000; pointer-events: none; }
|
|
19
|
+
#status { position: absolute; inset: 0; display: grid; place-items: center; font: 500 13px system-ui, sans-serif; color: #c8ccd4; pointer-events: none; }
|
|
20
|
+
#status[hidden] { display: none; }
|
|
21
|
+
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
|
|
22
|
+
.label { position: absolute; left: 0; top: 0; margin: 0; padding: 3px 8px; border: 1px solid rgba(255, 255, 255, 0.45); border-radius: 12px; background: rgba(0, 0, 0, 0.55); color: #e8ecf2; font: 500 11px/1.3 system-ui, sans-serif; white-space: nowrap; pointer-events: auto; cursor: pointer; will-change: transform; touch-action: manipulation; }
|
|
23
|
+
.label:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
|
|
24
|
+
.label[hidden] { display: none; }
|
|
25
|
+
.label[aria-pressed="true"] { background: rgba(255, 255, 255, 0.85); color: #10141c; }
|
|
26
|
+
#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
|
+
#about[hidden] { display: none; }
|
|
28
|
+
#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
|
+
#stick[hidden] { display: none; }
|
|
30
|
+
#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>`;
|
|
32
|
+
const num = (value, fallback) => {
|
|
33
|
+
const n = value === null || value.trim() === "" ? NaN : Number(value);
|
|
34
|
+
return Number.isFinite(n) ? n : fallback;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* The `<wakusei-surface>` custom element: standing on a body.
|
|
38
|
+
*
|
|
39
|
+
* Attributes: `body` (`moon`), `site` (a name from `SURFACE_SITES`, `apollo-17`), `time` (an ISO date and time, or milliseconds since 1970; the site's own landing moment when left out; `now` for the real time),
|
|
40
|
+
* `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),
|
|
41
|
+
* `lang` (`en` or `ja`: the words on the picture).
|
|
42
|
+
*
|
|
43
|
+
* A drag turns the view; the keys W, A, S, D and the arrow keys walk (1.4 metres a second, over the real ground: it rises and falls under the eyes), Q and E turn, + and - zoom, and Ctrl with the wheel or a
|
|
44
|
+
* pinch zooms. Nothing is drawn at rest.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts no-run
|
|
48
|
+
* import type { WakuseiSurface } from "@johnmorrisdotca/wakusei-planets/surface/element";
|
|
49
|
+
*
|
|
50
|
+
* const view = document.createElement("wakusei-surface") as WakuseiSurface;
|
|
51
|
+
* view.setAttribute("site", "apollo-17");
|
|
52
|
+
* document.body.append(view);
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export class WakuseiSurface extends HTMLElement {
|
|
56
|
+
static observedAttributes = ["quality", "shadows", "detail", "exposure", "site", "time", "heading", "pitch", "fov", "tiles", "lang", "body", "standby", "scale", "stick", "objects"];
|
|
57
|
+
#root;
|
|
58
|
+
#stage;
|
|
59
|
+
#noteEl;
|
|
60
|
+
#statusEl;
|
|
61
|
+
#state = "idle";
|
|
62
|
+
#renderer;
|
|
63
|
+
#release;
|
|
64
|
+
#view;
|
|
65
|
+
#terrain;
|
|
66
|
+
#loading;
|
|
67
|
+
#abort;
|
|
68
|
+
#gate;
|
|
69
|
+
#look = { azimuth: 232, pitch: 13, fov: 74 };
|
|
70
|
+
#at = { east: 0, north: 0 };
|
|
71
|
+
#time = 0;
|
|
72
|
+
#sky;
|
|
73
|
+
#visible = typeof IntersectionObserver !== "function";
|
|
74
|
+
#io;
|
|
75
|
+
#keys = new Set();
|
|
76
|
+
#walkTimer;
|
|
77
|
+
#walkAt = 0;
|
|
78
|
+
#progress;
|
|
79
|
+
/** What has changed in the terrain since the card was last sent it, and the timer that sends it (the tiles come in dozens, the card is sent them at most every 300 ms). */
|
|
80
|
+
#pending = new Set();
|
|
81
|
+
#flush;
|
|
82
|
+
#placed = false;
|
|
83
|
+
/** Whether the view is being moved now (a drag, a step, a zoom): drawn at the quality of motion, and once more at the quality of rest when it stops. */
|
|
84
|
+
#moving = false;
|
|
85
|
+
#settle;
|
|
86
|
+
/** The quality of rest in `auto`: stepped down when a draw at rest takes too long on this machine. */
|
|
87
|
+
#restQuality = "full";
|
|
88
|
+
#drawMs;
|
|
89
|
+
#measured = 0;
|
|
90
|
+
/** The share the ground is drawn at while the view moves (1, or a half where the machine is slow), and the moving draws timed to decide it. */
|
|
91
|
+
#moveScale = 1;
|
|
92
|
+
#movingTimes = [];
|
|
93
|
+
#movingPending = false;
|
|
94
|
+
#drawScale = 1;
|
|
95
|
+
#scaled = 0;
|
|
96
|
+
/** The walking stick's push, east and north, each -1 to 1, and the finger that holds it. */
|
|
97
|
+
#push = { x: 0, y: 0 };
|
|
98
|
+
/** The things at the site and the buttons that name them, and the one chosen. */
|
|
99
|
+
#objects = [];
|
|
100
|
+
#labelEls = new Map();
|
|
101
|
+
#chosen;
|
|
102
|
+
#stickPointer = -1;
|
|
103
|
+
#pointers = new Map();
|
|
104
|
+
#pinch = 0;
|
|
105
|
+
#draws = 0;
|
|
106
|
+
#onContext = (state) => {
|
|
107
|
+
if (state === "unavailable")
|
|
108
|
+
this.#set("unavailable");
|
|
109
|
+
else if (state === "lost")
|
|
110
|
+
this.#set("lost");
|
|
111
|
+
else if (this.#view?.live)
|
|
112
|
+
this.#set("live");
|
|
113
|
+
};
|
|
114
|
+
/** Whether the first view of the ground is in (the heights are fetched and the view could draw at once): true while on `standby` too, which is how a page makes ready without taking the renderer. */
|
|
115
|
+
get loaded() {
|
|
116
|
+
return this.#terrain !== undefined;
|
|
117
|
+
}
|
|
118
|
+
/** The state now. */
|
|
119
|
+
get state() {
|
|
120
|
+
return this.#state;
|
|
121
|
+
}
|
|
122
|
+
/** The eyes' look now. Setting it turns the view (azimuth and pitch in degrees, `fov` the view's height in degrees); it is drawn at once. */
|
|
123
|
+
get look() {
|
|
124
|
+
return { ...this.#look };
|
|
125
|
+
}
|
|
126
|
+
set look(value) {
|
|
127
|
+
this.#look = clampLook(value);
|
|
128
|
+
this.#changed();
|
|
129
|
+
}
|
|
130
|
+
/** Where the eyes are: metres east and north of the site, and metres over the ground under them. */
|
|
131
|
+
get position() {
|
|
132
|
+
return { ...this.#at, up: EYE_HEIGHT };
|
|
133
|
+
}
|
|
134
|
+
/** The sky now: the Sun and the Earth in it. */
|
|
135
|
+
get sky() {
|
|
136
|
+
return this.#sky;
|
|
137
|
+
}
|
|
138
|
+
/** The moment shown, milliseconds since 1970. */
|
|
139
|
+
get time() {
|
|
140
|
+
return this.#time;
|
|
141
|
+
}
|
|
142
|
+
set time(value) {
|
|
143
|
+
this.#time = value;
|
|
144
|
+
this.#changed();
|
|
145
|
+
}
|
|
146
|
+
/** The height model as loaded, or `undefined` before: for a status line and a test. */
|
|
147
|
+
get terrain() {
|
|
148
|
+
return this.#terrain;
|
|
149
|
+
}
|
|
150
|
+
/** 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
|
+
get stats() {
|
|
152
|
+
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 };
|
|
154
|
+
}
|
|
155
|
+
/** 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
|
+
#quality() {
|
|
157
|
+
const own = this.getAttribute("quality");
|
|
158
|
+
if (own === "full" || own === "medium" || own === "fast")
|
|
159
|
+
return own;
|
|
160
|
+
return this.#moving ? "fast" : this.#restQuality;
|
|
161
|
+
}
|
|
162
|
+
connectedCallback() {
|
|
163
|
+
this.#root = this.shadowRoot ?? this.attachShadow({ mode: "open" });
|
|
164
|
+
this.#root.innerHTML = TEMPLATE;
|
|
165
|
+
this.#stage = this.#root.getElementById("stage");
|
|
166
|
+
this.#noteEl = this.#root.getElementById("note");
|
|
167
|
+
this.#statusEl = this.#root.getElementById("status");
|
|
168
|
+
if (!this.hasAttribute("role"))
|
|
169
|
+
this.setAttribute("role", "img");
|
|
170
|
+
if (!this.hasAttribute("tabindex"))
|
|
171
|
+
this.setAttribute("tabindex", "0");
|
|
172
|
+
this.setAttribute("data-state", this.#state);
|
|
173
|
+
this.#gate = createGate(1000 / frameCap(30, { deviceMemory: navigator.deviceMemory, hardwareConcurrency: navigator.hardwareConcurrency }), () => this.#draw());
|
|
174
|
+
this.#readAttributes();
|
|
175
|
+
this.addEventListener("pointerdown", this.#onPointerDown);
|
|
176
|
+
this.addEventListener("pointermove", this.#onPointerMove);
|
|
177
|
+
this.addEventListener("pointerup", this.#onPointerUp);
|
|
178
|
+
this.addEventListener("pointercancel", this.#onPointerUp);
|
|
179
|
+
this.addEventListener("wheel", this.#onWheel, { passive: false });
|
|
180
|
+
this.addEventListener("keydown", this.#onKeyDown);
|
|
181
|
+
this.addEventListener("keyup", this.#onKeyUp);
|
|
182
|
+
this.addEventListener("blur", this.#onBlur);
|
|
183
|
+
const stick = this.#root.getElementById("stick");
|
|
184
|
+
stick.addEventListener("pointerdown", this.#onStickDown);
|
|
185
|
+
stick.addEventListener("pointermove", this.#onStickMove);
|
|
186
|
+
stick.addEventListener("pointerup", this.#onStickUp);
|
|
187
|
+
stick.addEventListener("pointercancel", this.#onStickUp);
|
|
188
|
+
this.#showStick();
|
|
189
|
+
if (typeof IntersectionObserver === "function") {
|
|
190
|
+
this.#io = new IntersectionObserver((entries) => {
|
|
191
|
+
const last = entries[entries.length - 1];
|
|
192
|
+
if (last === undefined)
|
|
193
|
+
return;
|
|
194
|
+
this.#visible = last.isIntersecting;
|
|
195
|
+
if (this.#visible)
|
|
196
|
+
void this.#start();
|
|
197
|
+
else
|
|
198
|
+
this.#view?.blur();
|
|
199
|
+
});
|
|
200
|
+
this.#io.observe(this);
|
|
201
|
+
}
|
|
202
|
+
void this.#start();
|
|
203
|
+
}
|
|
204
|
+
disconnectedCallback() {
|
|
205
|
+
this.#io?.disconnect();
|
|
206
|
+
this.#abort?.abort();
|
|
207
|
+
clearTimeout(this.#flush);
|
|
208
|
+
this.#flush = undefined;
|
|
209
|
+
this.#gate?.cancel();
|
|
210
|
+
clearTimeout(this.#walkTimer);
|
|
211
|
+
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]])
|
|
212
|
+
this.removeEventListener(type, fn);
|
|
213
|
+
this.#view?.dispose();
|
|
214
|
+
this.#view = undefined;
|
|
215
|
+
this.#release?.();
|
|
216
|
+
this.#release = undefined;
|
|
217
|
+
this.#renderer = undefined;
|
|
218
|
+
}
|
|
219
|
+
attributeChangedCallback(name) {
|
|
220
|
+
if (!this.isConnected)
|
|
221
|
+
return;
|
|
222
|
+
if (name === "stick") {
|
|
223
|
+
this.#showStick();
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (name === "standby") {
|
|
227
|
+
if (!this.hasAttribute("standby"))
|
|
228
|
+
void this.#start();
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
if (name === "site" || name === "body" || name === "tiles" || name === "objects") {
|
|
232
|
+
this.#terrain = undefined;
|
|
233
|
+
this.#loading = undefined;
|
|
234
|
+
this.#pending.clear();
|
|
235
|
+
this.removeAttribute("data-loading");
|
|
236
|
+
this.#view?.dispose();
|
|
237
|
+
this.#view = undefined;
|
|
238
|
+
this.#readAttributes();
|
|
239
|
+
void this.#start();
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
this.#readAttributes();
|
|
243
|
+
this.#changed();
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Walk: `ahead` metres along the heading (negative backs up) and `aside` to its right. The ground under the eyes is read from the heights, so the eyes rise and fall with it.
|
|
247
|
+
*
|
|
248
|
+
* @param ahead - Metres forward.
|
|
249
|
+
* @param aside - Metres to the right.
|
|
250
|
+
*/
|
|
251
|
+
walk(ahead, aside = 0) {
|
|
252
|
+
this.#at = stepOver(this.#at, this.#look.azimuth, ahead, aside);
|
|
253
|
+
this.#changed();
|
|
254
|
+
}
|
|
255
|
+
#site() {
|
|
256
|
+
return siteById(this.getAttribute("site") ?? "apollo-17");
|
|
257
|
+
}
|
|
258
|
+
#readAttributes() {
|
|
259
|
+
const site = this.#site();
|
|
260
|
+
if (site === undefined) {
|
|
261
|
+
this.#set("unavailable", "no such site");
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const look = site.look;
|
|
265
|
+
this.#look = clampLook({ azimuth: num(this.getAttribute("heading"), look.azimuth), pitch: num(this.getAttribute("pitch"), look.pitch), fov: num(this.getAttribute("fov"), look.fov) });
|
|
266
|
+
const time = this.getAttribute("time");
|
|
267
|
+
this.#time = time === null || time === "" ? site.time : time === "now" ? Date.now() : Number.isFinite(Number(time)) ? Number(time) : Date.parse(time);
|
|
268
|
+
if (!Number.isFinite(this.#time))
|
|
269
|
+
this.#time = site.time;
|
|
270
|
+
this.#sky = moonSky(site.lat, site.lon, this.#time);
|
|
271
|
+
this.setAttribute("aria-label", `${site.name[this.#lang()]}: ${this.#lang() === "ja" ? "月面に立った視点" : "standing on the Moon"}`);
|
|
272
|
+
}
|
|
273
|
+
#lang() {
|
|
274
|
+
return this.getAttribute("lang") === "ja" ? "ja" : "en";
|
|
275
|
+
}
|
|
276
|
+
#set(state, text = "") {
|
|
277
|
+
this.#state = state;
|
|
278
|
+
this.setAttribute("data-state", state);
|
|
279
|
+
if (this.#statusEl !== undefined) {
|
|
280
|
+
this.#statusEl.textContent = state === "live" ? "" : text;
|
|
281
|
+
this.#statusEl.hidden = state === "live" || text === "";
|
|
282
|
+
}
|
|
283
|
+
this.dispatchEvent(new CustomEvent("wakusei-surface-state", { detail: { state } }));
|
|
284
|
+
}
|
|
285
|
+
async #start() {
|
|
286
|
+
if (!this.isConnected || !this.#visible || this.#state === "unavailable")
|
|
287
|
+
return;
|
|
288
|
+
const site = this.#site();
|
|
289
|
+
if (site === undefined)
|
|
290
|
+
return;
|
|
291
|
+
if (this.#terrain === undefined) {
|
|
292
|
+
this.#loading ??= this.#load(site.body, site.id);
|
|
293
|
+
await this.#loading;
|
|
294
|
+
}
|
|
295
|
+
if (this.#terrain === undefined)
|
|
296
|
+
return;
|
|
297
|
+
// on standby the ground is loaded and nothing more: the renderer is another view's until the attribute goes
|
|
298
|
+
if (this.hasAttribute("standby"))
|
|
299
|
+
return;
|
|
300
|
+
// the things at the site (and the made ground keeping away from them) are known before the place the eyes start from is chosen
|
|
301
|
+
this.#objects = this.getAttribute("objects") === "off" ? [] : objectsOf(site.id);
|
|
302
|
+
setKeepOut(this.#objects);
|
|
303
|
+
if (!this.#placed) {
|
|
304
|
+
// a step or two from the landing point, out of any made crater
|
|
305
|
+
const stand = this.getAttribute("detail") === "off" ? { x: 0, y: 0 } : standingPlace(0, 0);
|
|
306
|
+
this.#at = { east: stand.x, north: stand.y };
|
|
307
|
+
this.#placed = true;
|
|
308
|
+
}
|
|
309
|
+
if (this.#view === undefined) {
|
|
310
|
+
if (this.#renderer === undefined) {
|
|
311
|
+
const taken = takeRenderer(this.#onContext);
|
|
312
|
+
this.#renderer = taken.renderer;
|
|
313
|
+
this.#release = taken.release;
|
|
314
|
+
}
|
|
315
|
+
this.#makeLabels();
|
|
316
|
+
const item = createSurfaceItem({ objects: this.#objects, traverse: this.#objects.length > 0 ? traverseOf(site.id) : [], levels: this.#terrain.levels, pictures: this.#terrain.pictures, horizons: this.#terrain.horizons, manifest: this.#terrain.manifest, groundY: (east, north) => this.#groundAt(east, north), key: `surface:${site.id}` });
|
|
317
|
+
this.#view = this.#renderer.view(this.#stage, item, { still: null });
|
|
318
|
+
}
|
|
319
|
+
const ok = await this.#view.focus();
|
|
320
|
+
if (ok) {
|
|
321
|
+
this.#set("live");
|
|
322
|
+
this.#noteEl.textContent = this.#noteText();
|
|
323
|
+
this.#changed();
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
const now = this.#state;
|
|
327
|
+
if (now !== "unavailable" && now !== "lost")
|
|
328
|
+
this.#set("unavailable", this.#lang() === "ja" ? "この端末では3Dを描けません" : "This device cannot draw 3D");
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
async #load(body, site) {
|
|
332
|
+
this.#set("loading", this.#lang() === "ja" ? "地形を読み込んでいます" : "Loading the ground");
|
|
333
|
+
this.#abort?.abort();
|
|
334
|
+
this.#abort = new AbortController();
|
|
335
|
+
try {
|
|
336
|
+
const base = this.getAttribute("tiles");
|
|
337
|
+
const folder = base === null || base === "" ? TILES_BASE : base;
|
|
338
|
+
this.#terrain = await loadTerrain(folder, body, site, {
|
|
339
|
+
signal: this.#abort.signal,
|
|
340
|
+
onProgress: (progress) => {
|
|
341
|
+
this.#progress = progress;
|
|
342
|
+
if (this.#state === "loading")
|
|
343
|
+
this.#statusEl.textContent = `${this.#lang() === "ja" ? "地形を読み込んでいます" : "Loading the ground"} ${Math.round((100 * Math.min(progress.done, progress.first)) / progress.first)} %`;
|
|
344
|
+
},
|
|
345
|
+
onChange: (id) => {
|
|
346
|
+
this.#pending.add(id);
|
|
347
|
+
this.#flush ??= setTimeout(() => this.#sendChanges(), 300);
|
|
348
|
+
},
|
|
349
|
+
});
|
|
350
|
+
// the first view is in and the ground is whole; the rest comes in place, nearest first
|
|
351
|
+
this.setAttribute("data-loading", "more");
|
|
352
|
+
const terrain = this.#terrain;
|
|
353
|
+
terrain.complete.then(() => {
|
|
354
|
+
if (this.#terrain === terrain)
|
|
355
|
+
this.setAttribute("data-loading", "done");
|
|
356
|
+
}, (error) => {
|
|
357
|
+
if (this.#terrain === terrain && error.name !== "AbortError")
|
|
358
|
+
this.setAttribute("data-loading", "failed");
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
catch (error) {
|
|
362
|
+
if (error.name !== "AbortError")
|
|
363
|
+
this.#set("unavailable", this.#lang() === "ja" ? "この場所の地形がありません" : "No ground for this site yet");
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
/** Send the card what has changed in the terrain and draw it. */
|
|
367
|
+
#sendChanges() {
|
|
368
|
+
this.#flush = undefined;
|
|
369
|
+
const ids = [...this.#pending];
|
|
370
|
+
this.#pending.clear();
|
|
371
|
+
const scene = this.#view?.scene;
|
|
372
|
+
if (scene === undefined || ids.length === 0)
|
|
373
|
+
return;
|
|
374
|
+
scene.refresh(ids);
|
|
375
|
+
this.#changed();
|
|
376
|
+
}
|
|
377
|
+
#noteText() {
|
|
378
|
+
const m = this.#terrain?.manifest;
|
|
379
|
+
if (m === undefined)
|
|
380
|
+
return "";
|
|
381
|
+
const made = this.getAttribute("detail") === "off" ? "" : this.#lang() === "ja" ? "5 m より細かい地形(小さなクレーター、砂塵、岩)は計算で作ったもので、実測ではありません。" : "Detail finer than the 5 m grid (small craters, dust, rocks) is made, not measured.";
|
|
382
|
+
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.";
|
|
383
|
+
const picture = m.picture === null || m.picture === undefined ? "" : ` ${m.picture.credit}.`;
|
|
384
|
+
return this.#lang() === "ja" ? `高さの実測: ${m.accuracy}。${m.credit}。${made}${things}` : `Heights measured: ${m.accuracy}. ${m.credit}.${picture} ${made}${things}`;
|
|
385
|
+
}
|
|
386
|
+
/** The ground's height at a point over the site's: the measured heights, the made craters on them (if the page has them on) and the Moon's curve taken off. */
|
|
387
|
+
#groundAt(east, north) {
|
|
388
|
+
const t = this.#terrain;
|
|
389
|
+
const h = groundAt(t.levels, t.manifest.height, east, north) ?? t.manifest.ground;
|
|
390
|
+
const made = this.getAttribute("detail") === "off" ? 0 : madeGround(east, north, 0.35).h;
|
|
391
|
+
return h - t.manifest.ground - drop(Math.hypot(east, north), t.manifest.radius) + made;
|
|
392
|
+
}
|
|
393
|
+
/** 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
|
+
#eyeUp() {
|
|
395
|
+
return this.#groundAt(this.#at.east, this.#at.north) + EYE_HEIGHT;
|
|
396
|
+
}
|
|
397
|
+
/** 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. */
|
|
398
|
+
#changed(moving = true) {
|
|
399
|
+
if (!this.#view?.live)
|
|
400
|
+
return;
|
|
401
|
+
if (moving) {
|
|
402
|
+
this.#moving = true;
|
|
403
|
+
clearTimeout(this.#settle);
|
|
404
|
+
this.#settle = setTimeout(() => {
|
|
405
|
+
this.#moving = false;
|
|
406
|
+
this.#gate?.request();
|
|
407
|
+
}, 160);
|
|
408
|
+
}
|
|
409
|
+
this.#gate?.request();
|
|
410
|
+
}
|
|
411
|
+
#draw() {
|
|
412
|
+
const scene = this.#view?.scene;
|
|
413
|
+
if (scene === undefined || this.#terrain === undefined)
|
|
414
|
+
return;
|
|
415
|
+
const site = this.#site();
|
|
416
|
+
if (site === undefined)
|
|
417
|
+
return;
|
|
418
|
+
this.#sky = moonSky(site.lat, site.lon, this.#time);
|
|
419
|
+
// `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)
|
|
420
|
+
const auto = this.getAttribute("quality") === null || this.getAttribute("quality") === "auto";
|
|
421
|
+
const was = scene.drawMs;
|
|
422
|
+
if (auto && !this.#moving && was !== undefined && this.#measured > 0) {
|
|
423
|
+
if (was > 120 && this.#restQuality === "full")
|
|
424
|
+
this.#restQuality = "medium";
|
|
425
|
+
else if (was > 250 && this.#restQuality === "medium")
|
|
426
|
+
this.#restQuality = "fast";
|
|
427
|
+
}
|
|
428
|
+
// the draws while the view moves are timed too (the first few), and a machine that takes over 24 ms for one is given a half size for them: a quarter of the pixels, stretched
|
|
429
|
+
const scaleAttr = this.getAttribute("scale");
|
|
430
|
+
if (this.#movingPending && was !== undefined) {
|
|
431
|
+
this.#movingPending = false;
|
|
432
|
+
this.#movingTimes.push(was);
|
|
433
|
+
if (this.#movingTimes.length >= 2 && this.#moveScale === 1) {
|
|
434
|
+
const sorted = [...this.#movingTimes].sort((a, b) => a - b);
|
|
435
|
+
if (sorted[Math.floor(sorted.length / 2)] > 24)
|
|
436
|
+
this.#moveScale = 0.5;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
const forced = scaleAttr === null || scaleAttr === "auto" ? undefined : Number(scaleAttr);
|
|
440
|
+
const timeMoving = auto && this.#moving && this.#movingTimes.length < 4 && forced === undefined;
|
|
441
|
+
if (timeMoving)
|
|
442
|
+
this.#movingPending = true;
|
|
443
|
+
this.#drawScale = forced !== undefined && Number.isFinite(forced) ? Math.min(1, Math.max(0.25, forced)) : this.#moving ? this.#moveScale : 1;
|
|
444
|
+
const measure = (auto && !this.#moving && this.#measured < 4) || timeMoving;
|
|
445
|
+
if (measure && !this.#moving)
|
|
446
|
+
this.#measured += 1;
|
|
447
|
+
if (this.#drawScale < 1)
|
|
448
|
+
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 });
|
|
450
|
+
this.#view.invalidate();
|
|
451
|
+
this.#draws += 1;
|
|
452
|
+
this.#placeLabels();
|
|
453
|
+
}
|
|
454
|
+
// --- the things at the site: a small button on each, which goes to it and says what it is ----------------------------------------------------------------------------------------------------
|
|
455
|
+
/** The things at the site, at their published places (none where the site has none or `objects="off"`). */
|
|
456
|
+
get objects() {
|
|
457
|
+
return this.#objects;
|
|
458
|
+
}
|
|
459
|
+
/** The words on a thing's button and in the line that says what it is. */
|
|
460
|
+
#objectWords(o) {
|
|
461
|
+
const ja = this.#lang() === "ja";
|
|
462
|
+
const short = { lander: ["Lunar module", "月着陸船"], rover: ["Rover", "月面車"], flag: ["Flag", "旗"], station: ["ALSEP", "ALSEP"], instrument: ["Transmitter", "送信機"] };
|
|
463
|
+
const placed = ja
|
|
464
|
+
? "このパッケージが、公表された座標(Haase ほか 2019)の位置に置きました。形はこちらで描いた簡単なもので、スキャンではありません。"
|
|
465
|
+
: "Placed by this package at its published position (Haase et al. 2019). The shape is a plain one drawn here, not a scan.";
|
|
466
|
+
const rover = ja ? "月面車は、最後の走行の記録の終点に置いています。向きと形はこちらで決めたものです。" : "The rover stands where the record of its last traverse ends; its heading and shape are ours.";
|
|
467
|
+
return { short: short[o.kind][ja ? 1 : 0], about: `${o.name[ja ? "ja" : "en"]}. ${o.kind === "rover" ? rover : placed}` };
|
|
468
|
+
}
|
|
469
|
+
#makeLabels() {
|
|
470
|
+
const box = this.#root.getElementById("labels");
|
|
471
|
+
box.replaceChildren();
|
|
472
|
+
this.#labelEls.clear();
|
|
473
|
+
for (const o of this.#objects) {
|
|
474
|
+
const button = document.createElement("button");
|
|
475
|
+
button.type = "button";
|
|
476
|
+
button.className = "label";
|
|
477
|
+
button.hidden = true;
|
|
478
|
+
button.setAttribute("aria-pressed", "false");
|
|
479
|
+
button.textContent = this.#objectWords(o).short;
|
|
480
|
+
button.addEventListener("click", (event) => {
|
|
481
|
+
event.stopPropagation();
|
|
482
|
+
this.choose(o.id);
|
|
483
|
+
});
|
|
484
|
+
// a press on the button is not a drag of the view
|
|
485
|
+
button.addEventListener("pointerdown", (event) => event.stopPropagation());
|
|
486
|
+
box.append(button);
|
|
487
|
+
this.#labelEls.set(o.id, button);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
/** 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
|
+
#placeLabels() {
|
|
492
|
+
if (this.#labelEls.size === 0)
|
|
493
|
+
return;
|
|
494
|
+
const box = this.getBoundingClientRect();
|
|
495
|
+
const [w, h] = [box.width, box.height];
|
|
496
|
+
const vp = viewProjection([this.#at.east, this.#eyeUp(), -this.#at.north], this.#look, w / Math.max(1, h));
|
|
497
|
+
for (const o of this.#objects) {
|
|
498
|
+
const el = this.#labelEls.get(o.id);
|
|
499
|
+
const up = this.#groundAt(o.east, o.north) + (o.kind === "lander" ? 3.4 : o.kind === "flag" ? 2.6 : o.kind === "rover" ? 2.0 : 0.9);
|
|
500
|
+
const [x, y, z] = [o.east, up, -o.north];
|
|
501
|
+
const cw = vp[3] * x + vp[7] * y + vp[11] * z + vp[15];
|
|
502
|
+
const nx = (vp[0] * x + vp[4] * y + vp[8] * z + vp[12]) / cw;
|
|
503
|
+
const ny = (vp[1] * x + vp[5] * y + vp[9] * z + vp[13]) / cw;
|
|
504
|
+
const distance = Math.hypot(o.east - this.#at.east, o.north - this.#at.north);
|
|
505
|
+
const shown = cw > 0 && Math.abs(nx) < 1 && Math.abs(ny) < 1 && distance < 400 && distance > 1.5;
|
|
506
|
+
el.hidden = !shown;
|
|
507
|
+
if (shown)
|
|
508
|
+
el.style.transform = `translate(${((nx + 1) / 2) * w - el.offsetWidth / 2}px, ${((1 - ny) / 2) * h - el.offsetHeight - 4}px)`;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Choose a thing at the site: the eyes go to a few metres from it, looking at it, its button is pressed and a line says what it is and that it was placed by this package. `wakusei-surface-object` is sent
|
|
513
|
+
* with its id. Choosing the same one again, or `undefined`, puts the line away.
|
|
514
|
+
*
|
|
515
|
+
* @param id - A thing's id (`lm`, `rover`, `flag`, `alsep`, `sep`), or `undefined` for none.
|
|
516
|
+
* @returns Whether there is such a thing here.
|
|
517
|
+
*/
|
|
518
|
+
choose(id) {
|
|
519
|
+
const about = this.#root.getElementById("about");
|
|
520
|
+
const o = id === undefined ? undefined : this.#objects.find((x) => x.id === id);
|
|
521
|
+
if (id !== undefined && o === undefined)
|
|
522
|
+
return false;
|
|
523
|
+
if (o === undefined || this.#chosen === id) {
|
|
524
|
+
this.#chosen = undefined;
|
|
525
|
+
about.hidden = true;
|
|
526
|
+
for (const el of this.#labelEls.values())
|
|
527
|
+
el.setAttribute("aria-pressed", "false");
|
|
528
|
+
this.#changed(false);
|
|
529
|
+
return true;
|
|
530
|
+
}
|
|
531
|
+
this.#chosen = id;
|
|
532
|
+
for (const [key, el] of this.#labelEls)
|
|
533
|
+
el.setAttribute("aria-pressed", String(key === id));
|
|
534
|
+
about.textContent = this.#objectWords(o).about;
|
|
535
|
+
about.hidden = false;
|
|
536
|
+
// stand a few metres off, on the side the eyes are on, and look at it
|
|
537
|
+
const near = { lander: 14, rover: 7, flag: 5, station: 8, instrument: 6 };
|
|
538
|
+
const [dx, dy] = [this.#at.east - o.east, this.#at.north - o.north];
|
|
539
|
+
const length = Math.hypot(dx, dy) || 1;
|
|
540
|
+
const stand = near[o.kind];
|
|
541
|
+
const [east, north] = length < 1 ? [o.east - stand, o.north] : [o.east + (dx / length) * stand, o.north + (dy / length) * stand];
|
|
542
|
+
this.#at = { east, north };
|
|
543
|
+
const azimuth = ((Math.atan2(o.east - east, o.north - north) * 180) / Math.PI + 360) % 360;
|
|
544
|
+
this.#look = clampLook({ azimuth, pitch: o.kind === "lander" ? 8 : 5, fov: this.#look.fov });
|
|
545
|
+
this.dispatchEvent(new CustomEvent("wakusei-surface-object", { detail: { id: o.id, name: o.name }, bubbles: true, composed: true }));
|
|
546
|
+
this.#changed();
|
|
547
|
+
return true;
|
|
548
|
+
}
|
|
549
|
+
// --- the walking stick: for a touch screen, where there are no keys. One finger on the view looks, two fingers pinch to zoom, and the finger on the stick walks ----------------------------------------
|
|
550
|
+
/** Whether the stick is shown: `stick="on"` or `off`, and left out it is shown where the main pointer is a finger (`pointer: coarse`). */
|
|
551
|
+
#showStick() {
|
|
552
|
+
const own = this.getAttribute("stick");
|
|
553
|
+
const coarse = typeof matchMedia === "function" && matchMedia("(pointer: coarse)").matches;
|
|
554
|
+
const on = own === "on" || (own !== "off" && coarse);
|
|
555
|
+
const stick = this.#root?.getElementById("stick");
|
|
556
|
+
if (stick !== null && stick !== undefined)
|
|
557
|
+
stick.hidden = !on;
|
|
558
|
+
}
|
|
559
|
+
#onStickDown = (event) => {
|
|
560
|
+
event.stopPropagation(); // the view's own hands (look, pinch) never hear the finger that walks
|
|
561
|
+
if (this.#stickPointer !== -1)
|
|
562
|
+
return;
|
|
563
|
+
this.#stickPointer = event.pointerId;
|
|
564
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
565
|
+
this.#onStickMove(event);
|
|
566
|
+
};
|
|
567
|
+
#onStickMove = (event) => {
|
|
568
|
+
if (event.pointerId !== this.#stickPointer)
|
|
569
|
+
return;
|
|
570
|
+
event.stopPropagation();
|
|
571
|
+
const stick = event.currentTarget;
|
|
572
|
+
const box = stick.getBoundingClientRect();
|
|
573
|
+
const reach = box.width / 2;
|
|
574
|
+
let x = (event.clientX - (box.left + reach)) / reach;
|
|
575
|
+
let y = (event.clientY - (box.top + reach)) / reach;
|
|
576
|
+
const length = Math.hypot(x, y);
|
|
577
|
+
if (length > 1) {
|
|
578
|
+
x /= length;
|
|
579
|
+
y /= length;
|
|
580
|
+
}
|
|
581
|
+
// a small dead centre: a finger resting on the stick does not creep
|
|
582
|
+
this.#push = length < 0.12 ? { x: 0, y: 0 } : { x, y: -y };
|
|
583
|
+
const knob = this.#root.getElementById("knob");
|
|
584
|
+
knob.style.transform = `translate(${x * reach * 0.6}px, ${y * reach * 0.6}px)`;
|
|
585
|
+
if (this.#push.x !== 0 || this.#push.y !== 0) {
|
|
586
|
+
this.#walkAt = performance.now();
|
|
587
|
+
this.#walkTick();
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
#onStickUp = (event) => {
|
|
591
|
+
if (event.pointerId !== this.#stickPointer)
|
|
592
|
+
return;
|
|
593
|
+
event.stopPropagation();
|
|
594
|
+
this.#stickPointer = -1;
|
|
595
|
+
this.#push = { x: 0, y: 0 };
|
|
596
|
+
this.#root.getElementById("knob").style.transform = "";
|
|
597
|
+
};
|
|
598
|
+
// --- hands ---------------------------------------------------------------------------------------------------------------------------------------
|
|
599
|
+
#onPointerDown = (event) => {
|
|
600
|
+
this.#pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
|
|
601
|
+
this.setPointerCapture(event.pointerId);
|
|
602
|
+
this.setAttribute("data-dragging", "");
|
|
603
|
+
this.#pinch = this.#pointers.size === 2 ? this.#spread() : 0;
|
|
604
|
+
};
|
|
605
|
+
#onPointerMove = (event) => {
|
|
606
|
+
const was = this.#pointers.get(event.pointerId);
|
|
607
|
+
if (was === undefined)
|
|
608
|
+
return;
|
|
609
|
+
this.#pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
|
|
610
|
+
if (this.#pointers.size >= 2) {
|
|
611
|
+
const now = this.#spread();
|
|
612
|
+
if (this.#pinch > 0 && now > 0)
|
|
613
|
+
this.#zoom(this.#pinch / now);
|
|
614
|
+
this.#pinch = now;
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
const box = this.getBoundingClientRect();
|
|
618
|
+
const perPixel = this.#look.fov / Math.max(1, box.height);
|
|
619
|
+
this.#look = clampLook({ ...this.#look, azimuth: this.#look.azimuth - (event.clientX - was.x) * perPixel, pitch: this.#look.pitch + (event.clientY - was.y) * perPixel });
|
|
620
|
+
this.#changed();
|
|
621
|
+
};
|
|
622
|
+
#onPointerUp = (event) => {
|
|
623
|
+
this.#pointers.delete(event.pointerId);
|
|
624
|
+
if (this.#pointers.size === 0)
|
|
625
|
+
this.removeAttribute("data-dragging");
|
|
626
|
+
this.#pinch = 0;
|
|
627
|
+
};
|
|
628
|
+
#spread() {
|
|
629
|
+
const [a, b] = [...this.#pointers.values()];
|
|
630
|
+
return a === undefined || b === undefined ? 0 : Math.hypot(a.x - b.x, a.y - b.y);
|
|
631
|
+
}
|
|
632
|
+
#zoom(factor) {
|
|
633
|
+
this.#look = clampLook({ ...this.#look, fov: this.#look.fov * factor });
|
|
634
|
+
this.#changed();
|
|
635
|
+
}
|
|
636
|
+
#onWheel = (event) => {
|
|
637
|
+
if (!event.ctrlKey && !event.metaKey)
|
|
638
|
+
return;
|
|
639
|
+
event.preventDefault();
|
|
640
|
+
this.#zoom(Math.exp(event.deltaY * 0.0015));
|
|
641
|
+
};
|
|
642
|
+
#onKeyDown = (event) => {
|
|
643
|
+
const key = event.key.length === 1 ? event.key.toLowerCase() : event.key;
|
|
644
|
+
if (key === "+" || key === "=")
|
|
645
|
+
return this.#zoom(0.85);
|
|
646
|
+
if (key === "-" || key === "_")
|
|
647
|
+
return this.#zoom(1 / 0.85);
|
|
648
|
+
if (!["w", "a", "s", "d", "q", "e", "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].includes(key))
|
|
649
|
+
return;
|
|
650
|
+
event.preventDefault();
|
|
651
|
+
if (!this.#keys.has(key)) {
|
|
652
|
+
this.#keys.add(key);
|
|
653
|
+
this.#walkAt = performance.now();
|
|
654
|
+
this.#walkTick();
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
#onKeyUp = (event) => {
|
|
658
|
+
this.#keys.delete(event.key.length === 1 ? event.key.toLowerCase() : event.key);
|
|
659
|
+
};
|
|
660
|
+
#onBlur = () => {
|
|
661
|
+
this.#keys.clear();
|
|
662
|
+
};
|
|
663
|
+
/** 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
|
+
#walkTick = () => {
|
|
665
|
+
clearTimeout(this.#walkTimer);
|
|
666
|
+
if (this.#keys.size === 0 && this.#push.x === 0 && this.#push.y === 0)
|
|
667
|
+
return;
|
|
668
|
+
const now = performance.now();
|
|
669
|
+
const dt = Math.min(0.1, (now - this.#walkAt) / 1000);
|
|
670
|
+
this.#walkAt = now;
|
|
671
|
+
const k = this.#keys;
|
|
672
|
+
const ahead = (k.has("w") || k.has("ArrowUp") ? 1 : 0) - (k.has("s") || k.has("ArrowDown") ? 1 : 0) + this.#push.y;
|
|
673
|
+
const aside = (k.has("d") ? 1 : 0) - (k.has("a") ? 1 : 0) + this.#push.x;
|
|
674
|
+
const turn = (k.has("e") || k.has("ArrowRight") ? 1 : 0) - (k.has("q") || k.has("ArrowLeft") ? 1 : 0);
|
|
675
|
+
if (turn !== 0)
|
|
676
|
+
this.#look = clampLook({ ...this.#look, azimuth: this.#look.azimuth + turn * 60 * dt });
|
|
677
|
+
const speed = Math.min(1, Math.hypot(ahead, aside)) / Math.max(1e-9, Math.hypot(ahead, aside));
|
|
678
|
+
if (ahead !== 0 || aside !== 0)
|
|
679
|
+
this.#at = stepOver(this.#at, this.#look.azimuth, ahead * speed * WALK_SPEED * dt, aside * speed * WALK_SPEED * dt);
|
|
680
|
+
this.#changed();
|
|
681
|
+
this.#walkTimer = setTimeout(this.#walkTick, 33);
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
if (typeof customElements !== "undefined" && customElements.get("wakusei-surface") === undefined)
|
|
685
|
+
customElements.define("wakusei-surface", WakuseiSurface);
|