Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 59bcacfd6d | |||
| d56282a140 | |||
| 2396810930 | |||
| 564b4a8012 | |||
| a06c9023fc | |||
| 4bcfe2cb2d | |||
| 4f32286a9b | |||
| f765ebd6bb | |||
| 85a73cb8eb | |||
| 64c7fa7d48 | |||
| 380a2ee844 | |||
| 7ba4467217 | |||
| 463b53f8c8 | |||
| 1f908aa8d2 | |||
| d40821dfa6 | |||
| 73a44c6d5c | |||
| 14d9197aea | |||
| fb43a37b2f | |||
| 7ce386f2cf |
@@ -6,7 +6,7 @@
|
||||
"dockerFile": "../Dockerfile",
|
||||
|
||||
// Use 'postCreateCommand' to run commands after the container is created.
|
||||
// "postCreateCommand": "poetry install --no-root",
|
||||
"postCreateCommand": "poetry install --no-root",
|
||||
|
||||
// Configure tool-specific properties.
|
||||
"customizations": {
|
||||
|
||||
@@ -4,8 +4,6 @@ dist/
|
||||
*.egg-info/
|
||||
.cache/
|
||||
*.log
|
||||
.ruff_cache/
|
||||
.venv/
|
||||
.env/
|
||||
.git/
|
||||
Dockerfile copy*
|
||||
@@ -0,0 +1,6 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
@@ -29,12 +29,12 @@ jobs:
|
||||
run: |
|
||||
python main.py generate_schema ${HOME}/${{ env.FUNCTION_SCHEMA_FILE_NAME }}
|
||||
- name: Speckle Automate Function - Build and Publish
|
||||
uses: specklesystems/speckle-automate-github-composite-action@0.7.2
|
||||
uses: specklesystems/speckle-automate-github-composite-action@0.7.4
|
||||
with:
|
||||
speckle_automate_url: ${{ env.SPECKLE_AUTOMATE_URL || 'https://automate.speckle.dev' }}
|
||||
speckle_token: ${{ secrets.SPECKLE_FUNCTION_TOKEN }}
|
||||
speckle_function_id: ${{ secrets.SPECKLE_FUNCTION_ID }}
|
||||
speckle_function_input_schema_file_path: ${{ env.FUNCTION_SCHEMA_FILE_NAME }}
|
||||
speckle_function_command: 'python -u main.py run'
|
||||
speckle_function_recommended_cpu_m: 2000
|
||||
speckle_function_recommended_memory_mi: 100
|
||||
speckle_function_recommended_cpu_m: 4000
|
||||
speckle_function_recommended_memory_mi: 4000
|
||||
|
||||
Regular → Executable
+11
@@ -311,3 +311,14 @@ pyrightconfig.json
|
||||
.ionide
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,python,pycharm
|
||||
Dockerfile copy
|
||||
Dockerfile copy 2
|
||||
.idea/git_toolbox_prj.xml
|
||||
.gitignore
|
||||
.idea/misc.xml
|
||||
.idea/inspectionProfiles/Project_Default.xml
|
||||
.gitignore
|
||||
.idea/vcs.xml
|
||||
.idea/speckle-automate-basic-clash-demo.iml
|
||||
.idea/modules.xml
|
||||
.idea/inspectionProfiles/profiles_settings.xml
|
||||
|
||||
+3
-1
@@ -246,4 +246,6 @@ COPY . /home/speckle
|
||||
|
||||
# Using poetry, we generate a list of requirements, save them to requirements.txt, and then use pip to install them
|
||||
RUN poetry export --format requirements.txt --output /home/speckle/requirements.txt --without-hashes && \
|
||||
pip install --requirement /home/speckle/requirements.txt
|
||||
pip install --requirement /home/speckle/requirements.txt
|
||||
|
||||
RUN poetry install --no-root
|
||||
@@ -0,0 +1,156 @@
|
||||
from concurrent.futures import ProcessPoolExecutor, as_completed
|
||||
from typing import List, Tuple, Any, Optional
|
||||
|
||||
try:
|
||||
import pymesh
|
||||
except ImportError:
|
||||
from Geometry.mocks import mypymesh
|
||||
|
||||
pymesh = mypymesh
|
||||
|
||||
from speckle_automate import AutomationContext
|
||||
|
||||
from Geometry.element import Element
|
||||
from Geometry.mesh import cast
|
||||
|
||||
|
||||
def detect_clashes_old(
|
||||
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.
|
||||
|
||||
Args:
|
||||
reference_elements (List[Element]): Elements from the reference model.
|
||||
latest_elements (List[Element]): Elements from the latest model.
|
||||
_tolerance (float): Tolerance value for clash detection. TODO: how to implement this?
|
||||
|
||||
Returns:
|
||||
List[Tuple[str, str]]: List of tuples indicating clashes, with each tuple
|
||||
containing the IDs of the clashing elements.
|
||||
"""
|
||||
# TODO: Spatial partitioning to reduce number of comparisons
|
||||
# TODO: Tolerance
|
||||
# TODO: parallel processing
|
||||
|
||||
clashes = []
|
||||
for ref_element in reference_elements:
|
||||
for latest_element in latest_elements:
|
||||
for ref_mesh in ref_element.meshes:
|
||||
for latest_mesh in latest_element.meshes:
|
||||
# Convert Trimesh meshes to Pymesh if necessary
|
||||
ref_pymesh: pymesh.Mesh = cast(ref_mesh, pymesh.Mesh)
|
||||
latest_pymesh: pymesh.Mesh = cast(latest_mesh, pymesh.Mesh)
|
||||
|
||||
if not ref_pymesh or not latest_pymesh:
|
||||
continue
|
||||
|
||||
intersection = pymesh.boolean(
|
||||
latest_pymesh, ref_pymesh, operation="intersection"
|
||||
)
|
||||
|
||||
if (
|
||||
intersection and intersection.volume > 0
|
||||
): # TODO: could tolerance relate to this?
|
||||
severity = intersection.volume / min(
|
||||
ref_pymesh.volume, latest_pymesh.volume
|
||||
)
|
||||
clashes.append((ref_element.id, latest_element.id, severity))
|
||||
break
|
||||
|
||||
return clashes
|
||||
|
||||
|
||||
def check_for_clash(
|
||||
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.
|
||||
|
||||
Args:
|
||||
ref_element (Element): An element from the reference model.
|
||||
latest_element (Element): An element from the latest model.
|
||||
|
||||
Returns:
|
||||
Tuple[str, str, float]: A tuple containing the IDs of the clashing elements and the severity, if a clash is found.
|
||||
"""
|
||||
|
||||
for ref_mesh in ref_element.meshes:
|
||||
for latest_mesh in latest_element.meshes:
|
||||
ref_pymesh = cast(ref_mesh, pymesh.Mesh)
|
||||
latest_pymesh = cast(latest_mesh, pymesh.Mesh)
|
||||
|
||||
if not ref_pymesh or not latest_pymesh:
|
||||
continue
|
||||
|
||||
intersection = pymesh.boolean(latest_pymesh, ref_pymesh, operation="intersection")
|
||||
|
||||
if intersection and intersection.volume > 0:
|
||||
severity = intersection.volume / min(
|
||||
ref_pymesh.volume, latest_pymesh.volume
|
||||
)
|
||||
return ref_element.id, latest_element.id, severity
|
||||
return None
|
||||
|
||||
|
||||
def detect_clashes(
|
||||
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.
|
||||
|
||||
Args:
|
||||
reference_elements (List[Element]): Elements from the reference model.
|
||||
latest_elements (List[Element]): Elements from the latest model.
|
||||
_tolerance (float): Tolerance value for clash detection. TODO: how to implement this?
|
||||
|
||||
Returns:
|
||||
List[Tuple[str, str, float]]: A list of tuples indicating clashes.
|
||||
"""
|
||||
clashes = []
|
||||
with ProcessPoolExecutor() as executor:
|
||||
future_clash = {
|
||||
executor.submit(check_for_clash, ref, latest): (ref, latest)
|
||||
for ref in reference_elements
|
||||
for latest in latest_elements
|
||||
}
|
||||
for future in as_completed(future_clash):
|
||||
result = future.result()
|
||||
if result:
|
||||
clashes.append(result)
|
||||
|
||||
return clashes
|
||||
|
||||
|
||||
def detect_and_report_clashes(
|
||||
reference_elements: list[Element],
|
||||
latest_elements: list[Element],
|
||||
tolerance: float,
|
||||
automate_context: AutomationContext,
|
||||
) -> list[tuple[str, str, float]]:
|
||||
print(f"{len(reference_elements[0].meshes)} reference meshes")
|
||||
print(f"{len(latest_elements[0].meshes)} latest meshes")
|
||||
|
||||
clashes = detect_clashes(reference_elements, latest_elements, tolerance)
|
||||
|
||||
total_clashes = len(clashes)
|
||||
padding_length = len(str(total_clashes))
|
||||
|
||||
for i, (ref_id, latest_id, severity) in enumerate(clashes, start=1):
|
||||
clash_number = str(i).zfill(padding_length)
|
||||
combined_message = f"Clash {clash_number}: between {ref_id} and {latest_id} with severity {severity:.2f}"
|
||||
object_ids = [ref_id, latest_id]
|
||||
|
||||
# Assuming severity levels: Low (<0.25), Medium (0.25-0.75), High (>0.75) TODO: Determine severity levels
|
||||
if severity > 0.75:
|
||||
category = "High"
|
||||
elif severity > 0.25:
|
||||
category = "Medium"
|
||||
else:
|
||||
category = "Low"
|
||||
|
||||
automate_context.attach_error_to_objects(
|
||||
category=category, object_ids=object_ids, message=combined_message
|
||||
)
|
||||
|
||||
return clashes
|
||||
@@ -0,0 +1,64 @@
|
||||
from typing import Tuple, Optional, List
|
||||
|
||||
import numpy as np
|
||||
import trimesh
|
||||
from specklepy.objects import Base
|
||||
from specklepy.objects.geometry import Mesh as SpeckleMesh
|
||||
from specklepy.objects.other import Transform
|
||||
|
||||
from Geometry.helpers import combine_transform_matrices
|
||||
from Geometry.mesh import speckle_mesh_to_trimesh
|
||||
|
||||
|
||||
class Element:
|
||||
def __init__(self, id, meshes):
|
||||
"""
|
||||
Initialize an Element object with an ID and a list of meshes.
|
||||
|
||||
Args:
|
||||
id (str): The ID of the Element.
|
||||
meshes (List[Trimesh]): List of trimesh Mesh objects.
|
||||
"""
|
||||
self.id = id
|
||||
self.meshes = meshes
|
||||
|
||||
|
||||
def speckle_to_element(
|
||||
base_id_transforms: Tuple[Base, str, Optional[List[Transform]]]
|
||||
) -> Element:
|
||||
"""
|
||||
Convert a SpecklePy Base object, its identifier, and an optional list of transforms
|
||||
to an Element object.
|
||||
|
||||
Args:
|
||||
base_id_transforms (tuple): Contains a SpecklePy Base object, its identifier,
|
||||
and an optional list of Transform objects.
|
||||
|
||||
Returns:
|
||||
Element: The resulting Element object.
|
||||
"""
|
||||
base, speckle_id, transforms = base_id_transforms
|
||||
|
||||
display_value = base.displayValue
|
||||
if isinstance(display_value, SpeckleMesh):
|
||||
display_value = [display_value]
|
||||
|
||||
element = Element(speckle_id, meshes=[])
|
||||
|
||||
# Combine all transforms into a single matrix
|
||||
combined_transform = (
|
||||
combine_transform_matrices(transforms) if transforms else np.identity(4)
|
||||
)
|
||||
|
||||
if isinstance(display_value, list):
|
||||
for mesh in display_value:
|
||||
if mesh:
|
||||
t_mesh = speckle_mesh_to_trimesh(mesh)
|
||||
if not isinstance(t_mesh, trimesh.Trimesh):
|
||||
continue
|
||||
|
||||
# Apply the combined transformation matrix
|
||||
t_mesh.apply_transform(combined_transform)
|
||||
element.meshes.append(t_mesh)
|
||||
|
||||
return element
|
||||
@@ -0,0 +1,143 @@
|
||||
from typing import List
|
||||
|
||||
import numpy as np
|
||||
from specklepy.objects.geometry import Vector
|
||||
from specklepy.objects.other import Transform as SpeckleTransform
|
||||
|
||||
|
||||
def calculate_polygon_normal(vertices: List[Vector]) -> Vector:
|
||||
"""
|
||||
Calculate the normal vector for a polygon represented by a list of vertices.
|
||||
|
||||
Args:
|
||||
vertices (List[Vector]): A list of vertices representing the polygon.
|
||||
|
||||
Returns:
|
||||
Vector: The normal vector of the polygon.
|
||||
"""
|
||||
normal = Vector.from_list([0.0, 0.0, 0.0])
|
||||
num_vertices = len(vertices)
|
||||
for i in range(num_vertices):
|
||||
curr, nxt = vertices[i], vertices[(i + 1) % num_vertices]
|
||||
# Cross product components are accumulated to find the normal.
|
||||
normal.x += (curr.y - nxt.y) * (curr.z + nxt.z)
|
||||
normal.y += (curr.z - nxt.z) * (curr.x + nxt.x)
|
||||
normal.z += (curr.x - nxt.x) * (curr.y + nxt.y)
|
||||
|
||||
# Normalize the calculated normal vector.
|
||||
length = np.sqrt(normal.x**2 + normal.y**2 + normal.z**2)
|
||||
normal.x, normal.y, normal.z = (
|
||||
normal.x / length,
|
||||
normal.y / length,
|
||||
normal.z / length,
|
||||
)
|
||||
return normal
|
||||
|
||||
|
||||
def is_point_within_triangle(pt: Vector, v1: Vector, v2: Vector, v3: Vector) -> bool:
|
||||
"""
|
||||
Check if a point is inside a given triangle.
|
||||
|
||||
Args:
|
||||
pt (Vector): The point to check.
|
||||
v1, v2, v3 (Vector): The vertices of the triangle.
|
||||
|
||||
Returns:
|
||||
bool: True if the point is inside the triangle, False otherwise.
|
||||
"""
|
||||
|
||||
def sign(p1, p2, p3):
|
||||
return (p1.x - p3.x) * (p2.y - p3.y) - (p2.x - p3.x) * (p1.y - p3.y)
|
||||
|
||||
b1 = sign(pt, v1, v2) < 0.0
|
||||
b2 = sign(pt, v2, v3) < 0.0
|
||||
b3 = sign(pt, v3, v1) < 0.0
|
||||
|
||||
return (b1 == b2) and (b2 == b3)
|
||||
|
||||
|
||||
def triangulate_face(vertices: List[Vector]) -> List[List[int]]:
|
||||
"""
|
||||
Triangulate a polygon defined by a list of vertices.
|
||||
|
||||
Args:
|
||||
vertices (List[Vector]): The vertices of the polygon.
|
||||
|
||||
Returns:
|
||||
List[List[int]]: A list of triangles, each represented as a list of vertex indices.
|
||||
"""
|
||||
triangles = []
|
||||
indices = list(range(len(vertices)))
|
||||
normal = calculate_polygon_normal(vertices)
|
||||
|
||||
# The ear clipping algorithm is used for triangulation.
|
||||
while len(indices) > 2:
|
||||
for i in range(len(indices)):
|
||||
prev, curr, nxt = (
|
||||
indices[i - 1],
|
||||
indices[i],
|
||||
indices[(i + 1) % len(indices)],
|
||||
)
|
||||
if is_convex(vertices[prev], vertices[curr], vertices[nxt], normal):
|
||||
triangles.append([prev, curr, nxt])
|
||||
del indices[i]
|
||||
break
|
||||
|
||||
return triangles
|
||||
|
||||
|
||||
def is_convex(a: Vector, b: Vector, c: Vector, normal: Vector) -> bool:
|
||||
"""
|
||||
Check if a triangle formed by three vertices (a, b, c) is convex with respect to a given normal.
|
||||
|
||||
Args:
|
||||
a (Vector): The first vertex of the triangle.
|
||||
b (Vector): The second vertex of the triangle.
|
||||
c (Vector): The third vertex of the triangle.
|
||||
normal (Vector): The normal vector with respect to which convexity is checked.
|
||||
|
||||
Returns:
|
||||
bool: True if the triangle is convex with respect to the normal, False otherwise.
|
||||
"""
|
||||
ab = Vector.from_list([b.x - a.x, b.y - a.y, b.z - a.z])
|
||||
bc = Vector.from_list([c.x - b.x, c.y - b.y, c.z - b.z])
|
||||
cross = Vector.from_list(
|
||||
[
|
||||
ab.y * bc.z - ab.z * bc.y,
|
||||
ab.z * bc.x - ab.x * bc.z,
|
||||
ab.x * bc.y - ab.y * bc.x,
|
||||
]
|
||||
)
|
||||
|
||||
# Dot product to compare with the face normal
|
||||
return cross.x * normal.x + cross.y * normal.y + cross.z * normal.z > 0
|
||||
|
||||
|
||||
def combine_transform_matrices(transforms: List[SpeckleTransform]) -> np.ndarray:
|
||||
"""
|
||||
Combine multiple transformation matrices into a single matrix.
|
||||
|
||||
Args:
|
||||
transforms (List[SpeckleTransform]): A list of Speckle Transform objects.
|
||||
|
||||
Returns:
|
||||
np.ndarray: A combined 4x4 transformation matrix.
|
||||
"""
|
||||
combined_matrix = np.identity(4)
|
||||
for transform in transforms:
|
||||
matrix = convert_speckle_transform_to_matrix(transform)
|
||||
combined_matrix = np.dot(combined_matrix, matrix)
|
||||
return combined_matrix
|
||||
|
||||
|
||||
def convert_speckle_transform_to_matrix(transform: SpeckleTransform) -> np.ndarray:
|
||||
"""
|
||||
Convert a Speckle Transform object to a 4x4 NumPy matrix.
|
||||
|
||||
Args:
|
||||
transform (SpeckleTransform): The Speckle Transform object.
|
||||
|
||||
Returns:
|
||||
np.ndarray: A 4x4 transformation matrix.
|
||||
"""
|
||||
return np.array(transform.value).reshape(4, 4)
|
||||
+81
-93
@@ -1,107 +1,95 @@
|
||||
from typing import Tuple, Optional
|
||||
from typing import Union, Type
|
||||
|
||||
try:
|
||||
import pymesh
|
||||
except ImportError:
|
||||
from Geometry.mocks import mypymesh
|
||||
|
||||
pymesh = mypymesh
|
||||
|
||||
import trimesh
|
||||
|
||||
from Geometry.helpers import triangulate_face
|
||||
|
||||
|
||||
def trimesh_to_pymesh(mesh: trimesh.Trimesh) -> pymesh.Mesh:
|
||||
"""
|
||||
Convert a Trimesh object to a Pymesh object.
|
||||
Args:
|
||||
mesh (Trimesh): The Trimesh object to convert.
|
||||
Returns:
|
||||
pymesh.Mesh: The resulting Pymesh object.
|
||||
"""
|
||||
return pymesh.form_mesh(mesh.vertices, mesh.faces)
|
||||
|
||||
|
||||
def pymesh_to_trimesh(mesh: pymesh.Mesh) -> trimesh.Trimesh:
|
||||
"""
|
||||
Convert a Pymesh object to a Trimesh object.
|
||||
Args:
|
||||
mesh (pymesh.Mesh): The Pymesh object to convert.
|
||||
Returns:
|
||||
trimesh.Trimesh: The resulting Trimesh object.
|
||||
"""
|
||||
return trimesh.Trimesh(vertices=mesh.vertices, faces=mesh.faces)
|
||||
|
||||
|
||||
def cast(
|
||||
mesh: Union[trimesh.Trimesh, pymesh.Mesh], target_type: Type
|
||||
) -> Union[trimesh.Trimesh, pymesh.Mesh]:
|
||||
"""
|
||||
Casts a mesh object to a specified type.
|
||||
|
||||
Args:
|
||||
mesh (Union[trimesh.Trimesh, pymesh.Mesh]): The mesh object to cast.
|
||||
target_type (Type): The type to cast the mesh to.
|
||||
|
||||
Returns:
|
||||
Union[trimesh.Trimesh, pymesh.Mesh]: The cast mesh object.
|
||||
"""
|
||||
|
||||
if isinstance(mesh, trimesh.Trimesh) and target_type is pymesh.Mesh:
|
||||
return trimesh_to_pymesh(mesh)
|
||||
elif isinstance(mesh, pymesh.Mesh) and target_type is trimesh.Trimesh:
|
||||
return pymesh_to_trimesh(mesh)
|
||||
else:
|
||||
raise TypeError("Unsupported mesh type or target type.")
|
||||
|
||||
|
||||
import numpy as np
|
||||
import trimesh
|
||||
from specklepy.objects import Base
|
||||
from specklepy.objects.geometry import Mesh as SpeckleMesh
|
||||
from specklepy.objects.other import Transform
|
||||
from trimesh import Trimesh
|
||||
from specklepy.objects.geometry import Mesh as SpeckleMesh, Vector
|
||||
|
||||
|
||||
class Element:
|
||||
def __init__(self, id, meshes):
|
||||
"""
|
||||
Initialize an Element object with an ID and a list of meshes.
|
||||
def speckle_mesh_to_trimesh(input_mesh: SpeckleMesh) -> trimesh.Trimesh:
|
||||
vertices = np.array(input_mesh.vertices).reshape((-1, 3))
|
||||
faces = []
|
||||
|
||||
Args:
|
||||
id (str): The ID of the Element.
|
||||
meshes (List[Trimesh]): List of trimesh Mesh objects.
|
||||
"""
|
||||
self.id = id
|
||||
self.meshes = meshes
|
||||
i = 0
|
||||
while i < len(input_mesh.faces):
|
||||
face_vertex_count = input_mesh.faces[i]
|
||||
i += 1 # Skip the vertex count
|
||||
|
||||
face_vertex_indices = input_mesh.faces[i: i + face_vertex_count]
|
||||
|
||||
def speckle_transform_to_trimesh_matrix(transform: Transform) -> np.ndarray:
|
||||
"""
|
||||
Convert the Speckle Transform matrix to a NumPy array format suitable for trimesh.
|
||||
face_vertices = [
|
||||
Vector.from_list(vertices[idx].tolist()) for idx in face_vertex_indices
|
||||
]
|
||||
|
||||
Returns:
|
||||
np.ndarray: 4x4 transformation matrix in NumPy array format.
|
||||
"""
|
||||
return np.array(transform.value).reshape(4, 4)
|
||||
if face_vertex_count == 3:
|
||||
faces.append(face_vertex_indices)
|
||||
else:
|
||||
triangulated = triangulate_face(face_vertices)
|
||||
faces.extend(
|
||||
[[face_vertex_indices[idx] for idx in tri] for tri in triangulated]
|
||||
)
|
||||
|
||||
i += face_vertex_count
|
||||
|
||||
def speckle_to_element(
|
||||
base_with_transforms: Tuple[Base, str, Optional[Transform]]
|
||||
) -> Element:
|
||||
"""
|
||||
Convert a SpecklePy Base object and its associated Transform to an Element object.
|
||||
t_mesh = trimesh.Trimesh(vertices=vertices, faces=np.array(faces))
|
||||
|
||||
Args:
|
||||
base_with_transforms (tuple): Contains a SpecklePy Base object and its
|
||||
associated Transform object.
|
||||
obbox = t_mesh.bounding_box_oriented
|
||||
|
||||
Returns:
|
||||
Element: The resulting Element object.
|
||||
"""
|
||||
obbox_mesh = obbox.to_mesh()
|
||||
|
||||
# Unpack the tuple to get the base, speckle ID, and transform.
|
||||
base, speckle_id, transform = base_with_transforms
|
||||
|
||||
# To convert the Base object to a trimesh Mesh, use the displayValue property.
|
||||
# This property provides the display mesh, expected to be an iterable of
|
||||
# SpecklePy Mesh objects. However, legacy objects might be a single mesh.
|
||||
display_value = base.displayValue
|
||||
if isinstance(display_value, SpeckleMesh):
|
||||
display_value = [display_value]
|
||||
|
||||
if isinstance(display_value, list):
|
||||
# Initialize an Element with an empty list of meshes.
|
||||
element = Element(speckle_id, meshes=[])
|
||||
|
||||
for mesh in display_value:
|
||||
if mesh:
|
||||
# Convert the SpecklePy Mesh to a trimesh Mesh.
|
||||
t_mesh = speckle_to_trimesh(mesh)
|
||||
if not isinstance(t_mesh, Trimesh):
|
||||
continue
|
||||
|
||||
# If there's a transform, apply it to the trimesh Mesh.
|
||||
if transform is not None:
|
||||
trimesh_matrix = speckle_transform_to_trimesh_matrix(transform)
|
||||
t_mesh.apply_transform(trimesh_matrix)
|
||||
|
||||
# Append the trimesh Mesh to the Element's list of meshes.
|
||||
element.meshes.append(t_mesh)
|
||||
|
||||
return element
|
||||
|
||||
|
||||
def speckle_to_trimesh(speckle_mesh: SpeckleMesh) -> Trimesh:
|
||||
"""
|
||||
Convert a SpecklePy Mesh to a trimesh Mesh object.
|
||||
|
||||
Args:
|
||||
speckle_mesh: The SpecklePy Mesh to convert.
|
||||
|
||||
Returns:
|
||||
trimesh.Trimesh: The resulting trimesh Mesh object.
|
||||
"""
|
||||
|
||||
# Convert the list of vertices to a numpy array. Reshape it to
|
||||
# (num_vertices, 3) to fit the trimesh format.
|
||||
vertices_array = np.array(speckle_mesh.vertices).reshape((-1, 3))
|
||||
|
||||
# Faces are expected to be triangular. Reshape the faces list accordingly.
|
||||
|
||||
# Convert the faces list to a numpy array
|
||||
faces_array_raw = np.array(speckle_mesh.faces)
|
||||
|
||||
# Remove the leading 3s by skipping every 4th value
|
||||
faces_cleaned = np.delete(faces_array_raw, np.arange(0, faces_array_raw.size, 4))
|
||||
|
||||
# Reshape the array into (-1, 3) shape
|
||||
faces_array = faces_cleaned.reshape((-1, 3))
|
||||
|
||||
# Return a new trimesh object using the reshaped vertices and faces.
|
||||
return trimesh.Trimesh(vertices=vertices_array, faces=faces_array)
|
||||
return obbox_mesh
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
class mypymesh:
|
||||
class Mesh:
|
||||
def __init__(self, vertices, faces):
|
||||
self.vertices = vertices
|
||||
self.faces = faces
|
||||
|
||||
@property
|
||||
def volume(self):
|
||||
return 0
|
||||
|
||||
@staticmethod
|
||||
def boolean(mesh_a, mesh_b, operation):
|
||||
return mypymesh.Mesh([], [])
|
||||
|
||||
@staticmethod
|
||||
def form_mesh(vertices, faces):
|
||||
return mypymesh.Mesh(vertices, faces)
|
||||
@@ -1,16 +0,0 @@
|
||||
import pymesh
|
||||
|
||||
vertices = [
|
||||
[0, 0, 0],
|
||||
[1, 0, 0],
|
||||
[1, 1, 0],
|
||||
[0, 1, 0]
|
||||
|
||||
]
|
||||
|
||||
faces = [
|
||||
[0, 1, 2],
|
||||
[0, 2, 3]
|
||||
]
|
||||
|
||||
mesh = pymesh.form_mesh(vertices, faces)
|
||||
@@ -28,6 +28,27 @@ This demo showcases the ability to incorporate complex third-party libraries for
|
||||
## Note
|
||||
This function is designed for educational purposes and is not equipped for real-world AEC projects.
|
||||
|
||||
---
|
||||
## Potential Expansions for the Basic Clash Analysis Demo
|
||||
|
||||
This demo serves as a starting point and can be expanded in several ways to enhance its capabilities and usability within Speckle Automate. Below are some ideas for future development:
|
||||
|
||||
### Importing Rule Sets from External Sources
|
||||
- **Dynamic Rule Set Integration:** Enable the function to import clash detection rules from external files or databases, allowing for greater flexibility and customization of clash criteria.
|
||||
- **API-Based Rule Configuration:** Develop an API endpoint where users can update or modify rule sets dynamically, making the function adaptable to varying project requirements.
|
||||
|
||||
### Enhancing User Interaction with External UIs
|
||||
- **Customizable User Interface:** Implement a user-friendly interface that allows users to interact with the function directly, configure settings, and view clash reports more intuitively.
|
||||
- **Integration with AEC Tools:** Design interfaces or plugins for popular AEC software tools, enabling users to access and use the clash detection function directly from their preferred design environment.
|
||||
|
||||
### Advanced Analysis Features
|
||||
- **Complex Geometric Analysis:** Expand the function to perform more sophisticated geometric analyses, potentially using advanced algorithms or machine learning models to identify complex clashes.
|
||||
- **Historical Data Analysis:** Incorporate features to analyze the evolution of clashes over time, providing insights into recurring issues or patterns in the project lifecycle.
|
||||
|
||||
### Collaborative Feedback Loops
|
||||
- **Real-Time Collaboration Tools:** Integrate real-time communication tools within the function, allowing team members to discuss and resolve clashes directly within the Speckle environment.
|
||||
- **Automated Notification System:** Enhance the notification system to provide more detailed alerts, including clash severity levels and suggested resolutions.
|
||||
|
||||
---
|
||||
|
||||
**Reminder:** This repository is a conceptual demonstration for automated clash detection and the use of third-party libraries in Speckle Automate.
|
||||
|
||||
+3
-5
@@ -30,12 +30,12 @@ class ElementCheckRules:
|
||||
"""Rule: Check if a parameter is displayable."""
|
||||
return (
|
||||
lambda parameter: parameter.displayValue
|
||||
and parameter.displayValue is not None
|
||||
and parameter.displayValue is not None
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def speckle_type_rule(
|
||||
desired_type: Union[str, List[str]]
|
||||
desired_type: Union[str, List[str]]
|
||||
) -> Callable[[Base], bool]:
|
||||
"""Rule: Check if a parameter's speckle_type matches the desired type."""
|
||||
|
||||
@@ -43,9 +43,7 @@ class ElementCheckRules:
|
||||
if isinstance(desired_type, str):
|
||||
desired_type = [desired_type]
|
||||
|
||||
print(desired_type)
|
||||
|
||||
return (
|
||||
lambda speckle_object: getattr(speckle_object, "speckle_type", None)
|
||||
in desired_type
|
||||
in desired_type
|
||||
)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"""Helper module for a simple speckle object tree flattening."""
|
||||
from typing import Tuple, Optional
|
||||
from typing import Tuple, Optional, List
|
||||
|
||||
from specklepy.objects import Base
|
||||
from specklepy.objects.other import Instance, Transform
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use the automation_context module to wrap your function in an Automate context helper
|
||||
"""
|
||||
from typing import List, Optional, Tuple
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import Field
|
||||
from speckle_automate import (
|
||||
@@ -16,11 +16,11 @@ from specklepy.objects import Base
|
||||
from specklepy.objects.other import Transform
|
||||
from specklepy.objects.units import Units
|
||||
from specklepy.transports.server import ServerTransport
|
||||
from trimesh import Trimesh
|
||||
|
||||
from Geometry.mesh import speckle_to_element, Element
|
||||
from Geometry.clash import detect_and_report_clashes
|
||||
from Geometry.element import speckle_to_element
|
||||
from Rules.checks import ElementCheckRules
|
||||
from flatten import extract_base_and_transform
|
||||
from Utilities.flatten import extract_base_and_transform
|
||||
|
||||
|
||||
class FunctionInputs(AutomateBase):
|
||||
@@ -31,28 +31,31 @@ class FunctionInputs(AutomateBase):
|
||||
https://docs.pydantic.dev/latest/usage/models/
|
||||
"""
|
||||
|
||||
tolerance: float = Field(
|
||||
default=25.0,
|
||||
title="Tolerance",
|
||||
description="Specify the tolerance value for the analysis. \
|
||||
Negative values relaxes the test, positive values make it more strict.",
|
||||
)
|
||||
tolerance_unit: str = Field( # Using the SpecklePy Units enum here
|
||||
default=Units.mm,
|
||||
json_schema_extra={"examples": ["mm", "cm", "m"]},
|
||||
title="Tolerance Unit",
|
||||
description="Unit of the tolerance value.",
|
||||
)
|
||||
static_model_name: str = Field(
|
||||
...,
|
||||
title="Static Model Name",
|
||||
description="Name of the static structural model.",
|
||||
)
|
||||
tolerance: float = Field(
|
||||
default=25.0,
|
||||
title="Tolerance",
|
||||
description="Specify the tolerance value for the analysis. \
|
||||
Negative values relaxes the test, positive values make it more strict.",
|
||||
json_schema_extra={
|
||||
"readOnly": True,
|
||||
}
|
||||
)
|
||||
tolerance_unit: str = Field( # Using the SpecklePy Units enum here
|
||||
default=Units.mm,
|
||||
json_schema_extra={"examples": ["mm", "cm", "m"], "readOnly": True},
|
||||
title="Tolerance Unit",
|
||||
description="Unit of the tolerance value.",
|
||||
)
|
||||
|
||||
|
||||
def automate_function(
|
||||
automate_context: AutomationContext,
|
||||
function_inputs: FunctionInputs,
|
||||
automate_context: AutomationContext,
|
||||
function_inputs: FunctionInputs,
|
||||
) -> None:
|
||||
"""This is an example Speckle Automate function.
|
||||
|
||||
@@ -67,9 +70,10 @@ def automate_function(
|
||||
changed_model_version = automate_context.receive_version()
|
||||
|
||||
try:
|
||||
reference_model_version = get_reference_model(
|
||||
reference_model_version, reference_model_id, reference_model_version_id = get_reference_model(
|
||||
automate_context, function_inputs.static_model_name
|
||||
)
|
||||
print(f"Reference model id: {reference_model_id}, version id: {reference_model_version_id}")
|
||||
|
||||
except Exception as ex:
|
||||
automate_context.mark_run_failed(status_message=str(ex))
|
||||
@@ -112,6 +116,7 @@ def automate_function(
|
||||
for base_obj, id, transform in reference_objects
|
||||
if visible_beams_rule(base_obj)
|
||||
]
|
||||
|
||||
latest_displayable_objects = [
|
||||
(base_obj, id, transform)
|
||||
for base_obj, id, transform in latest_objects
|
||||
@@ -125,84 +130,53 @@ def automate_function(
|
||||
speckle_to_element(obj) for obj in latest_displayable_objects
|
||||
]
|
||||
|
||||
# using trimesh library process all these meshes in the form of A vs B
|
||||
# and get the clashes
|
||||
tolerance = function_inputs.tolerance
|
||||
|
||||
clashes = detect_clashes(
|
||||
reference_mesh_elements, latest_mesh_elements, function_inputs.tolerance
|
||||
clashes = detect_and_report_clashes(
|
||||
reference_mesh_elements, latest_mesh_elements, tolerance, automate_context
|
||||
)
|
||||
|
||||
print(len(clashes))
|
||||
percentage_reference_objects_clashing = (
|
||||
len(set([ref_id for ref_id, latest_id, severity in clashes]))
|
||||
/ len(reference_mesh_elements)
|
||||
* 100
|
||||
)
|
||||
percentage_latest_objects_clashing = (
|
||||
len(set([latest_id for ref_id, latest_id, severity in clashes]))
|
||||
/ len(latest_mesh_elements)
|
||||
* 100
|
||||
)
|
||||
|
||||
automate_context.mark_run_success(status_message="Clash detection completed.")
|
||||
# all clashes count
|
||||
all_objects_count = len(reference_mesh_elements) + len(latest_mesh_elements)
|
||||
all_clashes_count = len(clashes)
|
||||
|
||||
print(f"Clash detection report: {all_clashes_count} clashes found between {all_objects_count} objects.")
|
||||
|
||||
print(f"Reference objects: {len([x for x in reference_objects])}.")
|
||||
print(f"Latest objects: {len([x for x in latest_objects])}.")
|
||||
|
||||
def detect_clashes(
|
||||
elements_a: List[Element], elements_b: List[Element], length_tolerance: float
|
||||
) -> List[Tuple[Element, Element]]:
|
||||
"""
|
||||
Detects clashes between two sets of elements with a specified tolerance.
|
||||
clash_report_message = (
|
||||
f"Clash detection report: {all_clashes_count} clashes found "
|
||||
f"between {all_objects_count} objects. "
|
||||
f"Percentage of reference objects clashing: "
|
||||
f"{percentage_reference_objects_clashing}%. "
|
||||
f"Percentage of latest objects clashing: "
|
||||
f"{percentage_latest_objects_clashing}%."
|
||||
)
|
||||
|
||||
This function checks each combination of elements from `elements_a` and `elements_b`
|
||||
to see if any of their respective meshes intersect within the specified tolerance.
|
||||
If a clash is detected between any mesh from an element in `elements_a` and any mesh
|
||||
from an element in `elements_b`, the pair of elements is added to the results.
|
||||
reference_view = [f"{reference_model_id}@{reference_model_version_id}"]
|
||||
|
||||
Args:
|
||||
- elements_a (List[Element]): A list of `Element` objects to be checked for clashes.
|
||||
- elements_b (List[Element]): A second list of `Element` objects to be checked for clashes against `elements_a`.
|
||||
- length_tolerance (float): The distance to offset mesh vertices for intersection check.
|
||||
automate_context.set_context_view(reference_view)
|
||||
|
||||
Returns:
|
||||
- List[Tuple[Element, Element]]: A list of tuples where each tuple contains a pair of `Element` objects that clash.
|
||||
"""
|
||||
|
||||
# Use list comprehension to get pairs of elements that have clashing meshes
|
||||
clashes = [
|
||||
(element_a, element_b)
|
||||
for element_a in elements_a
|
||||
for element_b in elements_b
|
||||
if any(
|
||||
check_intersection_with_tolerance(mesh_a, mesh_b, length_tolerance)
|
||||
for mesh_a in element_a.meshes
|
||||
for mesh_b in element_b.meshes
|
||||
)
|
||||
]
|
||||
|
||||
return clashes
|
||||
|
||||
|
||||
def check_intersection_with_tolerance(
|
||||
mesh_a: Trimesh, mesh_b: Trimesh, tolerance: float
|
||||
) -> bool:
|
||||
"""
|
||||
Checks for intersections between two meshes within a specified tolerance.
|
||||
|
||||
Args:
|
||||
- mesh_a: The first mesh to check.
|
||||
- mesh_b: The second mesh to check.
|
||||
- tolerance (float): The distance to offset mesh vertices for intersection check.
|
||||
Positive values expand the mesh, negative values contract it.
|
||||
|
||||
Returns:
|
||||
- bool: True if the meshes intersect within the specified tolerance, otherwise False.
|
||||
"""
|
||||
half_tolerance = tolerance / 2.0 # TODO: how to shrink bloat mesh?
|
||||
offset_mesh_a: Trimesh = mesh_a # mesh_a.offset_mesh(half_tolerance)
|
||||
offset_mesh_b: Trimesh = mesh_b # mesh_b.offset_mesh(half_tolerance)
|
||||
|
||||
# return offset_mesh_a.intersection(offset_mesh_b).volume > 0 TODO: Install Blender as the engine
|
||||
|
||||
# return a random boolean for testing - significantly favouring false
|
||||
import random
|
||||
|
||||
return random.random() < 0.05
|
||||
automate_context.mark_run_success(
|
||||
status_message="Clash detection completed. " + clash_report_message
|
||||
)
|
||||
|
||||
|
||||
def get_reference_model(
|
||||
automate_context: AutomationContext, static_model_name: str
|
||||
) -> Base:
|
||||
automate_context: AutomationContext, static_model_name: str
|
||||
) -> tuple[Base, Optional[str], Optional[str]]:
|
||||
# the static reference model will be retrieved from the project using model name stored in the inputs
|
||||
speckle_client = automate_context.speckle_client
|
||||
project_id = automate_context.automation_run_data.project_id
|
||||
@@ -236,7 +210,7 @@ def get_reference_model(
|
||||
remote_transport,
|
||||
) # receive the static model
|
||||
|
||||
return latest_reference_model_version
|
||||
return latest_reference_model_version, model.id, reference_model_commits[0].id
|
||||
|
||||
|
||||
# make sure to call the function with the executor
|
||||
|
||||
Generated
+80
-1
@@ -540,6 +540,51 @@ files = [
|
||||
{file = "mypy_extensions-1.0.0.tar.gz", hash = "sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "numpy"
|
||||
version = "1.26.2"
|
||||
description = "Fundamental package for array computing in Python"
|
||||
optional = false
|
||||
python-versions = ">=3.9"
|
||||
files = [
|
||||
{file = "numpy-1.26.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:3703fc9258a4a122d17043e57b35e5ef1c5a5837c3db8be396c82e04c1cf9b0f"},
|
||||
{file = "numpy-1.26.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:cc392fdcbd21d4be6ae1bb4475a03ce3b025cd49a9be5345d76d7585aea69440"},
|
||||
{file = "numpy-1.26.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:36340109af8da8805d8851ef1d74761b3b88e81a9bd80b290bbfed61bd2b4f75"},
|
||||
{file = "numpy-1.26.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bcc008217145b3d77abd3e4d5ef586e3bdfba8fe17940769f8aa09b99e856c00"},
|
||||
{file = "numpy-1.26.2-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:3ced40d4e9e18242f70dd02d739e44698df3dcb010d31f495ff00a31ef6014fe"},
|
||||
{file = "numpy-1.26.2-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:b272d4cecc32c9e19911891446b72e986157e6a1809b7b56518b4f3755267523"},
|
||||
{file = "numpy-1.26.2-cp310-cp310-win32.whl", hash = "sha256:22f8fc02fdbc829e7a8c578dd8d2e15a9074b630d4da29cda483337e300e3ee9"},
|
||||
{file = "numpy-1.26.2-cp310-cp310-win_amd64.whl", hash = "sha256:26c9d33f8e8b846d5a65dd068c14e04018d05533b348d9eaeef6c1bd787f9919"},
|
||||
{file = "numpy-1.26.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:b96e7b9c624ef3ae2ae0e04fa9b460f6b9f17ad8b4bec6d7756510f1f6c0c841"},
|
||||
{file = "numpy-1.26.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:aa18428111fb9a591d7a9cc1b48150097ba6a7e8299fb56bdf574df650e7d1f1"},
|
||||
{file = "numpy-1.26.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:06fa1ed84aa60ea6ef9f91ba57b5ed963c3729534e6e54055fc151fad0423f0a"},
|
||||
{file = "numpy-1.26.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:96ca5482c3dbdd051bcd1fce8034603d6ebfc125a7bd59f55b40d8f5d246832b"},
|
||||
{file = "numpy-1.26.2-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:854ab91a2906ef29dc3925a064fcd365c7b4da743f84b123002f6139bcb3f8a7"},
|
||||
{file = "numpy-1.26.2-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:f43740ab089277d403aa07567be138fc2a89d4d9892d113b76153e0e412409f8"},
|
||||
{file = "numpy-1.26.2-cp311-cp311-win32.whl", hash = "sha256:a2bbc29fcb1771cd7b7425f98b05307776a6baf43035d3b80c4b0f29e9545186"},
|
||||
{file = "numpy-1.26.2-cp311-cp311-win_amd64.whl", hash = "sha256:2b3fca8a5b00184828d12b073af4d0fc5fdd94b1632c2477526f6bd7842d700d"},
|
||||
{file = "numpy-1.26.2-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:a4cd6ed4a339c21f1d1b0fdf13426cb3b284555c27ac2f156dfdaaa7e16bfab0"},
|
||||
{file = "numpy-1.26.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:5d5244aabd6ed7f312268b9247be47343a654ebea52a60f002dc70c769048e75"},
|
||||
{file = "numpy-1.26.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6a3cdb4d9c70e6b8c0814239ead47da00934666f668426fc6e94cce869e13fd7"},
|
||||
{file = "numpy-1.26.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:aa317b2325f7aa0a9471663e6093c210cb2ae9c0ad824732b307d2c51983d5b6"},
|
||||
{file = "numpy-1.26.2-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:174a8880739c16c925799c018f3f55b8130c1f7c8e75ab0a6fa9d41cab092fd6"},
|
||||
{file = "numpy-1.26.2-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:f79b231bf5c16b1f39c7f4875e1ded36abee1591e98742b05d8a0fb55d8a3eec"},
|
||||
{file = "numpy-1.26.2-cp312-cp312-win32.whl", hash = "sha256:4a06263321dfd3598cacb252f51e521a8cb4b6df471bb12a7ee5cbab20ea9167"},
|
||||
{file = "numpy-1.26.2-cp312-cp312-win_amd64.whl", hash = "sha256:b04f5dc6b3efdaab541f7857351aac359e6ae3c126e2edb376929bd3b7f92d7e"},
|
||||
{file = "numpy-1.26.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:4eb8df4bf8d3d90d091e0146f6c28492b0be84da3e409ebef54349f71ed271ef"},
|
||||
{file = "numpy-1.26.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:1a13860fdcd95de7cf58bd6f8bc5a5ef81c0b0625eb2c9a783948847abbef2c2"},
|
||||
{file = "numpy-1.26.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:64308ebc366a8ed63fd0bf426b6a9468060962f1a4339ab1074c228fa6ade8e3"},
|
||||
{file = "numpy-1.26.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:baf8aab04a2c0e859da118f0b38617e5ee65d75b83795055fb66c0d5e9e9b818"},
|
||||
{file = "numpy-1.26.2-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:d73a3abcac238250091b11caef9ad12413dab01669511779bc9b29261dd50210"},
|
||||
{file = "numpy-1.26.2-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:b361d369fc7e5e1714cf827b731ca32bff8d411212fccd29ad98ad622449cc36"},
|
||||
{file = "numpy-1.26.2-cp39-cp39-win32.whl", hash = "sha256:bd3f0091e845164a20bd5a326860c840fe2af79fa12e0469a12768a3ec578d80"},
|
||||
{file = "numpy-1.26.2-cp39-cp39-win_amd64.whl", hash = "sha256:2beef57fb031dcc0dc8fa4fe297a742027b954949cabb52a2a376c144e5e6060"},
|
||||
{file = "numpy-1.26.2-pp39-pypy39_pp73-macosx_10_9_x86_64.whl", hash = "sha256:1cc3d5029a30fb5f06704ad6b23b35e11309491c999838c31f124fee32107c79"},
|
||||
{file = "numpy-1.26.2-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:94cc3c222bb9fb5a12e334d0479b97bb2df446fbe622b470928f5284ffca3f8d"},
|
||||
{file = "numpy-1.26.2-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:fe6b44fb8fcdf7eda4ef4461b97b3f63c466b27ab151bec2366db8b197387841"},
|
||||
{file = "numpy-1.26.2.tar.gz", hash = "sha256:f65738447676ab5777f11e6bbbdb8ce11b785e105f690bc45966574816b6d3ea"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "packaging"
|
||||
version = "23.2"
|
||||
@@ -751,6 +796,20 @@ tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""}
|
||||
[package.extras]
|
||||
testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"]
|
||||
|
||||
[[package]]
|
||||
name = "python-dotenv"
|
||||
version = "1.0.0"
|
||||
description = "Read key-value pairs from a .env file and set them as environment variables"
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
files = [
|
||||
{file = "python-dotenv-1.0.0.tar.gz", hash = "sha256:a8df96034aae6d2d50a4ebe8216326c61c3eb64836776504fcca410e5937a3ba"},
|
||||
{file = "python_dotenv-1.0.0-py3-none-any.whl", hash = "sha256:f5971a9226b701070a4bf2c38c89e5a3f0d64de8debda981d1db98583009122a"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
cli = ["click (>=5.0)"]
|
||||
|
||||
[[package]]
|
||||
name = "requests"
|
||||
version = "2.31.0"
|
||||
@@ -865,6 +924,26 @@ files = [
|
||||
{file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "trimesh"
|
||||
version = "4.0.4"
|
||||
description = "Import, export, process, analyze and view triangular meshes."
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "trimesh-4.0.4-py3-none-any.whl", hash = "sha256:a7149aac5609df7e1da3bf6f40c1ced5b44c2084eec3b14ef982c926045ba7e9"},
|
||||
{file = "trimesh-4.0.4.tar.gz", hash = "sha256:dd7a67706e8848a414fa1a89a6f724f36b3405882f6293469f7cdc756901e4fb"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
numpy = "*"
|
||||
|
||||
[package.extras]
|
||||
all = ["trimesh[easy,recommend,test]"]
|
||||
easy = ["chardet", "colorlog", "embreex", "jsonschema", "lxml", "mapbox-earcut", "networkx", "pillow", "pycollada", "requests", "rtree", "scipy", "setuptools", "shapely", "svg.path", "xxhash"]
|
||||
recommend = ["glooey", "manifold3d", "meshio", "psutil", "pyglet (<2)", "python-fcl", "scikit-image", "sympy", "vhacdx", "xatlas"]
|
||||
test = ["black", "coveralls", "ezdxf", "matplotlib", "mypy", "pyinstrument", "pymeshlab", "pytest", "pytest-cov", "ruff"]
|
||||
|
||||
[[package]]
|
||||
name = "typing-extensions"
|
||||
version = "4.8.0"
|
||||
@@ -1209,4 +1288,4 @@ multidict = ">=4.0"
|
||||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = "^3.10"
|
||||
content-hash = "4fdcfbc4093906ea3530e143e5a06e9f323fda77d7685503cd2e545528063c2a"
|
||||
content-hash = "e4e56818583a9f0fad2adbfbc4dcb2ebaa1fc8f917004477f0e1574237b7850a"
|
||||
|
||||
+8
-6
@@ -8,12 +8,14 @@ readme = "README.md"
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.10"
|
||||
specklepy = "2.17.11"
|
||||
trimesh = "^4.0.4"
|
||||
pytest = "^7.4.2"
|
||||
python-dotenv = "^1.0.0"
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
black = "^23.3.0"
|
||||
mypy = "^1.3.0"
|
||||
ruff = "^0.0.271"
|
||||
pytest = "^7.4.2"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
@@ -21,11 +23,11 @@ build-backend = "poetry.core.masonry.api"
|
||||
|
||||
[tool.ruff]
|
||||
select = [
|
||||
"E", # pycodestyle
|
||||
"F", # pyflakes
|
||||
"UP", # pyupgrade
|
||||
"D", # pydocstyle
|
||||
"I", # isort
|
||||
"E", # pycodestyle
|
||||
"F", # pyflakes
|
||||
"UP", # pyupgrade
|
||||
"D", # pydocstyle
|
||||
"I", # isort
|
||||
]
|
||||
|
||||
[tool.ruff.pydocstyle]
|
||||
|
||||
@@ -206,6 +206,32 @@ multidict==6.0.4 ; python_version >= "3.10" and python_version < "4.0" \
|
||||
--hash=sha256:f70b98cd94886b49d91170ef23ec5c0e8ebb6f242d734ed7ed677b24d50c82cf \
|
||||
--hash=sha256:fc35cb4676846ef752816d5be2193a1e8367b4c1397b74a565a9d0389c433a1d \
|
||||
--hash=sha256:ff959bee35038c4624250473988b24f846cbeb2c6639de3602c073f10410ceba
|
||||
numpy==1.25.2 ; python_version >= "3.10" and python_version < "4.0" \
|
||||
--hash=sha256:0d60fbae8e0019865fc4784745814cff1c421df5afee233db6d88ab4f14655a2 \
|
||||
--hash=sha256:1a1329e26f46230bf77b02cc19e900db9b52f398d6722ca853349a782d4cff55 \
|
||||
--hash=sha256:1b9735c27cea5d995496f46a8b1cd7b408b3f34b6d50459d9ac8fe3a20cc17bf \
|
||||
--hash=sha256:2792d23d62ec51e50ce4d4b7d73de8f67a2fd3ea710dcbc8563a51a03fb07b01 \
|
||||
--hash=sha256:3e0746410e73384e70d286f93abf2520035250aad8c5714240b0492a7302fdca \
|
||||
--hash=sha256:4c3abc71e8b6edba80a01a52e66d83c5d14433cbcd26a40c329ec7ed09f37901 \
|
||||
--hash=sha256:5883c06bb92f2e6c8181df7b39971a5fb436288db58b5a1c3967702d4278691d \
|
||||
--hash=sha256:5c97325a0ba6f9d041feb9390924614b60b99209a71a69c876f71052521d42a4 \
|
||||
--hash=sha256:60e7f0f7f6d0eee8364b9a6304c2845b9c491ac706048c7e8cf47b83123b8dbf \
|
||||
--hash=sha256:76b4115d42a7dfc5d485d358728cdd8719be33cc5ec6ec08632a5d6fca2ed380 \
|
||||
--hash=sha256:7dc869c0c75988e1c693d0e2d5b26034644399dd929bc049db55395b1379e044 \
|
||||
--hash=sha256:834b386f2b8210dca38c71a6e0f4fd6922f7d3fcff935dbe3a570945acb1b545 \
|
||||
--hash=sha256:8b77775f4b7df768967a7c8b3567e309f617dd5e99aeb886fa14dc1a0791141f \
|
||||
--hash=sha256:90319e4f002795ccfc9050110bbbaa16c944b1c37c0baeea43c5fb881693ae1f \
|
||||
--hash=sha256:b79e513d7aac42ae918db3ad1341a015488530d0bb2a6abcbdd10a3a829ccfd3 \
|
||||
--hash=sha256:bb33d5a1cf360304754913a350edda36d5b8c5331a8237268c48f91253c3a364 \
|
||||
--hash=sha256:bec1e7213c7cb00d67093247f8c4db156fd03075f49876957dca4711306d39c9 \
|
||||
--hash=sha256:c5462d19336db4560041517dbb7759c21d181a67cb01b36ca109b2ae37d32418 \
|
||||
--hash=sha256:c5652ea24d33585ea39eb6a6a15dac87a1206a692719ff45d53c5282e66d4a8f \
|
||||
--hash=sha256:d7806500e4f5bdd04095e849265e55de20d8cc4b661b038957354327f6d9b295 \
|
||||
--hash=sha256:db3ccc4e37a6873045580d413fe79b68e47a681af8db2e046f1dacfa11f86eb3 \
|
||||
--hash=sha256:dfe4a913e29b418d096e696ddd422d8a5d13ffba4ea91f9f60440a3b759b0187 \
|
||||
--hash=sha256:eb942bfb6f84df5ce05dbf4b46673ffed0d3da59f13635ea9b926af3deb76926 \
|
||||
--hash=sha256:f08f2e037bba04e707eebf4bc934f1972a315c883a9e0ebfa8a7756eabf9e357 \
|
||||
--hash=sha256:fd608e19c8d7c55021dffd43bfe5492fab8cc105cc8986f813f8c3c048b38760
|
||||
pydantic-core==2.10.1 ; python_version >= "3.10" and python_version < "4.0" \
|
||||
--hash=sha256:042462d8d6ba707fd3ce9649e7bf268633a41018d6a998fb5fbacb7e928a183e \
|
||||
--hash=sha256:0523aeb76e03f753b58be33b26540880bac5aa54422e4462404c432230543f33 \
|
||||
@@ -330,6 +356,9 @@ specklepy==2.17.11 ; python_version >= "3.10" and python_version < "4.0" \
|
||||
--hash=sha256:e915ec4c3862a517f417f0b764e252a6582e7ace3696938a8e5043891308a5ab
|
||||
stringcase==1.2.0 ; python_version >= "3.10" and python_version < "4.0" \
|
||||
--hash=sha256:48a06980661908efe8d9d34eab2b6c13aefa2163b3ced26972902e3bdfd87008
|
||||
trimesh==4.0.4 ; python_version >= "3.10" and python_version < "4.0" \
|
||||
--hash=sha256:a7149aac5609df7e1da3bf6f40c1ced5b44c2084eec3b14ef982c926045ba7e9 \
|
||||
--hash=sha256:dd7a67706e8848a414fa1a89a6f724f36b3405882f6293469f7cdc756901e4fb
|
||||
typing-extensions==4.8.0 ; python_version >= "3.10" and python_version < "4.0" \
|
||||
--hash=sha256:8f92fc8806f9a6b641eaa5318da32b44d401efaac0f6678c9bc448ba3605faa0 \
|
||||
--hash=sha256:df8e4339e9cb77357558cbdbceca33c303714cf861d1eef15e1070055ae8b7ef
|
||||
@@ -614,3 +643,51 @@ yarl==1.9.2 ; python_version >= "3.10" and python_version < "4.0" \
|
||||
--hash=sha256:f3b078dbe227f79be488ffcfc7a9edb3409d018e0952cf13f15fd6512847f3f7 \
|
||||
--hash=sha256:f4e2d08f07a3d7d3e12549052eb5ad3eab1c349c53ac51c209a0e5991bbada78 \
|
||||
--hash=sha256:f7a3d8146575e08c29ed1cd287068e6d02f1c7bdff8970db96683b9591b86ee7
|
||||
|
||||
yarl~=1.9.2
|
||||
gql~=3.4.1
|
||||
backoff~=2.2.1
|
||||
multidict~=6.0.4
|
||||
requests~=2.31.0
|
||||
websockets~=10.4
|
||||
pytest~=7.4.2
|
||||
h11~=0.14.0
|
||||
pip~=23.3.1
|
||||
attrs~=23.1.0
|
||||
wheel~=0.40.0
|
||||
mypy~=1.6.1
|
||||
idna~=3.4
|
||||
sniffio~=1.3.0
|
||||
black~=23.10.0
|
||||
platformdirs~=3.11.0
|
||||
packaging~=23.2
|
||||
pathspec~=0.11.2
|
||||
click~=8.1.5
|
||||
httpcore~=1.0.2
|
||||
certifi~=2023.7.22
|
||||
setuptools~=65.5.0
|
||||
numpy~=1.25.2
|
||||
pluggy~=1.3.0
|
||||
Deprecated~=1.2.14
|
||||
iniconfig~=2.0.0
|
||||
trimesh~=4.0.4
|
||||
anyio~=4.0.0
|
||||
pydantic~=2.4.2
|
||||
urllib3~=1.26.18
|
||||
specklepy~=2.17.11
|
||||
stringcase~=1.2.0
|
||||
ujson~=5.8.0
|
||||
wrapt~=1.16.0
|
||||
httpx~=0.25.1
|
||||
Pillow~=10.1.0
|
||||
docutils~=0.20.1
|
||||
sphinx~=7.0.1
|
||||
Jinja2~=3.1.2
|
||||
filelock~=3.12.2
|
||||
Pygments~=2.15.1
|
||||
pytz~=2023.3.post1
|
||||
networkx~=3.1
|
||||
scipy~=1.11.1
|
||||
psutil~=5.9.5
|
||||
python-dotenv~=1.0.0
|
||||
pymesh~=1.0.2
|
||||
+15
-15
@@ -23,12 +23,12 @@ def crypto_random_string(length: int) -> str:
|
||||
|
||||
|
||||
def register_new_automation(
|
||||
project_id: str,
|
||||
model_id: str,
|
||||
speckle_client: SpeckleClient,
|
||||
automation_id: str,
|
||||
automation_name: str,
|
||||
automation_revision_id: str,
|
||||
project_id: str,
|
||||
model_id: str,
|
||||
speckle_client: SpeckleClient,
|
||||
automation_id: str,
|
||||
automation_name: str,
|
||||
automation_revision_id: str,
|
||||
):
|
||||
"""Register a new automation in the speckle server."""
|
||||
query = gql(
|
||||
@@ -103,7 +103,7 @@ def fake_automation_run_data(request, test_client: SpeckleClient) -> AutomationR
|
||||
function_name = "Clash Test"
|
||||
|
||||
automation_id = crypto_random_string(10)
|
||||
automation_name = "Local Test Automation"
|
||||
automation_name = "Long running clash test"
|
||||
automation_revision_id = crypto_random_string(10)
|
||||
|
||||
register_new_automation(
|
||||
@@ -119,7 +119,7 @@ def fake_automation_run_data(request, test_client: SpeckleClient) -> AutomationR
|
||||
project_id=project_id,
|
||||
model_id=model_id,
|
||||
branch_name="main",
|
||||
version_id="2b16327448",
|
||||
version_id="861bbab860",
|
||||
speckle_server_url=server_url,
|
||||
# These ids would be available with a valid registered Automation definition.
|
||||
automation_id=automation_id,
|
||||
@@ -142,7 +142,7 @@ def test_function_run(fake_automation_run_data: AutomationRunData, speckle_token
|
||||
context,
|
||||
automate_function,
|
||||
FunctionInputs(
|
||||
tolerance=0.1, tolerance_unit="mm", static_model_name="structural"
|
||||
tolerance=0.1, tolerance_unit="mm", static_model_name="structures from revit"
|
||||
),
|
||||
)
|
||||
|
||||
@@ -156,26 +156,26 @@ def context(fake_automation_run_data: AutomationRunData, speckle_token: str):
|
||||
|
||||
def test_non_existent_model(context, test_client: SpeckleClient):
|
||||
with pytest.raises(
|
||||
Exception, match="The static model named does not exist, skipping the function."
|
||||
Exception, match="The static model named does not exist, skipping the function."
|
||||
):
|
||||
get_reference_model(context, "Fake Name")
|
||||
|
||||
|
||||
def test_model_with_no_versions(context, test_client: SpeckleClient):
|
||||
with pytest.raises(
|
||||
Exception, match="The static model has no versions, skipping the function."
|
||||
Exception, match="The static model has no versions, skipping the function."
|
||||
):
|
||||
get_reference_model(context, "blank")
|
||||
|
||||
|
||||
def test_same_as_changed_model(context, test_client: SpeckleClient):
|
||||
with pytest.raises(
|
||||
Exception,
|
||||
match="The static model is the same as the changed model, skipping the function.",
|
||||
Exception,
|
||||
match="The static model is the same as the changed model, skipping the function.",
|
||||
):
|
||||
get_reference_model(context, "hvac")
|
||||
get_reference_model(context, "clash simple")
|
||||
|
||||
|
||||
def test_valid_reference_model(context, test_client: SpeckleClient):
|
||||
reference_model = get_reference_model(context, "structural")
|
||||
reference_model = get_reference_model(context, "simple beams")
|
||||
assert reference_model is not None
|
||||
|
||||
Reference in New Issue
Block a user