Skip to content

Commit bdf7b4d

Browse files
authored
Merge pull request #764 from compas-dev/robot_visuals_blender
hide meshes on instantiation of RobotModelArtist
2 parents 7dce88d + 1a4108d commit bdf7b4d

File tree

5 files changed

+41
-30
lines changed

5 files changed

+41
-30
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323
* Added ability of `RobotModel.add_link` to accept primitives in addition to meshes.
2424
* Fixed bug regarding the computation of `Joint.current_origin`.
2525
* Fixed bug regarding a repeated call to `RobotModel.add_joint`.
26+
* Fixed bug in `compas_blender.RobotModelArtist.update`.
2627
* Fixed bug in `compas.datastructures.mesh_slice_plane`.
2728
* Fixed bug where initialising a `compas_blender.artists.Robotmodelartist` would create a new collection for each mesh and then also not put the mesh iton the created collection.
2829
* Changed the initialisation of `compas_blender.artists.Robotmodelartist` to include a `collection`-parameter instead of a `layer`-parameter to be more consistent with Blender's nomenclature.
@@ -528,12 +529,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
528529
* Split up network and mesh naming conventions.
529530
* Reworked network face cycle finding.
530531
* Updated mesh from lines.
531-
* Updated network plotter in correspondance with network.
532+
* Updated network plotter in correspondence with network.
532533
* Integrated mixin functionality and removed mixins.
534+
* Meshes are now initially hidden in `compas_blender.artists.RobotModelArtist`.
535+
* `compas_blender.artists.RobotModelArtist.draw_visual` and `compas_blender.artists.RobotModelArtist.draw_collision` now show those meshes.
536+
* Renamed the method `draw_geometry` of `compas.robots.base_artist.RobotModelBaseArtist` to `create_geometry`.
533537

534538
### Removed
535539

536-
* Removed parallelisation from network algorithms.
540+
* Removed parallelization from network algorithms.
537541
* Removed numba based dr implementations.
538542

539543
## [0.15.0] 2020-01-24

src/compas/robots/base_artist/_artist.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ def transform(self, geometry, transformation):
2222
Parameters
2323
----------
2424
geometry : object
25-
A CAD-specific (i.e. native) geometry object as returned by :meth:`draw_geometry`.
25+
A CAD-specific (i.e. native) geometry object as returned by :meth:`create_geometry`.
2626
transformation : `Transformation`
2727
**COMPAS** transformation to update the geometry object.
2828
"""
2929
raise NotImplementedError
3030

31-
def draw_geometry(self, geometry, name=None, color=None):
31+
def create_geoemetry(self, geometry, name=None, color=None):
3232
"""Draw a **COMPAS** geometry in the respective CAD environment.
3333
3434
Note
@@ -60,7 +60,7 @@ class BaseRobotModelArtist(AbstractRobotModelArtist):
6060
6161
There are two methods that implementers of this base class should provide, one
6262
is concerned with the actual creation of geometry in the native format of the
63-
CAD environment (:meth:`draw_geometry`) and the other is one to apply a transformation
63+
CAD environment (:meth:`create_geometry`) and the other is one to apply a transformation
6464
to geometry (:meth:`transform`).
6565
6666
Attributes
@@ -117,7 +117,7 @@ def detach_tool_model(self):
117117
def create(self, link=None, context=None):
118118
"""Recursive function that triggers the drawing of the robot model's geometry.
119119
120-
This method delegates the geometry drawing to the :meth:`draw_geometry`
120+
This method delegates the geometry drawing to the :meth:`create_geometry`
121121
method. It transforms the geometry based on the saved initial
122122
transformation from the robot model.
123123
@@ -150,7 +150,7 @@ def create(self, link=None, context=None):
150150
else:
151151
mesh_name_components = [self.model.name, mesh_type, context, link.name, str(i)]
152152
mesh_name = '.'.join(mesh_name_components)
153-
native_mesh = self.draw_geometry(mesh, name=mesh_name, color=color)
153+
native_mesh = self.create_geoemetry(mesh, name=mesh_name, color=color)
154154

155155
self.transform(native_mesh, item.init_transformation)
156156

@@ -288,22 +288,22 @@ def update_tool(self, joint_state=None, visual=True, collision=True, transformat
288288

289289
def draw_visual(self):
290290
"""Draws all visual geometry of the robot model."""
291-
for native_geometry in self._draw_model_geometry(self.model, 'visual'):
291+
for native_geometry in self._iter_geometry(self.model, 'visual'):
292292
yield native_geometry
293293
if self.attached_tool_model:
294-
for native_geometry in self._draw_model_geometry(self.attached_tool_model, 'visual'):
294+
for native_geometry in self._iter_geometry(self.attached_tool_model, 'visual'):
295295
yield native_geometry
296296

297297
def draw_collision(self):
298298
"""Draws all collision geometry of the robot model."""
299-
for native_geometry in self._draw_model_geometry(self.model, 'collision'):
299+
for native_geometry in self._iter_geometry(self.model, 'collision'):
300300
yield native_geometry
301301
if self.attached_tool_model:
302-
for native_geometry in self._draw_model_geometry(self.attached_tool_model, 'collision'):
302+
for native_geometry in self._iter_geometry(self.attached_tool_model, 'collision'):
303303
yield native_geometry
304304

305305
@staticmethod
306-
def _draw_model_geometry(model, geometry_type):
306+
def _iter_geometry(model, geometry_type):
307307
for link in model.iter_links():
308308
for item in getattr(link, geometry_type):
309309
if item.native_geometry:

src/compas_blender/artists/robotmodelartist.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,44 @@ class RobotModelArtist(BaseRobotModelArtist):
1616
----------
1717
model : :class:`compas.robots.RobotModel`
1818
Robot model.
19-
layer : str, optional
20-
The name of the layer that will contain the robot meshes.
2119
"""
2220

23-
def __init__(self, model, collection=None, layer=None):
24-
self.view_layer = layer
21+
def __init__(self, model, collection=None):
2522
self.collection = collection
2623
super(RobotModelArtist, self).__init__(model)
2724

2825
def transform(self, native_mesh, transformation):
29-
native_mesh.matrix_world @= mathutils.Matrix(transformation.matrix)
26+
native_mesh.matrix_world = mathutils.Matrix(transformation.matrix) @ native_mesh.matrix_world
3027

31-
def draw_geometry(self, geometry, name=None, color=None):
28+
def create_geoemetry(self, geometry, name=None, color=None):
3229
# Imported colors take priority over a the parameter color
33-
3430
if 'mesh_color.diffuse' in geometry.attributes:
3531
color = geometry.attributes['mesh_color.diffuse']
3632

3733
# If we have a color, we'll discard alpha because draw_mesh is hard coded for a=1
3834
if color:
3935
r, g, b, _a = color
40-
color = [r, g, b]
36+
color = (r, g, b)
4137
else:
42-
color = [1., 1., 1.]
38+
color = (1., 1., 1.)
4339

44-
if self.collection:
45-
if self.collection not in bpy.data.collections.keys():
46-
compas_blender.utilities.create_collection(self.collection)
40+
if self.collection and self.collection not in bpy.data.collections.keys():
41+
compas_blender.utilities.create_collection(self.collection)
4742

4843
v, f = geometry.to_vertices_and_faces()
49-
return compas_blender.draw_mesh(vertices=v, faces=f, name=name, color=color, centroid=False, collection=self.collection)
50-
51-
def redraw(self, timeout=None):
52-
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
44+
native_mesh = compas_blender.draw_mesh(vertices=v, faces=f, name=name, color=color, centroid=False, collection=self.collection)
45+
native_mesh.hide_set(True)
46+
return native_mesh
47+
48+
def redraw(self, timeout=0.0):
49+
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1, time_limit=timeout)
50+
51+
def draw_visual(self):
52+
visuals = super(RobotModelArtist, self).draw_visual()
53+
for visual in visuals:
54+
visual.hide_set(False)
55+
56+
def draw_collision(self):
57+
collisions = super(RobotModelArtist, self).draw_collision()
58+
for collision in collisions:
59+
collision.hide_set(False)

src/compas_ghpython/artists/robotmodelartist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __init__(self, model):
3030
def transform(self, native_mesh, transformation):
3131
xtransform(native_mesh, transformation)
3232

33-
def draw_geometry(self, geometry, name=None, color=None):
33+
def create_geoemetry(self, geometry, name=None, color=None):
3434
if color:
3535
color = rgb_to_rgb(color[0], color[1], color[2])
3636
vertices, faces = geometry.to_vertices_and_faces()

src/compas_rhino/artists/robotmodelartist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def transform(self, native_mesh, transformation):
4343
T = xform_from_transformation(transformation)
4444
native_mesh.Transform(T)
4545

46-
def draw_geometry(self, geometry, name=None, color=None):
46+
def create_geoemetry(self, geometry, name=None, color=None):
4747
# Imported colors take priority over a the parameter color
4848
if 'mesh_color.diffuse' in geometry.attributes:
4949
color = geometry.attributes['mesh_color.diffuse']

0 commit comments

Comments
 (0)