55import Rhino
66from functools import partial
77
8- from compas .geometry import centroid_polygon
98from compas .utilities import color_to_colordict
10- from compas .utilities import pairwise
119
1210import compas_ghpython
1311from compas .artists import MeshArtist
@@ -25,12 +23,69 @@ class MeshArtist(GHArtist, MeshArtist):
2523 A COMPAS mesh.
2624 """
2725
28- def __init__ (self , mesh , ** kwargs ):
26+ def __init__ (self ,
27+ mesh ,
28+ show_mesh = False ,
29+ show_vertices = True ,
30+ show_edges = True ,
31+ show_faces = True ,
32+ ** kwargs ):
2933 super (MeshArtist , self ).__init__ (mesh = mesh , ** kwargs )
34+ self .show_mesh = show_mesh
35+ self .show_vertices = show_vertices
36+ self .show_edges = show_edges
37+ self .show_faces = show_faces
3038
31- def draw (self , color = None ):
39+ def draw (self , vertices = None , edges = None , faces = None , vertexcolor = None , edgecolor = None , facecolor = None , color = None , join_faces = False ):
40+ """Draw the mesh using the chosen visualization settings.
41+
42+ Parameters
43+ ----------
44+ vertices : list, optional
45+ A list of vertices to draw.
46+ Default is ``None``, in which case all vertices are drawn.
47+ edges : list, optional
48+ A list of edges to draw.
49+ The default is ``None``, in which case all edges are drawn.
50+ faces : list, optional
51+ A selection of faces to draw.
52+ The default is ``None``, in which case all faces are drawn.
53+ vertexcolor : tuple or dict of tuple, optional
54+ The color specification for the vertices.
55+ The default color is the value of ``~MeshArtist.default_vertexcolor``.
56+ edgecolor : tuple or dict of tuple, optional
57+ The color specification for the edges.
58+ The default color is the value of ``~MeshArtist.default_edgecolor``.
59+ facecolor : tuple or dict of tuple, optional
60+ The color specification for the faces.
61+ The default color is the value of ``~MeshArtist.default_facecolor``.
62+ color : tuple, optional
63+ The color of the mesh.
64+ Default is the value of ``~MeshArtist.default_color``.
65+ join_faces : bool, optional
66+ Join the faces into 1 mesh.
67+ Default is ``False``, in which case the faces are drawn as individual meshes.
68+
69+ Returns
70+ -------
71+ list of :class:`Rhino.Geometry.Mesh`, :class:`Rhino.Geometry.Point3d` and :class:`Rhino.Geometry.Line` depending on the selection.
72+ """
73+ geometry = []
74+ if self .show_mesh :
75+ geometry .append (self .draw_mesh (color = color ))
76+ if self .show_vertices :
77+ geometry .extend (self .draw_vertices (vertices = vertices , color = vertexcolor ))
78+ if self .show_edges :
79+ geometry .extend (self .draw_edges (edges = edges , color = edgecolor ))
80+ if self .show_faces :
81+ geometry .extend (self .draw_faces (faces = faces , color = facecolor , join_faces = join_faces ))
82+ return geometry
83+
84+ def draw_mesh (self , color = None ):
3285 """Draw the mesh as a RhinoMesh.
3386
87+ This method is an alias for ``~MeshArtist.draw``.
88+
3489 Parameters
3590 ----------
3691 color : tuple, optional
@@ -47,24 +102,8 @@ def draw(self, color=None):
47102 Faces with more than 4 vertices will be triangulated on-the-fly.
48103 """
49104 color = color or self .default_color
50- vertex_index = self .mesh .vertex_index ()
51- vertex_xyz = self .vertex_xyz
52- vertices = [vertex_xyz [vertex ] for vertex in self .mesh .vertices ()]
53- faces = [[vertex_index [vertex ] for vertex in self .mesh .face_vertices (face )] for face in self .mesh .faces ()]
54- new_faces = []
55- for face in faces :
56- f = len (face )
57- if f == 3 :
58- new_faces .append (face + [face [- 1 ]])
59- elif f == 4 :
60- new_faces .append (face )
61- elif f > 4 :
62- centroid = len (vertices )
63- vertices .append (centroid_polygon (
64- [vertices [index ] for index in face ]))
65- for a , b in pairwise (face + face [0 :1 ]):
66- new_faces .append ([centroid , a , b , b ])
67- return compas_ghpython .draw_mesh (vertices , new_faces , color )
105+ vertices , faces = self .mesh .to_vertices_and_faces ()
106+ return compas_ghpython .draw_mesh (vertices , faces , color )
68107
69108 def draw_vertices (self , vertices = None , color = None ):
70109 """Draw a selection of vertices.
@@ -75,7 +114,7 @@ def draw_vertices(self, vertices=None, color=None):
75114 A selection of vertices to draw.
76115 Default is ``None``, in which case all vertices are drawn.
77116 color : tuple or dict of tuple, optional
78- The color specififcation for the vertices.
117+ The color specification for the vertices.
79118 The default is the value of ``~MeshArtist.default_vertexcolor``.
80119
81120 Returns
@@ -104,7 +143,7 @@ def draw_faces(self, faces=None, color=None, join_faces=False):
104143 A selection of faces to draw.
105144 The default is ``None``, in which case all faces are drawn.
106145 color : tuple or dict of tuple, optional
107- The color specififcation for the faces.
146+ The color specification for the faces.
108147 The default color is the value of ``~MeshArtist.default_facecolor``.
109148 join_faces : bool, optional
110149 Join the faces into 1 mesh.
@@ -142,7 +181,7 @@ def draw_edges(self, edges=None, color=None):
142181 A selection of edges to draw.
143182 The default is ``None``, in which case all edges are drawn.
144183 color : tuple or dict of tuple, optional
145- The color specififcation for the edges.
184+ The color specification for the edges.
146185 The default color is the value of ``~MeshArtist.default_edgecolor``.
147186
148187 Returns
0 commit comments