def draw(self, color=None, u=None, v=None): """Draw the sphere associated with the artist. Parameters ---------- color : tuple of float, optional The RGB color of the sphere. u : int, optional Number of faces in the "u" direction. Default is ``~SphereArtist.u``. v : int, optional Number of faces in the "v" direction. Default is ``~SphereArtist.v``. Returns ------- :class:`Rhino.Geometry.Mesh` """ color = color or self.color u = u or self.u v = v or self.v vertices, faces = self.shape.to_vertices_and_faces(u=u, v=v) vertices = [list(vertex) for vertex in vertices] mesh = compas_ghpython.draw_mesh(vertices, faces, color=color) return mesh
def draw(self, color=None): """Draw the mesh as a RhinoMesh. Parameters ---------- color : 3-tuple, optional RGB color components in integer format (0-255). Returns ------- :class:`Rhino.Geometry.Mesh` """ vertex_index = self.mesh.key_index() vertices = self.mesh.vertices_attributes('xyz') faces = [[ vertex_index[vertex] for vertex in self.mesh.face_vertices(face) ] for face in self.mesh.faces()] new_faces = [] for face in faces: f = len(face) if f == 3: new_faces.append(face + [face[-1]]) elif f == 4: new_faces.append(face) elif f > 4: centroid = len(vertices) vertices.append( centroid_polygon([vertices[index] for index in face])) for a, b in pairwise(face + face[0:1]): new_faces.append([centroid, a, b, b]) else: continue return compas_ghpython.draw_mesh(vertices, new_faces, color)
def create_geometry(self, geometry, name=None, color=None): if color: color = rgb_to_rgb(color[0], color[1], color[2]) vertices, faces = geometry.to_vertices_and_faces() mesh = compas_ghpython.draw_mesh(vertices, faces, color=color) # Try to fix invalid meshes if not mesh.IsValid: mesh.FillHoles() return mesh
def draw(self, color=None): key_index = self.mesh.key_index() vertices = self.mesh.get_vertices_attributes('xyz') faces = [[key_index[key] for key in self.mesh.face_vertices(fkey)] for fkey in self.mesh.faces()] new_faces = [] for face in faces: l = len(face) if l == 3: new_faces.append(face + [face[-1]]) elif l == 4: new_faces.append(face) return compas_ghpython.draw_mesh(vertices, new_faces, color)
def draw(self, color=None): """Draw the box associated with the artist. Parameters ---------- color : tuple of float, optional The RGB color of the box. Returns ------- :class:`Rhino.Geometry.Mesh` """ color = color or self.color vertices = [list(vertex) for vertex in self.shape.vertices] faces = self.shape.faces mesh = compas_ghpython.draw_mesh(vertices, faces, color=color) return mesh
def draw_mesh(self, color=None): key_index = self.mesh.key_index() vertices = self.mesh.vertices_attributes('xyz') faces = [[key_index[key] for key in self.mesh.face_vertices(fkey)] for fkey in self.mesh.faces()] new_faces = [] for face in faces: f = len(face) if f == 3: new_faces.append(face + [face[-1]]) elif f == 4: new_faces.append(face) elif f > 4: centroid = len(vertices) vertices.append( centroid_polygon([vertices[index] for index in face])) for a, b in pairwise(face + face[0:1]): new_faces.append([centroid, a, b, b]) else: continue return compas_ghpython.draw_mesh(vertices, new_faces, color)
def draw(self, color=None, u=None): """Draw the cone associated with the artist. Parameters ---------- color : tuple[int, int, int], optional The RGB color of the cone. u : int, optional Number of faces in the "u" direction. Default is :attr:`ConeArtist.u` Returns ------- :rhino:`Rhino.Geometry.Mesh` """ color = color or self.color u = u or self.u vertices, faces = self.shape.to_vertices_and_faces(u=u) vertices = [list(vertex) for vertex in vertices] mesh = compas_ghpython.draw_mesh(vertices, faces, color=color) return mesh
def draw_mesh(self, color=None): """Draw the mesh as a RhinoMesh. This method is an alias for ``~MeshArtist.draw``. Parameters ---------- color : tuple, optional The color of the mesh. Default is the value of ``~MeshArtist.default_color``. Returns ------- :class:`Rhino.Geometry.Mesh` Notes ----- The mesh should be a valid Rhino Mesh object, which means it should have only triangular or quadrilateral faces. Faces with more than 4 vertices will be triangulated on-the-fly. """ color = color or self.default_color vertices, faces = self.mesh.to_vertices_and_faces() return compas_ghpython.draw_mesh(vertices, faces, color)