#!/usr/bin/env python3 """Reference dumps for the PBR-texture stages, for validating the C++/ggml port. Produces dumps/reference_texture.gguf with per-stage golden tensors so each C++ stage validates in isolation (feed identical inputs, compare outputs): cond [T, Cc] DINOv3 conditioning at texture resolution R enc_vert [N, 3] shape-encoder input: dual-vertex offsets (QEF) enc_inter [N, 3] shape-encoder input: intersection flags (QEF) enc_coords [N, 4] active voxels at R (batch-idx 0 + xyz) shape_slat [Nl, 32] shape encoder output (mean), the concat_cond shape_coords [Nl, 4] latent voxels at R/16 tex_noise [Nl, 32] fixed sampling noise (seed) tex_flow_t500 [Nl, 32] tex-flow forward at t=500 (concat_cond, f32) tex_slat [Nl, 32] full sampler output, denormalized pbr [M, 6] decoded PBR voxels (base_color,metal,rough,alpha), *0.5+0.5 pbr_coords [M, 4] decoded voxels at R (should equal enc_coords set) shape_slat_mean/std [32] shape_slat_normalization (concat_cond in-norm) tex_slat_mean/std [32] tex_slat_normalization (output de-norm) This dump validates the standalone arbitrary-mesh texturing path, whose encoder is fed a reproducible QEF dual grid. Integrated image-to-3D generation instead retains the generated shape SLat and replays the shape decoder's subdivisions; that wiring is covered by test_slat plus the sparse PBR sampling regression. Run inside the reference container (real o-voxel), e.g.: docker exec t2tex bash -lc \ 'cd /work && TRELLIS2_PY=/trellis2 python scripts/dump_texture_reference.py \ --mesh /s/mesh_shipped.bin --image dumps/fixture_rgba.png --resolution 512' """ import argparse, json, os, struct, sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import o_voxel # noqa: E402 real o-voxel BEFORE ref_common (skips its stub) import o_voxel.convert # noqa: E402 import ref_common # noqa: E402 ref_common.setup() # sdpa attention + pure-torch sparse conv import numpy as np # noqa: E402 import torch # noqa: E402 import torch.nn.functional as F # noqa: E402 from PIL import Image # noqa: E402 import trimesh # noqa: E402 from safetensors.torch import load_file # noqa: E402 from trellis2.models.sc_vaes.fdg_vae import FlexiDualGridVaeEncoder # noqa: E402 from trellis2.models.sc_vaes.sparse_unet_vae import SparseUnetVaeDecoder # noqa: E402 from trellis2.models.structured_latent_flow import SLatFlowModel # noqa: E402 from trellis2.pipelines.samplers import FlowEulerGuidanceIntervalSampler # noqa: E402 from trellis2.pipelines import Trellis2TexturingPipeline # noqa: E402 from trellis2.modules.image_feature_extractor import DinoV3FeatureExtractor # noqa: E402 from trellis2.modules import sparse as sp # noqa: E402 def load_t2mesh(path): b = open(path, "rb").read() assert b[:8] == b"T2MESH01", b[:8] nv, nt = struct.unpack("