Texturing: make the keep-existing-UVs path reachable (and non-crashing once it is) - #173
Open
xocialize wants to merge 1 commit into
Open
Texturing: make the keep-existing-UVs path reachable (and non-crashing once it is)#173xocialize wants to merge 1 commit into
xocialize wants to merge 1 commit into
Conversation
- preprocess_mesh: carry mesh.visual through the rebuilt Trimesh. run() normalizes the mesh before postprocess_mesh ever sees it, so dropping the visual made the keep-existing-UVs branch unreachable via the public API. Vertex order is unchanged, so per-vertex UVs stay valid. - postprocess_mesh: copy vertices/faces/normals up front. trimesh's vertex_normals cache is read-only and the glTF axis swap writes in place; only the uv-unwrap branch happened to replace these with fresh arrays. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Trellis2TexturingPipeline.postprocess_meshimplements a keep-existing-UVs branch, but it is unreachable viarun():preprocess_meshrebuilds the mesh astrimesh.Trimesh(vertices=vertices, faces=mesh.faces, process=False)and dropsmesh.visual, so by the timepostprocess_meshchecksmesh.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