Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

feat([issue-2981]): wire the 3D-page Generate flow + prompt for Hugging Face gated-model access

[._.]/ Adam Eivy731315b214af
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index aa01a10f10..11a712f8cf 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -2,6 +2,7 @@
## 3D
+- **[issue-2981] Generate a 3D mesh from the 3D page — with a heads-up about Hugging Face access** — the **Generate 3D** button on the 3D page is now live: pick a source image, click Generate, watch on-device progress, and the finished `.glb` renders right there in the interactive viewer (its URL is shareable and reload-safe). If a render fails, the reason now shows inline — including the exact steps when TRELLIS.2 needs Hugging Face access. And before you ever hit that wall, the page and installer now tell you up front that TRELLIS.2 downloads two **gated** Hugging Face models on first render (DINOv3 and RMBG-2.0) and links you to accept their terms and sign in (`huggingface-cli login` or an `HF_TOKEN`).
- **[issue-2952] Turn a rendered image into a downloadable 3D mesh (create/render backend)** — once TRELLIS.2 is installed, PortOS can now take one of your gallery images and render it into a real 3D model (a `.glb` mesh with PBR textures) entirely on-device. Each render is saved as its own record you can list, re-render, download, or delete, and it tracks live status (generating → ready, with progress) and its render history — the backend "create a 3D model" path the 3D page's UI drives. The render only ever runs when you ask for it (never in the background), and is refused with a clear reason if the model isn't installed or your hardware can't run it.
- **[issue-2953] Install image-to-3D models from a new 3D page** — a new **3D** page under Create lists the available image-to-3D models (starting with Microsoft TRELLIS.2) and shows each one's state at a glance: **Ready**, an **Install** button, or a note explaining why your hardware can't run it (e.g. needs an Apple Silicon Mac with enough memory). Installing runs entirely on-device with a live progress log — the same in-app install experience as the image generators — so you never touch a terminal. Reachable from the sidebar, ⌘K, and voice. (Turning one of your rendered images into a 3D mesh from this page lands next.)
- **[issue-2952] TRELLIS.2 install now survives network hiccups** — the multi-gigabyte TRELLIS.2 install pulls from several code repositories, and a single dropped connection mid-download used to abort the whole thing with a cryptic error. The installer now automatically retries a step that fails from a transient network drop (with a short backoff), and already-downloaded pieces are kept — so a flaky connection resumes instead of starting over. If it still can't finish, the error now says plainly that it was a network hiccup and that clicking **Install** again picks up where it left off.
diff --git a/client/src/pages/Media3D.jsx b/client/src/pages/Media3D.jsx
index 3c1bba87d2..49e08e6f01 100644
--- a/client/src/pages/Media3D.jsx
+++ b/client/src/pages/Media3D.jsx
@@ -1,12 +1,60 @@
-import { useCallback, useEffect, useMemo, useState } from 'react';
+import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useSearchParams } from 'react-router-dom';
-import { Boxes, CheckCircle2, Download, AlertTriangle, Loader2, ExternalLink, ImagePlus, Sparkles } from 'lucide-react';
-import { getImageTo3dTargets } from '../services/api';
+import { Boxes, CheckCircle2, Download, AlertTriangle, Loader2, ExternalLink, ImagePlus, Sparkles, KeyRound } from 'lucide-react';
+import { getImageTo3dTargets, createImageTo3dModel, getImageTo3dModel } from '../services/api';
import RuntimeInstallModal from '../components/install/RuntimeInstallModal';
import GalleryImagePicker from '../components/imageGen/GalleryImagePicker';
import GlbViewer from '../components/media/GlbViewer';
import MediaImage from '../components/MediaImage';
+// Poll cadence while a render is in flight (a real TRELLIS.2 render is multi-minute).
+const POLL_INTERVAL_MS = 2500;
+
+// A model record needs a name (1–120 chars); derive a sensible default from the
+// source image filename so the user isn't prompted for one mid-flow.
+function deriveModelName(filename) {
+ const base = String(filename || '').split('/').pop().replace(/\.[^.]+$/, '').trim();
+ return (base || 'Untitled 3D model').slice(0, 120);
+}
+
+// Targets that download gated Hugging Face models on first run. Keyed by target id
+// so the page can warn about the (free, one-time) HF sign-in + terms acceptance
+// BEFORE a render fails opaquely. TRELLIS.2 pulls DINOv3 (image conditioning) and
+// RMBG-2.0 (background removal), both gated Meta/BRIA repos.
+const HF_GATED_MODELS = {
+ trellis2: [
+ { label: 'facebook/dinov3-vitl16-pretrain-lvd1689m', url: 'https://huggingface.co/facebook/dinov3-vitl16-pretrain-lvd1689m' },
+ { label: 'briaai/RMBG-2.0', url: 'https://huggingface.co/briaai/RMBG-2.0' },
+ ],
+};
+
+// Prerequisite notice for a target that needs gated Hugging Face access. Shown once
+// the gated target is selectable so the user accepts terms + signs in up front.
+function HfAccessNotice({ models }) {
+ if (!models?.length) return null;
+ return (
+ <div className="rounded-lg border border-port-warning/40 bg-port-warning/10 p-3 text-xs text-gray-300">
+ <div className="mb-1 flex items-center gap-1.5 font-medium text-port-warning">
+ <KeyRound className="h-3.5 w-3.5" /> Needs a free Hugging Face account
+ </div>
+ <p className="text-gray-400">
+ On first render this downloads two <strong>gated</strong> models. Accept their terms (signed in to Hugging Face), then
+ authenticate the machine with <code className="rounded bg-port-bg px-1">huggingface-cli login</code> or an{' '}
+ <code className="rounded bg-port-bg px-1">HF_TOKEN</code>:
+ </p>
+ <ul className="mt-1.5 space-y-1">
+ {models.map((m) => (
+ <li key={m.url}>
+ <a href={m.url} target="_blank" rel="noreferrer" className="inline-flex items-center gap-1 text-port-accent hover:underline">
+ <ExternalLink className="h-3 w-3" /> {m.label}
+ </a>
+ </li>
+ ))}
+ </ul>
+ </div>
+ );
+}
+
// Human-readable reasons a target can't run on this host, keyed by the stable
// reason code the registry returns (server/services/imageTo3d/targets.js).
const REASON_LABEL = {
@@ -113,6 +161,20 @@ export default function Media3D() {
// The target whose install modal is open (only local-install targets); null = closed.
const [installTarget, setInstallTarget] = useState(null);
const [pickerOpen, setPickerOpen] = useState(false);
+ // Render lifecycle: a create kicks off an on-device render, then we poll the
+ // record until it lands (ready → preview) or fails (error → surfaced inline,
+ // which is where the runner's actionable HF-auth message shows up).
+ const [generating, setGenerating] = useState(false);
+ const [genError, setGenError] = useState(null);
+ const [genPercent, setGenPercent] = useState(null);
+ const pollRef = useRef(null);
+ const mountedRef = useRef(true);
+ // Deferred-poll guards: stop firing into the void after unmount (never reset to
+ // true — handles dev-mode double-mount cleanly).
+ useEffect(() => () => {
+ mountedRef.current = false;
+ if (pollRef.current) clearTimeout(pollRef.current);
+ }, []);
const load = useCallback(() => {
setLoading(true);
@@ -163,19 +225,60 @@ export default function Media3D() {
const handlePick = (item) => { setParam('image', item.filename); setPickerOpen(false); };
- // The image→mesh runner (POST generate + landed .glb) lands with #2952. Until a
- // producer exists the workspace only *stages* the source image + target, so the
- // Generate action is always gated — this returns the reason it's blocked, and the
- // button stays disabled whenever a reason is present (which, today, is always,
- // via the terminal "coming next" branch — so no inert-but-enabled button leaks).
+ // Poll a record until the render settles. Guards on mountedRef so a navigation-away
+ // unmount stops the loop; a fresh generate cancels any prior timer before starting.
+ const pollModel = useCallback((id) => {
+ const tick = async () => {
+ const model = await getImageTo3dModel(id, { silent: true }).catch((err) => {
+ if (mountedRef.current) { setGenerating(false); setGenError(err?.message || 'Lost track of the render.'); }
+ return null;
+ });
+ if (!model || !mountedRef.current) return;
+ const latest = Array.isArray(model.runs) && model.runs.length ? model.runs[model.runs.length - 1] : null;
+ if (Number.isFinite(latest?.percent)) setGenPercent(latest.percent);
+ if (model.status === 'ready' && model.assetPath) {
+ setGenerating(false); setGenPercent(100); setParam('glb', model.assetPath);
+ return;
+ }
+ if (model.status === 'failed' || model.status === 'canceled') {
+ setGenerating(false);
+ // model.error carries the runner's actionable message (e.g. the HF-auth guidance).
+ setGenError(model.error || 'The render did not finish.');
+ return;
+ }
+ pollRef.current = setTimeout(tick, POLL_INTERVAL_MS); // still draft/generating
+ };
+ tick();
+ }, [setParam]);
+
+ const handleGenerate = useCallback(async () => {
+ if (!selectedImage || !selectedTarget) return;
+ if (pollRef.current) clearTimeout(pollRef.current);
+ setGenError(null); setGenPercent(0); setGenerating(true);
+ setParam('glb', ''); // clear any previously-previewed mesh
+ const created = await createImageTo3dModel(
+ { name: deriveModelName(selectedImage.filename), filename: selectedImage.filename, target: selectedTarget.id },
+ { silent: true },
+ ).catch((err) => {
+ if (mountedRef.current) { setGenerating(false); setGenError(err?.message || 'Could not start the render.'); }
+ return null;
+ });
+ if (created && mountedRef.current) pollModel(created.id);
+ }, [selectedImage, selectedTarget, setParam, pollModel]);
+
+ // Why the Generate action is blocked, or null when it's ready to run. The runner
+ // (POST create → on-device render → landed .glb) is wired, so the terminal state
+ // is "ready", not a placeholder.
const generateGatedReason = (() => {
if (!selectedImage) return 'Pick a source image to continue.';
if (!selectedTarget) return 'No image-to-3D model is registered.';
if (!selectedTarget.available) return REASON_LABEL[selectedTarget.unavailableReason] || 'This model can’t run on this host.';
if (selectedTarget.installed === false) return `Install ${selectedTarget.label} below before generating.`;
- return 'Generation lands with the on-device runner — coming next.';
+ return null;
})();
+ const gatedHfModels = selectedTarget?.available ? HF_GATED_MODELS[selectedTarget?.id] : null;
+
return (
<div className="mx-auto max-w-4xl">
<header className="mb-5">
@@ -189,8 +292,7 @@ export default function Media3D() {
</p>
</header>
- {/* Generation workspace — source image + target selection + preview. The
- create/generate call is wired when the runner (#2952) lands. */}
+ {/* Generation workspace — source image + target selection → on-device render. */}
<section className="mb-6 grid gap-4 rounded-xl border border-port-border bg-port-card p-4 sm:grid-cols-[200px_1fr]">
<button
type="button"
@@ -244,22 +346,35 @@ export default function Media3D() {
)}
</div>
+ {gatedHfModels && <HfAccessNotice models={gatedHfModels} />}
+
<div className="mt-auto flex flex-col items-start gap-2">
<button
type="button"
- disabled={!!generateGatedReason}
- title={generateGatedReason}
+ onClick={handleGenerate}
+ disabled={!!generateGatedReason || generating}
+ title={generateGatedReason || undefined}
className="inline-flex items-center gap-2 rounded-lg bg-port-accent px-4 py-2 text-sm text-white hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-40"
>
- <Sparkles className="h-4 w-4" /> Generate 3D
+ {generating
+ ? <><Loader2 className="h-4 w-4 animate-spin" /> Generating{Number.isFinite(genPercent) ? ` ${Math.round(genPercent)}%` : '…'}</>
+ : <><Sparkles className="h-4 w-4" /> Generate 3D</>}
</button>
- <p className="text-xs text-gray-500">{generateGatedReason}</p>
+ {genError ? (
+ <p className="flex items-start gap-1.5 text-xs text-port-error">
+ <AlertTriangle className="mt-0.5 h-3.5 w-3.5 shrink-0" /> {genError}
+ </p>
+ ) : (
+ <p className="text-xs text-gray-500">
+ {generating ? 'Rendering on-device — this takes a few minutes.' : (generateGatedReason || 'Ready to render on-device.')}
+ </p>
+ )}
</div>
</div>
</section>
- {/* Generated-mesh preview. Driven by `?glb=` so a finished render (#2952)
- is a shareable, reload-safe deep link; empty until one lands. */}
+ {/* Generated-mesh preview. Driven by `?glb=` so a finished render is a
+ shareable, reload-safe deep link; empty until one lands. */}
{glbFromRoute && (
<section className="mb-6">
<h2 className="mb-2 text-xs font-medium uppercase tracking-wide text-gray-400">Mesh preview</h2>
@@ -306,7 +421,7 @@ export default function Media3D() {
runtime={installTarget?.id}
label={installTarget?.label}
installUrlBase="/api/image-to-3d/trellis2/install"
- description="Cloning the TRELLIS.2 (Apple Silicon) port and installing its Python environment. The model weights are a large download on first run (~15 GB)."
+ description="Cloning the TRELLIS.2 (Apple Silicon) port and installing its Python environment (~15 GB on first run). It also pulls two gated Hugging Face models on first render — accept their terms and sign in with huggingface-cli login / HF_TOKEN (see the note on the 3D page)."
onClose={() => setInstallTarget(null)}
onComplete={() => { setInstallTarget(null); load(); }}
/>
diff --git a/client/src/pages/Media3D.test.jsx b/client/src/pages/Media3D.test.jsx
index 93d40dc799..db69ea0297 100644
--- a/client/src/pages/Media3D.test.jsx
+++ b/client/src/pages/Media3D.test.jsx
@@ -4,8 +4,12 @@ import { MemoryRouter, useLocation } from 'react-router-dom';
import Media3D from './Media3D';
const getImageTo3dTargets = vi.fn();
+const createImageTo3dModel = vi.fn();
+const getImageTo3dModel = vi.fn();
vi.mock('../services/api', () => ({
getImageTo3dTargets: (...a) => getImageTo3dTargets(...a),
+ createImageTo3dModel: (...a) => createImageTo3dModel(...a),
+ getImageTo3dModel: (...a) => getImageTo3dModel(...a),
}));
// Stub the shared install modal so the test doesn't open a real EventSource;
@@ -108,13 +112,40 @@ describe('Media3D — generation workspace', () => {
expect(screen.queryByText(/Pick a source image to continue/i)).not.toBeInTheDocument();
});
- it('keeps Generate disabled with a "coming next" reason once an image + ready target are staged', async () => {
- // Generation is deferred to the runner (#2952); even a fully-staged workspace
- // must not present a live-but-inert button.
+ it('enables Generate when an image + ready target are staged, and previews the produced mesh', async () => {
+ createImageTo3dModel.mockResolvedValue({ id: 'm1', status: 'generating', assetPath: null, runs: [] });
+ getImageTo3dModel.mockResolvedValue({
+ id: 'm1', status: 'ready', assetPath: '/data/image-to-3d/m1/model.glb', runs: [{ percent: 100 }],
+ });
renderAt('/media/3d?image=example-robot.png');
const btn = await screen.findByRole('button', { name: /Generate 3D/i });
- expect(btn).toBeDisabled();
- expect(screen.getByText(/Generation lands with the on-device runner/i)).toBeInTheDocument();
+ expect(btn).toBeEnabled();
+ fireEvent.click(btn);
+ await waitFor(() => expect(createImageTo3dModel).toHaveBeenCalledWith(
+ expect.objectContaining({ filename: 'example-robot.png', target: 'trellis2', name: 'example-robot' }),
+ expect.anything(),
+ ));
+ expect(await screen.findByTestId('glb-viewer')).toHaveTextContent('/data/image-to-3d/m1/model.glb');
+ });
+
+ it('surfaces the render error (e.g. the Hugging Face auth guidance) on failure', async () => {
+ createImageTo3dModel.mockResolvedValue({ id: 'm2', status: 'generating', runs: [] });
+ getImageTo3dModel.mockResolvedValue({
+ id: 'm2', status: 'failed', assetPath: null,
+ error: 'TRELLIS.2 could not download a gated model dependency from Hugging Face. Accept the terms … huggingface-cli login',
+ });
+ renderAt('/media/3d?image=example-robot.png');
+ fireEvent.click(await screen.findByRole('button', { name: /Generate 3D/i }));
+ expect(await screen.findByText(/could not download a gated model dependency from Hugging Face/i)).toBeInTheDocument();
+ // No mesh preview on failure.
+ expect(screen.queryByTestId('glb-viewer')).toBeNull();
+ });
+
+ it('shows the Hugging Face gated-model prerequisite for the TRELLIS.2 target', async () => {
+ renderAt('/media/3d?image=example-robot.png');
+ expect(await screen.findByText(/needs a free Hugging Face account/i)).toBeInTheDocument();
+ expect(screen.getByRole('link', { name: /dinov3-vitl16-pretrain-lvd1689m/i })).toBeInTheDocument();
+ expect(screen.getByRole('link', { name: /RMBG-2\.0/i })).toBeInTheDocument();
});
it('keeps Generate disabled and explains why when no image is picked', async () => {
diff --git a/client/src/services/README.md b/client/src/services/README.md
index a1db8126f2..856d7c7f9f 100644
--- a/client/src/services/README.md
+++ b/client/src/services/README.md
@@ -98,6 +98,7 @@ toasts on throw). **Custom catch ⇒ `silent: true`** — otherwise toasts fire
| `apiMusicVideo.js` | Music Video projects + scene board + audio analysis. |
| `apiSprites.js` | Sprite Manager records, asset library, production-set import (#2895), reference workflow: create/generate/lock (#2896), walk workflow: generate/approve/trim/postprocess (#2897). |
| `apiThreejsModels.js` | Procedural Three.js model workspaces: gallery-image generation, refinement, source export, and deletion. |
+| `apiImageTo3d.js` | Image-to-3D (`/media/3d`): selectable targets (TRELLIS.2) with host availability/install status, and per-image model records — create/list/get/generate/delete + GLB asset URL. |
| `apiPipeline.js` | Pipeline (issues + stages + canon). |
| `apiUniverseBuilder.js` | Universe Builder (generate + edit + commit). |
| `apiAuthors.js` | Author personas (name, writing style, bio, headshot description/style). |
diff --git a/client/src/services/api.js b/client/src/services/api.js
index 7ef806089b..2490b9ba53 100644
--- a/client/src/services/api.js
+++ b/client/src/services/api.js
@@ -19,6 +19,7 @@ export * from './apiGit.js';
export * from './apiCatalog.js';
export * from './apiCatalogTypes.js';
export * from './apiMedia.js';
+export * from './apiImageTo3d.js';
export * from './apiAgents.js';
export * from './apiPersonalities.js';
export * from './apiAccounts.js';
diff --git a/client/src/services/apiCore.js b/client/src/services/apiCore.js
index 7bfa316218..0f7076b2f9 100644
--- a/client/src/services/apiCore.js
+++ b/client/src/services/apiCore.js
@@ -90,10 +90,6 @@ export async function request(endpoint, options = {}) {
// Search
export const search = (q) => request(`/search?q=${encodeURIComponent(q)}`);
-// Image-to-3D: the selectable targets (TRELLIS.2, …) annotated with host
-// availability + install status, for the /media/3d management page.
-export const getImageTo3dTargets = () => request('/image-to-3d/targets');
-
// Default export for simplified imports
export default {
get: (endpoint, options) => request(endpoint, { method: 'GET', ...options }),
diff --git a/client/src/services/apiImageTo3d.js b/client/src/services/apiImageTo3d.js
new file mode 100644
index 0000000000..7c4c2b03cd
--- /dev/null
+++ b/client/src/services/apiImageTo3d.js
@@ -0,0 +1,40 @@
+import { request } from './apiCore.js';
+
+// Image-to-3D (the /media/3d page): the selectable targets (TRELLIS.2, …)
+// annotated with host availability + install status, plus the per-image model
+// records that drive create → render → preview → download.
+
+export const getImageTo3dTargets = (options) => request('/image-to-3d/targets', options);
+
+export const listImageTo3dModels = (options) => request('/image-to-3d/models', options);
+
+export const getImageTo3dModel = (id, options) =>
+ request(`/image-to-3d/models/${encodeURIComponent(id)}`, options);
+
+// Create a record from a gallery image; the server kicks off the on-device render
+// immediately (status → generating), so poll getImageTo3dModel until ready/failed.
+export const createImageTo3dModel = (input, options) =>
+ request('/image-to-3d/models', {
+ method: 'POST',
+ body: JSON.stringify(input),
+ ...options,
+ });
+
+// Re-run the render for an existing record (status → generating again).
+export const generateImageTo3dModel = (id, options) =>
+ request(`/image-to-3d/models/${encodeURIComponent(id)}/generate`, {
+ method: 'POST',
+ ...options,
+ });
+
+export const deleteImageTo3dModel = (id, options) =>
+ request(`/image-to-3d/models/${encodeURIComponent(id)}`, {
+ method: 'DELETE',
+ ...options,
+ });
+
+// Direct GLB download endpoint (Content-Disposition attachment). The record's
+// `assetPath` (the static `/data/image-to-3d/<id>/model.glb` mount) is what the
+// GlbViewer renders; this URL is for an explicit "download the file" action.
+export const imageTo3dAssetUrl = (id) =>
+ `/api/image-to-3d/models/${encodeURIComponent(id)}/asset`;