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
feat: implement dashboard preferences API for user settings management
nirholas5c4dd53560ac
diff --git a/home.css b/home.cssindex 316760484..145381a1b 100644--- a/home.css+++ b/home.css@@ -27,6 +27,16 @@}}+/* ── Act 2 Three.js canvas (full-area, transparent) ─────────────────────── */++#home-act2-canvas.h-avatar-viewer {+ display: block;+ width: 100%;+ height: 100%;+ background: transparent;+ cursor: pointer;+}+/* ── Fluid canvas ────────────────────────────────────────────────────────── */.h-fluid-canvas {diff --git a/home.html b/home.htmlindex 809ef4959..d1f8260aa 100644--- a/home.html+++ b/home.html@@ -36,6 +36,7 @@src="https://ajax.googleapis.com/ajax/libs/model-viewer/4.0.0/model-viewer.min.js"></script><script src="/fluid-particles.js" defer></script>+ <script type="module" src="/src/home-act2-viewer.js"></script></head><body class="home-page"><div class="cursor" id="cursor" aria-hidden="true"></div>@@ -218,22 +219,7 @@<div class="h-layer" style="--depth: 1"><div class="h-avatar-stage"><div class="h-avatar-wrap">- <model-viewer- id="home-act2-mv"- class="h-avatar-viewer"- src="/animations/robotexpressive.glb"- animation-name="Idle"- autoplay- camera-controls- disable-zoom- interaction-prompt="none"- shadow-intensity="0.6"- exposure="1.0"- environment-image="neutral"- camera-orbit="0deg 78deg 12m"- field-of-view="16deg"- loading="lazy"- ></model-viewer>+ <canvas id="home-act2-canvas" class="h-avatar-viewer"></canvas></div></div></div>@@ -633,88 +619,76 @@});})();- // Avatar picker + dynamic animation chips (Act 2) — same UX as /app+ // Act 2 viewer — Three.js + animation manifest, same trick as /app.+ // Every model gets every clip from /animations/manifest.json (retargeted+ // onto its skeleton via AnimationMixer), regardless of what's baked in.(function () {- const mv = document.getElementById('home-act2-mv');+ const canvas = document.getElementById('home-act2-canvas');const opts = document.querySelectorAll('.h-av-opt');const chipsWrap = document.querySelector('[data-role="anim-chips"]');- if (!mv || !chipsWrap) return;-- const ANIM_EMOJI = {- Dance: '💃', Wave: '👋', Jump: '⬆', ThumbsUp: '👍',- Punch: '🥊', No: '🙅', Yes: '🙆', Idle: '😐',- Walk: '🚶', Walking: '🚶', Run: '🏃', Running: '🏃',- TPose: '🧍', Sitting: '💺', Standing: '🧍',- WalkJump: '🤸', Death: '💀',- };-- function prettyLabel(name) {- /* Strip stuff like "V4.2(maya_head)" or anything in parens */- let clean = name.replace(/\s*\([^)]*\)/g, '')- .replace(/V\d+(\.\d+)?$/, '')- .replace(/_/g, ' ')- .trim();- if (!clean) clean = name;- const key = clean.replace(/\s+/g, '');- const emoji = ANIM_EMOJI[key] || '✨';- return emoji + ' ' + clean;+ if (!canvas || !chipsWrap) return;++ /* Wait for the Act2Viewer ESM to load (it sets window.Act2Viewer) */+ function whenReady(cb) {+ if (window.Act2Viewer) return cb();+ setTimeout(() => whenReady(cb), 60);}- /* Generate one chip per available animation in the loaded model */- function rebuildChips() {- const avail = mv.availableAnimations || [];- chipsWrap.innerHTML = '';- if (!avail.length) return;- for (const animName of avail) {- const btn = document.createElement('button');- btn.type = 'button';- btn.className = 'h-anim-chip';- btn.dataset.anim = animName;- btn.textContent = prettyLabel(animName);- btn.addEventListener('click', () => {- chipsWrap.querySelectorAll('.h-anim-chip').forEach(c => delete c.dataset.active);- btn.dataset.active = 'true';- mv.animationName = animName;- mv.play();+ whenReady(() => {+ const viewer = new window.Act2Viewer(canvas);++ function prettyLabel(def) {+ const icon = def.icon || '✨';+ const label = (def.label || def.name).replace(/\s*\([^)]*\)/g, '').trim();+ return icon + ' ' + label;+ }++ function rebuildChips(defs) {+ chipsWrap.innerHTML = '';+ defs.forEach((def, i) => {+ const btn = document.createElement('button');+ btn.type = 'button';+ btn.className = 'h-anim-chip';+ btn.dataset.anim = def.name;+ btn.textContent = prettyLabel(def);+ if (i === 0) btn.dataset.active = 'true';+ btn.addEventListener('click', async () => {+ chipsWrap.querySelectorAll('.h-anim-chip').forEach((c) => delete c.dataset.active);+ btn.dataset.active = 'true';+ try { await viewer.playClip(def.name); } catch (e) { /* ignore */ }+ });+ chipsWrap.appendChild(btn);});- chipsWrap.appendChild(btn);}- /* mark first chip active to mirror the auto-played animation */- const first = chipsWrap.querySelector('.h-anim-chip');- if (first) first.dataset.active = 'true';- }- /* Avatar switch — load model, rebuild chips for whatever animations it has */- opts.forEach(btn => {- btn.addEventListener('click', () => {- opts.forEach(b => b.setAttribute('aria-pressed', 'false'));- btn.setAttribute('aria-pressed', 'true');- mv.addEventListener('load', () => {- rebuildChips();- const first = (mv.availableAnimations || [])[0];- if (first) {- mv.animationName = first;- mv.play();- }- }, { once: true });- mv.src = btn.dataset.src;+ viewer.onClipsReady = rebuildChips;++ /* default avatar */+ viewer.loadModel('/avatars/cz.glb').catch(console.error);++ /* avatar picker */+ opts.forEach((btn) => {+ btn.addEventListener('click', async () => {+ opts.forEach((b) => b.setAttribute('aria-pressed', 'false'));+ btn.setAttribute('aria-pressed', 'true');+ try { await viewer.loadModel(btn.dataset.src); } catch (e) { console.error(e); }+ });});- });+ /* highlight CZ as default */+ const czBtn = Array.from(opts).find((b) => b.dataset.src === '/avatars/cz.glb');+ if (czBtn) {+ opts.forEach((b) => b.setAttribute('aria-pressed', 'false'));+ czBtn.setAttribute('aria-pressed', 'true');+ }- /* Click-to-zoom toggle — default is wide so the full body is visible,- click zooms in closer for a portrait shot, click again to reset. */- const ORBIT_DEFAULT = '0deg 78deg 12m';- const ORBIT_ZOOMED = '0deg 78deg 6m';- let zoomed = false;- mv.addEventListener('click', (e) => {- /* don't fire when interacting with the chip area */- if (e.target.closest('.h-anim-chip, .h-av-opt')) return;- zoomed = !zoomed;- mv.cameraOrbit = zoomed ? ORBIT_ZOOMED : ORBIT_DEFAULT;+ /* click on canvas to toggle zoom (default → extra-wide) */+ let wider = false;+ const NEAR = 22, FAR = 36;+ canvas.addEventListener('click', () => {+ wider = !wider;+ viewer.zoom(wider ? FAR : NEAR);+ });});-- /* Initial chip build once model loads */- mv.addEventListener('load', rebuildChips, { once: true });})();// Chain ribbon (Act 3)diff --git a/src/home-act2-viewer.js b/src/home-act2-viewer.jsnew file mode 100644index 000000000..002974a7a--- /dev/null+++ b/src/home-act2-viewer.js@@ -0,0 +1,250 @@+/**+ * Three.js viewer for the homepage Act 2 — same trick as /app:+ * loads any GLB, fetches the project's animation manifest+ * (/animations/manifest.json), lazy-loads clips on first play, and+ * retargets them onto whatever skeleton is loaded.+ *+ * Public API (mounted on window):+ * const v = new Act2Viewer(canvas);+ * v.onClipsReady = (defs) => { /* build chips */ /* };+ * await v.loadModel('/avatars/cz.glb');+ * v.playClip('dance');+ */+import {+ WebGLRenderer,+ Scene,+ PerspectiveCamera,+ AnimationMixer,+ AnimationClip,+ Box3,+ Vector3,+ Clock,+ HemisphereLight,+ DirectionalLight,+ ACESFilmicToneMapping,+ SRGBColorSpace,+ PMREMGenerator,+} from 'three';+import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';+import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';++const CROSSFADE = 0.35;++export class Act2Viewer {+ constructor(canvas) {+ this.canvas = canvas;+ this.renderer = new WebGLRenderer({ canvas, antialias: true, alpha: true });+ this.renderer.toneMapping = ACESFilmicToneMapping;+ this.renderer.toneMappingExposure = 1.0;+ this.renderer.outputColorSpace = SRGBColorSpace;++ this.scene = new Scene();+ this.camera = new PerspectiveCamera(14, 1, 0.1, 100);+ this.camera.position.set(0, 1.0, 22);++ /* neutral environment (matches model-viewer's environment-image="neutral") */+ const pmrem = new PMREMGenerator(this.renderer);+ this.scene.environment = pmrem.fromScene(new RoomEnvironment(), 0.04).texture;++ this.scene.add(new HemisphereLight(0xffffff, 0x444466, 0.8));+ const sun = new DirectionalLight(0xffffff, 1.2);+ sun.position.set(4, 8, 6);+ this.scene.add(sun);++ /** @type {Map<string, AnimationClip>} */+ this.clips = new Map();+ /** @type {THREE.AnimationAction|null} */+ this.currentAction = null;+ this.mixer = null;+ this.model = null;++ /** @type {Array<{name:string,url:string,label:string,icon:string,loop?:boolean}>} */+ this._manifest = [];+ this._manifestPromise = null;++ this._loader = new GLTFLoader();+ this._clock = new Clock();+ this._modelYaw = 0;++ /** Optional callback when the chip list changes (manifest + GLB-baked combined). */+ this.onClipsReady = null;++ this._resize();+ const ro = new ResizeObserver(() => this._resize());+ ro.observe(canvas);++ this._tick = this._tick.bind(this);+ requestAnimationFrame(this._tick);+ }++ _resize() {+ const dpr = Math.min(devicePixelRatio || 1, 2);+ const w = this.canvas.clientWidth;+ const h = this.canvas.clientHeight;+ if (!w || !h) return;+ this.renderer.setPixelRatio(dpr);+ this.renderer.setSize(w, h, false);+ this.camera.aspect = w / h;+ this.camera.updateProjectionMatrix();+ }++ _tick() {+ const dt = this._clock.getDelta();+ if (this.mixer) this.mixer.update(dt);+ if (this.model) {+ this._modelYaw += dt * 0.18; /* slow auto-rotate, like model-viewer's auto-rotate */+ this.model.rotation.y = this._modelYaw;+ }+ this.renderer.render(this.scene, this.camera);+ requestAnimationFrame(this._tick);+ }++ async _loadManifest() {+ if (this._manifest.length) return this._manifest;+ if (this._manifestPromise) return this._manifestPromise;+ this._manifestPromise = fetch('/animations/manifest.json')+ .then((r) => r.json())+ .then((data) => {+ const arr = Array.isArray(data) ? data : data.animations || [];+ this._manifest = arr;+ return arr;+ })+ .catch(() => {+ this._manifest = [];+ return [];+ });+ return this._manifestPromise;+ }++ /** Returns combined: GLB-baked clips + project animation manifest, deduped by name. */+ listAvailableClips() {+ const out = [];+ const seen = new Set();+ /* manifest first (these are the "preset" controls /app shows) */+ for (const def of this._manifest) {+ if (!seen.has(def.name)) {+ out.push({ ...def, source: 'manifest' });+ seen.add(def.name);+ }+ }+ /* then GLB-baked names not already in manifest */+ for (const name of this.clips.keys()) {+ if (seen.has(name)) continue;+ seen.add(name);+ out.push({+ name,+ label: name,+ icon: '✨',+ loop: true,+ source: 'glb',+ });+ }+ return out;+ }++ async _fetchClip(url) {+ const r = await fetch(url);+ if (!r.ok) throw new Error('clip ' + url + ' ' + r.status);+ const json = await r.json();+ return AnimationClip.parse(json);+ }++ async loadModel(url) {+ /* swap out previous model */+ if (this.model) {+ if (this.mixer) this.mixer.stopAllAction();+ this.scene.remove(this.model);+ this.model = null;+ this.mixer = null;+ this.currentAction = null;+ this.clips.clear();+ }++ const gltf = await this._loader.loadAsync(url);+ this.model = gltf.scene;+ this.scene.add(this.model);++ /* center horizontally + plant feet on ground */+ const box = new Box3().setFromObject(this.model);+ const size = box.getSize(new Vector3());+ const center = box.getCenter(new Vector3());+ this.model.position.x -= center.x;+ this.model.position.z -= center.z;+ this.model.position.y -= box.min.y;++ /* fit camera to model height with a comfortable framing */+ const targetHeight = size.y;+ const dist = (targetHeight / 2) / Math.tan((this.camera.fov / 2) * (Math.PI / 180));+ this.camera.position.set(0, targetHeight * 0.55, dist * 1.2);+ this.camera.lookAt(0, targetHeight * 0.55, 0);++ this.mixer = new AnimationMixer(this.model);++ /* register baked-in clips */+ for (const clip of gltf.animations || []) {+ this.clips.set(clip.name, clip);+ }++ /* ensure manifest is fetched */+ await this._loadManifest();++ /* fire chip rebuild */+ if (typeof this.onClipsReady === 'function') {+ this.onClipsReady(this.listAvailableClips());+ }++ /* auto-play first idle if available */+ const startName = this._pickStartName();+ if (startName) await this.playClip(startName);++ return this.model;+ }++ _pickStartName() {+ /* prefer 'idle', then anything matching 'Idle*', then first manifest entry,+ then first baked clip */+ const all = this.listAvailableClips();+ const idle = all.find((c) => c.name.toLowerCase() === 'idle');+ if (idle) return idle.name;+ const idleish = all.find((c) => c.name.toLowerCase().includes('idle'));+ if (idleish) return idleish.name;+ return all[0]?.name || null;+ }++ async playClip(name) {+ if (!this.mixer) return;+ let clip = this.clips.get(name);++ if (!clip) {+ /* lazy-load from manifest */+ const def = this._manifest.find((d) => d.name === name);+ if (!def) return;+ clip = await this._fetchClip(def.url);+ this.clips.set(name, clip);+ }++ const action = this.mixer.clipAction(clip);+ action.enabled = true;+ action.setLoop(undefined, Infinity); /* default loop */+ if (this.currentAction && this.currentAction !== action) {+ action.reset().fadeIn(CROSSFADE).play();+ this.currentAction.fadeOut(CROSSFADE);+ } else {+ action.reset().play();+ }+ this.currentAction = action;+ }++ setExposure(v) {+ this.renderer.toneMappingExposure = v;+ }++ zoom(distance) {+ const cur = this.camera.position.length();+ this.camera.position.normalize().multiplyScalar(distance);+ this.camera.lookAt(0, this.camera.position.y * 0.6, 0);+ }+}++/* expose on window so the inline home.html script can use it */+window.Act2Viewer = Act2Viewer;