Skip to content

Commit 57a430d

Browse files
authored
Merge pull request #882 from compas-dev/all_robot_meshes
adds meshes method to BaseRobotModelArtist
2 parents 70a9789 + b0c0ee3 commit 57a430d

File tree

3 files changed

+49
-7
lines changed

3 files changed

+49
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
* Added general plotter for geometry objects and data structures based on the artist registration mechanism.
1616
* Added support for multimesh files to OBJ reader/writer.
1717
* Added support for attaching and detaching meshes in `compas.robots.RobotModelArtist` and drawing them.
18+
* Added `meshes` method to artists of `compas.robots.RobotModel`.
1819

1920
### Changed
2021

src/compas/robots/base_artist/_artist.py

Lines changed: 45 additions & 4 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,6 +219,47 @@ 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, 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+
222263
def scale(self, factor):
223264
"""Scales the robot model's geometry by factor (absolute).
224265

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)