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.

feat: agent skills scene, avatar drop, OS demos, voice, build scripts, config updates

nirholas39d6a2974d1b
diff --git a/package.json b/package.json
index 56a90b4da..22cd0999f 100644
--- a/package.json
+++ b/package.json
@@ -49,7 +49,7 @@
]
},
"scripts": {
- "postinstall": "npm run build --prefix agent-payments-sdk && (node scripts/fix-pump-sdk-esm.mjs & node scripts/fix-x402-extensions-esm.mjs & node scripts/copy-three-decoders.mjs & node scripts/setup-claude-skills.mjs & wait)",
+ "postinstall": "(node scripts/build-cache.mjs check agent-payments-sdk agent-payments-sdk/src agent-payments-sdk/package.json || (npm run build --prefix agent-payments-sdk && node scripts/build-cache.mjs stamp agent-payments-sdk agent-payments-sdk/src agent-payments-sdk/package.json)) && (node scripts/fix-pump-sdk-esm.mjs & node scripts/fix-x402-extensions-esm.mjs & node scripts/copy-three-decoders.mjs & node scripts/setup-claude-skills.mjs & wait)",
"dev": "vite --port 3000",
"dev:multi": "npm run dev --prefix multiplayer",
"dev:walk-all": "node scripts/dev-walk-all.mjs",
@@ -57,7 +57,7 @@
"build:pages": "node scripts/build-page-index.mjs",
"audit:pages": "node scripts/audit-page-index.mjs",
"build:news": "node scripts/build-news.mjs",
- "prebuild": "(node scripts/build-news.mjs & node scripts/build-skill-metadata.mjs & node scripts/build-local-skill-packs.mjs & npm run build:club-assets & wait) && node scripts/build-page-index.mjs && node scripts/audit-page-index.mjs",
+ "prebuild": "(node scripts/build-news.mjs & node scripts/build-skill-metadata.mjs & node scripts/build-local-skill-packs.mjs & npm run build:club-assets & wait) && (node scripts/build-page-index.mjs && node scripts/audit-page-index.mjs)",
"build": "vite build && node scripts/strip-sw-from-embeds.mjs",
"build:wasm": "PATH=\"$HOME/.cargo/bin:$PATH\" RUSTFLAGS='-C target-feature=+simd128' wasm-pack build crates/vanity-grinder --target web --release --out-dir ../../src/solana/vanity/wasm && printf '%s\\n' '# wasm-pack writes a default `*` gitignore that excludes everything.' '# Override it: the generated files in this directory ARE checked in so the' '# app builds without requiring a Rust toolchain at install time. Run' '# `npm run build:wasm` after editing /crates/vanity-grinder/src/lib.rs to' '# refresh these artifacts.' '!*' > src/solana/vanity/wasm/.gitignore",
"build:animations": "node scripts/build-animations.mjs",
@@ -74,7 +74,7 @@
"build:chat": "cd chat && node scripts/ensure-deps.mjs && npm run build && cd .. && mkdir -p dist/chat && cp -rf public/chat/. dist/chat/",
"build:avatar-studio": "npm run build --prefix character-studio",
"build:fast": "npm run build",
- "build:vercel": "(npm run build:avatar-studio & npm run build:chat & (npm run build:lib && node avatar-sdk/build.mjs && NODE_OPTIONS=--max-old-space-size=4096 npm run build) & node scripts/bundle-api.mjs & wait) && node scripts/copy-avatar-studio.mjs && npm run publish:lib && npm run apply:r2-cors",
+ "build:vercel": "node scripts/build-vercel.mjs",
"apply:r2-cors": "node scripts/set-r2-cors.mjs || echo '[apply:r2-cors] skipped (missing creds or transient failure — see build log)'",
"build:all": "npm run build:chat && (npm run build & npm run build:lib & wait)",
"release:lib": "npm run build:lib && npm run publish:lib",
diff --git a/scripts/build-cache.mjs b/scripts/build-cache.mjs
new file mode 100644
index 000000000..8e5c1c1eb
--- /dev/null
+++ b/scripts/build-cache.mjs
@@ -0,0 +1,102 @@
+#!/usr/bin/env node
+/**
+ * Hash-based build cache: skip a build step if its inputs haven't changed.
+ *
+ * Usage:
+ * import { cached } from './build-cache.mjs';
+ * const hit = await cached('avatar-studio', ['character-studio/src', 'character-studio/package.json']);
+ * if (!hit) runBuild();
+ *
+ * Or from CLI:
+ * node scripts/build-cache.mjs check <name> <paths...> → exit 0 if cached, exit 1 if stale
+ * node scripts/build-cache.mjs stamp <name> <paths...> → write stamp after successful build
+ */
+import { createHash } from 'crypto';
+import { readFileSync, writeFileSync, existsSync, readdirSync, statSync, mkdirSync } from 'fs';
+import { resolve, join, relative } from 'path';
+import { fileURLToPath } from 'url';
+
+const ROOT = resolve(fileURLToPath(import.meta.url), '../..');
+const CACHE_DIR = resolve(ROOT, 'node_modules/.cache/build-stamps');
+
+function ensureCacheDir() {
+ if (!existsSync(CACHE_DIR)) mkdirSync(CACHE_DIR, { recursive: true });
+}
+
+function hashFile(path) {
+ try {
+ return createHash('sha256').update(readFileSync(path)).digest('hex');
+ } catch {
+ return 'missing';
+ }
+}
+
+function collectFiles(dir, out = []) {
+ if (!existsSync(dir)) return out;
+ const st = statSync(dir);
+ if (st.isFile()) {
+ out.push(dir);
+ return out;
+ }
+ if (!st.isDirectory()) return out;
+ const entries = readdirSync(dir, { withFileTypes: true });
+ for (const e of entries) {
+ if (e.name === 'node_modules' || e.name === '.git' || e.name === 'dist' || e.name === 'build') continue;
+ const full = join(dir, e.name);
+ if (e.isDirectory()) collectFiles(full, out);
+ else if (e.isFile()) out.push(full);
+ }
+ return out;
+}
+
+function computeHash(inputPaths) {
+ const hash = createHash('sha256');
+ for (const p of inputPaths) {
+ const abs = resolve(ROOT, p);
+ const files = collectFiles(abs).sort();
+ for (const f of files) {
+ hash.update(relative(ROOT, f) + '\0');
+ hash.update(hashFile(f));
+ }
+ }
+ return hash.digest('hex');
+}
+
+export function stampPath(name) {
+ return join(CACHE_DIR, `${name}.stamp`);
+}
+
+export function isCached(name, inputPaths) {
+ ensureCacheDir();
+ const stamp = stampPath(name);
+ if (!existsSync(stamp)) return false;
+ const stored = readFileSync(stamp, 'utf8').trim();
+ const current = computeHash(inputPaths);
+ return stored === current;
+}
+
+export function writeStamp(name, inputPaths) {
+ ensureCacheDir();
+ writeFileSync(stampPath(name), computeHash(inputPaths));
+}
+
+export async function cached(name, inputPaths) {
+ const hit = isCached(name, inputPaths);
+ if (hit) console.log(`[build-cache] ${name}: cache hit, skipping`);
+ else console.log(`[build-cache] ${name}: cache miss, rebuilding`);
+ return hit;
+}
+
+if (process.argv[1] && process.argv[1].endsWith('build-cache.mjs')) {
+ const [, , cmd, name, ...paths] = process.argv;
+ if (!cmd || !name || paths.length === 0) {
+ console.error('Usage: build-cache.mjs <check|stamp> <name> <paths...>');
+ process.exit(2);
+ }
+ if (cmd === 'check') {
+ process.exit(isCached(name, paths) ? 0 : 1);
+ } else if (cmd === 'stamp') {
+ writeStamp(name, paths);
+ console.log(`[build-cache] stamped ${name}`);
+ }
+}
diff --git a/scripts/build-vercel.mjs b/scripts/build-vercel.mjs
new file mode 100644
index 000000000..248ca34b4
--- /dev/null
+++ b/scripts/build-vercel.mjs
@@ -0,0 +1,119 @@
+#!/usr/bin/env node
+/**
+ * Optimized Vercel build orchestrator.
+ *
+ * Replaces the npm script one-liner with:
+ * - Hash-based caching (skip sub-builds whose inputs haven't changed)
+ * - Maximum parallelism across independent tasks
+ * - Clear timing + error reporting
+ */
+import { execSync, spawn } from 'child_process';
+import { existsSync } from 'fs';
+import { resolve, dirname } from 'path';
+import { fileURLToPath } from 'url';
+import { isCached, writeStamp } from './build-cache.mjs';
+
+const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
+
+function run(label, cmd, opts = {}) {
+ const start = Date.now();
+ return new Promise((res, rej) => {
+ console.log(`\n[${label}] starting: ${cmd}`);
+ const child = spawn('sh', ['-c', cmd], {
+ cwd: opts.cwd || ROOT,
+ stdio: 'inherit',
+ env: { ...process.env, ...opts.env },
+ });
+ child.on('close', (code) => {
+ const elapsed = ((Date.now() - start) / 1000).toFixed(1);
+ if (code === 0) {
+ console.log(`[${label}] done in ${elapsed}s`);
+ res();
+ } else {
+ const err = new Error(`[${label}] failed (exit ${code}) after ${elapsed}s`);
+ err.label = label;
+ rej(err);
+ }
+ });
+ });
+}
+
+async function buildAvatarStudio() {
+ const inputs = ['character-studio/src', 'character-studio/package.json', 'character-studio/vite.config.ts'];
+ if (isCached('avatar-studio', inputs) && existsSync(resolve(ROOT, 'character-studio/build'))) {
+ return;
+ }
+ await run('avatar-studio', 'npm run build --prefix character-studio');
+ writeStamp('avatar-studio', inputs);
+}
+
+async function buildChat() {
+ const inputs = ['chat/src', 'chat/package.json'];
+ if (isCached('chat', inputs) && existsSync(resolve(ROOT, 'chat/build'))) {
+ return;
+ }
+ await run('chat', 'cd chat && node scripts/ensure-deps.mjs && npm run build && cd .. && mkdir -p dist/chat && cp -rf public/chat/. dist/chat/');
+ writeStamp('chat', inputs);
+}
+
+async function prebuild() {
+ await Promise.all([
+ run('build:news', 'node scripts/build-news.mjs'),
+ run('build:skill-metadata', 'node scripts/build-skill-metadata.mjs'),
+ run('build:local-skill-packs', 'node scripts/build-local-skill-packs.mjs'),
+ run('build:club-assets', '(node scripts/build-club-props.mjs & node scripts/build-club-venue.mjs & node scripts/build-club-hdri.mjs & wait)'),
+ ]);
+ await run('build:page-index', 'node scripts/build-page-index.mjs && node scripts/audit-page-index.mjs');
+}
+
+async function buildLib() {
+ await run('build:lib', 'TARGET=lib npx vite build');
+ await run('avatar-sdk', 'node avatar-sdk/build.mjs');
+}
+
+async function buildApp() {
+ await run('build:app', 'npx vite build && node scripts/strip-sw-from-embeds.mjs', {
+ env: { NODE_OPTIONS: '--max-old-space-size=4096' },
+ });
+}
+
+async function bundleApi() {
+ await run('bundle-api', 'node scripts/bundle-api.mjs');
+}
+
+async function postBuild() {
+ await run('copy-avatar-studio', 'node scripts/copy-avatar-studio.mjs');
+
+ await Promise.all([
+ run('publish:lib', 'node scripts/publish-lib.mjs'),
+ run('apply:r2-cors', "node scripts/set-r2-cors.mjs || echo '[apply:r2-cors] skipped'"),
+ ]);
+}
+
+const totalStart = Date.now();
+
+try {
+ // Phase 1: prebuild + build:lib + independent sub-builds — all in parallel
+ // prebuild generates data files the app vite build reads (pages.json, skill metadata, news)
+ // build:lib is independent of prebuild — produces dist-lib/agent-3d.js
+ // avatar-studio, chat, bundle-api are fully independent
+ await Promise.all([
+ prebuild(),
+ buildLib(),
+ buildAvatarStudio(),
+ buildChat(),
+ bundleApi(),
+ ]);
+
+ // Phase 2: app vite build (needs prebuild outputs + same node_modules)
+ await buildApp();
+
+ // Phase 3: post-build steps (depend on Phase 1+2 outputs)
+ await postBuild();
+
+ const totalElapsed = ((Date.now() - totalStart) / 1000).toFixed(1);
+ console.log(`\n✓ build:vercel complete in ${totalElapsed}s`);
+} catch (err) {
+ console.error(`\n✗ build:vercel failed: ${err.message}`);
+ process.exit(1);
+}
diff --git a/src/agent-skills-scene.js b/src/agent-skills-scene.js
index a9a25fbab..abda4867e 100644
--- a/src/agent-skills-scene.js
+++ b/src/agent-skills-scene.js
@@ -3,7 +3,15 @@
* ----------------------------
* Skills for creating and manipulating objects in the Three.js scene.
*/
-import * as THREE from 'three';
+import {
+ SphereGeometry,
+ ConeGeometry,
+ CylinderGeometry,
+ BoxGeometry,
+ MeshStandardMaterial,
+ Color,
+ Mesh,
+} from 'three';
// Store a reference to the viewer instance
let viewer;
@@ -40,22 +48,22 @@ export function registerSceneSkills(skills) {
let geometry;
switch (shape) {
case 'sphere':
- geometry = new THREE.SphereGeometry(0.5, 32, 32);
+ geometry = new SphereGeometry(0.5, 32, 32);
break;
case 'cone':
- geometry = new THREE.ConeGeometry(0.5, 1, 32);
+ geometry = new ConeGeometry(0.5, 1, 32);
break;
case 'cylinder':
- geometry = new THREE.CylinderGeometry(0.5, 0.5, 1, 32);
+ geometry = new CylinderGeometry(0.5, 0.5, 1, 32);
break;
case 'box':
default:
- geometry = new THREE.BoxGeometry(1, 1, 1);
+ geometry = new BoxGeometry(1, 1, 1);
break;
}
- const material = new THREE.MeshStandardMaterial({ color: new THREE.Color(color) });
- const mesh = new THREE.Mesh(geometry, material);
+ const material = new MeshStandardMaterial({ color: new Color(color) });
+ const mesh = new Mesh(geometry, material);
mesh.position.set(position.x, position.y, position.z);
mesh.scale.set(scale.x, scale.y, scale.z);
mesh.name = `${shape}_${Date.now()}`;
@@ -117,7 +125,7 @@ export function registerSceneSkills(skills) {
}
if (color && object.material) {
- object.material.color.set(new THREE.Color(color));
+ object.material.color.set(new Color(color));
}
if (position) {
object.position.set(position.x, position.y, position.z);
diff --git a/src/avatar-drop.js b/src/avatar-drop.js
index 2e7636e5b..af5235be5 100644
--- a/src/avatar-drop.js
+++ b/src/avatar-drop.js
@@ -1,4 +1,18 @@
-import * as THREE from 'three';
+import {
+ WebGLRenderer,
+ SRGBColorSpace,
+ ACESFilmicToneMapping,
+ Scene,
+ OrthographicCamera,
+ Vector3,
+ AmbientLight,
+ DirectionalLight,
+ Clock,
+ AnimationMixer,
+ AnimationClip,
+ LoopRepeat,
+ LoopOnce,
+} from 'three';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
export function initAvatarDrop(sectionEl) {
@@ -7,16 +21,16 @@ export function initAvatarDrop(sectionEl) {
const ctaBtn = sectionEl.querySelector('#drop-cta-btn');
if (!canvas || !sitLine || !ctaBtn) return;
- const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: true });
+ const renderer = new WebGLRenderer({ canvas, antialias: true, alpha: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
- renderer.outputColorSpace = THREE.SRGBColorSpace;
- renderer.toneMapping = THREE.ACESFilmicToneMapping;
+ renderer.outputColorSpace = SRGBColorSpace;
+ renderer.toneMapping = ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.1;
- const scene = new THREE.Scene();
+ const scene = new Scene();
let PX_PER_UNIT = 120;
- const camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0.1, 100);
+ const camera = new OrthographicCamera(-1, 1, 1, -1, 0.1, 100);
camera.position.z = 10;
function updateFrustum() {
@@ -29,7 +43,7 @@ export function initAvatarDrop(sectionEl) {
camera.updateProjectionMatrix();
}
- const _v3 = new THREE.Vector3();
+ const _v3 = new Vector3();
function domToWorld(screenX, screenY) {
const rect = sectionEl.getBoundingClientRect();
_v3.set(
@@ -80,14 +94,14 @@ export function initAvatarDrop(sectionEl) {
sitLineRO.observe(sitLine);
// Lights — neutral/warm to match the monochrome theme
- scene.add(new THREE.AmbientLight(0xffffff, 0.65));
- const key = new THREE.DirectionalLight(0xfff8f0, 1.9);
+ scene.add(new AmbientLight(0xffffff, 0.65));
+ const key = new DirectionalLight(0xfff8f0, 1.9);
key.position.set(3, 6, 5);
scene.add(key);
- const rim = new THREE.DirectionalLight(0xc0c8e0, 0.5);
+ const rim = new DirectionalLight(0xc0c8e0, 0.5);
rim.position.set(-4, 3, -2);
scene.add(rim);
- const fill = new THREE.DirectionalLight(0xffeedd, 0.35);
+ const fill = new DirectionalLight(0xffeedd, 0.35);
fill.position.set(0, 2, 7);
scene.add(fill);
@@ -290,7 +304,7 @@ export function initAvatarDrop(sectionEl) {
});
// Proximity text shadow
- const _proj = new THREE.Vector3();
+ const _proj = new Vector3();
function updateProximityShadow() {
if (!avatar) return;
const sRect = sectionEl.getBoundingClientRect();
@@ -341,7 +355,7 @@ export function initAvatarDrop(sectionEl) {
});
avatar.rotation.y = 0;
scene.add(avatar);
- mixer = new THREE.AnimationMixer(avatar);
+ mixer = new AnimationMixer(avatar);
const fetchClip = f => fetch(f).then(r => r.json());
Promise.all([
@@ -349,15 +363,15 @@ export function initAvatarDrop(sectionEl) {
fetchClip('/animations/clips/standup.json'),
fetchClip('/animations/clips/jumpdown.json'),
]).then(([sitJson, standJson, jumpJson]) => {
- sitAction = mixer.clipAction(THREE.AnimationClip.parse(sitJson));
- sitAction.setLoop(THREE.LoopRepeat, Infinity);
+ sitAction = mixer.clipAction(AnimationClip.parse(sitJson));
+ sitAction.setLoop(LoopRepeat, Infinity);
- standupAction = mixer.clipAction(THREE.AnimationClip.parse(standJson));
- standupAction.setLoop(THREE.LoopOnce, 1);
+ standupAction = mixer.clipAction(AnimationClip.parse(standJson));
+ standupAction.setLoop(LoopOnce, 1);
standupAction.clampWhenFinished = true;
- fallAction = mixer.clipAction(THREE.AnimationClip.parse(jumpJson));
- fallAction.setLoop(THREE.LoopOnce, 1);
+ fallAction = mixer.clipAction(AnimationClip.parse(jumpJson));
+ fallAction.setLoop(LoopOnce, 1);
fallAction.clampWhenFinished = true;
fallAction.timeScale = JUMP_RATE;
@@ -386,7 +400,7 @@ export function initAvatarDrop(sectionEl) {
.catch(e => console.warn('[avatar-drop] boot failed', e));
// Render loop with visibility pause
- const clock = new THREE.Clock();
+ const clock = new Clock();
let running = true;
function tick() {
diff --git a/src/demo/os-combined.js b/src/demo/os-combined.js
index 5cf1fe1d9..ac11d2f40 100644
--- a/src/demo/os-combined.js
+++ b/src/demo/os-combined.js
@@ -7,7 +7,24 @@
* of the body's bounding box. The whole scene exports as one GLB.
*/
-import * as THREE from 'three';
+import {
+ Box3,
+ Vector3,
+ BufferGeometry,
+ BufferAttribute,
+ CanvasTexture,
+ SRGBColorSpace,
+ MeshStandardMaterial,
+ DoubleSide,
+ Mesh,
+ Scene,
+ Color,
+ PerspectiveCamera,
+ WebGLRenderer,
+ HemisphereLight,
+ DirectionalLight,
+ GridHelper,
+} from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { GLTFExporter } from 'three/addons/exporters/GLTFExporter.js';
@@ -204,8 +221,8 @@ btnBuild.addEventListener('click', async () => {
mesh.position.set(0, 0.1, 0.1);
} else {
// No head bone: position at top of body bbox.
- const box = new THREE.Box3().setFromObject(bodyRoot);
- const center = new THREE.Vector3();
+ const box = new Box3().setFromObject(bodyRoot);
+ const center = new Vector3();
box.getCenter(center);
mesh.position.set(center.x, box.max.y - 0.12, center.z + 0.08);
bodyRoot.add(mesh);
@@ -232,7 +249,7 @@ btnBuild.addEventListener('click', async () => {
});
function buildFaceMesh(landmarks, photoImg) {
- const geom = new THREE.BufferGeometry();
+ const geom = new BufferGeometry();
const aspect = photoImg.naturalWidth / photoImg.naturalHeight;
const scale = 0.2;
const positions = new Float32Array(landmarks.length * 3);
@@ -245,8 +262,8 @@ function buildFaceMesh(landmarks, photoImg) {
uvs[i * 2 + 0] = p.x;
uvs[i * 2 + 1] = 1 - p.y;
}
- geom.setAttribute('position', new THREE.BufferAttribute(positions, 3));
- geom.setAttribute('uv', new THREE.BufferAttribute(uvs, 2));
+ geom.setAttribute('position', new BufferAttribute(positions, 3));
+ geom.setAttribute('uv', new BufferAttribute(uvs, 2));
geom.setIndex(TRIANGULATION);
geom.computeVertexNormals();
@@ -254,17 +271,17 @@ function buildFaceMesh(landmarks, photoImg) {
canvas.width = photoImg.naturalWidth;
canvas.height = photoImg.naturalHeight;
canvas.getContext('2d').drawImage(photoImg, 0, 0);
- const texture = new THREE.CanvasTexture(canvas);
- texture.colorSpace = THREE.SRGBColorSpace;
+ const texture = new CanvasTexture(canvas);
+ texture.colorSpace = SRGBColorSpace;
texture.flipY = false;
- const material = new THREE.MeshStandardMaterial({
+ const material = new MeshStandardMaterial({
map: texture,
- side: THREE.DoubleSide,
+ side: DoubleSide,
roughness: 0.85,
metalness: 0,
});
- const mesh = new THREE.Mesh(geom, material);
+ const mesh = new Mesh(geom, material);
mesh.name = 'os-face-mesh';
return mesh;
}
@@ -276,23 +293,23 @@ function ensureViewer() {
const width = viewerHost.clientWidth;
const height = viewerHost.clientHeight || 600;
- const scene = new THREE.Scene();
- scene.background = new THREE.Color(0x050505);
- const camera = new THREE.PerspectiveCamera(35, width / height, 0.01, 100);
+ const scene = new Scene();
+ scene.background = new Color(0x050505);
+ const camera = new PerspectiveCamera(35, width / height, 0.01, 100);
camera.position.set(0, 1.4, 2.4);
- const renderer = new THREE.WebGLRenderer({ antialias: true });
+ const renderer = new WebGLRenderer({ antialias: true });
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(width, height);
- renderer.outputColorSpace = THREE.SRGBColorSpace;
+ renderer.outputColorSpace = SRGBColorSpace;
viewerHost.appendChild(renderer.domElement);
- scene.add(new THREE.HemisphereLight(0xffffff, 0x333333, 1.2));
- const dir = new THREE.DirectionalLight(0xffffff, 1.5);
+ scene.add(new HemisphereLight(0xffffff, 0x333333, 1.2));
+ const dir = new DirectionalLight(0xffffff, 1.5);
dir.position.set(2, 4, 3);
scene.add(dir);
- const grid = new THREE.GridHelper(4, 8, 0x222222, 0x111111);
+ const grid = new GridHelper(4, 8, 0x222222, 0x111111);
scene.add(grid);
const controls = new OrbitControls(camera, renderer.domElement);
@@ -320,9 +337,9 @@ function ensureViewer() {
}
function fitToObject({ camera, controls }, obj) {
- const box = new THREE.Box3().setFromObject(obj);
- const size = new THREE.Vector3();
- const center = new THREE.Vector3();
+ const box = new Box3().setFromObject(obj);
+ const size = new Vector3();
+ const center = new Vector3();
box.getSize(size);
box.getCenter(center);
const maxDim = Math.max(size.x, size.y, size.z);
diff --git a/src/demo/os-selfie.js b/src/demo/os-selfie.js
index b0ad78232..a47a3c077 100644
--- a/src/demo/os-selfie.js
+++ b/src/demo/os-selfie.js
@@ -13,7 +13,24 @@
* No server calls for inference. WASM + model fetch from Google's CDN at init.
*/
-import * as THREE from 'three';
+import {
+ BufferGeometry,
+ BufferAttribute,
+ CanvasTexture,
+ SRGBColorSpace,
+ MeshStandardMaterial,
+ DoubleSide,
+ Mesh,
+ Scene,
+ Color,
+ PerspectiveCamera,
+ WebGLRenderer,
+ HemisphereLight,
+ DirectionalLight,
+ GridHelper,
+ Box3,
+ Vector3,
+} from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { GLTFExporter } from 'three/addons/exporters/GLTFExporter.js';
import { FilesetResolver, FaceLandmarker } from '@mediapipe/tasks-vision';
@@ -231,7 +248,7 @@ btnBuild.addEventListener('click', async () => {
});
function buildFaceMesh(landmarks, photoImg) {
- const geom = new THREE.BufferGeometry();
+ const geom = new BufferGeometry();
// Landmarks: { x, y, z } with x,y in [0,1] image coords, y=down, z=depth (negative into screen)
// Convert into a centered, world-up mesh. Scale so the face is roughly 0.2m tall.
@@ -247,8 +264,8 @@ function buildFaceMesh(landmarks, photoImg) {
uvs[i * 2 + 0] = p.x;
uvs[i * 2 + 1] = 1 - p.y;
}
- geom.setAttribute('position', new THREE.BufferAttribute(positions, 3));
- geom.setAttribute('uv', new THREE.BufferAttribute(uvs, 2));
+ geom.setAttribute('position', new BufferAttribute(positions, 3));
+ geom.setAttribute('uv', new BufferAttribute(uvs, 2));
geom.setIndex(TRIANGULATION);
geom.computeVertexNormals();
@@ -257,17 +274,17 @@ function buildFaceMesh(landmarks, photoImg) {
canvas.width = photoImg.naturalWidth;
canvas.height = photoImg.naturalHeight;
canvas.getContext('2d').drawImage(photoImg, 0, 0);
- const texture = new THREE.CanvasTexture(canvas);
- texture.colorSpace = THREE.SRGBColorSpace;
+ const texture = new CanvasTexture(canvas);
+ texture.colorSpace = SRGBColorSpace;
texture.flipY = false; // we already flipped V
- const material = new THREE.MeshStandardMaterial({
+ const material = new MeshStandardMaterial({
map: texture,
- side: THREE.DoubleSide,
+ side: DoubleSide,
roughness: 0.85,
metalness: 0,
});
- const mesh = new THREE.Mesh(geom, material);
+ const mesh = new Mesh(geom, material);
mesh.name = 'os-face-mesh';
return mesh;
}
@@ -279,27 +296,27 @@ function ensureViewer() {
const width = viewerHost.clientWidth;
const height = viewerHost.clientHeight || 480;
- const scene = new THREE.Scene();
- scene.background = new THREE.Color(0x050505);
+ const scene = new Scene();
+ scene.background = new Color(0x050505);
- const camera = new THREE.PerspectiveCamera(35, width / height, 0.001, 10);
+ const camera = new PerspectiveCamera(35, width / height, 0.001, 10);
camera.position.set(0, 0, 0.6);
- const renderer = new THREE.WebGLRenderer({ antialias: true });
+ const renderer = new WebGLRenderer({ antialias: true });
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(width, height);
- renderer.outputColorSpace = THREE.SRGBColorSpace;
+ renderer.outputColorSpace = SRGBColorSpace;
viewerHost.appendChild(renderer.domElement);
- scene.add(new THREE.HemisphereLight(0xffffff, 0x333333, 1.2));
- const dir = new THREE.DirectionalLight(0xffffff, 1.4);
+ scene.add(new HemisphereLight(0xffffff, 0x333333, 1.2));
+ const dir = new DirectionalLight(0xffffff, 1.4);
dir.position.set(1, 2, 3);
scene.add(dir);
- const dir2 = new THREE.DirectionalLight(0xffffff, 0.6);
+ const dir2 = new DirectionalLight(0xffffff, 0.6);
dir2.position.set(-2, 1, -1);
scene.add(dir2);
- const grid = new THREE.GridHelper(1, 10, 0x222222, 0x111111);
+ const grid = new GridHelper(1, 10, 0x222222, 0x111111);
grid.position.y = -0.2;
scene.add(grid);
@@ -328,9 +345,9 @@ function ensureViewer() {
}
function fitToObject({ camera, controls }, obj) {
- const box = new THREE.Box3().setFromObject(obj);
- const size = new THREE.Vector3();
- const center = new THREE.Vector3();
+ const box = new Box3().setFromObject(obj);
+ const size = new Vector3();
+ const center = new Vector3();
box.getSize(size);
box.getCenter(center);
const maxDim = Math.max(size.x, size.y, size.z);
diff --git a/src/demo/os-studio.js b/src/demo/os-studio.js
index 653b785a6..808a19d01 100644
--- a/src/demo/os-studio.js
+++ b/src/demo/os-studio.js
@@ -7,7 +7,18 @@
* standalone three.js viewer + offers download / save-to-account.
*/
-import * as THREE from 'three';
+import {
+ Scene,
+ Color,
+ PerspectiveCamera,
+ WebGLRenderer,
+ SRGBColorSpace,
+ HemisphereLight,
+ DirectionalLight,
+ GridHelper,
+ Box3,
+ Vector3,
+} from 'three';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
@@ -106,8 +117,8 @@ async function renderPreview(blob) {
gltf.scene.userData.kind = 'avatar';
scene.add(gltf.scene);
fitToObject(previewState, gltf.scene);
- const box = new THREE.Box3().setFromObject(gltf.scene);
- const size = new THREE.Vector3();
+ const box = new Box3().setFromObject(gltf.scene);
+ const size = new Vector3();
box.getSize(size);
previewBadge.textContent = `GLB · ${size.x.toFixed(2)}×${size.y.toFixed(2)}×${size.z.toFixed(2)}m`;
setStatus(
@@ -125,23 +136,23 @@ async function renderPreview(blob) {
function initViewer(host) {
const width = host.clientWidth;
const height = host.clientHeight || 360;
- const scene = new THREE.Scene();
- scene.background = new THREE.Color(0x050505);
- const camera = new THREE.PerspectiveCamera(35, width / height, 0.01, 100);
+ const scene = new Scene();
+ scene.background = new Color(0x050505);
+ const camera = new PerspectiveCamera(35, width / height, 0.01, 100);
camera.position.set(0, 1.4, 2.4);
- const renderer = new THREE.WebGLRenderer({ antialias: true });
+ const renderer = new WebGLRenderer({ antialias: true });
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(width, height);
- renderer.outputColorSpace = THREE.SRGBColorSpace;
+ renderer.outputColorSpace = SRGBColorSpace;
host.appendChild(renderer.domElement);
- scene.add(new THREE.HemisphereLight(0xffffff, 0x444444, 1.2));
- const dir = new THREE.DirectionalLight(0xffffff, 1.5);
+ scene.add(new HemisphereLight(0xffffff, 0x444444, 1.2));
+ const dir = new DirectionalLight(0xffffff, 1.5);
dir.position.set(2, 4, 3);
scene.add(dir);
- const grid = new THREE.GridHelper(4, 8, 0x222222, 0x111111);
+ const grid = new GridHelper(4, 8, 0x222222, 0x111111);
scene.add(grid);
const controls = new OrbitControls(camera, renderer.domElement);
@@ -168,9 +179,9 @@ function initViewer(host) {
}
function fitToObject({ camera, controls }, obj) {
- const box = new THREE.Box3().setFromObject(obj);
- const size = new THREE.Vector3();
- const center = new THREE.Vector3();
+ const box = new Box3().setFromObject(obj);
+ const size = new Vector3();
+ const center = new Vector3();
box.getSize(size);
box.getCenter(center);
const maxDim = Math.max(size.x, size.y, size.z);
diff --git a/src/footer-bot.js b/src/footer-bot.js
index 03cc70612..c2dc3c0b7 100644
--- a/src/footer-bot.js
+++ b/src/footer-bot.js
@@ -1,4 +1,15 @@
-import * as THREE from 'three';
+import {
+ WebGLRenderer,
+ ACESFilmicToneMapping,
+ SRGBColorSpace,
+ Scene,
+ PerspectiveCamera,
+ MathUtils,
+ AmbientLight,
+ DirectionalLight,
+ Clock,
+ AnimationMixer,
+} from 'three';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
const canvas = document.getElementById('footer-bot-canvas');
@@ -8,45 +19,45 @@ const parent = canvas.parentElement;
const w = parent?.clientWidth || 300;
const h = parent?.clientHeight || 400;
-const renderer = new THREE.WebGLRenderer({ canvas, alpha: true, antialias: true });
+const renderer = new WebGLRenderer({ canvas, alpha: true, antialias: true });
renderer.setSize(w, h);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
-renderer.toneMapping = THREE.ACESFilmicToneMapping;
+renderer.toneMapping = ACESFilmicToneMapping;
renderer.toneMappingExposure = 0.7;
-renderer.outputColorSpace = THREE.SRGBColorSpace;
+renderer.outputColorSpace = SRGBColorSpace;
-const scene = new THREE.Scene();
+const scene = new Scene();
// Match model-viewer camera-orbit="0deg 80deg 9m" field-of-view="35deg"
-const camera = new THREE.PerspectiveCamera(35, w / h, 0.1, 100);
-const phi = THREE.MathUtils.degToRad(80);
+const camera = new PerspectiveCamera(35, w / h, 0.1, 100);
+const phi = MathUtils.degToRad(80);
camera.position.set(0, 9 * Math.cos(phi), 9 * Math.sin(phi));
camera.lookAt(0, 0, 0);
// Neutral environment (exposure 0.7, no shadows)
-scene.add(new THREE.AmbientLight(0xffffff, 1.5));
-const sun = new THREE.DirectionalLight(0xffffff, 2.0);
+scene.add(new AmbientLight(0xffffff, 1.5));
+const sun = new DirectionalLight(0xffffff, 2.0);
sun.position.set(1, 2, 3);
scene.add(sun);
-const fill = new THREE.DirectionalLight(0xffffff, 0.5);
+const fill = new DirectionalLight(0xffffff, 0.5);
fill.position.set(-1, 1, -2);
scene.add(fill);
let mixer = null;
-const clock = new THREE.Clock();
+const clock = new Clock();
let robot = null;
new GLTFLoader().load('/animations/robotexpressive.glb', (gltf) => {
robot = gltf.scene;
scene.add(robot);
if (gltf.animations.length > 0) {
- mixer = new THREE.AnimationMixer(robot);
+ mixer = new AnimationMixer(robot);
mixer.clipAction(gltf.animations[0]).play();
}
});
// 20deg/sec auto-rotate, matching model-viewer rotation-per-second="20deg"
-const rotSpeed = THREE.MathUtils.degToRad(20);
+const rotSpeed = MathUtils.degToRad(20);
(function animate() {
requestAnimationFrame(animate);
diff --git a/src/voice/talk-scene.js b/src/voice/talk-scene.js
index dc069ab91..275b21fec 100644
--- a/src/voice/talk-scene.js
+++ b/src/voice/talk-scene.js
@@ -15,7 +15,19 @@
* scene.unmount();
*/
-import * as THREE from 'three';
+import {
+ Clock,
+ WebGLRenderer,
+ SRGBColorSpace,
+ ACESFilmicToneMapping,
+ Scene,
+ PMREMGenerator,
+ AmbientLight,
+ DirectionalLight,
+ PerspectiveCamera,
+ AnimationMixer,
+ Box3,
+} from 'three';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';
@@ -35,7 +47,7 @@ export class TalkScene {
this.mixer = null;
this._clips = [];
this._currentAction = null;
- this._clock = new THREE.Clock();
+ this._clock = new Clock();
this._rafId = 0;
this._running = false;
this._resizeObserver = null;
@@ -72,14 +84,14 @@ export class TalkScene {
// `canvas.toBlob` — required for the snapshot pipeline (see
// avatar-snapshot.js) to capture a valid JPEG after a render. The perf
// cost is small for avatar-scale scenes; large at fullscreen-game scale.
- this.renderer = new THREE.WebGLRenderer({
+ this.renderer = new WebGLRenderer({
antialias: true,
alpha: true,
preserveDrawingBuffer: true,
});
this.renderer.setPixelRatio(window.devicePixelRatio);
- this.renderer.outputColorSpace = THREE.SRGBColorSpace;
- this.renderer.toneMapping = THREE.ACESFilmicToneMapping;
+ this.renderer.outputColorSpace = SRGBColorSpace;
+ this.renderer.toneMapping = ACESFilmicToneMapping;
this.renderer.toneMappingExposure = 1.0;
const { width, height } = sizeOf(container);
@@ -87,24 +99,24 @@ export class TalkScene {
this.renderer.domElement.style.cssText = 'width:100%;height:100%;display:block;';
container.appendChild(this.renderer.domElement);
- this.scene = new THREE.Scene();
+ this.scene = new Scene();
this.scene.background = null; // transparent so the page bg shows through
// Image-based lighting via RoomEnvironment — same look-and-feel choice
// model-viewer uses when no environment-image is set.
- const pmrem = new THREE.PMREMGenerator(this.renderer);
+ const pmrem = new PMREMGenerator(this.renderer);
this.scene.environment = pmrem.fromScene(new RoomEnvironment(), 0.04).texture;
// Fill + key + rim for visual depth.
- this.scene.add(new THREE.AmbientLight(0xffffff, 0.4));
- const key = new THREE.DirectionalLight(0xffffff, 1.4);
+ this.scene.add(new AmbientLight(0xffffff, 0.4));
+ const key = new DirectionalLight(0xffffff, 1.4);
key.position.set(2, 4, 3);
this.scene.add(key);
- const rim = new THREE.DirectionalLight(0x90a0ff, 0.6);
+ const rim = new DirectionalLight(0x90a0ff, 0.6);
rim.position.set(-3, 2, -2);
this.scene.add(rim);
- this.camera = new THREE.PerspectiveCamera(35, width / height, 0.05, 100);
+ this.camera = new PerspectiveCamera(35, width / height, 0.05, 100);
this.camera.position.set(0, 1.55, 2.0);
this.controls = new OrbitControls(this.camera, this.renderer.domElement);
@@ -148,7 +160,7 @@ export class TalkScene {
// If the GLB ships any animations, set up a mixer and remember the
// clips so the caller can request one (e.g. 'Idle' for a base loop).
if (gltf.animations?.length) {
- this.mixer = new THREE.AnimationMixer(this.root);
+ this.mixer = new AnimationMixer(this.root);
this._clips = gltf.animations;
// Auto-play an idle if one is present.
const idle = gltf.animations.find((c) => /idle|breath/i.test(c.name));
@@ -277,7 +289,7 @@ export class TalkScene {
_frameAvatar() {
if (!this.root || !this.camera || !this.controls) return;
- const b = new THREE.Box3().setFromObject(this.root);
+ const b = new Box3().setFromObject(this.root);
const aspect = this.camera.aspect || 1;
const framing = computeFraming({
box: { min: { x: b.min.x, y: b.min.y, z: b.min.z }, max: { x: b.max.x, y: b.max.y, z: b.max.z } },
diff --git a/vercel.json b/vercel.json
index 8e2596057..ca0c5aadb 100644
--- a/vercel.json
+++ b/vercel.json
@@ -2,7 +2,7 @@
"buildCommand": "npm run build:vercel",
"outputDirectory": "dist",
"public": true,
- "installCommand": "npm install --prefer-offline --no-audit --no-fund",
+ "installCommand": "npm install --prefer-offline --no-audit --no-fund && npm dedupe --prefer-offline 2>/dev/null || true",
"env": {
"NODE_OPTIONS": "--no-deprecation"
},
diff --git a/vite.config.js b/vite.config.js
index 5429515af..c43024930 100644
--- a/vite.config.js
+++ b/vite.config.js
@@ -146,8 +146,13 @@ const appConfig = {
external: ['/studio/launch-panel.js'],
output: {
manualChunks(id) {
- if (id.includes('node_modules/three/')) return 'three';
+ if (id.includes('node_modules/three/')) {
+ if (id.includes('three/examples/') || id.includes('three/addons/')) return 'three-addons';
+ return 'three-core';
+ }
if (id.includes('node_modules/ethers/')) return 'ethers';
+ if (id.includes('node_modules/@solana/') || id.includes('node_modules/@coral-xyz/')) return 'solana';
+ if (id.includes('node_modules/@mediapipe/')) return 'mediapipe';
},
// footer-bot.js needs a stable, unhashed filename so footer.js can
// load it by a predictable URL without knowing the build hash.