Source code for compas_rhino.artists.boxartist


from __future__ import print_function
from __future__ import absolute_import
from __future__ import division

import compas_rhino
from ._shapeartist import ShapeArtist


[docs]class BoxArtist(ShapeArtist): """Artist for drawing box shapes. Parameters ---------- shape : :class:`compas.geometry.Box` A COMPAS box. Notes ----- See :class:`compas_rhino.artists.ShapeArtist` for all other parameters. Examples -------- .. code-block:: python import random from compas.geometry import Pointcloud from compas.geometry import Box from compas.utilities import i_to_rgb import compas_rhino from compas_rhino.artists import BoxArtist pcl = Pointcloud.from_bounds(10, 10, 10, 100) tpl = Box.from_width_height_depth(0.3, 0.3, 0.3) compas_rhino.clear_layer("Test::BoxArtist") for point in pcl.points: box = tpl.copy() box.frame.point = point artist = BoxArtist(box, color=i_to_rgb(random.random()), layer="Test::BoxArtist") artist.draw() """
[docs] def draw(self, show_vertices=False, show_edges=False, show_faces=True, join_faces=True): """Draw the box associated with the artist. Parameters ---------- show_vertices : bool, optional Default is ``False``. show_edges : bool, optional Default is ``False``. show_faces : bool, optional Default is ``True``. join_faces : bool, optional Default is ``True``. Returns ------- list The GUIDs of the objects created in Rhino. """ vertices = [list(vertex) for vertex in self.shape.vertices] guids = [] if show_vertices: points = [{'pos': point, 'color': self.color, 'name': self.name} for point in vertices] guids += compas_rhino.draw_points(points, layer=self.layer, clear=False, redraw=False) if show_edges: edges = self.shape.edges lines = [{'start': vertices[i], 'end': vertices[j], 'color': self.color, 'name': self.name} for i, j in edges] guids += compas_rhino.draw_lines(lines, layer=self.layer, clear=False, redraw=False) if show_faces: faces = self.shape.faces if join_faces: guid = compas_rhino.draw_mesh(vertices, faces, layer=self.layer, name=self.name, color=self.color, disjoint=True) guids.append(guid) else: polygons = [{'points': [vertices[index] for index in face], 'color': self.color, 'name': self.name} for face in faces] guids += compas_rhino.draw_faces(polygons, layer=self.layer, clear=False, redraw=False) self._guids = guids return guids
# ============================================================================== # Main # ============================================================================== if __name__ == '__main__': pass