@johnmorrisdotca/wakusei-planets 0.69.0 → 0.70.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 +46 -0
- package/NOTICE.md +29 -1
- package/README.md +7 -7
- package/dist/bodies/moons-jupiter.js +2 -0
- package/dist/bodies/moons-mars.js +2 -2
- package/dist/bodies/moons-neptune.js +2 -1
- package/dist/bodies/moons-pluto.js +2 -2
- package/dist/bodies/moons-saturn.js +14 -2
- package/dist/data/discovery.js +225 -0
- package/dist/data/moon-catalogue.js +15 -15
- package/dist/data/orbits.js +15 -0
- package/dist/data/shapes/amalthea.d.ts +2 -0
- package/dist/data/shapes/amalthea.js +1 -0
- package/dist/data/shapes/atlas.d.ts +2 -0
- package/dist/data/shapes/atlas.js +1 -0
- package/dist/data/shapes/calypso.d.ts +2 -0
- package/dist/data/shapes/calypso.js +1 -0
- package/dist/data/shapes/daphnis.d.ts +2 -0
- package/dist/data/shapes/daphnis.js +1 -0
- package/dist/data/shapes/deimos.d.ts +2 -0
- package/dist/data/shapes/deimos.js +1 -0
- package/dist/data/shapes/epimetheus.d.ts +2 -0
- package/dist/data/shapes/epimetheus.js +1 -0
- package/dist/data/shapes/helene.d.ts +2 -0
- package/dist/data/shapes/helene.js +1 -0
- package/dist/data/shapes/hydra.d.ts +2 -0
- package/dist/data/shapes/hydra.js +1 -0
- package/dist/data/shapes/hyperion.d.ts +2 -0
- package/dist/data/shapes/hyperion.js +1 -0
- package/dist/data/shapes/janus.d.ts +2 -0
- package/dist/data/shapes/janus.js +1 -0
- package/dist/data/shapes/larissa.d.ts +2 -0
- package/dist/data/shapes/larissa.js +1 -0
- package/dist/data/shapes/nix.d.ts +2 -0
- package/dist/data/shapes/nix.js +1 -0
- package/dist/data/shapes/pan.d.ts +2 -0
- package/dist/data/shapes/pan.js +1 -0
- package/dist/data/shapes/pandora.d.ts +2 -0
- package/dist/data/shapes/pandora.js +1 -0
- package/dist/data/shapes/phobos.d.ts +2 -0
- package/dist/data/shapes/phobos.js +1 -0
- package/dist/data/shapes/phoebe.d.ts +2 -0
- package/dist/data/shapes/phoebe.js +1 -0
- package/dist/data/shapes/prometheus.d.ts +2 -0
- package/dist/data/shapes/prometheus.js +1 -0
- package/dist/data/shapes/proteus.d.ts +2 -0
- package/dist/data/shapes/proteus.js +1 -0
- package/dist/data/shapes/telesto.d.ts +2 -0
- package/dist/data/shapes/telesto.js +1 -0
- package/dist/data/shapes/thebe.d.ts +2 -0
- package/dist/data/shapes/thebe.js +1 -0
- package/dist/discovery.d.ts +1 -1
- package/dist/earth-places.d.ts +7 -6
- package/dist/earth-places.js +11 -8
- package/dist/facts.d.ts +21 -4
- package/dist/facts.js +71 -38
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/moon-catalogue.d.ts +1 -1
- package/dist/nearest.js +2 -0
- package/dist/picture-credits.js +3 -0
- package/dist/scene/body-places.js +4 -5
- package/dist/scene/body.js +10 -5
- package/dist/scene/earth-places.d.ts +110 -2
- package/dist/scene/earth-places.js +149 -9
- package/dist/scene/glsl.d.ts +2 -2
- package/dist/scene/glsl.js +11 -0
- package/dist/scene/look.d.ts +7 -0
- package/dist/scene/look.js +1 -0
- package/dist/scene/painter.js +18 -3
- package/dist/scene/recipes.js +6 -2
- package/dist/scene/rings.js +11 -2
- package/dist/scene/shape.d.ts +50 -0
- package/dist/scene/shape.js +110 -0
- package/dist/shape-basis.d.ts +43 -0
- package/dist/shape-basis.js +45 -0
- package/dist/space/all-moons.d.ts +6 -1
- package/dist/space/all-moons.js +5 -1
- package/dist/space/element.d.ts +28 -3
- package/dist/space/element.js +169 -40
- package/dist/space/orbit-lines.d.ts +66 -0
- package/dist/space/orbit-lines.js +118 -0
- package/dist/space/scale.d.ts +1 -1
- package/dist/space/scale.js +20 -5
- package/dist/space/scene.d.ts +8 -0
- package/dist/space/scene.js +116 -9
- package/dist/stops.js +12 -0
- package/dist/surface/element.js +3 -3
- package/dist/surface/glsl.d.ts +2 -2
- package/dist/surface/glsl.js +15 -3
- package/dist/surface/height.d.ts +7 -0
- package/dist/surface/height.js +10 -0
- package/dist/textures/deimos-1024.webp +0 -0
- package/dist/textures/deimos-512.webp +0 -0
- package/dist/textures/phobos-1024.webp +0 -0
- package/dist/textures/phobos-512.webp +0 -0
- package/dist/textures/phoebe-1024.webp +0 -0
- package/dist/textures/phoebe-512.webp +0 -0
- package/package.json +1 -1
package/dist/scene/body.js
CHANGED
|
@@ -3,6 +3,7 @@ import { silhouette } from "../pose.js";
|
|
|
3
3
|
import { cross } from "../vec.js";
|
|
4
4
|
import { BALL_FRAGMENT, bodyFragment, GLOW_FRAGMENT, GLOW_VERTEX, PAINTED_SURFACE, PAINTED_SURFACE_WINDOWED, RING_FRAGMENT_DETAIL, RING_VERTEX, STAR_GLOW_FRAGMENT, VERTEX } from "./glsl.js";
|
|
5
5
|
import { detailOf, lookOf } from "./look.js";
|
|
6
|
+
import { shapeGeometry } from "./shape.js";
|
|
6
7
|
import { createDetail } from "./detail.js";
|
|
7
8
|
import { fallbackLook } from "./fallback.js";
|
|
8
9
|
import { writeBasis } from "./basis.js";
|
|
@@ -69,7 +70,11 @@ export function createBodyItem(options) {
|
|
|
69
70
|
async build({ three: T, assets, width, height }) {
|
|
70
71
|
const look = options.shaded ?? lookOf(options.id) ?? fallbackLook(facts);
|
|
71
72
|
const wantPainted = (options.look === "painted" || look.mapped === true) && look.painted !== undefined;
|
|
72
|
-
|
|
73
|
+
// a moon with a published shape model is the globe moved to its radii (its table is a chunk of its own, waited for here), and then needs no stretching to an ellipsoid
|
|
74
|
+
const shapeTable = look.shape === undefined ? undefined : await look.shape().catch(() => undefined);
|
|
75
|
+
// a big picture gets a globe of 192 by 96 steps (as the unshaped sphere has), a tile or a card one of 96 by 48: a page can hold a dozen moons, and the arrays of a globe stay in the page
|
|
76
|
+
const grid = Math.min(width, height) >= 300 ? { lon: 192, lat: 96 } : { lon: 96, lat: 48 };
|
|
77
|
+
const geometry = shapeTable === undefined ? assets.acquire("wk:sphere", () => new T.SphereGeometry(1, 192, 96), (g) => g.dispose()) : assets.acquire(`wk:shape:${held}:${grid.lon}`, () => shapeGeometry(T, shapeTable, facts.radiusKm, grid), (g) => g.dispose());
|
|
73
78
|
const shader = assets.acquire(`wk:body:${held}:r`, () => makeBodyMaterial(T, look, false), (m) => m.dispose());
|
|
74
79
|
const paintedMaterial = wantPainted ? assets.acquire(`wk:body:${held}:p`, () => makeBodyMaterial(T, look, true), (m) => m.dispose()) : undefined;
|
|
75
80
|
const materials = paintedMaterial === undefined ? [shader] : [shader, paintedMaterial];
|
|
@@ -270,10 +275,10 @@ export function createBodyItem(options) {
|
|
|
270
275
|
const orient = (state) => {
|
|
271
276
|
const { pole, meridian } = state.pose;
|
|
272
277
|
const east = cross(pole, meridian);
|
|
273
|
-
const ax = facts.axesKm;
|
|
278
|
+
const ax = shapeTable === undefined ? facts.axesKm : undefined;
|
|
274
279
|
const mean = facts.radiusKm;
|
|
275
280
|
const scaleX = ax ? ax[1] / mean : 1;
|
|
276
|
-
const scaleY = ax ? ax[2] / mean : 1 - facts.flattening;
|
|
281
|
+
const scaleY = ax ? ax[2] / mean : shapeTable === undefined ? 1 - facts.flattening : 1;
|
|
277
282
|
const scaleZ = ax ? ax[0] / mean : 1;
|
|
278
283
|
setBasis(mesh, east, pole, meridian, scaleX, scaleY, scaleZ);
|
|
279
284
|
if (cut !== undefined)
|
|
@@ -463,9 +468,9 @@ export function createBodyItem(options) {
|
|
|
463
468
|
label.update(camera, ((aspect >= 1 ? viewHeight : viewWidth) / 2) * (state.zoom / state.extent), state.pose.light);
|
|
464
469
|
if (detail !== undefined && textureWidth > 0) {
|
|
465
470
|
const east = cross(state.pose.pole, state.pose.meridian);
|
|
466
|
-
const ax = facts.axesKm;
|
|
471
|
+
const ax = shapeTable === undefined ? facts.axesKm : undefined;
|
|
467
472
|
const mean = facts.radiusKm;
|
|
468
|
-
detail.sync({ left: camera.left, right: camera.right, bottom: camera.bottom, top: camera.top }, { east, pole: state.pose.pole, meridian: state.pose.meridian, scale: [ax ? ax[1] / mean : 1, ax ? ax[2] / mean : 1 - facts.flattening, ax ? ax[0] / mean : 1] }, viewWidth);
|
|
473
|
+
detail.sync({ left: camera.left, right: camera.right, bottom: camera.bottom, top: camera.top }, { east, pole: state.pose.pole, meridian: state.pose.meridian, scale: [ax ? ax[1] / mean : 1, ax ? ax[2] / mean : shapeTable === undefined ? 1 - facts.flattening : 1, ax ? ax[0] / mean : 1] }, viewWidth);
|
|
469
474
|
}
|
|
470
475
|
};
|
|
471
476
|
apply(latest);
|
|
@@ -38,7 +38,39 @@ export interface EarthPlace {
|
|
|
38
38
|
kind?: EarthPlaceKind;
|
|
39
39
|
/** A CSS colour for this place alone: a hex colour, `rgb()` or `hsl()` with numbers, or a colour's name. */
|
|
40
40
|
color?: string;
|
|
41
|
+
/** A set of places (spaceports, harbours) the page shows or hides together with `earth-place-layers`; left out, the place is always shown. */
|
|
42
|
+
layer?: string;
|
|
43
|
+
/** `small` draws a shorter, narrower mark; left out, the kind's own size. */
|
|
44
|
+
size?: EarthPlaceSize;
|
|
45
|
+
/** How this place is drawn, over `earth-places-look`; left out, `earth-places-look`. */
|
|
46
|
+
look?: EarthPlaceLook;
|
|
47
|
+
/** `low` lays this place's name after the others' (and, past the 32 markers, its marker too), so its name gives way where they crowd; left out (`high`), it is laid with the rest. */
|
|
48
|
+
namePriority?: EarthPlaceNamePriority;
|
|
41
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* How big a place's mark is: `normal` (the default) or `small`, a shorter, narrower stick and a smaller ring, so a harbour can stand beside a city and "You are here" stays the tall beam.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* import type { EarthPlaceSize } from "@johnmorrisdotca/wakusei-planets/earth-places";
|
|
56
|
+
*
|
|
57
|
+
* const size: EarthPlaceSize = "small";
|
|
58
|
+
* console.log(size);
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export type EarthPlaceSize = "normal" | "small";
|
|
62
|
+
/**
|
|
63
|
+
* Where a place's name is laid among the others: `high` (the default) in the order given, or `low`, after all the others.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* import type { EarthPlaceNamePriority } from "@johnmorrisdotca/wakusei-planets/earth-places";
|
|
68
|
+
*
|
|
69
|
+
* const priority: EarthPlaceNamePriority = "low";
|
|
70
|
+
* console.log(priority);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export type EarthPlaceNamePriority = "high" | "low";
|
|
42
74
|
/**
|
|
43
75
|
* How a place is drawn: `beam` (a light rising out of the ground with a ring at its foot, the default), `pin` (a thin stick with a round head) or `ring` (only the ring lying on the ground).
|
|
44
76
|
*
|
|
@@ -139,6 +171,51 @@ export interface EarthPlaceLayoutOptions {
|
|
|
139
171
|
lat: number;
|
|
140
172
|
} | null;
|
|
141
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* Which layers of places are shown (the attribute `earth-place-layers`): a JSON object of layer names to true or false, such as `{"harbours":false}`. A layer that is not named is shown, and so is a place with no layer. Anything that is not an object
|
|
176
|
+
* of that kind is no switches. chikyu-earth's `readPlaceLayers`.
|
|
177
|
+
*
|
|
178
|
+
* @param value - The attribute's text, or null.
|
|
179
|
+
* @returns The switches, a name to whether it is shown.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* import { readEarthPlaceLayers } from "@johnmorrisdotca/wakusei-planets/earth-places";
|
|
184
|
+
*
|
|
185
|
+
* console.log(readEarthPlaceLayers('{"harbours":false,"airports":true,"x":1}')); // { harbours: false, airports: true }
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
export declare function readEarthPlaceLayers(value: string | null | undefined): Record<string, boolean>;
|
|
189
|
+
/**
|
|
190
|
+
* The places whose layer is shown: a place with no layer is always in, and a layer is in unless `layers` says `false` for it. A place of a layer that is off is not drawn, not named and cannot be pressed. The list is returned as it came when nothing is left out.
|
|
191
|
+
*
|
|
192
|
+
* @param places - The places, as `readEarthPlaces` makes them.
|
|
193
|
+
* @param layers - The switches, a layer's name to whether it is shown (`readEarthPlaceLayers`).
|
|
194
|
+
* @returns The places to draw.
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```ts
|
|
198
|
+
* import { shownEarthPlaces } from "@johnmorrisdotca/wakusei-planets/earth-places";
|
|
199
|
+
*
|
|
200
|
+
* const places = [{ id: "yvr", lon: -123.18, lat: 49.19, layer: "airports" }, { id: "cavan", lon: -123.1, lat: 49.29, layer: "harbours" }, { id: "me", lon: -79.4, lat: 43.7 }];
|
|
201
|
+
* console.log(shownEarthPlaces(places, { harbours: false }).map((place) => place.id)); // ["yvr", "me"]
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
export declare function shownEarthPlaces<T extends EarthPlace>(places: readonly T[], layers: Readonly<Record<string, boolean>>): readonly T[];
|
|
205
|
+
/** The order the markers are given out in: where the reader is, then the rest in the order given, then the places whose name is `low`. */
|
|
206
|
+
export declare const placeRank: (place: EarthPlace) => number;
|
|
207
|
+
/** The places in that order (the order given within each rank). */
|
|
208
|
+
export declare const inMarkOrder: <T extends EarthPlace>(places: readonly T[]) => T[];
|
|
209
|
+
/**
|
|
210
|
+
* The fields beyond chikyu-earth's own that a place may carry (`layer`, `size`, `look`, `namePriority`), put back on the places its reader (older than them) made from the same text, so the views need no newer chikyu-earth. A place is found by its `id`
|
|
211
|
+
* (or, with none, its place in the list, as chikyu-earth gives it); a field that is not valid is left out.
|
|
212
|
+
*/
|
|
213
|
+
export declare function keepPlaceFields(value: string | null | undefined, places: EarthPlace[]): EarthPlace[];
|
|
214
|
+
/**
|
|
215
|
+
* A layout that gives each place its own `size` and `look`: the places' markers are laid as beams (chikyu-earth knows one look for a whole list), then a `small` place's stick is cut to about half and its ring to 70 per cent, and a place whose look is `ring`
|
|
216
|
+
* (its own or the list's) has no stick, its name moving with the top of what is left. A list with no `size` or `look` of its own is laid as `layout` lays it, untouched.
|
|
217
|
+
*/
|
|
218
|
+
export declare function layWithOwn(layout: EarthPlacesLayout["layout"], places: readonly EarthPlace[], view: SpotView, look: EarthPlaceLook, options?: EarthPlaceLayoutOptions): EarthPlaceLayout;
|
|
142
219
|
/** The two things `@johnmorrisdotca/wakusei-planets/earth-places` hands the views: reading the attribute, and laying places on a picture. Both are chikyu-earth's. */
|
|
143
220
|
export interface EarthPlacesLayout {
|
|
144
221
|
read(value: string | null | undefined): EarthPlace[];
|
|
@@ -172,6 +249,37 @@ export interface EarthPlaceMark {
|
|
|
172
249
|
/** For a place on a body other than the Earth (`body-places`): the body. */
|
|
173
250
|
body?: string;
|
|
174
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* What `wakusei-place-click` carries in `event.detail`: the place that was pressed (chikyu-earth's `chikyu-place-click` detail, with the `body` it is on, `earth` for the Earth's), and where the press was, in CSS pixels inside the element's box.
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* ```ts
|
|
257
|
+
* import type { EarthPlaceClickDetail } from "@johnmorrisdotca/wakusei-planets/earth-places";
|
|
258
|
+
*
|
|
259
|
+
* const on = (event: Event): void => {
|
|
260
|
+
* const { body, id, kind, layer } = (event as CustomEvent<EarthPlaceClickDetail>).detail;
|
|
261
|
+
* console.log(body, id, kind, layer ?? "no layer");
|
|
262
|
+
* };
|
|
263
|
+
* console.log(typeof on);
|
|
264
|
+
* ```
|
|
265
|
+
*/
|
|
266
|
+
export interface EarthPlaceClickDetail {
|
|
267
|
+
/** The body the place is on: `earth`, `moon`, `mars` and so on. */
|
|
268
|
+
body: string;
|
|
269
|
+
id: string;
|
|
270
|
+
/** `here` or `favourite`. */
|
|
271
|
+
kind: EarthPlaceKind;
|
|
272
|
+
/** The place's `layer`, when it has one. */
|
|
273
|
+
layer?: string;
|
|
274
|
+
label?: string;
|
|
275
|
+
lon: number;
|
|
276
|
+
lat: number;
|
|
277
|
+
/** Where the press was, in CSS pixels inside the element's box. */
|
|
278
|
+
x: number;
|
|
279
|
+
y: number;
|
|
280
|
+
}
|
|
281
|
+
/** The detail of `wakusei-place-click` for a pressed place. */
|
|
282
|
+
export declare function earthPlaceClick(body: string, place: EarthPlace, x: number, y: number): EarthPlaceClickDetail;
|
|
175
283
|
/** The markers over one view. */
|
|
176
284
|
export interface EarthPlaceLayerView {
|
|
177
285
|
/** Draw the markers of a layout, moving the ones already there and hiding the rest. */
|
|
@@ -187,9 +295,9 @@ export interface EarthPlaceLayerView {
|
|
|
187
295
|
* Make the layer of markers inside a view's shadow root, above its picture. It holds a handful of elements made once and kept; a draw only writes the numbers that changed.
|
|
188
296
|
*
|
|
189
297
|
* @param root - The view's shadow root.
|
|
190
|
-
* @param options - `press`, called with the mark
|
|
298
|
+
* @param options - `press`, called with the mark, the pointer event and the place when a press that did not move ends over a drawn name or a foot ring (the layer itself takes no pointer: a press on it goes on to the view's controls, as a name on a body's surface does).
|
|
191
299
|
* @returns The layer.
|
|
192
300
|
*/
|
|
193
301
|
export declare function createEarthPlaceLayer(root: ShadowRoot, options?: {
|
|
194
|
-
press?: (mark: EarthPlaceMark, event: PointerEvent) => void;
|
|
302
|
+
press?: (mark: EarthPlaceMark, event: PointerEvent, place: EarthPlace) => void;
|
|
195
303
|
}): EarthPlaceLayerView;
|
|
@@ -22,6 +22,136 @@ export const EARTH_PLACE_LOOKS = ["beam", "pin", "ring"];
|
|
|
22
22
|
export const EARTH_PLACE_MARKS = 32;
|
|
23
23
|
/** Nothing is laid on an Earth under this many CSS pixels of radius: a marker the size of the planet is not a marker. */
|
|
24
24
|
export const EARTH_PLACES_FROM_PX = 40;
|
|
25
|
+
/** What a `small` place's stick and ring are of the kind's own. */
|
|
26
|
+
const SMALL_LENGTH = 0.55;
|
|
27
|
+
const SMALL_RING = 0.7;
|
|
28
|
+
const isObject = (value) => typeof value === "object" && value !== null;
|
|
29
|
+
/**
|
|
30
|
+
* Which layers of places are shown (the attribute `earth-place-layers`): a JSON object of layer names to true or false, such as `{"harbours":false}`. A layer that is not named is shown, and so is a place with no layer. Anything that is not an object
|
|
31
|
+
* of that kind is no switches. chikyu-earth's `readPlaceLayers`.
|
|
32
|
+
*
|
|
33
|
+
* @param value - The attribute's text, or null.
|
|
34
|
+
* @returns The switches, a name to whether it is shown.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { readEarthPlaceLayers } from "@johnmorrisdotca/wakusei-planets/earth-places";
|
|
39
|
+
*
|
|
40
|
+
* console.log(readEarthPlaceLayers('{"harbours":false,"airports":true,"x":1}')); // { harbours: false, airports: true }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export function readEarthPlaceLayers(value) {
|
|
44
|
+
if (!value)
|
|
45
|
+
return {};
|
|
46
|
+
try {
|
|
47
|
+
const parsed = JSON.parse(value);
|
|
48
|
+
if (!isObject(parsed))
|
|
49
|
+
return {};
|
|
50
|
+
const out = {};
|
|
51
|
+
for (const [name, on] of Object.entries(parsed))
|
|
52
|
+
if (typeof on === "boolean")
|
|
53
|
+
out[name] = on;
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return {};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The places whose layer is shown: a place with no layer is always in, and a layer is in unless `layers` says `false` for it. A place of a layer that is off is not drawn, not named and cannot be pressed. The list is returned as it came when nothing is left out.
|
|
62
|
+
*
|
|
63
|
+
* @param places - The places, as `readEarthPlaces` makes them.
|
|
64
|
+
* @param layers - The switches, a layer's name to whether it is shown (`readEarthPlaceLayers`).
|
|
65
|
+
* @returns The places to draw.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* import { shownEarthPlaces } from "@johnmorrisdotca/wakusei-planets/earth-places";
|
|
70
|
+
*
|
|
71
|
+
* const places = [{ id: "yvr", lon: -123.18, lat: 49.19, layer: "airports" }, { id: "cavan", lon: -123.1, lat: 49.29, layer: "harbours" }, { id: "me", lon: -79.4, lat: 43.7 }];
|
|
72
|
+
* console.log(shownEarthPlaces(places, { harbours: false }).map((place) => place.id)); // ["yvr", "me"]
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export function shownEarthPlaces(places, layers) {
|
|
76
|
+
const shown = places.filter((place) => !place.layer || layers[place.layer] !== false);
|
|
77
|
+
return shown.length === places.length ? places : shown;
|
|
78
|
+
}
|
|
79
|
+
/** The order the markers are given out in: where the reader is, then the rest in the order given, then the places whose name is `low`. */
|
|
80
|
+
export const placeRank = (place) => (place.kind === "here" ? 0 : place.namePriority === "low" ? 2 : 1);
|
|
81
|
+
/** The places in that order (the order given within each rank). */
|
|
82
|
+
export const inMarkOrder = (places) => [0, 1, 2].flatMap((rank) => places.filter((place) => placeRank(place) === rank));
|
|
83
|
+
/**
|
|
84
|
+
* The fields beyond chikyu-earth's own that a place may carry (`layer`, `size`, `look`, `namePriority`), put back on the places its reader (older than them) made from the same text, so the views need no newer chikyu-earth. A place is found by its `id`
|
|
85
|
+
* (or, with none, its place in the list, as chikyu-earth gives it); a field that is not valid is left out.
|
|
86
|
+
*/
|
|
87
|
+
export function keepPlaceFields(value, places) {
|
|
88
|
+
let raw;
|
|
89
|
+
try {
|
|
90
|
+
raw = typeof value === "string" ? JSON.parse(value) : null;
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return places;
|
|
94
|
+
}
|
|
95
|
+
if (!Array.isArray(raw))
|
|
96
|
+
return places;
|
|
97
|
+
const own = new Map();
|
|
98
|
+
for (const [i, item] of raw.entries()) {
|
|
99
|
+
if (!isObject(item))
|
|
100
|
+
continue;
|
|
101
|
+
const fields = {};
|
|
102
|
+
if (typeof item["layer"] === "string" && item["layer"].trim())
|
|
103
|
+
fields.layer = item["layer"].trim().slice(0, 40);
|
|
104
|
+
if (item["size"] === "small")
|
|
105
|
+
fields.size = "small";
|
|
106
|
+
if (EARTH_PLACE_LOOKS.includes(item["look"]))
|
|
107
|
+
fields.look = item["look"];
|
|
108
|
+
if (item["namePriority"] === "low")
|
|
109
|
+
fields.namePriority = "low";
|
|
110
|
+
if (Object.keys(fields).length > 0)
|
|
111
|
+
own.set(typeof item["id"] === "string" && item["id"] ? item["id"] : String(i), fields);
|
|
112
|
+
}
|
|
113
|
+
return own.size === 0 ? places : places.map((place) => (own.has(place.id) ? { ...place, ...own.get(place.id) } : place));
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* A layout that gives each place its own `size` and `look`: the places' markers are laid as beams (chikyu-earth knows one look for a whole list), then a `small` place's stick is cut to about half and its ring to 70 per cent, and a place whose look is `ring`
|
|
117
|
+
* (its own or the list's) has no stick, its name moving with the top of what is left. A list with no `size` or `look` of its own is laid as `layout` lays it, untouched.
|
|
118
|
+
*/
|
|
119
|
+
export function layWithOwn(layout, places, view, look, options) {
|
|
120
|
+
if (!places.some((place) => place.size === "small" || place.look !== undefined))
|
|
121
|
+
return layout(places, view, look, options);
|
|
122
|
+
const plain = places.map((place) => {
|
|
123
|
+
const one = { ...place };
|
|
124
|
+
delete one.size;
|
|
125
|
+
delete one.look;
|
|
126
|
+
return one;
|
|
127
|
+
});
|
|
128
|
+
const laid = layout(plain, view, "beam", options);
|
|
129
|
+
const moved = new Map();
|
|
130
|
+
for (const shape of laid.shapes) {
|
|
131
|
+
const place = places[shape.index];
|
|
132
|
+
const flat = (place.look ?? look) === "ring";
|
|
133
|
+
const small = place.size === "small";
|
|
134
|
+
const keep = flat ? 0 : small ? SMALL_LENGTH : 1;
|
|
135
|
+
if (keep === 1)
|
|
136
|
+
continue;
|
|
137
|
+
const dx = (shape.tipX - shape.x) * (keep - 1);
|
|
138
|
+
const dy = (shape.tipY - shape.y) * (keep - 1);
|
|
139
|
+
shape.tipX += dx;
|
|
140
|
+
shape.tipY += dy;
|
|
141
|
+
shape.length *= keep;
|
|
142
|
+
if (small)
|
|
143
|
+
shape.ring *= SMALL_RING;
|
|
144
|
+
moved.set(shape.index, { dx, dy });
|
|
145
|
+
}
|
|
146
|
+
for (const spot of laid.labels) {
|
|
147
|
+
const by = moved.get(spot.index);
|
|
148
|
+
if (by !== undefined) {
|
|
149
|
+
spot.left += by.dx;
|
|
150
|
+
spot.top += by.dy;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return laid;
|
|
154
|
+
}
|
|
25
155
|
// on globalThis, so the separate copies a CDN can load share the one layout
|
|
26
156
|
const SLOT = Symbol.for("@johnmorrisdotca/wakusei-planets/earth-places");
|
|
27
157
|
const slot = (globalThis[SLOT] ??= { heard: new Set() });
|
|
@@ -48,11 +178,20 @@ const STYLE = `.wk-eplaces{position:absolute;inset:0;pointer-events:none;overflo
|
|
|
48
178
|
.wk-eplace line,.wk-eplace ellipse,.wk-eplace circle{vector-effect:non-scaling-stroke}
|
|
49
179
|
.wk-eplace-name{position:absolute;left:0;top:0;padding:0 5px;box-sizing:border-box;border-radius:4px;background:rgba(10,14,22,.78);color:#fff;font:12px/18px var(--wakusei-place-font,system-ui,-apple-system,sans-serif);white-space:nowrap;height:18px}
|
|
50
180
|
.wk-eplace-name[data-kind=here]{font-weight:600}`;
|
|
181
|
+
/** The detail of `wakusei-place-click` for a pressed place. */
|
|
182
|
+
export function earthPlaceClick(body, place, x, y) {
|
|
183
|
+
const detail = { body, id: place.id, kind: place.kind === "here" ? "here" : "favourite", lon: place.lon, lat: place.lat, x, y };
|
|
184
|
+
if (place.layer)
|
|
185
|
+
detail.layer = place.layer;
|
|
186
|
+
if (place.label)
|
|
187
|
+
detail.label = place.label;
|
|
188
|
+
return detail;
|
|
189
|
+
}
|
|
51
190
|
/**
|
|
52
191
|
* Make the layer of markers inside a view's shadow root, above its picture. It holds a handful of elements made once and kept; a draw only writes the numbers that changed.
|
|
53
192
|
*
|
|
54
193
|
* @param root - The view's shadow root.
|
|
55
|
-
* @param options - `press`, called with the mark
|
|
194
|
+
* @param options - `press`, called with the mark, the pointer event and the place when a press that did not move ends over a drawn name or a foot ring (the layer itself takes no pointer: a press on it goes on to the view's controls, as a name on a body's surface does).
|
|
56
195
|
* @returns The layer.
|
|
57
196
|
*/
|
|
58
197
|
export function createEarthPlaceLayer(root, options = {}) {
|
|
@@ -129,11 +268,11 @@ export function createEarthPlaceLayer(root, options = {}) {
|
|
|
129
268
|
continue;
|
|
130
269
|
const away = Math.hypot(event.clientX - (r.left + r.right) / 2, event.clientY - (r.top + r.bottom) / 2);
|
|
131
270
|
if (best === undefined || away < best.away)
|
|
132
|
-
best = { mark: entry.mark, away };
|
|
271
|
+
best = { mark: entry.mark, place: entry.place, away };
|
|
133
272
|
}
|
|
134
273
|
}
|
|
135
274
|
if (best !== undefined)
|
|
136
|
-
options.press(best.mark, event);
|
|
275
|
+
options.press(best.mark, event, best.place);
|
|
137
276
|
};
|
|
138
277
|
const cancel = () => {
|
|
139
278
|
pressed = null;
|
|
@@ -165,16 +304,17 @@ export function createEarthPlaceLayer(root, options = {}) {
|
|
|
165
304
|
set(it.ring, "ry", n(shape.ring * shape.squash));
|
|
166
305
|
set(it.ring, "transform", `rotate(${n(shape.ringAngle)})`);
|
|
167
306
|
set(it.ring, "stroke-width", here ? "2" : "1.5");
|
|
168
|
-
const
|
|
307
|
+
const own = place.look ?? look;
|
|
308
|
+
const stick = own !== "ring";
|
|
169
309
|
it.stick.style.display = stick ? "" : "none";
|
|
170
|
-
it.head.style.display =
|
|
310
|
+
it.head.style.display = own === "pin" ? "" : "none";
|
|
171
311
|
if (stick) {
|
|
172
312
|
set(it.stick, "x2", n(shape.tipX - shape.x));
|
|
173
313
|
set(it.stick, "y2", n(shape.tipY - shape.y));
|
|
174
|
-
set(it.stick, "stroke-width",
|
|
175
|
-
set(it.stick, "stroke-opacity",
|
|
314
|
+
set(it.stick, "stroke-width", own === "beam" ? (here ? "3" : "2") : here ? "2" : "1.5");
|
|
315
|
+
set(it.stick, "stroke-opacity", own === "beam" ? "0.85" : "1");
|
|
176
316
|
}
|
|
177
|
-
if (
|
|
317
|
+
if (own === "pin") {
|
|
178
318
|
set(it.head, "cx", n(shape.tipX - shape.x));
|
|
179
319
|
set(it.head, "cy", n(shape.tipY - shape.y));
|
|
180
320
|
set(it.head, "r", here ? "5" : "3.5");
|
|
@@ -195,7 +335,7 @@ export function createEarthPlaceLayer(root, options = {}) {
|
|
|
195
335
|
if (body !== undefined)
|
|
196
336
|
mark.body = body;
|
|
197
337
|
shown.push(mark);
|
|
198
|
-
live.push({ mark, it, opacity: shape.opacity * dim });
|
|
338
|
+
live.push({ mark, place, it, opacity: shape.opacity * dim });
|
|
199
339
|
}
|
|
200
340
|
for (let i = layout.shapes.length; i < pool.length; i += 1) {
|
|
201
341
|
const it = pool[i];
|
package/dist/scene/glsl.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const VERTEX = "\nvarying vec3 vObj;\nvarying vec3 vN;\nvarying vec3 vW;\nvoid main() {\n vObj = vec3(position.z, position.x, position.y);\n vN = normalize(normalMatrix * normal);\n vec4 w = modelMatrix * vec4(position, 1.0);\n vW = w.xyz;\n gl_Position = projectionMatrix * viewMatrix * w;\n}";
|
|
2
2
|
/** Noise, craters and the band palette, for the surface code of a body to call. */
|
|
3
|
-
export declare const PRELUDE = "\nfloat hash13(vec3 p) { p = fract(p * 0.1031); p += dot(p, p.zyx + 31.32); return fract((p.x + p.y) * p.z); }\nvec3 hash33(vec3 p) { p = fract(p * vec3(0.1031, 0.1030, 0.0973)); p += dot(p, p.yxz + 33.33); return fract((p.xxy + p.yxx) * p.zyx); }\nfloat vnoise(vec3 p) {\n vec3 i = floor(p); vec3 f = fract(p); f = f * f * (3.0 - 2.0 * f);\n return mix(mix(mix(hash13(i), hash13(i + vec3(1,0,0)), f.x), mix(hash13(i + vec3(0,1,0)), hash13(i + vec3(1,1,0)), f.x), f.y),\n mix(mix(hash13(i + vec3(0,0,1)), hash13(i + vec3(1,0,1)), f.x), mix(hash13(i + vec3(0,1,1)), hash13(i + vec3(1,1,1)), f.x), f.y), f.z);\n}\n// Noise that knows how big a pixel is: an octave finer than the pixel can show is replaced by its average (0.5) instead of being sampled, so a small body is smooth and not a spray of pixel-sized specks.\nfloat fbm(vec3 p) { float fw = length(fwidth(p)); float a = 0.5; float s = 0.0; for (int i = 0; i < 5; i++) { s += a * mix(0.5, vnoise(p), 1.0 - smoothstep(0.3, 0.7, fw)); p = p * 2.03 + vec3(1.7, 9.2, 3.1); fw *= 2.03; a *= 0.5; } return s; }\n// Craters: a bowl and a raised rim in each cell that has one. Returns a height, negative in a bowl. A crater smaller than about two pixels fades out (it would only be noise).\nfloat craters(vec3 p, float freq, float amp, float seed) {\n vec3 q = p * freq + seed; vec3 ip = floor(q); float h = 0.0;\n float fw = length(fwidth(q));\n for (int x = -1; x <= 1; x++) for (int y = -1; y <= 1; y++) for (int z = -1; z <= 1; z++) {\n vec3 c = ip + vec3(float(x), float(y), float(z));\n float on = step(0.52, hash13(c + 3.7));\n vec3 ctr = c + hash33(c);\n float rad = mix(0.12, 0.36, hash13(c + 17.3));\n float d = length(q - ctr) / rad;\n float bowl = d < 1.0 ? (d * d - 1.0) : 0.0;\n float rim = d >= 1.0 ? exp(-pow((d - 1.0) * 5.0, 2.0)) * 0.3 * smoothstep(1.0, 1.08, d) : 0.0;\n h += on * amp * rad * (bowl + rim) * (1.0 - smoothstep(0.14, 0.34, fw / rad));\n }\n return h;\n}\nfloat lon(vec3 p) { return atan(p.y, p.x); }\nfloat lat(vec3 p) { return asin(clamp(p.z, -1.0, 1.0)); }\nfloat wrapPi(float a) { return a - 6.2831853 * floor((a + 3.1415927) / 6.2831853); }\nvec3 dirOf(float lonDeg, float latDeg) { float lo = radians(lonDeg); float la = radians(latDeg); return vec3(cos(la) * cos(lo), cos(la) * sin(lo), sin(la)); }\n// One big round bowl with a rim, by longitude, latitude and angular radius in degrees. Negative inside.\nfloat bowl(vec3 p, float lonDeg, float latDeg, float radDeg, float depth) {\n float d = acos(clamp(dot(p, dirOf(lonDeg, latDeg)), -1.0, 1.0)) / radians(radDeg);\n return d < 1.0 ? depth * (d * d - 1.0) : depth * exp(-pow((d - 1.0) * 5.0, 2.0)) * 0.3 * smoothstep(1.0, 1.08, d);\n}\n// A soft oval on the body, 1 inside and 0 outside, by longitude and latitude in degrees.\nfloat oval(vec3 p, float lon0, float lat0, float rx, float ry, float soft) {\n float dx = wrapPi(lon(p) - radians(lon0)) * cos(radians(lat0)) / radians(rx);\n float dy = (lat(p) - radians(lat0)) / radians(ry);\n return 1.0 - smoothstep(1.0 - soft, 1.0, sqrt(dx * dx + dy * dy));\n}";
|
|
3
|
+
export declare const PRELUDE = "\nfloat hash13(vec3 p) { p = fract(p * 0.1031); p += dot(p, p.zyx + 31.32); return fract((p.x + p.y) * p.z); }\nvec3 hash33(vec3 p) { p = fract(p * vec3(0.1031, 0.1030, 0.0973)); p += dot(p, p.yxz + 33.33); return fract((p.xxy + p.yxx) * p.zyx); }\nfloat vnoise(vec3 p) {\n vec3 i = floor(p); vec3 f = fract(p); f = f * f * (3.0 - 2.0 * f);\n return mix(mix(mix(hash13(i), hash13(i + vec3(1,0,0)), f.x), mix(hash13(i + vec3(0,1,0)), hash13(i + vec3(1,1,0)), f.x), f.y),\n mix(mix(hash13(i + vec3(0,0,1)), hash13(i + vec3(1,0,1)), f.x), mix(hash13(i + vec3(0,1,1)), hash13(i + vec3(1,1,1)), f.x), f.y), f.z);\n}\n// Noise that knows how big a pixel is: an octave finer than the pixel can show is replaced by its average (0.5) instead of being sampled, so a small body is smooth and not a spray of pixel-sized specks.\nfloat fbm(vec3 p) { float fw = length(fwidth(p)); float a = 0.5; float s = 0.0; for (int i = 0; i < 5; i++) { s += a * mix(0.5, vnoise(p), 1.0 - smoothstep(0.3, 0.7, fw)); p = p * 2.03 + vec3(1.7, 9.2, 3.1); fw *= 2.03; a *= 0.5; } return s; }\n// Craters: a bowl and a raised rim in each cell that has one. Returns a height, negative in a bowl. A crater smaller than about two pixels fades out (it would only be noise).\nfloat craters(vec3 p, float freq, float amp, float seed) {\n vec3 q = p * freq + seed; vec3 ip = floor(q); float h = 0.0;\n float fw = length(fwidth(q));\n for (int x = -1; x <= 1; x++) for (int y = -1; y <= 1; y++) for (int z = -1; z <= 1; z++) {\n vec3 c = ip + vec3(float(x), float(y), float(z));\n float on = step(0.52, hash13(c + 3.7));\n vec3 ctr = c + hash33(c);\n float rad = mix(0.12, 0.36, hash13(c + 17.3));\n float d = length(q - ctr) / rad;\n float bowl = d < 1.0 ? (d * d - 1.0) : 0.0;\n float rim = d >= 1.0 ? exp(-pow((d - 1.0) * 5.0, 2.0)) * 0.3 * smoothstep(1.0, 1.08, d) : 0.0;\n h += on * amp * rad * (bowl + rim) * (1.0 - smoothstep(0.14, 0.34, fw / rad));\n }\n return h;\n}\n// How much of a crater layer's height the relief may use (MODULES-1639). The relief is the difference between neighbouring pixels (1 to 2 pixels apart, and the screen works in blocks of 2 by 2), and it tips the surface all\n// the way wherever there is any slope, so a crater a few pixels across is read as noise: a lattice of dark dots over the lit side. The layer's mean crater (0.24 of a cell, a cell being 1 / freq of a radian) is about\n// 0.24 / (freq * pixel) pixels across its radius: under RELIEF_FROM of them the layer has no share, over RELIEF_FULL all of it, and the share rises as the eighth power of the ramp, so a layer part way up (the ramp gives a\n// tail of a few thousandths, which the tilt would still turn all the way) is not seen. The colour of the same crater is drawn whatever the share.\nconst float RELIEF_FROM = 8.0;\nconst float RELIEF_FULL = 16.0;\nfloat reliefShare(vec3 p, float freq) {\n float w = smoothstep(RELIEF_FROM, RELIEF_FULL, 0.24 / (freq * max(length(fwidth(p)), 1e-6)));\n float w2 = w * w; float w4 = w2 * w2;\n return w4 * w4;\n}\nfloat lon(vec3 p) { return atan(p.y, p.x); }\nfloat lat(vec3 p) { return asin(clamp(p.z, -1.0, 1.0)); }\nfloat wrapPi(float a) { return a - 6.2831853 * floor((a + 3.1415927) / 6.2831853); }\nvec3 dirOf(float lonDeg, float latDeg) { float lo = radians(lonDeg); float la = radians(latDeg); return vec3(cos(la) * cos(lo), cos(la) * sin(lo), sin(la)); }\n// One big round bowl with a rim, by longitude, latitude and angular radius in degrees. Negative inside.\nfloat bowl(vec3 p, float lonDeg, float latDeg, float radDeg, float depth) {\n float d = acos(clamp(dot(p, dirOf(lonDeg, latDeg)), -1.0, 1.0)) / radians(radDeg);\n return d < 1.0 ? depth * (d * d - 1.0) : depth * exp(-pow((d - 1.0) * 5.0, 2.0)) * 0.3 * smoothstep(1.0, 1.08, d);\n}\n// A soft oval on the body, 1 inside and 0 outside, by longitude and latitude in degrees.\nfloat oval(vec3 p, float lon0, float lat0, float rx, float ry, float soft) {\n float dx = wrapPi(lon(p) - radians(lon0)) * cos(radians(lat0)) / radians(rx);\n float dy = (lat(p) - radians(lat0)) / radians(ry);\n return 1.0 - smoothstep(1.0 - soft, 1.0, sqrt(dx * dx + dy * dy));\n}";
|
|
4
4
|
/**
|
|
5
5
|
* The generic fine detail of a close view, for the fragment shader of a body (`bodyFragment` with `detail`). It is not a measured feature of the body: it is noise, put on so that a body never goes smooth when the
|
|
6
6
|
* zoom takes it past the sharpness of its map. `gTexel` is the angle one texel of the picture being read covers (radians); where a pixel is smaller than a texel (the map is enlarged more than about one and a
|
|
@@ -45,4 +45,4 @@ export declare const GLOW_FRAGMENT = "\nprecision highp float;\nvarying vec2 vP;
|
|
|
45
45
|
*/
|
|
46
46
|
export declare const STAR_GLOW_FRAGMENT = "\nprecision highp float;\nvarying vec2 vP;\nuniform vec3 uColour;\nuniform float uStrength;\nuniform float uSpread;\nuniform float uRim;\nuniform float uProm;\nuniform float uSeed;\nuniform float uTime;\nfloat h1(float n) { return fract(sin(n * 127.1 + uSeed * 91.7) * 43758.5453); }\nfloat n1(float x) { float i = floor(x); float f = fract(x); f = f * f * (3.0 - 2.0 * f); return mix(h1(i), h1(i + 1.0), f); }\nvoid main() {\n float r = length(vP);\n if (r < 0.98) discard;\n float x = r - 1.0;\n float fade = smoothstep(3.0, 1.6, r);\n float halo = exp(-x * uSpread) * uStrength;\n float tight = exp(-x * 14.0) * uStrength * 0.9;\n float rim = exp(-x * 60.0) * uRim;\n vec3 col = uColour * (halo + tight) + mix(uColour, vec3(1.0), 0.4) * rim;\n float a = halo + tight + rim;\n if (uProm > 0.0) {\n float ang = atan(vP.y, vP.x);\n float site = smoothstep(0.55, 0.85, n1(ang * 2.6 + uSeed * 20.0));\n float drift = 0.75 + 0.25 * sin(uTime * 0.5 + ang * 4.0);\n float height = site * uProm * 0.3 * drift;\n float strands = 0.65 + 0.35 * n1(ang * 70.0 + uTime * 0.3);\n float pr = step(0.0, x) * pow(smoothstep(height, 0.0, x), 1.6) * site * strands * 0.9;\n vec3 pc = mix(vec3(1.0, 0.42, 0.26), uColour, 0.2);\n float a0 = uSeed * 6.2831853 + uTime * 0.02;\n float da = atan(sin(ang - a0), cos(ang - a0));\n float burst = pow(max(0.0, sin(uTime * 0.9 + uSeed * 40.0)), 24.0) * uProm;\n float fl = exp(-da * da * 14.0) * exp(-x * 6.0) * burst * 1.6;\n col += pc * pr + vec3(1.0, 0.92, 0.75) * fl;\n a += pr + fl;\n }\n // additive blending multiplies by alpha, so the root of the light is the alpha and the colour carries the rest: the sum arrives as written\n float s = sqrt(min(a * fade, 1.0));\n gl_FragColor = vec4(col / max(a, 1e-4) * s, s);\n}";
|
|
47
47
|
/** A cheap lit ball for a moon seen small beside its planet. */
|
|
48
|
-
export declare const BALL_FRAGMENT = "\nprecision highp float;\nuniform vec3 uLight;\nuniform vec3 uColour;\nvarying vec3 vObj;\nvarying vec3 vN;\nvarying vec3 vW;\n\nfloat hash13(vec3 p) { p = fract(p * 0.1031); p += dot(p, p.zyx + 31.32); return fract((p.x + p.y) * p.z); }\nvec3 hash33(vec3 p) { p = fract(p * vec3(0.1031, 0.1030, 0.0973)); p += dot(p, p.yxz + 33.33); return fract((p.xxy + p.yxx) * p.zyx); }\nfloat vnoise(vec3 p) {\n vec3 i = floor(p); vec3 f = fract(p); f = f * f * (3.0 - 2.0 * f);\n return mix(mix(mix(hash13(i), hash13(i + vec3(1,0,0)), f.x), mix(hash13(i + vec3(0,1,0)), hash13(i + vec3(1,1,0)), f.x), f.y),\n mix(mix(hash13(i + vec3(0,0,1)), hash13(i + vec3(1,0,1)), f.x), mix(hash13(i + vec3(0,1,1)), hash13(i + vec3(1,1,1)), f.x), f.y), f.z);\n}\n// Noise that knows how big a pixel is: an octave finer than the pixel can show is replaced by its average (0.5) instead of being sampled, so a small body is smooth and not a spray of pixel-sized specks.\nfloat fbm(vec3 p) { float fw = length(fwidth(p)); float a = 0.5; float s = 0.0; for (int i = 0; i < 5; i++) { s += a * mix(0.5, vnoise(p), 1.0 - smoothstep(0.3, 0.7, fw)); p = p * 2.03 + vec3(1.7, 9.2, 3.1); fw *= 2.03; a *= 0.5; } return s; }\n// Craters: a bowl and a raised rim in each cell that has one. Returns a height, negative in a bowl. A crater smaller than about two pixels fades out (it would only be noise).\nfloat craters(vec3 p, float freq, float amp, float seed) {\n vec3 q = p * freq + seed; vec3 ip = floor(q); float h = 0.0;\n float fw = length(fwidth(q));\n for (int x = -1; x <= 1; x++) for (int y = -1; y <= 1; y++) for (int z = -1; z <= 1; z++) {\n vec3 c = ip + vec3(float(x), float(y), float(z));\n float on = step(0.52, hash13(c + 3.7));\n vec3 ctr = c + hash33(c);\n float rad = mix(0.12, 0.36, hash13(c + 17.3));\n float d = length(q - ctr) / rad;\n float bowl = d < 1.0 ? (d * d - 1.0) : 0.0;\n float rim = d >= 1.0 ? exp(-pow((d - 1.0) * 5.0, 2.0)) * 0.3 * smoothstep(1.0, 1.08, d) : 0.0;\n h += on * amp * rad * (bowl + rim) * (1.0 - smoothstep(0.14, 0.34, fw / rad));\n }\n return h;\n}\nfloat lon(vec3 p) { return atan(p.y, p.x); }\nfloat lat(vec3 p) { return asin(clamp(p.z, -1.0, 1.0)); }\nfloat wrapPi(float a) { return a - 6.2831853 * floor((a + 3.1415927) / 6.2831853); }\nvec3 dirOf(float lonDeg, float latDeg) { float lo = radians(lonDeg); float la = radians(latDeg); return vec3(cos(la) * cos(lo), cos(la) * sin(lo), sin(la)); }\n// One big round bowl with a rim, by longitude, latitude and angular radius in degrees. Negative inside.\nfloat bowl(vec3 p, float lonDeg, float latDeg, float radDeg, float depth) {\n float d = acos(clamp(dot(p, dirOf(lonDeg, latDeg)), -1.0, 1.0)) / radians(radDeg);\n return d < 1.0 ? depth * (d * d - 1.0) : depth * exp(-pow((d - 1.0) * 5.0, 2.0)) * 0.3 * smoothstep(1.0, 1.08, d);\n}\n// A soft oval on the body, 1 inside and 0 outside, by longitude and latitude in degrees.\nfloat oval(vec3 p, float lon0, float lat0, float rx, float ry, float soft) {\n float dx = wrapPi(lon(p) - radians(lon0)) * cos(radians(lat0)) / radians(rx);\n float dy = (lat(p) - radians(lat0)) / radians(ry);\n return 1.0 - smoothstep(1.0 - soft, 1.0, sqrt(dx * dx + dy * dy));\n}\nvoid main() {\n vec3 n = normalize(vN);\n float shade = 0.82 + 0.3 * (fbm(normalize(vObj) * 4.0) - 0.5);\n float diff = max(dot(n, uLight), 0.0);\n vec3 c = pow(uColour * shade, vec3(2.2)) * (0.04 + 1.1 * diff);\n gl_FragColor = vec4(pow(c, vec3(1.0 / 2.2)), 1.0);\n}";
|
|
48
|
+
export declare const BALL_FRAGMENT = "\nprecision highp float;\nuniform vec3 uLight;\nuniform vec3 uColour;\nvarying vec3 vObj;\nvarying vec3 vN;\nvarying vec3 vW;\n\nfloat hash13(vec3 p) { p = fract(p * 0.1031); p += dot(p, p.zyx + 31.32); return fract((p.x + p.y) * p.z); }\nvec3 hash33(vec3 p) { p = fract(p * vec3(0.1031, 0.1030, 0.0973)); p += dot(p, p.yxz + 33.33); return fract((p.xxy + p.yxx) * p.zyx); }\nfloat vnoise(vec3 p) {\n vec3 i = floor(p); vec3 f = fract(p); f = f * f * (3.0 - 2.0 * f);\n return mix(mix(mix(hash13(i), hash13(i + vec3(1,0,0)), f.x), mix(hash13(i + vec3(0,1,0)), hash13(i + vec3(1,1,0)), f.x), f.y),\n mix(mix(hash13(i + vec3(0,0,1)), hash13(i + vec3(1,0,1)), f.x), mix(hash13(i + vec3(0,1,1)), hash13(i + vec3(1,1,1)), f.x), f.y), f.z);\n}\n// Noise that knows how big a pixel is: an octave finer than the pixel can show is replaced by its average (0.5) instead of being sampled, so a small body is smooth and not a spray of pixel-sized specks.\nfloat fbm(vec3 p) { float fw = length(fwidth(p)); float a = 0.5; float s = 0.0; for (int i = 0; i < 5; i++) { s += a * mix(0.5, vnoise(p), 1.0 - smoothstep(0.3, 0.7, fw)); p = p * 2.03 + vec3(1.7, 9.2, 3.1); fw *= 2.03; a *= 0.5; } return s; }\n// Craters: a bowl and a raised rim in each cell that has one. Returns a height, negative in a bowl. A crater smaller than about two pixels fades out (it would only be noise).\nfloat craters(vec3 p, float freq, float amp, float seed) {\n vec3 q = p * freq + seed; vec3 ip = floor(q); float h = 0.0;\n float fw = length(fwidth(q));\n for (int x = -1; x <= 1; x++) for (int y = -1; y <= 1; y++) for (int z = -1; z <= 1; z++) {\n vec3 c = ip + vec3(float(x), float(y), float(z));\n float on = step(0.52, hash13(c + 3.7));\n vec3 ctr = c + hash33(c);\n float rad = mix(0.12, 0.36, hash13(c + 17.3));\n float d = length(q - ctr) / rad;\n float bowl = d < 1.0 ? (d * d - 1.0) : 0.0;\n float rim = d >= 1.0 ? exp(-pow((d - 1.0) * 5.0, 2.0)) * 0.3 * smoothstep(1.0, 1.08, d) : 0.0;\n h += on * amp * rad * (bowl + rim) * (1.0 - smoothstep(0.14, 0.34, fw / rad));\n }\n return h;\n}\n// How much of a crater layer's height the relief may use (MODULES-1639). The relief is the difference between neighbouring pixels (1 to 2 pixels apart, and the screen works in blocks of 2 by 2), and it tips the surface all\n// the way wherever there is any slope, so a crater a few pixels across is read as noise: a lattice of dark dots over the lit side. The layer's mean crater (0.24 of a cell, a cell being 1 / freq of a radian) is about\n// 0.24 / (freq * pixel) pixels across its radius: under RELIEF_FROM of them the layer has no share, over RELIEF_FULL all of it, and the share rises as the eighth power of the ramp, so a layer part way up (the ramp gives a\n// tail of a few thousandths, which the tilt would still turn all the way) is not seen. The colour of the same crater is drawn whatever the share.\nconst float RELIEF_FROM = 8.0;\nconst float RELIEF_FULL = 16.0;\nfloat reliefShare(vec3 p, float freq) {\n float w = smoothstep(RELIEF_FROM, RELIEF_FULL, 0.24 / (freq * max(length(fwidth(p)), 1e-6)));\n float w2 = w * w; float w4 = w2 * w2;\n return w4 * w4;\n}\nfloat lon(vec3 p) { return atan(p.y, p.x); }\nfloat lat(vec3 p) { return asin(clamp(p.z, -1.0, 1.0)); }\nfloat wrapPi(float a) { return a - 6.2831853 * floor((a + 3.1415927) / 6.2831853); }\nvec3 dirOf(float lonDeg, float latDeg) { float lo = radians(lonDeg); float la = radians(latDeg); return vec3(cos(la) * cos(lo), cos(la) * sin(lo), sin(la)); }\n// One big round bowl with a rim, by longitude, latitude and angular radius in degrees. Negative inside.\nfloat bowl(vec3 p, float lonDeg, float latDeg, float radDeg, float depth) {\n float d = acos(clamp(dot(p, dirOf(lonDeg, latDeg)), -1.0, 1.0)) / radians(radDeg);\n return d < 1.0 ? depth * (d * d - 1.0) : depth * exp(-pow((d - 1.0) * 5.0, 2.0)) * 0.3 * smoothstep(1.0, 1.08, d);\n}\n// A soft oval on the body, 1 inside and 0 outside, by longitude and latitude in degrees.\nfloat oval(vec3 p, float lon0, float lat0, float rx, float ry, float soft) {\n float dx = wrapPi(lon(p) - radians(lon0)) * cos(radians(lat0)) / radians(rx);\n float dy = (lat(p) - radians(lat0)) / radians(ry);\n return 1.0 - smoothstep(1.0 - soft, 1.0, sqrt(dx * dx + dy * dy));\n}\nvoid main() {\n vec3 n = normalize(vN);\n float shade = 0.82 + 0.3 * (fbm(normalize(vObj) * 4.0) - 0.5);\n float diff = max(dot(n, uLight), 0.0);\n vec3 c = pow(uColour * shade, vec3(2.2)) * (0.04 + 1.1 * diff);\n gl_FragColor = vec4(pow(c, vec3(1.0 / 2.2)), 1.0);\n}";
|
package/dist/scene/glsl.js
CHANGED
|
@@ -38,6 +38,17 @@ float craters(vec3 p, float freq, float amp, float seed) {
|
|
|
38
38
|
}
|
|
39
39
|
return h;
|
|
40
40
|
}
|
|
41
|
+
// How much of a crater layer's height the relief may use (MODULES-1639). The relief is the difference between neighbouring pixels (1 to 2 pixels apart, and the screen works in blocks of 2 by 2), and it tips the surface all
|
|
42
|
+
// the way wherever there is any slope, so a crater a few pixels across is read as noise: a lattice of dark dots over the lit side. The layer's mean crater (0.24 of a cell, a cell being 1 / freq of a radian) is about
|
|
43
|
+
// 0.24 / (freq * pixel) pixels across its radius: under RELIEF_FROM of them the layer has no share, over RELIEF_FULL all of it, and the share rises as the eighth power of the ramp, so a layer part way up (the ramp gives a
|
|
44
|
+
// tail of a few thousandths, which the tilt would still turn all the way) is not seen. The colour of the same crater is drawn whatever the share.
|
|
45
|
+
const float RELIEF_FROM = 8.0;
|
|
46
|
+
const float RELIEF_FULL = 16.0;
|
|
47
|
+
float reliefShare(vec3 p, float freq) {
|
|
48
|
+
float w = smoothstep(RELIEF_FROM, RELIEF_FULL, 0.24 / (freq * max(length(fwidth(p)), 1e-6)));
|
|
49
|
+
float w2 = w * w; float w4 = w2 * w2;
|
|
50
|
+
return w4 * w4;
|
|
51
|
+
}
|
|
41
52
|
float lon(vec3 p) { return atan(p.y, p.x); }
|
|
42
53
|
float lat(vec3 p) { return asin(clamp(p.z, -1.0, 1.0)); }
|
|
43
54
|
float wrapPi(float a) { return a - 6.2831853 * floor((a + 3.1415927) / 6.2831853); }
|
package/dist/scene/look.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { BodyId } from "../facts.ts";
|
|
2
|
+
import type { ShapeTable } from "./shape.ts";
|
|
3
|
+
export { shapeRadii, type ShapeTable } from "./shape.ts";
|
|
2
4
|
/**
|
|
3
5
|
* A rim of air: the colour it scatters (0 to 1 each), how strong it is and how thin the rim is.
|
|
4
6
|
*
|
|
@@ -98,6 +100,11 @@ export interface BodyLook {
|
|
|
98
100
|
stretch?: number;
|
|
99
101
|
};
|
|
100
102
|
painted?: PaintedMap;
|
|
103
|
+
/**
|
|
104
|
+
* The real shape of a small moon: a function that fetches its table of radii (a chunk of its own, made from a published shape model), so that the body is drawn as the globe moved to those radii, with this look's shader, map and light, instead of the
|
|
105
|
+
* ellipsoid of `axesKm`. Until it arrives the ellipsoid is drawn.
|
|
106
|
+
*/
|
|
107
|
+
shape?: () => Promise<ShapeTable>;
|
|
101
108
|
/** Draw the painted map in the realistic look too: for a body with no honest drawing from numbers (the Earth's continents). */
|
|
102
109
|
mapped?: boolean;
|
|
103
110
|
}
|
package/dist/scene/look.js
CHANGED
package/dist/scene/painter.js
CHANGED
|
@@ -10,6 +10,7 @@ import { bodyFragment, GLOW_FRAGMENT, GLOW_VERTEX, PAINTED_SURFACE, PAINTED_SURF
|
|
|
10
10
|
import { fallbackLook } from "./fallback.js";
|
|
11
11
|
import { createDetail } from "./detail.js";
|
|
12
12
|
import { detailOf, lookOf } from "./look.js";
|
|
13
|
+
import { shapeGeometry } from "./shape.js";
|
|
13
14
|
import { seenRegion } from "./tiles.js";
|
|
14
15
|
import { moonOffset, orientation } from "./orient.js";
|
|
15
16
|
import { ringStrip } from "./rings.js";
|
|
@@ -366,9 +367,23 @@ function paint(T, id, context, bases, hold) {
|
|
|
366
367
|
},
|
|
367
368
|
});
|
|
368
369
|
const axes = facts.axesKm;
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
370
|
+
let scaleX = axes ? axes[1] / facts.radiusKm : 1;
|
|
371
|
+
let scaleY = axes ? axes[2] / facts.radiusKm : 1 - facts.flattening;
|
|
372
|
+
let scaleZ = axes ? axes[0] / facts.radiusKm : 1;
|
|
373
|
+
// a moon with a published shape model: the globe moved to its radii takes the ellipsoid's place when its table (a chunk of its own) arrives, and needs no stretching
|
|
374
|
+
if (look.shape !== undefined) {
|
|
375
|
+
look.shape().then((table) => {
|
|
376
|
+
if (gone)
|
|
377
|
+
return;
|
|
378
|
+
const shaped = acquire(T, `shape:${id}`, () => shapeGeometry(T, table, facts.radiusKm, { lon: 96, lat: 48 }));
|
|
379
|
+
releases.push(shaped.release);
|
|
380
|
+
mesh.geometry = shaped.value;
|
|
381
|
+
scaleX = 1;
|
|
382
|
+
scaleY = 1;
|
|
383
|
+
scaleZ = 1;
|
|
384
|
+
redraw();
|
|
385
|
+
}, () => undefined);
|
|
386
|
+
}
|
|
372
387
|
const light = new T.Vector3();
|
|
373
388
|
const poleVec = new T.Vector3();
|
|
374
389
|
// 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
|
package/dist/scene/recipes.js
CHANGED
|
@@ -37,13 +37,17 @@ export function rock(options) {
|
|
|
37
37
|
const seed = (options.seed ?? 0).toFixed(1);
|
|
38
38
|
return `
|
|
39
39
|
vec4 surface(vec3 p) {
|
|
40
|
-
float
|
|
40
|
+
float h1 = craters(p, 3.0, ${(c * 1.0).toFixed(2)}, ${seed});
|
|
41
|
+
float h2 = craters(p, 8.0, ${(c * 0.7).toFixed(2)}, ${seed} + 7.0) * 0.6;
|
|
42
|
+
float h3 = craters(p, 20.0, ${(c * 0.6).toFixed(2)}, ${seed} + 3.0) * 0.3;
|
|
43
|
+
float h = h1 + h2 + h3;
|
|
44
|
+
float hr = h1 * reliefShare(p, 3.0) + h2 * reliefShare(p, 8.0) + h3 * reliefShare(p, 20.0);
|
|
41
45
|
float tone = fbm(p * ${(options.patches ?? 2.3).toFixed(2)} + ${seed});
|
|
42
46
|
vec3 col = mix(${vec(options.dark)}, ${vec(options.light)}, smoothstep(0.25, 0.75, tone));
|
|
43
47
|
col *= 1.0 + ${(options.contrast ?? 1).toFixed(2)} * 1.15 * h;
|
|
44
48
|
col *= 0.94 + 0.12 * fbm(p * 60.0);
|
|
45
49
|
${options.extra ?? ""}
|
|
46
|
-
return vec4(col,
|
|
50
|
+
return vec4(col, hr);
|
|
47
51
|
}`;
|
|
48
52
|
}
|
|
49
53
|
/** A world wrapped in cloud: pale and smooth, streaked and swirled. */
|
package/dist/scene/rings.js
CHANGED
|
@@ -4,6 +4,7 @@ const PALETTE = {
|
|
|
4
4
|
uranus: [[58, 62, 66], [150, 158, 162]],
|
|
5
5
|
neptune: [[48, 56, 70], [140, 156, 176]],
|
|
6
6
|
};
|
|
7
|
+
const RING_FLOOR = 0.12;
|
|
7
8
|
const hash = (n) => {
|
|
8
9
|
const s = Math.sin(n * 127.1 + 311.7) * 43758.5453;
|
|
9
10
|
return s - Math.floor(s);
|
|
@@ -41,6 +42,8 @@ export function ringStrip(facts, width = 1024) {
|
|
|
41
42
|
const [dark, light] = PALETTE[facts.id] ?? [[90, 90, 90], [170, 170, 170]];
|
|
42
43
|
const data = new Uint8Array(width * 4);
|
|
43
44
|
const km = (to - from) / width;
|
|
45
|
+
const alphas = new Float32Array(width);
|
|
46
|
+
const tones = new Float32Array(width);
|
|
44
47
|
for (let x = 0; x < width; x += 1) {
|
|
45
48
|
const r = from + (x + 0.5) * km;
|
|
46
49
|
let alpha = 0;
|
|
@@ -56,8 +59,14 @@ export function ringStrip(facts, width = 1024) {
|
|
|
56
59
|
tone += inside * band.tone * (0.9 + 0.2 * ripple(r / 650 + 7));
|
|
57
60
|
weight += inside;
|
|
58
61
|
}
|
|
59
|
-
|
|
60
|
-
|
|
62
|
+
alphas[x] = alpha;
|
|
63
|
+
tones[x] = weight > 0 ? Math.min(1, tone / weight) : 0;
|
|
64
|
+
}
|
|
65
|
+
// The floor is a drawing choice, not physics: a system whose most opaque point would come out under RING_FLOOR (Jupiter's, Neptune's) is scaled up together until that point reaches it, so it stays just visible and its parts keep their order.
|
|
66
|
+
const lift = Math.max(1, RING_FLOOR / Math.max(...alphas));
|
|
67
|
+
for (let x = 0; x < width; x += 1) {
|
|
68
|
+
const t = tones[x];
|
|
69
|
+
const a = Math.min(1, alphas[x] * lift);
|
|
61
70
|
// The colour is stored already multiplied by the opacity. A clear part of the strip is black, so it stays clear even when a sampler drops the alpha.
|
|
62
71
|
data[x * 4] = Math.round((dark[0] + (light[0] - dark[0]) * t) * a);
|
|
63
72
|
data[x * 4 + 1] = Math.round((dark[1] + (light[1] - dark[1]) * t) * a);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type * as THREE from "three";
|
|
2
|
+
import type { ThreeParts } from "./body.ts";
|
|
3
|
+
/**
|
|
4
|
+
* A moon's shape as a table of radii: `lon` steps of longitude and `lat` steps of latitude round the globe (the vertices of `SphereGeometry(1, lon, lat)`, `(lat + 1) * lon` radii, the seam and the poles shared), each
|
|
5
|
+
* in units of 1 / `unit` kilometre (`unit` is a tenth of a per cent of the moon's mean radius). The radii are whole numbers of those units, each stored as how far it is from the one predicted from its neighbours
|
|
6
|
+
* (the one to the west plus the one to the north less the one to the north-west; the first column from the one to its north; the first row from the one to its west), as 16-bit integers, little-endian, in base64.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { shapeRadii, type ShapeTable } from "@johnmorrisdotca/wakusei-planets/look";
|
|
11
|
+
*
|
|
12
|
+
* const table: ShapeTable = { lon: 2, lat: 1, unit: 2, steps: "BAAAAAAAAAAAAAAAAA==" };
|
|
13
|
+
* console.log(shapeRadii(table));
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export interface ShapeTable {
|
|
17
|
+
lon: number;
|
|
18
|
+
lat: number;
|
|
19
|
+
unit: number;
|
|
20
|
+
steps: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The radii of a table in kilometres, `lat + 1` rows of `lon`, the first row at the north pole.
|
|
24
|
+
*
|
|
25
|
+
* @param table - The table.
|
|
26
|
+
* @returns The radii.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { shapeRadii } from "@johnmorrisdotca/wakusei-planets/look";
|
|
31
|
+
*
|
|
32
|
+
* console.log(shapeRadii({ lon: 2, lat: 1, unit: 2, steps: "BAAAAAAAAAAAAAAAAA==" }));
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function shapeRadii(table: ShapeTable): Float32Array;
|
|
36
|
+
/**
|
|
37
|
+
* The globe moved to the moon's shape: positions in units of `meanKm` (1 is the moon's mean radius), normals from the moved mesh with the seam and the poles joined. The caller disposes it.
|
|
38
|
+
* The globe has the table's own steps of longitude and of latitude, or `grid`'s where one is given, with the table's radii carried to it by a smooth curve: a finer globe for a big picture, a coarser one for a small picture
|
|
39
|
+
* and for the many moons of a page (a globe of 192 by 96 steps is 0.8 MB of arrays, which three.js keeps in the page after the card has it, and a page can hold a dozen).
|
|
40
|
+
*
|
|
41
|
+
* @param three - The parts of three.js the bodies use.
|
|
42
|
+
* @param table - The moon's table.
|
|
43
|
+
* @param meanKm - The moon's mean radius in kilometres, which the picture takes as 1.
|
|
44
|
+
* @param grid - The steps of longitude and of latitude of the globe, if not the table's.
|
|
45
|
+
* @returns The geometry.
|
|
46
|
+
*/
|
|
47
|
+
export declare function shapeGeometry(three: Pick<ThreeParts, "SphereGeometry">, table: ShapeTable, meanKm: number, grid?: {
|
|
48
|
+
readonly lon: number;
|
|
49
|
+
readonly lat: number;
|
|
50
|
+
}): THREE.BufferGeometry;
|