@johnmorrisdotca/wakusei-planets 0.56.0 → 0.57.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +3 -3
- package/dist/scene/glsl.d.ts +2 -2
- package/dist/scene/glsl.js +5 -2
- package/dist/scene/name-label.d.ts +11 -1
- package/dist/scene/name-label.js +8 -5
- package/dist/scene/painter.d.ts +7 -1
- package/dist/scene/painter.js +18 -2
- package/dist/scene/round.d.ts +43 -0
- package/dist/scene/round.js +91 -0
- package/dist/space/scene.js +13 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.57.0] - 2026-11-17
|
|
6
|
+
|
|
7
|
+
- **A planet, a moon or the Sun is round wherever it is in the picture** (MODULES-1390; John Morris, 2026-11-20). In the space view's wide windows the Sun near the left edge was a wide flat ellipse, the Moon at the bottom stretched tall and the Earth near a corner stretched along the diagonal. The cause is the perspective camera itself, not a stale aspect, a non-uniform scale on the magnified bodies or a frame's up vector: a sphere `theta` off the line of sight is drawn `1 / cos(theta)` as long as it is wide, along the line to the middle of the picture, and the view's field of view (35 degrees top to bottom, 80 degrees across a 2012 by 745 window) puts the edge 37 degrees out and a corner more. Measured as the long axis over the short from the drawn pixels, in a 2012 by 745 window: Venus 1.267, the Earth 1.081 (the painter's own bodies at the edges and corners of that window: 1.21 to 1.24), all now 1.00 to 1.01. A narrower field of view was not taken: within 3% at the corners it would need under 30 degrees across, which moves the camera three times as far back and changes every travel and arrival framing. Each body is now drawn as the ellipsoid that projects to a circle: the sphere squeezed, across the line of sight to it, by `1 / sqrt(1 + tan²θ · d² / (d² − r²))` (the circular sections of the cone of sight), done in the vertex shaders of the globe, its rings and its name (`src/scene/round.ts`). The colours, light, map, rings, glow and name are the sphere's own, and the body's centre, its depth, picking and every camera path (travel, arrival, the Pair and Body frames) are unchanged. The radius on the screen (`placeOf(id).r`, what a press is tested against, the names' offset and the map tiles' choice) is now the drawn one, `1 / cos(theta)` times that in the middle (a press near the edge of a wide window used to miss the outer fifth of a disc), and the marks over the Earth and over a body follow the squeezed surface. `PaintInfo.round` (default `true`, in effect only with `view` and a perspective camera) turns it off for a scene of your own. Tests: `e2e/round-bodies.demo.ts` (the Sun, Mars and the Moon at the left, top, right, bottom and corners of a wide, a tall and a square window; the Sun's glow; the space view's Earth, Moon and Venus in two wide windows) and `test/round.test.ts`.
|
|
8
|
+
|
|
5
9
|
## [0.56.0] - 2026-11-17
|
|
6
10
|
|
|
7
11
|
- **A move from the Earth view out to a planet or the Sun goes straight, not out to the whole system and back** (MODULES-1388, linked to MODULES-1371; John Morris, 2026-11-16). The site hands the planets view over at the Earth view's far distance (187 Earth radii, the Earth a few pixels across) with the destination turned into the picture; in the squeezed scale that distance already shows the whole system, and the planner then backed off from the Earth to a stand on the line of the last view, 2.2 times the distance between the two bodies for the Earth to Pluto, to turn there and come in. Where that stand is more than 1.2 times as far from the body left as the camera began (`BACK_UP`), the planner now tries the straight way, a swing (straight at the destination with it in the picture, the look direction turned round it over the last stretch), and takes it when its walk has no fault of any kind more than the other. Measured on the inputs the space view handed the planner (`test/data/travel-site-inputs.json`), how far out the camera goes, in the larger of the distance between the bodies and where it began (`out` in `test/travel-harness.ts`): the Earth to Mars 1.52 before and 1.00 now, to Pluto 2.23 and 0.64, to the Sun 1.00 and 1.00; over 180 moves from the Earth (ten destinations, three directions, both pictures' shapes, both scales) the ones over 1.2 fall from 15 to 3 (the tall picture with the destination 50 degrees off, where the swing has a fault) and the farthest from 3.22 to 1.6. Stops between the turn and the way on (MODULES-1384), over the 54 moves of `test/travel-smooth.test.ts`: 26 before and 26 now; the moves that start the way on during the turn fall from 42 to 35, those 7 being swings, which keep their own timing.
|
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ Wakusei Planets runs in the browser of a phone, a tablet or a computer: nothing
|
|
|
19
19
|
|
|
20
20
|
<p align="center"><img alt="The demo on a desk: Saturn in the painted look, turning in the big view, with the page's links to the portrait builder, the colouring sheets, the space view, the star page and the size line-up above it, and the choice of body and its moons below" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/main/docs/images/home-desk.webp" width="620"> <img alt="The same page on a phone: the same links in rows, and Saturn in the painted look below them" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/main/docs/images/home-phone.webp" width="200"></p>
|
|
21
21
|
|
|
22
|
-
<p align="center"><img alt="Every body at one scale, the Earth among them: each small body has a magnified picture joined by a line, and the Sun shows only its edge" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.
|
|
22
|
+
<p align="center"><img alt="Every body at one scale, the Earth among them: each small body has a magnified picture joined by a line, and the Sun shows only its edge" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.57.0/docs/images/lineup-desk.png" width="640"></p>
|
|
23
23
|
|
|
24
24
|
## Who it is for
|
|
25
25
|
|
|
@@ -388,7 +388,7 @@ The tiles of every body share one 48 MB budget, six loads at a time for a source
|
|
|
388
388
|
|
|
389
389
|
## The portrait builder
|
|
390
390
|
|
|
391
|
-
<p align="center"><img alt="The Sun and the planets in an arc, painted, with their names, in the portrait builder" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.
|
|
391
|
+
<p align="center"><img alt="The Sun and the planets in an arc, painted, with their names, in the portrait builder" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.57.0/docs/images/portrait-family.png" width="640"></p>
|
|
392
392
|
|
|
393
393
|
[The portrait builder](https://johnmorrisdotca.github.io/wakusei-planets/portrait.html) puts any bodies in one picture: drag them, size them, turn them, order them front to back, arrange them in a row, an arc, a grid or at true orbit distance (true or readable sizes, a planet's moons round it in orbit order), light them from one direction, and take the code, a PNG or an SVG. The scene is kept in the address, and every body is drawn in one WebGL scene, so the page holds one WebGL context. [The portrait builder](docs/guides/portrait-builder.md) is its guide.
|
|
394
394
|
|
|
@@ -537,7 +537,7 @@ BODIES.pluto.kind; // "dwarf-planet"
|
|
|
537
537
|
|
|
538
538
|
If this package helps a paper, a talk or a class, please cite it as software. GitHub's "Cite this repository" button reads [CITATION.cff](CITATION.cff) and gives BibTeX and APA; in plain text:
|
|
539
539
|
|
|
540
|
-
> Morris, J. (2026). *Wakusei Planets* (version 0.
|
|
540
|
+
> Morris, J. (2026). *Wakusei Planets* (version 0.57.0) [Computer software]. https://github.com/johnmorrisdotca/wakusei-planets
|
|
541
541
|
|
|
542
542
|
Cite the version you used (`npm ls @johnmorrisdotca/wakusei-planets`), and cite the sources of the numbers you use as well: [NOTICE.md](NOTICE.md) names each one, with the paper or the page it was read from (the IAU working group's report for sizes and poles, VSOP87B, ELP2000-82B, L1.2 and TASS1.7 for positions, and NASA's JPL Horizons for the fits and the spacecraft).
|
|
543
543
|
|
package/dist/scene/glsl.d.ts
CHANGED
|
@@ -32,9 +32,9 @@ export declare const RING_VERTEX = "\nvarying vec3 vL;\nvarying vec3 vW;\nvoid m
|
|
|
32
32
|
* The body's vertex shader for a perspective camera and a body anywhere in the scene: the normal and the position are in the scene's axes, the position in body radii from the body's centre
|
|
33
33
|
* (`uScale` is the body's size in scene units), and `vV` points at the camera.
|
|
34
34
|
*/
|
|
35
|
-
export declare const VERTEX_WORLD = "\nuniform float uScale;\nvarying vec3 vObj;\nvarying vec3 vN;\nvarying vec3 vW;\nvarying vec3 vV;\nvoid main() {\n vObj = vec3(position.z, position.x, position.y);\n vec4 w = modelMatrix * vec4(position, 1.0);\n vN = normalize(transpose(inverse(mat3(modelMatrix))) * normal);\n vW = mat3(modelMatrix) * position / uScale;\n vV = cameraPosition - w.xyz;\n gl_Position = projectionMatrix * viewMatrix * w;\n}";
|
|
35
|
+
export declare const VERTEX_WORLD = "\n\nuniform vec3 uRoundAxis;\nuniform float uRoundK;\nvec4 roundWorld(vec4 w) {\n if (uRoundK < 1.0) {\n vec3 c = modelMatrix[3].xyz;\n vec3 d = w.xyz - c;\n w.xyz = c + d - (1.0 - uRoundK) * uRoundAxis * dot(d, uRoundAxis);\n }\n return w;\n}\nuniform float uScale;\nvarying vec3 vObj;\nvarying vec3 vN;\nvarying vec3 vW;\nvarying vec3 vV;\nvoid main() {\n vObj = vec3(position.z, position.x, position.y);\n vec4 w = modelMatrix * vec4(position, 1.0);\n vN = normalize(transpose(inverse(mat3(modelMatrix))) * normal);\n vW = mat3(modelMatrix) * position / uScale;\n vV = cameraPosition - w.xyz;\n gl_Position = projectionMatrix * viewMatrix * roundWorld(w);\n}";
|
|
36
36
|
/** The ring's vertex shader for a perspective camera, with the same frame as `VERTEX_WORLD`. */
|
|
37
|
-
export declare const RING_VERTEX_WORLD = "\nuniform float uScale;\nvarying vec3 vL;\nvarying vec3 vW;\nvarying vec3 vV;\nvoid main() {\n vL = position;\n vec4 w = modelMatrix * vec4(position, 1.0);\n vW = mat3(modelMatrix) * position / uScale;\n vV = cameraPosition - w.xyz;\n gl_Position = projectionMatrix * viewMatrix * w;\n}";
|
|
37
|
+
export declare const RING_VERTEX_WORLD = "\n\nuniform vec3 uRoundAxis;\nuniform float uRoundK;\nvec4 roundWorld(vec4 w) {\n if (uRoundK < 1.0) {\n vec3 c = modelMatrix[3].xyz;\n vec3 d = w.xyz - c;\n w.xyz = c + d - (1.0 - uRoundK) * uRoundAxis * dot(d, uRoundAxis);\n }\n return w;\n}\nuniform float uScale;\nvarying vec3 vL;\nvarying vec3 vW;\nvarying vec3 vV;\nvoid main() {\n vL = position;\n vec4 w = modelMatrix * vec4(position, 1.0);\n vW = mat3(modelMatrix) * position / uScale;\n vV = cameraPosition - w.xyz;\n gl_Position = projectionMatrix * viewMatrix * roundWorld(w);\n}";
|
|
38
38
|
/** The ring's fragment shader for a perspective camera: which side is seen comes from the direction to the camera. */
|
|
39
39
|
export declare const RING_FRAGMENT_WORLD: string;
|
|
40
40
|
export declare const GLOW_VERTEX = "\nvarying vec2 vP;\nvoid main() { vP = position.xy; gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }";
|
package/dist/scene/glsl.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// The shader code shared by every body: noise, craters and bands for the realistic look, the lighting, and the ring and glow shaders. Strings only.
|
|
2
|
+
import { ROUND_GLSL } from "./round.js";
|
|
2
3
|
export const VERTEX = /* glsl */ `
|
|
3
4
|
varying vec3 vObj;
|
|
4
5
|
varying vec3 vN;
|
|
@@ -310,6 +311,7 @@ void main() {
|
|
|
310
311
|
* (`uScale` is the body's size in scene units), and `vV` points at the camera.
|
|
311
312
|
*/
|
|
312
313
|
export const VERTEX_WORLD = /* glsl */ `
|
|
314
|
+
${ROUND_GLSL}
|
|
313
315
|
uniform float uScale;
|
|
314
316
|
varying vec3 vObj;
|
|
315
317
|
varying vec3 vN;
|
|
@@ -321,10 +323,11 @@ void main() {
|
|
|
321
323
|
vN = normalize(transpose(inverse(mat3(modelMatrix))) * normal);
|
|
322
324
|
vW = mat3(modelMatrix) * position / uScale;
|
|
323
325
|
vV = cameraPosition - w.xyz;
|
|
324
|
-
gl_Position = projectionMatrix * viewMatrix * w;
|
|
326
|
+
gl_Position = projectionMatrix * viewMatrix * roundWorld(w);
|
|
325
327
|
}`;
|
|
326
328
|
/** The ring's vertex shader for a perspective camera, with the same frame as `VERTEX_WORLD`. */
|
|
327
329
|
export const RING_VERTEX_WORLD = /* glsl */ `
|
|
330
|
+
${ROUND_GLSL}
|
|
328
331
|
uniform float uScale;
|
|
329
332
|
varying vec3 vL;
|
|
330
333
|
varying vec3 vW;
|
|
@@ -334,7 +337,7 @@ void main() {
|
|
|
334
337
|
vec4 w = modelMatrix * vec4(position, 1.0);
|
|
335
338
|
vW = mat3(modelMatrix) * position / uScale;
|
|
336
339
|
vV = cameraPosition - w.xyz;
|
|
337
|
-
gl_Position = projectionMatrix * viewMatrix * w;
|
|
340
|
+
gl_Position = projectionMatrix * viewMatrix * roundWorld(w);
|
|
338
341
|
}`;
|
|
339
342
|
/** The ring's fragment shader for a perspective camera: which side is seen comes from the direction to the camera. */
|
|
340
343
|
export const RING_FRAGMENT_WORLD = RING_FRAGMENT.replace("varying vec3 vW;", "varying vec3 vW;\nvarying vec3 vV;").replace("float side = nl * uRingN.z;", "float side = nl * dot(uRingN, normalize(vV));");
|
|
@@ -128,6 +128,15 @@ export declare function nameLabelText(name: {
|
|
|
128
128
|
export declare function nameLabelKey(text: string, options: NameLabelOptions | null | undefined): string;
|
|
129
129
|
/** The parts of three.js the label needs beyond the bodies': a page that hands over a subset without them gets no label, and a warning once. */
|
|
130
130
|
export type LabelParts = Pick<typeof THREE, "CanvasTexture" | "SRGBColorSpace" | "NormalBlending">;
|
|
131
|
+
/** The two uniforms of `ROUND_GLSL`, one object each, written by the body at each draw. */
|
|
132
|
+
export interface RoundUniforms {
|
|
133
|
+
uRoundAxis: {
|
|
134
|
+
value: THREE.Vector3;
|
|
135
|
+
};
|
|
136
|
+
uRoundK: {
|
|
137
|
+
value: number;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
131
140
|
/** What `createNameLabel` returns: the group to add to the body's mesh, and the calls the host makes. */
|
|
132
141
|
export interface NameLabel {
|
|
133
142
|
/** Add it to the body's turning mesh (a radius-1 sphere whose +z is longitude 0). */
|
|
@@ -165,5 +174,6 @@ export declare function setBodyLabelFontUrl(url: string | URL): void;
|
|
|
165
174
|
* @param emissive - The body glows (the Sun): the name is lit fully, from no direction.
|
|
166
175
|
* @param onReady - Called when the name is drawn, and again when a new font is in.
|
|
167
176
|
* @param colour - The body's mean colour, `#rrggbb`: with `tone: "auto"` the letters are dark on a light body and pale on a dark one. Left out, they are the look's own.
|
|
177
|
+
* @param squeeze - The uniforms a body drawn round shares with its name (see `round.ts`), so the name is squeezed with the globe. Left out, the name is not squeezed.
|
|
168
178
|
*/
|
|
169
|
-
export declare function createNameLabel(T: ThreeParts, text: string, options: NameLabelOptions, emissive: boolean, onReady: () => void, colour?: string): NameLabel;
|
|
179
|
+
export declare function createNameLabel(T: ThreeParts, text: string, options: NameLabelOptions, emissive: boolean, onReady: () => void, colour?: string, squeeze?: RoundUniforms): NameLabel;
|
package/dist/scene/name-label.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// the bodies' shaders use (longitude 0 along the mesh's +z, east along +x, the pole +y); and it is lit by the same direction the body is, through its own small shader, because the
|
|
3
3
|
// bodies have no three.js lights (each is lit by the `uLight` of its own material). Nothing here draws: the host calls `update` before each draw and `set` when a setting changed.
|
|
4
4
|
import { BODY_LABEL_FONT, createBodyLabel, loadBodyLabelFont } from "@johnmorrisdotca/kazoku-ui/body-label";
|
|
5
|
+
import { ROUND_GLSL } from "./round.js";
|
|
5
6
|
/** The family's standard attribute names, as `readNameLabel` reads them. */
|
|
6
7
|
export const NAME_LABEL_ATTRIBUTES = ["body-label", "body-label-strength", "body-label-repeat", "body-label-latitude", "body-label-facing", "body-label-font", "body-label-fallback-font", "body-label-tone"];
|
|
7
8
|
const LOOKS = ["painted", "etched", "outline", "burned"];
|
|
@@ -134,12 +135,13 @@ let warned = false;
|
|
|
134
135
|
/** The name is drawn to a canvas: without one (Node, a worker with no `OffscreenCanvas`) there is no label and nothing to draw. */
|
|
135
136
|
const canDraw = () => typeof document !== "undefined" || typeof OffscreenCanvas !== "undefined";
|
|
136
137
|
const LABEL_VERTEX = /* glsl */ `
|
|
138
|
+
${ROUND_GLSL}
|
|
137
139
|
varying vec2 vUv;
|
|
138
140
|
varying vec3 vN;
|
|
139
141
|
void main() {
|
|
140
142
|
vUv = uv;
|
|
141
143
|
vN = normalize(transpose(inverse(mat3(modelMatrix))) * normal);
|
|
142
|
-
gl_Position = projectionMatrix *
|
|
144
|
+
gl_Position = projectionMatrix * viewMatrix * roundWorld(modelMatrix * vec4(position, 1.0));
|
|
143
145
|
}`;
|
|
144
146
|
// lit as the bodies are: the Sun's direction in the scene's axes, a little wrap past the terminator and a little ambient on the night side, so a name on the night side is dark too
|
|
145
147
|
const LABEL_FRAGMENT = /* glsl */ `
|
|
@@ -158,7 +160,7 @@ void main() {
|
|
|
158
160
|
#include <colorspace_fragment>
|
|
159
161
|
}`;
|
|
160
162
|
/** The three.js the shared label is handed: its own, but with a material lit by the bodies' light instead of three's Lambert (the scenes here have no three.js lights). */
|
|
161
|
-
function litThree(T, emissive) {
|
|
163
|
+
function litThree(T, emissive, squeeze) {
|
|
162
164
|
const made = [];
|
|
163
165
|
class LitLabelMaterial extends T.ShaderMaterial {
|
|
164
166
|
constructor(parameters) {
|
|
@@ -167,7 +169,7 @@ function litThree(T, emissive) {
|
|
|
167
169
|
...rest,
|
|
168
170
|
vertexShader: LABEL_VERTEX,
|
|
169
171
|
fragmentShader: LABEL_FRAGMENT,
|
|
170
|
-
uniforms: { uMap: { value: map }, uLight: { value: new T.Vector3(0, 0, 1) }, uOpacity: { value: 1 }, uAmbient: { value: emissive ? 1 : 0.06 }, uWrap: { value: 0.08 } },
|
|
172
|
+
uniforms: { ...squeeze, uMap: { value: map }, uLight: { value: new T.Vector3(0, 0, 1) }, uOpacity: { value: 1 }, uAmbient: { value: emissive ? 1 : 0.06 }, uWrap: { value: 0.08 } },
|
|
171
173
|
});
|
|
172
174
|
made.push(this);
|
|
173
175
|
}
|
|
@@ -205,8 +207,9 @@ const ensureFont = (font) => (font === BODY_LABEL_FONT && canDraw() ? (fontLoad
|
|
|
205
207
|
* @param emissive - The body glows (the Sun): the name is lit fully, from no direction.
|
|
206
208
|
* @param onReady - Called when the name is drawn, and again when a new font is in.
|
|
207
209
|
* @param colour - The body's mean colour, `#rrggbb`: with `tone: "auto"` the letters are dark on a light body and pale on a dark one. Left out, they are the look's own.
|
|
210
|
+
* @param squeeze - The uniforms a body drawn round shares with its name (see `round.ts`), so the name is squeezed with the globe. Left out, the name is not squeezed.
|
|
208
211
|
*/
|
|
209
|
-
export function createNameLabel(T, text, options, emissive, onReady, colour) {
|
|
212
|
+
export function createNameLabel(T, text, options, emissive, onReady, colour, squeeze) {
|
|
210
213
|
const group = new T.Group();
|
|
211
214
|
group.name = "name-label";
|
|
212
215
|
// the shared label's frame has longitude 0 along +x and east towards -z; the bodies' has longitude 0 along +z and east along +x: a quarter turn about the pole maps one onto the other
|
|
@@ -231,7 +234,7 @@ export function createNameLabel(T, text, options, emissive, onReady, colour) {
|
|
|
231
234
|
const make = () => {
|
|
232
235
|
if (disposed || label !== undefined || !able)
|
|
233
236
|
return;
|
|
234
|
-
const lit = litThree(T, emissive);
|
|
237
|
+
const lit = litThree(T, emissive, squeeze ?? { uRoundAxis: { value: new T.Vector3(1, 0, 0) }, uRoundK: { value: 1 } });
|
|
235
238
|
label = createBodyLabel(lit, { text: wanted.text, ...wanted.options, radius: 1 });
|
|
236
239
|
materials = lit.made;
|
|
237
240
|
group.add(label.object);
|
package/dist/scene/painter.d.ts
CHANGED
|
@@ -132,8 +132,14 @@ export interface PaintInfo {
|
|
|
132
132
|
};
|
|
133
133
|
/** Spheres that may shade this body from the Sun: x, y, z (from this body's centre) and radius, all in this body's radii, in the scene's axes. At most six are used. */
|
|
134
134
|
occluders?: readonly (readonly [number, number, number, number])[];
|
|
135
|
-
/** The camera, so that a body big in the view gets finer map tiles for the part in view (see `PaintView`). Left out, none are used. */
|
|
135
|
+
/** The camera, so that a body big in the view gets finer map tiles for the part in view (see `PaintView`), and so that the body is drawn round wherever it is in the picture (see `round`). Left out, none are used. */
|
|
136
136
|
view?: PaintView;
|
|
137
|
+
/**
|
|
138
|
+
* Draw the body round wherever it is in the picture. A perspective camera draws a sphere near the picture's edge as an ellipse (long along the line to the middle, by 1 / cos of the angle off the line of sight: a quarter
|
|
139
|
+
* as long again 37 degrees out, which is the edge of a wide window); with `view` given, a body is drawn as the ellipsoid that projects to a circle, its colours, light and map unchanged, a ring and a name squeezed with it. `false` leaves
|
|
140
|
+
* the camera's own stretch. Default `true`; it takes effect only for a perspective camera given in `view`.
|
|
141
|
+
*/
|
|
142
|
+
round?: boolean;
|
|
137
143
|
}
|
|
138
144
|
/**
|
|
139
145
|
* One body made by the painter: an object of radius 1 at the origin for the caller to move and scale.
|
package/dist/scene/painter.js
CHANGED
|
@@ -14,6 +14,7 @@ import { seenRegion } from "./tiles.js";
|
|
|
14
14
|
import { moonOffset, orientation } from "./orient.js";
|
|
15
15
|
import { ringStrip } from "./rings.js";
|
|
16
16
|
import { createNameLabel, nameLabelText } from "./name-label.js";
|
|
17
|
+
import { roundShape } from "./round.js";
|
|
17
18
|
let pictureLoads = 0;
|
|
18
19
|
/**
|
|
19
20
|
* How many surface pictures are still being fetched. A view draws once more when one arrives, so a rest test waits for this to be 0.
|
|
@@ -133,9 +134,12 @@ function paint(T, id, context, bases, hold) {
|
|
|
133
134
|
// a glowing body (the Sun) is drawn as it always was: no window of finer map and no generic detail
|
|
134
135
|
const generic = look.emissive !== true;
|
|
135
136
|
const fine = detailOf(look);
|
|
137
|
+
// the squeeze that makes the body look round (see `round.ts`), written at each draw and shared by the globe, the rings and the name: one object each, so that a material made later holds the same
|
|
138
|
+
const squeeze = { uRoundAxis: { value: new T.Vector3(1, 0, 0) }, uRoundK: { value: 1 } };
|
|
136
139
|
const uniforms = (painted) => {
|
|
137
140
|
const a = look.atmosphere;
|
|
138
141
|
return {
|
|
142
|
+
...squeeze,
|
|
139
143
|
...(generic
|
|
140
144
|
? {
|
|
141
145
|
uTexel: { value: painted ? (2 * Math.PI) / (look.painted?.widths[0] ?? 2048) : 0.005 },
|
|
@@ -200,7 +204,7 @@ function paint(T, id, context, bases, hold) {
|
|
|
200
204
|
transparent: true,
|
|
201
205
|
premultipliedAlpha: true,
|
|
202
206
|
depthWrite: false,
|
|
203
|
-
uniforms: { uRingTex: { value: strip }, uRingR: { value: new T.Vector2(ringInner, ringOuter) }, uLight: { value: new T.Vector3(1, 0, 0) }, uRingN: { value: new T.Vector3(0, 1, 0) }, uScale: { value: 1 } },
|
|
207
|
+
uniforms: { ...squeeze, uRingTex: { value: strip }, uRingR: { value: new T.Vector2(ringInner, ringOuter) }, uLight: { value: new T.Vector3(1, 0, 0) }, uRingN: { value: new T.Vector3(0, 1, 0) }, uScale: { value: 1 } },
|
|
204
208
|
});
|
|
205
209
|
disposables.push(ringMaterial);
|
|
206
210
|
ringMesh = new T.Mesh(ringGeometry, ringMaterial);
|
|
@@ -388,7 +392,7 @@ function paint(T, id, context, bases, hold) {
|
|
|
388
392
|
labelText = text ?? nameLabelText(facts.name, lang ?? "en");
|
|
389
393
|
labelReport.text = labelText;
|
|
390
394
|
if (label === undefined) {
|
|
391
|
-
label = createNameLabel(T, labelText, options, look.emissive === true, redraw, facts.colour);
|
|
395
|
+
label = createNameLabel(T, labelText, options, look.emissive === true, redraw, facts.colour, squeeze);
|
|
392
396
|
labelReport.look = label.look;
|
|
393
397
|
mesh.add(label.object);
|
|
394
398
|
}
|
|
@@ -418,6 +422,18 @@ function paint(T, id, context, bases, hold) {
|
|
|
418
422
|
// pole and prime meridian like every other body
|
|
419
423
|
if (glowMesh !== undefined && info.view !== undefined)
|
|
420
424
|
glowMesh.quaternion.copy(info.view.camera.quaternion);
|
|
425
|
+
// round wherever it is in the picture: a perspective camera given to us, the body not squeezed when it was asked not to be (the glow is a disc facing the camera, which a perspective camera draws round already)
|
|
426
|
+
{
|
|
427
|
+
const camera = info.view?.camera;
|
|
428
|
+
if (camera !== undefined && camera.isPerspectiveCamera === true && info.round !== false) {
|
|
429
|
+
const e = camera.matrixWorld.elements;
|
|
430
|
+
const shape = roundShape([e[12], e[13], e[14]], [-e[8], -e[9], -e[10]], [group.position.x, group.position.y, group.position.z], scale);
|
|
431
|
+
squeeze.uRoundAxis.value.set(shape.axis[0], shape.axis[1], shape.axis[2]);
|
|
432
|
+
squeeze.uRoundK.value = shape.k;
|
|
433
|
+
}
|
|
434
|
+
else
|
|
435
|
+
squeeze.uRoundK.value = 1;
|
|
436
|
+
}
|
|
421
437
|
{
|
|
422
438
|
const { pole, meridian } = info.pose ?? orientation(id, info.ms);
|
|
423
439
|
const east = cross(pole, meridian);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type Vec3 } from "../vec.ts";
|
|
2
|
+
/** How a body is squeezed to look round: along the unit `axis` (about the body's centre, in the scene's axes) to `k` times its length, `k` from 0 to 1, 1 for no change. */
|
|
3
|
+
export interface Round {
|
|
4
|
+
axis: Vec3;
|
|
5
|
+
k: number;
|
|
6
|
+
}
|
|
7
|
+
/** No squeeze. */
|
|
8
|
+
export declare const NOT_SQUEEZED: Round;
|
|
9
|
+
/**
|
|
10
|
+
* How the body at `centre` with `radius` is squeezed to look round to a perspective camera at `eye` looking along `forward` (a unit vector), in the scene's axes. A body in the middle of the picture, one the camera is in
|
|
11
|
+
* or at, and one behind it are not squeezed.
|
|
12
|
+
*
|
|
13
|
+
* @param eye - The camera's place.
|
|
14
|
+
* @param forward - The way the camera looks, a unit vector.
|
|
15
|
+
* @param centre - The body's centre.
|
|
16
|
+
* @param radius - The body's radius.
|
|
17
|
+
* @returns The squeeze.
|
|
18
|
+
*/
|
|
19
|
+
export declare function roundShape(eye: Vec3, forward: Vec3, centre: Vec3, radius: number): Round;
|
|
20
|
+
/**
|
|
21
|
+
* How much wider across a body is drawn off the middle of the picture than on it: a perspective camera draws the same body `1 / cos(theta)` as wide at `theta` off the line of sight (the picture's plane is that much
|
|
22
|
+
* farther from the camera there). With the body drawn round, this is the factor on its radius on the screen; the on-axis radius is `(height / 2) * r / sqrt(d^2 - r^2) / tan(fov / 2)` pixels.
|
|
23
|
+
*
|
|
24
|
+
* @param eye - The camera's place.
|
|
25
|
+
* @param forward - The way the camera looks, a unit vector.
|
|
26
|
+
* @param centre - The body's centre.
|
|
27
|
+
* @returns 1 in the middle of the picture, more out from it; 1 for a body behind the camera.
|
|
28
|
+
*/
|
|
29
|
+
export declare function edgeStretch(eye: Vec3, forward: Vec3, centre: Vec3): number;
|
|
30
|
+
/**
|
|
31
|
+
* Where a point of the body goes when the body is squeezed: the same shift the vertex shaders make. For a layer that is laid over the body (a name, a mark) and must stay on its drawn surface.
|
|
32
|
+
*
|
|
33
|
+
* @param point - A point in the scene's axes.
|
|
34
|
+
* @param centre - The body's centre.
|
|
35
|
+
* @param round - The squeeze from `roundShape`.
|
|
36
|
+
* @returns The point moved.
|
|
37
|
+
*/
|
|
38
|
+
export declare function squashPoint(point: Vec3, centre: Vec3, round: Round): Vec3;
|
|
39
|
+
/**
|
|
40
|
+
* The shader's side of the squeeze: declare the two uniforms and `roundWorld`, which takes a world position and gives the one it is drawn at. The centre is the model matrix's own place (the body's group is at its
|
|
41
|
+
* centre and its meshes are at the group's origin).
|
|
42
|
+
*/
|
|
43
|
+
export declare const ROUND_GLSL = "\nuniform vec3 uRoundAxis;\nuniform float uRoundK;\nvec4 roundWorld(vec4 w) {\n if (uRoundK < 1.0) {\n vec3 c = modelMatrix[3].xyz;\n vec3 d = w.xyz - c;\n w.xyz = c + d - (1.0 - uRoundK) * uRoundAxis * dot(d, uRoundAxis);\n }\n return w;\n}";
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// A body that looks round wherever it is in the picture. A perspective camera draws a sphere away from the middle of the picture as an ellipse, long along the line to the middle: at an angle `theta` off the line of sight
|
|
2
|
+
// the ellipse is about `1 / cos(theta)` as long as it is wide, and a wide window's edge is 40 degrees or more off it. The body is drawn as the ellipsoid that makes a circle: the sphere squeezed along that line, across the
|
|
3
|
+
// line of sight to its centre, by the factor the cone of sight from the camera needs for a circular section by the picture's plane (the circular sections of an elliptic cone: tan(theta)^2 = (1/A^2 - 1/B^2) / (1/B^2 + 1)
|
|
4
|
+
// for a cone of half-angles A across the squeezed way and B across the other, and with B = r / sqrt(d^2 - r^2) the factor A / B is below). The body's colours, lighting and texture are still the sphere's own; only where
|
|
5
|
+
// its points land on the screen changes, in the vertex shaders (`ROUND_GLSL`), by `squashPoint`'s sum. Pure, no allocation beyond the arrays themselves.
|
|
6
|
+
import { dot, length } from "../vec.js";
|
|
7
|
+
/** No squeeze. */
|
|
8
|
+
export const NOT_SQUEEZED = { axis: [1, 0, 0], k: 1 };
|
|
9
|
+
/** The weight of the squeeze falls to nothing as the body's edge gets this close to 90 degrees off the line of sight (in radians): there the plane of the picture cuts the cone of sight in a curve that is no ellipse. */
|
|
10
|
+
const FADE_FROM = (75 * Math.PI) / 180;
|
|
11
|
+
const FADE_TO = (88 * Math.PI) / 180;
|
|
12
|
+
/**
|
|
13
|
+
* How the body at `centre` with `radius` is squeezed to look round to a perspective camera at `eye` looking along `forward` (a unit vector), in the scene's axes. A body in the middle of the picture, one the camera is in
|
|
14
|
+
* or at, and one behind it are not squeezed.
|
|
15
|
+
*
|
|
16
|
+
* @param eye - The camera's place.
|
|
17
|
+
* @param forward - The way the camera looks, a unit vector.
|
|
18
|
+
* @param centre - The body's centre.
|
|
19
|
+
* @param radius - The body's radius.
|
|
20
|
+
* @returns The squeeze.
|
|
21
|
+
*/
|
|
22
|
+
export function roundShape(eye, forward, centre, radius) {
|
|
23
|
+
const to = [centre[0] - eye[0], centre[1] - eye[1], centre[2] - eye[2]];
|
|
24
|
+
const d = length(to);
|
|
25
|
+
if (!(d > radius * 1.001) || !(radius > 0))
|
|
26
|
+
return NOT_SQUEEZED;
|
|
27
|
+
const sight = [to[0] / d, to[1] / d, to[2] / d];
|
|
28
|
+
const cos = dot(forward, sight);
|
|
29
|
+
if (!(cos > 0))
|
|
30
|
+
return NOT_SQUEEZED;
|
|
31
|
+
// the way the line of sight to the body's centre leans to the camera's own, across it
|
|
32
|
+
const lean = [forward[0] - cos * sight[0], forward[1] - cos * sight[1], forward[2] - cos * sight[2]];
|
|
33
|
+
const across = length(lean);
|
|
34
|
+
if (!(across > 1e-9))
|
|
35
|
+
return NOT_SQUEEZED;
|
|
36
|
+
const theta = Math.acos(Math.min(1, cos));
|
|
37
|
+
const tan2 = (1 - cos * cos) / (cos * cos);
|
|
38
|
+
const half = Math.asin(radius / d);
|
|
39
|
+
const k = 1 / Math.sqrt(1 + (tan2 * d * d) / (d * d - radius * radius));
|
|
40
|
+
// the whole of the squeeze while the body's far edge is well inside the picture's plane's reach, none as it nears 90 degrees
|
|
41
|
+
const t = Math.min(1, Math.max(0, (theta + half - FADE_FROM) / (FADE_TO - FADE_FROM)));
|
|
42
|
+
const weight = 1 - t * t * (3 - 2 * t);
|
|
43
|
+
return { axis: [lean[0] / across, lean[1] / across, lean[2] / across], k: 1 - weight * (1 - k) };
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* How much wider across a body is drawn off the middle of the picture than on it: a perspective camera draws the same body `1 / cos(theta)` as wide at `theta` off the line of sight (the picture's plane is that much
|
|
47
|
+
* farther from the camera there). With the body drawn round, this is the factor on its radius on the screen; the on-axis radius is `(height / 2) * r / sqrt(d^2 - r^2) / tan(fov / 2)` pixels.
|
|
48
|
+
*
|
|
49
|
+
* @param eye - The camera's place.
|
|
50
|
+
* @param forward - The way the camera looks, a unit vector.
|
|
51
|
+
* @param centre - The body's centre.
|
|
52
|
+
* @returns 1 in the middle of the picture, more out from it; 1 for a body behind the camera.
|
|
53
|
+
*/
|
|
54
|
+
export function edgeStretch(eye, forward, centre) {
|
|
55
|
+
const to = [centre[0] - eye[0], centre[1] - eye[1], centre[2] - eye[2]];
|
|
56
|
+
const d = length(to);
|
|
57
|
+
if (!(d > 0))
|
|
58
|
+
return 1;
|
|
59
|
+
const cos = dot(forward, to) / d;
|
|
60
|
+
return cos > 0.2 ? 1 / cos : 1;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Where a point of the body goes when the body is squeezed: the same shift the vertex shaders make. For a layer that is laid over the body (a name, a mark) and must stay on its drawn surface.
|
|
64
|
+
*
|
|
65
|
+
* @param point - A point in the scene's axes.
|
|
66
|
+
* @param centre - The body's centre.
|
|
67
|
+
* @param round - The squeeze from `roundShape`.
|
|
68
|
+
* @returns The point moved.
|
|
69
|
+
*/
|
|
70
|
+
export function squashPoint(point, centre, round) {
|
|
71
|
+
if (round.k >= 1)
|
|
72
|
+
return point;
|
|
73
|
+
const d = [point[0] - centre[0], point[1] - centre[1], point[2] - centre[2]];
|
|
74
|
+
const along = (1 - round.k) * dot(d, round.axis);
|
|
75
|
+
return [point[0] - round.axis[0] * along, point[1] - round.axis[1] * along, point[2] - round.axis[2] * along];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The shader's side of the squeeze: declare the two uniforms and `roundWorld`, which takes a world position and gives the one it is drawn at. The centre is the model matrix's own place (the body's group is at its
|
|
79
|
+
* centre and its meshes are at the group's origin).
|
|
80
|
+
*/
|
|
81
|
+
export const ROUND_GLSL = /* glsl */ `
|
|
82
|
+
uniform vec3 uRoundAxis;
|
|
83
|
+
uniform float uRoundK;
|
|
84
|
+
vec4 roundWorld(vec4 w) {
|
|
85
|
+
if (uRoundK < 1.0) {
|
|
86
|
+
vec3 c = modelMatrix[3].xyz;
|
|
87
|
+
vec3 d = w.xyz - c;
|
|
88
|
+
w.xyz = c + d - (1.0 - uRoundK) * uRoundAxis * dot(d, uRoundAxis);
|
|
89
|
+
}
|
|
90
|
+
return w;
|
|
91
|
+
}`;
|
package/dist/space/scene.js
CHANGED
|
@@ -4,6 +4,7 @@ import { createMoonDots } from "./all-moons.js";
|
|
|
4
4
|
import { BELT_IDS, BELTS, OORT } from "../belts/index.js";
|
|
5
5
|
import { toTerrestrialTime } from "../clock.js";
|
|
6
6
|
import { moonOffset, orientation } from "../scene/orient.js";
|
|
7
|
+
import { edgeStretch, roundShape, squashPoint } from "../scene/round.js";
|
|
7
8
|
import {} from "../scene/painter.js";
|
|
8
9
|
import "../bodies/all.js";
|
|
9
10
|
import { turn } from "../vec.js";
|
|
@@ -745,10 +746,13 @@ export function createSpaceItem(model, deps) {
|
|
|
745
746
|
model.heightPx = size.height;
|
|
746
747
|
// how many pixels across each body is: for the pictures it needs and for what is chosen
|
|
747
748
|
const half = Math.tan((fovNow / 2) * RAD);
|
|
749
|
+
// a body is drawn round wherever it is in the picture, and wider across the farther out it is (the picture's plane is that much farther from the camera there): its radius on the screen is that of one in the middle times `1 / cos` of how far off the line of sight it is
|
|
750
|
+
const eyeAt = [camera.position.x, camera.position.y, camera.position.z];
|
|
751
|
+
const lookAt = [-e2[8], -e2[9], -e2[10]];
|
|
748
752
|
const radiusPxOf = (id) => {
|
|
749
753
|
const d = Math.hypot(pos[id][0] - camera.position.x, pos[id][1] - camera.position.y, pos[id][2] - camera.position.z);
|
|
750
754
|
const r = radiusOf(id);
|
|
751
|
-
return d <= r * 1.001 ? 1e5 : ((size.height / 2) * (r / Math.sqrt(d * d - r * r))) / half;
|
|
755
|
+
return d <= r * 1.001 ? 1e5 : (((size.height / 2) * (r / Math.sqrt(d * d - r * r))) / half) * edgeStretch(eyeAt, lookAt, pos[id]);
|
|
752
756
|
};
|
|
753
757
|
const px = {};
|
|
754
758
|
for (const id of SPACE_BODIES)
|
|
@@ -794,7 +798,10 @@ export function createSpaceItem(model, deps) {
|
|
|
794
798
|
const r = shown.object.scale.x;
|
|
795
799
|
const d = Math.hypot(at.x - camera.position.x, at.y - camera.position.y, at.z - camera.position.z);
|
|
796
800
|
const { pole, meridian } = orientation(model.focus, model.time);
|
|
797
|
-
|
|
801
|
+
const centre = [at.x, at.y, at.z];
|
|
802
|
+
// what is laid over the body is put where the drawn (round) body's surface is
|
|
803
|
+
const shape = roundShape(eyeAt, lookAt, centre, r);
|
|
804
|
+
deps.onSurface({ id: model.focus, centre, radius: r, pole, meridian, eye: eyeAt, project: (v) => labelFor(squashPoint(v, centre, shape)), width: size.width, height: size.height, radiusPx: d <= r * 1.001 ? 1e5 : (((size.height / 2) * (r / Math.sqrt(d * d - r * r))) / half) * edgeStretch(eyeAt, lookAt, centre) });
|
|
798
805
|
}
|
|
799
806
|
}
|
|
800
807
|
if (points !== undefined && deps.book !== undefined) {
|
|
@@ -1208,7 +1215,7 @@ export function createSpaceItem(model, deps) {
|
|
|
1208
1215
|
drawing.object.visible = true;
|
|
1209
1216
|
drawing.object.position.set(at[0], at[1], at[2]);
|
|
1210
1217
|
drawing.object.scale.setScalar(drawn);
|
|
1211
|
-
const moonPx = away <= drawn * 1.001 ? 1e5 : ((size.height / 2) * (drawn / Math.sqrt(away * away - drawn * drawn))) / half;
|
|
1218
|
+
const moonPx = away <= drawn * 1.001 ? 1e5 : (((size.height / 2) * (drawn / Math.sqrt(away * away - drawn * drawn))) / half) * edgeStretch(eyeAt, lookAt, at);
|
|
1212
1219
|
drawing.update({ toSun: model.light === "lit" ? unit([camera.position.x - at[0], camera.position.y - at[1], camera.position.z - at[2]]) : toSunOf(id), ms: model.time, radiusPx: moonPx, view: { camera, width: size.width, height: size.height } });
|
|
1213
1220
|
const spot = labelFor(at);
|
|
1214
1221
|
if (spot) {
|
|
@@ -1319,7 +1326,9 @@ export function createSpaceItem(model, deps) {
|
|
|
1319
1326
|
const r = earth.object.scale.x;
|
|
1320
1327
|
const d = Math.hypot(at.x - camera.position.x, at.y - camera.position.y, at.z - camera.position.z);
|
|
1321
1328
|
const { pole, meridian } = orientation("earth", model.time);
|
|
1322
|
-
|
|
1329
|
+
const centre = [at.x, at.y, at.z];
|
|
1330
|
+
const shape = roundShape(eyeAt, lookAt, centre, r);
|
|
1331
|
+
deps.onEarth({ id: "earth", centre, radius: r, pole, meridian, eye: eyeAt, project: (v) => labelFor(squashPoint(v, centre, shape)), width: size.width, height: size.height, radiusPx: d <= r * 1.001 ? 1e5 : (((size.height / 2) * (r / Math.sqrt(d * d - r * r))) / half) * edgeStretch(eyeAt, lookAt, centre), sun: model.light === "lit" ? null : toSunOf("earth") });
|
|
1323
1332
|
}
|
|
1324
1333
|
}
|
|
1325
1334
|
if (deps.onSight && (deps.wantSight?.() ?? true)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/wakusei-planets",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.57.0",
|
|
4
4
|
"description": "Wakusei Planets 惑星 — The Sun, planets and moons for the web: each as a clean line drawing, a shaded realistic drawing or a painted surface map, with real sizes, axial tilt and rotation as data, and positions of the moons for any date and time. SVG for the lines, three.js (optional) for the rest.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"planets",
|