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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title data-i18n="demos_usdz_ar.meta_title">USDZ & AR Quick Look · three.ws lab</title>
<meta name="robots" content="noindex" />
<link rel="stylesheet" href="/style.css" />
<link rel="stylesheet" href="/nav.css" />
<script
type="module"
src="https://cdn.jsdelivr.net/npm/@google/[email protected]/dist/model-viewer.min.js" integrity="sha384-wjsPzEO+lXOf7d9csIDfAQpPt2OKuUU3m0K9qsdKIuzX4N8czSF6hdh23eAbZa3p" crossorigin="anonymous"
></script>
<style>
:root { color-scheme: dark; }
body { background: #060606; color: #eee; font: 15px/1.5 -apple-system, system-ui, sans-serif; margin: 0; }
.stage { max-width: 1000px; margin: 0 auto; padding: 48px 24px 80px; }
.crumb a { color: #8a8d98; text-decoration: none; }
.crumb a:hover { color: #3dc1ff; }
h1 { font-size: 28px; font-weight: 600; letter-spacing: -0.015em; margin: 14px 0 8px; }
.sub { color: #8a8d98; max-width: 64ch; margin: 0 0 30px; }
.row { display: grid; grid-template-columns: 1fr 360px; gap: 24px; }
@media (max-width: 820px) { .row { grid-template-columns: 1fr; } }
.viewer-card {
background: #101010; border: 1.5px solid #202020; border-radius: 14px;
overflow: hidden; aspect-ratio: 1 / 1; min-height: 400px;
}
model-viewer { width: 100%; height: 100%; --poster-color: transparent; background: #0b0b0b; }
.panel { background: #101010; border: 1.5px solid #202020; border-radius: 14px; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
label { font-size: 12.5px; color: #8a8d98; text-transform: uppercase; letter-spacing: 0.06em; }
input[type=text], input[type=file], select {
width: 100%; padding: 10px 12px; border-radius: 9px;
background: #080808; color: #eee; border: 1px solid #202020;
font: inherit;
}
button {
background: #3dc1ff; color: #0a0a0a; border: 0; border-radius: 9px;
padding: 10px 14px; font-weight: 600; cursor: pointer;
font: inherit;
}
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.secondary { background: rgba(255,255,255,0.06); color: #eee; }
.log {
background: #080808; border: 1px solid #202020; border-radius: 9px;
padding: 12px; font-family: ui-monospace, monospace; font-size: 12px;
line-height: 1.6; color: #8a8d98; max-height: 280px; overflow: auto; white-space: pre-wrap;
}
.log .ok { color: #3dc1ff; }
.log .err { color: #ff6b6b; }
.log .info { color: #66d9ef; }
</style>
<script src="/model-viewer-meshopt.js"></script>
</head>
<body>
<header><div id="nav-container"></div></header>
<main class="stage">
<p class="crumb" data-i18n-html="demos_usdz_ar.lab"><a href="/demos">← lab</a></p>
<h1 data-i18n="demos_usdz_ar.usdz_ar_quick_look">USDZ & AR Quick Look</h1>
<p class="sub" data-i18n-html="demos_usdz_ar.loads_a_glb_generates_a_usdz_companion">
Loads a GLB, generates a USDZ companion entirely in-browser via the
three.js <code>USDZExporter</code>, uploads it to R2 through the
<code>/api/avatars/presign-usdz</code> action, then renders
<code><model-viewer></code> with both <code>src</code> and
<code>ios-src</code>. Tap the AR button on iPhone Safari to verify
Quick Look opens. Nothing here touches the live <code>/create</code>
or <code>/avatars/:id</code> flow.
</p>
<div class="row">
<div class="viewer-card">
<model-viewer
id="mv"
src="/avatars/default.glb"
alt="three.ws sample avatar"
camera-controls
auto-rotate
rotation-per-second="14deg"
interaction-prompt="none"
exposure="1.05"
shadow-intensity="0.9"
environment-image="neutral"
ar
ar-modes="webxr scene-viewer quick-look"
></model-viewer>
</div>
<div class="panel">
<label data-i18n="demos_usdz_ar.1_pick_a_glb_or_use_the">1. Pick a GLB (or use the sample)</label>
<input type="file" id="glb-input" accept=".glb,model/gltf-binary" />
<input type="text" id="glb-url" placeholder="…or paste a GLB URL" />
<label style="margin-top:6px" data-i18n="demos_usdz_ar.2_convert_to_usdz">2. Convert to USDZ</label>
<button id="convert-btn" data-i18n="demos_usdz_ar.generate_usdz_in_browser">Generate USDZ in-browser</button>
<label style="margin-top:6px" data-i18n="demos_usdz_ar.3_optional_upload_to_your_account">3. Optional — upload to your account</label>
<input type="text" id="avatar-id" placeholder="Existing avatar UUID (must be yours)" />
<button id="upload-btn" class="secondary" disabled data-i18n="demos_usdz_ar.upload_patch_avatar">Upload + PATCH avatar</button>
<label style="margin-top:6px" data-i18n="demos_usdz_ar.log">Log</label>
<div class="log" id="log">ready.</div>
</div>
</div>
</main>
<script src="/nav.js" defer></script>
<script type="module">
import { glbBlobToUsdzBlob } from '/src/usdz-pipeline.js';
import { apiFetch } from '/src/api.js';
const $ = (id) => document.getElementById(id);
const log = $('log');
const logLine = (msg, cls = '') => {
const t = new Date().toTimeString().slice(0, 8);
log.innerHTML += `\n<span class="${cls}">[${t}] ${msg}</span>`;
log.scrollTop = log.scrollHeight;
};
let lastUsdzBlob = null;
let lastUsdzUrl = null;
let lastGlbBlob = null;
$('glb-input').addEventListener('change', async (e) => {
const file = e.target.files?.[0];
if (!file) return;
const url = URL.createObjectURL(file);
$('mv').src = url;
lastGlbBlob = file;
logLine(`loaded local GLB: ${file.name} (${file.size} bytes)`, 'info');
});
$('glb-url').addEventListener('change', async (e) => {
const url = e.target.value.trim();
if (!url) return;
$('mv').src = url;
logLine(`loaded remote GLB: ${url}`, 'info');
try {
const r = await fetch(url);
if (!r.ok) throw new Error(`GLB fetch ${r.status}`);
lastGlbBlob = await r.blob();
} catch (err) {
logLine(`remote fetch failed: ${err.message}`, 'err');
}
});
$('convert-btn').addEventListener('click', async () => {
try {
if (!lastGlbBlob) {
const r = await fetch($('mv').src);
if (!r.ok) throw new Error(`GLB fetch ${r.status}`);
lastGlbBlob = await r.blob();
}
logLine(`converting ${lastGlbBlob.size} byte GLB → USDZ…`, 'info');
const t0 = performance.now();
lastUsdzBlob = await glbBlobToUsdzBlob(lastGlbBlob);
const ms = Math.round(performance.now() - t0);
if (lastUsdzUrl) URL.revokeObjectURL(lastUsdzUrl);
lastUsdzUrl = URL.createObjectURL(lastUsdzBlob);
$('mv').setAttribute('ios-src', lastUsdzUrl);
$('upload-btn').disabled = false;
logLine(`✓ USDZ generated (${lastUsdzBlob.size} bytes, ${ms} ms). Tap the AR button on iPhone Safari to test Quick Look.`, 'ok');
} catch (err) {
logLine(`USDZ conversion failed: ${err.message}`, 'err');
}
});
$('upload-btn').addEventListener('click', async () => {
const avatarId = $('avatar-id').value.trim();
if (!avatarId) {
logLine('upload skipped — no avatar id', 'err');
return;
}
if (!lastUsdzBlob) {
logLine('no USDZ to upload — run step 2 first', 'err');
return;
}
try {
logLine('requesting presigned upload URL…', 'info');
const presignRes = await fetch('/api/avatars/presign-usdz', {
method: 'POST',
credentials: 'include',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ avatar_id: avatarId, size_bytes: lastUsdzBlob.size }),
});
if (!presignRes.ok) throw new Error(`presign ${presignRes.status}: ${await presignRes.text()}`);
const pre = await presignRes.json();
logLine(`presign ok, key=${pre.usdz_key}`, 'info');
logLine('uploading to R2…', 'info');
const put = await fetch(pre.upload_url, {
method: 'PUT',
headers: { 'content-type': 'model/vnd.usdz+zip' },
body: lastUsdzBlob,
});
if (!put.ok) throw new Error(`R2 ${put.status}`);
logLine('upload ok', 'ok');
logLine('PATCHing avatar with usdz_key…', 'info');
const patch = await apiFetch(`/api/avatars/${encodeURIComponent(avatarId)}`, {
method: 'PATCH',
credentials: 'include',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ usdz_key: pre.usdz_key }),
});
if (!patch.ok) throw new Error(`PATCH ${patch.status}: ${await patch.text()}`);
logLine('✓ avatar updated. Reload /avatars/' + avatarId + ' to see iOS Quick Look wired in.', 'ok');
} catch (err) {
logLine(`upload failed: ${err.message}`, 'err');
}
});
</script>
<script src="/brand.js" defer></script>
<!-- Runtime i18n: detects locale, swaps annotated copy, mounts <lang-switcher>. -->
<script type="module" src="/i18n.js"></script>
</body>
</html>