Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5ad615eb5b | |||
| 59bcacfd6d | |||
| d56282a140 | |||
| 2396810930 | |||
| 564b4a8012 | |||
| a06c9023fc |
@@ -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*
|
||||
@@ -36,5 +36,5 @@ jobs:
|
||||
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: 8000
|
||||
speckle_function_recommended_memory_mi: 8000
|
||||
|
||||
Regular → Executable
+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
|
||||
+7
-4
@@ -46,7 +46,7 @@ def detect_clashes_old(
|
||||
continue
|
||||
|
||||
intersection = pymesh.boolean(
|
||||
latest_pymesh, operation="intersection"
|
||||
latest_pymesh, ref_pymesh, operation="intersection"
|
||||
)
|
||||
|
||||
if (
|
||||
@@ -74,6 +74,7 @@ def check_for_clash(
|
||||
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)
|
||||
@@ -82,9 +83,8 @@ 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, ref_pymesh, operation="intersection")
|
||||
|
||||
if intersection and intersection.volume > 0:
|
||||
severity = intersection.volume / min(
|
||||
ref_pymesh.volume, latest_pymesh.volume
|
||||
@@ -128,6 +128,9 @@ def detect_and_report_clashes(
|
||||
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)
|
||||
|
||||
+7
-10
@@ -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.
|
||||
@@ -95,4 +86,10 @@ def speckle_mesh_to_trimesh(input_mesh: SpeckleMesh) -> trimesh.Trimesh:
|
||||
|
||||
i += face_vertex_count
|
||||
|
||||
return trimesh.Trimesh(vertices=vertices, faces=np.array(faces))
|
||||
t_mesh = trimesh.Trimesh(vertices=vertices, faces=np.array(faces))
|
||||
|
||||
obbox = t_mesh.bounding_box_oriented
|
||||
|
||||
obbox_mesh = obbox.to_mesh()
|
||||
|
||||
return obbox_mesh
|
||||
|
||||
+13
-8
@@ -1,12 +1,17 @@
|
||||
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([], [])
|
||||
def boolean(mesh_a, mesh_b, operation):
|
||||
return mypymesh.Mesh([], [])
|
||||
|
||||
@property
|
||||
def volume(self):
|
||||
return 0
|
||||
@staticmethod
|
||||
def form_mesh(vertices, faces):
|
||||
return mypymesh.Mesh(vertices, faces)
|
||||
|
||||
+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
|
||||
)
|
||||
|
||||
@@ -36,27 +36,26 @@ class FunctionInputs(AutomateBase):
|
||||
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.",
|
||||
readonly=True,
|
||||
)
|
||||
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.",
|
||||
readonly=True,
|
||||
)
|
||||
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.
|
||||
|
||||
@@ -71,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))
|
||||
@@ -116,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
|
||||
@@ -129,32 +130,32 @@ 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_and_report_clashes(
|
||||
reference_mesh_elements, latest_mesh_elements, tolerance, automate_context
|
||||
)
|
||||
|
||||
# all object count
|
||||
# all reference objects count
|
||||
# all latest objects count
|
||||
|
||||
percentage_reference_objects_clashing = (
|
||||
len(set([ref_id for ref_id, latest_id, severity in clashes]))
|
||||
/ len(reference_mesh_elements)
|
||||
* 100
|
||||
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
|
||||
len(set([latest_id for ref_id, latest_id, severity in clashes]))
|
||||
/ len(latest_mesh_elements)
|
||||
* 100
|
||||
)
|
||||
|
||||
# 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])}.")
|
||||
|
||||
clash_report_message = (
|
||||
f"Clash detection report: {all_clashes_count} clashes found "
|
||||
f"between {all_objects_count} objects. "
|
||||
@@ -164,14 +165,18 @@ def automate_function(
|
||||
f"{percentage_latest_objects_clashing}%."
|
||||
)
|
||||
|
||||
reference_view = [f"{reference_model_id}@{reference_model_version_id}"]
|
||||
|
||||
automate_context.set_context_view(reference_view)
|
||||
|
||||
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
|
||||
@@ -205,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
+15
-1
@@ -796,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"
|
||||
@@ -1274,4 +1288,4 @@ multidict = ">=4.0"
|
||||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = "^3.10"
|
||||
content-hash = "3abedc1c21df21ba5ab28f1ea6dc49c8a84c768e0f8f155e5c619ca3fd023765"
|
||||
content-hash = "e4e56818583a9f0fad2adbfbc4dcb2ebaa1fc8f917004477f0e1574237b7850a"
|
||||
|
||||
+2
-1
@@ -9,12 +9,13 @@ readme = "README.md"
|
||||
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"]
|
||||
|
||||
+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