zeux/meshoptimizer

Simplification should prune topologically separate components

Ono-Sendai opened this issue · 8 comments

Hi,
I'm running into this problem a lot, here is an example mesh on which it occurs.

unsimplified gallery non wireframe

unsimplified gallery

The mesh has a bunch of small items in it (the cylindrical spotlights) that are topologically separate. As a result of that, meshopt_simplify / meshopt_simplifyWithAttributes can't remove them (as documented).

This is the result of meshopt_simplify:

simplified without attributes

The total number of triangles is only slightly reduced.

So then I call meshopt_simplifySloppy, which successfully removes the spotlights. Unfortunately meshopt_simplifySloppy seems to merge vertices aggressively, resulting in pretty incorrect shading normals on the room itself. See attached pics.

simplified sloppy
simplified sloppy2
simplified sloppy 3

What I want is some kind of simplification that can remove or merge topologically separate components, but which doesn't merge vertices on edges, and hence maintains reasonable shading normal fidelity.

Do you have any suggestions for that? Is it possible with meshoptimizer as-is, or would it need to be added?

Thanks,
Nick C.

p.s. please feel free to recategorise as a feature enhancement or discussion item.

Ah looks like a dup of #71 which has been open since 2019... :)

Just thinking out loud... what about a pass that computes the topological submeshes, computes bounding boxes of them, and discards any with size below the error threshold? I think it would help in this case at least.

zeux commented

a pass that computes the topological submeshes, computes bounding boxes of them, and discards any with size below the error threshold

Yeah this happens to be planned as one of the next improvements to simplify.

a pass that computes the topological submeshes, computes bounding boxes of them, and discards any with size below the error threshold

Yeah this happens to be planned as one of the next improvements to simplify.

Oh awesome! Was thinking of trying it myself.
Presumably there's some code to compute AABBs in there already, i can just adapt it.

I tried an implementation with some of my code, seems to work well:

It's relatively straightforward, breadth first search over adjacent triangles to identify connected components, compute AABB, compare with error, discard small components. Runs in linear time on the number of triangles.

I had a look at the meshoptimizer code but the data structures look a little tricky so I think I'll leave that to you :)
Can post my code for reference if you want but I imagine you don't need it.

2024-09-12.21-04-07.mp4
zeux commented

If you could share the asset that would be nice; I have a preliminary implementation for this feature and would like to make sure it works well on this.

zeux commented

Thanks! This was helpful.

Screencast.from.2024-09-25.14-20-45.webm