Automatic merging of vertices based on angle
OmarShehata opened this issue · 1 comments
In Better outline rendering with surface IDs we can see that using a surface ID buffer gives you more stable outlines vs just a normal buffer.
One problem with this is you might need to go through your geometry and merge a lot of vertices manually for faces that should all be considered one surface.
I think it should be possible to do this almost completely automatically. It would work like this:
- Use an algorithm like ThreeJS EdgesGeometry that looks at the all the triangles, and determines if an edge should be drawn based on the angle of the two triangles it's connected to
- If an edge does NOT pass this angle test, its vertices should be merged so that it appears as one surface, and the edge does not render
- If an edge DOES pass the angle test, you should leave the vertices alone (or duplicate them if they are already merged?)
The only manual part about this is setting the threshold, but I think that's something that would be far easier to tweak than the normal buffer parameters.
If we can have a utility like that, then you'll be able to have very clean outlines by default, while still allowing you to edit individual edges in the model. It'd be the best of both worlds.
This is now resolved by: https://github.com/OmarShehata/webgl-outlines/tree/main/vertex-welder#vertex-welder
However, there's a number of caveats which I have listed at the end of that README. The biggest one is that texture coordinates get messed up when you delete vertices.