@johnmorrisdotca/wakusei-planets 0.56.0 → 0.58.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.
@@ -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;
@@ -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 * modelViewMatrix * vec4(position, 1.0);
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);
@@ -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.
@@ -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);
@@ -1,5 +1,8 @@
1
1
  import type { Place, PlaceBody } from "../places.ts";
2
2
  import type { PlaceLayer, PlaceMark } from "../place-marks.ts";
3
+ import { type LandingSite } from "../landing-sites.ts";
4
+ /** A body's radius on the screen, in CSS pixels, from which the landing sites' names are written beside their dots (when the `site-flags` attribute is on). */
5
+ export declare const SITE_LABEL_FROM_PX = 110;
3
6
  /**
4
7
  * The short line under a place's name: what it is and when (a site's year, a planned landing's announced year, a feature's kind and size), in English or Japanese.
5
8
  *
@@ -38,8 +41,8 @@ export declare const placesLoader: () => PlacesLoader | undefined;
38
41
  export declare function onPlacesLoader(heard: () => void): () => void;
39
42
  /** The marks over one view. */
40
43
  export interface PlaceLayerView {
41
- /** Lay these marks, moving the ones already there, adding the new and taking away the rest. */
42
- set(marks: readonly PlaceMark[]): void;
44
+ /** Lay these marks, moving the ones already there, adding the new and taking away the rest. `radiusPx` is the body's radius on the screen: with flags on, the landing sites are named beside their dots from `SITE_LABEL_FROM_PX`. */
45
+ set(marks: readonly PlaceMark[], radiusPx?: number): void;
43
46
  /** Take every mark away. */
44
47
  clear(): void;
45
48
  /** The marks laid now: the place's id, its layer and where it is, in CSS pixels. */
@@ -60,7 +63,8 @@ export interface PlaceLayerView {
60
63
  */
61
64
  export declare function createPlaceLayer(root: ShadowRoot, options: {
62
65
  lang(): "en" | "ja";
63
- pick(place: Place, at: {
66
+ flags?(): boolean;
67
+ pick(place: Place, site: LandingSite | undefined, at: {
64
68
  x: number;
65
69
  y: number;
66
70
  }): void;
@@ -1,3 +1,4 @@
1
+ import { findLandingSite, flagCodeOf } from "../landing-sites.js";
1
2
  const STYLE = `.wk-places{position:absolute;inset:0;pointer-events:none;overflow:hidden}
2
3
  .wk-place{position:absolute;left:0;top:0;width:20px;height:20px;margin:-10px 0 0 -10px;padding:0;border:0;background:none;cursor:pointer;pointer-events:auto;will-change:transform;-webkit-tap-highlight-color:transparent}
3
4
  .wk-place::before{content:"";position:absolute;left:50%;top:50%;width:6px;height:6px;margin:-3px 0 0 -3px;border-radius:50%;box-sizing:border-box;background:var(--wakusei-place-landing,#fff);box-shadow:0 0 0 1px rgba(0,0,0,.55);opacity:.85}
@@ -11,7 +12,14 @@ const STYLE = `.wk-places{position:absolute;inset:0;pointer-events:none;overflow
11
12
  .wk-place[data-name]{width:auto;height:auto;margin:0;padding:0 3px;color:#fff;font:600 12px/1.2 var(--wakusei-place-font,system-ui,-apple-system,sans-serif);white-space:nowrap;text-shadow:0 1px 2px #000,0 0 3px #000;pointer-events:auto}
12
13
  .wk-place[data-pure]{pointer-events:none}
13
14
  .wk-place[data-name]::before{display:none}
14
- .wk-place-tip[data-on]{visibility:visible}`;
15
+ .wk-place-tip[data-on]{visibility:visible}
16
+ .wk-place-tip .wk-place-head{display:flex;align-items:center;gap:5px}
17
+ .wk-place-flag{flex:none;height:11px;pointer-events:none}
18
+ .wk-place-flag:not(:defined){display:none}
19
+ .wk-place-site{position:absolute;top:50%;left:13px;display:flex;align-items:center;gap:4px;margin-top:-8px;color:#fff;font:600 11px/16px var(--wakusei-place-font,system-ui,-apple-system,sans-serif);white-space:nowrap;text-shadow:0 1px 2px #000,0 0 3px #000;pointer-events:none}
20
+ .wk-place-site[data-side=left]{left:auto;right:13px;flex-direction:row-reverse}`;
21
+ /** A body's radius on the screen, in CSS pixels, from which the landing sites' names are written beside their dots (when the `site-flags` attribute is on). */
22
+ export const SITE_LABEL_FROM_PX = 110;
15
23
  const KIND_WORD = {
16
24
  crewed: { en: "crewed landing", ja: "有人着陸" },
17
25
  landing: { en: "lander", ja: "着陸機" },
@@ -52,6 +60,18 @@ export function placeLine(place, lang) {
52
60
  const year = place.date?.slice(0, 4);
53
61
  return year === undefined ? word : ja ? `${word}、${year}年` : `${word}, ${year}`;
54
62
  }
63
+ /** A flag for a country, as `<hata-flag>` (from `@johnmorrisdotca/hata`, which the page imports; where it is not defined the element draws nothing and the name stands alone). */
64
+ function flagFor(place) {
65
+ const code = flagCodeOf(place.country);
66
+ if (code === undefined)
67
+ return undefined;
68
+ const flag = document.createElement("hata-flag");
69
+ flag.className = "wk-place-flag";
70
+ flag.setAttribute("code", code);
71
+ flag.setAttribute("border", "");
72
+ flag.setAttribute("aria-hidden", "true");
73
+ return flag;
74
+ }
55
75
  // on globalThis, so the separate copies a CDN can load share the one loader
56
76
  const SLOT = Symbol.for("@johnmorrisdotca/wakusei-planets/places-loader");
57
77
  const slot = (globalThis[SLOT] ??= { heard: new Set() });
@@ -113,7 +133,15 @@ export function createPlaceLayer(root, options) {
113
133
  name.textContent = entry.mark.place.name[lang];
114
134
  const line = document.createElement("small");
115
135
  line.textContent = placeLine(entry.mark.place, lang);
116
- tip.replaceChildren(name, line);
136
+ const flag = options.flags?.() === true ? flagFor(entry.mark.place) : undefined;
137
+ if (flag === undefined)
138
+ tip.replaceChildren(name, line);
139
+ else {
140
+ const head = document.createElement("div");
141
+ head.className = "wk-place-head";
142
+ head.append(flag, name);
143
+ tip.replaceChildren(head, line);
144
+ }
117
145
  tip.setAttribute("data-on", "");
118
146
  tipFor = id;
119
147
  placeTip();
@@ -157,7 +185,7 @@ export function createPlaceLayer(root, options) {
157
185
  event.stopPropagation();
158
186
  const entry = held.get(id);
159
187
  if (entry !== undefined)
160
- options.pick(entry.mark.place, { x: entry.x, y: entry.y });
188
+ options.pick(entry.mark.place, entry.site, { x: entry.x, y: entry.y });
161
189
  });
162
190
  return button;
163
191
  };
@@ -189,7 +217,7 @@ export function createPlaceLayer(root, options) {
189
217
  best = { entry, away };
190
218
  }
191
219
  if (best !== undefined)
192
- options.pick(best.entry.mark.place, { x: best.entry.x, y: best.entry.y });
220
+ options.pick(best.entry.mark.place, best.entry.site, { x: best.entry.x, y: best.entry.y });
193
221
  };
194
222
  const nameCancel = () => {
195
223
  pressed = null;
@@ -197,8 +225,66 @@ export function createPlaceLayer(root, options) {
197
225
  window.addEventListener("pointerdown", nameDown, true);
198
226
  window.addEventListener("pointerup", nameUp, true);
199
227
  window.addEventListener("pointercancel", nameCancel, true);
228
+ // The landing sites' names beside their dots, with the country's flag: only with flags on, only on a body close enough to leave the room, and each in the first of the right or the left side that clears the dots and the names
229
+ // already written (marks come in the order they matter). A label belongs to its dot's button, so a press on it is the dot's.
230
+ const labelSites = (marks, radiusPx) => {
231
+ const lang = options.lang();
232
+ const width = box.clientWidth;
233
+ const on = options.flags?.() === true && radiusPx >= SITE_LABEL_FROM_PX;
234
+ // the names of the surface (Mare Imbrium, Plato) are written first and keep their place: a site's label goes round them
235
+ const taken = marks
236
+ .filter((mark) => mark.label === true && (mark.fade ?? 1) > 0.2)
237
+ .map((mark) => {
238
+ const halfWidth = Math.ceil(mark.place.name[lang].length * 3.7) + 5;
239
+ return { x0: mark.x - halfWidth, x1: mark.x + halfWidth, y0: mark.y - 9, y1: mark.y + 9 };
240
+ });
241
+ const dots = marks.filter((mark) => mark.label !== true).map((mark) => ({ mark, x0: mark.x - 8, x1: mark.x + 8, y0: mark.y - 8, y1: mark.y + 8 }));
242
+ const clear = (r, self) => (width <= 0 || (r.x0 >= 0 && r.x1 <= width)) && !taken.some((o) => r.x0 < o.x1 && r.x1 > o.x0 && r.y0 < o.y1 && r.y1 > o.y0) &&
243
+ !dots.some((d) => d.mark !== self && r.x0 < d.x1 && r.x1 > d.x0 && r.y0 < d.y1 && r.y1 > d.y0);
244
+ for (const mark of marks) {
245
+ const entry = held.get(mark.place.id);
246
+ if (entry === undefined)
247
+ continue;
248
+ let side;
249
+ if (on && mark.label !== true && entry.site !== undefined) {
250
+ const text = entry.site.name[lang];
251
+ const w = 13 + text.length * 6.4 + (flagCodeOf(entry.site.country) === undefined ? 0 : 19);
252
+ const right = { x0: mark.x + 10, x1: mark.x + 10 + w, y0: mark.y - 8, y1: mark.y + 8 };
253
+ const left = { x0: mark.x - 10 - w, x1: mark.x - 10, y0: mark.y - 8, y1: mark.y + 8 };
254
+ const spot = clear(right, mark) ? right : clear(left, mark) ? left : undefined;
255
+ if (spot !== undefined) {
256
+ taken.push(spot);
257
+ side = spot === right ? "right" : "left";
258
+ }
259
+ }
260
+ if (side === undefined) {
261
+ entry.label?.remove();
262
+ entry.label = undefined;
263
+ entry.labelKey = undefined;
264
+ continue;
265
+ }
266
+ const key = `${lang}|${side}`;
267
+ if (entry.label === undefined || !entry.label.isConnected || entry.labelKey !== key) {
268
+ entry.label?.remove();
269
+ const label = document.createElement("span");
270
+ label.className = "wk-place-site";
271
+ label.setAttribute("part", "place-site");
272
+ label.setAttribute("aria-hidden", "true");
273
+ label.dataset.side = side;
274
+ const flag = flagFor(mark.place);
275
+ const name = document.createElement("span");
276
+ name.textContent = entry.site.name[lang];
277
+ if (flag !== undefined)
278
+ label.append(flag);
279
+ label.append(name);
280
+ entry.button.append(label);
281
+ entry.label = label;
282
+ entry.labelKey = key;
283
+ }
284
+ }
285
+ };
200
286
  return {
201
- set(marks) {
287
+ set(marks, radiusPx = 0) {
202
288
  const lang = options.lang();
203
289
  const next = new Set();
204
290
  for (const mark of marks) {
@@ -207,7 +293,7 @@ export function createPlaceLayer(root, options) {
207
293
  let entry = held.get(id);
208
294
  if (entry === undefined) {
209
295
  const button = make(mark);
210
- entry = { button, mark, x: Number.NaN, y: Number.NaN, lang: "" };
296
+ entry = { button, mark, x: Number.NaN, y: Number.NaN, lang: "", site: findLandingSite(id) };
211
297
  held.set(id, entry);
212
298
  box.insertBefore(button, tip);
213
299
  }
@@ -249,6 +335,7 @@ export function createPlaceLayer(root, options) {
249
335
  entry.button.style.transform = `translate(${mark.x.toFixed(1)}px,${mark.y.toFixed(1)}px)${shift}`;
250
336
  }
251
337
  }
338
+ labelSites(marks, radiusPx);
252
339
  for (const [id, entry] of held) {
253
340
  if (next.has(id))
254
341
  continue;
@@ -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
+ }`;
@@ -197,6 +197,13 @@ export declare class WakuseiSpace extends HTMLElement {
197
197
  */
198
198
  get places(): PlaceLayer[];
199
199
  set places(layers: readonly PlaceLayer[] | null);
200
+ /**
201
+ * Whether the places carry their country's flag (the attribute `site-flags`): the tip of a place with a country shows its flag, and on a body close enough on the screen (110 pixels of radius) the landing sites (`LANDING_SITES` from
202
+ * `/landing-sites`) are named beside their dots, each with its flag. The flag is `<hata-flag>` from `@johnmorrisdotca/hata`, which the page imports itself (`import "@johnmorrisdotca/hata/element/define"`); until it is defined the name stands alone. Needs `places`.
203
+ * The `wakusei-place` event's detail carries the landing site as `site` where the place is one. Setting it writes the attribute.
204
+ */
205
+ get siteFlags(): boolean;
206
+ set siteFlags(on: boolean);
200
207
  /** The marks laid on the body looked at now: each place's id, its layer and where its mark is, in CSS pixels from the view's top left. */
201
208
  get placesShown(): readonly {
202
209
  id: string;
@@ -142,7 +142,7 @@ const orbiterLines = (value) => (value === "chosen" || value === "none" ? value
142
142
  * ```
143
143
  */
144
144
  export class WakuseiSpace extends HTMLElement {
145
- static observedAttributes = ["center", "time", "speed", "scale", "labels", "labels-always", "covered", "roadster", "spacecraft", "orbiters", "orbiter", "orbiter-lines", "orbiter-track", "orbits", "help", "look", "light", "lang", "data", "arrows", "help-through", "help-place", "places", "surface-names", "earth-places", "earth-places-look", "all-moons", "far-opacity", "transition", "pace", "frame", "pair-with", "belts", "moon-size", ...NAME_LABEL_ATTRIBUTES];
145
+ static observedAttributes = ["center", "time", "speed", "scale", "labels", "labels-always", "covered", "roadster", "spacecraft", "orbiters", "orbiter", "orbiter-lines", "orbiter-track", "orbits", "help", "look", "light", "lang", "data", "arrows", "help-through", "help-place", "places", "surface-names", "site-flags", "earth-places", "earth-places-look", "all-moons", "far-opacity", "transition", "pace", "frame", "pair-with", "belts", "moon-size", ...NAME_LABEL_ATTRIBUTES];
146
146
  #model = newSpaceModel();
147
147
  #allMoons = false;
148
148
  #catalogue;
@@ -421,7 +421,7 @@ export class WakuseiSpace extends HTMLElement {
421
421
  }
422
422
  else if (NAME_LABEL_ATTRIBUTES.includes(name))
423
423
  this.#relabel();
424
- if (name === "places" || name === "lang" || name === "surface-names")
424
+ if (name === "places" || name === "site-flags" || name === "lang" || name === "surface-names")
425
425
  this.#markSurface();
426
426
  if (name === "earth-places" || name === "earth-places-look")
427
427
  this.#askEarthPlaces();
@@ -439,6 +439,17 @@ export class WakuseiSpace extends HTMLElement {
439
439
  else
440
440
  this.setAttribute("places", layers.join(" "));
441
441
  }
442
+ /**
443
+ * Whether the places carry their country's flag (the attribute `site-flags`): the tip of a place with a country shows its flag, and on a body close enough on the screen (110 pixels of radius) the landing sites (`LANDING_SITES` from
444
+ * `/landing-sites`) are named beside their dots, each with its flag. The flag is `<hata-flag>` from `@johnmorrisdotca/hata`, which the page imports itself (`import "@johnmorrisdotca/hata/element/define"`); until it is defined the name stands alone. Needs `places`.
445
+ * The `wakusei-place` event's detail carries the landing site as `site` where the place is one. Setting it writes the attribute.
446
+ */
447
+ get siteFlags() {
448
+ return this.hasAttribute("site-flags");
449
+ }
450
+ set siteFlags(on) {
451
+ this.toggleAttribute("site-flags", on);
452
+ }
442
453
  /** The marks laid on the body looked at now: each place's id, its layer and where its mark is, in CSS pixels from the view's top left. */
443
454
  get placesShown() {
444
455
  return this.#markLayer?.shown ?? [];
@@ -769,7 +780,8 @@ export class WakuseiSpace extends HTMLElement {
769
780
  if (this.#markLayer === undefined) {
770
781
  this.#markLayer = createPlaceLayer(root, {
771
782
  lang: () => (this.getAttribute("lang") === "ja" ? "ja" : "en"),
772
- pick: (place, at) => this.dispatchEvent(new CustomEvent("wakusei-place", { detail: { body: id, place, x: at.x, y: at.y }, bubbles: true, composed: true })),
783
+ flags: () => this.hasAttribute("site-flags"),
784
+ pick: (place, site, at) => this.dispatchEvent(new CustomEvent("wakusei-place", { detail: { body: id, place, site, x: at.x, y: at.y }, bubbles: true, composed: true })),
773
785
  });
774
786
  if (this.getAttribute("role") === "img")
775
787
  this.setAttribute("role", "group");
@@ -782,7 +794,7 @@ export class WakuseiSpace extends HTMLElement {
782
794
  for (const [other, at] of Object.entries(this.#places ?? {}))
783
795
  if (at !== null && other !== id)
784
796
  keepClear.push({ x: at.x, y: at.y, halfWidth: 8, halfHeight: 8 });
785
- this.#markLayer.set(marksToShow(this.#markList.list, layers, { ...surface, scale }, facts.radiusKm, names, keepClear, this.getAttribute("lang") === "ja" ? "ja" : "en"));
797
+ this.#markLayer.set(marksToShow(this.#markList.list, layers, { ...surface, scale }, facts.radiusKm, names, keepClear, this.getAttribute("lang") === "ja" ? "ja" : "en"), surface.radiusPx);
786
798
  }
787
799
  #bodyLabel;
788
800
  /**