A link to only a view opens with the opening too, stopping at that view

The app writes its view into the address, so a reload or a bookmark is a
share link and opened without the opening. A start-up share whose camera
landed and that follows or selects nothing now plays it as well, ending
where the link points; the share restore says when the share is of a thing.

The flight turns to the target's heading and pitch over its last part, so a
view at an angle is reached without a jump. A camera held in a target's
frame plays no opening.
This commit is contained in:
German Khokhlov committed 2026-11-23 16:08:30 +04:00
1 parent 9088c01d1a
commit 31ce6cbf79
6 files changed
+120 -25

No files matched your search

+27 -13
View File
@@ -95,8 +95,10 @@ export function openingStage(t, timing = OPENING) {
/**
* The camera `flight` (0–1) of the way in: from `farHeight` over the
* equator, a turn of `spinDeg` west to east that slows to a stop over
* `target`, closing in on `target.height`.
* equator, looking straight down, a turn of `spinDeg` west to east that
* slows to a stop over `target`, closing in on `target.height`. Over the
* last part it turns to `target`'s heading and pitch (radians), so a view
* at an angle (a shared one) is reached without a jump.
*/
export function openingPose(
flight,
@@ -109,10 +111,18 @@ export function openingPose(
(Math.log(target.height) - Math.log(farHeight)) * closing,
);
const lon = target.lon + spinDeg * (1 - easeOutCubic(f));
const turning = easeInOutCubic(span(f, [0.6, 1]));
const heading = target.heading ?? 0;
// The short way round to the target's heading.
const headingFrom =
heading - 2 * Math.PI * Math.round(heading / (2 * Math.PI));
const pitch = target.pitch ?? -Math.PI / 2;
return {
lon: ((((lon + 180) % 360) + 360) % 360) - 180,
lat: target.lat * closing,
height,
heading: headingFrom * turning,
pitch: -Math.PI / 2 + (pitch + Math.PI / 2) * turning,
};
}
@@ -191,10 +201,11 @@ export function openingWanted(win = globalThis.window) {
}
/**
* Play the opening over `loadingScreen`, from where the camera stands (the
* start view). Returns null when it does not play; else `done`, which
* settles when the camera has stopped, and `cancel()`. A click, a key or the
* wheel skips to the start view; any other camera move stops it where it is. The loading
* Play the opening over `loadingScreen`, ending where the camera stands (the
* start view, or the view a link opened). Returns null when it does not
* play, as for a camera held in a target's frame; else `done`, which settles
* when the camera has stopped, and `cancel()`. A click, a key or the wheel
* skips to the end; any other camera move stops it where it is. The loading
* screen is `hidden` once the real globe shows, or at once on a cancel.
* @param {{viewer: object, loadingScreen: HTMLElement, win?: Window,
* camera?: object}} options `camera` is the viewer's camera port unless given.
@@ -213,6 +224,7 @@ export function playOpeningIntro({
}
const target = camera.pose();
if (
target?.frameIsIdentity === false ||
!Number.isFinite(target?.height) ||
!Number.isFinite(target.lon) ||
!Number.isFinite(target.lat)
@@ -273,11 +285,11 @@ export function playOpeningIntro({
: 1;
let driving = false;
const place = (pose, heading = 0, pitch = -Math.PI / 2) => {
const place = ({ lon, lat, height, heading, pitch }) => {
driving = true;
try {
camera.setView({
destination: pose,
destination: { lon, lat, height },
orientation: { heading, pitch, roll: 0 },
});
} finally {
@@ -310,11 +322,13 @@ export function playOpeningIntro({
for (const type of inputs)
win.removeEventListener(type, onInput, { capture: true });
if (land)
place(
{ lon: target.lon, lat: target.lat, height: target.height },
target.heading ?? 0,
target.pitch ?? -Math.PI / 2,
);
place({
lon: target.lon,
lat: target.lat,
height: target.height,
heading: target.heading ?? 0,
pitch: target.pitch ?? -Math.PI / 2,
});
hide();
resolveDone();
}
+27
View File
@@ -85,6 +85,25 @@ test('the flight turns west to east, slows and stops over the target', () => {
}
});
test('a view at an angle is reached by turning over the last part', () => {
const angled = {
lon: 2.35,
lat: 48.86,
height: 5000,
heading: 5.5,
pitch: -0.5,
};
const far = 4e8;
const early = openingPose(0.5, { target: angled, farHeight: far });
assert.ok(Math.abs(early.heading) < 1e-12);
assert.equal(early.pitch, -Math.PI / 2, 'straight down while far out');
const end = openingPose(1, { target: angled, farHeight: far });
// 5.5 rad turns the short way round: -0.78 rad.
assert.ok(Math.abs(end.heading - (5.5 - 2 * Math.PI)) < 1e-9);
assert.ok(Math.abs(end.pitch - angled.pitch) < 1e-9);
assert.ok(Math.abs(end.height - angled.height) < 1e-6);
});
test('the far start draws the globe the size of the pupil', () => {
for (const radius of [12, 20, 64]) {
const height = heightForGlobeRadius(radius, LENS);
@@ -187,11 +206,19 @@ test('the opening runs to the start view, then hides the cover', async () => {
await opening.done;
const last = s.views.at(-1);
assert.deepEqual(last.destination, LANDED);
assert.equal(last.orientation.heading, TARGET.heading);
assert.equal(last.orientation.pitch, TARGET.pitch);
assert.equal(openingPlaying(), false);
assert.equal(s.commandListeners.size, 0);
});
test('a camera held in a target frame plays no opening', () => {
const s = stage();
s.camera.pose = () => ({ ...TARGET, frameIsIdentity: false });
assert.equal(s.play(), null);
assert.ok(!s.screen.classList.contains('opening'));
});
test("the person's input skips to the start view", async () => {
const s = stage();
const opening = s.play();
+21 -5
View File
@@ -32,12 +32,14 @@ export function startApplicationChrome({
.catch(() => {
/* Restoration reports its own outcome through the controls. */
})
.then(() => {
.then(([restored] = []) => {
if (disposed || signal.aborted) return;
// A bare address opens with the opening; welcome waits for its end.
opening = styleManager.hasShareState
? null
: playOpening?.({ viewer: styleManager.viewer, loadingScreen });
// A bare address, or a share of only a view, opens with the opening
// (it ends where the camera stands); welcome waits for its end.
opening =
!styleManager.hasShareState || sharesOnlyAView(restored)
? playOpening?.({ viewer: styleManager.viewer, loadingScreen })
: null;
if (opening) {
void opening.done.then(revealFirstRun);
return;
@@ -66,3 +68,17 @@ export function startApplicationChrome({
(await keySetup.catch(() => null))?.destroy();
};
}
/**
* Whether a start-up share restore left only a view: the camera landed where
* the link points and nothing is followed or selected for it.
*/
function sharesOnlyAView(restored) {
return (
restored?.status === 'settled' &&
restored.share?.camera === 'applied' &&
restored.tracking?.status === 'skipped' &&
restored.tracking.reason === 'no-shared-target' &&
!restored.thing
);
}