Skip to content

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.

perf(character-library): load a character's GLB on intent instead of streaming the grid on first paint

nirholas0f62fbba41f3
diff --git a/pages/character-library.html b/pages/character-library.html
index d6284d5b8..51549f572 100644
--- a/pages/character-library.html
+++ b/pages/character-library.html
@@ -105,7 +105,10 @@
position: absolute; inset: 0; display: grid; place-items: center; z-index: 1;
font-size: 30px; color: rgba(255,255,255,.0); transition: color .18s ease; pointer-events: none;
}
- .ch-card-thumb:hover .ch-card-play { color: rgba(255,255,255,.85); }
+ .ch-card-thumb:hover .ch-card-play,
+ .ch-card-thumb:focus-visible .ch-card-play { color: rgba(255,255,255,.85); }
+ /* Once the model is streaming, the play cue has done its job. */
+ .ch-card-thumb.is-live .ch-card-play { display: none; }
.ch-card-body { padding: 12px 13px 13px; display: flex; flex-direction: column; gap: 8px; }
.ch-card-name { font-size: 15px; margin: 0; letter-spacing: -.01em; }
.ch-card-meta { font-size: 12px; color: var(--ink-dim); font-family: var(--font-mono); }
diff --git a/src/character-library.js b/src/character-library.js
index 0fb687b1c..71f2db878 100644
--- a/src/character-library.js
+++ b/src/character-library.js
@@ -67,7 +67,7 @@ function renderCard(a) {
src="${escapeAttr(glbUrl)}"
alt="${escapeAttr(alt)}"
class="ch-card-mv"
- reveal="auto"
+ reveal="manual"
loading="lazy"
disable-zoom
disable-pan
@@ -99,6 +99,60 @@ function renderCard(a) {
return card;
}
+// ── Intent-driven model loading ──────────────────────────────────────────────
+// A library character is a 4-76 MB GLB, so letting every card auto-load streamed
+// hundreds of megabytes nobody had asked for, and any model still in flight when
+// the visitor navigated away logged an aborted fetch in the console. Cards mount
+// with `reveal="manual"`, which paints the poster and downloads nothing; the
+// model streams on real intent only: a hover that settles, or keyboard focus
+// that settles. Tabbing or sweeping the pointer across the grid therefore costs
+// nothing, and a touch visitor taps straight through to the full viewer instead
+// of paying for a preview on cellular.
+const REVEAL_DWELL_MS = 180;
+let pendingReveal = null;
+
+function revealModel(thumb) {
+ if (!thumb || thumb.dataset.revealed) return;
+ const mv = thumb.querySelector('model-viewer');
+ if (!mv) return;
+ thumb.dataset.revealed = '1';
+ thumb.classList.add('is-live');
+ // whenDefined resolves synchronously once the CDN module has upgraded the
+ // element, and waits for it on a slow connection instead of no-opping.
+ customElements.whenDefined('model-viewer').then(() => mv.dismissPoster?.());
+}
+
+function scheduleReveal(thumb) {
+ if (!thumb || thumb.dataset.revealed) return;
+ cancelReveal();
+ pendingReveal = { thumb, timer: setTimeout(() => revealModel(thumb), REVEAL_DWELL_MS) };
+}
+
+function cancelReveal(thumb) {
+ if (!pendingReveal) return;
+ if (thumb && pendingReveal.thumb !== thumb) return;
+ clearTimeout(pendingReveal.timer);
+ pendingReveal = null;
+}
+
+function wireReveal() {
+ if (!els.grid) return;
+ els.grid.addEventListener('pointerover', (e) => {
+ // Touch fires pointerover just before the tap navigates to the viewer, so
+ // starting a download there would be pure waste. Honour Data Saver too.
+ if (e.pointerType === 'touch' || navigator.connection?.saveData) return;
+ scheduleReveal(e.target.closest?.('.ch-card-thumb'));
+ });
+ els.grid.addEventListener('pointerout', (e) => {
+ const thumb = e.target.closest?.('.ch-card-thumb');
+ // pointerout also fires moving between a card's own children; only a
+ // pointer that actually left the card cancels the pending reveal.
+ if (thumb && !thumb.contains(e.relatedTarget)) cancelReveal(thumb);
+ });
+ els.grid.addEventListener('focusin', (e) => scheduleReveal(e.target.closest?.('.ch-card-thumb')));
+ els.grid.addEventListener('focusout', (e) => cancelReveal(e.target.closest?.('.ch-card-thumb')));
+}
+
function applyView() {
const q = state.query.trim().toLowerCase();
let list = state.all;
@@ -137,6 +191,9 @@ function applyView() {
const frag = document.createDocumentFragment();
for (const a of list) frag.appendChild(renderCard(a));
+ // A reveal armed against a card this render is about to drop would fire on a
+ // detached element.
+ cancelReveal();
els.grid.replaceChildren(frag);
show(els.loading, false);
@@ -206,4 +263,5 @@ function wire() {
}
wire();
+wireReveal();
load();