@johnmorrisdotca/wakusei-planets 0.40.0 → 0.42.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 +18 -0
- package/NOTICE.md +1 -1
- package/README.md +3 -3
- package/dist/element.d.ts +1 -1
- package/dist/element.js +1 -1
- package/dist/scene/body.d.ts +1 -0
- package/dist/scene/body.js +2 -2
- package/dist/scene/glsl.d.ts +2 -2
- package/dist/scene/glsl.js +4 -2
- package/dist/scene/name-label.d.ts +56 -3
- package/dist/scene/name-label.js +72 -7
- package/dist/scene/painter.d.ts +2 -1
- package/dist/scene/painter.js +5 -3
- package/dist/scene/textures.d.ts +2 -2
- package/dist/space/element.d.ts +15 -1
- package/dist/space/element.js +96 -18
- package/dist/space/index.d.ts +3 -3
- package/dist/space/index.js +3 -3
- package/dist/space/labels.d.ts +32 -0
- package/dist/space/labels.js +39 -0
- package/dist/space/scale.d.ts +27 -0
- package/dist/space/scale.js +49 -0
- package/dist/space/scene.d.ts +31 -1
- package/dist/space/scene.js +38 -3
- package/dist/space/travel.d.ts +55 -4
- package/dist/space/travel.js +105 -16
- package/dist/textures/pluto-1024.webp +0 -0
- package/dist/textures/pluto-512.webp +0 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/space/element.js
CHANGED
|
@@ -6,7 +6,7 @@ import { arrowCount } from "./arrows.js";
|
|
|
6
6
|
import { createGameClock } from "./clock.js";
|
|
7
7
|
import { bodyKindOf, findBody, hopFrom, hostOf, HOP_ORDER, systemOf } from "./bodies.js";
|
|
8
8
|
import { sightChanged, sightOf } from "./sight.js";
|
|
9
|
-
import { chooseLabels } from "./labels.js";
|
|
9
|
+
import { chooseLabels, nameSpot } from "./labels.js";
|
|
10
10
|
import { coverArrows } from "./covered.js";
|
|
11
11
|
import { createPainter } from "../scene/painter.js";
|
|
12
12
|
import { NAME_LABEL_ATTRIBUTES, readNameLabel } from "../scene/name-label.js";
|
|
@@ -17,7 +17,7 @@ import { setThreeLoader, takeRenderer } from "../scene/shared.js";
|
|
|
17
17
|
import { texturePaths, tilesBase } from "../scene/textures.js";
|
|
18
18
|
import { AU_IN_EARTH_RADII, EARTH_RADIUS_KM, frameAt, SPACE_DWARFS, SPACE_MINORS, SPACE_PLANETS } from "./frame.js";
|
|
19
19
|
import { moonOffset, orientation } from "../scene/orient.js";
|
|
20
|
-
import { moonDistance, placeBodies, radiusIn } from "./scale.js";
|
|
20
|
+
import { moonDistance, placeBodies, radiusIn, readMoonSize } from "./scale.js";
|
|
21
21
|
import { groundDirection } from "./aim.js";
|
|
22
22
|
import { besideMoon } from "./beside.js";
|
|
23
23
|
import { SUN_REGIONS } from "./regions.js";
|
|
@@ -26,8 +26,8 @@ import { findPlace, PLACE_BODIES } from "../places.js";
|
|
|
26
26
|
import { placeMarks, pointUnder, readPlaceLayers, spotView } from "../place-marks.js";
|
|
27
27
|
import { createPlaceLayer, onPlacesLoader, placesLoader } from "../scene/place-layer.js";
|
|
28
28
|
import { createEarthPlaceLayer, EARTH_PLACE_MARKS, EARTH_PLACES_FROM_PX, earthPlacesLayout, onEarthPlacesLayout, readEarthPlaceLook } from "../scene/earth-places.js";
|
|
29
|
-
import { cross, dot } from "../vec.js";
|
|
30
|
-
import { createSpaceItem, FIT_DISTANCE, newSpaceModel, SPACE_BODIES } from "./scene.js";
|
|
29
|
+
import { cross, dot, length, sub, unit } from "../vec.js";
|
|
30
|
+
import { createSpaceItem, FIT_DISTANCE, moonScaleFor, newSpaceModel, SPACE_BODIES } from "./scene.js";
|
|
31
31
|
import { paintLengthOf, paintSwathOf } from "../paint/trail.js";
|
|
32
32
|
export { setPlacesLoader } from "../scene/place-layer.js";
|
|
33
33
|
export { EARTH_PLACE_LOOKS, EARTH_PLACE_MARKS } from "../scene/earth-places.js";
|
|
@@ -105,7 +105,7 @@ const readBody = (value) => {
|
|
|
105
105
|
* 1.05 radii from the surface (`FIT_DISTANCE` over the zoom), so past a zoom of about 3.9 nothing moves; 3.6 is where the finest map tiles of the Earth, Mars and the Moon (16384 pixels round) run out of detail too, so it is the same ceiling for both.
|
|
106
106
|
*/
|
|
107
107
|
const CARRIED_LIMITS = { zoomMin: 1e-6, zoomMax: 3.6, tiltMax: 90 };
|
|
108
|
-
const STYLE = `<style>:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden}:host([immersive]){aspect-ratio:auto;width:100%;height:100%;touch-action:none!important;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent}#stage,#labels{position:absolute;inset:0}#labels{pointer-events:none;overflow:hidden}.sp-label{position:absolute;left:0;top:0;margin:0;padding:0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-label:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label::before{content:"";display:inline-block;width:5px;height:5px;margin:0 5px 1px -2px;border-radius:50%;background:#fff}.sp-label[hidden]{display:none}.sp-arrow{position:absolute;left:0;top:0;margin:0;padding:0 4px 0 0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.8;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:auto;cursor:pointer}.sp-arrow::before{content:"";display:inline-block;width:0;height:0;margin:0 5px 1px 0;border:5px solid transparent;border-left:7px solid #fff;transform:rotate(var(--turn,0deg));transform-origin:30% 50%}.sp-arrow[hidden]{display:none}.sp-arrow:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label[data-far]:not([data-carried]),.sp-ring[data-far]:not([data-carried]){opacity:var(--wakusei-far-opacity,.5)}.sp-arrow[data-far]{opacity:calc(.8*var(--wakusei-far-opacity,.5))}.sp-label,.sp-ring,.sp-arrow{transition:opacity .35s ease}.sp-label[data-carried],.sp-ring[data-carried]{opacity:0;pointer-events:none}@media (prefers-reduced-motion:reduce){.sp-label,.sp-ring,.sp-arrow{transition:none}}.sp-ring{position:absolute;left:0;top:0;width:16px;height:16px;margin:-8px 0 0 -8px;box-sizing:border-box;border:1.5px solid rgba(255,255,255,.85);border-radius:50%;box-shadow:0 0 3px #000;pointer-events:none;will-change:transform}.sp-ring[hidden]{display:none}.sp-scale{position:absolute;left:10px;top:8px;margin:0;padding:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.9;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}.sp-region{position:absolute;left:10px;bottom:8px;margin:0;padding:0;font:600 15px/20px system-ui,-apple-system,sans-serif;color:#fff;opacity:.95;text-shadow:0 0 4px #000,0 0 4px #000;pointer-events:none;transition:opacity .35s}.sp-region[hidden]{display:block;opacity:0}@media (prefers-reduced-motion:reduce){.sp-region{transition:none}}.sp-note{position:absolute;left:10px;right:10px;top:28px;max-width:44em;margin:0;padding:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.92;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}.sp-note[hidden],.sp-oort[hidden]{display:none}.sp-oort{position:absolute;left:0;top:0;margin:0;padding:0;font:italic 12px/16px system-ui,-apple-system,sans-serif;color:#aeb8e6;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}</style><div id="stage"></div><div id="labels"></div><p class="sp-scale" part="scale" role="status"></p><p class="sp-region" id="region" part="region" role="status" hidden></p><p class="sp-note" part="note" role="status" hidden></p><p class="sp-oort" part="oort" hidden></p>`;
|
|
108
|
+
const STYLE = `<style>:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden}:host([immersive]){aspect-ratio:auto;width:100%;height:100%;touch-action:none!important;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent}#stage,#labels{position:absolute;inset:0}#labels{pointer-events:none;overflow:hidden}.sp-label{position:absolute;left:0;top:0;margin:0;padding:0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-label:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label::before{content:"";display:inline-block;width:5px;height:5px;margin:0 5px 1px -2px;border-radius:50%;background:#fff}.sp-label[data-flip]{display:flex;flex-direction:row-reverse}.sp-label[data-flip]::before{margin:0 -2px 1px 5px}.sp-label[hidden]{display:none}.sp-arrow{position:absolute;left:0;top:0;margin:0;padding:0 4px 0 0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.8;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:auto;cursor:pointer}.sp-arrow::before{content:"";display:inline-block;width:0;height:0;margin:0 5px 1px 0;border:5px solid transparent;border-left:7px solid #fff;transform:rotate(var(--turn,0deg));transform-origin:30% 50%}.sp-arrow[hidden]{display:none}.sp-arrow:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label[data-far]:not([data-carried]),.sp-ring[data-far]:not([data-carried]){opacity:var(--wakusei-far-opacity,.5)}.sp-arrow[data-far]{opacity:calc(.8*var(--wakusei-far-opacity,.5))}.sp-label,.sp-ring,.sp-arrow{transition:opacity .35s ease}.sp-label[data-carried],.sp-ring[data-carried]{opacity:0;pointer-events:none}@media (prefers-reduced-motion:reduce){.sp-label,.sp-ring,.sp-arrow{transition:none}}.sp-ring{position:absolute;left:0;top:0;width:16px;height:16px;margin:-8px 0 0 -8px;box-sizing:border-box;border:1.5px solid rgba(255,255,255,.85);border-radius:50%;box-shadow:0 0 3px #000;pointer-events:none;will-change:transform}.sp-ring[hidden]{display:none}.sp-scale{position:absolute;left:10px;top:8px;margin:0;padding:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.9;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}.sp-region{position:absolute;left:10px;bottom:8px;margin:0;padding:0;font:600 15px/20px system-ui,-apple-system,sans-serif;color:#fff;opacity:.95;text-shadow:0 0 4px #000,0 0 4px #000;pointer-events:none;transition:opacity .35s}.sp-region[hidden]{display:block;opacity:0}@media (prefers-reduced-motion:reduce){.sp-region{transition:none}}.sp-note{position:absolute;left:10px;right:10px;top:28px;max-width:44em;margin:0;padding:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.92;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}.sp-note[hidden],.sp-oort[hidden]{display:none}.sp-oort{position:absolute;left:0;top:0;margin:0;padding:0;font:italic 12px/16px system-ui,-apple-system,sans-serif;color:#aeb8e6;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}</style><div id="stage"></div><div id="labels"></div><p class="sp-scale" part="scale" role="status"></p><p class="sp-region" id="region" part="region" role="status" hidden></p><p class="sp-note" part="note" role="status" hidden></p><p class="sp-oort" part="oort" hidden></p>`;
|
|
109
109
|
const orbiterLines = (value) => (value === "chosen" || value === "none" ? value : "all");
|
|
110
110
|
/**
|
|
111
111
|
* The `<wakusei-space>` custom element: the Earth, the Moon, the Sun and the planets where they are at a date and time, drawn with three.js through the shared renderer. It takes `center`
|
|
@@ -140,7 +140,7 @@ const orbiterLines = (value) => (value === "chosen" || value === "none" ? value
|
|
|
140
140
|
* ```
|
|
141
141
|
*/
|
|
142
142
|
export class WakuseiSpace extends HTMLElement {
|
|
143
|
-
static observedAttributes = ["center", "time", "speed", "scale", "labels", "labels-always", "covered", "roadster", "orbiters", "orbiter", "orbiter-lines", "orbiter-track", "orbits", "help", "look", "light", "lang", "data", "arrows", "help-through", "places", "earth-places", "earth-places-look", "all-moons", "far-opacity", "transition", "pace", "belts", ...NAME_LABEL_ATTRIBUTES];
|
|
143
|
+
static observedAttributes = ["center", "time", "speed", "scale", "labels", "labels-always", "covered", "roadster", "orbiters", "orbiter", "orbiter-lines", "orbiter-track", "orbits", "help", "look", "light", "lang", "data", "arrows", "help-through", "places", "earth-places", "earth-places-look", "all-moons", "far-opacity", "transition", "pace", "belts", "moon-size", ...NAME_LABEL_ATTRIBUTES];
|
|
144
144
|
#model = newSpaceModel();
|
|
145
145
|
#allMoons = false;
|
|
146
146
|
#catalogue;
|
|
@@ -204,6 +204,7 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
204
204
|
this.#clock = createGameClock(readTime(this.getAttribute("time")), this.#readSpeed());
|
|
205
205
|
this.#model.time = this.#clock.time;
|
|
206
206
|
this.#model.mode = this.getAttribute("scale") === "compressed" ? "compressed" : "true";
|
|
207
|
+
this.#model.moonSize = readMoonSize(this.getAttribute("moon-size") ?? 2);
|
|
207
208
|
this.#model.labels = this.getAttribute("labels") !== "off";
|
|
208
209
|
this.#labelsAlways = this.hasAttribute("labels-always") && this.getAttribute("labels-always") !== "off";
|
|
209
210
|
this.#covered = this.getAttribute("covered") === "arrow" ? "arrow" : "name";
|
|
@@ -297,7 +298,7 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
297
298
|
this.addEventListener("pointerleave", this.#leave);
|
|
298
299
|
// before the shared hands (which hear it after this): a plain wheel in an immersive view zooms
|
|
299
300
|
this.addEventListener("wheel", this.#wheel, { capture: true, passive: false });
|
|
300
|
-
this.#hands = carryControls(this, { limits: CARRIED_LIMITS, onChange: (view, info) => this.setView(view, info.final) });
|
|
301
|
+
this.#hands = carryControls(this, { limits: CARRIED_LIMITS, onChange: (view, info) => this.setView(view, info.final, info.reason) });
|
|
301
302
|
this.#markHeard = onPlacesLoader(() => {
|
|
302
303
|
this.#markList = undefined;
|
|
303
304
|
this.#markSurface();
|
|
@@ -351,6 +352,8 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
351
352
|
this.speed = this.#readSpeed();
|
|
352
353
|
else if (name === "scale")
|
|
353
354
|
this.scale = value === "compressed" ? "compressed" : "true";
|
|
355
|
+
else if (name === "moon-size")
|
|
356
|
+
this.moonSize = readMoonSize(value);
|
|
354
357
|
else if (name === "labels")
|
|
355
358
|
this.labels = value !== "off";
|
|
356
359
|
else if (name === "labels-always")
|
|
@@ -701,6 +704,16 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
701
704
|
this.#nameScale();
|
|
702
705
|
this.#gate?.request();
|
|
703
706
|
}
|
|
707
|
+
/**
|
|
708
|
+
* How many times larger than life to draw moons in the squeezed scale (`moon-size`; 2 by default, from 1 to 8). 1 is the real size. Ignored at true distances. A moon is never drawn larger than a quarter of its planet, into the planet or its rings, or across to the next moon's orbit: every moon of one planet is reduced by the same factor, so they keep their order of size, and `stats.moonSize` says the factor used.
|
|
709
|
+
*/
|
|
710
|
+
get moonSize() {
|
|
711
|
+
return this.#model.moonSize;
|
|
712
|
+
}
|
|
713
|
+
set moonSize(value) {
|
|
714
|
+
this.#model.moonSize = readMoonSize(value);
|
|
715
|
+
this.#gate?.request();
|
|
716
|
+
}
|
|
704
717
|
/** The words naming the scale on the view, for a page in another language (`{ true: "距離はそのまま" }`). A scale left out keeps its words in the element's `lang`. */
|
|
705
718
|
get scaleNames() {
|
|
706
719
|
return { ...this.#scaleNames };
|
|
@@ -1036,7 +1049,7 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
1036
1049
|
* @param view - The controls' yaw and tilt in degrees and zoom.
|
|
1037
1050
|
* @param final - False for the frames of a turn that is still going on (Auto-turn, a drag); true when it has settled.
|
|
1038
1051
|
*/
|
|
1039
|
-
setView(view, final = true) {
|
|
1052
|
+
setView(view, final = true, reason) {
|
|
1040
1053
|
const now = this.#model.view;
|
|
1041
1054
|
if (this.#model.region !== null && view.zoom !== 1) {
|
|
1042
1055
|
// at a stage out from the Sun a zoom gesture is a step: out to the next stage, in to the one before (or the Sun); one gesture, one step, and the controls go back to holding zoom 1 (the element's own
|
|
@@ -1058,6 +1071,16 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
1058
1071
|
const [roll, panX, panY] = [view.roll ?? 0, view.panX ?? 0, view.panY ?? 0];
|
|
1059
1072
|
if (view.yaw === now.yaw && view.tilt === now.tilt && view.zoom === now.zoom && roll === now.roll && panX === now.panX && panY === now.panY)
|
|
1060
1073
|
return;
|
|
1074
|
+
// a double click jumps the zoom to 1 or to 2: stand so a companion is in the picture. A drag, a wheel step or the side just chosen does not.
|
|
1075
|
+
if (!this.#siding && reason === "zoom" && (view.zoom === 1 || view.zoom === 2) && Math.abs(view.zoom - now.zoom) > 0.4 && this.#model.pose.valid) {
|
|
1076
|
+
const side = this.#faceApproach(this.#model.focus);
|
|
1077
|
+
if (side) {
|
|
1078
|
+
this.#siding = true;
|
|
1079
|
+
this.#hands?.controller.set({ ...side, zoom: view.zoom, roll, panX: 0, panY: 0 }, true, "set");
|
|
1080
|
+
this.#siding = false;
|
|
1081
|
+
return;
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1061
1084
|
this.#model.view = { yaw: view.yaw, tilt: view.tilt, zoom: view.zoom, roll, panX, panY };
|
|
1062
1085
|
this.dispatchEvent(new CustomEvent("wakusei-view", { detail: { yaw: view.yaw, tilt: view.tilt, zoom: view.zoom, roll, panX, panY } }));
|
|
1063
1086
|
const drawn = this.#model.drawnView;
|
|
@@ -1113,6 +1136,7 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
1113
1136
|
return false;
|
|
1114
1137
|
const model = this.#model;
|
|
1115
1138
|
const leaving = this.#leaving();
|
|
1139
|
+
this.#arrivedFrom = leaving;
|
|
1116
1140
|
const kind = this.#moveKind(options, id);
|
|
1117
1141
|
if (model.ride !== null)
|
|
1118
1142
|
this.ride(null, { smooth: false });
|
|
@@ -1123,7 +1147,10 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
1123
1147
|
this.#model.focus = id;
|
|
1124
1148
|
const zoom = options.zoom ?? 1;
|
|
1125
1149
|
// the side the camera comes from, as the controls' yaw and tilt: the element's own hands are set to it here, and a bar bound to the element (which holds the view's state) hears it in the event with the zoom
|
|
1126
|
-
|
|
1150
|
+
// a straight move (`direct`, `look-back`) keeps its destination in the picture all the way, and is not turned to a companion's side: that could take the destination out of the picture. A turning move may be, and its plan
|
|
1151
|
+
// works round the planet in a way that never leaves the picture empty (`travelPlan`).
|
|
1152
|
+
const swing = kind === "cut" || kind === "turn-travel";
|
|
1153
|
+
const side = this.#faceApproach(id, swing);
|
|
1127
1154
|
if (!this.hasAttribute("data-kazoku-bar"))
|
|
1128
1155
|
this.#hands?.controller.set(side ? { ...side, zoom } : { zoom }, true, "jump");
|
|
1129
1156
|
this.#schedule();
|
|
@@ -1184,19 +1211,61 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
1184
1211
|
const d = Math.hypot(real[0], real[1], real[2]);
|
|
1185
1212
|
const k = (d === 0 ? 1 : moonDistance(mode, host, d) / d) * radiusIn(host, mode);
|
|
1186
1213
|
const centre = pos[host];
|
|
1187
|
-
return { at: [centre[0] + real[0] * k, centre[1] + real[1] * k, centre[2] + real[2] * k], radius: Math.max(1e-6, (BODIES[id].radiusKm / BODIES[host].radiusKm) * radiusIn(host, mode)) };
|
|
1214
|
+
return { at: [centre[0] + real[0] * k, centre[1] + real[1] * k, centre[2] + real[2] * k], radius: Math.max(1e-6, (BODIES[id].radiusKm / BODIES[host].radiusKm) * radiusIn(host, mode) * moonScaleFor(mode, host, this.#model.moonSize, this.#model.time).factor) };
|
|
1215
|
+
}
|
|
1216
|
+
#siding = false;
|
|
1217
|
+
/** The body the camera was at when the latest arrival was chosen, so that body can stay in the picture. */
|
|
1218
|
+
#arrivedFrom = null;
|
|
1219
|
+
/** Moons or the planet first, then the body left or the planet nearest that way, then the Sun. */
|
|
1220
|
+
#companions(id) {
|
|
1221
|
+
const out = [];
|
|
1222
|
+
const seen = new Set();
|
|
1223
|
+
const add = (body, rank) => {
|
|
1224
|
+
if (body === id || seen.has(body))
|
|
1225
|
+
return;
|
|
1226
|
+
seen.add(body);
|
|
1227
|
+
out.push({ id: body, at: this.#site(body).at, rank });
|
|
1228
|
+
};
|
|
1229
|
+
const host = hostOf(id);
|
|
1230
|
+
if (host !== undefined)
|
|
1231
|
+
add(host, 1);
|
|
1232
|
+
for (const moon of MOONS_OF[id] ?? [])
|
|
1233
|
+
add(moon, 1);
|
|
1234
|
+
if (this.#arrivedFrom !== null)
|
|
1235
|
+
add(this.#arrivedFrom, 2);
|
|
1236
|
+
const here = this.#site(id).at;
|
|
1237
|
+
const from = sub(this.#model.camera.position, here);
|
|
1238
|
+
const approach = length(from) < 1e-9 ? [0, 0, 1] : unit(from);
|
|
1239
|
+
let nearest = null;
|
|
1240
|
+
for (const planet of ["mercury", "venus", "earth", "mars", "jupiter", "saturn", "uranus", "neptune"]) {
|
|
1241
|
+
if (planet === id)
|
|
1242
|
+
continue;
|
|
1243
|
+
const away = sub(this.#site(planet).at, here);
|
|
1244
|
+
if (length(away) < 1e-9)
|
|
1245
|
+
continue;
|
|
1246
|
+
const score = dot(unit(away), approach);
|
|
1247
|
+
if (score > 0.15 && (nearest === null || score > nearest.score))
|
|
1248
|
+
nearest = { id: planet, score };
|
|
1249
|
+
}
|
|
1250
|
+
if (nearest !== null)
|
|
1251
|
+
add(nearest.id, 2);
|
|
1252
|
+
if (id !== "sun")
|
|
1253
|
+
add("sun", 3);
|
|
1254
|
+
return out;
|
|
1188
1255
|
}
|
|
1189
1256
|
/**
|
|
1190
|
-
* The controls' yaw and tilt that look at a body from the side the camera comes from
|
|
1191
|
-
*
|
|
1257
|
+
* The controls' yaw and tilt that look at a body from the side the camera comes from, swung so a companion is in the picture and the body stays at least half lit; null when the camera has not drawn yet.
|
|
1258
|
+
* The reader's own later turn is not touched: this runs for an arrival and for a double click, not for a drag.
|
|
1192
1259
|
*/
|
|
1193
|
-
#faceApproach(id) {
|
|
1260
|
+
#faceApproach(id, swing = true) {
|
|
1194
1261
|
const model = this.#model;
|
|
1195
1262
|
if (!model.pose.valid)
|
|
1196
1263
|
return null;
|
|
1197
1264
|
const body = this.#site(id);
|
|
1198
1265
|
const sun = id === "sun" ? undefined : this.#site("sun").at;
|
|
1199
|
-
const
|
|
1266
|
+
const aspect = this.clientWidth > 0 && this.clientHeight > 0 ? this.clientWidth / this.clientHeight : 16 / 9;
|
|
1267
|
+
const wanted = travelArrival({ body: body.at, radius: body.radius, from: model.camera.position, sun, aspect, companions: swing ? this.#companions(id) : [] });
|
|
1268
|
+
model.companion = wanted.companion;
|
|
1200
1269
|
const side = [wanted.position[0] - body.at[0], wanted.position[1] - body.at[1], wanted.position[2] - body.at[2]];
|
|
1201
1270
|
const anchor = model.anchor ?? model.time;
|
|
1202
1271
|
// the scene aims from the ground direction of (lon - yaw, lat - tilt) at the anchor moment: search the pair that lies along the wanted side, coarse then fine
|
|
@@ -1629,6 +1698,8 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
1629
1698
|
bodyLabels: { count: this.#model.labelsDrawn.count, focus: this.#model.labelsDrawn.focus === null ? null : { ...this.#model.labelsDrawn.focus } },
|
|
1630
1699
|
orbiters: { count: this.#model.orbitersDrawn.count, status: { ...this.#model.orbitersDrawn.status }, dim: [...this.#model.orbitersDrawn.dim], lines: this.#model.orbitersDrawn.lines, track: this.#model.orbitersDrawn.track },
|
|
1631
1700
|
roadster: { shown: this.#model.roadsterDrawn.shown, position: this.#model.roadsterDrawn.position === null ? null : [...this.#model.roadsterDrawn.position], radiusPx: this.#model.roadsterDrawn.radiusPx },
|
|
1701
|
+
companion: this.#model.companion,
|
|
1702
|
+
moonSize: { asked: this.#model.moonSize, factor: this.#model.moonDrawn.factor, clamped: this.#model.moonDrawn.clamped },
|
|
1632
1703
|
};
|
|
1633
1704
|
}
|
|
1634
1705
|
// --- the game clock ----------------------------------------------------------------------------------------------------------------------------
|
|
@@ -1687,6 +1758,7 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
1687
1758
|
return;
|
|
1688
1759
|
const wanted = [];
|
|
1689
1760
|
const spots = new Map();
|
|
1761
|
+
const frame = { width: box.clientWidth, height: box.clientHeight };
|
|
1690
1762
|
const ids = [...new Set([...SPACE_BODIES, ...this.#pool.keys(), ...Object.keys(places)])];
|
|
1691
1763
|
for (const id of ids) {
|
|
1692
1764
|
let label = this.#pool.get(id);
|
|
@@ -1714,19 +1786,23 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
1714
1786
|
}
|
|
1715
1787
|
if (!at)
|
|
1716
1788
|
continue;
|
|
1717
|
-
const
|
|
1718
|
-
|
|
1789
|
+
const width = this.#widthOf(label);
|
|
1790
|
+
// beside the dot, on the side that stays inside the view
|
|
1791
|
+
const { x, y, flipped } = nameSpot(at, { width, height: 16 }, frame);
|
|
1719
1792
|
// a body that carries its drawn name gives its floating name up (it fades, and leaves its place to the others) unless the page keeps both; a body behind another gives it up for the arrow
|
|
1720
1793
|
const carried = at.named === true && !this.#labelsAlways;
|
|
1721
1794
|
const covered = at.behind !== undefined && this.#covered === "arrow";
|
|
1722
1795
|
if (covered)
|
|
1723
1796
|
continue;
|
|
1724
|
-
spots.set(id, { x, y, small: at.r < RING_BELOW_PX, carried });
|
|
1797
|
+
spots.set(id, { x, y, small: at.r < RING_BELOW_PX, carried, flipped });
|
|
1725
1798
|
if (!carried)
|
|
1726
|
-
wanted.push({ id, x, y, width
|
|
1799
|
+
wanted.push({ id, x, y, width, height: 16, rank: this.#rank(id), size: at.r });
|
|
1727
1800
|
}
|
|
1728
1801
|
// no two names overlap: a moon gives way to its planet and a planet to the Sun
|
|
1729
1802
|
const shown = chooseLabels(wanted);
|
|
1803
|
+
const companion = this.#model.companion;
|
|
1804
|
+
if (companion !== null && spots.has(companion))
|
|
1805
|
+
shown.add(companion);
|
|
1730
1806
|
this.#nameBoxes = wanted.filter((one) => shown.has(one.id));
|
|
1731
1807
|
for (const id of ids) {
|
|
1732
1808
|
const label = this.#pool.get(id);
|
|
@@ -1756,6 +1832,8 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
1756
1832
|
label.setAttribute("aria-hidden", String(spot.carried));
|
|
1757
1833
|
label.tabIndex = spot.carried ? -1 : 0;
|
|
1758
1834
|
}
|
|
1835
|
+
if (label.hasAttribute("data-flip") !== spot.flipped)
|
|
1836
|
+
label.toggleAttribute("data-flip", spot.flipped);
|
|
1759
1837
|
label.style.transform = `translate(${spot.x}px,${spot.y}px)`;
|
|
1760
1838
|
// a body too small to see is marked: a ring round the place it is, as well as its name
|
|
1761
1839
|
if (ring.hidden === spot.small)
|
package/dist/space/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, eclipticToScene, frameAt, moonOrbit, planetOrbit, SPACE_DWARFS, SPACE_MINORS, SPACE_PLANETS, type SpaceDwarf, type SpaceFrame, type SpaceMinor, type SpacePlanet, type SpaceVec3 } from "./frame.ts";
|
|
2
|
-
export { compress, MOON_COMPRESSED, moonDistance, orbitLine, placeAround, placeBodies, placeMoon, placeSun, radiusIn, SUN_COMPRESSED, truePosition, type ScaleMode } from "./scale.ts";
|
|
2
|
+
export { compress, MOON_COMPRESSED, moonDistance, moonSizeFactor, orbitLine, placeAround, placeBodies, placeMoon, placeSun, radiusIn, SUN_COMPRESSED, truePosition, type ScaleMode } from "./scale.ts";
|
|
3
3
|
export { groundDirection } from "./aim.ts";
|
|
4
4
|
export { RIDE_FOV, ridePose, type RideInput, type RideLook, type RidePose } from "./ride.ts";
|
|
5
|
-
export { chooseLabels, LABEL_GAP, type LabelBox } from "./labels.ts";
|
|
5
|
+
export { chooseLabels, LABEL_GAP, nameSpot, type LabelBox } from "./labels.ts";
|
|
6
6
|
export { bodyKindOf, findBody, HOP_ORDER, hopFrom, hostOf, systemOf, type SpaceKind } from "./bodies.ts";
|
|
7
7
|
export { besideMoon, BESIDE_RADII, type BesideCamera, type BesideInput } from "./beside.ts";
|
|
8
8
|
export { ARROWS_PER_ORBIT, arrowCount, arrowSites, MAX_ARROWS_PER_ORBIT, chevron, spinArrow, type OrbitArrow } from "./arrows.ts";
|
|
9
9
|
export { spinAxis, type SpinAxis } from "./spin.ts";
|
|
10
10
|
export { COVER_ARROW_GAP, COVER_MIN_PX, coverArrows, coveredBy, type CoverArrow, type CoverEntry } from "./covered.ts";
|
|
11
|
-
export { TRAVEL_CLEARANCE, travelArrival, travelPlan, travelPose, type TravelBody, type TravelInput, type TravelKind, type TravelPlan, type TravelSample, type TravelSight, type TravelView } from "./travel.ts";
|
|
11
|
+
export { TRAVEL_CLEARANCE, arrivalSide, travelArrival, travelPlan, travelPose, type ArrivalCompanion, type TravelBody, type TravelInput, type TravelKind, type TravelPlan, type TravelSample, type TravelSight, type TravelView } from "./travel.ts";
|
|
12
12
|
export { regionOrbits, regionView, SUN_REGIONS, type SunRegion } from "./regions.ts";
|
|
13
13
|
export { SIGHT_STEP_PX, sightChanged, sightOf, type Sight, type SightEdge, type SightInput } from "./sight.ts";
|
package/dist/space/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// The space view's pure parts: where the bodies are (this package's own models), the two scales and, for riding along, where a camera looks. They import on a server. The element is `@johnmorrisdotca/wakusei-planets/space/element`.
|
|
2
2
|
export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, eclipticToScene, frameAt, moonOrbit, planetOrbit, SPACE_DWARFS, SPACE_MINORS, SPACE_PLANETS } from "./frame.js";
|
|
3
|
-
export { compress, MOON_COMPRESSED, moonDistance, orbitLine, placeAround, placeBodies, placeMoon, placeSun, radiusIn, SUN_COMPRESSED, truePosition } from "./scale.js";
|
|
3
|
+
export { compress, MOON_COMPRESSED, moonDistance, moonSizeFactor, orbitLine, placeAround, placeBodies, placeMoon, placeSun, radiusIn, SUN_COMPRESSED, truePosition } from "./scale.js";
|
|
4
4
|
export { groundDirection } from "./aim.js";
|
|
5
5
|
export { RIDE_FOV, ridePose } from "./ride.js";
|
|
6
|
-
export { chooseLabels, LABEL_GAP } from "./labels.js";
|
|
6
|
+
export { chooseLabels, LABEL_GAP, nameSpot } from "./labels.js";
|
|
7
7
|
export { bodyKindOf, findBody, HOP_ORDER, hopFrom, hostOf, systemOf } from "./bodies.js";
|
|
8
8
|
export { besideMoon, BESIDE_RADII } from "./beside.js";
|
|
9
9
|
export { ARROWS_PER_ORBIT, arrowCount, arrowSites, MAX_ARROWS_PER_ORBIT, chevron, spinArrow } from "./arrows.js";
|
|
10
10
|
export { spinAxis } from "./spin.js";
|
|
11
11
|
export { COVER_ARROW_GAP, COVER_MIN_PX, coverArrows, coveredBy } from "./covered.js";
|
|
12
|
-
export { TRAVEL_CLEARANCE, travelArrival, travelPlan, travelPose } from "./travel.js";
|
|
12
|
+
export { TRAVEL_CLEARANCE, arrivalSide, travelArrival, travelPlan, travelPose } from "./travel.js";
|
|
13
13
|
export { regionOrbits, regionView, SUN_REGIONS } from "./regions.js";
|
|
14
14
|
export { SIGHT_STEP_PX, sightChanged, sightOf } from "./sight.js";
|
package/dist/space/labels.d.ts
CHANGED
|
@@ -50,3 +50,35 @@ export declare const LABEL_GAP = 3;
|
|
|
50
50
|
* ```
|
|
51
51
|
*/
|
|
52
52
|
export declare function chooseLabels(boxes: readonly LabelBox[], gap?: number): Set<string>;
|
|
53
|
+
/**
|
|
54
|
+
* Where a floating name goes: beside its body's dot, and kept inside the view (MODULES-1144). It starts to the right of the dot, at `max(4, min(r, 40))` pixels from its middle and 8 pixels above it. A name that would run past the right edge goes to the dot's left side instead (`flipped`); one that fits on neither side is held against the edge, and a name past the top or the bottom is held inside. A body whose dot is itself outside the view keeps its name where it falls, since the view cuts it with the body.
|
|
55
|
+
*
|
|
56
|
+
* @param dot - The body's place on the screen in CSS pixels: its middle and its radius on the screen.
|
|
57
|
+
* @param size - The name's width and height in CSS pixels.
|
|
58
|
+
* @param frame - The view's width and height in CSS pixels.
|
|
59
|
+
* @returns The name's top-left corner, and whether it went to the left of the dot.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { nameSpot } from "@johnmorrisdotca/wakusei-planets/space";
|
|
64
|
+
*
|
|
65
|
+
* // a body 20 pixels from the right edge of a 400 pixel view: its 60 pixel name goes to the left of it
|
|
66
|
+
* const spot = nameSpot({ x: 380, y: 100, r: 10 }, { width: 60, height: 16 }, { width: 400, height: 300 });
|
|
67
|
+
* console.log(spot.flipped, spot.x + 60 <= 380);
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare function nameSpot(dot: {
|
|
71
|
+
x: number;
|
|
72
|
+
y: number;
|
|
73
|
+
r: number;
|
|
74
|
+
}, size: {
|
|
75
|
+
width: number;
|
|
76
|
+
height: number;
|
|
77
|
+
}, frame: {
|
|
78
|
+
width: number;
|
|
79
|
+
height: number;
|
|
80
|
+
}): {
|
|
81
|
+
x: number;
|
|
82
|
+
y: number;
|
|
83
|
+
flipped: boolean;
|
|
84
|
+
};
|
package/dist/space/labels.js
CHANGED
|
@@ -38,3 +38,42 @@ export function chooseLabels(boxes, gap = LABEL_GAP) {
|
|
|
38
38
|
kept.push(box);
|
|
39
39
|
return new Set(kept.map((box) => box.id));
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Where a floating name goes: beside its body's dot, and kept inside the view (MODULES-1144). It starts to the right of the dot, at `max(4, min(r, 40))` pixels from its middle and 8 pixels above it. A name that would run past the right edge goes to the dot's left side instead (`flipped`); one that fits on neither side is held against the edge, and a name past the top or the bottom is held inside. A body whose dot is itself outside the view keeps its name where it falls, since the view cuts it with the body.
|
|
43
|
+
*
|
|
44
|
+
* @param dot - The body's place on the screen in CSS pixels: its middle and its radius on the screen.
|
|
45
|
+
* @param size - The name's width and height in CSS pixels.
|
|
46
|
+
* @param frame - The view's width and height in CSS pixels.
|
|
47
|
+
* @returns The name's top-left corner, and whether it went to the left of the dot.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { nameSpot } from "@johnmorrisdotca/wakusei-planets/space";
|
|
52
|
+
*
|
|
53
|
+
* // a body 20 pixels from the right edge of a 400 pixel view: its 60 pixel name goes to the left of it
|
|
54
|
+
* const spot = nameSpot({ x: 380, y: 100, r: 10 }, { width: 60, height: 16 }, { width: 400, height: 300 });
|
|
55
|
+
* console.log(spot.flipped, spot.x + 60 <= 380);
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export function nameSpot(dot, size, frame) {
|
|
59
|
+
const gap = Math.max(4, Math.min(dot.r, 40));
|
|
60
|
+
let x = Math.round(dot.x + gap);
|
|
61
|
+
let y = Math.round(dot.y - 8);
|
|
62
|
+
let flipped = false;
|
|
63
|
+
if (frame.width <= 0 || frame.height <= 0)
|
|
64
|
+
return { x, y, flipped };
|
|
65
|
+
if (dot.x >= 0 && dot.x <= frame.width) {
|
|
66
|
+
if (x + size.width > frame.width) {
|
|
67
|
+
const left = Math.round(dot.x - gap - size.width);
|
|
68
|
+
if (left >= 0) {
|
|
69
|
+
x = left;
|
|
70
|
+
flipped = true;
|
|
71
|
+
}
|
|
72
|
+
else
|
|
73
|
+
x = Math.max(0, frame.width - size.width);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (dot.y >= 0 && dot.y <= frame.height)
|
|
77
|
+
y = Math.max(0, Math.min(y, frame.height - size.height));
|
|
78
|
+
return { x, y, flipped };
|
|
79
|
+
}
|
package/dist/space/scale.d.ts
CHANGED
|
@@ -143,6 +143,33 @@ export declare function radiusIn(id: "sun" | "earth" | "moon" | SpacePlanet | Sp
|
|
|
143
143
|
* ```
|
|
144
144
|
*/
|
|
145
145
|
export declare function moonDistance(mode: ScaleMode, host: SpacePlanet | SpaceDwarf, distance: number): number;
|
|
146
|
+
/** The squeezed view draws moons this many times their real size, unless a moon would pass a limit. 1 is today's size. True distances ignore it. */
|
|
147
|
+
export declare const MOON_SIZE_DEFAULT = 2;
|
|
148
|
+
/**
|
|
149
|
+
* How many times larger than life to draw a planet's moons in the squeezed view. Every moon gets the same factor, so they keep their real order of size. The factor is the one asked for, or less when that would draw a moon bigger than a quarter of its planet, into the planet or its rings, or across to the next moon's orbit. True scale always returns 1 and is not clamped.
|
|
150
|
+
*
|
|
151
|
+
* @param mode - The scale. `true` ignores `size`.
|
|
152
|
+
* @param host - The planet the moons go round.
|
|
153
|
+
* @param size - The factor asked for (1, 2, 4, 8, or any number from 1 to 8).
|
|
154
|
+
* @param moons - Each moon's radius and orbital distance, both in radii of the planet. The distance is the one `moonDistance` draws.
|
|
155
|
+
* @returns The factor to use, and whether it is less than the one asked for.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* import { moonSizeFactor } from "@johnmorrisdotca/wakusei-planets/space";
|
|
160
|
+
*
|
|
161
|
+
* console.log(moonSizeFactor("true", "jupiter", 4, [{ radius: 0.04, orbit: 6 }]).factor);
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
export declare function moonSizeFactor(mode: ScaleMode, host: SpacePlanet | SpaceDwarf, size: number, moons: readonly {
|
|
165
|
+
radius: number;
|
|
166
|
+
orbit: number;
|
|
167
|
+
}[]): {
|
|
168
|
+
factor: number;
|
|
169
|
+
clamped: boolean;
|
|
170
|
+
};
|
|
171
|
+
/** Read a `moon-size` attribute or property: a number from 1 to 8, or 2 when it is missing or not a number. */
|
|
172
|
+
export declare function readMoonSize(value: string | number | null | undefined): number;
|
|
146
173
|
/**
|
|
147
174
|
* Where every body of the view is, in Earth radii from the Earth's centre, at one moment: the Earth at the centre, the Moon, the Sun and the planets. The same mapping places
|
|
148
175
|
* the bodies and the lines of their orbits (`orbitLine`), so a body is always on its own orbit.
|
package/dist/space/scale.js
CHANGED
|
@@ -204,6 +204,55 @@ export function moonDistance(mode, host, distance) {
|
|
|
204
204
|
const far = Math.max(space / radius, near * 1.6);
|
|
205
205
|
return Math.min(distance, near + (far - near) * Math.sqrt(distance / reach));
|
|
206
206
|
}
|
|
207
|
+
/** The squeezed view draws moons this many times their real size, unless a moon would pass a limit. 1 is today's size. True distances ignore it. */
|
|
208
|
+
export const MOON_SIZE_DEFAULT = 2;
|
|
209
|
+
/**
|
|
210
|
+
* How many times larger than life to draw a planet's moons in the squeezed view. Every moon gets the same factor, so they keep their real order of size. The factor is the one asked for, or less when that would draw a moon bigger than a quarter of its planet, into the planet or its rings, or across to the next moon's orbit. True scale always returns 1 and is not clamped.
|
|
211
|
+
*
|
|
212
|
+
* @param mode - The scale. `true` ignores `size`.
|
|
213
|
+
* @param host - The planet the moons go round.
|
|
214
|
+
* @param size - The factor asked for (1, 2, 4, 8, or any number from 1 to 8).
|
|
215
|
+
* @param moons - Each moon's radius and orbital distance, both in radii of the planet. The distance is the one `moonDistance` draws.
|
|
216
|
+
* @returns The factor to use, and whether it is less than the one asked for.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```ts
|
|
220
|
+
* import { moonSizeFactor } from "@johnmorrisdotca/wakusei-planets/space";
|
|
221
|
+
*
|
|
222
|
+
* console.log(moonSizeFactor("true", "jupiter", 4, [{ radius: 0.04, orbit: 6 }]).factor);
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
export function moonSizeFactor(mode, host, size, moons) {
|
|
226
|
+
if (mode !== "compressed")
|
|
227
|
+
return { factor: 1, clamped: false };
|
|
228
|
+
const asked = Math.min(8, Math.max(1, Number.isFinite(size) ? size : MOON_SIZE_DEFAULT));
|
|
229
|
+
const bands = BODIES[host].rings ?? [];
|
|
230
|
+
const ringOuter = bands.length === 0 ? 0 : Math.max(...bands.map((band) => band.to)) / BODIES[host].radiusKm;
|
|
231
|
+
let factor = asked;
|
|
232
|
+
for (const moon of moons) {
|
|
233
|
+
if (!(moon.radius > 0))
|
|
234
|
+
continue;
|
|
235
|
+
let cap = 0.25;
|
|
236
|
+
cap = Math.min(cap, Math.max(moon.radius, moon.orbit - 1.05));
|
|
237
|
+
if (ringOuter > 0 && moon.orbit > ringOuter + 0.05)
|
|
238
|
+
cap = Math.min(cap, Math.max(moon.radius, moon.orbit - ringOuter - 0.05));
|
|
239
|
+
for (const other of moons) {
|
|
240
|
+
if (other === moon)
|
|
241
|
+
continue;
|
|
242
|
+
cap = Math.min(cap, Math.max(moon.radius, Math.abs(moon.orbit - other.orbit) * 0.9));
|
|
243
|
+
}
|
|
244
|
+
factor = Math.min(factor, cap / moon.radius);
|
|
245
|
+
}
|
|
246
|
+
factor = Math.max(1, factor);
|
|
247
|
+
return { factor, clamped: factor + 1e-6 < asked };
|
|
248
|
+
}
|
|
249
|
+
/** Read a `moon-size` attribute or property: a number from 1 to 8, or 2 when it is missing or not a number. */
|
|
250
|
+
export function readMoonSize(value) {
|
|
251
|
+
const n = typeof value === "number" ? value : Number(value);
|
|
252
|
+
if (!Number.isFinite(n))
|
|
253
|
+
return MOON_SIZE_DEFAULT;
|
|
254
|
+
return Math.min(8, Math.max(1, n));
|
|
255
|
+
}
|
|
207
256
|
/** The nearest a moon is drawn to its planet in a compressed view, in the planet's radii: outside the globe, and outside its rings with a little room, so the moon never sits in the ring plane. */
|
|
208
257
|
function nearestOf(host) {
|
|
209
258
|
const facts = BODIES[host];
|
package/dist/space/scene.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ import "../bodies/all.ts";
|
|
|
10
10
|
import { type Vec3 } from "../vec.ts";
|
|
11
11
|
import { type OrbitArrow } from "./arrows.ts";
|
|
12
12
|
import type { SightInput } from "./sight.ts";
|
|
13
|
-
import { type SpaceFrame, type SpaceVec3 } from "./frame.ts";
|
|
13
|
+
import { type SpaceDwarf, type SpaceFrame, type SpacePlanet, type SpaceVec3 } from "./frame.ts";
|
|
14
14
|
import { type PaintSpec, type PaintTrail } from "../paint/trail.ts";
|
|
15
15
|
import { type RideLook } from "./ride.ts";
|
|
16
16
|
import { type ScaleMode } from "./scale.ts";
|
|
@@ -166,6 +166,15 @@ export interface SpaceModel {
|
|
|
166
166
|
speed: number;
|
|
167
167
|
/** The body the camera looks at, and (in `zoom`) fills the view with at 1x: any body the package knows that the view can place (the eleven of `SPACE_BODIES` and the moons of the planets). */
|
|
168
168
|
focus: BodyId;
|
|
169
|
+
/** The body kept in the picture beside the one arrived at, or null. Its name is not dropped for a clash. */
|
|
170
|
+
companion: string | null;
|
|
171
|
+
/** How many times larger than life the squeezed view draws moons. Ignored at true distances. 2 by default. */
|
|
172
|
+
moonSize: number;
|
|
173
|
+
/** The factor actually used for the system in the middle, and whether a limit cut the one asked for. */
|
|
174
|
+
moonDrawn: {
|
|
175
|
+
factor: number;
|
|
176
|
+
clamped: boolean;
|
|
177
|
+
};
|
|
169
178
|
light: SpaceLight;
|
|
170
179
|
/** How the painter draws the bodies (`realistic` or `painted`). */
|
|
171
180
|
look: string;
|
|
@@ -242,6 +251,7 @@ export interface SpaceModel {
|
|
|
242
251
|
shown: boolean;
|
|
243
252
|
text: string;
|
|
244
253
|
turn: number;
|
|
254
|
+
look: string;
|
|
245
255
|
} | null;
|
|
246
256
|
};
|
|
247
257
|
/** How long an arrowhead drawn at the last draw is on the screen, in CSS pixels (measured from its own points), or 0 when none was drawn. */
|
|
@@ -435,4 +445,24 @@ export interface SpaceDeps {
|
|
|
435
445
|
/** The painter could not make a body (the three.js parts handed over lack something it needs). */
|
|
436
446
|
onPainterError?: (error: unknown) => void;
|
|
437
447
|
}
|
|
448
|
+
/**
|
|
449
|
+
* The factor the squeezed view draws the moons of one planet at (1 at true distances), worked out from the planet's moons as the drawing does, so a camera that frames a moon frames the size it is drawn.
|
|
450
|
+
*
|
|
451
|
+
* @param mode - The scale.
|
|
452
|
+
* @param host - The planet or dwarf planet the moons go round.
|
|
453
|
+
* @param size - The `moon-size` asked for.
|
|
454
|
+
* @param time - The moment, in milliseconds, that sets where the moons are.
|
|
455
|
+
* @returns The factor used, and whether a limit cut it.
|
|
456
|
+
*
|
|
457
|
+
* @example
|
|
458
|
+
* ```ts no-run
|
|
459
|
+
* import { moonScaleFor } from "@johnmorrisdotca/wakusei-planets/space/element";
|
|
460
|
+
*
|
|
461
|
+
* console.log(moonScaleFor("compressed", "jupiter", 4, Date.UTC(2026, 10, 11)).factor);
|
|
462
|
+
* ```
|
|
463
|
+
*/
|
|
464
|
+
export declare function moonScaleFor(mode: ScaleMode, host: SpacePlanet | SpaceDwarf, size: number, time: number): {
|
|
465
|
+
factor: number;
|
|
466
|
+
clamped: boolean;
|
|
467
|
+
};
|
|
438
468
|
export declare function createSpaceItem(model: SpaceModel, deps: SpaceDeps): Item3D<ThreeParts>;
|
package/dist/space/scene.js
CHANGED
|
@@ -18,7 +18,7 @@ import { createPaintOverlay } from "./paint-overlay.js";
|
|
|
18
18
|
import { createPaintTrail, groundUnder, paintMinute } from "../paint/trail.js";
|
|
19
19
|
import { BALL_FRAGMENT, VERTEX } from "../scene/glsl.js";
|
|
20
20
|
import { ridePose } from "./ride.js";
|
|
21
|
-
import { moonDistance, orbitLine, placeAround, placeBodies, placeMoon, radiusIn } from "./scale.js";
|
|
21
|
+
import { moonDistance, moonSizeFactor, orbitLine, placeAround, placeBodies, placeMoon, radiusIn } from "./scale.js";
|
|
22
22
|
import { regionOrbits, regionView } from "./regions.js";
|
|
23
23
|
import { travelPlan, travelPose } from "./travel.js";
|
|
24
24
|
const RAD = Math.PI / 180;
|
|
@@ -83,6 +83,9 @@ export const newSpaceModel = () => ({
|
|
|
83
83
|
stepMs: 1000,
|
|
84
84
|
speed: 1,
|
|
85
85
|
focus: "earth",
|
|
86
|
+
companion: null,
|
|
87
|
+
moonSize: 2,
|
|
88
|
+
moonDrawn: { factor: 1, clamped: false },
|
|
86
89
|
light: "sun",
|
|
87
90
|
look: "realistic",
|
|
88
91
|
drawn: null,
|
|
@@ -128,6 +131,29 @@ export const newSpaceModel = () => ({
|
|
|
128
131
|
ratio: () => Math.min(globalThis.devicePixelRatio || 1, 2),
|
|
129
132
|
});
|
|
130
133
|
const minus = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
134
|
+
/**
|
|
135
|
+
* The factor the squeezed view draws the moons of one planet at (1 at true distances), worked out from the planet's moons as the drawing does, so a camera that frames a moon frames the size it is drawn.
|
|
136
|
+
*
|
|
137
|
+
* @param mode - The scale.
|
|
138
|
+
* @param host - The planet or dwarf planet the moons go round.
|
|
139
|
+
* @param size - The `moon-size` asked for.
|
|
140
|
+
* @param time - The moment, in milliseconds, that sets where the moons are.
|
|
141
|
+
* @returns The factor used, and whether a limit cut it.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts no-run
|
|
145
|
+
* import { moonScaleFor } from "@johnmorrisdotca/wakusei-planets/space/element";
|
|
146
|
+
*
|
|
147
|
+
* console.log(moonScaleFor("compressed", "jupiter", 4, Date.UTC(2026, 10, 11)).factor);
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
export function moonScaleFor(mode, host, size, time) {
|
|
151
|
+
const moons = (MOONS_OF[host] ?? []).map((moon) => {
|
|
152
|
+
const offset = moonOffset(moon, time);
|
|
153
|
+
return { radius: BODIES[moon].radiusKm / BODIES[host].radiusKm, orbit: moonDistance(mode, host, Math.hypot(offset[0], offset[1], offset[2])) };
|
|
154
|
+
});
|
|
155
|
+
return moonSizeFactor(mode, host, size, moons);
|
|
156
|
+
}
|
|
131
157
|
/** How far a place is from the nearest point of a line through `points`, in the line's units. */
|
|
132
158
|
const plus = (a, b) => [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
|
|
133
159
|
function distanceToLine(place, points) {
|
|
@@ -391,7 +417,8 @@ export function createSpaceItem(model, deps) {
|
|
|
391
417
|
const offset = moonSite(focus, model.time, host);
|
|
392
418
|
const hostRadius = radiusOf(host);
|
|
393
419
|
focusPos = [pos[host][0] + offset[0] * hostRadius, pos[host][1] + offset[1] * hostRadius, pos[host][2] + offset[2] * hostRadius];
|
|
394
|
-
|
|
420
|
+
// a moon the view draws larger than life is framed at the size it is drawn
|
|
421
|
+
focusRadius = Math.max(1e-9, (BODIES[focus].radiusKm / BODIES[host].radiusKm) * hostRadius * moonScaleFor(mode, host, model.moonSize, model.time).factor);
|
|
395
422
|
}
|
|
396
423
|
let aimWay = 1;
|
|
397
424
|
let besideIn = null;
|
|
@@ -1020,6 +1047,9 @@ export function createSpaceItem(model, deps) {
|
|
|
1020
1047
|
if (!planet)
|
|
1021
1048
|
continue;
|
|
1022
1049
|
const sites = (MOONS_OF[id] ?? []).map((moon) => ({ name: moon, offset: moonOffset(moon, model.time), radius: BODIES[moon].radiusKm / BODIES[id].radiusKm }));
|
|
1050
|
+
const sized = moonSizeFactor(mode, id, model.moonSize, sites.map((site) => ({ radius: site.radius, orbit: moonDistance(mode, id, Math.hypot(site.offset[0], site.offset[1], site.offset[2])) })));
|
|
1051
|
+
if (id === model.focus || hostOf(model.focus) === id)
|
|
1052
|
+
model.moonDrawn = { factor: sized.factor, clamped: sized.clamped };
|
|
1023
1053
|
// the moons are shown once the planet is a few pixels across, or the system round it is wide enough on the screen to tell its moons from the planet, or one of its moons is the body looked at
|
|
1024
1054
|
let spread = 1;
|
|
1025
1055
|
for (const site of sites)
|
|
@@ -1048,7 +1078,12 @@ export function createSpaceItem(model, deps) {
|
|
|
1048
1078
|
if (!drawing)
|
|
1049
1079
|
continue;
|
|
1050
1080
|
const away = Math.hypot(at[0] - camera.position.x, at[1] - camera.position.y, at[2] - camera.position.z);
|
|
1051
|
-
const
|
|
1081
|
+
const floor = (away * half * MOON_MIN_PX) / (size.height / 2);
|
|
1082
|
+
const wanted = Math.max(site.radius * radius, floor) * sized.factor;
|
|
1083
|
+
const cap = 0.25 * radius;
|
|
1084
|
+
const drawn = Math.min(wanted, cap);
|
|
1085
|
+
if (drawn + 1e-4 < wanted && (id === model.focus || hostOf(model.focus) === id))
|
|
1086
|
+
model.moonDrawn = { factor: sized.factor, clamped: true };
|
|
1052
1087
|
drawing.object.visible = true;
|
|
1053
1088
|
drawing.object.position.set(at[0], at[1], at[2]);
|
|
1054
1089
|
drawing.object.scale.setScalar(drawn);
|