如何10分钟用ComfyUI-Trellis2生成第一个3D模型:新手快速上手工作流详解
如何10分钟用ComfyUI-Trellis2生成第一个3D模型:新手快速上手工作流详解
ComfyUI-Trellis2 是微软 Trellis.2 3D 生成模型的 ComfyUI 节点封装,支持从一张图片快速生成带纹理的 3D 模型(图生3D / image-to-3D)。本文面向新手,用 5 个节点讲透核心工作流,10 分钟内跑通你的第一个 3D 模型生成任务。
一、为什么选择 ComfyUI-Trellis2 做图生3D?
- 🎨 节点化封装:把 Trellis.2 复杂的扩散模型管线拆解为一个个可视化节点(如
Trellis2 - LoadModel、Trellis2 - Sparse Generator),在 nodes.py 中注册了近 70 个节点 - 📦 开箱即用的示例工作流:example_workflows/ 目录内置 17 份 JSON 工作流,从纯白模到带纹理、多视图一应俱全
- 🖼️ 一张图进、一个 3D 文件出:输入参考图片,直接导出 GLB 模型并实时预览
核心生成逻辑位于 trellis2/pipelines/trellis2_image_to_3d.py,采用"稀疏结构 + 结构化潜变量(Structured Latents)"两级级联生成,显存占用比普通方案更紧凑。
二、一键安装:最快配置方法
1️⃣ 获取仓库
将仓库克隆到 ComfyUI 的 custom_nodes 目录:
git clone https://gitcode.com/gh_mirrors/co/ComfyUI-Trellis2
2️⃣ 安装专用 Wheels(按 PyTorch 版本选)
仓库的 wheels/ 目录预编译了 cumesh、nvdiffrast、flex_gemm、o_voxel 等加速组件,覆盖 Windows / Linux 与多个 Torch 版本。以 Windows + Torch 2.7.0 为例:
python -m pip install ComfyUI/custom_nodes/ComfyUI-Trellis2/wheels/Windows/Torch270/cumesh-1.0-cp311-cp311-win_amd64.whl
python -m pip install ComfyUI/custom_nodes/ComfyUI-Trellis2/wheels/Windows/Torch270/nvdiffrast-0.4.0-cp311-cp311-win_amd64.whl
python -m pip install ComfyUI/custom_nodes/ComfyUI-Trellis2/wheels/Windows/Torch270/nvdiffrec_render-0.0.0-cp311-cp311-win_amd64.whl
python -m pip install ComfyUI/custom_nodes/ComfyUI-Trellis2/wheels/Windows/Torch270/flex_gemm-0.0.1-cp311-cp311-win_amd64.whl
python -m pip install ComfyUI/custom_nodes/ComfyUI-Trellis2/wheels/Windows/Torch270/o_voxel-0.0.1-cp311-cp311-win_amd64.whl
💡 ComfyUI Portable 用户请把
python换成python_embeded\python.exe,其余照抄即可。
3️⃣ 安装 Python 依赖
python -m pip install -r ComfyUI/custom_nodes/ComfyUI-Trellis2/requirements.txt
依赖清单见 requirements.txt(含 meshlib、pymeshlab、open3d、trimesh、rembg 等)。
4️⃣ 准备 DINOv3 特征模型
⚠️ 必做:Trellis.2 需要访问 Facebook 的 DINOv3 模型,将其放入 ComfyUI/models/facebook/dinov3-vitl16-pretrain-lvd1689m 目录,详细说明见 README.md。
三、5 个核心节点,生成你的第一个 3D 模型
以官方示例 example_workflows/MeshOnly.json 为例(纯白模、节点最少,最适合首次上手),整个管线只需理解下面 5 步:
| 步骤 | 节点名称 | 作用 |
|---|---|---|
| 1 | Trellis2 - LoadModel |
加载 microsoft/TRELLIS.2-4B 主模型,可配置 flash_attn 后端与 FP8 省显存模式 |
| 2 | Trellis2 - PreProcess Image |
预处理输入图片(填充边距、可自动去背景 remove_background) |
| 3 | Trellis2 - Sparse Generator |
由图片生成稀疏体素结构(3D 骨架),控制生成速度与细节上限 |
| 4 | Trellis2 - Decode Latents |
将潜变量解码为网格(Mesh),输出 MESHWITHVOXEL 数据 |
| 5 | Trellis2 - Simplify Mesh → Trellis2 - Export Mesh → Preview3D |
简化面数(如 50 万面)、导出 GLB 并在 3D 视口实时查看 |
🎯 小技巧:
Simplify Mesh的target_face_num直接决定模型大小。导入游戏引擎建议 5 万面以内,打印/展示可用 50 万面。
四、推荐工作流清单:按需求挑选
example_workflows/ 中的工作流可直接拖入 ComfyUI 使用:
| 工作流文件 | 适用场景 | 难度 |
|---|---|---|
| MeshOnly.json | 单图生成白模,最快上手 ⭐推荐新手 | ⭐ |
| MeshOnly_HighQuality.json | 高质量白模(级联生成 + 重建网格,细节更丰富) | ⭐⭐ |
| MeshOnly_LowPoly.json | 低模生成,适合游戏资产 | ⭐⭐ |
| MeshWithTexturing.json | 生成网格 + 自动纹理烘焙(UV 展开 + 贴图) | ⭐⭐⭐ |
| MeshOnly_MultiView.json | 多视角图片输入,形状还原更准确 | ⭐⭐⭐ |
| MeshOnly_Pixal3D.json | 使用 Pixal3D-T 模型版本 | ⭐⭐⭐ |
| RefineMesh_MeshOnly.json | 对已有网格做细节精修 | ⭐⭐⭐ |
进阶玩家可关注 reconviagen_pipeline.json(ReconViaGen 稀疏结构生成)与
Projection_*系列(高模纹理投影到低模)。
五、新手常见问题排查(FAQ)
Q1:运行报错缺少 DINOv3 相关模块?
确认模型已放在 ComfyUI/models/facebook/dinov3-vitl16-pretrain-lvd1689m 下,参考 README.md 的 REQUIREMENTS 章节。
Q2:导入 wheels 失败?
wheels 与 Python 版本 + Torch 版本强绑定(如 cp311 对应 Python 3.11),请进入 wheels/ 按 Windows/Linux/Torch版本号 三级目录挑选匹配文件。
Q3:显存不够(OOM)?
在 LoadModel 节点开启 FP8 模式,或调低 Sparse Generator 的分辨率与采样步数。
Q4:想用 Pixal3D-T 模型?
需要额外安装 natten 包,且并非所有节点兼容,请以 example_workflows/ 中带 Pixal3D 字样的工作流为准。
Q5:模型有破面/小孔洞?
在解码后接入 Trellis2 - Fill Holes With CuMesh 或 Trellis2 - Fill Holes Nicely With Meshlib 节点,即可自动补洞(官方示例工作流已默认包含)。
六、总结
- 克隆仓库 → 安装 wheels 与依赖 → 放置 DINOv3 模型(约 5 分钟)
- 拖入 MeshOnly.json 工作流,换上一张你的图片
- 调整面数、导出 GLB,用 Preview3D 节点检查效果
掌握 LoadModel → PreProcess Image → Sparse Generator → Decode Latents → Export Mesh 这条主线后,再去尝试 MeshWithTexturing.json 加纹理,即可完整体验 ComfyUI-Trellis2 的图生 3D 全流程。祝创作顺利!🚀