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(viewer): register the meshopt decoder for model-viewer, avoid the deprecated RGBELoader and Clock warnings, and stop the hidden panel widening the page

nirholas8b7dc6142439
diff --git a/avatar-sdk/src/viewer.js b/avatar-sdk/src/viewer.js
index d3c344ad3..357211c29 100644
--- a/avatar-sdk/src/viewer.js
+++ b/avatar-sdk/src/viewer.js
@@ -85,9 +85,18 @@ function getHdriTexture() {
// three into a hard "module not found" build failure on older three. A
// runtime try/catch cannot rescue that: the failure is at build time.
// Revisit when the peer floor moves to >= 0.180.0.
- _hdriPromise = import('three/addons/loaders/RGBELoader.js').then(({ RGBELoader }) =>
- new RGBELoader().loadAsync(`${AR_LAUNCH_ORIGIN}/hdri/studio.hdr`),
- );
+ //
+ // The warning is avoidable without naming the new module: from r180
+ // RGBELoader is an empty `extends HDRLoader` shim, so its parent class IS
+ // HDRLoader, reachable at runtime. Before r180 the parent is
+ // DataTextureLoader, which leaves `parse()` to its subclass, so owning
+ // `parse` is what tells the two apart (class names do not survive
+ // minification). Old three keeps constructing RGBELoader itself.
+ _hdriPromise = import('three/addons/loaders/RGBELoader.js').then(({ RGBELoader }) => {
+ const parent = Object.getPrototypeOf(RGBELoader);
+ const HDR = Object.prototype.hasOwnProperty.call(parent?.prototype ?? {}, 'parse') ? parent : RGBELoader;
+ return new HDR().loadAsync(`${AR_LAUNCH_ORIGIN}/hdri/studio.hdr`);
+ });
}
return _hdriPromise;
}
diff --git a/pages/create.html b/pages/create.html
index e8624d947..d461c4da4 100644
--- a/pages/create.html
+++ b/pages/create.html
@@ -1071,6 +1071,7 @@
</style>
<link rel="preload" href="/fonts/inter-latin.woff2" as="font" type="font/woff2" crossorigin />
<link rel="preload" href="/fonts/space-grotesk-latin.woff2" as="font" type="font/woff2" crossorigin />
+ <link rel="stylesheet" href="/fonts/fonts.css" />
<link rel="stylesheet" href="/nav.css" />
<link rel="stylesheet" href="/footer.css" />
<link rel="stylesheet" href="/mobile.css" />
diff --git a/pages/forge-nim.html b/pages/forge-nim.html
index 63305d1f0..72d22e1b4 100644
--- a/pages/forge-nim.html
+++ b/pages/forge-nim.html
@@ -35,6 +35,7 @@
<link rel="manifest" href="/manifest.webmanifest" />
<link rel="canonical" href="https://three.ws/forge-nim" />
<link rel="stylesheet" href="/style.css" />
+ <script src="/model-viewer-meshopt.js"></script>
<script
type="module"
src="https://ajax.googleapis.com/ajax/libs/model-viewer/4.3.1/model-viewer.min.js"
diff --git a/pages/nim-forge.html b/pages/nim-forge.html
index 2eec4fd4b..5040a776d 100644
--- a/pages/nim-forge.html
+++ b/pages/nim-forge.html
@@ -11,6 +11,7 @@
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<link rel="stylesheet" href="/style.css" />
<link rel="preconnect" href="https://ajax.googleapis.com" />
+ <script src="/model-viewer-meshopt.js"></script>
<script
type="module"
src="https://ajax.googleapis.com/ajax/libs/model-viewer/4.3.1/model-viewer.min.js"
diff --git a/public/demos/3d-home.html b/public/demos/3d-home.html
index aff9de5d4..57805332a 100644
--- a/public/demos/3d-home.html
+++ b/public/demos/3d-home.html
@@ -826,10 +826,11 @@
}
// ── Render loop ───────────────────────────────────────────────────
- const clock = new THREE.Clock();
- (function tick() {
+ const clock = new THREE.Timer();
+ (function tick(timestamp) {
requestAnimationFrame(tick);
try {
+ clock.update(timestamp);
const dt = Math.min(clock.getDelta(), 0.05);
mixer?.update(dt);
updateSeq(dt);
diff --git a/public/style.css b/public/style.css
index cb0e6887b..3fd113738 100644
--- a/public/style.css
+++ b/public/style.css
@@ -849,9 +849,13 @@ header .site-wordmark .wordmark-logo {
transform var(--duration-base) var(--ease-standard);
}
+/* Scale from the top-right corner rather than slide in from past the edge: a
+ translateX on the hidden panel left it 12px outside the viewport, widening
+ the page's scrollable area even while it was invisible. */
.gui-wrap--hidden {
opacity: 0;
- transform: translateX(12px);
+ transform: scale(0.97);
+ transform-origin: top right;
pointer-events: none !important;
visibility: hidden;
}
diff --git a/src/avatar-page.js b/src/avatar-page.js
index 58fbae63d..16075b489 100644
--- a/src/avatar-page.js
+++ b/src/avatar-page.js
@@ -161,6 +161,10 @@ const MODEL_STORAGE_KEY = 'avatar_chat_model_v1';
// ── Init ──────────────────────────────────────────────────────────────
async function init() {
+ // A working share link from the first paint: the named one below replaces it
+ // once the entity resolves, and a page whose entity never resolves still has
+ // a button that goes somewhere.
+ setShareXHref('Check this out on three.ws');
({ agent, avatar } = await resolveEntity(entityId));
avatarId = avatar.id || '';
viewerOwns = mode === 'agent' ? !!agent.is_owner : !!avatar.owner_id;
@@ -1603,7 +1607,6 @@ function bindTabs() {
function bindShareButtons() {
const linkBtn = $('share-link');
- const twBtn = $('share-twitter');
if (linkBtn) {
linkBtn.addEventListener('click', async () => {
try {
@@ -1619,16 +1622,21 @@ function bindShareButtons() {
}
});
}
- if (twBtn && avatar) {
- const text =
+ if (avatar) {
+ setShareXHref(
mode === 'agent'
? `Meet "${avatar.name}", a 3D AI agent on three.ws`
- : `Check out "${avatar.name}", a 3D avatar on three.ws`;
- const url = `https://twitter.com/intent/tweet?text=${encodeURIComponent(text)}&url=${encodeURIComponent(location.href)}`;
- twBtn.href = url;
+ : `Check out "${avatar.name}", a 3D avatar on three.ws`,
+ );
}
}
+function setShareXHref(text) {
+ const twBtn = $('share-twitter');
+ if (!twBtn) return;
+ twBtn.href = `https://twitter.com/intent/tweet?text=${encodeURIComponent(text)}&url=${encodeURIComponent(location.href)}`;
+}
+
// ── Owner actions (Edit / Deploy on-chain / Launch Pump.fun) ─────────
function bindOwnerActions() {
diff --git a/src/home-forge.js b/src/home-forge.js
index bea2bd08d..77f10f7d4 100644
--- a/src/home-forge.js
+++ b/src/home-forge.js
@@ -41,6 +41,10 @@ import {
nextBackoff,
} from './shared/resilient-poll.js';
import { coldStartLabel } from './shared/forge-frames.js';
+// model-viewer carries its own renderer (~700 KB): the shared loader fetches it
+// only once a generation is running, fails over across CDNs, and registers the
+// meshopt decoder that every Forge GLB needs.
+import { ensureModelViewer } from './shared/model-viewer-loader.js';
const POLL_INTERVAL_MS = 2500;
// Max-tier texture bakes legitimately run past 10 minutes at full quality; the
@@ -52,8 +56,6 @@ const MAX_POLL_MS = 12 * 60 * 1000;
// keeps holding until the network has been unusable for this long.
const POLL_MAX_BACKOFF_MS = 20_000;
const POLL_TRANSPORT_GRACE_MS = 90_000;
-const MODEL_VIEWER_SRC =
- 'https://ajax.googleapis.com/ajax/libs/model-viewer/4.3.1/model-viewer.min.js';
const HISTORY_KEY = 'forge:home:history';
const HISTORY_MAX = 6;
// Cumulative models forged on this device, driving the sparse milestone nudge
@@ -162,7 +164,6 @@ let lastPrompt = '';
let controls = null;
let highBlocked = false;
let enhanceBusy = false;
-let modelViewerReady = null;
let currentViewer = null; // the live <model-viewer> on stage
let currentGlbUrl = ''; // what the toolbar acts on
let currentCreationId = ''; // persisted creation id → real shareable permalink
@@ -176,23 +177,6 @@ let runSeq = 0;
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
-// model-viewer carries its own renderer (~700 KB) — fetch it only once a
-// generation is actually running, so it's registered by the time the GLB lands.
-function ensureModelViewer() {
- if (modelViewerReady) return modelViewerReady;
- modelViewerReady = customElements.get('model-viewer')
- ? Promise.resolve()
- : new Promise((resolve, reject) => {
- const s = document.createElement('script');
- s.type = 'module';
- s.src = MODEL_VIEWER_SRC;
- s.crossOrigin = 'anonymous';
- s.onload = () => resolve();
- s.onerror = () => reject(new Error('Failed to load the 3D viewer.'));
- document.head.appendChild(s);
- });
- return modelViewerReady;
-}
// Honest telemetry words for the HUD readout, keyed by state.
const TEL_WORDS = { idle: 'standby', generating: 'forging', result: 'complete', error: 'error' };
diff --git a/src/shared/model-viewer-loader.js b/src/shared/model-viewer-loader.js
index 97ef4c7a9..e887f8d35 100644
--- a/src/shared/model-viewer-loader.js
+++ b/src/shared/model-viewer-loader.js
@@ -24,6 +24,24 @@ const PER_SOURCE_TIMEOUT_MS = 12_000;
let _pending = null;
let _defineGuarded = false;
+// model-viewer auto-loads Draco and KTX2 but leaves the meshopt decoder unset,
+// and every server-baked avatar and Forge GLB ships EXT_meshopt_compression, so
+// without it the viewer throws "setMeshoptDecoder must be called before loading
+// compressed files" and the model never renders. The decoder config is captured
+// when a load starts, so it is set inside define(), before any element upgrades.
+// Same-origin copy, vendored by scripts/vendor-meshopt-decoder.mjs (the same
+// file public/model-viewer-meshopt.js points classic-script pages at).
+const MESHOPT_DECODER_URL = '/vendor/meshopt_decoder.js';
+
+function registerMeshopt(ctor) {
+ if (!ctor || ctor.meshoptDecoderLocation) return;
+ try {
+ ctor.meshoptDecoderLocation = MESHOPT_DECODER_URL;
+ } catch {
+ /* read-only in some future build: the model-viewer default stands */
+ }
+}
+
// The chain abandons a source after PER_SOURCE_TIMEOUT_MS, but removing a
// <script> does not cancel a fetch already in flight: a slow first CDN can
// still execute after a later one defined the element, and that second
@@ -37,7 +55,10 @@ function guardDuplicateDefine() {
_defineGuarded = true;
const nativeDefine = customElements.define;
customElements.define = function (name, ctor, options) {
- if (name === 'model-viewer' && customElements.get(name)) return undefined;
+ if (name === 'model-viewer') {
+ if (customElements.get(name)) return undefined;
+ registerMeshopt(ctor);
+ }
return nativeDefine.call(this, name, ctor, options);
};
}
@@ -74,7 +95,10 @@ function loadScript(src) {
* @returns {Promise<void>}
*/
export function ensureModelViewer() {
- if (typeof customElements !== 'undefined' && customElements.get('model-viewer')) return Promise.resolve();
+ if (typeof customElements !== 'undefined' && customElements.get('model-viewer')) {
+ registerMeshopt(customElements.get('model-viewer'));
+ return Promise.resolve();
+ }
if (_pending) return _pending;
guardDuplicateDefine();
_pending = (async () => {