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
Enhance NIM configuration for improved fidelity in image-to-3D reconstructions
vwkb894956899f57
diff --git a/api/forge-nim.js b/api/forge-nim.jsindex 221478cf8..81275dbb6 100644--- a/api/forge-nim.js+++ b/api/forge-nim.js@@ -39,9 +39,16 @@ const MAX_IMAGE_BYTES = 10 * 1024 * 1024; // 10 MB decoded reference image ceiliconst MAX_BODY_BYTES = 16 * 1024 * 1024; // base64 inflates ~33%, plus JSON envelopefunction trellisSteps(tier) {- return tier === 'high' ? { ss: 40, slat: 40 } : { ss: 15, slat: 15 };+ return tier === 'high' ? { ss: 50, slat: 50 } : { ss: 15, slat: 15 };}+// CFG scales control how strictly diffusion adheres to the input. TRELLIS defaults+// slat_cfg_scale to 3.0, which yields smooth, cartoonish reconstructions; 5.0 keeps+// the output faithful to the real texture/shape of the source photo. ss_cfg_scale+// stays at the tuned 7.5 default.+const SS_CFG = 7.5;+const SLAT_CFG = 5.0;+// Mirror the provider's prompt shaping so text-mode results look the same as the// production forge lane: keep an already-styled prompt, else append a lighting// cue, always inside TRELLIS's 77-char window.@@ -261,6 +268,8 @@ async function infer(req, res) {prompt,ss_sampling_steps: steps.ss,slat_sampling_steps: steps.slat,+ ss_cfg_scale: SS_CFG,+ slat_cfg_scale: SLAT_CFG,output_format: 'glb',};} else {@@ -270,6 +279,8 @@ async function infer(req, res) {image: imageDataUri,ss_sampling_steps: steps.ss,slat_sampling_steps: steps.slat,+ ss_cfg_scale: SS_CFG,+ slat_cfg_scale: SLAT_CFG,output_format: 'glb',};}diff --git a/api/nim-forge.js b/api/nim-forge.jsindex b3cc8d07e..412472cae 100644--- a/api/nim-forge.js+++ b/api/nim-forge.js@@ -29,7 +29,7 @@ const INFER_TIMEOUT_MS = 110_000;function stepsForTier(tier) {switch (tier) {case 'high':- return 40;+ return 50;case 'standard':return 25;case 'draft':@@ -110,9 +110,15 @@ export default wrap(async (req, res) => {return json(res, 400, { error: 'bad_image', message: 'image must be a base64 data-uri.' });}+ // slat_cfg_scale governs how strictly the structured-latent diffusion adheres+ // to the input. TRELLIS defaults to 3.0, which makes reconstructions look+ // smooth and cartoonish (the model invents toy-like detail). Raising it to 5.0+ // keeps the output faithful to the real texture/shape in the source photo.+ const SLAT_CFG = 5.0;+ const SS_CFG = 7.5;const payload = image- ? { mode: 'image', image, ss_sampling_steps: steps, slat_sampling_steps: steps, output_format: 'glb', seed }- : { mode: 'text', prompt, ss_sampling_steps: steps, slat_sampling_steps: steps, output_format: 'glb', seed };+ ? { mode: 'image', image, ss_sampling_steps: steps, slat_sampling_steps: steps, ss_cfg_scale: SS_CFG, slat_cfg_scale: SLAT_CFG, output_format: 'glb', seed }+ : { mode: 'text', prompt, ss_sampling_steps: steps, slat_sampling_steps: steps, ss_cfg_scale: SS_CFG, slat_cfg_scale: SLAT_CFG, output_format: 'glb', seed };const url = `${NIM_URL.replace(/\/$/, '')}/v1/infer`;const headers = { 'content-type': 'application/json', accept: 'application/json' };diff --git a/scripts/nim-img-to-3d.mjs b/scripts/nim-img-to-3d.mjsindex 5c4d82aca..f561e623d 100644--- a/scripts/nim-img-to-3d.mjs+++ b/scripts/nim-img-to-3d.mjs@@ -1,17 +1,30 @@#!/usr/bin/env node// Image→3D against the live self-hosted TRELLIS NIM (large:image) on GCP.-// Hits the box directly (firewall open on :8000), high quality (40 steps),-// saves the GLB locally for the auto-orbit viewer.+// Hits the box directly (firewall open on :8000) at MAX fidelity and saves the+// GLB locally for the auto-orbit viewer.//// node scripts/nim-img-to-3d.mjs path/to/photo.jpg [steps]//-// Output: demo/<name>.glb → view with scripts/nvidia-demo-serve.mjs+// Quality knobs (verified live against the NIM's /openapi.json Object3DRequest):+// • ss_sampling_steps / slat_sampling_steps — TRELLIS default 25, ceiling 50.+// Too few sparse-structure steps leave HOLES in the mesh; we max both at 50.+// • slat_cfg_scale — how strictly the structured-latent diffusion adheres to+// the input photo. The NIM default (3.0) is low, which is why output looks+// CARTOONISH (the model invents smooth, toy-like detail). We raise it so the+// reconstruction stays faithful to the real texture/shape in the photo.+// • ss_cfg_scale — sparse-structure guidance; kept at the tuned default (7.5).+// All three are env-overridable (STEPS / SLAT_CFG / SS_CFG) for live tuning.+// Note: this NIM exposes NO mesh_simplify / texture_size — fidelity comes from+// steps + cfg + a sharp, evenly-lit input photo (the biggest lever of all).import { readFile, mkdir, writeFile } from 'node:fs/promises';import { basename, extname } from 'node:path';const NIM = process.env.NIM_URL || 'http://104.154.74.37:8000';const imgPath = process.argv[2];-const steps = Number(process.argv[3]) || 40;+// Max-fidelity defaults; CLI arg or env can override.+const steps = Number(process.argv[3]) || Number(process.env.STEPS) || 50;+const slatCfg = Number(process.env.SLAT_CFG) || 5.0; // ↑ from NIM default 3.0 → less cartoonish+const ssCfg = Number(process.env.SS_CFG) || 7.5; // tuned defaultif (!imgPath) { console.error('usage: node scripts/nim-img-to-3d.mjs <image> [steps]'); process.exit(1); }const MIME = { '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.webp': 'image/webp' };@@ -20,7 +33,7 @@ async function main() {const buf = await readFile(imgPath);const mime = MIME[extname(imgPath).toLowerCase()] || 'image/png';const dataUri = `data:${mime};base64,${buf.toString('base64')}`;- console.log(`→ NIM image→3D ${NIM} steps=${steps} input=${imgPath} (${(buf.length / 1024).toFixed(0)} KB)`);+ console.log(`→ NIM image→3D ${NIM} steps=${steps}/${steps} slat_cfg=${slatCfg} ss_cfg=${ssCfg} input=${imgPath} (${(buf.length / 1024).toFixed(0)} KB)`);const t0 = Date.now();const res = await fetch(`${NIM}/v1/infer`, {@@ -31,6 +44,8 @@ async function main() {image: dataUri,ss_sampling_steps: steps,slat_sampling_steps: steps,+ ss_cfg_scale: ssCfg,+ slat_cfg_scale: slatCfg,output_format: 'glb',}),signal: AbortSignal.timeout(240_000),