How firtoz/trellis works
Project Type and Purpose
• TRELLIS is a 3D asset generation tool that converts images (and eventually text) into high-quality 3D models in multiple representations (3D Gaussians, Radiance Fields, and textured meshes). Its core differentiator is a structured latent (SLAT) representation that unifies the generation process.
• The project supports both a web demo (using a Gradio-based interface in app.py) and local Python pipelines for generating and rendering 3D assets from input images. There are also dataset toolkits provided for data preparation and several extensions (like vox2seq) that leverage CUDA for performance acceleration.
Key Components
a. Frontend / Web Demo:
• “app.py” serves as the gateway for the browser-based demo. This component, depending on Gradio (or Hugging Face Spaces), allows users to upload images and view generated 3D assets.
b. Inference Pipeline & API Layer:
• The primary logic resides in the pipelines inside the “trellis/pipelines” directory (for example, TrellisImageTo3DPipeline). This module orchestrates the overall 3D generation process.
• “predict.py” and “example.py” exemplify how to trigger the pipeline from different contexts.
c. Model Logic:
• Located in “trellis/models” (including submodules like sparse_structure_flow, structured_latent_vae, etc.), this part encapsulates the deep learning models and the unified SLAT representation.
d. Core Modules & Utilities:
• The “trellis/modules” directory contains various building blocks (e.g., attention, sparse convolutions, transformers) that facilitate the computations behind the scenes.
• The “trellis/utils” provide helper functions for rendering, postprocessing, and general utilities for random and render operations.
e. Data Preparation and Toolkit Components:
• The “dataset_toolkits” folder contains scripts (e.g., build_metadata.py, download.py, encode_latent.py) for handling datasets, performing rendering tasks, voxelization, and dataset building.
f. Extensions:
• The “extensions” folder (specifically, vox2seq) includes CUDA implementations and benchmarks that extend the core functionality—especially for high-performance or experimental modules.
g. Representations & Renderers:
• Under “trellis/representations” and “trellis/renderers”, different output formats of the generated 3D models are managed, ensuring compatibility with formats like GLB, PLY, or supporting video renderings (mp4).
Relationships and Data Flow
• User提交s an image through the Web Demo (app.py) or a script (example.py).
• The input is fed into the pipeline (for example, TrellisImageTo3DPipeline) that locates and invokes the appropriate model modules in “trellis/models”.
• The model’s output, which leverages the defined SLAT representations, passes through various renderers and utilities:
• Renderers convert the model’s internal representations to videos (mp4) or 3D file formats (GLB, PLY).
• Postprocessing utilities in “trellis/utils” refine the outputs.
• Separately, dataset toolkits (found in “dataset_toolkits”) prepare or process training data, impacting model training and evaluation (although training code is noted as a TODO item).
• The “extensions/vox2seq” acts as an additional layer that may expedite or offer alternative computations (via GPU/CUDA kernels).
Architectural Patterns
• The design follows a modular, layered architecture where the interface (web demo or scripts) sits atop clearly partitioned pipelines.
• There is a clear separation between model computation, utility/rendering functions, and dataset processing.
• Components communicate via well-defined input-output contracts (e.g., pipelines expect images and output multi-format 3D assets).