Wimacs/trellis2.c
Contribute to Wimacs/trellis2.c development by creating an account on GitHub.
37 stars · 1 forks · C
README
_____ __ ___ _ __ __ __ |_ _| \| ___| | | | | / _||_ \ / _| | | | |) | | | | | | | |\_ \ __) || | | | | <| |__| |_| |_ | | _) |/ _/ | |__ || || \\____|___|___|_|__/|___()___|
trellis2.c 3D Local Gen All-in-One
trellis2.c is an all-in-one local 3D generation toolkit powered by TRELLIS.2, Pixal3D, SegViGen, and TokenSkin. It includes image-to-3D generation, mesh texturing, automatic part decomposition, and automatic rigging. Inference runs entirely on native CUDA or Vulkan, with no Python or PyTorch runtime.
Build Requirements:
Git and CMake 3.22 or newer. A C/C++ toolchain: GCC/Clang on Linux or Visual Studio 2022 on Windows. The Vulkan SDK, including the loader, headers, and glslc. The CUDA Toolkit when building the CUDA backend. OpenGL and X11 development packages on Linux when building the bundled raylib viewer.
The Vulkan SDK is required for both inference backends because the pipeline tools also build the Vulkan mesh postprocessor and texture baker. Clone the repository with all submodules: git clone --recursive https://github.com/Wimacs/trellis2.c.git cd trellis2.c If the repository was cloned without submodules: git submodule update --init --recursive Linux CUDA: cmake -S . -B build-cuda \ -DCMAKE_BUILD_TYPE=Release \ -DTRELLIS2_C_BACKEND=cuda cmake --build build-cuda -j Vulkan: cmake -S . -B build-vulkan \ -DCMAKE_BUILD_TYPE=Release \ -DTRELLIS2_C_BACKEND=vulkan cmake --build build-vulkan -j Windows Run from a Visual Studio developer shell. CUDA: cmake -S . -B build-win -G "Visual Studio 17 2022" -A x64 ` -DTRELLIS2_C_BACKEND=cuda cmake --build build-win --config Release --parallel Vulkan: cmake -S . -B build-win-vulkan -G "Visual Studio 17 2022" -A x64 ` -DTRELLIS2_C_BACKEND=vulkan cmake --build build-win-vulkan --config Release --parallel CUDA defaults to compute capability 8.9. Set -DCMAKE_CUDA_ARCHITECTURES=<SM> for another GPU generation. For CLI-only builds, add -DTRELLIS2_C_BUILD_RAYLIB_VIEWER=OFF; add -DTRELLIS2_C_BUILD_TESTS=OFF when the test binaries are not needed. The examples below use ./build-cuda/. Use ./build-vulkan/ for a Vulkan build, ./build-win/Release/ for Windows CUDA, or ./build-win-vulkan/Release/ for Windows Vulkan. The backend is compiled into the executable and does not require a different command-line flag. Pipelines The examples assume that the corresponding model packages have already been downloaded or converted. TRELLIS.2, DINOv3, and BiRefNet can use the layout created by tools/download_weights.py; conversion helpers for NAF, SegviGen, and TokenSkin are also provided under tools/. trellis2-image-to-gltf Generates a textured 3D asset from one image with TRELLIS.2. The complete path prepares the foreground, encodes the image with DINOv3, generates and decodes the shape, cleans the topology, generates PBR textures, and exports GLB/glTF. The default profile is 512; --pipeline 1024 selects the 1024 profile. --shape-only skips texture generation. ./build-cuda/trellis2-image-to-gltf \ --model ../TRELLIS.2/TRELLIS.2-4B \ --dino ../TRELLIS.2/dinov3-vitl16-pretrain-lvd1689m \ --image example_image/T.png \ --pipeline 1024 \ --output output.glb For opaque input, an auto-discovered BiRefNet checkpoint is used when available; transparent RGBA input is used directly. pixal3d-image-to-gltf Generates a textured 3D asset with Pixal3D's NAF and projected-image conditioning. It defaults to 1024_cascade; use --pipeline 1536_cascade for the larger cascade. NAF is discovered at MODEL/ckpts/naf_release.safetensors or can be supplied with --naf. ./build-cuda/pixal3d-image-to-gltf \ --model ../Pixal3D/Pixal3D \ --dino ../TRELLIS.2/dinov3-vitl16-pretrain-lvd1689m \ --image example_image/T.png \ --output pixal3d.glb Opaque input also requires an auto-discovered BiRefNet checkpoint or an explicit --birefnet FILE; transparent RGBA input does not. trellis2-texture-mesh Generates new PBR materials for an existing triangle mesh from a reference image. It encodes the mesh as a TRELLIS.2 shape latent, runs the texture flow and decoder, and writes a new static GLB. Because the asset is rebuilt, source node hierarchy, materials, UVs, skins, animations, and VRM extensions are not preserved. ./build-cuda/trellis2-texture-mesh \ --model ../TRELLIS.2/TRELLIS.2-4B \ --dino ../TRELLIS.2/dinov3-vitl16-pretrain-lvd1689m \ --input input.glb \ --image reference.png \ --output textured.glb Opaque reference images require BiRefNet. A prepared foreground image can be passed with --image-prepared. trellis2-segment-mesh Automatically decomposes a static GLB/glTF mesh with SegViGen Full. When no condition image is supplied, the pipeline renders one from a fixed camera, predicts part labels, separates connected components, and writes one assembly GLB with one selectable node and mesh per physical part. The default output preserves every source face exactly once together with mappable standard vertex attributes, materials, and textures. ./build-cuda/trellis2-segment-mesh \ --model ../TRELLIS.2/TRELLIS.2-4B \ --segmentation-model ../SegviGen \ --dino ../TRELLIS.2/dinov3-vitl16-pretrain-lvd1689m \ --input input.glb \ --output parts.glb --small-part-mode keep|merge|discard controls disconnected micro-shells; discard intentionally removes their faces. The pipeline does not generate cut surfaces or caps, so separated parts are not guaranteed to be watertight. Inputs whose skins, animations, morphs, instancing, or extensions cannot be preserved correctly are rejected. tokenskin-rig Automatically rigs an existing GLB/glTF mesh with TokenSkin. The output GLB contains the generated skeleton, joints, inverse bind matrices, and skin weights. Flattened world-space geometry and standard PBR appearance are preserved; source node hierarchy, morph targets, and existing animations are not. ./build-cuda/tokenskin-rig \ --model models/tokenskin \ --input input.glb \ --output rigged.glb
