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 and Elements: make the other sides of an object from its front with Idol 3D

Claudea09fe4de291f
diff --git a/src/components/elements-view.tsx b/src/components/elements-view.tsx
index e45d3d8f..7b29ffa5 100644
--- a/src/components/elements-view.tsx
+++ b/src/components/elements-view.tsx
@@ -3,7 +3,7 @@
import { AtSign, AudioLines, Check, Copy, GraduationCap, Loader2, Plus, Trash2, X } from "lucide-react";
import Link from "next/link";
import { useRouter, useSearchParams } from "next/navigation";
-import { Suspense, useMemo, useState } from "react";
+import { Suspense, useCallback, useMemo, useState } from "react";
import { nanoid } from "nanoid";
import { toast } from "sonner";
import { PageHeader, PageShell } from "@/components/page-shell";
@@ -28,6 +28,9 @@ import { fileToSlot, MediaSlot, type SlotValue } from "@/components/studio/media
import { ELEMENT_ICONS } from "@/components/studio/prompt-input";
import { VoiceRecorder } from "@/components/studio/voice-recorder";
import { useMaybeClean } from "@/components/audio-tools/clean-voice-switch";
+import { OtherSides, useOtherSidesOffered } from "@/components/model3d/other-sides";
+import { elementViews, IDOL_VIEWS_NOTE, OTHER_SIDES } from "@/lib/av/idol-views";
+import type { ViewSide } from "@/lib/av/model3d";
import { SelfHostNote } from "@/components/self-host-note";
import { useEdgeFade } from "@/components/studio/use-edge-fade";
import { useDeleteElement, useElements, useIsVisitor, useSaveElement } from "@/lib/api";
@@ -139,6 +142,20 @@ function ElementForm({ onOpenChange, element, defaultKind = "character", onSaved
const uploading = photos.some((p) => p.uploading);
const refs = photos.filter((p) => p.ref).map((p) => p.ref);
+ // Characters and products (idol-8): side and back views made from the first photo with Idol 3D on your GPU, once per
+ // dialog, while there's room for them.
+ const sidesOffered = useOtherSidesOffered();
+ const [sidesAdded, setSidesAdded] = useState<string[] | null>(null);
+ const first = photos[0];
+ const offerSides = sidesOffered && !sidesAdded && (kind === "character" || kind === "prop") && !!first?.ref && !first.uploading && photos.length + OTHER_SIDES.length <= MAX_PHOTOS;
+ const addSides = useCallback(
+ (made: Partial<Record<ViewSide, string>>) => {
+ const urls = elementViews(made);
+ setPhotos((ps) => [...ps, ...urls.filter((u) => !ps.some((p) => p.ref === u)).map((url) => ({ id: nanoid(6), ref: url, preview: url, kind: "image" as const, source: "generation" as const }))]);
+ setSidesAdded(urls);
+ },
+ [],
+ );
const canSave = !!name.trim() && (refs.length > 0 || !!description.trim()) && !uploading && !save.isPending;
const submit = () =>
@@ -218,7 +235,11 @@ function ElementForm({ onOpenChange, element, defaultKind = "character", onSaved
)}
</>
) : (
- <PhotoGrid photos={photos} setPhotos={setPhotos} />
+ <>
+ <PhotoGrid photos={photos} setPhotos={setPhotos} />
+ {offerSides && first && <OtherSides photo={first.ref} asPhoto={first.source !== "generation"} label="Add side and back views" onMade={addSides} />}
+ {sidesAdded?.some((u) => refs.includes(u)) && <p className="text-[12px] text-muted-foreground">Side and back views by Idol 3D: {IDOL_VIEWS_NOTE.charAt(0).toLowerCase() + IDOL_VIEWS_NOTE.slice(1)}</p>}
+ </>
)}
</div>
<DialogFooter>
diff --git a/src/components/model3d/model3d-studio.tsx b/src/components/model3d/model3d-studio.tsx
index bd886db5..97c5cbfd 100644
--- a/src/components/model3d/model3d-studio.tsx
+++ b/src/components/model3d/model3d-studio.tsx
@@ -51,6 +51,8 @@ import { toastError } from "@/lib/refusals";
import { priceLine, useRunPreview } from "./hooks";
import { ModelCard } from "./model-card";
import { RefineOption } from "./refine-option";
+import { OtherSides, useOtherSidesOffered } from "./other-sides";
+import { IDOL_VIEWS_NOTE, canMakeOtherSides, fillOtherSides } from "@/lib/av/idol-views";
import { HI3D_MODEL, withRefine, type Hi3dResolution } from "@/lib/av/hi3d";
/**
@@ -358,6 +360,18 @@ export function Model3dStudio({ info }: { info: Record<string, Model3dInfo> }) {
const licence = modelId ? info[modelId]?.licence : undefined;
const items = (results.data ?? []).filter((g) => g.feature !== "image-to-3d-step");
const setSide = (s: ViewSide) => (v: SlotValue | null) => setViews((cur) => ({ ...cur, [s]: v }));
+ // From several images on your GPU, with only the front in: Idol 3D makes the other three sides from it (idol-8).
+ const sidesOffered = useOtherSidesOffered();
+ const front = views.front;
+ const [sidesBusy, setSidesBusy] = useState(false);
+ const otherSides = mode === "multi" && engine === "open" && sidesOffered && !!front && !front.uploading && (sidesBusy || canMakeOtherSides(views));
+ // The views it made, so the note about them stays while they're in the slots.
+ const [madeSides, setMadeSides] = useState<string[]>([]);
+ const takeSides = useCallback((made: Partial<Record<ViewSide, string>>) => {
+ setMadeSides((cur) => [...cur, ...Object.values(made).filter((u): u is string => !!u)]);
+ setViews((cur) => fillOtherSides(cur, made, (url) => ({ ref: url, preview: url, kind: "image", source: "generation" })));
+ }, []);
+ const showsMade = mode === "multi" && VIEW_SIDES.some((s) => s !== "front" && !!views[s] && madeSides.includes(views[s]!.ref));
return (
<ToolShell title="Image to 3D" selfHostedOnly>
<Suspense fallback={null}>
@@ -402,6 +416,10 @@ export function Model3dStudio({ info }: { info: Record<string, Model3dInfo> }) {
The front and at least one more side. Same object, same distance and light in each; a plain background helps.
{engine === "open" && ` The open model puts each photo on the side you add it to. ${SIDES_HINT}`}
</p>
+ {otherSides && front && (
+ <OtherSides className="mt-3" photo={front.ref} asPhoto={front.source !== "generation"} label="Make the other sides from the front (Idol 3D)" onMade={takeSides} onBusy={setSidesBusy} />
+ )}
+ {!otherSides && showsMade && <p className="mt-2 text-[12px] text-muted-foreground">Made by Idol 3D: {IDOL_VIEWS_NOTE.charAt(0).toLowerCase() + IDOL_VIEWS_NOTE.slice(1)}</p>}
</Panel>
) : mode === "text" ? (
<Panel title="Describe the object">
diff --git a/src/components/model3d/other-sides.tsx b/src/components/model3d/other-sides.tsx
new file mode 100644
index 00000000..a3185c70
--- /dev/null
+++ b/src/components/model3d/other-sides.tsx
@@ -0,0 +1,94 @@
+"use client";
+
+import { Loader2, Rotate3d } from "lucide-react";
+import { useEffect, useRef, useState } from "react";
+import { Button } from "@/components/ui/button";
+import { useCreateGeneration, useEngine, useGenerations, useIsVisitor, useModelAccess } from "@/lib/api";
+import { IDOL_MODELS } from "@/lib/av/model3d";
+import { IDOL_VIEWS_FEATURE, IDOL_VIEWS_NOTE, idolViewsOf, idolViewsRequest } from "@/lib/av/idol-views";
+import type { ViewSide } from "@/lib/av/model3d";
+import { offered } from "@/lib/model-access";
+import { toastError } from "@/lib/refusals";
+import { cn } from "@/lib/utils";
+import { priceLine, useRunPreview } from "./hooks";
+
+/**
+ * Whether "Make the other sides" is offered here: Idol 3D's views run on your GPU only (Idol's cloud endpoint returns a
+ * splat, not views), so not on an install that runs paid APIs only, not with Idol 3D switched off in Settings → Models &
+ * licences, and not for a guest or an account (3D models are the owner's for now).
+ */
+export function useOtherSidesOffered(): boolean {
+ const [, , engineMode] = useEngine();
+ const access = useModelAccess();
+ const visitor = useIsVisitor();
+ return !visitor && engineMode !== "cloud" && offered(access, IDOL_MODELS.open, "open");
+}
+
+/**
+ * The button that makes the other sides of the object in one picture (Idol 3D on your GPU: front, left, back, right) and
+ * hands them over once they're ready. Said plainly beside it: they're renders of a 3D guess, so they can be soft.
+ */
+export function OtherSides({
+ photo,
+ asPhoto,
+ label,
+ onMade,
+ onBusy,
+ className,
+}: {
+ /** The picture of the front (an uploaded or library file). */
+ photo: string;
+ /** The picture is a photo (Idol's looser crop); a picture made here isn't. */
+ asPhoto: boolean;
+ label: string;
+ onMade: (views: Partial<Record<ViewSide, string>>) => void;
+ /** Told while a run is going (the page keeps the button there until its views are in). */
+ onBusy?: (busy: boolean) => void;
+ className?: string;
+}) {
+ const create = useCreateGeneration();
+ const [runId, setRunId] = useState<string | null>(null);
+ const list = useGenerations({ features: [IDOL_VIEWS_FEATURE], limit: 20 });
+ const run = runId ? list.data?.find((g) => g.id === runId) : undefined;
+ const preview = useRunPreview(idolViewsRequest(photo, { asPhoto }));
+ const price = priceLine(preview.data);
+ // Hand the views over once per run.
+ const handed = useRef<string | null>(null);
+ const made = useRef(onMade);
+ useEffect(() => {
+ made.current = onMade;
+ }, [onMade]);
+ useEffect(() => {
+ if (!run || run.status !== "succeeded" || handed.current === run.id) return;
+ handed.current = run.id;
+ made.current(idolViewsOf(run.outputs));
+ setRunId(null);
+ }, [run]);
+ const failed = run && (run.status === "failed" || run.status === "canceled") ? run : undefined;
+ const working = create.isPending || (!!runId && !failed);
+ useEffect(() => onBusy?.(working), [onBusy, working]);
+ useEffect(() => () => onBusy?.(false), [onBusy]);
+ const start = () =>
+ create.mutate(idolViewsRequest(photo, { asPhoto }), {
+ onSuccess: (items) => setRunId(items[0]?.id ?? null),
+ onError: (e) => toastError(e),
+ });
+ return (
+ <div className={cn("space-y-1.5", className)} data-testid="other-sides">
+ <Button type="button" variant="outline" size="sm" className="h-auto min-h-8 rounded-full py-1.5 text-left whitespace-normal" onClick={start} disabled={working}>
+ {working ? <Loader2 className="animate-spin" /> : <Rotate3d />}
+ {working ? "Making the other sides…" : label}
+ </Button>
+ <p className="text-[12px] text-muted-foreground" aria-live="polite">
+ {failed ? (
+ <span className="text-destructive">{failed.error ?? "The sides couldn't be made. Please try again."}</span>
+ ) : (
+ <>
+ {price ? `${price} · ` : ""}
+ {IDOL_VIEWS_NOTE}
+ </>
+ )}
+ </p>
+ </div>
+ );
+}
diff --git a/tests/e2e/idol-views.mjs b/tests/e2e/idol-views.mjs
new file mode 100644
index 00000000..64471864
--- /dev/null
+++ b/tests/e2e/idol-views.mjs
@@ -0,0 +1,109 @@
+// Fill the other sides from one picture (idol-8) in a real browser (the app must be running in demo mode).
+// Usage: node tests/e2e/idol-views.mjs [appUrl] [--shots=dir]. Exits 1 on any failure.
+//
+// At 1440 px and 390 px, in light and dark, on your GPU: Image to 3D → From several images with only the front filled
+// offers "Make the other sides from the front (Idol 3D)" with its price and the soft-renders note; pressing it fills the
+// left, back and right slots and Make it 3D is ready. A photo the person brought for a side hides the button. On the cloud
+// engine there's no button. In Elements, a new character with one photo offers "Add side and back views", which adds three
+// pictures. Nothing scrolls sideways; no page errors or console errors.
+import assert from "node:assert/strict";
+import fs from "node:fs";
+import path from "node:path";
+import { DESKTOP, PHONE, launch } 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 sleep = (ms) => new Promise((r) => setTimeout(r, ms));
+async function until(fn, what, ms = 60_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(500);
+ }
+}
+
+const status = await (await fetch(`${app}/api/status`)).json();
+assert.notEqual(status.demoMode, "off", "run the app in demo mode (FUOBE_DEMO_MODE=on)");
+
+const PHOTO = path.resolve("public/previews/presets/app-3d-figure.jpg");
+const BUTTON = "Make the other sides from the front (Idol 3D)";
+const NOTE = /3D guess of your photo/;
+const browser = await launch();
+const failures = [];
+const flat = async (page, tag, where) => assert.equal(await page.evaluate(() => document.documentElement.scrollWidth - window.innerWidth), 0, `${tag}: ${where} doesn't scroll sideways`);
+
+for (const phone of [false, true]) {
+ for (const scheme of ["light", "dark"]) {
+ const tag = `${phone ? "phone" : "desktop"} ${scheme}`;
+ const ctx = await browser.newContext({ ...(phone ? PHONE : DESKTOP), colorScheme: scheme });
+ await ctx.addInitScript(() => localStorage.setItem("fuobe.engine", "open"));
+ const page = await ctx.newPage();
+ page.on("pageerror", (e) => failures.push(`${tag}: page error ${e.message}`));
+ page.on("console", (m) => m.type() === "error" && !/Failed to load resource/.test(m.text()) && failures.push(`${tag}: console ${m.text().slice(0, 200)}`));
+ try {
+ // From several images: only the front in → the button; the views fill the other three slots.
+ await page.goto(`${app}/image-to-3d?mode=multi`, { waitUntil: "load", timeout: 120_000 });
+ await page.getByRole("button", { name: "Front (required): upload" }).waitFor({ timeout: 60_000 });
+ assert.equal(await page.getByRole("button", { name: BUTTON }).count(), 0, `${tag}: no button before the front`);
+ await page.locator('input[type="file"]').first().setInputFiles(PHOTO);
+ const button = page.getByRole("button", { name: BUTTON });
+ await button.waitFor({ timeout: 30_000 });
+ const box = page.getByTestId("other-sides");
+ await until(async () => /Placeholder · nothing is charged|Free/.test(await box.innerText()), `${tag}: the price`, 20_000);
+ assert.match(await box.innerText(), NOTE, `${tag}: the note`);
+ await flat(page, tag, "From several images");
+ if (shots) await page.screenshot({ path: path.join(shots, `multi-${phone ? "390" : "1440"}-${scheme}.png`), fullPage: false });
+ await button.click();
+ for (const side of ["Left side", "Back", "Right side"]) await page.getByRole("button", { name: `Remove ${side}` }).waitFor({ timeout: 60_000 });
+ assert.equal(await page.getByRole("button", { name: BUTTON }).count(), 0, `${tag}: the button goes once the sides are in`);
+ assert.match(await page.locator("main").innerText(), /4 of 4/, `${tag}: four of four`);
+ assert.match(await page.locator("main").innerText(), /Made by Idol 3D: rendered from a 3D guess/, `${tag}: the note stays with the views`);
+ assert.doesNotMatch(await page.locator("main").innerText(), /Add at least one more side/, `${tag}: ready to make it 3D`);
+ await flat(page, tag, "the filled slots");
+ if (shots) await page.screenshot({ path: path.join(shots, `multi-filled-${phone ? "390" : "1440"}-${scheme}.png`) });
+ // A side the person brought: no button. On the cloud engine: no button.
+ await page.getByRole("button", { name: "Remove Left side" }).click();
+ await page.getByRole("button", { name: "Remove Right side" }).click();
+ assert.equal(await page.getByRole("button", { name: BUTTON }).count(), 0, `${tag}: a side already there hides the button`);
+ await page.getByRole("button", { name: "Remove Back" }).click();
+ await button.waitFor({ timeout: 10_000 });
+ await page.evaluate(() => {
+ localStorage.setItem("fuobe.engine", "cloud");
+ window.dispatchEvent(new StorageEvent("storage"));
+ });
+ await until(async () => (await page.getByRole("button", { name: BUTTON }).count()) === 0, `${tag}: no button on the cloud`, 10_000);
+
+ // Elements: a character with one photo → "Add side and back views" adds three pictures.
+ await page.evaluate(() => localStorage.setItem("fuobe.engine", "open"));
+ await page.goto(`${app}/elements`, { waitUntil: "load", timeout: 120_000 });
+ await page.getByRole("button", { name: "New element" }).first().click();
+ const dialog = page.getByRole("dialog");
+ await dialog.waitFor();
+ assert.equal(await dialog.getByRole("button", { name: "Add side and back views" }).count(), 0, `${tag}: no views button before a photo`);
+ await dialog.locator('input[type="file"]').first().setInputFiles(PHOTO);
+ const add = dialog.getByRole("button", { name: "Add side and back views" });
+ await add.waitFor({ timeout: 30_000 });
+ assert.match(await dialog.getByTestId("other-sides").innerText(), NOTE, `${tag}: the element's note`);
+ await flat(page, tag, "the element dialog");
+ await add.click();
+ await until(async () => (await dialog.getByRole("button", { name: "Remove photo" }).count()) === 4, `${tag}: four photos`, 60_000);
+ assert.equal(await dialog.getByRole("button", { name: "Add side and back views" }).count(), 0, `${tag}: offered once`);
+ assert.match(await dialog.innerText(), /Side and back views by Idol 3D: rendered from a 3D guess/, `${tag}: the element's note stays`);
+ if (shots) await dialog.screenshot({ path: path.join(shots, `element-${phone ? "390" : "1440"}-${scheme}.png`) });
+ console.log(`ok ${tag}`);
+ } catch (e) {
+ failures.push(`${tag}: ${e.message}`);
+ }
+ await ctx.close();
+ }
+}
+await browser.close();
+if (failures.length) {
+ console.error(failures.join("\n"));
+ process.exit(1);
+}
+console.log("all good");