@johnmorrisdotca/chikyu-earth 0.30.0 → 0.32.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 +11 -0
- package/NOTICE.md +4 -0
- package/README.md +73 -1
- package/dist/data-door.d.ts +357 -0
- package/dist/data-door.js +393 -0
- package/dist/door/book.d.ts +118 -0
- package/dist/door/book.js +211 -0
- package/dist/door/elements.d.ts +96 -0
- package/dist/door/elements.js +108 -0
- package/dist/door/host.d.ts +30 -0
- package/dist/door/host.js +44 -0
- package/dist/door/index.d.ts +6 -0
- package/dist/door/index.js +10 -0
- package/dist/door/map.d.ts +165 -0
- package/dist/door/map.js +182 -0
- package/dist/door/own.d.ts +36 -0
- package/dist/door/own.js +75 -0
- package/dist/passes/element.d.ts +18 -0
- package/dist/passes/element.js +67 -5
- package/dist/realistic/body-label.d.ts +113 -0
- package/dist/realistic/body-label.js +171 -0
- package/dist/realistic/earth.d.ts +10 -3
- package/dist/realistic/earth.js +10 -1
- package/dist/realistic/element.d.ts +35 -0
- package/dist/realistic/element.js +107 -5
- package/dist/realistic/index.d.ts +1 -0
- package/dist/realistic/index.js +1 -0
- package/dist/realistic/textures.d.ts +8 -0
- package/dist/realistic/tile-set.d.ts +27 -2
- package/dist/realistic/tile-set.js +155 -49
- package/dist/space/element.d.ts +17 -0
- package/dist/space/element.js +46 -2
- package/dist/space/scene.d.ts +5 -0
- package/dist/space/scene.js +8 -0
- package/package.json +7 -2
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The attributes of the family's body label, in the order a settings panel lists them.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { BODY_LABEL_ATTRIBUTES } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
7
|
+
*
|
|
8
|
+
* console.log(BODY_LABEL_ATTRIBUTES.join(", "));
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export const BODY_LABEL_ATTRIBUTES = ["body-label", "body-label-strength", "body-label-repeat", "body-label-latitude", "body-label-facing", "body-label-font", "body-label-fallback-font"];
|
|
12
|
+
export const newBodyLabelState = () => ({ settings: null, text: "EARTH", drawn: { made: false, showing: false } });
|
|
13
|
+
const LOOKS = ["painted", "etched", "outline", "burned"];
|
|
14
|
+
const REPEATS = ["once", "both", "around"];
|
|
15
|
+
/**
|
|
16
|
+
* What the family's attributes mean: `body-label` (`painted`, `etched`, `outline` or `burned`; present with another value, or none, it is `painted`; absent, no label), `body-label-strength` (0 to 1, 0.5), `body-label-repeat` (`once`, `both` or
|
|
17
|
+
* `around`; `once`), `body-label-latitude` (degrees; 0), `body-label-facing` (present: always facing the reader), `body-label-font` and `body-label-fallback-font`.
|
|
18
|
+
*
|
|
19
|
+
* @param get - Reads an attribute by name, `null` for one that is not there.
|
|
20
|
+
* @returns The settings, or `null` for no label.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { readBodyLabel } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
25
|
+
*
|
|
26
|
+
* const attributes: Record<string, string> = { "body-label": "etched", "body-label-strength": "0.8", "body-label-repeat": "both" };
|
|
27
|
+
* console.log(readBodyLabel((name) => attributes[name] ?? null));
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export function readBodyLabel(get) {
|
|
31
|
+
const look = get("body-label");
|
|
32
|
+
if (look === null)
|
|
33
|
+
return null;
|
|
34
|
+
const strength = get("body-label-strength");
|
|
35
|
+
const latitude = get("body-label-latitude");
|
|
36
|
+
const repeat = get("body-label-repeat") ?? "once";
|
|
37
|
+
const font = get("body-label-font")?.trim();
|
|
38
|
+
const fallback = get("body-label-fallback-font")?.trim();
|
|
39
|
+
const number = (text, fallbackValue) => (text === null || text.trim() === "" || !Number.isFinite(Number(text)) ? fallbackValue : Number(text));
|
|
40
|
+
return {
|
|
41
|
+
look: (LOOKS.includes(look.trim()) ? look.trim() : "painted"),
|
|
42
|
+
strength: Math.min(1, Math.max(0, number(strength, 0.5))),
|
|
43
|
+
repeat: (REPEATS.includes(repeat) ? repeat : "once"),
|
|
44
|
+
latitude: number(latitude, 0),
|
|
45
|
+
facing: get("body-label-facing") !== null && get("body-label-facing") !== "off",
|
|
46
|
+
...(font ? { font } : {}),
|
|
47
|
+
...(fallback ? { fallbackFont: fallback } : {}),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The name written on the Earth: `EARTH`, or `地球` for a Japanese page.
|
|
52
|
+
*
|
|
53
|
+
* @param language - `en` or `ja`.
|
|
54
|
+
* @returns The text.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* import { bodyLabelText } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
59
|
+
*
|
|
60
|
+
* console.log(bodyLabelText("en"), bodyLabelText("ja"));
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export const bodyLabelText = (language) => (language === "ja" ? "地球" : "EARTH");
|
|
64
|
+
let fontUrl;
|
|
65
|
+
/**
|
|
66
|
+
* Where Michroma, the family's font for the name, is fetched from. Left alone it is the file beside the label's own module (`fonts/Michroma-Regular.ttf` in kazoku-ui's `body-label`), which is right where the package is used as it is shipped, or through a
|
|
67
|
+
* bundler that keeps assets beside the code (Vite does); a bundler or a site that moves the module copies the file and says where with this. A page that names its own font (`body-label-font`) never fetches it.
|
|
68
|
+
*
|
|
69
|
+
* @param url - The font file's address, or `undefined` for the default.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts no-run
|
|
73
|
+
* import { setBodyLabelFontUrl } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
74
|
+
*
|
|
75
|
+
* setBodyLabelFontUrl("/fonts/Michroma-Regular.ttf");
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export function setBodyLabelFontUrl(url) {
|
|
79
|
+
fontUrl = url;
|
|
80
|
+
}
|
|
81
|
+
const signatureOf = (state) => (state.settings ? JSON.stringify([state.text, state.settings]) : "");
|
|
82
|
+
/**
|
|
83
|
+
* Makes the layer that keeps the Earth's name on its globe, inside `parent` (the group or mesh that turns with the Earth, a radius of 1). The family's body label is loaded only when the settings first ask for it, and its font (Michroma, 64 kB) only
|
|
84
|
+
* when the page has named no font of its own. All three.js parts the label needs must be in `three` (the full three.js has them); without them `onError` is told once and nothing is drawn.
|
|
85
|
+
*
|
|
86
|
+
* @param three - The page's three.js.
|
|
87
|
+
* @param parent - What turns with the Earth.
|
|
88
|
+
* @param state - The settings and the text, which the element changes.
|
|
89
|
+
* @param deps - `invalidate` asks for a draw; `onError` hears of a label that could not be made.
|
|
90
|
+
* @returns The layer.
|
|
91
|
+
*/
|
|
92
|
+
export function createBodyLabelLayer(three, parent, state, deps) {
|
|
93
|
+
let label = null;
|
|
94
|
+
let loading = false;
|
|
95
|
+
let failed = false;
|
|
96
|
+
let signature = "";
|
|
97
|
+
let gone = false;
|
|
98
|
+
const options = () => {
|
|
99
|
+
const s = state.settings;
|
|
100
|
+
return { text: state.text, look: s.look, strength: s.strength, repeat: s.repeat, latitude: s.latitude, facing: s.facing, ...(s.font ? { font: s.font } : {}), ...(s.fallbackFont ? { fallbackFont: s.fallbackFont } : {}) };
|
|
101
|
+
};
|
|
102
|
+
const remove = () => {
|
|
103
|
+
if (!label)
|
|
104
|
+
return;
|
|
105
|
+
parent.remove(label.object);
|
|
106
|
+
label.dispose();
|
|
107
|
+
label = null;
|
|
108
|
+
signature = "";
|
|
109
|
+
state.drawn = { made: false, showing: false };
|
|
110
|
+
};
|
|
111
|
+
const make = () => {
|
|
112
|
+
loading = true;
|
|
113
|
+
void import("@johnmorrisdotca/kazoku-ui/body-label")
|
|
114
|
+
.then(async (module) => {
|
|
115
|
+
const parts = three;
|
|
116
|
+
for (const name of ["CanvasTexture", "SphereGeometry", "MeshLambertMaterial", "SRGBColorSpace", "NormalBlending", "AdditiveBlending"])
|
|
117
|
+
if (parts[name] === undefined)
|
|
118
|
+
throw new Error(`the three.js handed over has no ${name}, which the name on the Earth needs`);
|
|
119
|
+
if (!state.settings?.font)
|
|
120
|
+
await module.loadBodyLabelFont(fontUrl);
|
|
121
|
+
if (gone || !state.settings) {
|
|
122
|
+
loading = false;
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const made = module.createBodyLabel(three, options());
|
|
126
|
+
parent.add(made.object);
|
|
127
|
+
label = made;
|
|
128
|
+
state.drawn.made = true;
|
|
129
|
+
signature = signatureOf(state);
|
|
130
|
+
loading = false;
|
|
131
|
+
void made.ready.then(() => {
|
|
132
|
+
if (!gone)
|
|
133
|
+
deps.invalidate();
|
|
134
|
+
});
|
|
135
|
+
deps.invalidate();
|
|
136
|
+
})
|
|
137
|
+
.catch((error) => {
|
|
138
|
+
loading = false;
|
|
139
|
+
failed = true;
|
|
140
|
+
deps.onError?.(error);
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
return {
|
|
144
|
+
sync(camera, radiusPx) {
|
|
145
|
+
if (gone)
|
|
146
|
+
return;
|
|
147
|
+
if (!state.settings) {
|
|
148
|
+
remove();
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (!label) {
|
|
152
|
+
if (!loading && !failed)
|
|
153
|
+
make();
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const now = signatureOf(state);
|
|
157
|
+
if (now !== signature) {
|
|
158
|
+
signature = now;
|
|
159
|
+
label.set(options());
|
|
160
|
+
deps.invalidate();
|
|
161
|
+
}
|
|
162
|
+
if (label.update(camera, radiusPx))
|
|
163
|
+
deps.invalidate();
|
|
164
|
+
state.drawn.showing = label.object.visible;
|
|
165
|
+
},
|
|
166
|
+
dispose() {
|
|
167
|
+
gone = true;
|
|
168
|
+
remove();
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
}
|
|
@@ -6,7 +6,8 @@ import { lookAt } from "../view.ts";
|
|
|
6
6
|
import { type SatelliteState } from "../space/satellite-layer.ts";
|
|
7
7
|
import type { Layer } from "./tiers.ts";
|
|
8
8
|
import { type ThreeParts } from "./textures.ts";
|
|
9
|
-
import { type TileSet } from "./tile-set.ts";
|
|
9
|
+
import { type TileSet, type TileSources } from "./tile-set.ts";
|
|
10
|
+
import { type BodyLabelState } from "./body-label.ts";
|
|
10
11
|
import { type MeteorState } from "../meteors/layer.ts";
|
|
11
12
|
export type { ThreeParts };
|
|
12
13
|
type Three = ThreeParts;
|
|
@@ -85,6 +86,8 @@ export interface EarthModel {
|
|
|
85
86
|
ratio(): number;
|
|
86
87
|
/** Meteors seen from space (src/meteors/layer.ts): off unless the element switches them on. */
|
|
87
88
|
meteors: MeteorState;
|
|
89
|
+
/** The name written on the Earth (src/realistic/body-label.ts): off unless the element sets it. */
|
|
90
|
+
bodyLabel: BodyLabelState;
|
|
88
91
|
}
|
|
89
92
|
export interface EarthDeps {
|
|
90
93
|
assets: AssetCache;
|
|
@@ -92,8 +95,8 @@ export interface EarthDeps {
|
|
|
92
95
|
textureBase: () => string;
|
|
93
96
|
/** The widest texture, 4096 at most. */
|
|
94
97
|
cap: () => number;
|
|
95
|
-
/**
|
|
96
|
-
|
|
98
|
+
/** The map source of each layer now (the data door's: a source a page added, else the `tiles` folder), or none: the Earth then keeps the package's own pictures. */
|
|
99
|
+
sources?: () => TileSources;
|
|
97
100
|
/** Told once when the tile set has been read: the width in pixels of the finest level of each of its layers. */
|
|
98
101
|
onTiles?: (layers: Record<string, number>) => void;
|
|
99
102
|
invalidate: () => void;
|
|
@@ -103,6 +106,10 @@ export interface EarthDeps {
|
|
|
103
106
|
air?: () => "full" | "light";
|
|
104
107
|
/** The satellites could not be drawn (the three.js parts handed over lack `Points`). */
|
|
105
108
|
onSatellitesError?: (error: unknown) => void;
|
|
109
|
+
/** The name written on the Earth could not be made (the three.js handed over lacks a part, or the label could not be loaded). */
|
|
110
|
+
onLabelError?: (error: unknown) => void;
|
|
111
|
+
/** Told after the tiles were put right for a draw: what the draw shows from each source is known now. */
|
|
112
|
+
onTiled?: () => void;
|
|
106
113
|
/** Told at the start of every draw, before anything is read for it. */
|
|
107
114
|
onDraw?: () => void;
|
|
108
115
|
/** Told at every draw where the disc is, for what is laid over it (markers). */
|
package/dist/realistic/earth.js
CHANGED
|
@@ -5,6 +5,7 @@ import { greenwichSidereal, subsolarPoint, unitVector } from "./sun.js";
|
|
|
5
5
|
import { createSatelliteLayer, newSatelliteState } from "../space/satellite-layer.js";
|
|
6
6
|
import { createTextureSet } from "./textures.js";
|
|
7
7
|
import { createTileSet } from "./tile-set.js";
|
|
8
|
+
import { createBodyLabelLayer, newBodyLabelState } from "./body-label.js";
|
|
8
9
|
import { createMeteorLayer, newMeteorState } from "../meteors/layer.js";
|
|
9
10
|
const RAD = Math.PI / 180;
|
|
10
11
|
/**
|
|
@@ -38,6 +39,7 @@ export const newModel = () => ({
|
|
|
38
39
|
pick: null,
|
|
39
40
|
ratio: () => Math.min(globalThis.devicePixelRatio || 1, 2),
|
|
40
41
|
meteors: newMeteorState(),
|
|
42
|
+
bodyLabel: newBodyLabelState(),
|
|
41
43
|
});
|
|
42
44
|
/**
|
|
43
45
|
* The disc's radius in CSS pixels in a box of `width` x `height` at `zoom`: it fits the glow in the box at 1x.
|
|
@@ -159,7 +161,7 @@ export function createEarthItem(model, deps) {
|
|
|
159
161
|
});
|
|
160
162
|
const turned = new three.Group();
|
|
161
163
|
const earth = new three.Mesh(grid, surface);
|
|
162
|
-
const tiles = createTileSet(three, turned, { sunDir, lights: surface.uniforms["lights"], boost: surface.uniforms["boost"], ortho: surface.uniforms["ortho"], water: uniform.water, night: uniform.night, extra: { cloudMap: uniform.clouds, sunLocal, cloudShift } }, { assets: deps.assets,
|
|
164
|
+
const tiles = createTileSet(three, turned, { sunDir, lights: surface.uniforms["lights"], boost: surface.uniforms["boost"], ortho: surface.uniforms["ortho"], water: uniform.water, night: uniform.night, extra: { cloudMap: uniform.clouds, sunLocal, cloudShift } }, { assets: deps.assets, sources: () => deps.sources?.() ?? {}, cap: deps.cap, invalidate: deps.invalidate, ...(deps.onTiles ? { onManifest: deps.onTiles } : {}) });
|
|
163
165
|
model.tiles = tiles;
|
|
164
166
|
const clouds = new three.Mesh(grid, cloudMaterial);
|
|
165
167
|
clouds.scale.setScalar(CLOUD_RADIUS);
|
|
@@ -183,6 +185,7 @@ export function createEarthItem(model, deps) {
|
|
|
183
185
|
// the meteors: made the first time they are switched on, and asking for their own next draw while a streak is alive or one is due
|
|
184
186
|
let meteors = null;
|
|
185
187
|
let meteorTimer;
|
|
188
|
+
let nameOn = null;
|
|
186
189
|
return {
|
|
187
190
|
scene,
|
|
188
191
|
camera,
|
|
@@ -226,6 +229,11 @@ export function createEarthItem(model, deps) {
|
|
|
226
229
|
model.drawn = { view: { ...view }, time: model.time, radius, centre: { ...centre } };
|
|
227
230
|
textures.sync(radius * model.ratio());
|
|
228
231
|
tiles.sync({ lon: look.lon, lat: look.lat, width: size.width, height: size.height, panX: view.panX, panY: view.panY, radius }, [sunDir.value.x, sunDir.value.y, sunDir.value.z], true, model.ratio());
|
|
232
|
+
deps.onTiled?.();
|
|
233
|
+
// the name written on the Earth: the layer is made the first time the settings ask for it, and keeps itself right
|
|
234
|
+
if (model.bodyLabel.settings && !nameOn)
|
|
235
|
+
nameOn = createBodyLabelLayer(three, turned, model.bodyLabel, { invalidate: deps.invalidate, ...(deps.onLabelError ? { onError: deps.onLabelError } : {}) });
|
|
236
|
+
nameOn?.sync(camera, radius);
|
|
229
237
|
deps.onPose?.({ lon: look.lon, lat: look.lat, radius, cx: size.width / 2 + view.panX, cy: size.height / 2 + view.panY, width: size.width, height: size.height });
|
|
230
238
|
if (model.meteors.on && !meteors)
|
|
231
239
|
meteors = createMeteorLayer(three, turned, model.meteors);
|
|
@@ -244,6 +252,7 @@ export function createEarthItem(model, deps) {
|
|
|
244
252
|
model.pick = null;
|
|
245
253
|
clearTimeout(meteorTimer);
|
|
246
254
|
meteors?.dispose();
|
|
255
|
+
nameOn?.dispose();
|
|
247
256
|
model.tiles = null;
|
|
248
257
|
tiles.dispose();
|
|
249
258
|
textures.dispose();
|
|
@@ -3,6 +3,8 @@ import type { GeoPoint, GlobeView } from "../types.ts";
|
|
|
3
3
|
import { type CameraMode, type LightMode } from "./earth.ts";
|
|
4
4
|
import type { SatelliteInfo, SatelliteRef, Satellites } from "../satellites/types.ts";
|
|
5
5
|
import { type SatelliteStyle } from "../space/satellite-layer.ts";
|
|
6
|
+
import type { Credit, DataSource } from "../data-door.ts";
|
|
7
|
+
import { type BodyLabelSettings } from "./body-label.ts";
|
|
6
8
|
import { setSharedRenderer, setThreeLoader } from "./shared.ts";
|
|
7
9
|
export { setSharedRenderer, setThreeLoader };
|
|
8
10
|
export type { CameraMode };
|
|
@@ -122,8 +124,34 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
|
|
|
122
124
|
*/
|
|
123
125
|
get meteorsStrength(): number;
|
|
124
126
|
set meteorsStrength(value: number);
|
|
127
|
+
/**
|
|
128
|
+
* The name written on the Earth, as the family's body label: `EARTH` (`地球` on a Japanese page) laid on the globe so it turns with it, the surface showing through the letters. Off (`null`) unless the page sets it. The plain attributes are the family's:
|
|
129
|
+
* `body-label` (`painted`, `etched`, `outline` or `burned`; absent, no label), `body-label-strength` (0 to 1, 0.5), `body-label-repeat` (`once`, `both` or `around`), `body-label-latitude` (degrees), `body-label-facing` (present: always facing the reader),
|
|
130
|
+
* `body-label-font` (a CSS font family the page has loaded; Michroma, fetched once, when left out) and `body-label-fallback-font` (for letters the font has none of, such as Japanese). The property is the same options as an object, or `null`; setting it writes the attributes.
|
|
131
|
+
* Nothing of it is fetched or made until it is first set, it is not drawn while the Earth is under 24 pixels in radius, and nothing is drawn at rest. A three.js handed over with `setThreeLoader` must include `CanvasTexture`, `SphereGeometry`, `MeshLambertMaterial`, `SRGBColorSpace`, `NormalBlending`
|
|
132
|
+
* and `AdditiveBlending`; without them `chikyu-body-label-unavailable` is sent and the name is not drawn.
|
|
133
|
+
*/
|
|
134
|
+
get bodyLabel(): BodyLabelSettings | null;
|
|
135
|
+
set bodyLabel(value: Partial<BodyLabelSettings> | null);
|
|
125
136
|
/** The controller behind the element's own hands (`set`, `fit`, `state`), while it is in a page. */
|
|
126
137
|
get controller(): ViewController | undefined;
|
|
138
|
+
/**
|
|
139
|
+
* The outside sources of map this Earth draws from (the data door): each carries its own licence and credit, and a map source for the `day` or `night` layer takes the place of the folder of tiles for that layer. Assign a list to
|
|
140
|
+
* replace them; a source that is refused (an empty credit, no licence, a clashing id, a kind the Earth does not draw, a layer it does not know) throws a `TypeError` and nothing changes. A property, never an attribute: data is not text.
|
|
141
|
+
*/
|
|
142
|
+
get sources(): readonly DataSource[];
|
|
143
|
+
set sources(list: readonly unknown[]);
|
|
144
|
+
/** Adds an outside source of map: checked at once (a `TypeError` for one that is refused), and the Earth draws from it. Returns the function that takes it away. */
|
|
145
|
+
addSource(source: unknown): () => void;
|
|
146
|
+
/** Takes a source away by its id: its loads stop, its tiles are freed, its credit goes. Returns whether there was one. */
|
|
147
|
+
removeSource(id: string): boolean;
|
|
148
|
+
/** Switches a source off (`false`) or on again, and keeps it in the Earth: a layers panel's switch. The attribute `data="own"` ignores every outside source at once. */
|
|
149
|
+
enableSource(id: string, on: boolean): void;
|
|
150
|
+
/**
|
|
151
|
+
* Whose data is in the last drawn frame: the package's own first (its pictures; its finer tiles while a window of them is in view) and then each outside source that gave a tile, with how many (`used`). `creditLine(credits, "en" | "ja")`
|
|
152
|
+
* from `@johnmorrisdotca/chikyu-earth/door` writes them as a line with the licences. `chikyu-creditschange` fires when this set changes (not at each frame), with `detail: { credits }`.
|
|
153
|
+
*/
|
|
154
|
+
credits(): Credit[];
|
|
127
155
|
/** Where the finer map tiles are served from (a folder with `manifest.json`), or `null` for none; the attribute `tiles`. The Earth loads only the tiles in view, over its own pictures. */
|
|
128
156
|
get tiles(): string | null;
|
|
129
157
|
set tiles(value: string | null);
|
|
@@ -185,6 +213,13 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
|
|
|
185
213
|
shower: string | null;
|
|
186
214
|
zhr: number;
|
|
187
215
|
};
|
|
216
|
+
/** The name written on the Earth: whether `body-label` is set, its text, the label is made, and it is showing (it is hidden while the Earth is small). */
|
|
217
|
+
bodyLabel: {
|
|
218
|
+
on: boolean;
|
|
219
|
+
text: string;
|
|
220
|
+
made: boolean;
|
|
221
|
+
showing: boolean;
|
|
222
|
+
};
|
|
188
223
|
};
|
|
189
224
|
/**
|
|
190
225
|
* Apply a shared view controller's camera (yaw, tilt, zoom, pan). A change under half a pixel is not drawn, a settled change always is,
|
|
@@ -10,6 +10,10 @@ import { MAX_SATELLITE_SPEED } from "../satellites/limits.js";
|
|
|
10
10
|
import { MAX_ORBIT_GROUP } from "../space/satellite-layer.js";
|
|
11
11
|
import { readMeteorStrength } from "../meteors/strength.js";
|
|
12
12
|
import { METEOR_NOTE_STYLE, prefersLessMotion, setMeteorNote } from "../meteors/note.js";
|
|
13
|
+
import { createDoorHost } from "../door/host.js";
|
|
14
|
+
import { folderSource } from "../door/map.js";
|
|
15
|
+
import { ownCredit } from "../door/own.js";
|
|
16
|
+
import { BODY_LABEL_ATTRIBUTES, bodyLabelText, readBodyLabel } from "./body-label.js";
|
|
13
17
|
import { createGate, frameCap } from "./gate.js";
|
|
14
18
|
import { setSharedRenderer, setThreeLoader, takeRenderer } from "./shared.js";
|
|
15
19
|
export { setSharedRenderer, setThreeLoader };
|
|
@@ -125,7 +129,7 @@ export const readTime = (value) => {
|
|
|
125
129
|
* ```
|
|
126
130
|
*/
|
|
127
131
|
export class ChikyuEarthRealistic extends HTMLElement {
|
|
128
|
-
static observedAttributes = ["cloud-drift", "center", "time", "speed", "clouds", "lights", "light", "live-seconds", "tiles", "camera", "immersive", "meteors", "meteors-label", "meteors-strength", "air-thickness", "air-label", "lang"];
|
|
132
|
+
static observedAttributes = ["cloud-drift", "center", "time", "speed", "clouds", "lights", "light", "live-seconds", "tiles", "data", "camera", "immersive", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, "air-thickness", "air-label", "lang"];
|
|
129
133
|
#model = newModel();
|
|
130
134
|
#mode = "now";
|
|
131
135
|
#view;
|
|
@@ -141,6 +145,11 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
141
145
|
#state = "loading";
|
|
142
146
|
#tiers = { day: TIERS.day[0], night: TIERS.night[0], clouds: TIERS.clouds[0], water: TIERS.water[0] };
|
|
143
147
|
#taken;
|
|
148
|
+
/** The data door: the outside sources of map this Earth draws from, and whose data is on the screen. */
|
|
149
|
+
#door = createDoorHost(this, {
|
|
150
|
+
own: () => this.#ownCredits(),
|
|
151
|
+
used: () => new Map(Object.entries(this.#model.tiles?.stats.used ?? {})),
|
|
152
|
+
}, { kinds: ["tiles"] }, () => this.#gate?.soon());
|
|
144
153
|
#stage;
|
|
145
154
|
#overlay;
|
|
146
155
|
#pose = null;
|
|
@@ -170,6 +179,8 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
170
179
|
this.#model.camera = readCamera(this.getAttribute("camera"));
|
|
171
180
|
this.#model.cloudDrift = readDrift(this.getAttribute("cloud-drift"));
|
|
172
181
|
this.#model.airThickness = readAirThickness(this.getAttribute("air-thickness"));
|
|
182
|
+
this.#applyBodyLabel();
|
|
183
|
+
this.#door.book.ownOnly(this.getAttribute("data") === "own");
|
|
173
184
|
this.#model.speed = this.speed;
|
|
174
185
|
if (!this.hasAttribute("role"))
|
|
175
186
|
this.setAttribute("role", "img");
|
|
@@ -207,17 +218,21 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
207
218
|
assets: taken.renderer.assets,
|
|
208
219
|
textureBase: () => this.#textureBase(),
|
|
209
220
|
cap: () => this.#textureCap(),
|
|
210
|
-
|
|
221
|
+
sources: () => this.#tileSources(),
|
|
211
222
|
onTiles: (layers) => {
|
|
212
223
|
if (!this.hasAttribute("zoom-max") || this.getAttribute("zoom-max") === this.#reach) {
|
|
213
224
|
this.#reach = TILES_ZOOM_MAX;
|
|
214
|
-
|
|
225
|
+
// not written again when it is already there: the view controls take a written attribute as a new limit and bring the view back to fit, which a change of source must not do to a reader's zoom
|
|
226
|
+
if (this.getAttribute("zoom-max") !== TILES_ZOOM_MAX)
|
|
227
|
+
this.setAttribute("zoom-max", TILES_ZOOM_MAX);
|
|
215
228
|
}
|
|
216
229
|
this.dispatchEvent(new CustomEvent("chikyu-tiles", { detail: { layers } }));
|
|
217
230
|
},
|
|
218
231
|
air: () => airFor(this.getAttribute("air")),
|
|
219
232
|
invalidate: () => this.#gate?.soon(),
|
|
220
233
|
onDraw: () => this.#gate?.drawn(),
|
|
234
|
+
onTiled: () => this.#door.announce(),
|
|
235
|
+
onLabelError: (error) => this.dispatchEvent(new CustomEvent("chikyu-body-label-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
|
|
221
236
|
onPose: (pose) => {
|
|
222
237
|
if (this.#hands)
|
|
223
238
|
this.#hands.controller.grabRadius = discRadius(pose.width, pose.height, 1);
|
|
@@ -291,6 +306,8 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
291
306
|
this.#startTick();
|
|
292
307
|
else if (name === "tiles")
|
|
293
308
|
this.#gate?.soon();
|
|
309
|
+
else if (name === "data")
|
|
310
|
+
this.#door.book.ownOnly(value === "own");
|
|
294
311
|
else if (name === "camera")
|
|
295
312
|
this.camera = readCamera(value);
|
|
296
313
|
else if (name === "cloud-drift") {
|
|
@@ -307,8 +324,13 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
307
324
|
this.#model.airThickness = readAirThickness(value);
|
|
308
325
|
this.#gate?.soon();
|
|
309
326
|
}
|
|
310
|
-
else if (name === "meteors-label" || name === "lang")
|
|
327
|
+
else if (name === "meteors-label" || name === "lang") {
|
|
311
328
|
this.#meteorNote();
|
|
329
|
+
if (name === "lang")
|
|
330
|
+
this.#applyBodyLabel();
|
|
331
|
+
}
|
|
332
|
+
else if (BODY_LABEL_ATTRIBUTES.includes(name))
|
|
333
|
+
this.#applyBodyLabel();
|
|
312
334
|
if (name === "air-thickness" || name === "air-label" || name === "lang")
|
|
313
335
|
setAirNote(this.#airNote, this, this.#model.airThickness);
|
|
314
336
|
}
|
|
@@ -358,10 +380,89 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
358
380
|
set meteorsStrength(value) {
|
|
359
381
|
this.setAttribute("meteors-strength", String(value));
|
|
360
382
|
}
|
|
383
|
+
/**
|
|
384
|
+
* The name written on the Earth, as the family's body label: `EARTH` (`地球` on a Japanese page) laid on the globe so it turns with it, the surface showing through the letters. Off (`null`) unless the page sets it. The plain attributes are the family's:
|
|
385
|
+
* `body-label` (`painted`, `etched`, `outline` or `burned`; absent, no label), `body-label-strength` (0 to 1, 0.5), `body-label-repeat` (`once`, `both` or `around`), `body-label-latitude` (degrees), `body-label-facing` (present: always facing the reader),
|
|
386
|
+
* `body-label-font` (a CSS font family the page has loaded; Michroma, fetched once, when left out) and `body-label-fallback-font` (for letters the font has none of, such as Japanese). The property is the same options as an object, or `null`; setting it writes the attributes.
|
|
387
|
+
* Nothing of it is fetched or made until it is first set, it is not drawn while the Earth is under 24 pixels in radius, and nothing is drawn at rest. A three.js handed over with `setThreeLoader` must include `CanvasTexture`, `SphereGeometry`, `MeshLambertMaterial`, `SRGBColorSpace`, `NormalBlending`
|
|
388
|
+
* and `AdditiveBlending`; without them `chikyu-body-label-unavailable` is sent and the name is not drawn.
|
|
389
|
+
*/
|
|
390
|
+
get bodyLabel() {
|
|
391
|
+
return readBodyLabel((name) => this.getAttribute(name));
|
|
392
|
+
}
|
|
393
|
+
set bodyLabel(value) {
|
|
394
|
+
for (const name of BODY_LABEL_ATTRIBUTES)
|
|
395
|
+
this.removeAttribute(name);
|
|
396
|
+
if (value === null)
|
|
397
|
+
return;
|
|
398
|
+
this.setAttribute("body-label", value.look ?? "painted");
|
|
399
|
+
if (value.strength !== undefined)
|
|
400
|
+
this.setAttribute("body-label-strength", String(value.strength));
|
|
401
|
+
if (value.repeat !== undefined)
|
|
402
|
+
this.setAttribute("body-label-repeat", value.repeat);
|
|
403
|
+
if (value.latitude !== undefined)
|
|
404
|
+
this.setAttribute("body-label-latitude", String(value.latitude));
|
|
405
|
+
if (value.facing)
|
|
406
|
+
this.setAttribute("body-label-facing", "");
|
|
407
|
+
if (value.font)
|
|
408
|
+
this.setAttribute("body-label-font", value.font);
|
|
409
|
+
if (value.fallbackFont)
|
|
410
|
+
this.setAttribute("body-label-fallback-font", value.fallbackFont);
|
|
411
|
+
}
|
|
412
|
+
/** Puts the name's settings and text right from the attributes (`body-label` and its family, `lang`). */
|
|
413
|
+
#applyBodyLabel() {
|
|
414
|
+
this.#model.bodyLabel.settings = readBodyLabel((name) => this.getAttribute(name));
|
|
415
|
+
this.#model.bodyLabel.text = bodyLabelText((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en");
|
|
416
|
+
this.#gate?.soon();
|
|
417
|
+
}
|
|
361
418
|
/** The controller behind the element's own hands (`set`, `fit`, `state`), while it is in a page. */
|
|
362
419
|
get controller() {
|
|
363
420
|
return this.#hands?.controller;
|
|
364
421
|
}
|
|
422
|
+
/** The map source of each layer now: the last one a page added for it, else the folder of the `tiles` attribute. */
|
|
423
|
+
#tileSources() {
|
|
424
|
+
const folder = this.tiles === null ? undefined : folderSource(this.tiles);
|
|
425
|
+
const day = this.#door.book.mapSources("day")[0] ?? folder;
|
|
426
|
+
const night = this.#door.book.mapSources("night")[0] ?? folder;
|
|
427
|
+
return { ...(day ? { day } : {}), ...(night ? { night } : {}) };
|
|
428
|
+
}
|
|
429
|
+
/** The package's own credits for the last drawn frame: its pictures while it is drawn, and its finer tiles when a window of them is in view (unless a page added the folder itself, which the door counts). */
|
|
430
|
+
#ownCredits() {
|
|
431
|
+
const used = this.#model.tiles?.stats.used ?? {};
|
|
432
|
+
const own = [ownCredit("chikyu-pictures", this.#state === "live" ? 1 : 0)];
|
|
433
|
+
if (this.#door.book.get("chikyu-tiles") === undefined)
|
|
434
|
+
own.push(ownCredit("chikyu-tiles", used["chikyu-tiles"] ?? 0));
|
|
435
|
+
return own;
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* The outside sources of map this Earth draws from (the data door): each carries its own licence and credit, and a map source for the `day` or `night` layer takes the place of the folder of tiles for that layer. Assign a list to
|
|
439
|
+
* replace them; a source that is refused (an empty credit, no licence, a clashing id, a kind the Earth does not draw, a layer it does not know) throws a `TypeError` and nothing changes. A property, never an attribute: data is not text.
|
|
440
|
+
*/
|
|
441
|
+
get sources() {
|
|
442
|
+
return this.#door.sources();
|
|
443
|
+
}
|
|
444
|
+
set sources(list) {
|
|
445
|
+
this.#door.setSources(list);
|
|
446
|
+
}
|
|
447
|
+
/** Adds an outside source of map: checked at once (a `TypeError` for one that is refused), and the Earth draws from it. Returns the function that takes it away. */
|
|
448
|
+
addSource(source) {
|
|
449
|
+
return this.#door.book.addSource(source);
|
|
450
|
+
}
|
|
451
|
+
/** Takes a source away by its id: its loads stop, its tiles are freed, its credit goes. Returns whether there was one. */
|
|
452
|
+
removeSource(id) {
|
|
453
|
+
return this.#door.book.removeSource(id);
|
|
454
|
+
}
|
|
455
|
+
/** Switches a source off (`false`) or on again, and keeps it in the Earth: a layers panel's switch. The attribute `data="own"` ignores every outside source at once. */
|
|
456
|
+
enableSource(id, on) {
|
|
457
|
+
this.#door.book.enableSource(id, on);
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Whose data is in the last drawn frame: the package's own first (its pictures; its finer tiles while a window of them is in view) and then each outside source that gave a tile, with how many (`used`). `creditLine(credits, "en" | "ja")`
|
|
461
|
+
* from `@johnmorrisdotca/chikyu-earth/door` writes them as a line with the licences. `chikyu-creditschange` fires when this set changes (not at each frame), with `detail: { credits }`.
|
|
462
|
+
*/
|
|
463
|
+
credits() {
|
|
464
|
+
return this.#door.credits();
|
|
465
|
+
}
|
|
365
466
|
/** Where the finer map tiles are served from (a folder with `manifest.json`), or `null` for none; the attribute `tiles`. The Earth loads only the tiles in view, over its own pictures. */
|
|
366
467
|
get tiles() {
|
|
367
468
|
const given = this.getAttribute("tiles");
|
|
@@ -486,12 +587,13 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
486
587
|
state: this.#state,
|
|
487
588
|
tiers: { ...this.#tiers },
|
|
488
589
|
satellites: this.#satelliteStats(),
|
|
489
|
-
tiles: this.#model.tiles?.stats ?? { ready: false, level: null, held: 0, shown: 0, loading: 0, failed: 0, requested: 0 },
|
|
590
|
+
tiles: this.#model.tiles?.stats ?? { ready: false, level: null, held: 0, shown: 0, loading: 0, failed: 0, requested: 0, heldBytes: 0, refused: 0, used: {} },
|
|
490
591
|
draws: stats?.draws ?? 0,
|
|
491
592
|
contexts: stats?.contexts ?? 0,
|
|
492
593
|
canvas: stats?.canvas ?? { width: 0, height: 0, pixels: 0 },
|
|
493
594
|
assets: { entries: stats?.assets.entries ?? 0, refs: stats?.assets.refs ?? 0 },
|
|
494
595
|
meteors: { on: this.#model.meteors.on, strength: this.#model.meteors.strength, ...this.#model.meteors.drawn },
|
|
596
|
+
bodyLabel: { on: this.#model.bodyLabel.settings !== null, text: this.#model.bodyLabel.text, ...this.#model.bodyLabel.drawn },
|
|
495
597
|
};
|
|
496
598
|
}
|
|
497
599
|
/**
|
|
@@ -5,5 +5,6 @@ export { lookAt, discRadius, ATMOSPHERE_OUTER, cameraCentre, type CameraMode, ty
|
|
|
5
5
|
export type { ThreeParts } from "./earth.ts";
|
|
6
6
|
export { TEXEL_SLACK, coveringTile, parseManifest, pointOnEarth, tileColumns, tileLevel, tileRect, tileRows, tilesInView, type TileCamera, type TileId, type TileLayer, type VisibleTile } from "./tiles.ts";
|
|
7
7
|
export { TILE_KEEP_MS, TILE_LIMIT } from "./tile-set.ts";
|
|
8
|
+
export { BODY_LABEL_ATTRIBUTES, bodyLabelText, readBodyLabel, setBodyLabelFontUrl, type BodyLabelSettings } from "./body-label.ts";
|
|
8
9
|
export { AIR_QUALITY, AIR_THICKNESS_DEFAULT, AIR_THICKNESS_MAX, AIR_TOP, AIR_VERT, airFor, airFrag, airTop, readAirThickness, type AirSamples } from "./air.ts";
|
|
9
10
|
export { AIR_NOTE } from "./air-note.ts";
|
package/dist/realistic/index.js
CHANGED
|
@@ -6,5 +6,6 @@ export { createGate, frameCap } from "./gate.js";
|
|
|
6
6
|
export { lookAt, discRadius, ATMOSPHERE_OUTER, cameraCentre } from "./earth.js";
|
|
7
7
|
export { TEXEL_SLACK, coveringTile, parseManifest, pointOnEarth, tileColumns, tileLevel, tileRect, tileRows, tilesInView } from "./tiles.js";
|
|
8
8
|
export { TILE_KEEP_MS, TILE_LIMIT } from "./tile-set.js";
|
|
9
|
+
export { BODY_LABEL_ATTRIBUTES, bodyLabelText, readBodyLabel, setBodyLabelFontUrl } from "./body-label.js";
|
|
9
10
|
export { AIR_QUALITY, AIR_THICKNESS_DEFAULT, AIR_THICKNESS_MAX, AIR_TOP, AIR_VERT, airFor, airFrag, airTop, readAirThickness } from "./air.js";
|
|
10
11
|
export { AIR_NOTE } from "./air-note.js";
|
|
@@ -17,6 +17,14 @@ export type ThreeParts = {
|
|
|
17
17
|
} & {
|
|
18
18
|
/** Only the satellites use it, so a loader that hands over a subset of three.js without it still draws everything else. */
|
|
19
19
|
Points?: typeof THREE.Points;
|
|
20
|
+
} & {
|
|
21
|
+
/** Only the name written on the Earth (`body-label`) uses these, so a subset of three.js without them still draws everything else. */
|
|
22
|
+
CanvasTexture?: typeof THREE.CanvasTexture;
|
|
23
|
+
SphereGeometry?: typeof THREE.SphereGeometry;
|
|
24
|
+
MeshLambertMaterial?: typeof THREE.MeshLambertMaterial;
|
|
25
|
+
SRGBColorSpace?: typeof THREE.SRGBColorSpace;
|
|
26
|
+
NormalBlending?: typeof THREE.NormalBlending;
|
|
27
|
+
AdditiveBlending?: typeof THREE.AdditiveBlending;
|
|
20
28
|
};
|
|
21
29
|
/** Milliseconds a lower texture size must be enough before the larger one is let go. */
|
|
22
30
|
export declare const DOWNGRADE_AFTER_MS = 4000;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type * as THREE from "three";
|
|
2
2
|
import type { AssetCache } from "@johnmorrisdotca/kazoku-ui/renderer";
|
|
3
|
+
import { type EarthMapSource } from "../door/map.ts";
|
|
3
4
|
import type { ThreeParts } from "./textures.ts";
|
|
4
5
|
import { type TileCamera } from "./tiles.ts";
|
|
5
6
|
/**
|
|
@@ -24,6 +25,18 @@ export declare const TILE_LIMIT = 48;
|
|
|
24
25
|
* ```
|
|
25
26
|
*/
|
|
26
27
|
export declare const TILE_KEEP_MS = 4000;
|
|
28
|
+
/**
|
|
29
|
+
* The bytes of decoded tiles the view holds, all sources together: 72 MB, which is the 48 tiles it has always held (`TILE_LIMIT`, a 512 pixel square with its mipmaps is 1.4 MB). A tile that arrives when the view needs every tile it holds,
|
|
30
|
+
* and does not fit, is refused and counted (`stats.refused`): the view draws what it holds.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { TILE_BUDGET } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
35
|
+
*
|
|
36
|
+
* console.log(TILE_BUDGET / 1024 / 1024);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare const TILE_BUDGET: number;
|
|
27
40
|
type Three = ThreeParts;
|
|
28
41
|
type Uniform<T> = {
|
|
29
42
|
value: T;
|
|
@@ -40,10 +53,17 @@ export interface TileShared {
|
|
|
40
53
|
/** More uniforms the surface program reads (the cloud picture and where the Sun is in the Earth's axes), shared with the sphere's own. */
|
|
41
54
|
extra?: Record<string, Uniform<unknown>>;
|
|
42
55
|
}
|
|
56
|
+
/** The map source each layer is drawn from now, or none: read at every draw. A layer's tiles come from its source alone, and the night tiles go with day tiles (no day source, no tiles). */
|
|
57
|
+
export type TileSources = {
|
|
58
|
+
day?: EarthMapSource;
|
|
59
|
+
night?: EarthMapSource;
|
|
60
|
+
};
|
|
43
61
|
export interface TileSetDeps {
|
|
44
62
|
assets: AssetCache;
|
|
45
|
-
/**
|
|
46
|
-
|
|
63
|
+
/** The sources of the layers now (the data door's: a source a page added, else the `tiles` folder). Read at every draw; the objects are the same while nothing changed. */
|
|
64
|
+
sources: () => TileSources;
|
|
65
|
+
/** The bytes of decoded tiles held, all sources together: `TILE_BUDGET` where left out. */
|
|
66
|
+
budgetBytes?: number;
|
|
47
67
|
/** The widest picture this device holds: tiles are only used where the day picture reaches 4096. */
|
|
48
68
|
cap: () => number;
|
|
49
69
|
/** Ask for one draw. */
|
|
@@ -67,6 +87,11 @@ export interface TileStats {
|
|
|
67
87
|
failed: number;
|
|
68
88
|
/** Tile fetches made. */
|
|
69
89
|
requested: number;
|
|
90
|
+
/** The bytes of decoded tiles held, which never pass the budget except by tiles the view needs now, and tiles that arrived and did not fit, which are not held. */
|
|
91
|
+
heldBytes: number;
|
|
92
|
+
refused: number;
|
|
93
|
+
/** The tiles in view that came from each source, by the source's id: what a credit line counts. */
|
|
94
|
+
used: Record<string, number>;
|
|
70
95
|
}
|
|
71
96
|
export interface TileSet {
|
|
72
97
|
sync(camera: TileCamera, sun: readonly [number, number, number], night: boolean, ratio: number): void;
|