@johnmorrisdotca/wakusei-planets 0.46.0 → 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 +5 -0
- package/NOTICE.md +1 -0
- package/README.md +3 -3
- package/dist/scene/body.d.ts +1 -1
- package/dist/scene/textures.d.ts +2 -2
- package/dist/surface/detail.d.ts +17 -0
- package/dist/surface/detail.js +25 -1
- package/dist/surface/element.d.ts +13 -0
- package/dist/surface/element.js +218 -15
- package/dist/surface/glsl.d.ts +11 -5
- package/dist/surface/glsl.js +55 -1
- package/dist/surface/index.d.ts +3 -1
- package/dist/surface/index.js +3 -1
- 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/scene.d.ts +8 -0
- package/dist/surface/scene.js +169 -4
- package/dist/surface/shapes.d.ts +62 -0
- package/dist/surface/shapes.js +247 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.47.0] - 2026-11-13
|
|
6
|
+
|
|
7
|
+
- **Things at the Apollo 17 site, at their published places** (MODULES-1308). The descent stage of the lunar module, the flag, the ALSEP central station, the surface electrical properties transmitter and the rover stand at the coordinates of Haase et al. (2019, doi 10.1029/2018EA000408; two small files read by byte range from the PDS archive of its map, NOTICE.md), drawn by this package as plain shapes with flat colours (an octagonal gold body on four splayed legs with braces, pads and the ladder; a frame on four wheels with fenders, seats, console, dish and camera masts) and cast shadows, and the rover's nine traverses as a faint pair of tracks along the published line. Each has a small pressable button (`choose(id)`, `objects`, the `wakusei-surface-object` event, `objects="off"`) that goes to it and says it was placed by this package; the rover's place is the end of its last traverse line and its heading a reading of it, both labelled ours. The made craters and rocks keep away from them.
|
|
8
|
+
- **Half size while the view moves, and a walking stick for touch** (MODULES-1324). A machine that takes over 24 ms for a draw while the view moves draws the ground at half width and height into a smaller target stretched to the canvas, back at full size one draw after it stops (`scale`, `stats.scale`, `stats.scaled`). On a touch screen one finger looks, two pinch to zoom and an on-screen stick (`stick`) walks.
|
|
9
|
+
|
|
5
10
|
## [0.46.0] - 2026-11-13
|
|
6
11
|
|
|
7
12
|
- **Standing on the Moon** (MODULES-1308). `<wakusei-surface>` (`@johnmorrisdotca/wakusei-planets/surface/element`) puts the viewer on the Moon at the Apollo 17 landing site, Taurus-Littrow: the ground is drawn from the measured 5 m LROC/LOLA height model (public domain, credited in NOTICE.md) with the Sun and the Earth where they really are at the moment shown (`moonSky`), hard shadows (the measured ground's baked into horizon maps, only the made detail marched, in three `quality` tiers with `auto` stepping down on a slow card), a ground picture from the LROC mosaic with its shading divided out, and made detail marked as made (craters from half a metre by the lunar size-frequency law, mostly old and soft; rounded, part-buried rocks lit like the ground). One draw when something changes, nothing at rest; drag to look, W A S D to walk at 1.4 m/s over the ground, zoom is the field of view. The first view is 4.2 MB (12.9 MB for the whole site), fetched in rings: the coarse level whole, the middle of the finest, nearest first after that; tiles and horizon maps are lossless WebP. The tiles are made by `scripts/make-moon-terrain.py` (`pnpm terrain:fetch` downloads the three NASA files, SHA-256 checked, then `pnpm terrain`) and the Pages build makes and serves them beside the body tiles (cached on the script; nothing is downloaded when the cache hits), in no package. Pure parts (`moonSky`, the camera, the tile decoding and filling, the made craters and rocks, `loadPlan`) are exported from `/surface`.
|
package/NOTICE.md
CHANGED
|
@@ -269,6 +269,7 @@ The height tiles of `<wakusei-surface>` (`scripts/make-moon-terrain.py`; they ar
|
|
|
269
269
|
- **The ground picture**: the browse picture of `NAC_ROI_APOLLO17LOC_E205N0306_5M`, the Apollo 17 low-Sun controlled narrow angle camera mosaic, 5 m a pixel (https://pds.lroc.im-ldi.com/data/LRO-L-LROC-5-RDR-V1.0/LROLRC_2001/EXTRAS/BROWSE/NAC_ROI/APOLLO17LOC/NAC_ROI_APOLLO17LOC_E205N0306_5M.TIF, 108,949,491 bytes). The build fits the Sun the mosaic was lit by to the heights, divides that shading out and keeps the ground's own light and dark (the fit for Apollo 17: azimuth 264 degrees, elevation 7 degrees, correlation 0.76).
|
|
270
270
|
- **Heights beyond the model**: the Lunar Orbiter Laser Altimeter (LOLA) global height map at 64 pixels a degree (`ldem_64.img`, data set `LRO-L-LOLA-4-GDR-V1.0`, https://pds-geosciences.wustl.edu/lro/lro-l-lola-3-rdr-v1/lrolol_1xxx/data/lola_gdr/cylindrical/img/ldem_64.img, 23,040 x 11,520 samples of 16 bits, height = 0.5 m x value above a sphere of radius 1,737.4 km), of which only the window round the site is read, by HTTP byte ranges (about 25 MB of a 531 MB file).
|
|
271
271
|
- **Terms**: the PDS Geosciences Node's FAQ (https://pds-geosciences.wustl.edu/faq.html, read 2026-11-13): "Data sets archived in the PDS are in the public domain." The LROC terms of use (https://lroc.im-ldi.com/about/terms, read 2026-11-13) say the products of the LROC data node and the PDS archive are in the public domain, that images elsewhere on the LROC website (featured images and curated products) are copyrighted and are not used here, and ask for the credit "NASA/GSFC/Arizona State University". The credit lines the page shows are that, and "LOLA Team (NASA/GSFC)", with the Planetary Data System as the publisher of the data sets (the PDS asks that a data set be cited like published research; its DOI is in the PDS DOI portal).
|
|
272
|
+
- **Things at the Apollo 17 site** (`src/surface/objects-apollo-17.ts`, made by `scripts/make-apollo17-objects.py`, read on 2026-11-13): the positions of the lunar module's descent stage, the flag, the ALSEP central station and the surface electrical properties transmitter, and the rover's nine traverses, from the map of Haase, Wählisch, Gläser, Oberst and Robinson, "Coordinates and Maps of the Apollo 17 Landing Site", Earth and Space Science 6 (2019), https://doi.org/10.1029/2018EA000408, as archived by the PDS Cartography and Imaging Sciences Node and published by USGS Astrogeology (https://astrogeology.usgs.gov/search/map/moon_apollo_17_lroc_nac_landing_site_orthomosaic_50cm, whose use constraint reads "Please cite authors"). Two files are read out of its 1.7 GB zip by HTTP byte ranges (about 94 KB fetched; the zip is never downloaded): `APOLLO17_CONTROLPOINTS_2018.TAB` (body-fixed X, Y, Z in metres, the published positions) and `APOLLO17_TRAVERSE_2018.SHP` (the traverses, Transverse Mercator on a sphere of 1,737.4 km, central meridian 30.7 degrees). They are coordinates, which are facts; no picture, text or map of the paper is used. The rover's place and heading are this package's reading of the end of the last traverse line: the paper's own table of the rover's parking place was not available to this build (the publisher's page refused programs), so the rover's place is not that published position and the page says so. The shapes of all five things are plain drawings made here (boxes, cylinders and struts, from sizes of about 3.2 m for the descent stage's deck, 4.7 m from its middle to a footpad, and 3.1 m by 2.3 m for the rover); no flag, name or mark is drawn. uchusen-rockets has a lunar module (its descent and ascent stages, plain shapes) that this package does not use; no lunar rover model was found in it.
|
|
272
273
|
- **Left out**: the merged LOLA and Kaguya (SELENE) height grid. The JAXA part's terms could not be found, and an MIT-licensed package can pass on only what it knows to be free to pass on.
|
|
273
274
|
- **Made, not measured**: everything below the 5 m grid (small craters from 0.5 to 20 m, the roughness of the dust, rocks of 0.1 to 1.5 m) is made by this package from a seeded random grid, by the lunar size-frequency law, and is not a picture or a measurement of any place. The picture says so under the ground.
|
|
274
275
|
|
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ Wakusei Planets runs in the browser of a phone, a tablet or a computer: nothing
|
|
|
19
19
|
|
|
20
20
|
<p align="center"><img alt="The demo on a desk: Saturn in the painted look, turning in the big view, with the page's links to the portrait builder, the colouring sheets, the space view, the star page and the size line-up above it, and the choice of body and its moons below" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/main/docs/images/home-desk.webp" width="620"> <img alt="The same page on a phone: the same links in rows, and Saturn in the painted look below them" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/main/docs/images/home-phone.webp" width="200"></p>
|
|
21
21
|
|
|
22
|
-
<p align="center"><img alt="Every body at one scale, the Earth among them: each small body has a magnified picture joined by a line, and the Sun shows only its edge" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.
|
|
22
|
+
<p align="center"><img alt="Every body at one scale, the Earth among them: each small body has a magnified picture joined by a line, and the Sun shows only its edge" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.47.0/docs/images/lineup-desk.png" width="640"></p>
|
|
23
23
|
|
|
24
24
|
## Who it is for
|
|
25
25
|
|
|
@@ -388,7 +388,7 @@ The tiles of every body share one 48 MB budget, six loads at a time for a source
|
|
|
388
388
|
|
|
389
389
|
## The portrait builder
|
|
390
390
|
|
|
391
|
-
<p align="center"><img alt="The Sun and the planets in an arc, painted, with their names, in the portrait builder" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.
|
|
391
|
+
<p align="center"><img alt="The Sun and the planets in an arc, painted, with their names, in the portrait builder" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.47.0/docs/images/portrait-family.png" width="640"></p>
|
|
392
392
|
|
|
393
393
|
[The portrait builder](https://johnmorrisdotca.github.io/wakusei-planets/portrait.html) puts any bodies in one picture: drag them, size them, turn them, order them front to back, arrange them in a row, an arc, a grid or at true orbit distance (true or readable sizes, a planet's moons round it in orbit order), light them from one direction, and take the code, a PNG or an SVG. The scene is kept in the address, and every body is drawn in one WebGL scene, so the page holds one WebGL context. [The portrait builder](docs/guides/portrait-builder.md) is its guide.
|
|
394
394
|
|
|
@@ -535,7 +535,7 @@ BODIES.pluto.kind; // "dwarf-planet"
|
|
|
535
535
|
|
|
536
536
|
If this package helps a paper, a talk or a class, please cite it as software. GitHub's "Cite this repository" button reads [CITATION.cff](CITATION.cff) and gives BibTeX and APA; in plain text:
|
|
537
537
|
|
|
538
|
-
> Morris, J. (2026). *Wakusei Planets* (version 0.
|
|
538
|
+
> Morris, J. (2026). *Wakusei Planets* (version 0.47.0) [Computer software]. https://github.com/johnmorrisdotca/wakusei-planets
|
|
539
539
|
|
|
540
540
|
Cite the version you used (`npm ls @johnmorrisdotca/wakusei-planets`), and cite the sources of the numbers you use as well: [NOTICE.md](NOTICE.md) names each one, with the paper or the page it was read from (the IAU working group's report for sizes and poles, VSOP87B, ELP2000-82B, L1.2 and TASS1.7 for positions, and NASA's JPL Horizons for the fits and the spacecraft).
|
|
541
541
|
|
package/dist/scene/body.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type { TileLevel } from "./tiles.ts";
|
|
|
10
10
|
import { type NameLabelOptions } from "./name-label.ts";
|
|
11
11
|
export { fallbackLook } from "./fallback.ts";
|
|
12
12
|
/** The parts of three.js the bodies use: a page may hand over a module with only these (see `setThreeLoader`). `CanvasTexture`, `SRGBColorSpace` and `NormalBlending` are needed only for a name written on a body (`body-label`). */
|
|
13
|
-
export type ThreeParts = Pick<typeof THREE, "AdditiveBlending" | "BufferAttribute" | "BufferGeometry" | "ClampToEdgeWrapping" | "DataTexture" | "DoubleSide" | "Group" | "Line" | "LineBasicMaterial" | "LineSegments" | "LinearFilter" | "Mesh" | "NoColorSpace" | "OrthographicCamera" | "PlaneGeometry" | "RepeatWrapping" | "RGBAFormat" | "RingGeometry" | "Scene" | "ShaderMaterial" | "SphereGeometry" | "TextureLoader" | "Vector2" | "Vector3" | "WebGLRenderer"> & Partial<Pick<typeof THREE, "CanvasTexture" | "SRGBColorSpace" | "NormalBlending">>;
|
|
13
|
+
export type ThreeParts = Pick<typeof THREE, "AdditiveBlending" | "BufferAttribute" | "BufferGeometry" | "ClampToEdgeWrapping" | "DataTexture" | "DoubleSide" | "Group" | "Line" | "LineBasicMaterial" | "LineSegments" | "LinearFilter" | "Mesh" | "NoColorSpace" | "OrthographicCamera" | "PlaneGeometry" | "RepeatWrapping" | "RGBAFormat" | "RingGeometry" | "Scene" | "ShaderMaterial" | "SphereGeometry" | "TextureLoader" | "Vector2" | "Vector3" | "WebGLRenderer"> & Partial<Pick<typeof THREE, "CanvasTexture" | "SRGBColorSpace" | "NormalBlending" | "WebGLRenderTarget">>;
|
|
14
14
|
/** One moon in a system view: its place in planet radii (viewer's frame) and the points of its orbit, if they changed. */
|
|
15
15
|
export interface MoonDraw {
|
|
16
16
|
id: BodyId;
|
package/dist/scene/textures.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { type BodyMapSource } from "../door/map.ts";
|
|
|
11
11
|
* console.log(TEXTURE_BASE);
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
|
-
export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@0.
|
|
14
|
+
export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@0.47.0/dist/textures/";
|
|
15
15
|
/**
|
|
16
16
|
* Where the sharpest surface pictures are: the files of this exact version in the repository, on jsDelivr's GitHub address. The npm package holds only the two smaller widths, so a page that
|
|
17
17
|
* never zooms in never fetches them. Set `texture-far-base` on an element to serve them yourself.
|
|
@@ -23,7 +23,7 @@ export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdot
|
|
|
23
23
|
* console.log(TEXTURE_FAR_BASE);
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
|
-
export declare const TEXTURE_FAR_BASE = "https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v0.
|
|
26
|
+
export declare const TEXTURE_FAR_BASE = "https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v0.47.0/textures/";
|
|
27
27
|
/**
|
|
28
28
|
* Where the finer map tiles are by default: the demo site's `tiles/` folder (GitHub Pages sends `access-control-allow-origin: *`). The tiles are made by `scripts/make-body-tiles.py` and are in no package and no repository:
|
|
29
29
|
* a page that serves its own gives the folder in the `tiles` attribute, and `tiles="off"` turns them off. A page that sets `texture-base` (it serves its own pictures) has none unless it says where they are.
|
package/dist/surface/detail.d.ts
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
import { type SiteObject } from "./objects.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Say which objects the made craters and rocks keep away from (the ones `objectsOf` gives for the site), or none. The shader holds the same list.
|
|
4
|
+
*
|
|
5
|
+
* @param objects - The objects.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { madeGround, objectsOf, setKeepOut } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
10
|
+
*
|
|
11
|
+
* const [lander] = objectsOf("apollo-17");
|
|
12
|
+
* setKeepOut(objectsOf("apollo-17"));
|
|
13
|
+
* console.log(madeGround(lander!.east, lander!.north, 0.35).h);
|
|
14
|
+
* setKeepOut([]);
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function setKeepOut(objects: readonly SiteObject[]): void;
|
|
1
18
|
/** The smallest crater's nominal diameter in metres: each octave doubles it, up to `OCTAVES` octaves (0.5, 1, 2, 4, 8, 16). A crater in an octave is between 1 and 2 times its nominal diameter. */
|
|
2
19
|
export declare const D0 = 0.5;
|
|
3
20
|
export declare const OCTAVES = 6;
|
package/dist/surface/detail.js
CHANGED
|
@@ -2,6 +2,27 @@
|
|
|
2
2
|
// age), laid on a seeded grid of cells, so the same place is always the same. It is MADE, not measured, and the page says so. The shader (glsl.ts) holds the same formulas; this is the same
|
|
3
3
|
// maths in JS, for the feet (the eyes follow the made ground too), for the rocks (placed on the ground and denser by fresh rims) and for the tests that hold the two together.
|
|
4
4
|
// Every random number is an integer hash (PCG, 32 bit) cut to 24 bits, so the two agree exactly.
|
|
5
|
+
import { keepAway } from "./objects.js";
|
|
6
|
+
/** The objects the made ground keeps away from: set for the site being stood on (`setKeepOut`), none until then. */
|
|
7
|
+
let keepObjects = [];
|
|
8
|
+
/**
|
|
9
|
+
* Say which objects the made craters and rocks keep away from (the ones `objectsOf` gives for the site), or none. The shader holds the same list.
|
|
10
|
+
*
|
|
11
|
+
* @param objects - The objects.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { madeGround, objectsOf, setKeepOut } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
16
|
+
*
|
|
17
|
+
* const [lander] = objectsOf("apollo-17");
|
|
18
|
+
* setKeepOut(objectsOf("apollo-17"));
|
|
19
|
+
* console.log(madeGround(lander!.east, lander!.north, 0.35).h);
|
|
20
|
+
* setKeepOut([]);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export function setKeepOut(objects) {
|
|
24
|
+
keepObjects = objects;
|
|
25
|
+
}
|
|
5
26
|
/** The smallest crater's nominal diameter in metres: each octave doubles it, up to `OCTAVES` octaves (0.5, 1, 2, 4, 8, 16). A crater in an octave is between 1 and 2 times its nominal diameter. */
|
|
6
27
|
export const D0 = 0.5;
|
|
7
28
|
export const OCTAVES = 6;
|
|
@@ -156,7 +177,8 @@ export function madeGround(x, y, fromDiameter) {
|
|
|
156
177
|
}
|
|
157
178
|
}
|
|
158
179
|
}
|
|
159
|
-
|
|
180
|
+
const keep = keepAway(x, y, keepObjects);
|
|
181
|
+
return { h: h * keep, gx: gx * keep, gy: gy * keep };
|
|
160
182
|
}
|
|
161
183
|
/** The rocks of a class are `ROCK_MIN * 2 ** class` metres: 0.05, 0.1, 0.2, 0.4, 0.8, 1.6; a rock of a class is between 1 and 1.4 times that. */
|
|
162
184
|
export const ROCK_MIN = 0.05;
|
|
@@ -242,6 +264,8 @@ export function rocksAround(cx, cy, radius, pixel) {
|
|
|
242
264
|
const boost = rimBoost(x, y);
|
|
243
265
|
if (unit24(pcg2d(c, d)[0]) > 0.3 * boost)
|
|
244
266
|
continue;
|
|
267
|
+
if (keepAway(x, y, keepObjects) < 0.5)
|
|
268
|
+
continue;
|
|
245
269
|
const [e, f] = pcg2d(c ^ 0x9e3779b9, d + 17);
|
|
246
270
|
out.push({ x, y, size, shape: e % 3, turn: unit24(f) * Math.PI * 2, tone: 0.75 + 0.5 * unit24(e >>> 3), flat: 0.45 + 0.4 * unit24(f >>> 5) });
|
|
247
271
|
}
|
|
@@ -4,6 +4,7 @@ import { setThreeLoader } from "../scene/shared.ts";
|
|
|
4
4
|
import { type HeightLevel, type TerrainManifest } from "./height.ts";
|
|
5
5
|
import { type TerrainProgress } from "./load.ts";
|
|
6
6
|
import { type SurfaceScene } from "./scene.ts";
|
|
7
|
+
import { type SiteObject } from "./objects.ts";
|
|
7
8
|
import { type MoonSky } from "./sky.ts";
|
|
8
9
|
import { type Look } from "./view.ts";
|
|
9
10
|
export { setThreeLoader };
|
|
@@ -74,6 +75,8 @@ export declare class WakuseiSurface extends HTMLElement {
|
|
|
74
75
|
renderer: SharedRenderer<ThreeParts>["stats"] | undefined;
|
|
75
76
|
mesh: SurfaceScene["mesh"] | undefined;
|
|
76
77
|
quality: string;
|
|
78
|
+
scale: number;
|
|
79
|
+
scaled: number;
|
|
77
80
|
drawMs: number | undefined;
|
|
78
81
|
rocks: number;
|
|
79
82
|
};
|
|
@@ -87,4 +90,14 @@ export declare class WakuseiSurface extends HTMLElement {
|
|
|
87
90
|
* @param aside - Metres to the right.
|
|
88
91
|
*/
|
|
89
92
|
walk(ahead: number, aside?: number): void;
|
|
93
|
+
/** The things at the site, at their published places (none where the site has none or `objects="off"`). */
|
|
94
|
+
get objects(): readonly SiteObject[];
|
|
95
|
+
/**
|
|
96
|
+
* 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
|
|
97
|
+
* with its id. Choosing the same one again, or `undefined`, puts the line away.
|
|
98
|
+
*
|
|
99
|
+
* @param id - A thing's id (`lm`, `rover`, `flag`, `alsep`, `sep`), or `undefined` for none.
|
|
100
|
+
* @returns Whether there is such a thing here.
|
|
101
|
+
*/
|
|
102
|
+
choose(id: string | undefined): boolean;
|
|
90
103
|
}
|
package/dist/surface/element.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
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, standingPlace } from "./detail.js";
|
|
4
|
+
import { madeGround, setKeepOut, standingPlace } from "./detail.js";
|
|
5
5
|
import { drop, groundAt } from "./height.js";
|
|
6
6
|
import { loadTerrain } from "./load.js";
|
|
7
7
|
import { createSurfaceItem } from "./scene.js";
|
|
8
|
+
import { objectsOf, traverseOf } from "./objects.js";
|
|
8
9
|
import { moonSky } from "./sky.js";
|
|
9
10
|
import { siteById } from "./site.js";
|
|
10
|
-
import { clampLook, EYE_HEIGHT, stepOver, WALK_SPEED } from "./view.js";
|
|
11
|
+
import { clampLook, EYE_HEIGHT, stepOver, viewProjection, WALK_SPEED } from "./view.js";
|
|
11
12
|
export { setThreeLoader };
|
|
12
13
|
const TEMPLATE = `<style>
|
|
13
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; }
|
|
@@ -17,7 +18,17 @@ const TEMPLATE = `<style>
|
|
|
17
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; }
|
|
18
19
|
#status { position: absolute; inset: 0; display: grid; place-items: center; font: 500 13px system-ui, sans-serif; color: #c8ccd4; pointer-events: none; }
|
|
19
20
|
#status[hidden] { display: none; }
|
|
20
|
-
|
|
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>`;
|
|
21
32
|
const num = (value, fallback) => {
|
|
22
33
|
const n = value === null || value.trim() === "" ? NaN : Number(value);
|
|
23
34
|
return Number.isFinite(n) ? n : fallback;
|
|
@@ -42,7 +53,7 @@ const num = (value, fallback) => {
|
|
|
42
53
|
* ```
|
|
43
54
|
*/
|
|
44
55
|
export class WakuseiSurface extends HTMLElement {
|
|
45
|
-
static observedAttributes = ["quality", "shadows", "detail", "exposure", "site", "time", "heading", "pitch", "fov", "tiles", "lang", "body", "standby"];
|
|
56
|
+
static observedAttributes = ["quality", "shadows", "detail", "exposure", "site", "time", "heading", "pitch", "fov", "tiles", "lang", "body", "standby", "scale", "stick", "objects"];
|
|
46
57
|
#root;
|
|
47
58
|
#stage;
|
|
48
59
|
#noteEl;
|
|
@@ -76,6 +87,19 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
76
87
|
#restQuality = "full";
|
|
77
88
|
#drawMs;
|
|
78
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;
|
|
79
103
|
#pointers = new Map();
|
|
80
104
|
#pinch = 0;
|
|
81
105
|
#draws = 0;
|
|
@@ -126,7 +150,7 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
126
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. */
|
|
127
151
|
get stats() {
|
|
128
152
|
const scene = this.#view?.scene;
|
|
129
|
-
return { state: this.#state, draws: this.#draws, tiles: this.#progress, renderer: this.#renderer?.stats, mesh: scene?.mesh, quality: this.#quality(), drawMs: scene?.drawMs ?? this.#drawMs, rocks: scene?.rocks ?? 0 };
|
|
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 };
|
|
130
154
|
}
|
|
131
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. */
|
|
132
156
|
#quality() {
|
|
@@ -156,6 +180,12 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
156
180
|
this.addEventListener("keydown", this.#onKeyDown);
|
|
157
181
|
this.addEventListener("keyup", this.#onKeyUp);
|
|
158
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();
|
|
159
189
|
if (typeof IntersectionObserver === "function") {
|
|
160
190
|
this.#io = new IntersectionObserver((entries) => {
|
|
161
191
|
const last = entries[entries.length - 1];
|
|
@@ -189,12 +219,16 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
189
219
|
attributeChangedCallback(name) {
|
|
190
220
|
if (!this.isConnected)
|
|
191
221
|
return;
|
|
222
|
+
if (name === "stick") {
|
|
223
|
+
this.#showStick();
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
192
226
|
if (name === "standby") {
|
|
193
227
|
if (!this.hasAttribute("standby"))
|
|
194
228
|
void this.#start();
|
|
195
229
|
return;
|
|
196
230
|
}
|
|
197
|
-
if (name === "site" || name === "body" || name === "tiles") {
|
|
231
|
+
if (name === "site" || name === "body" || name === "tiles" || name === "objects") {
|
|
198
232
|
this.#terrain = undefined;
|
|
199
233
|
this.#loading = undefined;
|
|
200
234
|
this.#pending.clear();
|
|
@@ -263,6 +297,9 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
263
297
|
// on standby the ground is loaded and nothing more: the renderer is another view's until the attribute goes
|
|
264
298
|
if (this.hasAttribute("standby"))
|
|
265
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);
|
|
266
303
|
if (!this.#placed) {
|
|
267
304
|
// a step or two from the landing point, out of any made crater
|
|
268
305
|
const stand = this.getAttribute("detail") === "off" ? { x: 0, y: 0 } : standingPlace(0, 0);
|
|
@@ -275,7 +312,8 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
275
312
|
this.#renderer = taken.renderer;
|
|
276
313
|
this.#release = taken.release;
|
|
277
314
|
}
|
|
278
|
-
|
|
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}` });
|
|
279
317
|
this.#view = this.#renderer.view(this.#stage, item, { still: null });
|
|
280
318
|
}
|
|
281
319
|
const ok = await this.#view.focus();
|
|
@@ -341,8 +379,9 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
341
379
|
if (m === undefined)
|
|
342
380
|
return "";
|
|
343
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.";
|
|
344
383
|
const picture = m.picture === null || m.picture === undefined ? "" : ` ${m.picture.credit}.`;
|
|
345
|
-
return this.#lang() === "ja" ? `高さの実測: ${m.accuracy}。${m.credit}。${made}` : `Heights measured: ${m.accuracy}. ${m.credit}.${picture} ${made}`;
|
|
384
|
+
return this.#lang() === "ja" ? `高さの実測: ${m.accuracy}。${m.credit}。${made}${things}` : `Heights measured: ${m.accuracy}. ${m.credit}.${picture} ${made}${things}`;
|
|
346
385
|
}
|
|
347
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. */
|
|
348
387
|
#groundAt(east, north) {
|
|
@@ -386,13 +425,176 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
386
425
|
else if (was > 250 && this.#restQuality === "medium")
|
|
387
426
|
this.#restQuality = "fast";
|
|
388
427
|
}
|
|
389
|
-
|
|
390
|
-
|
|
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)
|
|
391
446
|
this.#measured += 1;
|
|
392
|
-
|
|
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 });
|
|
393
450
|
this.#view.invalidate();
|
|
394
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;
|
|
395
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
|
+
};
|
|
396
598
|
// --- hands ---------------------------------------------------------------------------------------------------------------------------------------
|
|
397
599
|
#onPointerDown = (event) => {
|
|
398
600
|
this.#pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
|
|
@@ -461,19 +663,20 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
461
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. */
|
|
462
664
|
#walkTick = () => {
|
|
463
665
|
clearTimeout(this.#walkTimer);
|
|
464
|
-
if (this.#keys.size === 0)
|
|
666
|
+
if (this.#keys.size === 0 && this.#push.x === 0 && this.#push.y === 0)
|
|
465
667
|
return;
|
|
466
668
|
const now = performance.now();
|
|
467
669
|
const dt = Math.min(0.1, (now - this.#walkAt) / 1000);
|
|
468
670
|
this.#walkAt = now;
|
|
469
671
|
const k = this.#keys;
|
|
470
|
-
const ahead = (k.has("w") || k.has("ArrowUp") ? 1 : 0) - (k.has("s") || k.has("ArrowDown") ? 1 : 0);
|
|
471
|
-
const aside = (k.has("d") ? 1 : 0) - (k.has("a") ? 1 : 0);
|
|
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;
|
|
472
674
|
const turn = (k.has("e") || k.has("ArrowRight") ? 1 : 0) - (k.has("q") || k.has("ArrowLeft") ? 1 : 0);
|
|
473
675
|
if (turn !== 0)
|
|
474
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));
|
|
475
678
|
if (ahead !== 0 || aside !== 0)
|
|
476
|
-
this.#at = stepOver(this.#at, this.#look.azimuth, ahead * WALK_SPEED * dt, aside * WALK_SPEED * dt);
|
|
679
|
+
this.#at = stepOver(this.#at, this.#look.azimuth, ahead * speed * WALK_SPEED * dt, aside * speed * WALK_SPEED * dt);
|
|
477
680
|
this.#changed();
|
|
478
681
|
this.#walkTimer = setTimeout(this.#walkTick, 33);
|
|
479
682
|
};
|