Skip to content

Commit b0c0ee3

Browse files
committed
return attached meshes, fix docs, rename Item to LinkItem
1 parent 5b50ea9 commit b0c0ee3

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/compas/robots/base_artist/_artist.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from compas.geometry import Scale
99
from compas.geometry import Transformation
1010
from compas.robots import Geometry
11-
from compas.robots.model.link import Item
11+
from compas.robots.model.link import LinkItem
1212

1313

1414
__all__ = [
@@ -79,7 +79,7 @@ def __init__(self, model):
7979
self.attached_items = {}
8080

8181
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.
8383
8484
Parameters
8585
----------
@@ -117,7 +117,7 @@ def detach_tool_model(self):
117117
self.attached_tool_model = None
118118

119119
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.
121121
122122
Parameters
123123
----------
@@ -149,7 +149,7 @@ def attach_mesh(self, mesh, name, link=None, frame=None):
149149
init_transformation = transformation * sample_geometry.init_transformation
150150
self.transform(native_mesh, sample_geometry.current_transformation * init_transformation)
151151

152-
item = Item()
152+
item = LinkItem()
153153
item.native_geometry = [native_mesh]
154154
item.init_transformation = init_transformation
155155
item.current_transformation = sample_geometry.current_transformation
@@ -219,7 +219,7 @@ def create(self, link=None, context=None):
219219
for child_joint in link.joints:
220220
self.create(child_joint.child_link)
221221

222-
def meshes(self, link=None, visual=True, collision=False):
222+
def meshes(self, link=None, visual=True, collision=False, attached_meshes=True):
223223
"""Returns all compas meshes of the model.
224224
225225
Parameters
@@ -232,6 +232,9 @@ def meshes(self, link=None, visual=True, collision=False):
232232
collision : :obj:`bool`, optional
233233
Whether to include the robot's collision meshes. Defaults
234234
to ``False``.
235+
attached_meshes : :obj:`bool`, optional
236+
Whether to include the robot's attached meshes. Defaults
237+
to ``True``.
235238
236239
Returns
237240
-------
@@ -246,13 +249,15 @@ def meshes(self, link=None, visual=True, collision=False):
246249
items += link.visual
247250
if collision:
248251
items += link.collision
252+
if attached_meshes:
253+
items += list(self.attached_items.get(link.name, {}).values())
249254
for item in items:
250255
new_meshes = Geometry._get_item_meshes(item)
251256
for mesh in new_meshes:
252257
mesh.transform(item.current_transformation)
253258
meshes += new_meshes
254259
for child_joint in link.joints:
255-
meshes += self.meshes(child_joint.child_link)
260+
meshes += self.meshes(child_joint.child_link, visual, collision, attached_meshes)
256261
return meshes
257262

258263
def scale(self, factor):

src/compas/robots/model/link.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,14 @@ def data(self, data):
168168
self.inertia = Inertia.from_data(data['inertia']) if data['inertia'] else None
169169

170170

171-
class Item(object):
171+
class LinkItem(object):
172172
def __init__(self):
173173
self.init_transformation = None # to store the init transformation
174174
self.current_transformation = None # to store the current transformation
175175
self.native_geometry = None # to store the link's CAD native geometry
176176

177177

178-
class Visual(Item, Data):
178+
class Visual(LinkItem, Data):
179179
"""Visual description of a link.
180180
181181
Attributes
@@ -268,7 +268,7 @@ def from_primitive(cls, primitive, **kwargs):
268268
return cls(geometry, origin=origin, **kwargs)
269269

270270

271-
class Collision(Item, Data):
271+
class Collision(LinkItem, Data):
272272
"""Collidable description of a link.
273273
274274
Attributes

0 commit comments

Comments
 (0)