zeux / meshoptimizer

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

simplifySloppy aggressively welds vertices causing issues for attribute discontinuities #71

Open FreakTheMighty opened 5 years ago

FreakTheMighty commented 5 years ago

When I use the aggressive option in gltfpack I find that the model shading looks off. This appears to be caused by the normal being a bit messy. Attached is a screen shot from the babylon.js viewer with normal preview turned on for one of the meshes (hence the beautiful rainbow).

Screen Shot 2019-10-24 at 3 00 30 PM

I'm not sure if this is an unavoidable artifact, or something that can be improved. Also, I realize the input model is already pretty sparse. Nonetheless, the vertex removals seem reasonable, if only the normals were better preserved.

Here's an example of the command I'm using. I've also attached the input and output GLBs I'm using.

gltfpack -i /tmp/input.glb -o /tmp/output.glb -si 0.8 -sa -v

Archive.zip

zeux commented 5 years ago

This is the current deficiency of the aggressive mode, or more specifically the sloppy simplifier. It does not preserve attribute discontinuities which causes issues like this. I have thoughts about improving this in the future but for now that’s expected.

FreakTheMighty commented 5 years ago

Sounds good @zeux. Out of curiosity, would throwing out the normals and recalculating them after decimation work, or is the problem more complex than that?

zeux commented 5 years ago

It would work as an option but this requires reindexing - it’s fine to do as part of gltfpack, but it doesn’t work with the simplifier interface. Additionally this doesn’t work for texture coordinates. So my hope is that this can be solved during simplification, but it’s certainly possible that that doesn’t work well enough and we’ll need to recompute normals and give up on UVs. Regular simplifier doesn’t have this issue but it respects the mesh topology which makes it get “stuck” on some models.