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-6: the turnaround plan: sides, WorldCast's convention, routes per engine, prices

Claude3d0225abf0a6
diff --git a/src/lib/catalog/turnaround.ts b/src/lib/catalog/turnaround.ts
new file mode 100644
index 00000000..789e0e37
--- /dev/null
+++ b/src/lib/catalog/turnaround.ts
@@ -0,0 +1,584 @@
+/**
+ * Turnaround video (build plan N7-6; research new-models-7.md §3.7 recipes (B) and (C), §3.10 row 2): one click on a cast
+ * sheet or a saved character makes a 360° turnaround of the same person, on both engines, with routes Fuobe already has.
+ *
+ * - The views: the person's front, right side, back and left side (their own left and right, as Image to 3D's side picker
+ * names them), filmed in that order and back to the front. Sides nobody has a picture of are drawn first from the front
+ * view by the Angles app's route (the Multiple-Angles LoRA); a sheet with no front view gets one drawn from it.
+ * - Open engine: Frames mode's chain (Wan 2.2 14B start / end-frame clips, src/server/chains.ts createKeyframeFilm) with
+ * the views at 0, ¼, ½, ¾ and the end of the clip, and the orbit words.
+ * - Cloud: MiniMax H3 Max reference-to-video with the views as Image 1…n (recipe C), FLUX 3 Max keyframes-to-video with
+ * the views at their quarters (recipe B), or, from the front view alone, H3 Max camera controls on an exact path (A).
+ *
+ * N7-9 later puts WorldCast behind the same buttons on the open engine; its side names and angles are written down here.
+ * Pure: the browser prices it live, the server runs the same steps (src/server/turnaround.ts, Cinema's "turnaround").
+ */
+import { PATH_PRESETS, presetKeys, type CameraKey } from "@/lib/camera-path";
+import { poseWords } from "@/lib/scene3d";
+import { getModel, getPreset } from "./index";
+import { onEngine } from "./engines";
+import { FRAMES_MODELS, chainGapProblem, chainTiming, frameTimes } from "./keyframes";
+import { ANGLES_2511_LORA } from "./open-tools";
+import { estimateCost, planGeneration } from "./plan";
+import type { ChainSlot, Engine, Generation, GenerationRequest, GenParams, ModelDef } from "./types";
+
+// ---------------------------------------------------------------------------
+// Sides
+
+export type TurnSide = "front" | "right" | "back" | "left";
+/** The order the camera passes the sides: front → right side → back → left side (then the front again). */
+export const TURN_SIDES: readonly TurnSide[] = ["front", "right", "back", "left"];
+export const SIDE_NAMES: Record<TurnSide, string> = { front: "Front", right: "Right side", back: "Back", left: "Left side" };
+/** Said beside the side picker (Image to 3D says the same of objects, src/lib/av/model3d.ts SIDES_HINT). */
+export const SIDES_HINT = "Left and right are the person's own: facing them, their right side is on your left.";
+
+const AZIMUTH: Record<TurnSide, number> = { front: 0, right: 90, back: 180, left: 270 };
+
+/**
+ * Where the camera stands to see a side, in degrees round the person from their front: front 0°, right side 90°, back 180°,
+ * left side 270°. Left and right are the person's own (their right side faces your left when they face you), like Image to
+ * 3D's side picker. A turnaround passes them in this order, so its azimuth only grows.
+ */
+export function viewAzimuth(side: TurnSide): number {
+ return AZIMUTH[side];
+}
+
+/** The film's frames: the four sides at 0, ¼, ½ and ¾ of the clip, and the front again at its end. */
+export const TURN_FRAMES: readonly { side: TurnSide; t: number }[] = [...TURN_SIDES.map((side) => ({ side, t: viewAzimuth(side) / 360 })), { side: "front" as const, t: 1 }];
+
+/**
+ * The same camera in the camera-path library's terms (src/lib/camera-path.ts, where + is moved round to the viewer's
+ * right): seeing the person's right side means moving round to the viewer's left, so a turnaround is a clockwise orbit
+ * seen from above (presetKeys("orbit_360_cw")).
+ */
+export function pathAzimuth(side: TurnSide): number {
+ return -viewAzimuth(side) + 0;
+}
+
+/**
+ * WorldCast's convention, for N7-9 (new-models-7.md §3.4, §3.11): its 1–4 anchor photos are named front, right_side, back and
+ * left_side, with each one's azimuth in body_views_meta.json. Its demo case puts them at 0°, 91.79°, 171.39° and 266.91°, with
+ * `left_sign` −1 (the left side is reached turning the other way: −93°, the same place as 267°). That is viewAzimuth's turn:
+ * a side keeps its name and sits within a few degrees of the angle here. Convert in worldcastAnchor and nowhere else; a
+ * swapped left and right silently hurts identity.
+ */
+export const WORLDCAST = {
+ anchor: { front: "front", right: "right_side", back: "back", left: "left_side" } as const satisfies Record<TurnSide, string>,
+ /** The demo case's azimuths (demo_case/A360-031__portrait/body_views_vggt/body_views_meta.json). */
+ demoAzimuth: { front: 0, right_side: 91.79, back: 171.39, left_side: 266.91 },
+ leftSign: -1 as const,
+};
+
+/** A side as a WorldCast anchor: its name and the azimuth to write for it (left_side signed by `left_sign`: −90°). */
+export function worldcastAnchor(side: TurnSide): { name: (typeof WORLDCAST.anchor)[TurnSide]; azimuth: number; signed: number } {
+ const azimuth = viewAzimuth(side);
+ return { name: WORLDCAST.anchor[side], azimuth, signed: side === "left" ? WORLDCAST.leftSign * (360 - azimuth) : azimuth };
+}
+
+/**
+ * The Angles app's horizontal_angle for a side. The Multiple-Angles LoRA calls 90° the "right side view", read here as the
+ * person's own right side. Neither its card nor fal's page says whose right that is: one constant to flip after the first
+ * real run (as N7-5 keeps H3's azimuth sign behind H3_AZIMUTH_SIGN).
+ */
+export const ANGLES_SIDE_SIGN: 1 | -1 = 1;
+export function anglesHorizontal(side: TurnSide): number {
+ return (((viewAzimuth(side) * ANGLES_SIDE_SIGN) % 360) + 360) % 360;
+}
+
+// ---------------------------------------------------------------------------
+// Routes
+
+export type TurnRoute = "frames" | "references" | "keyframes" | "camera";
+
+export interface TurnRouteInfo {
+ engine: Engine;
+ modelId: string;
+ name: string;
+ /** One line under the choice. */
+ detail: string;
+ durations: number[];
+ duration: number;
+ resolution: string;
+}
+
+/** The routes, the open engine's first, then the cloud's in the order they are offered. */
+export const TURN_ROUTES: Record<TurnRoute, TurnRouteInfo> = {
+ frames: {
+ engine: "open",
+ modelId: FRAMES_MODELS.open.id,
+ name: "Frames",
+ detail: "Wan 2.2 14B films each quarter turn from one view to the next, then joins them",
+ durations: [5, 8, 10, 15, 20],
+ duration: 8,
+ resolution: "480p",
+ },
+ references: {
+ engine: "cloud",
+ modelId: "minimax-h3-max",
+ name: "References",
+ detail: "MiniMax H3 Max takes every view as a reference (Image 1, Image 2…) and turns the camera from your words",
+ durations: [5, 8, 10, 15],
+ duration: 5,
+ resolution: "768P",
+ },
+ keyframes: {
+ engine: "cloud",
+ modelId: FRAMES_MODELS.cloud.id,
+ name: "Keyframes",
+ detail: "FLUX 3 Max puts each view at its quarter of the turn",
+ durations: [5, 6, 8, 10, 12, 15, 20],
+ duration: 8,
+ resolution: "720p",
+ },
+ camera: {
+ engine: "cloud",
+ modelId: "minimax-h3-max-camera",
+ name: "Camera path",
+ detail: "MiniMax H3 Max camera controls follow an exact path from the front view alone; it invents the sides and back",
+ durations: [3, 4, 5, 6, 8, 10, 12, 15],
+ duration: 5,
+ resolution: "768P",
+ },
+};
+
+export const ROUTES_ON: Record<Engine, TurnRoute[]> = { open: ["frames"], cloud: ["references", "keyframes", "camera"] };
+
+/** The Angles app's routes, which draw a missing side from the front view. */
+export const FILL_MODELS: Record<Engine, string> = { cloud: "qwen-multiple-angles", open: "oss-qwen-edit" };
+/** What draws a front view from a whole sheet, when no picture shows the front alone. */
+export const SHEET_FRONT_MODELS: Record<Engine, string> = { cloud: "nano-banana-pro", open: "oss-qwen-edit" };
+
+/** The camera route's paths (N7-5's moves); the turnaround's own Orbit 360° passes the right side first, as the views do. */
+export const TURN_PATHS = [
+ { id: "orbit_360_cw", name: "Orbit 360°", description: "A full level ring, past their right side first, as the views are ordered" },
+ ...PATH_PRESETS.filter((p) => ["orbit_90_cw", "orbit_90_ccw", "orbit_180_push", "orbit_tilt_20", "zoom_in", "zoom_out"].includes(p.id)),
+];
+export const DEFAULT_PATH = TURN_PATHS[0].id;
+
+/** The words every turnaround films to (the open engine's and FLUX 3 Max's frames, the camera path). */
+export const ORBIT_PROMPT = "The camera orbits 360 degrees around the person at a constant height; the person stands naturally";
+
+const FILL_KEEP = "Keep the same person: identity, face, hair, body, outfit, lighting and plain background";
+const SHEET_FRONT_PROMPT =
+ "Image 1 is a character turnaround sheet. Show only this character's front view as one full-body picture, centred and facing the camera, on the same plain backdrop and light. Keep the face, hair, body and outfit exactly as on the sheet; no text, no other views";
+
+const tidy = (p: string | undefined) => (p ?? "").trim().replace(/[.\s]+$/, "");
+const withWords = (base: string, extra: string | undefined) => (tidy(extra) ? `${base}. ${tidy(extra)}` : base);
+
+/** What a reference is to H3 Max, in its prompt ("Image 2 is their right side"). */
+const REF_WORDS: Record<TurnSide | "sheet", string> = {
+ front: "the person's front view",
+ right: "their right side",
+ back: "their back",
+ left: "their left side",
+ sheet: "a turnaround sheet of the same person",
+};
+
+/**
+ * The reference-to-video words: each Image N named for the side it shows, then the orbit, in the sides' order. H3 Max
+ * reads Image 1…n in reference_image_urls order (fal's schema), and Image 1 is also the first frame.
+ */
+export function referencesPrompt(order: (TurnSide | "sheet")[], extra?: string): string {
+ const named = order.map((k, i) => `Image ${i + 1} is ${REF_WORDS[k]}`).join(", ");
+ const seen = order.filter((k): k is TurnSide => k !== "sheet");
+ const path = seen.length > 1 || order.includes("sheet") ? "from the front past their right side, their back and their left side back to the front" : "all the way round them";
+ return withWords(`${named}. The camera orbits 360 degrees around the person at a constant height, ${path}; the person stands naturally and looks the same from every side as in the images`, extra);
+}
+
+// ---------------------------------------------------------------------------
+// The pictures a sheet or a character offers
+
+export interface TurnPicture {
+ url: string;
+ label: string;
+ /** The side it shows, when known (the Soul Cast sheet graph's cut views). */
+ side?: TurnSide;
+ /** A whole turnaround sheet (several views in one picture). */
+ sheet?: boolean;
+}
+
+/** The open Soul Cast sheet graph cuts the sheet into four views, in this order (soul-cast-sheet-zimage, ImageGridtoBatch 4×1). */
+const TILES: { label: string; side?: TurnSide }[] = [{ label: "Front", side: "front" }, { label: "Three-quarter" }, { label: "Profile" }, { label: "Back", side: "back" }];
+
+/**
+ * The pictures a finished Character Sheet or Soul Cast result offers: the views its graph cut (front and back known; the
+ * three-quarter and profile turn either way, so the user places them), the sheet itself, and the photos it was made from
+ * (the first is the front when nothing else is).
+ */
+export function sheetPictures(g: Pick<Generation, "outputs" | "request">): TurnPicture[] {
+ const out: TurnPicture[] = [];
+ const images = g.outputs.filter((o) => o.kind === "image");
+ const tiles = images.filter((o) => o.meta?.role === "tiles");
+ images.forEach((o, i) => {
+ if (o.meta?.role === "tiles") {
+ const n = tiles.indexOf(o);
+ const tile = TILES[typeof o.meta?.index === "number" ? (o.meta.index as number) : n];
+ out.push({ url: o.url, label: tile?.label ?? `View ${n + 1}`, ...(tile?.side && { side: tile.side }) });
+ } else if (o.meta?.role === "sheet" || i === 0) out.push({ url: o.url, label: "Sheet", sheet: true });
+ else out.push({ url: o.url, label: `Picture ${i + 1}` });
+ });
+ const photos = (g.request.inputs?.images ?? []).filter((u) => u.startsWith("/api/files/"));
+ const hasFront = out.some((p) => p.side === "front");
+ photos.forEach((url, i) => out.push({ url, label: `Photo ${i + 1}`, ...(i === 0 && !hasFront && { side: "front" as const }) }));
+ return out;
+}
+
+/**
+ * A saved character's pictures: a wide one (1.6:1 or wider: a sheet's shape) is its sheet, and the first other one its
+ * front, until the user says otherwise. Sizes come from the browser; a picture not measured yet counts as a photo.
+ */
+export function elementPictures(refs: { url: string; width?: number; height?: number }[]): TurnPicture[] {
+ let sheet = false;
+ let front = false;
+ return refs.map((r, i) => {
+ const wide = !!r.width && !!r.height && r.width / r.height >= 1.6;
+ if (wide && !sheet) {
+ sheet = true;
+ return { url: r.url, label: "Sheet", sheet: true };
+ }
+ if (!wide && !front) {
+ front = true;
+ return { url: r.url, label: `Photo ${i + 1}`, side: "front" as const };
+ }
+ return { url: r.url, label: `Photo ${i + 1}` };
+ });
+}
+
+/** The views and sheet a set of pictures starts with (each side's first picture; the first sheet). */
+export function startingViews(pics: TurnPicture[]): { views: Partial<Record<TurnSide, string>>; sheet?: string } {
+ const views: Partial<Record<TurnSide, string>> = {};
+ for (const p of pics) if (p.side && !views[p.side]) views[p.side] = p.url;
+ return { views, ...(pics.find((p) => p.sheet) && { sheet: pics.find((p) => p.sheet)!.url }) };
+}
+
+// ---------------------------------------------------------------------------
+// The plan
+
+export interface TurnaroundInput {
+ engine: Engine;
+ /** The pictures by side (the person's own left and right). The front is the hero: the film starts and ends on it. */
+ views?: Partial<Record<TurnSide, string>>;
+ /** A whole turnaround sheet: a reference on the cloud's References route, and where a missing front view is drawn from. */
+ sheet?: string;
+ /** The route (the engine's default when left out or not offered: ROUTES_ON, defaultRoute). */
+ route?: TurnRoute;
+ /** Draw the sides nobody has a picture of with the Angles app first (default on, except References with a sheet). */
+ fill?: boolean;
+ /** The camera route's path (TURN_PATHS; any N7-5 preset id is taken). */
+ path?: string;
+ duration?: number;
+ aspectRatio?: "9:16" | "16:9";
+ /** Words added after the orbit's own. */
+ prompt?: string;
+ /** The character's name, for the title. */
+ name?: string;
+ /** Where the takes are filed (the feature of every step); default "turnaround". */
+ feature?: string;
+ seed?: number;
+}
+
+export interface TurnaroundContext {
+ /** Whether this install offers a model (Settings → Models & licences); every model by default. */
+ has?: (id: string) => boolean;
+}
+
+export interface TurnStep {
+ key: string;
+ request: GenerationRequest;
+ /** Keys of earlier steps it waits for (one per chain slot, in order), as Cinema's steps do. */
+ after?: string[];
+}
+
+/** A frame of the film (or a reference, on References): where its picture comes from. */
+export interface TurnFrame {
+ side: TurnSide | "sheet";
+ /** Its time, 0–1 (frames and keyframes); undefined for a reference. */
+ t?: number;
+ from: "picture" | "angles" | "sheet";
+ url?: string;
+}
+
+export interface TurnaroundPlan {
+ engine: Engine;
+ route: TurnRoute;
+ /** The routes this engine offers here. */
+ routes: TurnRoute[];
+ model: ModelDef;
+ steps: TurnStep[];
+ frames: TurnFrame[];
+ /** The sides drawn first by the Angles app. */
+ fills: TurnSide[];
+ /** Whether a front view is drawn from the sheet first. */
+ frontFromSheet: boolean;
+ fill: boolean;
+ duration: number;
+ durations: number[];
+ notes: string[];
+ blocker?: string;
+ /** What it costs at list (or launch) price; 0 on the open engine. Null when a step has no known price. */
+ costUsd: number | null;
+}
+
+export const NEEDS_FRONT = "Pick the front view: the person facing the camera";
+export const NEEDS_SECOND_VIEW = "Add another side, or let Fuobe draw the missing sides";
+
+const offered = (ctx: TurnaroundContext) => (id: string) => (ctx.has ? ctx.has(id) : !!getModel(id));
+
+/**
+ * The route a turnaround takes when none is asked for. Open: Frames. Cloud (research §3.7: "default to (A); use (C) or (B)
+ * when the user has three or more views or a cast sheet"): References when there are two or more views or a sheet,
+ * else the camera path from the front alone.
+ */
+export function defaultRoute(engine: Engine, input: Pick<TurnaroundInput, "views" | "sheet">, routes: TurnRoute[] = ROUTES_ON[engine]): TurnRoute {
+ const own = TURN_SIDES.filter((s) => input.views?.[s]).length;
+ const want: TurnRoute = engine === "open" ? "frames" : own >= 2 || input.sheet ? "references" : "camera";
+ return routes.includes(want) ? want : (routes[0] ?? want);
+}
+
+/** The duration a route takes: the one asked for when offered, else the nearest it offers. */
+export function turnDuration(route: TurnRoute, asked?: number): number {
+ const { durations, duration } = TURN_ROUTES[route];
+ const want = asked ?? duration;
+ return durations.reduce((best, d) => (Math.abs(d - want) < Math.abs(best - want) ? d : best), durations[0]);
+}
+
+/** A request whose chained inputs are placeholders (to price it before they exist), as the runner fills them. */
+function placeholders(req: GenerationRequest): GenerationRequest {
+ if (!req.chain?.length) return req;
+ const inputs = { ...req.inputs };
+ const png = "/api/files/placeholder.png";
+ const placed = req.chain.filter((c) => c.slot === "images" && c.at !== undefined).sort((a, b) => a.at! - b.at!);
+ for (const c of req.chain) {
+ if (c.slot === "images" && c.at === undefined) inputs.images = [...(inputs.images ?? []), png];
+ if (c.slot === "endImage") inputs.endImage = png;
+ }
+ for (const c of placed) {
+ const list = [...(inputs.images ?? [])];
+ list.splice(Math.min(c.at!, list.length), 0, png);
+ inputs.images = list;
+ }
+ return { ...req, inputs };
+}
+
+function stepCost(req: GenerationRequest, engine: Engine): number | null {
+ const lookup = (id: string) => {
+ const m = getModel(id);
+ return m && onEngine(m, engine);
+ };
+ const p = planGeneration(placeholders(req), lookup, getPreset);
+ return estimateCost(p.model, p.params, 1, p.op);
+}
+
+type Source = { url: string } | { key: string };
+
+/**
+ * Everything a Turnaround press runs, in order, priced, without running it: a front drawn from the sheet (when no picture
+ * shows the front), the sides drawn by the Angles app, then the film on the route. The steps are Cinema-shaped (key,
+ * request, after) so Cinema's runner and src/server/turnaround.ts run them the same way.
+ */
+export function planTurnaround(input: TurnaroundInput, ctx: TurnaroundContext = {}): TurnaroundPlan {
+ const { engine } = input;
+ const has = offered(ctx);
+ const routes = ROUTES_ON[engine].filter((r) => has(TURN_ROUTES[r].modelId));
+ const route = input.route && routes.includes(input.route) ? input.route : defaultRoute(engine, input, routes);
+ const info = TURN_ROUTES[route];
+ const model = getModel(info.modelId)!;
+ const feature = input.feature ?? "turnaround";
+ const views: Partial<Record<TurnSide, string>> = {};
+ for (const s of TURN_SIDES) if (input.views?.[s]) views[s] = input.views[s];
+ const sheet = input.sheet || undefined;
+ const camera = route === "camera";
+ const frontFromSheet = !views.front && !!sheet;
+ const fill = camera ? false : (input.fill ?? !(route === "references" && sheet));
+ const fills = fill && (views.front || frontFromSheet) ? TURN_SIDES.filter((s) => s !== "front" && !views[s]) : [];
+ const duration = turnDuration(route, input.duration);
+ const aspectRatio = input.aspectRatio ?? "9:16";
+ const notes: string[] = [];
+ const steps: TurnStep[] = [];
+
+ // A front view drawn from the sheet first, when no picture shows the front alone.
+ if (frontFromSheet) {
+ const m = getModel(SHEET_FRONT_MODELS[engine])!;
+ steps.push({
+ key: "front",
+ request: {
+ feature,
+ modelId: m.id,
+ op: "edit",
+ prompt: SHEET_FRONT_PROMPT,
+ inputs: { images: [sheet!] },
+ params: { numOutputs: 1, ...(engine === "cloud" && { aspectRatio }) },
+ },
+ });
+ notes.push(`${m.name} draws a front view from the sheet first`);
+ }
+ // The missing sides, drawn from the front view by the Angles app's route.
+ const fillModel = getModel(FILL_MODELS[engine])!;
+ for (const side of fills) {
+ const horizontal = anglesHorizontal(side);
+ const request: GenerationRequest =
+ engine === "cloud"
+ ? { feature, modelId: fillModel.id, op: "edit", prompt: FILL_KEEP, params: { numOutputs: 1, extra: { horizontal_angle: horizontal, vertical_angle: 0, zoom: 5 } } }
+ : {
+ feature,
+ modelId: fillModel.id,
+ op: "edit",
+ prompt: `<sks> ${poseWords({ horizontal, vertical: 0, zoom: 5 })}. ${FILL_KEEP}`,
+ params: { numOutputs: 1 },
+ loras: [ANGLES_2511_LORA],
+ };
+ if (frontFromSheet) steps.push({ key: `fill-${side}`, request: { ...request, chain: [{ slot: "images" }] }, after: ["front"] });
+ else steps.push({ key: `fill-${side}`, request: { ...request, inputs: { images: [views.front!] } } });
+ }
+ if (fills.length) {
+ const list = fills.map((s) => SIDE_NAMES[s].toLowerCase());
+ const said = list.length > 1 ? `${list.slice(0, -1).join(", ")} and ${list.at(-1)}` : list[0];
+ notes.push(`The Angles app (${fillModel.name} with the Multiple-Angles LoRA) draws the ${said} from the front view first`);
+ }
+
+ const sourceOf = (side: TurnSide): Source | undefined =>
+ views[side] ? { url: views[side]! } : side === "front" && frontFromSheet ? { key: "front" } : fills.includes(side) ? { key: `fill-${side}` } : undefined;
+ const fromOf = (src: Source, side: TurnSide): TurnFrame["from"] => ("url" in src ? "picture" : side === "front" ? "sheet" : "angles");
+ /** The request's own pictures, and the ones steps make put in at their places (ChainSlot.at). */
+ const gather = (list: Source[]) => {
+ const images: string[] = [];
+ const chain: ChainSlot[] = [];
+ const after: string[] = [];
+ list.forEach((src, i) => {
+ if ("url" in src) images.push(src.url);
+ else {
+ chain.push({ slot: "images", at: i });
+ after.push(src.key);
+ }
+ });
+ return { images, chain, after };
+ };
+ const title = `Turnaround${input.name?.trim() ? ` · ${input.name.trim()}` : ""}`;
+ const seed = input.seed !== undefined ? { seed: input.seed } : {};
+ let frames: TurnFrame[] = [];
+ let main: TurnStep | undefined;
+ let blocker: string | undefined = views.front || frontFromSheet ? undefined : NEEDS_FRONT;
+
+ if (route === "frames" || route === "keyframes") {
+ const list = TURN_FRAMES.flatMap((f) => {
+ const src = sourceOf(f.side);
+ return src ? [{ ...f, src }] : [];
+ });
+ frames = list.map((f) => ({ side: f.side, t: f.t, from: fromOf(f.src, f.side), ...("url" in f.src && { url: f.src.url }) }));
+ const times = frameTimes(
+ list.map((f) => f.t),
+ duration,
+ );
+ const { images, chain, after } = gather(list.map((f) => f.src));
+ const params: GenParams = {
+ numOutputs: 1,
+ duration,
+ keyframeTimes: times,
+ aspectRatio,
+ resolution: info.resolution,
+ ...(route === "keyframes" && { generateAudio: false }),
+ ...seed,
+ };
+ main = {
+ key: "main",
+ request: { feature, modelId: model.id, op: "keyframes", prompt: withWords(ORBIT_PROMPT, input.prompt), title, ...(images.length && { inputs: { images } }), ...(chain.length && { chain }), params },
+ ...(after.length && { after }),
+ };
+ if (!blocker && list.filter((f) => f.side !== "front").length === 0) blocker = NEEDS_SECOND_VIEW;
+ if (!blocker && route === "frames") {
+ // Wan 2.2 14B's longest clip between two frames: a missing side doubles the gap.
+ const timing = chainTiming(onEngine(model, "open"));
+ if (chainGapProblem(times, duration, timing)) {
+ const missing = TURN_SIDES.some((s) => !sourceOf(s));
+ blocker = `${model.name} films up to ${timing.maxSeconds} s from one view to the next — make the turnaround shorter${missing ? " or let Fuobe draw the missing sides" : ""}`;
+ }
+ }
+ notes.push(
+ route === "frames"
+ ? `${model.name} films each turn from one view to the next (${list.length - 1} clips), then joins them, on your GPU`
+ : `${model.name} puts each view at its place in the turn (${list.map((f) => SIDE_NAMES[f.side].toLowerCase()).join(", ")})`,
+ );
+ } else if (route === "references") {
+ const list: { key: TurnSide | "sheet"; src: Source }[] = TURN_SIDES.flatMap((s) => {
+ const src = sourceOf(s);
+ return src ? [{ key: s, src }] : [];
+ });
+ if (sheet) list.push({ key: "sheet", src: { url: sheet } });
+ frames = list.map((f) => ({ side: f.key, from: f.key === "sheet" ? "picture" : fromOf(f.src, f.key), ...("url" in f.src && { url: f.src.url }) }));
+ const { images, chain, after } = gather(list.map((f) => f.src));
+ const max = model.options.maxImages ?? 9;
+ if (list.length > max) blocker ??= `${model.name} takes up to ${max} references`;
+ main = {
+ key: "main",
+ request: {
+ feature,
+ modelId: model.id,
+ op: "ref2v",
+ prompt: referencesPrompt(
+ list.map((f) => f.key),
+ input.prompt,
+ ),
+ title,
+ ...(images.length && { inputs: { images } }),
+ ...(chain.length && { chain }),
+ params: { numOutputs: 1, duration, resolution: info.resolution, aspectRatio, ...seed },
+ },
+ ...(after.length && { after }),
+ };
+ notes.push(`${model.name} takes ${list.length === 1 ? "the front view" : `the ${list.length} pictures`} as references and turns the camera from the words: identity holds, the path is loose`);
+ } else {
+ const path = input.path && presetKeys(input.path) ? input.path : DEFAULT_PATH;
+ const keys: CameraKey[] = presetKeys(path)!;
+ const src = sourceOf("front");
+ frames = src ? [{ side: "front", t: 0, from: fromOf(src, "front"), ...("url" in src && { url: src.url }) }] : [];
+ main = {
+ key: "main",
+ request: {
+ feature,
+ modelId: model.id,
+ op: "camera-path",
+ prompt: withWords(ORBIT_PROMPT, input.prompt),
+ title,
+ ...(src && "url" in src && { inputs: { images: [src.url] } }),
+ ...(src && "key" in src && { chain: [{ slot: "images" as const }] }),
+ params: { numOutputs: 1, duration, resolution: info.resolution, cameraPath: keys, ...seed },
+ },
+ ...(src && "key" in src && { after: [src.key] }),
+ };
+ const name = TURN_PATHS.find((p) => p.id === path)?.name ?? path;
+ notes.push(`${model.name} follows ${name} from the front view alone, with prompt expansion off: it invents the sides and back`);
+ if (TURN_SIDES.some((s) => s !== "front" && views[s]) || sheet) notes.push("Your other views aren't used on this route: References or Keyframes keep them");
+ }
+ // The pictures drawn first are numbered steps of the run, before the film (whose own clips the keyframe film numbers).
+ steps.forEach((s, i) => (s.request.step = { label: s.key === "front" ? "Front view from the sheet" : `${SIDE_NAMES[s.key.slice(5) as TurnSide]} (Angles)`, index: i, of: steps.length + 1 }));
+ steps.push(main);
+
+ // Prices at list (or launch) rates; free on the open engine.
+ let cost: number | null = 0;
+ if (!blocker) {
+ for (const s of steps) {
+ try {
+ const c = stepCost(s.request, engine);
+ cost = c === null || cost === null ? null : cost + c;
+ } catch (e) {
+ blocker ??= (e as Error).message;
+ }
+ }
+ }
+ return {
+ engine,
+ route,
+ routes,
+ model,
+ steps,
+ frames,
+ fills,
+ frontFromSheet,
+ fill,
+ duration,
+ durations: info.durations,
+ notes,
+ ...(blocker && { blocker }),
+ costUsd: cost === null ? null : Math.round(cost * 1000) / 1000,
+ };
+}
diff --git a/src/server/chains.ts b/src/server/chains.ts
index b2b429dc..0c1d91dc 100644
--- a/src/server/chains.ts
+++ b/src/server/chains.ts
@@ -299,7 +299,7 @@ export function createKeyframeFilm(original: GenerationRequest, model: ModelDef,
feature: original.feature,
batchId,
demo: original.demo,
- title: tidy(original.prompt) || "Keyframe film",
+ title: original.title?.trim() || tidy(original.prompt) || "Keyframe film",
aspectRatio: params.aspectRatio,
resolution: params.resolution,
step: { label: `Film · ${images.length} frames`, index: n, of: n + 1 },
diff --git a/tests/turnaround.test.ts b/tests/turnaround.test.ts
new file mode 100644
index 00000000..52290fee
--- /dev/null
+++ b/tests/turnaround.test.ts
@@ -0,0 +1,291 @@
+import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
+import { presetKeys } from "@/lib/camera-path";
+import { getModel } from "@/lib/catalog";
+import { buildPayload } from "@/lib/catalog/payload";
+import { ANGLES_2511_LORA } from "@/lib/catalog/open-tools";
+import {
+ NEEDS_FRONT,
+ NEEDS_SECOND_VIEW,
+ ORBIT_PROMPT,
+ TURN_FRAMES,
+ TURN_SIDES,
+ WORLDCAST,
+ anglesHorizontal,
+ elementPictures,
+ pathAzimuth,
+ planTurnaround,
+ referencesPrompt,
+ sheetPictures,
+ startingViews,
+ viewAzimuth,
+ worldcastAnchor,
+ type TurnSide,
+} from "@/lib/catalog/turnaround";
+import type { Generation, GenInput } from "@/lib/catalog/types";
+
+// Prices at list rates: after FLUX 3 Max's launch price (2026-11-07) and H3 Max camera controls' (2026-10-31).
+beforeAll(() => {
+ vi.useFakeTimers({ toFake: ["Date"] });
+ vi.setSystemTime(new Date("2026-11-15T12:00:00Z"));
+});
+afterAll(() => vi.useRealTimers());
+
+const V = { front: "/api/files/front.png", right: "/api/files/right.png", back: "/api/files/back.png", left: "/api/files/left.png" };
+const SHEET = "/api/files/sheet.png";
+const views = (...sides: TurnSide[]) => Object.fromEntries(sides.map((s) => [s, V[s]]));
+
+describe("views", () => {
+ it("puts the sides round the person, their own left and right, front → right → back → left → front", () => {
+ expect(TURN_SIDES.map(viewAzimuth)).toEqual([0, 90, 180, 270]);
+ expect(TURN_FRAMES).toEqual([
+ { side: "front", t: 0 },
+ { side: "right", t: 0.25 },
+ { side: "back", t: 0.5 },
+ { side: "left", t: 0.75 },
+ { side: "front", t: 1 },
+ ]);
+ });
+
+ it("is a clockwise orbit in the camera-path library's terms (+ = round to the viewer's right)", () => {
+ // Seeing someone's right side means walking round to your left: N7-5's orbit_360_cw passes it at a quarter of the way.
+ const keys = presetKeys("orbit_360_cw")!;
+ expect(keys.map((k) => [k.t, k.azimuth])).toEqual(TURN_FRAMES.map((f) => [f.t, f.t === 1 ? -360 : pathAzimuth(f.side)]));
+ });
+
+ it("writes WorldCast's convention down for N7-9: its side names, its demo angles, left_sign −1", () => {
+ for (const s of TURN_SIDES) {
+ const a = worldcastAnchor(s);
+ expect(a.name).toBe(WORLDCAST.anchor[s]);
+ // Each demo anchor sits within 10° of the side's angle here.
+ expect(Math.abs(WORLDCAST.demoAzimuth[a.name] - viewAzimuth(s))).toBeLessThan(10);
+ }
+ expect(worldcastAnchor("left")).toEqual({ name: "left_side", azimuth: 270, signed: -90 });
+ expect(WORLDCAST.leftSign).toBe(-1);
+ });
+
+ it("asks the Angles app for the missing sides at 90°, 180° and 270°", () => {
+ expect((["right", "back", "left"] as const).map(anglesHorizontal)).toEqual([90, 180, 270]);
+ });
+});
+
+describe("the pictures a sheet or a character offers", () => {
+ const gen = (outputs: Generation["outputs"], images?: string[]) => ({ outputs, request: { feature: "character-sheet", modelId: "m", ...(images && { inputs: { images } }) } });
+
+ it("takes the Soul Cast sheet graph's front and back, and leaves the three-quarter and profile for the user to place", () => {
+ const pics = sheetPictures(
+ gen([
+ { url: "/s.png", kind: "image", meta: { role: "sheet" } },
+ ...["/f.png", "/q.png", "/p.png", "/b.png"].map((url) => ({ url, kind: "image" as const, meta: { role: "tiles" } })),
+ ]),
+ );
+ expect(pics).toEqual([
+ { url: "/s.png", label: "Sheet", sheet: true },
+ { url: "/f.png", label: "Front", side: "front" },
+ { url: "/q.png", label: "Three-quarter" },
+ { url: "/p.png", label: "Profile" },
+ { url: "/b.png", label: "Back", side: "back" },
+ ]);
+ expect(startingViews(pics)).toEqual({ views: { front: "/f.png", back: "/b.png" }, sheet: "/s.png" });
+ });
+
+ it("reads a one-picture sheet as the sheet, and its first source photo as the front", () => {
+ expect(startingViews(sheetPictures(gen([{ url: "/s.png", kind: "image" }])))).toEqual({ views: {}, sheet: "/s.png" });
+ const pics = sheetPictures(gen([{ url: "/s.png", kind: "image" }], ["/api/files/me.jpg", "/api/files/me2.jpg"]));
+ expect(pics.slice(1)).toEqual([
+ { url: "/api/files/me.jpg", label: "Photo 1", side: "front" },
+ { url: "/api/files/me2.jpg", label: "Photo 2" },
+ ]);
+ });
+
+ it("takes a character's wide picture as its sheet and the first other one as its front", () => {
+ const pics = elementPictures([
+ { url: "/a.png", width: 2048, height: 1152 },
+ { url: "/b.png", width: 768, height: 1024 },
+ { url: "/c.png", width: 1024, height: 1024 },
+ ]);
+ expect(pics.map((p) => [p.url, p.side, p.sheet])).toEqual([
+ ["/a.png", undefined, true],
+ ["/b.png", "front", undefined],
+ ["/c.png", undefined, undefined],
+ ]);
+ });
+});
+
+describe("the open engine: Frames mode's chain", () => {
+ it("films all four sides as keyframes at 0, ¼, ½, ¾ and the end, with the orbit words, free", () => {
+ const plan = planTurnaround({ engine: "open", views: views("front", "right", "back", "left"), name: "Maya" });
+ expect(plan).toMatchObject({ route: "frames", routes: ["frames"], fills: [], duration: 8, costUsd: 0 });
+ expect(plan.blocker).toBeUndefined();
+ expect(plan.steps).toHaveLength(1);
+ const { request } = plan.steps[0];
+ expect(request).toMatchObject({
+ feature: "turnaround",
+ modelId: "oss-wan22-14b",
+ op: "keyframes",
+ prompt: ORBIT_PROMPT,
+ title: "Turnaround · Maya",
+ inputs: { images: [V.front, V.right, V.back, V.left, V.front] },
+ params: { duration: 8, keyframeTimes: [0, 2, 4, 6, 8], aspectRatio: "9:16", resolution: "480p" },
+ });
+ expect(request.chain).toBeUndefined();
+ });
+
+ it("draws the missing sides from the front with the Angles app's open route, and places them in the film", () => {
+ const plan = planTurnaround({ engine: "open", views: views("front", "back") });
+ expect(plan.fills).toEqual(["right", "left"]);
+ expect(plan.steps.map((s) => s.key)).toEqual(["fill-right", "fill-left", "main"]);
+ const right = plan.steps[0].request;
+ expect(right).toMatchObject({ modelId: "oss-qwen-edit", op: "edit", inputs: { images: [V.front] }, loras: [ANGLES_2511_LORA] });
+ expect(right.prompt).toMatch(/^<sks> right side view eye-level shot medium shot\. Keep the same person/);
+ expect(plan.steps[1].request.prompt).toMatch(/^<sks> left side view /);
+ expect(right.step).toEqual({ label: "Right side (Angles)", index: 0, of: 3 });
+ const main = plan.steps[2];
+ expect(main.request.inputs?.images).toEqual([V.front, V.back, V.front]);
+ expect(main.request.chain).toEqual([
+ { slot: "images", at: 1 },
+ { slot: "images", at: 3 },
+ ]);
+ expect(main.after).toEqual(["fill-right", "fill-left"]);
+ expect(plan.frames.map((f) => [f.side, f.from])).toEqual([
+ ["front", "picture"],
+ ["right", "angles"],
+ ["back", "picture"],
+ ["left", "angles"],
+ ["front", "picture"],
+ ]);
+ expect(plan.costUsd).toBe(0);
+ });
+
+ it("without fills, films the sides it has, and says when a gap is too long for Wan 2.2's clips", () => {
+ const two = planTurnaround({ engine: "open", views: views("front", "back"), fill: false });
+ expect(two.steps).toHaveLength(1);
+ expect(two.steps[0].request.inputs?.images).toEqual([V.front, V.back, V.front]);
+ expect(two.steps[0].request.params?.keyframeTimes).toEqual([0, 4, 8]);
+ expect(planTurnaround({ engine: "open", views: views("front", "back"), fill: false, duration: 20 }).blocker).toMatch(/up to 7 s from one view to the next — make the turnaround shorter or let Fuobe draw the missing sides/);
+ expect(planTurnaround({ engine: "open", views: views("front"), fill: false }).blocker).toBe(NEEDS_SECOND_VIEW);
+ expect(planTurnaround({ engine: "open", views: views("back") }).blocker).toBe(NEEDS_FRONT);
+ });
+
+ it("draws a front view from a sheet first, then the sides from it, then films them all", () => {
+ const plan = planTurnaround({ engine: "open", sheet: SHEET });
+ expect(plan.frontFromSheet).toBe(true);
+ expect(plan.steps.map((s) => [s.key, s.after])).toEqual([
+ ["front", undefined],
+ ["fill-right", ["front"]],
+ ["fill-back", ["front"]],
+ ["fill-left", ["front"]],
+ ["main", ["front", "fill-right", "fill-back", "fill-left", "front"]],
+ ]);
+ expect(plan.steps[0].request).toMatchObject({ modelId: "oss-qwen-edit", op: "edit", inputs: { images: [SHEET] } });
+ expect(plan.steps[1].request.chain).toEqual([{ slot: "images" }]);
+ const main = plan.steps[4].request;
+ expect(main.inputs).toBeUndefined();
+ expect(main.chain?.map((c) => c.at)).toEqual([0, 1, 2, 3, 4]);
+ });
+});
+
+describe("the cloud", () => {
+ it("takes the camera path from a single front view, an exact clockwise orbit by default: $0.40 for 5 s at 768P", () => {
+ const plan = planTurnaround({ engine: "cloud", views: views("front") });
+ expect(plan).toMatchObject({ route: "camera", routes: ["references", "keyframes", "camera"], fills: [], costUsd: 0.4 });
+ expect(plan.steps[0].request).toMatchObject({
+ modelId: "minimax-h3-max-camera",
+ op: "camera-path",
+ inputs: { images: [V.front] },
+ params: { duration: 5, resolution: "768P", cameraPath: presetKeys("orbit_360_cw") },
+ });
+ expect(planTurnaround({ engine: "cloud", views: views("front"), path: "orbit_180_push" }).steps[0].request.params?.cameraPath).toEqual(presetKeys("orbit_180_push"));
+ });
+
+ it("takes two or more views or a sheet as references on H3 Max: Image N named by side, $0.40 for 5 s at 768P", () => {
+ const plan = planTurnaround({ engine: "cloud", views: views("front", "right", "back", "left") });
+ expect(plan).toMatchObject({ route: "references", fills: [], costUsd: 0.4 });
+ const r = plan.steps[0].request;
+ expect(r).toMatchObject({ modelId: "minimax-h3-max", op: "ref2v", inputs: { images: [V.front, V.right, V.back, V.left] }, params: { duration: 5, resolution: "768P", aspectRatio: "9:16" } });
+ expect(r.prompt).toMatch(/^Image 1 is the person's front view, Image 2 is their right side, Image 3 is their back, Image 4 is their left side\. The camera orbits 360 degrees/);
+ // With a sheet: no sides drawn (the sheet shows them), and it is the last reference.
+ const sheet = planTurnaround({ engine: "cloud", views: views("front", "back"), sheet: SHEET });
+ expect(sheet.fills).toEqual([]);
+ expect(sheet.steps[0].request.inputs?.images).toEqual([V.front, V.back, SHEET]);
+ expect(sheet.steps[0].request.prompt).toMatch(/Image 3 is a turnaround sheet of the same person/);
+ });
+
+ it("draws missing sides with Qwen Multiple Angles ($0.035 each) and places them among the references", () => {
+ const plan = planTurnaround({ engine: "cloud", views: views("front", "back"), fill: true });
+ expect(plan.steps.map((s) => s.key)).toEqual(["fill-right", "fill-left", "main"]);
+ expect(plan.steps[0].request).toMatchObject({ modelId: "qwen-multiple-angles", op: "edit", inputs: { images: [V.front] }, params: { extra: { horizontal_angle: 90, vertical_angle: 0, zoom: 5 } } });
+ expect(plan.steps[1].request.params?.extra).toMatchObject({ horizontal_angle: 270 });
+ expect(plan.steps[2].request.chain).toEqual([
+ { slot: "images", at: 1 },
+ { slot: "images", at: 3 },
+ ]);
+ expect(plan.costUsd).toBe(0.47);
+ });
+
+ it("films the views as FLUX 3 Max keyframes at their quarters, silent: $0.17/s at 720p", () => {
+ const plan = planTurnaround({ engine: "cloud", views: views("front", "right", "back", "left"), route: "keyframes" });
+ expect(plan.steps[0].request).toMatchObject({
+ modelId: "flux-3-max",
+ op: "keyframes",
+ inputs: { images: [V.front, V.right, V.back, V.left, V.front] },
+ params: { duration: 8, keyframeTimes: [0, 2, 4, 6, 8], resolution: "720p", generateAudio: false },
+ });
+ expect(plan.costUsd).toBe(1.36);
+ // With a front alone and the sides drawn: 3 drawn pictures, then the film.
+ expect(planTurnaround({ engine: "cloud", views: views("front"), route: "keyframes" }).costUsd).toBe(1.465);
+ });
+
+ it("prices 1 to 5 pictures, with and without the sides drawn", () => {
+ const cases: [TurnSide[], boolean, boolean, string, number][] = [
+ [["front"], false, true, "camera", 0.4],
+ [["front", "back"], false, true, "references", 0.47],
+ [["front", "back"], false, false, "references", 0.4],
+ [["front", "right", "back"], false, true, "references", 0.435],
+ [["front", "right", "back", "left"], false, true, "references", 0.4],
+ [["front", "right", "back", "left"], true, true, "references", 0.4],
+ ];
+ for (const [sides, withSheet, fill, route, cost] of cases) {
+ const plan = planTurnaround({ engine: "cloud", views: views(...sides), ...(withSheet && { sheet: SHEET }), fill });
+ expect([plan.route, plan.costUsd], `${sides.join("+")}${withSheet ? "+sheet" : ""} fill ${fill}`).toEqual([route, cost]);
+ expect(plan.steps.at(-1)!.request.inputs?.images?.length ?? 0).toBeLessThanOrEqual(9);
+ }
+ });
+
+ it("picks another route when a model is switched off in Settings → Models & licences", () => {
+ const plan = planTurnaround({ engine: "cloud", views: views("front", "right", "back", "left") }, { has: (id) => id !== "minimax-h3-max" });
+ expect(plan.routes).toEqual(["keyframes", "camera"]);
+ expect(plan.route).toBe("keyframes");
+ });
+});
+
+describe("the reference-to-video payload", () => {
+ it("sends the views as reference_image_urls (H3 Max takes up to 9, 12 files in all), the front as the first frame, and names each Image N", () => {
+ const plan = planTurnaround({ engine: "cloud", views: views("front", "right", "back", "left"), sheet: SHEET });
+ const r = plan.steps[0].request;
+ const route = getModel("minimax-h3-max")!.routes.find((x) => x.op === "ref2v")!;
+ const body = buildPayload(route.map!, { prompt: r.prompt, images: r.inputs?.images, ...(r.params as GenInput) });
+ expect(body).toMatchObject({
+ reference_image_urls: [V.front, V.right, V.back, V.left, SHEET],
+ image_url: V.front,
+ duration: 5,
+ resolution: "768P",
+ aspect_ratio: "9:16",
+ });
+ expect((body.reference_image_urls as string[]).length).toBeLessThanOrEqual(9);
+ for (const [n, words] of [
+ [1, "the person's front view"],
+ [2, "their right side"],
+ [3, "their back"],
+ [4, "their left side"],
+ [5, "a turnaround sheet"],
+ ] as const)
+ expect(body.prompt).toContain(`Image ${n} is ${words}`);
+ });
+
+ it("words a single picture as a turn all the way round", () => {
+ expect(referencesPrompt(["front"])).toBe(
+ "Image 1 is the person's front view. The camera orbits 360 degrees around the person at a constant height, all the way round them; the person stands naturally and looks the same from every side as in the images",
+ );
+ expect(referencesPrompt(["front"], "golden hour")).toMatch(/as in the images\. golden hour$/);
+ });
+});