// [246] Dialog „Kamerafahrt": Dauer je Abschnitt, Interpolation, Videoformat (WebM, MP4 wenn der Browser es kann), Abspielen // im 3D-Viewport und Aufnahme als Video (`MediaRecorder` auf dem Canvas, Auflösung = Viewport, 30 Bilder/s). Während // Abspielen/Aufnahme schrumpft der Dialog zu einer Leiste mit Fortschritt und „Abbrechen" (der Viewport bleibt sichtbar; // Esc oder Klick in den Viewport brechen ebenfalls ab). Zustand: `cameraTourDialogState.ts`; Öffner `state/cameraTourDialogHook`. import { memo, useCallback, useEffect, useMemo, useReducer, useRef } from "react"; import { useModalFocus } from "./modalFocus"; import { t } from "../i18n"; import { getState } from "../state/appStore"; import { cancelCameraTour, currentTourKeys, getTourSettings, playCameraTour, recordCameraTour, setTourSettings } from "../state/cameraTourActions"; import { setCameraTourDialogOpener } from "../state/cameraTourDialogHook"; import { saveBinaryFile } from "../native/saveFile"; import { runWithAnonymityGate } from "../state/anonymityGate"; import { exportProjectName } from "../core"; import { getViewportCanvas } from "../viewport/cameraBridge"; import { availableVideoFormats, videoFileName } from "../viewport/videoRecorder"; import type { TourMode } from "../viewport/cameraTour"; import { TOUR_FPS, canRecord, canStart, initialTourDialogState, parseSeconds, totalSeconds, tourDialogReducer, } from "./cameraTourDialogState"; import { PreviewBadge } from "./PreviewBadge"; export const CameraTourDialogHost = memo(function CameraTourDialogHost() { const [s, dispatch] = useReducer(tourDialogReducer, initialTourDialogState); const resultRef = useRef<{ blob: Blob; ext: string } | null>(null); const formats = useMemo(() => (s.open ? availableVideoFormats() : []), [s.open]); useEffect(() => { setCameraTourDialogOpener(() => { resultRef.current = null; const cur = getTourSettings(); dispatch({ type: "open", cameraCount: currentTourKeys().length, seconds: cur.seconds, mode: cur.mode, formats: availableVideoFormats().map((f) => f.id) }); }); return () => setCameraTourDialogOpener(null); }, []); const close = useCallback(() => dispatch({ type: "close" }), []); // [249] Fokus ins erste Feld (Dauer; nach der Aufnahme „Speichern"), Tab-Falle, Esc, Enter = Hauptaktion, Fokus zurück. // Esc während der Fahrt bricht die Fahrt ab (cameraTourPlayer); die Leiste ist kein modaler Dialog. const primaryRef = useRef<() => void>(() => {}); const dialogRef = useModalFocus({ onEscape: close, onEnter: () => primaryRef.current() }); if (!s.open) return null; const commitSettings = () => { const seconds = parseSeconds(s.secondsText); if (seconds !== null) setTourSettings({ seconds, mode: s.mode }); }; const play = async () => { if (!canStart(s)) return; commitSettings(); dispatch({ type: "start", recording: false }); const r = await playCameraTour((f) => dispatch({ type: "progress", fraction: f })); if (r.status === "unavailable" || r.status === "failed") dispatch({ type: "cancel" }); else dispatch({ type: "finish", recording: false }); }; const record = async () => { const format = availableVideoFormats().find((f) => f.id === s.format); if (!canRecord(s) || !format) return; commitSettings(); resultRef.current = null; dispatch({ type: "start", recording: true }); const r = await recordCameraTour(format, TOUR_FPS, (f) => dispatch({ type: "progress", fraction: f })); if (r.status === "done" && r.blob) { resultRef.current = { blob: r.blob, ext: format.ext }; dispatch({ type: "finish", recording: true }); } else if (r.status === "cancelled") { dispatch({ type: "cancel" }); getState().notify(t("tour.cancelled"), "info"); } else { dispatch({ type: "cancel" }); } }; const save = async () => { const res = resultRef.current; if (!res) return; try { const bytes = new Uint8Array(await res.blob.arrayBuffer()); const name = videoFileName(exportProjectName(getState().project) || "projekt", res.ext); runWithAnonymityGate(getState().project, [name], async () => { if (await saveBinaryFile(bytes, name, res.blob.type || "video/webm")) getState().notify(t("tour.saved"), "info"); }); } catch (err) { getState().notify(t("tour.recordFailed", { reason: err instanceof Error ? err.message : String(err) }), "warning"); } }; primaryRef.current = () => { if (s.phase === "done") void save(); else if (canRecord(s)) void record(); else if (canStart(s)) void play(); }; if (s.phase === "running") { return (
{s.recording ? t("tour.recording") : t("tour.playing")} {Math.round(s.progress * 100)} %
); } const canvas = getViewportCanvas(); const total = totalSeconds(s); const secondsOk = parseSeconds(s.secondsText) !== null; const res = resultRef.current; return (
e.stopPropagation()}>
{t("tour.title")}
{s.phase === "done" && res ? (
{t("tour.done", { size: (res.blob.size / 1_048_576).toFixed(1), ext: res.ext.toUpperCase() })}
) : ( <>

{t("tour.intro", { count: s.cameraCount })}

{secondsOk ? t("tour.total", { seconds: total.toFixed(1) }) : t("tour.secondsBad")}
{t("tour.video")}
{formats.length === 0 ? (
{t("tour.noRecorder")}
) : ( )}
{canvas ? t("tour.resolution", { width: canvas.width, height: canvas.height, fps: TOUR_FPS }) : t("tour.resolutionUnknown", { fps: TOUR_FPS })}
{s.cameraCount < 2 &&
{t("tour.needTwo")}
} {getState().renderMode === "pathtrace" &&
{t("tour.pathtrace")}
}
)} {s.message && (

{s.message}

)}
); });