Skip to content

Commit

Permalink
Update to use manifold3d library
Browse files Browse the repository at this point in the history
  • Loading branch information
drlukeparry committed Dec 8, 2023
1 parent 114ffa9 commit bad0fc0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 32 deletions.
56 changes: 27 additions & 29 deletions pyslm/support/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,80 +104,78 @@ def extrudeFace(extrudeMesh: trimesh.Trimesh,

def boolUnion(meshA: trimesh.Trimesh, meshB: trimesh.Trimesh) -> trimesh.Trimesh:
"""
Performs a Boolean CSG union operation using the `pycork <https://github.com/drlukeparry/pycork>`_ library between
two meshes.
Performs a Boolean CSG union operation using the `manifold3d <https://github.com/elalish/manifold>`_ library
between two meshes.
.. note::
The meshes provided should ideally be watertight (manifold) and have no-self intersecting faces to ensure that
the underlying Cork Library can correctly perform the operation. The resultant mesh is processed natively
The meshes provided should be watertight (manifold) and have no-self intersecting faces to ensure that
the underlying manifold3D Library can correctly perform the operation. The resultant mesh is processed natively
using Trimesh to merge coincident vertices and remove degenerate faces.
:param meshA: Mesh A
:param meshB: Mesh B
:return: The Boolean union between Mesh A and Mesh B.
"""
vertsOut, facesOut = pycork.union(meshA.vertices, meshA.faces, meshB.vertices, meshB.faces)

return trimesh.Trimesh(vertices=vertsOut, faces=facesOut, process=True)
#vertsOut, facesOut = pycork.union(meshA.vertices, meshA.faces, meshB.vertices, meshB.faces)
outMesh = trimesh.boolean.union([meshA, meshB], engine='manifold')
return outMesh


def boolIntersect(meshA: trimesh.Trimesh, meshB: trimesh.Trimesh):
"""
Performs a Boolean CSG intersection operation using the `pycork <https://github.com/drlukeparry/pycork>`_ library
between two meshes.
.. note::
The meshes provided should ideally be watertight (manifold) and have no-self intersecting faces to ensure that
the underlying Cork Library can correctly perform the operation. The resultant mesh is processed natively
using Trimesh to merge coincident vertices and remove degenerate faces.
Performs a Boolean CSG intersection operation using the `manifold3d <https://github.com/elalish/manifold>`_ library
between two meshes.
.. note::
The meshes provided should be watertight (manifold) and have no-self intersecting faces to ensure that
the underlying manifold3D Library can correctly perform the operation. The resultant mesh is processed natively
using Trimesh to merge coincident vertices and remove degenerate faces.
:param meshA: Mesh A
:param meshB: Mesh B
:return: The Boolean intersection between Mesh A and Mesh B.
"""
vertsOut, facesOut = pycork.intersection(meshA.vertices, meshA.faces, meshB.vertices, meshB.faces)
#vertsOut, facesOut = pycork.intersection(meshA.vertices, meshA.faces, meshB.vertices, meshB.faces)

return trimesh.Trimesh(vertices=vertsOut, faces=facesOut, process=True)
outMesh = trimesh.boolean.intersection([meshA, meshB], engine='manifold')
return outMesh


def boolDiff(meshA: trimesh.Trimesh, meshB: trimesh.Trimesh) -> trimesh.Trimesh:
"""
Performs a Boolean CSG difference operation using the `pycork <https://github.com/drlukeparry/pycork>`_ library
Performs a Boolean CSG difference operation using the `manifold3d <https://github.com/elalish/manifold>`_ library
between two meshes.
.. note::
The meshes provided should ideally be watertight (manifold) and have no-self intersecting faces to ensure that
the underlying Cork Library can correctly perform the operation. The resultant mesh is processed natively
The meshes provided should be watertight (manifold) and have no-self intersecting faces to ensure that
the underlying manifold3D Library can correctly perform the operation. The resultant mesh is processed natively
using Trimesh to merge coincident vertices and remove degenerate faces.
:param meshA: Mesh A
:param meshB: Mesh B
:return: The Boolean difference between Mesh A and Mesh B.
"""
vertsOut, facesOut = pycork.difference(meshA.vertices, meshA.faces, meshB.vertices, meshB.faces)
#vertsOut, facesOut = pycork.difference(meshA.vertices, meshA.faces, meshB.vertices, meshB.faces)

return trimesh.Trimesh(vertices=vertsOut, faces=facesOut, process=True)
outMesh = trimesh.boolean.difference([meshA, meshB], engine='manifold')
return outMesh


def resolveIntersection(meshA: trimesh.Trimesh) -> trimesh.Trimesh:
"""
Resolves all self-intersections within a meshn using the `pycork <https://github.com/drlukeparry/pycork>`_ library.
Resolves all self-intersections within a mesh
.. note::
The meshes provided should ideally be watertight (manifold) and have no-self intersecting faces to ensure that
the underlying Cork Library can correctly perform the operation. The resultant mesh is processed natively
using Trimesh to merge coincident vertices and remove degenerate faces.
This function has become deprecated due to the transfer to the `manifold3d` library
:param meshA: Mesh A
:return: Mesh with all intersections resolved
"""
vertsOut, facesOut = pycork.resolveIntersection(meshA.vertices, meshA.faces)

return trimesh.Trimesh(vertices=vertsOut, faces=facesOut, process=True)
raise Exception('Unsupported')

return trimesh.Trimesh()


def createPath2DfromPaths(paths: List[np.ndarray]) -> trimesh.path.Path2D:
Expand Down
3 changes: 1 addition & 2 deletions pyslm/support/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,7 @@ def _identifySelfIntersectionHeightMapRayTracing(self, subregion: trimesh.Trimes

return heightMap, heightMapUpper, heightMapLower


def identifySupportRegions(self, part: Part, overhangAngle: float,
findSelfIntersectingSupport: Optional[bool] = True) -> List[BlockSupportBase]:
"""
Expand All @@ -736,8 +737,6 @@ def identifySupportRegions(self, part: Part, overhangAngle: float,
:return: A list of BlockSupports
"""

import time

overhangSubregions = getOverhangMesh(part, overhangAngle, True)

"""
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
sphinx
pyclipr >= 0.1.4
numpy
manifold3d
matplotlib
networkx
Rtree
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
'shapely',
'cython',
'pyclipr',
'manifold3d',
'Rtree',
'networkx',
'matplotlib',
Expand Down Expand Up @@ -53,7 +54,6 @@
'trimesh', # Required for meshing geometry
'triangle',
'vispy',
'pycork'
'PyQt5',
'mapbox-earcut'
'colorlog']) # log in pretty colors
Expand Down

0 comments on commit bad0fc0

Please sign in to comment.