1 Commits

Author SHA1 Message Date
Jonathon Broughton a06c9023fc better mock Mesh
build and deploy Speckle functions / publish-automate-function-version (push) Has been cancelled
2023-11-13 03:37:59 +00:00
3 changed files with 20 additions and 30 deletions
+9 -11
View File
@@ -15,7 +15,7 @@ from Geometry.mesh import cast
def detect_clashes_old(
reference_elements: List[Element], latest_elements: List[Element], _tolerance: float
reference_elements: List[Element], latest_elements: List[Element], _tolerance: float
) -> list[tuple[str, str, float]]:
"""
Detect clashes between two sets of mesh elements using Pymesh.
@@ -50,7 +50,7 @@ def detect_clashes_old(
)
if (
intersection and intersection.volume > 0
intersection and intersection.volume > 0
): # TODO: could tolerance relate to this?
severity = intersection.volume / min(
ref_pymesh.volume, latest_pymesh.volume
@@ -62,7 +62,7 @@ def detect_clashes_old(
def check_for_clash(
ref_element: Element, latest_element: Element
ref_element: Element, latest_element: Element
) -> Optional[tuple[Any, Any, Any]]:
"""
Check for a clash between two elements and calculate the severity of the clash.
@@ -82,9 +82,7 @@ def check_for_clash(
if not ref_pymesh or not latest_pymesh:
continue
intersection = pymesh.boolean(
latest_pymesh, operation="intersection"
)
intersection = pymesh.boolean(latest_pymesh, operation="intersection")
if intersection and intersection.volume > 0:
severity = intersection.volume / min(
ref_pymesh.volume, latest_pymesh.volume
@@ -94,7 +92,7 @@ def check_for_clash(
def detect_clashes(
reference_elements: List[Element], latest_elements: List[Element], _tolerance: float
reference_elements: List[Element], latest_elements: List[Element], _tolerance: float
) -> List[Tuple[str, str, float]]:
"""
Detect clashes between two sets of mesh elements using parallel processing.
@@ -123,10 +121,10 @@ def detect_clashes(
def detect_and_report_clashes(
reference_elements: list[Element],
latest_elements: list[Element],
tolerance: float,
automate_context: AutomationContext,
reference_elements: list[Element],
latest_elements: list[Element],
tolerance: float,
automate_context: AutomationContext,
) -> list[tuple[str, str, float]]:
clashes = detect_clashes(reference_elements, latest_elements, tolerance)
+2 -11
View File
@@ -12,15 +12,6 @@ import trimesh
from Geometry.helpers import triangulate_face
class MockPyMesh:
def __init__(self, vertices, faces):
self.vertices = vertices or []
self.faces = faces or []
def boolean(self, other, operation):
return MockPyMesh([], [])
def trimesh_to_pymesh(mesh: trimesh.Trimesh) -> pymesh.Mesh:
"""
Convert a Trimesh object to a Pymesh object.
@@ -44,7 +35,7 @@ def pymesh_to_trimesh(mesh: pymesh.Mesh) -> trimesh.Trimesh:
def cast(
mesh: Union[trimesh.Trimesh, pymesh.Mesh], target_type: Type
mesh: Union[trimesh.Trimesh, pymesh.Mesh], target_type: Type
) -> Union[trimesh.Trimesh, pymesh.Mesh]:
"""
Casts a mesh object to a specified type.
@@ -79,7 +70,7 @@ def speckle_mesh_to_trimesh(input_mesh: SpeckleMesh) -> trimesh.Trimesh:
face_vertex_count = input_mesh.faces[i]
i += 1 # Skip the vertex count
face_vertex_indices = input_mesh.faces[i: i + face_vertex_count]
face_vertex_indices = input_mesh.faces[i : i + face_vertex_count]
face_vertices = [
Vector.from_list(vertices[idx].tolist()) for idx in face_vertex_indices
+9 -8
View File
@@ -1,12 +1,13 @@
class mypymesh:
def __init__(self, vertices, faces):
self.vertices = vertices
self.faces = faces
class Mesh:
def __init__(self, vertices, faces):
self.vertices = vertices
self.faces = faces
@property
def volume(self):
return 0
@staticmethod
def boolean(_other, _operation):
return mypymesh([], [])
@property
def volume(self):
return 0
return mypymesh.Mesh([], [])