Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

feat([issue-878]): pause CyberCity animations during photo capture

Adam Eivy9f399cc4ec88
diff --git a/client/src/components/city/CityPhotoCamera.jsx b/client/src/components/city/CityPhotoCamera.jsx
index f9d6f0e1cd..2bb88895a1 100644
--- a/client/src/components/city/CityPhotoCamera.jsx
+++ b/client/src/components/city/CityPhotoCamera.jsx
@@ -1,19 +1,22 @@
import { useRef, useEffect } from 'react';
import { useThree, useFrame } from '@react-three/fiber';
import * as THREE from 'three';
-import { getPreset } from '../../utils/cityPhotoMode';
-import { smoothstep } from '../../utils/easing';
+import { getPreset, stepFly } from '../../utils/cityPhotoMode';
-// Photo-mode camera driver (roadmap 3.3). When photo mode is active this flies the camera to
-// the selected cinematic preset with a smooth ease, and registers a capture function with the
+// Photo-mode camera driver (roadmap 3.3 / 3.6). When photo mode is active this flies the camera
+// to the selected cinematic preset with a smooth ease, and registers a capture function with the
// page (via `onReady`) that grabs the current WebGL frame as a PNG data URL. It renders nothing
// itself — it only mutates the shared camera and forces an on-demand render before each capture
// so `preserveDrawingBuffer` has a fresh frame to read. Mirrors CameraTransition's ease/lerp.
-
-const FLY_DURATION = 1.1; // seconds — slower than the exploration transition for a cinematic feel
+//
+// In photo mode the Canvas runs frameloop="demand" (roadmap 3.6 animation-pause): the scene
+// animates only while the camera is flying, then freezes for a clean, deliberate still. Because
+// "demand" stops ticking useFrame on its own, this component pumps the loop via `invalidate()` —
+// once when a fly begins (activation / preset change) and again every frame until the fly
+// settles. After that nothing invalidates, so the scene holds frozen until the next fly.
export default function CityPhotoCamera({ active, presetId, onReady }) {
- const { camera, gl, scene } = useThree();
+ const { camera, gl, scene, invalidate } = useThree();
const progressRef = useRef(1);
const startPosRef = useRef(new THREE.Vector3());
const startTargetRef = useRef(new THREE.Vector3());
@@ -34,12 +37,14 @@ export default function CityPhotoCamera({ active, presetId, onReady }) {
return () => onReady(null);
}, [onReady, gl, scene, camera]);
- // Begin a fly whenever photo mode turns on or the preset changes.
+ // Begin a fly whenever photo mode turns on or the preset changes. Kick the demand loop once so
+ // useFrame starts ticking again even though the scene is otherwise frozen.
const beginFly = () => {
progressRef.current = 0;
startPosRef.current.copy(camera.position);
const dir = new THREE.Vector3(0, 0, -1).applyQuaternion(camera.quaternion);
startTargetRef.current.copy(camera.position).add(dir.multiplyScalar(10));
+ invalidate();
};
useFrame((_, delta) => {
@@ -54,10 +59,10 @@ export default function CityPhotoCamera({ active, presetId, onReady }) {
lastPresetRef.current = presetId;
beginFly();
}
- if (progressRef.current >= 1) return; // settled — leave the camera where the fly left it
+ if (progressRef.current >= 1) return; // settled — leave the camera where the fly left it, scene frozen
- progressRef.current = Math.min(1, progressRef.current + delta / FLY_DURATION);
- const t = smoothstep(progressRef.current);
+ const { progress, t, done } = stepFly(progressRef.current, delta);
+ progressRef.current = progress;
const preset = getPreset(presetId);
const endPos = new THREE.Vector3(...preset.position);
@@ -65,6 +70,10 @@ export default function CityPhotoCamera({ active, presetId, onReady }) {
camera.position.lerpVectors(startPosRef.current, endPos, t);
camera.lookAt(new THREE.Vector3().lerpVectors(startTargetRef.current, endTarget, t));
+
+ // In frameloop="demand" the loop sleeps after this frame unless something requests another.
+ // Keep pumping until the fly settles; once done, stop so the scene freezes for the shot.
+ if (!done) invalidate();
});
return null;
diff --git a/client/src/components/city/CityScene.jsx b/client/src/components/city/CityScene.jsx
index 33e3a3687d..a1d883148d 100644
--- a/client/src/components/city/CityScene.jsx
+++ b/client/src/components/city/CityScene.jsx
@@ -156,6 +156,11 @@ export default function CityScene({ apps, agentMap, onBuildingClick, cosStatus,
camera={{ position: [0, 25, 45], fov: 50 }}
dpr={dpr}
shadows={false}
+ // Photo mode freezes the scene for a clean still (roadmap 3.6): "demand" stops the
+ // frameloop once the camera-fly settles, so particles/streams/weather/pulses pause for a
+ // deliberate shot. CityPhotoCamera pumps invalidate() during the fly; capture renders
+ // directly via gl.render(). Live mode keeps the always-on loop the dashboard relies on.
+ frameloop={photoMode ? 'demand' : 'always'}
onCreated={handleCanvasCreated}
style={{ background: sceneClearColor, cursor: explorationMode ? 'crosshair' : 'auto', opacity: webglLost ? 0 : 1 }}
// preserveDrawingBuffer is only needed while taking postcards. Keeping it
diff --git a/client/src/utils/cityPhotoMode.js b/client/src/utils/cityPhotoMode.js
index 8ab25b7a31..bfa109397b 100644
--- a/client/src/utils/cityPhotoMode.js
+++ b/client/src/utils/cityPhotoMode.js
@@ -1,8 +1,9 @@
// Pure, deterministic helpers for CyberCity's photo mode (roadmap 3.3): cinematic camera
-// presets, the "city postcard" stats overlay, and screenshot filename generation. No three.js
-// / React imports so it's unit-testable (mirrors the other city helpers). The component reads
-// these presets to fly the camera and composites the postcard caption from a live stats
-// snapshot the page passes in.
+// presets, the camera-fly stepper, the "city postcard" stats overlay, and screenshot filename
+// generation. No three.js / React imports so it's unit-testable (mirrors the other city
+// helpers). The component reads these presets to fly the camera and composites the postcard
+// caption from a live stats snapshot the page passes in.
+import { smoothstep } from './easing';
// Cinematic camera presets. Each is a stable framing of the city — position + look-at target —
// the photo UI cycles through. Tuned against the default orbital view (camera at [0,25,45]
@@ -33,6 +34,21 @@ export function cyclePreset(currentId, direction = 1) {
return PHOTO_PRESETS[next].id;
}
+// Photo mode runs the Canvas frameloop in "demand" mode (roadmap 3.6): the scene animates only
+// while the camera is flying to a preset, then freezes for a clean, deliberate still. This pure
+// stepper advances the fly progress by an elapsed delta and reports whether the loop still needs
+// pumping. `FLY_DURATION` is the seconds the cinematic ease takes (slower than the exploration
+// transition). `stepFly` returns the clamped next progress, the eased interpolation factor `t`,
+// and `done` (true once settled) so the component can stop invalidating the demand loop.
+export const FLY_DURATION = 1.1;
+
+export function stepFly(progress, deltaSeconds, duration = FLY_DURATION) {
+ const safeDelta = Number.isFinite(deltaSeconds) && deltaSeconds > 0 ? deltaSeconds : 0;
+ const safeDuration = duration > 0 ? duration : FLY_DURATION;
+ const next = Math.min(1, (Number.isFinite(progress) ? progress : 1) + safeDelta / safeDuration);
+ return { progress: next, t: smoothstep(next), done: next >= 1 };
+}
+
// Build the short stat lines printed on a "city postcard". Pulls a handful of headline numbers
// from a stats snapshot the page already has (apps, agents, peers, level). Missing fields are
// omitted rather than rendered as "0/undefined", so a sparse install still prints a clean card.
diff --git a/client/src/utils/cityPhotoMode.test.js b/client/src/utils/cityPhotoMode.test.js
index 6932b73989..086be272c9 100644
--- a/client/src/utils/cityPhotoMode.test.js
+++ b/client/src/utils/cityPhotoMode.test.js
@@ -4,6 +4,8 @@ import {
DEFAULT_PRESET_ID,
getPreset,
cyclePreset,
+ stepFly,
+ FLY_DURATION,
buildPostcardStats,
screenshotFilename,
} from './cityPhotoMode';
@@ -49,6 +51,34 @@ describe('cyclePreset', () => {
});
});
+describe('stepFly', () => {
+ it('advances progress by delta/duration and eases t', () => {
+ const { progress, t, done } = stepFly(0, FLY_DURATION / 2);
+ expect(progress).toBeCloseTo(0.5, 5);
+ expect(t).toBeCloseTo(0.5, 5); // smoothstep(0.5) === 0.5
+ expect(done).toBe(false);
+ });
+ it('clamps progress to 1 and reports done at/after the duration', () => {
+ const { progress, t, done } = stepFly(0.9, FLY_DURATION);
+ expect(progress).toBe(1);
+ expect(t).toBe(1);
+ expect(done).toBe(true);
+ });
+ it('reports done when already settled (no negative drift)', () => {
+ expect(stepFly(1, 0.016).done).toBe(true);
+ expect(stepFly(1, 0.016).progress).toBe(1);
+ });
+ it('treats a non-positive or non-finite delta as no advance', () => {
+ expect(stepFly(0.3, 0).progress).toBeCloseTo(0.3, 5);
+ expect(stepFly(0.3, -1).progress).toBeCloseTo(0.3, 5);
+ expect(stepFly(0.3, NaN).progress).toBeCloseTo(0.3, 5);
+ });
+ it('treats a non-finite progress as settled', () => {
+ expect(stepFly(undefined, 0.016).progress).toBe(1);
+ expect(stepFly(NaN, 0.016).done).toBe(true);
+ });
+});
+
describe('buildPostcardStats', () => {
it('renders the headline lines that have data', () => {
const lines = buildPostcardStats({ online: 3, total: 5, agents: 2, peers: 1, level: 7, streak: 4 });