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(seeder): head-to-toe complexion + height variation in studio lane
nirholas5b82ee4a9875
diff --git a/api/_lib/studio-avatar.js b/api/_lib/studio-avatar.jsindex bb5fefedb..5d97ec47e 100644--- a/api/_lib/studio-avatar.js+++ b/api/_lib/studio-avatar.js@@ -132,25 +132,51 @@ export function pickColorway(profile, seed) {};}+// Wolf3D_Skin is the head; Wolf3D_Body is the body skin (hands, neck, feet). Both+// take the complexion so the avatar is one consistent tone head-to-toe — tinting+// only the face left the hands the base color, a visible mismatch on dark tones.const MATERIAL_CHANNEL = {Wolf3D_Skin: 'skin',+ Wolf3D_Body: 'skin',Wolf3D_Hair: 'hair',Wolf3D_Outfit_Top: 'top',Wolf3D_Outfit_Bottom: 'bottom',Wolf3D_Outfit_Footwear: 'footwear',};+/**+ * Pick a uniform size multiplier for a profile + seed. Morph targets on these+ * bodies are ARKit expressions (no body shape), so height is the only real size+ * axis — a uniform node scale gives believable tall / average / petite variety+ * without distorting the rig. Women trend slightly shorter, seniors a touch more.+ * @param {{ gender?:'male'|'female', ageKey?:string, build?:string }} profile+ * @param {string} seed+ * @returns {number} scale in ~[0.9, 1.1]+ */+export function pickScale(profile, seed) {+ const rng = mulberry32(hashSeed(seed + ':scale'));+ let s = 0.97 + rng() * 0.13; // 0.97–1.10 base spread+ if (profile?.gender === 'female') s -= 0.05;+ if (profile?.ageKey === 'senior') s -= 0.02;+ if (profile?.build === 'petite' || profile?.build === 'slim') s -= 0.02;+ if (profile?.build === 'stocky' || profile?.build === 'athletic') s += 0.02;+ return Math.round(Math.max(0.88, Math.min(1.12, s)) * 1000) / 1000;+}+const GLB_MAGIC = 0x46546c67;const CHUNK_JSON = 0x4e4f534a;/**- * Recolor a Wolf3D/RPM rigged GLB (JSON-chunk edit, binary untouched). Returns a- * new Buffer plus the list of materials recolored.+ * Restyle a Wolf3D/RPM rigged GLB: recolor the skin / hair / outfit materials and+ * apply a uniform size scale to the scene roots (JSON-chunk edit, binary+ * untouched). The skeleton, weights and blendshapes are preserved, so the result+ * stays a valid, rigged, walk-ready avatar. Returns a new Buffer + what changed.* @param {Buffer} glb* @param {ReturnType<typeof pickColorway>} colorway- * @returns {{ buffer: Buffer, recolored: string[] }}+ * @param {number} [scale=1] - uniform size multiplier (see pickScale)+ * @returns {{ buffer: Buffer, recolored: string[], scale: number }}*/-export function recolorGlb(glb, colorway) {+export function recolorGlb(glb, colorway, scale = 1) {if (!Buffer.isBuffer(glb) || glb.length < 20) throw new Error('recolorGlb: not a GLB buffer');if (glb.readUInt32LE(0) !== GLB_MAGIC || glb.readUInt32LE(4) !== 2)throw new Error('recolorGlb: bad GLB header');@@ -170,6 +196,20 @@ export function recolorGlb(glb, colorway) {recolored.push(mat.name);}+ // Uniform size: scale every root node of the default scene. Uniform scaling+ // keeps the rig valid and the clip retarget re-normalizes hip height, so a+ // taller/shorter avatar still walks correctly.+ const s = Number(scale) || 1;+ if (Math.abs(s - 1) > 1e-4 && Array.isArray(gltf.nodes)) {+ const scene = gltf.scenes?.[gltf.scene ?? 0];+ for (const idx of scene?.nodes || []) {+ const node = gltf.nodes[idx];+ if (!node || node.matrix) continue; // skip matrix-form nodes (rare here)+ const cur = Array.isArray(node.scale) ? node.scale : [1, 1, 1];+ node.scale = [cur[0] * s, cur[1] * s, cur[2] * s];+ }+ }+let jsonBuf = Buffer.from(JSON.stringify(gltf), 'utf8');const pad = (4 - (jsonBuf.length % 4)) % 4;if (pad) jsonBuf = Buffer.concat([jsonBuf, Buffer.alloc(pad, 0x20)]);@@ -182,5 +222,5 @@ export function recolorGlb(glb, colorway) {header.writeUInt32LE(jsonBuf.length, 12);header.writeUInt32LE(CHUNK_JSON, 16);- return { buffer: Buffer.concat([header, jsonBuf, rest]), recolored };+ return { buffer: Buffer.concat([header, jsonBuf, rest]), recolored, scale: s };}diff --git a/api/cron/avaturn-seed-cron.js b/api/cron/avaturn-seed-cron.jsindex 5a3ae12a2..d3269a095 100644--- a/api/cron/avaturn-seed-cron.js+++ b/api/cron/avaturn-seed-cron.js@@ -36,7 +36,7 @@ import { inspectGlb } from '../_lib/glb-inspect.js';import { fetchModel } from '../_lib/fetch-model.js';import { isFlagEnabled } from '../_lib/flags.js';import { pickDiversityProfile, describeProfile } from '../_lib/avaturn-seed.js';-import { pickBaseBody, pickColorway, recolorGlb } from '../_lib/studio-avatar.js';+import { pickBaseBody, pickColorway, pickScale, recolorGlb } from '../_lib/studio-avatar.js';import { randomUUID } from 'node:crypto';const CIRCUIT_NAME = 'avaturn-seed';@@ -127,7 +127,8 @@ async function runOnce() {const baseUrl = `${ORIGIN()}/avatars/${base.file}`;const { bytes } = await fetchModel(baseUrl, { maxBytes: 40 * 1024 * 1024 });const colorway = pickColorway(profile, seed);- const { buffer: glbBytes, recolored } = recolorGlb(Buffer.from(bytes), colorway);+ const scale = pickScale(profile, seed);+ const { buffer: glbBytes, recolored } = recolorGlb(Buffer.from(bytes), colorway, scale);const slug = toSlug(displayName);const storageKey = `u/${user.id}/${slug}.glb`;@@ -152,6 +153,7 @@ async function runOnce() {skeleton_joint_count: rigInfo?.skeletonJointCount ?? null,skin_count: rigInfo?.skinCount ?? null,recolored,+ scale,profile: {gender: profile.gender,age: profile.ageKey,diff --git a/tests/studio-avatar.test.js b/tests/studio-avatar.test.jsindex 95c34a358..04f29e12f 100644--- a/tests/studio-avatar.test.js+++ b/tests/studio-avatar.test.js@@ -1,11 +1,17 @@// Studio avatar lane (api/_lib/studio-avatar.js) — the free, self-owned seeder// engine. Recoloring a rigged Wolf3D/RPM base keeps it a valid, rigged GLB while-// genuinely changing complexion, hair and outfit — deterministically per seed.+// genuinely changing complexion (head-to-toe), hair, outfit and size.import { describe, it, expect } from 'vitest';import { readFileSync } from 'node:fs';import { resolve } from 'node:path';-import { pickBaseBody, pickColorway, recolorGlb, BASE_BODIES } from '../api/_lib/studio-avatar.js';+import {+ pickBaseBody,+ pickColorway,+ pickScale,+ recolorGlb,+ BASE_BODIES,+} from '../api/_lib/studio-avatar.js';import { inspectGlb } from '../api/_lib/glb-inspect.js';const AV = (f) => resolve(process.cwd(), 'public/avatars', f);@@ -40,27 +46,68 @@ describe('pickColorway', () => {});});+describe('pickScale', () => {+ it('is deterministic and stays in a believable band', () => {+ const p = { gender: 'male', ageKey: 'adult', build: 'average' };+ expect(pickScale(p, 'z')).toBe(pickScale(p, 'z'));+ for (let i = 0; i < 100; i++) {+ const s = pickScale({ gender: i % 2 ? 'male' : 'female', build: 'stocky' }, `sc-${i}`);+ expect(s).toBeGreaterThanOrEqual(0.88);+ expect(s).toBeLessThanOrEqual(1.12);+ }+ });+ it('trends women shorter than men for the same seed', () => {+ let shorter = 0;+ for (let i = 0; i < 60; i++) {+ const m = pickScale({ gender: 'male', build: 'average' }, `g-${i}`);+ const f = pickScale({ gender: 'female', build: 'average' }, `g-${i}`);+ if (f < m) shorter++;+ }+ expect(shorter).toBe(60);+ });+});+describe('recolorGlb', () => {it('keeps every base body a valid, rigged GLB with the skeleton intact', () => {for (const body of BASE_BODIES) {const glb = readFileSync(AV(body.file));const before = inspectGlb(glb);const cw = pickColorway({ gender: body.gender, ethnicityKey: 'south-asian' }, body.id);- const { buffer, recolored } = recolorGlb(glb, cw);+ const { buffer, recolored, scale } = recolorGlb(+ glb,+ cw,+ pickScale({ gender: body.gender }, body.id),+ );const after = inspectGlb(buffer);expect(after?.valid).toBe(true);expect(after?.isRigged).toBe(true);expect(after?.skeletonJointCount).toBe(before?.skeletonJointCount);expect(recolored).toContain('Wolf3D_Skin');+ expect(scale).toBeGreaterThan(0);}});- it('writes the requested complexion onto the skin material', () => {- const glb = readFileSync(AV('realistic-female.glb'));- const cw = pickColorway({ gender: 'female', ethnicityKey: 'black-african' }, 'x');- const { buffer } = recolorGlb(glb, cw);+ it('tints face and body skin the same for head-to-toe complexion', () => {+ const glb = readFileSync(AV('realistic-male.glb'));+ const cw = pickColorway({ gender: 'male', ethnicityKey: 'black-african' }, 'x');+ const { buffer, recolored } = recolorGlb(glb, cw);+ // realistic-male has both Wolf3D_Skin (face) and Wolf3D_Body (limbs)+ expect(recolored).toEqual(expect.arrayContaining(['Wolf3D_Skin', 'Wolf3D_Body']));const gltf = JSON.parse(buffer.slice(20, 20 + buffer.readUInt32LE(12)).toString('utf8'));const skin = gltf.materials.find((m) => m.name === 'Wolf3D_Skin');+ const bodyMat = gltf.materials.find((m) => m.name === 'Wolf3D_Body');expect(skin.pbrMetallicRoughness.baseColorFactor.slice(0, 3)).toEqual(cw.skin);+ expect(bodyMat.pbrMetallicRoughness.baseColorFactor.slice(0, 3)).toEqual(cw.skin);+ });+ it('applies a uniform scale to the scene roots', () => {+ const glb = readFileSync(AV('realistic-female.glb'));+ const { buffer } = recolorGlb(glb, pickColorway({ gender: 'female' }, 's'), 1.1);+ const gltf = JSON.parse(buffer.slice(20, 20 + buffer.readUInt32LE(12)).toString('utf8'));+ const roots = (gltf.scenes[gltf.scene ?? 0].nodes || []).map((i) => gltf.nodes[i]);+ // at least one root now carries a ~1.1 scale+ const scaled = roots.some(+ (n) => Array.isArray(n.scale) && Math.abs(n.scale[1] - 1.1) < 0.02,+ );+ expect(scaled).toBe(true);});it('rejects non-GLB input', () => {expect(() => recolorGlb(Buffer.from('not a glb'), pickColorway({}, 's'))).toThrow();