|
8 | 8 | from compas.geometry import Scale |
9 | 9 | from compas.geometry import Transformation |
10 | 10 | from compas.robots import Geometry |
11 | | -from compas.robots.model.link import Item |
| 11 | +from compas.robots.model.link import LinkItem |
12 | 12 |
|
13 | 13 |
|
14 | 14 | __all__ = [ |
@@ -79,7 +79,7 @@ def __init__(self, model): |
79 | 79 | self.attached_items = {} |
80 | 80 |
|
81 | 81 | def attach_tool_model(self, tool_model): |
82 | | - """Attach a tool to the robot artist. |
| 82 | + """Attach a tool to the robot artist for visualization. |
83 | 83 |
|
84 | 84 | Parameters |
85 | 85 | ---------- |
@@ -117,7 +117,7 @@ def detach_tool_model(self): |
117 | 117 | self.attached_tool_model = None |
118 | 118 |
|
119 | 119 | def attach_mesh(self, mesh, name, link=None, frame=None): |
120 | | - """Rigidly attaches a compas mesh to a given link. |
| 120 | + """Rigidly attaches a compas mesh to a given link for visualization. |
121 | 121 |
|
122 | 122 | Parameters |
123 | 123 | ---------- |
@@ -149,7 +149,7 @@ def attach_mesh(self, mesh, name, link=None, frame=None): |
149 | 149 | init_transformation = transformation * sample_geometry.init_transformation |
150 | 150 | self.transform(native_mesh, sample_geometry.current_transformation * init_transformation) |
151 | 151 |
|
152 | | - item = Item() |
| 152 | + item = LinkItem() |
153 | 153 | item.native_geometry = [native_mesh] |
154 | 154 | item.init_transformation = init_transformation |
155 | 155 | item.current_transformation = sample_geometry.current_transformation |
@@ -219,6 +219,47 @@ def create(self, link=None, context=None): |
219 | 219 | for child_joint in link.joints: |
220 | 220 | self.create(child_joint.child_link) |
221 | 221 |
|
| 222 | + def meshes(self, link=None, visual=True, collision=False, attached_meshes=True): |
| 223 | + """Returns all compas meshes of the model. |
| 224 | +
|
| 225 | + Parameters |
| 226 | + ---------- |
| 227 | + link : :class:`compas.robots.Link`, optional |
| 228 | + Base link instance. Defaults to the robot model's root. |
| 229 | + visual : :obj:`bool`, optional |
| 230 | + Whether to include the robot's visual meshes. Defaults |
| 231 | + to ``True``. |
| 232 | + collision : :obj:`bool`, optional |
| 233 | + Whether to include the robot's collision meshes. Defaults |
| 234 | + to ``False``. |
| 235 | + attached_meshes : :obj:`bool`, optional |
| 236 | + Whether to include the robot's attached meshes. Defaults |
| 237 | + to ``True``. |
| 238 | +
|
| 239 | + Returns |
| 240 | + ------- |
| 241 | + :obj:`list` of :class:`compas.datastructures.Mesh` |
| 242 | + """ |
| 243 | + if link is None: |
| 244 | + link = self.model.root |
| 245 | + |
| 246 | + meshes = [] |
| 247 | + items = [] |
| 248 | + if visual: |
| 249 | + items += link.visual |
| 250 | + if collision: |
| 251 | + items += link.collision |
| 252 | + if attached_meshes: |
| 253 | + items += list(self.attached_items.get(link.name, {}).values()) |
| 254 | + for item in items: |
| 255 | + new_meshes = Geometry._get_item_meshes(item) |
| 256 | + for mesh in new_meshes: |
| 257 | + mesh.transform(item.current_transformation) |
| 258 | + meshes += new_meshes |
| 259 | + for child_joint in link.joints: |
| 260 | + meshes += self.meshes(child_joint.child_link, visual, collision, attached_meshes) |
| 261 | + return meshes |
| 262 | + |
222 | 263 | def scale(self, factor): |
223 | 264 | """Scales the robot model's geometry by factor (absolute). |
224 | 265 |
|
|
0 commit comments