astraeus 0.9.0 → 0.9.1
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/README.md +87 -27
- package/package.json +1 -1
- package/src/api/assembleScene.js +1 -1
- package/src/api/index.d.ts +1 -1
- package/src/api/planBodies.d.ts +2 -1
- package/src/api/planBodies.js +6 -1
- package/src/api/planPaths.d.ts +2 -0
- package/src/api/planPaths.js +14 -9
- package/src/api/providerPathTimes.d.ts +10 -0
- package/src/api/providerPathTimes.js +109 -0
- package/src/api/scene.d.ts +6 -0
- package/src/api/shownDuring.d.ts +12 -0
- package/src/api/shownDuring.js +30 -0
- package/src/api/story.d.ts +1 -1
- package/src/api/story.js +1 -1
- package/src/app/App.js +33 -16
- package/src/app/App.node.js +33 -16
- package/src/app/CameraController.d.ts +2 -1
- package/src/app/CameraController.js +4 -2
- package/src/app/sceneFrame.d.ts +14 -5
- package/src/app/sceneFrame.js +29 -19
- package/src/app/viewHiding.d.ts +8 -1
- package/src/app/viewHiding.js +23 -0
- package/src/core/pacing.d.ts +38 -6
- package/src/core/pacing.js +141 -21
- package/src/shell/AstraeusShell.d.ts +3 -1
- package/src/shell/AstraeusShell.js +25 -7
- package/src/shell/AstraeusShell.node.js +25 -7
- package/src/shell/ObjectControls.js +1 -1
- package/src/shell/experience.d.ts +7 -0
- package/src/shell/objectModel.d.ts +3 -2
- package/src/shell/objectModel.js +6 -4
package/src/app/sceneFrame.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { drawnRadii } from "./bodyDraw.js";
|
|
2
2
|
import { DEFAULT_BODY_SET_LOOK, familyColorOf } from "./bodySet.js";
|
|
3
|
-
import { applyPacing } from "../core/pacing.js";
|
|
3
|
+
import { applyPacing, stepPacing } from "../core/pacing.js";
|
|
4
4
|
import { poseCamera, resolveCamera } from "./CameraController.js";
|
|
5
5
|
import { DEFAULT_CAMERA_FAR } from "./experienceDefinition.js";
|
|
6
6
|
import { DEFAULT_FEATURE_MIN_BODY_PX } from "./FeatureMarkers.js";
|
|
@@ -15,7 +15,7 @@ import { clampHoverBrightness, HOVER_BRIGHTNESS_DEFAULT, hoverTarget, pickCandid
|
|
|
15
15
|
import { updateSky } from "./sceneSky.js";
|
|
16
16
|
import { labelPositionOf } from "./sceneTargets.js";
|
|
17
17
|
import { skyViewOf } from "./lookOut.js";
|
|
18
|
-
import { hiddenWithLookOut } from "./viewHiding.js";
|
|
18
|
+
import { hiddenWithLookOut, hiddenWithShownSpans } from "./viewHiding.js";
|
|
19
19
|
import { viewFromAngles } from "./viewLink.js";
|
|
20
20
|
import { EQUATORIAL_UP } from "./viewUp.js";
|
|
21
21
|
import { prefersReducedMotion } from "./skyFigures.js";
|
|
@@ -36,14 +36,24 @@ export function viewUpOf(ctx) {
|
|
|
36
36
|
export function bodiesMounted(runtime, refs) {
|
|
37
37
|
return runtime.bodies.every((id) => refs.groups.has(id) && refs.orients.has(id));
|
|
38
38
|
}
|
|
39
|
-
/**
|
|
40
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Stage 0: the time of this frame. While pacing is in charge the clock is first stepped through the frame's real time under the paced rate (so no frame passes over a slow-down); looping playback then wraps inside its window,
|
|
41
|
+
* and other playback stops on the window's edge (a scene with a timeline bar). A wrap or stop lands on the paced rate for its new time at once.
|
|
42
|
+
*/
|
|
43
|
+
export function frameTime(runtime, controls, nowMs = performance.now()) {
|
|
44
|
+
const paced = controls.paceAuto === true && runtime.pacing !== undefined;
|
|
45
|
+
if (paced && controls.pace !== undefined)
|
|
46
|
+
stepPacing(runtime.clock, runtime.pacing, controls.pace, nowMs);
|
|
47
|
+
let moved = false;
|
|
41
48
|
if (controls.loop === true && runtime.loopWindow !== undefined)
|
|
42
|
-
runtime.clock.wrapWithin(runtime.loopWindow);
|
|
49
|
+
moved = runtime.clock.wrapWithin(runtime.loopWindow);
|
|
43
50
|
else if (runtime.stopAtWindow === true && runtime.loopWindow !== undefined)
|
|
44
|
-
runtime.clock.stopWithin(runtime.loopWindow);
|
|
45
|
-
if (
|
|
46
|
-
|
|
51
|
+
moved = runtime.clock.stopWithin(runtime.loopWindow);
|
|
52
|
+
if (paced && (moved || controls.pace === undefined)) {
|
|
53
|
+
if (controls.pace !== undefined)
|
|
54
|
+
delete controls.pace.last;
|
|
55
|
+
applyPacing(runtime.clock, runtime.pacing, controls.pace, nowMs);
|
|
56
|
+
}
|
|
47
57
|
return runtime.clock.now();
|
|
48
58
|
}
|
|
49
59
|
/** Stage 1: brings every view to the time of the frame. Returns the live body-set look. */
|
|
@@ -105,7 +115,7 @@ export function stepAndPoseCamera(ctx, t, placed) {
|
|
|
105
115
|
const reach = liveReach(runtime.cameraReach, policy, camera.aspect);
|
|
106
116
|
const focusBody = stepCameraTarget({ camState: orbit, controls, targets, frame, catalogue, reach, fovDeg: orbit.lookOut === null ? camera.fov : CAMERA_FOV_DEG, viewUp, firstFrame, previousUp: state.lastUp });
|
|
107
117
|
state.lastUp = viewUp;
|
|
108
|
-
resolveCamera(orbit, cameraTargetAbsolute(orbit, targets), ctx.origin, ctx.delta, REBASE_THRESHOLD, viewUp);
|
|
118
|
+
resolveCamera(orbit, cameraTargetAbsolute(orbit, targets), ctx.origin, ctx.delta, REBASE_THRESHOLD, viewUp, prefersReducedMotion());
|
|
109
119
|
placeBodies(ctx.assets, placed.composed.states, ctx.bodyRefs, policy, ctx.origin);
|
|
110
120
|
const baseFar = reach.far ?? DEFAULT_CAMERA_FAR;
|
|
111
121
|
// Looking out, the camera stands at a body, so a far plane sized for orbit framing could cut off the Sun or any body beyond it: reach everything placed.
|
|
@@ -188,13 +198,13 @@ export function placeViews(ctx, t, placed, setLook) {
|
|
|
188
198
|
publishPointsData(canvas, views.groupViews, camera, views.bodySetViews);
|
|
189
199
|
return hoverGain;
|
|
190
200
|
}
|
|
191
|
-
/** What this frame hides: the view's hidden ids, and the body the camera stands inside while looking out (the one hidden-set path, read by the visibility, label and tap stages). */
|
|
192
|
-
export function hiddenOf(ctx) {
|
|
193
|
-
return hiddenWithLookOut(ctx.controls.viewHidden, ctx.orbit.lookOut === null ? null : ctx.orbit.focus);
|
|
201
|
+
/** What this frame hides: the view's hidden ids, the objects not shown at clock time `t` (`shownDuring`; none when `t` is not given), and the body the camera stands inside while looking out (the one hidden-set path, read by the visibility, label and tap stages). */
|
|
202
|
+
export function hiddenOf(ctx, t) {
|
|
203
|
+
return hiddenWithLookOut(hiddenWithShownSpans(ctx.controls.viewHidden, ctx.controls.labelObjects, t), ctx.orbit.lookOut === null ? null : ctx.orbit.focus);
|
|
194
204
|
}
|
|
195
205
|
/** Stage 5b: shows or hides each drawn group by the current view's hidden ids (bodies, paths, point groups, body sets). One set, read here; nothing is rebuilt. */
|
|
196
|
-
export function applyViewVisibility(ctx) {
|
|
197
|
-
const hidden = hiddenOf(ctx)?.objects;
|
|
206
|
+
export function applyViewVisibility(ctx, t) {
|
|
207
|
+
const hidden = hiddenOf(ctx, t)?.objects;
|
|
198
208
|
const { views, bodyRefs } = ctx;
|
|
199
209
|
const show = (id, group) => { group.visible = hidden?.has(id) !== true; };
|
|
200
210
|
for (const [id, group] of bodyRefs.groups)
|
|
@@ -221,9 +231,9 @@ export function featureHostOf(assets, parts, id, policy) {
|
|
|
221
231
|
return sphere === undefined || asset === undefined ? null : { sphere, radius: drawnRadii(asset.definition, policy).equatorial };
|
|
222
232
|
}
|
|
223
233
|
/** What the labels and taps see under the current view: the objects and body sets it shows, and the label-hidden ids with the view's own added. Allocates only when a view hides something. */
|
|
224
|
-
function shownUnderView(ctx) {
|
|
234
|
+
export function shownUnderView(ctx, t) {
|
|
225
235
|
const { controls, views } = ctx;
|
|
226
|
-
const hidden = hiddenOf(ctx)?.objects;
|
|
236
|
+
const hidden = hiddenOf(ctx, t)?.objects;
|
|
227
237
|
if (hidden === undefined || hidden.size === 0)
|
|
228
238
|
return { objects: controls.labelObjects, bodySetViews: views.bodySetViews, hiddenLabels: controls.hiddenLabels };
|
|
229
239
|
return {
|
|
@@ -239,7 +249,7 @@ export function updateOverlays(ctx, t, step, hoverGain) {
|
|
|
239
249
|
publishBodyData(canvas, bodyScreens);
|
|
240
250
|
layers.anchorLabels.current?.update(controls.showAnchorLabels, camera, size.width, size.height);
|
|
241
251
|
const positionFor = (id) => labelPositionOf(step.targets, id);
|
|
242
|
-
const shown = shownUnderView(ctx);
|
|
252
|
+
const shown = shownUnderView(ctx, t);
|
|
243
253
|
layers.sceneLabels.current?.update(positionFor, camera, size.width, size.height, origin, controls.selectedObjectId, shown.hiddenLabels, { on: controls.skyLines, labelColor: controls.skyColours.label, selectedColor: controls.skyColours.selected, opacity: (id) => ctx.views.skyFiguresView.labelOpacity(id), distance: 0.5 * (camera.near + camera.far) });
|
|
244
254
|
state.pickables = pickCandidatesOf({ objects: shown.objects, bodyIdFor: ctx.bodyIdFor, bodyScreens, widthPx: size.width, heightPx: size.height, labelRects: layers.sceneLabels.current?.shownRects, canvas, bodySetViews: shown.bodySetViews });
|
|
245
255
|
// Sky figures are projected only when a tap asks, from this frame's camera and shown names (no per-frame work).
|
|
@@ -248,7 +258,7 @@ export function updateOverlays(ctx, t, step, hoverGain) {
|
|
|
248
258
|
canvas.style.cursor = hover === null ? "" : "pointer";
|
|
249
259
|
canvas.dataset.pickHover = hover ?? "";
|
|
250
260
|
layers.sceneLabels.current?.setHover(hover, hoverGain);
|
|
251
|
-
layers.storyMarkers.current?.update(positionFor, camera, size.width, size.height, origin, controls.openStoryPanelId ?? null, t, hiddenOf(ctx));
|
|
261
|
+
layers.storyMarkers.current?.update(positionFor, camera, size.width, size.height, origin, controls.openStoryPanelId ?? null, t, hiddenOf(ctx, t));
|
|
252
262
|
const featureReadout = layers.featureMarkers.current?.update((id) => featureHostOf(ctx.assets, ctx.bodyRefs.parts, id, controls.policy), camera, camera.fov, size.width, size.height, controls.openFeatureKey ?? null, controls.featureMinBodyPx ?? DEFAULT_FEATURE_MIN_BODY_PX);
|
|
253
263
|
if (featureReadout !== null && featureReadout !== undefined)
|
|
254
264
|
canvas.dataset.featureMarkers = JSON.stringify(featureReadout);
|
|
@@ -346,7 +356,7 @@ export function runFrame(ctx) {
|
|
|
346
356
|
publishCanvasReadouts(ctx);
|
|
347
357
|
placeSkyFigures(ctx);
|
|
348
358
|
advanceSkyTraces(ctx);
|
|
349
|
-
applyViewVisibility(ctx);
|
|
359
|
+
applyViewVisibility(ctx, t);
|
|
350
360
|
const hoverGain = placeViews(ctx, t, placed, setLook);
|
|
351
361
|
updateOverlays(ctx, t, step, hoverGain);
|
|
352
362
|
placeLightsAndReadout(ctx, t, placed);
|
package/src/app/viewHiding.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ExperienceConfig } from "../shell/experience.js";
|
|
1
|
+
import type { ExperienceConfig, ExperienceObject } from "../shell/experience.js";
|
|
2
2
|
import type { ResolvedView, ViewSettings } from "./views.js";
|
|
3
3
|
/** The ids the current view hides: objects (bodies, paths, groups) and story panels. Empty sets: everything shows. */
|
|
4
4
|
export interface ViewHidden {
|
|
@@ -13,3 +13,10 @@ export declare function hiddenByView(settings: ViewSettings | undefined, view: R
|
|
|
13
13
|
export declare function experienceInView(experience: ExperienceConfig, settings: ViewSettings | undefined, view: ResolvedView | undefined): ExperienceConfig;
|
|
14
14
|
/** `hidden` with the body the camera stands inside added while it looks out. The same object when nothing is added, so a normal frame allocates nothing. */
|
|
15
15
|
export declare function hiddenWithLookOut(hidden: ViewHidden | undefined, body: string | null): ViewHidden | undefined;
|
|
16
|
+
/** Whether `object` is shown at `timeUtcMs`: `startUtcMs <= t < endUtcMs`, an absent end unbounded, no span always shown (`shownDuring`). The one rule, so an object that ends at T and one that starts at T never both show or both hide. */
|
|
17
|
+
export declare function shownAt(object: Pick<ExperienceObject, "shownDuring">, timeUtcMs: number): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* `hidden` with every object not shown at `timeUtcMs` added, and what belongs to one (`partOf`: a body's orbit line) with it. The same object when no object has a span or
|
|
20
|
+
* every span shows, so a frame without `shownDuring` allocates nothing. The one place the time-aware hidden set is built; the frame's `hiddenOf` calls it.
|
|
21
|
+
*/
|
|
22
|
+
export declare function hiddenWithShownSpans(hidden: ViewHidden | undefined, objects: readonly ExperienceObject[] | undefined, timeUtcMs: number | undefined): ViewHidden | undefined;
|
package/src/app/viewHiding.js
CHANGED
|
@@ -41,3 +41,26 @@ export function hiddenWithLookOut(hidden, body) {
|
|
|
41
41
|
return hidden;
|
|
42
42
|
return { objects: new Set([...(hidden?.objects ?? []), body]), panels: hidden?.panels ?? new Set() };
|
|
43
43
|
}
|
|
44
|
+
/** Whether `object` is shown at `timeUtcMs`: `startUtcMs <= t < endUtcMs`, an absent end unbounded, no span always shown (`shownDuring`). The one rule, so an object that ends at T and one that starts at T never both show or both hide. */
|
|
45
|
+
export function shownAt(object, timeUtcMs) {
|
|
46
|
+
const span = object.shownDuring;
|
|
47
|
+
return span === undefined || ((span.startUtcMs === undefined || span.startUtcMs <= timeUtcMs) && (span.endUtcMs === undefined || timeUtcMs < span.endUtcMs));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* `hidden` with every object not shown at `timeUtcMs` added, and what belongs to one (`partOf`: a body's orbit line) with it. The same object when no object has a span or
|
|
51
|
+
* every span shows, so a frame without `shownDuring` allocates nothing. The one place the time-aware hidden set is built; the frame's `hiddenOf` calls it.
|
|
52
|
+
*/
|
|
53
|
+
export function hiddenWithShownSpans(hidden, objects, timeUtcMs) {
|
|
54
|
+
if (objects === undefined || timeUtcMs === undefined)
|
|
55
|
+
return hidden;
|
|
56
|
+
let ids;
|
|
57
|
+
for (const object of objects)
|
|
58
|
+
if (!shownAt(object, timeUtcMs))
|
|
59
|
+
(ids ??= new Set(hidden?.objects)).add(object.id);
|
|
60
|
+
if (ids === undefined)
|
|
61
|
+
return hidden;
|
|
62
|
+
for (const object of objects)
|
|
63
|
+
if (object.partOf !== undefined && ids.has(object.partOf))
|
|
64
|
+
ids.add(object.id);
|
|
65
|
+
return { objects: ids, panels: hidden?.panels ?? new Set() };
|
|
66
|
+
}
|
package/src/core/pacing.d.ts
CHANGED
|
@@ -32,15 +32,19 @@ export declare function zonesInView<Z extends EventZone>(zones: readonly Z[], sh
|
|
|
32
32
|
* Span zones carry no event and never count. A pure function of its arguments.
|
|
33
33
|
*/
|
|
34
34
|
export declare function activeEventZones(zones: readonly EventZone[], shown: ShownEvents, timeUtcMs: number): readonly string[];
|
|
35
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* A scene's pacing: the rate outside every zone and its zones. Faster spans (zones with no event) set the cruise over the base and the faster wins where they meet; slower spans and event rules ease down from the cruise, and where they overlap or their ramps meet the slowest
|
|
37
|
+
* speed any one of them alone would give wins, whatever order they are listed in.
|
|
38
|
+
*/
|
|
36
39
|
export interface Pacing {
|
|
37
40
|
readonly baseRate: number;
|
|
38
41
|
readonly zones: readonly PaceZone[];
|
|
39
42
|
}
|
|
40
43
|
/**
|
|
41
|
-
* The playback rate at `timeUtcMs
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
+
* The playback rate at `timeUtcMs`, all blends in log space by the zone weight. The cruise is the base, raised to the fastest of what each span faster than the base gives alone (the faster wins where such spans meet).
|
|
45
|
+
* The rate is the slowest of the cruise and of what each slower span (rate at or under the base) and each event rule touching that time gives easing from the cruise toward its rate (the slowest wins where they meet; a piece
|
|
46
|
+
* whose blend is faster than the cruise changes nothing). Each term equals its underlying value where its weight is 0, so the rate is continuous at every zone and ramp edge, and it does not depend on the order of the zones.
|
|
47
|
+
* Untouched, it is exactly the base. A pure function of its arguments: nothing about the State changes.
|
|
44
48
|
*/
|
|
45
49
|
export declare function pacedRate(pacing: Pacing, timeUtcMs: number, shown?: ShownEvents): number;
|
|
46
50
|
/** How long, in real milliseconds, a change of the paced rate that comes from a view switch takes to ease in. */
|
|
@@ -50,10 +54,38 @@ export interface PaceView {
|
|
|
50
54
|
shown?: ShownEvents;
|
|
51
55
|
ease?: {
|
|
52
56
|
readonly fromRate: number;
|
|
53
|
-
readonly startMs: number;
|
|
57
|
+
readonly startMs: number; /** log(fromRate) - log(paced rate at the switch): the change the switch itself caused; set on first use. */
|
|
58
|
+
k0?: number;
|
|
59
|
+
};
|
|
60
|
+
/** Where `stepPacing` left the clock: its time and rate, and the real time it did so. Absent until the first step, and cleared by a seek or any other move of the clock the step did not make. */
|
|
61
|
+
last?: {
|
|
62
|
+
readonly timeUtcMs: number;
|
|
63
|
+
readonly rate: number;
|
|
64
|
+
readonly nowMs: number;
|
|
54
65
|
};
|
|
55
66
|
}
|
|
56
67
|
/** Starts the ease from the clock's present rate; the next `applyPacing` calls blend from it to the paced rate over `PACE_EASE_MS`. */
|
|
57
68
|
export declare function startPaceEase(view: PaceView, fromRate: number, nowMs: number): void;
|
|
58
|
-
/**
|
|
69
|
+
/** The ease's own change, fixed once at the switch (the first time it is read, at the switch's time): log(start rate) minus log(the new view's paced rate there). */
|
|
70
|
+
export declare function easeShift(view: PaceView, timeUtcMs: number, pacing: Pacing): number;
|
|
71
|
+
/** Sets the clock to the paced rate for its current time (skipped when it already runs at it); mid-ease the switch's own change decays over it: the paced shape times exp(k0 * (1 - weight)), so a zone reached during the ease still slows playback. */
|
|
59
72
|
export declare function applyPacing(clock: SimulationClock, pacing: Pacing, view?: PaceView, nowMs?: number): void;
|
|
73
|
+
/** The most sub-steps one `pacedAdvance` call takes; real time left over after them is dropped, so a frame that long (a tab left hidden) slows the clock rather than skipping a zone. */
|
|
74
|
+
export declare const MAX_PACE_STEPS = 4096;
|
|
75
|
+
/** A view-switch ease as `pacedAdvance` reads it: the switch's own change k0 (see `easeShift`) and how far into its `PACE_EASE_MS` it already is, in real milliseconds, when the advance begins. */
|
|
76
|
+
export interface AdvanceEase {
|
|
77
|
+
readonly k0: number;
|
|
78
|
+
readonly elapsedMs: number;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The time `realElapsedMs` of real time after `fromUtcMs` when the clock runs at `pacedRate` throughout (`direction` -1 runs it backward): the rate is integrated, not read once, so a long frame still slows down
|
|
82
|
+
* through every zone and ramp it crosses. Each sub-step stops at the next zone or ramp edge, covers at most 1/32 of a ramp, and is timed by the trapezoid rule on the rates at its two ends (the far one a millisecond short).
|
|
83
|
+
* With an `ease` (a view switch changing the rate) the rate integrated is the eased one, and a sub-step also covers at most 1/32 of the ease's real time while it runs.
|
|
84
|
+
* At most `MAX_PACE_STEPS` sub-steps; the result is a whole millisecond. A pure function of its arguments.
|
|
85
|
+
*/
|
|
86
|
+
export declare function pacedAdvance(pacing: Pacing, fromUtcMs: number, realElapsedMs: number, shown?: ShownEvents, direction?: 1 | -1, ease?: AdvanceEase): number;
|
|
87
|
+
/**
|
|
88
|
+
* One pacing step per frame: moves the clock from where the last step left it by `pacedAdvance` over the real time since, then sets the paced rate for the new time (`applyPacing`'s job). Falls back to `applyPacing`
|
|
89
|
+
* (one rate for the frame) on the first step, while paused, or when the clock was moved or re-rated since the last step. The clock is moved through its public `seek` and `setRate`.
|
|
90
|
+
*/
|
|
91
|
+
export declare function stepPacing(clock: SimulationClock, pacing: Pacing, view: PaceView, nowMs?: number): void;
|
package/src/core/pacing.js
CHANGED
|
@@ -33,34 +33,59 @@ export function activeEventZones(zones, shown, timeUtcMs) {
|
|
|
33
33
|
}
|
|
34
34
|
return ids;
|
|
35
35
|
}
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
function
|
|
39
|
-
let
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
const smooth = (x) => x * x * (3 - 2 * x);
|
|
37
|
+
const layered = new WeakMap();
|
|
38
|
+
function layersOf(zones) {
|
|
39
|
+
let layers = layered.get(zones);
|
|
40
|
+
if (layers === undefined) {
|
|
41
|
+
layers = { spans: zones.filter((zone) => zone.eventId === undefined), rules: zones.filter((zone) => zone.eventId !== undefined) };
|
|
42
|
+
layered.set(zones, layers);
|
|
43
43
|
}
|
|
44
|
-
return
|
|
44
|
+
return layers;
|
|
45
|
+
}
|
|
46
|
+
/** The weight of `zone` at `timeUtcMs`: 1 inside it, falling to 0 over its ramp (smoothstep). */
|
|
47
|
+
function zoneWeight(zone, timeUtcMs) {
|
|
48
|
+
const distance = timeUtcMs < zone.fromUtcMs ? zone.fromUtcMs - timeUtcMs : timeUtcMs > zone.toUtcMs ? timeUtcMs - zone.toUtcMs : 0;
|
|
49
|
+
return distance === 0 ? 1 : distance >= zone.rampMs ? 0 : smooth(1 - distance / zone.rampMs);
|
|
45
50
|
}
|
|
46
|
-
const smooth = (x) => x * x * (3 - 2 * x);
|
|
47
51
|
/**
|
|
48
|
-
* The playback rate at `timeUtcMs
|
|
49
|
-
*
|
|
50
|
-
*
|
|
52
|
+
* The playback rate at `timeUtcMs`, all blends in log space by the zone weight. The cruise is the base, raised to the fastest of what each span faster than the base gives alone (the faster wins where such spans meet).
|
|
53
|
+
* The rate is the slowest of the cruise and of what each slower span (rate at or under the base) and each event rule touching that time gives easing from the cruise toward its rate (the slowest wins where they meet; a piece
|
|
54
|
+
* whose blend is faster than the cruise changes nothing). Each term equals its underlying value where its weight is 0, so the rate is continuous at every zone and ramp edge, and it does not depend on the order of the zones.
|
|
55
|
+
* Untouched, it is exactly the base. A pure function of its arguments: nothing about the State changes.
|
|
51
56
|
*/
|
|
52
57
|
export function pacedRate(pacing, timeUtcMs, shown) {
|
|
53
|
-
|
|
58
|
+
const { spans, rules } = layersOf(pacing.zones);
|
|
59
|
+
const logBase = Math.log(pacing.baseRate);
|
|
54
60
|
let touched = false;
|
|
55
|
-
|
|
61
|
+
let logCruise = logBase;
|
|
62
|
+
for (const zone of spans) {
|
|
63
|
+
if (zone.rate <= pacing.baseRate)
|
|
64
|
+
continue;
|
|
65
|
+
const weight = zoneWeight(zone, timeUtcMs);
|
|
66
|
+
if (weight > 0) {
|
|
67
|
+
touched = true;
|
|
68
|
+
logCruise = Math.max(logCruise, logBase + (Math.log(zone.rate) - logBase) * weight);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
let logRate = logCruise;
|
|
72
|
+
for (const zone of spans) {
|
|
73
|
+
if (zone.rate > pacing.baseRate)
|
|
74
|
+
continue;
|
|
75
|
+
const weight = zoneWeight(zone, timeUtcMs);
|
|
76
|
+
if (weight > 0) {
|
|
77
|
+
touched = true;
|
|
78
|
+
logRate = Math.min(logRate, logCruise + (Math.log(zone.rate) - logCruise) * weight);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
for (const zone of rules) {
|
|
56
82
|
if (!zoneInView(zone, shown))
|
|
57
83
|
continue;
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
if (weight > 0)
|
|
84
|
+
const weight = zoneWeight(zone, timeUtcMs);
|
|
85
|
+
if (weight > 0) {
|
|
61
86
|
touched = true;
|
|
62
|
-
|
|
63
|
-
|
|
87
|
+
logRate = Math.min(logRate, logCruise + (Math.log(zone.rate) - logCruise) * weight);
|
|
88
|
+
}
|
|
64
89
|
}
|
|
65
90
|
return touched ? Math.exp(logRate) : pacing.baseRate; // untouched: exactly the base, not its log round trip
|
|
66
91
|
}
|
|
@@ -70,7 +95,13 @@ export const PACE_EASE_MS = 1000;
|
|
|
70
95
|
export function startPaceEase(view, fromRate, nowMs) {
|
|
71
96
|
view.ease = { fromRate, startMs: nowMs };
|
|
72
97
|
}
|
|
73
|
-
/**
|
|
98
|
+
/** The ease's own change, fixed once at the switch (the first time it is read, at the switch's time): log(start rate) minus log(the new view's paced rate there). */
|
|
99
|
+
export function easeShift(view, timeUtcMs, pacing) {
|
|
100
|
+
const ease = view.ease;
|
|
101
|
+
ease.k0 ??= Math.log(ease.fromRate) - Math.log(pacedRate(pacing, timeUtcMs, view.shown));
|
|
102
|
+
return ease.k0;
|
|
103
|
+
}
|
|
104
|
+
/** Sets the clock to the paced rate for its current time (skipped when it already runs at it); mid-ease the switch's own change decays over it: the paced shape times exp(k0 * (1 - weight)), so a zone reached during the ease still slows playback. */
|
|
74
105
|
export function applyPacing(clock, pacing, view, nowMs = performance.now()) {
|
|
75
106
|
let rate = pacedRate(pacing, clock.now(), view?.shown);
|
|
76
107
|
const ease = view?.ease;
|
|
@@ -79,8 +110,97 @@ export function applyPacing(clock, pacing, view, nowMs = performance.now()) {
|
|
|
79
110
|
if (progress >= 1)
|
|
80
111
|
delete view.ease;
|
|
81
112
|
else if (progress >= 0)
|
|
82
|
-
rate = Math.exp(Math.log(
|
|
113
|
+
rate = Math.exp(Math.log(rate) + easeShift(view, clock.now(), pacing) * (1 - smooth(progress)));
|
|
83
114
|
}
|
|
84
115
|
if (rate !== clock.rate)
|
|
85
116
|
clock.setRate(rate);
|
|
86
117
|
}
|
|
118
|
+
/** The most sub-steps one `pacedAdvance` call takes; real time left over after them is dropped, so a frame that long (a tab left hidden) slows the clock rather than skipping a zone. */
|
|
119
|
+
export const MAX_PACE_STEPS = 4096;
|
|
120
|
+
/** A sub-step inside a ramp covers at most this part of the ramp's simulated length. */
|
|
121
|
+
const RAMP_STEP_FRACTION = 1 / 32;
|
|
122
|
+
/** The longest simulated distance a sub-step from `t` may cover in `direction`: to the next zone or ramp edge, and a fraction of the ramp while inside one. */
|
|
123
|
+
function stepCap(zones, t, direction) {
|
|
124
|
+
let cap = Infinity;
|
|
125
|
+
for (const zone of zones) {
|
|
126
|
+
const edges = [zone.fromUtcMs - zone.rampMs, zone.fromUtcMs, zone.toUtcMs, zone.toUtcMs + zone.rampMs];
|
|
127
|
+
for (const edge of edges) {
|
|
128
|
+
const distance = direction * (edge - t);
|
|
129
|
+
if (distance > 0)
|
|
130
|
+
cap = Math.min(cap, distance);
|
|
131
|
+
}
|
|
132
|
+
if (zone.rampMs > 0) {
|
|
133
|
+
for (const [lo, hi] of [[edges[0], edges[1]], [edges[2], edges[3]]]) {
|
|
134
|
+
const inside = direction === 1 ? t >= lo && t < hi : t > lo && t <= hi;
|
|
135
|
+
if (inside)
|
|
136
|
+
cap = Math.min(cap, zone.rampMs * RAMP_STEP_FRACTION);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return cap;
|
|
141
|
+
}
|
|
142
|
+
/** A sub-step inside a running ease covers at most this much real time, so the eased rate is read finely enough. */
|
|
143
|
+
const EASE_STEP_MS = PACE_EASE_MS / 32;
|
|
144
|
+
/** The rate the clock runs at: the paced rate at `t`, with the ease's decaying change laid over its shape while the ease runs (as `applyPacing` does), `usedMs` of real time into the advance. */
|
|
145
|
+
function advanceRate(pacing, t, shown, ease, usedMs) {
|
|
146
|
+
const rate = pacedRate(pacing, t, shown);
|
|
147
|
+
if (ease === undefined)
|
|
148
|
+
return rate;
|
|
149
|
+
const progress = (ease.elapsedMs + usedMs) / PACE_EASE_MS;
|
|
150
|
+
if (progress >= 1 || progress < 0)
|
|
151
|
+
return rate;
|
|
152
|
+
return Math.exp(Math.log(rate) + ease.k0 * (1 - smooth(progress)));
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* The time `realElapsedMs` of real time after `fromUtcMs` when the clock runs at `pacedRate` throughout (`direction` -1 runs it backward): the rate is integrated, not read once, so a long frame still slows down
|
|
156
|
+
* through every zone and ramp it crosses. Each sub-step stops at the next zone or ramp edge, covers at most 1/32 of a ramp, and is timed by the trapezoid rule on the rates at its two ends (the far one a millisecond short).
|
|
157
|
+
* With an `ease` (a view switch changing the rate) the rate integrated is the eased one, and a sub-step also covers at most 1/32 of the ease's real time while it runs.
|
|
158
|
+
* At most `MAX_PACE_STEPS` sub-steps; the result is a whole millisecond. A pure function of its arguments.
|
|
159
|
+
*/
|
|
160
|
+
export function pacedAdvance(pacing, fromUtcMs, realElapsedMs, shown, direction = 1, ease) {
|
|
161
|
+
const zones = zonesInView(pacing.zones, shown);
|
|
162
|
+
let t = fromUtcMs;
|
|
163
|
+
let left = realElapsedMs;
|
|
164
|
+
for (let step = 0; step < MAX_PACE_STEPS && left > 0; step += 1) {
|
|
165
|
+
const used = realElapsedMs - left;
|
|
166
|
+
const easing = ease !== undefined && ease.elapsedMs + used >= 0 && ease.elapsedMs + used < PACE_EASE_MS;
|
|
167
|
+
const startRate = advanceRate(pacing, t, shown, ease, used);
|
|
168
|
+
const length = Math.min(stepCap(zones, t, direction), startRate * Math.min(left, easing ? EASE_STEP_MS : Infinity));
|
|
169
|
+
const end = t + direction * length;
|
|
170
|
+
const endUsed = used + Math.min(left, length / startRate); // the real time the step takes if the rate stayed as at its start
|
|
171
|
+
const endRate = advanceRate(pacing, end - direction * Math.min(1, length / 2), shown, ease, endUsed); // a millisecond short of the end, so a jump of rate at a hard edge is not read early
|
|
172
|
+
const needed = (length * (1 / startRate + 1 / endRate)) / 2; // trapezoid: real time is the mean of the reciprocal rates times the distance
|
|
173
|
+
if (needed <= left) {
|
|
174
|
+
t = end;
|
|
175
|
+
left -= needed;
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
t += (direction * length * left) / needed;
|
|
179
|
+
left = 0;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return Math.round(t);
|
|
183
|
+
}
|
|
184
|
+
/** Real-time slack, in milliseconds, between the clock's own advance and the real time `stepPacing` measured before the move is taken as someone else's (a seek). */
|
|
185
|
+
const STEP_SLACK_MS = 5;
|
|
186
|
+
/**
|
|
187
|
+
* One pacing step per frame: moves the clock from where the last step left it by `pacedAdvance` over the real time since, then sets the paced rate for the new time (`applyPacing`'s job). Falls back to `applyPacing`
|
|
188
|
+
* (one rate for the frame) on the first step, while paused, or when the clock was moved or re-rated since the last step. The clock is moved through its public `seek` and `setRate`.
|
|
189
|
+
*/
|
|
190
|
+
export function stepPacing(clock, pacing, view, nowMs = performance.now()) {
|
|
191
|
+
const last = view.last;
|
|
192
|
+
const realMs = last === undefined ? 0 : nowMs - last.nowMs;
|
|
193
|
+
const clockMs = last === undefined ? 0 : (clock.now() - last.timeUtcMs) / last.rate;
|
|
194
|
+
const continuous = last !== undefined && clock.playing && clock.rate === last.rate && realMs > 0 && Math.abs(clockMs - realMs) <= STEP_SLACK_MS + 2 / last.rate;
|
|
195
|
+
if (continuous) {
|
|
196
|
+
const ease = view.ease === undefined ? undefined : { k0: easeShift(view, last.timeUtcMs, pacing), elapsedMs: last.nowMs - view.ease.startMs };
|
|
197
|
+
const to = pacedAdvance(pacing, last.timeUtcMs, realMs, view.shown, 1, ease);
|
|
198
|
+
if (to !== clock.now())
|
|
199
|
+
clock.seek(to);
|
|
200
|
+
}
|
|
201
|
+
applyPacing(clock, pacing, view, nowMs);
|
|
202
|
+
if (clock.playing)
|
|
203
|
+
view.last = { timeUtcMs: clock.now(), rate: clock.rate, nowMs };
|
|
204
|
+
else
|
|
205
|
+
delete view.last;
|
|
206
|
+
}
|
|
@@ -32,6 +32,8 @@ interface Props {
|
|
|
32
32
|
readonly onTurnToFigure?: (id: string) => void;
|
|
33
33
|
/** Holds the camera where it is, its target fixed in the scene (a view's `stay` rule); a later camera request replaces it. */
|
|
34
34
|
readonly onCameraHold?: () => void;
|
|
35
|
+
/** Told the clock time as it moves, so the app can hold a camera whose target (named by a host or a story panel, not a preset) is no longer shown. */
|
|
36
|
+
readonly onTimeShown?: (timeUtcMs: number) => void;
|
|
35
37
|
/** True when the host has set the camera since the last view switch: that call answers the switch, so the view's own camera rule does not replace it. */
|
|
36
38
|
readonly hostCameraSet?: () => boolean;
|
|
37
39
|
/** Filled with the shell's story seek note, so a host's time jump re-bases the panel crossing check exactly as a visitor's seek does. */
|
|
@@ -104,5 +106,5 @@ interface Props {
|
|
|
104
106
|
readonly children: ReactNode;
|
|
105
107
|
}
|
|
106
108
|
/** Canvas-first layout shared by astronomy experiences. Scene and diagnostics stay app-owned. */
|
|
107
|
-
export declare function AstraeusShell({ experience, snapshot, developerMode, onDeveloperModeChange, onTogglePlayback, onRateChange, paceAuto, onSeek, onCameraRequest, onTurnToFigure, onCameraHold, hostCameraSet, storySeekNote, onSelectionChange, scaleId, onScaleChange, scaleChoices, switcher, displaySwitches, viewChoice, viewCamera, metricsFor, developerTools, storyPanelSettings, timelineGlow, phoneLayout, labelStyle, highlightedFamily, onHighlightFamily, onSetPlaying, panelRequest, onOpenPanelChange, featureRequest, onOpenFeatureChange, pickRequest, selectRequest, onSelectRequestApplied, children, }: Props): import("react").JSX.Element;
|
|
109
|
+
export declare function AstraeusShell({ experience, snapshot, developerMode, onDeveloperModeChange, onTogglePlayback, onRateChange, paceAuto, onSeek, onCameraRequest, onTurnToFigure, onCameraHold, onTimeShown, hostCameraSet, storySeekNote, onSelectionChange, scaleId, onScaleChange, scaleChoices, switcher, displaySwitches, viewChoice, viewCamera, metricsFor, developerTools, storyPanelSettings, timelineGlow, phoneLayout, labelStyle, highlightedFamily, onHighlightFamily, onSetPlaying, panelRequest, onOpenPanelChange, featureRequest, onOpenFeatureChange, pickRequest, selectRequest, onSelectRequestApplied, children, }: Props): import("react").JSX.Element;
|
|
108
110
|
export {};
|
|
@@ -15,6 +15,7 @@ import { labelStyleVars } from "../app/labelStyle.js";
|
|
|
15
15
|
import { DEFAULT_PHONE_LAYOUT, phoneLayoutStyle, pickOpensInfo, usePhone } from "./phoneLayout.js";
|
|
16
16
|
import { presetForViewRule } from "./viewCamera.js";
|
|
17
17
|
import { DeveloperToggle, TopBar } from "./TopBar.js";
|
|
18
|
+
import { shownAt } from "../app/viewHiding.js";
|
|
18
19
|
import { availableObjectById, findCameraPreset, firstAvailableObject, focusPresetFor, isObjectAvailable, skyFigureById } from "./objectModel.js";
|
|
19
20
|
import "./controls.css";
|
|
20
21
|
import "./style.css";
|
|
@@ -70,6 +71,12 @@ function selectionLost(selected, timeUtcMs, clearedByHost, isFigure) {
|
|
|
70
71
|
// A selected sky figure is never lost: it has no availability and no view hides it.
|
|
71
72
|
return !clearedByHost && !isFigure && (selected === undefined || !isObjectAvailable(selected, timeUtcMs));
|
|
72
73
|
}
|
|
74
|
+
/** What a camera preset's object asks of the camera at `timeUtcMs`: "hold" when its shown time has ended or not begun (keep the pose), "overview" when it is gone or unavailable, else undefined. */
|
|
75
|
+
function cameraTargetLoss(target, timeUtcMs) {
|
|
76
|
+
if (target !== undefined && !shownAt(target, timeUtcMs))
|
|
77
|
+
return "hold";
|
|
78
|
+
return target === undefined || !isObjectAvailable(target, timeUtcMs) ? "overview" : undefined;
|
|
79
|
+
}
|
|
73
80
|
function serialOf(request) {
|
|
74
81
|
return request?.serial;
|
|
75
82
|
}
|
|
@@ -124,7 +131,7 @@ function infoContent(experience, info, selectedObjectId, timeUtcMs, metricsFor)
|
|
|
124
131
|
/** The moon families load on demand: only an experience with `moonFamilies` draws them (I-089). */
|
|
125
132
|
const MoonFamilyPanel = lazy(() => import("./MoonFamilyPanel.js").then((module) => ({ default: module.MoonFamilyPanel })));
|
|
126
133
|
/** Canvas-first layout shared by astronomy experiences. Scene and diagnostics stay app-owned. */
|
|
127
|
-
export function AstraeusShell({ experience, snapshot, developerMode, onDeveloperModeChange, onTogglePlayback, onRateChange, paceAuto, onSeek, onCameraRequest, onTurnToFigure, onCameraHold, hostCameraSet, storySeekNote, onSelectionChange, scaleId, onScaleChange, scaleChoices, switcher, displaySwitches, viewChoice, viewCamera, metricsFor, developerTools, storyPanelSettings, timelineGlow, phoneLayout = DEFAULT_PHONE_LAYOUT, labelStyle, highlightedFamily = null, onHighlightFamily, onSetPlaying, panelRequest, onOpenPanelChange, featureRequest, onOpenFeatureChange, pickRequest, selectRequest, onSelectRequestApplied, children, }) {
|
|
134
|
+
export function AstraeusShell({ experience, snapshot, developerMode, onDeveloperModeChange, onTogglePlayback, onRateChange, paceAuto, onSeek, onCameraRequest, onTurnToFigure, onCameraHold, onTimeShown, hostCameraSet, storySeekNote, onSelectionChange, scaleId, onScaleChange, scaleChoices, switcher, displaySwitches, viewChoice, viewCamera, metricsFor, developerTools, storyPanelSettings, timelineGlow, phoneLayout = DEFAULT_PHONE_LAYOUT, labelStyle, highlightedFamily = null, onHighlightFamily, onSetPlaying, panelRequest, onOpenPanelChange, featureRequest, onOpenFeatureChange, pickRequest, selectRequest, onSelectRequestApplied, children, }) {
|
|
128
135
|
const infoPanelId = `${useId()}-info-panel`;
|
|
129
136
|
const [selectedObjectId, setSelectedObjectId] = useState(() => initialObjectId(experience, snapshot.timeUtcMs));
|
|
130
137
|
const phone = usePhone();
|
|
@@ -202,6 +209,7 @@ export function AstraeusShell({ experience, snapshot, developerMode, onDeveloper
|
|
|
202
209
|
if (switchRule !== undefined && selected === undefined)
|
|
203
210
|
setInfo((now) => (now?.kind === "object" ? null : now));
|
|
204
211
|
}
|
|
212
|
+
onTimeShown?.(snapshot.timeUtcMs);
|
|
205
213
|
const active = experience.cameraPresets.find((preset) => preset.id === activePresetId);
|
|
206
214
|
const activeRequest = active?.request;
|
|
207
215
|
if (switchRule?.rule === "start" && switchRule.framing?.always === true) {
|
|
@@ -212,12 +220,8 @@ export function AstraeusShell({ experience, snapshot, developerMode, onDeveloper
|
|
|
212
220
|
if (switchRule !== undefined && target === undefined) {
|
|
213
221
|
applyViewRule(switchRule);
|
|
214
222
|
}
|
|
215
|
-
else
|
|
216
|
-
|
|
217
|
-
if (overview !== undefined) {
|
|
218
|
-
setActivePresetId(overview.id);
|
|
219
|
-
onCameraRequest(overview.request);
|
|
220
|
-
}
|
|
223
|
+
else {
|
|
224
|
+
loseCameraTarget(cameraTargetLoss(target, snapshot.timeUtcMs));
|
|
221
225
|
}
|
|
222
226
|
}
|
|
223
227
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -237,6 +241,20 @@ export function AstraeusShell({ experience, snapshot, developerMode, onDeveloper
|
|
|
237
241
|
// Only a new request applies.
|
|
238
242
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
239
243
|
}, [requestedSelectSerial]);
|
|
244
|
+
/** The camera's object is gone or not shown: "hold" keeps the pose and stops following (its shown time ended or has not begun, no jump); "overview" frames the overview. */
|
|
245
|
+
const loseCameraTarget = (loss) => {
|
|
246
|
+
if (loss === "hold") {
|
|
247
|
+
setActivePresetId(null);
|
|
248
|
+
onCameraHold?.();
|
|
249
|
+
}
|
|
250
|
+
else if (loss === "overview") {
|
|
251
|
+
const overview = findCameraPreset(experience, "overview");
|
|
252
|
+
if (overview !== undefined) {
|
|
253
|
+
setActivePresetId(overview.id);
|
|
254
|
+
onCameraRequest(overview.request);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
};
|
|
240
258
|
/** The view's camera rule for a followed or focused object the new view does not show: `stay` keeps the pose and stops following; otherwise the rule's framing is requested. */
|
|
241
259
|
const applyViewRule = (rule) => {
|
|
242
260
|
const asked = presetForViewRule(rule, experience);
|
|
@@ -15,6 +15,7 @@ import { labelStyleVars } from "../app/labelStyle.js";
|
|
|
15
15
|
import { DEFAULT_PHONE_LAYOUT, phoneLayoutStyle, pickOpensInfo, usePhone } from "./phoneLayout.js";
|
|
16
16
|
import { presetForViewRule } from "./viewCamera.js";
|
|
17
17
|
import { DeveloperToggle, TopBar } from "./TopBar.node.js";
|
|
18
|
+
import { shownAt } from "../app/viewHiding.js";
|
|
18
19
|
import { availableObjectById, findCameraPreset, firstAvailableObject, focusPresetFor, isObjectAvailable, skyFigureById } from "./objectModel.js";
|
|
19
20
|
/** Keeps `--timeline-space` at the distance from the screen's bottom to the top of the timeline bar, so a phone sheet can sit above it. */
|
|
20
21
|
function useTimelineSpace(root, phone) {
|
|
@@ -66,6 +67,12 @@ function selectionLost(selected, timeUtcMs, clearedByHost, isFigure) {
|
|
|
66
67
|
// A selected sky figure is never lost: it has no availability and no view hides it.
|
|
67
68
|
return !clearedByHost && !isFigure && (selected === undefined || !isObjectAvailable(selected, timeUtcMs));
|
|
68
69
|
}
|
|
70
|
+
/** What a camera preset's object asks of the camera at `timeUtcMs`: "hold" when its shown time has ended or not begun (keep the pose), "overview" when it is gone or unavailable, else undefined. */
|
|
71
|
+
function cameraTargetLoss(target, timeUtcMs) {
|
|
72
|
+
if (target !== undefined && !shownAt(target, timeUtcMs))
|
|
73
|
+
return "hold";
|
|
74
|
+
return target === undefined || !isObjectAvailable(target, timeUtcMs) ? "overview" : undefined;
|
|
75
|
+
}
|
|
69
76
|
function serialOf(request) {
|
|
70
77
|
return request?.serial;
|
|
71
78
|
}
|
|
@@ -120,7 +127,7 @@ function infoContent(experience, info, selectedObjectId, timeUtcMs, metricsFor)
|
|
|
120
127
|
/** The moon families load on demand: only an experience with `moonFamilies` draws them (I-089). */
|
|
121
128
|
const MoonFamilyPanel = lazy(() => import("./MoonFamilyPanel.js").then((module) => ({ default: module.MoonFamilyPanel })));
|
|
122
129
|
/** Canvas-first layout shared by astronomy experiences. Scene and diagnostics stay app-owned. */
|
|
123
|
-
export function AstraeusShell({ experience, snapshot, developerMode, onDeveloperModeChange, onTogglePlayback, onRateChange, paceAuto, onSeek, onCameraRequest, onTurnToFigure, onCameraHold, hostCameraSet, storySeekNote, onSelectionChange, scaleId, onScaleChange, scaleChoices, switcher, displaySwitches, viewChoice, viewCamera, metricsFor, developerTools, storyPanelSettings, timelineGlow, phoneLayout = DEFAULT_PHONE_LAYOUT, labelStyle, highlightedFamily = null, onHighlightFamily, onSetPlaying, panelRequest, onOpenPanelChange, featureRequest, onOpenFeatureChange, pickRequest, selectRequest, onSelectRequestApplied, children, }) {
|
|
130
|
+
export function AstraeusShell({ experience, snapshot, developerMode, onDeveloperModeChange, onTogglePlayback, onRateChange, paceAuto, onSeek, onCameraRequest, onTurnToFigure, onCameraHold, onTimeShown, hostCameraSet, storySeekNote, onSelectionChange, scaleId, onScaleChange, scaleChoices, switcher, displaySwitches, viewChoice, viewCamera, metricsFor, developerTools, storyPanelSettings, timelineGlow, phoneLayout = DEFAULT_PHONE_LAYOUT, labelStyle, highlightedFamily = null, onHighlightFamily, onSetPlaying, panelRequest, onOpenPanelChange, featureRequest, onOpenFeatureChange, pickRequest, selectRequest, onSelectRequestApplied, children, }) {
|
|
124
131
|
const infoPanelId = `${useId()}-info-panel`;
|
|
125
132
|
const [selectedObjectId, setSelectedObjectId] = useState(() => initialObjectId(experience, snapshot.timeUtcMs));
|
|
126
133
|
const phone = usePhone();
|
|
@@ -198,6 +205,7 @@ export function AstraeusShell({ experience, snapshot, developerMode, onDeveloper
|
|
|
198
205
|
if (switchRule !== undefined && selected === undefined)
|
|
199
206
|
setInfo((now) => (now?.kind === "object" ? null : now));
|
|
200
207
|
}
|
|
208
|
+
onTimeShown?.(snapshot.timeUtcMs);
|
|
201
209
|
const active = experience.cameraPresets.find((preset) => preset.id === activePresetId);
|
|
202
210
|
const activeRequest = active?.request;
|
|
203
211
|
if (switchRule?.rule === "start" && switchRule.framing?.always === true) {
|
|
@@ -208,12 +216,8 @@ export function AstraeusShell({ experience, snapshot, developerMode, onDeveloper
|
|
|
208
216
|
if (switchRule !== undefined && target === undefined) {
|
|
209
217
|
applyViewRule(switchRule);
|
|
210
218
|
}
|
|
211
|
-
else
|
|
212
|
-
|
|
213
|
-
if (overview !== undefined) {
|
|
214
|
-
setActivePresetId(overview.id);
|
|
215
|
-
onCameraRequest(overview.request);
|
|
216
|
-
}
|
|
219
|
+
else {
|
|
220
|
+
loseCameraTarget(cameraTargetLoss(target, snapshot.timeUtcMs));
|
|
217
221
|
}
|
|
218
222
|
}
|
|
219
223
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -233,6 +237,20 @@ export function AstraeusShell({ experience, snapshot, developerMode, onDeveloper
|
|
|
233
237
|
// Only a new request applies.
|
|
234
238
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
235
239
|
}, [requestedSelectSerial]);
|
|
240
|
+
/** The camera's object is gone or not shown: "hold" keeps the pose and stops following (its shown time ended or has not begun, no jump); "overview" frames the overview. */
|
|
241
|
+
const loseCameraTarget = (loss) => {
|
|
242
|
+
if (loss === "hold") {
|
|
243
|
+
setActivePresetId(null);
|
|
244
|
+
onCameraHold?.();
|
|
245
|
+
}
|
|
246
|
+
else if (loss === "overview") {
|
|
247
|
+
const overview = findCameraPreset(experience, "overview");
|
|
248
|
+
if (overview !== undefined) {
|
|
249
|
+
setActivePresetId(overview.id);
|
|
250
|
+
onCameraRequest(overview.request);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
};
|
|
236
254
|
/** The view's camera rule for a followed or focused object the new view does not show: `stay` keeps the pose and stops following; otherwise the rule's framing is requested. */
|
|
237
255
|
const applyViewRule = (rule) => {
|
|
238
256
|
const asked = presetForViewRule(rule, experience);
|
|
@@ -14,7 +14,7 @@ export function ObjectControls({ experience, timeUtcMs, selectedObjectId, active
|
|
|
14
14
|
const presetIcon = (preset) => preset.request.kind === "overview" ? _jsx(OverviewIcon, {}) : preset.request.kind === "follow" ? _jsx(FollowIcon, {}) : preset.request.kind === "lookOut" ? _jsx(LookOutIcon, {}) : _jsx(FocusIcon, {});
|
|
15
15
|
const presetText = (preset) => (preset.request.kind === "overview" ? "Overview" : preset.request.kind === "follow" ? "Follow" : preset.request.kind === "lookOut" ? "Look out" : "Focus");
|
|
16
16
|
const renderPreset = (preset) => preset && (_jsxs("button", { type: "button", className: "top-bar-button ui-icon", "data-closes-drawer": "", "aria-label": preset.label, title: preset.label, "aria-pressed": activePresetId === preset.id, "data-camera-preset": preset.id, onClick: () => onCameraPreset(preset), disabled: preset.request.kind !== "overview" && !selectedAvailable, children: [presetIcon(preset), _jsx(ButtonText, { children: presetText(preset) })] }, preset.id));
|
|
17
|
-
return (_jsxs("section", { className: "object-controls", "aria-label": "Object and camera controls", children: [_jsxs("select", { className: "object-picker", "data-closes-drawer": "", "aria-label": "Select object", value: selectedObjectId, onChange: (event) => onSelectObject(event.target.value), children: [listedObjects(experience, selectedObjectId).map((object) => {
|
|
17
|
+
return (_jsxs("section", { className: "object-controls", "aria-label": "Object and camera controls", children: [_jsxs("select", { className: "object-picker", "data-closes-drawer": "", "aria-label": "Select object", value: selectedObjectId, onChange: (event) => onSelectObject(event.target.value), children: [listedObjects(experience, selectedObjectId, timeUtcMs).map((object) => {
|
|
18
18
|
const available = isObjectAvailable(object, timeUtcMs);
|
|
19
19
|
return (_jsxs("option", { value: object.id, disabled: !available, "data-available": available, "data-available-from": object.availability?.startUtcMs, "data-available-to": object.availability?.endUtcMs, children: [object.label, available ? "" : " (Unavailable)"] }, object.id));
|
|
20
20
|
}), listedFigures(experience, selectedObjectId).map((figure) => _jsx("option", { value: figure.id, "data-sky-figure": "", children: figure.label }, figure.id))] }), _jsxs("button", { type: "button", className: "top-bar-button ui-icon object-info-toggle", "data-closes-drawer": "", "aria-label": infoLabel === undefined ? "Information" : `Information about ${infoLabel}`, title: infoLabel === undefined ? "Information" : `Information about ${infoLabel}`, "aria-expanded": infoOpen, "aria-controls": infoPanelId, disabled: !selectedAvailable && selectedFigure === undefined, onClick: onToggleInfo, children: [_jsx(InfoIcon, {}), _jsx(ButtonText, { children: "Info" })] }), _jsxs("div", { className: "object-camera-actions", children: [renderPreset(focus), renderPreset(follow), renderPreset(lookOut), renderPreset(overview), related.map((object) => (_jsxs("button", { type: "button", className: "top-bar-button ui-icon object-related", "aria-label": object.label, title: object.label, "data-related-object": object.id, disabled: !isObjectAvailable(object, timeUtcMs), onClick: () => onSelectObject(object.id), children: [_jsx(OrbitIcon, {}), _jsx(ButtonText, { children: object.label })] }, object.id)))] })] }));
|