@johnmorrisdotca/wakusei-planets 0.33.0 → 0.35.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.
Files changed (207) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/NOTICE.md +52 -0
  3. package/README.md +26 -3
  4. package/dist/approaches.d.ts +276 -0
  5. package/dist/approaches.js +255 -0
  6. package/dist/asteroids.d.ts +397 -0
  7. package/dist/asteroids.js +338 -0
  8. package/dist/comets.d.ts +316 -0
  9. package/dist/comets.js +404 -0
  10. package/dist/craft/bepicolombo.d.ts +1 -0
  11. package/dist/craft/bepicolombo.js +923 -0
  12. package/dist/craft/europaclipper.d.ts +1 -0
  13. package/dist/craft/europaclipper.js +342 -0
  14. package/dist/craft/hayabusa2.d.ts +1 -0
  15. package/dist/craft/hayabusa2.js +73 -0
  16. package/dist/craft/juice.d.ts +1 -0
  17. package/dist/craft/juice.js +40 -0
  18. package/dist/craft/lucy.d.ts +1 -0
  19. package/dist/craft/lucy.js +42 -0
  20. package/dist/craft/osirisapex.d.ts +1 -0
  21. package/dist/craft/osirisapex.js +69 -0
  22. package/dist/craft/psyche.d.ts +1 -0
  23. package/dist/craft/psyche.js +30 -0
  24. package/dist/craft/solarorbiter.d.ts +1 -0
  25. package/dist/craft/solarorbiter.js +94 -0
  26. package/dist/data/approaches.d.ts +17 -0
  27. package/dist/data/approaches.js +4192 -0
  28. package/dist/data/asteroids.d.ts +3 -0
  29. package/dist/data/asteroids.js +107 -0
  30. package/dist/data/comets.d.ts +2 -0
  31. package/dist/data/comets.js +36 -0
  32. package/dist/data/places-67p.d.ts +27 -0
  33. package/dist/data/places-67p.js +2 -0
  34. package/dist/data/places-ariel.d.ts +602 -0
  35. package/dist/data/places-ariel.js +27 -0
  36. package/dist/data/places-bennu.d.ts +25 -0
  37. package/dist/data/places-bennu.js +2 -0
  38. package/dist/data/places-callisto.d.ts +3547 -0
  39. package/dist/data/places-callisto.js +155 -0
  40. package/dist/data/places-ceres.d.ts +3436 -0
  41. package/dist/data/places-ceres.js +150 -0
  42. package/dist/data/places-charon.d.ts +349 -0
  43. package/dist/data/places-charon.js +16 -0
  44. package/dist/data/places-dimorphos.d.ts +23 -0
  45. package/dist/data/places-dimorphos.js +2 -0
  46. package/dist/data/places-dione.d.ts +2258 -0
  47. package/dist/data/places-dione.js +99 -0
  48. package/dist/data/places-enceladus.d.ts +2009 -0
  49. package/dist/data/places-enceladus.js +88 -0
  50. package/dist/data/places-eros.d.ts +26 -0
  51. package/dist/data/places-eros.js +2 -0
  52. package/dist/data/places-europa.d.ts +2977 -0
  53. package/dist/data/places-europa.js +130 -0
  54. package/dist/data/places-ganymede.d.ts +4518 -0
  55. package/dist/data/places-ganymede.js +197 -0
  56. package/dist/data/places-iapetus.d.ts +1616 -0
  57. package/dist/data/places-iapetus.js +71 -0
  58. package/dist/data/places-io.d.ts +6012 -0
  59. package/dist/data/places-io.js +262 -0
  60. package/dist/data/places-jupiter.d.ts +46 -0
  61. package/dist/data/places-jupiter.js +3 -0
  62. package/dist/data/places-mars.d.ts +20701 -0
  63. package/dist/data/places-mars.js +942 -0
  64. package/dist/data/places-mercury.d.ts +9256 -0
  65. package/dist/data/places-mercury.js +403 -0
  66. package/dist/data/places-mimas.d.ts +968 -0
  67. package/dist/data/places-mimas.js +43 -0
  68. package/dist/data/places-miranda.d.ts +419 -0
  69. package/dist/data/places-miranda.js +19 -0
  70. package/dist/data/places-moon.d.ts +18849 -0
  71. package/dist/data/places-moon.js +861 -0
  72. package/dist/data/places-oberon.d.ts +235 -0
  73. package/dist/data/places-oberon.js +11 -0
  74. package/dist/data/places-pluto.d.ts +1687 -0
  75. package/dist/data/places-pluto.js +74 -0
  76. package/dist/data/places-rhea.d.ts +3317 -0
  77. package/dist/data/places-rhea.js +145 -0
  78. package/dist/data/places-ryugu.d.ts +87 -0
  79. package/dist/data/places-ryugu.js +5 -0
  80. package/dist/data/places-saturn.d.ts +25 -0
  81. package/dist/data/places-saturn.js +2 -0
  82. package/dist/data/places-tempel-1.d.ts +25 -0
  83. package/dist/data/places-tempel-1.js +2 -0
  84. package/dist/data/places-tethys.d.ts +1222 -0
  85. package/dist/data/places-tethys.js +54 -0
  86. package/dist/data/places-titan.d.ts +7031 -0
  87. package/dist/data/places-titan.js +306 -0
  88. package/dist/data/places-titania.d.ts +418 -0
  89. package/dist/data/places-titania.js +19 -0
  90. package/dist/data/places-triton.d.ts +1457 -0
  91. package/dist/data/places-triton.js +64 -0
  92. package/dist/data/places-umbriel.d.ts +303 -0
  93. package/dist/data/places-umbriel.js +14 -0
  94. package/dist/data/places-venus.d.ts +9290 -0
  95. package/dist/data/places-venus.js +405 -0
  96. package/dist/data/places-vesta.d.ts +2444 -0
  97. package/dist/data/places-vesta.js +107 -0
  98. package/dist/data/roadster.d.ts +8 -0
  99. package/dist/data/roadster.js +686 -0
  100. package/dist/element.d.ts +10 -1
  101. package/dist/element.js +39 -4
  102. package/dist/places/67p.d.ts +13 -0
  103. package/dist/places/67p.js +14 -0
  104. package/dist/places/ariel.d.ts +13 -0
  105. package/dist/places/ariel.js +14 -0
  106. package/dist/places/bennu.d.ts +13 -0
  107. package/dist/places/bennu.js +14 -0
  108. package/dist/places/callisto.d.ts +13 -0
  109. package/dist/places/callisto.js +14 -0
  110. package/dist/places/ceres.d.ts +13 -0
  111. package/dist/places/ceres.js +14 -0
  112. package/dist/places/charon.d.ts +13 -0
  113. package/dist/places/charon.js +14 -0
  114. package/dist/places/dimorphos.d.ts +13 -0
  115. package/dist/places/dimorphos.js +14 -0
  116. package/dist/places/dione.d.ts +13 -0
  117. package/dist/places/dione.js +14 -0
  118. package/dist/places/enceladus.d.ts +13 -0
  119. package/dist/places/enceladus.js +14 -0
  120. package/dist/places/eros.d.ts +13 -0
  121. package/dist/places/eros.js +14 -0
  122. package/dist/places/europa.d.ts +13 -0
  123. package/dist/places/europa.js +14 -0
  124. package/dist/places/ganymede.d.ts +13 -0
  125. package/dist/places/ganymede.js +14 -0
  126. package/dist/places/iapetus.d.ts +13 -0
  127. package/dist/places/iapetus.js +14 -0
  128. package/dist/places/io.d.ts +13 -0
  129. package/dist/places/io.js +14 -0
  130. package/dist/places/jupiter.d.ts +13 -0
  131. package/dist/places/jupiter.js +14 -0
  132. package/dist/places/mars.d.ts +12 -0
  133. package/dist/places/mars.js +13 -0
  134. package/dist/places/mercury.d.ts +13 -0
  135. package/dist/places/mercury.js +14 -0
  136. package/dist/places/mimas.d.ts +13 -0
  137. package/dist/places/mimas.js +14 -0
  138. package/dist/places/miranda.d.ts +13 -0
  139. package/dist/places/miranda.js +14 -0
  140. package/dist/places/moon.d.ts +12 -0
  141. package/dist/places/moon.js +13 -0
  142. package/dist/places/oberon.d.ts +13 -0
  143. package/dist/places/oberon.js +14 -0
  144. package/dist/places/pluto.d.ts +13 -0
  145. package/dist/places/pluto.js +14 -0
  146. package/dist/places/rhea.d.ts +13 -0
  147. package/dist/places/rhea.js +14 -0
  148. package/dist/places/ryugu.d.ts +13 -0
  149. package/dist/places/ryugu.js +14 -0
  150. package/dist/places/saturn.d.ts +13 -0
  151. package/dist/places/saturn.js +14 -0
  152. package/dist/places/tempel-1.d.ts +13 -0
  153. package/dist/places/tempel-1.js +14 -0
  154. package/dist/places/tethys.d.ts +13 -0
  155. package/dist/places/tethys.js +14 -0
  156. package/dist/places/titan.d.ts +13 -0
  157. package/dist/places/titan.js +14 -0
  158. package/dist/places/titania.d.ts +13 -0
  159. package/dist/places/titania.js +14 -0
  160. package/dist/places/triton.d.ts +13 -0
  161. package/dist/places/triton.js +14 -0
  162. package/dist/places/umbriel.d.ts +13 -0
  163. package/dist/places/umbriel.js +14 -0
  164. package/dist/places/venus.d.ts +13 -0
  165. package/dist/places/venus.js +14 -0
  166. package/dist/places/vesta.d.ts +13 -0
  167. package/dist/places/vesta.js +14 -0
  168. package/dist/places.d.ts +354 -0
  169. package/dist/places.js +357 -0
  170. package/dist/plan/element.d.ts +52 -0
  171. package/dist/plan/element.js +258 -0
  172. package/dist/plan/index.d.ts +2 -0
  173. package/dist/plan/index.js +2 -0
  174. package/dist/plan/layout.d.ts +230 -0
  175. package/dist/plan/layout.js +229 -0
  176. package/dist/plan/svg.d.ts +125 -0
  177. package/dist/plan/svg.js +185 -0
  178. package/dist/roadster.d.ts +415 -0
  179. package/dist/roadster.js +496 -0
  180. package/dist/scene/body.d.ts +13 -2
  181. package/dist/scene/body.js +36 -0
  182. package/dist/scene/name-label.d.ts +116 -0
  183. package/dist/scene/name-label.js +232 -0
  184. package/dist/scene/painter.d.ts +30 -1
  185. package/dist/scene/painter.js +56 -4
  186. package/dist/scene/textures.d.ts +2 -2
  187. package/dist/space/beside.d.ts +4 -1
  188. package/dist/space/beside.js +47 -6
  189. package/dist/space/covered.d.ts +102 -0
  190. package/dist/space/covered.js +98 -0
  191. package/dist/space/element.d.ts +37 -1
  192. package/dist/space/element.js +151 -11
  193. package/dist/space/index.d.ts +1 -0
  194. package/dist/space/index.js +1 -0
  195. package/dist/space/scale.d.ts +2 -1
  196. package/dist/space/scale.js +13 -2
  197. package/dist/space/scene.d.ts +23 -1
  198. package/dist/space/scene.js +62 -21
  199. package/dist/spacecraft-facts.d.ts +4 -4
  200. package/dist/spacecraft-facts.js +158 -3
  201. package/dist/spacecraft.d.ts +69 -2
  202. package/dist/spacecraft.js +45 -2
  203. package/dist/textures/mimas-1024.webp +0 -0
  204. package/dist/textures/mimas-512.webp +0 -0
  205. package/dist/version.d.ts +1 -1
  206. package/dist/version.js +1 -1
  207. package/package.json +204 -2
@@ -0,0 +1,116 @@
1
+ import { type BodyLabelLook, type BodyLabelRepeat, type BodyLabelSize } from "@johnmorrisdotca/kazoku-ui/body-label";
2
+ import type * as THREE from "three";
3
+ import type { ThreeParts } from "./body.ts";
4
+ import type { Vec3 } from "../vec.ts";
5
+ /**
6
+ * The name written on a body's globe: the family's `bodyLabel` property. `look` is the one setting with no default: `painted` (pale letters over the surface), `etched` (the letters lighten the surface), `outline`
7
+ * (the letters' edges) or `burned` (darker letters). The rest fall back to the family's: half strength, the name once, on the equator, turning with the body, in Michroma. The text is the body's own name
8
+ * in the element's language (`EARTH`, `地球`), so it is not a setting here.
9
+ *
10
+ * @example
11
+ * ```ts no-run
12
+ * import type { NameLabelOptions } from "@johnmorrisdotca/wakusei-planets/painter";
13
+ *
14
+ * const label: NameLabelOptions = { look: "painted", strength: 0.5, repeat: "both", latitude: 0, facing: false };
15
+ * console.log(label.look);
16
+ * ```
17
+ */
18
+ export interface NameLabelOptions {
19
+ look: BodyLabelLook;
20
+ /** How strongly it shows, 0 to 1. Default 0.5. */
21
+ strength?: number;
22
+ /** `once`, `both` (two, on opposite sides, so one is always in view) or `around` (as many as fit). Default `once`. */
23
+ repeat?: BodyLabelRepeat;
24
+ /** The band's latitude in degrees: 0 is the equator; 55 or -55 is near a pole. Default 0. */
25
+ latitude?: number;
26
+ /** True: the name keeps facing the reader while the body turns under it. Default false. */
27
+ facing?: boolean;
28
+ /** A CSS font family the page has loaded. Default Michroma, which the label fetches itself (64 kB, once). */
29
+ font?: string;
30
+ /** The family for letters `font` has none of, such as Japanese (`"Noto Sans JP"`). Default the page's sans. */
31
+ fallbackFont?: string;
32
+ /** `small`, `medium` or `large`. Default `medium`. */
33
+ size?: BodyLabelSize;
34
+ /** No label while the body is drawn smaller than this many CSS pixels in radius. Default 24. */
35
+ minRadiusPx?: number;
36
+ }
37
+ /** The family's standard attribute names, as `readNameLabel` reads them. */
38
+ export declare const NAME_LABEL_ATTRIBUTES: readonly ["body-label", "body-label-strength", "body-label-repeat", "body-label-latitude", "body-label-facing", "body-label-font", "body-label-fallback-font"];
39
+ /**
40
+ * The label the family's attributes ask for (`body-label="painted"` and the six beside it), or `null` when `body-label` is absent or not a look.
41
+ *
42
+ * @param el - Anything with `getAttribute` and `hasAttribute`: the element.
43
+ * @returns The options, or `null` for no label.
44
+ *
45
+ * @example
46
+ * ```ts no-run
47
+ * import { readNameLabel } from "@johnmorrisdotca/wakusei-planets/painter";
48
+ *
49
+ * const el = document.querySelector("wakusei-body")!;
50
+ * el.setAttribute("body-label", "etched");
51
+ * console.log(readNameLabel(el)?.look);
52
+ * ```
53
+ */
54
+ export declare function readNameLabel(el: {
55
+ getAttribute(name: string): string | null;
56
+ hasAttribute(name: string): boolean;
57
+ }): NameLabelOptions | null;
58
+ /**
59
+ * The text written for a body: its English name in capitals (the family's look), or its Japanese name as it is.
60
+ *
61
+ * @param name - The body's names, as `BODIES[id].name` holds them.
62
+ * @param lang - `en` (the default) or `ja`.
63
+ * @returns The text to write.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * import { BODIES } from "@johnmorrisdotca/wakusei-planets";
68
+ * import { nameLabelText } from "@johnmorrisdotca/wakusei-planets/painter";
69
+ *
70
+ * console.log(nameLabelText(BODIES.earth.name, "en"), nameLabelText(BODIES.earth.name, "ja"));
71
+ * ```
72
+ */
73
+ export declare function nameLabelText(name: {
74
+ en: string;
75
+ ja: string;
76
+ }, lang?: "en" | "ja"): string;
77
+ /** One string that changes whenever the label would be made differently (the text and every setting): for a host that keeps a still for each state. */
78
+ export declare function nameLabelKey(text: string, options: NameLabelOptions | null | undefined): string;
79
+ /** 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. */
80
+ export type LabelParts = Pick<typeof THREE, "CanvasTexture" | "SRGBColorSpace" | "NormalBlending">;
81
+ /** What `createNameLabel` returns: the group to add to the body's mesh, and the calls the host makes. */
82
+ export interface NameLabel {
83
+ /** Add it to the body's turning mesh (a radius-1 sphere whose +z is longitude 0). */
84
+ readonly object: THREE.Group;
85
+ /** True once the name is drawn in its font: the host draws its view again when `onReady` is called. */
86
+ readonly ready: boolean;
87
+ /** Before each draw: the camera (for `facing`; left out, the name faces +z), the body's radius on the screen in CSS pixels, and the direction to the light in the scene's axes. Returns true when it hid, showed or turned the name. */
88
+ update(camera: THREE.Camera | undefined, radiusPx: number, light: Vec3): boolean;
89
+ /** New settings or text; the texture is drawn again only when it must be. */
90
+ set(text: string, options: NameLabelOptions): void;
91
+ dispose(): void;
92
+ }
93
+ /**
94
+ * Where Michroma is fetched from, for a page whose bundler does not carry kazoku-ui's font file along with its module (the label looks for it next to the module, `fonts/Michroma-Regular.ttf`). Call it before the
95
+ * first name is written. A page that sets `body-label-font` to a font of its own needs nothing here.
96
+ *
97
+ * @param url - The address of `Michroma-Regular.ttf`, with its `OFL.txt` beside it.
98
+ *
99
+ * @example
100
+ * ```ts no-run
101
+ * import { setBodyLabelFontUrl } from "@johnmorrisdotca/wakusei-planets/painter";
102
+ *
103
+ * setBodyLabelFontUrl("/fonts/Michroma-Regular.ttf");
104
+ * ```
105
+ */
106
+ export declare function setBodyLabelFontUrl(url: string | URL): void;
107
+ /**
108
+ * Make a body's name label. The group is empty until the font is in (at once when it is already loaded); `onReady` is called when the name is drawn, so the host can draw its view again.
109
+ *
110
+ * @param T - The three.js module the bodies use. Without `CanvasTexture`, `SRGBColorSpace` and `NormalBlending` there is no label, and a warning once.
111
+ * @param text - The name as it is written.
112
+ * @param options - The look and the rest.
113
+ * @param emissive - The body glows (the Sun): the name is lit fully, from no direction.
114
+ * @param onReady - Called when the name is drawn, and again when a new font is in.
115
+ */
116
+ export declare function createNameLabel(T: ThreeParts, text: string, options: NameLabelOptions, emissive: boolean, onReady: () => void): NameLabel;
@@ -0,0 +1,232 @@
1
+ // A body's name written on its own globe (kazoku-ui's shared body label), fitted to this package's bodies: the band is a child of the body's mesh, so it turns with the body, in the frame
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
+ // 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
+ import { BODY_LABEL_FONT, createBodyLabel, loadBodyLabelFont } from "@johnmorrisdotca/kazoku-ui/body-label";
5
+ /** The family's standard attribute names, as `readNameLabel` reads them. */
6
+ 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"];
7
+ const LOOKS = ["painted", "etched", "outline", "burned"];
8
+ const REPEATS = ["once", "both", "around"];
9
+ /**
10
+ * The label the family's attributes ask for (`body-label="painted"` and the six beside it), or `null` when `body-label` is absent or not a look.
11
+ *
12
+ * @param el - Anything with `getAttribute` and `hasAttribute`: the element.
13
+ * @returns The options, or `null` for no label.
14
+ *
15
+ * @example
16
+ * ```ts no-run
17
+ * import { readNameLabel } from "@johnmorrisdotca/wakusei-planets/painter";
18
+ *
19
+ * const el = document.querySelector("wakusei-body")!;
20
+ * el.setAttribute("body-label", "etched");
21
+ * console.log(readNameLabel(el)?.look);
22
+ * ```
23
+ */
24
+ export function readNameLabel(el) {
25
+ const look = el.getAttribute("body-label");
26
+ if (look === null || !LOOKS.includes(look))
27
+ return null;
28
+ const out = { look: look };
29
+ const strength = Number(el.getAttribute("body-label-strength"));
30
+ if (el.getAttribute("body-label-strength") !== null && Number.isFinite(strength))
31
+ out.strength = Math.max(0, Math.min(1, strength));
32
+ const repeat = el.getAttribute("body-label-repeat");
33
+ if (repeat !== null && REPEATS.includes(repeat))
34
+ out.repeat = repeat;
35
+ const latitude = Number(el.getAttribute("body-label-latitude"));
36
+ if (el.getAttribute("body-label-latitude") !== null && Number.isFinite(latitude))
37
+ out.latitude = latitude;
38
+ if (el.hasAttribute("body-label-facing") && el.getAttribute("body-label-facing") !== "off" && el.getAttribute("body-label-facing") !== "false")
39
+ out.facing = true;
40
+ const font = el.getAttribute("body-label-font");
41
+ if (font !== null && font.trim() !== "")
42
+ out.font = font.trim();
43
+ const fallback = el.getAttribute("body-label-fallback-font");
44
+ if (fallback !== null && fallback.trim() !== "")
45
+ out.fallbackFont = fallback.trim();
46
+ return out;
47
+ }
48
+ /**
49
+ * The text written for a body: its English name in capitals (the family's look), or its Japanese name as it is.
50
+ *
51
+ * @param name - The body's names, as `BODIES[id].name` holds them.
52
+ * @param lang - `en` (the default) or `ja`.
53
+ * @returns The text to write.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * import { BODIES } from "@johnmorrisdotca/wakusei-planets";
58
+ * import { nameLabelText } from "@johnmorrisdotca/wakusei-planets/painter";
59
+ *
60
+ * console.log(nameLabelText(BODIES.earth.name, "en"), nameLabelText(BODIES.earth.name, "ja"));
61
+ * ```
62
+ */
63
+ export function nameLabelText(name, lang = "en") {
64
+ return lang === "ja" ? name.ja : name.en.toUpperCase();
65
+ }
66
+ /** One string that changes whenever the label would be made differently (the text and every setting): for a host that keeps a still for each state. */
67
+ export function nameLabelKey(text, options) {
68
+ if (!options)
69
+ return "";
70
+ const o = { ...DEFAULTS, ...options };
71
+ return `${text}|${o.look}|${o.strength}|${o.repeat}|${o.latitude}|${o.facing}|${o.font}|${o.fallbackFont}|${o.size}|${o.minRadiusPx}`;
72
+ }
73
+ const DEFAULTS = { strength: 0.5, repeat: "once", latitude: 0, facing: false, font: BODY_LABEL_FONT, fallbackFont: "", size: "medium", minRadiusPx: 24 };
74
+ const hasLabelParts = (T) => {
75
+ const parts = T;
76
+ return typeof parts.CanvasTexture === "function" && typeof parts.SRGBColorSpace === "string" && typeof parts.NormalBlending === "number";
77
+ };
78
+ let warned = false;
79
+ /** The name is drawn to a canvas: without one (Node, a worker with no `OffscreenCanvas`) there is no label and nothing to draw. */
80
+ const canDraw = () => typeof document !== "undefined" || typeof OffscreenCanvas !== "undefined";
81
+ const LABEL_VERTEX = /* glsl */ `
82
+ varying vec2 vUv;
83
+ varying vec3 vN;
84
+ void main() {
85
+ vUv = uv;
86
+ vN = normalize(transpose(inverse(mat3(modelMatrix))) * normal);
87
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
88
+ }`;
89
+ // 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
90
+ const LABEL_FRAGMENT = /* glsl */ `
91
+ uniform sampler2D uMap;
92
+ uniform vec3 uLight;
93
+ uniform float uOpacity;
94
+ uniform float uAmbient;
95
+ uniform float uWrap;
96
+ varying vec2 vUv;
97
+ varying vec3 vN;
98
+ void main() {
99
+ vec4 c = texture2D(uMap, vUv);
100
+ float d = dot(normalize(vN), uLight);
101
+ float lit = uAmbient + (1.0 - uAmbient) * clamp((d + uWrap) / (1.0 + uWrap), 0.0, 1.0);
102
+ gl_FragColor = vec4(c.rgb * lit, c.a * uOpacity);
103
+ #include <colorspace_fragment>
104
+ }`;
105
+ /** 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). */
106
+ function litThree(T, emissive) {
107
+ const made = [];
108
+ class LitLabelMaterial extends T.ShaderMaterial {
109
+ constructor(parameters) {
110
+ const { map, ...rest } = parameters;
111
+ super({
112
+ ...rest,
113
+ vertexShader: LABEL_VERTEX,
114
+ fragmentShader: LABEL_FRAGMENT,
115
+ 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 } },
116
+ });
117
+ made.push(this);
118
+ }
119
+ }
120
+ return { ...T, MeshLambertMaterial: LitLabelMaterial, made };
121
+ }
122
+ const FAR_EYE = { getWorldPosition: (v) => v.set(0, 0, 1e6) };
123
+ let fontLoad;
124
+ let fontUrl;
125
+ /**
126
+ * Where Michroma is fetched from, for a page whose bundler does not carry kazoku-ui's font file along with its module (the label looks for it next to the module, `fonts/Michroma-Regular.ttf`). Call it before the
127
+ * first name is written. A page that sets `body-label-font` to a font of its own needs nothing here.
128
+ *
129
+ * @param url - The address of `Michroma-Regular.ttf`, with its `OFL.txt` beside it.
130
+ *
131
+ * @example
132
+ * ```ts no-run
133
+ * import { setBodyLabelFontUrl } from "@johnmorrisdotca/wakusei-planets/painter";
134
+ *
135
+ * setBodyLabelFontUrl("/fonts/Michroma-Regular.ttf");
136
+ * ```
137
+ */
138
+ export function setBodyLabelFontUrl(url) {
139
+ fontUrl = url;
140
+ fontLoad = undefined;
141
+ }
142
+ /** Michroma, fetched once from kazoku-ui's own copy (or `setBodyLabelFontUrl`'s), the first time a label in it is made. A fetch that fails leaves the page's sans, and is not tried again. */
143
+ const ensureFont = (font) => (font === BODY_LABEL_FONT && canDraw() ? (fontLoad ??= (fontUrl === undefined ? loadBodyLabelFont() : loadBodyLabelFont(fontUrl)).catch(() => BODY_LABEL_FONT)) : Promise.resolve());
144
+ /**
145
+ * Make a body's name label. The group is empty until the font is in (at once when it is already loaded); `onReady` is called when the name is drawn, so the host can draw its view again.
146
+ *
147
+ * @param T - The three.js module the bodies use. Without `CanvasTexture`, `SRGBColorSpace` and `NormalBlending` there is no label, and a warning once.
148
+ * @param text - The name as it is written.
149
+ * @param options - The look and the rest.
150
+ * @param emissive - The body glows (the Sun): the name is lit fully, from no direction.
151
+ * @param onReady - Called when the name is drawn, and again when a new font is in.
152
+ */
153
+ export function createNameLabel(T, text, options, emissive, onReady) {
154
+ const group = new T.Group();
155
+ group.name = "name-label";
156
+ // 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
157
+ group.rotation.y = -Math.PI / 2;
158
+ let label;
159
+ let materials = [];
160
+ let wanted = { text, options: { ...DEFAULTS, ...withoutUndefined(options) } };
161
+ let disposed = false;
162
+ let ready = false;
163
+ const light = new T.Vector3(0, 0, 1);
164
+ const able = hasLabelParts(T) && canDraw();
165
+ if (!able && !warned && canDraw()) {
166
+ warned = true;
167
+ console.warn("wakusei-planets: the three.js handed over lacks CanvasTexture, SRGBColorSpace or NormalBlending, so a name cannot be written on a body");
168
+ }
169
+ const make = () => {
170
+ if (disposed || label !== undefined || !able)
171
+ return;
172
+ const lit = litThree(T, emissive);
173
+ label = createBodyLabel(lit, { text: wanted.text, ...wanted.options, radius: 1 });
174
+ materials = lit.made;
175
+ group.add(label.object);
176
+ void label.ready.then(() => {
177
+ if (disposed)
178
+ return;
179
+ ready = true;
180
+ onReady();
181
+ });
182
+ };
183
+ void ensureFont(wanted.options.font).then(() => {
184
+ if (!disposed)
185
+ make();
186
+ });
187
+ return {
188
+ object: group,
189
+ get ready() {
190
+ return ready;
191
+ },
192
+ update(camera, radiusPx, toLight) {
193
+ if (label === undefined)
194
+ return false;
195
+ light.set(toLight[0], toLight[1], toLight[2]);
196
+ for (const m of materials) {
197
+ const u = m.uniforms;
198
+ u.uLight.value.copy(light);
199
+ u.uOpacity.value = m.opacity;
200
+ }
201
+ return label.update((camera ?? FAR_EYE), radiusPx);
202
+ },
203
+ set(nextText, next) {
204
+ wanted = { text: nextText, options: { ...DEFAULTS, ...withoutUndefined(next) } };
205
+ if (label === undefined)
206
+ return;
207
+ const fontChanged = wanted.options.font !== label.options.font;
208
+ label.set({ text: wanted.text, ...wanted.options });
209
+ if (fontChanged)
210
+ void ensureFont(wanted.options.font).then(() => {
211
+ // the shared label repaints only when a setting changed: the new font arriving after the set is told by setting the font again
212
+ if (!disposed && label !== undefined) {
213
+ label.set({ font: "" });
214
+ label.set({ font: wanted.options.font });
215
+ onReady();
216
+ }
217
+ });
218
+ },
219
+ dispose() {
220
+ disposed = true;
221
+ if (label !== undefined) {
222
+ group.remove(label.object);
223
+ label.dispose();
224
+ label = undefined;
225
+ }
226
+ materials = [];
227
+ },
228
+ };
229
+ }
230
+ function withoutUndefined(value) {
231
+ return Object.fromEntries(Object.entries(value).filter(([, v]) => v !== undefined));
232
+ }
@@ -5,7 +5,9 @@ import { type Vec3 } from "../vec.ts";
5
5
  import { type DetailStats } from "./detail.ts";
6
6
  import { type TileLevel } from "./tiles.ts";
7
7
  import { moonOffset, orientation } from "./orient.ts";
8
+ import { type NameLabelOptions } from "./name-label.ts";
8
9
  export { moonOffset, orientation };
10
+ export { nameLabelText, readNameLabel, setBodyLabelFontUrl, type NameLabelOptions } from "./name-label.ts";
9
11
  /**
10
12
  * The looks the painter draws: `realistic` (shaded from the body's real colours and features) and `painted` (a public-domain surface map, with the shaded look until it arrives).
11
13
  *
@@ -54,6 +56,25 @@ export interface PaintContext {
54
56
  maxTexture?: number;
55
57
  /** Told when the finer map tiles' levels for this body are known (`undefined` when it has none), so a view can raise its zoom range. Only called for a painter that has a tile set and a view in `PaintInfo`. */
56
58
  onLevels?(levels: readonly TileLevel[] | undefined): void;
59
+ /** The body's name written on its globe (see `PaintLabel`), or none. `setLabel` on the painting changes it later. */
60
+ label?: PaintLabel | null;
61
+ }
62
+ /**
63
+ * The name on a body the painter makes: the family's `NameLabelOptions`, with the language the name is written in (`en`, in capitals, by default) or a `text` of your own instead of the body's name.
64
+ *
65
+ * @example
66
+ * ```ts no-run
67
+ * import type { PaintLabel } from "@johnmorrisdotca/wakusei-planets/painter";
68
+ *
69
+ * const label: PaintLabel = { look: "painted", lang: "ja" };
70
+ * console.log(label.lang);
71
+ * ```
72
+ */
73
+ export interface PaintLabel extends NameLabelOptions {
74
+ /** The language of the name: `en` (capitals) or `ja`. Default `en`. */
75
+ lang?: "en" | "ja";
76
+ /** Written instead of the body's name. */
77
+ text?: string;
57
78
  }
58
79
  /**
59
80
  * The camera that draws a body and the size of its view, so the painter can tell which part of the body's surface is in view and lay finer map tiles over it. The camera's world and projection matrices must be
@@ -113,12 +134,20 @@ export interface PaintInfo {
113
134
  */
114
135
  export interface Painting {
115
136
  object: THREE.Object3D;
116
- /** True to have the caller turn the object to face the camera (the Sun, which carries a glow). */
137
+ /** True to have the caller turn the whole object to face the camera. No body asks for it now: the Sun is a globe that turns with its own spin and the view, and its glow turns itself to the camera in `update` (from `PaintInfo.view`). */
117
138
  billboard?: boolean;
118
139
  /** Call at each draw, after the object has been placed and scaled. */
119
140
  update(info: PaintInfo): void;
120
141
  /** What the window of finer map tiles on this body is doing, or `undefined` for a body with none (a glowing one, one with no painted map, or a painter with no tile set). */
121
142
  readonly tiles?: DetailStats;
143
+ /** Write the body's name on its globe, change how, or take it off (`null`). The name is drawn when the font is in, and `context.invalidate` is called then. */
144
+ setLabel(label: PaintLabel | null): void;
145
+ /** The name on the globe now: whether one is drawn (made and big enough on the screen at the last `update`), the text, and the group's turn about the pole in radians (for `facing`). */
146
+ readonly label: {
147
+ shown: boolean;
148
+ text: string;
149
+ turn: number;
150
+ } | null;
122
151
  dispose(): void;
123
152
  }
124
153
  /**
@@ -11,7 +11,9 @@ import { detailOf, lookOf } from "./look.js";
11
11
  import { seenRegion } from "./tiles.js";
12
12
  import { moonOffset, orientation } from "./orient.js";
13
13
  import { ringStrip } from "./rings.js";
14
+ import { createNameLabel, nameLabelText } from "./name-label.js";
14
15
  export { moonOffset, orientation };
16
+ export { nameLabelText, readNameLabel, setBodyLabelFontUrl } from "./name-label.js";
15
17
  /**
16
18
  * The looks the painter draws: `realistic` (shaded from the body's real colours and features) and `painted` (a public-domain surface map, with the shaded look until it arrives).
17
19
  *
@@ -216,7 +218,8 @@ function paint(T, id, context, bases) {
216
218
  m.uniforms.uRingR.value.set(ringInner, ringOuter);
217
219
  }
218
220
  }
219
- // the glow of a star: a plane through its centre that the caller turns to the camera
221
+ // the glow of a star: a plane through its centre that `update` turns to the camera, so the globe inside it keeps its own orientation
222
+ let glowMesh;
220
223
  if (look.emissive === true) {
221
224
  const glowGeometry = acquire(T, "glow", () => new T.PlaneGeometry(6, 6));
222
225
  releases.push(glowGeometry.release);
@@ -226,6 +229,7 @@ function paint(T, id, context, bases) {
226
229
  glow.renderOrder = 4;
227
230
  glow.frustumCulled = false;
228
231
  group.add(glow);
232
+ glowMesh = glow;
229
233
  }
230
234
  // the painted map: the smallest width at once, a sharper one when the body is big on the screen, back to the small one when it is not
231
235
  const widths = (look.painted?.widths ?? []).filter((w, i) => i === 0 || w <= maxWidth);
@@ -336,19 +340,58 @@ function paint(T, id, context, bases) {
336
340
  const scaleZ = axes ? axes[0] / facts.radiusKm : 1;
337
341
  const light = new T.Vector3();
338
342
  const poleVec = new T.Vector3();
343
+ // the name on the globe: a child of the mesh, so it turns with the body; made when asked, drawn once its font is in
344
+ let label;
345
+ let labelText = "";
346
+ let labelShown = false;
347
+ // what `label` reports: one object, written at each draw (it is read for every body at every frame)
348
+ const labelReport = { shown: false, text: "", turn: 0 };
349
+ const setLabel = (next) => {
350
+ if (next === null || next === undefined || gone) {
351
+ if (label !== undefined) {
352
+ mesh.remove(label.object);
353
+ label.dispose();
354
+ label = undefined;
355
+ labelShown = false;
356
+ labelReport.shown = false;
357
+ }
358
+ return;
359
+ }
360
+ const { lang, text, ...options } = next;
361
+ labelText = text ?? nameLabelText(facts.name, lang ?? "en");
362
+ labelReport.text = labelText;
363
+ if (label === undefined) {
364
+ label = createNameLabel(T, labelText, options, look.emissive === true, redraw);
365
+ mesh.add(label.object);
366
+ }
367
+ else {
368
+ label.set(labelText, options);
369
+ redraw();
370
+ }
371
+ };
372
+ if (context.label)
373
+ setLabel(context.label);
339
374
  return {
340
375
  object: group,
341
- ...(look.emissive === true ? { billboard: true } : {}),
376
+ setLabel,
377
+ get label() {
378
+ return label === undefined ? null : labelReport;
379
+ },
342
380
  get tiles() {
343
381
  return detail?.stats;
344
382
  },
345
383
  update(info) {
346
384
  light.set(info.toSun[0], info.toSun[1], info.toSun[2]);
347
385
  const scale = group.scale.x || 1;
348
- if (look.emissive !== true) {
386
+ // a star's glow faces the camera, when `update` is given the camera (`info.view`): without it the glow keeps its last turn, so a caller that used to turn the Sun's object itself passes `view` now. The group is
387
+ // never turned, so `camera.quaternion` (the camera's local turn, which is its world turn for a camera with no parent, as the views here have) is the glow's own; the globe inside it has the body's own
388
+ // pole and prime meridian like every other body
389
+ if (glowMesh !== undefined && info.view !== undefined)
390
+ glowMesh.quaternion.copy(info.view.camera.quaternion);
391
+ {
349
392
  const { pole, meridian } = info.pose ?? orientation(id, info.ms);
350
393
  const east = cross(pole, meridian);
351
- if (detail !== undefined) {
394
+ if (look.emissive !== true && detail !== undefined) {
352
395
  // a body big enough in the view, seen by a camera we were told of, is worked out for a window of finer map; any other keeps the pictures it has
353
396
  if (info.view === undefined || mesh.material !== paintedMaterial || info.radiusPx * ratio < TILES_FROM_PX)
354
397
  detail.rest();
@@ -377,9 +420,18 @@ function paint(T, id, context, bases) {
377
420
  ringMaterial.uniforms.uScale.value = scale;
378
421
  }
379
422
  keepSized(info.radiusPx);
423
+ if (label !== undefined) {
424
+ label.update(info.view?.camera, info.radiusPx, info.toSun);
425
+ const inner = label.object.children[0];
426
+ labelShown = inner !== undefined && inner.visible;
427
+ labelReport.shown = labelShown;
428
+ labelReport.text = labelText;
429
+ labelReport.turn = inner?.rotation.y ?? 0;
430
+ }
380
431
  },
381
432
  dispose() {
382
433
  gone = true;
434
+ setLabel(null);
383
435
  if (windowUniforms !== undefined) {
384
436
  windowUniforms.uDetailOn.value = 0;
385
437
  windowUniforms.uDetail.value = null;
@@ -11,7 +11,7 @@ import { type BodyMapSource } from "../door/map.ts";
11
11
  * console.log(TEXTURE_BASE);
12
12
  * ```
13
13
  */
14
- export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@0.33.0/dist/textures/";
14
+ export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@0.35.0/dist/textures/";
15
15
  /**
16
16
  * 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
17
17
  * never zooms in never fetches them. Set `texture-far-base` on an element to serve them yourself.
@@ -23,7 +23,7 @@ export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdot
23
23
  * console.log(TEXTURE_FAR_BASE);
24
24
  * ```
25
25
  */
26
- export declare const TEXTURE_FAR_BASE = "https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v0.33.0/textures/";
26
+ export declare const TEXTURE_FAR_BASE = "https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v0.35.0/textures/";
27
27
  /**
28
28
  * 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:
29
29
  * 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.
@@ -35,6 +35,8 @@ export interface BesideInput {
35
35
  yaw: number;
36
36
  /** Degrees the camera opens further off that line (a drag down the view is 60). */
37
37
  tilt: number;
38
+ /** The planet's own north pole in the scene's axes (a unit vector): the picture's up is this laid across the line of sight. The scene's +y when not given. */
39
+ north?: Vec3;
38
40
  }
39
41
  /**
40
42
  * The camera `besideMoon` works out: where it is, which way it looks and its up, its vertical field of view in degrees, how far it is from the moon, and the angle in degrees between the moon and the planet as the camera sees them.
@@ -58,7 +60,8 @@ export interface BesideCamera {
58
60
  /**
59
61
  * The camera for a view from near a moon with its planet still in view: beyond the moon on the side away from the planet and a little off the line to it, so the moon is large in the foreground and the planet is behind it,
60
62
  * at the angular size it really has from there. The camera sits on the Sun's side of that line where it can, so the moon shows a lit face. It opens off the line, from 25 degrees, until the two discs no longer touch
61
- * (with 2 degrees to spare), turns the picture so the planet is to one side of the moon, and widens the field of view until both fit the view's narrower side.
63
+ * (with 2 degrees to spare), keeps the planet's own north pole up (laid across the line of sight, so the equator and any rings stay level whatever the date), and widens the field of view until both discs fit the view.
64
+ * Where the Sun lies near the line from the planet through the moon, the camera goes round over the planet's north side a little at a time, rather than hopping to the Sun's other side from one moment to the next.
62
65
  *
63
66
  * @param input - The places and sizes, the view's shape, and the zoom, yaw and tilt.
64
67
  * @returns The camera.
@@ -13,12 +13,23 @@ import { add, cross, dot, length, RAD, scale, unit } from "../vec.js";
13
13
  export const BESIDE_RADII = 5.8;
14
14
  /** The angle off the line from the planet through the moon, in degrees, the camera first tries; it opens wider until the planet clears the moon. */
15
15
  const FIRST_ANGLE = 25;
16
+ /**
17
+ * Inside this (the sine of about 20 degrees) of the Sun lying on the line from the planet through the moon, the camera's side is pushed towards the planet's north side, more the nearer the Sun is to the line (a cosine ramp), so the
18
+ * camera goes round over the top a little at a time rather than hopping to the Sun's other side. One moment is still sharp, as any rule from the Sun's place alone must have one: a Sun about 11 degrees south of the
19
+ * moon's orbit as the moon crosses the line; the moons of Jupiter, whose Sun is always within 3 degrees of their orbits, never meet it.
20
+ */
21
+ const SIDE_BLEND = 0.35;
22
+ /** Inside this (the sine of 10 degrees) of looking along the planet's pole, the up blends towards the scene's +y laid across the line of sight: there is little north left to lay. */
23
+ const POLE_CONE = Math.sin(10 * RAD);
16
24
  const angleBetween = (a, b) => Math.acos(Math.max(-1, Math.min(1, dot(unit(a), unit(b))))) / RAD;
17
25
  const minus = (a, b) => add(a, scale(b, -1));
26
+ /** The part of `v` square to the unit vector `along`. */
27
+ const across = (v, along) => minus(v, scale(along, dot(v, along)));
18
28
  /**
19
29
  * The camera for a view from near a moon with its planet still in view: beyond the moon on the side away from the planet and a little off the line to it, so the moon is large in the foreground and the planet is behind it,
20
30
  * at the angular size it really has from there. The camera sits on the Sun's side of that line where it can, so the moon shows a lit face. It opens off the line, from 25 degrees, until the two discs no longer touch
21
- * (with 2 degrees to spare), turns the picture so the planet is to one side of the moon, and widens the field of view until both fit the view's narrower side.
31
+ * (with 2 degrees to spare), keeps the planet's own north pole up (laid across the line of sight, so the equator and any rings stay level whatever the date), and widens the field of view until both discs fit the view.
32
+ * Where the Sun lies near the line from the planet through the moon, the camera goes round over the planet's north side a little at a time, rather than hopping to the Sun's other side from one moment to the next.
22
33
  *
23
34
  * @param input - The places and sizes, the view's shape, and the zoom, yaw and tilt.
24
35
  * @returns The camera.
@@ -35,7 +46,16 @@ export function besideMoon(input) {
35
46
  const { moon, moonRadius, host, hostRadius } = input;
36
47
  const away = unit(minus(moon, host));
37
48
  const toSun = unit(minus(input.sun, moon));
38
- let side = minus(toSun, scale(away, dot(toSun, away)));
49
+ const north = unit(input.north ?? [0, 1, 0]);
50
+ // the side the camera opens to: the Sun's, so the moon shows a lit face; as the moon crosses the line from the Sun through its planet that side swings round, the faster the nearer the Sun is to the line,
51
+ // so over the last degrees it is pushed towards the planet's north side and the camera goes round over the top a little at a time (the push is 0 at the edge of the band and 1 on the line)
52
+ let side = across(toSun, away);
53
+ const over = (1 - Math.cos((Math.PI * Math.max(0, SIDE_BLEND - length(side))) / SIDE_BLEND)) / 2;
54
+ const northSide = across(north, away);
55
+ if (over > 0 && length(northSide) > 1e-3)
56
+ side = add(side, scale(unit(northSide), over));
57
+ if (length(side) < 1e-3)
58
+ side = cross(away, north);
39
59
  if (length(side) < 1e-3)
40
60
  side = cross(away, [0, 1, 0]);
41
61
  if (length(side) < 1e-3)
@@ -66,11 +86,32 @@ export function besideMoon(input) {
66
86
  // look between the two, and turn the picture so the planet is to the side of the moon, not above or below it
67
87
  const forward = unit(add(toMoon, toHost));
68
88
  const shift = minus(toHost, toMoon);
69
- const across = unit(minus(shift, scale(forward, dot(shift, forward))));
70
- const up = unit(cross(across, forward));
89
+ // north is up, always: the planet's own pole laid across the line of sight, so the picture is never rolled by where the Sun or the moon happens to be, and the planet's equator and rings stay level; a regular
90
+ // moon keeps the camera near the planet's equator, so the pole stays near square to the line of sight. A camera looking nearly along the pole (an odd inclined moon) has little north to lay, and blends to
91
+ // the scene's +y laid across; looking along both, it takes the side the planet is on
92
+ let up = across(north, forward);
93
+ const poleward = Math.max(0, POLE_CONE - length(up)) / POLE_CONE;
94
+ if (poleward > 0) {
95
+ // the +y part is laid the way the pole's part already leans (-y when they would oppose), so the two never cancel and up never collapses inside the cone
96
+ const y = across([0, 1, 0], forward);
97
+ if (length(y) > 1e-6)
98
+ up = add(up, scale(unit(y), dot(up, y) < 0 ? -poleward : poleward));
99
+ }
100
+ if (length(up) < 1e-6)
101
+ up = cross(unit(across(shift, forward)), forward);
102
+ up = unit(up);
71
103
  // both discs fit: the half-angle from the middle to the far edge of each, across and up
72
- const reach = Math.max(angleBetween(forward, toMoon) + moonHalf(position), angleBetween(forward, toHost) + hostHalf(position)) + 3;
73
- const half = Math.max(Math.tan(reach * RAD) / Math.min(1.6, Math.max(0.3, input.aspect)), Math.tan((moonHalf(position) + 3) * RAD));
104
+ // both discs fit, whichever way they lie now that north is up: the view must reach each disc's far edge across (over the aspect) and up, with a little room
105
+ const right = unit(cross(forward, up));
106
+ const need = (direction, halfAngle) => {
107
+ const z = Math.max(1e-9, dot(direction, forward));
108
+ const marginTan = Math.tan((halfAngle + 3) * RAD);
109
+ return { across: Math.abs(dot(direction, right)) / z + marginTan, up: Math.abs(dot(direction, up)) / z + marginTan };
110
+ };
111
+ const moonNeed = need(toMoon, moonHalf(position));
112
+ const hostNeed = need(toHost, hostHalf(position));
113
+ const aspect = Math.min(1.6, Math.max(0.3, input.aspect));
114
+ const half = Math.max(moonNeed.up, hostNeed.up, moonNeed.across / aspect, hostNeed.across / aspect, Math.tan((moonHalf(position) + 3) * RAD));
74
115
  const fov = Math.min(110, Math.max(35, 2 * Math.atan(half) / RAD));
75
116
  return { position, forward, up, fov, distance, separation: spot.separation };
76
117
  }