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(pose): pose share module, home/pose-studio updates, brain chat + env refinements
nirholasbe5174bcdef8
diff --git a/api/_lib/demo-avatars.js b/api/_lib/demo-avatars.jsindex 0a986852b..9562cd79c 100644--- a/api/_lib/demo-avatars.js+++ b/api/_lib/demo-avatars.js@@ -42,15 +42,17 @@ function demoItem({ id, slug, name, description, tags, glbUrl, image, sortDate,export const DEMO_AVATARS = [demoItem({ id: "avatar_demo_disk_cz", slug: "demo-cz", name: "CZ", description: "CZ — stylized humanoid with idle pose, ready for chat overlays.", tags: ["humanoid","character","community"], glbUrl: "https://three.ws/avatars/cz.glb", image: null, sortDate: "2025-04-01T00:00:00.000Z", attribution: {"handle":"three.ws","displayName":"three.ws starter","url":"https://three.ws","license":"CC-BY 4.0"}, author: {"handle":"three.ws","displayName":"three.ws starter","profileUrl":"https://three.ws"} }),demoItem({ id: "avatar_demo_disk_ansem", slug: "demo-ansem", name: "Ansem", description: "Ansem — trader persona for chart-watchers and crypto Twitter.", tags: ["humanoid","community","trader"], glbUrl: "https://three.ws/avatars/default.glb", image: null, sortDate: "2025-03-31T23:00:00.000Z", attribution: {"handle":"three.ws","displayName":"three.ws starter","url":"https://three.ws","license":"CC-BY 4.0"}, author: {"handle":"three.ws","displayName":"three.ws starter","profileUrl":"https://three.ws"} }),- demoItem({ id: "avatar_demo_disk_boss", slug: "demo-boss", name: "Boss", description: "Boss — for the one running the room. Soldier rig with locomotion.", tags: ["humanoid","rigged","animated","community"], glbUrl: "https://three.ws/animations/soldier.glb", image: null, sortDate: "2025-03-31T22:00:00.000Z", attribution: {"handle":"three.ws","displayName":"three.ws starter","url":"https://three.ws","license":"CC-BY 4.0"}, author: {"handle":"three.ws","displayName":"three.ws starter","profileUrl":"https://three.ws"} }),- demoItem({ id: "avatar_demo_disk_vernington", slug: "demo-vernington", name: "Vernington", description: "Vernington — the senior of the Vern lineage.", tags: ["humanoid","community"], glbUrl: "https://three.ws/avatars/default.glb", image: null, sortDate: "2025-03-31T21:00:00.000Z", attribution: {"handle":"three.ws","displayName":"three.ws starter","url":"https://three.ws","license":"CC-BY 4.0"}, author: {"handle":"three.ws","displayName":"three.ws starter","profileUrl":"https://three.ws"} }),- demoItem({ id: "avatar_demo_disk_saga", slug: "demo-saga", name: "Saga", description: "Saga — mobile-native, expressive robot rig with idle, walk, jump, dance clips.", tags: ["robot","animated","rigged","community"], glbUrl: "https://three.ws/animations/robotexpressive.glb", image: null, sortDate: "2025-03-31T20:00:00.000Z", attribution: {"handle":"three.ws","displayName":"three.ws starter","url":"https://three.ws","license":"CC-BY 4.0"}, author: {"handle":"three.ws","displayName":"three.ws starter","profileUrl":"https://three.ws"} }),- demoItem({ id: "avatar_demo_disk_claude", slug: "demo-claude", name: "Claude", description: "Claude — calm, thoughtful AI persona.", tags: ["humanoid","community","ai"], glbUrl: "https://three.ws/avatars/default.glb", image: null, sortDate: "2025-03-31T19:00:00.000Z", attribution: {"handle":"three.ws","displayName":"three.ws starter","url":"https://three.ws","license":"CC-BY 4.0"}, author: {"handle":"three.ws","displayName":"three.ws starter","profileUrl":"https://three.ws"} }),- demoItem({ id: "avatar_demo_disk_3d", slug: "demo-3d", name: "3D", description: "3D — meta avatar representing the platform itself.", tags: ["humanoid","community","meta"], glbUrl: "https://three.ws/avatars/default.glb", image: null, sortDate: "2025-03-31T18:00:00.000Z", attribution: {"handle":"three.ws","displayName":"three.ws starter","url":"https://three.ws","license":"CC-BY 4.0"}, author: {"handle":"three.ws","displayName":"three.ws starter","profileUrl":"https://three.ws"} }),- demoItem({ id: "avatar_demo_disk_ai", slug: "demo-ai", name: "AI", description: "AI — generic agent stand-in, expressive robot rig.", tags: ["robot","animated","rigged","community","ai"], glbUrl: "https://three.ws/animations/robotexpressive.glb", image: null, sortDate: "2025-03-31T17:00:00.000Z", attribution: {"handle":"three.ws","displayName":"three.ws starter","url":"https://three.ws","license":"CC-BY 4.0"}, author: {"handle":"three.ws","displayName":"three.ws starter","profileUrl":"https://three.ws"} }),- demoItem({ id: "avatar_demo_disk_agent", slug: "demo-agent", name: "Agent", description: "Agent — operative ready for autonomous on-chain work.", tags: ["humanoid","rigged","animated","community","agent"], glbUrl: "https://three.ws/animations/soldier.glb", image: null, sortDate: "2025-03-31T16:00:00.000Z", attribution: {"handle":"three.ws","displayName":"three.ws starter","url":"https://three.ws","license":"CC-BY 4.0"}, author: {"handle":"three.ws","displayName":"three.ws starter","profileUrl":"https://three.ws"} }),- demoItem({ id: "avatar_demo_disk_vern", slug: "demo-vern", name: "Vern", description: "Vern — base form, before the Vernington promotion.", tags: ["humanoid","community"], glbUrl: "https://three.ws/avatars/default.glb", image: null, sortDate: "2025-03-31T15:00:00.000Z", attribution: {"handle":"three.ws","displayName":"three.ws starter","url":"https://three.ws","license":"CC-BY 4.0"}, author: {"handle":"three.ws","displayName":"three.ws starter","profileUrl":"https://three.ws"} }),- demoItem({ id: "avatar_demo_disk_crossinger", slug: "demo-crossinger", name: "Crossinger", description: "Crossinger — chain-hopper, multi-network identity.", tags: ["humanoid","community"], glbUrl: "https://three.ws/avatars/default.glb", image: null, sortDate: "2025-03-31T14:00:00.000Z", attribution: {"handle":"three.ws","displayName":"three.ws starter","url":"https://three.ws","license":"CC-BY 4.0"}, author: {"handle":"three.ws","displayName":"three.ws starter","profileUrl":"https://three.ws"} }),- demoItem({ id: "avatar_demo_disk_spartian", slug: "demo-spartian", name: "Spartian", description: "Spartian — disciplined, armored, never folds.", tags: ["humanoid","rigged","animated","community"], glbUrl: "https://three.ws/animations/soldier.glb", image: null, sortDate: "2025-03-31T13:00:00.000Z", attribution: {"handle":"three.ws","displayName":"three.ws starter","url":"https://three.ws","license":"CC-BY 4.0"}, author: {"handle":"three.ws","displayName":"three.ws starter","profileUrl":"https://three.ws"} }),+ demoItem({ id: "avatar_demo_disk_boss", slug: "demo-boss", name: "Boss", description: "Boss — for the one running the room. Soldier rig with locomotion.", tags: ["humanoid","rigged","animated","community"], glbUrl: "https://three.ws/animations/soldier.glb", image: null, sortDate: "2025-03-31T22:00:00.000Z", attribution: {"handle":"threejs","displayName":"three.js examples","url":"https://github.com/mrdoob/three.js","license":"MIT"}, author: {"handle":"threejs","displayName":"three.js examples","profileUrl":"https://github.com/mrdoob/three.js"} }),+ demoItem({ id: "avatar_demo_disk_vernington", slug: "demo-vernington", name: "Vernington", description: "Vernington — the senior of the Vern lineage, full-body ready-player rig.", tags: ["humanoid","rigged","avatar","community"], glbUrl: "https://three.ws/avatars/readyplayerme.glb", image: null, sortDate: "2025-03-31T21:00:00.000Z", attribution: {"handle":"threejs","displayName":"three.js examples","url":"https://github.com/mrdoob/three.js","license":"MIT"}, author: {"handle":"threejs","displayName":"three.js examples","profileUrl":"https://github.com/mrdoob/three.js"} }),+ demoItem({ id: "avatar_demo_disk_saga", slug: "demo-saga", name: "Saga", description: "Saga — mobile-native, expressive robot rig with idle, walk, jump, dance clips.", tags: ["robot","animated","rigged","community"], glbUrl: "https://three.ws/animations/robotexpressive.glb", image: null, sortDate: "2025-03-31T20:00:00.000Z", attribution: {"handle":"threejs","displayName":"three.js examples","url":"https://github.com/mrdoob/three.js","license":"MIT"}, author: {"handle":"threejs","displayName":"three.js examples","profileUrl":"https://github.com/mrdoob/three.js"} }),+ demoItem({ id: "avatar_demo_disk_claude", slug: "demo-claude", name: "Claude", description: "Claude — calm, thoughtful AI persona on a clean walking rig.", tags: ["humanoid","rigged","animated","community","ai"], glbUrl: "https://three.ws/avatars/cesium-man.glb", image: null, sortDate: "2025-03-31T19:00:00.000Z", attribution: {"handle":"khronos","displayName":"Khronos Group","url":"https://github.com/KhronosGroup/glTF-Sample-Assets","license":"CC-BY 4.0"}, author: {"handle":"khronos","displayName":"Khronos Group","profileUrl":"https://github.com/KhronosGroup/glTF-Sample-Assets"} }),+ demoItem({ id: "avatar_demo_disk_3d", slug: "demo-3d", name: "3D", description: "3D — meta avatar for the platform itself, fully articulated sci-fi rig.", tags: ["robot","rigged","animated","community","meta"], glbUrl: "https://three.ws/avatars/brainstem.glb", image: null, sortDate: "2025-03-31T18:00:00.000Z", attribution: {"handle":"khronos","displayName":"Khronos Group","url":"https://github.com/KhronosGroup/glTF-Sample-Assets","license":"CC-BY 4.0"}, author: {"handle":"khronos","displayName":"Khronos Group","profileUrl":"https://github.com/KhronosGroup/glTF-Sample-Assets"} }),+ demoItem({ id: "avatar_demo_disk_ai", slug: "demo-ai", name: "AI", description: "AI — clean rigged android stand-in, ready for animation retargeting.", tags: ["robot","rigged","animated","community","ai"], glbUrl: "https://three.ws/avatars/xbot.glb", image: null, sortDate: "2025-03-31T17:00:00.000Z", attribution: {"handle":"threejs","displayName":"three.js examples","url":"https://github.com/mrdoob/three.js","license":"MIT"}, author: {"handle":"threejs","displayName":"three.js examples","profileUrl":"https://github.com/mrdoob/three.js"} }),+ demoItem({ id: "avatar_demo_disk_agent", slug: "demo-agent", name: "Agent", description: "Agent — operative ready for autonomous on-chain work.", tags: ["humanoid","rigged","animated","community","agent"], glbUrl: "https://three.ws/animations/soldier.glb", image: null, sortDate: "2025-03-31T16:00:00.000Z", attribution: {"handle":"threejs","displayName":"three.js examples","url":"https://github.com/mrdoob/three.js","license":"MIT"}, author: {"handle":"threejs","displayName":"three.js examples","profileUrl":"https://github.com/mrdoob/three.js"} }),+ demoItem({ id: "avatar_demo_disk_vern", slug: "demo-vern", name: "Vern", description: "Vern — base form, before the Vernington promotion.", tags: ["humanoid","rigged","community"], glbUrl: "https://three.ws/avatars/rigged-figure.glb", image: null, sortDate: "2025-03-31T15:00:00.000Z", attribution: {"handle":"khronos","displayName":"Khronos Group","url":"https://github.com/KhronosGroup/glTF-Sample-Assets","license":"CC-BY 4.0"}, author: {"handle":"khronos","displayName":"Khronos Group","profileUrl":"https://github.com/KhronosGroup/glTF-Sample-Assets"} }),+ demoItem({ id: "avatar_demo_disk_crossinger", slug: "demo-crossinger", name: "Crossinger", description: "Crossinger — chain-hopper, multi-network identity.", tags: ["humanoid","rigged","character","community"], glbUrl: "https://three.ws/avatars/michelle.glb", image: null, sortDate: "2025-03-31T14:00:00.000Z", attribution: {"handle":"threejs","displayName":"three.js examples","url":"https://github.com/mrdoob/three.js","license":"MIT"}, author: {"handle":"threejs","displayName":"three.js examples","profileUrl":"https://github.com/mrdoob/three.js"} }),+ demoItem({ id: "avatar_demo_disk_spartian", slug: "demo-spartian", name: "Spartian", description: "Spartian — disciplined, armored, never folds.", tags: ["humanoid","rigged","animated","community"], glbUrl: "https://three.ws/animations/soldier.glb", image: null, sortDate: "2025-03-31T13:00:00.000Z", attribution: {"handle":"threejs","displayName":"three.js examples","url":"https://github.com/mrdoob/three.js","license":"MIT"}, author: {"handle":"threejs","displayName":"three.js examples","profileUrl":"https://github.com/mrdoob/three.js"} }),demoItem({ id: "avatar_demo_disk_test", slug: "demo-test", name: "Tester", description: "Tester — kicks the tires on every release before anyone else.", tags: ["humanoid","community"], glbUrl: "https://three.ws/avatars/default.glb", image: null, sortDate: "2025-03-31T12:00:00.000Z", attribution: {"handle":"three.ws","displayName":"three.ws starter","url":"https://three.ws","license":"CC-BY 4.0"}, author: {"handle":"three.ws","displayName":"three.ws starter","profileUrl":"https://three.ws"} }),+ demoItem({ id: "avatar_demo_disk_nova", slug: "demo-nova", name: "Nova", description: "Nova — high-detail portrait avatar with an expressive face, built for streams and overlays.", tags: ["humanoid","character","community"], glbUrl: "https://three.ws/avatars/selfie-girl.glb", image: null, sortDate: "2025-03-31T11:00:00.000Z", attribution: {"handle":"three.ws","displayName":"three.ws starter","url":"https://three.ws","license":"CC-BY 4.0"}, author: {"handle":"three.ws","displayName":"three.ws starter","profileUrl":"https://three.ws"} }),+ demoItem({ id: "avatar_demo_disk_foxy", slug: "demo-foxy", name: "Foxy", description: "Foxy — stylized fox mascot with survey, walk, and run animations.", tags: ["animal","mascot","rigged","animated","community"], glbUrl: "https://three.ws/avatars/fox.glb", image: null, sortDate: "2025-03-31T10:00:00.000Z", attribution: {"handle":"khronos","displayName":"Khronos Group","url":"https://github.com/KhronosGroup/glTF-Sample-Assets","license":"CC-BY 4.0"}, author: {"handle":"khronos","displayName":"Khronos Group","profileUrl":"https://github.com/KhronosGroup/glTF-Sample-Assets"} }),];diff --git a/api/_lib/env.js b/api/_lib/env.jsindex 5b84e8e41..6532f7010 100644--- a/api/_lib/env.js+++ b/api/_lib/env.js@@ -109,6 +109,16 @@ export const env = {return opt('GROQ_API_KEY');},+ // NVIDIA NIM API key (build.nvidia.com) — free OpenAI-compatible inference for+ // 100+ hosted models (Nemotron, DeepSeek, Kimi, GLM, Llama 4, Qwen). Used by+ // brain/chat as selectable native providers and by the embed we-pay proxy+ // (api/llm/anthropic.js) as a free fallback tier. Endpoint:+ // https://integrate.api.nvidia.com/v1 — rate-limited free tier, no SLA, so it+ // is positioned as a budget/fallback lane that degrades back to paid providers.+ get NVIDIA_API_KEY() {+ return opt('NVIDIA_API_KEY');+ },+// IBM watsonx.ai (Granite foundation models) — selectable brain in// /api/chat and /api/brain/chat. Requires the API key AND a project (or// space) id; the shared client in _lib/watsonx.js exchanges the key for andiff --git a/api/brain/chat.js b/api/brain/chat.jsindex 827c4ce04..69893a2ae 100644--- a/api/brain/chat.js+++ b/api/brain/chat.js@@ -146,6 +146,68 @@ const PROVIDERS = {description: 'IBM’s open, enterprise-governed foundation model on watsonx.ai.',watsonx: true,},++ // ── NVIDIA NIM (build.nvidia.com) — free hosted inference ────────────────────+ // One free `nvapi-...` key (NVIDIA_API_KEY) unlocks all of these. NVIDIA-hosted,+ // so there is no first-party-vs-OpenRouter split: `native` is the only route and+ // the provider simply shows unavailable until the key is set. Rate-limited free+ // tier — great for experimentation, not a guaranteed-uptime production path.+ 'nvidia-nemotron-120b': {+ label: 'Nemotron 3 Super 120B',+ network: 'NVIDIA NIM',+ tier: 'flagship',+ maxOutput: 16384,+ description: 'NVIDIA’s flagship Nemotron MoE. Strong agentic reasoning, free on NIM.',+ native: () => (env.NVIDIA_API_KEY ? nvidia('nvidia/nemotron-3-super-120b-a12b') : null),+ },+ 'nvidia-nemotron-super-49b': {+ label: 'Llama-Nemotron Super 49B',+ network: 'NVIDIA NIM',+ tier: 'reasoning',+ maxOutput: 16384,+ description: 'Nemotron reasoning model tuned on Llama 3.3. Math, code, planning.',+ native: () => (env.NVIDIA_API_KEY ? nvidia('nvidia/llama-3.3-nemotron-super-49b-v1.5') : null),+ },+ 'nvidia-nemotron-nano': {+ label: 'Nemotron Nano 9B',+ network: 'NVIDIA NIM',+ tier: 'fast',+ maxOutput: 8192,+ description: 'Compact, low-latency Nemotron. Great default for simple agent turns.',+ native: () => (env.NVIDIA_API_KEY ? nvidia('nvidia/nvidia-nemotron-nano-9b-v2') : null),+ },+ 'nvidia-deepseek-v4': {+ label: 'DeepSeek V4 Pro',+ network: 'NVIDIA NIM',+ tier: 'reasoning',+ maxOutput: 16384,+ description: 'DeepSeek V4 Pro hosted on NVIDIA NIM. Deep reasoning, free tier.',+ native: () => (env.NVIDIA_API_KEY ? nvidia('deepseek-ai/deepseek-v4-pro') : null),+ },+ 'nvidia-kimi-k2': {+ label: 'Kimi K2.6',+ network: 'NVIDIA NIM',+ tier: 'flagship',+ maxOutput: 16384,+ description: 'Moonshot Kimi K2.6 on NIM. Long-context agentic model, free tier.',+ native: () => (env.NVIDIA_API_KEY ? nvidia('moonshotai/kimi-k2.6') : null),+ },+ 'nvidia-llama4-maverick': {+ label: 'Llama 4 Maverick',+ network: 'NVIDIA NIM',+ tier: 'balanced',+ maxOutput: 8192,+ description: 'Meta Llama 4 Maverick (128-expert MoE) on NIM. Fast, multimodal-capable.',+ native: () => (env.NVIDIA_API_KEY ? nvidia('meta/llama-4-maverick-17b-128e-instruct') : null),+ },+ 'nvidia-minimax-m2': {+ label: 'MiniMax M2.7',+ network: 'NVIDIA NIM',+ tier: 'balanced',+ maxOutput: 8192,+ description: 'MiniMax M2.7 on NIM. Strong general reasoning and chat, free tier.',+ native: () => (env.NVIDIA_API_KEY ? nvidia('minimaxai/minimax-m2.7') : null),+ },};// Resolve the primary route for a spec: native first-party model when its key is@@ -171,6 +233,16 @@ function buildFallback(spec, primary) {return openrouter()(spec.openrouterModel);}+// NVIDIA NIM (build.nvidia.com) is OpenAI-*compatible* (Chat Completions, not the+// Responses API), so — like Groq, ModelScope and OpenRouter — we force the+// `.chat()` surface. One free `nvapi-...` key unlocks every hosted model.+function nvidia(modelId) {+ return createOpenAI({+ apiKey: env.NVIDIA_API_KEY,+ baseURL: 'https://integrate.api.nvidia.com/v1',+ }).chat(modelId);+}+function openrouter() {const provider = createOpenAI({apiKey: env.OPENROUTER_API_KEY,diff --git a/api/llm/anthropic.js b/api/llm/anthropic.jsindex 0844c0787..a5867f5b5 100644--- a/api/llm/anthropic.js+++ b/api/llm/anthropic.js@@ -57,12 +57,20 @@ const MODELS = {// Groq free tier (sub-second latency; per-IP+per-key minute caps).'llama-3.3-70b-versatile': { kind: 'openai', provider: 'groq', envKey: 'GROQ_API_KEY' },'llama-3.1-8b-instant': { kind: 'openai', provider: 'groq', envKey: 'GROQ_API_KEY' },++ // NVIDIA NIM free tier (build.nvidia.com). One nvapi key, OpenAI-compatible,+ // tool-call capable. Used both as directly-selectable models and as a free+ // fallback ahead of paid Anthropic in the chain below.+ 'nvidia/llama-3.3-nemotron-super-49b-v1.5': { kind: 'openai', provider: 'nvidia', envKey: 'NVIDIA_API_KEY' },+ 'nvidia/nvidia-nemotron-nano-9b-v2': { kind: 'openai', provider: 'nvidia', envKey: 'NVIDIA_API_KEY' },+ 'meta/llama-4-maverick-17b-128e-instruct': { kind: 'openai', provider: 'nvidia', envKey: 'NVIDIA_API_KEY' },};const UPSTREAM_URL = {anthropic: 'https://api.anthropic.com/v1/messages',openrouter: 'https://openrouter.ai/api/v1/chat/completions',groq: 'https://api.groq.com/openai/v1/chat/completions',+ nvidia: 'https://integrate.api.nvidia.com/v1/chat/completions',};const FIRST_PARTY = ['three.ws', 'localhost'];diff --git a/pages/home.html b/pages/home.htmlindex d8856f1b8..7b04d7d73 100644--- a/pages/home.html+++ b/pages/home.html@@ -3245,15 +3245,23 @@#home-pose .hp-slider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 15px; height: 15px; border-radius: 50%; background: var(--text); border: 2px solid #09090a; box-shadow: 0 0 0 1px var(--hairline-strong); cursor: grab; transition: transform .12s; }#home-pose .hp-slider::-webkit-slider-thumb:hover { transform: scale(1.15); }#home-pose .hp-slider::-moz-range-thumb { width: 13px; height: 13px; border-radius: 50%; background: var(--text); border: 2px solid #09090a; cursor: grab; }- #home-pose .hp-actions { display: flex; gap: 10px; margin-top: 4px; }+ #home-pose .hp-mini-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }#home-pose .hp-btn {- flex: 1; text-align: center; font-family: var(--font-mono); font-size: 12.5px; padding: 11px 14px;+ text-align: center; font-family: var(--font-mono); font-size: 12.5px; padding: 11px 14px;border-radius: 10px; border: 1px solid var(--hairline); background: transparent; color: var(--text-2);cursor: pointer; text-decoration: none; transition: border-color .16s, color .16s, background .16s;}#home-pose .hp-btn:hover { color: var(--text); border-color: var(--hairline-strong); }- #home-pose .hp-btn-primary { background: var(--text); color: #09090a; border-color: var(--text); font-weight: 600; }+ #home-pose .hp-btn:focus-visible { outline: 2px solid #4fc3ff; outline-offset: 2px; }+ #home-pose .hp-btn-primary { display: block; background: var(--text); color: #09090a; border-color: var(--text); font-weight: 600; }#home-pose .hp-btn-primary:hover { color: #09090a; background: #e2e2e2; }+ #home-pose .hp-toast {+ position: absolute; left: 50%; top: 16px; transform: translateX(-50%) translateY(-8px);+ font-family: var(--font-mono); font-size: 12px; color: #061015; background: #4fc3ff;+ padding: 7px 14px; border-radius: 999px; opacity: 0; pointer-events: none;+ transition: opacity .2s, transform .2s; z-index: 4;+ }+ #home-pose .hp-toast.is-show { opacity: 1; transform: translateX(-50%) translateY(0); }@media (max-width: 880px) {#home-pose .hp-wrap { grid-template-columns: 1fr; }#home-pose .hp-stage-card { min-height: 400px; }@@ -3272,7 +3280,8 @@<div class="hp-stage-card"><div data-pose-stage></div><div class="hp-stage-hud"><span class="dot"></span>Live rig</div>- <p class="hp-hint" data-pose-hint>Drag to orbit · click a body part to pose it</p>+ <p class="hp-hint" data-pose-hint>Grab a limb to pose it · drag the floor to orbit</p>+ <div class="hp-toast" data-pose-toast aria-live="polite"></div><div class="hp-chips" data-pose-chips role="group" aria-label="Preset poses"></div></div><div class="hp-panel">@@ -3281,10 +3290,12 @@<p class="hp-panel-sel" data-pose-selected>—</p><div class="hp-sliders" data-pose-sliders></div></div>- <div class="hp-actions">- <button type="button" class="hp-btn" data-pose-reset>Reset pose</button>- <a class="hp-btn hp-btn-primary" href="/pose">Open full studio →</a>+ <div class="hp-mini-actions">+ <button type="button" class="hp-btn" data-pose-reset>Reset</button>+ <button type="button" class="hp-btn" data-pose-copy>Copy link</button>+ <button type="button" class="hp-btn" data-pose-snap>Snapshot</button></div>+ <a class="hp-btn hp-btn-primary" href="/pose" data-pose-studio>Open this pose in the full studio →</a></div></div></div>diff --git a/scripts/gen-demo-avatars.mjs b/scripts/gen-demo-avatars.mjsindex d2a620044..556f761ec 100644--- a/scripts/gen-demo-avatars.mjs+++ b/scripts/gen-demo-avatars.mjs@@ -18,26 +18,35 @@ const THREEJS = fs.readFileSync(path.join(HERE, 'threejs-glbs.txt'), 'utf8').tri.map((s) => s.replace(/\.glb$/, '')).filter(Boolean);// Curated community-avatar lineup. Each entry is a named identity rendered with-// a real GLB shipped under /public. The mapping from name → GLB is intentional:-// soldier-rigs go to operative/military-leaning personas, the expressive robot-// goes to AI/protocol personas, the default humanoid covers the rest.+// a real GLB shipped under /public, and every persona maps to a *visually+// distinct* model — no two share a silhouette unless the personas are thematic+// siblings (Boss/Agent/Spartian all run the soldier rig on purpose). Soldier+// rigs go to operative personas, robot rigs to AI/protocol personas, and the+// human rigs are spread across the rest so the gallery reads as a real roster.+//+// `attr` selects the license/attribution block (see *_ATTR below): 'threejs'+// for MIT three.js example models, 'khronos' for CC-BY 4.0 Khronos sample+// assets, and the default (omitted) for first-party three.ws starter assets.const ON_DISK = [{ name: 'CZ', slug: 'cz', path: '/avatars/cz.glb', tags: ['humanoid', 'character', 'community'], desc: 'CZ — stylized humanoid with idle pose, ready for chat overlays.' },{ name: 'Ansem', slug: 'ansem', path: '/avatars/default.glb', tags: ['humanoid', 'community', 'trader'], desc: 'Ansem — trader persona for chart-watchers and crypto Twitter.' },- { name: 'Boss', slug: 'boss', path: '/animations/soldier.glb', tags: ['humanoid', 'rigged', 'animated', 'community'], desc: 'Boss — for the one running the room. Soldier rig with locomotion.' },- { name: 'Vernington', slug: 'vernington', path: '/avatars/default.glb', tags: ['humanoid', 'community'], desc: 'Vernington — the senior of the Vern lineage.' },- { name: 'Saga', slug: 'saga', path: '/animations/robotexpressive.glb', tags: ['robot', 'animated', 'rigged', 'community'], desc: 'Saga — mobile-native, expressive robot rig with idle, walk, jump, dance clips.' },- { name: 'Claude', slug: 'claude', path: '/avatars/default.glb', tags: ['humanoid', 'community', 'ai'], desc: 'Claude — calm, thoughtful AI persona.' },- { name: '3D', slug: '3d', path: '/avatars/default.glb', tags: ['humanoid', 'community', 'meta'], desc: '3D — meta avatar representing the platform itself.' },- { name: 'AI', slug: 'ai', path: '/animations/robotexpressive.glb', tags: ['robot', 'animated', 'rigged', 'community', 'ai'], desc: 'AI — generic agent stand-in, expressive robot rig.' },- { name: 'Agent', slug: 'agent', path: '/animations/soldier.glb', tags: ['humanoid', 'rigged', 'animated', 'community', 'agent'], desc: 'Agent — operative ready for autonomous on-chain work.' },- { name: 'Vern', slug: 'vern', path: '/avatars/default.glb', tags: ['humanoid', 'community'], desc: 'Vern — base form, before the Vernington promotion.' },- { name: 'Crossinger', slug: 'crossinger', path: '/avatars/default.glb', tags: ['humanoid', 'community'], desc: 'Crossinger — chain-hopper, multi-network identity.' },- { name: 'Spartian', slug: 'spartian', path: '/animations/soldier.glb', tags: ['humanoid', 'rigged', 'animated', 'community'], desc: 'Spartian — disciplined, armored, never folds.' },+ { name: 'Boss', slug: 'boss', path: '/animations/soldier.glb', tags: ['humanoid', 'rigged', 'animated', 'community'], desc: 'Boss — for the one running the room. Soldier rig with locomotion.', attr: 'threejs' },+ { name: 'Vernington', slug: 'vernington', path: '/avatars/readyplayerme.glb', tags: ['humanoid', 'rigged', 'avatar', 'community'], desc: 'Vernington — the senior of the Vern lineage, full-body ready-player rig.', attr: 'threejs' },+ { name: 'Saga', slug: 'saga', path: '/animations/robotexpressive.glb', tags: ['robot', 'animated', 'rigged', 'community'], desc: 'Saga — mobile-native, expressive robot rig with idle, walk, jump, dance clips.', attr: 'threejs' },+ { name: 'Claude', slug: 'claude', path: '/avatars/cesium-man.glb', tags: ['humanoid', 'rigged', 'animated', 'community', 'ai'], desc: 'Claude — calm, thoughtful AI persona on a clean walking rig.', attr: 'khronos' },+ { name: '3D', slug: '3d', path: '/avatars/brainstem.glb', tags: ['robot', 'rigged', 'animated', 'community', 'meta'], desc: '3D — meta avatar for the platform itself, fully articulated sci-fi rig.', attr: 'khronos' },+ { name: 'AI', slug: 'ai', path: '/avatars/xbot.glb', tags: ['robot', 'rigged', 'animated', 'community', 'ai'], desc: 'AI — clean rigged android stand-in, ready for animation retargeting.', attr: 'threejs' },+ { name: 'Agent', slug: 'agent', path: '/animations/soldier.glb', tags: ['humanoid', 'rigged', 'animated', 'community', 'agent'], desc: 'Agent — operative ready for autonomous on-chain work.', attr: 'threejs' },+ { name: 'Vern', slug: 'vern', path: '/avatars/rigged-figure.glb', tags: ['humanoid', 'rigged', 'community'], desc: 'Vern — base form, before the Vernington promotion.', attr: 'khronos' },+ { name: 'Crossinger', slug: 'crossinger', path: '/avatars/michelle.glb', tags: ['humanoid', 'rigged', 'character', 'community'], desc: 'Crossinger — chain-hopper, multi-network identity.', attr: 'threejs' },+ { name: 'Spartian', slug: 'spartian', path: '/animations/soldier.glb', tags: ['humanoid', 'rigged', 'animated', 'community'], desc: 'Spartian — disciplined, armored, never folds.', attr: 'threejs' },// Name surfaced as "Tester" because the marketplace UI auto-name filter// strips entries whose name is exactly "test" (see AVATAR_AUTONAMED_RE in// src/marketplace.js). Slug stays `test` to preserve the requested handle.{ name: 'Tester', slug: 'test', path: '/avatars/default.glb', tags: ['humanoid', 'community'], desc: 'Tester — kicks the tires on every release before anyone else.' },+ // New distinct characters that widen the gallery beyond the starter trio.+ { name: 'Nova', slug: 'nova', path: '/avatars/selfie-girl.glb', tags: ['humanoid', 'character', 'community'], desc: 'Nova — high-detail portrait avatar with an expressive face, built for streams and overlays.' },+ { name: 'Foxy', slug: 'foxy', path: '/avatars/fox.glb', tags: ['animal', 'mascot', 'rigged', 'animated', 'community'], desc: 'Foxy — stylized fox mascot with survey, walk, and run animations.', attr: 'khronos' },];// Curated metadata for well-known Khronos models. Anything not listed here gets@@ -260,6 +269,7 @@ const THREEJS_ATTR = { handle: 'threejs', displayName: 'three.js examples', url:const ONDISK_ATTR = { handle: 'three.ws', displayName: 'three.ws starter', url: 'https://three.ws', license: 'CC-BY 4.0' };// On-disk first+const ATTR_BY_KEY = { khronos: KHRONOS_ATTR, threejs: THREEJS_ATTR, ondisk: ONDISK_ATTR };for (const m of ON_DISK) {addItem({id: `avatar_demo_disk_${m.slug}`,@@ -269,7 +279,7 @@ for (const m of ON_DISK) {image: null,tags: m.tags,desc: m.desc,- attribution: ONDISK_ATTR,+ attribution: ATTR_BY_KEY[m.attr] || ONDISK_ATTR,});}diff --git a/src/home-pose.js b/src/home-pose.jsindex b75a54560..467d032db 100644--- a/src/home-pose.js+++ b/src/home-pose.js@@ -1,11 +1,15 @@-// Homepage "Pose it here" demo — a lite, embeddable slice of /pose.-// Reuses the exact same primitive Mannequin and preset library the full Pose-// Studio runs on, wrapped in a self-contained Three.js stage: orbit the camera,-// click a body part to select it, drag the X/Y/Z sliders to pose that joint, or-// tap a preset to morph the whole figure. No fake data — this is the real rig.+// Homepage "Pose it here" demo — a lite, fully-interactive slice of /pose.+// Runs the exact MannequinRig the full studio runs on, so every interaction is+// real: orbit the camera, GRAB a limb and move it (CCD inverse kinematics on+// hands & feet, world-space trackball rotation on every other joint), drag the+// X/Y/Z sliders for precision, or tap a preset to morph the whole figure. The+// figure idles with a faint breathing sway and slowly auto-orbits until you+// touch it, so the section is never a dead grey statue. Snapshot the pose to a+// PNG, or carry the exact pose into the full studio via a shareable link.//-// The render loop is gated on visibility (IntersectionObserver) so the homepage-// stays smooth: the WebGL context idles whenever the section is off-screen.+// The render loop is gated on visibility (IntersectionObserver): the WebGL+// context idles whenever the section scrolls off-screen, keeping the homepage+// smooth.import {AmbientLight,@@ -17,6 +21,8 @@ import {MeshBasicMaterial,PCFSoftShadowMap,PerspectiveCamera,+ Plane,+ Quaternion,Raycaster,Scene,ShadowMaterial,@@ -27,28 +33,34 @@ import {} from 'three';import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';-import {- Mannequin,- JOINT_LABELS,- JOINT_AXIS_LABELS,-} from './pose-mannequin.js';+import { MannequinRig } from './pose-rig.js';+import { JOINT_LABELS, JOINT_AXIS_LABELS } from './pose-mannequin.js';import { getPresetById } from './pose-presets.js';+import { encodePose } from './pose-share.js';// Curated spread of presets for the lite demo — one or two from each group so// the chip row reads like a tour without overwhelming the homepage.const DEMO_PRESET_IDS = [- 'relaxed',- 'tpose',- 'wave',- 'hands-on-hips',- 'run',- 'jump',- 'superhero-landing',- 'sit-chair',- 'thinker',- 'warrior2',- 'flex',- 'meditate',+ 'relaxed', 'tpose', 'wave', 'hands-on-hips', 'run', 'jump',+ 'superhero-landing', 'sit-chair', 'thinker', 'warrior2', 'flex', 'meditate',+];++// Mannequin joints that drive a CCD IK chain when grabbed — drag the hand/foot+// and the limb reaches for the cursor. Everything else trackball-rotates.+const IK_EFFECTOR = {+ wristL: 'LeftHand', wristR: 'RightHand',+ ankleL: 'LeftFoot', ankleR: 'RightFoot',+};++// Joints that breathe when idle, and the per-axis sway amplitude (radians).+// Kept tiny — this should read as "alive," not "wobbling."+const BREATH = [+ { joint: 'chest', axis: 'x', amp: 0.018, freq: 1.1, phase: 0 },+ { joint: 'spine', axis: 'x', amp: 0.010, freq: 1.1, phase: 0 },+ { joint: 'head', axis: 'y', amp: 0.013, freq: 0.5, phase: 0.4 },+ { joint: 'head', axis: 'x', amp: 0.009, freq: 0.9, phase: 1.2 },+ { joint: 'shoulderL', axis: 'z', amp: 0.012, freq: 1.1, phase: 0 },+ { joint: 'shoulderR', axis: 'z', amp: -0.012, freq: 1.1, phase: 0 },];const DEG = 180 / Math.PI;@@ -82,6 +94,10 @@ export function initHomePose(root) {const selLabel = root.querySelector('[data-pose-selected]');const hint = root.querySelector('[data-pose-hint]');const resetBtn = root.querySelector('[data-pose-reset]');+ const copyBtn = root.querySelector('[data-pose-copy]');+ const snapBtn = root.querySelector('[data-pose-snap]');+ const studioLink = root.querySelector('[data-pose-studio]');+ const toastEl = root.querySelector('[data-pose-toast]');if (!stage || !chipRow || !sliderHost) return;// ── Scene ───────────────────────────────────────────────────────────@@ -92,6 +108,8 @@ export function initHomePose(root) {canvas,antialias: true,alpha: true,+ // Required so the snapshot can read the drawing buffer back as a PNG.+ preserveDrawingBuffer: true,powerPreference: 'high-performance',});renderer.setPixelRatio(Math.min(2, window.devicePixelRatio || 1));@@ -112,11 +130,12 @@ export function initHomePose(root) {controls.minPolarAngle = 0.35;controls.maxPolarAngle = Math.PI * 0.52;controls.rotateSpeed = 0.85;+ controls.autoRotate = !prefersReducedMotion;+ controls.autoRotateSpeed = 0.55;// ── Lighting ────────────────────────────────────────────────────────scene.add(new AmbientLight(0xffffff, 0.55));- const hemi = new HemisphereLight(0xffffff, 0x202024, 0.6);- scene.add(hemi);+ scene.add(new HemisphereLight(0xffffff, 0x202024, 0.6));const key = new DirectionalLight(0xffffff, 1.5);key.position.set(2.6, 4.2, 2.4);key.castShadow = true;@@ -134,31 +153,25 @@ export function initHomePose(root) {rim.position.set(-3, 2, -2.5);scene.add(rim);- // ── Ground (shadow catcher + faint disc) ────────────────────────────- const disc = new Mesh(- new CircleGeometry(3.4, 64),- new MeshBasicMaterial({ color: new Color(0x0c0c0d) }),- );+ // ── Ground (faint disc + shadow catcher) ────────────────────────────+ const disc = new Mesh(new CircleGeometry(3.4, 64), new MeshBasicMaterial({ color: 0x0c0c0d }));disc.rotation.x = -Math.PI / 2;disc.position.y = -0.001;scene.add(disc);-- const shadowCatcher = new Mesh(- new CircleGeometry(3.4, 64),- new ShadowMaterial({ opacity: 0.42 }),- );+ const shadowCatcher = new Mesh(new CircleGeometry(3.4, 64), new ShadowMaterial({ opacity: 0.42 }));shadowCatcher.rotation.x = -Math.PI / 2;shadowCatcher.receiveShadow = true;scene.add(shadowCatcher);- // ── Mannequin ───────────────────────────────────────────────────────- const mannequin = new Mannequin({ build: 'male', color: '#e6e6ea' });- mannequin.setConstraintsEnabled(true);- scene.add(mannequin.root);+ // ── Rig (the real MannequinRig — same as the full studio) ────────────+ const rig = new MannequinRig({ build: 'male', color: '#e6e6ea' });+ rig.setConstraintsEnabled(true);+ const man = rig.mannequin;+ scene.add(rig.root);- // Selection marker — a soft glowing orb pinned to the active joint.- // (The mannequin shares materials across the body, so we can't tint one- // joint via emissive; an overlay marker selects without side effects.)+ // Selection marker — a soft glowing orb pinned to the active joint. (The+ // mannequin shares materials across the body, so a per-joint emissive tint+ // is impossible; an overlay marker selects without side effects.)const marker = new Mesh(new SphereGeometry(0.05, 20, 16),new MeshBasicMaterial({ color: 0x4fc3ff, transparent: true, opacity: 0.9 }),@@ -177,161 +190,239 @@ export function initHomePose(root) {const pointer = new Vector2();const tmpVec = new Vector3();- // Pose tween (preset morph). Captures start/target euler per joint + root.- let tween = null;-- function captureEuler() {- const pose = {};- for (const name of Object.keys(mannequin.joints)) {- const r = mannequin.joints[name].rotation;- pose[name] = { x: r.x, y: r.y, z: r.z };+ // committed = the user's "real" pose (euler per joint + root); breathing is+ // layered on top each frame without corrupting it.+ const committed = {};+ function captureCommitted() {+ for (const name of Object.keys(man.joints)) {+ const r = man.joints[name].rotation;+ committed[name] = { x: r.x, y: r.y, z: r.z };}- pose.rootPosition = {- x: mannequin.root.position.x,- y: mannequin.root.position.y,- z: mannequin.root.position.z,- };- return pose;+ committed.rootY = man.root.position.y;+ committed.rootX = man.root.position.x;+ committed.rootZ = man.root.position.z;+ updateStudioHref();}+ // ── Preset morph (eased tween over the euler pose) ──────────────────+ let tween = null;function targetFromPreset(preset) {const target = {};- for (const name of Object.keys(mannequin.joints)) {+ for (const name of Object.keys(man.joints)) {const r = preset.pose[name];target[name] = { x: r?.x || 0, y: r?.y || 0, z: r?.z || 0 };}const rp = preset.pose.rootPosition;- target.rootPosition = { x: rp?.x || 0, y: rp?.y || 0, z: rp?.z || 0 };+ target.root = { x: rp?.x || 0, y: rp?.y || 0, z: rp?.z || 0 };return target;}-- function applyEuler(pose) {- for (const name of Object.keys(mannequin.joints)) {- const r = pose[name];- if (!r) continue;- mannequin.joints[name].rotation.set(r.x, r.y, r.z);+ function applyEuler(target) {+ for (const name of Object.keys(man.joints)) {+ const r = target[name];+ if (r) man.joints[name].rotation.set(r.x, r.y, r.z);}- if (pose.rootPosition) {- mannequin.root.position.set(- pose.rootPosition.x,- pose.rootPosition.y,- pose.rootPosition.z,- );+ if (target.root) man.root.position.set(target.root.x, target.root.y, target.root.z);+ }+ function snapshotEuler() {+ const from = {};+ for (const name of Object.keys(man.joints)) {+ const r = man.joints[name].rotation;+ from[name] = { x: r.x, y: r.y, z: r.z };}+ from.root = { x: man.root.position.x, y: man.root.position.y, z: man.root.position.z };+ return from;}-function morphToPreset(preset) {const target = targetFromPreset(preset);if (prefersReducedMotion) {applyEuler(target);+ captureCommitted();refreshSliders();return;}- tween = { from: captureEuler(), to: target, t: 0, dur: 0.55 };+ tween = { from: snapshotEuler(), to: target, t: 0, dur: 0.55 };}-function advanceTween(dt) {if (!tween) return;tween.t = Math.min(1, tween.t + dt / tween.dur);const k = easeInOutCubic(tween.t);const { from, to } = tween;- for (const name of Object.keys(mannequin.joints)) {+ for (const name of Object.keys(man.joints)) {const a = from[name];const b = to[name];if (!a || !b) continue;- mannequin.joints[name].rotation.set(+ man.joints[name].rotation.set(a.x + (b.x - a.x) * k,a.y + (b.y - a.y) * k,a.z + (b.z - a.z) * k,);}- mannequin.root.position.set(- from.rootPosition.x + (to.rootPosition.x - from.rootPosition.x) * k,- from.rootPosition.y + (to.rootPosition.y - from.rootPosition.y) * k,- from.rootPosition.z + (to.rootPosition.z - from.rootPosition.z) * k,+ man.root.position.set(+ from.root.x + (to.root.x - from.root.x) * k,+ from.root.y + (to.root.y - from.root.y) * k,+ from.root.z + (to.root.z - from.root.z) * k,);if (tween.t >= 1) {tween = null;+ captureCommitted();refreshSliders();}}- // ── Selection ───────────────────────────────────────────────────────- function selectJoint(name) {- selected = name;- if (selLabel) selLabel.textContent = name ? JOINT_LABELS[name] || name : '—';- if (hint) hint.hidden = !!name;- marker.visible = !!name;- buildSliders(name);+ // ── Idle breathing ──────────────────────────────────────────────────+ function applyBreathing(t) {+ for (const name of Object.keys(man.joints)) {+ const c = committed[name];+ if (c) man.joints[name].rotation.set(c.x, c.y, c.z);+ }+ for (const b of BREATH) {+ const j = man.joints[b.joint];+ const c = committed[b.joint];+ if (!j || !c) continue;+ j.rotation[b.axis] = c[b.axis] + Math.sin(t * b.freq + b.phase) * b.amp;+ }+ man.root.position.y = (committed.rootY || 0) + Math.sin(t * 1.1) * 0.004;}- function pickFromEvent(e) {+ // ── Direct manipulation (grab-to-pose) ──────────────────────────────+ let drag = null; // { mode:'ik'|'fk', joint, effectorKey, plane, lastX, lastY }+ const camDir = new Vector3();+ const camRight = new Vector3();+ const camUp = new Vector3();+ const dragPlane = new Plane();+ const ikTarget = new Vector3();+ const qWorld = new Quaternion();+ const qParent = new Quaternion();+ const qDelta = new Quaternion();+ const qAxis = new Quaternion();++ function setPointer(e) {const rect = canvas.getBoundingClientRect();pointer.x = ((e.clientX - rect.left) / rect.width) * 2 - 1;pointer.y = -((e.clientY - rect.top) / rect.height) * 2 + 1;+ }++ function hitJoint(e) {+ setPointer(e);raycaster.setFromCamera(pointer, camera);- const hits = raycaster.intersectObjects(mannequin.selectableMeshes, false);- if (!hits.length) return;- const name = mannequin.jointFromHit(hits[0].object);- if (name) selectJoint(name);+ const hits = raycaster.intersectObjects(man.selectableMeshes, false);+ if (!hits.length) return null;+ return man.jointFromHit(hits[0].object);}- // Distinguish a click (select) from an orbit drag.- let downPos = null;- canvas.addEventListener('pointerdown', (e) => {- downPos = { x: e.clientX, y: e.clientY };- });- canvas.addEventListener('pointerup', (e) => {- if (!downPos) return;- const moved = Math.hypot(e.clientX - downPos.x, e.clientY - downPos.y);- downPos = null;- if (moved < 5) pickFromEvent(e);- });+ // Capture phase so we can veto OrbitControls before it engages: grabbing a+ // body part poses it; grabbing empty space orbits the camera.+ function onDown(e) {+ const joint = hitJoint(e);+ if (!joint) return; // let OrbitControls handle the orbit+ stopAutoOrbit();+ controls.enabled = false;+ selectJoint(joint);+ const effectorKey = IK_EFFECTOR[joint];+ if (effectorKey && rig.getNode(effectorKey)) {+ rig.getNode(effectorKey).getWorldPosition(tmpVec);+ camera.getWorldDirection(camDir);+ dragPlane.setFromNormalAndCoplanarPoint(camDir, tmpVec);+ drag = { mode: 'ik', joint, effectorKey };+ } else {+ drag = { mode: 'fk', joint, lastX: e.clientX, lastY: e.clientY };+ }+ canvas.setPointerCapture?.(e.pointerId);+ }++ function onMove(e) {+ if (!drag) return;+ if (drag.mode === 'ik') {+ setPointer(e);+ raycaster.setFromCamera(pointer, camera);+ if (raycaster.ray.intersectPlane(dragPlane, ikTarget)) {+ rig.solveIK(drag.effectorKey, ikTarget);+ }+ } else {+ const j = man.joints[drag.joint];+ if (!j || !j.parent) return;+ const dx = e.clientX - drag.lastX;+ const dy = e.clientY - drag.lastY;+ drag.lastX = e.clientX;+ drag.lastY = e.clientY;+ camRight.setFromMatrixColumn(camera.matrixWorld, 0).normalize();+ camUp.setFromMatrixColumn(camera.matrixWorld, 1).normalize();+ const k = 0.011;+ qDelta+ .setFromAxisAngle(camUp, dx * k)+ .multiply(qAxis.setFromAxisAngle(camRight, dy * k));+ // Apply the screen-space delta in world space, then convert back to+ // the joint's local frame (its parent's world rotation is fixed here).+ j.getWorldQuaternion(qWorld);+ j.parent.getWorldQuaternion(qParent);+ qWorld.premultiply(qDelta);+ j.quaternion.copy(qParent.invert().multiply(qWorld));+ }+ refreshSliders();+ }++ function endDrag(e) {+ if (!drag) return;+ canvas.releasePointerCapture?.(e.pointerId);+ drag = null;+ controls.enabled = true;+ captureCommitted();+ }++ canvas.addEventListener('pointerdown', onDown, true);+ window.addEventListener('pointermove', onMove);+ window.addEventListener('pointerup', endDrag);+ window.addEventListener('pointercancel', endDrag);++ // ── Selection + sliders ─────────────────────────────────────────────+ function selectJoint(name) {+ selected = name;+ if (selLabel) selLabel.textContent = name ? JOINT_LABELS[name] || name : '—';+ if (hint) hint.hidden = !!name;+ marker.visible = !!name;+ buildSliders(name);+ }- // ── Sliders ─────────────────────────────────────────────────────────const sliderRefs = {};function buildSliders(name) {sliderHost.replaceChildren();for (const k of Object.keys(sliderRefs)) delete sliderRefs[k];if (!name) {- sliderHost.appendChild(- el('p', { class: 'hp-sliders-empty', text: 'Select a joint to reveal its controls.' }),- );+ sliderHost.appendChild(el('p', {+ class: 'hp-sliders-empty',+ text: 'Grab the figure to pose a joint — or pick one here.',+ }));return;}const axisLabels = JOINT_AXIS_LABELS[name] || JOINT_AXIS_LABELS.default;for (const axis of ['x', 'y', 'z']) {const value = el('span', { class: 'hp-slider-val' });const input = el('input', {- type: 'range',- min: '-180',- max: '180',- step: '1',- class: 'hp-slider',+ type: 'range', min: '-180', max: '180', step: '1', class: 'hp-slider','aria-label': `${JOINT_LABELS[name] || name} ${axisLabels[axis]}`,oninput: () => {- const rad = Number(input.value) * RAD;- mannequin.setJointRotation(name, axis, rad);- value.textContent = `${Math.round(mannequin.getJointRotation(name)[axis] * DEG)}°`;+ stopAutoOrbit();+ man.setJointRotation(name, axis, Number(input.value) * RAD);+ committed[name] = { ...man.getJointRotation(name) };+ value.textContent = `${Math.round(man.getJointRotation(name)[axis] * DEG)}°`;+ updateStudioHref();},});sliderRefs[axis] = { input, value };- sliderHost.appendChild(- el('div', { class: 'hp-slider-row' }, [- el('div', { class: 'hp-slider-head' }, [- el('span', { class: 'hp-slider-axis', text: axisLabels[axis] }),- value,- ]),- input,+ sliderHost.appendChild(el('div', { class: 'hp-slider-row' }, [+ el('div', { class: 'hp-slider-head' }, [+ el('span', { class: 'hp-slider-axis', text: axisLabels[axis] }),+ value,]),- );+ input,+ ]));}refreshSliders();}function refreshSliders() {if (!selected) return;- const rot = mannequin.getJointRotation(selected);+ const rot = man.getJointRotation(selected);for (const axis of ['x', 'y', 'z']) {const ref = sliderRefs[axis];if (!ref) continue;@@ -346,10 +437,9 @@ export function initHomePose(root) {const preset = getPresetById(id);if (!preset) continue;const chip = el('button', {- type: 'button',- class: 'hp-chip',- text: preset.label,+ type: 'button', class: 'hp-chip', text: preset.label,onclick: () => {+ stopAutoOrbit();morphToPreset(preset);if (activeChip) activeChip.classList.remove('is-active');chip.classList.add('is-active');@@ -359,17 +449,74 @@ export function initHomePose(root) {chipRow.appendChild(chip);}- if (resetBtn) {- resetBtn.addEventListener('click', () => {- const relaxed = getPresetById('relaxed');- if (relaxed) morphToPreset(relaxed);- if (activeChip) {- activeChip.classList.remove('is-active');- activeChip = null;- }- });+ // ── Actions: reset / copy link / snapshot ───────────────────────────+ function clearActiveChip() {+ if (activeChip) { activeChip.classList.remove('is-active'); activeChip = null; }+ }+ resetBtn?.addEventListener('click', () => {+ const relaxed = getPresetById('relaxed');+ if (relaxed) morphToPreset(relaxed);+ clearActiveChip();+ });++ let toastTimer = 0;+ function toast(msg) {+ if (!toastEl) return;+ toastEl.textContent = msg;+ toastEl.classList.add('is-show');+ clearTimeout(toastTimer);+ toastTimer = setTimeout(() => toastEl.classList.remove('is-show'), 2000);}+ function poseUrl() {+ return `${window.location.origin}/pose#p=${encodePose(rig.getPose())}`;+ }+ function updateStudioHref() {+ if (studioLink) studioLink.href = poseUrl();+ }+ copyBtn?.addEventListener('click', async () => {+ const url = poseUrl();+ try {+ await navigator.clipboard.writeText(url);+ toast('Pose link copied');+ } catch {+ // Clipboard blocked (no permission / insecure context) — fall back to+ // navigating the user to their pose in the full studio.+ window.open(url, '_blank', 'noopener');+ }+ });++ snapBtn?.addEventListener('click', () => {+ const W = 1600, H = 1200;+ const prevW = stage.clientWidth, prevH = stage.clientHeight;+ const hadBg = scene.background;+ const markerWasVisible = marker.visible;+ marker.visible = false;+ scene.background = new Color(0x0a0a0b);+ renderer.setSize(W, H, false);+ camera.aspect = W / H;+ camera.updateProjectionMatrix();+ renderer.render(scene, camera);+ const dataUrl = canvas.toDataURL('image/png');+ // Restore the live view.+ scene.background = hadBg;+ marker.visible = markerWasVisible;+ renderer.setSize(prevW, prevH, false);+ camera.aspect = (prevW || 1) / (prevH || 1);+ camera.updateProjectionMatrix();+ const a = el('a', { href: dataUrl, download: 'three-ws-pose.png' });+ document.body.appendChild(a);+ a.click();+ a.remove();+ toast('Pose saved as PNG');+ });++ // ── Auto-orbit (stops on first interaction) ─────────────────────────+ function stopAutoOrbit() {+ if (controls.autoRotate) controls.autoRotate = false;+ }+ controls.addEventListener('start', stopAutoOrbit);+// ── Render loop (visibility-gated) ──────────────────────────────────let running = false;let last = 0;@@ -389,13 +536,13 @@ export function initHomePose(root) {rafId = requestAnimationFrame(frame);const dt = last ? Math.min(0.05, (now - last) / 1000) : 0.016;last = now;- advanceTween(dt);- if (selected && mannequin.joints[selected]) {- mannequin.joints[selected].getWorldPosition(tmpVec);+ if (tween) advanceTween(dt);+ else if (!drag && !prefersReducedMotion) applyBreathing(now / 1000);+ if (selected && man.joints[selected]) {+ man.joints[selected].getWorldPosition(tmpVec);marker.position.copy(tmpVec);}- const pulse = 0.9 + Math.sin(now / 320) * 0.12;- markerHalo.scale.setScalar(pulse);+ markerHalo.scale.setScalar(0.9 + Math.sin(now / 320) * 0.12);controls.update();renderer.render(scene, camera);}@@ -413,23 +560,15 @@ export function initHomePose(root) {rafId = 0;}- const ro = new ResizeObserver(resize);- ro.observe(stage);-- const io = new IntersectionObserver(- (entries) => {- for (const entry of entries) {- if (entry.isIntersecting) start();- else stop();- }- },- { threshold: 0.08 },- );- io.observe(stage);+ new ResizeObserver(resize).observe(stage);+ new IntersectionObserver((entries) => {+ for (const entry of entries) entry.isIntersecting ? start() : stop();+ }, { threshold: 0.08 }).observe(stage);// ── First pose ──────────────────────────────────────────────────────const initial = getPresetById('relaxed');if (initial) applyEuler(targetFromPreset(initial));+ captureCommitted();buildSliders(null);resize();}diff --git a/src/pose-share.js b/src/pose-share.jsnew file mode 100644index 000000000..0cc19e0b1--- /dev/null+++ b/src/pose-share.js@@ -0,0 +1,107 @@+// Compact, URL-safe codec for a canonical pose — the bridge that lets the+// homepage demo hand its exact pose to the full Pose Studio (and back).+//+// A pose is the canonical quaternion shape every rig speaks (see pose-rig.js):+// { bones: { Hips:[x,y,z,w], … }, rootPosition:{ x, y, z } }+// We pack only the bones actually present, addressing each by its index in+// CANONICAL_BONES, and quantize quaternion components to int16 and root+// translation to millimetres. ~17 bones encodes to a ~220-char hash — small+// enough to live in a URL fragment, lossless to the eye.++import { CANONICAL_BONES } from './pose-rig.js';++const VERSION = 1;+const Q_SCALE = 32767; // quaternion component (−1..1) → int16+const ROOT_SCALE = 1000; // metres → millimetres (int16 reaches ±32.7 m)++const clampI16 = (n) => Math.max(-32768, Math.min(32767, n | 0));++function bytesToB64url(bytes) {+ let bin = '';+ for (let i = 0; i < bytes.length; i++) bin += String.fromCharCode(bytes[i]);+ return btoa(bin).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');+}++function b64urlToBytes(str) {+ let s = str.replace(/-/g, '+').replace(/_/g, '/');+ while (s.length % 4) s += '=';+ const bin = atob(s);+ const out = new Uint8Array(bin.length);+ for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);+ return out;+}++export function encodePose(pose) {+ const bones = pose?.bones || {};+ const entries = [];+ for (let i = 0; i < CANONICAL_BONES.length; i++) {+ const v = bones[CANONICAL_BONES[i]];+ if (Array.isArray(v) && v.length >= 4) entries.push([i, v]);+ }+ const rp = pose?.rootPosition;+ const hasRoot = !!(rp && (rp.x || rp.y || rp.z));++ const size = 2 + entries.length * 9 + 1 + (hasRoot ? 6 : 0);+ const dv = new DataView(new ArrayBuffer(size));+ let o = 0;+ dv.setUint8(o++, VERSION);+ dv.setUint8(o++, entries.length);+ for (const [idx, v] of entries) {+ dv.setUint8(o++, idx);+ for (let k = 0; k < 4; k++) {+ dv.setInt16(o, clampI16(Math.round(v[k] * Q_SCALE)));+ o += 2;+ }+ }+ dv.setUint8(o++, hasRoot ? 1 : 0);+ if (hasRoot) {+ dv.setInt16(o, clampI16(Math.round((rp.x || 0) * ROOT_SCALE))); o += 2;+ dv.setInt16(o, clampI16(Math.round((rp.y || 0) * ROOT_SCALE))); o += 2;+ dv.setInt16(o, clampI16(Math.round((rp.z || 0) * ROOT_SCALE))); o += 2;+ }+ return bytesToB64url(new Uint8Array(dv.buffer));+}++export function decodePose(str) {+ if (!str) return null;+ try {+ const bytes = b64urlToBytes(str);+ const dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);+ let o = 0;+ if (dv.getUint8(o++) !== VERSION) return null;+ const count = dv.getUint8(o++);+ const bones = {};+ for (let e = 0; e < count; e++) {+ const key = CANONICAL_BONES[dv.getUint8(o++)];+ const q = [];+ for (let k = 0; k < 4; k++) { q.push(dv.getInt16(o) / Q_SCALE); o += 2; }+ // Renormalize — int16 quantization nudges the quaternion off the unit+ // sphere, and three.js expects unit quaternions for clean rotations.+ const len = Math.hypot(q[0], q[1], q[2], q[3]) || 1;+ if (key) bones[key] = [q[0] / len, q[1] / len, q[2] / len, q[3] / len];+ }+ const pose = { bones };+ if (dv.getUint8(o++)) {+ pose.rootPosition = {+ x: dv.getInt16(o) / ROOT_SCALE,+ y: dv.getInt16(o + 2) / ROOT_SCALE,+ z: dv.getInt16(o + 4) / ROOT_SCALE,+ };+ }+ return pose;+ } catch {+ return null;+ }+}++// Pull a shared pose out of a URL fragment or query (#p=… or ?p=…).+export function decodePoseFromLocation(href = window.location.href) {+ try {+ const url = new URL(href);+ const fromHash = /[#&]p=([^&]+)/.exec(url.hash);+ const raw = fromHash ? fromHash[1] : url.searchParams.get('p');+ return raw ? decodePose(decodeURIComponent(raw)) : null;+ } catch {+ return null;+ }+}diff --git a/src/pose-studio.js b/src/pose-studio.jsindex 4d36673ae..f3f15a830 100644--- a/src/pose-studio.js+++ b/src/pose-studio.js@@ -43,6 +43,7 @@ import {poseFromMannequinPreset,} from './pose-rig.js';import { PRESETS, getPresetsByGroup, getPresetById } from './pose-presets.js';+import { decodePoseFromLocation } from './pose-share.js';import { AvatarGalleryPicker } from './avatar-gallery-picker.js';import {createDocument,@@ -399,9 +400,16 @@ function boot() {mountRig(mannequinRig);state.avatar = null;- // Pick a reasonable starting pose so the figure looks alive on load.- const intro = getPresetById('contrapposto');- if (intro) state.rig.applyPose(poseFromMannequinPreset(intro.pose));+ // A pose handed over from elsewhere (the homepage demo's "Open full studio"+ // link / share URL) wins; otherwise pick a reasonable starting pose so the+ // figure looks alive on load.+ const sharedPose = decodePoseFromLocation();+ if (sharedPose) {+ state.rig.applyPose(sharedPose);+ } else {+ const intro = getPresetById('contrapposto');+ if (intro) state.rig.applyPose(poseFromMannequinPreset(intro.pose));+ }// ── Render loop ──────────────────────────────────────────────────────let lastFrameMs = performance.now();