示例#1
0
    def draw_nodes(self, nodes=None, color=None):
        """Draw a selection of nodes.

        Parameters
        ----------
        nodes : list of int, optional
            A list of node identifiers.
            Default is ``None``, in which case all nodes are drawn.
        color : rgb-tuple or dict of rgb-tuples
            The color specififcation for the nodes.

        Returns
        -------
        list of :class:`bpy.types.Object`

        """
        nodes = nodes or list(self.network.nodes())
        node_color = colordict(color, nodes, default=self.color_nodes)
        points = []
        for node in nodes:
            points.append({
                'pos': self.network.node_coordinates(node),
                'name': f"{self.network.name}.node.{node}",
                'color': node_color[node],
                'radius': 0.05
            })
        objects = compas_blender.draw_points(points, self.nodecollection)
        self.object_node = zip(objects, nodes)
        return objects
示例#2
0
    def draw_vertices(
        self,
        vertices: Optional[List[int]] = None,
        color: Optional[Union[str, RGBColor, List[RGBColor],
                              Dict[int, RGBColor]]] = None
    ) -> List[bpy.types.Object]:
        """Draw a selection of vertices.

        Parameters
        ----------
        vertices : list
            A list of vertex keys identifying which vertices to draw.
            Default is ``None``, in which case all vertices are drawn.
        color : rgb-tuple or dict of rgb-tuple
            The color specification for the vertices.

        Returns
        -------
        list of :class:`bpy.types.Object`
        """
        self.vertex_color = color
        vertices = vertices or self.vertices
        points = []
        for vertex in vertices:
            points.append({
                'pos':
                self.vertex_xyz[vertex],
                'name':
                f"{self.mesh.name}.vertex.{vertex}",
                'color':
                self.vertex_color.get(vertex, self.default_vertexcolor),
                'radius':
                0.01
            })
        return compas_blender.draw_points(points, self.vertexcollection)
示例#3
0
    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
示例#4
0
    def draw_vertices(self, vertices=None, color=None):
        """Draw a selection of vertices.

        Parameters
        ----------
        vertices : list
            A list of vertex keys identifying which vertices to draw.
            Default is ``None``, in which case all vertices are drawn.
        color : rgb-tuple or dict of rgb-tuple
            The color specififcation for the vertices.

        Returns
        -------
        list of :class:`bpy.types.Object`

        """
        vertices = vertices or list(self.mesh.vertices())
        vertex_color = colordict(color, vertices, default=self.color_vertices)
        points = []
        for vertex in vertices:
            points.append({
                'pos': self.mesh.vertex_coordinates(vertex),
                'name': f"{self.mesh.name}.vertex.{vertex}",
                'color': vertex_color[vertex],
                'radius': 0.01
            })
        objects = compas_blender.draw_points(points, self.vertexcollection)
        self.object_vertex = zip(objects, vertices)
        return objects
示例#5
0
    def draw_nodes(self,
                   nodes: Optional[List[int]] = None,
                   color: Optional[Union[str, RGBColor, List[RGBColor], Dict[int, RGBColor]]] = None
                   ) -> List[bpy.types.Object]:
        """Draw a selection of nodes.

        Parameters
        ----------
        nodes : list of int, optional
            A list of node identifiers.
            Default is ``None``, in which case all nodes are drawn.
        color : rgb-tuple or dict of rgb-tuples
            The color specification for the nodes.

        Returns
        -------
        list of :class:`bpy.types.Object`

        """
        self.node_color = color
        nodes = nodes or self.nodes
        points = []
        for node in nodes:
            points.append({
                'pos': self.node_xyz[node],
                'name': f"{self.network.name}.node.{node}",
                'color': self.node_color.get(node, self.default_nodecolor),
                'radius': 0.05
            })
        return compas_blender.draw_points(points, self.nodecollection)
示例#6
0
    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
示例#7
0
    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
示例#8
0
    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
示例#9
0
    def draw_origin(self) -> List[bpy.types.Object]:
        """Draw the origin of the frame.

        Returns
        -------
        list of :class:`bpy.types.Object`
        """
        points = [{
            'pos': self.primitive.point,
            'name': f"{self.primitive.name}.origin",
            'color': self.color_origin,
            'radius': 0.01
        }]
        return compas_blender.draw_points(points, self.collection)
示例#10
0
    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
示例#11
0
    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
示例#12
0
    def draw(self, color: Optional[RGBColor] = None) -> List[bpy.types.Object]:
        """Draw the point.

        Returns
        -------
        list of :class:`bpy.types.Object`
        """
        color = color or self.color
        points = [{
            'pos': self.primitive,
            'name': f"{self.primitive.name}",
            'color': color,
            'radius': 0.01
        }]
        objects = compas_blender.draw_points(points, self.collection)
        return objects
示例#13
0
 def draw_nodes(self, nodes=None, color=None):
     """Draw the blocks of the assembly.
     """
     nodes = nodes or list(self.assembly.nodes())
     node_color = colordict(color, nodes, default=self.color_nodes)
     points = []
     for node in nodes:
         block = self.assembly.node_attribute(node, 'block')
         points.append({
             'pos': block.centroid(),
             'name': f"{self.assembly.name}.node.{node}",
             'color': node_color[node],
             'radius': 0.05})
     objects = compas_blender.draw_points(points, self.nodecollection)
     self.object_node = zip(objects, nodes)
     return objects
 def draw_resultants(self, scale=1.0, eps=1e-3):
     """
     """
     edges = list(self.assembly.edges())
     scale = scale or self.scale_forces
     eps = eps or self.eps_forces
     eps2 = eps**2
     points = []
     for edge in edges:
         u, v = edge
         interface = self.assembly.edge_attribute(edge, 'interface')
         corners = interface.points
         forces = interface.forces
         if not forces:
             continue
         cx, cy, cz = 0, 0, 0
         R = 0
         for point, force in zip(corners, forces):
             c = force['c_np']
             t = force['c_nn']
             f = c - t
             cx += point[0] * f
             cy += point[1] * f
             cz += point[2] * f
             R += f
         if R**2 < eps2:
             continue
         cx = cx / R
         cy = cy / R
         cz = cz / R
         c = [cx, cy, cz]
         if R < 0:
             color = self.color_tension
             radius = -R * scale
         else:
             color = self.color_compression
             radius = +R * scale
         points.append({
             'pos': c,
             'radius': radius,
             'color': color,
             'name': f"POA.{u}-{v}"
         })
     objects = compas_blender.draw_points(points, self.resultantcollection)
     self.object_resultant = zip(objects, edges)
示例#15
0
    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
示例#16
0
    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
示例#17
0
    def draw(self, color: Optional[RGBColor] = None) -> List[bpy.types.Object]:
        """Draw the point.

        Parameters
        ----------
        color : tuple[float, float, float] or tuple[int, int, int], optional
            Color of the point object.
            The default color is :attr:`compas.artists.PrimitiveArtist.color`.

        Returns
        -------
        list[:blender:`bpy.types.Object`]

        """
        color = color or self.color
        points = [{
            'pos': self.primitive,
            'name': f"{self.primitive.name}",
            'color': color,
            'radius': 0.01
        }]
        objects = compas_blender.draw_points(points, self.collection)
        return objects