@johnmorrisdotca/wakusei-planets 0.23.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +41 -14
- package/dist/blackbody.d.ts +2 -0
- package/dist/blackbody.js +10 -0
- package/dist/element.d.ts +12 -0
- package/dist/element.js +160 -23
- package/dist/embed.d.ts +5 -0
- package/dist/embed.js +32 -8
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/kids/data.d.ts +109 -0
- package/dist/kids/data.js +164 -0
- package/dist/kids/index.d.ts +4 -0
- package/dist/kids/index.js +5 -0
- package/dist/kids/land.d.ts +3 -0
- package/dist/kids/land.js +29 -0
- package/dist/kids/picture.d.ts +39 -0
- package/dist/kids/picture.js +255 -0
- package/dist/kids/sheet.d.ts +60 -0
- package/dist/kids/sheet.js +79 -0
- package/dist/kids/svg.d.ts +46 -0
- package/dist/kids/svg.js +193 -0
- package/dist/line.d.ts +9 -1
- package/dist/line.js +3 -4
- package/dist/portrait/element.d.ts +9 -0
- package/dist/portrait/element.js +39 -5
- package/dist/scene/body.d.ts +8 -1
- package/dist/scene/body.js +33 -9
- package/dist/scene/glsl.d.ts +7 -2
- package/dist/scene/glsl.js +49 -3
- package/dist/scene/look.d.ts +43 -0
- package/dist/scene/look.js +39 -1
- package/dist/scene/store.d.ts +3 -0
- package/dist/scene/store.js +3 -1
- package/dist/scene/textures.d.ts +2 -2
- package/dist/space/element.d.ts +6 -0
- package/dist/space/element.js +18 -0
- package/dist/star-line.d.ts +20 -0
- package/dist/star-line.js +59 -0
- package/dist/star.d.ts +193 -0
- package/dist/star.js +261 -0
- package/dist/stars.js +3 -5
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +9 -2
package/dist/line.js
CHANGED
|
@@ -3,7 +3,7 @@ import { apparent, nearMoons, orbitPath, system } from "./ephemeris.js";
|
|
|
3
3
|
import { BODIES, ringReach } from "./facts.js";
|
|
4
4
|
import { facing, portrait, silhouette, surfacePoint } from "./pose.js";
|
|
5
5
|
import { cross, RAD, scale, unit } from "./vec.js";
|
|
6
|
-
const NAVY = "#0b1424";
|
|
6
|
+
export const NAVY = "#0b1424";
|
|
7
7
|
const hex = (c) => [parseInt(c.slice(1, 3), 16), parseInt(c.slice(3, 5), 16), parseInt(c.slice(5, 7), 16)];
|
|
8
8
|
/**
|
|
9
9
|
* Mix two `#rrggbb` colours: `t` is how much of `b` (0 to 1).
|
|
@@ -177,13 +177,12 @@ function cachedOrbit(id, time) {
|
|
|
177
177
|
}
|
|
178
178
|
return path;
|
|
179
179
|
}
|
|
180
|
-
|
|
181
|
-
|
|
180
|
+
/** The body's outline, features, rings and dark side as SVG, centred in `frame`. `facts` and `clip` stand in for the table's entry and the clip path's name when a star that is not in the table is drawn. */
|
|
181
|
+
export function bodyGroup(id, pose, frame, o, hair, ringScale, facts = BODIES[id], clipId = `wk-${id}-clip`) {
|
|
182
182
|
const sil = silhouette(pose, facts.flattening, axesOf(facts));
|
|
183
183
|
const disc = `<ellipse cx="${n(frame.cx)}" cy="${n(frame.cy)}" rx="${n(frame.r * sil.a)}" ry="${n(frame.r * sil.b)}" transform="rotate(${n(sil.angle)} ${n(frame.cx)} ${n(frame.cy)})"`;
|
|
184
184
|
const rings = ringPaths(facts, pose, frame, o.stroke, hair, ringScale);
|
|
185
185
|
const dark = id === "sun" || facts.kind === "star" ? "" : nightPath(pose, frame);
|
|
186
|
-
const clipId = `wk-${id}-clip`;
|
|
187
186
|
return [
|
|
188
187
|
rings.back,
|
|
189
188
|
`${disc} fill="${o.paper}" stroke="${o.stroke}" stroke-width="${n(hair * 1.6)}"/>`,
|
|
@@ -22,6 +22,9 @@ export type PortraitState = "line" | "loading" | "still" | "live" | "lost" | "un
|
|
|
22
22
|
* Attributes: `scene` (the scene as the portrait builder writes it in its address), `look` (`line`, `realistic` or `painted`: replaces the scene's), `size` (pixels across), `lang` (`en` or `ja`: the names),
|
|
23
23
|
* `live` (`always`, `hover` or `off`: when it takes the page's one WebGL context), `texture-base` and `texture-far-base` (where the surface pictures are).
|
|
24
24
|
*
|
|
25
|
+
* It carries the shared view controls itself: a drag moves the picture, two fingers pinch, Ctrl, Command or Alt with the wheel zooms (the plain wheel scrolls the page at Fit), and the arrow keys, + and - and 0 work once it is focused.
|
|
26
|
+
* `controls="none"` turns them off (the portrait builder does, for it edits the scene by dragging its bodies); `zoom-min` and `zoom-max` set the range (0.1 to 8 by default); a `<kazoku-view-controls for="...">` takes over and reads it.
|
|
27
|
+
*
|
|
25
28
|
* @example
|
|
26
29
|
* ```ts no-run
|
|
27
30
|
* import { WakuseiPortrait } from "@johnmorrisdotca/wakusei-planets/portrait";
|
|
@@ -67,6 +70,12 @@ export declare class WakuseiPortrait extends HTMLElement {
|
|
|
67
70
|
connectedCallback(): void;
|
|
68
71
|
disconnectedCallback(): void;
|
|
69
72
|
attributeChangedCallback(name: string): void;
|
|
73
|
+
/** The shared controllers' camera over the scene's own (and a `wakusei-view` event with the `zoom`, `panX` and `panY`): `zoom` scales the picture about its middle, `panX` and `panY` move it by that many CSS pixels. The scene's camera, and what `portrait` holds, are left as they are. */
|
|
74
|
+
setView(view: {
|
|
75
|
+
zoom?: number;
|
|
76
|
+
panX?: number;
|
|
77
|
+
panY?: number;
|
|
78
|
+
}): void;
|
|
70
79
|
/** Take the page's one WebGL context and draw the scene on it. Resolves true when it is live; a line scene has nothing to take and resolves false. */
|
|
71
80
|
goLive(): Promise<boolean>;
|
|
72
81
|
/** Give the WebGL context back: the picture stays as a still. */
|
package/dist/portrait/element.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { carryControls } from "@johnmorrisdotca/kazoku-ui/view-controls";
|
|
1
2
|
import { BODIES } from "../facts.js";
|
|
2
3
|
import { createGate, frameCap } from "../gate.js";
|
|
3
4
|
import { setThreeLoader, takeRenderer } from "../scene/shared.js";
|
|
@@ -10,6 +11,11 @@ import { REDUCED_TURN } from "../live.js";
|
|
|
10
11
|
import { poseOf } from "./pose.js";
|
|
11
12
|
import { createPortraitItem } from "./scene3d.js";
|
|
12
13
|
export { setThreeLoader };
|
|
14
|
+
/**
|
|
15
|
+
* The zoom range of a portrait that carries its own controls. The floor is arbitrary: a tenth of Fit leaves room to see the whole scene small. The ceiling is the painted maps: the sharpest is 2048 pixels round
|
|
16
|
+
* a body, which stays sharp to a few times the size at Fit and softens after that; 8 times is as far as the bodies' own shader detail goes. A scene of a line look has detail at any scale.
|
|
17
|
+
*/
|
|
18
|
+
const CARRIED_LIMITS = { zoomMin: 0.1, zoomMax: 8 };
|
|
13
19
|
const TEMPLATE = `<style>
|
|
14
20
|
:host { display: block; width: var(--wakusei-size, 720px); max-width: 100%; aspect-ratio: var(--wakusei-ratio, 16 / 9); position: relative; overflow: hidden; contain: layout style; touch-action: none; user-select: none; }
|
|
15
21
|
#bg, #stage, #over { position: absolute; inset: 0; width: 100%; height: 100%; }
|
|
@@ -26,6 +32,9 @@ const num = (value, fallback) => {
|
|
|
26
32
|
* Attributes: `scene` (the scene as the portrait builder writes it in its address), `look` (`line`, `realistic` or `painted`: replaces the scene's), `size` (pixels across), `lang` (`en` or `ja`: the names),
|
|
27
33
|
* `live` (`always`, `hover` or `off`: when it takes the page's one WebGL context), `texture-base` and `texture-far-base` (where the surface pictures are).
|
|
28
34
|
*
|
|
35
|
+
* It carries the shared view controls itself: a drag moves the picture, two fingers pinch, Ctrl, Command or Alt with the wheel zooms (the plain wheel scrolls the page at Fit), and the arrow keys, + and - and 0 work once it is focused.
|
|
36
|
+
* `controls="none"` turns them off (the portrait builder does, for it edits the scene by dragging its bodies); `zoom-min` and `zoom-max` set the range (0.1 to 8 by default); a `<kazoku-view-controls for="...">` takes over and reads it.
|
|
37
|
+
*
|
|
29
38
|
* @example
|
|
30
39
|
* ```ts no-run
|
|
31
40
|
* import { WakuseiPortrait } from "@johnmorrisdotca/wakusei-planets/portrait";
|
|
@@ -61,6 +70,10 @@ export class WakuseiPortrait extends HTMLElement {
|
|
|
61
70
|
#edit = {};
|
|
62
71
|
#overKey = "";
|
|
63
72
|
#lineKey = "";
|
|
73
|
+
#zoom = 1;
|
|
74
|
+
#panX = 0;
|
|
75
|
+
#panY = 0;
|
|
76
|
+
#hands;
|
|
64
77
|
#hover = () => void this.goLive();
|
|
65
78
|
#onContext = (state) => {
|
|
66
79
|
if (state === "unavailable")
|
|
@@ -147,6 +160,7 @@ export class WakuseiPortrait extends HTMLElement {
|
|
|
147
160
|
document.addEventListener("visibilitychange", this.#onHidden);
|
|
148
161
|
this.#applyHover();
|
|
149
162
|
this.#readAttributes();
|
|
163
|
+
this.#hands = carryControls(this, { turnable: false, limits: CARRIED_LIMITS, onChange: (view) => this.setView(view) });
|
|
150
164
|
this.#queue();
|
|
151
165
|
}
|
|
152
166
|
disconnectedCallback() {
|
|
@@ -154,6 +168,8 @@ export class WakuseiPortrait extends HTMLElement {
|
|
|
154
168
|
this.#io?.disconnect();
|
|
155
169
|
document.removeEventListener("visibilitychange", this.#onHidden);
|
|
156
170
|
this.#applyHover(false);
|
|
171
|
+
this.#hands?.unbind();
|
|
172
|
+
this.#hands = undefined;
|
|
157
173
|
this.#disposeView(true);
|
|
158
174
|
}
|
|
159
175
|
attributeChangedCallback(name) {
|
|
@@ -165,6 +181,24 @@ export class WakuseiPortrait extends HTMLElement {
|
|
|
165
181
|
this.#readAttributes();
|
|
166
182
|
this.#queue();
|
|
167
183
|
}
|
|
184
|
+
/** The shared controllers' camera over the scene's own (and a `wakusei-view` event with the `zoom`, `panX` and `panY`): `zoom` scales the picture about its middle, `panX` and `panY` move it by that many CSS pixels. The scene's camera, and what `portrait` holds, are left as they are. */
|
|
185
|
+
setView(view) {
|
|
186
|
+
const [zoom, panX, panY] = [Math.max(1e-6, view.zoom ?? 1), view.panX ?? 0, view.panY ?? 0];
|
|
187
|
+
if (zoom === this.#zoom && panX === this.#panX && panY === this.#panY)
|
|
188
|
+
return;
|
|
189
|
+
[this.#zoom, this.#panX, this.#panY] = [zoom, panX, panY];
|
|
190
|
+
this.dispatchEvent(new CustomEvent("wakusei-view", { detail: { zoom: this.#zoom, panX: this.#panX, panY: this.#panY } }));
|
|
191
|
+
this.#changed();
|
|
192
|
+
}
|
|
193
|
+
/** The scene's resolved camera with the view's zoom and pan put over it. */
|
|
194
|
+
#resolveNow() {
|
|
195
|
+
const resolved = resolve(this.#portrait);
|
|
196
|
+
if (this.#zoom === 1 && this.#panX === 0 && this.#panY === 0)
|
|
197
|
+
return resolved;
|
|
198
|
+
const h = resolved.camera.h / this.#zoom;
|
|
199
|
+
const scale = this.#size().height / (2 * h);
|
|
200
|
+
return { ...resolved, camera: { x: resolved.camera.x - this.#panX / scale, y: resolved.camera.y + this.#panY / scale, h } };
|
|
201
|
+
}
|
|
168
202
|
/** Take the page's one WebGL context and draw the scene on it. Resolves true when it is live; a line scene has nothing to take and resolves false. */
|
|
169
203
|
async goLive() {
|
|
170
204
|
if (this.#portrait.look === "line")
|
|
@@ -260,7 +294,7 @@ export class WakuseiPortrait extends HTMLElement {
|
|
|
260
294
|
if (!this.isConnected)
|
|
261
295
|
return;
|
|
262
296
|
if (this.#view?.live === true && !this.#queued) {
|
|
263
|
-
this.#resolved =
|
|
297
|
+
this.#resolved = this.#resolveNow();
|
|
264
298
|
this.#style();
|
|
265
299
|
this.#gate?.request();
|
|
266
300
|
}
|
|
@@ -303,7 +337,7 @@ export class WakuseiPortrait extends HTMLElement {
|
|
|
303
337
|
if (!this.isConnected)
|
|
304
338
|
return;
|
|
305
339
|
const p = this.#portrait;
|
|
306
|
-
this.#resolved =
|
|
340
|
+
this.#resolved = this.#resolveNow();
|
|
307
341
|
this.#style();
|
|
308
342
|
this.setAttribute("aria-label", this.#label());
|
|
309
343
|
const wants3d = p.look !== "line" && this.#state !== "unavailable" && p.items.length > 0;
|
|
@@ -360,7 +394,7 @@ export class WakuseiPortrait extends HTMLElement {
|
|
|
360
394
|
#drawLine() {
|
|
361
395
|
const { width, height } = this.#size();
|
|
362
396
|
const markup = this.#lineBody(width, height);
|
|
363
|
-
const key = `${width}x${height}|${markup.length}|${this.#portrait.light.az}`;
|
|
397
|
+
const key = `${width}x${height}|${markup.length}|${this.#portrait.light.az}|${this.#zoom.toFixed(3)},${this.#panX.toFixed(1)},${this.#panY.toFixed(1)}`;
|
|
364
398
|
if (this.#portrait.look !== "line") {
|
|
365
399
|
if (this.#stage.firstChild !== null && this.#lineKey !== "")
|
|
366
400
|
this.#stage.innerHTML = "";
|
|
@@ -374,7 +408,7 @@ export class WakuseiPortrait extends HTMLElement {
|
|
|
374
408
|
}
|
|
375
409
|
#key() {
|
|
376
410
|
const { width } = this.#size();
|
|
377
|
-
return `${encodeScene(this.#portrait)}|${width}`;
|
|
411
|
+
return `${encodeScene(this.#portrait)}|${width}|${this.#zoom.toFixed(3)},${this.#panX.toFixed(1)},${this.#panY.toFixed(1)}`;
|
|
378
412
|
}
|
|
379
413
|
// Replacing a view keeps the renderer lease; leaving 3D gives it back.
|
|
380
414
|
#disposeView(releaseRenderer = false) {
|
|
@@ -436,7 +470,7 @@ export class WakuseiPortrait extends HTMLElement {
|
|
|
436
470
|
}
|
|
437
471
|
// --- moving -------------------------------------------------------------------------------------------------------------------------------------------
|
|
438
472
|
#frame() {
|
|
439
|
-
this.#resolved =
|
|
473
|
+
this.#resolved = this.#resolveNow();
|
|
440
474
|
this.#paintOver();
|
|
441
475
|
if (this.#portrait.look === "line") {
|
|
442
476
|
this.#drawLine();
|
package/dist/scene/body.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Item3D, Scene3D } from "@johnmorrisdotca/kazoku-ui/renderer";
|
|
2
2
|
import type * as THREE from "three";
|
|
3
3
|
import type { Pose } from "../ephemeris.ts";
|
|
4
|
-
import { type BodyId } from "../facts.ts";
|
|
4
|
+
import { type BodyFacts, type BodyId } from "../facts.ts";
|
|
5
|
+
import { type BodyLook } from "./look.ts";
|
|
5
6
|
export { fallbackLook } from "./fallback.ts";
|
|
6
7
|
/** The parts of three.js the bodies use: a page may hand over a module with only these (see `setThreeLoader`). */
|
|
7
8
|
export type ThreeParts = Pick<typeof THREE, "AdditiveBlending" | "BufferAttribute" | "BufferGeometry" | "ClampToEdgeWrapping" | "DataTexture" | "DoubleSide" | "Group" | "Line" | "LineBasicMaterial" | "LinearFilter" | "Mesh" | "NoColorSpace" | "OrthographicCamera" | "PlaneGeometry" | "RepeatWrapping" | "RGBAFormat" | "RingGeometry" | "Scene" | "ShaderMaterial" | "SphereGeometry" | "TextureLoader" | "Vector2" | "Vector3" | "WebGLRenderer">;
|
|
@@ -39,6 +40,12 @@ export interface BodyScene extends Scene3D {
|
|
|
39
40
|
}
|
|
40
41
|
export interface BodyItemOptions {
|
|
41
42
|
id: BodyId;
|
|
43
|
+
/** The look to draw instead of the one registered for `id`: a star made from numbers (`starLook`). */
|
|
44
|
+
shaded?: BodyLook;
|
|
45
|
+
/** The facts to draw instead of the table's for `id` (a star's size and flattening). */
|
|
46
|
+
facts?: BodyFacts;
|
|
47
|
+
/** What the renderer keeps this body's materials under, instead of `id`: a star's key, so two stars do not share a program. */
|
|
48
|
+
assetKey?: string;
|
|
42
49
|
look: "realistic" | "painted";
|
|
43
50
|
/** A key that changes whenever the picture would: the renderer keeps one still for each key. */
|
|
44
51
|
key: string;
|
package/dist/scene/body.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BODIES } from "../facts.js";
|
|
2
|
+
import { silhouette } from "../pose.js";
|
|
2
3
|
import { cross } from "../vec.js";
|
|
3
|
-
import { BALL_FRAGMENT, bodyFragment, GLOW_FRAGMENT, GLOW_VERTEX, PAINTED_SURFACE, RING_FRAGMENT, RING_VERTEX, VERTEX } from "./glsl.js";
|
|
4
|
+
import { BALL_FRAGMENT, bodyFragment, GLOW_FRAGMENT, GLOW_VERTEX, PAINTED_SURFACE, RING_FRAGMENT, RING_VERTEX, STAR_GLOW_FRAGMENT, VERTEX } from "./glsl.js";
|
|
4
5
|
import { lookOf } from "./look.js";
|
|
5
6
|
import { fallbackLook } from "./fallback.js";
|
|
6
7
|
import { writeBasis } from "./basis.js";
|
|
@@ -11,7 +12,7 @@ function makeBodyMaterial(T, look, painted) {
|
|
|
11
12
|
const a = look.atmosphere;
|
|
12
13
|
return new T.ShaderMaterial({
|
|
13
14
|
vertexShader: VERTEX,
|
|
14
|
-
fragmentShader: bodyFragment(painted ? PAINTED_SURFACE : look.surface, painted),
|
|
15
|
+
fragmentShader: bodyFragment(painted ? PAINTED_SURFACE : look.surface, painted, false, look.limbTint),
|
|
15
16
|
uniforms: {
|
|
16
17
|
uLight: { value: new T.Vector3(-0.6, 0.2, 0.77) },
|
|
17
18
|
uRelief: { value: (painted ? (look.painted?.relief ?? 0) : (look.relief ?? 0.6)) },
|
|
@@ -22,6 +23,7 @@ function makeBodyMaterial(T, look, painted) {
|
|
|
22
23
|
uAtmosPow: { value: a?.power ?? 3 },
|
|
23
24
|
uRimBase: { value: 0.12 },
|
|
24
25
|
uEmissive: { value: look.emissive === true ? 1 : 0 },
|
|
26
|
+
uTime: { value: 0 },
|
|
25
27
|
...(painted ? { uMark: { value: look.painted?.turn === "hexagon" ? 2 : look.painted?.turn === "bands" ? 1 : 0 } } : {}),
|
|
26
28
|
uRingN: { value: new T.Vector3(0, 1, 0) },
|
|
27
29
|
uRingR: { value: new T.Vector2(1, 2) },
|
|
@@ -45,15 +47,16 @@ function setBasis(object, x, y, z, sx = 1, sy = 1, sz = 1) {
|
|
|
45
47
|
* @returns The item for kazoku-ui's shared renderer.
|
|
46
48
|
*/
|
|
47
49
|
export function createBodyItem(options) {
|
|
48
|
-
const facts = BODIES[options.id];
|
|
50
|
+
const facts = options.facts ?? BODIES[options.id];
|
|
51
|
+
const held = options.assetKey ?? options.id;
|
|
49
52
|
return {
|
|
50
53
|
key: options.key,
|
|
51
54
|
async build({ three: T, assets, width, height }) {
|
|
52
|
-
const look = lookOf(options.id) ?? fallbackLook(facts);
|
|
55
|
+
const look = options.shaded ?? lookOf(options.id) ?? fallbackLook(facts);
|
|
53
56
|
const wantPainted = (options.look === "painted" || look.mapped === true) && look.painted !== undefined;
|
|
54
57
|
const geometry = assets.acquire("wk:sphere", () => new T.SphereGeometry(1, 128, 64), (g) => g.dispose());
|
|
55
|
-
const shader = assets.acquire(`wk:body:${
|
|
56
|
-
const paintedMaterial = wantPainted ? assets.acquire(`wk:body:${
|
|
58
|
+
const shader = assets.acquire(`wk:body:${held}:r`, () => makeBodyMaterial(T, look, false), (m) => m.dispose());
|
|
59
|
+
const paintedMaterial = wantPainted ? assets.acquire(`wk:body:${held}:p`, () => makeBodyMaterial(T, look, true), (m) => m.dispose()) : undefined;
|
|
57
60
|
const materials = paintedMaterial === undefined ? [shader] : [shader, paintedMaterial];
|
|
58
61
|
const baseWrap = look.wrap ?? (look.atmosphere === undefined ? 0.04 : 0.3);
|
|
59
62
|
const baseAmbient = look.ambient ?? 0.04;
|
|
@@ -124,13 +127,18 @@ export function createBodyItem(options) {
|
|
|
124
127
|
}
|
|
125
128
|
// the glow of a star
|
|
126
129
|
let glow;
|
|
130
|
+
let glowMaterialOf;
|
|
127
131
|
if (look.emissive === true) {
|
|
128
132
|
const glowGeometry = assets.acquire("wk:glow", () => new T.PlaneGeometry(6, 6), (g) => g.dispose());
|
|
129
|
-
const
|
|
133
|
+
const own = look.glow;
|
|
134
|
+
const glowMaterial = own === undefined
|
|
135
|
+
? assets.acquire("wk:glowmat", () => new T.ShaderMaterial({ vertexShader: GLOW_VERTEX, fragmentShader: GLOW_FRAGMENT, transparent: true, depthWrite: false, blending: T.AdditiveBlending, uniforms: { uColour: { value: new T.Vector3(1, 0.7, 0.3) } } }), (m) => m.dispose())
|
|
136
|
+
: assets.acquire(`wk:glowmat:${held}`, () => new T.ShaderMaterial({ vertexShader: GLOW_VERTEX, fragmentShader: STAR_GLOW_FRAGMENT, transparent: true, depthWrite: false, blending: T.AdditiveBlending, uniforms: { uColour: { value: new T.Vector3(...own.colour) }, uStrength: { value: own.strength }, uSpread: { value: own.spread }, uRim: { value: own.rim ?? 0 }, uProm: { value: own.prominence ?? 0 }, uSeed: { value: own.seed ?? 0 }, uTime: { value: 0 } } }), (m) => m.dispose());
|
|
130
137
|
glow = new T.Mesh(glowGeometry, glowMaterial);
|
|
131
138
|
glow.position.z = -5;
|
|
132
139
|
glow.scale.setScalar(1);
|
|
133
140
|
glow.frustumCulled = false;
|
|
141
|
+
glowMaterialOf = glowMaterial;
|
|
134
142
|
scene.add(glow);
|
|
135
143
|
}
|
|
136
144
|
// moons, made on first use
|
|
@@ -332,8 +340,24 @@ export function createBodyItem(options) {
|
|
|
332
340
|
mat.uniforms.uAmbient.value = sky ? 0.012 : baseAmbient;
|
|
333
341
|
mat.uniforms.uRimBase.value = sky ? 0.02 : 0.12;
|
|
334
342
|
}
|
|
335
|
-
if (glow !== undefined)
|
|
336
|
-
|
|
343
|
+
if (look.glow !== undefined) {
|
|
344
|
+
// the star's surface boils and its prominences move with the clock, but only when a frame is asked for: a star at rest draws nothing
|
|
345
|
+
const seconds = (performance.now() / 1000) % 100_000;
|
|
346
|
+
for (const mat of materials)
|
|
347
|
+
mat.uniforms.uTime.value = seconds;
|
|
348
|
+
if (glowMaterialOf !== undefined)
|
|
349
|
+
glowMaterialOf.uniforms.uTime.value = seconds;
|
|
350
|
+
}
|
|
351
|
+
if (glow !== undefined) {
|
|
352
|
+
// a flattened star is squeezed along its pole: the glow starts at its edge, not at a round one
|
|
353
|
+
if (look.glow !== undefined && facts.flattening > 0) {
|
|
354
|
+
const { b, angle } = silhouette(state.pose, facts.flattening);
|
|
355
|
+
glow.rotation.z = (-angle * Math.PI) / 180;
|
|
356
|
+
glow.scale.set(1, b, 1);
|
|
357
|
+
}
|
|
358
|
+
else
|
|
359
|
+
glow.scale.setScalar(1);
|
|
360
|
+
}
|
|
337
361
|
requestSharperTexture(state);
|
|
338
362
|
};
|
|
339
363
|
apply(latest);
|
package/dist/scene/glsl.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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
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.35, 0.9, fw / rad));\n }\n return h;\n}\nfloat lon(vec3 p) { return atan(p.y, p.x); }\nfloat lat(vec3 p) { return asin(clamp(p.z, -1.0, 1.0)); }\nfloat wrapPi(float a) { return a - 6.2831853 * floor((a + 3.1415927) / 6.2831853); }\nvec3 dirOf(float lonDeg, float latDeg) { float lo = radians(lonDeg); float la = radians(latDeg); return vec3(cos(la) * cos(lo), cos(la) * sin(lo), sin(la)); }\n// One big round bowl with a rim, by longitude, latitude and angular radius in degrees. Negative inside.\nfloat bowl(vec3 p, float lonDeg, float latDeg, float radDeg, float depth) {\n float d = acos(clamp(dot(p, dirOf(lonDeg, latDeg)), -1.0, 1.0)) / radians(radDeg);\n return d < 1.0 ? depth * (d * d - 1.0) : depth * exp(-pow((d - 1.0) * 5.0, 2.0)) * 0.3 * smoothstep(1.0, 1.08, d);\n}\n// A soft oval on the body, 1 inside and 0 outside, by longitude and latitude in degrees.\nfloat oval(vec3 p, float lon0, float lat0, float rx, float ry, float soft) {\n float dx = wrapPi(lon(p) - radians(lon0)) * cos(radians(lat0)) / radians(rx);\n float dy = (lat(p) - radians(lat0)) / radians(ry);\n return 1.0 - smoothstep(1.0 - soft, 1.0, sqrt(dx * dx + dy * dy));\n}";
|
|
4
|
-
/** The fragment shader of a body: the surface code goes between the prelude and `main`. */
|
|
5
|
-
export declare function bodyFragment(surface: string, painted: boolean, world?: boolean): string;
|
|
4
|
+
/** The fragment shader of a body: the surface code goes between the prelude and `main`. `limbTint` is the colour the edge of a glowing body shifts to (default the Sun's orange). */
|
|
5
|
+
export declare function bodyFragment(surface: string, painted: boolean, world?: boolean, limbTint?: readonly [number, number, number]): string;
|
|
6
6
|
/** A painted body's surface code: the map by longitude and latitude, with the seam at 180 degrees left alone. */
|
|
7
7
|
export declare const PAINTED_SURFACE = "\nvec4 surface(vec3 p) {\n float u1 = atan(p.y, p.x) / 6.2831853 + 0.5;\n float u2 = fract(u1 + 0.5) - 0.5;\n float v = asin(clamp(p.z, -1.0, 1.0)) / 3.1415927 + 0.5;\n vec2 a = vec2(u1, v); vec2 b = vec2(u2, v);\n vec2 ax = dFdx(a); vec2 ay = dFdy(a); vec2 bx = dFdx(b); vec2 by = dFdy(b);\n bool useA = dot(ax, ax) + dot(ay, ay) <= dot(bx, bx) + dot(by, by);\n vec3 c = textureGrad(uMap, useA ? a : b, useA ? ax : bx, useA ? ay : by).rgb;\n // A map of plain bands is the same at every longitude, so the body turns and the picture does not. The wave, the spot and the polar hexagon move with the surface.\n if (uMark > 0.5) {\n float lon = atan(p.y, p.x);\n float lat = asin(clamp(p.z, -1.0, 1.0));\n float wave = sin(lon * 4.0 + lat * 6.0);\n float belt = 1.0 - smoothstep(1.15, 1.45, abs(lat));\n c *= 0.86 + 0.22 * (0.5 + 0.5 * wave) * belt;\n if (uMark > 1.5) {\n float ang = atan(p.y, p.x);\n float radius = length(p.xy);\n float hexR = 0.26 + 0.045 * cos(ang * 6.0);\n float hex = (1.0 - smoothstep(0.0, 0.028, abs(radius - hexR))) * smoothstep(0.42, 0.68, p.z);\n c = mix(c, vec3(0.45, 0.55, 0.68), hex);\n } else {\n float spot = exp(-pow((lat - 0.32) / 0.2, 2.0) - pow(lon / 0.5, 2.0));\n c = mix(c, c * vec3(0.28, 0.34, 0.5), clamp(spot, 0.0, 1.0));\n }\n }\n return vec4(c, dot(c, vec3(0.3, 0.59, 0.11)));\n}";
|
|
8
8
|
export declare const RING_FRAGMENT = "\nprecision highp float;\nuniform sampler2D uRingTex;\nuniform vec2 uRingR;\nuniform vec3 uLight;\nuniform vec3 uRingN;\nvarying vec3 vL;\nvarying vec3 vW;\nvoid main() {\n float u = (length(vL.xy) - uRingR.x) / (uRingR.y - uRingR.x);\n if (u < 0.0 || u > 1.0) discard;\n vec4 t = texture2D(uRingTex, vec2(u, 0.5));\n float nl = dot(uRingN, uLight);\n float side = nl * uRingN.z;\n float bright = 0.16 + 0.84 * clamp(abs(nl) * 2.0, 0.0, 1.0);\n if (side < 0.0) bright *= 0.38;\n float b = dot(vW, uLight);\n float closest = sqrt(max(dot(vW, vW) - b * b, 0.0));\n float shadow = b < 0.0 ? smoothstep(1.02, 0.97, closest) : 0.0;\n vec3 c = pow(t.rgb, vec3(2.2)) * bright * (1.0 - 0.93 * shadow);\n gl_FragColor = vec4(pow(c, vec3(1.0 / 2.2)), t.a);\n}";
|
|
@@ -18,5 +18,10 @@ export declare const RING_VERTEX_WORLD = "\nuniform float uScale;\nvarying vec3
|
|
|
18
18
|
export declare const RING_FRAGMENT_WORLD: string;
|
|
19
19
|
export declare const GLOW_VERTEX = "\nvarying vec2 vP;\nvoid main() { vP = position.xy; gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }";
|
|
20
20
|
export declare const GLOW_FRAGMENT = "\nprecision highp float;\nvarying vec2 vP;\nuniform vec3 uColour;\nvoid main() {\n float r = length(vP);\n if (r < 0.98) discard;\n float a = exp(-(r - 1.0) * 2.4) * 0.62;\n float streak = 0.82 + 0.18 * sin(atan(vP.y, vP.x) * 9.0 + r * 3.0);\n a *= streak * smoothstep(3.0, 1.6, r);\n gl_FragColor = vec4(uColour * a, a);\n}";
|
|
21
|
+
/**
|
|
22
|
+
* The glow round a star that is not the Sun, drawn on a plane behind it: a wide soft bloom, a tight bright inner bloom, a thin glowing edge (the chromosphere), and, on an active star, prominences standing off the edge
|
|
23
|
+
* with an occasional flare. `uStrength` is how bright, `uSpread` how fast the bloom fades, `uRim` the edge, `uProm` how big the prominences are, `uSeed` where they are and `uTime` moves them.
|
|
24
|
+
*/
|
|
25
|
+
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}";
|
|
21
26
|
/** A cheap lit ball for a moon seen small beside its planet. */
|
|
22
27
|
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.35, 0.9, fw / rad));\n }\n return h;\n}\nfloat lon(vec3 p) { return atan(p.y, p.x); }\nfloat lat(vec3 p) { return asin(clamp(p.z, -1.0, 1.0)); }\nfloat wrapPi(float a) { return a - 6.2831853 * floor((a + 3.1415927) / 6.2831853); }\nvec3 dirOf(float lonDeg, float latDeg) { float lo = radians(lonDeg); float la = radians(latDeg); return vec3(cos(la) * cos(lo), cos(la) * sin(lo), sin(la)); }\n// One big round bowl with a rim, by longitude, latitude and angular radius in degrees. Negative inside.\nfloat bowl(vec3 p, float lonDeg, float latDeg, float radDeg, float depth) {\n float d = acos(clamp(dot(p, dirOf(lonDeg, latDeg)), -1.0, 1.0)) / radians(radDeg);\n return d < 1.0 ? depth * (d * d - 1.0) : depth * exp(-pow((d - 1.0) * 5.0, 2.0)) * 0.3 * smoothstep(1.0, 1.08, d);\n}\n// A soft oval on the body, 1 inside and 0 outside, by longitude and latitude in degrees.\nfloat oval(vec3 p, float lon0, float lat0, float rx, float ry, float soft) {\n float dx = wrapPi(lon(p) - radians(lon0)) * cos(radians(lat0)) / radians(rx);\n float dy = (lat(p) - radians(lat0)) / radians(ry);\n return 1.0 - smoothstep(1.0 - soft, 1.0, sqrt(dx * dx + dy * dy));\n}\nvoid main() {\n vec3 n = normalize(vN);\n float shade = 0.82 + 0.3 * (fbm(normalize(vObj) * 4.0) - 0.5);\n float diff = max(dot(n, uLight), 0.0);\n vec3 c = pow(uColour * shade, vec3(2.2)) * (0.04 + 1.1 * diff);\n gl_FragColor = vec4(pow(c, vec3(1.0 / 2.2)), 1.0);\n}";
|
package/dist/scene/glsl.js
CHANGED
|
@@ -52,8 +52,9 @@ float oval(vec3 p, float lon0, float lat0, float rx, float ry, float soft) {
|
|
|
52
52
|
float dy = (lat(p) - radians(lat0)) / radians(ry);
|
|
53
53
|
return 1.0 - smoothstep(1.0 - soft, 1.0, sqrt(dx * dx + dy * dy));
|
|
54
54
|
}`;
|
|
55
|
-
/** The fragment shader of a body: the surface code goes between the prelude and `main`. */
|
|
56
|
-
export function bodyFragment(surface, painted, world = false) {
|
|
55
|
+
/** The fragment shader of a body: the surface code goes between the prelude and `main`. `limbTint` is the colour the edge of a glowing body shifts to (default the Sun's orange). */
|
|
56
|
+
export function bodyFragment(surface, painted, world = false, limbTint) {
|
|
57
|
+
const tint = limbTint === undefined ? "vec3(1.0, 0.55, 0.25)" : `vec3(${limbTint.map((v) => v.toFixed(4)).join(", ")})`;
|
|
57
58
|
return /* glsl */ `
|
|
58
59
|
precision highp float;
|
|
59
60
|
uniform vec3 uLight;
|
|
@@ -84,7 +85,7 @@ void main() {
|
|
|
84
85
|
float mu = ${world ? "clamp(dot(n, normalize(vV)), 0.0, 1.0)" : "clamp(n.z, 0.0, 1.0)"};
|
|
85
86
|
if (uEmissive > 0.5) {
|
|
86
87
|
float edge = pow(mu, uLimb);
|
|
87
|
-
vec3 c = s.rgb * mix(
|
|
88
|
+
vec3 c = s.rgb * mix(${tint}, vec3(1.0), edge) * (0.55 + 0.45 * edge);
|
|
88
89
|
gl_FragColor = vec4(c, 1.0);
|
|
89
90
|
return;
|
|
90
91
|
}
|
|
@@ -235,6 +236,51 @@ void main() {
|
|
|
235
236
|
a *= streak * smoothstep(3.0, 1.6, r);
|
|
236
237
|
gl_FragColor = vec4(uColour * a, a);
|
|
237
238
|
}`;
|
|
239
|
+
/**
|
|
240
|
+
* The glow round a star that is not the Sun, drawn on a plane behind it: a wide soft bloom, a tight bright inner bloom, a thin glowing edge (the chromosphere), and, on an active star, prominences standing off the edge
|
|
241
|
+
* with an occasional flare. `uStrength` is how bright, `uSpread` how fast the bloom fades, `uRim` the edge, `uProm` how big the prominences are, `uSeed` where they are and `uTime` moves them.
|
|
242
|
+
*/
|
|
243
|
+
export const STAR_GLOW_FRAGMENT = /* glsl */ `
|
|
244
|
+
precision highp float;
|
|
245
|
+
varying vec2 vP;
|
|
246
|
+
uniform vec3 uColour;
|
|
247
|
+
uniform float uStrength;
|
|
248
|
+
uniform float uSpread;
|
|
249
|
+
uniform float uRim;
|
|
250
|
+
uniform float uProm;
|
|
251
|
+
uniform float uSeed;
|
|
252
|
+
uniform float uTime;
|
|
253
|
+
float h1(float n) { return fract(sin(n * 127.1 + uSeed * 91.7) * 43758.5453); }
|
|
254
|
+
float 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); }
|
|
255
|
+
void main() {
|
|
256
|
+
float r = length(vP);
|
|
257
|
+
if (r < 0.98) discard;
|
|
258
|
+
float x = r - 1.0;
|
|
259
|
+
float fade = smoothstep(3.0, 1.6, r);
|
|
260
|
+
float halo = exp(-x * uSpread) * uStrength;
|
|
261
|
+
float tight = exp(-x * 14.0) * uStrength * 0.9;
|
|
262
|
+
float rim = exp(-x * 60.0) * uRim;
|
|
263
|
+
vec3 col = uColour * (halo + tight) + mix(uColour, vec3(1.0), 0.4) * rim;
|
|
264
|
+
float a = halo + tight + rim;
|
|
265
|
+
if (uProm > 0.0) {
|
|
266
|
+
float ang = atan(vP.y, vP.x);
|
|
267
|
+
float site = smoothstep(0.55, 0.85, n1(ang * 2.6 + uSeed * 20.0));
|
|
268
|
+
float drift = 0.75 + 0.25 * sin(uTime * 0.5 + ang * 4.0);
|
|
269
|
+
float height = site * uProm * 0.3 * drift;
|
|
270
|
+
float strands = 0.65 + 0.35 * n1(ang * 70.0 + uTime * 0.3);
|
|
271
|
+
float pr = step(0.0, x) * pow(smoothstep(height, 0.0, x), 1.6) * site * strands * 0.9;
|
|
272
|
+
vec3 pc = mix(vec3(1.0, 0.42, 0.26), uColour, 0.2);
|
|
273
|
+
float a0 = uSeed * 6.2831853 + uTime * 0.02;
|
|
274
|
+
float da = atan(sin(ang - a0), cos(ang - a0));
|
|
275
|
+
float burst = pow(max(0.0, sin(uTime * 0.9 + uSeed * 40.0)), 24.0) * uProm;
|
|
276
|
+
float fl = exp(-da * da * 14.0) * exp(-x * 6.0) * burst * 1.6;
|
|
277
|
+
col += pc * pr + vec3(1.0, 0.92, 0.75) * fl;
|
|
278
|
+
a += pr + fl;
|
|
279
|
+
}
|
|
280
|
+
// 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
|
|
281
|
+
float s = sqrt(min(a * fade, 1.0));
|
|
282
|
+
gl_FragColor = vec4(col / max(a, 1e-4) * s, s);
|
|
283
|
+
}`;
|
|
238
284
|
/** A cheap lit ball for a moon seen small beside its planet. */
|
|
239
285
|
export const BALL_FRAGMENT = /* glsl */ `
|
|
240
286
|
precision highp float;
|
package/dist/scene/look.d.ts
CHANGED
|
@@ -72,6 +72,17 @@ export interface BodyLook {
|
|
|
72
72
|
atmosphere?: Atmosphere;
|
|
73
73
|
/** How much the disc darkens toward the limb, 0 to 1. Default 0. */
|
|
74
74
|
limb?: number;
|
|
75
|
+
/** For a glowing body: the colour its edge shifts to as it darkens (0 to 1 each). Default the Sun's, orange. */
|
|
76
|
+
limbTint?: readonly [number, number, number];
|
|
77
|
+
/** For a glowing body: its soft corona. The colour (0 to 1 each), how strong it is and how fast it fades (higher is tighter). Default the Sun's glow. */
|
|
78
|
+
glow?: {
|
|
79
|
+
colour: readonly [number, number, number];
|
|
80
|
+
strength: number;
|
|
81
|
+
spread: number; /** How bright the thin glowing edge is. Default 0. */
|
|
82
|
+
rim?: number; /** How big the prominences and flares on the edge are, 0 to 1. Default 0. */
|
|
83
|
+
prominence?: number; /** 0 to 1: where on the edge they are. */
|
|
84
|
+
seed?: number;
|
|
85
|
+
};
|
|
75
86
|
/** How strongly the height shows as relief, 0 to 2. Default 0.6. */
|
|
76
87
|
relief?: number;
|
|
77
88
|
/** How far light wraps round the terminator: 0 is a hard edge (no air), 0.3 a soft one. Default 0.04, or 0.3 with an atmosphere. */
|
|
@@ -82,6 +93,7 @@ export interface BodyLook {
|
|
|
82
93
|
/** Draw the painted map in the realistic look too: for a body with no honest drawing from numbers (the Earth's continents). */
|
|
83
94
|
mapped?: boolean;
|
|
84
95
|
}
|
|
96
|
+
import type { StarLook, StarNumbers } from "../star.ts";
|
|
85
97
|
/**
|
|
86
98
|
* Teach the package how to draw a body in three.js. Each body's entry point (`@johnmorrisdotca/wakusei-planets/jupiter`) calls this once as it loads; call it yourself to add or replace a look.
|
|
87
99
|
*
|
|
@@ -111,3 +123,34 @@ export declare function registerLook(look: BodyLook): BodyLook;
|
|
|
111
123
|
* ```
|
|
112
124
|
*/
|
|
113
125
|
export declare const lookOf: (id: BodyId) => BodyLook | undefined;
|
|
126
|
+
/**
|
|
127
|
+
* Teach the package a star by name, so an element can be told `star="Betelgeuse"` and draw it from these numbers. The package holds no catalogue of stars: this is where a page puts the few it draws.
|
|
128
|
+
* The name is matched without regard to case. Registering a name again replaces it.
|
|
129
|
+
*
|
|
130
|
+
* @param name - What the star is called in the `star` attribute.
|
|
131
|
+
* @param numbers - The star's numbers.
|
|
132
|
+
* @returns The star, ready to draw.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* import { registerStarLook, starLookOf } from "@johnmorrisdotca/wakusei-planets/look";
|
|
137
|
+
*
|
|
138
|
+
* registerStarLook("Proxima Centauri", { temperatureK: 3042, radiusSun: 0.154, luminosityClass: "V", rotationDays: 83 });
|
|
139
|
+
* console.log(starLookOf("proxima centauri")?.colour);
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
export declare function registerStarLook(name: string, numbers: StarNumbers): StarLook;
|
|
143
|
+
/**
|
|
144
|
+
* The star registered under a name, or `undefined`.
|
|
145
|
+
*
|
|
146
|
+
* @param name - The name given to `registerStarLook`, in any case.
|
|
147
|
+
* @returns The star, or `undefined` when none is registered by that name.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* import { starLookOf } from "@johnmorrisdotca/wakusei-planets/look";
|
|
152
|
+
*
|
|
153
|
+
* console.log(starLookOf("Vega") === undefined);
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
export declare const starLookOf: (name: string) => StarLook | undefined;
|
package/dist/scene/look.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { starLook } from "../star.js";
|
|
2
|
+
import { looks, stars, waiting } from "./store.js";
|
|
2
3
|
/**
|
|
3
4
|
* Teach the package how to draw a body in three.js. Each body's entry point (`@johnmorrisdotca/wakusei-planets/jupiter`) calls this once as it loads; call it yourself to add or replace a look.
|
|
4
5
|
*
|
|
@@ -33,3 +34,40 @@ export function registerLook(look) {
|
|
|
33
34
|
* ```
|
|
34
35
|
*/
|
|
35
36
|
export const lookOf = (id) => looks.get(id);
|
|
37
|
+
/**
|
|
38
|
+
* Teach the package a star by name, so an element can be told `star="Betelgeuse"` and draw it from these numbers. The package holds no catalogue of stars: this is where a page puts the few it draws.
|
|
39
|
+
* The name is matched without regard to case. Registering a name again replaces it.
|
|
40
|
+
*
|
|
41
|
+
* @param name - What the star is called in the `star` attribute.
|
|
42
|
+
* @param numbers - The star's numbers.
|
|
43
|
+
* @returns The star, ready to draw.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { registerStarLook, starLookOf } from "@johnmorrisdotca/wakusei-planets/look";
|
|
48
|
+
*
|
|
49
|
+
* registerStarLook("Proxima Centauri", { temperatureK: 3042, radiusSun: 0.154, luminosityClass: "V", rotationDays: 83 });
|
|
50
|
+
* console.log(starLookOf("proxima centauri")?.colour);
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export function registerStarLook(name, numbers) {
|
|
54
|
+
const made = starLook({ name, ...numbers });
|
|
55
|
+
stars.set(name.trim().toLowerCase(), made);
|
|
56
|
+
for (const wake of waiting)
|
|
57
|
+
wake();
|
|
58
|
+
return made;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The star registered under a name, or `undefined`.
|
|
62
|
+
*
|
|
63
|
+
* @param name - The name given to `registerStarLook`, in any case.
|
|
64
|
+
* @returns The star, or `undefined` when none is registered by that name.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* import { starLookOf } from "@johnmorrisdotca/wakusei-planets/look";
|
|
69
|
+
*
|
|
70
|
+
* console.log(starLookOf("Vega") === undefined);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export const starLookOf = (name) => stars.get(name.trim().toLowerCase());
|
package/dist/scene/store.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { BodyId } from "../facts.ts";
|
|
2
|
+
import type { StarLook } from "../star.ts";
|
|
2
3
|
import type { BodyLook } from "./look.ts";
|
|
3
4
|
/** A body whose line look another package's element draws (the Earth, by chikyu-earth) instead of this one: the element asks it for what to show. The shaded and painted looks are always this package's. */
|
|
4
5
|
export interface Delegate {
|
|
@@ -9,5 +10,7 @@ export interface Delegate {
|
|
|
9
10
|
}): Promise<HTMLElement | null>;
|
|
10
11
|
}
|
|
11
12
|
export declare const looks: Map<BodyId, BodyLook>, waiting: Set<() => void>, delegates: Map<BodyId, Delegate>;
|
|
13
|
+
/** Stars registered by name. A copy of the package from before stars had no table, so one is added to it. */
|
|
14
|
+
export declare const stars: Map<string, StarLook>;
|
|
12
15
|
/** Call `wake` whenever a look is registered; returns a function that stops it. */
|
|
13
16
|
export declare function onRegister(wake: () => void): () => void;
|
package/dist/scene/store.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const KEY = Symbol.for("johnmorrisdotca.wakusei-planets.looks");
|
|
2
|
-
const store = (globalThis[KEY] ??= { looks: new Map(), waiting: new Set(), delegates: new Map() });
|
|
2
|
+
const store = (globalThis[KEY] ??= { looks: new Map(), stars: new Map(), waiting: new Set(), delegates: new Map() });
|
|
3
3
|
export const { looks, waiting, delegates } = store;
|
|
4
|
+
/** Stars registered by name. A copy of the package from before stars had no table, so one is added to it. */
|
|
5
|
+
export const stars = (store.stars ??= new Map());
|
|
4
6
|
/** Call `wake` whenever a look is registered; returns a function that stops it. */
|
|
5
7
|
export function onRegister(wake) {
|
|
6
8
|
waiting.add(wake);
|
package/dist/scene/textures.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import type * as THREE from "three";
|
|
|
9
9
|
* console.log(TEXTURE_BASE);
|
|
10
10
|
* ```
|
|
11
11
|
*/
|
|
12
|
-
export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@0.
|
|
12
|
+
export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@0.25.0/dist/textures/";
|
|
13
13
|
/**
|
|
14
14
|
* Where the sharpest surface pictures are: the files of this exact version in the repository, on jsDelivr's GitHub address. The npm package holds only the two smaller widths, so a page that
|
|
15
15
|
* never zooms in never fetches them. Set `texture-far-base` on an element to serve them yourself.
|
|
@@ -21,7 +21,7 @@ export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdot
|
|
|
21
21
|
* console.log(TEXTURE_FAR_BASE);
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
-
export declare const TEXTURE_FAR_BASE = "https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v0.
|
|
24
|
+
export declare const TEXTURE_FAR_BASE = "https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v0.25.0/textures/";
|
|
25
25
|
export declare const slash: (base: string) => string;
|
|
26
26
|
export declare function texturePaths(element: Element): {
|
|
27
27
|
textureBase(): string;
|
package/dist/space/element.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ViewController } from "@johnmorrisdotca/kazoku-ui/view-controls";
|
|
1
2
|
import { setThreeLoader } from "../scene/shared.ts";
|
|
2
3
|
import { type SpacePlanet } from "./frame.ts";
|
|
3
4
|
import { type ScaleMode } from "./scale.ts";
|
|
@@ -86,6 +87,9 @@ export type Riding = RideState;
|
|
|
86
87
|
* `light` (`sun` or `lit`), `lang` (`en` or `ja`: the names), `labels` and `orbits` (`off` hides them), and `texture-base`, `texture-far-base` and `max-texture`. Positions come from this package's own models. It draws
|
|
87
88
|
* only when something changes, and nothing while it is out of sight.
|
|
88
89
|
*
|
|
90
|
+
* It carries the shared view controls itself: a drag turns the camera round the body, two fingers pinch, Ctrl, Command or Alt with the wheel zooms (the plain wheel scrolls the page), and the arrow keys, + and - and 0 work once it is
|
|
91
|
+
* focused. `controls="none"` turns them off; `zoom-min` and `zoom-max` set the range (a millionth to 3 by default); a `<kazoku-view-controls for="...">` takes over and reads it.
|
|
92
|
+
*
|
|
89
93
|
* @example
|
|
90
94
|
* ```ts no-run
|
|
91
95
|
* import type { WakuseiSpace } from "@johnmorrisdotca/wakusei-planets/space/element";
|
|
@@ -99,6 +103,8 @@ export type Riding = RideState;
|
|
|
99
103
|
export declare class WakuseiSpace extends HTMLElement {
|
|
100
104
|
#private;
|
|
101
105
|
static observedAttributes: string[];
|
|
106
|
+
/** The shared controller behind the element's own hands: for a page that moves the view itself, such as `controller.set({ zoom: space.zoomFor("moon") })`. It is there while the element is connected, whether `controls` is `none` or not. */
|
|
107
|
+
get controller(): ViewController | undefined;
|
|
102
108
|
connectedCallback(): void;
|
|
103
109
|
disconnectedCallback(): void;
|
|
104
110
|
attributeChangedCallback(name: string, _old: string | null, value: string | null): void;
|