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.

fix(irl): wait for the meshopt decoder before loading a GLB so a cold start no longer shows "Couldn't load this agent"

nirholas2b7ff20be09c
diff --git a/src/ar-studio.js b/src/ar-studio.js
index e8a2b7891..356e78ec8 100644
--- a/src/ar-studio.js
+++ b/src/ar-studio.js
@@ -55,7 +55,7 @@ import {
} from './ar/studio-scene.js';
import { renderQRToSVG } from './erc8004/qr.js';
import { deriveVerticalFovDeg, DEFAULT_DIAG_FOV_DEG } from './irl/camera-fov.js';
-import { createLoadQueue, sharedGLTFLoader } from './irl/load-queue.js';
+import { createLoadQueue, loadGLTF } from './irl/load-queue.js';
import { mountPinIdle } from './irl/pin-idle.js';
import { clampPitch, isFiniteReading, resolveLockYaw, screenPitchDeg } from './irl/sensor-fusion.js';
import { captureComposite, shareOrDownload } from './irl/share-frame.js';
@@ -329,7 +329,7 @@ const templates = new Map();
// await, so it places only sources that have already finished loading.
const tplReady = new Map();
const loadQueue = createLoadQueue({
- run: (src) => sharedGLTFLoader().loadAsync(src),
+ run: (src) => loadGLTF(src),
maxActive: 3,
});
diff --git a/src/irl/load-queue.js b/src/irl/load-queue.js
index 5af972adb..5e3df1dd7 100644
--- a/src/irl/load-queue.js
+++ b/src/irl/load-queue.js
@@ -13,6 +13,10 @@ import { dracoLoader } from '../game/avatar-rig.js';
import { getMeshoptDecoder } from '../viewer/internal.js';
let _loader = null;
+// Settles once the meshopt decoder is attached (or its import failed). Every load
+// goes through loadGLTF() below, which awaits this, so a meshopt-compressed GLB
+// requested in the first frames after boot can never race ahead of the decoder.
+let _ready = null;
// One GLTFLoader for the whole IRL scene. Pin avatars come from arbitrary
// `avatar_url`s — pump.fun/Sketchfab exports are commonly Draco-compressed and
@@ -23,12 +27,24 @@ export function sharedGLTFLoader() {
if (_loader) return _loader;
_loader = new GLTFLoader();
_loader.setDRACOLoader(dracoLoader);
- getMeshoptDecoder()
+ _ready = getMeshoptDecoder()
.then((d) => _loader.setMeshoptDecoder(d))
.catch(() => { /* meshopt GLBs will fail loudly at load; Draco/plain still work */ });
return _loader;
}
+// Load a GLB through the shared loader once both decoders are wired. Most
+// three.ws avatars ship with EXT_meshopt_compression, and the decoder attaches
+// asynchronously: a bare `sharedGLTFLoader().loadAsync()` issued during boot (the
+// viewer's own avatar, the first nearby pin) raced that import and failed with
+// "setMeshoptDecoder must be called before loading compressed files", which /irl
+// surfaced as a "Couldn't load this agent" overlay on a cold start.
+export async function loadGLTF(url) {
+ const loader = sharedGLTFLoader();
+ await _ready;
+ return loader.loadAsync(url);
+}
+
// Generic priority queue with a concurrency cap. `run(item)` returns a promise;
// jobs start nearest-first via `priorityOf(item)` (lower number = sooner). The
// queue never rejects the caller's promise on cancellation silently — a