Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
feat(forge): gradient thumbnail fallback chain with GLB capture
nirholasbd859faf5d20
diff --git a/pages/forge.html b/pages/forge.htmlindex da8376782..6b6b57b88 100644--- a/pages/forge.html+++ b/pages/forge.html@@ -1853,6 +1853,24 @@color: var(--ink-dim);font-size: 1.6rem;}+ .creation .thumb.gradient-ph {+ display: flex;+ align-items: flex-end;+ position: relative;+ overflow: hidden;+ padding: 0.6rem;+ }+ .creation .thumb .gradient-ph-text {+ font-size: 0.65rem;+ line-height: 1.3;+ color: rgba(255,255,255,0.45);+ display: -webkit-box;+ -webkit-line-clamp: 3;+ -webkit-box-orient: vertical;+ overflow: hidden;+ font-style: italic;+ letter-spacing: 0.01em;+ }.creation .meta {padding: 0.5rem 0.6rem;font-size: var(--text-xs);@@ -1991,6 +2009,39 @@}}+ /* Remix flash: border pulse on the prompt box when a prompt is loaded */+ @keyframes prompt-remix-flash {+ 0% { box-shadow: 0 0 0 0 var(--accent); border-color: var(--accent); }+ 40% { box-shadow: 0 0 0 6px transparent; border-color: var(--accent); }+ 100% { box-shadow: 0 0 0 0 transparent; }+ }+ #prompt.remix-flash {+ animation: prompt-remix-flash 0.7s ease forwards;+ }++ /* Remix toast — floats at top of viewport, fades out */+ .remix-toast {+ position: fixed;+ top: 5rem;+ left: 50%;+ transform: translateX(-50%) translateY(0);+ background: var(--surface-3, #1e1e1e);+ border: 1px solid var(--accent);+ color: var(--ink);+ font-size: 0.8rem;+ padding: 0.5rem 1.1rem;+ border-radius: 999px;+ pointer-events: none;+ white-space: nowrap;+ z-index: 1000;+ opacity: 1;+ transition: opacity 0.4s ease, transform 0.4s ease;+ }+ .remix-toast.fade-out {+ opacity: 0;+ transform: translateX(-50%) translateY(-6px);+ }+/* Empty + error + unconfigured */.notice {padding: var(--space-2xl) var(--space-lg);diff --git a/src/forge-showcase.js b/src/forge-showcase.jsindex 112b45446..590a63338 100644--- a/src/forge-showcase.js+++ b/src/forge-showcase.js@@ -17,6 +17,139 @@ ensureStateKitStyles();const ENGINE_LABELS = { nvidia: 'Free', trellis: 'Fast', meshy: 'Meshy', tripo: 'Tripo', hunyuan3d: 'Hunyuan3D', triposg: 'TripoSG' };+// ── Thumbnail fallback chain ──────────────────────────────────────────────────+// Plan A: preview_image_url from DB → <img>+// Plan B: img onerror or no preview_image_url + has glb_url → capture a frame+// from a hidden <model-viewer> (queued, max 1 concurrent load so we+// don't slam the network with a dozen 10MB GLBs simultaneously)+// Plan C: model-viewer fails / times out → gradient card generated from prompt+// Plan D: no glb_url at all → gradient card++const CAPTURE_TIMEOUT_MS = 20_000;+const captureQueue = [];+let captureActive = false;++function drainCaptureQueue() {+ if (captureActive || captureQueue.length === 0) return;+ captureActive = true;+ const { card, glbUrl, resolve } = captureQueue.shift();+ captureFromGlb(card, glbUrl)+ .then(resolve)+ .catch(() => resolve(null))+ .finally(() => {+ captureActive = false;+ drainCaptureQueue();+ });+}++function enqueueCaptureFromGlb(card, glbUrl) {+ return new Promise((resolve) => {+ captureQueue.push({ card, glbUrl, resolve });+ drainCaptureQueue();+ });+}++async function captureFromGlb(card, glbUrl) {+ if (!window.customElements?.get('model-viewer')) return null;+ return new Promise((resolve) => {+ const viewer = document.createElement('model-viewer');+ viewer.style.cssText =+ 'position:absolute;width:1px;height:1px;opacity:0;pointer-events:none;overflow:hidden;';+ viewer.setAttribute('src', glbUrl);+ viewer.setAttribute('shadow-intensity', '0');+ viewer.setAttribute('exposure', '0.9');+ viewer.setAttribute('environment-image', 'neutral');+ viewer.setAttribute('aria-hidden', 'true');++ let done = false;+ const finish = (dataUrl) => {+ if (done) return;+ done = true;+ clearTimeout(timer);+ viewer.remove();+ resolve(dataUrl);+ };++ const timer = setTimeout(() => finish(null), CAPTURE_TIMEOUT_MS);++ viewer.addEventListener(+ 'load',+ async () => {+ try {+ // Brief settle so the mesh textures are uploaded to GPU.+ await new Promise((r) => setTimeout(r, 800));+ const url = viewer.toDataURL?.('image/webp') ?? null;+ finish(url && url.length > 100 ? url : null);+ } catch {+ finish(null);+ }+ },+ { once: true },+ );+ viewer.addEventListener('error', () => finish(null), { once: true });++ document.body.appendChild(viewer);+ });+}++// Deterministic gradient from a string — same prompt always gets the same colours.+function promptGradient(str) {+ let h = 0;+ for (let i = 0; i < (str || '').length; i++) h = (Math.imul(31, h) + str.charCodeAt(i)) | 0;+ const hue = Math.abs(h) % 360;+ const hue2 = (hue + 40) % 360;+ return `linear-gradient(135deg, hsl(${hue},28%,14%) 0%, hsl(${hue2},22%,10%) 100%)`;+}++function applyGradientFallback(card, prompt) {+ const existing = card.querySelector('.thumb');+ if (existing) existing.remove();+ if (card.querySelector('.thumb.gradient-ph')) return;+ const ph = document.createElement('span');+ ph.className = 'thumb gradient-ph';+ ph.style.background = promptGradient(prompt);+ // Show the prompt text as the visual — makes the card feel intentional, not broken.+ if (prompt) {+ const label = document.createElement('span');+ label.className = 'gradient-ph-text';+ label.textContent = prompt;+ ph.appendChild(label);+ }+ card.prepend(ph);+}++// IntersectionObserver: only attempt GLB capture when the card is actually+// visible — no wasted work on cards the user never scrolls to.+const captureObserver =+ 'IntersectionObserver' in window+ ? new IntersectionObserver(+ (entries) => {+ entries.forEach((e) => {+ if (!e.isIntersecting) return;+ captureObserver.unobserve(e.target);+ const card = e.target;+ const glbUrl = card.dataset.glbUrl;+ if (!glbUrl) return;+ enqueueCaptureFromGlb(card, glbUrl).then((dataUrl) => {+ if (dataUrl) {+ const img = document.createElement('img');+ img.className = 'thumb';+ img.loading = 'lazy';+ img.alt = '';+ img.src = dataUrl;+ img.onerror = () => applyGradientFallback(card, card.title);+ const existing = card.querySelector('.thumb');+ existing ? existing.replaceWith(img) : card.prepend(img);+ } else {+ applyGradientFallback(card, card.title);+ }+ });+ });+ },+ { rootMargin: '200px' },+ )+ : null;+const els = {section: document.getElementById('showcase'),grid: document.getElementById('showcase-grid'),@@ -44,17 +177,30 @@ function buildCard(c) {card.setAttribute('aria-label', `Open in viewer: ${c.prompt || 'forged model'}`);if (c.preview_image_url) {+ // Plan A: stored thumbnailconst img = document.createElement('img');img.className = 'thumb';img.loading = 'lazy';img.alt = '';img.src = c.preview_image_url;+ img.onerror = () => {+ // Plan B: image URL broken → try GLB capture, then gradient+ if (c.glb_url) {+ card.dataset.glbUrl = c.glb_url;+ captureObserver ? captureObserver.observe(card) : applyGradientFallback(card, c.prompt);+ } else {+ applyGradientFallback(card, c.prompt);+ }+ };card.appendChild(img);+ } else if (c.glb_url) {+ // Plan B: no thumbnail yet → gradient placeholder now, GLB capture when visible+ applyGradientFallback(card, c.prompt);+ card.dataset.glbUrl = c.glb_url;+ captureObserver ? captureObserver.observe(card) : undefined;} else {- const ph = document.createElement('span');- ph.className = 'thumb placeholder';- ph.textContent = '◳';- card.appendChild(ph);+ // Plan C: no assets at all → gradient placeholder+ applyGradientFallback(card, c.prompt);}// Engine · tier provenance, same convention as "Your creations".diff --git a/src/forge.js b/src/forge.jsindex 95f814740..442fb7381 100644--- a/src/forge.js+++ b/src/forge.js@@ -1245,6 +1245,27 @@ function showResult(glbUrl, label, meta) {}}+// Deterministic gradient from prompt text — same prompt → same colours.+function promptGradient(str) {+ let h = 0;+ for (let i = 0; i < (str || '').length; i++) h = (Math.imul(31, h) + str.charCodeAt(i)) | 0;+ const hue = Math.abs(h) % 360;+ return `linear-gradient(135deg,hsl(${hue},28%,14%) 0%,hsl(${(hue + 40) % 360},22%,10%) 100%)`;+}++function makeGradientThumb(prompt) {+ const ph = document.createElement('span');+ ph.className = 'thumb gradient-ph';+ ph.style.background = promptGradient(prompt);+ if (prompt) {+ const label = document.createElement('span');+ label.className = 'gradient-ph-text';+ label.textContent = prompt;+ ph.appendChild(label);+ }+ return ph;+}+// Load (or reload) the "Your creations" strip from durable storage.async function loadGallery() {if (!els.creations) return;@@ -1288,12 +1309,13 @@ async function loadGallery() {img.loading = 'lazy';img.alt = '';img.src = c.preview_image_url;+ img.onerror = () => {+ // Thumbnail URL broken — show gradient fallback.+ img.replaceWith(makeGradientThumb(c.prompt));+ };card.appendChild(img);} else {- const ph = document.createElement('span');- ph.className = 'thumb placeholder';- ph.textContent = '◳';- card.appendChild(ph);+ card.appendChild(makeGradientThumb(c.prompt));}if (c.outcome === 'accepted' || c.outcome === 'rejected') {