@johnmorrisdotca/wakusei-planets 0.33.0 → 0.34.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 +4 -0
- package/NOTICE.md +4 -0
- package/README.md +8 -3
- package/dist/element.d.ts +10 -1
- package/dist/element.js +25 -4
- package/dist/scene/body.d.ts +13 -2
- package/dist/scene/body.js +35 -0
- package/dist/scene/name-label.d.ts +116 -0
- package/dist/scene/name-label.js +232 -0
- package/dist/scene/painter.d.ts +29 -0
- package/dist/scene/painter.js +36 -0
- package/dist/scene/textures.d.ts +2 -2
- package/dist/space/element.d.ts +16 -0
- package/dist/space/element.js +26 -1
- package/dist/space/scene.d.ts +13 -1
- package/dist/space/scene.js +21 -3
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.34.0] - 2026-11-11
|
|
6
|
+
|
|
7
|
+
- **The body's name written on its globe** (MODULES-923). `body-label="painted"` on `<wakusei-body>` and `<wakusei-space>` writes each body's name on its own surface in the shaded looks, large and in capitals, lying on the globe and turning with it as a film lays a title over the thing it names, with the surface showing through. Off by default. The family's standard attributes beside it: `body-label-strength` (0 to 1), `body-label-repeat` (`once`, `both` so one is always in view, `around`), `body-label-latitude` (the equator, or a band near a pole), `body-label-facing` (the name keeps facing the reader while the body turns under it), `body-label-font` and `body-label-fallback-font`; and one property, `bodyLabel`, taking the same as an object or `null`. The looks are `painted`, `etched`, `outline` and `burned`. The default when on is John's pick: Michroma, painted, half strength, once, on the equator, turning with the body. The text is the body's name in the element's `lang` (`EARTH`, `地球`; Japanese in the fallback font). A body drawn smaller than 24 CSS pixels in radius carries no name, so the small moons and the whole solar system stay plain; the Sun's is drawn on its disc, fully lit; the name is lit as the body is, so it is dark on the night side. The drawing is kazoku-ui 0.37's `body-label` (the one drawing for the family, so chikyu-earth's Earth can carry the same), fitted to the bodies' own frame and lit through the painter's own light (the scenes have no three.js lights). Through the painter: `label` in `PaintContext`, `setLabel` and `label` on a `Painting`, `PaintLabel`; `readNameLabel` and `nameLabelText` from `/painter`. Michroma (SIL OFL 1.1) is fetched once from kazoku-ui's copy the first time a name is written in it; a page's own font fetches nothing. A page that hands over a subset of three.js adds `CanvasTexture`, `SRGBColorSpace` and `NormalBlending` for the name to be drawn. Both demo pages have a "Name on the body" row kept in the address (`bl`, `blr`, `bll`, `bls`, `blf`); `stats.label` and `stats.bodyLabels` say what is drawn. Guide "A name on the body" in English and Japanese; `e2e/body-label.demo.ts` and a freeze case. kazoku-ui 0.37.
|
|
8
|
+
|
|
5
9
|
## [0.33.0] - 2026-11-11
|
|
6
10
|
|
|
7
11
|
- **CI installs Playwright's browsers in bounded, cached steps** (KAZOKU-UI-100). A slow package mirror held `playwright install --with-deps` for the whole job limit on 2026-11-09 and 2026-11-10, so no test ran and the failure read as a test failure. `.github/actions/playwright` (the family's, kazoku-ui's copy is canonical) caches the browsers by Playwright's version, then installs the system libraries in a step of their own: two tries, each cut off after 7 minutes, and a failure that says it is the runner's package mirror and that nothing was run. Free: GitHub-hosted Linux runners and the cache.
|
package/NOTICE.md
CHANGED
|
@@ -142,6 +142,10 @@ Not tiled, because no finer public-domain map was found that this package can us
|
|
|
142
142
|
|
|
143
143
|
The generic detail of a close zoom (docs/guides/close-zoom.md) is noise made in the shader. It is no data and takes nothing from any source.
|
|
144
144
|
|
|
145
|
+
## The font of a name on a body
|
|
146
|
+
|
|
147
|
+
A body's name written on its globe (`body-label`) is drawn in Michroma, by Vernon Adams, "Copyright 2011 The Michroma Project Authors (https://github.com/googlefonts/Michroma-font)", under the SIL Open Font License, Version 1.1, with no Reserved Font Name. The licence was read on 2026-11-11: it allows the font to be used, bundled, embedded and redistributed with software, as long as the copyright notice and the licence go with it and the font is not sold by itself. This package bundles no font: the file ships unchanged in `@johnmorrisdotca/kazoku-ui` (`dist/body-label/fonts/Michroma-Regular.ttf`, with `OFL.txt` beside it) and is fetched from there only when a page writes a name in it. A page that names its own font fetches nothing.
|
|
148
|
+
|
|
145
149
|
## The data door
|
|
146
150
|
|
|
147
151
|
- **The package's own credits (`OWN_SOURCES` in `@johnmorrisdotca/wakusei-planets/door`, MODULES-831, written 2026-11-10)**: three rows, written from the entries of this file and read nowhere else. `wakusei-pictures` is the surface pictures (Surface pictures above: NASA, USGS and JPL maps that are public domain, and Solar System Scope's and Nestaeric's maps, CC BY 4.0; its licence name is the stricter, "CC BY 4.0", read 2026-11-02). `wakusei-tiles` is the finer map tiles (Finer map tiles above: public domain, read 2026-11-09). `wakusei-orbits` is the series and tables the positions come from (The numbers above: IMCCE's VSOP87B and ELP2000-82B, which "carry no licence text" and are published for use with the credit, and JPL Horizons, NASA/JPL-Caltech, read 2026-11-07; its licence name says "Published for use with credit"). A test holds that none of the three is marked non-commercial or share-alike.
|
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.34.0/docs/images/lineup-desk.png" width="640"></p>
|
|
23
23
|
|
|
24
24
|
## Who it is for
|
|
25
25
|
|
|
@@ -151,6 +151,10 @@ const text = lineupText(largest, "en");
|
|
|
151
151
|
console.log(`${text.name}: ${text.radius}, ${text.km}, ${text.source}`);
|
|
152
152
|
```
|
|
153
153
|
|
|
154
|
+
## A name on the body
|
|
155
|
+
|
|
156
|
+
`body-label="painted"` writes the body's name on its own globe, large and in capitals, lying on the surface and turning with it, as a film lays a title over the thing it names: on `<wakusei-body>` and on every body of `<wakusei-space>`, in the page's language, in Michroma by default or a font of yours. Four looks (`painted`, `etched`, `outline`, `burned`), once or on both sides, at the equator or near a pole, turning with the body or always facing you; nothing on a body too small on the screen. [A name on the body](docs/guides/name-on-the-body.md) has the attributes.
|
|
157
|
+
|
|
154
158
|
## Two packages: this one and chikyu-earth
|
|
155
159
|
|
|
156
160
|
This package is the Sun, the planets, the dwarf planets and the moons, and where they are. [chikyu-earth](https://github.com/johnmorrisdotca/chikyu-earth) is the Earth in detail: its countries, day and night, places and satellites. Each works alone; install both and the Earth's line look becomes chikyu-earth's globe with the countries. The dependency runs one way: this package may use chikyu-earth, never the reverse. [Why two packages](docs/guides/two-packages.md) has the rule, a table of what lives where and how to use them together.
|
|
@@ -372,7 +376,7 @@ The tiles of every body share one 48 MB budget, six loads at a time for a source
|
|
|
372
376
|
|
|
373
377
|
## The portrait builder
|
|
374
378
|
|
|
375
|
-
<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.
|
|
379
|
+
<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.34.0/docs/images/portrait-family.png" width="640"></p>
|
|
376
380
|
|
|
377
381
|
[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.
|
|
378
382
|
|
|
@@ -455,6 +459,7 @@ Each guide has a Japanese twin in [docs/guides/ja](docs/guides/ja/getting-starte
|
|
|
455
459
|
| [Put it in your page](docs/guides/put-it-in-your-page.md) | Set up a body and copy the code |
|
|
456
460
|
| [The portrait builder](docs/guides/portrait-builder.md) | Many bodies in one picture |
|
|
457
461
|
| [Looks and bodies](docs/guides/looks-and-bodies.md) | The looks and each body's entry point |
|
|
462
|
+
| [A name on the body](docs/guides/name-on-the-body.md) | The body's name written on its globe: looks, how many, where, facing you, the font |
|
|
458
463
|
| [Why two packages](docs/guides/two-packages.md) | This package and chikyu-earth: which to install, alone or together |
|
|
459
464
|
| [Moons and time](docs/guides/moons-and-time.md) | The sky on a date, time that runs fast |
|
|
460
465
|
| [The space view](docs/guides/space-view.md) | The Earth, Moon, Sun and planets in their places; two scales; time both ways |
|
|
@@ -508,7 +513,7 @@ BODIES.pluto.kind; // "dwarf-planet"
|
|
|
508
513
|
|
|
509
514
|
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:
|
|
510
515
|
|
|
511
|
-
> Morris, J. (2026). *Wakusei Planets* (version 0.
|
|
516
|
+
> Morris, J. (2026). *Wakusei Planets* (version 0.34.0) [Computer software]. https://github.com/johnmorrisdotca/wakusei-planets
|
|
512
517
|
|
|
513
518
|
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).
|
|
514
519
|
|
package/dist/element.d.ts
CHANGED
|
@@ -7,7 +7,8 @@ import type { Credit, DataSource } from "./data-door.ts";
|
|
|
7
7
|
import { type DoorHost } from "./door/host.ts";
|
|
8
8
|
export { TEXTURE_BASE, TEXTURE_FAR_BASE, TILES_BASE } from "./scene/textures.ts";
|
|
9
9
|
import type { DetailStats } from "./scene/detail.ts";
|
|
10
|
-
import { type ThreeParts } from "./scene/body.ts";
|
|
10
|
+
import { type BodyScene, type ThreeParts } from "./scene/body.ts";
|
|
11
|
+
import { type NameLabelOptions } from "./scene/name-label.ts";
|
|
11
12
|
import { setThreeLoader } from "./scene/shared.ts";
|
|
12
13
|
export { setThreeLoader };
|
|
13
14
|
/**
|
|
@@ -33,6 +34,7 @@ export type WakuseiState = "line" | "loading" | "still" | "live" | "lost" | "una
|
|
|
33
34
|
* `controls="none"` turns them off, and `live="off"` (a still, a thumbnail) starts without them (`controls` with no value brings them back). `zoom-min` and `zoom-max` set the range (0.1 to 50 for the line drawing; for the shaded looks 0.1 up to where the body's detail runs out, 8 at least and 1000 at most: see the close zoom guide); a `<kazoku-view-controls for="...">` takes over and reads it.
|
|
34
35
|
* 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.
|
|
35
36
|
* Whatever moves the view, `setView` sends a `wakusei-view` event with its `yaw`, `tilt`, `roll`, `zoom`, `panX` and `panY`.
|
|
37
|
+
* `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` and `-fallback-font` beside it, and the `bodyLabel` property takes the same as an object: see the guide "A name on the body".
|
|
36
38
|
* 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
|
|
37
39
|
* `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
|
|
38
40
|
* `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.
|
|
@@ -83,6 +85,12 @@ export declare class WakuseiBody extends HTMLElement {
|
|
|
83
85
|
set star(numbers: StarNumbers | string | null | undefined);
|
|
84
86
|
get star(): StarNumbers | undefined;
|
|
85
87
|
get look(): Look;
|
|
88
|
+
/**
|
|
89
|
+
* The name written on the body's globe in the shaded looks, as an object (`{ look: "painted", strength: 0.5, repeat: "once", latitude: 0, facing: false, font: "Michroma", fallbackFont: "" }`), or `null` for none.
|
|
90
|
+
* Set, it takes the place of the `body-label` attributes; set to `undefined` the attributes are read again. The text is the body's own name in the element's `lang`, in capitals in English.
|
|
91
|
+
*/
|
|
92
|
+
get bodyLabel(): NameLabelOptions | null;
|
|
93
|
+
set bodyLabel(value: NameLabelOptions | null | undefined);
|
|
86
94
|
/** What the element is doing now. */
|
|
87
95
|
get state(): WakuseiState;
|
|
88
96
|
/** Numbers for a test or a status line: the state, the texture width in use and the renderer's own counts. */
|
|
@@ -93,6 +101,7 @@ export declare class WakuseiBody extends HTMLElement {
|
|
|
93
101
|
renderer: SharedRenderer<ThreeParts>["stats"] | undefined;
|
|
94
102
|
tiles: DetailStats | undefined;
|
|
95
103
|
zoomMax: number | undefined;
|
|
104
|
+
label: BodyScene["label"] | null;
|
|
96
105
|
};
|
|
97
106
|
connectedCallback(): void;
|
|
98
107
|
disconnectedCallback(): void;
|
package/dist/element.js
CHANGED
|
@@ -17,6 +17,7 @@ import { ownCredit } from "./door/own.js";
|
|
|
17
17
|
export { TEXTURE_BASE, TEXTURE_FAR_BASE, TILES_BASE } from "./scene/textures.js";
|
|
18
18
|
import { mapWidthOf, ringWidthOf, zoomLimit } from "./scene/reach.js";
|
|
19
19
|
import { createBodyItem } from "./scene/body.js";
|
|
20
|
+
import { NAME_LABEL_ATTRIBUTES, nameLabelKey, nameLabelText, readNameLabel } from "./scene/name-label.js";
|
|
20
21
|
import { delegates, onRegister } from "./scene/store.js";
|
|
21
22
|
import { setThreeLoader, takeRenderer } from "./scene/shared.js";
|
|
22
23
|
import { turn as turnVec } from "./vec.js";
|
|
@@ -78,6 +79,7 @@ const TEMPLATE = `<style>
|
|
|
78
79
|
* `controls="none"` turns them off, and `live="off"` (a still, a thumbnail) starts without them (`controls` with no value brings them back). `zoom-min` and `zoom-max` set the range (0.1 to 50 for the line drawing; for the shaded looks 0.1 up to where the body's detail runs out, 8 at least and 1000 at most: see the close zoom guide); a `<kazoku-view-controls for="...">` takes over and reads it.
|
|
79
80
|
* 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.
|
|
80
81
|
* Whatever moves the view, `setView` sends a `wakusei-view` event with its `yaw`, `tilt`, `roll`, `zoom`, `panX` and `panY`.
|
|
82
|
+
* `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` and `-fallback-font` beside it, and the `bodyLabel` property takes the same as an object: see the guide "A name on the body".
|
|
81
83
|
* 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
|
|
82
84
|
* `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
|
|
83
85
|
* `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.
|
|
@@ -94,7 +96,7 @@ const TEMPLATE = `<style>
|
|
|
94
96
|
* ```
|
|
95
97
|
*/
|
|
96
98
|
export class WakuseiBody extends HTMLElement {
|
|
97
|
-
static observedAttributes = ["body", "star", "quality", ...STAR_ATTRS, "look", "size", "time", "tilt", "pitch", "phase", "meridian", "turn", "rate", "moons", "range", "scale-to", "span-km", "fit", "live", "texture-base", "texture-far-base", "tiles", "data", "lang", "labels"];
|
|
99
|
+
static observedAttributes = ["body", "star", "quality", ...STAR_ATTRS, "look", "size", "time", "tilt", "pitch", "phase", "meridian", "turn", "rate", "moons", "range", "scale-to", "span-km", "fit", "live", "texture-base", "texture-far-base", "tiles", "data", "lang", "labels", ...NAME_LABEL_ATTRIBUTES];
|
|
98
100
|
#stage;
|
|
99
101
|
#state = "line";
|
|
100
102
|
#renderer;
|
|
@@ -135,6 +137,7 @@ export class WakuseiBody extends HTMLElement {
|
|
|
135
137
|
#limitKey = "";
|
|
136
138
|
#tileLevels;
|
|
137
139
|
#tiles;
|
|
140
|
+
#bodyLabel;
|
|
138
141
|
#door = createDoorHost(this, {
|
|
139
142
|
own: () => {
|
|
140
143
|
// the body's own pictures and, where a window of the package's own tiles is on it, those
|
|
@@ -241,13 +244,25 @@ export class WakuseiBody extends HTMLElement {
|
|
|
241
244
|
get look() {
|
|
242
245
|
return readLook(this.getAttribute("look"));
|
|
243
246
|
}
|
|
247
|
+
/**
|
|
248
|
+
* The name written on the body's globe in the shaded looks, as an object (`{ look: "painted", strength: 0.5, repeat: "once", latitude: 0, facing: false, font: "Michroma", fallbackFont: "" }`), or `null` for none.
|
|
249
|
+
* Set, it takes the place of the `body-label` attributes; set to `undefined` the attributes are read again. The text is the body's own name in the element's `lang`, in capitals in English.
|
|
250
|
+
*/
|
|
251
|
+
get bodyLabel() {
|
|
252
|
+
return this.#bodyLabel !== undefined ? this.#bodyLabel : readNameLabel(this);
|
|
253
|
+
}
|
|
254
|
+
set bodyLabel(value) {
|
|
255
|
+
this.#bodyLabel = value;
|
|
256
|
+
this.#lastAnchors = -1;
|
|
257
|
+
this.#queue();
|
|
258
|
+
}
|
|
244
259
|
/** What the element is doing now. */
|
|
245
260
|
get state() {
|
|
246
261
|
return this.#state;
|
|
247
262
|
}
|
|
248
263
|
/** Numbers for a test or a status line: the state, the texture width in use and the renderer's own counts. */
|
|
249
264
|
get stats() {
|
|
250
|
-
return { state: this.#state, textureWidth: this.#textureWidth, anchors: this.#live.anchors, renderer: this.#renderer?.stats, tiles: this.#view?.scene?.detail ?? this.#tiles, zoomMax: this.#hands?.controller.limits.zoomMax };
|
|
265
|
+
return { state: this.#state, textureWidth: this.#textureWidth, anchors: this.#live.anchors, renderer: this.#renderer?.stats, tiles: this.#view?.scene?.detail ?? this.#tiles, zoomMax: this.#hands?.controller.limits.zoomMax, label: this.#view?.scene?.label ?? null };
|
|
251
266
|
}
|
|
252
267
|
connectedCallback() {
|
|
253
268
|
const root = this.shadowRoot ?? this.attachShadow({ mode: "open" });
|
|
@@ -509,7 +524,13 @@ export class WakuseiBody extends HTMLElement {
|
|
|
509
524
|
const r = this.#request();
|
|
510
525
|
const extent = this.#extent(r.moons);
|
|
511
526
|
const moons = r.moons ? this.#moonsOf(frame, extent, tiltBy, roll) : undefined;
|
|
512
|
-
|
|
527
|
+
const label = this.#labelNow();
|
|
528
|
+
return { pose, extent, sky: frame.time !== undefined, zoom: this.#zoom, panX: clampPan(this.#panX, extent, this.#zoom), panY: clampPan(this.#panY, extent, this.#zoom), moons, label };
|
|
529
|
+
}
|
|
530
|
+
/** The name on the globe the attributes or the property ask for, with its text in the element's language. */
|
|
531
|
+
#labelNow() {
|
|
532
|
+
const options = this.bodyLabel;
|
|
533
|
+
return options === null ? null : { ...options, text: nameLabelText(this.#facts().name, this.getAttribute("lang") === "ja" ? "ja" : "en") };
|
|
513
534
|
}
|
|
514
535
|
/** Body radii from the middle of the picture to its edge at zoom 1, for the attributes now. */
|
|
515
536
|
#extent(moons) {
|
|
@@ -733,7 +754,7 @@ export class WakuseiBody extends HTMLElement {
|
|
|
733
754
|
}
|
|
734
755
|
#key(state) {
|
|
735
756
|
const moons = (state.moons ?? []).map((m) => `${m.id}:${m.x.toFixed(1)},${m.y.toFixed(1)}`).join(";");
|
|
736
|
-
return `${this.#star()?.key ?? this.body}|${this.look}|${vectorKey(state.pose.pole)}|${vectorKey(state.pose.meridian)}|${vectorKey(state.pose.light)}|${state.extent.toFixed(2)}|${state.zoom.toFixed(2)}|${state.panX.toFixed(2)},${state.panY.toFixed(2)}|${moons}`;
|
|
757
|
+
return `${this.#star()?.key ?? this.body}|${this.look}|${vectorKey(state.pose.pole)}|${vectorKey(state.pose.meridian)}|${vectorKey(state.pose.light)}|${state.extent.toFixed(2)}|${state.zoom.toFixed(2)}|${state.panX.toFixed(2)},${state.panY.toFixed(2)}|${moons}|${state.label ? nameLabelKey(state.label.text, state.label) : ""}`;
|
|
737
758
|
}
|
|
738
759
|
// Replacing a view keeps the renderer lease; leaving 3D gives it back.
|
|
739
760
|
#disposeView(releaseRenderer = false) {
|
package/dist/scene/body.d.ts
CHANGED
|
@@ -7,9 +7,10 @@ import type { SourceBook } from "../door/book.ts";
|
|
|
7
7
|
import type { BodyMapSource } from "../door/map.ts";
|
|
8
8
|
import { type DetailStats } from "./detail.ts";
|
|
9
9
|
import type { TileLevel } from "./tiles.ts";
|
|
10
|
+
import { type NameLabelOptions } from "./name-label.ts";
|
|
10
11
|
export { fallbackLook } from "./fallback.ts";
|
|
11
|
-
/** The parts of three.js the bodies use: a page may hand over a module with only these (see `setThreeLoader`). */
|
|
12
|
-
export type ThreeParts = Pick<typeof THREE, "AdditiveBlending" | "BufferAttribute" | "BufferGeometry" | "ClampToEdgeWrapping" | "DataTexture" | "DoubleSide" | "Group" | "Line" | "LineBasicMaterial" | "LineSegments" | "LinearFilter" | "Mesh" | "NoColorSpace" | "OrthographicCamera" | "PlaneGeometry" | "RepeatWrapping" | "RGBAFormat" | "RingGeometry" | "Scene" | "ShaderMaterial" | "SphereGeometry" | "TextureLoader" | "Vector2" | "Vector3" | "WebGLRenderer"
|
|
12
|
+
/** The parts of three.js the bodies use: a page may hand over a module with only these (see `setThreeLoader`). `CanvasTexture`, `SRGBColorSpace` and `NormalBlending` are needed only for a name written on a body (`body-label`). */
|
|
13
|
+
export type ThreeParts = Pick<typeof THREE, "AdditiveBlending" | "BufferAttribute" | "BufferGeometry" | "ClampToEdgeWrapping" | "DataTexture" | "DoubleSide" | "Group" | "Line" | "LineBasicMaterial" | "LineSegments" | "LinearFilter" | "Mesh" | "NoColorSpace" | "OrthographicCamera" | "PlaneGeometry" | "RepeatWrapping" | "RGBAFormat" | "RingGeometry" | "Scene" | "ShaderMaterial" | "SphereGeometry" | "TextureLoader" | "Vector2" | "Vector3" | "WebGLRenderer"> & Partial<Pick<typeof THREE, "CanvasTexture" | "SRGBColorSpace" | "NormalBlending">>;
|
|
13
14
|
/** One moon in a system view: its place in planet radii (viewer's frame) and the points of its orbit, if they changed. */
|
|
14
15
|
export interface MoonDraw {
|
|
15
16
|
id: BodyId;
|
|
@@ -34,6 +35,10 @@ export interface SceneState {
|
|
|
34
35
|
minMoonPx?: number;
|
|
35
36
|
/** The colour of the orbit lines, `#rrggbb`. */
|
|
36
37
|
orbitColour?: string;
|
|
38
|
+
/** The body's name written on its globe: the text and the look, or none. */
|
|
39
|
+
label?: ({
|
|
40
|
+
text: string;
|
|
41
|
+
} & NameLabelOptions) | null;
|
|
37
42
|
}
|
|
38
43
|
/** The scene the shared renderer draws, with the one call that moves it. */
|
|
39
44
|
export interface BodyScene extends Scene3D {
|
|
@@ -43,6 +48,12 @@ export interface BodyScene extends Scene3D {
|
|
|
43
48
|
readonly painted: boolean;
|
|
44
49
|
/** The window of finer map on the body, or `undefined` for a body with none (a glowing one, or one with no painted map). */
|
|
45
50
|
readonly detail: DetailStats | undefined;
|
|
51
|
+
/** The name on the globe now: whether it is drawn (made, its font in, and the body big enough), its text, and its turn about the pole in radians (for `facing`); `null` for none. */
|
|
52
|
+
readonly label: {
|
|
53
|
+
shown: boolean;
|
|
54
|
+
text: string;
|
|
55
|
+
turn: number;
|
|
56
|
+
} | null;
|
|
46
57
|
}
|
|
47
58
|
export interface BodyItemOptions {
|
|
48
59
|
id: BodyId;
|
package/dist/scene/body.js
CHANGED
|
@@ -8,6 +8,7 @@ import { fallbackLook } from "./fallback.js";
|
|
|
8
8
|
import { writeBasis } from "./basis.js";
|
|
9
9
|
import { loadImage } from "./textures.js";
|
|
10
10
|
import { ringStrip } from "./rings.js";
|
|
11
|
+
import { createNameLabel, nameLabelKey } from "./name-label.js";
|
|
11
12
|
export { fallbackLook } from "./fallback.js";
|
|
12
13
|
/** The shader material of a body: its surface code with the look's lighting and glow uniforms. A star made from numbers is drawn with it too (the size line-up). */
|
|
13
14
|
export function makeBodyMaterial(T, look, painted) {
|
|
@@ -353,6 +354,30 @@ export function createBodyItem(options) {
|
|
|
353
354
|
}
|
|
354
355
|
}
|
|
355
356
|
};
|
|
357
|
+
// the name on the globe: a child of the mesh, so it turns with the body
|
|
358
|
+
let label;
|
|
359
|
+
let labelKey = "";
|
|
360
|
+
const syncLabel = (state) => {
|
|
361
|
+
const key = state.label ? nameLabelKey(state.label.text, state.label) : "";
|
|
362
|
+
if (key === labelKey)
|
|
363
|
+
return;
|
|
364
|
+
labelKey = key;
|
|
365
|
+
if (!state.label) {
|
|
366
|
+
if (label !== undefined) {
|
|
367
|
+
mesh.remove(label.object);
|
|
368
|
+
label.dispose();
|
|
369
|
+
label = undefined;
|
|
370
|
+
}
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
const { text, ...rest } = state.label;
|
|
374
|
+
if (label === undefined) {
|
|
375
|
+
label = createNameLabel(T, text, rest, look.emissive === true, () => options.redraw());
|
|
376
|
+
mesh.add(label.object);
|
|
377
|
+
}
|
|
378
|
+
else
|
|
379
|
+
label.set(text, rest);
|
|
380
|
+
};
|
|
356
381
|
const light = new T.Vector3();
|
|
357
382
|
const pole = new T.Vector3();
|
|
358
383
|
const apply = (state) => {
|
|
@@ -360,6 +385,7 @@ export function createBodyItem(options) {
|
|
|
360
385
|
orient(state);
|
|
361
386
|
frame(state);
|
|
362
387
|
place(state);
|
|
388
|
+
syncLabel(state);
|
|
363
389
|
light.set(...state.pose.light);
|
|
364
390
|
if (ringHalves !== undefined) {
|
|
365
391
|
pole.set(...state.pose.pole);
|
|
@@ -400,6 +426,9 @@ export function createBodyItem(options) {
|
|
|
400
426
|
glow.scale.setScalar(1);
|
|
401
427
|
}
|
|
402
428
|
requestSharperTexture(state);
|
|
429
|
+
// the disc's radius on the screen in CSS pixels: the short side's half at zoom 1 over the extent
|
|
430
|
+
if (label !== undefined)
|
|
431
|
+
label.update(camera, ((aspect >= 1 ? viewHeight : viewWidth) / 2) * (state.zoom / state.extent), state.pose.light);
|
|
403
432
|
if (detail !== undefined && textureWidth > 0) {
|
|
404
433
|
const east = cross(state.pose.pole, state.pose.meridian);
|
|
405
434
|
const ax = facts.axesKm;
|
|
@@ -421,6 +450,10 @@ export function createBodyItem(options) {
|
|
|
421
450
|
get detail() {
|
|
422
451
|
return detail?.stats;
|
|
423
452
|
},
|
|
453
|
+
get label() {
|
|
454
|
+
const inner = label?.object.children[0];
|
|
455
|
+
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
|
+
},
|
|
424
457
|
resize(w, h) {
|
|
425
458
|
viewWidth = w;
|
|
426
459
|
viewHeight = h;
|
|
@@ -438,6 +471,8 @@ export function createBodyItem(options) {
|
|
|
438
471
|
windowUniforms.uDetail.value = null;
|
|
439
472
|
}
|
|
440
473
|
detail?.dispose();
|
|
474
|
+
label?.dispose();
|
|
475
|
+
label = undefined;
|
|
441
476
|
for (const o of orbitLines.values())
|
|
442
477
|
o.line.geometry.dispose();
|
|
443
478
|
orbitMaterial.dispose();
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { type BodyLabelLook, type BodyLabelRepeat, type BodyLabelSize } from "@johnmorrisdotca/kazoku-ui/body-label";
|
|
2
|
+
import type * as THREE from "three";
|
|
3
|
+
import type { ThreeParts } from "./body.ts";
|
|
4
|
+
import type { Vec3 } from "../vec.ts";
|
|
5
|
+
/**
|
|
6
|
+
* The name written on a body's globe: the family's `bodyLabel` property. `look` is the one setting with no default: `painted` (pale letters over the surface), `etched` (the letters lighten the surface), `outline`
|
|
7
|
+
* (the letters' edges) or `burned` (darker letters). The rest fall back to the family's: half strength, the name once, on the equator, turning with the body, in Michroma. The text is the body's own name
|
|
8
|
+
* in the element's language (`EARTH`, `地球`), so it is not a setting here.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts no-run
|
|
12
|
+
* import type { NameLabelOptions } from "@johnmorrisdotca/wakusei-planets/painter";
|
|
13
|
+
*
|
|
14
|
+
* const label: NameLabelOptions = { look: "painted", strength: 0.5, repeat: "both", latitude: 0, facing: false };
|
|
15
|
+
* console.log(label.look);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export interface NameLabelOptions {
|
|
19
|
+
look: BodyLabelLook;
|
|
20
|
+
/** How strongly it shows, 0 to 1. Default 0.5. */
|
|
21
|
+
strength?: number;
|
|
22
|
+
/** `once`, `both` (two, on opposite sides, so one is always in view) or `around` (as many as fit). Default `once`. */
|
|
23
|
+
repeat?: BodyLabelRepeat;
|
|
24
|
+
/** The band's latitude in degrees: 0 is the equator; 55 or -55 is near a pole. Default 0. */
|
|
25
|
+
latitude?: number;
|
|
26
|
+
/** True: the name keeps facing the reader while the body turns under it. Default false. */
|
|
27
|
+
facing?: boolean;
|
|
28
|
+
/** A CSS font family the page has loaded. Default Michroma, which the label fetches itself (64 kB, once). */
|
|
29
|
+
font?: string;
|
|
30
|
+
/** The family for letters `font` has none of, such as Japanese (`"Noto Sans JP"`). Default the page's sans. */
|
|
31
|
+
fallbackFont?: string;
|
|
32
|
+
/** `small`, `medium` or `large`. Default `medium`. */
|
|
33
|
+
size?: BodyLabelSize;
|
|
34
|
+
/** No label while the body is drawn smaller than this many CSS pixels in radius. Default 24. */
|
|
35
|
+
minRadiusPx?: number;
|
|
36
|
+
}
|
|
37
|
+
/** 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"];
|
|
39
|
+
/**
|
|
40
|
+
* The label the family's attributes ask for (`body-label="painted"` and the six beside it), or `null` when `body-label` is absent or not a look.
|
|
41
|
+
*
|
|
42
|
+
* @param el - Anything with `getAttribute` and `hasAttribute`: the element.
|
|
43
|
+
* @returns The options, or `null` for no label.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts no-run
|
|
47
|
+
* import { readNameLabel } from "@johnmorrisdotca/wakusei-planets/painter";
|
|
48
|
+
*
|
|
49
|
+
* const el = document.querySelector("wakusei-body")!;
|
|
50
|
+
* el.setAttribute("body-label", "etched");
|
|
51
|
+
* console.log(readNameLabel(el)?.look);
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function readNameLabel(el: {
|
|
55
|
+
getAttribute(name: string): string | null;
|
|
56
|
+
hasAttribute(name: string): boolean;
|
|
57
|
+
}): NameLabelOptions | null;
|
|
58
|
+
/**
|
|
59
|
+
* The text written for a body: its English name in capitals (the family's look), or its Japanese name as it is.
|
|
60
|
+
*
|
|
61
|
+
* @param name - The body's names, as `BODIES[id].name` holds them.
|
|
62
|
+
* @param lang - `en` (the default) or `ja`.
|
|
63
|
+
* @returns The text to write.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* import { BODIES } from "@johnmorrisdotca/wakusei-planets";
|
|
68
|
+
* import { nameLabelText } from "@johnmorrisdotca/wakusei-planets/painter";
|
|
69
|
+
*
|
|
70
|
+
* console.log(nameLabelText(BODIES.earth.name, "en"), nameLabelText(BODIES.earth.name, "ja"));
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare function nameLabelText(name: {
|
|
74
|
+
en: string;
|
|
75
|
+
ja: string;
|
|
76
|
+
}, lang?: "en" | "ja"): string;
|
|
77
|
+
/** One string that changes whenever the label would be made differently (the text and every setting): for a host that keeps a still for each state. */
|
|
78
|
+
export declare function nameLabelKey(text: string, options: NameLabelOptions | null | undefined): string;
|
|
79
|
+
/** The parts of three.js the label needs beyond the bodies': a page that hands over a subset without them gets no label, and a warning once. */
|
|
80
|
+
export type LabelParts = Pick<typeof THREE, "CanvasTexture" | "SRGBColorSpace" | "NormalBlending">;
|
|
81
|
+
/** What `createNameLabel` returns: the group to add to the body's mesh, and the calls the host makes. */
|
|
82
|
+
export interface NameLabel {
|
|
83
|
+
/** Add it to the body's turning mesh (a radius-1 sphere whose +z is longitude 0). */
|
|
84
|
+
readonly object: THREE.Group;
|
|
85
|
+
/** True once the name is drawn in its font: the host draws its view again when `onReady` is called. */
|
|
86
|
+
readonly ready: boolean;
|
|
87
|
+
/** 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. */
|
|
88
|
+
update(camera: THREE.Camera | undefined, radiusPx: number, light: Vec3): boolean;
|
|
89
|
+
/** New settings or text; the texture is drawn again only when it must be. */
|
|
90
|
+
set(text: string, options: NameLabelOptions): void;
|
|
91
|
+
dispose(): void;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Where Michroma is fetched from, for a page whose bundler does not carry kazoku-ui's font file along with its module (the label looks for it next to the module, `fonts/Michroma-Regular.ttf`). Call it before the
|
|
95
|
+
* first name is written. A page that sets `body-label-font` to a font of its own needs nothing here.
|
|
96
|
+
*
|
|
97
|
+
* @param url - The address of `Michroma-Regular.ttf`, with its `OFL.txt` beside it.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts no-run
|
|
101
|
+
* import { setBodyLabelFontUrl } from "@johnmorrisdotca/wakusei-planets/painter";
|
|
102
|
+
*
|
|
103
|
+
* setBodyLabelFontUrl("/fonts/Michroma-Regular.ttf");
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export declare function setBodyLabelFontUrl(url: string | URL): void;
|
|
107
|
+
/**
|
|
108
|
+
* Make a body's name label. The group is empty until the font is in (at once when it is already loaded); `onReady` is called when the name is drawn, so the host can draw its view again.
|
|
109
|
+
*
|
|
110
|
+
* @param T - The three.js module the bodies use. Without `CanvasTexture`, `SRGBColorSpace` and `NormalBlending` there is no label, and a warning once.
|
|
111
|
+
* @param text - The name as it is written.
|
|
112
|
+
* @param options - The look and the rest.
|
|
113
|
+
* @param emissive - The body glows (the Sun): the name is lit fully, from no direction.
|
|
114
|
+
* @param onReady - Called when the name is drawn, and again when a new font is in.
|
|
115
|
+
*/
|
|
116
|
+
export declare function createNameLabel(T: ThreeParts, text: string, options: NameLabelOptions, emissive: boolean, onReady: () => void): NameLabel;
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
// A body's name written on its own globe (kazoku-ui's shared body label), fitted to this package's bodies: the band is a child of the body's mesh, so it turns with the body, in the frame
|
|
2
|
+
// the bodies' shaders use (longitude 0 along the mesh's +z, east along +x, the pole +y); and it is lit by the same direction the body is, through its own small shader, because the
|
|
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
|
+
import { BODY_LABEL_FONT, createBodyLabel, loadBodyLabelFont } from "@johnmorrisdotca/kazoku-ui/body-label";
|
|
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"];
|
|
7
|
+
const LOOKS = ["painted", "etched", "outline", "burned"];
|
|
8
|
+
const REPEATS = ["once", "both", "around"];
|
|
9
|
+
/**
|
|
10
|
+
* The label the family's attributes ask for (`body-label="painted"` and the six beside it), or `null` when `body-label` is absent or not a look.
|
|
11
|
+
*
|
|
12
|
+
* @param el - Anything with `getAttribute` and `hasAttribute`: the element.
|
|
13
|
+
* @returns The options, or `null` for no label.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts no-run
|
|
17
|
+
* import { readNameLabel } from "@johnmorrisdotca/wakusei-planets/painter";
|
|
18
|
+
*
|
|
19
|
+
* const el = document.querySelector("wakusei-body")!;
|
|
20
|
+
* el.setAttribute("body-label", "etched");
|
|
21
|
+
* console.log(readNameLabel(el)?.look);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function readNameLabel(el) {
|
|
25
|
+
const look = el.getAttribute("body-label");
|
|
26
|
+
if (look === null || !LOOKS.includes(look))
|
|
27
|
+
return null;
|
|
28
|
+
const out = { look: look };
|
|
29
|
+
const strength = Number(el.getAttribute("body-label-strength"));
|
|
30
|
+
if (el.getAttribute("body-label-strength") !== null && Number.isFinite(strength))
|
|
31
|
+
out.strength = Math.max(0, Math.min(1, strength));
|
|
32
|
+
const repeat = el.getAttribute("body-label-repeat");
|
|
33
|
+
if (repeat !== null && REPEATS.includes(repeat))
|
|
34
|
+
out.repeat = repeat;
|
|
35
|
+
const latitude = Number(el.getAttribute("body-label-latitude"));
|
|
36
|
+
if (el.getAttribute("body-label-latitude") !== null && Number.isFinite(latitude))
|
|
37
|
+
out.latitude = latitude;
|
|
38
|
+
if (el.hasAttribute("body-label-facing") && el.getAttribute("body-label-facing") !== "off" && el.getAttribute("body-label-facing") !== "false")
|
|
39
|
+
out.facing = true;
|
|
40
|
+
const font = el.getAttribute("body-label-font");
|
|
41
|
+
if (font !== null && font.trim() !== "")
|
|
42
|
+
out.font = font.trim();
|
|
43
|
+
const fallback = el.getAttribute("body-label-fallback-font");
|
|
44
|
+
if (fallback !== null && fallback.trim() !== "")
|
|
45
|
+
out.fallbackFont = fallback.trim();
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The text written for a body: its English name in capitals (the family's look), or its Japanese name as it is.
|
|
50
|
+
*
|
|
51
|
+
* @param name - The body's names, as `BODIES[id].name` holds them.
|
|
52
|
+
* @param lang - `en` (the default) or `ja`.
|
|
53
|
+
* @returns The text to write.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { BODIES } from "@johnmorrisdotca/wakusei-planets";
|
|
58
|
+
* import { nameLabelText } from "@johnmorrisdotca/wakusei-planets/painter";
|
|
59
|
+
*
|
|
60
|
+
* console.log(nameLabelText(BODIES.earth.name, "en"), nameLabelText(BODIES.earth.name, "ja"));
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export function nameLabelText(name, lang = "en") {
|
|
64
|
+
return lang === "ja" ? name.ja : name.en.toUpperCase();
|
|
65
|
+
}
|
|
66
|
+
/** One string that changes whenever the label would be made differently (the text and every setting): for a host that keeps a still for each state. */
|
|
67
|
+
export function nameLabelKey(text, options) {
|
|
68
|
+
if (!options)
|
|
69
|
+
return "";
|
|
70
|
+
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}`;
|
|
72
|
+
}
|
|
73
|
+
const DEFAULTS = { strength: 0.5, repeat: "once", latitude: 0, facing: false, font: BODY_LABEL_FONT, fallbackFont: "", size: "medium", minRadiusPx: 24 };
|
|
74
|
+
const hasLabelParts = (T) => {
|
|
75
|
+
const parts = T;
|
|
76
|
+
return typeof parts.CanvasTexture === "function" && typeof parts.SRGBColorSpace === "string" && typeof parts.NormalBlending === "number";
|
|
77
|
+
};
|
|
78
|
+
let warned = false;
|
|
79
|
+
/** The name is drawn to a canvas: without one (Node, a worker with no `OffscreenCanvas`) there is no label and nothing to draw. */
|
|
80
|
+
const canDraw = () => typeof document !== "undefined" || typeof OffscreenCanvas !== "undefined";
|
|
81
|
+
const LABEL_VERTEX = /* glsl */ `
|
|
82
|
+
varying vec2 vUv;
|
|
83
|
+
varying vec3 vN;
|
|
84
|
+
void main() {
|
|
85
|
+
vUv = uv;
|
|
86
|
+
vN = normalize(transpose(inverse(mat3(modelMatrix))) * normal);
|
|
87
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
88
|
+
}`;
|
|
89
|
+
// lit as the bodies are: the Sun's direction in the scene's axes, a little wrap past the terminator and a little ambient on the night side, so a name on the night side is dark too
|
|
90
|
+
const LABEL_FRAGMENT = /* glsl */ `
|
|
91
|
+
uniform sampler2D uMap;
|
|
92
|
+
uniform vec3 uLight;
|
|
93
|
+
uniform float uOpacity;
|
|
94
|
+
uniform float uAmbient;
|
|
95
|
+
uniform float uWrap;
|
|
96
|
+
varying vec2 vUv;
|
|
97
|
+
varying vec3 vN;
|
|
98
|
+
void main() {
|
|
99
|
+
vec4 c = texture2D(uMap, vUv);
|
|
100
|
+
float d = dot(normalize(vN), uLight);
|
|
101
|
+
float lit = uAmbient + (1.0 - uAmbient) * clamp((d + uWrap) / (1.0 + uWrap), 0.0, 1.0);
|
|
102
|
+
gl_FragColor = vec4(c.rgb * lit, c.a * uOpacity);
|
|
103
|
+
#include <colorspace_fragment>
|
|
104
|
+
}`;
|
|
105
|
+
/** The three.js the shared label is handed: its own, but with a material lit by the bodies' light instead of three's Lambert (the scenes here have no three.js lights). */
|
|
106
|
+
function litThree(T, emissive) {
|
|
107
|
+
const made = [];
|
|
108
|
+
class LitLabelMaterial extends T.ShaderMaterial {
|
|
109
|
+
constructor(parameters) {
|
|
110
|
+
const { map, ...rest } = parameters;
|
|
111
|
+
super({
|
|
112
|
+
...rest,
|
|
113
|
+
vertexShader: LABEL_VERTEX,
|
|
114
|
+
fragmentShader: LABEL_FRAGMENT,
|
|
115
|
+
uniforms: { uMap: { value: map }, uLight: { value: new T.Vector3(0, 0, 1) }, uOpacity: { value: 1 }, uAmbient: { value: emissive ? 1 : 0.06 }, uWrap: { value: 0.08 } },
|
|
116
|
+
});
|
|
117
|
+
made.push(this);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return { ...T, MeshLambertMaterial: LitLabelMaterial, made };
|
|
121
|
+
}
|
|
122
|
+
const FAR_EYE = { getWorldPosition: (v) => v.set(0, 0, 1e6) };
|
|
123
|
+
let fontLoad;
|
|
124
|
+
let fontUrl;
|
|
125
|
+
/**
|
|
126
|
+
* Where Michroma is fetched from, for a page whose bundler does not carry kazoku-ui's font file along with its module (the label looks for it next to the module, `fonts/Michroma-Regular.ttf`). Call it before the
|
|
127
|
+
* first name is written. A page that sets `body-label-font` to a font of its own needs nothing here.
|
|
128
|
+
*
|
|
129
|
+
* @param url - The address of `Michroma-Regular.ttf`, with its `OFL.txt` beside it.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts no-run
|
|
133
|
+
* import { setBodyLabelFontUrl } from "@johnmorrisdotca/wakusei-planets/painter";
|
|
134
|
+
*
|
|
135
|
+
* setBodyLabelFontUrl("/fonts/Michroma-Regular.ttf");
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
export function setBodyLabelFontUrl(url) {
|
|
139
|
+
fontUrl = url;
|
|
140
|
+
fontLoad = undefined;
|
|
141
|
+
}
|
|
142
|
+
/** Michroma, fetched once from kazoku-ui's own copy (or `setBodyLabelFontUrl`'s), the first time a label in it is made. A fetch that fails leaves the page's sans, and is not tried again. */
|
|
143
|
+
const ensureFont = (font) => (font === BODY_LABEL_FONT && canDraw() ? (fontLoad ??= (fontUrl === undefined ? loadBodyLabelFont() : loadBodyLabelFont(fontUrl)).catch(() => BODY_LABEL_FONT)) : Promise.resolve());
|
|
144
|
+
/**
|
|
145
|
+
* Make a body's name label. The group is empty until the font is in (at once when it is already loaded); `onReady` is called when the name is drawn, so the host can draw its view again.
|
|
146
|
+
*
|
|
147
|
+
* @param T - The three.js module the bodies use. Without `CanvasTexture`, `SRGBColorSpace` and `NormalBlending` there is no label, and a warning once.
|
|
148
|
+
* @param text - The name as it is written.
|
|
149
|
+
* @param options - The look and the rest.
|
|
150
|
+
* @param emissive - The body glows (the Sun): the name is lit fully, from no direction.
|
|
151
|
+
* @param onReady - Called when the name is drawn, and again when a new font is in.
|
|
152
|
+
*/
|
|
153
|
+
export function createNameLabel(T, text, options, emissive, onReady) {
|
|
154
|
+
const group = new T.Group();
|
|
155
|
+
group.name = "name-label";
|
|
156
|
+
// 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
|
+
group.rotation.y = -Math.PI / 2;
|
|
158
|
+
let label;
|
|
159
|
+
let materials = [];
|
|
160
|
+
let wanted = { text, options: { ...DEFAULTS, ...withoutUndefined(options) } };
|
|
161
|
+
let disposed = false;
|
|
162
|
+
let ready = false;
|
|
163
|
+
const light = new T.Vector3(0, 0, 1);
|
|
164
|
+
const able = hasLabelParts(T) && canDraw();
|
|
165
|
+
if (!able && !warned && canDraw()) {
|
|
166
|
+
warned = true;
|
|
167
|
+
console.warn("wakusei-planets: the three.js handed over lacks CanvasTexture, SRGBColorSpace or NormalBlending, so a name cannot be written on a body");
|
|
168
|
+
}
|
|
169
|
+
const make = () => {
|
|
170
|
+
if (disposed || label !== undefined || !able)
|
|
171
|
+
return;
|
|
172
|
+
const lit = litThree(T, emissive);
|
|
173
|
+
label = createBodyLabel(lit, { text: wanted.text, ...wanted.options, radius: 1 });
|
|
174
|
+
materials = lit.made;
|
|
175
|
+
group.add(label.object);
|
|
176
|
+
void label.ready.then(() => {
|
|
177
|
+
if (disposed)
|
|
178
|
+
return;
|
|
179
|
+
ready = true;
|
|
180
|
+
onReady();
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
void ensureFont(wanted.options.font).then(() => {
|
|
184
|
+
if (!disposed)
|
|
185
|
+
make();
|
|
186
|
+
});
|
|
187
|
+
return {
|
|
188
|
+
object: group,
|
|
189
|
+
get ready() {
|
|
190
|
+
return ready;
|
|
191
|
+
},
|
|
192
|
+
update(camera, radiusPx, toLight) {
|
|
193
|
+
if (label === undefined)
|
|
194
|
+
return false;
|
|
195
|
+
light.set(toLight[0], toLight[1], toLight[2]);
|
|
196
|
+
for (const m of materials) {
|
|
197
|
+
const u = m.uniforms;
|
|
198
|
+
u.uLight.value.copy(light);
|
|
199
|
+
u.uOpacity.value = m.opacity;
|
|
200
|
+
}
|
|
201
|
+
return label.update((camera ?? FAR_EYE), radiusPx);
|
|
202
|
+
},
|
|
203
|
+
set(nextText, next) {
|
|
204
|
+
wanted = { text: nextText, options: { ...DEFAULTS, ...withoutUndefined(next) } };
|
|
205
|
+
if (label === undefined)
|
|
206
|
+
return;
|
|
207
|
+
const fontChanged = wanted.options.font !== label.options.font;
|
|
208
|
+
label.set({ text: wanted.text, ...wanted.options });
|
|
209
|
+
if (fontChanged)
|
|
210
|
+
void ensureFont(wanted.options.font).then(() => {
|
|
211
|
+
// the shared label repaints only when a setting changed: the new font arriving after the set is told by setting the font again
|
|
212
|
+
if (!disposed && label !== undefined) {
|
|
213
|
+
label.set({ font: "" });
|
|
214
|
+
label.set({ font: wanted.options.font });
|
|
215
|
+
onReady();
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
},
|
|
219
|
+
dispose() {
|
|
220
|
+
disposed = true;
|
|
221
|
+
if (label !== undefined) {
|
|
222
|
+
group.remove(label.object);
|
|
223
|
+
label.dispose();
|
|
224
|
+
label = undefined;
|
|
225
|
+
}
|
|
226
|
+
materials = [];
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
function withoutUndefined(value) {
|
|
231
|
+
return Object.fromEntries(Object.entries(value).filter(([, v]) => v !== undefined));
|
|
232
|
+
}
|
package/dist/scene/painter.d.ts
CHANGED
|
@@ -5,7 +5,9 @@ import { type Vec3 } from "../vec.ts";
|
|
|
5
5
|
import { type DetailStats } from "./detail.ts";
|
|
6
6
|
import { type TileLevel } from "./tiles.ts";
|
|
7
7
|
import { moonOffset, orientation } from "./orient.ts";
|
|
8
|
+
import { type NameLabelOptions } from "./name-label.ts";
|
|
8
9
|
export { moonOffset, orientation };
|
|
10
|
+
export { nameLabelText, readNameLabel, setBodyLabelFontUrl, type NameLabelOptions } from "./name-label.ts";
|
|
9
11
|
/**
|
|
10
12
|
* 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).
|
|
11
13
|
*
|
|
@@ -54,6 +56,25 @@ export interface PaintContext {
|
|
|
54
56
|
maxTexture?: number;
|
|
55
57
|
/** Told when the finer map tiles' levels for this body are known (`undefined` when it has none), so a view can raise its zoom range. Only called for a painter that has a tile set and a view in `PaintInfo`. */
|
|
56
58
|
onLevels?(levels: readonly TileLevel[] | undefined): void;
|
|
59
|
+
/** The body's name written on its globe (see `PaintLabel`), or none. `setLabel` on the painting changes it later. */
|
|
60
|
+
label?: PaintLabel | null;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The name on a body the painter makes: the family's `NameLabelOptions`, with the language the name is written in (`en`, in capitals, by default) or a `text` of your own instead of the body's name.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts no-run
|
|
67
|
+
* import type { PaintLabel } from "@johnmorrisdotca/wakusei-planets/painter";
|
|
68
|
+
*
|
|
69
|
+
* const label: PaintLabel = { look: "painted", lang: "ja" };
|
|
70
|
+
* console.log(label.lang);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export interface PaintLabel extends NameLabelOptions {
|
|
74
|
+
/** The language of the name: `en` (capitals) or `ja`. Default `en`. */
|
|
75
|
+
lang?: "en" | "ja";
|
|
76
|
+
/** Written instead of the body's name. */
|
|
77
|
+
text?: string;
|
|
57
78
|
}
|
|
58
79
|
/**
|
|
59
80
|
* The camera that draws a body and the size of its view, so the painter can tell which part of the body's surface is in view and lay finer map tiles over it. The camera's world and projection matrices must be
|
|
@@ -119,6 +140,14 @@ export interface Painting {
|
|
|
119
140
|
update(info: PaintInfo): void;
|
|
120
141
|
/** What the window of finer map tiles on this body is doing, or `undefined` for a body with none (a glowing one, one with no painted map, or a painter with no tile set). */
|
|
121
142
|
readonly tiles?: DetailStats;
|
|
143
|
+
/** Write the body's name on its globe, change how, or take it off (`null`). The name is drawn when the font is in, and `context.invalidate` is called then. */
|
|
144
|
+
setLabel(label: PaintLabel | null): void;
|
|
145
|
+
/** The name on the globe now: whether one is drawn (made and big enough on the screen at the last `update`), the text, and the group's turn about the pole in radians (for `facing`). */
|
|
146
|
+
readonly label: {
|
|
147
|
+
shown: boolean;
|
|
148
|
+
text: string;
|
|
149
|
+
turn: number;
|
|
150
|
+
} | null;
|
|
122
151
|
dispose(): void;
|
|
123
152
|
}
|
|
124
153
|
/**
|
package/dist/scene/painter.js
CHANGED
|
@@ -11,7 +11,9 @@ import { detailOf, lookOf } from "./look.js";
|
|
|
11
11
|
import { seenRegion } from "./tiles.js";
|
|
12
12
|
import { moonOffset, orientation } from "./orient.js";
|
|
13
13
|
import { ringStrip } from "./rings.js";
|
|
14
|
+
import { createNameLabel, nameLabelText } from "./name-label.js";
|
|
14
15
|
export { moonOffset, orientation };
|
|
16
|
+
export { nameLabelText, readNameLabel, setBodyLabelFontUrl } from "./name-label.js";
|
|
15
17
|
/**
|
|
16
18
|
* 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).
|
|
17
19
|
*
|
|
@@ -336,9 +338,38 @@ function paint(T, id, context, bases) {
|
|
|
336
338
|
const scaleZ = axes ? axes[0] / facts.radiusKm : 1;
|
|
337
339
|
const light = new T.Vector3();
|
|
338
340
|
const poleVec = new T.Vector3();
|
|
341
|
+
// the name on the globe: a child of the mesh, so it turns with the body; made when asked, drawn once its font is in
|
|
342
|
+
let label;
|
|
343
|
+
let labelText = "";
|
|
344
|
+
let labelShown = false;
|
|
345
|
+
const setLabel = (next) => {
|
|
346
|
+
if (next === null || next === undefined || gone) {
|
|
347
|
+
if (label !== undefined) {
|
|
348
|
+
mesh.remove(label.object);
|
|
349
|
+
label.dispose();
|
|
350
|
+
label = undefined;
|
|
351
|
+
labelShown = false;
|
|
352
|
+
}
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
const { lang, text, ...options } = next;
|
|
356
|
+
labelText = text ?? nameLabelText(facts.name, lang ?? "en");
|
|
357
|
+
if (label === undefined) {
|
|
358
|
+
label = createNameLabel(T, labelText, options, look.emissive === true, redraw);
|
|
359
|
+
mesh.add(label.object);
|
|
360
|
+
}
|
|
361
|
+
else
|
|
362
|
+
label.set(labelText, options);
|
|
363
|
+
};
|
|
364
|
+
if (context.label)
|
|
365
|
+
setLabel(context.label);
|
|
339
366
|
return {
|
|
340
367
|
object: group,
|
|
341
368
|
...(look.emissive === true ? { billboard: true } : {}),
|
|
369
|
+
setLabel,
|
|
370
|
+
get label() {
|
|
371
|
+
return label === undefined ? null : { shown: labelShown, text: labelText, turn: label.object.children[0] !== undefined ? label.object.children[0].rotation.y : 0 };
|
|
372
|
+
},
|
|
342
373
|
get tiles() {
|
|
343
374
|
return detail?.stats;
|
|
344
375
|
},
|
|
@@ -377,9 +408,14 @@ function paint(T, id, context, bases) {
|
|
|
377
408
|
ringMaterial.uniforms.uScale.value = scale;
|
|
378
409
|
}
|
|
379
410
|
keepSized(info.radiusPx);
|
|
411
|
+
if (label !== undefined) {
|
|
412
|
+
label.update(info.view?.camera, info.radiusPx, info.toSun);
|
|
413
|
+
labelShown = label.object.children[0] !== undefined && label.object.children[0].visible;
|
|
414
|
+
}
|
|
380
415
|
},
|
|
381
416
|
dispose() {
|
|
382
417
|
gone = true;
|
|
418
|
+
setLabel(null);
|
|
383
419
|
if (windowUniforms !== undefined) {
|
|
384
420
|
windowUniforms.uDetailOn.value = 0;
|
|
385
421
|
windowUniforms.uDetail.value = null;
|
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.34.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.34.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
|
@@ -2,6 +2,7 @@ import { type ViewController } from "@johnmorrisdotca/kazoku-ui/view-controls";
|
|
|
2
2
|
import "../tables/minor.ts";
|
|
3
3
|
import { type BodyId } from "../facts.ts";
|
|
4
4
|
import { type SpaceKind } from "./bodies.ts";
|
|
5
|
+
import { type NameLabelOptions } from "../scene/name-label.ts";
|
|
5
6
|
import type { Credit, DataSource } from "../data-door.ts";
|
|
6
7
|
import { type DoorHost } from "../door/host.ts";
|
|
7
8
|
import { setThreeLoader } from "../scene/shared.ts";
|
|
@@ -128,6 +129,12 @@ export declare class WakuseiSpace extends HTMLElement {
|
|
|
128
129
|
connectedCallback(): void;
|
|
129
130
|
disconnectedCallback(): void;
|
|
130
131
|
attributeChangedCallback(name: string, _old: string | null, value: string | null): void;
|
|
132
|
+
/**
|
|
133
|
+
* The name written on each body's globe (`{ look: "painted", strength: 0.5, repeat: "once", latitude: 0, facing: false, font: "Michroma", fallbackFont: "" }`), or `null` for none. Set, it takes the place of the
|
|
134
|
+
* `body-label` attributes; set to `undefined` the attributes are read again. The text is each body's own name in the element's `lang` (capitals in English). A body too small on the screen (24 CSS pixels of radius by default) carries none.
|
|
135
|
+
*/
|
|
136
|
+
get bodyLabel(): NameLabelOptions | null;
|
|
137
|
+
set bodyLabel(value: NameLabelOptions | null | undefined);
|
|
131
138
|
/** The home place the camera starts above, as longitude and latitude in degrees. */
|
|
132
139
|
get centre(): {
|
|
133
140
|
lon: number;
|
|
@@ -325,6 +332,15 @@ export declare class WakuseiSpace extends HTMLElement {
|
|
|
325
332
|
retrograde: boolean;
|
|
326
333
|
arcTurn: [number, number, number];
|
|
327
334
|
} | null;
|
|
335
|
+
/** The names on the globes at the last draw: how many are drawn (made, their font in, and the body big enough on the screen), and the one on the body looked at (its text and its turn about the pole in radians), or null. */
|
|
336
|
+
bodyLabels: {
|
|
337
|
+
count: number;
|
|
338
|
+
focus: {
|
|
339
|
+
shown: boolean;
|
|
340
|
+
text: string;
|
|
341
|
+
turn: number;
|
|
342
|
+
} | null;
|
|
343
|
+
};
|
|
328
344
|
};
|
|
329
345
|
/** 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. */
|
|
330
346
|
placeOf(id: BodyId): BodyPlace | null;
|
package/dist/space/element.js
CHANGED
|
@@ -7,6 +7,7 @@ import { createGameClock } from "./clock.js";
|
|
|
7
7
|
import { bodyKindOf, findBody, hopFrom, hostOf, HOP_ORDER } from "./bodies.js";
|
|
8
8
|
import { chooseLabels } from "./labels.js";
|
|
9
9
|
import { createPainter } from "../scene/painter.js";
|
|
10
|
+
import { NAME_LABEL_ATTRIBUTES, readNameLabel } from "../scene/name-label.js";
|
|
10
11
|
import { createDoorHost } from "../door/host.js";
|
|
11
12
|
import { ownCredit } from "../door/own.js";
|
|
12
13
|
import { setThreeLoader, takeRenderer } from "../scene/shared.js";
|
|
@@ -85,7 +86,7 @@ const STYLE = `<style>:host{display:block;aspect-ratio:1/1;position:relative;ove
|
|
|
85
86
|
* ```
|
|
86
87
|
*/
|
|
87
88
|
export class WakuseiSpace extends HTMLElement {
|
|
88
|
-
static observedAttributes = ["center", "time", "speed", "scale", "labels", "orbits", "help", "look", "light", "lang", "data", "arrows"];
|
|
89
|
+
static observedAttributes = ["center", "time", "speed", "scale", "labels", "orbits", "help", "look", "light", "lang", "data", "arrows", ...NAME_LABEL_ATTRIBUTES];
|
|
89
90
|
#model = newSpaceModel();
|
|
90
91
|
#clock = createGameClock("now", 1);
|
|
91
92
|
#view;
|
|
@@ -137,6 +138,7 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
137
138
|
this.#model.help = this.hasAttribute("help") && this.getAttribute("help") !== "off";
|
|
138
139
|
this.#model.look = this.getAttribute("look") === "painted" ? "painted" : "realistic";
|
|
139
140
|
this.#model.light = readLight(this.getAttribute("light"));
|
|
141
|
+
this.#relabel();
|
|
140
142
|
this.#door.book.ownOnly(this.getAttribute("data") === "own");
|
|
141
143
|
this.#model.stepMs = Math.max(1000, Math.abs(this.#clock.speed) * 1000);
|
|
142
144
|
if (!this.hasAttribute("role"))
|
|
@@ -235,7 +237,29 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
235
237
|
for (const [id, button] of this.#pool)
|
|
236
238
|
this.#nameLabel(button, id);
|
|
237
239
|
this.#nameScale();
|
|
240
|
+
this.#relabel();
|
|
238
241
|
}
|
|
242
|
+
else if (NAME_LABEL_ATTRIBUTES.includes(name))
|
|
243
|
+
this.#relabel();
|
|
244
|
+
}
|
|
245
|
+
#bodyLabel;
|
|
246
|
+
/**
|
|
247
|
+
* The name written on each body's globe (`{ look: "painted", strength: 0.5, repeat: "once", latitude: 0, facing: false, font: "Michroma", fallbackFont: "" }`), or `null` for none. Set, it takes the place of the
|
|
248
|
+
* `body-label` attributes; set to `undefined` the attributes are read again. The text is each body's own name in the element's `lang` (capitals in English). A body too small on the screen (24 CSS pixels of radius by default) carries none.
|
|
249
|
+
*/
|
|
250
|
+
get bodyLabel() {
|
|
251
|
+
return this.#bodyLabel !== undefined ? this.#bodyLabel : readNameLabel(this);
|
|
252
|
+
}
|
|
253
|
+
set bodyLabel(value) {
|
|
254
|
+
this.#bodyLabel = value;
|
|
255
|
+
this.#relabel();
|
|
256
|
+
}
|
|
257
|
+
/** Tell the scene the name on the globes changed (the attributes, the property or the language): each body is told once at the next draw. */
|
|
258
|
+
#relabel() {
|
|
259
|
+
const options = this.bodyLabel;
|
|
260
|
+
this.#model.label = options === null ? null : { ...options, lang: this.getAttribute("lang") === "ja" ? "ja" : "en" };
|
|
261
|
+
this.#model.labelVersion += 1;
|
|
262
|
+
this.#gate?.request();
|
|
239
263
|
}
|
|
240
264
|
/** The home place the camera starts above, as longitude and latitude in degrees. */
|
|
241
265
|
get centre() {
|
|
@@ -643,6 +667,7 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
643
667
|
arrows: Object.fromEntries(Object.entries(this.#model.arrows).map(([id, list]) => [id, list.map((a) => ({ position: [...a.position], direction: [...a.direction] }))])),
|
|
644
668
|
arrowPx: this.#model.arrowPx,
|
|
645
669
|
help: this.#model.helpDrawn ? { body: this.#model.helpDrawn.body, axis: [...this.#model.helpDrawn.axis], pole: [...this.#model.helpDrawn.pole], retrograde: this.#model.helpDrawn.retrograde, arcTurn: [...this.#model.helpDrawn.arcTurn] } : null,
|
|
670
|
+
bodyLabels: { count: this.#model.labelsDrawn.count, focus: this.#model.labelsDrawn.focus === null ? null : { ...this.#model.labelsDrawn.focus } },
|
|
646
671
|
};
|
|
647
672
|
}
|
|
648
673
|
// --- the game clock ----------------------------------------------------------------------------------------------------------------------------
|
package/dist/space/scene.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Item3D } from "@johnmorrisdotca/kazoku-ui/renderer";
|
|
|
3
3
|
import { type BodyId, type MoonId } from "../facts.ts";
|
|
4
4
|
import type { ThreeParts } from "../scene/body.ts";
|
|
5
5
|
import type { SourceBook } from "../door/book.ts";
|
|
6
|
-
import { type WakuseiPainter } from "../scene/painter.ts";
|
|
6
|
+
import { type PaintLabel, type WakuseiPainter } from "../scene/painter.ts";
|
|
7
7
|
import "../bodies/all.ts";
|
|
8
8
|
import type { Vec3 } from "../vec.ts";
|
|
9
9
|
import { type OrbitArrow } from "./arrows.ts";
|
|
@@ -157,6 +157,18 @@ export interface SpaceModel {
|
|
|
157
157
|
help: boolean;
|
|
158
158
|
/** How many arrowheads each orbit line carries: 0 to `MAX_ARROWS_PER_ORBIT`, two by default. */
|
|
159
159
|
arrowCount: number;
|
|
160
|
+
/** The name written on each body's globe, or null for none; `labelVersion` goes up whenever it (or the language) changes, so each body is told once. */
|
|
161
|
+
label: PaintLabel | null;
|
|
162
|
+
labelVersion: number;
|
|
163
|
+
/** The names on the globes at the last draw: how many are drawn (made, their font in, and big enough on the screen), and the one on the body looked at, or null. */
|
|
164
|
+
labelsDrawn: {
|
|
165
|
+
count: number;
|
|
166
|
+
focus: {
|
|
167
|
+
shown: boolean;
|
|
168
|
+
text: string;
|
|
169
|
+
turn: number;
|
|
170
|
+
} | null;
|
|
171
|
+
};
|
|
160
172
|
/** 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. */
|
|
161
173
|
arrowPx: number;
|
|
162
174
|
/** What the help arrow drew at the last draw, or null: the body, the axis it spins about (right-hand rule), the north pole, and the axis the drawn arc itself turns about (measured from its points). */
|
package/dist/space/scene.js
CHANGED
|
@@ -68,6 +68,9 @@ export const newSpaceModel = () => ({
|
|
|
68
68
|
help: false,
|
|
69
69
|
arrowPx: 0,
|
|
70
70
|
arrowCount: ARROWS_PER_ORBIT,
|
|
71
|
+
label: null,
|
|
72
|
+
labelVersion: 0,
|
|
73
|
+
labelsDrawn: { count: 0, focus: null },
|
|
71
74
|
helpDrawn: null,
|
|
72
75
|
door: { points: 0, used: {} },
|
|
73
76
|
lookups: 0,
|
|
@@ -136,12 +139,13 @@ export function createSpaceItem(model, deps) {
|
|
|
136
139
|
empty(slot);
|
|
137
140
|
slot.look = model.look;
|
|
138
141
|
try {
|
|
139
|
-
const made = deps.painter().make(three, id, { look: model.look, mapped: true, invalidate: () => deps.invalidate(), ratio: model.ratio(), maxTexture: deps.cap() });
|
|
142
|
+
const made = deps.painter().make(three, id, { look: model.look, mapped: true, invalidate: () => deps.invalidate(), ratio: model.ratio(), maxTexture: deps.cap(), label: model.label });
|
|
140
143
|
if (ended) {
|
|
141
144
|
made.dispose();
|
|
142
145
|
return;
|
|
143
146
|
}
|
|
144
147
|
slot.drawing = made;
|
|
148
|
+
slot.labelled = model.labelVersion;
|
|
145
149
|
scene.add(made.object);
|
|
146
150
|
}
|
|
147
151
|
catch (error) {
|
|
@@ -152,9 +156,16 @@ export function createSpaceItem(model, deps) {
|
|
|
152
156
|
const slotOf = (id) => {
|
|
153
157
|
let slot = slots.get(id);
|
|
154
158
|
if (!slot)
|
|
155
|
-
slots.set(id, (slot = { drawing: undefined, look: null, failed: false }));
|
|
159
|
+
slots.set(id, (slot = { drawing: undefined, look: null, failed: false, labelled: -1 }));
|
|
156
160
|
return slot;
|
|
157
161
|
};
|
|
162
|
+
/** A body whose name setting changed since it was made is told the new one (once). */
|
|
163
|
+
const relabel = (slot) => {
|
|
164
|
+
if (slot.drawing === undefined || slot.labelled === model.labelVersion)
|
|
165
|
+
return;
|
|
166
|
+
slot.labelled = model.labelVersion;
|
|
167
|
+
slot.drawing.setLabel(model.label);
|
|
168
|
+
};
|
|
158
169
|
// each line has its colour and a fade (the fourth number of the colour) at every point, so that near the body looked at the part of a line that would cross it is let go
|
|
159
170
|
const orbits = new Map();
|
|
160
171
|
for (const id of ORBIT_BODIES) {
|
|
@@ -461,6 +472,7 @@ export function createSpaceItem(model, deps) {
|
|
|
461
472
|
continue;
|
|
462
473
|
}
|
|
463
474
|
fill(id, slot);
|
|
475
|
+
relabel(slot);
|
|
464
476
|
const drawing = slot.drawing;
|
|
465
477
|
if (!drawing)
|
|
466
478
|
continue;
|
|
@@ -630,10 +642,11 @@ export function createSpaceItem(model, deps) {
|
|
|
630
642
|
continue;
|
|
631
643
|
let held = moonSlots.get(key);
|
|
632
644
|
if (!held)
|
|
633
|
-
moonSlots.set(key, (held = { slot: { drawing: undefined, look: null, failed: false }, seen: now }));
|
|
645
|
+
moonSlots.set(key, (held = { slot: { drawing: undefined, look: null, failed: false, labelled: -1 }, seen: now }));
|
|
634
646
|
held.seen = now;
|
|
635
647
|
seen.add(key);
|
|
636
648
|
fill(key, held.slot);
|
|
649
|
+
relabel(held.slot);
|
|
637
650
|
const drawing = held.slot.drawing;
|
|
638
651
|
if (!drawing)
|
|
639
652
|
continue;
|
|
@@ -672,6 +685,11 @@ export function createSpaceItem(model, deps) {
|
|
|
672
685
|
paintedMoons += 1;
|
|
673
686
|
model.painted.moons = paintedMoons;
|
|
674
687
|
model.painted.held = moonSlots.size;
|
|
688
|
+
let labelsDrawn = 0;
|
|
689
|
+
for (const painting of [...[...slots.values()].map((slot) => slot.drawing), ...[...moonSlots.values()].map((held) => held.slot.drawing)])
|
|
690
|
+
if (painting?.object.visible && painting.label?.shown)
|
|
691
|
+
labelsDrawn += 1;
|
|
692
|
+
model.labelsDrawn = { count: labelsDrawn, focus: (slots.get(focus)?.drawing ?? moonSlots.get(focus)?.slot.drawing)?.label ?? null };
|
|
675
693
|
const tiles = { requested: 0, loading: 0, failed: 0, shown: null };
|
|
676
694
|
for (const painting of [...[...slots.values()].map((slot) => slot.drawing), ...[...moonSlots.values()].map((held) => held.slot.drawing)]) {
|
|
677
695
|
const stats = painting?.tiles;
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.34.0";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.
|
|
1
|
+
export const VERSION = "0.34.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/wakusei-planets",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.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",
|
|
@@ -409,7 +409,7 @@
|
|
|
409
409
|
},
|
|
410
410
|
"packageManager": "pnpm@10.28.0",
|
|
411
411
|
"dependencies": {
|
|
412
|
-
"@johnmorrisdotca/kazoku-ui": "^0.
|
|
412
|
+
"@johnmorrisdotca/kazoku-ui": "^0.37.0"
|
|
413
413
|
},
|
|
414
414
|
"peerDependencies": {
|
|
415
415
|
"@johnmorrisdotca/chikyu-earth": ">=0.10.0",
|