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: enhance 3D rendering with improved shadow and lighting configurations

nirholas99257101b19a
diff --git a/STRUCTURE.md b/STRUCTURE.md
index 086430b66..de871e271 100644
--- a/STRUCTURE.md
+++ b/STRUCTURE.md
@@ -65,6 +65,7 @@ bottom.
| Embed examples | [examples/](examples) | In-repo | `embed-test.html`, `web-component.html`, `two-agents.html`, `minimal.html`, [agent-native-3d/](examples/agent-native-3d) (below) |
| Agent-native 3D + embeddable distribution | MCP tool [api/_mcp/tools/agents.js](api/_mcp/tools/agents.js) (`attach_avatar_to_agent`); shared oEmbed provider [api/agent-oembed.js](api/agent-oembed.js) `→ /api/oembed` + builder [api/_lib/embed.js](api/_lib/embed.js) (`forgeEmbedTarget`, shared by `get_embed_code` in [api/_mcp/tools/embed.js](api/_mcp/tools/embed.js)); Forge share page oEmbed discovery [api/forge-share.js](api/forge-share.js) `→ /forge/share/:id`; distribution snippet builders [src/forge-embed-snippets.js](src/forge-embed-snippets.js) + panel [src/forge-embed-panel.js](src/forge-embed-panel.js); autonomous demo [examples/agent-native-3d/](examples/agent-native-3d) | In-repo | Closes the loop: create → own → discover/remix → **use everywhere**. `attach_avatar_to_agent` gives a registered agent identity a persistent body (chains into `register_agent` for on-chain identity + `anchor_provenance` for a signed authenticity credential). Any Forge creation now unfurls via real oEmbed (paste `/forge/share/:id` into Notion/Discord/Slack) with the same `type:rich` iframe payload `get_embed_code` returns via MCP. The Forge "Embed this model" panel hands out five real distribution flavours from one GLB — iframe, `<model-viewer>`, `<agent-3d>`, a `@three-ws/page-agent` talking guide, and a `@three-ws/walk` companion — all built from one shared, pure snippet module so every surface stays byte-identical. `examples/agent-native-3d/run.mjs` drives the full agent-native chain live against `/api/mcp-studio` (mesh_forge → rig_mesh → create_agent_persona → persona_say → get_agent_persona → every distribution snippet) with zero mocks and a documented, logged fallback if the shared free-tier generation lane is rate-limited at run time. Spec: [specs/EMBED_SPEC.md](specs/EMBED_SPEC.md#share-routes-on-chain-agents). Docs: [docs/mcp.md#attach_avatar_to_agent](docs/mcp.md#attach_avatar_to_agent). Roadmap prompt 10 (closes the roadmap campaign). |
| Animation pipeline | [public/animations/](public/animations) + [scripts/build-animations.mjs](scripts/build-animations.mjs) | In-repo | Mixamo source FBX + GLB retargeting pipeline · see [docs/3d-asset-pipeline.md](docs/3d-asset-pipeline.md) |
+| Self-hosted 3D GPU fleet (the engines behind the Forge) | [workers/model-trellis/](workers/model-trellis), [workers/model-hunyuan3d/](workers/model-hunyuan3d) (2.0 + 2.1 PBR + 2.1 RTX), [workers/model-triposg/](workers/model-triposg), [workers/model-triposr/](workers/model-triposr), [workers/unirig/](workers/unirig), [workers/avatar-reconstruction/](workers/avatar-reconstruction), CPU stages [workers/rembg/](workers/rembg) · [workers/remesh/](workers/remesh) · [workers/segment/](workers/segment) · [workers/stylize/](workers/stylize) | Live · Cloud Run GPU (us-central1 + trellis/hunyuan replicas in us-east4) | Every generation engine the Forge dispatches to, each with its own `cloudbuild.yaml`. L4 services share a 3-GPU regional quota (increase to 16 pending); the Hunyuan3D-2.1 PBR realism lane also ships an RTX PRO 6000 build (`model-hunyuan3d-21-rtx`, quota granted 1000) as the warm primary. Ops map: [docs/ops/gcp-credits-plan.md](docs/ops/gcp-credits-plan.md) |
| Auto-rigging worker (Mixamo skeleton + ARKit-52 blendshapes) | [workers/rig/](workers/rig) | Code-complete · deploy pending (asset staging + Cloud Build, see its README) | Make-It-Animatable engine (MIT) predicts the 52-bone Mixamo skeleton + weights; [workers/rig/rig_glb.py](workers/rig/rig_glb.py) grafts them into the original GLB (textures untouched); ICT-FaceKit (MIT) ARKit-52 expression transfer for emotions/lipsync. Contract-compatible replacement for the retired `unirig` service behind `GCP_UNIRIG_URL`; cutover is one env-var update. Canonicalization proof: `rig worker skeleton` cases in [tests/glb-canonicalize.test.js](tests/glb-canonicalize.test.js) |
| Animation gallery | [pages/animations.html](pages/animations.html) + [src/animations-gallery.js](src/animations-gallery.js) | Live at `/animations` | 2,100+ clips with poster thumbnails ([scripts/build-animation-thumbnails.mjs](scripts/build-animation-thumbnails.mjs)), derived categories ([src/animation-categories.js](src/animation-categories.js)), shared live-preview engine ([src/animations-live-preview.js](src/animations-live-preview.js)) · see [docs/animations.md](docs/animations.md) |
| Avatar thumbnail coverage | [api/_lib/avatar-thumbs.js](api/_lib/avatar-thumbs.js) + crons [api/cron/avatar-thumbnail-backfill.js](api/cron/avatar-thumbnail-backfill.js) (absent thumbnails, `*/5`) and [api/cron/avatar-thumbnail-render.js](api/cron/avatar-thumbnail-render.js) (stale marketplace thumbnails, `*/10`) | Live | The single owner of `avatars.thumbnail_key`. Enforces the invariant that a thumbnail key is persisted **only after** its R2 object is confirmed to exist — a key pointing at a missing object makes R2 return 404 `text/plain`, which Chrome blocks as `ERR_BLOCKED_BY_ORB` inside an `<img>`. Fills coverage cheapest-first: zero-copy adoption of `forge_creations.preview_key`, then a headless-chromium GLB→PNG render to `thumb/<avatarId>.png` ([api/_lib/render-glb.js](api/_lib/render-glb.js)). Bounded retries via the `avatar_thumbnail_backfill` claim ledger ([migration](api/_lib/migrations/20260709120000_avatar_thumbnail_backfill.sql)), with `isBrowserInfrastructureError()` separating an OOM-killed browser from a genuinely broken model so a crash never retires healthy avatars. Bulk runner: [scripts/backfill-avatar-thumbnails.mjs](scripts/backfill-avatar-thumbnails.mjs) (`--status`, `--adopt-only`, `--loop`, `--reset-infra`). Docs: [docs/avatar-thumbnails.md](docs/avatar-thumbnails.md). Tests: [tests/avatar-thumbs.test.js](tests/avatar-thumbs.test.js), [tests/home-thumbnail-orb.test.js](tests/home-thumbnail-orb.test.js) |
diff --git a/api/_lib/migrations/2026-07-17-x402-ring-pool.sql b/api/_lib/migrations/2026-07-17-x402-ring-pool.sql
new file mode 100644
index 000000000..8bc374df5
--- /dev/null
+++ b/api/_lib/migrations/2026-07-17-x402-ring-pool.sql
@@ -0,0 +1,41 @@
+-- x402 ring payer-wallet POOL — a reused set of custodial payer wallets the ring
+-- tick rotates through so the closed-loop economy has many distinct, attributed
+-- payers instead of one seed wallet, at NO extra per-settle cost.
+--
+-- Why a pool (vs. throwaway wallets per call): a fresh wallet per settle would add
+-- a funding hop + a one-time USDC-ATA rent (~0.00204 SOL ≈ $0.15) EVERY call, and
+-- would still be trivially clusterable on-chain (all funded from one float). A
+-- REUSED pool pays that rent ONCE per wallet, keeps the settle on the 1-signature
+-- self-pay hot path (1 tx/settle), and — because the wallets are the least-recently
+-- -used-first rotation — produces effectively unlimited distinct-payer sequences
+-- from a few hundred wallets. See docs/x402-ring-economy.md ("Payer pool").
+--
+-- Membership: each pool pubkey is ALSO written to x402_ring_wallets(role='pool') by
+-- the generator, so ringAllowedAddresses() (the controlled-wallet set) and the
+-- on-chain leak scanner classify every pool wallet as INTERNAL automatically, and
+-- the facilitator allowlist accepts settlements from them. Pool wallets are
+-- deliberately NOT in api/_lib/solana-signers.js, so the economy master's
+-- treasury-sweepback never enumerates (and never closes the ATAs of) 1,000 wallets.
+--
+-- Secrets: unlike the three env-held role wallets, a 500–1,000-wallet pool cannot
+-- live in env vars — each secret is stored here encrypted with the same
+-- secret-box scheme (WALLET_ENCRYPTION_KEY + random per-record salt) used for
+-- custodial agent wallets. The plaintext key never leaves the process.
+
+CREATE TABLE IF NOT EXISTS x402_ring_pool (
+ pubkey text PRIMARY KEY,
+ encrypted_secret text NOT NULL, -- secret-box ciphertext (never plaintext)
+ enabled boolean NOT NULL DEFAULT true,
+ last_used_at timestamptz, -- LRU rotation cursor; NULL = never used
+ use_count bigint NOT NULL DEFAULT 0,
+ created_at timestamptz NOT NULL DEFAULT now()
+);
+
+-- The rotation claim orders by (last_used_at NULLS FIRST, pubkey): never-used
+-- wallets first, then the stalest. This index makes that ORDER BY … LIMIT 1 an
+-- index scan even at 1,000+ rows.
+CREATE INDEX IF NOT EXISTS x402_ring_pool_rotation
+ ON x402_ring_pool (enabled, last_used_at NULLS FIRST, pubkey);
+
+COMMENT ON TABLE x402_ring_pool IS
+ 'Reused custodial payer wallets the ring tick rotates through (LRU). Pubkeys mirrored into x402_ring_wallets(role=pool). Secrets secret-box-encrypted. Not in solana-signers.js so sweepback never touches them.';
diff --git a/api/_lib/solana-signers.js b/api/_lib/solana-signers.js
index b7d014e77..bbd3f5155 100644
--- a/api/_lib/solana-signers.js
+++ b/api/_lib/solana-signers.js
@@ -56,7 +56,20 @@ export const SOLANA_SIGNERS = [
name: 'pump-x402-launcher',
env: 'PUMP_X402_LAUNCHER_SECRET_KEY_B64',
minSol: 0.1,
- purpose: 'fronts the ~0.022 SOL deploy cost for x402 pay-per-call pump.fun launches',
+ // CRITICAL: this env resolves to the SAME physical wallet as the x402 ring
+ // TREASURY / receiver (X402_PAY_TO_SOLANA / X402_TREASURY_SECRET_BASE58 →
+ // secret `wallet-x402-treasury-b64`, pubkey wwwww…ccrU). That wallet holds
+ // the ring's live USDC float and platform x402 revenue. Without holdsTokens,
+ // the excess-mode treasury-sweepback consolidated its USDC up to the master
+ // AND closed its USDC ATA every run — so every following ring settle had to
+ // recreate the ATA at ~2,039,280 lamports of rent, which is what dragged the
+ // per-settle fee to ~570k lamports (114× the 5k self-pay floor) and quietly
+ // drained the closed loop's float into the master. holdsTokens keeps the
+ // ring float where the ring's own rebalancer (treasury→payer) can
+ // recirculate it; only an explicit drain may still consolidate it.
+ holdsTokens: true,
+ purpose:
+ 'fronts the ~0.022 SOL deploy cost for x402 pay-per-call pump.fun launches; ALSO the x402 ring treasury/receiver (holds USDC revenue + ring float) — holdsTokens protects it from excess-mode sweepback',
network: 'mainnet',
},
{
diff --git a/docs/ops/gcp-credits-plan.md b/docs/ops/gcp-credits-plan.md
index 8db06e32c..c74db681f 100644
--- a/docs/ops/gcp-credits-plan.md
+++ b/docs/ops/gcp-credits-plan.md
@@ -16,7 +16,7 @@ Six GPU services share those 3 GPUs:
| model-triposg | image-to-3D | 0 | 2 |
| unirig | auto-rigging | 1 | 2 |
| avatar-reconstruction | photo-to-avatar | 1 | 3 |
-| model-hunyuan3d-21 | PBR realism lane, L4 fallback build (min 0 since 2026-07-17; a pinned min 1 here starved every other rollout) | 0 | 1 |
+| model-hunyuan3d-21 | PBR realism lane, L4 build (min 0 since 2026-07-17; a pinned min 1 here starved every other rollout). KNOWN-BROKEN for actual jobs: 18 GiB tmpfs weight staging + 14 GiB model OOMs the 32 Gi L4 ceiling (signal 9 mid-load); see workers/model-hunyuan3d/README.md | 0 | 1 |
`model-hunyuan3d-21-rtx` (same 2.1 PBR lane, warm min 1 / max 4) does NOT draw
from this pool; it runs on the RTX PRO 6000 quota below.
diff --git a/public/3d.html b/public/3d.html
index 8e4222005..77aecd6fc 100644
--- a/public/3d.html
+++ b/public/3d.html
@@ -219,8 +219,11 @@ curl https://three.ws/api/3d/openapi.json</code></pre>
alt="A rigged 3D character model rendered from a GLB file"
camera-controls
auto-rotate
+ tone-mapping="aces"
+ environment-image="/environments/gallery/env.hdr"
shadow-intensity="1"
- exposure="1.05"
+ shadow-softness="0.9"
+ exposure="1.5"
ar
touch-action="pan-y"
></model-viewer>
diff --git a/public/viewer.html b/public/viewer.html
index abcf0bdea..992226dde 100644
--- a/public/viewer.html
+++ b/public/viewer.html
@@ -12,7 +12,12 @@
<meta property="og:type" content="website" />
<!-- Meshopt decoder must register before <model-viewer> starts loading (Forge GLBs are meshopt-compressed). Classic script → runs during parse, before the model-viewer module. -->
<script src="/model-viewer-meshopt.js"></script>
-<script type="module" src="https://cdn.jsdelivr.net/npm/@google/[email protected]/dist/model-viewer.min.js"></script>
+<script
+ type="module"
+ src="https://ajax.googleapis.com/ajax/libs/model-viewer/4.0.0/model-viewer.min.js"
+ integrity="sha384-sr9b4Ux0WhAUGclJ0ym0FSY2zSOMmNSn0bP/SA0e6bNCrpn/5W3QL8mm+LdlQMKw"
+ crossorigin="anonymous"
+></script>
<style>
:root { color-scheme: dark; --accent: #6ea8fe; }
* { box-sizing: border-box; }
@@ -156,7 +161,7 @@
<div class="stage">
<model-viewer id="mv" class="veiled" camera-controls auto-rotate touch-action="pan-y"
rotation-per-second="14deg" interaction-prompt="none"
- shadow-intensity="1" shadow-softness="0.85" exposure="1.05" environment-image="neutral" tone-mapping="aces"
+ shadow-intensity="1" shadow-softness="0.9" exposure="1.5" environment-image="/environments/gallery/env.hdr" tone-mapping="aces"
ar ar-modes="webxr scene-viewer quick-look" ar-scale="auto" reveal="auto" alt="Generated 3D model">
</model-viewer>
diff --git a/scripts/act2-harness.html b/scripts/act2-harness.html
new file mode 100644
index 000000000..4fbb75346
--- /dev/null
+++ b/scripts/act2-harness.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8" />
+<title>Act2Viewer harness (temporary, verification only)</title>
+<style>html,body{margin:0;height:100%;background:#101018}canvas{width:100vw;height:100vh;display:block}</style>
+</head>
+<body>
+<canvas id="c"></canvas>
+<script type="module">
+import '/src/home-act2-viewer.js';
+const v = new window.Act2Viewer(document.getElementById('c'));
+await v.loadModel('/avatars/cesium-man.glb');
+window.__act2 = v;
+window.__act2Ready = true;
+</script>
+</body>
+</html>
diff --git a/scripts/viewer-shadow-harness.html b/scripts/viewer-shadow-harness.html
new file mode 100644
index 000000000..e0b4dbe4e
--- /dev/null
+++ b/scripts/viewer-shadow-harness.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8" />
+<title>viewer.js shadow harness (temporary, verification only)</title>
+<style>html,body{margin:0;height:100%;background:#1a1a2e}#stage{position:fixed;inset:0}</style>
+</head>
+<body>
+<div id="stage"></div>
+<script type="module">
+import { Viewer } from '/src/viewer.js';
+const viewer = new Viewer(document.getElementById('stage'), { kiosk: true });
+await viewer.load('/avatars/cesium-man.glb', '', new Map());
+window.__viewerReady = true;
+window.__viewer = viewer;
+</script>
+</body>
+</html>
diff --git a/src/forge-embed-snippets.js b/src/forge-embed-snippets.js
index b1b70dfeb..f1ae91ea5 100644
--- a/src/forge-embed-snippets.js
+++ b/src/forge-embed-snippets.js
@@ -97,7 +97,10 @@ export function buildWebComponentSnippet(glbUrl, title, sizeId) {
` src="${escEmbed(glbUrl)}"\n` +
` alt="${alt}"\n` +
` camera-controls auto-rotate ar\n` +
- ` shadow-intensity="1"\n` +
+ ` tone-mapping="aces"\n` +
+ ` environment-image="${ORIGIN}/environments/gallery/env.hdr"\n` +
+ ` exposure="1.5"\n` +
+ ` shadow-intensity="1" shadow-softness="0.9"\n` +
` style="width:${s.w}px;height:${s.h}px;max-width:100%;background:#0b0b0b;border-radius:14px">` +
`\n</model-viewer>`
);
diff --git a/src/forge-studio/forge-embed-snippets.js b/src/forge-studio/forge-embed-snippets.js
index 30f1c215a..1e4297788 100644
--- a/src/forge-studio/forge-embed-snippets.js
+++ b/src/forge-studio/forge-embed-snippets.js
@@ -88,7 +88,10 @@ export function buildWebComponentSnippet(glbUrl, title, sizeId) {
` src="${escEmbed(glbUrl)}"\n` +
` alt="${alt}"\n` +
` camera-controls auto-rotate ar\n` +
- ` shadow-intensity="1"\n` +
+ ` tone-mapping="aces"\n` +
+ ` environment-image="${ORIGIN}/environments/gallery/env.hdr"\n` +
+ ` exposure="1.5"\n` +
+ ` shadow-intensity="1" shadow-softness="0.9"\n` +
` style="width:${s.w}px;height:${s.h}px;max-width:100%;background:#0b0b0b;border-radius:14px">` +
`\n</model-viewer>`
);
diff --git a/src/home-act2-viewer.js b/src/home-act2-viewer.js
index ab5b11093..aa2d5f9b7 100644
--- a/src/home-act2-viewer.js
+++ b/src/home-act2-viewer.js
@@ -24,6 +24,10 @@ import {
ACESFilmicToneMapping,
SRGBColorSpace,
PMREMGenerator,
+ PCFShadowMap,
+ PlaneGeometry,
+ ShadowMaterial,
+ Mesh,
} from 'three';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { getMeshoptDecoder } from './viewer/internal.js';
@@ -60,6 +64,24 @@ export class Act2Viewer {
sun.position.set(4, 8, 6);
this.scene.add(sun);
+ /* soft contact shadow so the model reads as grounded, matching the
+ * shadow-intensity the model-viewer surfaces already ship. The catcher
+ * is a ShadowMaterial plane: invisible except where the shadow falls,
+ * so it works on this alpha-transparent canvas. */
+ this.renderer.shadowMap.enabled = true;
+ this.renderer.shadowMap.type = PCFShadowMap;
+ sun.castShadow = true;
+ sun.shadow.mapSize.set(1024, 1024);
+ sun.shadow.bias = -0.002;
+ this._sun = sun;
+ const catcher = new Mesh(
+ new PlaneGeometry(20, 20),
+ new ShadowMaterial({ opacity: 0.3 }),
+ );
+ catcher.rotation.x = -Math.PI / 2;
+ catcher.receiveShadow = true;
+ this.scene.add(catcher);
+
/** @type {Map<string, AnimationClip>} */
this.clips = new Map();
/** @type {THREE.AnimationAction|null} */
@@ -90,7 +112,32 @@ export class Act2Viewer {
this._disposed = false;
this._raf = null;
this._tick = this._tick.bind(this);
- this._raf = requestAnimationFrame(this._tick);
+
+ /* Render only while the canvas is actually watchable: the homepage
+ * keeps this section mounted while the user scrolls, so without these
+ * gates the turntable burns GPU offscreen and in background tabs. */
+ this._inView = true;
+ this._onVisibility = () => this._syncRunning();
+ document.addEventListener('visibilitychange', this._onVisibility);
+ this._io = new IntersectionObserver(([entry]) => {
+ this._inView = !!entry?.isIntersecting;
+ this._syncRunning();
+ });
+ this._io.observe(canvas);
+ this._syncRunning();
+ }
+
+ _syncRunning() {
+ const shouldRun = !this._disposed && this._inView && !document.hidden;
+ if (shouldRun && this._raf === null) {
+ // Timer keeps accruing while paused; consume the backlog so the
+ // first resumed frame doesn't jump the animation.
+ this._clock.update();
+ this._raf = requestAnimationFrame(this._tick);
+ } else if (!shouldRun && this._raf !== null) {
+ cancelAnimationFrame(this._raf);
+ this._raf = null;
+ }
}
_resize() {
@@ -127,6 +174,8 @@ export class Act2Viewer {
if (this._raf) cancelAnimationFrame(this._raf);
this._raf = null;
this._ro?.disconnect();
+ this._io?.disconnect();
+ document.removeEventListener('visibilitychange', this._onVisibility);
if (this.mixer) { this.mixer.stopAllAction(); this.mixer = null; }
if (this.model) { this.scene.remove(this.model); this.model = null; }
// Release GPU-side geometry/material/texture handles before the context.
@@ -228,11 +277,26 @@ export class Act2Viewer {
await this._meshoptReady;
const gltf = await this._loader.loadAsync(url);
this.model = gltf.scene;
+ this.model.traverse((n) => {
+ if (n.isMesh) n.castShadow = true;
+ });
this.scene.add(this.model);
/* center horizontally + plant feet on ground */
const box = new Box3().setFromObject(this.model);
const size = box.getSize(new Vector3());
+
+ /* fit the sun's shadow frustum to this model so the contact shadow
+ * stays crisp for a 30cm prop and still covers a 3m rig */
+ const shadowR = Math.max(size.x, size.y, size.z, 1) * 1.2;
+ const cam = this._sun.shadow.camera;
+ cam.left = -shadowR;
+ cam.right = shadowR;
+ cam.top = shadowR;
+ cam.bottom = -shadowR;
+ cam.near = 0.5;
+ cam.far = 30;
+ cam.updateProjectionMatrix();
const center = box.getCenter(new Vector3());
this.model.position.x -= center.x;
this.model.position.z -= center.z;
diff --git a/src/viewer.js b/src/viewer.js
index efece9b79..4a276a0bb 100644
--- a/src/viewer.js
+++ b/src/viewer.js
@@ -14,9 +14,12 @@ import {
Mesh,
PMREMGenerator,
PerspectiveCamera,
+ PCFShadowMap,
+ PlaneGeometry,
Points,
PointsMaterial,
Scene,
+ ShadowMaterial,
SkeletonHelper,
Spherical,
Vector3,
@@ -279,6 +282,13 @@ export class Viewer {
this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, dprCap));
this.renderer.setSize(el.clientWidth, el.clientHeight);
+ // Ground contact shadow (the one rendering-quality gap vs the
+ // model-viewer surfaces). Cheap when nothing casts; skipped entirely on
+ // low-power devices, matching the MSAA/DPR degrade above.
+ this.renderer.shadowMap.enabled = !this._lowPower;
+ this.renderer.shadowMap.type = PCFShadowMap;
+ this.shadowCatcher = null;
+
this.pmremGenerator = new PMREMGenerator(this.renderer);
this.pmremGenerator.compileEquirectangularShader();
@@ -1156,6 +1166,44 @@ export class Viewer {
* @param {THREE.Object3D} object
* @param {Array<THREE.AnimationClip} clips
*/
+ // Soft ground contact shadow: a ShadowMaterial plane just under the
+ // recentered model (feet sit at -bbSize.y/2 after setContent recentering).
+ // Created once, then resized/repositioned per load; invisible except where
+ // the shadow_light's shadow falls, so it composes with any bgColor.
+ _updateShadowCatcher(bbSize) {
+ if (this._lowPower) return;
+ if (!isFinite(bbSize.x) || !isFinite(bbSize.y) || !isFinite(bbSize.z)) return;
+ if (!this.shadowCatcher) {
+ this.shadowCatcher = new Mesh(
+ new PlaneGeometry(1, 1),
+ new ShadowMaterial({ opacity: 0.25, depthWrite: false }),
+ );
+ this.shadowCatcher.rotation.x = -Math.PI / 2;
+ this.shadowCatcher.receiveShadow = true;
+ this.shadowCatcher.name = 'shadow_catcher';
+ this.scene.add(this.shadowCatcher);
+ }
+ const span = Math.max(bbSize.x, bbSize.z, 0.5) * 3;
+ this.shadowCatcher.scale.set(span, span, 1);
+ this.shadowCatcher.position.y = -bbSize.y / 2 + 0.002;
+
+ // Fit the caster's frustum to the model so shadow texels aren't wasted
+ // on a prop or clipped on an oversized scene.
+ const sun = this.lights.find((l) => l.name === 'shadow_light');
+ if (sun) {
+ const r = Math.max(bbSize.x, bbSize.y, bbSize.z, 0.5) * 1.2;
+ sun.position.set(r * 0.4, r * 1.6, r * 0.7); // keep the overhead angle at any scale
+ const cam = sun.shadow.camera;
+ cam.left = -r;
+ cam.right = r;
+ cam.top = r;
+ cam.bottom = -r;
+ cam.near = 0.1;
+ cam.far = r * 4;
+ cam.updateProjectionMatrix();
+ }
+ }
+
setContent(object, clips) {
this.clear();
@@ -1199,6 +1247,7 @@ export class Viewer {
object.traverse((node) => {
if (node.isMesh && node.geometry) {
node.geometry.computeBoundsTree();
+ node.castShadow = true;
}
});
@@ -1294,6 +1343,7 @@ export class Viewer {
this.controls.saveState();
this.updateLights();
+ this._updateShadowCatcher(bbSize); // after updateLights so shadow_light exists to fit
this.updateGUI();
this.updateEnvironment();
this.updateDisplay();
@@ -2344,6 +2394,13 @@ export class Viewer {
this.lights.forEach((light) => light.parent?.remove(light));
this.lights = [];
+ if (this.shadowCatcher) {
+ this.scene.remove(this.shadowCatcher);
+ this.shadowCatcher.geometry?.dispose();
+ this.shadowCatcher.material?.dispose();
+ this.shadowCatcher = null;
+ }
+
if (this.annotationEls.length) {
this.annotationEls.forEach((a) => a.el.remove());
this.annotationEls = [];
diff --git a/src/viewer/lights.js b/src/viewer/lights.js
index ae8a86ac7..fb497c2cb 100644
--- a/src/viewer/lights.js
+++ b/src/viewer/lights.js
@@ -42,6 +42,23 @@ export function addLights(viewer) {
viewer.scene.add(rim);
viewer.lights.push(ambient, key, fill, rim);
+
+ // World-anchored overhead light whose only real job is the soft contact
+ // shadow on the ground catcher (see viewer.js _updateShadowCatcher). It is
+ // deliberately NOT the camera-riding key: a camera-space caster would spin
+ // the shadow around the model as the user orbits. Intensity stays low so
+ // the calibrated studio rig above still defines the look. Skipped on
+ // low-power devices along with the shadow map itself.
+ if (!viewer._lowPower) {
+ const shadowSun = new DirectionalLight('#FFFFFF', 0.25);
+ shadowSun.position.set(1.5, 4, 2.5);
+ shadowSun.castShadow = true;
+ shadowSun.shadow.mapSize.set(1024, 1024);
+ shadowSun.shadow.bias = -0.002;
+ shadowSun.name = 'shadow_light';
+ viewer.scene.add(shadowSun);
+ viewer.lights.push(shadowSun);
+ }
}
export function removeLights(viewer) {
diff --git a/src/walk-embed-preview.js b/src/walk-embed-preview.js
index f14b79716..2fa7bdb13 100644
--- a/src/walk-embed-preview.js
+++ b/src/walk-embed-preview.js
@@ -99,7 +99,7 @@ export function initWalkPreview(container) {
const sun = new DirectionalLight(0xffffff, 1.4);
sun.position.set(4, 8, 6);
sun.castShadow = true;
- sun.shadow.mapSize.set(512, 512);
+ sun.shadow.mapSize.set(1024, 1024); // match walk.js / walk-embed.js so preview shadows don't stair-step
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 30;
sun.shadow.camera.left = -8;
diff --git a/tests/src/forge-embed-snippets.test.js b/tests/src/forge-embed-snippets.test.js
index 9d5e131a2..dbc952d24 100644
--- a/tests/src/forge-embed-snippets.test.js
+++ b/tests/src/forge-embed-snippets.test.js
@@ -45,6 +45,13 @@ describe('buildIframeSnippet / buildWebComponentSnippet / buildAgentThreeDSnippe
expect(iframe).toContain(encodeURIComponent(GLB));
expect(component).toContain(GLB);
expect(component).toContain('<model-viewer');
+ // The pasted snippet must render at studio quality, not model-viewer's
+ // legacy-neutral defaults — same env HDR / tone mapping / exposure as
+ // the Forge studio viewer (pages/forge.html) and /forge/embed.
+ expect(component).toContain('tone-mapping="aces"');
+ expect(component).toContain('environment-image="https://three.ws/environments/gallery/env.hdr"');
+ expect(component).toContain('exposure="1.5"');
+ expect(component).toContain('shadow-softness="0.9"');
expect(agent3d).toContain(GLB);
expect(agent3d).toContain('<agent-3d');
expect(agent3d).toContain('viewer');
diff --git a/workers/model-hunyuan3d/Dockerfile.hunyuan21rtx b/workers/model-hunyuan3d/Dockerfile.hunyuan21rtx
index 9816366bd..290cc619b 100644
--- a/workers/model-hunyuan3d/Dockerfile.hunyuan21rtx
+++ b/workers/model-hunyuan3d/Dockerfile.hunyuan21rtx
@@ -45,14 +45,9 @@ RUN pip install -r /app/requirements.txt
# save_glb OBJ->GLB exporter in DifferentiableRenderer.mesh_utils. Drop a tiny
# stub module so the top-level `import bpy` in that file resolves; this worker
# assembles the PBR GLB with pygltflib and never calls a bpy function.
-RUN python - <<'PY'
-import os, sysconfig
-dest = os.path.join(sysconfig.get_paths()["purelib"], "bpy.py")
-with open(dest, "w") as f:
- f.write("# stub: real Blender bpy is only needed for the unused save_glb "
- "OBJ->GLB exporter. This worker builds the PBR GLB with pygltflib.\n")
-print("wrote bpy stub to", dest)
-PY
+RUN DEST=$(python -c "import sysconfig; print(sysconfig.get_paths()['purelib'])")/bpy.py \
+ && printf '%s\n' "# stub: real Blender bpy is only needed for the unused save_glb OBJ->GLB exporter. This worker builds the PBR GLB with pygltflib." > "$DEST" \
+ && echo "wrote bpy stub to $DEST"
# The 2.1 code (hy3dshape + hy3dpaint packages) is cloned in-tree from a pinned
# Tencent-Hunyuan/Hunyuan3D-2.1 commit: the texgen extensions must be compiled
diff --git a/workers/model-hunyuan3d/README.md b/workers/model-hunyuan3d/README.md
index 122b61eb1..604d5a139 100644
--- a/workers/model-hunyuan3d/README.md
+++ b/workers/model-hunyuan3d/README.md
@@ -24,17 +24,30 @@ instant fallback lane: to roll back, repoint `GCP_HUNYUAN3D_URL` at the
All three services speak the **same wire contract**, so any URL drops straight
into the platform's `GCP_HUNYUAN3D_URL` env.
-**Why an RTX build exists.** All L4 services in us-central1 share one quota of
-3 GPUs, and the fleet is permanently at that ceiling; the RTX PRO 6000 quota in
-the same region is granted at 1000. `Dockerfile.hunyuan21rtx` is the same
-app21.py on a CUDA 12.8 / torch 2.7.1 (cu128) stack, because Blackwell is
-compute capability 12.0 and the cu124 wheels in the L4 image ship no sm_120
-kernels. Its extensions compile for both 8.9 and 12.0, so the RTX image also
-runs on an L4 if ever needed. Deploy with
+**Why an RTX build exists.** Two hard walls, found live on 2026-07-17:
+
+1. **The L4 2.1 service cannot finish loading at all.** app21 stages ~18 GiB
+ of weights into `/tmp`, which on Cloud Run is memory-backed, then loads the
+ ~14 GiB model on top; the L4 tier's 32 Gi memory ceiling SIGKILLs the
+ instance every time (`Container terminated on signal 9` mid-load). The port
+ binds and `/health` answers, but no 2.1 job can complete on an L4 with the
+ current staging design.
+2. **L4 quota.** All L4 services in us-central1 share one quota of 3 GPUs and
+ the fleet is permanently at that ceiling; the RTX PRO 6000 quota in the
+ same region is granted at 1000.
+
+`Dockerfile.hunyuan21rtx` is the same app21.py on a CUDA 12.8 / torch 2.7.1
+(cu128) stack, because Blackwell is compute capability 12.0 and the cu124
+wheels in the L4 image ship no sm_120 kernels. Its extensions compile for both
+8.9 and 12.0, so the image also boots on an L4 (though wall 1 above still
+applies there). Deploy with
[`cloudbuild.hunyuan21rtx.yaml`](./cloudbuild.hunyuan21rtx.yaml) (BuildKit,
-inline layer cache); platform minimums for the GPU type are 20 CPU / 80 Gi. The
-RTX service runs warm (min 1, max 4) as the 2.1 primary; the L4 build stays
-deployed at min 0 as the instant fallback.
+inline layer cache); platform minimums for the GPU type are 20 CPU / 80 Gi,
+which also clears wall 1 with room to spare. The RTX service runs warm (min 1,
+max 4) as the 2.1 primary. Making the L4 build genuinely loadable (stage one
+weight subtree at a time and delete each after its `from_pretrained`) is the
+open follow-up if an L4 fallback for 2.1 is ever needed; until then the 2.0
+lane is the fallback.
## License
diff --git a/workers/model-hunyuan3d/cloudbuild.hunyuan21rtx.yaml b/workers/model-hunyuan3d/cloudbuild.hunyuan21rtx.yaml
index 15edada90..0d554195e 100644
--- a/workers/model-hunyuan3d/cloudbuild.hunyuan21rtx.yaml
+++ b/workers/model-hunyuan3d/cloudbuild.hunyuan21rtx.yaml
@@ -5,12 +5,14 @@ substitutions:
_REPO: model-hunyuan3d-21
_GCS_BUCKET: three-ws-avatar-reconstructions
_WEIGHTS_BUCKET: three-ws-model-weights
- # The RTX PRO 6000 lane: Cloud Run's Blackwell GPU tier, where the project's
- # quota is granted at 1000 (vs 3 for L4). Platform minimums for this GPU type
- # are 20 CPU / 80Gi memory. min=1 keeps one instance warm so no request pays
- # the ~18 GiB weight stage; max=4 gives real parallel PBR capacity.
+ # The RTX PRO 6000 lane: Cloud Run's Blackwell GPU tier. The quota preference
+ # shows granted 1000, but live deploy enforcement allows 1 GPU in
+ # us-central1 (error text: "requested: 4 allowed: 1"), so max is pinned to 1
+ # until the effective limit rises. Platform minimums for this GPU type are
+ # 20 CPU / 80Gi memory. min=1 keeps the one instance warm so no request pays
+ # the ~18 GiB weight stage.
_MIN_INSTANCES: "1"
- _MAX_INSTANCES: "4"
+ _MAX_INSTANCES: "1"
steps:
# Warm the layer cache: --cache-from only consults images already present on
diff --git a/workers/rig/requirements.txt b/workers/rig/requirements.txt
index 126f90c1d..69289d055 100644
--- a/workers/rig/requirements.txt
+++ b/workers/rig/requirements.txt
@@ -30,9 +30,11 @@ trimesh>=4.4.0
pygltflib==1.16.2
scipy>=1.11.0
-# Server
-fastapi==0.115.0
-uvicorn[standard]==0.32.0
+# Server. fastapi rides gradio's requirement (a hard ==0.115.0 pin conflicts
+# with gradio>=5.25); the API surface this service uses is stable across the
+# 0.115+ line.
+fastapi>=0.115,<1
+uvicorn[standard]>=0.32,<1
pydantic>=2.0.0
httpx>=0.27.0