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.

Add avatar picker bottom-sheet to /irl and /xr

nirholasad57764dd041
diff --git a/data/changelog.json b/data/changelog.json
index 9ea1a87ab..be0f9efe1 100644
--- a/data/changelog.json
+++ b/data/changelog.json
@@ -1,6 +1,27 @@
{
"$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-16",
+ "title": "Oracle Proof ✓ tab — gallery of verified high-conviction wins",
+ "summary": "New Proof ✓ tab on the Oracle page shows every coin that the Oracle called strong or prime and that subsequently delivered — graduated to Raydium or hit ≥2× ATH. Each card shows the conviction score at call time, the four pillar breakdown, and the outcome ATH multiple. Filterable by tier and time window (7d / 30d / 90d). This is the edge made visible: every number is ground-truth, on-chain verifiable.",
+ "tags": ["feature"],
+ "link": "/oracle"
+ },
+ {
+ "date": "2026-06-16",
+ "title": "Oracle wallet drawer: trader profile and copy-trades links",
+ "summary": "When you open a wallet from the Oracle's Top Wallets leaderboard, the drawer now shows 'Trader profile ↗' and 'Copy trades →' links below the track record — connecting the wallet reputation system directly to copy trading. The wallet list rows also gain a hover-reveal '→' button that opens the trader profile without needing to open the drawer first.",
+ "tags": ["improvement"],
+ "link": "/oracle"
+ },
+ {
+ "date": "2026-06-16",
+ "title": "IRL and XR: choose any of your 3D avatars from a bottom-sheet picker",
+ "summary": "Both /irl and /xr now let you swap your 3D avatar without leaving the page. Tap Avatar (IRL) or Change (XR) to open a thumbnail grid of all your uploaded avatars. Selecting one hot-swaps the model in the scene instantly — camera, animations, half-body mode, and AR state all carry over. Signed-out users see a prompt to sign in; empty accounts link to the creation flow.",
+ "tags": ["feature"],
+ "link": "/irl"
+ },
{
"date": "2026-06-16",
"title": "Watchlist: live Oracle conviction badges on every watched coin",
diff --git a/pages/irl.html b/pages/irl.html
index 046bf6066..ae702c824 100644
--- a/pages/irl.html
+++ b/pages/irl.html
@@ -494,6 +494,10 @@
</button>
<div class="irl-secondary-row">
+ <button class="irl-pill-btn" id="irl-avatar-btn" type="button" aria-label="Change avatar">
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="8" r="4"/><path d="M4 20c0-4 3.582-7 8-7s8 3 8 7"/></svg>
+ Avatar
+ </button>
<button class="irl-pill-btn" id="irl-place-btn" type="button" aria-pressed="false">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>
Add object
diff --git a/pages/xr.html b/pages/xr.html
index 5863f5b60..90925309b 100644
--- a/pages/xr.html
+++ b/pages/xr.html
@@ -178,9 +178,16 @@
font-size: 14px; font-weight: 600; color: var(--text);
letter-spacing: -0.01em;
}
- .xr-avatar-sub {
- font-size: 12px; color: var(--text-2); margin-left: auto;
+ .xr-change-btn {
+ margin-left: auto;
+ background: rgba(61,193,255,0.1); border: 1px solid rgba(61,193,255,0.28);
+ color: var(--accent); border-radius: 999px;
+ font: inherit; font-size: 12px; font-weight: 600;
+ padding: 4px 12px; cursor: pointer;
+ transition: background 0.15s, border-color 0.15s;
+ white-space: nowrap;
}
+ .xr-change-btn:hover { background: rgba(61,193,255,0.18); border-color: rgba(61,193,255,0.5); }
/* Body toggle */
.xr-toggle {
@@ -366,7 +373,7 @@
</svg>
</div>
<span id="xr-avatar-label">Your Avatar</span>
- <span class="xr-avatar-sub">3D agent</span>
+ <button id="xr-change-avatar" type="button" class="xr-change-btn" aria-label="Change avatar">Change</button>
</div>
<div id="xr-body-toggle" class="xr-toggle">
diff --git a/src/avatar-picker.js b/src/avatar-picker.js
new file mode 100644
index 000000000..ed23bdbb0
--- /dev/null
+++ b/src/avatar-picker.js
@@ -0,0 +1,278 @@
+// Shared avatar-picker bottom sheet for /xr and /irl.
+// Usage:
+// import { createAvatarPicker } from './avatar-picker.js';
+// const picker = createAvatarPicker({ onSelect: ({ id, url, name }) => { ... } });
+// picker.open(currentAvatarId);
+
+const DEFAULT_AVATAR = {
+ id: null,
+ url: '/avatars/default.glb',
+ name: 'Default',
+ thumbnailUrl: null,
+};
+
+const CSS = `
+.avp-overlay {
+ position: fixed; inset: 0; z-index: 200;
+ background: rgba(0,0,0,0.72);
+ backdrop-filter: blur(6px);
+ -webkit-backdrop-filter: blur(6px);
+ display: flex; align-items: flex-end;
+ opacity: 0; transition: opacity 0.22s ease;
+ touch-action: none;
+}
+.avp-overlay.is-open { opacity: 1; }
+.avp-sheet {
+ width: 100%; max-height: 72vh;
+ background: #0d0e14;
+ border-top: 1px solid rgba(255,255,255,0.08);
+ border-radius: 20px 20px 0 0;
+ display: flex; flex-direction: column;
+ transform: translateY(100%);
+ transition: transform 0.28s cubic-bezier(0.32,0.72,0,1);
+ overflow: hidden;
+}
+.avp-overlay.is-open .avp-sheet { transform: translateY(0); }
+.avp-header {
+ display: flex; align-items: center; justify-content: space-between;
+ padding: 20px 20px 0;
+ flex-shrink: 0;
+}
+.avp-title {
+ font-size: 16px; font-weight: 700; letter-spacing: -0.02em;
+ color: #f0f1f5;
+}
+.avp-close {
+ width: 32px; height: 32px;
+ background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
+ border-radius: 50%; cursor: pointer;
+ display: flex; align-items: center; justify-content: center;
+ color: #7a7d8c; transition: background 0.15s, color 0.15s;
+}
+.avp-close:hover { background: rgba(255,255,255,0.1); color: #f0f1f5; }
+.avp-close svg { display: block; }
+.avp-body {
+ flex: 1; overflow-y: auto; padding: 16px 16px calc(env(safe-area-inset-bottom,0px) + 24px);
+ -webkit-overflow-scrolling: touch;
+}
+.avp-grid {
+ display: grid;
+ grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
+ gap: 10px;
+}
+.avp-card {
+ background: rgba(255,255,255,0.04);
+ border: 1.5px solid rgba(255,255,255,0.08);
+ border-radius: 14px; overflow: hidden;
+ cursor: pointer; transition: border-color 0.15s, background 0.15s, transform 0.1s;
+ -webkit-tap-highlight-color: transparent;
+}
+.avp-card:hover { background: rgba(255,255,255,0.07); border-color: rgba(255,255,255,0.18); }
+.avp-card:active { transform: scale(0.96); }
+.avp-card.is-active {
+ border-color: #3dc1ff;
+ background: rgba(61,193,255,0.08);
+ box-shadow: 0 0 0 1px rgba(61,193,255,0.3);
+}
+.avp-thumb {
+ width: 100%; aspect-ratio: 1;
+ background: #111318;
+ display: flex; align-items: center; justify-content: center;
+ overflow: hidden;
+}
+.avp-thumb img {
+ width: 100%; height: 100%; object-fit: cover;
+ display: block;
+}
+.avp-thumb-placeholder {
+ width: 38px; height: 38px;
+ color: rgba(255,255,255,0.18);
+}
+.avp-label {
+ padding: 6px 8px 8px;
+ font-size: 12px; font-weight: 600; line-height: 1.3;
+ color: #c8cadb;
+ white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
+}
+.avp-card.is-active .avp-label { color: #3dc1ff; }
+
+/* skeleton */
+.avp-skel { background: rgba(255,255,255,0.05); border-radius: 14px; }
+.avp-skel-thumb { width: 100%; aspect-ratio: 1; background: rgba(255,255,255,0.05); border-radius: 14px 14px 0 0; animation: avp-pulse 1.5s ease-in-out infinite; }
+.avp-skel-label { height: 28px; margin: 6px 8px 8px; background: rgba(255,255,255,0.05); border-radius: 6px; animation: avp-pulse 1.5s ease-in-out 0.15s infinite; }
+@keyframes avp-pulse { 0%,100%{opacity:1} 50%{opacity:0.45} }
+
+/* empty / error states */
+.avp-state {
+ padding: 40px 20px;
+ text-align: center;
+ color: #7a7d8c;
+ font-size: 14px; line-height: 1.55;
+}
+.avp-state a { color: #3dc1ff; text-decoration: none; }
+.avp-state a:hover { text-decoration: underline; }
+.avp-state-icon { font-size: 32px; margin-bottom: 10px; }
+`;
+
+function injectStyles() {
+ if (document.getElementById('avp-styles')) return;
+ const el = document.createElement('style');
+ el.id = 'avp-styles';
+ el.textContent = CSS;
+ document.head.appendChild(el);
+}
+
+function thumbPlaceholderSvg() {
+ return `<svg class="avp-thumb-placeholder" viewBox="0 0 38 38" fill="none" xmlns="http://www.w3.org/2000/svg">
+ <circle cx="19" cy="12" r="6" stroke="currentColor" stroke-width="1.6"/>
+ <path d="M5 34c0-7.732 6.268-14 14-14s14 6.268 14 14" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/>
+ </svg>`;
+}
+
+export function createAvatarPicker({ onSelect } = {}) {
+ injectStyles();
+
+ // ── Build DOM ──────────────────────────────────────────────────────────
+ const overlay = document.createElement('div');
+ overlay.className = 'avp-overlay';
+ overlay.setAttribute('role', 'dialog');
+ overlay.setAttribute('aria-modal', 'true');
+ overlay.setAttribute('aria-label', 'Select avatar');
+ overlay.innerHTML = `
+ <div class="avp-sheet">
+ <div class="avp-header">
+ <div class="avp-title">Your Avatars</div>
+ <button class="avp-close" aria-label="Close" type="button">
+ <svg width="14" height="14" viewBox="0 0 14 14" fill="none">
+ <path d="M1 1l12 12M13 1L1 13" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
+ </svg>
+ </button>
+ </div>
+ <div class="avp-body">
+ <div class="avp-grid" id="avp-grid"></div>
+ </div>
+ </div>`;
+
+ const sheet = overlay.querySelector('.avp-sheet');
+ const closeBtn = overlay.querySelector('.avp-close');
+ const grid = overlay.querySelector('#avp-grid');
+
+ // ── State ──────────────────────────────────────────────────────────────
+ let currentId = null;
+ let avatarCache = null; // null = not yet loaded
+ let isOpen = false;
+
+ // ── Close logic ───────────────────────────────────────────────────────
+ function close() {
+ if (!isOpen) return;
+ isOpen = false;
+ overlay.classList.remove('is-open');
+ overlay.addEventListener('transitionend', () => {
+ if (!isOpen) overlay.remove();
+ }, { once: true });
+ }
+
+ closeBtn.addEventListener('click', close);
+ overlay.addEventListener('click', (e) => { if (e.target === overlay) close(); });
+ document.addEventListener('keydown', (e) => { if (e.key === 'Escape' && isOpen) close(); });
+
+ // Prevent sheet clicks from bubbling to the overlay (would trigger close)
+ sheet.addEventListener('click', (e) => e.stopPropagation());
+
+ // ── Render ─────────────────────────────────────────────────────────────
+ function renderSkeletons(n = 6) {
+ grid.innerHTML = Array.from({ length: n }, () => `
+ <div class="avp-skel">
+ <div class="avp-skel-thumb"></div>
+ <div class="avp-skel-label"></div>
+ </div>`).join('');
+ }
+
+ function renderAvatars(avatars) {
+ const all = [DEFAULT_AVATAR, ...avatars];
+ grid.innerHTML = '';
+ for (const av of all) {
+ const card = document.createElement('div');
+ card.className = 'avp-card' + (av.id === currentId ? ' is-active' : '');
+ card.setAttribute('role', 'button');
+ card.setAttribute('tabindex', '0');
+ card.setAttribute('aria-label', av.name);
+ card.innerHTML = `
+ <div class="avp-thumb">
+ ${av.thumbnailUrl
+ ? `<img src="${av.thumbnailUrl}" alt="${av.name}" loading="lazy">`
+ : thumbPlaceholderSvg()}
+ </div>
+ <div class="avp-label">${av.name}</div>`;
+
+ card.addEventListener('click', () => {
+ grid.querySelectorAll('.avp-card').forEach(c => c.classList.remove('is-active'));
+ card.classList.add('is-active');
+ currentId = av.id;
+ onSelect?.({ id: av.id, url: av.url, name: av.name });
+ close();
+ });
+ card.addEventListener('keydown', (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); card.click(); } });
+ grid.appendChild(card);
+ }
+ }
+
+ function renderUnauthed() {
+ grid.innerHTML = `
+ <div class="avp-state" style="grid-column:1/-1">
+ <div class="avp-state-icon">🔒</div>
+ <div>Sign in to use your own avatars.<br><a href="/login?return=${encodeURIComponent(location.pathname + location.search)}">Sign in →</a></div>
+ </div>`;
+ }
+
+ function renderEmpty() {
+ grid.innerHTML = `
+ <div class="avp-state" style="grid-column:1/-1">
+ <div class="avp-state-icon">🧑‍🎨</div>
+ <div>You don't have any avatars yet.<br><a href="/create">Create your first →</a></div>
+ </div>`;
+ }
+
+ function renderError() {
+ grid.innerHTML = `
+ <div class="avp-state" style="grid-column:1/-1">
+ <div class="avp-state-icon">⚠️</div>
+ <div>Couldn't load avatars. Check your connection and try again.</div>
+ </div>`;
+ }
+
+ // ── Fetch ──────────────────────────────────────────────────────────────
+ async function loadAvatars() {
+ if (avatarCache) { renderAvatars(avatarCache); return; }
+ renderSkeletons();
+ try {
+ const res = await fetch('/api/avatars?limit=50', { credentials: 'include' });
+ if (res.status === 401) { renderUnauthed(); return; }
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
+ const { avatars = [] } = await res.json();
+ avatarCache = avatars.map(av => ({
+ id: av.id,
+ url: av.url || av.model_url || `/api/avatars/${av.id}/glb`,
+ name: av.name || 'Untitled',
+ thumbnailUrl: av.thumbnail_url || null,
+ }));
+ if (!avatarCache.length) { renderEmpty(); return; }
+ renderAvatars(avatarCache);
+ } catch {
+ renderError();
+ }
+ }
+
+ // ── Open ───────────────────────────────────────────────────────────────
+ function open(activeId) {
+ currentId = activeId ?? null;
+ document.body.appendChild(overlay);
+ // Force a reflow so the transition fires
+ overlay.getBoundingClientRect();
+ overlay.classList.add('is-open');
+ isOpen = true;
+ loadAvatars();
+ }
+
+ return { open, close };
+}
diff --git a/src/irl.js b/src/irl.js
index 774ef3aaa..497568381 100644
--- a/src/irl.js
+++ b/src/irl.js
@@ -36,6 +36,7 @@ import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';
import nipplejs from 'nipplejs';
import { AnimationManager } from './animation-manager.js';
import { log } from './shared/log.js';
+import { createAvatarPicker } from './avatar-picker.js';
const AVATAR_URL_DEFAULT = '/avatars/default.glb';
const ANIMATIONS_MANIFEST_URL = '/animations/manifest.json';
@@ -78,11 +79,12 @@ const subtitleEl = $('irl-subtitle');
const statusEl = $('irl-status');
const statusTxt = $('irl-status-text');
const spinner = $('irl-spinner');
-const cameraBtn = $('irl-camera-btn');
-const cameraLabel = $('irl-camera-label');
-const placeBtn = $('irl-place-btn');
-const clearBtn = $('irl-clear-btn');
-const pickerEl = $('irl-picker');
+const cameraBtn = $('irl-camera-btn');
+const cameraLabel = $('irl-camera-label');
+const placeBtn = $('irl-place-btn');
+const clearBtn = $('irl-clear-btn');
+const pickerEl = $('irl-picker');
+const avatarBtn = $('irl-avatar-btn');
// ── Status helpers ────────────────────────────────────────────────────────
function setStatus(msg, { error = false, loading = false, sticky = false } = {}) {
@@ -482,19 +484,30 @@ window.addEventListener('keyup', e => {
// ── Avatar loading ────────────────────────────────────────────────────────
const animMgr = new AnimationManager();
let avatar = null, avatarYaw = 0, avatarLean = 0, currentMotion = 'idle';
+let _currentAvatarId = null;
-async function loadAvatar() {
- // If we have an ID, fetch metadata first to get the name for the bottom panel.
- let avatarName = 'Your Avatar';
- let glbUrl = resolveAvatarUrl(avatarIdParam);
+function _clearAvatar() {
+ if (avatar) {
+ avatarRig.remove(avatar);
+ avatar = null;
+ }
+ animMgr.detach();
+}
+
+async function loadAvatar(idOrUrl, nameOverride) {
+ // Resolve id/url — accepts: null (default), a UUID (look up), a direct URL
+ const id = idOrUrl !== undefined ? idOrUrl : avatarIdParam;
+ let avatarName = nameOverride || 'Your Avatar';
+ let glbUrl = resolveAvatarUrl(typeof idOrUrl === 'string' && /^https?:\/\/|^\//.test(idOrUrl) ? idOrUrl : id);
- if (avatarIdParam && !/^https?:\/\//.test(avatarIdParam) && !avatarIdParam.startsWith('/')) {
+ // Fetch metadata only when id is a DB UUID (not already a URL)
+ if (id && !/^https?:\/\//.test(id) && !id.startsWith('/')) {
try {
- const res = await fetch(`/api/avatars/${encodeURIComponent(avatarIdParam)}`);
+ const res = await fetch(`/api/avatars/${encodeURIComponent(id)}`);
if (res.ok) {
const { avatar: meta } = await res.json();
- if (meta?.name) avatarName = meta.name;
- if (meta?.url) glbUrl = meta.url;
+ if (meta?.name && !nameOverride) avatarName = meta.name;
+ if (meta?.url) glbUrl = meta.url;
}
} catch {}
}
@@ -504,6 +517,8 @@ async function loadAvatar() {
setStatus('Loading avatar…', { loading: true, sticky: true });
+ _clearAvatar();
+
const loader = new GLTFLoader();
const gltf = await loader.loadAsync(glbUrl);
avatar = gltf.scene;
@@ -540,6 +555,27 @@ async function loadAvatar() {
setStatus(null);
}
+// ── Avatar picker ─────────────────────────────────────────────────────────
+const irlAvatarPicker = createAvatarPicker({
+ onSelect: async ({ id, url, name }) => {
+ _currentAvatarId = id;
+ // Update URL so sharing reflects the choice
+ const sp = new URLSearchParams(location.search);
+ if (id) sp.set('avatar', id); else sp.delete('avatar');
+ history.replaceState(null, '', location.pathname + (sp.toString() ? '?' + sp : ''));
+ try {
+ await loadAvatar(url, name);
+ } catch (err) {
+ log.error('[irl] avatar swap failed:', err);
+ setStatus(`Couldn't load avatar: ${err?.message ?? err}`, { error: true, sticky: true });
+ }
+ },
+});
+
+if (avatarBtn) {
+ avatarBtn.addEventListener('click', () => irlAvatarPicker.open(_currentAvatarId));
+}
+
// ── Resize ────────────────────────────────────────────────────────────────
function resize() {
renderer.setSize(window.innerWidth, window.innerHeight, false);
diff --git a/src/xr.js b/src/xr.js
index c8d0eb242..5ee7e5c30 100644
--- a/src/xr.js
+++ b/src/xr.js
@@ -26,6 +26,7 @@ import { WebXRSession } from './ar/webxr.js';
import { canUseQuickLook } from './ar/quick-look.js';
import { canUseSceneViewer, openSceneViewer } from './ar/scene-viewer.js';
import { log } from './shared/log.js';
+import { createAvatarPicker } from './avatar-picker.js';
// ── DOM ──────────────────────────────────────────────────────────────────────
@@ -39,6 +40,7 @@ const statusEl = document.getElementById('xr-status');
const statusDot = document.getElementById('xr-status-dot');
const deviceChip = document.getElementById('xr-device-chip');
const avatarLabel = document.getElementById('xr-avatar-label');
+const changeAvatarBtn = document.getElementById('xr-change-avatar');
const loadingEl = document.getElementById('xr-loading');
function setStatus(msg, type = 'idle') {
@@ -387,9 +389,18 @@ halfBtn.addEventListener('click', () => {
// ── Avatar loading ────────────────────────────────────────────────────────────
-async function resolveAvatarUrl() {
- const params = new URLSearchParams(location.search);
- const id = params.get('avatar');
+let _currentAvatarId = null;
+
+function _clearAvatar() {
+ if (xrViewer.content) {
+ scene.remove(xrViewer.content);
+ xrViewer.content = null;
+ }
+ animationManager.detach();
+ xrViewer.mixer = null;
+}
+
+async function _resolveAvatarUrl(id) {
if (!id) return '/avatars/default.glb';
const res = await fetch(`/api/avatars/${encodeURIComponent(id)}`);
if (!res.ok) return '/avatars/default.glb';
@@ -397,9 +408,22 @@ async function resolveAvatarUrl() {
return avatar?.url || '/avatars/default.glb';
}
-async function loadAvatar() {
- const url = await resolveAvatarUrl();
+async function loadAvatar(idOrUrl) {
+ const params = new URLSearchParams(location.search);
+ const id = idOrUrl !== undefined ? idOrUrl : params.get('avatar');
+
+ let url;
+ if (!id) {
+ url = '/avatars/default.glb';
+ } else if (/^https?:\/\/|^\//.test(id)) {
+ url = id;
+ } else {
+ url = await _resolveAvatarUrl(id);
+ }
+
_avatarGlbUrl = url;
+ _clearAvatar();
+
const loader = new GLTFLoader();
const gltf = await loader.loadAsync(url);
const root = gltf.scene;
@@ -435,10 +459,12 @@ async function loadAvatar() {
xrViewer.mixer = animationManager.mixer;
if (animationManager._animationDefs.length) animationManager.play('idle');
- // Avatar name from URL param
- const params = new URLSearchParams(location.search);
+ // Re-apply half-body if the mode was active during a hot-swap
+ if (halfBodyActive) applyHalfBody();
+
+ // Avatar label: prefer picker-supplied name, fall back to URL param
const handle = params.get('handle');
- if (avatarLabel && handle) avatarLabel.textContent = handle;
+ if (avatarLabel) avatarLabel.textContent = handle || 'Your Avatar';
}
// ── Resize ───────────────────────────────────────────────────────────────────
@@ -449,6 +475,33 @@ window.addEventListener('resize', () => {
camera.updateProjectionMatrix();
});
+// ── Avatar picker ─────────────────────────────────────────────────────────────
+
+const avatarPicker = createAvatarPicker({
+ onSelect: async ({ id, url, name }) => {
+ _currentAvatarId = id;
+ if (avatarLabel) avatarLabel.textContent = name;
+ setStatus('Loading avatar…', 'loading');
+ // Update URL so sharing reflects the chosen avatar
+ const sp = new URLSearchParams(location.search);
+ if (id) sp.set('avatar', id); else sp.delete('avatar');
+ history.replaceState(null, '', location.pathname + (sp.toString() ? '?' + sp : ''));
+ try {
+ await loadAvatar(url);
+ setStatus('Avatar loaded', 'idle');
+ } catch (err) {
+ setStatus('Failed to load avatar', 'error');
+ log.error('[xr] avatar swap failed:', err);
+ }
+ },
+});
+
+if (changeAvatarBtn) {
+ changeAvatarBtn.addEventListener('click', () => {
+ avatarPicker.open(_currentAvatarId);
+ });
+}
+
// ── Init ─────────────────────────────────────────────────────────────────────
(async () => {