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="robots" content="noindex,nofollow" />
<title data-i18n="internal_avaturn_forge.meta_title">three.ws · avaturn forge harness</title>
<style>
html, body { margin: 0; padding: 0; width: 100vw; height: 100vh; background: #0a0a0a; overflow: hidden; }
#stage { position: absolute; inset: 0; }
#stage iframe { width: 100%; height: 100%; border: 0; }
</style>
</head>
<body>
<!--
Headless harness for the avaturn-seed cron. NOT a user-facing page.
api/_lib/avaturn-headless.js loads this in headless chromium with a fresh
Avaturn catalog session URL, lets the official SDK randomize a body + assets
+ colors from the account's own catalog, exports a rigged GLB, and reads the
result back off window.__avaturnResult. Everything is driven through the
SDK's disableUi promise API — no human ever sees this.
-->
<div id="stage"></div>
<script type="module">
import { AvaturnSDK } from '/dashboard/avaturn-sdk.js';
// ── result channel (read by puppeteer.waitForFunction) ──────────────────────────
window.__avaturnDone = false;
window.__avaturnError = null;
window.__avaturnResult = null;
window.__avaturnProgress = 'boot';
const fail = (msg) => { window.__avaturnError = String(msg || 'unknown'); window.__avaturnDone = true; };
const step = (s) => { window.__avaturnProgress = s; };
// ── seeded RNG (browser copy of api/_lib/avaturn-seed.js — kept minimal) ────────
function hashSeed(str) {
let h = 2166136261 >>> 0;
for (let i = 0; i < str.length; i++) { h ^= str.charCodeAt(i); h = Math.imul(h, 16777619); }
return h >>> 0;
}
function mulberry32(seed) {
let a = seed >>> 0;
return function () {
a |= 0; a = (a + 0x6d2b79f5) | 0;
let t = Math.imul(a ^ (a >>> 15), 1 | a);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const pickOne = (arr, rng) => (Array.isArray(arr) && arr.length ? arr[Math.floor(rng() * arr.length)] : undefined);
const WEARABLE_SLOTS = ['outfit', 'top', 'bottom', 'shoes', 'hair', 'headwear', 'glasses', 'outerwear'];
const SLOT_ALIASES = { clothing: 'outfit', costume: 'outfit', footwear: 'shoes', shoe: 'shoes', hairstyle: 'hair', hat: 'headwear', headgear: 'headwear', eyewear: 'glasses', jacket: 'outerwear', coat: 'outerwear' };
const normalizeSlot = (raw) => { const k = String(raw || '').trim().toLowerCase(); return SLOT_ALIASES[k] || k; };
const HAIR_COLORS = ['#0b0b0b', '#1c1310', '#2a1a0f', '#3b2412', '#4a2f1a', '#5c3a1e', '#6b4423', '#7a5230', '#8d6239', '#a87c4f', '#c69a63', '#d9b380', '#e3c79a', '#9a9a9a', '#d8d8d8'];
const EYE_COLORS = ['brown', 'dark_brown', 'hazel', 'amber', 'green', 'blue', 'gray'];
// Public editor (no API key) — same iframe the demo uses.
const AVATURN_DEFAULT_BODY = {
male: 'https://assets.avaturn.me/editor_resources/default_male.glb',
female: 'https://assets.avaturn.me/editor_resources/default_female.glb',
};
const defaultEditorUrl = (bodyType) =>
'https://preview.avaturn.dev/editor?avatar_link=' +
encodeURIComponent(AVATURN_DEFAULT_BODY[bodyType] || AVATURN_DEFAULT_BODY.male);
function pickRandomLook(seed, { bodies, assets, bodyType }) {
const rng = mulberry32(hashSeed(String(seed)));
let bodyPool = (bodies || []).filter((b) => b && b.id);
if (bodyType) {
const matched = bodyPool.filter((b) => normalizeSlot(b.gender ?? b.body_type) === bodyType);
if (matched.length) bodyPool = matched;
}
const body = pickOne(bodyPool, rng);
const grouped = {};
for (const a of assets || []) {
if (!a || !a.id) continue;
const slot = normalizeSlot(a.category ?? a.type ?? a.slot);
if (!WEARABLE_SLOTS.includes(slot)) continue;
(grouped[slot] ||= []).push(a);
}
const assetIds = [];
for (const slot of WEARABLE_SLOTS) {
const choice = pickOne(grouped[slot] || [], rng);
if (choice) assetIds.push(choice.id);
}
return {
bodyId: body?.id ?? null,
assetIds,
hairColor: pickOne(HAIR_COLORS, rng) ?? HAIR_COLORS[0],
eyeColor: pickOne(EYE_COLORS, rng) ?? EYE_COLORS[0],
skinToneCorrection: Math.round((rng() - 0.5) * 30),
};
}
// ── helpers ─────────────────────────────────────────────────────────────────────
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
async function quiet(promise) { try { return await promise; } catch { return null; } }
// Poll an async getter until it returns a non-empty array or we run out of tries.
async function waitForList(getter, { tries = 20, gap = 500 } = {}) {
for (let i = 0; i < tries; i++) {
const list = await quiet(getter());
if (Array.isArray(list) && list.length) return list;
await sleep(gap);
}
return [];
}
function extractExportUrl(result) {
if (!result) return null;
return result.url || result.glbUrl || result.avatarUrl || result?.data?.url || (typeof result === 'string' ? result : null);
}
// ── main ─────────────────────────────────────────────────────────────────────────
(async () => {
try {
const params = new URLSearchParams(location.search);
const bodyType = params.get('bodyType') || 'male';
const seed = params.get('seed') || String(hashSeed('fallback'));
// Photo-session avatars are a reconstructed person: keep that body/face and
// only vary outfit + colors. Catalog sessions swap to a random base body.
const keepBody = params.get('keepBody') === '1';
// Use an explicit session URL if one was supplied (authenticated path),
// otherwise drive the public demo editor — no API key needed.
const editorUrl = params.get('session') || defaultEditorUrl(bodyType);
step('init');
const sdk = new AvaturnSDK();
const stage = document.getElementById('stage');
// disableUi: no editor chrome; drive everything through the promise API.
const ready = new Promise((resolve) => {
let settled = false;
const done = () => { if (!settled) { settled = true; resolve(); } };
// 'load' is the one callback allowed in disableUi mode.
try { sdk.on('load', done); } catch { /* fall through to init resolve */ }
sdk.init(stage, { url: editorUrl, disableUi: true })
.then(() => setTimeout(done, 1500)) // safety net if 'load' never fires
.catch((e) => fail('init failed: ' + (e?.message || e)));
});
await ready;
if (window.__avaturnDone) return;
step('catalog');
const [bodies, assets] = await Promise.all([
waitForList(() => sdk.getBodyList()),
waitForList(() => sdk.getAssetList()),
]);
if (!bodies.length && !assets.length) return fail('empty catalog (bodies + assets)');
const look = pickRandomLook(seed, { bodies, assets, bodyType });
window.__avaturnLook = look;
step('apply-body');
// keepBody: preserve the photo-reconstructed person; only catalog runs swap body.
if (!keepBody && look.bodyId) await quiet(sdk.setActiveBody(look.bodyId));
step('apply-assets');
for (const id of look.assetIds) await quiet(sdk.setActiveAsset(id));
step('apply-colors');
await quiet(sdk.setHairColor(look.hairColor));
await quiet(sdk.setEyeColor(look.eyeColor));
await quiet(sdk.setSkinToneCorrection(look.skinToneCorrection));
// Let the editor settle the last asset swap before exporting.
await sleep(800);
step('export');
const result = await sdk.exportAvatar();
const url = extractExportUrl(result);
if (!url) return fail('export returned no url');
window.__avaturnResult = { url, look, raw: result };
window.__avaturnDone = true;
} catch (err) {
fail(err?.message || err);
}
})();
</script>
<!-- Runtime i18n: detects locale, swaps annotated copy, mounts <lang-switcher>. -->
<script type="module" src="/i18n.js"></script>
</body>
</html>