From 3328c4adc3960392e6f28388b508539ab0113d80 Mon Sep 17 00:00:00 2001 From: Victor LEUNG Date: Wed, 20 Nov 2024 19:28:29 +0800 Subject: [PATCH] Address the issues in the Review from Chen and Gonzalo --- src/compas_robots/model/base.py | 3 --- src/compas_robots/model/robot.py | 10 +++++----- tests/test_model_frame.py | 11 +++++++++++ 3 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 tests/test_model_frame.py diff --git a/src/compas_robots/model/base.py b/src/compas_robots/model/base.py index b4902a42..3d05794b 100644 --- a/src/compas_robots/model/base.py +++ b/src/compas_robots/model/base.py @@ -132,9 +132,6 @@ def scale(self, factor): """ self.point = self.point * factor - def to_compas_frame(self): - return Frame(self.point, self.xaxis, self.yaxis) - class ColorProxy(ProxyObject): """Proxy class that adds URDF functionality to an instance of :class:`Color`. diff --git a/src/compas_robots/model/robot.py b/src/compas_robots/model/robot.py index e0327987..ed0b5829 100644 --- a/src/compas_robots/model/robot.py +++ b/src/compas_robots/model/robot.py @@ -1027,21 +1027,18 @@ def _extract_link_meshes(self, link_elements, meshes_at_link_origin=True): ------- list of :class:`~compas.datastructures.Mesh` A list of meshes belonging to the link elements. + If there are no meshes, an empty list is returned. Notes ----- Only MeshDescriptor in `element.geometry.shape` is supported. Other shapes are ignored. """ - if not link_elements: - return None - meshes = [] # Note: Each Link can have multiple visual nodes for element in link_elements: # Some elements may have a non-identity origin frame - origin = element.origin.to_compas_frame() if element.origin else Frame.worldXY() - t_origin = Transformation.from_frame(origin) + t_origin = Transformation.from_frame(element.origin or Frame.worldXY()) # If `meshes_at_link_origin` is False, we use an identity transformation t_origin = t_origin if meshes_at_link_origin else Transformation() @@ -1052,6 +1049,7 @@ def _extract_link_meshes(self, link_elements, meshes_at_link_origin=True): for mesh in shape.meshes: # Transform the mesh (even if t_origin is identity) so we always get a new mesh object meshes.append(mesh.transformed(t_origin)) + # Add support for other shapes here if needed, e.g. Box, Cylinder, Sphere, Capsule etc. return meshes @@ -1071,6 +1069,7 @@ def get_link_visual_meshes(self, link): ------- list of :class:`~compas.datastructures.Mesh` A list of visual meshes belonging to the link + The list is empty if no visual meshes are found. Notes ----- @@ -1131,6 +1130,7 @@ def get_link_collision_meshes(self, link): ------- list of :class:`~compas.datastructures.Mesh` A list of collision meshes belonging to the link + The list is empty if no collision meshes are found. Notes ----- diff --git a/tests/test_model_frame.py b/tests/test_model_frame.py new file mode 100644 index 00000000..a37c0e44 --- /dev/null +++ b/tests/test_model_frame.py @@ -0,0 +1,11 @@ +from compas_fab.robots import RobotCellLibrary + +rc, rcs = RobotCellLibrary.ur10e() +model = rc.robot_model +for link in model.iter_links(): + print(link.name) + print(model.get_link_visual_meshes(link)) + print(model.get_link_collision_meshes(link)) + print(model.get_link_visual_meshes_joined(link)) + print(model.get_link_collision_meshes_joined(link)) + print("---------------------")