예제 #1
0
def mesh_draw_vertices(mesh,
                       keys=None,
                       color=None):
    """Draw a selection of vertices of the mesh.

    Parameters
    ----------
    mesh : :class:`compas.datastructures.Mesh`
        A mesh object.
    keys : list (None)
        A list of vertex keys identifying which vertices to draw.
        Default is to draw all vertices.
    color : str, tuple, dict (None)
        The color specififcation for the vertices.
        Colors should be specified in the form of a string (hex colors) or as a tuple of RGB components.
        To apply the same color to all vertices, provide a single color specification.
        Individual colors can be assigned using a dictionary of key-color pairs.
        Missing keys will be assigned the default vertex color (``self.defaults['vertex.color']``).
        Default is use the color of the parent layer.

    Notes
    -----
    The vertices are named using the following template: ``"{mesh.name}.vertex.{id}"``.
    This name can be used afterwards to identify vertices of the mesh in the Rhino model.

    Examples
    --------
    >>>

    """
    artist = MeshArtist(mesh)
    return artist.draw_vertices(keys, color)
예제 #2
0
def mesh_draw(mesh, color=None):
    """
    Draw a mesh object in Rhino.

    Parameters
    ----------
    mesh : compas.datastructures.Mesh
        The mesh object.
    color : str, tuple, list, dict (None)
        The vertex color specification.
        Defaults to None.

    Notes
    -----
    Colors can be specifiedin different ways:

    * str: A hexadecimal color that will be applied to all elements subject to the specification.
    * tuple, list: RGB color that will be applied to all elements subject to the specification.
    * dict: RGB or hex color dict with a specification for some or all of the related elements.

    Notes
    -----
    RGB colors specified as values between 0 and 255, should be integers.
    RGB colors specified as values between 0.0 and 1.0, should be floats.
    """

    artist = MeshArtist(mesh)
    return artist.draw_mesh(color)
예제 #3
0
def mesh_draw_faces(mesh,
                    keys=None,
                    color=None,
                    join_faces=False):
    """Draw a selection of faces of the mesh.

    Parameters
    ----------
    keys : list (None)
        A list of face keys identifying which faces to draw.
        Default is to draw all faces.
    join_faces : bool (False)
        Join the faces into a polymesh object.

    Notes
    -----
    The faces are named using the following template: ``"{mesh.name}.face.{id}"``.

    Examples
    --------
    >>>

    """
    artist = MeshArtist(mesh)
    return artist.draw_faces(keys, color, join_faces)
예제 #4
0
    def to_rgmesh(self):
        """Convert to :class:`Rhino.Geometry.Mesh`

        Returns
        -------
        :class:`Rhino.Geometry.Mesh`
        """
        artist = MeshArtist(self)
        return artist.draw_mesh()
 def grasshopper_draw(self):
     visualisations = []
     for woodLayer in self.timberboards:
         for board in woodLayer:
             my_box = board.box
             mesh_box = Mesh.from_shape(my_box)
             artist = MeshArtist(mesh_box)
             box_visualisation = artist.draw_mesh()
             visualisations.append(box_visualisation)
     return visualisations
    def grasshopper_draw():
        visualisations = []
        for brd in self.elements():
            board = brd[1]

            # visualise all the boards
            my_box = box_update(board)[1]
            mesh_box = Mesh.from_shape(my_box)
            artist = MeshArtist(mesh_box)
            box_visualisation = artist.draw_mesh()
            visualisations.append(box_visualisation)

        return visualisations
예제 #7
0
def load_slicer(path, folder_name, json_name):
    """ Loads slicer data. """
    data = load_json_file(path, folder_name, json_name)

    mesh = None
    paths_nested_list = []
    are_closed = []
    all_points = []

    if data:

        if 'mesh' in data:
            compas_mesh = Mesh.from_data(data['mesh'])
            artist = MeshArtist(compas_mesh)
            mesh = artist.draw()
        else:
            print('No mesh has been saved in the json file.')

        if 'layers' in data:
            layers_data = data['layers']

            for i in range(len(layers_data)):
                paths_nested_list.append(
                    [])  # save each layer on a different list
                layer_data = layers_data[str(i)]
                paths_data = layer_data['paths']

                for j in range(len(paths_data)):
                    path_data = paths_data[str(j)]
                    pts = []

                    are_closed.append(path_data['is_closed'])

                    if len(path_data['points']
                           ) > 2:  # ignore smaller curves that throw errors
                        for k in range(len(path_data['points'])):
                            pt = path_data['points'][str(k)]
                            pt = rs.AddPoint(pt[0], pt[1],
                                             pt[2])  # re-create points
                            pts.append(pt)
                        all_points.extend(pts)
                        path = rs.AddPolyline(pts)
                        paths_nested_list[-1].append(path)
        else:
            print(
                'No layers have been saved in the json file. Is this the correct json?'
            )

    print('The slicer contains %d layers. ' % len(paths_nested_list))
    paths_nested_list = list_to_ghtree(paths_nested_list)
    return mesh, paths_nested_list, are_closed, all_points
def grasshopper_draw(system):
    def box_update(elmnt):
        elmnt.board_frame = Frame(elmnt.centre_point, elmnt.length_vector, elmnt.width_vector)
        elmnt.box = Box(elmnt.board_frame, elmnt.length, elmnt.width, elmnt.height)
        return elmnt.board_frame, elmnt.box

    visualisations = []
    for brd in system.elements():
        board = brd[1]
        # visualise all the boards
        my_box = box_update(board)[1]
        mesh_box = Mesh.from_shape(my_box)
        artist = MeshArtist(mesh_box)
        box_visualisation = artist.draw_mesh()
        visualisations.append(box_visualisation)

    return visualisations
예제 #9
0
def load_multiple_meshes(starts_with, ends_with, path, folder_name):
    """ Load all the meshes that have the specified name, and print them in different colors. """
    filenames = get_files_with_name(starts_with, ends_with,
                                    os.path.join(path, folder_name, 'output'))
    meshes = [
        Mesh.from_obj(os.path.join(path, folder_name, 'output', filename))
        for filename in filenames
    ]

    loaded_meshes = []
    for i, m in enumerate(meshes):
        artist = MeshArtist(m)
        color = get_color(i, total=len(meshes))
        mesh = artist.draw(color)
        loaded_meshes.append(mesh)

    return loaded_meshes
예제 #10
0
파일: code.py 프로젝트: xarthurx/compas_fab
    def RunScript(self, robot, group, configuration, attached_collision_meshes,
                  show_visual, show_collision, show_frames, show_base_frame,
                  show_end_effector_frame, show_acm):

        visual = None
        collision = None
        attached_meshes = None
        frames = None
        base_frame = None
        ee_frame = None

        if robot:
            show_visual = True if show_visual is None else show_visual
            configuration = configuration or robot.zero_configuration()

            robot.update(configuration,
                         visual=show_visual,
                         collision=show_collision)
            compas_frames = robot.transformed_frames(configuration, group)

            if show_visual:
                visual = robot.artist.draw_visual()

            if show_collision:
                collision = robot.artist.draw_collision()

            if show_base_frame:
                base_compas_frame = compas_frames[0]
                artist = FrameArtist(base_compas_frame)
                base_frame = artist.draw()

            if show_end_effector_frame:
                ee_compas_frame = robot.forward_kinematics(
                    configuration, group, options=dict(solver='model'))
                artist = FrameArtist(ee_compas_frame)
                ee_frame = artist.draw()

            if show_frames:
                frames = []
                for compas_frame in compas_frames[1:]:
                    artist = FrameArtist(compas_frame)
                    frame = artist.draw()
                    frames.append(frame)

            if show_acm:
                attached_meshes = []
                for acm in attached_collision_meshes:
                    frame = robot.forward_kinematics(configuration,
                                                     options=dict(
                                                         solver='model',
                                                         link=acm.link_name))
                    T = Transformation.from_frame_to_frame(
                        acm.collision_mesh.frame, frame)
                    mesh = acm.collision_mesh.mesh.transformed(T)
                    attached_meshes.append(MeshArtist(mesh).draw())

        return (visual, collision, attached_meshes, frames, base_frame,
                ee_frame)
예제 #11
0
    def get_rgmesh(self, face_count=18):
        """Generate mesh representation of bullet with custom resolution.

        Parameters
        ----------
        face_count : :class:`int`, optional
            Desired number of faces, by default 18
            Used as a guide for the resolution of the mesh cylinder

        Returns
        -------
        :class:`Rhino.Geometry.Mesh`
        """
        mesh = self.get_cgmesh(face_count=face_count)
        # to Rhino.Geometry and clean it up
        rgmesh = MeshArtist(mesh).draw_mesh()
        rgmesh.UnifyNormals()
        rgmesh.Normals.ComputeNormals()

        return rgmesh
예제 #12
0
def mesh_draw_edges(mesh, keys=None, color=None):
    """Draw a selection of edges of the mesh.

    Parameters
    ----------
    keys : list
        A list of edge keys (as uv pairs) identifying which edges to draw.
        Default is to draw all edges.

    Notes
    -----
    All edges are named using the following template:
    ``"{}.edge.{}-{}".fromat(self.mesh.attributes['name'], u, v)``.

    Examples
    --------
    >>> mesh_draw_edges(mesh)
    >>> mesh_draw_edges(mesh, keys=mesh.edges_on_boundary())

    """
    artist = MeshArtist(mesh)
    return artist.draw_edges(keys, color)
예제 #13
0
 def receive_mesh(message):
     mesh_message = Mesh.from_msg(message)
     artist = MeshArtist(mesh_message.mesh)
     sc.doc = Rhino.RhinoDoc.ActiveDoc
     sc.doc.Objects.AddMesh(artist.draw())
     sc.doc = ghdoc
예제 #14
0
# Ghpython
import compas
from compas.datastructures import Mesh
from compas_ghpython.artists import MeshArtist

mesh = Mesh.from_obj(compas.get('hypar.obj'))

artist = MeshArtist(mesh)
a = artist.draw()
예제 #15
0
from __future__ import print_function
from __future__ import division

from compas.datastructures import Mesh
from compas.datastructures import mesh_subdivide

from compas_ghpython.artists import MeshArtist

# make a control mesh
mesh = Mesh.from_polyhedron(6)

# set default vertex attributes
mesh.update_default_vertex_attributes({'is_fixed': False})

# make an artist for drawing
artist = MeshArtist(mesh)

# draw the control mesh into outputs P, L
P = artist.draw_vertices()
L = artist.draw_edges()

# keep some of the vertices fixed and make a subd mesh (using catmullclark)
for key, value in zip(range(len(is_fixed)), is_fixed):
    mesh.set_vertex_attribute(key, 'is_fixed', value)

fixed = mesh.vertices_where({'is_fixed': True})
subd = mesh_subdivide(mesh, scheme='catmullclark', k=k, fixed=fixed)

# pass the new mesh to the artist
artist.mesh = subd
예제 #16
0
    def get_rgmesh(self, face_count=18):
        """Generate mesh representation of bullet with custom resolution.

        Parameters
        ----------
        face_count : :class:`int`, optional
            Desired number of faces, by default 18
            Used as a guide for the resolution of the mesh cylinder

        Returns
        -------
        :class:`Rhino.Geometry.Mesh`
        """
        import Rhino.Geometry as rg

        if face_count < 6:
            sides = 3
        elif face_count < 15:
            sides = 4
        else:
            sides = face_count // 3

        circle = self.get_rgcircle()

        polygons = []
        polygons.append(rg.Polyline.CreateInscribedPolygon(circle, sides))

        T = rg.Transform.Translation(circle.Normal *
                                     -self.get_compressed_height())

        second_polygon = polygons[0].Duplicate()
        second_polygon.Transform(T)

        polygons.append(second_polygon)

        mesh = cg_Mesh()
        outer_verts_polygons = []

        # generate verts at polygon corners
        for polygon in polygons:
            _temp_list = []

            polygon_corners = list(polygon.Item)
            polygon_corners.pop()  # remove end pt since == start pt

            for pt in polygon_corners:
                _temp_list.append(mesh.add_vertex(x=pt.X, y=pt.Y, z=pt.Z))
            outer_verts_polygons.append(_temp_list)

        polygon_faces = []
        for vkeys in outer_verts_polygons:
            polygon_faces.append(mesh.add_face(vkeys))

        # if >4 sides polygon, create faces by tri subd
        if sides > 4:

            centroid_verts = []
            for fkey in polygon_faces:
                x, y, z = mesh.face_centroid(fkey)
                centroid_verts.append(mesh.add_vertex(x=x, y=y, z=z))
                mesh.delete_face(fkey)

            # create new faces
            for vkeys, ckey in zip(outer_verts_polygons, centroid_verts):
                for i, vkey in enumerate(vkeys):
                    next_vkey = wrap_list(vkeys, i + 1)
                    mesh.add_face([ckey, vkey, next_vkey])

        # generate faces between polygons
        vertex_for_vertex = zip(*outer_verts_polygons)

        for i, mirror_corners_1 in enumerate(vertex_for_vertex):
            mirror_corners_2 = wrap_list(vertex_for_vertex, i + 1)
            mesh.add_face(mirror_corners_1 + mirror_corners_2[::-1])

        # to Rhino.Geometry and clean it up
        rgmesh = MeshArtist(mesh).draw_mesh()
        rgmesh.UnifyNormals()
        rgmesh.Normals.ComputeNormals()

        return rgmesh
예제 #17
0
 def draw(self):
     from compas_ghpython.artists import MeshArtist
     for vkey, element in self.assembly.elements():
         artist = MeshArtist(element.mesh)
         yield artist.draw_mesh()
def cgmesh_to_rgmesh(mesh):
    artist = MeshArtist(mesh)

    return artist.draw_mesh()