Texturing: make the keep-existing-UVs path reachable (and non-crashing once it is)
Problem
Trellis2TexturingPipeline.postprocess_mesh implements a keep-existing-UVs branch, but it is unreachable via run(): preprocess_mesh rebuilds the mesh as trimesh.Trimesh(vertices=vertices, faces=mesh.faces, process=False) and drops mesh.visual, so by the time postprocess_mesh checks mesh.visual.uv, the UVs are always gone and every input falls into the uv-unwrap branch. The shipped "texture an existing mesh preserving its UVs" capability silently never engages.
Fix
preprocess_mesh: passvisual=mesh.visualthrough the rebuiltTrimesh. The rebuild doesn't change vertex order (only positions), so per-vertex UVs remain valid.postprocess_mesh: copyvertices/faces/normalswithnp.array()up front.mesh.vertex_normalsis a read-only trimesh cache, and the glTF axis swap at the end writes it in place (normals[:, 1], normals[:, 2] = ...). Today only the uv-unwrap branch runs, and it happens to replacenormalswith a fresh indexed array — so this second bug is latent until fix (1) makes the UV-preserve branch reachable, at which point it crashes. The two fixes belong in the same PR.
Evidence
With these changes, re-texturing an existing UV-mapped mesh preserves its UVs bit-identically — we measured max UV delta 0.0 between input and output in production use (Apple Silicon port work, https://github.com/xocialize/trellis2-apple).
🤖 Generated with Claude Code