three-bvh-csg
three-bvh-csg copied to clipboard
Add utility for simplifying flat mesh surfaces
During the process of applying CSG to a mesh flat surfaces become unnecessarily complex. During lulls in user operation it would be good to remesh brushes so they use a minimal number of triangles while still being connected - ie retriangulate flat / coplanar surfaces.
- Find all large, flat surfaces while retaining half edges
- Mark shared vertices as being removeable or not - ie required to define the contour of a shape.
- Remove unnecessary vertices from the new shapes
- Earcut to triangulate the surfaces
Alternative:
- Find all polygon contours
- Remove vertices along straight edges
- Find connected edges of contours and join them (check for coplanarity)
- Ensure holes are retained
- Use earcut to produce a new geometry
TODO:
- How do deal with uv or other buffer attributes?
For a variety of use cases, it'd be good to make this a purely optional part of the workflow--I have applications where retaining the position & connectivity of any un-changed vertices is mildly important
Possibly related:
https://github.com/mrdoob/three.js/issues/10517