CadQuery / cadquery

A python parametric CAD scripting framework based on OCCT
https://cadquery.readthedocs.io
Other
3.16k stars 289 forks source link

Fuse fails to clean a face that is based on a somewhat tangled wire #1010

Open voneiden opened 2 years ago

voneiden commented 2 years ago

1) Similar as in CQ SVG export, the wire is created from projected edges using cq.Wire.combine. The result has 7 edges. 2) The wire edge order is shown in screenshot, it forms a sort of number "8" loop:

image

3) The wire is then converted to face using cq.Face.makeFromWires - the face looks OK, but the underlying Wire is still tangled 4) Further attempts to fuse, combine, clean, etc. fail to clean up the underlying wire. 5) Exporting face to brep shows the 7 edges still there in the brep file, however, importBrep appears to clean the wire (!) 6) The wire brep seems to be imported with the original 7 edges intact (seems correct).

Attached are both breps for the face and the wire. breps.tar.gz

voneiden commented 2 years ago

I also tried to fuse these two faces (illustrated in wireframe) image

and the result was a face like this (illustrated in wireframe) image

voneiden commented 2 years ago

Tested the imports like this

import cadquery as cq
import logging

logger = logging.getLogger(__name__)

face = cq.Face.importBrep('projected_face.brep')
wire = face.outerWire()
wire2 = cq.Face.importBrep('projected_wire.brep')
logger.info(face.Area())
show_object(face, 'face') # Face is correct size
show_object(wire, 'wire') # Clean wire with 4 edges
show_object(wire2, 'wire2') # Tangled wire, OK as expected
jmwright commented 2 years ago

I wonder if sortWiresByBuildOrder would help here.

voneiden commented 2 years ago

In this case there's only one wire, sortWiresByBuildOrder expects two or more. Under the hood it uses Face.makeFromWires, which does not resolve the issue (step 3 in the original description).

edgesToWires does not change anything either (uses ShapeAnalysis_FreeBounds.ConnectEdgesToWires).