Skip to content

Commit

Permalink
[fix] BlockSupportGenerator generates base-support correctly
Browse files Browse the repository at this point in the history
# Remove volume check in trimesh.boolean operations
# Block volume supports that are connected to the build-plate are intersected with the original mesh
  • Loading branch information
drlukeparry committed Mar 19, 2024
1 parent 7f1e42a commit f1d9c95
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
6 changes: 3 additions & 3 deletions pyslm/support/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def boolUnion(meshA: trimesh.Trimesh, meshB: trimesh.Trimesh) -> trimesh.Trimesh
:return: The Boolean union between Mesh A and Mesh B.
"""
#vertsOut, facesOut = pycork.union(meshA.vertices, meshA.faces, meshB.vertices, meshB.faces)
outMesh = trimesh.boolean.union([meshA, meshB], engine='manifold')
outMesh = trimesh.boolean.union([meshA, meshB], engine='manifold', check_volume=False)
return outMesh


Expand All @@ -323,7 +323,7 @@ def boolIntersect(meshA: trimesh.Trimesh, meshB: trimesh.Trimesh):
"""
#vertsOut, facesOut = pycork.intersection(meshA.vertices, meshA.faces, meshB.vertices, meshB.faces)

outMesh = trimesh.boolean.intersection([meshA, meshB], engine='manifold')
outMesh = trimesh.boolean.intersection([meshA, meshB], engine='manifold', check_volume=False)
return outMesh


Expand All @@ -344,7 +344,7 @@ def boolDiff(meshA: trimesh.Trimesh, meshB: trimesh.Trimesh) -> trimesh.Trimesh:
"""
#vertsOut, facesOut = pycork.difference(meshA.vertices, meshA.faces, meshB.vertices, meshB.faces)

outMesh = trimesh.boolean.difference([meshA, meshB], engine='manifold')
outMesh = trimesh.boolean.difference([meshA, meshB], engine='manifold', check_volume=False)
return outMesh


Expand Down
24 changes: 13 additions & 11 deletions pyslm/support/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,10 +728,6 @@ def identifySupportRegions(self, part: Part, overhangAngle: float,

overhangSubregions = getOverhangMesh(part, overhangAngle, True)

"""
The geometry of the part requires exporting as a '.off' file to be correctly used with the Cork Library
"""

supportBlockRegions = []

totalBooleanTime = 0.0
Expand All @@ -750,9 +746,7 @@ def identifySupportRegions(self, part: Part, overhangAngle: float,
#mergedPoly.merge_vertices(1)
#mergedPoly = mergedPoly.simplify_spline(self._splineSimplificationFactor)

# Simplify the polygon to ease simplify extrusion

# Offset in 2D the support region projection
# Simplify the polygon to ease simplify extrusion and offset in 2D the support region projection
offsetShape = polygon.simplify(self.simplifyPolygonFactor, preserve_topology=False).buffer(-self.outerSupportEdgeGap)

if offsetShape is None or offsetShape.area < self.minimumAreaThreshold:
Expand Down Expand Up @@ -786,6 +780,8 @@ def identifySupportRegions(self, part: Part, overhangAngle: float,
extruMesh2Flat.vertices[:,2] = 0.0

extruMesh2 = trimesh.creation.extrude_triangulation(extruMesh2Flat.vertices[:,:2], extruMesh2Flat.faces, 100)

# Position the upper-surface of the mesh just below the upper surface (1e-2) to avoid self-intersection
eMesh2Idx = extruMesh2.vertices[:,2] > 1.0
extruMesh2.vertices[eMesh2Idx,2] = subregion.vertices[:,2] - 0.01
extruMesh = extruMesh2
Expand All @@ -798,7 +794,7 @@ def identifySupportRegions(self, part: Part, overhangAngle: float,

bbox = extruMesh.bounds
cutMesh = boolIntersect(part.geometry, extruMesh)
logging.info('\t\t - Mesh intersection time using Cork: {:.3f}s'.format(time.time() - timeIntersect))
logging.info('\t\t - Mesh intersection time using manifold: {:.3f}s'.format(time.time() - timeIntersect))
logging.info('\t - Finished intersecting mesh')
totalBooleanTime += time.time() - timeIntersect

Expand Down Expand Up @@ -953,7 +949,7 @@ def identifySupportRegions(self, part: Part, overhangAngle: float,
ray_directions=ray_dir,
multiple_hits=False)
else:
# Base-plate support
# The region was not intersecting with the part so this is a Base-plate support
hitLoc2 = []

if len(hitLoc) != len(coords) or len(hitLoc2) != len(hitLoc):
Expand Down Expand Up @@ -999,10 +995,16 @@ def identifySupportRegions(self, part: Part, overhangAngle: float,
Previous mesh was used in Version 0.5. This was not necessarily required, but offers the most robust
implementation dealing with self-intersections
"""
#blockSupportMesh = boolDiff(part.geometry,extrudedBlock)


extrudedBlock.fix_normals()
extrudedBlock.merge_vertices()
blockSupportMesh = boolDiff(extrudedBlock, cutMesh)

if cutMesh.volume < BlockSupportGenerator._intersectionVolumeTolerance:
# Base-plate support voliume is created but requires intersection with the previous full mesh
blockSupportMesh = boolDiff(extrudedBlock, part.geometry)
else:
blockSupportMesh = boolDiff(extrudedBlock, cutMesh)

logging.info('\t\t Boolean Difference Time: {:.3f}\n'.format(time.time() - timeDiff))

Expand Down

0 comments on commit f1d9c95

Please sign in to comment.