---
catalog_id: "R-006"
kind: "repo"
domain: "multimodal"
domain_label: "视频多模态 / Multimodal & Video"
date: "2026-11-26"
title: "huangserva/3DCellForge"
verdict: "收敛四路图生 3D 代理，配类别运镜、模型评分与逐级降级"
summary: "从生物细胞原型演进出的全栈 3D Model Studio：以 React 19 + R3F 为前端工作台、Node 代理编排 Hyper3D Rodin/Tripo/Fal/Hunyuan 多后端 Image-to-3D 管线，配合多模态类别感知运镜、GLB 质检评分与 JS 深度/CSS 3D 降级渲染。"
summary_en: "Full-stack 3D Model Studio unifying Rodin, Tripo, Fal, and Hunyuan in a Node proxy with vision-routed cameras, GLB scoring, and CSS 3D fallbacks."
canonical_url: "https://oumuatown.com/repos/huangserva__3DCellForge/"
markdown_url: "https://oumuatown.com/repos/huangserva__3DCellForge.md"
og_image_zh: "https://oumuatown.com/og/zh/R-006.png"
og_image_en: "https://oumuatown.com/og/en/R-006.png"
cite_count: 83
repo: "huangserva/3dcellforge"
github_url: "https://github.com/huangserva/3dcellforge"
commit: "df56957"
tags:
  - "threejs"
  - "react-three-fiber"
  - "image-to-3d"
  - "glb-studio"
  - "webgl"
  - "vision-routing"
github_repos:
  - "https://github.com/huangserva/3dcellforge/tree/df56957"
---

# R-006 · huangserva/3DCellForge

> **结论 / Verdict**: 收敛四路图生 3D 代理，配类别运镜、模型评分与逐级降级
> **EN Summary**: Full-stack 3D Model Studio unifying Rodin, Tripo, Fal, and Hunyuan in a Node proxy with vision-routed cameras, GLB scoring, and CSS 3D fallbacks.

## Provenance & Evidence

- Primary Repository: https://github.com/huangserva/3dcellforge (@df56957)
- Verified Source Citations (#Lxx): 83
- Web Reader: https://oumuatown.com/repos/huangserva__3DCellForge/

# huangserva/3DCellForge

> 仓库地址：https://github.com/huangserva/3DCellForge · 审计版本：`huangserva/3DCellForge@df56957` · 审计日期：2026-11-26
> 来源文章：[关联文章](../articles/2026-11-26-servasyy-manhattan-3d-city-film.md)

## 定位与解决的真问题

- **核心定位与目标用户**：开源全栈交互式 3D 资产工作台（源码内已从早期生物教学原型 `bio-demo` 产品化重构为通用 `3D Model Studio`，见 `package.json#L2` 与 `src/components/StudioHeader.jsx#L4-L23`），面向需要从单张参考图快速生成、审校、打分并录屏展示 3D GLB 资产的创作者与前端工程师。
- **相比常规做法解决的关键痛点**：
  1. **多 Image-to-3D 后端协议碎片化与密钥暴露**：将 Hyper3D Rodin（multipart 表单 + `subscription_key`）、Tripo（STS 临时凭证 + AWS SigV4 对象存储直传）、Fal.ai（多模型队列 Schema 差异）与本地 Hunyuan3D 统一收敛在 Node 代理层并原子落盘缓存，避免前端暴露 Key 与临时签名链接过期。
  2. **AI 生成 3D 模型的“盲用”与单调转盘展示**：上传阶段先通过 OpenAI Vision 或本地规则识别物体类别，自动匹配专属运镜轨迹（汽车推进、战机掠飞、舰船巡航、文物转台）与舞台环境，并在前端实时解析 GLB 网格/纹理给出 0–98 演示就绪度评分。
  3. **无服务端 Key 或无 WebGL 环境直接白屏**：内置浏览器端图像深度置换网格（`JS Depth`）、8 层背景剔除透明 PNG CSS 3D 视差以及纯 DOM 回退视图，并配合 IndexedDB + 渐进式 `localStorage` 压缩防止大体积上传图触发配额异常。

## 技术栈与核心目录结构

- **语言 / 运行时 / 关键依赖**：
  - 前端：`React 19.2` + `Vite 8` + `Three.js 0.184` + `@react-three/fiber 9.6` + `@react-three/drei 10.7` + `framer-motion 12` + `lucide-react`（`package.json#L16-L39`；注：`@react-three/postprocessing` 与 `postprocessing` 声明在依赖中但 `src/` 下尚未使用）。
  - 后端：原生 `Node.js` (`node:http` / `node:crypto` / `undici`) 轻量 API 服务（默认 `127.0.0.1:8787`，`server/config.mjs#L7-L8`）。
  - 测试：`node --test` 单元测试 + `@playwright/test` 布局与视觉快照回归（`package.json#L11-L13`）。
- **关键目录树与职责划分**（`huangserva/3DCellForge@df56957`）：
  - `server.mjs` & `server/`：API 路由入口（`server.mjs#L14-L208`）、环境与代理配置（`server/config.mjs`）、GLB 原子缓存与代理流（`server/model-store.mjs`）、本地日志脱敏（`server/logger.mjs`）、4 大 3D 生成 Provider（`server/providers/{rodin,tripo,fal,hunyuan}.mjs`）与视觉理解（`server/providers/vision.mjs`）。
  - `src/viewer/CellViewer.jsx`：Three.js / R3F 舞台核心，含 6 类 Demo 运镜与程序化舞台（`#L62-L342`）、程序化细胞骨架几何（`#L344-L986`）、GLB 归一化加载器（`#L1061-L1134`）、JS Depth 置换网格与 CSS 3D 视差降级（`#L1136-L1333`）及纯 DOM 兜底（`#L1384-L1457`）。
  - `src/lib/`：资产智能分类与舞台映射（`assetIntelligence.js`, `assetMetadata.js`, `motionProfiles.js`）、GLB 几何纹理质检打分（`modelQuality.js`）、抠图去底与深度置换（`imagePipeline.js`）、GLB/PNG 导出（`downloads.js`）、IndexedDB 存储（`modelStore.js`, `projectStore.js`）。
  - `src/domain/`：资产目录合并（`cellCatalog.js`, `cellData.js`）、配额自愈持久化（`cellPersistence.js`）、配置版本迁移（`preferences.js`）。
  - `src/components/` & `src/App.jsx`：三栏工作台、任务队列与多厂商横向对比编排。
  - `test/`：服务端工具/质检/分类单测与 Playwright 视觉回归套件（`test/visual/workbench.visual.spec.mjs`）。

## 核心实现源码级剖析（附文件路径与行号）

1. **多厂商 Image-to-3D 代理架构、STS SigV4 上传与原子磁盘缓存**（`server.mjs#L81-L208`, `server/providers/*.mjs`, `server/model-store.mjs#L10-L210`）：
   - **统一任务路由与编排**：`server.mjs#L81-L145` 暴露 `/api/3d/generate`、`/api/3d/status/:taskId`、`/api/3d/analyze`、`/api/3d/model` 与 `/api/3d/local-model`。前端 `getProviderPlan('auto')`（`src/services/modelApi.js#L29-L31`）按 `rodin → tripo → fal → hunyuan → cinematic` 依次回落（`src/App.jsx#L394-L555`），并支持 `handleRunProviderCompare`（`src/App.jsx#L1029-L1069`）用 `Promise.all` 对同一源图并发触发多厂商对比。
   - **四路 Provider 适配器细节**：
     - `rodin.mjs#L29-L188`：用 `FormData` 上传参考图到 `/rodin`，将 `{taskUuid, subscriptionKey}` 编码为 `rodin-<base64url>`（`encodeRodinTaskId#L126-L128`），轮询 `/status` 时聚合多子任务状态（`normalizeRodinStatus#L147-L154`），并在日志/错误返回前擦除 `subscription_key`（`sanitizeRodinRaw#L240-L246`）。
     - `tripo.mjs#L84-L277`：先调 `/upload/sts/token` 拿临时凭证，再用原生 `node:crypto` 手写 AWS4-HMAC-SHA256 签名（`uploadToTripoObjectStorage#L161-L200`）直传 S3，随后创建 `image_to_model` 任务并在完整参数失败时自动降级为最小 Payload 重试（`#L134-L151`）。
     - `fal.mjs#L9-L293`：封装 `@fal-ai/client`（注入 `OUTBOUND_PROXY_AGENT`），维护 5 个模型 Schema 表 `FAL_MODEL_DEFINITIONS`（`#L9-L51`，含 `fal-ai/hunyuan3d/v2`、`fal-ai/trellis`、`fal-ai/triposr`、`tripo3d/tripo/v2.5/image-to-3d`、`fal-ai/hyper3d/rodin`），并用 `scoreFalModelCandidate`（`#L288-L293`）从嵌套返回中优先拣选含 `pbr`/`glb` 键的模型 URL。
     - `hunyuan.mjs#L16-L146`：对接本地 Hunyuan3D 服务（`/send`、`/status/:uid`），兼容远程模型 URL 与内联 `model_base64`/`glb_base64` 落盘，并在日志里剔除 Base64 大字段。
   - **魔数校验与原子缓存**：`cacheRemoteModelAs`（`server/model-store.mjs#L72-L91`）先检查 `.generated-models/` 缓存命中，未命中则流式写入 `.<ts>.tmp` 临时文件，经 `validateModelBuffer`（`#L121-L138` 校验 GLB 4 字节头 `'glTF'` 或 `.gltf` 合法 JSON）后再 `rename` 原子落盘，异常时自动清理 `.tmp`。`/api/3d/logs` 则由 `assertLocalDiagnosticsRequest`（`server/http-utils.mjs#L9-L25`）限制仅本机 IP 与 `localhost`/`127.0.0.1` Origin 访问。

2. **多模态视觉分析与“物体类别驱动”的动态舞台/运镜系统**（`server/providers/vision.mjs#L32-L217`, `src/lib/assetIntelligence.js#L1-L258`, `src/viewer/CellViewer.jsx#L41-L342`）：
   - **语义分类与 Prompt 增强**：上传图片后前端触发 `/api/3d/analyze`（`src/App.jsx#L361-L370`, `#L602-L608`），`openAiVisionRequest`（`server/providers/vision.mjs#L94-L167`）以 `json_object` 模式输出 `objectName`/`categoryId`/`material`/`inspectionFocus`/`presentation`/`generationPrompt`，且 Prompt 显式纠偏（如规定航母归入 `vessel` 而非 `aircraft`，`#L115`）；`getGenerationPrompt`（`src/domain/cellCatalog.js#L97-L113`）再追加防浮雕/防底座（`single integrated object, not a flat relief, not a display base`）与 PBR 材质约束。
   - **双语本地启发式兜底**：未配置 `OPENAI_API_KEY` 时，`inferAssetCategory`（`src/lib/assetIntelligence.js#L141-L258`）对文件名/元数据做中英文词边界权重打分，并通过 `applyCategoryOverrides`（`#L188-L208`）解决 `"aircraft carrier"` 误触发 `"aircraft"` 关键词的冲突（`vessel +32`, `aircraft -18`）。
   - **六类程序化舞台与 Ping-Pong 运镜**：开启 `Demo` 模式后，`PresentationMotionRig`（`src/viewer/CellViewer.jsx#L62-L147`）使用 `smoothPingPong`（`0.5 - Math.cos(phase * 2π) * 0.5`，`#L41-L50`）按类别循环时间（7.2s–9.0s）同步驱动根节点位姿与相机推拉，并由 `PresentationEnvironment`（`#L149-L342`）动态渲染对应 3D 舞台：如 `road` 的循环移动车道线、`aircraft` 的飘动云团与尾迹线、`vessel` 的水面波纹、`artifact` 的暗色博物馆展台+暖色聚光灯+金环。

3. **Three.js / R3F 场景管线、GLB 自动居中归一化与多级视觉降级**（`src/viewer/CellViewer.jsx#L344-L1457`, `src/lib/imagePipeline.js#L88-L475`）：
   - **舞台光照与视图模式**：`CellScene`（`CellViewer.jsx#L1335-L1382`）固定 `fov: 35`、`ACESFilmicToneMapping`（`exposure: 1.08`）、`preserveDrawingBuffer: true`（支撑高倍截图），配置环境光 + 暖色主平行光（`1024×1024` 阴影）+ 冷色补光 + 双点光 + `ContactShadows`。`GeneratedGlbModel`（`#L1061-L1134`）克隆加载后的 `gltf.scene` 后按 `THREE.Box3` 计算中心归零并缩放到统一尺度 `3.25 / longest`，支持 `Solid` / `X-Ray`（青色线框 `depthWrite: false`）/ `Inspect`（抬高 `envMapIntensity` 至 `1.75` 并微降粗糙度）。
   - **程序化细胞器原型资产**：7 套内置模型（`PlantCellModel#L502-L647` 与 `CellModel#L798-L986`）采用 `RoundedBox`、`sphereGeometry`、`capsuleGeometry`、`Line` 与 `meshPhysicalMaterial`（`transmission`/`clearcoat`/`sheen`），由 `seeded` 确定性坐标生成（`src/lib/math.js#L1-L20`），并支持点击部位隔离（`hideOthers`）、剖面切片（`crossSection`）与爆炸偏移标尺（`ProofRig#L1001-L1033`）。
   - **三层无缝降级渲染链**：
     1. *浏览器端 JS Depth 浮雕网格*：`createImageReliefGeometry`（`src/lib/imagePipeline.js#L309-L373`）在前端 Canvas 采样像素亮度、饱和度、Alpha 边缘梯度与正弦噪点，对最高 `96×96` 分段 `PlaneGeometry` 做顶点 Z 轴置换并 `computeVertexNormals`，在 `CinematicReliefSpecimen`（`CellViewer.jsx#L1136-L1193`）中以 `meshPhysicalMaterial` 渲染；
     2. *无 WebGL 环境的 CSS 3D 8 图层视差*：若 `canUseWebGL` 为 `false`，`removeLightBackground`（`imagePipeline.js#L88-L137`）检测四边浅灰白底比例（`>42%` 则软边抠图并 `trimTransparentCanvas`），随后 `buildLayeredPngVisual`（`#L375-L426`）派生 `shadow`/`depth`/`rim`/`body`/`core`/`front`/`particles`/`highlight` 8 张透明 PNG，配合鼠标坐标 CSS 变量 `--px`/`--py` 做视差展示（`CellViewer.jsx#L1233-L1333`）；
     3. *纯 DOM 兜底*：`ViewerErrorBoundary`（`#L1035-L1059`）捕获加载异常后切换至 `CellFallback`（`#L1384-L1457`）。

4. **GLB 质检评分引擎、双层容错存储与导出管线**（`src/lib/modelQuality.js#L5-L152`, `src/lib/downloads.js#L19-L95`, `src/domain/cellPersistence.js#L4-L69`, `src/lib/modelStore.js#L1-L81`）：
   - **客户端 GLB 资产体检**：`inspectModelUrl`（`modelQuality.js#L5-L67`）缓存解析 Promise，按需动态引入 `GLTFLoader`，遍历统计 `nodeCount`/`meshCount`/`triangleCount`/`materialCount` 与 9 种 PBR 贴图槽位去重计数；`calculateScore`（`#L99-L134`）依据 GLB 可用性、三角面数（`>=50k` 满分档）、贴图数（`>=4` 满分档）、子网格数、文件体积与耗时给出 0–98 分及 `Demo-ready` / `Solid` / `Usable` 评级，提示录制前淘汰残次生成物。
   - **双层持久化和三段式配额自愈**：主库使用 IndexedDB（`modelStore.js` 存模型库、`projectStore.js` 存完整工作区快照），`localStorage` 同步写入失败时，`persistCustomCells`（`cellPersistence.js#L4-L69`）依次按 `generated-previews`（先丢弃已生成模型的原图预览但保留失败重试图的源图）→ `all-previews` → `minimal`（截断消息与 `rawModelUrl`）逐级瘦身重存（验证于 `test/server-utils.test.mjs#L157-L246`）。
   - **导出能力**：`exportObjectAsGlb`（`downloads.js#L19-L59`）克隆 `exportRoot` 并剥离阴影标记后用 `GLTFExporter` 导出二进制 `.glb`（WebGL 不可用或失败时降级导出 JSON 元数据，`App.jsx#L312-L344`）；截图支持 `1x`/`2x`/`3x` 离屏缩放导出，JS Depth 无 WebGL 时自动调用 `downloadLayeredPngSnapshot`（`imagePipeline.js#L443-L475`）合成 `1400×900` 渐变背景 PNG。

5. **三栏工作室 UI 与无障碍/视觉回归门禁**（`src/App.jsx#L106-L1229`, `test/visual/workbench.visual.spec.mjs#L3-L133`）：
   - 状态中心 `App.jsx` 维护模型库水合合并（`mergeCustomModelRecords#L44-L84` 防止 IndexedDB 与 localStorage 互相覆盖正在进行的任务状态）、Demo 模式 9.2 秒轮播（`#L242-L259`）与跨面板同步；Playwright 视觉套件（`workbench.visual.spec.mjs#L54-L133`）禁用动画后分别对三栏布局、Model Library 抽屉、Demo 演示态与 Inspector 面板做像素级 `maxDiffPixelRatio: 0.025` 快照比对，并显式断言 UI 中不再泄露 `"Organelle"` / `"Plasma Membrane"` 等旧生物原型文案（`#L72, #L129-L130`）。

## 亮点设计 vs 局限/坑点

- **值得借鉴的设计**：
  - **多后端容错与对比基座**：将 4 个异构 3D 云/本地 API + 前端 JS Depth 封装进统一队列与降级链（`Auto` 顺序兜底 + `Provider Compare` 并发横向打分），大幅降低单一模型翻车成本。
  - **配额自愈与原图保留策略**：`compactCustomCellsForStorage` 优先清理已有 `.glb` 资产的高分辨率 DataURL（保留缩略图 `thumbnailUrl`），而为失败/排队项保留原始上传图以便重试（`cellPersistence.js#L30-L64`）。
  - **演示即舞台（Scene-Aware Presentation）**：用轻量级 Vision JSON + 关键词纠偏将静态资产自动匹配到 6 套参数化 Three.js 舞台与运镜函数，可直接用于无剪辑的宣传片录屏。
- **局限、隐含假设与潜在坑点**（截至 `huangserva/3DCellForge@df56957`，`2026-11-26`）：
  - **历史重构命名债务与未接通控件**：大量内部文件与存储键仍保留 `bio-demo-*`/`Cell`/`Organelle` 命名；`package.json#L20,L23` 引入的 `@react-three/postprocessing`/`postprocessing` 未实际挂载；`BottomDeck.jsx` 的 `Studio Preview` / `Texture Pass` / `Depth Preview` 选择器仅写入历史笔记，不实际切换渲染管线或着色器；`StudioHeader.jsx#L14-L23` 的中英文切换仅覆盖顶栏，其余面板仍硬编码英文。
  - **仅限本机信任边界的代理安全假设**：`server/http-utils.mjs#L4` 默认 `Access-Control-Allow-Origin: *`；`/api/3d/model?url=`（`server/model-store.mjs#L192-L201`）放行任意 `https://` URL 存在 SSRF 风险（仅适用于本机单用户 `127.0.0.1` 运行，不可直接暴露公网）。
  - **导出边界**：进入 `JS Depth` 模式后 `CenterStage.jsx#L194-L196` 主动置空 `sceneExporter`，无法将浏览器置换出的立体浮雕网格直接导出为 GLB；且当前版本无专门的自定义 GLSL `ShaderMaterial` 或后期通道，全靠 `MeshPhysicalMaterial` 与动态光影表现质感。

## 可复用的模块或设计模式

- **如何迁移到未来项目**：
  1. **直接复用多后端 3D 生成代理与自建 S3 SigV4 上传器**：将 `server/providers/{rodin,tripo,fal,hunyuan}.mjs` 与 `server/model-store.mjs` 的原子缓存机制抽为独立微服务，配合 `vision.mjs` 自动补全 `generationPrompt` 并过滤非单一体/浮雕退化结果。
  2. **迁移 `modelQuality.js` 作为 3D 资产自动化验收探针**：在批量生成管道（如 AI 城市建筑、道具资产批产）后挂载 `inspectModelUrl` + `calculateScore`，按面数/贴图数/文件大小阈值自动筛除空壳或无贴图模型。
  3. **复用 `imagePipeline.js` 的前后端协同去底与 WebGL 兜底链路**：`removeLightBackground` 四边采样去白底 + `createImageReliefGeometry` 顶点深度置换 + 8 层 CSS 3D 视差可用于任意无后端 GPU 的轻量交互展示页。
- **关联 Pattern**：[procedural-world-and-camera-rig-pipeline](../patterns/procedural-world-and-camera-rig-pipeline.md) · [agentic-video-and-3d-toolchain-matrix](../patterns/agentic-video-and-3d-toolchain-matrix.md)

## Cross-Referenced Specimens

- [A-003 · 4 天 4 夜零手写代码造出 2K 60fps 曼哈顿——Three.js 实时漫游与无头 Blender 光追成片七步管线](https://oumuatown.com/articles/2026-11-26-servasyy-manhattan-3d-city-film.md) — Three.js 城景与无头光追 2K60 七步管线
- [P-005 · 程序化三维世界构建、浏览器导播台与光追热插拔成片管线（Procedural World, Camera Rig & Cycles Hot-Swap Pipeline）](https://oumuatown.com/patterns/procedural-world-and-camera-rig-pipeline.md) — 纯函数共享演出表与无锁弧长导播台贯通 Web 与光追双轨
- [P-001 · Agent 驱动视频剪辑、2D/3D 动画与跨宿主技能选型矩阵（Agentic Video, 3D & Skill Toolchain Matrix）](https://oumuatown.com/patterns/agentic-video-and-3d-toolchain-matrix.md) — 视频生成、三维自动化与跨宿主技能选型边界与避坑矩阵
- [P-019 · 零资产程序化建筑重建、多镜头着色器与平面图双向漫游管线（Zero-Asset Procedural Architecture, Multi-Lens Shaders & Plan Walkthrough）](https://oumuatown.com/patterns/zero-asset-procedural-architecture-and-plan-walkthrough.md) — 模数轴网解耦、三镜头着色器与平面图双向配准的零资产漫游
