@johnmorrisdotca/wakusei-planets 0.40.0 → 0.42.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 +18 -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 +15 -1
- package/dist/space/element.js +96 -18
- package/dist/space/index.d.ts +3 -3
- package/dist/space/index.js +3 -3
- package/dist/space/labels.d.ts +32 -0
- package/dist/space/labels.js +39 -0
- package/dist/space/scale.d.ts +27 -0
- package/dist/space/scale.js +49 -0
- package/dist/space/scene.d.ts +31 -1
- package/dist/space/scene.js +38 -3
- package/dist/space/travel.d.ts +55 -4
- package/dist/space/travel.js +105 -16
- 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,24 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.42.0] - 2026-11-13
|
|
6
|
+
|
|
7
|
+
- **An arrival keeps a companion in the picture** (MODULES-1026). `arrivalSide` (and `travelArrival`, which uses it) stands on the side where the frame is not empty black: the body's own moons, or its planet when it is a moon; else the body the camera came from, or the nearest planet in that direction; else the Sun, only while at least half the body stays lit. A side that would turn the globe black is refused. `goTo` and a double click (the zoom jump to 1 or to 2) set the controls to that side; a drag afterwards is left as the reader set it. `stats.companion` names the body kept beside it, and that name is not dropped when names would otherwise clash. The swing is not applied to a straight move (`direct`, `look-back`), which keeps its destination in the picture the whole way.
|
|
8
|
+
|
|
9
|
+
- **Moons are larger than life in the squeezed view** (MODULES-989). `moon-size` on `<wakusei-space>` (and `space.moonSize`) is 2 by default: moons are drawn that many times their real radius, only while `scale` is `compressed`. 1 is today's size; 4 and 8 go further. True distances ignore it. Every moon of one planet takes the same factor, so they keep their real order of size. The factor is cut when a moon would be larger than a quarter of its planet, would touch the planet or its rings, or would reach the next moon's orbit, and `stats.moonSize` reports the factor used and `clamped`. Picking, the name on the body and the hidden-body rule use that drawn size. `moonSizeFactor` from `/space` is the same rule on plain numbers. A moon looked at, or gone to, is framed at the size it is drawn, so it still fits the view.
|
|
10
|
+
|
|
11
|
+
- **A page for the spacecraft** (MODULES-875). `craft.html` picks one of the eighteen craft, draws its path and where it is on a date, and lists the facts and the voyage. The craft's table loads only when it is chosen. The date plays when the page opens, and every time shown is the reader's own. English and Japanese.
|
|
12
|
+
|
|
13
|
+
## [0.41.0] - 2026-11-13
|
|
14
|
+
|
|
15
|
+
- **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.
|
|
16
|
+
|
|
17
|
+
- **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.
|
|
18
|
+
|
|
19
|
+
- **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`).
|
|
20
|
+
|
|
21
|
+
- **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.
|
|
22
|
+
|
|
5
23
|
## [0.40.0] - 2026-11-13
|
|
6
24
|
|
|
7
25
|
- **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.42.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.42.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.42.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.42.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.42.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
|
@@ -257,6 +257,11 @@ export declare class WakuseiSpace extends HTMLElement {
|
|
|
257
257
|
/** `true` (the default: real distances and sizes; a body too small to see is marked with a ring and its name) or `compressed` (every direction real, the distances squeezed). The scale in use is always named on the view. */
|
|
258
258
|
get scale(): ScaleMode;
|
|
259
259
|
set scale(value: ScaleMode);
|
|
260
|
+
/**
|
|
261
|
+
* How many times larger than life to draw moons in the squeezed scale (`moon-size`; 2 by default, from 1 to 8). 1 is the real size. Ignored at true distances. A moon is never drawn larger than a quarter of its planet, into the planet or its rings, or across to the next moon's orbit: every moon of one planet is reduced by the same factor, so they keep their order of size, and `stats.moonSize` says the factor used.
|
|
262
|
+
*/
|
|
263
|
+
get moonSize(): number;
|
|
264
|
+
set moonSize(value: number);
|
|
260
265
|
/** The words naming the scale on the view, for a page in another language (`{ true: "距離はそのまま" }`). A scale left out keeps its words in the element's `lang`. */
|
|
261
266
|
get scaleNames(): Partial<Record<ScaleMode, string>>;
|
|
262
267
|
set scaleNames(value: Partial<Record<ScaleMode, string>>);
|
|
@@ -398,7 +403,7 @@ export declare class WakuseiSpace extends HTMLElement {
|
|
|
398
403
|
roll?: number;
|
|
399
404
|
panX?: number;
|
|
400
405
|
panY?: number;
|
|
401
|
-
}, final?: boolean): void;
|
|
406
|
+
}, final?: boolean, reason?: string): void;
|
|
402
407
|
/** The body the camera looks at: any body the view places, by name in any case (`earth`, `sun`, `moon`, `mercury` to `neptune`, `pluto`, and the moons of the planets such as `titan`). At zoom 1 it fills the view; the yaw and tilt turn the camera round it. Setting it moves the camera there at once and keeps the zoom; `goTo` glides and brings the body into view. */
|
|
403
408
|
get body(): BodyId;
|
|
404
409
|
set body(name: BodyId | string);
|
|
@@ -615,6 +620,7 @@ export declare class WakuseiSpace extends HTMLElement {
|
|
|
615
620
|
shown: boolean;
|
|
616
621
|
text: string;
|
|
617
622
|
turn: number;
|
|
623
|
+
look: string;
|
|
618
624
|
} | null;
|
|
619
625
|
};
|
|
620
626
|
/** 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. */
|
|
@@ -623,6 +629,12 @@ export declare class WakuseiSpace extends HTMLElement {
|
|
|
623
629
|
position: [number, number, number] | null;
|
|
624
630
|
radiusPx: number;
|
|
625
631
|
};
|
|
632
|
+
/** How large the squeezed view drew the moons of the system in the middle: the factor asked for, the one used, and whether a limit cut it. At true distances `factor` is 1. */
|
|
633
|
+
moonSize: {
|
|
634
|
+
asked: number;
|
|
635
|
+
factor: number;
|
|
636
|
+
clamped: boolean;
|
|
637
|
+
};
|
|
626
638
|
/** The orbiters at the last draw: how many dots were drawn (their body big enough on the screen), each drawn craft's status (`tracked`, `predicted`, `modelled`); `dim` lists the craft drawn dim (`orbiterDim` from `/orbiters`); `lines` how many orbit lines and `track` how many points of ground track were drawn. */
|
|
627
639
|
orbiters: {
|
|
628
640
|
count: number;
|
|
@@ -631,6 +643,8 @@ export declare class WakuseiSpace extends HTMLElement {
|
|
|
631
643
|
lines: number;
|
|
632
644
|
track: number;
|
|
633
645
|
};
|
|
646
|
+
/** The body the last arrival kept in the picture beside the one gone to, or null. */
|
|
647
|
+
companion: string | null;
|
|
634
648
|
};
|
|
635
649
|
/** Where a body is on the screen now: its centre and radius in CSS pixels in the element, or `null` when it is behind the camera or not drawn. */
|
|
636
650
|
placeOf(id: BodyId): BodyPlace | null;
|