three-bvh-csg
three-bvh-csg copied to clipboard
New TriangleSplitter
Related to #51, #97
TODO
- Add "verbose" flag & update docs
- Implement the proper algorithm for inserting segments. From the paper:
- required segments can intersect - need a point inserted
- insert points first
- remove triangles that conflict
- triangulate using earcut
- https://github.com/gcherchi/FastAndRobustMeshArrangements
- https://dl.acm.org/doi/10.1145/3414685.3417818
Follow On
- Potentially able to determine coplanar triangles much more easily (triangles within a coplanar triangle)
- We have half-edge connectivity and "required" edges
- These can be used to more quickly determine connected triangle sets to add together and reduce raycasts
- Because it will be easier to track the original half edge sibling we can even use the sibling edges raycast result
- We can use these to update the half edge structure instead of rebuilding it from scratch
- Potentially enables easier water-tight detection
- Potentially able to choose edge direction that keep triangles fairly large
I have started using this branch and overall its a huge improvement over the old triangle splitter. I was able to find a couple small issues. https://github.com/ToyboxZach/three-bvh-csg/tree/FixTriangleSplit
I made three fixes:
- In the triangle splitter, if a triangle splits a triangle and ends directly on another edge the package used to ignore that point, we now correctly handle that.
- In edge sape, it was possible for those faces to be invalid this change fixes it so its much more unlikely to generate an invalid face.
- If there is a 0 area triangle we just don't add it to the final mesh, this was creating a few cases of extra edges/bounding box weirdness that was not necessary. I think the real fix is probably to not generate these 0 area triangles, but I need to move on to something else so I didn't dive too deeply into the issues.
I ended up finding most of these issues using various orientations of coplanar Boxes and TextGeomtery which gives a whole bunch of orientations
This is what was happening with this PR:
This is after my small fixes:
Thanks for taking a deeper look @ToyboxZach. As mentioned in #210 - there are still some issues with this approach. Specifically just "swapping edges" isn't good enough to generate a good topology. The paper referenced in the original comment instead requires that something like earcut triangulation be performed when we find that edges need to be swapped. Unfortunately the defacto javascript earch implementation (from MapboxGL) isn't robust to some scenarios and will produce bad triangulation. I think a CDL implementation (referenced in #210) would be easier to work with.