mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-24 04:02:19 +00:00
Keep the opening out of embeds, Street Level and moved cameras; fix review findings
- Embeds, inline panels, Street Level links and rejected share codes skip the opening. - The opening yields to a camera move made between its frames and keeps the view's roll. - A click skips it; the welcome waits for the cover to fade after a skip. - The first HUD summary is not spent while the opening plays. - Home countries follow tzdata backward links; the table is regenerated and checked. - QA scripts open the cockpit and Street Level checks with intro=0.
This commit is contained in:
1 parent
f4d936989b
commit
c4a846b8ad
20 files changed
+679
-291
No files matched your search
+152
-166
@@ -1,15 +1,12 @@
|
||||
import { START_VIEW } from '../camera.js';
|
||||
import { cameraOf } from '../render/rendererOf.js';
|
||||
import { normalizeCameraLongitude } from '../director/camera.js';
|
||||
import { findCamera } from '../render/rendererOf.js';
|
||||
import { isEmbedded } from './embed.js';
|
||||
|
||||
/**
|
||||
* The opening: once the world has loaded, the loading screen's logo turns
|
||||
* into the globe. The words fade and the logo glides to the centre. The
|
||||
* screen is then shut but for the empty circle inside the eye's ring, which
|
||||
* flies at the viewer and opens onto the application as it grows past the
|
||||
* screen's edges. The drawn planet in the pupil (its blue disc) gives way to
|
||||
* the real one, drawn the same size behind it, which grows to the whole
|
||||
* planet's size, turns there to a stop over the start view (the visitor's
|
||||
* country), and only then closes in on a closer view a link opened.
|
||||
* into the globe, which grows to the whole planet's size, turns there to a
|
||||
* stop over the view it ends at and only then closes in on a closer one.
|
||||
* Everything is timed from one clock, in ms.
|
||||
*/
|
||||
export const OPENING = Object.freeze({
|
||||
@@ -20,15 +17,14 @@ export const OPENING = Object.freeze({
|
||||
// The rest is timed from the end of the move.
|
||||
/** The eye grows past the screen's edges. */
|
||||
eyeMs: 1100,
|
||||
/** Without the logo's own parts (an <img>): the background clears. */
|
||||
veilMs: Object.freeze([200, 700]),
|
||||
/** The drawn planet fades into the real one. */
|
||||
pupilMs: Object.freeze([600, 1200]),
|
||||
/** The camera's flight starts. */
|
||||
flightStartMs: 300,
|
||||
/** The globe grows to the whole planet's size. */
|
||||
zoomMs: 1600,
|
||||
/** It turns there, slowing to a stop over the start view. */
|
||||
/** It turns there, slowing to a stop over the view it ends at: the turn
|
||||
* starts halfway through the zoom and ends this long after it. */
|
||||
spinMs: 2600,
|
||||
/** Then the camera closes in on a closer view (a shared one), per tenfold
|
||||
* change of height, within `approachMs`. */
|
||||
@@ -39,10 +35,7 @@ export const OPENING = Object.freeze({
|
||||
});
|
||||
|
||||
const EARTH_RADIUS_M = 6371000;
|
||||
// logo.svg: its viewBox width, the drawn planet's radius (the blue disc) and
|
||||
// the eye's centre, in its units.
|
||||
const LOGO_WIDTH = 775;
|
||||
const PUPIL_RADIUS = 195;
|
||||
// public/logo.svg geometry, in its viewBox units.
|
||||
const EYE_CENTRE = Object.freeze({ x: 568.8, y: 379 });
|
||||
const EYE_WIDTH = 726.3;
|
||||
/** The empty circle inside the eye's ring, the app's window. */
|
||||
@@ -72,19 +65,18 @@ const easeInOutCubic = (x) =>
|
||||
x < 0.5 ? 4 * x ** 3 : 1 - (-2 * x + 2) ** 3 / 2;
|
||||
const smoothstep = (x) => x * x * (3 - 2 * x);
|
||||
const span = (t, [from, to]) => clamp01((t - from) / (to - from));
|
||||
/** An angle, radians, the short way round. */
|
||||
const shortWay = (angle) =>
|
||||
angle - 2 * Math.PI * Math.round(angle / (2 * Math.PI));
|
||||
|
||||
/**
|
||||
* Where each part of the opening stands `t` ms after it starts.
|
||||
* @param {number} t
|
||||
*/
|
||||
export function openingStage(t, timing = OPENING, flightMs = flightLength()) {
|
||||
const move = clamp01(t / timing.centreMs);
|
||||
const after = t - timing.centreMs;
|
||||
const eye = clamp01(after / timing.eyeMs);
|
||||
const flight = clamp01((after - timing.flightStartMs) / flightMs);
|
||||
/** Where each part of the opening stands `t` ms after it starts. */
|
||||
export function openingStage(t) {
|
||||
const move = clamp01(t / OPENING.centreMs);
|
||||
const after = t - OPENING.centreMs;
|
||||
const eye = clamp01(after / OPENING.eyeMs);
|
||||
return {
|
||||
/** The words' opacity. */
|
||||
text: 1 - clamp01(t / timing.textMs),
|
||||
text: 1 - clamp01(t / OPENING.textMs),
|
||||
/** How far the logo has moved to the centre, 0–1. */
|
||||
centre: easeInOutCubic(move),
|
||||
/** Whether the screen is shut except inside the eye. */
|
||||
@@ -94,72 +86,58 @@ export function openingStage(t, timing = OPENING, flightMs = flightLength()) {
|
||||
/** The eye's own opacity, and that of the shutter around it. */
|
||||
eyeOpacity: 1 - span(eye, [0.6, 1]),
|
||||
shutterOpacity: 1 - span(eye, [0.85, 1]),
|
||||
eyeOpen: eye >= 1,
|
||||
/** The background's opacity where the logo is an <img>. */
|
||||
veil: 1 - span(after, timing.veilMs),
|
||||
pupilOpacity: 1 - span(after, timing.pupilMs),
|
||||
/** The flight's progress, 0–1. */
|
||||
flight,
|
||||
done: flight >= 1,
|
||||
pupilOpacity: 1 - span(after, OPENING.pupilMs),
|
||||
};
|
||||
}
|
||||
|
||||
/** How long the flight takes, ms, for a closing-in of `decades` (log10). */
|
||||
function flightLength(decades = 0, turns = false, timing = OPENING) {
|
||||
const [shortest, longest] = timing.approachMs;
|
||||
const approach =
|
||||
decades > 0.05 || turns
|
||||
? Math.min(
|
||||
longest,
|
||||
Math.max(shortest, decades * timing.approachPerDecadeMs),
|
||||
)
|
||||
: 0;
|
||||
return timing.zoomMs + timing.spinMs + approach;
|
||||
}
|
||||
|
||||
/**
|
||||
* The camera's flight in, from `farHeight` over the equator, looking straight
|
||||
* down. The globe first grows to the whole planet's size (`planetHeight`, or
|
||||
* `target.height` when that is further out), turns `spinDeg` west to east
|
||||
* there, slowing to a stop over `target`, and only then closes in on a closer
|
||||
* `target`, turning to its heading and pitch (radians) on the way.
|
||||
* Returns its length, ms, and its pose `ms` into it.
|
||||
* down. The globe first grows to the whole planet's size (or `target`'s
|
||||
* height when that is further out), turns `spinDeg` west to east there,
|
||||
* slowing to a stop over `target`, and only then closes in on a closer
|
||||
* `target`, turning to its heading, pitch and roll (radians) on the way.
|
||||
* With nothing to close in on, it grows to `target`'s height.
|
||||
* Returns `{ ms, pose(at) }`: its length, and its pose `at` ms into it.
|
||||
*/
|
||||
export function openingFlight({
|
||||
target,
|
||||
farHeight,
|
||||
planetHeight = PLANET_HEIGHT_M,
|
||||
timing = OPENING,
|
||||
}) {
|
||||
const heading = target.heading ?? 0;
|
||||
// The short way round to the target's heading.
|
||||
const headingTo = heading - 2 * Math.PI * Math.round(heading / (2 * Math.PI));
|
||||
export function openingFlight({ target, farHeight }) {
|
||||
const headingTo = shortWay(target.heading ?? 0);
|
||||
const rollTo = shortWay(target.roll ?? 0);
|
||||
const pitchTo = target.pitch ?? -Math.PI / 2;
|
||||
const turns =
|
||||
Math.abs(headingTo) > 1e-3 || Math.abs(pitchTo + Math.PI / 2) > 1e-3;
|
||||
const planet = Math.max(planetHeight, target.height);
|
||||
const decades = Math.log10(planet / target.height);
|
||||
const ms = flightLength(decades, turns, timing);
|
||||
const approachMs = ms - timing.zoomMs - timing.spinMs;
|
||||
Math.abs(headingTo) > 1e-3 ||
|
||||
Math.abs(rollTo) > 1e-3 ||
|
||||
Math.abs(pitchTo + Math.PI / 2) > 1e-3;
|
||||
const above = Math.max(PLANET_HEIGHT_M, target.height);
|
||||
const decades = Math.log10(above / target.height);
|
||||
const [shortest, longest] = OPENING.approachMs;
|
||||
const approachMs =
|
||||
decades > 0.05 || turns
|
||||
? Math.min(
|
||||
longest,
|
||||
Math.max(shortest, decades * OPENING.approachPerDecadeMs),
|
||||
)
|
||||
: 0;
|
||||
const planet = approachMs ? above : target.height;
|
||||
const ms = OPENING.zoomMs + OPENING.spinMs + approachMs;
|
||||
const logLerp = (from, to, k) =>
|
||||
Math.exp(Math.log(from) + (Math.log(to) - Math.log(from)) * k);
|
||||
// The turn starts halfway through the zoom, while the drawn planet has
|
||||
// given way to the real one.
|
||||
const spinFrom = timing.zoomMs / 2;
|
||||
const spinLength = timing.zoomMs + timing.spinMs - spinFrom;
|
||||
// The turn starts halfway through the zoom, as the drawn planet fades out.
|
||||
const spinFrom = OPENING.zoomMs / 2;
|
||||
const spinLength = OPENING.zoomMs + OPENING.spinMs - spinFrom;
|
||||
return {
|
||||
ms,
|
||||
pose(at) {
|
||||
const t = Math.min(Math.max(at, 0), ms);
|
||||
const zoom = smoothstep(clamp01(t / timing.zoomMs));
|
||||
const zoom = smoothstep(clamp01(t / OPENING.zoomMs));
|
||||
const spin = easeOutCubic(clamp01((t - spinFrom) / spinLength));
|
||||
const approach = approachMs
|
||||
? clamp01((t - timing.zoomMs - timing.spinMs) / approachMs)
|
||||
? clamp01((t - OPENING.zoomMs - OPENING.spinMs) / approachMs)
|
||||
: 0;
|
||||
const turning = easeInOutCubic(approach);
|
||||
const lon = target.lon + timing.spinDeg * (1 - spin);
|
||||
return {
|
||||
lon: ((((lon + 180) % 360) + 360) % 360) - 180,
|
||||
lon: normalizeCameraLongitude(
|
||||
target.lon + OPENING.spinDeg * (1 - spin),
|
||||
),
|
||||
lat: target.lat * spin,
|
||||
height:
|
||||
approach > 0
|
||||
@@ -167,6 +145,7 @@ export function openingFlight({
|
||||
: logLerp(farHeight, planet, zoom),
|
||||
heading: headingTo * turning,
|
||||
pitch: -Math.PI / 2 + (pitchTo + Math.PI / 2) * turning,
|
||||
roll: rollTo * turning,
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -193,7 +172,7 @@ export function heightForGlobeRadius(radiusPx, { fovy, viewportHeight }) {
|
||||
* its window (the empty circle inside its ring, `windowRadius` pixels) to
|
||||
* reach past the view's corners.
|
||||
*/
|
||||
export function eyeCoverScale(windowRadius, view) {
|
||||
function eyeCoverScale(windowRadius, view) {
|
||||
return (
|
||||
(WINDOW_COVER_MARGIN * Math.hypot(view.width, view.height)) /
|
||||
2 /
|
||||
@@ -207,9 +186,7 @@ export function eyeCoverScale(windowRadius, view) {
|
||||
* it. It sits under the logo's parts and grows with the eye, so the screen is
|
||||
* shut but for that circle.
|
||||
*/
|
||||
function eyeShutter(eye, loadingScreen, win) {
|
||||
const colour =
|
||||
win.getComputedStyle?.(loadingScreen).backgroundColor || '#000';
|
||||
function eyeShutter(eye) {
|
||||
const far = 1e5;
|
||||
// Centred where the eye grows from, so the two grow as one.
|
||||
const { x, y } = EYE_CENTRE;
|
||||
@@ -223,7 +200,7 @@ function eyeShutter(eye, loadingScreen, win) {
|
||||
`M${x - far},${y - far}H${x + far}V${y + far}H${x - far}Z` +
|
||||
`M${cx - r},${cy}a${r},${r} 0 1,0 ${2 * r},0a${r},${r} 0 1,0 ${-2 * r},0Z`,
|
||||
);
|
||||
shutter.setAttribute('fill', colour);
|
||||
shutter.style.fill = 'var(--bg-dark)';
|
||||
shutter.setAttribute('fill-rule', 'evenodd');
|
||||
shutter.dataset.openingShutter = '';
|
||||
eye.parentNode.insertBefore(shutter, eye.parentNode.firstElementChild);
|
||||
@@ -232,12 +209,15 @@ function eyeShutter(eye, loadingScreen, win) {
|
||||
|
||||
/**
|
||||
* Whether the page opens with the opening: not where motion is reduced, not
|
||||
* on a Stories link (Stories opens its own view) and not with `?intro=0`.
|
||||
* in an embedded view (its host drives the camera, and an inline panel's host
|
||||
* may stop animation frames), not on a Stories link (Stories opens its own
|
||||
* view) and not with `?intro=0`.
|
||||
*/
|
||||
export function openingWanted(win = globalThis.window) {
|
||||
if (!win) return false;
|
||||
if (win.matchMedia?.('(prefers-reduced-motion: reduce)').matches)
|
||||
return false;
|
||||
if (isEmbedded(win.location)) return false;
|
||||
const params = new URLSearchParams(win.location?.search ?? '');
|
||||
return !(
|
||||
params.get('intro') === '0' ||
|
||||
@@ -249,10 +229,12 @@ export function openingWanted(win = globalThis.window) {
|
||||
/**
|
||||
* 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.
|
||||
* play: without the logo's own parts (an <img> logo opens as with reduced
|
||||
* motion), or for a camera at or below the ellipsoid. Else `done`, which
|
||||
* settles when the camera has stopped, and `cancel()`. A press, a click, a
|
||||
* key, a touch 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.
|
||||
*/
|
||||
@@ -263,15 +245,12 @@ export function playOpeningIntro({
|
||||
camera = null,
|
||||
}) {
|
||||
if (!openingWanted(win)) return null;
|
||||
try {
|
||||
camera ??= cameraOf(viewer);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
camera ??= findCamera(viewer);
|
||||
if (!camera) return null;
|
||||
const target = camera.pose();
|
||||
if (
|
||||
target?.frameIsIdentity === false ||
|
||||
!Number.isFinite(target?.height) ||
|
||||
!Number.isFinite(target.height) ||
|
||||
target.height <= 0 ||
|
||||
!Number.isFinite(target.lon) ||
|
||||
!Number.isFinite(target.lat)
|
||||
)
|
||||
@@ -279,51 +258,48 @@ export function playOpeningIntro({
|
||||
const doc = loadingScreen.ownerDocument;
|
||||
const logo = loadingScreen.querySelector('.loader-logo');
|
||||
const svg = logo?.querySelector('svg');
|
||||
const part = (id) => svg?.querySelector(`#${id}`);
|
||||
const eye = part('outer_eye');
|
||||
// The drawn planet: its blue disc, continents and grid; the whole logo
|
||||
// where it is an <img>.
|
||||
const disc = part('inner_eye');
|
||||
const pupil = svg
|
||||
? [disc, part('globe'), part('globe_cage')].filter(Boolean)
|
||||
: [logo].filter(Boolean);
|
||||
const shutter = eye ? eyeShutter(eye, loadingScreen, win) : null;
|
||||
const eye = svg?.querySelector('#outer_eye');
|
||||
// The drawn planet: its blue disc, continents and grid.
|
||||
const disc = svg?.querySelector('#inner_eye');
|
||||
if (!eye || !disc) return null;
|
||||
const pupil = [
|
||||
disc,
|
||||
svg.querySelector('#globe'),
|
||||
svg.querySelector('#globe_cage'),
|
||||
].filter(Boolean);
|
||||
// Each part fades from its own opacity: the grid is translucent.
|
||||
const ownOpacity = pupil.map((element) => {
|
||||
const opacity = Number.parseFloat(win.getComputedStyle(element).opacity);
|
||||
return Number.isFinite(opacity) ? opacity : 1;
|
||||
});
|
||||
const shutter = eyeShutter(eye);
|
||||
|
||||
loadingScreen.classList.add('opening');
|
||||
playing += 1;
|
||||
// The planet looks out of the middle of the eye again.
|
||||
// Cancel the logo gaze's offset (src/logoGaze.js): the pupil starts centred.
|
||||
for (const element of pupil) element.style.transform = 'none';
|
||||
const pupilRect = (disc ?? logo)?.getBoundingClientRect();
|
||||
const eyeRect = eye?.getBoundingClientRect();
|
||||
const pupilRect = disc.getBoundingClientRect();
|
||||
const eyeRect = eye.getBoundingClientRect();
|
||||
const view = (
|
||||
doc.getElementById('cesiumContainer') ?? doc.documentElement
|
||||
).getBoundingClientRect();
|
||||
const viewportHeight = view.height || win.innerHeight;
|
||||
const aspect = (view.width || win.innerWidth) / viewportHeight;
|
||||
// Cesium's default lens: 60° across the wider side.
|
||||
const fovy = Number.isFinite(target.fovy)
|
||||
? target.fovy
|
||||
: aspect > 1
|
||||
? 2 * Math.atan(Math.tan(Math.PI / 6) / aspect)
|
||||
: Math.PI / 3;
|
||||
const lens = { fovy, viewportHeight };
|
||||
const pupilRadius = pupilRect
|
||||
? disc
|
||||
? pupilRect.width / 2
|
||||
: (pupilRect.width * PUPIL_RADIUS) / LOGO_WIDTH
|
||||
: 32;
|
||||
const lens = { fovy: target.fovy, viewportHeight };
|
||||
const pupilRadius = pupilRect.width / 2;
|
||||
const farHeight = Math.min(
|
||||
MAX_FAR_HEIGHT_M,
|
||||
Math.max(target.height * 2, heightForGlobeRadius(pupilRadius, lens)),
|
||||
);
|
||||
const toCentre = pupilRect
|
||||
? {
|
||||
x: view.left + view.width / 2 - (pupilRect.left + pupilRect.width / 2),
|
||||
y: view.top + view.height / 2 - (pupilRect.top + pupilRect.height / 2),
|
||||
}
|
||||
: { x: 0, y: 0 };
|
||||
const toCentre = {
|
||||
x: view.left + view.width / 2 - (pupilRect.left + pupilRect.width / 2),
|
||||
y: view.top + view.height / 2 - (pupilRect.top + pupilRect.height / 2),
|
||||
};
|
||||
const startRadius = globeRadiusPx(farHeight, lens);
|
||||
const eyeCover = eyeRect?.width
|
||||
// Where the far start is capped (a wide screen), the globe there is larger
|
||||
// than the drawn planet: the logo grows to it on its way to the centre,
|
||||
// under the cover, and matches it from then on.
|
||||
const discScale = pupilRadius > 0 ? startRadius / pupilRadius : 1;
|
||||
const eyeCover = eyeRect.width
|
||||
? eyeCoverScale((eyeRect.width * WINDOW.r) / EYE_WIDTH, {
|
||||
width: view.width || win.innerWidth,
|
||||
height: viewportHeight,
|
||||
@@ -331,16 +307,28 @@ export function playOpeningIntro({
|
||||
: 1;
|
||||
|
||||
let driving = false;
|
||||
const place = ({ lon, lat, height, heading, pitch }) => {
|
||||
/** The camera as the opening last left it. */
|
||||
let placed = null;
|
||||
const place = ({ lon, lat, height, heading, pitch, roll = 0 }) => {
|
||||
driving = true;
|
||||
try {
|
||||
camera.setView({
|
||||
destination: { lon, lat, height },
|
||||
orientation: { heading, pitch, roll: 0 },
|
||||
orientation: { heading, pitch, roll },
|
||||
});
|
||||
} finally {
|
||||
driving = false;
|
||||
}
|
||||
placed = camera.pose();
|
||||
};
|
||||
// A move made on the renderer's own camera sends no command.
|
||||
const movedElsewhere = () => {
|
||||
const now = camera.pose();
|
||||
return (
|
||||
Math.abs(now.lat - placed.lat) > 1e-6 ||
|
||||
Math.abs(normalizeCameraLongitude(now.lon - placed.lon)) > 1e-6 ||
|
||||
Math.abs(now.height - placed.height) > 1
|
||||
);
|
||||
};
|
||||
|
||||
let resolveDone;
|
||||
@@ -350,11 +338,10 @@ export function playOpeningIntro({
|
||||
let frame = 0;
|
||||
let finished = false;
|
||||
const hide = () => loadingScreen.classList.add('hidden');
|
||||
const stopCommands = camera.onCommand?.(() => {
|
||||
const stopCommands = camera.onCommand(() => {
|
||||
if (!driving) finish();
|
||||
});
|
||||
const inputs = ['pointerdown', 'wheel', 'keydown', 'touchstart'];
|
||||
// The person's own input skips to the end; another camera move stops it.
|
||||
const inputs = ['pointerdown', 'click', 'wheel', 'keydown', 'touchstart'];
|
||||
const onInput = () => finish({ land: true });
|
||||
for (const type of inputs)
|
||||
win.addEventListener(type, onInput, { capture: true, passive: true });
|
||||
@@ -363,20 +350,16 @@ export function playOpeningIntro({
|
||||
if (finished) return;
|
||||
finished = true;
|
||||
playing -= 1;
|
||||
if (frame) win.cancelAnimationFrame(frame);
|
||||
stopCommands?.();
|
||||
for (const type of inputs)
|
||||
win.removeEventListener(type, onInput, { capture: true });
|
||||
if (land)
|
||||
place({
|
||||
lon: target.lon,
|
||||
lat: target.lat,
|
||||
height: target.height,
|
||||
heading: target.heading ?? 0,
|
||||
pitch: target.pitch ?? -Math.PI / 2,
|
||||
});
|
||||
hide();
|
||||
resolveDone();
|
||||
try {
|
||||
if (frame) win.cancelAnimationFrame(frame);
|
||||
stopCommands();
|
||||
for (const type of inputs)
|
||||
win.removeEventListener(type, onInput, { capture: true });
|
||||
if (land) place(target);
|
||||
} finally {
|
||||
hide();
|
||||
resolveDone();
|
||||
}
|
||||
}
|
||||
|
||||
const flight = openingFlight({ target, farHeight });
|
||||
@@ -384,40 +367,43 @@ export function playOpeningIntro({
|
||||
const step = () => {
|
||||
frame = 0;
|
||||
if (finished) return;
|
||||
const stage = openingStage(
|
||||
win.performance.now() - start,
|
||||
OPENING,
|
||||
flight.ms,
|
||||
);
|
||||
if (stage.done) {
|
||||
finish({ land: true });
|
||||
return;
|
||||
}
|
||||
const pose = flight.pose(stage.flight * flight.ms);
|
||||
place(pose);
|
||||
const scale = globeRadiusPx(pose.height, lens) / startRadius;
|
||||
loadingScreen.style.setProperty('--opening-text', stage.text);
|
||||
// Once the logo is centred, the shutter around the eye is the cover.
|
||||
loadingScreen.style.setProperty(
|
||||
'--opening-veil',
|
||||
shutter ? (stage.shut ? 0 : 1) : stage.veil,
|
||||
);
|
||||
if (logo)
|
||||
try {
|
||||
if (placed && movedElsewhere()) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
const t = win.performance.now() - start;
|
||||
const flown = t - OPENING.centreMs - OPENING.flightStartMs;
|
||||
if (flown >= flight.ms) {
|
||||
finish({ land: true });
|
||||
return;
|
||||
}
|
||||
const stage = openingStage(t);
|
||||
const pose = flight.pose(flown);
|
||||
place(pose);
|
||||
const scale =
|
||||
(globeRadiusPx(pose.height, lens) / startRadius) *
|
||||
(1 + (discScale - 1) * stage.centre);
|
||||
loadingScreen.style.setProperty('--opening-text', stage.text);
|
||||
// Once the logo is centred, the shutter around the eye is the cover.
|
||||
loadingScreen.style.setProperty('--opening-veil', stage.shut ? 0 : 1);
|
||||
logo.style.transform = `translate(${toCentre.x * stage.centre}px, ${
|
||||
toCentre.y * stage.centre
|
||||
}px) scale(${scale})`;
|
||||
const eyeScale = `scale(${1 + (eyeCover - 1) * stage.eyeGrowth})`;
|
||||
if (eye) {
|
||||
const eyeScale = `scale(${1 + (eyeCover - 1) * stage.eyeGrowth})`;
|
||||
eye.style.transform = eyeScale;
|
||||
eye.style.opacity = stage.eyeOpacity;
|
||||
}
|
||||
if (shutter) {
|
||||
shutter.style.transform = eyeScale;
|
||||
shutter.style.opacity = stage.shutterOpacity;
|
||||
pupil.forEach((element, i) => {
|
||||
element.style.opacity = ownOpacity[i] * stage.pupilOpacity;
|
||||
});
|
||||
if (stage.pupilOpacity === 0) hide();
|
||||
frame = win.requestAnimationFrame(step);
|
||||
} catch (error) {
|
||||
finish();
|
||||
throw error;
|
||||
}
|
||||
for (const element of pupil) element.style.opacity = stage.pupilOpacity;
|
||||
if (stage.pupilOpacity === 0 && (stage.eyeOpen || !shutter)) hide();
|
||||
frame = win.requestAnimationFrame(step);
|
||||
};
|
||||
step();
|
||||
return { done, cancel: () => finish() };
|
||||
|
||||
Reference in new issue
Block a user