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
fix(tour): harden guided tour, free-roam, and avatar loader
nirholaseb66437cb1a2
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex be8a2404d..daa8ae578 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -56,6 +56,7 @@ Public history for [three.ws](https://three.ws), newest first. New pages come fr- **Game-Ready export is now a $THREE perk — hold, or pay per export** — Turning a generated or uploaded model into a clean, engine-ready asset — one-click retopology to a poly budget with a PBR texture re-bake, delivered as a GLB plus an FBX for Unity and Unreal — is now a $THREE benefit. Hold $THREE and every Game-Ready export is free; if you don't hold, pay once per export in $THREE without leaving the result view, then the export runs immediately. Text→3D generation at Draft and Standard stays free for everyone. The export runs real GPU retopology on our remesh service, so holders fund it by holding rather than us metering everyone — the same hold-or-pay model already used for High-quality generation. (`/forge`) `[feature]`- **Grind an agent's vanity wallet right on its page — with your CPU cores** — Giving an agent a custom wallet address used to run on our servers, so it was capped at short patterns and would time out and error on anything harder. Now the agent's Wallet → Vanity tab grinds the address in your own browser, exactly like the standalone /vanity-wallet tool: choose how many CPU cores to spend, match case-insensitively for a faster find, watch the live tries-per-second and ETA, and pause or resume anytime. Longer, rarer patterns are now possible with no timeouts. When a match is found, any SOL or tokens in the old wallet are still automatically swept to the new address before the key is swapped — funds are never stranded — and the server verifies the new address truly matches your pattern before storing it. `[fix, feature, improvement]`- **Guided Tour: no longer stops dead on full-screen pages** — The 3D guide that walks you through the platform would vanish the moment the tour stepped onto one of the immersive, full-screen pages — Selfie to Avatar, Scan, the Club and others — because those pages skip the shared top nav that used to start the tour. The tour's start logic now loads on every page, so the guide keeps walking, pointing, and narrating across the whole site without ever stranding you mid-tour. (`/tour`) `[fix]`+- **Guided Tour: smoother, more reliable, more accessible** — A pass over the 3D guided tour fixed a handful of rough edges. If a narration clip failed to load, the tour used to skip straight past that stop with no audio and no time to read the caption — now it paces the caption just like it does when audio is muted. In free roam, a movement key still held when you rejoined the tour could leave the guide drifting on its own; that's fixed. The spotlight ring now recovers if the thing it's highlighting briefly disappears and comes back, instead of going dark for the rest of the stop. Restarting from the 'Walk it again' button now cleanly rebuilds the tour, and the chapter menu keeps keyboard focus inside the panel so it no longer wanders behind the overlay. (`/tour`) `[fix, improvement]`- **Hardened on-chain confirmations and faster profile loads** — Two reliability fixes for everyone trading, launching, and browsing. First: every on-chain action that moves funds — coin launches, buys and sells, buybacks, payouts, transfers — now treats a transaction that lands but reverts as a real failure instead of quietly reporting success. You'll see an accurate error and your spending limit won't be charged for a trade that didn't go through. Second: public profile and creator pages are now cacheable at the edge, so they load noticeably faster under load. No action needed — these apply automatically. `[fix, security, improvement]`- **Imported avatars now animate with correct arm and leg orientation** — Animations are authored on one reference rig and retargeted onto whatever avatar you bring — Mixamo, Ready Player Me, VRoid, and more. We found that limbs on those rigs could play roughly 30° off from where they should be, because the retarget replayed each joint's motion in the wrong frame when a rig's rest pose differed from ours. The retarget now preserves each joint's true world-space motion, so idle, walk, and every other clip drive a foreign rig's arms and legs the way they were animated. Avatars matching the reference rig are byte-for-byte unchanged. `[fix, improvement]`- **Launch-and-snipe: atomic dev buy at token launch** — Atomic pump.fun launches can now include a first buy in the very same transaction that creates the token. The creator's buy lands in the same block as the mint — inside one Jito bundle — so no external sniper can wedge in ahead of the floor. Set a buy size and slippage; the funder covers it on top of rent, and the same spend caps apply. `[feature]`diff --git a/data/changelog.json b/data/changelog.jsonindex 9ef59e48b..97dff6a50 100644--- a/data/changelog.json+++ b/data/changelog.json@@ -1,6 +1,13 @@{"$comment": "Curated changelog entries for three.ws — the editorial layer of the public changelog. New PAGE launches are tracked automatically via the `added` field in data/pages.json; this file is for everything else holders care about: improvements, fixes, SDK releases, trading/payments capabilities, security work. scripts/build-page-index.mjs merges both sources into CHANGELOG.md, public/changelog.json, and public/changelog.xml. Newest first. Allowed tags: feature, improvement, fix, sdk, infra, docs, security. `link` is optional and must be a live three.ws path.","entries": [+ {+ "date": "2026-06-21",+ "title": "Guided Tour: smoother, more reliable, more accessible",+ "summary": "A pass over the 3D guided tour fixed a handful of rough edges. If a narration clip failed to load, the tour used to skip straight past that stop with no audio and no time to read the caption — now it paces the caption just like it does when audio is muted. In free roam, a movement key still held when you rejoined the tour could leave the guide drifting on its own; that's fixed. The spotlight ring now recovers if the thing it's highlighting briefly disappears and comes back, instead of going dark for the rest of the stop. Restarting from the 'Walk it again' button now cleanly rebuilds the tour, and the chapter menu keeps keyboard focus inside the panel so it no longer wanders behind the overlay.",+ "tags": ["fix", "improvement"],+ "link": "/tour"+ },{"date": "2026-06-21","title": "x402 comes to VS Code",diff --git a/public/changelog.json b/public/changelog.jsonindex bda704009..63b13f956 100644--- a/public/changelog.json+++ b/public/changelog.json@@ -1,5 +1,5 @@{- "generated_at": "2026-06-21T19:17:43.937Z",+ "generated_at": "2026-06-21T20:51:46.382Z","generated_by": "scripts/build-page-index.mjs from data/pages.json + data/changelog.json","site": {"name": "three.ws",@@ -524,6 +524,17 @@"fix"]},+ {+ "date": "2026-06-21",+ "type": "update",+ "title": "Guided Tour: smoother, more reliable, more accessible",+ "summary": "A pass over the 3D guided tour fixed a handful of rough edges. If a narration clip failed to load, the tour used to skip straight past that stop with no audio and no time to read the caption — now it paces the caption just like it does when audio is muted. In free roam, a movement key still held when you rejoined the tour could leave the guide drifting on its own; that's fixed. The spotlight ring now recovers if the thing it's highlighting briefly disappears and comes back, instead of going dark for the rest of the stop. Restarting from the 'Walk it again' button now cleanly rebuilds the tour, and the chapter menu keeps keyboard focus inside the panel so it no longer wanders behind the overlay.",+ "link": "/tour",+ "tags": [+ "fix",+ "improvement"+ ]+ },{"date": "2026-06-21","type": "update",diff --git a/public/changelog.xml b/public/changelog.xmlindex b28a8864a..fb015da89 100644--- a/public/changelog.xml+++ b/public/changelog.xml@@ -406,6 +406,14 @@<category>fix</category><description>The 3D guide that walks you through the platform would vanish the moment the tour stepped onto one of the immersive, full-screen pages — Selfie to Avatar, Scan, the Club and others — because those pages skip the shared top nav that used to start the tour. The tour's start logic now loads on every page, so the guide keeps walking, pointing, and narrating across the whole site without ever stranding you mid-tour.</description></item>+ <item>+ <title>Guided Tour: smoother, more reliable, more accessible</title>+ <link>https://three.ws/tour</link>+ <guid isPermaLink="false">2026-06-21:Guided Tour: smoother, more reliable, more accessible</guid>+ <pubDate>Sun, 21 Jun 2026 12:00:00 GMT</pubDate>+ <category>fix</category>+ <description>A pass over the 3D guided tour fixed a handful of rough edges. If a narration clip failed to load, the tour used to skip straight past that stop with no audio and no time to read the caption — now it paces the caption just like it does when audio is muted. In free roam, a movement key still held when you rejoined the tour could leave the guide drifting on its own; that's fixed. The spotlight ring now recovers if the thing it's highlighting briefly disappears and comes back, instead of going dark for the rest of the stop. Restarting from the 'Walk it again' button now cleanly rebuilds the tour, and the chapter menu keeps keyboard focus inside the panel so it no longer wanders behind the overlay.</description>+ </item><item><title>Hardened on-chain confirmations and faster profile loads</title><link>https://three.ws/changelog</link>diff --git a/public/features.json b/public/features.jsonindex 5a50fc6bd..de2218be2 100644--- a/public/features.json+++ b/public/features.json@@ -1,5 +1,5 @@{- "generated_at": "2026-06-21T19:17:43.919Z",+ "generated_at": "2026-06-21T20:51:46.367Z","generated_by": "scripts/build-page-index.mjs from data/pages.json","site": {"name": "three.ws",diff --git a/src/feature-tour.js b/src/feature-tour.jsindex c61e21404..998a961fd 100644--- a/src/feature-tour.js+++ b/src/feature-tour.js@@ -3,9 +3,10 @@// The tour engine lives in src/feature-tour/. This file is the thin platform// wiring, mirroring src/walk-companion.js: Vite emits it to the stable, unhashed// path /feature-tour.js (see vite.config.js → rollupOptions.output.entryFileNames),-// and public/nav.js injects it with <script type="module"> only when a tour is-// starting or already in progress — so a page that never runs the tour pays no-// Three.js cost. public/nav.js drives it through window.__featureTour.+// and the 'feature-tour-boot' Vite plugin (vite.config.js) injects it with+// <script type="module"> on every page — but only when a tour is starting or+// already in progress — so a page that never runs the tour pays no Three.js cost.+// public/nav.js's "Take the tour" button drives it through window.__featureTour.import { createFeatureTour } from './feature-tour/index.js';diff --git a/src/feature-tour/chapters.js b/src/feature-tour/chapters.jsindex 06cfda27f..b51fd2aa7 100644--- a/src/feature-tour/chapters.js+++ b/src/feature-tour/chapters.js@@ -296,6 +296,33 @@ export class ChapterPanel {e.stopPropagation();e.preventDefault();this.close();+ return;+ }+ // Trap Tab inside the open panel so keyboard focus can't wander behind the+ // modal scrim onto the obscured page. Recomputed each press because the+ // stop list re-renders as the search filters.+ if (e.key === 'Tab') {+ const panel = this.root?.querySelector('.tws-tour-menu__panel');+ if (!panel) return;+ const focusable = Array.from(+ panel.querySelectorAll(+ 'a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])',+ ),+ ).filter((el) => el.offsetParent !== null);+ if (!focusable.length) return;+ const first = focusable[0];+ const last = focusable[focusable.length - 1];+ const active = document.activeElement;+ if (!panel.contains(active)) {+ e.preventDefault();+ first.focus();+ } else if (e.shiftKey && active === first) {+ e.preventDefault();+ last.focus();+ } else if (!e.shiftKey && active === last) {+ e.preventDefault();+ first.focus();+ }}}diff --git a/src/feature-tour/curriculum.js b/src/feature-tour/curriculum.jsindex 0fd88d052..8b58d4a04 100644--- a/src/feature-tour/curriculum.js+++ b/src/feature-tour/curriculum.js@@ -25,7 +25,11 @@ export async function loadCurriculum() {// Normalize a pathname to match curriculum stop paths ("/" stays "/", others// lose any trailing slash). Query and hash are irrelevant to which stop we're on.export function normalizePath(pathname = location.pathname) {- const p = pathname.replace(/\/+$/, '');+ // Strip query/hash first (a caller may hand us a full href) then trailing+ // slashes, so only the route path decides which stop we're on — as the+ // surrounding comments promise.+ const clean = String(pathname).split(/[?#]/)[0];+ const p = clean.replace(/\/+$/, '');return p === '' ? '/' : p;}@@ -130,5 +134,5 @@ export function stopIndexForPath(curriculum, pathname = location.pathname) {}export function sectionTitle(curriculum, id) {- return curriculum.sections.find((s) => s.id === id)?.title || '';+ return (curriculum.sections || []).find((s) => s.id === id)?.title || '';}diff --git a/src/feature-tour/director.js b/src/feature-tour/director.jsindex f42bb7cb4..0eeb00310 100644--- a/src/feature-tour/director.js+++ b/src/feature-tour/director.js@@ -109,7 +109,10 @@ export class TourDirector {this.playlist = buildPlaylist(this.curriculum, this.track);const here = stopIndexForPath(this.curriculum, location.pathname);- const wanted = state.index || 0;+ // Clamp the persisted index to the live curriculum: a curriculum that lost+ // stops between deploys could otherwise point past the end and silently+ // finish the tour on resume.+ const wanted = Math.min(Math.max(0, state.index || 0), this.curriculum.stops.length - 1);if (normalizePath(this.curriculum.stops[wanted]?.path) === normalizePath()) {this.index = wanted; // arrived exactly where we were headingthis.offRoute = false;@@ -313,7 +316,7 @@ export class TourDirector {writeState({ muted: this.muted });this.controls.setMuted(this.muted);this.narrator.cancel();- if (!this.paused) {+ if (!this.paused && !this.roam) {const token = ++this._runToken;this._narrateAndMaybeAdvance(token);}@@ -396,7 +399,7 @@ export class TourDirector {this.controls?.setSpeed(next);this.panel?.setSpeed(next);// Re-narrate the current stop at the new rate if we're actively playing.- if (!this.paused && !this.offRoute && this.mounted) {+ if (!this.paused && !this.offRoute && !this.roam && this.mounted) {const token = ++this._runToken;this._narrateAndMaybeAdvance(token);}@@ -407,7 +410,7 @@ export class TourDirector {this.voice = value;writeState({ voice: value });this.panel?.setVoice(value);- if (!this.paused && !this.offRoute && this.mounted) {+ if (!this.paused && !this.offRoute && !this.roam && this.mounted) {const token = ++this._runToken;this._narrateAndMaybeAdvance(token);}@@ -527,6 +530,7 @@ export class TourDirector {this.avatar.point();const outro = "And that's the whole platform. You've seen how to build an agent, give it a body and a voice, take it on-chain, and put it to work. Go make something — I'll be around if you want to walk it again.";await this._present(outro, token);+ if (token !== this._runToken) return; // exited / navigated while the outro playedmarkCompleted();clearState();this._showCompletion();@@ -551,7 +555,10 @@ export class TourDirector {card.addEventListener('click', (e) => {const act = e.target.closest('[data-act]')?.dataset.act;if (act === 'restart') {- card.remove();+ // Tear the finished tour fully down before starting a fresh one —+ // otherwise _mount()'s `if (this.mounted) return` makes restart a+ // no-op that reuses the old, half-cleared avatar and listeners.+ this.exit();this.start(this.track);} else if (act === 'close') {card.remove();diff --git a/src/feature-tour/free-roam.js b/src/feature-tour/free-roam.jsindex c7277b5ba..26dd5d432 100644--- a/src/feature-tour/free-roam.js+++ b/src/feature-tour/free-roam.js@@ -52,6 +52,7 @@ export class FreeRoam {this.avatar = avatar;this.enabled = false;this.dragging = false;+ this._dragPointerId = null;this._grab = { x: 0, y: 0 };this._ptr = { x: 0, y: 0 };this._scrollRaf = 0;@@ -87,6 +88,10 @@ export class FreeRoam {this.enabled = false;this._endDrag();this._stopWalk();+ // A key still physically held when we disable will never deliver its keyup+ // here (listeners are about to be removed), which would leave that direction+ // stuck on for the next enable — clear the held state now.+ this._keys = { up: false, down: false, left: false, right: false, run: false };document.removeEventListener('pointerdown', this._onDown, true);document.removeEventListener('keydown', this._onKeyDown, true);document.removeEventListener('keyup', this._onKeyUp, true);@@ -106,6 +111,12 @@ export class FreeRoam {this._grab = { x: e.clientX - r.left, y: e.clientY - r.top };this._ptr = { x: e.clientX, y: e.clientY };this.dragging = true;+ this._dragPointerId = e.pointerId;+ try {+ host.setPointerCapture(e.pointerId);+ } catch {+ /* capture unsupported / already released — document listeners still cover it */+ }document.addEventListener('pointermove', this._onMove, true);document.addEventListener('pointerup', this._onUp, true);document.addEventListener('pointercancel', this._onUp, true);@@ -137,6 +148,14 @@ export class FreeRoam {this._scrollRaf = 0;if (!this.dragging) return;this.dragging = false;+ if (this._dragPointerId != null) {+ try {+ this.avatar.host?.releasePointerCapture(this._dragPointerId);+ } catch {+ /* already released */+ }+ this._dragPointerId = null;+ }document.removeEventListener('pointermove', this._onMove, true);document.removeEventListener('pointerup', this._onUp, true);document.removeEventListener('pointercancel', this._onUp, true);@@ -258,7 +277,6 @@ export class FreeRoam {// While dragging near the top/bottom edge, scroll the page and keep the guide// pinned under the pointer so it appears to walk the document up/down._startScrollLoop() {- if (this._reduced) return;const tick = () => {if (!this.dragging) return;const y = this._ptr.y;diff --git a/src/feature-tour/guide-avatar.js b/src/feature-tour/guide-avatar.jsindex c79ef6494..b2d8c3400 100644--- a/src/feature-tour/guide-avatar.js+++ b/src/feature-tour/guide-avatar.js@@ -66,6 +66,8 @@ export class GuideAvatar {this._targetYaw = 0;this._walking = false;this._walkRaf = 0;+ this._walkResolve = null;+ this._bubbleHideTimer = 0;this._reduced = matchMedia('(prefers-reduced-motion: reduce)').matches;this._pos = { x: 0, y: 0 };// Vertical physics state — height above the ground plane and its velocity.@@ -241,6 +243,13 @@ export class GuideAvatar {y: clamp(pos.y, MARGIN, window.innerHeight - CANVAS_H - MARGIN),};// Supersede any walk already in flight so a fresh click redirects the guide.+ // Settle its promise first so an awaiter (approach/park) can never hang+ // forever once we cancel the RAF that would have resolved it.+ if (this._walkResolve) {+ const prev = this._walkResolve;+ this._walkResolve = null;+ prev();+ }cancelAnimationFrame(this._walkRaf);this._walkRaf = 0;const dx = clamped.x - this._pos.x;@@ -258,6 +267,7 @@ export class GuideAvatar {let traveled = 0;let last = performance.now();return new Promise((resolve) => {+ this._walkResolve = resolve;const step = (now) => {const dt = Math.min((now - last) / 1000, 0.05);last = now;@@ -265,6 +275,7 @@ export class GuideAvatar {this.place({ x: from.x + ux * traveled, y: from.y + uy * traveled });if (traveled >= dist) {this._walkRaf = 0;+ this._walkResolve = null;this.settle();resolve();return;@@ -362,14 +373,16 @@ export class GuideAvatar {// ── Speech bubble ─────────────────────────────────────────────────────────say(text) {if (!this.bubble) return;+ clearTimeout(this._bubbleHideTimer);this.bubble.textContent = text;this.bubble.hidden = false;- requestAnimationFrame(() => this.bubble.classList.add('is-in'));+ requestAnimationFrame(() => this.bubble?.classList.add('is-in'));}hideBubble() {if (!this.bubble) return;this.bubble.classList.remove('is-in');- setTimeout(() => {+ clearTimeout(this._bubbleHideTimer);+ this._bubbleHideTimer = setTimeout(() => {if (this.bubble) this.bubble.hidden = true;}, 280);}@@ -411,8 +424,15 @@ export class GuideAvatar {cancelAnimationFrame(this._raf);cancelAnimationFrame(this._walkRaf);clearTimeout(this._settleTimer);+ clearTimeout(this._bubbleHideTimer);this._raf = 0;this._walkRaf = 0;+ // Settle any awaiter blocked on an in-flight walk so it can't hang past teardown.+ if (this._walkResolve) {+ const prev = this._walkResolve;+ this._walkResolve = null;+ prev();+ }try {this.controller?.dispose();} catch {@@ -429,6 +449,7 @@ export class GuideAvatar {}this.host?.remove();this.host = null;+ this.bubble = null;}}diff --git a/src/feature-tour/narrator.js b/src/feature-tour/narrator.jsindex 6debe03b6..290630025 100644--- a/src/feature-tour/narrator.js+++ b/src/feature-tour/narrator.js@@ -127,19 +127,23 @@ export class Narrator {// that works on whichever lane answered. (1× leaves audio untouched.)audio.playbackRate = rate;this.audio = audio;- const blocked = await new Promise((resolve) => {+ const outcome = await new Promise((resolve) => {let done = false;- const finish = (wasBlocked) => {+ const finish = (state) => {if (done) return;done = true;- audio.removeEventListener('ended', onEnd);- audio.removeEventListener('error', onEnd);- resolve(!!wasBlocked);+ audio.removeEventListener('ended', onEnded);+ audio.removeEventListener('error', onError);+ resolve(state);};- const onEnd = () => finish(false);- this._finishCurrent = () => finish(false);- audio.addEventListener('ended', onEnd);- audio.addEventListener('error', onEnd);+ const onEnded = () => finish('ended');+ // A media error (corrupt/expired blob, decode failure) must NOT be treated+ // like a clean 'ended' — that resolves instantly and races the tour past this+ // stop with no audio AND no reading time. Pace it like an autoplay-blocked clip.+ const onError = () => finish('error');+ this._finishCurrent = () => finish('ended');+ audio.addEventListener('ended', onEnded);+ audio.addEventListener('error', onError);audio.play().then(() => {this._blocked = false;@@ -155,14 +159,15 @@ export class Narrator {} catch {/* hook must never break narration */}- finish(true);+ finish('blocked');} else {- finish(false);+ // play() rejected for some other reason — pace, don't race.+ finish('error');}},);});- if (blocked && token === this._token) {+ if ((outcome === 'blocked' || outcome === 'error') && token === this._token) {await this._sleep(this.estimateMs(clean, rate), token);}} catch {diff --git a/src/feature-tour/spotlight.js b/src/feature-tour/spotlight.jsindex 122897f33..12448e453 100644--- a/src/feature-tour/spotlight.js+++ b/src/feature-tour/spotlight.js@@ -41,12 +41,17 @@ export class Spotlight {// Highlight an element. Pass null to fade the spotlight out (whole-page stop).async highlight(el) {this.target = el || null;+ if (!this.el) return; // disposedif (!el) {this.el.classList.remove('is-in');this._rect = null;return;}await scrollIntoViewIfNeeded(el);+ // The tour may have torn us down, or advanced to another target, during the+ // ~480ms smooth-scroll settle. Bail so we don't resurrect a RAF loop on a+ // removed overlay or fight the newer highlight.+ if (!this.el || this.target !== el) return;this._track();this.el.classList.add('is-in');if (!this._raf) this._raf = requestAnimationFrame(this._track);@@ -54,10 +59,21 @@ export class Spotlight {_track() {this._raf = 0;+ if (!this.el) return; // disposedconst el = this.target;- if (!el || !el.isConnected) {+ if (!el) {+ // Intentionally cleared (whole-page stop) — stop tracking.+ this.el.classList.remove('is-in');+ this._rect = null;+ return;+ }+ if (!el.isConnected) {+ // Target transiently detached (route re-render / virtualized list). Hide+ // the ring but keep watching, so it recovers the instant the node+ // reattaches instead of dying for the rest of this stop.this.el.classList.remove('is-in');this._rect = null;+ this._raf = requestAnimationFrame(this._track);return;}const r = el.getBoundingClientRect();@@ -93,7 +109,11 @@ export class Spotlight {dispose() {cancelAnimationFrame(this._raf);+ this._raf = 0;this.el?.remove();+ this.el = null;+ this.target = null;+ this._rect = null;}}diff --git a/walk-sdk/src/internal/load-avatar.js b/walk-sdk/src/internal/load-avatar.jsindex 26875f38e..8b0882387 100644--- a/walk-sdk/src/internal/load-avatar.js+++ b/walk-sdk/src/internal/load-avatar.js@@ -77,20 +77,42 @@ export async function loadWalkAvatar(entry, opts = {}) {});let controller;- if (active.rig === 'shared') {- controller = await buildSharedController(model, active.clips || DEFAULT_SHARED_CLIPS, {- manifestUrl,- waveMs,- });- } else {- controller = makeEmbeddedController(model, gltf.animations || [], active.clips || {}, {- waveMs,- });+ try {+ if (active.rig === 'shared') {+ controller = await buildSharedController(model, active.clips || DEFAULT_SHARED_CLIPS, {+ manifestUrl,+ waveMs,+ });+ } else {+ controller = makeEmbeddedController(model, gltf.animations || [], active.clips || {}, {+ waveMs,+ });+ }+ } catch (err) {+ // Controller build failed after the GLB parsed — free the scene's GPU+ // resources so a failed avatar load doesn't leak meshes/textures.+ disposeModel(model);+ throw err;}return { model, controller, gltf, entry: active };}+// Release a parsed GLB scene's GPU resources (geometries, materials, textures)+// when a load is abandoned mid-way so a failed avatar build leaks nothing.+function disposeModel(model) {+ model.traverse((n) => {+ if (!n.isMesh) return;+ n.geometry?.dispose?.();+ const mats = Array.isArray(n.material) ? n.material : [n.material];+ for (const m of mats) {+ if (!m) continue;+ for (const v of Object.values(m)) if (v && v.isTexture) v.dispose();+ m.dispose?.();+ }+ });+}+// ── Embedded-clip controller (rig: 'embedded') ───────────────────────────────function makeEmbeddedController(root, clips, overrides, { waveMs }) {const mixer = new AnimationMixer(root);@@ -193,25 +215,32 @@ async function buildSharedController(model, clips, { manifestUrl, waveMs }) {const manager = new AnimationManager();manager.attach(model);- const manifest = await fetch(manifestUrl, { cache: 'force-cache' }).then((r) => {- if (!r.ok) throw new Error(`HTTP ${r.status} fetching animation manifest`);- return r.json();- });- const available = new Set(manifest.map((d) => d.name));-- // Resolve each requested clip to one that actually exists; unknown names fall- // back to idle so the controller never asks the manager for a missing clip.const resolved = {};- for (const [state, name] of Object.entries({ ...DEFAULT_SHARED_CLIPS, ...clips })) {- resolved[state] = available.has(name) ? name : null;- }- resolved.idle = resolved.idle || (available.has('idle') ? 'idle' : null);- if (!resolved.idle) throw new Error('animation manifest missing an idle clip');- for (const k of Object.keys(resolved)) if (!resolved[k]) resolved[k] = resolved.idle;+ try {+ const manifest = await fetch(manifestUrl, { cache: 'force-cache' }).then((r) => {+ if (!r.ok) throw new Error(`HTTP ${r.status} fetching animation manifest`);+ return r.json();+ });+ const available = new Set(manifest.map((d) => d.name));++ // Resolve each requested clip to one that actually exists; unknown names fall+ // back to idle so the controller never asks the manager for a missing clip.+ for (const [state, name] of Object.entries({ ...DEFAULT_SHARED_CLIPS, ...clips })) {+ resolved[state] = available.has(name) ? name : null;+ }+ resolved.idle = resolved.idle || (available.has('idle') ? 'idle' : null);+ if (!resolved.idle) throw new Error('animation manifest missing an idle clip');+ for (const k of Object.keys(resolved)) if (!resolved[k]) resolved[k] = resolved.idle;- const wanted = new Set(Object.values(resolved));- manager.setAnimationDefs(manifest.filter((d) => wanted.has(d.name)));- await manager.loadAll();+ const wanted = new Set(Object.values(resolved));+ manager.setAnimationDefs(manifest.filter((d) => wanted.has(d.name)));+ await manager.loadAll();+ } catch (err) {+ // The GLB loaded but the animation manifest/clips didn't — release the+ // AnimationManager's mixer/retarget state instead of leaking it.+ manager.dispose();+ throw err;+ }let base = 'idle';let waveTimer = null;