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.

Image to 3D: an Idol 3D run can return the object's four sides, named front, left, back and right

Claudeea6b361bceb7
diff --git a/src/lib/av/idol-views.ts b/src/lib/av/idol-views.ts
new file mode 100644
index 00000000..eccb1420
--- /dev/null
+++ b/src/lib/av/idol-views.ts
@@ -0,0 +1,105 @@
+import type { GenerationRequest, OutputFile } from "@/lib/catalog/types";
+import { IDOL_MODELS, IDOL_WORKFLOWS, VIEW_SIDES, idolExtra, type ViewSide } from "@/lib/av/model3d";
+
+/**
+ * "Make the other sides from the front" (idol-8, docs/research/idol-9.md §8): Idol 3D builds a splat of the object in one
+ * picture on your GPU, and the image-to-views-idol graph renders it from the camera Idol predicted for that picture, then
+ * three more times a quarter turn apart. The four pictures fill From several images' sides (TRELLIS.2 multi-view) and an
+ * element's references. They are renders of a 3D guess, so they can be soft; faces and people are the risky case (eval first).
+ * Open engine only: Idol's fal endpoint returns a splat, not views, and nothing else stands in for it.
+ */
+export const IDOL_VIEWS_WORKFLOW = "image-to-views-idol";
+/** params.extra key that asks Idol 3D's open route for the four views (src/lib/comfy-variants.ts swaps the graph). */
+export const IDOL_VIEWS_PARAM = "idolViews";
+/** A helper job ("-step"): the views land in the slots or the element, not in the Library on their own. */
+export const IDOL_VIEWS_FEATURE = "image-to-3d-views-step";
+/** The graph's RenderSplat frames: four views, 90° apart. */
+export const IDOL_VIEWS_FRAMES = 4;
+
+/**
+ * Which side each rendered view is (meta.index → side). RenderSplat with frames +4 turns the camera about world +Y
+ * (three.js, Y up) toward the viewer's right, which is the object's own left (SIDES_HINT: "facing its front, walk round to
+ * your right for its left side"); checked with an asymmetric splat through ComfyUI 0.41.0's RenderSplat. A negative frames
+ * value would give the right side first.
+ */
+export const IDOL_VIEW_ORDER: readonly ViewSide[] = VIEW_SIDES;
+
+/** The side a view at this index shows (undefined past the fourth). */
+export function sideOfIndex(index: number): ViewSide | undefined {
+ return Number.isInteger(index) && index >= 0 ? IDOL_VIEW_ORDER[index] : undefined;
+}
+
+/** The plain line beside every place that offers the views. */
+export const IDOL_VIEWS_NOTE = "Rendered from a 3D guess of your photo, so they can look soft. Check each side before you use it.";
+
+/** What the owner reads when their ComfyUI can't make the views (the run fails with it). */
+export const IDOL_VIEWS_NEEDS_PACK = "Making the other sides needs the ComfyUI-Idol nodes on your ComfyUI";
+
+/**
+ * The run that makes the views: Idol 3D on the open engine with its Best settings, the picture's crop ("It's a photo": an
+ * upload gets Idol's looser crop, a picture made here the tighter one) and the views asked for.
+ */
+export function idolViewsRequest(photo: string, o: { asPhoto?: boolean } = {}): GenerationRequest {
+ return {
+ feature: IDOL_VIEWS_FEATURE,
+ modelId: IDOL_MODELS.open,
+ op: "splat",
+ inputs: { images: [photo] },
+ params: { extra: { ...idolExtra("open", "best", o.asPhoto ?? true), [IDOL_VIEWS_PARAM]: true } },
+ };
+}
+
+/** Whether a request asks for Idol's views (the graph swap, the demo's four pictures). */
+export function wantsIdolViews(extra: Record<string, unknown> | undefined): boolean {
+ return extra?.[IDOL_VIEWS_PARAM] === true;
+}
+
+/** The view graph a route's Idol endpoint runs as, when the request asks for views and the library has it. */
+export function idolViewsGraph(endpoint: string, extra: Record<string, unknown>, has: (id: string) => boolean): string {
+ return (endpoint === IDOL_WORKFLOWS.core || endpoint === IDOL_WORKFLOWS.clean) && wantsIdolViews(extra) && has(IDOL_VIEWS_WORKFLOW) ? IDOL_VIEWS_WORKFLOW : endpoint;
+}
+
+/** A view's own meta: its index in the batch and the side it shows. */
+export function idolViewMeta(index: number): { index: number; side?: ViewSide } {
+ const side = sideOfIndex(index);
+ return { index, ...(side && { side }) };
+}
+
+/**
+ * The finished views by side. An output's meta.side wins, else its meta.index, else its place among the images (the batch
+ * keeps its order).
+ */
+export function idolViewsOf(outputs: Pick<OutputFile, "url" | "kind" | "meta">[]): Partial<Record<ViewSide, string>> {
+ const out: Partial<Record<ViewSide, string>> = {};
+ outputs
+ .filter((o) => o.kind === "image")
+ .forEach((o, i) => {
+ const named = typeof o.meta?.side === "string" && (VIEW_SIDES as readonly string[]).includes(o.meta.side) ? (o.meta.side as ViewSide) : undefined;
+ const side = named ?? sideOfIndex(typeof o.meta?.index === "number" ? o.meta.index : i);
+ if (side && !out[side]) out[side] = o.url;
+ });
+ return out;
+}
+
+/** The sides the button fills: every one but the front. */
+export const OTHER_SIDES = IDOL_VIEW_ORDER.filter((s) => s !== "front");
+
+/** From several images offers the button with only the front filled (the person's own photos of other sides win). */
+export function canMakeOtherSides(views: Partial<Record<ViewSide, unknown>>): boolean {
+ return !!views.front && OTHER_SIDES.every((s) => !views[s]);
+}
+
+/**
+ * The slots after a run: each side still empty gets its view; the front, and any side the person filled meanwhile, stay
+ * as they are.
+ */
+export function fillOtherSides<T>(current: Partial<Record<ViewSide, T | null>>, made: Partial<Record<ViewSide, string>>, slot: (url: string, side: ViewSide) => T): Partial<Record<ViewSide, T | null>> {
+ const next = { ...current };
+ for (const s of OTHER_SIDES) if (!next[s] && made[s]) next[s] = slot(made[s]!, s);
+ return next;
+}
+
+/** An element's new references: the left, back and right views (the front is the photo it came from), not already there. */
+export function elementViews(made: Partial<Record<ViewSide, string>>, have: string[] = []): string[] {
+ return OTHER_SIDES.flatMap((s) => (made[s] && !have.includes(made[s]!) ? [made[s]!] : []));
+}
diff --git a/src/lib/comfy-variants.ts b/src/lib/comfy-variants.ts
index fb66da71..705e0ce6 100644
--- a/src/lib/comfy-variants.ts
+++ b/src/lib/comfy-variants.ts
@@ -1,4 +1,5 @@
import { exrWorkflow } from "@/lib/av/video-finish";
+import { idolViewsGraph } from "@/lib/av/idol-views";
import { qwen21Graph } from "@/lib/qwen21-speed";
import { H3_TIER_PARAM, tierGraphFor } from "@/lib/gpu/h3-tier";
@@ -115,5 +116,6 @@ export function resolveWorkflowId(endpointTemplate: string, r: VariantRequest):
if (cover && r.audio && r.has(cover)) endpoint = cover;
const bed = REUSE_BED_GRAPH[endpoint];
if (bed && r.extra.background === "keep" && r.has(bed)) endpoint = bed;
- return endpoint;
+ // Idol 3D's four views ("Make the other sides from the front"): the view graph, which needs the ComfyUI-Idol pack.
+ return idolViewsGraph(endpoint, r.extra, r.has);
}
diff --git a/src/server/gpu/tools.ts b/src/server/gpu/tools.ts
index 8d81100b..fa208476 100644
--- a/src/server/gpu/tools.ts
+++ b/src/server/gpu/tools.ts
@@ -2,6 +2,7 @@ import "server-only";
import { FLY_MODELS } from "@/lib/catalog/fly-around";
import { DUB_STEP_MODELS } from "@/lib/av/dub";
import { HI3D_MODEL } from "@/lib/av/hi3d";
+import { IDOL_VIEWS_WORKFLOW } from "@/lib/av/idol-views";
import { SPLIT_MODEL } from "@/lib/av/split";
import { BED_MUX_MODEL, VOICE_FIRST_MODELS } from "@/lib/av/voice-first";
import { BURN_MODELS } from "@/lib/av/captions";
@@ -164,6 +165,8 @@ export interface StudioRowDef {
config?: StudioConfig;
/** A studio with graphs of its own (Character swap). */
workflows?: string[];
+ /** What such a studio makes (video unless said). */
+ kind?: string;
/**
* A tool that runs open models' operations in steps (Split soundtrack, Cinema's fly path, the turnaround): their graphs
* and LoRAs together, with the LoRAs a step adds itself (the turnaround's Angles LoRA). The first names the tool.
@@ -201,6 +204,8 @@ export const STUDIO_ROWS: StudioRowDef[] = [
{ modelId: HI3D_MODEL, op: "refine-3d" },
],
},
+ // idol-8: From several images' "Make the other sides from the front": Idol 3D's four views, which need the ComfyUI-Idol pack.
+ { href: "/image-to-3d?mode=multi", label: "Other sides from one picture", group: "Images", kind: "image", workflows: [IDOL_VIEWS_WORKFLOW] },
// MiniMax H3's references (Pika H3 Flex Ref2VA) need the Ref2VA partition and Pika's adapter: a row of their own, so the
// Video row stays what text, image and frame clips need.
{ href: "/video", label: "Video", group: "Video", config: S.VIDEO_STUDIO, skipOps: ["ref2v"] },
@@ -442,7 +447,7 @@ export function studioTool(row: StudioRowDef): Tool | null {
if (row.workflows) {
const segment = row.workflows[row.workflows.length - 1];
const loras = [...graphLoras(segment, {}), ...row.workflows.flatMap((w) => regenerateGraphLoras(w))];
- return { ref: `studio:${row.href}`, name: row.label, kind: "video", workflows: row.workflows.filter((w) => !!loadIndex().workflows[w]), loras: loras.map(loraNeed) };
+ return { ref: `studio:${row.href}`, name: row.label, kind: row.kind ?? "video", workflows: row.workflows.filter((w) => !!loadIndex().workflows[w]), loras: loras.map(loraNeed) };
}
const c = row.config;
const id = c?.defaultModels.open;
diff --git a/src/server/providers/comfyui.ts b/src/server/providers/comfyui.ts
index 85b60220..2ab1ead9 100644
--- a/src/server/providers/comfyui.ts
+++ b/src/server/providers/comfyui.ts
@@ -45,6 +45,7 @@ import { HI3D_PARAM, strictHi3dResolution } from "@/lib/av/hi3d";
import { fpsPlan } from "@/lib/av/fps";
import { resolveWorkflowId } from "@/lib/comfy-variants";
import { IDOL_PACK, IDOL_PACK_CLASS, IDOL_WORKFLOWS, idolGraphValues, idolKept } from "@/lib/av/model3d";
+import { IDOL_VIEWS_NEEDS_PACK, IDOL_VIEWS_PARAM, IDOL_VIEWS_WORKFLOW, idolViewMeta } from "@/lib/av/idol-views";
import { DECODER_PARAM, editCanvas, GPU_PARAM, LIGHTNING_GRAPHS, lightningSigmas, SPEED_PARAM, ZEN_ADAPTER, ZEN_ENCODER } from "@/lib/qwen21-speed";
import { h3Canvas, h3Frames, isH3Graph } from "@/lib/h3-prompt";
import { expandH3References, h3ReferenceProblem } from "@/lib/h3-references";
@@ -590,6 +591,8 @@ export function collectOutputs(entry: HistoryEntry, manifest: ManifestWorkflow |
if (spec?.role === "splat" && idolSplat) Object.assign(meta, idolSplat);
// Qwen-Image-Layered saves its layers back to front.
if (spec?.role === "layers") Object.assign(meta, { z: i, name: i === 0 ? "Background" : `Layer ${i}` });
+ // Idol 3D's four views: one batch, front first, then the object's left, back and right (src/lib/av/idol-views.ts).
+ if (spec?.role === "tiles" && manifest?.id === IDOL_VIEWS_WORKFLOW) Object.assign(meta, idolViewMeta(i));
if (Object.keys(meta).length) o.meta = meta;
files.push(o);
});
@@ -1298,6 +1301,10 @@ export async function prepareWorkflow(endpointTemplate: string, input: GenInput,
if (endpoint === IDOL_WORKFLOWS.core && loadManifest().workflows.some((w) => w.id === IDOL_WORKFLOWS.clean) && (await ctx.idolPack?.().catch(() => undefined)) === true) {
endpoint = IDOL_WORKFLOWS.clean;
}
+ // Idol 3D's four views need the pack's camera (IdolCamera): with no pack (or the pack switched off in Settings), say so
+ // instead of a missing-node error. Unknown (someone's computer, a server that didn't answer): their ComfyUI has the last word.
+ if (endpoint === IDOL_VIEWS_WORKFLOW && (await ctx.idolPack?.().catch(() => undefined)) === false) throw new ProviderError(IDOL_VIEWS_NEEDS_PACK, 400);
+ delete extra[IDOL_VIEWS_PARAM];
delete extra.productShot;
delete extra[SPEED_PARAM];
delete extra[GPU_PARAM];
@@ -1870,7 +1877,7 @@ export async function prepareWorkflow(endpointTemplate: string, input: GenInput,
}
}
// Idol 3D: "It's a photo" is the clean graph's "real" crop (the core graph's photo switch), then the pack's pruning.
- if (manifest.id === IDOL_WORKFLOWS.core || manifest.id === IDOL_WORKFLOWS.clean) {
+ if (manifest.id === IDOL_WORKFLOWS.core || manifest.id === IDOL_WORKFLOWS.clean || manifest.id === IDOL_VIEWS_WORKFLOW) {
Object.assign(values, idolGraphValues(extra, (k) => !!b[k as BindingKey]));
for (const k of ["cropMode", "photoCrop", "minOpacity", "maxScale"]) delete extra[k];
}
@@ -2582,7 +2589,7 @@ export const comfyProvider: ProviderAdapter = {
}
if (!res.ok || !body.prompt_id) {
// The pack may have gone since the server said it had it: the next run asks again (and runs the core graph without it).
- if (manifest.id === IDOL_WORKFLOWS.clean) forgetComfyClass(IDOL_PACK_CLASS, worker);
+ if (manifest.id === IDOL_WORKFLOWS.clean || manifest.id === IDOL_VIEWS_WORKFLOW) forgetComfyClass(IDOL_PACK_CLASS, worker);
const refusal = promptRefusal(body, res.status, manifest, input.loras ?? [], worker);
if (!refusal.message && !res.ok && worker === "isolated") throw isolatedAnswer("the prompt", res.status);
throw Object.assign(new ProviderError(refusal.message ?? `ComfyUI /prompt failed (${res.status})`, res.status), refusal.fix ? { fix: refusal.fix } : {});
diff --git a/src/server/providers/mock.ts b/src/server/providers/mock.ts
index 6ac145ad..f1627bc1 100644
--- a/src/server/providers/mock.ts
+++ b/src/server/providers/mock.ts
@@ -2,6 +2,7 @@ import "server-only";
import fs from "node:fs";
import path from "node:path";
import { nanoid } from "nanoid";
+import { IDOL_VIEW_ORDER, idolViewMeta, wantsIdolViews } from "@/lib/av/idol-views";
import { cueText, parseCues, type Cue } from "@/lib/cues";
import { H3_REMOVAL_WORKFLOW } from "@/lib/catalog/character-swap";
import { HAND_OFF, windowArtifact } from "@/lib/catalog/remove-object";
@@ -322,6 +323,8 @@ function demoOutputs(op: Operation | undefined, kind: MediaKind, prompt: string,
return [{ url: "sample:demo-model.glb", kind: "model3d", contentType: "model/gltf-binary", meta: { demo: true, format: "glb", scene: true, role: "scene" } }, depth];
}
case "splat":
+ // Idol 3D's four views of the object (front, left, back, right), as image-to-views-idol returns them.
+ if (meta.idolViews) return IDOL_VIEW_ORDER.map((side, index) => ({ url: svgUri(demoSvg(`${side} view`, "1:1", index)), kind: "image" as const, contentType: "image/svg+xml", meta: { ...idolViewMeta(index), role: "tiles", demo: true } }));
return [{ url: "sample:demo-model.glb", kind: "model3d", contentType: "model/gltf-binary", meta: { demo: true, format: "glb", splat: true } }];
case "rig-3d":
return [{ url: "sample:demo-model.glb", kind: "model3d", contentType: "model/gltf-binary", meta: { demo: true, format: "glb", rigged: true } }];
@@ -440,6 +443,8 @@ export const mockProvider: ProviderAdapter = {
format: input.format,
clips: input.audios?.length,
frames: route.op === "extract-frames" ? input.extra?.max_frames : undefined,
+ // Idol 3D asked for its four views of the object (src/lib/av/idol-views.ts).
+ idolViews: route.op === "splat" && wantsIdolViews(input.extra),
// Remove background: which file the demo stands for (the cut-out or its alpha mask).
matteOutput: route.op === "bg-remove-video" ? (input.matteOutput ?? model.options.matteOutputs?.[0] ?? "cutout") : undefined,
// The painted eraser's second output: the window's last tracked mask (video-inpaint-wan-vace-painted), saved
diff --git a/tests/idol-views.test.ts b/tests/idol-views.test.ts
new file mode 100644
index 00000000..51a82bdd
--- /dev/null
+++ b/tests/idol-views.test.ts
@@ -0,0 +1,298 @@
+import fs from "node:fs";
+import http from "node:http";
+import type { AddressInfo } from "node:net";
+import os from "node:os";
+import path from "node:path";
+import { afterAll, beforeAll, describe, expect, it } from "vitest";
+import type { Manifest } from "@/lib/comfy";
+
+/**
+ * Fill the other sides from one picture (idol-8, docs/research/idol-9.md §8, §9 idol-8): the image-to-views-idol graph
+ * (the clean Idol graph up to the pruned splat, then IdolCamera → RenderSplat with frames +4 → one batch of four), the
+ * spec entry with its pack, the provider swapping to it when a request asks for views (and saying plainly when the
+ * ComfyUI has no ComfyUI-Idol), the index → side mapping, the demo's four pictures, the slots of From several images and
+ * the chain into TRELLIS.2 multi-view, and an element's new references.
+ */
+
+const dir = fs.mkdtempSync(path.join(os.tmpdir(), "fuobe-idol-views-"));
+process.env.FUOBE_DATA_DIR = dir;
+process.env.COMFYUI_URL = "http://127.0.0.1:9";
+
+const root = process.cwd();
+const { setSetting } = await import("@/server/settings");
+const { collectOutputs, comfyProvider, getWorkflow, prepareWorkflow } = await import("@/server/providers/comfyui");
+const { changeAccess } = await import("@/server/model-access");
+const views = await import("@/lib/av/idol-views");
+const m3d = await import("@/lib/av/model3d");
+const { resolveWorkflowId } = await import("@/lib/comfy-variants");
+const { getModel } = await import("@/lib/catalog");
+const { isHelperFeature } = await import("@/lib/library");
+
+const manifest = JSON.parse(fs.readFileSync(path.join(root, "workflows", "comfyui", "manifest.json"), "utf8")) as Manifest;
+const byId = new Map(manifest.workflows.map((w) => [w.id, w]));
+const entry = byId.get("image-to-views-idol")!;
+type Node = { class_type: string; inputs: Record<string, unknown> };
+const read = (id: string) => JSON.parse(fs.readFileSync(path.join(root, "workflows", "comfyui", `${id}.json`), "utf8")) as Record<string, Node>;
+const graph = read("image-to-views-idol");
+const clean = read("image-to-splat-idol-clean");
+
+// A stand-in ComfyUI: GET /object_info/<class> (the pack's classes when `pack` is on) and POST /prompt, keeping the graphs.
+let pack = true;
+const prompts: Record<string, Node>[] = [];
+const server = http.createServer((req, res) => {
+ if (req.method === "POST" && req.url === "/prompt") {
+ let body = "";
+ req.on("data", (c) => (body += c));
+ req.on("end", () => {
+ prompts.push((JSON.parse(body) as { prompt: Record<string, Node> }).prompt);
+ res.writeHead(200, { "Content-Type": "application/json" }).end(JSON.stringify({ prompt_id: `p-${prompts.length}` }));
+ });
+ return;
+ }
+ const m = /^\/object_info\/(\w+)$/.exec(req.url ?? "");
+ if (!m) return void res.writeHead(404).end();
+ const has = pack && /^Idol(PreprocessImage|Camera|PruneSplat)$/.test(m[1]);
+ res.writeHead(200, { "Content-Type": "application/json" }).end(JSON.stringify(has ? { [m[1]]: { input: {}, output: [] } } : {}));
+});
+
+beforeAll(async () => {
+ setSetting("demoMode", "auto");
+ await new Promise<void>((r) => server.listen(0, "127.0.0.1", r));
+ setSetting("comfyUrl", `http://127.0.0.1:${(server.address() as AddressInfo).port}`);
+});
+afterAll(() => {
+ server.close();
+ fs.rmSync(dir, { recursive: true, force: true });
+});
+
+const PHOTO = "/api/files/front.png";
+const viewsExtra = () => views.idolViewsRequest(PHOTO).params!.extra!;
+const prepare = (extra: Record<string, unknown>, idolPack?: () => Promise<boolean | undefined>) =>
+ prepareWorkflow("image-to-splat-idol", { prompt: "", images: ["p.png"], seed: 7, extra: { ...extra } }, { generationId: "gen-views", op: "splat", upload: async () => "x", idolPack });
+
+describe("image-to-views-idol: the spec, the manifest and the GPU check", () => {
+ it("is a hand-built splat entry with the ComfyUI-Idol pack, Idol's bindings and one batch of four images", async () => {
+ const spec = await import("../scripts/comfy/library.spec.mjs");
+ const e = spec.SPEC.find((s: { id: string }) => s.id === "image-to-views-idol");
+ expect(e).toMatchObject({ packs: ["ComfyUI-Idol"], capability: "splat", handBuilt: "hand-built/image-to-views-idol.json", vramGb: 8 });
+ expect(Object.keys(e.bindings).sort()).toEqual(["cfg", "cropMode", "cutout", "image", "maxScale", "minOpacity", "numGaussians", "sampler", "seed", "steps"]);
+ expect(entry.customNodes).toEqual([{ name: "ComfyUI-Idol", repo: "https://github.com/Nynxz/ComfyUI-Idol/tree/4d3a4f671028f0e062d9f004cda1a2dd73360d35" }]);
+ expect(entry.outputs).toEqual([{ node: "96", kind: "image", role: "tiles" }]);
+ expect(entry.defaults).toMatchObject({ steps: 50, cfg: 4, numGaussians: 262144, cutout: true, cropMode: "synthetic", minOpacity: 0.05, maxScale: 0 });
+ // Same weights (and sizes) as Idol 3D's other graphs; the licence is the clean graph's.
+ expect(entry.models).toEqual(byId.get("image-to-splat-idol-clean")!.models);
+ expect(entry.license).toBe(byId.get("image-to-splat-idol-clean")!.license);
+ expect(entry.bindings.image).toEqual([{ node: "99", input: "image" }]);
+ expect(entry.bindings.cropMode).toEqual([{ node: "88:110", input: "mode" }]);
+ });
+
+ it("is in the GPU pre-flight's index with the pack's three classes", () => {
+ const req = JSON.parse(fs.readFileSync(path.join(root, "workflows", "comfyui", "requirements.json"), "utf8"));
+ const w = req.workflows["image-to-views-idol"];
+ expect(w.packs).toEqual({ "ComfyUI-Idol": ["IdolCamera", "IdolPreprocessImage", "IdolPruneSplat"] });
+ expect(w.files).toEqual(req.workflows["image-to-splat-idol-clean"].files);
+ expect(w.core).toContain("RenderSplat");
+ expect(w.core).not.toContain("SaveGLB");
+ });
+});
+
+describe("image-to-views-idol: the graph", () => {
+ it("is the clean graph up to the pruned splat, without the file, the orbit video or the still", () => {
+ for (const id of ["99", "88:35", "88:110", "88:24", "88:6", "88:16", "88:96", "88:11", "88:55", "88:111", "88:112", "88:7", "88:8", "88:95", "88:85:81", "88:85:82"]) expect(graph[id], id).toEqual(clean[id]);
+ for (const id of ["41", "42", "51", "75", "79", "92", "93", "94", "88:113"]) expect(graph[id], id).toBeUndefined();
+ expect(graph["88:112"]).toEqual({ class_type: "IdolCamera", inputs: { samples: ["88:6", 0] }, _meta: expect.anything() });
+ });
+
+ it("renders the pruned splat from Idol's camera four times, a quarter turn apart toward the object's left, and saves one batch", () => {
+ const r = graph["88:120"];
+ expect(r.class_type).toBe("RenderSplat");
+ expect(r.inputs).toMatchObject({ splat: ["88:111", 0], camera_info: ["88:112", 0], frames: views.IDOL_VIEWS_FRAMES, width: 1024, height: 1024, opacity_threshold: 0.05, render_style: "color", background: "#FFFFFF" });
+ // +4, not -4: RenderSplat turns the camera toward the viewer's right for a positive count, and that's the object's left.
+ expect(r.inputs.frames).toBeGreaterThan(0);
+ expect(graph["96"]).toMatchObject({ class_type: "SaveImage", inputs: { images: ["88:120", 0] } });
+ const saves = Object.values(graph).filter((n) => /^Save/.test(n.class_type));
+ expect(saves).toHaveLength(1);
+ });
+});
+
+describe("the side of each view", () => {
+ it("index 0 is the front (the input view), then the object's left, back and right, as From several images names them", () => {
+ expect([0, 1, 2, 3].map(views.sideOfIndex)).toEqual(["front", "left", "back", "right"]);
+ expect(views.IDOL_VIEW_ORDER).toEqual(m3d.VIEW_SIDES);
+ expect(views.sideOfIndex(4)).toBeUndefined();
+ expect(views.sideOfIndex(-1)).toBeUndefined();
+ expect(views.idolViewMeta(1)).toEqual({ index: 1, side: "left" });
+ // The page's own words for left and right: the object's, walking round to your right for its left.
+ expect(m3d.SIDES_HINT).toMatch(/walk round to your right for its left side/);
+ });
+
+ it("the provider names each image of the batch by its side", () => {
+ const f = (n: number) => ({ filename: `idol_0000${n}_.png`, subfolder: "fuobe", type: "output" });
+ const outs = collectOutputs({ status: { status_str: "success", completed: true }, outputs: { "96": { images: [f(1), f(2), f(3), f(4)] } } }, getWorkflow("image-to-views-idol").manifest);
+ expect(outs.map((o) => o.meta)).toEqual([
+ { role: "tiles", index: 0, side: "front" },
+ { role: "tiles", index: 1, side: "left" },
+ { role: "tiles", index: 2, side: "back" },
+ { role: "tiles", index: 3, side: "right" },
+ ]);
+ expect(views.idolViewsOf(outs as never)).toEqual({ front: outs[0].url, left: outs[1].url, back: outs[2].url, right: outs[3].url });
+ });
+
+ it("idolViewsOf reads meta.side, else meta.index, else the order of the images", () => {
+ const img = (url: string, meta?: Record<string, unknown>) => ({ url, kind: "image" as const, meta });
+ expect(views.idolViewsOf([img("a", { side: "back" }), img("b", { index: 1 }), img("c")])).toEqual({ back: "a", left: "b" });
+ expect(views.idolViewsOf([img("a"), img("b"), img("c"), img("d")])).toEqual({ front: "a", left: "b", back: "c", right: "d" });
+ expect(views.idolViewsOf([{ url: "v", kind: "video" as const }, img("a")])).toEqual({ front: "a" });
+ });
+});
+
+describe("the provider: the view graph when a request asks for the views", () => {
+ it("resolveWorkflowId swaps either Idol graph to the view graph only when asked and only when the library has it", () => {
+ const r = (extra: Record<string, unknown>, has = true) => resolveWorkflowId("image-to-splat-idol", { op: "splat", clips: 0, images: 1, audio2: false, audio: false, extra, has: () => has });
+ expect(r({ idolViews: true })).toBe("image-to-views-idol");
+ expect(r({})).toBe("image-to-splat-idol");
+ expect(r({ idolViews: "yes" })).toBe("image-to-splat-idol");
+ expect(r({ idolViews: true }, false)).toBe("image-to-splat-idol");
+ expect(resolveWorkflowId("image-to-splat-triposplat", { op: "splat", clips: 0, images: 1, audio2: false, audio: false, extra: { idolViews: true }, has: () => true })).toBe("image-to-splat-triposplat");
+ });
+
+ it("runs image-to-views-idol with Idol's Best settings and the photo's crop, and binds nothing it doesn't take", async () => {
+ const p = await prepare({ ...views.idolViewsRequest(PHOTO, { asPhoto: true }).params!.extra! }, async () => true);
+ expect(p.manifest.id).toBe("image-to-views-idol");
+ expect(p.workflow["88:110"].inputs.mode).toBe("real");
+ expect(p.workflow["88:6"].inputs).toMatchObject({ steps: 50, cfg: 4, sampler_name: "euler", seed: 7 });
+ expect(p.workflow["88:55"].inputs.num_gaussians).toBe(262144);
+ expect(p.workflow["88:120"].inputs.frames).toBe(4);
+ const generated = await prepare({ ...views.idolViewsRequest(PHOTO, { asPhoto: false }).params!.extra! }, async () => true);
+ expect(generated.workflow["88:110"].inputs.mode).toBe("synthetic");
+ });
+
+ it("says plainly that the views need the pack when the ComfyUI hasn't got it (or it's switched off)", async () => {
+ await expect(prepare(viewsExtra(), async () => false)).rejects.toThrow(views.IDOL_VIEWS_NEEDS_PACK);
+ // Unknown (someone's computer, no answer): their ComfyUI has the last word.
+ expect((await prepare(viewsExtra(), async () => undefined)).manifest.id).toBe("image-to-views-idol");
+ });
+
+ it("leaves an ordinary Idol 3D run as it was", async () => {
+ expect((await prepare(m3d.idolExtra("open", "best", false), async () => true)).manifest.id).toBe("image-to-splat-idol-clean");
+ expect((await prepare(m3d.idolExtra("open", "best", false), async () => false)).manifest.id).toBe("image-to-splat-idol");
+ });
+});
+
+describe("the provider's submit", () => {
+ // No progress socket here: the run is only sent.
+ const realWs = globalThis.WebSocket;
+ class NoSocket {
+ readyState = 1;
+ onmessage = null;
+ onerror = null;
+ close() {}
+ }
+ beforeAll(() => {
+ globalThis.WebSocket = NoSocket as unknown as typeof WebSocket;
+ });
+ afterAll(() => {
+ globalThis.WebSocket = realWs;
+ changeAccess([{ kind: "pack", id: "ComfyUI-Idol", on: true }]);
+ });
+ const route = { op: "splat", provider: "comfyui", endpoint: "image-to-splat-idol" } as never;
+ const model = { id: "oss-idol", routes: [route] } as never;
+ const submit = (generationId: string) => comfyProvider.submit({ generationId, model, route, input: { prompt: "", images: ["p.png"], seed: 7, extra: viewsExtra() } });
+
+ it("sends the view graph where the server has the pack, and refuses before /prompt where Settings switched it off", async () => {
+ pack = true;
+ prompts.length = 0;
+ const res = await submit("gen-v1");
+ expect(res.meta).toMatchObject({ workflowId: "image-to-views-idol" });
+ expect(Object.values(prompts.at(-1)!).some((n) => n.class_type === "IdolCamera")).toBe(true);
+ expect(prompts.at(-1)!["88:120"].inputs.frames).toBe(4);
+ changeAccess([{ kind: "pack", id: "ComfyUI-Idol", on: false }]);
+ const before = prompts.length;
+ await expect(submit("gen-v2")).rejects.toThrow(views.IDOL_VIEWS_NEEDS_PACK);
+ expect(prompts.length).toBe(before);
+ changeAccess([{ kind: "pack", id: "ComfyUI-Idol", on: true }]);
+ });
+});
+
+describe("the request, the slots and the chain into TRELLIS.2 multi-view", () => {
+ it("is Idol 3D on your GPU, a helper job kept out of the Library", () => {
+ const req = views.idolViewsRequest(PHOTO);
+ expect(req).toMatchObject({ modelId: "oss-idol", op: "splat", inputs: { images: [PHOTO] }, feature: views.IDOL_VIEWS_FEATURE });
+ expect(req.params?.extra).toMatchObject({ idolViews: true, photoCrop: true, steps: 50, numGaussians: 262144 });
+ expect(isHelperFeature(req.feature)).toBe(true);
+ expect(views.wantsIdolViews(req.params?.extra)).toBe(true);
+ expect(views.wantsIdolViews({})).toBe(false);
+ });
+
+ it("offers the button with only the front filled", () => {
+ expect(views.canMakeOtherSides({ front: "f" })).toBe(true);
+ expect(views.canMakeOtherSides({ front: "f", left: null, back: undefined })).toBe(true);
+ expect(views.canMakeOtherSides({})).toBe(false);
+ expect(views.canMakeOtherSides({ front: "f", back: "b" })).toBe(false);
+ });
+
+ it("fills the left, back and right slots and never replaces a photo the person brought", () => {
+ const made = { front: "v0", left: "v1", back: "v2", right: "v3" };
+ const slot = (url: string, side: string) => ({ ref: url, side });
+ const filled = views.fillOtherSides({ front: { ref: "mine", side: "front" } }, made, slot);
+ expect(filled).toEqual({ front: { ref: "mine", side: "front" }, left: { ref: "v1", side: "left" }, back: { ref: "v2", side: "back" }, right: { ref: "v3", side: "right" } });
+ const kept = views.fillOtherSides({ front: { ref: "mine", side: "front" }, back: { ref: "my-back", side: "back" } }, made, slot);
+ expect(kept.back).toEqual({ ref: "my-back", side: "back" });
+ expect(kept.left?.ref).toBe("v1");
+ // A run that came back short fills what it has.
+ expect(views.fillOtherSides({ front: { ref: "mine", side: "front" } }, { front: "v0", left: "v1" }, slot)).toEqual({ front: { ref: "mine", side: "front" }, left: { ref: "v1", side: "left" } });
+ });
+
+ it("the filled slots go to oss-trellis2-multi in VIEW_SIDES order, with each photo's side named", () => {
+ const made = { front: "v0", left: "/api/files/l.png", back: "/api/files/b.png", right: "/api/files/r.png" };
+ const slots = views.fillOtherSides({ front: PHOTO }, made, (u) => u);
+ const req = m3d.model3dRequest({ engine: "open", mode: "multi", views: slots as never });
+ expect(req.modelId).toBe("oss-trellis2-multi");
+ expect(req.inputs?.images).toEqual([PHOTO, made.left, made.back, made.right]);
+ expect(req.params?.extra).toEqual({ views: ["front", "left", "back", "right"] });
+ expect(m3d.model3dBlocker({ engine: "open", mode: "multi", views: slots as never })).toBeNull();
+ // The person's own photos still go as they did.
+ const own = m3d.model3dRequest({ engine: "open", mode: "multi", views: { front: PHOTO, back: "/api/files/my-back.png" } });
+ expect(own.inputs?.images).toEqual([PHOTO, "/api/files/my-back.png"]);
+ expect(own.params?.extra).toEqual({ views: ["front", "back"] });
+ });
+
+ it("an element gets the left, back and right views it hasn't got yet", () => {
+ const made = { front: "v0", left: "v1", back: "v2", right: "v3" };
+ expect(views.elementViews(made)).toEqual(["v1", "v2", "v3"]);
+ expect(views.elementViews(made, ["v2"])).toEqual(["v1", "v3"]);
+ expect(views.elementViews({ front: "v0" })).toEqual([]);
+ });
+});
+
+describe("demo mode", () => {
+ it("the placeholder answers an Idol views run with four labelled pictures, front first", async () => {
+ const { mockProvider } = await import("@/server/providers/mock");
+ const model = getModel("oss-idol")!;
+ const route = model.routes[0];
+ const sub = await mockProvider.submit({ route, input: { prompt: "", images: [PHOTO], extra: viewsExtra() }, generationId: "g", model } as never);
+ expect(sub.meta?.idolViews).toBe(true);
+ const done = await mockProvider.poll({ externalId: sub.externalId, meta: { ...sub.meta, startedAt: 0 }, model, route } as never);
+ expect(done.state).toBe("succeeded");
+ const outs = (done as { outputs: { kind: string; url: string; meta?: Record<string, unknown> }[] }).outputs;
+ expect(outs.map((o) => [o.kind, o.meta?.index, o.meta?.side])).toEqual([
+ ["image", 0, "front"],
+ ["image", 1, "left"],
+ ["image", 2, "back"],
+ ["image", 3, "right"],
+ ]);
+ // An ordinary splat run is unchanged.
+ const plain = await mockProvider.submit({ route, input: { prompt: "", images: [PHOTO], extra: m3d.idolExtra("open") }, generationId: "g2", model } as never);
+ expect(plain.meta?.idolViews).toBe(false);
+ });
+});
+
+describe("the GPU pre-flight board", () => {
+ it("has a row for the other sides that needs the view graph (and so the ComfyUI-Idol pack)", async () => {
+ const { STUDIO_ROWS, studioTool } = await import("@/server/gpu/tools");
+ const row = STUDIO_ROWS.find((r) => r.href === "/image-to-3d?mode=multi")!;
+ expect(row).toMatchObject({ label: "Other sides from one picture", group: "Images" });
+ expect(studioTool(row)).toMatchObject({ ref: "studio:/image-to-3d?mode=multi", kind: "image", workflows: ["image-to-views-idol"], loras: [] });
+ expect(new Set(STUDIO_ROWS.map((r) => r.href)).size).toBe(STUDIO_ROWS.length);
+ });
+});