@johnmorrisdotca/wakusei-planets 0.40.0 → 0.41.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 +10 -0
- package/NOTICE.md +1 -1
- package/README.md +3 -3
- package/dist/element.d.ts +1 -1
- package/dist/element.js +1 -1
- package/dist/scene/body.d.ts +1 -0
- package/dist/scene/body.js +2 -2
- package/dist/scene/glsl.d.ts +2 -2
- package/dist/scene/glsl.js +4 -2
- package/dist/scene/name-label.d.ts +56 -3
- package/dist/scene/name-label.js +72 -7
- package/dist/scene/painter.d.ts +2 -1
- package/dist/scene/painter.js +5 -3
- package/dist/scene/textures.d.ts +2 -2
- package/dist/space/element.d.ts +1 -0
- package/dist/space/element.js +10 -6
- package/dist/space/index.d.ts +1 -1
- package/dist/space/index.js +1 -1
- package/dist/space/labels.d.ts +32 -0
- package/dist/space/labels.js +39 -0
- package/dist/space/scene.d.ts +1 -0
- package/dist/textures/pluto-1024.webp +0 -0
- package/dist/textures/pluto-512.webp +0 -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,16 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.41.0] - 2026-11-13
|
|
6
|
+
|
|
7
|
+
- **The name on a body reads on every body** (MODULES-983). One pale look for every body made the name vanish on Uranus, Venus, Saturn and the ice moons. The letters now take the tone that stands out: `body-label-tone` (and `tone` in `bodyLabel`) is `auto` by default, `light` or `dark`. Auto reads the body's own mean colour (`BODIES[id].colour`): dark letters (the `burned` look) when its relative luminance is above 0.5 (Venus, Saturn, Uranus, the Sun, Io, Europa, Enceladus, Tethys, Dione, Rhea, Triton, Hydra, Eris, Haumea), pale letters (`painted`) below it (Mars, the Moon, the Earth, Mercury, Jupiter, Neptune, Pluto and the rest); only a `painted` look is changed (to dark `burned` on a light body); `etched`, `burned` and `outline` are drawn as the page asked, and a forced `light` or `dark` wins over any look. The same rule on plain values is `nameTone(colour)` and `nameLabelLook(options, colour)` from `/painter`, and `stats.label.look` and `stats.bodyLabels.focus.look` report the look drawn. Picture test in `e2e/body-label.demo.ts` (realistic look, strength 0.5, name facing the reader): the letters' contrast (mean of the top 2 percent of brightness changes) on Uranus is 0.106 with pale letters, which is all origin/main draws, and 0.147 with dark ones; Venus 0.244 to 0.295, Saturn 0.242 to 0.346, Europa 0.237 to 0.297; the pale bodies are unchanged. The Moon (mean colour luminance 0.463) and Jupiter (0.492) stay pale, just under the line. Docs in English and Japanese.
|
|
8
|
+
|
|
9
|
+
- **Small moons with no map are drawn clean: no black rings and specks** (MODULES-994). Nix, Hydra, Miranda, Proteus, Phobos and the other cratered rock the shader makes showed a grid of dark edges over the disc. It was not number precision (the scene is moved to the body looked at, so Nix, 5 billion kilometres from the Sun, is drawn within about eight Earth radii of the origin, and near and far planes and depth hold): each crater's slope came from the difference between neighbouring pixels and tipped the surface by up to fifteen times that, so the wall of every crater a few pixels across turned away from the light and drew a black ring, and a crater of two or three pixels a speck. Now a crater fades out below about 3 to 8 pixels (it was 1 to 3), and the tip of the surface is held to about 50 degrees. Picture test `e2e/space-small-moons.demo.ts`, lit from the camera's side, share of the middle of the disc darker than a fifth of white: Nix 10.3%, Hydra 14.4%, Miranda 16.5%, Proteus 25.2% before, 0.0%, 3.8%, 0.1%, 3.5% after (the bowls that are really dark). A painted body changes only where its relief is steeper than that.
|
|
10
|
+
|
|
11
|
+
- **Pluto's unseen south is a plain tone with a soft edge, not a dark half** (MODULES-993). New Horizons never saw the south in daylight, and the map made it a dark brown that began on one straight line about 7 degrees south of the equator, so a globe showed a hard-edged dark half and the name written on the equator ran into it. The never-imaged part is now one plain tone, the mapped ground's average times 0.85, and the mapped detail fades into it over 8 percent of the map's height along an edge that follows the real coverage (about 30 degrees south), so the equator, and a name on it, are all on mapped ground. The three maps (512, 1024 and 2048) are 12.6, 44.6 and 179.4 KB, up from 10.0, 36.2 and 147.5 KB (+43.9 KB in all). Picture test `e2e/map-gaps.demo.ts` reads the shipped map: the detail lost over 1.5 percent of its height is 0.59 to 0.64 of the most before and 0.16 to 0.19 after; the unseen part's brightness is 0.26 of the mapped ground's before and 0.75 after. The finer map tiles of Pluto are made from this picture and need making again (`pnpm tiles`).
|
|
12
|
+
|
|
13
|
+
- **A floating name is no longer cut off at the view's edge** (MODULES-1144). A name beside a body near the right edge ran past the edge and was cut. It now goes to the dot's left side (the dot follows the text), and if it fits on neither side, or would pass the top or the bottom, it is held inside the edge; a body whose dot is outside the view keeps its name where it falls. `nameSpot(dot, size, frame)` from `/space` is the placing on plain numbers. `e2e/space-names.demo.ts` reads 3 names cut at three view sizes on the old code, none now.
|
|
14
|
+
|
|
5
15
|
## [0.40.0] - 2026-11-13
|
|
6
16
|
|
|
7
17
|
- **Paint an orbiter's path on the Moon or Mars** (MODULES-1168). `space.paint = { id, length, swath }` on `<wakusei-space>` paints that craft's ground track on the body it goes round (`id` such as `lro` or `mro`; `length` `1d` by default, or `1w`, `1m`, in the clock's time; `swath` `track` by default, or `coverage`, the ground where the craft is at least 10° up). `clearPaint()` takes it off, and another craft clears the old trail. Parts older than `length` fade and are dropped. The line is filled between frames, including backwards. One upload a frame while time moves, nothing at rest, and nothing while paint is off, when the picture and its sphere are freed on the graphics card. The craft's place is sampled at most a third of a trip apart, so a fast clock follows the orbit; a clock run backwards lays down the older end; a `coverage` swath over the date line is painted on both edges. The date-line split, the pole split and the swath radius are `@johnmorrisdotca/wakusei-planets/ground-track` (no DOM, no three.js). The space page has Paint, Clear, and 1 day, 1 week, 1 month.
|
package/NOTICE.md
CHANGED
|
@@ -108,7 +108,7 @@ The same rows are `PICTURE_CREDITS` (`picturesCredit` writes the line for the bo
|
|
|
108
108
|
| `saturn-*.webp` | Saturn | [2k_saturn.jpg](https://www.solarsystemscope.com/textures/) and [Nestaeric's Saturn](https://sketchfab.com/3d-models/saturn-c09a1970148c43ad99db134a9d6d00b5) | CC BY 4.0 | Solar System Scope; pole caps by Nestaeric | The bands are Solar System Scope's map. The last 20 degrees at each pole are reprojected from Nestaeric's caps, and the north cap has the hexagon. The band map itself has little east-west detail |
|
|
109
109
|
| `uranus-*.webp` | Uranus | [Uranus](https://sketchfab.com/3d-models/uranus-0009a69dbace44608c0bd09af9ba20db) by NestaEric | CC BY 4.0 | This work is based on "Uranus" (https://sketchfab.com/3d-models/uranus-0009a69dbace44608c0bd09af9ba20db) by NestaEric (https://sketchfab.com/Nestaeric) licensed under CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/) | The band half of the texture, which has a bright spot, resized to 512, 1024 and 2048 |
|
|
110
110
|
| `neptune-*.webp` | Neptune | [2k_neptune.jpg](https://www.solarsystemscope.com/textures/) | CC BY 4.0 | Solar System Scope | Equirectangular map, resized to 512, 1024 and 2048 |
|
|
111
|
-
| `pluto-*.webp` | Pluto | [Pluto color mapmosaic.jpg](https://commons.wikimedia.org/wiki/File:Pluto_color_mapmosaic.jpg) | Public domain | NASA / Johns Hopkins University Applied Physics Laboratory / Southwest Research Institute | New Horizons global colour map, turned so Sputnik Planitia is at 178 degrees east; the south, in the polar night New Horizons never saw, fades into
|
|
111
|
+
| `pluto-*.webp` | Pluto | [Pluto color mapmosaic.jpg](https://commons.wikimedia.org/wiki/File:Pluto_color_mapmosaic.jpg) | Public domain | NASA / Johns Hopkins University Applied Physics Laboratory / Southwest Research Institute | New Horizons global colour map, turned so Sputnik Planitia is at 178 degrees east; the south, in the polar night New Horizons never saw (about 30 degrees south and beyond, ragged), is one plain tone, the mapped ground's own average (rows weighted by the width of their circle of latitude) times 0.85, so it reads as not yet mapped; the mapped detail fades into it over 8 percent of the map's height (`scripts/make-textures.py`, `fill_unseen_plain`) |
|
|
112
112
|
| `sun-*.webp` | Sun | [2k_sun.jpg](https://www.solarsystemscope.com/textures/) | CC BY 4.0 | Solar System Scope | Equirectangular map, resized to 512, 1024 and 2048 |
|
|
113
113
|
| `moon-*.webp` | The Moon | [CGI Moon Kit - Lroc color poles.tif](https://commons.wikimedia.org/wiki/File:CGI_Moon_Kit_-_Lroc_color_poles.tif) | Public domain | NASA's Scientific Visualization Studio (Ernie Wright, Noah Petro); Lunar Reconnaissance Orbiter Camera | LRO WAC colour map from the SVS Moon Kit (4720), kept until it has been compared with Solar System Scope beside a photograph |
|
|
114
114
|
| `io-*.webp` | Io | [Io from Galileo and Voyager missions.jpg](https://commons.wikimedia.org/wiki/File:Io_from_Galileo_and_Voyager_missions.jpg) | Public domain | NASA / JPL (Galileo SSI and Voyager images); the file page names no author | Galileo and Voyager colour map between 57 degrees north and south, turned so Pele is at 105 degrees east; the poles it does not reach fade from the map's edge into its mean colour |
|
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.41.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.41.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
|
|
|
@@ -534,7 +534,7 @@ BODIES.pluto.kind; // "dwarf-planet"
|
|
|
534
534
|
|
|
535
535
|
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:
|
|
536
536
|
|
|
537
|
-
> Morris, J. (2026). *Wakusei Planets* (version 0.
|
|
537
|
+
> Morris, J. (2026). *Wakusei Planets* (version 0.41.0) [Computer software]. https://github.com/johnmorrisdotca/wakusei-planets
|
|
538
538
|
|
|
539
539
|
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).
|
|
540
540
|
|
package/dist/element.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ export type WakuseiState = "line" | "loading" | "still" | "live" | "lost" | "una
|
|
|
38
38
|
* Close up, `tiles` is where the finer map tiles are (a folder address; `off` for none; by default the demo site's, unless `texture-base` names your own pictures): a window of them is laid over the painted map for the part in view and let go when it is not, and the zoom range of a body with tiles grows with them.
|
|
39
39
|
* Whatever moves the view, `setView` sends a `wakusei-view` event with its `yaw`, `tilt`, `roll`, `zoom`, `panX` and `panY`.
|
|
40
40
|
* `places` marks the places on the body in the shaded looks, by layer (`landing`, `crash`, `planned`, `feature`; the lists come from `setPlacesLoader`), with `wakusei-place` on a click and `goToPlace` to turn one to the middle: see the guide "Places on the Moon, Mars and 31 more bodies".
|
|
41
|
-
* `body-label` writes the body's name on its globe in the shaded looks (`painted`, `etched`, `outline` or `burned`; absent for none), with `body-label-strength`, `-repeat`, `-latitude`, `-facing`, `-font
|
|
41
|
+
* `body-label` writes the body's name on its globe in the shaded looks (`painted`, `etched`, `outline` or `burned`; absent for none), with `body-label-strength`, `-repeat`, `-latitude`, `-facing`, `-font`, `-fallback-font` and `-tone` (`auto`, `light` or `dark` letters: auto takes dark ones for a `painted` look on a light body) beside it, and the `bodyLabel` property takes the same as an object: see the guide "A name on the body".
|
|
42
42
|
* A dated picture (a `time`, or `moons`) has a clock: `rate` is the simulated seconds for each real second, and `rate="0"` holds it, drawing nothing. While it runs (`rate` not 0), `wakusei-timechange` carries
|
|
43
43
|
* `detail: { time, running: true }` (`time` is the moment shown in milliseconds since 1970; four times a second, once a second at real time; only while the tab is shown, whether or not the picture is on screen), and once with
|
|
44
44
|
* `running: false` when the clock is held: a page writes the date into its date box from it. The `time` property reads the moment shown, and `undefined` for a portrait with no date.
|
package/dist/element.js
CHANGED
|
@@ -84,7 +84,7 @@ const TEMPLATE = `<style>
|
|
|
84
84
|
* Close up, `tiles` is where the finer map tiles are (a folder address; `off` for none; by default the demo site's, unless `texture-base` names your own pictures): a window of them is laid over the painted map for the part in view and let go when it is not, and the zoom range of a body with tiles grows with them.
|
|
85
85
|
* Whatever moves the view, `setView` sends a `wakusei-view` event with its `yaw`, `tilt`, `roll`, `zoom`, `panX` and `panY`.
|
|
86
86
|
* `places` marks the places on the body in the shaded looks, by layer (`landing`, `crash`, `planned`, `feature`; the lists come from `setPlacesLoader`), with `wakusei-place` on a click and `goToPlace` to turn one to the middle: see the guide "Places on the Moon, Mars and 31 more bodies".
|
|
87
|
-
* `body-label` writes the body's name on its globe in the shaded looks (`painted`, `etched`, `outline` or `burned`; absent for none), with `body-label-strength`, `-repeat`, `-latitude`, `-facing`, `-font
|
|
87
|
+
* `body-label` writes the body's name on its globe in the shaded looks (`painted`, `etched`, `outline` or `burned`; absent for none), with `body-label-strength`, `-repeat`, `-latitude`, `-facing`, `-font`, `-fallback-font` and `-tone` (`auto`, `light` or `dark` letters: auto takes dark ones for a `painted` look on a light body) beside it, and the `bodyLabel` property takes the same as an object: see the guide "A name on the body".
|
|
88
88
|
* A dated picture (a `time`, or `moons`) has a clock: `rate` is the simulated seconds for each real second, and `rate="0"` holds it, drawing nothing. While it runs (`rate` not 0), `wakusei-timechange` carries
|
|
89
89
|
* `detail: { time, running: true }` (`time` is the moment shown in milliseconds since 1970; four times a second, once a second at real time; only while the tab is shown, whether or not the picture is on screen), and once with
|
|
90
90
|
* `running: false` when the clock is held: a page writes the date into its date box from it. The `time` property reads the moment shown, and `undefined` for a portrait with no date.
|
package/dist/scene/body.d.ts
CHANGED
package/dist/scene/body.js
CHANGED
|
@@ -371,7 +371,7 @@ export function createBodyItem(options) {
|
|
|
371
371
|
return;
|
|
372
372
|
}
|
|
373
373
|
if (label === undefined) {
|
|
374
|
-
label = createNameLabel(T, state.label.text, state.label, look.emissive === true, () => options.redraw());
|
|
374
|
+
label = createNameLabel(T, state.label.text, state.label, look.emissive === true, () => options.redraw(), facts.colour);
|
|
375
375
|
mesh.add(label.object);
|
|
376
376
|
}
|
|
377
377
|
else {
|
|
@@ -453,7 +453,7 @@ export function createBodyItem(options) {
|
|
|
453
453
|
},
|
|
454
454
|
get label() {
|
|
455
455
|
const inner = label?.object.children[0];
|
|
456
|
-
return label === undefined || latest.label === undefined || latest.label === null ? null : { shown: label.ready && inner !== undefined && inner.visible, text: latest.label.text, turn: inner?.rotation.y ?? 0 };
|
|
456
|
+
return label === undefined || latest.label === undefined || latest.label === null ? null : { shown: label.ready && inner !== undefined && inner.visible, text: latest.label.text, turn: inner?.rotation.y ?? 0, look: label.look };
|
|
457
457
|
},
|
|
458
458
|
resize(w, h) {
|
|
459
459
|
viewWidth = w;
|
package/dist/scene/glsl.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const VERTEX = "\nvarying vec3 vObj;\nvarying vec3 vN;\nvarying vec3 vW;\nvoid main() {\n vObj = vec3(position.z, position.x, position.y);\n vN = normalize(normalMatrix * normal);\n vec4 w = modelMatrix * vec4(position, 1.0);\n vW = w.xyz;\n gl_Position = projectionMatrix * viewMatrix * w;\n}";
|
|
2
2
|
/** Noise, craters and the band palette, for the surface code of a body to call. */
|
|
3
|
-
export declare const PRELUDE = "\nfloat hash13(vec3 p) { p = fract(p * 0.1031); p += dot(p, p.zyx + 31.32); return fract((p.x + p.y) * p.z); }\nvec3 hash33(vec3 p) { p = fract(p * vec3(0.1031, 0.1030, 0.0973)); p += dot(p, p.yxz + 33.33); return fract((p.xxy + p.yxx) * p.zyx); }\nfloat vnoise(vec3 p) {\n vec3 i = floor(p); vec3 f = fract(p); f = f * f * (3.0 - 2.0 * f);\n return mix(mix(mix(hash13(i), hash13(i + vec3(1,0,0)), f.x), mix(hash13(i + vec3(0,1,0)), hash13(i + vec3(1,1,0)), f.x), f.y),\n mix(mix(hash13(i + vec3(0,0,1)), hash13(i + vec3(1,0,1)), f.x), mix(hash13(i + vec3(0,1,1)), hash13(i + vec3(1,1,1)), f.x), f.y), f.z);\n}\n// Noise that knows how big a pixel is: an octave finer than the pixel can show is replaced by its average (0.5) instead of being sampled, so a small body is smooth and not a spray of pixel-sized specks.\nfloat fbm(vec3 p) { float fw = length(fwidth(p)); float a = 0.5; float s = 0.0; for (int i = 0; i < 5; i++) { s += a * mix(0.5, vnoise(p), 1.0 - smoothstep(0.3, 0.7, fw)); p = p * 2.03 + vec3(1.7, 9.2, 3.1); fw *= 2.03; a *= 0.5; } return s; }\n// Craters: a bowl and a raised rim in each cell that has one. Returns a height, negative in a bowl. A crater smaller than about two pixels fades out (it would only be noise).\nfloat craters(vec3 p, float freq, float amp, float seed) {\n vec3 q = p * freq + seed; vec3 ip = floor(q); float h = 0.0;\n float fw = length(fwidth(q));\n for (int x = -1; x <= 1; x++) for (int y = -1; y <= 1; y++) for (int z = -1; z <= 1; z++) {\n vec3 c = ip + vec3(float(x), float(y), float(z));\n float on = step(0.52, hash13(c + 3.7));\n vec3 ctr = c + hash33(c);\n float rad = mix(0.12, 0.36, hash13(c + 17.3));\n float d = length(q - ctr) / rad;\n float bowl = d < 1.0 ? (d * d - 1.0) : 0.0;\n float rim = d >= 1.0 ? exp(-pow((d - 1.0) * 5.0, 2.0)) * 0.3 * smoothstep(1.0, 1.08, d) : 0.0;\n h += on * amp * rad * (bowl + rim) * (1.0 - smoothstep(0.
|
|
3
|
+
export declare const PRELUDE = "\nfloat hash13(vec3 p) { p = fract(p * 0.1031); p += dot(p, p.zyx + 31.32); return fract((p.x + p.y) * p.z); }\nvec3 hash33(vec3 p) { p = fract(p * vec3(0.1031, 0.1030, 0.0973)); p += dot(p, p.yxz + 33.33); return fract((p.xxy + p.yxx) * p.zyx); }\nfloat vnoise(vec3 p) {\n vec3 i = floor(p); vec3 f = fract(p); f = f * f * (3.0 - 2.0 * f);\n return mix(mix(mix(hash13(i), hash13(i + vec3(1,0,0)), f.x), mix(hash13(i + vec3(0,1,0)), hash13(i + vec3(1,1,0)), f.x), f.y),\n mix(mix(hash13(i + vec3(0,0,1)), hash13(i + vec3(1,0,1)), f.x), mix(hash13(i + vec3(0,1,1)), hash13(i + vec3(1,1,1)), f.x), f.y), f.z);\n}\n// Noise that knows how big a pixel is: an octave finer than the pixel can show is replaced by its average (0.5) instead of being sampled, so a small body is smooth and not a spray of pixel-sized specks.\nfloat fbm(vec3 p) { float fw = length(fwidth(p)); float a = 0.5; float s = 0.0; for (int i = 0; i < 5; i++) { s += a * mix(0.5, vnoise(p), 1.0 - smoothstep(0.3, 0.7, fw)); p = p * 2.03 + vec3(1.7, 9.2, 3.1); fw *= 2.03; a *= 0.5; } return s; }\n// Craters: a bowl and a raised rim in each cell that has one. Returns a height, negative in a bowl. A crater smaller than about two pixels fades out (it would only be noise).\nfloat craters(vec3 p, float freq, float amp, float seed) {\n vec3 q = p * freq + seed; vec3 ip = floor(q); float h = 0.0;\n float fw = length(fwidth(q));\n for (int x = -1; x <= 1; x++) for (int y = -1; y <= 1; y++) for (int z = -1; z <= 1; z++) {\n vec3 c = ip + vec3(float(x), float(y), float(z));\n float on = step(0.52, hash13(c + 3.7));\n vec3 ctr = c + hash33(c);\n float rad = mix(0.12, 0.36, hash13(c + 17.3));\n float d = length(q - ctr) / rad;\n float bowl = d < 1.0 ? (d * d - 1.0) : 0.0;\n float rim = d >= 1.0 ? exp(-pow((d - 1.0) * 5.0, 2.0)) * 0.3 * smoothstep(1.0, 1.08, d) : 0.0;\n h += on * amp * rad * (bowl + rim) * (1.0 - smoothstep(0.14, 0.34, fw / rad));\n }\n return h;\n}\nfloat lon(vec3 p) { return atan(p.y, p.x); }\nfloat lat(vec3 p) { return asin(clamp(p.z, -1.0, 1.0)); }\nfloat wrapPi(float a) { return a - 6.2831853 * floor((a + 3.1415927) / 6.2831853); }\nvec3 dirOf(float lonDeg, float latDeg) { float lo = radians(lonDeg); float la = radians(latDeg); return vec3(cos(la) * cos(lo), cos(la) * sin(lo), sin(la)); }\n// One big round bowl with a rim, by longitude, latitude and angular radius in degrees. Negative inside.\nfloat bowl(vec3 p, float lonDeg, float latDeg, float radDeg, float depth) {\n float d = acos(clamp(dot(p, dirOf(lonDeg, latDeg)), -1.0, 1.0)) / radians(radDeg);\n return d < 1.0 ? depth * (d * d - 1.0) : depth * exp(-pow((d - 1.0) * 5.0, 2.0)) * 0.3 * smoothstep(1.0, 1.08, d);\n}\n// A soft oval on the body, 1 inside and 0 outside, by longitude and latitude in degrees.\nfloat oval(vec3 p, float lon0, float lat0, float rx, float ry, float soft) {\n float dx = wrapPi(lon(p) - radians(lon0)) * cos(radians(lat0)) / radians(rx);\n float dy = (lat(p) - radians(lat0)) / radians(ry);\n return 1.0 - smoothstep(1.0 - soft, 1.0, sqrt(dx * dx + dy * dy));\n}";
|
|
4
4
|
/**
|
|
5
5
|
* The generic fine detail of a close view, for the fragment shader of a body (`bodyFragment` with `detail`). It is not a measured feature of the body: it is noise, put on so that a body never goes smooth when the
|
|
6
6
|
* zoom takes it past the sharpness of its map. `gTexel` is the angle one texel of the picture being read covers (radians); where a pixel is smaller than a texel (the map is enlarged more than about one and a
|
|
@@ -45,4 +45,4 @@ export declare const GLOW_FRAGMENT = "\nprecision highp float;\nvarying vec2 vP;
|
|
|
45
45
|
*/
|
|
46
46
|
export declare const STAR_GLOW_FRAGMENT = "\nprecision highp float;\nvarying vec2 vP;\nuniform vec3 uColour;\nuniform float uStrength;\nuniform float uSpread;\nuniform float uRim;\nuniform float uProm;\nuniform float uSeed;\nuniform float uTime;\nfloat h1(float n) { return fract(sin(n * 127.1 + uSeed * 91.7) * 43758.5453); }\nfloat n1(float x) { float i = floor(x); float f = fract(x); f = f * f * (3.0 - 2.0 * f); return mix(h1(i), h1(i + 1.0), f); }\nvoid main() {\n float r = length(vP);\n if (r < 0.98) discard;\n float x = r - 1.0;\n float fade = smoothstep(3.0, 1.6, r);\n float halo = exp(-x * uSpread) * uStrength;\n float tight = exp(-x * 14.0) * uStrength * 0.9;\n float rim = exp(-x * 60.0) * uRim;\n vec3 col = uColour * (halo + tight) + mix(uColour, vec3(1.0), 0.4) * rim;\n float a = halo + tight + rim;\n if (uProm > 0.0) {\n float ang = atan(vP.y, vP.x);\n float site = smoothstep(0.55, 0.85, n1(ang * 2.6 + uSeed * 20.0));\n float drift = 0.75 + 0.25 * sin(uTime * 0.5 + ang * 4.0);\n float height = site * uProm * 0.3 * drift;\n float strands = 0.65 + 0.35 * n1(ang * 70.0 + uTime * 0.3);\n float pr = step(0.0, x) * pow(smoothstep(height, 0.0, x), 1.6) * site * strands * 0.9;\n vec3 pc = mix(vec3(1.0, 0.42, 0.26), uColour, 0.2);\n float a0 = uSeed * 6.2831853 + uTime * 0.02;\n float da = atan(sin(ang - a0), cos(ang - a0));\n float burst = pow(max(0.0, sin(uTime * 0.9 + uSeed * 40.0)), 24.0) * uProm;\n float fl = exp(-da * da * 14.0) * exp(-x * 6.0) * burst * 1.6;\n col += pc * pr + vec3(1.0, 0.92, 0.75) * fl;\n a += pr + fl;\n }\n // additive blending multiplies by alpha, so the root of the light is the alpha and the colour carries the rest: the sum arrives as written\n float s = sqrt(min(a * fade, 1.0));\n gl_FragColor = vec4(col / max(a, 1e-4) * s, s);\n}";
|
|
47
47
|
/** A cheap lit ball for a moon seen small beside its planet. */
|
|
48
|
-
export declare const BALL_FRAGMENT = "\nprecision highp float;\nuniform vec3 uLight;\nuniform vec3 uColour;\nvarying vec3 vObj;\nvarying vec3 vN;\nvarying vec3 vW;\n\nfloat hash13(vec3 p) { p = fract(p * 0.1031); p += dot(p, p.zyx + 31.32); return fract((p.x + p.y) * p.z); }\nvec3 hash33(vec3 p) { p = fract(p * vec3(0.1031, 0.1030, 0.0973)); p += dot(p, p.yxz + 33.33); return fract((p.xxy + p.yxx) * p.zyx); }\nfloat vnoise(vec3 p) {\n vec3 i = floor(p); vec3 f = fract(p); f = f * f * (3.0 - 2.0 * f);\n return mix(mix(mix(hash13(i), hash13(i + vec3(1,0,0)), f.x), mix(hash13(i + vec3(0,1,0)), hash13(i + vec3(1,1,0)), f.x), f.y),\n mix(mix(hash13(i + vec3(0,0,1)), hash13(i + vec3(1,0,1)), f.x), mix(hash13(i + vec3(0,1,1)), hash13(i + vec3(1,1,1)), f.x), f.y), f.z);\n}\n// Noise that knows how big a pixel is: an octave finer than the pixel can show is replaced by its average (0.5) instead of being sampled, so a small body is smooth and not a spray of pixel-sized specks.\nfloat fbm(vec3 p) { float fw = length(fwidth(p)); float a = 0.5; float s = 0.0; for (int i = 0; i < 5; i++) { s += a * mix(0.5, vnoise(p), 1.0 - smoothstep(0.3, 0.7, fw)); p = p * 2.03 + vec3(1.7, 9.2, 3.1); fw *= 2.03; a *= 0.5; } return s; }\n// Craters: a bowl and a raised rim in each cell that has one. Returns a height, negative in a bowl. A crater smaller than about two pixels fades out (it would only be noise).\nfloat craters(vec3 p, float freq, float amp, float seed) {\n vec3 q = p * freq + seed; vec3 ip = floor(q); float h = 0.0;\n float fw = length(fwidth(q));\n for (int x = -1; x <= 1; x++) for (int y = -1; y <= 1; y++) for (int z = -1; z <= 1; z++) {\n vec3 c = ip + vec3(float(x), float(y), float(z));\n float on = step(0.52, hash13(c + 3.7));\n vec3 ctr = c + hash33(c);\n float rad = mix(0.12, 0.36, hash13(c + 17.3));\n float d = length(q - ctr) / rad;\n float bowl = d < 1.0 ? (d * d - 1.0) : 0.0;\n float rim = d >= 1.0 ? exp(-pow((d - 1.0) * 5.0, 2.0)) * 0.3 * smoothstep(1.0, 1.08, d) : 0.0;\n h += on * amp * rad * (bowl + rim) * (1.0 - smoothstep(0.
|
|
48
|
+
export declare const BALL_FRAGMENT = "\nprecision highp float;\nuniform vec3 uLight;\nuniform vec3 uColour;\nvarying vec3 vObj;\nvarying vec3 vN;\nvarying vec3 vW;\n\nfloat hash13(vec3 p) { p = fract(p * 0.1031); p += dot(p, p.zyx + 31.32); return fract((p.x + p.y) * p.z); }\nvec3 hash33(vec3 p) { p = fract(p * vec3(0.1031, 0.1030, 0.0973)); p += dot(p, p.yxz + 33.33); return fract((p.xxy + p.yxx) * p.zyx); }\nfloat vnoise(vec3 p) {\n vec3 i = floor(p); vec3 f = fract(p); f = f * f * (3.0 - 2.0 * f);\n return mix(mix(mix(hash13(i), hash13(i + vec3(1,0,0)), f.x), mix(hash13(i + vec3(0,1,0)), hash13(i + vec3(1,1,0)), f.x), f.y),\n mix(mix(hash13(i + vec3(0,0,1)), hash13(i + vec3(1,0,1)), f.x), mix(hash13(i + vec3(0,1,1)), hash13(i + vec3(1,1,1)), f.x), f.y), f.z);\n}\n// Noise that knows how big a pixel is: an octave finer than the pixel can show is replaced by its average (0.5) instead of being sampled, so a small body is smooth and not a spray of pixel-sized specks.\nfloat fbm(vec3 p) { float fw = length(fwidth(p)); float a = 0.5; float s = 0.0; for (int i = 0; i < 5; i++) { s += a * mix(0.5, vnoise(p), 1.0 - smoothstep(0.3, 0.7, fw)); p = p * 2.03 + vec3(1.7, 9.2, 3.1); fw *= 2.03; a *= 0.5; } return s; }\n// Craters: a bowl and a raised rim in each cell that has one. Returns a height, negative in a bowl. A crater smaller than about two pixels fades out (it would only be noise).\nfloat craters(vec3 p, float freq, float amp, float seed) {\n vec3 q = p * freq + seed; vec3 ip = floor(q); float h = 0.0;\n float fw = length(fwidth(q));\n for (int x = -1; x <= 1; x++) for (int y = -1; y <= 1; y++) for (int z = -1; z <= 1; z++) {\n vec3 c = ip + vec3(float(x), float(y), float(z));\n float on = step(0.52, hash13(c + 3.7));\n vec3 ctr = c + hash33(c);\n float rad = mix(0.12, 0.36, hash13(c + 17.3));\n float d = length(q - ctr) / rad;\n float bowl = d < 1.0 ? (d * d - 1.0) : 0.0;\n float rim = d >= 1.0 ? exp(-pow((d - 1.0) * 5.0, 2.0)) * 0.3 * smoothstep(1.0, 1.08, d) : 0.0;\n h += on * amp * rad * (bowl + rim) * (1.0 - smoothstep(0.14, 0.34, fw / rad));\n }\n return h;\n}\nfloat lon(vec3 p) { return atan(p.y, p.x); }\nfloat lat(vec3 p) { return asin(clamp(p.z, -1.0, 1.0)); }\nfloat wrapPi(float a) { return a - 6.2831853 * floor((a + 3.1415927) / 6.2831853); }\nvec3 dirOf(float lonDeg, float latDeg) { float lo = radians(lonDeg); float la = radians(latDeg); return vec3(cos(la) * cos(lo), cos(la) * sin(lo), sin(la)); }\n// One big round bowl with a rim, by longitude, latitude and angular radius in degrees. Negative inside.\nfloat bowl(vec3 p, float lonDeg, float latDeg, float radDeg, float depth) {\n float d = acos(clamp(dot(p, dirOf(lonDeg, latDeg)), -1.0, 1.0)) / radians(radDeg);\n return d < 1.0 ? depth * (d * d - 1.0) : depth * exp(-pow((d - 1.0) * 5.0, 2.0)) * 0.3 * smoothstep(1.0, 1.08, d);\n}\n// A soft oval on the body, 1 inside and 0 outside, by longitude and latitude in degrees.\nfloat oval(vec3 p, float lon0, float lat0, float rx, float ry, float soft) {\n float dx = wrapPi(lon(p) - radians(lon0)) * cos(radians(lat0)) / radians(rx);\n float dy = (lat(p) - radians(lat0)) / radians(ry);\n return 1.0 - smoothstep(1.0 - soft, 1.0, sqrt(dx * dx + dy * dy));\n}\nvoid main() {\n vec3 n = normalize(vN);\n float shade = 0.82 + 0.3 * (fbm(normalize(vObj) * 4.0) - 0.5);\n float diff = max(dot(n, uLight), 0.0);\n vec3 c = pow(uColour * shade, vec3(2.2)) * (0.04 + 1.1 * diff);\n gl_FragColor = vec4(pow(c, vec3(1.0 / 2.2)), 1.0);\n}";
|
package/dist/scene/glsl.js
CHANGED
|
@@ -33,7 +33,7 @@ float craters(vec3 p, float freq, float amp, float seed) {
|
|
|
33
33
|
float d = length(q - ctr) / rad;
|
|
34
34
|
float bowl = d < 1.0 ? (d * d - 1.0) : 0.0;
|
|
35
35
|
float rim = d >= 1.0 ? exp(-pow((d - 1.0) * 5.0, 2.0)) * 0.3 * smoothstep(1.0, 1.08, d) : 0.0;
|
|
36
|
-
h += on * amp * rad * (bowl + rim) * (1.0 - smoothstep(0.
|
|
36
|
+
h += on * amp * rad * (bowl + rim) * (1.0 - smoothstep(0.14, 0.34, fw / rad));
|
|
37
37
|
}
|
|
38
38
|
return h;
|
|
39
39
|
}
|
|
@@ -130,7 +130,9 @@ ${detail ? " s.rgb *= microDetail(p);\n" : ""}
|
|
|
130
130
|
float det = dot(dpx, cross(dpy, n));
|
|
131
131
|
// relief is worked out from differences between neighbouring pixels, which cannot show a bump only a few pixels wide: on a small disc it fades out and the colour alone carries the craters
|
|
132
132
|
float reliefLod = 1.0 - smoothstep(0.008, 0.024, length(fwidth(p)));
|
|
133
|
-
|
|
133
|
+
// a wall steeper than about 50 degrees is not tipped further: the tilt of two pixels' difference on a steep bowl would turn the surface away from the light and draw a hard black ring
|
|
134
|
+
vec3 tilt = sign(det) * uRelief * reliefLod * grad * 22.0;
|
|
135
|
+
vec3 nb = normalize(abs(det) * n - tilt * min(1.0, 1.2 * abs(det) / max(length(tilt), 1e-20)));
|
|
134
136
|
float d = dot(nb, uLight);
|
|
135
137
|
float diff = clamp((d + uWrap) / (1.0 + uWrap), 0.0, 1.0) * smoothstep(-0.02 - uWrap * 0.6, 0.1 + uWrap * 0.8, dg);
|
|
136
138
|
if (uRingOn > 0.5) {
|
|
@@ -33,11 +33,28 @@ export interface NameLabelOptions {
|
|
|
33
33
|
size?: BodyLabelSize;
|
|
34
34
|
/** No label while the body is drawn smaller than this many CSS pixels in radius. Default 24. */
|
|
35
35
|
minRadiusPx?: number;
|
|
36
|
+
/**
|
|
37
|
+
* The tone of the letters, so the name reads on every body: `auto` (the default) takes dark letters on a light body and pale letters on a dark one, from the body's own colour (`nameTone`); `light` and
|
|
38
|
+
* `dark` force one. Dark letters are the `burned` look, pale ones the `painted` look. `auto` changes only a `painted` look; the look a page names (`etched`, `outline`, `burned`) is drawn as asked.
|
|
39
|
+
*/
|
|
40
|
+
tone?: NameLabelTone;
|
|
36
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* The tone of a name's letters: `auto` (from the body's colour), `light` or `dark`.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import type { NameLabelTone } from "@johnmorrisdotca/wakusei-planets/painter";
|
|
48
|
+
*
|
|
49
|
+
* const tone: NameLabelTone = "dark";
|
|
50
|
+
* console.log(tone);
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export type NameLabelTone = "auto" | "light" | "dark";
|
|
37
54
|
/** The family's standard attribute names, as `readNameLabel` reads them. */
|
|
38
|
-
export declare const NAME_LABEL_ATTRIBUTES: readonly ["body-label", "body-label-strength", "body-label-repeat", "body-label-latitude", "body-label-facing", "body-label-font", "body-label-fallback-font"];
|
|
55
|
+
export declare const NAME_LABEL_ATTRIBUTES: readonly ["body-label", "body-label-strength", "body-label-repeat", "body-label-latitude", "body-label-facing", "body-label-font", "body-label-fallback-font", "body-label-tone"];
|
|
39
56
|
/**
|
|
40
|
-
* The label the family's attributes ask for (`body-label="painted"` and the
|
|
57
|
+
* The label the family's attributes ask for (`body-label="painted"` and the seven beside it), or `null` when `body-label` is absent or not a look.
|
|
41
58
|
*
|
|
42
59
|
* @param el - Anything with `getAttribute` and `hasAttribute`: the element.
|
|
43
60
|
* @returns The options, or `null` for no label.
|
|
@@ -55,6 +72,39 @@ export declare function readNameLabel(el: {
|
|
|
55
72
|
getAttribute(name: string): string | null;
|
|
56
73
|
hasAttribute(name: string): boolean;
|
|
57
74
|
}): NameLabelOptions | null;
|
|
75
|
+
/**
|
|
76
|
+
* The tone of letters that read on a body of this colour: `dark` when the body is light, `light` when it is dark. The two letters are the family's pale `#f4efe2` and dark `#1c140c`; laid over a surface at any
|
|
77
|
+
* strength, the pale ones stand out more on a surface darker than about half way between them and the dark ones on a lighter one, which is a relative luminance of 0.5 in the body's mean colour (`BODIES[id].colour`):
|
|
78
|
+
* Venus, Saturn, Uranus, the Sun, Io and the ice moons get dark letters, and Mars, the Moon, the Earth and Neptune pale ones.
|
|
79
|
+
*
|
|
80
|
+
* @param colour - The body's mean colour, `#rrggbb`.
|
|
81
|
+
* @returns `dark` or `light`.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* import { BODIES } from "@johnmorrisdotca/wakusei-planets";
|
|
86
|
+
* import { nameTone } from "@johnmorrisdotca/wakusei-planets/painter";
|
|
87
|
+
*
|
|
88
|
+
* console.log(nameTone(BODIES.uranus.colour), nameTone(BODIES.mars.colour));
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare function nameTone(colour: string): "light" | "dark";
|
|
92
|
+
/**
|
|
93
|
+
* The look a name is drawn in once its tone is settled. A tone the page forces (`light` or `dark`) wins: `dark` makes `painted` and `etched` the dark `burned` look, and `light` makes `burned` the pale `painted` look. With `auto` (or no
|
|
94
|
+
* tone) only a `painted` look is changed, to `burned` on a light body (`nameTone`); `etched`, `burned` and `outline` are drawn as the page asked. `outline` has one tone and is never changed.
|
|
95
|
+
*
|
|
96
|
+
* @param options - The label's look and tone.
|
|
97
|
+
* @param colour - The body's mean colour, `#rrggbb`; left out, `auto` leaves the look as it is.
|
|
98
|
+
* @returns The look to draw.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* import { nameLabelLook } from "@johnmorrisdotca/wakusei-planets/painter";
|
|
103
|
+
*
|
|
104
|
+
* console.log(nameLabelLook({ look: "painted" }, "#a9e0e5"), nameLabelLook({ look: "painted", tone: "light" }, "#a9e0e5"), nameLabelLook({ look: "etched" }, "#a9e0e5"));
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export declare function nameLabelLook(options: Pick<NameLabelOptions, "look" | "tone">, colour?: string): BodyLabelLook;
|
|
58
108
|
/**
|
|
59
109
|
* The text written for a body: its English name in capitals (the family's look), or its Japanese name as it is.
|
|
60
110
|
*
|
|
@@ -82,6 +132,8 @@ export type LabelParts = Pick<typeof THREE, "CanvasTexture" | "SRGBColorSpace" |
|
|
|
82
132
|
export interface NameLabel {
|
|
83
133
|
/** Add it to the body's turning mesh (a radius-1 sphere whose +z is longitude 0). */
|
|
84
134
|
readonly object: THREE.Group;
|
|
135
|
+
/** The look the name is drawn in now, its tone settled: `painted` (pale letters), `etched`, `outline` or `burned` (dark ones). */
|
|
136
|
+
readonly look: BodyLabelLook;
|
|
85
137
|
/** True once the name is drawn in its font: the host draws its view again when `onReady` is called. */
|
|
86
138
|
readonly ready: boolean;
|
|
87
139
|
/** Before each draw: the camera (for `facing`; left out, the name faces +z), the body's radius on the screen in CSS pixels, and the direction to the light in the scene's axes. Returns true when it hid, showed or turned the name. */
|
|
@@ -112,5 +164,6 @@ export declare function setBodyLabelFontUrl(url: string | URL): void;
|
|
|
112
164
|
* @param options - The look and the rest.
|
|
113
165
|
* @param emissive - The body glows (the Sun): the name is lit fully, from no direction.
|
|
114
166
|
* @param onReady - Called when the name is drawn, and again when a new font is in.
|
|
167
|
+
* @param colour - The body's mean colour, `#rrggbb`: with `tone: "auto"` the letters are dark on a light body and pale on a dark one. Left out, they are the look's own.
|
|
115
168
|
*/
|
|
116
|
-
export declare function createNameLabel(T: ThreeParts, text: string, options: NameLabelOptions, emissive: boolean, onReady: () => void): NameLabel;
|
|
169
|
+
export declare function createNameLabel(T: ThreeParts, text: string, options: NameLabelOptions, emissive: boolean, onReady: () => void, colour?: string): NameLabel;
|
package/dist/scene/name-label.js
CHANGED
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
// bodies have no three.js lights (each is lit by the `uLight` of its own material). Nothing here draws: the host calls `update` before each draw and `set` when a setting changed.
|
|
4
4
|
import { BODY_LABEL_FONT, createBodyLabel, loadBodyLabelFont } from "@johnmorrisdotca/kazoku-ui/body-label";
|
|
5
5
|
/** The family's standard attribute names, as `readNameLabel` reads them. */
|
|
6
|
-
export const NAME_LABEL_ATTRIBUTES = ["body-label", "body-label-strength", "body-label-repeat", "body-label-latitude", "body-label-facing", "body-label-font", "body-label-fallback-font"];
|
|
6
|
+
export const NAME_LABEL_ATTRIBUTES = ["body-label", "body-label-strength", "body-label-repeat", "body-label-latitude", "body-label-facing", "body-label-font", "body-label-fallback-font", "body-label-tone"];
|
|
7
7
|
const LOOKS = ["painted", "etched", "outline", "burned"];
|
|
8
8
|
const REPEATS = ["once", "both", "around"];
|
|
9
|
+
const TONES = ["auto", "light", "dark"];
|
|
9
10
|
/**
|
|
10
|
-
* The label the family's attributes ask for (`body-label="painted"` and the
|
|
11
|
+
* The label the family's attributes ask for (`body-label="painted"` and the seven beside it), or `null` when `body-label` is absent or not a look.
|
|
11
12
|
*
|
|
12
13
|
* @param el - Anything with `getAttribute` and `hasAttribute`: the element.
|
|
13
14
|
* @returns The options, or `null` for no label.
|
|
@@ -43,8 +44,62 @@ export function readNameLabel(el) {
|
|
|
43
44
|
const fallback = el.getAttribute("body-label-fallback-font");
|
|
44
45
|
if (fallback !== null && fallback.trim() !== "")
|
|
45
46
|
out.fallbackFont = fallback.trim();
|
|
47
|
+
const tone = el.getAttribute("body-label-tone");
|
|
48
|
+
if (tone !== null && TONES.includes(tone))
|
|
49
|
+
out.tone = tone;
|
|
46
50
|
return out;
|
|
47
51
|
}
|
|
52
|
+
/** The relative luminance (0 to 1, as WCAG defines it) of a `#rrggbb` colour. */
|
|
53
|
+
const luminanceOf = (hex) => {
|
|
54
|
+
const [r, g, b] = [1, 3, 5].map((i) => {
|
|
55
|
+
const c = parseInt(hex.slice(i, i + 2), 16) / 255;
|
|
56
|
+
return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
|
|
57
|
+
});
|
|
58
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* The tone of letters that read on a body of this colour: `dark` when the body is light, `light` when it is dark. The two letters are the family's pale `#f4efe2` and dark `#1c140c`; laid over a surface at any
|
|
62
|
+
* strength, the pale ones stand out more on a surface darker than about half way between them and the dark ones on a lighter one, which is a relative luminance of 0.5 in the body's mean colour (`BODIES[id].colour`):
|
|
63
|
+
* Venus, Saturn, Uranus, the Sun, Io and the ice moons get dark letters, and Mars, the Moon, the Earth and Neptune pale ones.
|
|
64
|
+
*
|
|
65
|
+
* @param colour - The body's mean colour, `#rrggbb`.
|
|
66
|
+
* @returns `dark` or `light`.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* import { BODIES } from "@johnmorrisdotca/wakusei-planets";
|
|
71
|
+
* import { nameTone } from "@johnmorrisdotca/wakusei-planets/painter";
|
|
72
|
+
*
|
|
73
|
+
* console.log(nameTone(BODIES.uranus.colour), nameTone(BODIES.mars.colour));
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export function nameTone(colour) {
|
|
77
|
+
return luminanceOf(colour) > 0.5 ? "dark" : "light";
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The look a name is drawn in once its tone is settled. A tone the page forces (`light` or `dark`) wins: `dark` makes `painted` and `etched` the dark `burned` look, and `light` makes `burned` the pale `painted` look. With `auto` (or no
|
|
81
|
+
* tone) only a `painted` look is changed, to `burned` on a light body (`nameTone`); `etched`, `burned` and `outline` are drawn as the page asked. `outline` has one tone and is never changed.
|
|
82
|
+
*
|
|
83
|
+
* @param options - The label's look and tone.
|
|
84
|
+
* @param colour - The body's mean colour, `#rrggbb`; left out, `auto` leaves the look as it is.
|
|
85
|
+
* @returns The look to draw.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* import { nameLabelLook } from "@johnmorrisdotca/wakusei-planets/painter";
|
|
90
|
+
*
|
|
91
|
+
* console.log(nameLabelLook({ look: "painted" }, "#a9e0e5"), nameLabelLook({ look: "painted", tone: "light" }, "#a9e0e5"), nameLabelLook({ look: "etched" }, "#a9e0e5"));
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export function nameLabelLook(options, colour) {
|
|
95
|
+
if (options.look === "outline")
|
|
96
|
+
return "outline";
|
|
97
|
+
if (options.tone === "dark")
|
|
98
|
+
return "burned";
|
|
99
|
+
if (options.tone === "light")
|
|
100
|
+
return options.look === "burned" ? "painted" : options.look;
|
|
101
|
+
return options.look === "painted" && colour !== undefined && nameTone(colour) === "dark" ? "burned" : options.look;
|
|
102
|
+
}
|
|
48
103
|
/**
|
|
49
104
|
* The text written for a body: its English name in capitals (the family's look), or its Japanese name as it is.
|
|
50
105
|
*
|
|
@@ -68,9 +123,9 @@ export function nameLabelKey(text, options) {
|
|
|
68
123
|
if (!options)
|
|
69
124
|
return "";
|
|
70
125
|
const o = { ...DEFAULTS, ...options };
|
|
71
|
-
return `${text}|${o.look}|${o.strength}|${o.repeat}|${o.latitude}|${o.facing}|${o.font}|${o.fallbackFont}|${o.size}|${o.minRadiusPx}`;
|
|
126
|
+
return `${text}|${o.look}|${o.tone}|${o.strength}|${o.repeat}|${o.latitude}|${o.facing}|${o.font}|${o.fallbackFont}|${o.size}|${o.minRadiusPx}`;
|
|
72
127
|
}
|
|
73
|
-
const DEFAULTS = { strength: 0.5, repeat: "once", latitude: 0, facing: false, font: BODY_LABEL_FONT, fallbackFont: "", size: "medium", minRadiusPx: 24 };
|
|
128
|
+
const DEFAULTS = { tone: "auto", strength: 0.5, repeat: "once", latitude: 0, facing: false, font: BODY_LABEL_FONT, fallbackFont: "", size: "medium", minRadiusPx: 24 };
|
|
74
129
|
const hasLabelParts = (T) => {
|
|
75
130
|
const parts = T;
|
|
76
131
|
return typeof parts.CanvasTexture === "function" && typeof parts.SRGBColorSpace === "string" && typeof parts.NormalBlending === "number";
|
|
@@ -149,15 +204,22 @@ const ensureFont = (font) => (font === BODY_LABEL_FONT && canDraw() ? (fontLoad
|
|
|
149
204
|
* @param options - The look and the rest.
|
|
150
205
|
* @param emissive - The body glows (the Sun): the name is lit fully, from no direction.
|
|
151
206
|
* @param onReady - Called when the name is drawn, and again when a new font is in.
|
|
207
|
+
* @param colour - The body's mean colour, `#rrggbb`: with `tone: "auto"` the letters are dark on a light body and pale on a dark one. Left out, they are the look's own.
|
|
152
208
|
*/
|
|
153
|
-
export function createNameLabel(T, text, options, emissive, onReady) {
|
|
209
|
+
export function createNameLabel(T, text, options, emissive, onReady, colour) {
|
|
154
210
|
const group = new T.Group();
|
|
155
211
|
group.name = "name-label";
|
|
156
212
|
// the shared label's frame has longitude 0 along +x and east towards -z; the bodies' has longitude 0 along +z and east along +x: a quarter turn about the pole maps one onto the other
|
|
157
213
|
group.rotation.y = -Math.PI / 2;
|
|
158
214
|
let label;
|
|
159
215
|
let materials = [];
|
|
160
|
-
|
|
216
|
+
// what the shared label is told: the look with its tone settled (`nameLabelLook`), and no tone of its own
|
|
217
|
+
const shared = (o) => {
|
|
218
|
+
const rest = { ...DEFAULTS, ...withoutUndefined(o) };
|
|
219
|
+
delete rest.tone;
|
|
220
|
+
return { ...rest, look: nameLabelLook(o, colour) };
|
|
221
|
+
};
|
|
222
|
+
let wanted = { text, options: shared(options) };
|
|
161
223
|
let disposed = false;
|
|
162
224
|
let ready = false;
|
|
163
225
|
const light = new T.Vector3(0, 0, 1);
|
|
@@ -189,6 +251,9 @@ export function createNameLabel(T, text, options, emissive, onReady) {
|
|
|
189
251
|
get ready() {
|
|
190
252
|
return ready;
|
|
191
253
|
},
|
|
254
|
+
get look() {
|
|
255
|
+
return wanted.options.look;
|
|
256
|
+
},
|
|
192
257
|
update(camera, radiusPx, toLight) {
|
|
193
258
|
if (label === undefined)
|
|
194
259
|
return false;
|
|
@@ -201,7 +266,7 @@ export function createNameLabel(T, text, options, emissive, onReady) {
|
|
|
201
266
|
return label.update((camera ?? FAR_EYE), radiusPx);
|
|
202
267
|
},
|
|
203
268
|
set(nextText, next) {
|
|
204
|
-
wanted = { text: nextText, options:
|
|
269
|
+
wanted = { text: nextText, options: shared(next) };
|
|
205
270
|
if (label === undefined)
|
|
206
271
|
return;
|
|
207
272
|
const fontChanged = wanted.options.font !== label.options.font;
|
package/dist/scene/painter.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { type TileLevel } from "./tiles.ts";
|
|
|
7
7
|
import { moonOffset, orientation } from "./orient.ts";
|
|
8
8
|
import { type NameLabelOptions } from "./name-label.ts";
|
|
9
9
|
export { moonOffset, orientation };
|
|
10
|
-
export { nameLabelText, readNameLabel, setBodyLabelFontUrl, type NameLabelOptions } from "./name-label.ts";
|
|
10
|
+
export { nameLabelLook, nameLabelText, nameTone, readNameLabel, setBodyLabelFontUrl, type NameLabelOptions, type NameLabelTone } from "./name-label.ts";
|
|
11
11
|
export { mercuryTilesCredit, PICTURE_CREDITS, picturesCredit, type PictureCredit } from "../picture-credits.ts";
|
|
12
12
|
/**
|
|
13
13
|
* The looks the painter draws: `realistic` (shaded from the body's real colours and features) and `painted` (a public-domain surface map, with the shaded look until it arrives).
|
|
@@ -148,6 +148,7 @@ export interface Painting {
|
|
|
148
148
|
shown: boolean;
|
|
149
149
|
text: string;
|
|
150
150
|
turn: number;
|
|
151
|
+
look: string;
|
|
151
152
|
} | null;
|
|
152
153
|
dispose(): void;
|
|
153
154
|
}
|
package/dist/scene/painter.js
CHANGED
|
@@ -15,7 +15,7 @@ import { moonOffset, orientation } from "./orient.js";
|
|
|
15
15
|
import { ringStrip } from "./rings.js";
|
|
16
16
|
import { createNameLabel, nameLabelText } from "./name-label.js";
|
|
17
17
|
export { moonOffset, orientation };
|
|
18
|
-
export { nameLabelText, readNameLabel, setBodyLabelFontUrl } from "./name-label.js";
|
|
18
|
+
export { nameLabelLook, nameLabelText, nameTone, readNameLabel, setBodyLabelFontUrl } from "./name-label.js";
|
|
19
19
|
export { mercuryTilesCredit, PICTURE_CREDITS, picturesCredit } from "../picture-credits.js";
|
|
20
20
|
/**
|
|
21
21
|
* The looks the painter draws: `realistic` (shaded from the body's real colours and features) and `painted` (a public-domain surface map, with the shaded look until it arrives).
|
|
@@ -350,7 +350,7 @@ function paint(T, id, context, bases, hold) {
|
|
|
350
350
|
let labelText = "";
|
|
351
351
|
let labelShown = false;
|
|
352
352
|
// what `label` reports: one object, written at each draw (it is read for every body at every frame)
|
|
353
|
-
const labelReport = { shown: false, text: "", turn: 0 };
|
|
353
|
+
const labelReport = { shown: false, text: "", turn: 0, look: "" };
|
|
354
354
|
const setLabel = (next) => {
|
|
355
355
|
if (next === null || next === undefined || gone) {
|
|
356
356
|
if (label !== undefined) {
|
|
@@ -366,11 +366,13 @@ function paint(T, id, context, bases, hold) {
|
|
|
366
366
|
labelText = text ?? nameLabelText(facts.name, lang ?? "en");
|
|
367
367
|
labelReport.text = labelText;
|
|
368
368
|
if (label === undefined) {
|
|
369
|
-
label = createNameLabel(T, labelText, options, look.emissive === true, redraw);
|
|
369
|
+
label = createNameLabel(T, labelText, options, look.emissive === true, redraw, facts.colour);
|
|
370
|
+
labelReport.look = label.look;
|
|
370
371
|
mesh.add(label.object);
|
|
371
372
|
}
|
|
372
373
|
else {
|
|
373
374
|
label.set(labelText, options);
|
|
375
|
+
labelReport.look = label.look;
|
|
374
376
|
redraw();
|
|
375
377
|
}
|
|
376
378
|
};
|
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.41.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.41.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/space/element.d.ts
CHANGED
|
@@ -615,6 +615,7 @@ export declare class WakuseiSpace extends HTMLElement {
|
|
|
615
615
|
shown: boolean;
|
|
616
616
|
text: string;
|
|
617
617
|
turn: number;
|
|
618
|
+
look: string;
|
|
618
619
|
} | null;
|
|
619
620
|
};
|
|
620
621
|
/** Starman and the Roadster at the last draw: whether the car was drawn (shown, its path in, the moment within 2018 to 2035), its place in Earth radii from the Earth's centre, and its radius on the screen in CSS pixels. */
|
package/dist/space/element.js
CHANGED
|
@@ -6,7 +6,7 @@ import { arrowCount } from "./arrows.js";
|
|
|
6
6
|
import { createGameClock } from "./clock.js";
|
|
7
7
|
import { bodyKindOf, findBody, hopFrom, hostOf, HOP_ORDER, systemOf } from "./bodies.js";
|
|
8
8
|
import { sightChanged, sightOf } from "./sight.js";
|
|
9
|
-
import { chooseLabels } from "./labels.js";
|
|
9
|
+
import { chooseLabels, nameSpot } from "./labels.js";
|
|
10
10
|
import { coverArrows } from "./covered.js";
|
|
11
11
|
import { createPainter } from "../scene/painter.js";
|
|
12
12
|
import { NAME_LABEL_ATTRIBUTES, readNameLabel } from "../scene/name-label.js";
|
|
@@ -105,7 +105,7 @@ const readBody = (value) => {
|
|
|
105
105
|
* 1.05 radii from the surface (`FIT_DISTANCE` over the zoom), so past a zoom of about 3.9 nothing moves; 3.6 is where the finest map tiles of the Earth, Mars and the Moon (16384 pixels round) run out of detail too, so it is the same ceiling for both.
|
|
106
106
|
*/
|
|
107
107
|
const CARRIED_LIMITS = { zoomMin: 1e-6, zoomMax: 3.6, tiltMax: 90 };
|
|
108
|
-
const STYLE = `<style>:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden}:host([immersive]){aspect-ratio:auto;width:100%;height:100%;touch-action:none!important;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent}#stage,#labels{position:absolute;inset:0}#labels{pointer-events:none;overflow:hidden}.sp-label{position:absolute;left:0;top:0;margin:0;padding:0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-label:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label::before{content:"";display:inline-block;width:5px;height:5px;margin:0 5px 1px -2px;border-radius:50%;background:#fff}.sp-label[hidden]{display:none}.sp-arrow{position:absolute;left:0;top:0;margin:0;padding:0 4px 0 0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.8;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:auto;cursor:pointer}.sp-arrow::before{content:"";display:inline-block;width:0;height:0;margin:0 5px 1px 0;border:5px solid transparent;border-left:7px solid #fff;transform:rotate(var(--turn,0deg));transform-origin:30% 50%}.sp-arrow[hidden]{display:none}.sp-arrow:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label[data-far]:not([data-carried]),.sp-ring[data-far]:not([data-carried]){opacity:var(--wakusei-far-opacity,.5)}.sp-arrow[data-far]{opacity:calc(.8*var(--wakusei-far-opacity,.5))}.sp-label,.sp-ring,.sp-arrow{transition:opacity .35s ease}.sp-label[data-carried],.sp-ring[data-carried]{opacity:0;pointer-events:none}@media (prefers-reduced-motion:reduce){.sp-label,.sp-ring,.sp-arrow{transition:none}}.sp-ring{position:absolute;left:0;top:0;width:16px;height:16px;margin:-8px 0 0 -8px;box-sizing:border-box;border:1.5px solid rgba(255,255,255,.85);border-radius:50%;box-shadow:0 0 3px #000;pointer-events:none;will-change:transform}.sp-ring[hidden]{display:none}.sp-scale{position:absolute;left:10px;top:8px;margin:0;padding:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.9;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}.sp-region{position:absolute;left:10px;bottom:8px;margin:0;padding:0;font:600 15px/20px system-ui,-apple-system,sans-serif;color:#fff;opacity:.95;text-shadow:0 0 4px #000,0 0 4px #000;pointer-events:none;transition:opacity .35s}.sp-region[hidden]{display:block;opacity:0}@media (prefers-reduced-motion:reduce){.sp-region{transition:none}}.sp-note{position:absolute;left:10px;right:10px;top:28px;max-width:44em;margin:0;padding:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.92;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}.sp-note[hidden],.sp-oort[hidden]{display:none}.sp-oort{position:absolute;left:0;top:0;margin:0;padding:0;font:italic 12px/16px system-ui,-apple-system,sans-serif;color:#aeb8e6;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}</style><div id="stage"></div><div id="labels"></div><p class="sp-scale" part="scale" role="status"></p><p class="sp-region" id="region" part="region" role="status" hidden></p><p class="sp-note" part="note" role="status" hidden></p><p class="sp-oort" part="oort" hidden></p>`;
|
|
108
|
+
const STYLE = `<style>:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden}:host([immersive]){aspect-ratio:auto;width:100%;height:100%;touch-action:none!important;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent}#stage,#labels{position:absolute;inset:0}#labels{pointer-events:none;overflow:hidden}.sp-label{position:absolute;left:0;top:0;margin:0;padding:0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-label:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label::before{content:"";display:inline-block;width:5px;height:5px;margin:0 5px 1px -2px;border-radius:50%;background:#fff}.sp-label[data-flip]{display:flex;flex-direction:row-reverse}.sp-label[data-flip]::before{margin:0 -2px 1px 5px}.sp-label[hidden]{display:none}.sp-arrow{position:absolute;left:0;top:0;margin:0;padding:0 4px 0 0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.8;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:auto;cursor:pointer}.sp-arrow::before{content:"";display:inline-block;width:0;height:0;margin:0 5px 1px 0;border:5px solid transparent;border-left:7px solid #fff;transform:rotate(var(--turn,0deg));transform-origin:30% 50%}.sp-arrow[hidden]{display:none}.sp-arrow:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label[data-far]:not([data-carried]),.sp-ring[data-far]:not([data-carried]){opacity:var(--wakusei-far-opacity,.5)}.sp-arrow[data-far]{opacity:calc(.8*var(--wakusei-far-opacity,.5))}.sp-label,.sp-ring,.sp-arrow{transition:opacity .35s ease}.sp-label[data-carried],.sp-ring[data-carried]{opacity:0;pointer-events:none}@media (prefers-reduced-motion:reduce){.sp-label,.sp-ring,.sp-arrow{transition:none}}.sp-ring{position:absolute;left:0;top:0;width:16px;height:16px;margin:-8px 0 0 -8px;box-sizing:border-box;border:1.5px solid rgba(255,255,255,.85);border-radius:50%;box-shadow:0 0 3px #000;pointer-events:none;will-change:transform}.sp-ring[hidden]{display:none}.sp-scale{position:absolute;left:10px;top:8px;margin:0;padding:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.9;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}.sp-region{position:absolute;left:10px;bottom:8px;margin:0;padding:0;font:600 15px/20px system-ui,-apple-system,sans-serif;color:#fff;opacity:.95;text-shadow:0 0 4px #000,0 0 4px #000;pointer-events:none;transition:opacity .35s}.sp-region[hidden]{display:block;opacity:0}@media (prefers-reduced-motion:reduce){.sp-region{transition:none}}.sp-note{position:absolute;left:10px;right:10px;top:28px;max-width:44em;margin:0;padding:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.92;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}.sp-note[hidden],.sp-oort[hidden]{display:none}.sp-oort{position:absolute;left:0;top:0;margin:0;padding:0;font:italic 12px/16px system-ui,-apple-system,sans-serif;color:#aeb8e6;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}</style><div id="stage"></div><div id="labels"></div><p class="sp-scale" part="scale" role="status"></p><p class="sp-region" id="region" part="region" role="status" hidden></p><p class="sp-note" part="note" role="status" hidden></p><p class="sp-oort" part="oort" hidden></p>`;
|
|
109
109
|
const orbiterLines = (value) => (value === "chosen" || value === "none" ? value : "all");
|
|
110
110
|
/**
|
|
111
111
|
* The `<wakusei-space>` custom element: the Earth, the Moon, the Sun and the planets where they are at a date and time, drawn with three.js through the shared renderer. It takes `center`
|
|
@@ -1687,6 +1687,7 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
1687
1687
|
return;
|
|
1688
1688
|
const wanted = [];
|
|
1689
1689
|
const spots = new Map();
|
|
1690
|
+
const frame = { width: box.clientWidth, height: box.clientHeight };
|
|
1690
1691
|
const ids = [...new Set([...SPACE_BODIES, ...this.#pool.keys(), ...Object.keys(places)])];
|
|
1691
1692
|
for (const id of ids) {
|
|
1692
1693
|
let label = this.#pool.get(id);
|
|
@@ -1714,16 +1715,17 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
1714
1715
|
}
|
|
1715
1716
|
if (!at)
|
|
1716
1717
|
continue;
|
|
1717
|
-
const
|
|
1718
|
-
|
|
1718
|
+
const width = this.#widthOf(label);
|
|
1719
|
+
// beside the dot, on the side that stays inside the view
|
|
1720
|
+
const { x, y, flipped } = nameSpot(at, { width, height: 16 }, frame);
|
|
1719
1721
|
// a body that carries its drawn name gives its floating name up (it fades, and leaves its place to the others) unless the page keeps both; a body behind another gives it up for the arrow
|
|
1720
1722
|
const carried = at.named === true && !this.#labelsAlways;
|
|
1721
1723
|
const covered = at.behind !== undefined && this.#covered === "arrow";
|
|
1722
1724
|
if (covered)
|
|
1723
1725
|
continue;
|
|
1724
|
-
spots.set(id, { x, y, small: at.r < RING_BELOW_PX, carried });
|
|
1726
|
+
spots.set(id, { x, y, small: at.r < RING_BELOW_PX, carried, flipped });
|
|
1725
1727
|
if (!carried)
|
|
1726
|
-
wanted.push({ id, x, y, width
|
|
1728
|
+
wanted.push({ id, x, y, width, height: 16, rank: this.#rank(id), size: at.r });
|
|
1727
1729
|
}
|
|
1728
1730
|
// no two names overlap: a moon gives way to its planet and a planet to the Sun
|
|
1729
1731
|
const shown = chooseLabels(wanted);
|
|
@@ -1756,6 +1758,8 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
1756
1758
|
label.setAttribute("aria-hidden", String(spot.carried));
|
|
1757
1759
|
label.tabIndex = spot.carried ? -1 : 0;
|
|
1758
1760
|
}
|
|
1761
|
+
if (label.hasAttribute("data-flip") !== spot.flipped)
|
|
1762
|
+
label.toggleAttribute("data-flip", spot.flipped);
|
|
1759
1763
|
label.style.transform = `translate(${spot.x}px,${spot.y}px)`;
|
|
1760
1764
|
// a body too small to see is marked: a ring round the place it is, as well as its name
|
|
1761
1765
|
if (ring.hidden === spot.small)
|
package/dist/space/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, eclipticToScene
|
|
|
2
2
|
export { compress, MOON_COMPRESSED, moonDistance, orbitLine, placeAround, placeBodies, placeMoon, placeSun, radiusIn, SUN_COMPRESSED, truePosition, type ScaleMode } from "./scale.ts";
|
|
3
3
|
export { groundDirection } from "./aim.ts";
|
|
4
4
|
export { RIDE_FOV, ridePose, type RideInput, type RideLook, type RidePose } from "./ride.ts";
|
|
5
|
-
export { chooseLabels, LABEL_GAP, type LabelBox } from "./labels.ts";
|
|
5
|
+
export { chooseLabels, LABEL_GAP, nameSpot, type LabelBox } from "./labels.ts";
|
|
6
6
|
export { bodyKindOf, findBody, HOP_ORDER, hopFrom, hostOf, systemOf, type SpaceKind } from "./bodies.ts";
|
|
7
7
|
export { besideMoon, BESIDE_RADII, type BesideCamera, type BesideInput } from "./beside.ts";
|
|
8
8
|
export { ARROWS_PER_ORBIT, arrowCount, arrowSites, MAX_ARROWS_PER_ORBIT, chevron, spinArrow, type OrbitArrow } from "./arrows.ts";
|
package/dist/space/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, eclipticToScene
|
|
|
3
3
|
export { compress, MOON_COMPRESSED, moonDistance, orbitLine, placeAround, placeBodies, placeMoon, placeSun, radiusIn, SUN_COMPRESSED, truePosition } from "./scale.js";
|
|
4
4
|
export { groundDirection } from "./aim.js";
|
|
5
5
|
export { RIDE_FOV, ridePose } from "./ride.js";
|
|
6
|
-
export { chooseLabels, LABEL_GAP } from "./labels.js";
|
|
6
|
+
export { chooseLabels, LABEL_GAP, nameSpot } from "./labels.js";
|
|
7
7
|
export { bodyKindOf, findBody, HOP_ORDER, hopFrom, hostOf, systemOf } from "./bodies.js";
|
|
8
8
|
export { besideMoon, BESIDE_RADII } from "./beside.js";
|
|
9
9
|
export { ARROWS_PER_ORBIT, arrowCount, arrowSites, MAX_ARROWS_PER_ORBIT, chevron, spinArrow } from "./arrows.js";
|
package/dist/space/labels.d.ts
CHANGED
|
@@ -50,3 +50,35 @@ export declare const LABEL_GAP = 3;
|
|
|
50
50
|
* ```
|
|
51
51
|
*/
|
|
52
52
|
export declare function chooseLabels(boxes: readonly LabelBox[], gap?: number): Set<string>;
|
|
53
|
+
/**
|
|
54
|
+
* Where a floating name goes: beside its body's dot, and kept inside the view (MODULES-1144). It starts to the right of the dot, at `max(4, min(r, 40))` pixels from its middle and 8 pixels above it. A name that would run past the right edge goes to the dot's left side instead (`flipped`); one that fits on neither side is held against the edge, and a name past the top or the bottom is held inside. A body whose dot is itself outside the view keeps its name where it falls, since the view cuts it with the body.
|
|
55
|
+
*
|
|
56
|
+
* @param dot - The body's place on the screen in CSS pixels: its middle and its radius on the screen.
|
|
57
|
+
* @param size - The name's width and height in CSS pixels.
|
|
58
|
+
* @param frame - The view's width and height in CSS pixels.
|
|
59
|
+
* @returns The name's top-left corner, and whether it went to the left of the dot.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { nameSpot } from "@johnmorrisdotca/wakusei-planets/space";
|
|
64
|
+
*
|
|
65
|
+
* // a body 20 pixels from the right edge of a 400 pixel view: its 60 pixel name goes to the left of it
|
|
66
|
+
* const spot = nameSpot({ x: 380, y: 100, r: 10 }, { width: 60, height: 16 }, { width: 400, height: 300 });
|
|
67
|
+
* console.log(spot.flipped, spot.x + 60 <= 380);
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare function nameSpot(dot: {
|
|
71
|
+
x: number;
|
|
72
|
+
y: number;
|
|
73
|
+
r: number;
|
|
74
|
+
}, size: {
|
|
75
|
+
width: number;
|
|
76
|
+
height: number;
|
|
77
|
+
}, frame: {
|
|
78
|
+
width: number;
|
|
79
|
+
height: number;
|
|
80
|
+
}): {
|
|
81
|
+
x: number;
|
|
82
|
+
y: number;
|
|
83
|
+
flipped: boolean;
|
|
84
|
+
};
|
package/dist/space/labels.js
CHANGED
|
@@ -38,3 +38,42 @@ export function chooseLabels(boxes, gap = LABEL_GAP) {
|
|
|
38
38
|
kept.push(box);
|
|
39
39
|
return new Set(kept.map((box) => box.id));
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Where a floating name goes: beside its body's dot, and kept inside the view (MODULES-1144). It starts to the right of the dot, at `max(4, min(r, 40))` pixels from its middle and 8 pixels above it. A name that would run past the right edge goes to the dot's left side instead (`flipped`); one that fits on neither side is held against the edge, and a name past the top or the bottom is held inside. A body whose dot is itself outside the view keeps its name where it falls, since the view cuts it with the body.
|
|
43
|
+
*
|
|
44
|
+
* @param dot - The body's place on the screen in CSS pixels: its middle and its radius on the screen.
|
|
45
|
+
* @param size - The name's width and height in CSS pixels.
|
|
46
|
+
* @param frame - The view's width and height in CSS pixels.
|
|
47
|
+
* @returns The name's top-left corner, and whether it went to the left of the dot.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { nameSpot } from "@johnmorrisdotca/wakusei-planets/space";
|
|
52
|
+
*
|
|
53
|
+
* // a body 20 pixels from the right edge of a 400 pixel view: its 60 pixel name goes to the left of it
|
|
54
|
+
* const spot = nameSpot({ x: 380, y: 100, r: 10 }, { width: 60, height: 16 }, { width: 400, height: 300 });
|
|
55
|
+
* console.log(spot.flipped, spot.x + 60 <= 380);
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export function nameSpot(dot, size, frame) {
|
|
59
|
+
const gap = Math.max(4, Math.min(dot.r, 40));
|
|
60
|
+
let x = Math.round(dot.x + gap);
|
|
61
|
+
let y = Math.round(dot.y - 8);
|
|
62
|
+
let flipped = false;
|
|
63
|
+
if (frame.width <= 0 || frame.height <= 0)
|
|
64
|
+
return { x, y, flipped };
|
|
65
|
+
if (dot.x >= 0 && dot.x <= frame.width) {
|
|
66
|
+
if (x + size.width > frame.width) {
|
|
67
|
+
const left = Math.round(dot.x - gap - size.width);
|
|
68
|
+
if (left >= 0) {
|
|
69
|
+
x = left;
|
|
70
|
+
flipped = true;
|
|
71
|
+
}
|
|
72
|
+
else
|
|
73
|
+
x = Math.max(0, frame.width - size.width);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (dot.y >= 0 && dot.y <= frame.height)
|
|
77
|
+
y = Math.max(0, Math.min(y, frame.height - size.height));
|
|
78
|
+
return { x, y, flipped };
|
|
79
|
+
}
|
package/dist/space/scene.d.ts
CHANGED
|
@@ -242,6 +242,7 @@ export interface SpaceModel {
|
|
|
242
242
|
shown: boolean;
|
|
243
243
|
text: string;
|
|
244
244
|
turn: number;
|
|
245
|
+
look: string;
|
|
245
246
|
} | null;
|
|
246
247
|
};
|
|
247
248
|
/** How long an arrowhead drawn at the last draw is on the screen, in CSS pixels (measured from its own points), or 0 when none was drawn. */
|
|
Binary file
|
|
Binary file
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.41.0";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.
|
|
1
|
+
export const VERSION = "0.41.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/wakusei-planets",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.41.0",
|
|
4
4
|
"description": "Wakusei Planets 惑星 — The Sun, planets and moons for the web: each as a clean line drawing, a shaded realistic drawing or a painted surface map, with real sizes, axial tilt and rotation as data, and positions of the moons for any date and time. SVG for the lines, three.js (optional) for the rest.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"planets",
|