Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

N7-5: Fly path in Cinema's 3D scene: the Path strip, the moves, Preview and Film this path

Claude0b92a7a91442
diff --git a/src/components/cinema/scene-path.tsx b/src/components/cinema/scene-path.tsx
new file mode 100644
index 00000000..1e1cf545
--- /dev/null
+++ b/src/components/cinema/scene-path.tsx
@@ -0,0 +1,200 @@
+"use client";
+
+import { Clapperboard, Loader2, Play, Plus, Square, X } from "lucide-react";
+import { useId } from "react";
+import { Button } from "@/components/ui/button";
+import { Textarea } from "@/components/ui/textarea";
+import { DEFAULT_MOTION, MAX_KEYS, PATH_FPS, PATH_FRAMES, PATH_PRESETS, keyLabel, type CameraKey } from "@/lib/camera-path";
+import { PATH_DURATIONS } from "@/lib/catalog/cinema";
+import type { Engine } from "@/lib/catalog/types";
+import { cn } from "@/lib/utils";
+
+/**
+ * Fly path in Cinema's 3D scene (build plan N7-5), the controls: the keys as chips with "+ Keyframe" and Preview (a strip
+ * over the view on wide screens), the moves, the length, the quality, the motion words and "Film this path". The viewer
+ * (scene-viewer.tsx) owns the path and the 3D engine; these only draw and report.
+ */
+
+/** The open engine always films this long. */
+export const OPEN_SECONDS = Math.round((PATH_FRAMES / PATH_FPS) * 10) / 10;
+
+export interface PathKeysProps {
+ keys: CameraKey[];
+ /** Seconds the chips' times are counted in. */
+ seconds: number;
+ disabled: boolean;
+ previewing: boolean;
+ onAdd: () => void;
+ onRemove: (index: number) => void;
+ onGoTo: (index: number) => void;
+ onPreview: () => void;
+ /** Dark glass over the 3D view, or the sheet's own colours. */
+ tone: "overlay" | "panel";
+}
+
+/** The keys in order (the start is the still's own camera), "+ Keyframe" and Preview. */
+export function PathKeys({ keys, seconds, disabled, previewing, onAdd, onRemove, onGoTo, onPreview, tone }: PathKeysProps) {
+ const full = keys.length >= MAX_KEYS;
+ const overlay = tone === "overlay";
+ const chip = overlay ? "bg-white/12 text-white hover:bg-white/20" : "bg-secondary hover:bg-accent";
+ return (
+ <div className={cn("flex min-w-0 items-center gap-1.5", overlay ? "flex-nowrap" : "flex-wrap")} role="group" aria-label="Path keyframes">
+ <div className={cn("flex min-w-0 items-center gap-1", overlay ? "overflow-x-auto [scrollbar-width:none]" : "flex-wrap")}>
+ {keys.map((k, i) =>
+ i === 0 ? (
+ <button
+ key="start"
+ type="button"
+ onClick={() => onGoTo(0)}
+ disabled={disabled}
+ className={cn("h-8 shrink-0 rounded-full px-3 text-[12px] whitespace-nowrap", chip)}
+ aria-label="Keyframe 1: the start, the still's own camera. Go there"
+ >
+ 0 s · the still
+ </button>
+ ) : (
+ <span key={i} className={cn("inline-flex h-8 shrink-0 items-center rounded-full", chip)}>
+ <button
+ type="button"
+ onClick={() => onGoTo(i)}
+ disabled={disabled}
+ className="h-full rounded-l-full pr-1 pl-3 text-[12px] whitespace-nowrap tabular-nums"
+ aria-label={`Keyframe ${i + 1}: ${keyLabel(k, seconds)}. Go there`}
+ >
+ {keyLabel(k, seconds)}
+ </button>
+ <button
+ type="button"
+ onClick={() => onRemove(i)}
+ disabled={disabled}
+ className={cn("grid h-full w-7 place-items-center rounded-r-full", overlay ? "hover:bg-white/15" : "hover:bg-background/60")}
+ aria-label={`Remove keyframe ${i + 1}`}
+ >
+ <X className="size-3.5" />
+ </button>
+ </span>
+ ),
+ )}
+ </div>
+ <Button
+ size="sm"
+ variant={overlay ? "secondary" : "outline"}
+ className="h-8 shrink-0 rounded-full"
+ onClick={onAdd}
+ disabled={disabled || full}
+ title={full ? `A path holds ${MAX_KEYS} keyframes at most` : "Adds where the camera is now (K)"}
+ >
+ <Plus /> Keyframe
+ </Button>
+ <Button size="sm" variant={overlay ? "secondary" : "outline"} className="h-8 shrink-0 rounded-full" onClick={onPreview} disabled={(disabled && !previewing) || keys.length < 2}>
+ {previewing ? <Square /> : <Play />} {previewing ? "Stop" : "Preview"}
+ </Button>
+ </div>
+ );
+}
+
+export interface PathOptionsProps {
+ engine: Engine;
+ preset: string | null;
+ onPreset: (id: string) => void;
+ duration: number;
+ onDuration: (s: number) => void;
+ resolution: string;
+ resolutions: string[];
+ onResolution: (r: string) => void;
+ words: string;
+ onWords: (w: string) => void;
+ notes: string[];
+ disabled: boolean;
+}
+
+/** The moves, the length and quality, the motion words and what will happen. */
+export function PathOptions({ engine, preset, onPreset, duration, onDuration, resolution, resolutions, onResolution, words, onWords, notes, disabled }: PathOptionsProps) {
+ const wordsId = useId();
+ const open = engine === "open";
+ return (
+ <div className="space-y-4">
+ <div className="flex flex-wrap gap-1" role="group" aria-label="Camera moves">
+ {PATH_PRESETS.map((p) => (
+ <button
+ key={p.id}
+ type="button"
+ aria-pressed={preset === p.id}
+ title={p.description}
+ disabled={disabled}
+ onClick={() => onPreset(p.id)}
+ className={cn("h-8 rounded-full px-3 text-[12.5px] whitespace-nowrap", preset === p.id ? "bg-primary text-primary-foreground" : "bg-secondary hover:bg-accent")}
+ >
+ {p.name}
+ </button>
+ ))}
+ </div>
+ <div className="space-y-1.5">
+ <p className="text-[12px] text-muted-foreground">Length</p>
+ {open ? (
+ <p className="text-[13px]">
+ About {OPEN_SECONDS} s <span className="text-muted-foreground">· {PATH_FRAMES} frames at {PATH_FPS} fps, always, on the open engine</span>
+ </p>
+ ) : (
+ <div className="flex flex-wrap gap-1" role="radiogroup" aria-label="Length">
+ {PATH_DURATIONS.map((s) => (
+ <button
+ key={s}
+ type="button"
+ role="radio"
+ aria-checked={duration === s}
+ disabled={disabled}
+ onClick={() => onDuration(s)}
+ className={cn("h-8 min-w-11 rounded-full px-2.5 font-mono text-[12px]", duration === s ? "bg-primary text-primary-foreground" : "bg-secondary hover:bg-accent")}
+ >
+ {s} s
+ </button>
+ ))}
+ </div>
+ )}
+ </div>
+ {resolutions.length > 1 && (
+ <div className="space-y-1.5">
+ <p className="text-[12px] text-muted-foreground">Quality</p>
+ <div className="inline-flex h-8 rounded-full bg-muted p-0.5" role="radiogroup" aria-label="Quality">
+ {resolutions.map((r) => (
+ <button
+ key={r}
+ type="button"
+ role="radio"
+ aria-checked={resolution === r}
+ disabled={disabled}
+ onClick={() => onResolution(r)}
+ className={cn("rounded-full px-3 text-[12.5px] font-medium", resolution === r ? "bg-background text-foreground shadow-soft" : "text-muted-foreground hover:text-foreground")}
+ >
+ {r.toLowerCase()}
+ </button>
+ ))}
+ </div>
+ </div>
+ )}
+ <div className="space-y-1.5">
+ <label htmlFor={wordsId} className="text-[12px] text-muted-foreground">
+ What moves in the shot (optional)
+ </label>
+ <Textarea id={wordsId} value={words} onChange={(e) => onWords(e.target.value)} placeholder={DEFAULT_MOTION} className="min-h-16 text-[13px]" maxLength={2000} disabled={disabled} />
+ </div>
+ {notes.map((n) => (
+ <p key={n} className="text-[12px] leading-snug text-muted-foreground">
+ {n}
+ </p>
+ ))}
+ </div>
+ );
+}
+
+/** "Film this path · price", with the browser's render progress on the open engine. */
+export function FilmButton({ onClick, busy, progress, price, disabled, className }: { onClick: () => void; busy: "render" | "send" | null; progress: number; price: string; disabled: boolean; className?: string }) {
+ const label = busy === "render" ? `Rendering the path… ${Math.round(progress * 100)}%` : busy === "send" ? "Sending…" : "Film this path";
+ return (
+ <Button onClick={onClick} disabled={disabled || !!busy} variant="secondary" className={cn("rounded-full", className)}>
+ {busy ? <Loader2 className="animate-spin" /> : <Clapperboard />} {label}
+ {!busy && <span className="opacity-80">· {price}</span>}
+ </Button>
+ );
+}
diff --git a/src/components/cinema/scene-viewer.tsx b/src/components/cinema/scene-viewer.tsx
index 0e83e462..15a45649 100644
--- a/src/components/cinema/scene-viewer.tsx
+++ b/src/components/cinema/scene-viewer.tsx
@@ -1,7 +1,7 @@
"use client";
-import { Box, Camera, CircleHelp, Loader2, RotateCcw, SlidersHorizontal, X } from "lucide-react";
-import { useEffect, useId, useMemo, useRef, useState } from "react";
+import { Box, Camera, CircleHelp, Loader2, Route, RotateCcw, SlidersHorizontal, X } from "lucide-react";
+import { useEffect, useEffectEvent, useId, useMemo, useRef, useState } from "react";
import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogDescription, DialogTitle } from "@/components/ui/dialog";
@@ -14,12 +14,14 @@ import { Textarea } from "@/components/ui/textarea";
import { EngineSwitch } from "@/components/studio/engine-switch";
import { uploadFile } from "@/lib/api";
import { getModel } from "@/lib/catalog";
-import { IMAGE_ASPECTS, RECOMPOSE_MODELS, planCinema, type CinemaGenerateInput, type DirectorSettings } from "@/lib/catalog/cinema";
+import { IMAGE_ASPECTS, PATH_MODELS, PATH_RENDER_FIRST, RECOMPOSE_MODELS, planCinema, type CinemaGenerateInput, type DirectorSettings } from "@/lib/catalog/cinema";
+import { PATH_FPS, PATH_FRAMES, PHOTO_KEY, addKey, flyPoseOf, framePoses, fromScenePose, keyAt, keyPose, presetKeys, removeKey, renderSize, type CameraKey } from "@/lib/camera-path";
import type { Engine } from "@/lib/catalog/types";
import { APERTURE, FLY_KEYS, F_STOPS, LENS, LENS_STOPS, captureSize, formatStop, frameRect, ratioOf, scenePose, twoFinger, type Rect } from "@/lib/scene3d";
import { cn } from "@/lib/utils";
import { useCinemaGenerate } from "./hooks";
import { usePlanPrice, type SceneTake } from "./scene-actions";
+import { FilmButton, OPEN_SECONDS, PathKeys, PathOptions } from "./scene-path";
import type { SceneEngine, SceneInfo } from "./scene-engine";
/**
@@ -27,6 +29,10 @@ import type { SceneEngine, SceneInfo } from "./scene-engine";
* (Shift faster), drag to look, scroll or pinch to move, two fingers to slide; a full-frame lens (18–300 mm),
* an aperture that previews the depth of field, the project's frame ratios, and Capture, which renders the
* frame to a PNG, uploads it and queues the recomposition as a new take next to the scene.
+ *
+ * Fly path (build plan N7-5): keyframe the camera (or pick a move), preview the flight, and "Film this path" films the
+ * still along it as a new take: H3 Max camera-controls on the cloud; on the open engine the browser first records the
+ * scene along the path, which guides Wan 2.1 through Uni3C on the user's GPU.
*/
export interface SceneViewerProps {
@@ -51,8 +57,9 @@ const LN_MAX = Math.log(LENS.max);
const lensToPos = (mm: number) => Math.round(((Math.log(mm) - LN_MIN) / (LN_MAX - LN_MIN)) * 1000);
const posToLens = (pos: number) => Math.round(Math.exp(LN_MIN + (pos / 1000) * (LN_MAX - LN_MIN)));
const clampLens = (mm: number) => Math.max(LENS.min, Math.min(LENS.max, Math.round(mm)));
-/** What the planner needs to price a recomposition before anything is captured. */
+/** What the planner needs to price a recomposition before anything is captured (and a path before it is recorded). */
const PLACEHOLDER_CAPTURE = "/api/files/placeholder.png";
+const PLACEHOLDER_RENDER = "/api/files/placeholder.mp4";
const isTyping = (t: EventTarget | null) => {
const el = t as HTMLElement | null;
@@ -104,6 +111,17 @@ export default function SceneViewer({ take, projectId, engine, onEngine, setting
const [capturing, setCapturing] = useState(false);
const [flash, setFlash] = useState(false);
const [queued, setQueued] = useState(0);
+ // The path: its keys (the first is the still's own camera), the move it came from, and how it is filmed.
+ const [keys, setKeys] = useState<CameraKey[]>([PHOTO_KEY]);
+ const [preset, setPreset] = useState<string | null>(null);
+ const [pathSeconds, setPathSeconds] = useState(5);
+ const [pathQuality, setPathQuality] = useState<string | null>(null);
+ const [words, setWords] = useState("");
+ const [pathOpen, setPathOpen] = useState(false);
+ const [previewing, setPreviewing] = useState(false);
+ const [filming, setFilming] = useState<"render" | "send" | null>(null);
+ const [progress, setProgress] = useState(0);
+ const previewRef = useRef<AbortController | null>(null);
const generate = useCinemaGenerate(take.generation.projectId ?? projectId);
const noteId = useId();
@@ -119,6 +137,30 @@ export default function SceneViewer({ take, projectId, engine, onEngine, setting
);
const price = usePlanPrice(plan);
+ const pathModel = getModel(PATH_MODELS[engine]);
+ const qualities = engine === "cloud" ? (pathModel?.options.resolutions ?? []) : [];
+ const quality = pathQuality && qualities.includes(pathQuality) ? pathQuality : (pathModel?.defaults?.resolution ?? qualities[0] ?? "");
+ const seconds = engine === "open" ? OPEN_SECONDS : pathSeconds;
+ const pathInput: Omit<CinemaGenerateInput, "brief"> = useMemo(
+ () => ({
+ engine,
+ mode: "video",
+ action: "path",
+ prompt: words,
+ settings,
+ source: { url: take.still, kind: "image" },
+ ...(engine === "cloud" && quality ? { resolution: quality } : {}),
+ path: { keys, duration: pathSeconds, ...(preset ? { preset } : {}) },
+ }),
+ [engine, words, settings, take.still, quality, keys, pathSeconds, preset],
+ );
+ const pathPlan = useMemo(
+ () => planCinema({ ...pathInput, brief, path: { ...pathInput.path!, ...(engine === "open" ? { render: PLACEHOLDER_RENDER } : {}) } }, context),
+ [pathInput, brief, context, engine],
+ );
+ const pathPrice = usePlanPrice(pathPlan);
+ const pathBusy = previewing || !!filming;
+
// The frame: the ratio's largest rectangle, centred, leaving room for the bars over the view.
const frame: Rect | null = useMemo(() => {
if (!stage.w || !stage.h) return null;
@@ -180,6 +222,29 @@ export default function SceneViewer({ take, projectId, engine, onEngine, setting
if (frame && status === "ready") engineRef.current?.setView({ lens, aperture, aspect: ratioOf(aspect), dof, frame, speed });
}, [lens, aperture, aspect, dof, frame, speed, status]);
+ // The camera of a key as the path films it: the still's own lens (a key's distance already counts the lens it was set with).
+ const goTo = (i: number) => {
+ const eng = engineRef.current;
+ if (!eng || !info || !keys[i]) return;
+ setLens(clampLens(info.photoLens));
+ eng.setPose(flyPoseOf(keyPose(keys[i], info.pivotDepth)));
+ };
+
+ const addKeyframe = () => {
+ const eng = engineRef.current;
+ if (!eng || !info || pathBusy) return;
+ const last = keys[keys.length - 1];
+ const k = fromScenePose(scenePose(eng.getPose(), lens, info.photoLens, info.pivotDepth), 1, last.azimuth);
+ if (Math.abs(k.azimuth - last.azimuth) < 0.5 && Math.abs(k.elevation - last.elevation) < 0.5 && Math.abs(k.distance / last.distance - 1) < 0.02) {
+ toast.info("Fly the camera somewhere new first, then add a keyframe");
+ return;
+ }
+ setKeys(addKey(keys, k));
+ setPreset(null);
+ };
+ // K on the view adds a keyframe (the key listener is set up once).
+ const onKeyframeKey = useEffectEvent(() => addKeyframe());
+
// W A S D Q E fly from anywhere in the viewer except a text field; arrows and R act on the focused view.
useEffect(() => {
const down = (e: KeyboardEvent) => {
@@ -198,6 +263,7 @@ export default function SceneViewer({ take, projectId, engine, onEngine, setting
e.preventDefault();
eng.turn(...turn[e.key]);
} else if (e.code === "KeyR") eng.reset();
+ else if (e.code === "KeyK") onKeyframeKey();
};
const up = (e: KeyboardEvent) => {
engineRef.current?.key(e.code, false);
@@ -216,6 +282,65 @@ export default function SceneViewer({ take, projectId, engine, onEngine, setting
};
}, []);
+ const pickPreset = (id: string) => {
+ const k = presetKeys(id);
+ if (!k) return;
+ setKeys(k);
+ setPreset(id);
+ };
+
+ const preview = async () => {
+ const eng = engineRef.current;
+ if (previewing) {
+ previewRef.current?.abort();
+ return;
+ }
+ if (!eng || !info || keys.length < 2 || filming) return;
+ setPathOpen(false);
+ const ctl = new AbortController();
+ previewRef.current = ctl;
+ const lensBefore = lens;
+ setLens(clampLens(info.photoLens));
+ setPreviewing(true);
+ try {
+ await eng.playPath((t) => flyPoseOf(keyPose(keyAt(keys, t), info.pivotDepth)), seconds, ctl.signal);
+ } finally {
+ setPreviewing(false);
+ setLens(lensBefore);
+ }
+ };
+
+ const filmPath = async () => {
+ const eng = engineRef.current;
+ if (!eng || !info || filming || previewing) return;
+ const blocker = pathPlan.blocker && pathPlan.blocker !== PATH_RENDER_FIRST ? pathPlan.blocker : undefined;
+ if (blocker) {
+ toast.error(blocker);
+ return;
+ }
+ setPathOpen(false);
+ try {
+ let render: string | undefined;
+ if (engine === "open") {
+ // The still's own view along the path: Uni3C's guide, in the still's shape (the open run keeps it).
+ setFilming("render");
+ setProgress(0);
+ const poses = framePoses(keys, PATH_FRAMES, info.pivotDepth, info.photoFov.h, renderSize(info.photoAspect));
+ const rec = await eng.recordPath(poses, { fps: PATH_FPS, onProgress: setProgress });
+ const ext = rec.type.includes("mp4") ? "mp4" : "webm";
+ setFilming("send");
+ render = (await uploadFile(new File([rec.render], `path-render.${ext}`, { type: rec.type }))).url;
+ } else setFilming("send");
+ await generate.mutateAsync({ input: { ...pathInput, path: { ...pathInput.path!, ...(render ? { render } : {}) } }, folderId: take.generation.folderId });
+ setQueued((n) => n + 1);
+ toast.success("Filming this path — it lands next to the scene as a new take", { duration: 3000 });
+ } catch (e) {
+ toast.error((e as Error).message || "Couldn't film this path");
+ } finally {
+ setFilming(null);
+ }
+ };
+
const resetView = () => {
engineRef.current?.reset();
if (info) setLens(clampLens(info.photoLens));
@@ -364,6 +489,51 @@ export default function SceneViewer({ take, projectId, engine, onEngine, setting
</div>
);
+ const pathKeys = (tone: "overlay" | "panel") => (
+ <PathKeys
+ keys={keys}
+ seconds={seconds}
+ disabled={status !== "ready" || !!filming || (previewing && tone === "panel")}
+ previewing={previewing}
+ onAdd={addKeyframe}
+ onRemove={(i) => {
+ setKeys(removeKey(keys, i));
+ setPreset(null);
+ }}
+ onGoTo={goTo}
+ onPreview={() => void preview()}
+ tone={tone}
+ />
+ );
+
+ const pathOptions = (
+ <PathOptions
+ engine={engine}
+ preset={preset}
+ onPreset={pickPreset}
+ duration={pathSeconds}
+ onDuration={setPathSeconds}
+ resolution={quality}
+ resolutions={qualities}
+ onResolution={setPathQuality}
+ words={words}
+ onWords={setWords}
+ notes={pathPlan.notes}
+ disabled={status !== "ready" || pathBusy}
+ />
+ );
+
+ const filmButton = (className?: string) => (
+ <FilmButton
+ onClick={() => void filmPath()}
+ busy={filming}
+ progress={progress}
+ price={pathPrice.label}
+ disabled={status !== "ready" || previewing || keys.length < 2}
+ className={className}
+ />
+ );
+
const captureButton = (className?: string) => (
<Button onClick={() => void capture()} disabled={status !== "ready" || capturing} className={cn("rounded-full", className)}>
{capturing ? <Loader2 className="animate-spin" /> : <Camera />} {captureLabel} <span className="opacity-80">· {price.label}</span>
@@ -441,7 +611,7 @@ export default function SceneViewer({ take, projectId, engine, onEngine, setting
<p className="truncate text-[11.5px] text-white/70">
{kind === "points" ? "Point cloud from a depth map" : info?.layout === "object" ? "3D model" : "MoGe 2 mesh"}
{sizeText ? ` · ${sizeText}` : ""}
- {queued ? ` · ${queued} re-render${queued > 1 ? "s" : ""} queued` : ""}
+ {queued ? ` · ${queued} new take${queued > 1 ? "s" : ""} queued` : ""}
</p>
</div>
<button type="button" onClick={() => setHelp((v) => !v)} aria-pressed={help} aria-label="Controls" className="grid size-9 place-items-center rounded-full hover:bg-white/15">
@@ -455,8 +625,20 @@ export default function SceneViewer({ take, projectId, engine, onEngine, setting
</button>
</div>
+ {/* Wide screens: the path's keys over the view, beside the frame (phones get them in the Path sheet). */}
+ {status === "ready" && (
+ <div className="absolute inset-x-3 bottom-3 hidden justify-center md:flex">
+ <div role="group" aria-label="Fly path" className="flex max-w-full min-w-0 items-center gap-2 rounded-full bg-black/65 py-1 pr-1 pl-3 text-white backdrop-blur">
+ <span className="flex shrink-0 items-center gap-1.5 text-[12px] font-medium">
+ <Route className="size-3.5" aria-hidden /> Path
+ </span>
+ {pathKeys("overlay")}
+ </div>
+ </div>
+ )}
+
{help && status === "ready" && (
- <div className="absolute bottom-3 left-3 max-w-[calc(100%-1.5rem)] rounded-xl bg-black/65 px-3 py-2 text-[12px] leading-relaxed text-white/90 backdrop-blur">
+ <div className="absolute bottom-3 left-3 max-w-[calc(100%-1.5rem)] rounded-xl bg-black/65 px-3 py-2 text-[12px] leading-relaxed text-white/90 backdrop-blur md:bottom-16">
{coarse ? (
<p>Drag to look · two fingers to move · pinch to go forward or back</p>
) : (
@@ -471,6 +653,9 @@ export default function SceneViewer({ take, projectId, engine, onEngine, setting
<Kbd>Shift</Kbd> faster
</span>
<span>drag to look · scroll to go forward</span>
+ <span>
+ <Kbd>K</Kbd> keyframe
+ </span>
</p>
)}
</div>
@@ -508,8 +693,11 @@ export default function SceneViewer({ take, projectId, engine, onEngine, setting
{/* Phones: the capture stays in reach; the camera and re-render settings open in a sheet. */}
<div className="flex shrink-0 items-center gap-2 border-t border-white/10 bg-[#0b0b0c] px-3 pt-2 pb-[max(0.5rem,env(safe-area-inset-bottom))] md:hidden">
- <Button variant="secondary" className="rounded-full" onClick={() => setPanelOpen(true)}>
- <SlidersHorizontal /> Camera
+ <Button variant="secondary" size="icon" className="shrink-0 rounded-full" onClick={() => setPanelOpen(true)} aria-label="Camera" title="Camera: lens, aperture, frame">
+ <SlidersHorizontal />
+ </Button>
+ <Button variant="secondary" className="shrink-0 rounded-full px-3" onClick={() => setPathOpen(true)} disabled={status !== "ready"} aria-label={`Path, ${keys.length - 1} keyframe${keys.length === 2 ? "" : "s"}`}>
+ {filming ? <Loader2 className="animate-spin" /> : <Route />} Path{keys.length > 1 ? ` · ${keys.length - 1}` : ""}
</Button>
{captureButton("min-w-0 flex-1")}
</div>
@@ -526,15 +714,31 @@ export default function SceneViewer({ take, projectId, engine, onEngine, setting
</div>
</SheetContent>
</Sheet>
+ <Sheet open={pathOpen} onOpenChange={setPathOpen}>
+ <SheetContent side="bottom" className="max-h-[80svh] gap-0 overflow-y-auto rounded-t-2xl p-0 md:hidden">
+ <SheetHeader className="border-b px-4 py-3">
+ <SheetTitle className="font-heading text-[20px] font-normal">Fly path</SheetTitle>
+ <SheetDescription className="text-[12.5px]">Fly the camera, add keyframes or pick a move, then film the still along the path.</SheetDescription>
+ </SheetHeader>
+ <div className="space-y-5 p-4">
+ {pathKeys("panel")}
+ {pathOptions}
+ <EngineSwitch value={engine} onChange={onEngine} size="sm" />
+ {filmButton("w-full")}
+ </div>
+ </SheetContent>
+ </Sheet>
<aside className="hidden w-[320px] shrink-0 flex-col border-l bg-background md:flex" aria-label="Camera and re-render">
<div className="min-h-0 flex-1 space-y-6 overflow-y-auto p-4">
{camera}
{rerender}
+ <Section title="Fly path">{pathOptions}</Section>
</div>
<div className="space-y-1.5 border-t p-4">
{captureButton("w-full")}
- <p className="text-center text-[11.5px] text-muted-foreground">Renders the frame, then re-renders it as a new take next to the scene</p>
+ {filmButton("w-full")}
+ <p className="text-center text-[11.5px] text-muted-foreground">Capture re-renders the frame; Film follows the path. Both land next to the scene</p>
</div>
</aside>
</DialogContent>
diff --git a/tests/e2e/cinema-path.mjs b/tests/e2e/cinema-path.mjs
new file mode 100644
index 00000000..f6ae6fb5
--- /dev/null
+++ b/tests/e2e/cinema-path.mjs
@@ -0,0 +1,235 @@
+// Fly path in Cinema's 3D scene (build plan N7-5) in a real browser (the app must be running in demo mode; WebGL runs
+// on SwiftShader). Usage: node tests/e2e/cinema-path.mjs [appUrl] [--shots=dir]. Exits 1 on the first failure.
+//
+// 1. 1440 px, light, cloud: the Path strip over the view (the still's chip, + Keyframe, Preview), the moves, the length
+// and quality, the motion words and "Film this path · price" beside Capture; K and + Keyframe add the flown pose as a
+// chip; a move replaces the keys; Preview flies the camera and gives it back; Film queues an H3 Max take that carries
+// the keys; Capture still re-renders a view. Keyboard focus reaches every new control; nothing scrolls sideways.
+// 2. 1440 px, dark, open engine: Film records the scene along the path in the browser (81 frames), uploads it and queues
+// the Uni3C take with the still and the render; the render is a real video of 81 frames in the still's shape.
+// 3. 390 px, light and dark: the Path button opens the Fly path sheet with the same controls; nothing scrolls sideways;
+// a finger drag on the view turns it.
+import assert from "node:assert/strict";
+import { execFileSync } from "node:child_process";
+import fs from "node:fs";
+import os from "node:os";
+import path from "node:path";
+import { DESKTOP, PHONE, chromiumPath, loadPlaywright } from "./_browser.mjs";
+
+const args = process.argv.slice(2);
+const app = (args.find((a) => !a.startsWith("--")) ?? "http://localhost:3000").replace(/\/$/, "");
+const shots = args.find((a) => a.startsWith("--shots="))?.slice(8);
+if (shots) fs.mkdirSync(shots, { recursive: true });
+const { chromium } = loadPlaywright();
+const browser = await chromium.launch({ executablePath: chromiumPath(), args: ["--use-angle=swiftshader", "--enable-unsafe-swiftshader", "--ignore-gpu-blocklist"] });
+const step = (name) => console.log(`- ${name}`);
+const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
+const api = browser.newContext().then((c) => c.request);
+async function call(url, method = "GET", data) {
+ const res = await (await api).fetch(app + url, { method, headers: { "Content-Type": "application/json" }, data: data === undefined ? undefined : JSON.stringify(data) });
+ return res.json();
+}
+async function until(fn, what, ms = 90_000) {
+ const t = Date.now();
+ for (;;) {
+ const v = await fn();
+ if (v) return v;
+ if (Date.now() - t > ms) throw new Error(`Timed out waiting for ${what}`);
+ await sleep(700);
+ }
+}
+const shoot = (page, name) => shots && page.screenshot({ path: path.join(shots, `${name}.png`) });
+const hideDevBadge = (ctx) =>
+ ctx.addInitScript(() =>
+ document.addEventListener("DOMContentLoaded", () => {
+ const s = document.createElement("style");
+ s.textContent = "nextjs-portal{display:none!important}";
+ document.head.append(s);
+ }),
+ );
+const noSideScroll = async (page, what) => assert.equal(await page.evaluate(() => document.documentElement.scrollWidth - window.innerWidth), 0, `${what}: nothing scrolls sideways`);
+
+const status = await call("/api/status");
+assert.notEqual(status.demoMode, "off", "run the app in demo mode (FUOBE_DEMO_MODE=on)");
+const project = await call("/api/cinema/projects", "POST", { name: "Fly path check" });
+const items = async () => (await call(`/api/cinema/projects/${project.id}/items`)).items;
+const errors = [];
+let failed = false;
+
+async function openScene(ctx, engine) {
+ await ctx.addInitScript((e) => localStorage.setItem("fuobe.engine", e), engine);
+ await hideDevBadge(ctx);
+ const page = await ctx.newPage();
+ page.on("pageerror", (e) => errors.push(e.message));
+ await page.goto(`${app}/cinema/${project.id}`, { waitUntil: "load", timeout: 120_000 });
+ await page.locator(`button[aria-label="Open 3D scene"]`).first().click({ force: true, timeout: 90_000 });
+ await page.getByText(/Point cloud from a depth map · \d+k points/).waitFor({ timeout: 60_000 });
+ return page;
+}
+
+try {
+ step("a still and its cloud 3D scene");
+ const settings = { camera: "modern", lens: "clean-sharp", focal: "24mm" };
+ const made = await call(`/api/cinema/projects/${project.id}/generate`, "POST", {
+ input: { engine: "cloud", mode: "image", action: "generate", prompt: "A dancer on a rooftop at dusk", settings, aspectRatio: "16:9" },
+ });
+ const still = await until(async () => (await items()).find((g) => g.id === made.items?.[0]?.id && g.status === "succeeded"), "the still");
+ const built = await call(`/api/cinema/projects/${project.id}/generate`, "POST", {
+ input: { engine: "cloud", mode: "image", action: "scene", prompt: "", settings, source: { url: still.outputs[0].url, kind: "image" }, aspectRatio: "16:9" },
+ });
+ await until(async () => (await items()).find((g) => g.id === built.items?.[0]?.id && g.status === "succeeded"), "the scene");
+
+ step("1440 light, cloud: the Path strip, the moves and Film beside Capture");
+ const ctx = await browser.newContext({ ...DESKTOP, colorScheme: "light" });
+ const page = await openScene(ctx, "cloud");
+ const strip = page.getByLabel("Fly path", { exact: true });
+ await strip.getByRole("button", { name: /Keyframe 1: the start/ }).waitFor();
+ const keyframe = strip.getByRole("button", { name: "Keyframe", exact: true });
+ const previewBtn = strip.getByRole("button", { name: "Preview" });
+ assert.equal(await previewBtn.isDisabled(), true, "Preview waits for a second keyframe");
+ const film = page.getByRole("complementary").getByRole("button", { name: /^Film this path · Demo · free$/ });
+ await film.waitFor();
+ assert.equal(await film.isDisabled(), true, "Film waits for a path");
+ await page.getByRole("complementary").getByRole("button", { name: /^Capture · Demo · free/ }).waitFor();
+ await noSideScroll(page, "desktop viewer");
+
+ step("flying and + Keyframe / K add the pose as a chip");
+ const canvas = page.locator("canvas[aria-roledescription='3D view']");
+ await canvas.focus();
+ const pixels = () => canvas.screenshot().then((b) => b.toString("base64"));
+ await page.keyboard.down("KeyD");
+ await sleep(500);
+ await page.keyboard.up("KeyD");
+ for (let i = 0; i < 8; i++) await page.keyboard.press("ArrowLeft");
+ await keyframe.click();
+ const chips = () => strip.getByRole("button", { name: /^Keyframe \d+: \d/ });
+ await until(async () => (await chips().count()) === 1, "the first keyframe chip");
+ assert.match(await chips().first().innerText(), /^5\.0 s · -?\d+° · [+-]?\d+° · \d\.\dx$/);
+ await canvas.focus();
+ await page.keyboard.down("KeyA");
+ await sleep(700);
+ await page.keyboard.up("KeyA");
+ await page.keyboard.press("KeyK");
+ await until(async () => (await chips().count()) === 2, "the K keyframe");
+ assert.match(await chips().first().innerText(), /^2\.5 s/);
+ await shoot(page, "path-desktop-keys");
+
+ step("a move replaces the keys; Preview flies the camera and gives it back");
+ await page.getByRole("button", { name: "Orbit 360°" }).click();
+ await until(async () => (await chips().count()) === 4, "the orbit's keys");
+ assert.equal(await page.getByRole("button", { name: "Orbit 360°" }).getAttribute("aria-pressed"), "true");
+ assert.match(await chips().nth(1).innerText(), /^2\.5 s · 180° · 0° · 1\.0x$/);
+ // Pixels of the view with the pointer away from the strip (a hovered button would differ).
+ const settled = async () => {
+ await page.mouse.move(1300, 20);
+ await sleep(250);
+ return pixels();
+ };
+ const before = await settled();
+ await previewBtn.click();
+ await strip.getByRole("button", { name: "Stop" }).waitFor();
+ await sleep(1500);
+ assert.notEqual(await pixels(), before, "Preview flies the camera");
+ await strip.getByRole("button", { name: "Preview" }).waitFor({ timeout: 15_000 });
+ assert.equal(await settled(), before, "the camera is back where it was");
+ await shoot(page, "path-desktop-light");
+
+ step("keyboard focus reaches every new control");
+ await canvas.focus();
+ const seen = new Set();
+ for (let i = 0; i < 80; i++) {
+ await page.keyboard.press("Tab");
+ const name = await page.evaluate(() => {
+ const el = document.activeElement;
+ return el ? (el.getAttribute("aria-label") || el.textContent || el.getAttribute("placeholder") || "").trim() : "";
+ });
+ seen.add(name);
+ }
+ for (const want of [/^Keyframe 1: the start/, /^Keyframe 2: /, /^Remove keyframe 2$/, /^Keyframe$/, /^Preview$/, /^Orbit 360°$/, /^Truck right$/, /^5 s$/, /^768p$/, /^Film this path/, /^Capture/]) {
+ assert.ok([...seen].some((s) => want.test(s)), `focus reaches ${want} (saw: ${[...seen].slice(0, 60).join(" | ")})`);
+ }
+ assert.ok(await page.getByPlaceholder("The character keeps moving naturally while the camera follows the path").isVisible(), "the motion words field");
+
+ step("Film queues an H3 Max take that carries the path; Capture still re-renders a view");
+ await page.getByRole("radio", { name: "8 s" }).click();
+ await page.getByPlaceholder(/keeps moving naturally/).fill("The dancer spins");
+ await film.click();
+ await page.locator("[data-sonner-toast]").filter({ hasText: "Filming this path" }).waitFor({ timeout: 30_000 });
+ const cloudTake = await until(async () => (await items()).find((g) => g.feature === "cinema-path"), "the cloud path take");
+ assert.equal(cloudTake.request.modelId, "minimax-h3-max-camera");
+ assert.equal(cloudTake.request.op, "camera-path");
+ assert.equal(cloudTake.request.params.cameraPath.length, 5);
+ assert.equal(cloudTake.request.params.duration, 8);
+ assert.equal(cloudTake.request.prompt, "The dancer spins");
+ assert.equal(cloudTake.request.inputs.images.length, 1, "the still is the first frame");
+ assert.equal(cloudTake.take?.path?.preset, "orbit_360");
+ await page.getByRole("complementary").getByRole("button", { name: /^Capture/ }).click();
+ await page.locator("[data-sonner-toast]").filter({ hasText: "Re-rendering this view" }).waitFor({ timeout: 30_000 });
+ await until(async () => (await items()).find((g) => g.feature === "cinema-recompose"), "the recomposition");
+ await ctx.close();
+
+ step("1440 dark, open engine: Film records the path in the browser and queues the Uni3C take");
+ const dark = await browser.newContext({ ...DESKTOP, colorScheme: "dark" });
+ const p2 = await openScene(dark, "open");
+ await p2.getByRole("button", { name: "Dolly in" }).click();
+ await p2.getByText(/About 5\.1 s · 81 frames at 16 fps/).waitFor();
+ const openFilm = p2.getByRole("complementary").getByRole("button", { name: /^Film this path · Demo · free$/ });
+ await shoot(p2, "path-desktop-dark-open");
+ await openFilm.click();
+ await p2.getByRole("complementary").getByRole("button", { name: /Rendering the path… \d+%/ }).waitFor({ timeout: 10_000 });
+ await p2.locator("[data-sonner-toast]").filter({ hasText: "Filming this path" }).waitFor({ timeout: 60_000 });
+ const openTake = await until(async () => (await items()).find((g) => g.feature === "cinema-path" && g.request.modelId === "oss-uni3c-path"), "the open path take");
+ const render = openTake.request.inputs.video;
+ assert.match(render, /^\/api\/files\/uploads\/.+\.(webm|mp4)$/);
+ const tmp = path.join(fs.mkdtempSync(path.join(os.tmpdir(), "fuobe-path-")), path.basename(render));
+ fs.writeFileSync(tmp, Buffer.from(await (await (await api).fetch(app + render)).body()));
+ const probe = JSON.parse(execFileSync("ffprobe", ["-v", "error", "-count_frames", "-select_streams", "v:0", "-show_entries", "stream=width,height,nb_read_frames", "-of", "json", tmp]).toString()).streams[0];
+ console.log(` render: ${path.extname(tmp)} ${probe.width}x${probe.height}, ${probe.nb_read_frames} frames`);
+ assert.equal(Number(probe.nb_read_frames), 81, "the render has 81 frames");
+ assert.equal(probe.width, 832, "the render is the still's 16:9 shape on Wan's grid");
+ assert.equal(probe.height, 464);
+ await noSideScroll(p2, "desktop dark");
+ await dark.close();
+
+ for (const scheme of ["light", "dark"]) {
+ step(`390 ${scheme}: the Path sheet, no sideways scroll, a finger drag turns the view`);
+ const phone = await browser.newContext({ ...PHONE, colorScheme: scheme });
+ const p3 = await openScene(phone, "cloud");
+ await noSideScroll(p3, `phone ${scheme}`);
+ const view = p3.locator("canvas[aria-roledescription='3D view']");
+ const shot = () => view.screenshot().then((b) => b.toString("base64"));
+ const a = await shot();
+ const box = await view.boundingBox();
+ const cdp = await phone.newCDPSession(p3);
+ const at = (x, y) => [{ x: box.x + x, y: box.y + y, id: 1 }];
+ await cdp.send("Input.dispatchTouchEvent", { type: "touchStart", touchPoints: at(200, 200) });
+ for (let i = 1; i <= 10; i++) await cdp.send("Input.dispatchTouchEvent", { type: "touchMove", touchPoints: at(200 - i * 12, 200) });
+ await cdp.send("Input.dispatchTouchEvent", { type: "touchEnd", touchPoints: [] });
+ await sleep(400);
+ assert.notEqual(await shot(), a, "a finger drag turns the view");
+ await p3.getByRole("button", { name: /^Path, 0 keyframes$/ }).click();
+ const sheet = p3.getByRole("dialog", { name: "Fly path" });
+ await sheet.getByRole("button", { name: "Keyframe", exact: true }).click();
+ await sheet.getByRole("button", { name: /^Keyframe 2: 5\.0 s/ }).waitFor();
+ await sheet.getByRole("button", { name: "Tilted ring" }).click();
+ await sheet.getByRole("button", { name: /^Keyframe 9: 5\.0 s · 360°/ }).waitFor();
+ await sheet.getByRole("button", { name: /^Film this path · Demo · free$/ }).waitFor();
+ await noSideScroll(p3, `phone ${scheme} sheet`);
+ const sheetBox = await sheet.boundingBox();
+ assert.ok(sheetBox.width <= 390, "the sheet fits the phone");
+ await shoot(p3, `path-phone-${scheme}`);
+ await p3.keyboard.press("Escape");
+ await p3.getByRole("button", { name: "Path, 8 keyframes" }).waitFor();
+ await phone.close();
+ }
+
+ assert.deepEqual(errors, [], "no page errors");
+ console.log("\nAll Fly path checks passed.");
+} catch (e) {
+ failed = true;
+ console.log(`FAIL ${e.message.split("\n")[0]}`);
+} finally {
+ await call(`/api/cinema/projects/${project.id}`, "DELETE").catch(() => {});
+ await browser.close();
+}
+process.exit(failed ? 1 : 0);