gkjohnson / three-bvh-csg

A flexible, memory compact, fast and dynamic CSG implementation on top of three-mesh-bvh
MIT License
601 stars 46 forks source link

Extra edges after complex subtraction #181

Closed codand closed 9 months ago

codand commented 10 months ago

Subtracting a box (or any shape) from a 3DBenchy (popular 3D print) produces a geometry with several incorrect edges contained in the subtraction area. These are only visible when rendering the result wireframe.

Repro: Open this codesandbox link (adapted from the Simple CSG example) and set brush 1's shape to "mesh".

Additional info:

isWaterTight reports true for this mesh,

Blender's 3D print checker also reports zero non-manifold edges. image image image

Hope this report might help figure out some edge cases.

gkjohnson commented 10 months ago

Interesting - I'm also seeing that "intersectionEdges" is reporting some odd extraneous edges:

image

Can you please produce a simpler example that just includes the two geometries and the clipping operation and the wireframe?

isWaterTight reports true for this mesh,

Also note that is water tight is not documented and not currently fully functional.

codand commented 10 months ago

Can you please produce a simpler example that just includes the two geometries and the clipping operation and the wireframe?

Sure. here's a stripped down version.

gkjohnson commented 10 months ago

I fixed #183 in v0.0.15 which seemed to be related but it does not seem to have fixed this issue. Are you seeing this same kind of issue with any simpler models? Ideally generated models from the three.js primitives?

codand commented 10 months ago

I've not yet seen it happen from a single subtraction between two threejs primitives, but I have seen it happen after multiple consecutive subtractions. I'll see if I can produce a simpler example on the latest update this week. Thank you for investigating!

gkjohnson commented 9 months ago

It looks this this is happening as part of the "full triangle" accumulation step - ie the step where unclipped triangles are appended to the result.

image

These edges look like they intersect the the clip volume but the intersection detection skips triangles marked as "degenerate". It seems they're inadvertently being added to the result geometry elsewhere, instead.

image

They're gone if we filter triangles with area === 0 when building the result geometry:

image

These degenerate triangles are in the original model, as well - 563 of them. I guess these will have to be filtered out during the clip process. I'll just have to think abut the right place to do it.

gkjohnson commented 9 months ago

193 should fix it:

image image
gkjohnson commented 9 months ago

I still want to check out the "intersection edges" issue listed above, though.

gkjohnson commented 9 months ago

Looks like the eges issue can't be easily reproduced at the moment - we can track it down when it arrises another time:

image