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.

GLB rigging inspection + docs cleanup

nirholasa3d5b8064e66
diff --git a/api/_lib/glb-inspect.js b/api/_lib/glb-inspect.js
new file mode 100644
index 000000000..7dd5e9c27
--- /dev/null
+++ b/api/_lib/glb-inspect.js
@@ -0,0 +1,130 @@
+// Deterministic GLB introspection helpers.
+//
+// Why server-side: we want to know whether a reconstructed avatar has a
+// usable skeleton (skins[] in the glTF JSON) BEFORE it lands in the user's
+// catalog, so the UI can show a "needs rigging" affordance and the materialize
+// path can flag the avatar's metadata accordingly. Without this every
+// TRELLIS / TripoSR output looks identical to a Hunyuan3D output that DOES
+// have a rig — users would only discover the gap when they tried to animate.
+//
+// We parse only the 12-byte file header and the first JSON chunk header
+// (the typical glTF 2.0 layout: HEADER + JSON_CHUNK + BIN_CHUNK?). We do not
+// touch the BIN chunk so this is fast even on large meshes.
+//
+// Spec: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#binary-gltf-layout
+
+const GLB_MAGIC = 0x46546C67; // 'glTF' little-endian
+const CHUNK_JSON = 0x4E4F534A; // 'JSON' little-endian
+const CHUNK_BIN = 0x004E4942; // 'BIN\0' little-endian
+
+/**
+ * Inspect a GLB buffer and return what we can determine from the JSON chunk.
+ * Returns null when the buffer isn't a valid binary glTF 2.0.
+ *
+ * @param {Buffer|Uint8Array} buf
+ * @returns {null | {
+ * valid: true,
+ * sizeBytes: number,
+ * isRigged: boolean,
+ * skinCount: number,
+ * skeletonJointCount: number,
+ * nodeCount: number,
+ * meshCount: number,
+ * animationCount: number,
+ * generator: string | null,
+ * extensionsUsed: string[],
+ * }}
+ */
+export function inspectGlb(buf) {
+ if (!isBufferLike(buf) || buf.length < 12 + 8) return null;
+ const view = bufToDataView(buf);
+ if (view.getUint32(0, true) !== GLB_MAGIC) return null;
+ if (view.getUint32(4, true) !== 2) return null;
+ if (view.getUint32(8, true) !== buf.length) return null;
+
+ // First chunk header at byte 12.
+ const jsonChunkLen = view.getUint32(12, true);
+ const jsonChunkType = view.getUint32(16, true);
+ if (jsonChunkType !== CHUNK_JSON) return null;
+ if (20 + jsonChunkLen > buf.length) return null;
+
+ const jsonBytes = bufSlice(buf, 20, 20 + jsonChunkLen);
+ let gltf;
+ try {
+ // glTF spec pads the JSON chunk with 0x20 (space) to a 4-byte boundary,
+ // which JSON.parse tolerates as whitespace.
+ gltf = JSON.parse(new TextDecoder('utf-8').decode(jsonBytes));
+ } catch {
+ return null;
+ }
+
+ const skins = Array.isArray(gltf.skins) ? gltf.skins : [];
+ const animations = Array.isArray(gltf.animations) ? gltf.animations : [];
+ const nodes = Array.isArray(gltf.nodes) ? gltf.nodes : [];
+ const meshes = Array.isArray(gltf.meshes) ? gltf.meshes : [];
+ const skeletonJointCount = skins.reduce(
+ (acc, s) => acc + (Array.isArray(s.joints) ? s.joints.length : 0),
+ 0,
+ );
+ const generator = typeof gltf.asset?.generator === 'string' ? gltf.asset.generator : null;
+ const extensionsUsed = Array.isArray(gltf.extensionsUsed) ? gltf.extensionsUsed : [];
+
+ return {
+ valid: true,
+ sizeBytes: buf.length,
+ isRigged: skins.length > 0 && skeletonJointCount > 0,
+ skinCount: skins.length,
+ skeletonJointCount,
+ nodeCount: nodes.length,
+ meshCount: meshes.length,
+ animationCount: animations.length,
+ generator,
+ extensionsUsed,
+ };
+}
+
+/**
+ * Strict header check used by upload boundaries — does not parse JSON.
+ * Returns true iff the 12-byte header + first chunk header look valid.
+ */
+export function isValidGlbHeader(buf) {
+ if (!isBufferLike(buf) || buf.length < 20) return false;
+ const view = bufToDataView(buf);
+ if (view.getUint32(0, true) !== GLB_MAGIC) return false;
+ if (view.getUint32(4, true) !== 2) return false;
+ if (view.getUint32(8, true) !== buf.length) return false;
+ return true;
+}
+
+/**
+ * Convenience: parse and report only the rigging signal, returning false on
+ * any parse failure. Use this when you don't care about the full struct.
+ */
+export function isRiggedGlb(buf) {
+ const info = inspectGlb(buf);
+ return !!(info && info.isRigged);
+}
+
+function isBufferLike(buf) {
+ return buf && typeof buf.byteLength === 'number' && buf.byteLength > 0;
+}
+
+function bufToDataView(buf) {
+ if (buf instanceof DataView) return buf;
+ if (ArrayBuffer.isView(buf)) {
+ return new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
+ }
+ if (buf instanceof ArrayBuffer) {
+ return new DataView(buf);
+ }
+ // Node Buffer is a Uint8Array under the hood; covered above.
+ throw new TypeError('expected Buffer / Uint8Array / DataView / ArrayBuffer');
+}
+
+function bufSlice(buf, start, end) {
+ if (Buffer.isBuffer?.(buf)) return buf.subarray(start, end);
+ if (ArrayBuffer.isView(buf)) {
+ return new Uint8Array(buf.buffer, buf.byteOffset + start, end - start);
+ }
+ return new Uint8Array(buf, start, end - start);
+}
diff --git a/api/avatars/_actions.js b/api/avatars/_actions.js
index 55491cf3e..159e07e6d 100644
--- a/api/avatars/_actions.js
+++ b/api/avatars/_actions.js
@@ -414,6 +414,25 @@ const handleRegenerateStatus = wrap(async (req, res) => {
const glbResp = await fetch(job.result_glb_url);
if (!glbResp.ok) throw new Error(`fetch result_glb_url: ${glbResp.status}`);
const glbBuf = Buffer.from(await glbResp.arrayBuffer());
+
+ // Probe the GLB to capture rigging state. Reconstruction families
+ // differ on whether they emit a skeleton (Hunyuan3D yes, TRELLIS/
+ // TripoSR no) — the UI uses source_meta.is_rigged to badge
+ // "needs rigging" and to gate animation features.
+ const { inspectGlb } = await import('../_lib/glb-inspect.js');
+ const info = inspectGlb(glbBuf);
+ const glbMeta = info
+ ? {
+ is_rigged: info.isRigged,
+ skin_count: info.skinCount,
+ skeleton_joint_count: info.skeletonJointCount,
+ node_count: info.nodeCount,
+ mesh_count: info.meshCount,
+ animation_count: info.animationCount,
+ glb_generator: info.generator,
+ }
+ : { is_rigged: null, glb_inspect_error: 'invalid_glb_header' };
+
const slug = `selfie-${Math.random().toString(36).slice(2, 8)}`;
const key = storageKeyFor({ userId, slug });
await putObject({
@@ -422,6 +441,8 @@ const handleRegenerateStatus = wrap(async (req, res) => {
contentType: 'model/gltf-binary',
metadata: { source: 'reconstruct', job_id: jobId },
});
+ const tags = ['selfie'];
+ if (info && !info.isRigged) tags.push('unrigged');
const avatar = await createAvatar({
userId,
storageKey: key,
@@ -432,9 +453,9 @@ const handleRegenerateStatus = wrap(async (req, res) => {
size_bytes: glbBuf.length,
content_type: 'model/gltf-binary',
source: 'reconstruct',
- source_meta: { jobId, provider: job.provider, replicateGlb: job.result_glb_url },
+ source_meta: { jobId, provider: job.provider, replicateGlb: job.result_glb_url, ...glbMeta },
visibility,
- tags: ['selfie'],
+ tags,
checksum_sha256: null,
parent_avatar_id: null,
},
diff --git a/api/webhooks/replicate.js b/api/webhooks/replicate.js
index 9b24d6d3b..8397b5445 100644
--- a/api/webhooks/replicate.js
+++ b/api/webhooks/replicate.js
@@ -22,6 +22,7 @@ import { sql } from '../_lib/db.js';
import { putObject } from '../_lib/r2.js';
import { storageKeyFor, createAvatar } from '../_lib/avatars.js';
import { json, method, wrap, error } from '../_lib/http.js';
+import { inspectGlb } from '../_lib/glb-inspect.js';
const REPLAY_WINDOW_SECONDS = 5 * 60;
@@ -184,6 +185,25 @@ export default wrap(async (req, res) => {
if (!glbResp.ok) throw new Error(`fetch result_glb_url: ${glbResp.status}`);
const glbBuf = Buffer.from(await glbResp.arrayBuffer());
+ // Probe the GLB JSON chunk to capture rigging state. Reconstruction
+ // model families differ on this: Hunyuan3D's generation_all returns
+ // a rigged textured GLB, but TRELLIS / TripoSR return static
+ // meshes. Surfacing is_rigged in source_meta lets the UI badge
+ // "needs rigging" + lets a future auto-rig pass enqueue itself
+ // against avatars that lack a skeleton.
+ const info = inspectGlb(glbBuf);
+ const glbMeta = info
+ ? {
+ is_rigged: info.isRigged,
+ skin_count: info.skinCount,
+ skeleton_joint_count: info.skeletonJointCount,
+ node_count: info.nodeCount,
+ mesh_count: info.meshCount,
+ animation_count: info.animationCount,
+ glb_generator: info.generator,
+ }
+ : { is_rigged: null, glb_inspect_error: 'invalid_glb_header' };
+
const slug = `selfie-${Math.random().toString(36).slice(2, 8)}`;
const key = storageKeyFor({ userId: job.user_id, slug });
await putObject({
@@ -192,6 +212,8 @@ export default wrap(async (req, res) => {
contentType: 'model/gltf-binary',
metadata: { source: 'reconstruct', job_id: job.job_id },
});
+ const tags = ['selfie'];
+ if (info && !info.isRigged) tags.push('unrigged');
const avatar = await createAvatar({
userId: job.user_id,
storageKey: key,
@@ -202,9 +224,15 @@ export default wrap(async (req, res) => {
size_bytes: glbBuf.length,
content_type: 'model/gltf-binary',
source: 'reconstruct',
- source_meta: { jobId: job.job_id, provider: 'replicate', replicateGlb: nextGlbUrl, via: 'webhook' },
+ source_meta: {
+ jobId: job.job_id,
+ provider: 'replicate',
+ replicateGlb: nextGlbUrl,
+ via: 'webhook',
+ ...glbMeta,
+ },
visibility,
- tags: ['selfie'],
+ tags,
checksum_sha256: null,
parent_avatar_id: null,
},
diff --git a/docs/widgets.md b/docs/widgets.md
index a12c42378..80623074b 100644
--- a/docs/widgets.md
+++ b/docs/widgets.md
@@ -436,9 +436,6 @@ window.addEventListener('message', (e) => {
case 'widget:hotspot:open':
// { id, label } — hotspot-tour only: visitor opened a POI
break;
- case 'widget:resize':
- // { width, height } — widget reports its preferred size
- break;
}
});
```