# kijai/comfyui-if_trellis architecture

> Architecture diagram of the GitHub repository kijai/comfyui-if_trellis, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kijai/comfyui-if_trellis
- Repository: https://github.com/kijai/comfyui-if_trellis

## Overview

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/pipelines/trellis_image_to_3d.py`](https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/pipelines/trellis_image_to_3d.py) (Image to 3D), [`trellis/models/structured_latent_vae/base.py`](https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/models/structured_latent_vae/base.py) (SLAT Base), [`IF_Trellis.py`](https://github.com/kijai/comfyui-if_trellis/blob/main/IF_Trellis.py) (Trellis Node), [`trellis/pipelines/samplers/base.py`](https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/pipelines/samplers/base.py) (Sampler Base)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_edge["ComfyUI Edge"]
  node_init["Package Init<br/>entry package<br/>[__init__.py]"]
  node_if_trellis["Trellis Node<br/>comfyui node<br/>[IF_Trellis.py]"]
  node_if_loader["Checkpoint Loader<br/>comfyui loader"]
end

subgraph group_runtime["TRELLIS Runtime"]
  node_manager["Model Manager<br/>runtime coordinator"]
  node_pipeline_base["Pipeline Base<br/>[base.py]"]
  node_image3d["Image to 3D<br/>application pipeline"]
  node_sampler_base["Sampler Base<br/>sampling core<br/>[base.py]"]
  node_cfg["CFG Mixin<br/>guidance mixin"]
  node_flow_euler["Flow Euler<br/>sampler<br/>[flow_euler.py]"]
end

subgraph group_core["Model Core"]
  node_slf["Latent Flow<br/>generative model"]
  node_ssf["Sparse Flow<br/>generative model"]
  node_ssvae["Sparse VAE<br/>latent encoder"]
  node_slvae_base["SLAT Base<br/>latent model base<br/>[base.py]"]
  node_encoder["Latent Encoder<br/>[encoder.py]"]
  node_modules["NN Modules<br/>backbone library"]
end

subgraph group_assets["Output Stack"]
  node_decoder_mesh["Mesh Decoder<br/>[decoder_mesh.py]"]
  node_decoder_rf["RF Decoder<br/>[decoder_rf.py]"]
  node_decoder_gs["GS Decoder<br/>[decoder_gs.py]"]
  node_mesh_rep["Mesh Rep<br/>representation<br/>[cube2mesh.py]"]
  node_gaussian_rep["Gaussian Rep<br/>representation<br/>[gaussian_model.py]"]
  node_octree_rep["Octree Rep<br/>representation<br/>[octree_dfs.py]"]
  node_rf_rep["Radiance Field<br/>representation<br/>[strivec.py]"]
  node_mesh_renderer["Mesh Renderer<br/>[mesh_renderer.py]"]
  node_gaussian_renderer["Gaussian Renderer<br/>[gaussian_render.py]"]
  node_octree_renderer["Octree Renderer<br/>[octree_renderer.py]"]
end

subgraph group_native["Native Backend"]
  node_nvdiffrast["nvdiffrast<br/>cuda extension"]
end

node_init -->|"registers"| node_if_trellis
node_init -->|"registers"| node_if_loader
node_if_loader -->|"loads"| node_manager
node_if_trellis -->|"uses"| node_manager
node_if_trellis -->|"invokes"| node_image3d
node_image3d -->|"extends"| node_pipeline_base
node_image3d -->|"drives"| node_sampler_base
node_sampler_base -->|"mixes in"| node_cfg
node_sampler_base -->|"implements"| node_flow_euler
node_image3d -->|"runs"| node_slf
node_image3d -->|"conditions"| node_ssvae
node_slf -->|"depends on"| node_modules
node_ssf -->|"depends on"| node_modules
node_ssvae -->|"inherits"| node_slvae_base
node_slvae_base -->|"contains"| node_encoder
node_slvae_base -->|"decodes"| node_decoder_mesh
node_slvae_base -->|"decodes"| node_decoder_rf
node_slvae_base -->|"decodes"| node_decoder_gs
node_decoder_mesh -->|"materializes"| node_mesh_rep
node_decoder_rf -->|"materializes"| node_rf_rep
node_decoder_gs -->|"materializes"| node_gaussian_rep
node_mesh_rep -->|"renders"| node_mesh_renderer
node_gaussian_rep -->|"renders"| node_gaussian_renderer
node_octree_rep -->|"renders"| node_octree_renderer
node_mesh_renderer -->|"accelerates"| node_nvdiffrast
node_gaussian_renderer -->|"accelerates"| node_nvdiffrast

click node_init "https://github.com/kijai/comfyui-if_trellis/blob/main/__init__.py"
click node_if_trellis "https://github.com/kijai/comfyui-if_trellis/blob/main/IF_Trellis.py"
click node_if_loader "https://github.com/kijai/comfyui-if_trellis/blob/main/IF_TrellisCheckpointLoader.py"
click node_manager "https://github.com/kijai/comfyui-if_trellis/blob/main/trellis_model_manager.py"
click node_pipeline_base "https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/pipelines/base.py"
click node_image3d "https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/pipelines/trellis_image_to_3d.py"
click node_sampler_base "https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/pipelines/samplers/base.py"
click node_cfg "https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/pipelines/samplers/classifier_free_guidance_mixin.py"
click node_flow_euler "https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/pipelines/samplers/flow_euler.py"
click node_slf "https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/models/structured_latent_flow.py"
click node_ssf "https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/models/sparse_structure_flow.py"
click node_ssvae "https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/models/sparse_structure_vae.py"
click node_slvae_base "https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/models/structured_latent_vae/base.py"
click node_encoder "https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/models/structured_latent_vae/encoder.py"
click node_decoder_mesh "https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/models/structured_latent_vae/decoder_mesh.py"
click node_decoder_rf "https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/models/structured_latent_vae/decoder_rf.py"
click node_decoder_gs "https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/models/structured_latent_vae/decoder_gs.py"
click node_mesh_rep "https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/representations/mesh/cube2mesh.py"
click node_gaussian_rep "https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/representations/gaussian/gaussian_model.py"
click node_octree_rep "https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/representations/octree/octree_dfs.py"
click node_rf_rep "https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/representations/radiance_field/strivec.py"
click node_mesh_renderer "https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/renderers/mesh_renderer.py"
click node_gaussian_renderer "https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/renderers/gaussian_render.py"
click node_octree_renderer "https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/renderers/octree_renderer.py"
click node_modules "https://github.com/kijai/comfyui-if_trellis/tree/main/trellis/modules"
click node_nvdiffrast "https://github.com/kijai/comfyui-if_trellis/tree/main/extensions/nvdiffrast"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_init,node_if_trellis,node_if_loader toneBlue
class node_manager,node_pipeline_base,node_image3d,node_sampler_base,node_cfg,node_flow_euler toneAmber
class node_slf,node_ssf,node_ssvae,node_slvae_base,node_encoder,node_modules toneMint
class node_decoder_mesh,node_decoder_rf,node_decoder_gs,node_mesh_rep,node_gaussian_rep,node_octree_rep,node_rf_rep,node_mesh_renderer,node_gaussian_renderer,node_octree_renderer toneRose
class node_nvdiffrast toneIndigo
```

## Components

### ComfyUI Edge

Node wrappers and workflow-facing entry points.

- [Package Init](https://github.com/kijai/comfyui-if_trellis/blob/main/__init__.py): entry package · Registers the custom node package with ComfyUI. · `__init__.py`
- [Trellis Node](https://github.com/kijai/comfyui-if_trellis/blob/main/IF_Trellis.py): comfyui node · Main generation node that drives TRELLIS inference from ComfyUI inputs. · `IF_Trellis.py`
- [Checkpoint Loader](https://github.com/kijai/comfyui-if_trellis/blob/main/IF_TrellisCheckpointLoader.py): comfyui 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](https://github.com/kijai/comfyui-if_trellis/blob/main/trellis_model_manager.py): runtime coordinator · Selects, loads, caches, and shares heavyweight model artifacts across executions. · `trellis_model_manager.py`
- [Pipeline Base](https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/pipelines/base.py): pipeline base · Shared execution scaffolding for TRELLIS pipelines. · `trellis/pipelines/base.py`
- [Image to 3D](https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/pipelines/trellis_image_to_3d.py): application pipeline · Primary TRELLIS pipeline for turning image inputs into 3D outputs. · `trellis/pipelines/trellis_image_to_3d.py`
- [Sampler Base](https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/pipelines/samplers/base.py): sampling core · Common sampler interface for rectified-flow style generation. · `trellis/pipelines/samplers/base.py`
- [CFG Mixin](https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/pipelines/samplers/classifier_free_guidance_mixin.py): guidance mixin · Classifier-free guidance behavior for sampling. · `trellis/pipelines/samplers/classifier_free_guidance_mixin.py`
- [Flow Euler](https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/pipelines/samplers/flow_euler.py): sampler · 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](https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/models/structured_latent_flow.py): generative model · Structured latent flow model that drives synthesis in latent 3D space. · `trellis/models/structured_latent_flow.py`
- [Sparse Flow](https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/models/sparse_structure_flow.py): generative model · Sparse structure flow model for structured 3D state. · `trellis/models/sparse_structure_flow.py`
- [Sparse VAE](https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/models/sparse_structure_vae.py): latent encoder · Sparse structure VAE that bridges observations and latent structure. · `trellis/models/sparse_structure_vae.py`
- [SLAT Base](https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/models/structured_latent_vae/base.py): latent model base · Shared base for structured latent VAE components. · `trellis/models/structured_latent_vae/base.py`
- [Latent Encoder](https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/models/structured_latent_vae/encoder.py): encoder · Encodes structured 3D inputs into the latent representation. · `trellis/models/structured_latent_vae/encoder.py`
- [NN Modules](https://github.com/kijai/comfyui-if_trellis/tree/main/trellis/modules): backbone library · Reusable attention, sparse ops, transformer blocks, and spatial utilities. · `trellis/modules`

### Output Stack

Decoders, representations, and renderers for 3D outputs.

- [Mesh Decoder](https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/models/structured_latent_vae/decoder_mesh.py): decoder · Decodes structured latent features into mesh geometry. · `trellis/models/structured_latent_vae/decoder_mesh.py`
- [RF Decoder](https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/models/structured_latent_vae/decoder_rf.py): decoder · Decodes structured latent features into radiance fields. · `trellis/models/structured_latent_vae/decoder_rf.py`
- [GS Decoder](https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/models/structured_latent_vae/decoder_gs.py): decoder · Decodes structured latent features into Gaussian splats. · `trellis/models/structured_latent_vae/decoder_gs.py`
- [Mesh Rep](https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/representations/mesh/cube2mesh.py): representation · Mesh construction and conversion utilities. · `trellis/representations/mesh/cube2mesh.py`
- [Gaussian Rep](https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/representations/gaussian/gaussian_model.py): representation · Gaussian model structures and helpers. · `trellis/representations/gaussian/gaussian_model.py`
- [Octree Rep](https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/representations/octree/octree_dfs.py): representation · Octree traversal and structured occupancy representation. · `trellis/representations/octree/octree_dfs.py`
- [Radiance Field](https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/representations/radiance_field/strivec.py): representation · Radiance-field representation used by decoding and rendering paths. · `trellis/representations/radiance_field/strivec.py`
- [Mesh Renderer](https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/renderers/mesh_renderer.py): renderer · Renders mesh outputs for preview or inspection. · `trellis/renderers/mesh_renderer.py`
- [Gaussian Renderer](https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/renderers/gaussian_render.py): renderer · Renders Gaussian splat outputs. · `trellis/renderers/gaussian_render.py`
- [Octree Renderer](https://github.com/kijai/comfyui-if_trellis/blob/main/trellis/renderers/octree_renderer.py): renderer · Renders octree-based outputs and previews. · `trellis/renderers/octree_renderer.py`

### Native Backend

Bundled GPU extensions and prebuilt wheels.

- [nvdiffrast](https://github.com/kijai/comfyui-if_trellis/tree/main/extensions/nvdiffrast): cuda extension · Bundled differentiable rasterization backend with Torch and TensorFlow bindings. · `extensions/nvdiffrast`

## Connections

- 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.
