@johnmorrisdotca/wakusei-planets 0.26.1 → 0.28.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 +9 -0
- package/NOTICE.md +30 -0
- package/README.md +6 -5
- package/dist/element.d.ts +11 -2
- package/dist/element.js +118 -38
- package/dist/kids/picture.d.ts +4 -4
- package/dist/kids/picture.js +4 -4
- package/dist/scene/body.d.ts +11 -0
- package/dist/scene/body.js +58 -6
- package/dist/scene/detail.d.ts +73 -0
- package/dist/scene/detail.js +289 -0
- package/dist/scene/extent.d.ts +10 -0
- package/dist/scene/extent.js +21 -0
- package/dist/scene/glsl.d.ts +23 -2
- package/dist/scene/glsl.js +119 -4
- package/dist/scene/look.d.ts +26 -0
- package/dist/scene/look.js +29 -0
- package/dist/scene/reach.d.ts +34 -0
- package/dist/scene/reach.js +44 -0
- package/dist/scene/textures.d.ts +16 -2
- package/dist/scene/textures.js +21 -0
- package/dist/scene/tiles.d.ts +108 -0
- package/dist/scene/tiles.js +228 -0
- package/dist/space/element.d.ts +8 -1
- package/dist/space/element.js +32 -4
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -2
package/dist/scene/glsl.js
CHANGED
|
@@ -52,8 +52,41 @@ 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
|
-
/**
|
|
56
|
-
|
|
55
|
+
/**
|
|
56
|
+
* 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
|
|
57
|
+
* 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
|
|
58
|
+
* quarter times) octaves of noise are added, each half the size of the one before, each only while its cells are still wider than about two pixels, so nothing is finer than the screen can show and nothing
|
|
59
|
+
* shimmers. `uDetailAmp` is how strong it is (0 turns it off) and `uDetailStretch` stretches it along the lines of latitude (a gas giant's streaks).
|
|
60
|
+
*/
|
|
61
|
+
export const MICRO_DETAIL = /* glsl */ `
|
|
62
|
+
uniform float uTexel;
|
|
63
|
+
uniform float uDetailAmp;
|
|
64
|
+
uniform float uDetailStretch;
|
|
65
|
+
float gTexel = 0.003;
|
|
66
|
+
float microDetail(vec3 p) {
|
|
67
|
+
if (uDetailAmp <= 0.0) return 1.0;
|
|
68
|
+
float fw = max(length(fwidth(p)), 1e-9);
|
|
69
|
+
float mag = gTexel / fw;
|
|
70
|
+
float fade = smoothstep(1.2, 3.0, mag);
|
|
71
|
+
if (fade <= 0.0) return 1.0;
|
|
72
|
+
float sum = 0.0;
|
|
73
|
+
float amp = 1.0;
|
|
74
|
+
for (int i = 0; i < 6; i++) {
|
|
75
|
+
float cell = gTexel * 0.7 / exp2(float(i));
|
|
76
|
+
float w = smoothstep(1.4, 3.0, cell / fw);
|
|
77
|
+
if (w <= 0.0) break;
|
|
78
|
+
vec3 q = vec3(p.xy, p.z * uDetailStretch) / cell;
|
|
79
|
+
sum += w * amp * (vnoise(q + float(i) * 19.19) - 0.5);
|
|
80
|
+
amp *= 0.58;
|
|
81
|
+
}
|
|
82
|
+
return max(0.0, 1.0 + uDetailAmp * 2.0 * fade * sum);
|
|
83
|
+
}
|
|
84
|
+
`;
|
|
85
|
+
/**
|
|
86
|
+
* 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). `detail` adds the generic fine
|
|
87
|
+
* detail (`MICRO_DETAIL`) that carries a body past the sharpness of its map; a body that glows never takes it, and without it the shader is the same program as before it existed.
|
|
88
|
+
*/
|
|
89
|
+
export function bodyFragment(surface, painted, world = false, limbTint, detail = false) {
|
|
57
90
|
const tint = limbTint === undefined ? "vec3(1.0, 0.55, 0.25)" : `vec3(${limbTint.map((v) => v.toFixed(4)).join(", ")})`;
|
|
58
91
|
return /* glsl */ `
|
|
59
92
|
precision highp float;
|
|
@@ -77,10 +110,11 @@ varying vec3 vN;
|
|
|
77
110
|
varying vec3 vW;
|
|
78
111
|
${world ? "varying vec3 vV;\nuniform int uOccN;\nuniform vec4 uOcc[6];" : ""}
|
|
79
112
|
${PRELUDE}
|
|
80
|
-
${surface}
|
|
113
|
+
${detail ? MICRO_DETAIL : ""}${surface}
|
|
81
114
|
void main() {
|
|
82
115
|
vec3 p = normalize(vObj);
|
|
83
|
-
vec4 s = surface(p);
|
|
116
|
+
${detail ? " gTexel = uTexel;\n" : ""} vec4 s = surface(p);
|
|
117
|
+
${detail ? " s.rgb *= microDetail(p);\n" : ""}
|
|
84
118
|
vec3 n = normalize(vN);
|
|
85
119
|
float mu = ${world ? "clamp(dot(n, normalize(vV)), 0.0, 1.0)" : "clamp(n.z, 0.0, 1.0)"};
|
|
86
120
|
if (uEmissive > 0.5) {
|
|
@@ -157,6 +191,61 @@ vec4 surface(vec3 p) {
|
|
|
157
191
|
}
|
|
158
192
|
return vec4(c, dot(c, vec3(0.3, 0.59, 0.11)));
|
|
159
193
|
}`;
|
|
194
|
+
/**
|
|
195
|
+
* A painted body's surface code with a window of finer picture (`uDetail`, placed by `uDetailRect` and softened at its edges by `uDetailFade`, `uDetailOn` is 1 while there is one), and the texel angles `micro` detail
|
|
196
|
+
* (`MICRO_DETAIL`) needs. Use it with `bodyFragment(..., true)`; a glowing body takes `PAINTED_SURFACE`.
|
|
197
|
+
*/
|
|
198
|
+
export const PAINTED_SURFACE_WINDOWED = /* glsl */ `
|
|
199
|
+
uniform sampler2D uDetail;
|
|
200
|
+
uniform vec4 uDetailRect;
|
|
201
|
+
uniform vec2 uDetailFade;
|
|
202
|
+
uniform float uDetailOn;
|
|
203
|
+
uniform float uDetailTexel;
|
|
204
|
+
vec4 surface(vec3 p) {
|
|
205
|
+
float u1 = atan(p.y, p.x) / 6.2831853 + 0.5;
|
|
206
|
+
float u2 = fract(u1 + 0.5) - 0.5;
|
|
207
|
+
float v = asin(clamp(p.z, -1.0, 1.0)) / 3.1415927 + 0.5;
|
|
208
|
+
vec2 a = vec2(u1, v); vec2 b = vec2(u2, v);
|
|
209
|
+
vec2 ax = dFdx(a); vec2 ay = dFdy(a); vec2 bx = dFdx(b); vec2 by = dFdy(b);
|
|
210
|
+
bool useA = dot(ax, ax) + dot(ay, ay) <= dot(bx, bx) + dot(by, by);
|
|
211
|
+
vec3 c = textureGrad(uMap, useA ? a : b, useA ? ax : bx, useA ? ay : by).rgb;
|
|
212
|
+
// The window of finer picture laid over the map: tiles of a sharper level, where they are loaded (see scene/detail.ts). Longitude is measured east of the window's west edge, so a window may cross the seam;
|
|
213
|
+
// the gradients are those of the continuous variant, so the picture is filtered the same on both sides of it.
|
|
214
|
+
gTexel = uTexel;
|
|
215
|
+
if (uDetailOn > 0.5) {
|
|
216
|
+
vec2 q = useA ? a : b;
|
|
217
|
+
vec2 gx = useA ? ax : bx;
|
|
218
|
+
vec2 gy = useA ? ay : by;
|
|
219
|
+
float rx = fract(q.x - uDetailRect.x) / uDetailRect.z;
|
|
220
|
+
float ry = (uDetailRect.y - q.y) / uDetailRect.w;
|
|
221
|
+
if (rx < 1.0 && ry > 0.0 && ry < 1.0) {
|
|
222
|
+
float fx = uDetailFade.x > 0.0 ? min(smoothstep(0.0, uDetailFade.x, rx), smoothstep(0.0, uDetailFade.x, 1.0 - rx)) : 1.0;
|
|
223
|
+
float fy = uDetailFade.y > 0.0 ? min(smoothstep(0.0, uDetailFade.y, ry), smoothstep(0.0, uDetailFade.y, 1.0 - ry)) : 1.0;
|
|
224
|
+
vec3 d = textureGrad(uDetail, vec2(rx, ry), vec2(gx.x / uDetailRect.z, -gx.y / uDetailRect.w), vec2(gy.x / uDetailRect.z, -gy.y / uDetailRect.w)).rgb;
|
|
225
|
+
c = mix(c, d, fx * fy);
|
|
226
|
+
gTexel = mix(uTexel, uDetailTexel, fx * fy);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
// 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.
|
|
230
|
+
if (uMark > 0.5) {
|
|
231
|
+
float lon = atan(p.y, p.x);
|
|
232
|
+
float lat = asin(clamp(p.z, -1.0, 1.0));
|
|
233
|
+
float wave = sin(lon * 4.0 + lat * 6.0);
|
|
234
|
+
float belt = 1.0 - smoothstep(1.15, 1.45, abs(lat));
|
|
235
|
+
c *= 0.86 + 0.22 * (0.5 + 0.5 * wave) * belt;
|
|
236
|
+
if (uMark > 1.5) {
|
|
237
|
+
float ang = atan(p.y, p.x);
|
|
238
|
+
float radius = length(p.xy);
|
|
239
|
+
float hexR = 0.26 + 0.045 * cos(ang * 6.0);
|
|
240
|
+
float hex = (1.0 - smoothstep(0.0, 0.028, abs(radius - hexR))) * smoothstep(0.42, 0.68, p.z);
|
|
241
|
+
c = mix(c, vec3(0.45, 0.55, 0.68), hex);
|
|
242
|
+
} else {
|
|
243
|
+
float spot = exp(-pow((lat - 0.32) / 0.2, 2.0) - pow(lon / 0.5, 2.0));
|
|
244
|
+
c = mix(c, c * vec3(0.28, 0.34, 0.5), clamp(spot, 0.0, 1.0));
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return vec4(c, dot(c, vec3(0.3, 0.59, 0.11)));
|
|
248
|
+
}`;
|
|
160
249
|
export const RING_FRAGMENT = /* glsl */ `
|
|
161
250
|
precision highp float;
|
|
162
251
|
uniform sampler2D uRingTex;
|
|
@@ -179,6 +268,32 @@ void main() {
|
|
|
179
268
|
vec3 c = pow(t.rgb, vec3(2.2)) * bright * (1.0 - 0.93 * shadow);
|
|
180
269
|
gl_FragColor = vec4(pow(c, vec3(1.0 / 2.2)), t.a);
|
|
181
270
|
}`;
|
|
271
|
+
/**
|
|
272
|
+
* The ring's fragment shader with generic ringlets for a close view: where a texel of the ring's strip (`uRingTexel`, its width as a fraction of the ring's span) is more than about a pixel and a quarter wide, noise
|
|
273
|
+
* along the radius, octave by octave, finer than the strip, only while its cells are still two or more pixels wide. It is not a measured feature of the rings: the strip's own opacity and colour, its gaps and the planet's
|
|
274
|
+
* shadow stay as they were, and the detail only makes the strip's blur ringlets. Where a texel is smaller than a pixel it changes nothing.
|
|
275
|
+
*/
|
|
276
|
+
export const RING_FRAGMENT_DETAIL = RING_FRAGMENT.replace("uniform vec3 uRingN;\nvarying", "uniform vec3 uRingN;\nuniform float uRingTexel;\nvarying")
|
|
277
|
+
.replace("void main() {", `float rhash(float n) { return fract(sin(n * 127.1 + 311.7) * 43758.5453); }
|
|
278
|
+
float rnoise(float x) { float i = floor(x); float f = fract(x); f = f * f * (3.0 - 2.0 * f); return mix(rhash(i), rhash(i + 1.0), f); }
|
|
279
|
+
void main() {`)
|
|
280
|
+
.replace(" vec4 t = texture2D(uRingTex, vec2(u, 0.5));\n", ` vec4 t = texture2D(uRingTex, vec2(u, 0.5));
|
|
281
|
+
float du = max(fwidth(u), 1e-9);
|
|
282
|
+
float fade = smoothstep(1.2, 3.0, uRingTexel / du);
|
|
283
|
+
if (fade > 0.0 && t.a > 0.02) {
|
|
284
|
+
float sum = 0.0;
|
|
285
|
+
float amp = 1.0;
|
|
286
|
+
for (int i = 0; i < 7; i++) {
|
|
287
|
+
float cell = uRingTexel * 0.7 / exp2(float(i));
|
|
288
|
+
float w = smoothstep(1.4, 3.0, cell / du);
|
|
289
|
+
if (w <= 0.0) break;
|
|
290
|
+
sum += w * amp * (rnoise(u / cell + float(i) * 17.0) - 0.5);
|
|
291
|
+
amp *= 0.62;
|
|
292
|
+
}
|
|
293
|
+
float k = max(0.0, 1.0 + 1.4 * fade * sum);
|
|
294
|
+
t = vec4(t.rgb * k, clamp(t.a * k, 0.0, 1.0));
|
|
295
|
+
}
|
|
296
|
+
`);
|
|
182
297
|
export const RING_VERTEX = /* glsl */ `
|
|
183
298
|
varying vec3 vL;
|
|
184
299
|
varying vec3 vW;
|
package/dist/scene/look.d.ts
CHANGED
|
@@ -89,11 +89,37 @@ export interface BodyLook {
|
|
|
89
89
|
wrap?: number;
|
|
90
90
|
/** How much of the night side shows (0 to 1). Default 0.04. */
|
|
91
91
|
ambient?: number;
|
|
92
|
+
/**
|
|
93
|
+
* The generic fine detail of a close view (noise, not a measured feature): how strong (0 to 1, default 0.32; 0 for none) and how much it is stretched along the lines of latitude (1 is none; a gas giant's streaks 3). A glowing body takes none.
|
|
94
|
+
* Where a map or a shader is enlarged more than about a quarter, octaves of it are added so the body does not go smooth.
|
|
95
|
+
*/
|
|
96
|
+
detail?: {
|
|
97
|
+
amount?: number;
|
|
98
|
+
stretch?: number;
|
|
99
|
+
};
|
|
92
100
|
painted?: PaintedMap;
|
|
93
101
|
/** Draw the painted map in the realistic look too: for a body with no honest drawing from numbers (the Earth's continents). */
|
|
94
102
|
mapped?: boolean;
|
|
95
103
|
}
|
|
96
104
|
import type { StarLook, StarNumbers } from "../star.ts";
|
|
105
|
+
/**
|
|
106
|
+
* The strength and stretch of a body's generic fine detail: its own `detail`, else the table's for a body that is smooth (the gas giants, Venus, Titan) or the rocky default.
|
|
107
|
+
*
|
|
108
|
+
* @param look - The body's look.
|
|
109
|
+
* @returns How strong it is (0 to 1) and how much it is stretched along the lines of latitude.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* import { detailOf, lookOf } from "@johnmorrisdotca/wakusei-planets/look";
|
|
114
|
+
*
|
|
115
|
+
* const look = lookOf("mars");
|
|
116
|
+
* console.log(look === undefined ? "no look" : detailOf(look).amount);
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export declare function detailOf(look: BodyLook): {
|
|
120
|
+
amount: number;
|
|
121
|
+
stretch: number;
|
|
122
|
+
};
|
|
97
123
|
/**
|
|
98
124
|
* 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.
|
|
99
125
|
*
|
package/dist/scene/look.js
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
import { starLook } from "../star.js";
|
|
2
2
|
import { looks, stars, waiting } from "./store.js";
|
|
3
|
+
const SMOOTH = {
|
|
4
|
+
jupiter: { amount: 0.11, stretch: 7 },
|
|
5
|
+
saturn: { amount: 0.06, stretch: 12 },
|
|
6
|
+
uranus: { amount: 0.04, stretch: 8 },
|
|
7
|
+
neptune: { amount: 0.05, stretch: 8 },
|
|
8
|
+
venus: { amount: 0.07, stretch: 4 },
|
|
9
|
+
titan: { amount: 0.06, stretch: 4 },
|
|
10
|
+
earth: { amount: 0.2, stretch: 1 },
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* The strength and stretch of a body's generic fine detail: its own `detail`, else the table's for a body that is smooth (the gas giants, Venus, Titan) or the rocky default.
|
|
14
|
+
*
|
|
15
|
+
* @param look - The body's look.
|
|
16
|
+
* @returns How strong it is (0 to 1) and how much it is stretched along the lines of latitude.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { detailOf, lookOf } from "@johnmorrisdotca/wakusei-planets/look";
|
|
21
|
+
*
|
|
22
|
+
* const look = lookOf("mars");
|
|
23
|
+
* console.log(look === undefined ? "no look" : detailOf(look).amount);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export function detailOf(look) {
|
|
27
|
+
if (look.emissive === true)
|
|
28
|
+
return { amount: 0, stretch: 1 };
|
|
29
|
+
const own = SMOOTH[look.id];
|
|
30
|
+
return { amount: look.detail?.amount ?? own?.amount ?? 0.32, stretch: look.detail?.stretch ?? own?.stretch ?? 1 };
|
|
31
|
+
}
|
|
3
32
|
/**
|
|
4
33
|
* 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.
|
|
5
34
|
*
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { BodyLook } from "./look.ts";
|
|
2
|
+
import { type TileLevel } from "./tiles.ts";
|
|
3
|
+
/** CSS pixels across the picture a zoom limit is worked out for. */
|
|
4
|
+
export declare const REFERENCE_FRAME = 480;
|
|
5
|
+
/** The widest a texel of the map may be, in CSS pixels at the reference frame, while the picture still shows real detail. */
|
|
6
|
+
export declare const SHARP_TEXEL = 1.6;
|
|
7
|
+
/** How many times further than the real detail the generic detail carries a body: a rocky or icy one, a smooth one (a gas giant's bands), and a ring system (its strip is a line, so the noise only sharpens it). */
|
|
8
|
+
export declare const GENERIC_REACH: {
|
|
9
|
+
readonly rocky: 1.15;
|
|
10
|
+
readonly smooth: 2;
|
|
11
|
+
readonly rings: 1.25;
|
|
12
|
+
};
|
|
13
|
+
/** No body zooms less than this (what the shaded looks always had), and none more than this. */
|
|
14
|
+
export declare const ZOOM_FLOOR = 8;
|
|
15
|
+
export declare const ZOOM_CEILING = 1000;
|
|
16
|
+
/** The width of map a body drawn by its shader alone is counted as: its craters and bands are drawn from numbers at any size, but only so finely. */
|
|
17
|
+
export declare const SHADER_WIDTH = 4096;
|
|
18
|
+
/** The widest map a body has, in texels round the equator: the finest tile level, else its widest painted picture, else what its shader counts for. */
|
|
19
|
+
export declare function mapWidthOf(look: BodyLook | undefined, painted: boolean, levels: readonly TileLevel[] | undefined): number;
|
|
20
|
+
/**
|
|
21
|
+
* The width of map round the equator that has as many texels to a kilometre as a body's picture of its rings has along a radius: the rings are one line of samples from their inner edge to their outer, so a body that has
|
|
22
|
+
* a picture of them (Saturn) can be zoomed to where the rings' detail runs out, which is further than its globe's. `0` for a body with none.
|
|
23
|
+
*/
|
|
24
|
+
export declare function ringWidthOf(look: BodyLook | undefined, radiusKm: number): number;
|
|
25
|
+
/**
|
|
26
|
+
* The zoom limit of a body: where its real detail runs out times how far its generic detail carries it, in zoom steps of a picture `extent` radii from the middle to the edge.
|
|
27
|
+
*
|
|
28
|
+
* @param extent - Body radii from the middle of the picture to its edge at zoom 1.
|
|
29
|
+
* @param width - The widest map the body has, in texels round the equator (`mapWidthOf`).
|
|
30
|
+
* @param smooth - True for a body whose surface is soft (a gas giant, Venus, Titan): the generic detail carries it further.
|
|
31
|
+
* @param ringWidth - The equivalent width of the body's picture of its rings (`ringWidthOf`), or 0.
|
|
32
|
+
* @returns The zoom, from `ZOOM_FLOOR` to `ZOOM_CEILING`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function zoomLimit(extent: number, width: number, smooth: boolean, ringWidth?: number): number;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { BASE_WIDTH } from "./tiles.js";
|
|
2
|
+
/** CSS pixels across the picture a zoom limit is worked out for. */
|
|
3
|
+
export const REFERENCE_FRAME = 480;
|
|
4
|
+
/** The widest a texel of the map may be, in CSS pixels at the reference frame, while the picture still shows real detail. */
|
|
5
|
+
export const SHARP_TEXEL = 1.6;
|
|
6
|
+
/** How many times further than the real detail the generic detail carries a body: a rocky or icy one, a smooth one (a gas giant's bands), and a ring system (its strip is a line, so the noise only sharpens it). */
|
|
7
|
+
export const GENERIC_REACH = { rocky: 1.15, smooth: 2, rings: 1.25 };
|
|
8
|
+
/** No body zooms less than this (what the shaded looks always had), and none more than this. */
|
|
9
|
+
export const ZOOM_FLOOR = 8;
|
|
10
|
+
export const ZOOM_CEILING = 1000;
|
|
11
|
+
/** The width of map a body drawn by its shader alone is counted as: its craters and bands are drawn from numbers at any size, but only so finely. */
|
|
12
|
+
export const SHADER_WIDTH = 4096;
|
|
13
|
+
/** The widest map a body has, in texels round the equator: the finest tile level, else its widest painted picture, else what its shader counts for. */
|
|
14
|
+
export function mapWidthOf(look, painted, levels) {
|
|
15
|
+
if (!painted || look?.painted === undefined)
|
|
16
|
+
return SHADER_WIDTH;
|
|
17
|
+
const own = look.painted.widths[look.painted.widths.length - 1] ?? BASE_WIDTH;
|
|
18
|
+
const finest = levels?.reduce((width, level) => Math.max(width, level.width), 0) ?? 0;
|
|
19
|
+
return Math.max(own, finest);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The width of map round the equator that has as many texels to a kilometre as a body's picture of its rings has along a radius: the rings are one line of samples from their inner edge to their outer, so a body that has
|
|
23
|
+
* a picture of them (Saturn) can be zoomed to where the rings' detail runs out, which is further than its globe's. `0` for a body with none.
|
|
24
|
+
*/
|
|
25
|
+
export function ringWidthOf(look, radiusKm) {
|
|
26
|
+
const rings = look?.painted?.rings;
|
|
27
|
+
if (rings === undefined || rings.width <= 0 || rings.to <= rings.from)
|
|
28
|
+
return 0;
|
|
29
|
+
return (2 * Math.PI * radiusKm * rings.width) / (rings.to - rings.from);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The zoom limit of a body: where its real detail runs out times how far its generic detail carries it, in zoom steps of a picture `extent` radii from the middle to the edge.
|
|
33
|
+
*
|
|
34
|
+
* @param extent - Body radii from the middle of the picture to its edge at zoom 1.
|
|
35
|
+
* @param width - The widest map the body has, in texels round the equator (`mapWidthOf`).
|
|
36
|
+
* @param smooth - True for a body whose surface is soft (a gas giant, Venus, Titan): the generic detail carries it further.
|
|
37
|
+
* @param ringWidth - The equivalent width of the body's picture of its rings (`ringWidthOf`), or 0.
|
|
38
|
+
* @returns The zoom, from `ZOOM_FLOOR` to `ZOOM_CEILING`.
|
|
39
|
+
*/
|
|
40
|
+
export function zoomLimit(extent, width, smooth, ringWidth = 0) {
|
|
41
|
+
const across = (texels) => (SHARP_TEXEL * texels) / (Math.PI * REFERENCE_FRAME);
|
|
42
|
+
const reach = Math.max(across(width) * (smooth ? GENERIC_REACH.smooth : GENERIC_REACH.rocky), across(ringWidth) * GENERIC_REACH.rings);
|
|
43
|
+
return Math.round(Math.min(ZOOM_CEILING, Math.max(ZOOM_FLOOR, reach * extent)) * 10) / 10;
|
|
44
|
+
}
|
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.28.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,8 +21,22 @@ 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.28.0/textures/";
|
|
25
|
+
/**
|
|
26
|
+
* Where the finer map tiles are by default: the demo site's `tiles/` folder (GitHub Pages sends `access-control-allow-origin: *`). The tiles are made by `scripts/make-body-tiles.py` and are in no package and no repository:
|
|
27
|
+
* a page that serves its own gives the folder in the `tiles` attribute, and `tiles="off"` turns them off. A page that sets `texture-base` (it serves its own pictures) has none unless it says where they are.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts no-run
|
|
31
|
+
* import { TILES_BASE } from "@johnmorrisdotca/wakusei-planets/element";
|
|
32
|
+
*
|
|
33
|
+
* console.log(TILES_BASE);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare const TILES_BASE = "https://johnmorrisdotca.github.io/wakusei-planets/tiles/";
|
|
25
37
|
export declare const slash: (base: string) => string;
|
|
38
|
+
/** The folder of finer map tiles for an element: its `tiles` attribute (`off` or `none` for none), else `TILES_BASE` unless the element names its own `texture-base`. */
|
|
39
|
+
export declare function tilesBase(element: Element): string | undefined;
|
|
26
40
|
export declare function texturePaths(element: Element): {
|
|
27
41
|
textureBase(): string;
|
|
28
42
|
farBase(): string;
|
package/dist/scene/textures.js
CHANGED
|
@@ -22,7 +22,28 @@ export const TEXTURE_BASE = `https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakus
|
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
24
|
export const TEXTURE_FAR_BASE = `https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v${VERSION}/textures/`;
|
|
25
|
+
/**
|
|
26
|
+
* Where the finer map tiles are by default: the demo site's `tiles/` folder (GitHub Pages sends `access-control-allow-origin: *`). The tiles are made by `scripts/make-body-tiles.py` and are in no package and no repository:
|
|
27
|
+
* a page that serves its own gives the folder in the `tiles` attribute, and `tiles="off"` turns them off. A page that sets `texture-base` (it serves its own pictures) has none unless it says where they are.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts no-run
|
|
31
|
+
* import { TILES_BASE } from "@johnmorrisdotca/wakusei-planets/element";
|
|
32
|
+
*
|
|
33
|
+
* console.log(TILES_BASE);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export const TILES_BASE = "https://johnmorrisdotca.github.io/wakusei-planets/tiles/";
|
|
25
37
|
export const slash = (base) => (base.endsWith("/") ? base : `${base}/`);
|
|
38
|
+
/** The folder of finer map tiles for an element: its `tiles` attribute (`off` or `none` for none), else `TILES_BASE` unless the element names its own `texture-base`. */
|
|
39
|
+
export function tilesBase(element) {
|
|
40
|
+
const own = element.getAttribute("tiles");
|
|
41
|
+
if (own === "off" || own === "none")
|
|
42
|
+
return undefined;
|
|
43
|
+
if (own !== null && own !== "")
|
|
44
|
+
return slash(own);
|
|
45
|
+
return element.hasAttribute("texture-base") ? undefined : TILES_BASE;
|
|
46
|
+
}
|
|
26
47
|
export function texturePaths(element) {
|
|
27
48
|
const textureBase = () => {
|
|
28
49
|
const own = element.getAttribute("texture-base");
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { Vec3 } from "../vec.ts";
|
|
2
|
+
/** The side of a tile in pixels. */
|
|
3
|
+
export declare const TILE_SIZE = 512;
|
|
4
|
+
/** The width of the package's own map, the pyramid's level 0. */
|
|
5
|
+
export declare const BASE_WIDTH = 2048;
|
|
6
|
+
/** The most tiles in a window of picture (a 2048 pixel square, or 4096 by 1024 round a pole) and the most along one side: the graphics memory a window takes is about 22 MB. */
|
|
7
|
+
export declare const WINDOW_TILES = 16;
|
|
8
|
+
export declare const WINDOW_SIDE = 8;
|
|
9
|
+
/** How much larger than a device pixel a texel may be before the next level is wanted: 1.25 is a quarter larger. */
|
|
10
|
+
export declare const TEXEL_SLACK = 1.25;
|
|
11
|
+
/** One level of a body's pyramid, from the manifest. */
|
|
12
|
+
export interface TileLevel {
|
|
13
|
+
level: number;
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
columns: number;
|
|
17
|
+
rows: number;
|
|
18
|
+
}
|
|
19
|
+
/** What a tile set says it holds: the levels of each body (level 1 and up). */
|
|
20
|
+
export interface TileManifest {
|
|
21
|
+
tileSize: number;
|
|
22
|
+
bodies: Record<string, TileLevel[]>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Read a tile set's `manifest.json`. A manifest that is not the shape this reads, or whose tile size is not the one the loader cuts windows for, is `undefined`: the bodies are then drawn from their own pictures.
|
|
26
|
+
*
|
|
27
|
+
* @param value - The parsed JSON.
|
|
28
|
+
* @returns The manifest, or `undefined`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function parseManifest(value: unknown): TileManifest | undefined;
|
|
31
|
+
/** The part of the surface in view: longitude from `lonMin` to `lonMax` (radians, not wrapped, so `lonMax - lonMin` is the width, at most a whole turn) and latitude from `latMin` to `latMax`. */
|
|
32
|
+
export interface Region {
|
|
33
|
+
lonMin: number;
|
|
34
|
+
lonMax: number;
|
|
35
|
+
latMin: number;
|
|
36
|
+
latMax: number;
|
|
37
|
+
}
|
|
38
|
+
/** A body's axes in the view: the three directions its east, pole and prime meridian point in (unit vectors, x right, y up, z toward the viewer), and the lengths of its semi-axes in the same order, in radii. */
|
|
39
|
+
export interface Axes {
|
|
40
|
+
east: Vec3;
|
|
41
|
+
pole: Vec3;
|
|
42
|
+
meridian: Vec3;
|
|
43
|
+
scale: Vec3;
|
|
44
|
+
}
|
|
45
|
+
/** The orthographic camera's box, in radii from the body's centre. */
|
|
46
|
+
export interface ViewBox {
|
|
47
|
+
left: number;
|
|
48
|
+
right: number;
|
|
49
|
+
bottom: number;
|
|
50
|
+
top: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The longitudes and latitudes of the body's surface that the camera's box shows: the front of the globe is sampled on a grid and round the limb, each point turned into the body's own frame,
|
|
54
|
+
* and the two poles are looked for separately (a pole in view means every longitude is). The region is a little too large rather than too small.
|
|
55
|
+
*
|
|
56
|
+
* @param box - The camera's box.
|
|
57
|
+
* @param axes - The body's axes in the view.
|
|
58
|
+
* @param pad - The margin added all round, as a fraction of the region (and at least two degrees when it is not 0). Default 0.06.
|
|
59
|
+
* @returns The region, or `undefined` when the box shows none of the disc.
|
|
60
|
+
*/
|
|
61
|
+
export declare function visibleRegion(box: ViewBox, axes: Axes, pad?: number): Region | undefined;
|
|
62
|
+
/** A window of picture: tiles of one level, `cols` across starting at column `col0` (the columns wrap round the far edge) and `rows` down from row `row0`. */
|
|
63
|
+
export interface TileWindow {
|
|
64
|
+
level: number;
|
|
65
|
+
col0: number;
|
|
66
|
+
cols: number;
|
|
67
|
+
row0: number;
|
|
68
|
+
rows: number;
|
|
69
|
+
columns: number;
|
|
70
|
+
rowsTotal: number;
|
|
71
|
+
}
|
|
72
|
+
/** The window of a level that holds the region, or `undefined` when it would be more tiles than a window may hold. */
|
|
73
|
+
export declare function windowOf(level: TileLevel, region: Region): TileWindow | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* The window the view needs: the lowest level whose texels are no wider than a device pixel (a quarter wider, `TEXEL_SLACK`), or the finest there is, brought down to the finest level whose
|
|
76
|
+
* window fits. `undefined` when the body's own 2048 pixel map is sharp enough, or no level has a window that fits.
|
|
77
|
+
*
|
|
78
|
+
* @param region - The part of the surface in view.
|
|
79
|
+
* @param levels - The body's levels, level 1 up.
|
|
80
|
+
* @param radiansPixels - Device pixels along one radian of the body at the middle of the view.
|
|
81
|
+
* @returns The window, or `undefined`.
|
|
82
|
+
*/
|
|
83
|
+
export declare function chooseWindow(region: Region, levels: readonly TileLevel[], radiansPixels: number): TileWindow | undefined;
|
|
84
|
+
/** The window's place on the map, for the shader: `u0` the map's longitude coordinate of its west edge (0 to 1), `du` its width, `vTop` the latitude coordinate of its north edge (1 is the north pole) and `dv` its height. */
|
|
85
|
+
export declare function windowRect(window: TileWindow): {
|
|
86
|
+
u0: number;
|
|
87
|
+
du: number;
|
|
88
|
+
vTop: number;
|
|
89
|
+
dv: number;
|
|
90
|
+
};
|
|
91
|
+
/** The tiles of a window, with where each goes in the window's picture (`x`, `y` in pixels from its top left). */
|
|
92
|
+
export declare function windowTiles(window: TileWindow): {
|
|
93
|
+
level: number;
|
|
94
|
+
col: number;
|
|
95
|
+
row: number;
|
|
96
|
+
x: number;
|
|
97
|
+
y: number;
|
|
98
|
+
}[];
|
|
99
|
+
/** `layer/level/column/row` as the tile's path under the tile set (without the `.webp`). */
|
|
100
|
+
export declare const tilePath: (body: string, tile: {
|
|
101
|
+
level: number;
|
|
102
|
+
col: number;
|
|
103
|
+
row: number;
|
|
104
|
+
}) => string;
|
|
105
|
+
/** True when the region lies inside the window (the window is then still the right one for the view, whatever else changed). */
|
|
106
|
+
export declare function covers(window: TileWindow, region: Region): boolean;
|
|
107
|
+
/** The angle one texel of a level covers, in radians along the equator (`2 pi / width`). */
|
|
108
|
+
export declare const texelAngle: (width: number) => number;
|