zeux / meshoptimizer

Mesh optimization library that makes meshes smaller and faster to render
MIT License
5.49k stars 473 forks source link

Simplification should recognize and handle UV mirroring seams #718

Open Makio64 opened 2 months ago

Makio64 commented 2 months ago

Rare case but on some models, simplification lead to UV artefacts : UVs are getting fully streched (same value on both vertices) when many other triangles could have been optimized instead, I suggest to give a lower priority to simplify/remove vertices/faces of the mesh leading to these results.

It might also be a bug in the way the uvs get re-assigned.

The model used to illustrate this example : https://www.dropbox.com/scl/fi/po761ykdiqdmtbzd9fitf/rhino.glb?rlkey=s6jp06vtr4id0opnv76wwys1p&dl=0

Before simplify :

Screenshot 2024-07-08 at 16 25 05

After simplify :

Screenshot 2024-07-08 at 16 14 54
zeux commented 2 months ago

Are UVs mirrored here? If so then yeah it’s a known issue atm, and will get addressed eventually.

zeux commented 2 months ago

Yeah I looked at the scene closer and it's indeed UV mirroring. This needs special handling in the simplifier, probably as a separate pre-process.

Re-attaching the file so that this isn't lost in the future (I also regenerated the normals here because they were just broken in the input file): rhino.zip rhino-tbn.zip

Worth noting is that if the GLB file gets re-exported with tangent data and a normal map (without a normal map gltfpack needs -kv flag), the simplifier will automatically recognize the mirroring seam and simplify correctly (of course, this ideally should work without tangent information present to begin with): image