def draw_edges(self, edges: Optional[Tuple[int, int]] = None, color: Optional[Union[str, RGBColor, List[RGBColor], Dict[int, RGBColor]]] = None ) -> List[bpy.types.Object]: """Draw a selection of edges. Parameters ---------- edges : list A list of edge keys (as uv pairs) identifying which edges to draw. The default is ``None``, in which case all edges are drawn. color : rgb-tuple or dict of rgb-tuples The color specification for the edges. Returns ------- list of :class:`bpy.types.Object` """ self.edge_color = color edges = edges or self.edges lines = [] for edge in edges: lines.append({ 'start': self.node_xyz[edge[0]], 'end': self.node_xyz[edge[1]], 'color': self.edge_color.get(edge, self.default_edgecolor), 'name': f"{self.network.name}.edge.{edge[0]}-{edge[1]}", 'width': 0.02 }) return compas_blender.draw_lines(lines, self.edgecollection)
def draw_edges(self, edges=None, color=None): """Draw a selection of edges. Parameters ---------- edges : list A list of edge keys (as uv pairs) identifying which edges to draw. The default is ``None``, in which case all edges are drawn. color : rgb-tuple or dict of rgb-tuples The color specififcation for the edges. Returns ------- list of :class:`bpy.types.Object` """ edges = edges or list(self.network.edges()) edge_color = colordict(color, edges, default=self.color_edges) lines = [] for edge in edges: lines.append({ 'start': self.network.node_coordinates(edge[0]), 'end': self.network.node_coordinates(edge[1]), 'color': edge_color[edge], 'name': f"{self.network.name}.edge.{edge[0]}-{edge[1]}", 'width': 0.02 }) objects = compas_blender.draw_lines(lines, self.edgecollection) self.object_edge = zip(objects, edges) return objects
def draw_edges(self, edges=None, color=None): """Draw a selection of edges. Parameters ---------- edges : list A list of edge keys (as uv pairs) identifying which edges to draw. The default is ``None``, in which case all edges are drawn. color : rgb-tuple or dict of rgb-tuple The color specififcation for the edges. Returns ------- list of :class:`bpy.types.Object` """ edges = edges or list(self.mesh.edges()) edge_color = colordict(color, edges, default=self.settings['color.edges'], colorformat='rgb', normalize=False) lines = [] for edge in edges: lines.append({ 'start': self.mesh.vertex_coordinates(edge[0]), 'end': self.mesh.vertex_coordinates(edge[1]), 'color': edge_color[edge], 'name': "{}.edge.{}-{}".format(self.mesh.name, *edge) }) objects = compas_blender.draw_lines(lines, self.edgecollection) self.object_edge = zip(objects, edges) return objects
def draw(self, color: Optional[RGBColor] = None, show_point=False, show_normal=False) -> List[bpy.types.Object]: """Draw the circle. Parameters ---------- color : tuple of float or tuple of int, optional The RGB color of the capsule. show_point : bool, optional Default is ``False``. show_normal : bool, optional Default is ``False``. Returns ------- list The objects created in Blender. """ color = color or self.color point = self.primitive.plane.point normal = self.primitive.plane.normal plane = point, normal radius = self.primitive.radius objects = [] if show_point: points = [{'pos': point, 'color': color, 'name': self.primitive.name, 'radius': 0.01}] objects += compas_blender.draw_points(points, collection=self.collection) if show_normal: end = add_vectors(point, normal) lines = [{'start': point, 'end': end, 'color': color, 'name': self.primitive.name}] objects += compas_blender.draw_lines(lines, collection=self.collection) circles = [{'plane': plane, 'radius': radius, 'color': color, 'name': self.primitive.name}] objects += compas_blender.draw_circles(circles, collection=self.collection) return objects
def draw_axes(self) -> List[bpy.types.Object]: """Draw the axes of the frame. Returns ------- list of :class:`bpy.types.Object` """ origin = self.primitive.point X = self.primitive.point + self.primitive.xaxis.scaled(self.scale) Y = self.primitive.point + self.primitive.yaxis.scaled(self.scale) Z = self.primitive.point + self.primitive.zaxis.scaled(self.scale) lines = [ { 'start': origin, 'end': X, 'color': self.color_xaxis, 'name': f"{self.primitive.name}.xaxis" }, { 'start': origin, 'end': Y, 'color': self.color_yaxis, 'name': f"{self.primitive.name}.yaxis" }, { 'start': origin, 'end': Z, 'color': self.color_zaxis, 'name': f"{self.primitive.name}.zaxis" }, ] return compas_blender.draw_lines(lines, self.collection)
def draw(self, color: Optional[RGBColor] = None, show_point=False, show_normal=False) -> List[bpy.types.Object]: """Draw the circle. Parameters ---------- color : tuple[float, float, float] or tuple[int, int, int], optional The RGB color of the capsule. The default color is :attr:`compas.artists.PrimitiveArtist.color`. show_point : bool, optional If True, also draw the center point of the circle. show_normal : bool, optional If True, also draw the normal vector of the circle. Returns ------- list[:blender:`bpy.types.Object`] The objects created in Blender. """ color = color or self.color point = self.primitive.plane.point normal = self.primitive.plane.normal plane = point, normal radius = self.primitive.radius objects = [] if show_point: points = [{ 'pos': point, 'color': color, 'name': self.primitive.name, 'radius': 0.01 }] objects += compas_blender.draw_points(points, collection=self.collection) if show_normal: end = add_vectors(point, normal) lines = [{ 'start': point, 'end': end, 'color': color, 'name': self.primitive.name }] objects += compas_blender.draw_lines(lines, collection=self.collection) circles = [{ 'plane': plane, 'radius': radius, 'color': color, 'name': self.primitive.name }] objects += compas_blender.draw_circles(circles, collection=self.collection) return objects
def draw(self, color: Optional[RGBColor] = None, show_points: bool = False, show_edges: bool = False, show_face: bool = True) -> List[bpy.types.Object]: """Draw the polygon. Parameters ---------- color : tuple[float, float, float] or tuple[int, int, int], optional The RGB color of the polygon. The default color is :attr:`compas.artists.PrimitiveArtist.color`. show_points : bool, optional If True, draw the corner points of the polygon. show_edges : bool, optional If True, draw the edges of the polygon. show_face : bool, optional If True, draw the face of the polygon. Returns ------- list[:blender:`bpy.types.Object`] """ color = color or self.color objects = [] if show_points: points = [{ 'pos': point, 'color': color, 'name': self.primitive.name, 'radius': 0.01 } for point in self.primitive.points] objects += compas_blender.draw_points(points, collection=self.collection) if show_edges: lines = [{ 'start': a, 'end': b, 'color': color, 'name': self.primitive.name } for a, b in self.primitive.lines] objects += compas_blender.draw_lines(lines, collection=self.collection) if show_face: polygons = [{ 'points': self.primitive.points, 'color': color, 'name': self.primitive.name }] objects += compas_blender.draw_faces(polygons, collection=self.collection) return objects
def draw(self, color: Optional[RGBColor] = None, show_points: bool = False, show_edges: bool = False, show_face: bool = True) -> List[bpy.types.Object]: """Draw the polygon. Parameters ---------- color : tuple of float or tuple of int, optional The RGB color of the polygon. show_points : bool, optional Default is ``False``. show_edges : bool, optional Default is ``False``. show_face : bool, optional Default is ``True``. Returns ------- list of bpy.types.Object """ color = color or self.color objects = [] if show_points: points = [{ 'pos': point, 'color': color, 'name': self.primitive.name, 'radius': 0.01 } for point in self.primitive.points] objects += compas_blender.draw_points(points, collection=self.collection) if show_edges: lines = [{ 'start': a, 'end': b, 'color': color, 'name': self.primitive.name } for a, b in self.primitive.lines] objects += compas_blender.draw_lines(lines, collection=self.collection) if show_face: polygons = [{ 'points': self.primitive.points, 'color': color, 'name': self.primitive.name }] objects += compas_blender.draw_faces(polygons, collection=self.collection) return objects
def draw(self, color: Optional[RGBColor] = None, show_points: Optional[bool] = False) -> List[bpy.types.Object]: """Draw the line. Parameters ---------- color : tuple[float, float, float] or tuple[int, int, int], optional The RGB color of the box. The default color is :attr:`compas.artists.PrimitiveArtist.color`. show_points : bool, optional If True, show the start and end point in addition to the line. Returns ------- list[:blender:`bpy.types.Object`] """ color = color or self.color start = self.primitive.start end = self.primitive.end objects = [] if show_points: points = [ { 'pos': start, 'name': f"{self.primitive.name}.start", 'color': color, 'radius': 0.01 }, { 'pos': end, 'name': f"{self.primitive.name}.end", 'color': color, 'radius': 0.01 }, ] objects += compas_blender.draw_points(points, collection=self.collection) lines = [ { 'start': start, 'end': end, 'color': color, 'name': f"{self.primitive.name}" }, ] objects += compas_blender.draw_lines(lines, collection=self.collection) return objects
def draw(self, color: Optional[RGBColor] = None, show_points: Optional[bool] = False) -> List[bpy.types.Object]: """Draw the line. Parameters ---------- color : tuple of float or tuple of int, optional The RGB color of the box. show_points : bool, optional Show the start and end point. Default is ``False``. Returns ------- list of bpy.types.Object """ color = color or self.color start = self.primitive.start end = self.primitive.end objects = [] if show_points: points = [ { 'pos': start, 'name': f"{self.primitive.name}.start", 'color': color, 'radius': 0.01 }, { 'pos': end, 'name': f"{self.primitive.name}.end", 'color': color, 'radius': 0.01 }, ] objects += compas_blender.draw_points(points, collection=self.collection) lines = [ { 'start': start, 'end': end, 'color': color, 'name': f"{self.primitive.name}" }, ] objects += compas_blender.draw_lines(lines, collection=self.collection) return objects
def draw_facenormals(self, faces: Optional[List[List[int]]] = None, color: Optional[Union[str, RGBColor, List[RGBColor], Dict[int, RGBColor]]] = (0.0, 1.0, 1.0), scale: float = 1.0) -> List[bpy.types.Object]: """Draw the normals of the faces. Parameters ---------- faces : list[int], optional A selection of face normals to draw. Default is to draw all face normals. color : rgb-tuple or dict[int, rgb-tuple], optional The color specification of the normal vectors. scale : float, optional Scale factor for the face normals. Returns ------- list[:blender:`bpy.types.Object`] """ faces = faces or self.faces face_color = colordict(color, faces, default=color) lines = [] for face in faces: a = centroid_points([ self.vertex_xyz[vertex] for vertex in self.mesh.face_vertices(face) ]) n = self.mesh.face_normal(face) b = add_vectors(a, scale_vector(n, scale)) lines.append({ 'start': a, 'end': b, 'name': "{}.facenormal.{}".format(self.mesh.name, face), 'color': face_color[face] }) return compas_blender.draw_lines(lines, collection=self.facenormalcollection)
def draw_vertexnormals(self, vertices: Optional[List[int]] = None, color: Optional[Union[str, RGBColor, List[RGBColor], Dict[int, RGBColor]]] = (0.0, 1.0, 0.0), scale: float = 1.0) -> List[bpy.types.Object]: """Draw the normals at the vertices of the mesh. Parameters ---------- vertices : list[int], optional A selection of vertex normals to draw. Default is to draw all vertex normals. color : rgb-tuple or dict[int, rgb-tuple], optional The color specification of the normal vectors. scale : float, optional Scale factor for the vertex normals. Returns ------- list[:blender:`bpy.types.Object`] """ vertices = vertices or self.vertices vertex_color = colordict(color, vertices, default=color) lines = [] for vertex in vertices: a = self.vertex_xyz[vertex] n = self.mesh.vertex_normal(vertex) b = add_vectors(a, scale_vector(n, scale)) lines.append({ 'start': a, 'end': b, 'color': vertex_color[vertex], 'name': "{}.vertexnormal.{}".format(self.mesh.name, vertex) }) return compas_blender.draw_lines( lines, collection=self.vertexnormalcollection)
def draw(self, color: Optional[RGBColor] = None, show_points: Optional[bool] = False) -> List[bpy.types.Object]: """Draw the line. Parameters ---------- color : tuple[float, float, float] or tuple[int, int, int], optional The RGB color of the polyline. The default color is :attr:`compas.artists.PrimitiveArtist.color`. show_points : bool, optional If True, draw the corner points of the polyline. Returns ------- list[:blender:`bpy.types.Object`] """ color = color or self.color _points = map(list, self.primitive.points) lines = [{ 'start': start, 'end': end, 'color': self.color, 'name': f"{self.primitive.name}" } for start, end in self.primitive.lines] objects = compas_blender.draw_lines(lines, collection=self.collection) if show_points: points = [{ 'pos': point, 'name': f"{self.primitive.name}.point", 'color': color, 'radius': 0.01 } for point in _points] objects += compas_blender.draw_points(points, collection=self.collection) return objects
def draw(self, color: Optional[RGBColor] = None, show_points: Optional[bool] = False) -> List[bpy.types.Object]: """Draw the line. Parameters ---------- color : tuple of float or tuple of int, optional The RGB color of the polyline. show_points : bool, optional Show the points of the polyline. Default is ``False``. Returns ------- list of bpy.types.Object """ color = color or self.color _points = map(list, self.primitive.points) lines = [{ 'start': start, 'end': end, 'color': self.color, 'name': f"{self.primitive.name}" } for start, end in self.primitive.lines] objects = compas_blender.draw_lines(lines, collection=self.collection) if show_points: points = [{ 'pos': point, 'name': f"{self.primitive.name}.point", 'color': color, 'radius': 0.01 } for point in _points] objects += compas_blender.draw_points(points, collection=self.collection) return objects
def draw_edges( self, edges: Optional[List[Tuple[int, int]]] = None, color: Optional[Union[str, RGBColor, List[RGBColor], Dict[int, RGBColor]]] = None ) -> List[bpy.types.Object]: """Draw a selection of edges. Parameters ---------- edges : list[tuple[int, int]], optional A list of edge keys (as uv pairs) identifying which edges to draw. The default is None, in which case all edges are drawn. color : rgb-tuple or dict[tuple[int, int], rgb-tuple], optional The color specification for the edges. The default color of edges is :attr:`default_edgecolor`. Returns ------- list[:blender:`bpy.types.Object`] """ self.edge_color = color edges = edges or self.edges lines = [] for edge in edges: lines.append({ 'start': self.vertex_xyz[edge[0]], 'end': self.vertex_xyz[edge[1]], 'color': self.edge_color.get(edge, self.default_edgecolor), 'name': f"{self.mesh.name}.edge.{edge[0]}-{edge[1]}" }) return compas_blender.draw_lines(lines, self.edgecollection)