three-bvh-csg icon indicating copy to clipboard operation
three-bvh-csg copied to clipboard

Add utility for simplifying flat mesh surfaces

Open gkjohnson opened this issue 2 years ago • 2 comments

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?

gkjohnson avatar Dec 04 '22 12:12 gkjohnson

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

johncalvinyoung avatar Dec 07 '22 00:12 johncalvinyoung

Possibly related:

https://github.com/mrdoob/three.js/issues/10517

gkjohnson avatar Mar 01 '23 01:03 gkjohnson