astraeus 0.8.1 → 0.9.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 +67 -0
- package/README.md +28 -15
- package/package.json +1 -1
- package/src/api/AstraeusScene.d.ts +1 -1
- package/src/api/AstraeusScene.js +4 -1
- package/src/api/AstraeusScene.node.js +4 -1
- package/src/api/assembleScene.d.ts +2 -0
- package/src/api/assembleScene.js +27 -5
- package/src/api/cameraRequest.d.ts +15 -0
- package/src/api/cameraRequest.js +89 -0
- package/src/api/errors.d.ts +9 -1
- package/src/api/index.d.ts +6 -3
- package/src/api/look.d.ts +49 -0
- package/src/api/lookInput.d.ts +1 -1
- package/src/api/lookInput.js +6 -1
- package/src/api/planCamera.d.ts +35 -7
- package/src/api/planCamera.js +94 -11
- package/src/api/planSkyFigures.d.ts +22 -0
- package/src/api/planSkyFigures.js +145 -0
- package/src/api/planStory.d.ts +2 -2
- package/src/api/planStory.js +14 -9
- package/src/api/planViews.js +1 -1
- package/src/api/scene.d.ts +17 -4
- package/src/api/scene.js +23 -5
- package/src/api/sceneReads.d.ts +21 -2
- package/src/api/skyFigureInput.d.ts +45 -0
- package/src/api/skyFigureInput.js +1 -0
- package/src/api/skyTraceInput.d.ts +33 -0
- package/src/api/skyTraceInput.js +45 -0
- package/src/api/story.d.ts +12 -3
- package/src/api/story.js +44 -1
- package/src/api/viewerCamera.d.ts +4 -3
- package/src/api/viewerCamera.js +10 -32
- package/src/api/viewerHandle.d.ts +27 -4
- package/src/api/viewerHandle.js +6 -0
- package/src/api/viewerLink.d.ts +49 -4
- package/src/api/viewerLink.js +25 -0
- package/src/api/viewerPanels.d.ts +26 -0
- package/src/api/viewerPanels.js +42 -0
- package/src/api/viewerSelection.d.ts +1 -1
- package/src/api/viewerSelection.js +3 -3
- package/src/app/App.js +100 -18
- package/src/app/App.node.js +100 -18
- package/src/app/AstraeusScene.d.ts +20 -5
- package/src/app/AstraeusScene.js +3 -3
- package/src/app/CameraController.d.ts +17 -0
- package/src/app/CameraController.js +34 -9
- package/src/app/DeveloperSettings.d.ts +11 -3
- package/src/app/DeveloperSettings.js +13 -3
- package/src/app/SceneLabels.d.ts +20 -2
- package/src/app/SceneLabels.js +46 -6
- package/src/app/SkyFiguresView.d.ts +56 -0
- package/src/app/SkyFiguresView.js +242 -0
- package/src/app/StoryMarkers.d.ts +2 -2
- package/src/app/StoryMarkers.js +2 -2
- package/src/app/displaySwitches.d.ts +13 -3
- package/src/app/displaySwitches.js +17 -3
- package/src/app/experienceDefinition.d.ts +9 -3
- package/src/app/experienceDefinition.js +4 -2
- package/src/app/labelStyle.d.ts +17 -0
- package/src/app/labelStyle.js +13 -0
- package/src/app/liveLook.js +8 -0
- package/src/app/look.d.ts +9 -5
- package/src/app/look.js +11 -0
- package/src/app/lookOut.d.ts +32 -0
- package/src/app/lookOut.js +50 -0
- package/src/app/sceneCamera.d.ts +5 -3
- package/src/app/sceneCamera.js +66 -3
- package/src/app/sceneContentsHooks.d.ts +2 -1
- package/src/app/sceneContentsHooks.js +3 -2
- package/src/app/sceneFrame.d.ts +10 -1
- package/src/app/sceneFrame.js +45 -10
- package/src/app/sceneFraming.d.ts +7 -0
- package/src/app/sceneFraming.js +12 -0
- package/src/app/sceneHooks.d.ts +2 -0
- package/src/app/sceneHooks.js +4 -1
- package/src/app/scenePicking.d.ts +20 -0
- package/src/app/scenePicking.js +49 -0
- package/src/app/scenePointer.d.ts +3 -1
- package/src/app/scenePointer.js +3 -2
- package/src/app/skyFigures.d.ts +73 -0
- package/src/app/skyFigures.js +50 -0
- package/src/app/style.css +2 -1
- package/src/app/viewHiding.d.ts +2 -0
- package/src/app/viewHiding.js +7 -1
- package/src/app/viewLink.d.ts +8 -8
- package/src/app/viewLink.js +24 -4
- package/src/app/viewerPort.d.ts +30 -3
- package/src/assets/sky.d.ts +13 -4
- package/src/assets/sky.js +33 -8
- package/src/assets/stars/hyg-v42-naked-eye.json +1 -1
- package/src/core/bodies/moonSystem.js +1 -15
- package/src/core/lookValues.d.ts +9 -0
- package/src/core/lookValues.js +24 -0
- package/src/core/readBytes.d.ts +1 -0
- package/src/core/readBytes.js +15 -0
- package/src/core/skyTrace.d.ts +49 -0
- package/src/core/skyTrace.js +39 -0
- package/src/core/startView.d.ts +39 -0
- package/src/core/startView.js +56 -0
- package/src/core/storyPanels.d.ts +51 -3
- package/src/core/storyPanels.js +52 -12
- package/src/shell/AstraeusShell.d.ts +15 -6
- package/src/shell/AstraeusShell.js +76 -20
- package/src/shell/AstraeusShell.node.js +76 -20
- package/src/shell/ObjectControls.js +11 -8
- package/src/shell/StoryPanelView.d.ts +12 -3
- package/src/shell/StoryPanelView.js +2 -2
- package/src/shell/experience.d.ts +24 -0
- package/src/shell/experience.js +4 -1
- package/src/shell/infoModel.js +9 -1
- package/src/shell/objectModel.d.ts +6 -2
- package/src/shell/objectModel.js +10 -1
- package/src/shell/phone.css +1 -1
- package/src/shell/storyPanels.d.ts +1 -1
- package/src/shell/storyPanels.js +1 -1
- package/src/shell/style.css +9 -1
- package/src/shell/topBarIcons.d.ts +1 -0
- package/src/shell/topBarIcons.js +1 -0
- package/src/shell/useStoryPanels.d.ts +9 -6
- package/src/shell/useStoryPanels.js +10 -6
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { BufferAttribute, BufferGeometry, Color, Group, LineBasicMaterial, LineSegments, Vector3 } from "three";
|
|
2
|
+
import { celestialEquatorSegments, eclipticSegments } from "./skyFigures.js";
|
|
3
|
+
import { stepFadeIn, stepHide, stepTrace } from "../core/skyTrace.js";
|
|
4
|
+
import { eqjToRenderVector } from "./renderCoordinates.js";
|
|
5
|
+
import { TRACK_LAYER } from "./TrackedBodyView.js";
|
|
6
|
+
import { projectSegmentClipped } from "./scenePicking.js";
|
|
7
|
+
const FADED = new Color();
|
|
8
|
+
const TRACE_OPACITY = 0.85;
|
|
9
|
+
/** The share of a trace over which the name of a figure shown only when traced fades in (owner, T-306: it no longer appears at once). */
|
|
10
|
+
const TRACE_LABEL_IN_SHARE = 0.5;
|
|
11
|
+
/** The opacity of an always-shown line once it has faded in. */
|
|
12
|
+
const LINE_OPACITY = 0.85;
|
|
13
|
+
function lines(segments, color, key) {
|
|
14
|
+
const positions = new Float32Array(segments.length * 6);
|
|
15
|
+
segments.forEach(([from, to], i) => positions.set([...eqjToRenderVector(from), ...eqjToRenderVector(to)], i * 6));
|
|
16
|
+
const geometry = new BufferGeometry();
|
|
17
|
+
geometry.setAttribute("position", new BufferAttribute(positions, 3));
|
|
18
|
+
// Depth is tested (a body in front of the sky hides the line) but never written. The lines are on the last render pass (TRACK_LAYER), after every body's pass, so the Sun's halo
|
|
19
|
+
// (drawn earlier, without depth) never covers them (owner decision 3, O-065).
|
|
20
|
+
const material = new LineBasicMaterial({ color, transparent: true, opacity: LINE_OPACITY, depthTest: true, depthWrite: false });
|
|
21
|
+
const object = new LineSegments(geometry, material);
|
|
22
|
+
object.name = key;
|
|
23
|
+
object.layers.set(TRACK_LAYER);
|
|
24
|
+
object.frustumCulled = false;
|
|
25
|
+
object.renderOrder = 1;
|
|
26
|
+
return object;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Figures, outlines and the two reference circles, drawn at infinity like the stars: the group stands on the camera every frame and is scaled to sit between the near and far planes,
|
|
30
|
+
* so only the camera's orientation matters. Carries no State (ARCH-02). The ecliptic and the equator are built the first time they are switched on.
|
|
31
|
+
*/
|
|
32
|
+
export class SkyFiguresView {
|
|
33
|
+
group = new Group();
|
|
34
|
+
#drawn = [];
|
|
35
|
+
#applied = null;
|
|
36
|
+
labels;
|
|
37
|
+
#layers;
|
|
38
|
+
#traces = new Map();
|
|
39
|
+
/** The emphasis lines over the selected figure (one set at most), built when the selection first names a figure. */
|
|
40
|
+
#selected = null;
|
|
41
|
+
#point = new Vector3();
|
|
42
|
+
/** How far each kind of line (and its names) has faded in since its switch last turned on, 0 to 1; 0 while the switch is off, so the next turn-on fades in again. */
|
|
43
|
+
#shownShare = { figures: 0, boundaries: 0, ecliptic: 0, celestialEquator: 0 };
|
|
44
|
+
constructor(layers) {
|
|
45
|
+
this.#layers = new Map(layers.map((layer) => [layer.id, layer]));
|
|
46
|
+
const add = (segments, shows, colour, key, own) => {
|
|
47
|
+
if (segments.length === 0)
|
|
48
|
+
return;
|
|
49
|
+
const object = lines(segments, own ?? "#ffffff", key);
|
|
50
|
+
this.#drawn.push({ object, shows, colour, own: own !== undefined });
|
|
51
|
+
this.group.add(object);
|
|
52
|
+
};
|
|
53
|
+
// Figures that take the look's colour share one set of lines per kind; a figure with its own colour is drawn on its own so a live look change leaves it alone.
|
|
54
|
+
for (const [kind, shows, key] of [["figure", "figures", "sky-figures"], ["boundary", "boundaries", "sky-boundaries"]]) {
|
|
55
|
+
const of = layers.filter((layer) => layer.kind === kind && layer.whenTraced !== true); // a figure shown only when traced has no lines of its own: its trace is the whole drawing
|
|
56
|
+
add(of.filter((layer) => layer.color === undefined).flatMap((layer) => layer.segments), shows, kind, key);
|
|
57
|
+
for (const layer of of)
|
|
58
|
+
if (layer.color !== undefined)
|
|
59
|
+
add(layer.segments, shows, kind, `${key}:${layer.id}`, layer.color);
|
|
60
|
+
}
|
|
61
|
+
this.labels = layers.map((layer) => ({
|
|
62
|
+
id: layer.id, label: layer.label, kind: layer.kind, direction: eqjToRenderVector(layer.labelAt), ...(layer.whenTraced === true ? { whenTraced: true } : {}),
|
|
63
|
+
...(layer.labelColor === undefined ? {} : { color: layer.labelColor }), ...(layer.labelFont === undefined ? {} : { font: layer.labelFont }), ...(layer.labelSizePx === undefined ? {} : { sizePx: layer.labelSizePx }),
|
|
64
|
+
}));
|
|
65
|
+
this.group.name = "sky-lines";
|
|
66
|
+
}
|
|
67
|
+
/** Stands the group on the camera, sized between its planes, shows the kinds the switches say (building a reference circle the first time it shows) and paints the lines in the colours given. */
|
|
68
|
+
place(camera, on, colours, selectedId = "") {
|
|
69
|
+
this.group.position.copy(camera.position);
|
|
70
|
+
this.group.scale.setScalar(0.5 * (camera.near + camera.far));
|
|
71
|
+
for (const [shows, colour, make, key] of [["ecliptic", "ecliptic", eclipticSegments, "sky-ecliptic"], ["celestialEquator", "equator", celestialEquatorSegments, "sky-celestial-equator"]]) {
|
|
72
|
+
if (on[shows] && !this.#drawn.some((entry) => entry.shows === shows)) {
|
|
73
|
+
const object = lines(make(), "#ffffff", key);
|
|
74
|
+
this.#drawn.push({ object, shows, colour, own: false });
|
|
75
|
+
this.group.add(object);
|
|
76
|
+
this.#applied = null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (this.#applied === null || Object.keys(colours).some((name) => colours[name] !== this.#applied[name])) {
|
|
80
|
+
for (const entry of this.#drawn)
|
|
81
|
+
if (!entry.own)
|
|
82
|
+
entry.object.material.color.set(colours[entry.colour]);
|
|
83
|
+
this.#applied = { ...colours };
|
|
84
|
+
}
|
|
85
|
+
for (const entry of this.#drawn)
|
|
86
|
+
entry.object.visible = on[entry.shows];
|
|
87
|
+
this.#emphasise(selectedId, on, colours);
|
|
88
|
+
}
|
|
89
|
+
/** Whether a tap or the emphasis can reach the figure now: its kind's switch is on and, for one shown only when traced, a trace shows it. */
|
|
90
|
+
#tappable(layer, on) {
|
|
91
|
+
return on[layer.kind === "figure" ? "figures" : "boundaries"] && (layer.whenTraced !== true || (this.#traces.get(layer.id)?.fade ?? 1) < 1);
|
|
92
|
+
}
|
|
93
|
+
/** True while a trace of `id` is still growing (not yet fully drawn, and not being cleared). */
|
|
94
|
+
#drawing(id) {
|
|
95
|
+
const trace = this.#traces.get(id);
|
|
96
|
+
return trace !== undefined && trace.hide === undefined && trace.drawn < 1;
|
|
97
|
+
}
|
|
98
|
+
/** Draws the selected figure's lines over it in the look's `selected` colour (and removes them when the selection moves or is not a figure); the name takes the same colour in the label layer. */
|
|
99
|
+
#emphasise(selectedId, on, colours) {
|
|
100
|
+
const layer = this.#layers.get(selectedId);
|
|
101
|
+
if (this.#selected !== null && this.#selected.id !== layer?.id) {
|
|
102
|
+
this.group.remove(this.#selected.object);
|
|
103
|
+
this.#selected.object.geometry.dispose();
|
|
104
|
+
this.#selected.object.material.dispose();
|
|
105
|
+
this.#selected = null;
|
|
106
|
+
}
|
|
107
|
+
if (layer === undefined)
|
|
108
|
+
return;
|
|
109
|
+
if (this.#selected === null) {
|
|
110
|
+
const object = lines(layer.segments, colours.selected, `sky-selected:${layer.id}`);
|
|
111
|
+
object.renderOrder = 3;
|
|
112
|
+
this.group.add(object);
|
|
113
|
+
this.#selected = { id: layer.id, object };
|
|
114
|
+
}
|
|
115
|
+
const material = this.#selected.object.material;
|
|
116
|
+
material.color.set(colours.selected);
|
|
117
|
+
material.opacity = LINE_OPACITY * (layer.whenTraced === true ? 1 : this.#shownShare[layer.kind === "figure" ? "figures" : "boundaries"]);
|
|
118
|
+
// While the figure's trace is still drawing, the trace itself grows in the selected colour (`advanceTraces`) and the whole-figure emphasis waits, so it never covers the growing line (owner, T-306).
|
|
119
|
+
this.#selected.object.visible = this.#tappable(layer, on) && !this.#drawing(layer.id);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The figures a tap can select, as screen lines (CSS px from the canvas's top left) and the rectangle of each shown name (`labelRects` are page rectangles; `box` is the canvas's). A figure whose switch is off, or that is
|
|
123
|
+
* shown only when traced and has no trace showing, is left out. A segment is kept whenever any part of it is in front of the camera (cut at the camera plane), even with both ends off screen. Worked out when asked, not each frame.
|
|
124
|
+
*/
|
|
125
|
+
screenFigures(camera, widthPx, heightPx, on, labelRects, box) {
|
|
126
|
+
camera.updateMatrixWorld(true);
|
|
127
|
+
const reach = 0.5 * (camera.near + camera.far); // where the lines are drawn, as the names are placed
|
|
128
|
+
const tanHalfFov = Math.tan((camera.fov * Math.PI) / 360);
|
|
129
|
+
const aspect = widthPx / heightPx;
|
|
130
|
+
const inCamera = (direction) => { const p = this.#point.fromArray(eqjToRenderVector(direction)).multiplyScalar(reach).add(camera.position).applyMatrix4(camera.matrixWorldInverse); return [p.x, p.y, p.z]; };
|
|
131
|
+
return [...this.#layers.values()].filter((layer) => this.#tappable(layer, on)).map((layer) => {
|
|
132
|
+
const rect = labelRects?.get(layer.id);
|
|
133
|
+
const lines = layer.segments.flatMap(([from, to]) => { const line = projectSegmentClipped(inCamera(from), inCamera(to), tanHalfFov, aspect, widthPx, heightPx); return line === null ? [] : [line]; });
|
|
134
|
+
return { id: layer.id, lines, label: rect === undefined ? null : { left: rect.left - box.left, top: rect.top - box.top, right: rect.right - box.left, bottom: rect.bottom - box.top } };
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/** Begins tracing the figure `request.id` (a trace already on it restarts). The trace is a separate set of lines drawn over the figure (the whole drawing of a figure shown only when traced); the figure itself is untouched. An id the view does not hold does nothing. */
|
|
138
|
+
startTrace(request) {
|
|
139
|
+
const layer = this.#layers.get(request.id);
|
|
140
|
+
if (layer === undefined)
|
|
141
|
+
return;
|
|
142
|
+
this.#removeTrace(request.id);
|
|
143
|
+
const object = lines(layer.segments, "#ffffff", `sky-trace:${request.id}`);
|
|
144
|
+
object.renderOrder = 2;
|
|
145
|
+
object.geometry.setDrawRange(0, 0);
|
|
146
|
+
const full = Float32Array.from(object.geometry.getAttribute("position").array);
|
|
147
|
+
this.group.add(object);
|
|
148
|
+
this.#traces.set(request.id, { object, full, kind: layer.kind, run: { seconds: request.seconds, after: request.after, reduced: request.reduced, elapsed: 0 }, drawn: 0, fade: 0 });
|
|
149
|
+
}
|
|
150
|
+
/** Removes the trace of `request.id` over `request.seconds` (at once for 0 or reduced motion), keeping what it had drawn; a figure with no trace, or an id the view does not hold, is left alone. */
|
|
151
|
+
clearTrace(request) {
|
|
152
|
+
const trace = this.#traces.get(request.id);
|
|
153
|
+
if (trace === undefined)
|
|
154
|
+
return;
|
|
155
|
+
if (request.reduced || request.seconds <= 0)
|
|
156
|
+
this.#removeTrace(request.id);
|
|
157
|
+
else
|
|
158
|
+
trace.hide = { seconds: request.seconds, from: trace.fade, elapsed: 0 };
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Moves every trace on by `deltaSeconds` of real time (the scene clock never enters): draws the segments reached so far, the last one part-grown from its first end, in the traced colour (the faded colour while fading),
|
|
162
|
+
* shows each with its figure's switch, and removes finished ones. Returns true while anything changed, so the caller wakes the draw rule.
|
|
163
|
+
*/
|
|
164
|
+
advanceTraces(deltaSeconds, colours, on, selectedId = "") {
|
|
165
|
+
let moving = false;
|
|
166
|
+
for (const [id, trace] of this.#traces) {
|
|
167
|
+
const frame = trace.hide === undefined ? stepTrace(trace.run, deltaSeconds) : stepHide(trace.hide, deltaSeconds, trace.drawn);
|
|
168
|
+
moving ||= frame.moving;
|
|
169
|
+
trace.fade = frame.fade;
|
|
170
|
+
trace.drawn = frame.drawn;
|
|
171
|
+
if (frame.done) {
|
|
172
|
+
this.#removeTrace(id);
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
const count = trace.full.length / 6;
|
|
176
|
+
const reached = frame.drawn * count;
|
|
177
|
+
const last = Math.min(count - 1, Math.floor(reached));
|
|
178
|
+
const grown = frame.drawn >= 1 ? 1 : reached - last;
|
|
179
|
+
const positions = trace.object.geometry.getAttribute("position");
|
|
180
|
+
positions.array.set(trace.full.subarray(0, (last + 1) * 6));
|
|
181
|
+
const at = last * 6;
|
|
182
|
+
const end = [0, 1, 2].map((axis) => trace.full[at + axis] + (trace.full[at + 3 + axis] - trace.full[at + axis]) * grown);
|
|
183
|
+
const length = Math.hypot(end[0], end[1], end[2]);
|
|
184
|
+
end.forEach((value, axis) => { positions.array[at + 3 + axis] = length > 1e-9 ? value / length : value; });
|
|
185
|
+
positions.needsUpdate = true;
|
|
186
|
+
trace.object.geometry.setDrawRange(0, (last + 1) * 2);
|
|
187
|
+
const material = trace.object.material;
|
|
188
|
+
material.color.set(id === selectedId && frame.drawn < 1 && trace.hide === undefined ? colours.selected : colours.traced).lerp(FADED.set(colours.faded), frame.fade);
|
|
189
|
+
material.opacity = TRACE_OPACITY * (1 - frame.fade);
|
|
190
|
+
trace.object.visible = on[trace.kind === "figure" ? "figures" : "boundaries"];
|
|
191
|
+
}
|
|
192
|
+
return moving;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Moves the fade-in of every kind of line on by `deltaSeconds` of real time over `seconds` (0: at once), and sets the lines' opacity; a kind whose switch is off goes back to 0 so it fades in again
|
|
196
|
+
* when it next turns on. Returns true while a fade-in is still running, so the caller wakes the draw rule.
|
|
197
|
+
*/
|
|
198
|
+
advanceFadeIn(deltaSeconds, seconds, on) {
|
|
199
|
+
let moving = false;
|
|
200
|
+
for (const kind of Object.keys(this.#shownShare)) {
|
|
201
|
+
const before = this.#shownShare[kind];
|
|
202
|
+
const after = on[kind] ? stepFadeIn(before, deltaSeconds, seconds) : 0;
|
|
203
|
+
this.#shownShare[kind] = after;
|
|
204
|
+
if (after !== before)
|
|
205
|
+
moving = true;
|
|
206
|
+
}
|
|
207
|
+
for (const entry of this.#drawn)
|
|
208
|
+
entry.object.material.opacity = LINE_OPACITY * this.#shownShare[entry.shows];
|
|
209
|
+
return moving;
|
|
210
|
+
}
|
|
211
|
+
/** How much of a label shows, 0 to 1: for a figure that is always shown, how far its kind has faded in; for one shown only when traced, 0 until a trace starts, then rising with the trace to 1 at half drawn (fading to 0 with a `fade` trace; 0 again once the trace is removed). */
|
|
212
|
+
labelOpacity(id) {
|
|
213
|
+
const layer = this.#layers.get(id);
|
|
214
|
+
if (layer === undefined)
|
|
215
|
+
return 1;
|
|
216
|
+
if (layer.whenTraced !== true)
|
|
217
|
+
return this.#shownShare[layer.kind === "figure" ? "figures" : "boundaries"];
|
|
218
|
+
const trace = this.#traces.get(id);
|
|
219
|
+
return trace === undefined ? 0 : Math.min(1, trace.drawn / TRACE_LABEL_IN_SHARE) * (1 - trace.fade);
|
|
220
|
+
}
|
|
221
|
+
#removeTrace(id) {
|
|
222
|
+
const trace = this.#traces.get(id);
|
|
223
|
+
if (trace === undefined)
|
|
224
|
+
return;
|
|
225
|
+
this.#traces.delete(id);
|
|
226
|
+
this.group.remove(trace.object);
|
|
227
|
+
trace.object.geometry.dispose();
|
|
228
|
+
trace.object.material.dispose();
|
|
229
|
+
}
|
|
230
|
+
/** Which lines are shown now, by name (read by tests and the canvas data). */
|
|
231
|
+
get shown() {
|
|
232
|
+
return this.group.children.filter((child) => child.visible).map((child) => child.name);
|
|
233
|
+
}
|
|
234
|
+
dispose() {
|
|
235
|
+
for (const child of this.group.children) {
|
|
236
|
+
const line = child;
|
|
237
|
+
line.geometry.dispose();
|
|
238
|
+
line.material.dispose();
|
|
239
|
+
}
|
|
240
|
+
this.group.clear();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
@@ -6,8 +6,8 @@ export interface StoryMarkerSpec {
|
|
|
6
6
|
readonly panelId: string;
|
|
7
7
|
readonly objectId: string;
|
|
8
8
|
readonly title: string;
|
|
9
|
-
/** The panel's moment, so a marker shared by several panels can pick the one the clock has reached. */
|
|
10
|
-
readonly timeUtcMs
|
|
9
|
+
/** The panel's moment, so a marker shared by several panels can pick the one the clock has reached; absent on a step, which comes after the moment panels. */
|
|
10
|
+
readonly timeUtcMs?: number;
|
|
11
11
|
}
|
|
12
12
|
/** One scene marker: an object and every panel that names it, in time order. */
|
|
13
13
|
export interface StoryMarkerGroup {
|
package/src/app/StoryMarkers.js
CHANGED
|
@@ -15,7 +15,7 @@ export function groupStoryMarkers(specs) {
|
|
|
15
15
|
else
|
|
16
16
|
list.push(spec);
|
|
17
17
|
}
|
|
18
|
-
return [...groups].map(([objectId, panels]) => ({ objectId, panels: [...panels
|
|
18
|
+
return [...groups].map(([objectId, panels]) => ({ objectId, panels: [...panels.filter((panel) => panel.timeUtcMs !== undefined).sort((a, b) => a.timeUtcMs - b.timeUtcMs), ...panels.filter((panel) => panel.timeUtcMs === undefined)] }));
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* The panel a press on a shared marker opens. When one of the group's panels is open, the next one in time order
|
|
@@ -28,7 +28,7 @@ export function panelForMarkerPress(group, timeUtcMs, openPanelId) {
|
|
|
28
28
|
if (openIndex >= 0)
|
|
29
29
|
return panels[(openIndex + 1) % panels.length].panelId;
|
|
30
30
|
let reached = 0;
|
|
31
|
-
panels.forEach((panel, index) => { if (panel.timeUtcMs <= timeUtcMs)
|
|
31
|
+
panels.forEach((panel, index) => { if (panel.timeUtcMs !== undefined && panel.timeUtcMs <= timeUtcMs)
|
|
32
32
|
reached = index; });
|
|
33
33
|
return panels[reached].panelId;
|
|
34
34
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { DisplaySwitchItem } from "../shell/DisplaySwitches.js";
|
|
2
2
|
import type { OrbitLook } from "../assets/orbitLook.js";
|
|
3
3
|
import type { BodySetLook } from "./bodySet.js";
|
|
4
|
+
import type { SkyLineSwitches } from "./skyFigures.js";
|
|
4
5
|
/** The display switches a story can place. Each one drives the same state as its Developer-drawer buttons, so the two never disagree. */
|
|
5
|
-
export declare const DISPLAY_SWITCH_IDS: readonly ["orbitLines", "labels", "milkyWay"];
|
|
6
|
-
/** The name of one display switch: "orbitLines", "labels" or "
|
|
6
|
+
export declare const DISPLAY_SWITCH_IDS: readonly ["orbitLines", "labels", "milkyWay", "skyFigures", "skyBoundaries", "ecliptic", "celestialEquator"];
|
|
7
|
+
/** The name of one display switch: "orbitLines", "labels", "milkyWay", "skyFigures", "skyBoundaries", "ecliptic" or "celestialEquator" (a key of `SwitchesInput`). */
|
|
7
8
|
export type DisplaySwitchId = (typeof DISPLAY_SWITCH_IDS)[number];
|
|
8
9
|
/** Where a switch shows: a button in the top bar, a row in the story switch panel opened from the bar, or only in the Developer drawer (where every switch stays). */
|
|
9
10
|
export declare const DISPLAY_SWITCH_PLACES: readonly ["top-bar", "panel", "developer"];
|
|
@@ -43,6 +44,13 @@ export interface SwitchBindings {
|
|
|
43
44
|
readonly on: boolean;
|
|
44
45
|
readonly set: (on: boolean) => void;
|
|
45
46
|
};
|
|
47
|
+
/** The sky lines: which kinds the scene has figures of (the ecliptic and the equator are always there), the state now, and a setter for one. */
|
|
48
|
+
readonly skyLines: {
|
|
49
|
+
readonly figures: boolean;
|
|
50
|
+
readonly boundaries: boolean;
|
|
51
|
+
readonly on: Readonly<SkyLineSwitches>;
|
|
52
|
+
readonly set: (key: keyof SkyLineSwitches, on: boolean) => void;
|
|
53
|
+
};
|
|
46
54
|
readonly labels: {
|
|
47
55
|
readonly objectIds: readonly string[];
|
|
48
56
|
readonly hidden: ReadonlySet<string>;
|
|
@@ -52,7 +60,9 @@ export interface SwitchBindings {
|
|
|
52
60
|
readonly setAnchors: (on: boolean) => void;
|
|
53
61
|
};
|
|
54
62
|
}
|
|
55
|
-
/** The
|
|
63
|
+
/** The sky lines' starting state: the defaults, with a story's `on` laid over the ones it named. */
|
|
64
|
+
export declare function skyLineStart(settings: DisplaySwitchSettings | undefined, defaults: Readonly<SkyLineSwitches>): SkyLineSwitches;
|
|
65
|
+
/** The switches to draw in the top bar and the switch panel: the placed ones the scene has something for, in the order orbit lines, labels, Milky Way, sky figures, sky outlines, ecliptic, celestial equator. */
|
|
56
66
|
export declare function displaySwitchItems(bindings: SwitchBindings): readonly DisplaySwitchItem[];
|
|
57
67
|
/** The settings with every placed switch counted as shown: a host reads and sets a switch placed only in the Developer drawer too. */
|
|
58
68
|
export declare function hostReachable(settings: DisplaySwitchSettings | undefined): DisplaySwitchSettings | undefined;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/** The display switches a story can place. Each one drives the same state as its Developer-drawer buttons, so the two never disagree. */
|
|
2
|
-
export const DISPLAY_SWITCH_IDS = ["orbitLines", "labels", "milkyWay"];
|
|
2
|
+
export const DISPLAY_SWITCH_IDS = ["orbitLines", "labels", "milkyWay", "skyFigures", "skyBoundaries", "ecliptic", "celestialEquator"];
|
|
3
3
|
/** Where a switch shows: a button in the top bar, a row in the story switch panel opened from the bar, or only in the Developer drawer (where every switch stays). */
|
|
4
4
|
export const DISPLAY_SWITCH_PLACES = ["top-bar", "panel", "developer"];
|
|
5
|
-
export const DISPLAY_SWITCH_LABELS = { orbitLines: "Orbit lines", labels: "Labels", milkyWay: "Milky Way" };
|
|
5
|
+
export const DISPLAY_SWITCH_LABELS = { orbitLines: "Orbit lines", labels: "Labels", milkyWay: "Milky Way", skyFigures: "Sky figures", skyBoundaries: "Sky outlines", ecliptic: "Ecliptic", celestialEquator: "Celestial equator" };
|
|
6
6
|
/** Orbit lines are on while the ring, the trailing arc or the moon orbits show: the Developer buttons for any of them keep the switch in step. */
|
|
7
7
|
export function orbitLinesOn(orbit, moonOrbitsOn) {
|
|
8
8
|
return (orbit !== null && (orbit.baseOn || orbit.arcOn)) || moonOrbitsOn === true;
|
|
@@ -27,7 +27,17 @@ function setLabels(bindings, on) {
|
|
|
27
27
|
if (labels.anchorsPresent)
|
|
28
28
|
labels.setAnchors(on);
|
|
29
29
|
}
|
|
30
|
-
/**
|
|
30
|
+
/** One sky-line switch: `applies` says whether the scene has anything of that kind; the state and the toggle are the live sky-line switches'. */
|
|
31
|
+
function skyLineState(bindings, key, applies) {
|
|
32
|
+
const on = bindings.skyLines.on[key];
|
|
33
|
+
return { applies, on, toggle: () => bindings.skyLines.set(key, !on) };
|
|
34
|
+
}
|
|
35
|
+
/** The sky lines' starting state: the defaults, with a story's `on` laid over the ones it named. */
|
|
36
|
+
export function skyLineStart(settings, defaults) {
|
|
37
|
+
const pick = (id, fallback) => settings?.[id]?.on ?? fallback;
|
|
38
|
+
return { figures: pick("skyFigures", defaults.figures), boundaries: pick("skyBoundaries", defaults.boundaries), ecliptic: pick("ecliptic", defaults.ecliptic), celestialEquator: pick("celestialEquator", defaults.celestialEquator) };
|
|
39
|
+
}
|
|
40
|
+
/** The switches to draw in the top bar and the switch panel: the placed ones the scene has something for, in the order orbit lines, labels, Milky Way, sky figures, sky outlines, ecliptic, celestial equator. */
|
|
31
41
|
export function displaySwitchItems(bindings) {
|
|
32
42
|
const { settings } = bindings;
|
|
33
43
|
if (settings === undefined)
|
|
@@ -38,6 +48,10 @@ export function displaySwitchItems(bindings) {
|
|
|
38
48
|
orbitLines: { applies: bindings.orbit.present || bindings.moons.present, on: orbitOn, toggle: () => setOrbitLines(bindings, !orbitOn) },
|
|
39
49
|
labels: { applies: bindings.labels.objectIds.length > 0 || bindings.labels.anchorsPresent, on: labelsNow, toggle: () => setLabels(bindings, !labelsNow) },
|
|
40
50
|
milkyWay: { applies: bindings.sky.present, on: bindings.sky.on, toggle: () => bindings.sky.set(!bindings.sky.on) },
|
|
51
|
+
skyFigures: skyLineState(bindings, "figures", bindings.skyLines.figures),
|
|
52
|
+
skyBoundaries: skyLineState(bindings, "boundaries", bindings.skyLines.boundaries),
|
|
53
|
+
ecliptic: skyLineState(bindings, "ecliptic", true),
|
|
54
|
+
celestialEquator: skyLineState(bindings, "celestialEquator", true),
|
|
41
55
|
};
|
|
42
56
|
return DISPLAY_SWITCH_IDS.flatMap((id) => {
|
|
43
57
|
const place = settings[id]?.place;
|
|
@@ -9,7 +9,7 @@ import { type BodyAsset, type BodyCatalogue } from "../assets/catalogue.js";
|
|
|
9
9
|
import type { SystemComposition } from "../assets/compositions.js";
|
|
10
10
|
import type { BodyVisual } from "../assets/visual.js";
|
|
11
11
|
import type { Metric } from "../shell/metrics.js";
|
|
12
|
-
import type
|
|
12
|
+
import { type ExperienceConfig, type ExperienceObject } from "../shell/experience.js";
|
|
13
13
|
import { type ScaleId } from "../shell/scaleModel.js";
|
|
14
14
|
import type { TrackedBody } from "./mission.js";
|
|
15
15
|
import type { SkySettings } from "../assets/sky.js";
|
|
@@ -17,6 +17,7 @@ import type { LookInput } from "./look.js";
|
|
|
17
17
|
import type { Pictures } from "../assets/pictures.js";
|
|
18
18
|
import { type BodySetLayer } from "./bodySet.js";
|
|
19
19
|
import type { DisplaySwitchSettings } from "./displaySwitches.js";
|
|
20
|
+
import type { SkyFigureLayer } from "./skyFigures.js";
|
|
20
21
|
import type { ViewSettings } from "./views.js";
|
|
21
22
|
/** Generic scene parts an experience opts into. Nothing here names a mission. */
|
|
22
23
|
export type SceneLayerId = "tracked-bodies" | "points" | "sun-centred";
|
|
@@ -204,14 +205,19 @@ export interface ExperienceDefinition {
|
|
|
204
205
|
readonly views?: ViewSettings;
|
|
205
206
|
/** Which direction the camera treats as up (default "equatorial", celestial north; "ecliptic" orbits about the ecliptic pole so the planets' plane reads flat). */
|
|
206
207
|
readonly viewUp?: import("./viewUp.js").ViewUp;
|
|
207
|
-
/**
|
|
208
|
-
|
|
208
|
+
/**
|
|
209
|
+
* The camera view to open on (focus id, azimuth and elevation in degrees, distance in scaled units; or a sky view), or a look-out request whose direction is an id (`scene.camera.lookOut` toward an object or sky figure),
|
|
210
|
+
* which the viewer resolves on the first frame by the same steps as a `setCamera` look-out. Absent: the usual opening. `?view=` overrides it.
|
|
211
|
+
*/
|
|
212
|
+
readonly startView?: import("./sceneCamera.js").OpeningView;
|
|
209
213
|
/** The sky behind the scene (stars and the Milky Way, at infinity). On at full brightness unless this says otherwise; presentation only. */
|
|
210
214
|
readonly sky?: SkySettings;
|
|
211
215
|
/** The looks the scene set (`Scene.setLook`); the page address (when on) overrides them, see `app/look.ts`. Presentation only. */
|
|
212
216
|
readonly look?: LookInput;
|
|
213
217
|
/** Many small bodies drawn as batches (dots with a pixel floor, balls close up, names on demand, orbit lines by family). Absent: none. */
|
|
214
218
|
readonly bodySets?: readonly BodySetLayer[];
|
|
219
|
+
/** Figures and outlines drawn on the sky at infinity (EQJ unit directions). Filled by `prepare` when a star list is needed to place them; the viewer draws after it resolves. Absent: none. */
|
|
220
|
+
readonly skyFigures?: readonly SkyFigureLayer[];
|
|
215
221
|
/** Data to load before the scene mounts (for example the curve-fit chunks of the window). The entry awaits it once. */
|
|
216
222
|
readonly prepare?: () => Promise<void>;
|
|
217
223
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { catalogue as builtInCatalogue, rootBodyId } from "../assets/catalogue.js";
|
|
2
|
+
import { requestObjectId } from "../shell/experience.js";
|
|
2
3
|
import { scaleChoicesFor } from "../shell/scaleModel.js";
|
|
3
4
|
import { validateBodySet } from "./bodySet.js";
|
|
4
5
|
/** The scene's far plane when an experience declares none. */
|
|
@@ -117,8 +118,9 @@ export function initialObjectIdOf(definition) {
|
|
|
117
118
|
const config = experienceWithGroups(definition);
|
|
118
119
|
const objects = config.objects;
|
|
119
120
|
const start = config.cameraPresets.find((preset) => preset.id === config.startCameraPresetId)?.request;
|
|
120
|
-
|
|
121
|
-
|
|
121
|
+
const startId = start === undefined ? undefined : requestObjectId(start);
|
|
122
|
+
if (startId !== undefined && objects.some((object) => object.id === startId))
|
|
123
|
+
return startId;
|
|
122
124
|
const centre = sceneCenterOf(definition);
|
|
123
125
|
return objects.some((object) => object.id === centre) ? centre : objects[0]?.id ?? centre;
|
|
124
126
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CSSProperties } from "react";
|
|
2
|
+
export interface LabelStyle {
|
|
3
|
+
readonly fontFamily: string;
|
|
4
|
+
readonly sizePx: number;
|
|
5
|
+
}
|
|
6
|
+
/** Today's label look: the page's own font (`inherit`) at 12 px. */
|
|
7
|
+
export declare const DEFAULT_LABEL_STYLE: Readonly<LabelStyle>;
|
|
8
|
+
export { LABEL_SIZE_LIMITS } from "../core/lookValues.js";
|
|
9
|
+
/** The label style in force: the look's `labels`, every part not named at its default. */
|
|
10
|
+
export declare function labelStyleOf(look: {
|
|
11
|
+
readonly labels?: Partial<LabelStyle>;
|
|
12
|
+
}): LabelStyle;
|
|
13
|
+
/** The CSS variables that carry a label style on the viewer root. A part at its default sets nothing, so a viewer with the default look carries no variable and the stylesheet's own value (the same one) stands. */
|
|
14
|
+
export declare function labelStyleVars(style?: {
|
|
15
|
+
readonly fontFamily?: string;
|
|
16
|
+
readonly sizePx?: number;
|
|
17
|
+
}): CSSProperties;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Today's label look: the page's own font (`inherit`) at 12 px. */
|
|
2
|
+
export const DEFAULT_LABEL_STYLE = Object.freeze({ fontFamily: "inherit", sizePx: 12 });
|
|
3
|
+
export { LABEL_SIZE_LIMITS } from "../core/lookValues.js";
|
|
4
|
+
/** The label style in force: the look's `labels`, every part not named at its default. */
|
|
5
|
+
export function labelStyleOf(look) {
|
|
6
|
+
return { ...DEFAULT_LABEL_STYLE, ...look.labels };
|
|
7
|
+
}
|
|
8
|
+
/** The CSS variables that carry a label style on the viewer root. A part at its default sets nothing, so a viewer with the default look carries no variable and the stylesheet's own value (the same one) stands. */
|
|
9
|
+
export function labelStyleVars(style = {}) {
|
|
10
|
+
const font = style.fontFamily !== undefined && style.fontFamily !== DEFAULT_LABEL_STYLE.fontFamily;
|
|
11
|
+
const size = style.sizePx !== undefined && style.sizePx !== DEFAULT_LABEL_STYLE.sizePx;
|
|
12
|
+
return { ...(font ? { "--label-font": style.fontFamily } : {}), ...(size ? { "--label-size": `${style.sizePx}px` } : {}) };
|
|
13
|
+
}
|
package/src/app/liveLook.js
CHANGED
|
@@ -3,6 +3,8 @@ import { glowLookOf, markerSettingsOf } from "./bodyDraw.js";
|
|
|
3
3
|
import { featureMinBodyPxOf } from "./FeatureMarkers.js";
|
|
4
4
|
import { resolveLook } from "./look.js";
|
|
5
5
|
import { resolveSkySettings } from "./skyModel.js";
|
|
6
|
+
import { labelStyleOf } from "./labelStyle.js";
|
|
7
|
+
import { skyColoursOf, skyFadeInSecondsOf } from "./skyFigures.js";
|
|
6
8
|
/** The sky settings in force: the experience's own, then the look (the scene's `setLook`, with the address over it). The Milky Way switch's start sits between the two. */
|
|
7
9
|
export function skySettingsOf(definition, look) {
|
|
8
10
|
const settings = resolveSkySettings(definition.sky);
|
|
@@ -30,7 +32,10 @@ export function lookReadOf(controls) {
|
|
|
30
32
|
markerSwapRadiusPx: controls.bodyMarker.minSpherePx,
|
|
31
33
|
featureMinBodyPx: featureMinBodyPxOf({ featureMinBodyPx: controls.featureMinBodyPx }),
|
|
32
34
|
loadFadeSeconds: controls.loadFadeSeconds ?? bootFadeSeconds(),
|
|
35
|
+
skyFadeInSeconds: controls.skyFadeInSeconds,
|
|
33
36
|
desktopPictures: controls.desktopPictures,
|
|
37
|
+
skyLines: { ...controls.skyColours },
|
|
38
|
+
labels: { ...controls.labelStyle },
|
|
34
39
|
};
|
|
35
40
|
}
|
|
36
41
|
/**
|
|
@@ -49,6 +54,9 @@ export function applyLook(controls, definition, glowBase, input) {
|
|
|
49
54
|
controls.bodyMarker = { ...controls.bodyMarker, minSpherePx: markerSettingsOf(look).minSpherePx };
|
|
50
55
|
controls.featureMinBodyPx = featureMinBodyPxOf(look);
|
|
51
56
|
controls.loadFadeSeconds = bootFadeSeconds(look);
|
|
57
|
+
controls.skyColours = skyColoursOf(look);
|
|
58
|
+
controls.skyFadeInSeconds = skyFadeInSecondsOf(look);
|
|
59
|
+
controls.labelStyle = labelStyleOf(look);
|
|
52
60
|
return lookReadOf(controls);
|
|
53
61
|
}
|
|
54
62
|
/** The host's view of the presentation: `items` (read fresh each time) are the display switches the scene placed (those with something to act on), so a switch is read and set exactly as its visible button does. */
|
package/src/app/look.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { LookInput } from "../api/look.js";
|
|
|
7
7
|
export type { LookInput } from "../api/look.js";
|
|
8
8
|
/** The address parameters that set a look. */
|
|
9
9
|
export type LookParam = "stars" | "milkyway" | "milkywaybrightness" | "sky" | "sunglow" | "sunbrightness" | "sunglowscale" | "markerpx" | "featurepx" | "loadfade" | "desktop";
|
|
10
|
-
/** How a look is written: a number in a range, an `on`/`off` switch,
|
|
10
|
+
/** How a look is written: a number in a range, an `on`/`off` switch, a switch the address can only turn off, a CSS colour text or a font-family text. */
|
|
11
11
|
export type LookKind = {
|
|
12
12
|
readonly kind: "range";
|
|
13
13
|
readonly min: number;
|
|
@@ -16,11 +16,15 @@ export type LookKind = {
|
|
|
16
16
|
readonly kind: "onoff";
|
|
17
17
|
} | {
|
|
18
18
|
readonly kind: "offOnly";
|
|
19
|
+
} | {
|
|
20
|
+
readonly kind: "colour";
|
|
21
|
+
} | {
|
|
22
|
+
readonly kind: "font";
|
|
19
23
|
};
|
|
20
|
-
/** One look: where it sits in `LookInput` (`["sunGlow", "sizePx"]` for a nested one), its address parameter and how it is written. */
|
|
24
|
+
/** One look: where it sits in `LookInput` (`["sunGlow", "sizePx"]` for a nested one), its address parameter (null: the look has none, it is set only with `setLook`) and how it is written. */
|
|
21
25
|
export interface LookField {
|
|
22
26
|
readonly path: readonly [string] | readonly [string, string];
|
|
23
|
-
readonly param: LookParam;
|
|
27
|
+
readonly param: LookParam | null;
|
|
24
28
|
readonly spec: LookKind;
|
|
25
29
|
}
|
|
26
30
|
/** Every look. The one table; the order is the order of `LookInput`. */
|
|
@@ -28,8 +32,8 @@ export declare const LOOK_FIELDS: readonly LookField[];
|
|
|
28
32
|
/** The name a look is called in a message: `sunGlow.sizePx`. */
|
|
29
33
|
export declare const lookName: (field: LookField) => string;
|
|
30
34
|
/** The value a look has in `look`, or undefined. */
|
|
31
|
-
export declare function lookValue(look: LookInput, field: LookField): number | boolean | undefined;
|
|
32
|
-
declare function withValue(look: LookInput, field: LookField, value: number | boolean): LookInput;
|
|
35
|
+
export declare function lookValue(look: LookInput, field: LookField): number | boolean | string | undefined;
|
|
36
|
+
declare function withValue(look: LookInput, field: LookField, value: number | boolean | string): LookInput;
|
|
33
37
|
/** Sets a look in a copy of `look` (used by `Scene.setLook` to build the checked look). */
|
|
34
38
|
export declare const lookWith: typeof withValue;
|
|
35
39
|
/** The looks in force: `base` (what the scene set) with the address text laid over it (`search` is empty when the host's `address` option is off). Pure; a live change (T-262) resolves a new base the same way. */
|
package/src/app/look.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { LABEL_SIZE_LIMITS } from "../core/lookValues.js";
|
|
1
2
|
const range = (path, param, min, max) => ({ path, param, spec: { kind: "range", min, max } });
|
|
3
|
+
const colour = (name) => ({ path: ["skyLines", name], param: null, spec: { kind: "colour" } });
|
|
2
4
|
/** Every look. The one table; the order is the order of `LookInput`. */
|
|
3
5
|
export const LOOK_FIELDS = [
|
|
4
6
|
range(["starBrightness"], "stars", 0, 2),
|
|
@@ -11,7 +13,12 @@ export const LOOK_FIELDS = [
|
|
|
11
13
|
range(["markerSwapRadiusPx"], "markerpx", 0, 100),
|
|
12
14
|
range(["featureMinBodyPx"], "featurepx", 0, 2000),
|
|
13
15
|
range(["loadFadeSeconds"], "loadfade", 0, 3),
|
|
16
|
+
range(["skyFadeInSeconds"], null, 0, 3),
|
|
14
17
|
{ path: ["desktopPictures"], param: "desktop", spec: { kind: "onoff" } },
|
|
18
|
+
// Sky line colours and the label font and size have no address parameter (T-296, owner decision): they are set with `setLook` and the Developer drawer only.
|
|
19
|
+
colour("figure"), colour("label"), colour("boundary"), colour("ecliptic"), colour("equator"), colour("traced"), colour("faded"), colour("selected"),
|
|
20
|
+
{ path: ["labels", "fontFamily"], param: null, spec: { kind: "font" } },
|
|
21
|
+
range(["labels", "sizePx"], null, LABEL_SIZE_LIMITS.min, LABEL_SIZE_LIMITS.max),
|
|
15
22
|
];
|
|
16
23
|
/** The name a look is called in a message: `sunGlow.sizePx`. */
|
|
17
24
|
export const lookName = (field) => field.path.join(".");
|
|
@@ -34,10 +41,14 @@ function rawParam(search, param) {
|
|
|
34
41
|
}
|
|
35
42
|
/** What one address parameter says: the value, or undefined when it is absent or unusable (an unusable number warns on the console, never throws). */
|
|
36
43
|
function fromAddress(search, field) {
|
|
44
|
+
if (field.param === null)
|
|
45
|
+
return undefined;
|
|
37
46
|
const raw = rawParam(search, field.param);
|
|
38
47
|
if (raw === null)
|
|
39
48
|
return undefined;
|
|
40
49
|
const { spec } = field;
|
|
50
|
+
if (spec.kind === "colour" || spec.kind === "font")
|
|
51
|
+
return undefined;
|
|
41
52
|
if (spec.kind === "onoff")
|
|
42
53
|
return raw === "on" ? true : raw === "off" ? false : undefined;
|
|
43
54
|
if (spec.kind === "offOnly")
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type SkyView } from "../core/startView.js";
|
|
2
|
+
import type { RenderVector } from "./renderCoordinates.js";
|
|
3
|
+
/** What a camera that stands inside a body carries beyond the orbit angles: the field of view is its zoom. The look direction is the orbit state's azimuth and elevation about the up in force. */
|
|
4
|
+
export interface LookOutState {
|
|
5
|
+
/** Vertical field of view in degrees, within `LOOK_OUT_FOV_RANGE_DEG`. */
|
|
6
|
+
fovDeg: number;
|
|
7
|
+
}
|
|
8
|
+
export declare const LOOK_OUT_FOV_RANGE_DEG: {
|
|
9
|
+
readonly min: 5;
|
|
10
|
+
readonly max: 100;
|
|
11
|
+
};
|
|
12
|
+
export declare const LOOK_OUT_OPENING_FOV_DEG = 60;
|
|
13
|
+
/** The nearest the look-out camera draws: positive, and far inside anything a sky shows. */
|
|
14
|
+
export declare const LOOK_OUT_NEAR = 0.001;
|
|
15
|
+
export declare function clampFov(fovDeg: number): number;
|
|
16
|
+
export declare function clampLookElevation(elevation: number): number;
|
|
17
|
+
/** The angles a look-out pan changes. */
|
|
18
|
+
export interface LookAngles {
|
|
19
|
+
azimuth: number;
|
|
20
|
+
elevation: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Direct manipulation: a drag of `dxPx`, `dyPx` moves the sky with the pointer, so the view turns the other way. One viewport height spans the field of view,
|
|
24
|
+
* which makes a narrow view pan slowly. Azimuth grows leftwards about the up in force, elevation upwards.
|
|
25
|
+
*/
|
|
26
|
+
export declare function panLookOut(angles: LookAngles, fovDeg: number, dxPx: number, dyPx: number, heightPx: number): void;
|
|
27
|
+
/** A wheel or pinch factor above 1 widens the view, below 1 narrows it. */
|
|
28
|
+
export declare function zoomLookOut(look: LookOutState, factor: number): void;
|
|
29
|
+
/** The unit direction at `azimuth` and `elevation` about `up`, given the orbit basis: the one rule the orbit offset and the look direction share. */
|
|
30
|
+
export declare function directionAt(azimuth: number, elevation: number, east: RenderVector, south: RenderVector, up: RenderVector): RenderVector;
|
|
31
|
+
/** The look-out camera as a sky reading: the way it looks (render axes, from the angles about `up`) as J2000 equatorial degrees, rounded the way a link rounds them. */
|
|
32
|
+
export declare function skyViewOf(body: string, azimuth: number, elevation: number, up: RenderVector, fovDeg: number): SkyView;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Look-out camera: standing at a body's centre and turning to look around the sky. Camera-only state; nothing in State is read or written.
|
|
2
|
+
import { orbitBasis } from "./viewUp.js";
|
|
3
|
+
import { SKY_FOV_RANGE_DEG, SKY_OPENING_FOV_DEG } from "../core/startView.js";
|
|
4
|
+
export const LOOK_OUT_FOV_RANGE_DEG = SKY_FOV_RANGE_DEG;
|
|
5
|
+
export const LOOK_OUT_OPENING_FOV_DEG = SKY_OPENING_FOV_DEG;
|
|
6
|
+
/** The nearest the look-out camera draws: positive, and far inside anything a sky shows. */
|
|
7
|
+
export const LOOK_OUT_NEAR = 1e-3;
|
|
8
|
+
const MAX_LOOK_ELEVATION = (89 * Math.PI) / 180;
|
|
9
|
+
/** Azimuth turns faster near the zenith; the pan divides by cos(elevation) down to this floor so a drag stays under the finger without running away at the pole. */
|
|
10
|
+
const MIN_PAN_COS = 0.1;
|
|
11
|
+
export function clampFov(fovDeg) {
|
|
12
|
+
return Math.min(LOOK_OUT_FOV_RANGE_DEG.max, Math.max(LOOK_OUT_FOV_RANGE_DEG.min, fovDeg));
|
|
13
|
+
}
|
|
14
|
+
export function clampLookElevation(elevation) {
|
|
15
|
+
return Math.max(-MAX_LOOK_ELEVATION, Math.min(MAX_LOOK_ELEVATION, elevation));
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Direct manipulation: a drag of `dxPx`, `dyPx` moves the sky with the pointer, so the view turns the other way. One viewport height spans the field of view,
|
|
19
|
+
* which makes a narrow view pan slowly. Azimuth grows leftwards about the up in force, elevation upwards.
|
|
20
|
+
*/
|
|
21
|
+
export function panLookOut(angles, fovDeg, dxPx, dyPx, heightPx) {
|
|
22
|
+
const perPx = ((fovDeg * Math.PI) / 180) / heightPx;
|
|
23
|
+
angles.azimuth += (dxPx * perPx) / Math.max(MIN_PAN_COS, Math.cos(angles.elevation));
|
|
24
|
+
angles.elevation = clampLookElevation(angles.elevation + dyPx * perPx);
|
|
25
|
+
}
|
|
26
|
+
/** A wheel or pinch factor above 1 widens the view, below 1 narrows it. */
|
|
27
|
+
export function zoomLookOut(look, factor) {
|
|
28
|
+
look.fovDeg = clampFov(look.fovDeg * factor);
|
|
29
|
+
}
|
|
30
|
+
/** The unit direction at `azimuth` and `elevation` about `up`, given the orbit basis: the one rule the orbit offset and the look direction share. */
|
|
31
|
+
export function directionAt(azimuth, elevation, east, south, up) {
|
|
32
|
+
const cosEl = Math.cos(elevation);
|
|
33
|
+
const [sa, ca, se] = [Math.sin(azimuth), Math.cos(azimuth), Math.sin(elevation)];
|
|
34
|
+
return [0, 1, 2].map((k) => cosEl * (sa * east[k] + ca * south[k]) + se * up[k]);
|
|
35
|
+
}
|
|
36
|
+
const round2 = (value) => Number(value.toFixed(2));
|
|
37
|
+
/** The look-out camera as a sky reading: the way it looks (render axes, from the angles about `up`) as J2000 equatorial degrees, rounded the way a link rounds them. */
|
|
38
|
+
export function skyViewOf(body, azimuth, elevation, up, fovDeg) {
|
|
39
|
+
const { east, south } = orbitBasis(up);
|
|
40
|
+
const [rx, ry, rz] = directionAt(azimuth, elevation, east, south, up);
|
|
41
|
+
// The inverse of `eqjToRenderVector`: render (x, y, z) is EQJ (x, -z, y).
|
|
42
|
+
const [x, y, z] = [rx, -rz, ry];
|
|
43
|
+
const deg = 180 / Math.PI;
|
|
44
|
+
return {
|
|
45
|
+
lookOut: body,
|
|
46
|
+
raDeg: round2(((Math.atan2(y, x) * deg) % 360 + 360) % 360) % 360,
|
|
47
|
+
decDeg: round2(Math.asin(Math.max(-1, Math.min(1, z))) * deg),
|
|
48
|
+
fovDeg: round2(fovDeg),
|
|
49
|
+
};
|
|
50
|
+
}
|