|
10 | 10 | from compas.geometry import Box |
11 | 11 | from compas.geometry import Brep |
12 | 12 | from compas.geometry import Frame |
| 13 | +from compas.geometry import Point |
13 | 14 | from compas.geometry import Shape |
14 | 15 | from compas.geometry import Transformation |
15 | | -from compas_model.interactions import BooleanModifier |
16 | | -from compas_model.interactions import ContactInterface |
17 | | -from compas_model.interactions import Interaction |
| 16 | +from compas_model.algorithms import mesh_mesh_collision |
| 17 | +from compas_model.algorithms import mesh_mesh_contacts |
| 18 | +from compas_model.interactions import Contact |
18 | 19 | from compas_model.materials import Material |
19 | 20 |
|
20 | 21 | if TYPE_CHECKING: |
@@ -241,6 +242,12 @@ def collision_mesh(self) -> Mesh: |
241 | 242 | self._collision_mesh = self.compute_collision_mesh() |
242 | 243 | return self._collision_mesh |
243 | 244 |
|
| 245 | + @property |
| 246 | + def point(self) -> Point: |
| 247 | + if not self._point: |
| 248 | + self._point = self.compute_point() |
| 249 | + return self._point |
| 250 | + |
244 | 251 | # ========================================================================== |
245 | 252 | # Abstract methods |
246 | 253 | # ========================================================================== |
@@ -310,17 +317,19 @@ def compute_modelgeometry(self) -> Union[Brep, Mesh]: |
310 | 317 | :class:`compas.datastructures.Mesh` | :class:`compas.geometry.Brep` |
311 | 318 |
|
312 | 319 | """ |
313 | | - graph = self.model.graph |
314 | | - elements = list(self.model.elements()) |
315 | 320 | xform = self.modeltransformation |
316 | 321 | modelgeometry = self.elementgeometry.transformed(xform) |
317 | 322 |
|
318 | | - for neighbor in graph.neighbors_in(self.graphnode): |
319 | | - for interaction in graph.edge_interactions((neighbor, self.graphnode)): |
320 | | - if isinstance(interaction, ContactInterface): |
321 | | - modelgeometry = interaction.apply(modelgeometry) |
322 | | - elif isinstance(interaction, BooleanModifier): |
323 | | - modelgeometry = interaction.apply(modelgeometry, elements[neighbor].modelgeometry) |
| 323 | + # this needs to be updated |
| 324 | + |
| 325 | + # graph = self.model.graph |
| 326 | + # elements = list(self.model.elements()) |
| 327 | + # for neighbor in graph.neighbors_in(self.graphnode): |
| 328 | + # for interaction in graph.edge_interactions((neighbor, self.graphnode)): |
| 329 | + # if isinstance(interaction, Contact): |
| 330 | + # modelgeometry = interaction.apply(modelgeometry) |
| 331 | + # elif isinstance(interaction, BooleanModifier): |
| 332 | + # modelgeometry = interaction.apply(modelgeometry, elements[neighbor].modelgeometry) |
324 | 333 |
|
325 | 334 | self.is_dirty = False |
326 | 335 |
|
@@ -359,17 +368,13 @@ def compute_collision_mesh(self) -> Mesh: |
359 | 368 | """ |
360 | 369 | raise NotImplementedError |
361 | 370 |
|
362 | | - def compute_contact(self, target_element: "Element", type: str = "") -> "Interaction": |
363 | | - """Computes the contact interaction of the geometry of the elements that is used in the model's add_contact method. |
| 371 | + def compute_point(self) -> Point: |
| 372 | + """Computes a reference point for the element geometry (e.g. the centroid). |
364 | 373 |
|
365 | 374 | Returns |
366 | 375 | ------- |
367 | | - :class:`compas_model.interactions.ContactInterface` |
368 | | - The ContactInteraction that is applied to the neighboring element. One pair can have one or multiple variants. |
369 | | - target_element : Element |
370 | | - The target element to compute the contact interaction. |
371 | | - type : str, optional |
372 | | - The type of contact interaction, if different contact are possible between the two elements. |
| 376 | + :class:`compas.geometry.Point` |
| 377 | + The reference point. |
373 | 378 |
|
374 | 379 | """ |
375 | 380 | raise NotImplementedError |
@@ -428,3 +433,44 @@ def add_feature(self, feature: Feature) -> None: |
428 | 433 |
|
429 | 434 | """ |
430 | 435 | self._features.append(feature) |
| 436 | + |
| 437 | + def collision(self, other: "Element") -> Mesh: |
| 438 | + """Compute the collision between this element and another element. |
| 439 | +
|
| 440 | + Parameters |
| 441 | + ---------- |
| 442 | + other : :class:`Element` |
| 443 | + The other element. |
| 444 | +
|
| 445 | + Returns |
| 446 | + ------- |
| 447 | + :class:`compas.datastructures.Mesh` |
| 448 | +
|
| 449 | + """ |
| 450 | + # perhaps we should check the type of self.modelgeometry to decide which collision algorithm to use |
| 451 | + mesh_mesh_collision() |
| 452 | + |
| 453 | + def contacts(self, other: "Element", tolerance: float = 1e-6, minimum_area: float = 1e-2) -> list[Contact]: |
| 454 | + """Compute the contacts between this element and another element. |
| 455 | +
|
| 456 | + Parameters |
| 457 | + ---------- |
| 458 | + other : :class:`Element` |
| 459 | + The other element. |
| 460 | + tolerance : float, optional |
| 461 | + A distance tolerance. |
| 462 | + minimum_area : float, optional |
| 463 | + The minimum area of the contact polygon. |
| 464 | +
|
| 465 | + Returns |
| 466 | + ------- |
| 467 | + list[:class:`Contact`] |
| 468 | +
|
| 469 | + """ |
| 470 | + # perhaps we should check the type of self.modelgeometry to decide which contact algorithm to use |
| 471 | + return mesh_mesh_contacts( |
| 472 | + self.modelgeometry, |
| 473 | + other.modelgeometry, |
| 474 | + tolerance=tolerance, |
| 475 | + minimum_area=minimum_area, |
| 476 | + ) |
0 commit comments