4 Commits

Author SHA1 Message Date
Jonathon Broughton 5ad615eb5b Update main.yml
build and deploy Speckle functions / publish-automate-function-version (push) Has been cancelled
2023-11-13 17:08:20 +00:00
Jonathon Broughton 59bcacfd6d Update main.yml
build and deploy Speckle functions / publish-automate-function-version (push) Has been cancelled
2023-11-13 13:11:08 +00:00
Jonathon Broughton d56282a140 demo ready
build and deploy Speckle functions / publish-automate-function-version (push) Has been cancelled
2023-11-13 12:20:52 +00:00
Jonathon Broughton 2396810930 fixes 2023-11-13 05:28:12 +00:00
8 changed files with 59 additions and 34 deletions
+2 -2
View File
@@ -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
+5
View File
@@ -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)
@@ -83,6 +84,7 @@ def check_for_clash(
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
@@ -126,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)
+9 -3
View File
@@ -35,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.
@@ -70,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
@@ -86,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
+5 -1
View File
@@ -9,5 +9,9 @@ class mypymesh:
return 0
@staticmethod
def boolean(_other, _operation):
def boolean(mesh_a, mesh_b, operation):
return mypymesh.Mesh([], [])
@staticmethod
def form_mesh(vertices, faces):
return mypymesh.Mesh(vertices, faces)
+3 -5
View File
@@ -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
)
+18 -6
View File
@@ -41,14 +41,15 @@ class FunctionInputs(AutomateBase):
title="Tolerance",
description="Specify the tolerance value for the analysis. \
Negative values relaxes the test, positive values make it more strict.",
readonly=True,
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"]},
json_schema_extra={"examples": ["mm", "cm", "m"], "readOnly": True},
title="Tolerance Unit",
description="Unit of the tolerance value.",
readonly=True,
)
@@ -69,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))
@@ -114,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
@@ -148,6 +151,11 @@ def automate_function(
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. "
@@ -157,6 +165,10 @@ 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
)
@@ -164,7 +176,7 @@ def automate_function(
def get_reference_model(
automate_context: AutomationContext, static_model_name: str
) -> Base:
) -> 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
@@ -198,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
+2 -2
View File
@@ -9,13 +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"
python-dotenv = "^1.0.0"
[build-system]
requires = ["poetry-core"]
+15 -15
View File
@@ -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