How kijai/comfyui-if_trellis works
1. This repository is a ComfyUI custom node wrapper around TRELLIS, a 3D asset generation system. The top-level boundary is: ComfyUI graph inputs in, TRELLIS model inference and decoding in the middle, and 3D outputs rendered or materialized as different asset types at the end.
2. The ComfyUI entry points are IF_Trellis.py and IF_TrellisCheckpointLoader.py, plus the package __init__.py. These are the node-facing integration layer: they expose loading and generation behavior to the ComfyUI runtime, and likely orchestrate prompts, checkpoints, and output routing into the internal TRELLIS package.
3. trellis_model_manager.py is the central model/runtime coordinator. In architecture terms, this is the place where heavyweight artifacts such as checkpoints, backbones, and decoding components are selected, loaded, cached, and shared across node executions.
4. The main generation pipeline lives under trellis/pipelines/. trellis/pipelines/trellis_image_to_3d.py is the primary application pipeline, and trellis/pipelines/base.py plus the sampler subpackage define the execution flow. The samplers include classifier-free guidance and flow-Euler style sampling, indicating a rectified-flow generative process rather than a conventional diffusion-only path.
5. The core learned representation is the Structured Latent (SLAT) model family in trellis/models/. There are separate model files for sparse structure flow, sparse structure VAE, and structured latent flow, which suggests a two-stage or modular design: one part learns latent 3D structure, another performs generative sampling in that latent space, and the decoder converts it into final assets.
6. The structured latent VAE subpackage is the decode boundary. It contains distinct decoders for meshes, radiance fields, and Gaussian splats: decoder_mesh.py, decoder_rf.py, and decoder_gs.py. This is the key architectural pivot in TRELLIS: one latent representation fans out into multiple output modalities depending on the selected export path.
7. Rendering is split into dedicated subsystem modules under trellis/renderers/. There are separate renderers for Gaussian splats, meshes, and octrees, which means the repo supports both visualization and geometry/appearance extraction. This rendering layer is downstream of representation decoding and is also likely used for previews inside ComfyUI.
8. The representation layer under trellis/representations/ contains the data structures and conversion logic for each 3D form: Gaussian models, meshes, octrees, and radiance fields. The mesh subpackage includes cube-to-mesh and FlexiCubes-style utilities, showing that mesh generation is not just a renderer artifact but a dedicated geometry construction path.
9. The module hierarchy under trellis/modules/ is the neural network backbone library. It contains standard and sparse transformer blocks, sparse convolutions, normalization, attention variants, and spatial utilities. This is the implementation boundary for the model internals; the generative models depend on these reusable blocks rather than embedding architecture code directly.
10. Sparse computation is a first-class concern. The trellis/modules/sparse/ tree includes sparse attention, sparse convolutions, and sparse transformer blocks, with separate implementations for spconv and torchsparse. That indicates the model processes structured 3D data in sparse voxel/point-like forms to keep memory and compute manageable.
11. There is a native GPU extension stack under extensions/nvdiffrast/. This is a bundled rasterization backend with Torch and TensorFlow bindings, CUDA/C++ sources, and GL utilities. Its presence means the repo depends on compiled GPU code for differentiable rasterization and related image-space operations, not just pure Python.
12. The repository also vendors binary wheels in wheels/ for diff_gaussian_rasterization and nvdiffrast, which reinforces that render-time performance and build reproducibility are important architectural constraints. The readme’s Linux/Windows setup notes and CUDA/toolchain requirements reflect this native-extension boundary.
13. Utility code is separated from the model core in trellis/utils/, covering rasterization helpers, rendering helpers, randomness, postprocessing, and general utilities. This is the glue layer between model outputs, renderer inputs, and ComfyUI-friendly postprocessing.
14. The workflow/ directory contains sample ComfyUI workflow JSONs for single-image and multi-image scenarios, and assets/ contains example inputs. These are not core runtime components, but they show the intended data flow at the application boundary: image prompts flow into the node graph, then into TRELLIS inference, then out to 3D asset previews or exports.
15. In architectural terms, the repo is organized as: ComfyUI node wrappers at the edge, a model manager and pipeline orchestration layer in the middle, a SLAT-based generative model core underneath, and modality-specific decoders/renderers backed by CUDA extensions at the bottom.
Main entry points: trellis_image_to_3d.py Image to 3D · structured_latent_vae/base.py SLAT Base · IF_Trellis.py Trellis Node · samplers/base.py Sampler Base
Components 26
ComfyUI Edge
Node wrappers and workflow-facing entry points.
- Package Init · Registers the custom node package with ComfyUI.
__init__.py - Trellis Node · Main generation node that drives TRELLIS inference from ComfyUI inputs.
IF_Trellis.py - Checkpoint Loader · Loads TRELLIS checkpoints and exposes them to the node runtime.
IF_TrellisCheckpointLoader.py
TRELLIS Runtime
Model loading, pipeline orchestration, and generation flow.
- Model Manager · Selects, loads, caches, and shares heavyweight model artifacts across executions.
trellis_model_manager.py - Pipeline Base · Shared execution scaffolding for TRELLIS pipelines.
trellis/pipelines/base.py - Image to 3D · Primary TRELLIS pipeline for turning image inputs into 3D outputs.
trellis/pipelines/trellis_image_to_3d.py - Sampler Base · Common sampler interface for rectified-flow style generation.
trellis/pipelines/samplers/base.py - CFG Mixin · Classifier-free guidance behavior for sampling.
trellis/pipelines/samplers/classifier_free_guidance_mixin.py - Flow Euler · Euler-style flow sampler used by the generation process.
trellis/pipelines/samplers/flow_euler.py
Model Core
Learned latent models and reusable network blocks.
- Latent Flow · Structured latent flow model that drives synthesis in latent 3D space.
trellis/models/structured_latent_flow.py - Sparse Flow · Sparse structure flow model for structured 3D state.
trellis/models/sparse_structure_flow.py - Sparse VAE · Sparse structure VAE that bridges observations and latent structure.
trellis/models/sparse_structure_vae.py - SLAT Base · Shared base for structured latent VAE components.
trellis/models/structured_latent_vae/base.py - Latent Encoder · Encodes structured 3D inputs into the latent representation.
trellis/models/structured_latent_vae/encoder.py - NN Modules · Reusable attention, sparse ops, transformer blocks, and spatial utilities.
trellis/modules
Output Stack
Decoders, representations, and renderers for 3D outputs.
- Mesh Decoder · Decodes structured latent features into mesh geometry.
trellis/models/structured_latent_vae/decoder_mesh.py - RF Decoder · Decodes structured latent features into radiance fields.
trellis/models/structured_latent_vae/decoder_rf.py - GS Decoder · Decodes structured latent features into Gaussian splats.
trellis/models/structured_latent_vae/decoder_gs.py - Mesh Rep · Mesh construction and conversion utilities.
trellis/representations/mesh/cube2mesh.py - Gaussian Rep · Gaussian model structures and helpers.
trellis/representations/gaussian/gaussian_model.py - Octree Rep · Octree traversal and structured occupancy representation.
trellis/representations/octree/octree_dfs.py - Radiance Field · Radiance-field representation used by decoding and rendering paths.
trellis/representations/radiance_field/strivec.py - Mesh Renderer · Renders mesh outputs for preview or inspection.
trellis/renderers/mesh_renderer.py - Gaussian Renderer · Renders Gaussian splat outputs.
trellis/renderers/gaussian_render.py - Octree Renderer · Renders octree-based outputs and previews.
trellis/renderers/octree_renderer.py
Native Backend
Bundled GPU extensions and prebuilt wheels.
- nvdiffrast · Bundled differentiable rasterization backend with Torch and TensorFlow bindings.
extensions/nvdiffrast
Connections 26
- Package Init → Trellis Node: registers · Package init exposes the ComfyUI generation node.
- Package Init → Checkpoint Loader: registers · Package init exposes the checkpoint loader node.
- Checkpoint Loader → Model Manager: loads · Loader resolves checkpoints through the central model manager.
- Trellis Node → Model Manager: uses · Generation node requests shared artifacts and runtime state.
- Trellis Node → Image to 3D: invokes · Node forwards ComfyUI inputs into the main TRELLIS pipeline.
- Image to 3D → Pipeline Base: extends · Image-to-3D pipeline builds on shared pipeline scaffolding.
- Image to 3D → Sampler Base: drives · Pipeline configures sampling execution.
- Sampler Base → CFG Mixin: mixes in · Sampler base can apply classifier-free guidance behavior.
- Sampler Base → Flow Euler: implements · Flow Euler is the concrete rectified-flow sampling path.
- Image to 3D → Latent Flow: runs · Primary pipeline executes the structured latent flow model.
- Image to 3D → Sparse VAE: conditions · Pipeline uses sparse VAE components for latent structure handling.
- Latent Flow → NN Modules: depends on · Generative models are built from reusable transformer and sparse blocks.
- Sparse Flow → NN Modules: depends on · Sparse structure flow reuses the shared neural backbone library.
- Sparse VAE → SLAT Base: inherits · Sparse VAE builds on the structured latent VAE base.
- SLAT Base → Latent Encoder: contains · Latent base coordinates encoding into SLAT space.
- SLAT Base → Mesh Decoder: decodes · One decode path materializes meshes.
- SLAT Base → RF Decoder: decodes · One decode path materializes radiance fields.
- SLAT Base → GS Decoder: decodes · One decode path materializes Gaussian splats.
- Mesh Decoder → Mesh Rep: materializes · Mesh decoder feeds mesh construction utilities.
- RF Decoder → Radiance Field: materializes · RF decoder feeds radiance-field structures.
- GS Decoder → Gaussian Rep: materializes · Gaussian decoder feeds splat representations.
- Mesh Rep → Mesh Renderer: renders · Mesh representations are previewed by the mesh renderer.
- Gaussian Rep → Gaussian Renderer: renders · Gaussian representations are previewed by the Gaussian renderer.
- Octree Rep → Octree Renderer: renders · Octree representations are previewed by the octree renderer.
- Mesh Renderer → nvdiffrast: accelerates · Mesh rendering relies on bundled rasterization backends.
- Gaussian Renderer → nvdiffrast: accelerates · Preview and rasterization paths use native GPU code.