Пример #1
0
def RunCommand(is_interactive):

    #load Derivation and model
    derivation = Derivation.from_json(
        rhino_UI_utilities.get_json_file_location())
    model = derivation.get_next_step()

    #user input
    rc, corners = Rhino.Input.RhinoGet.GetRectangle()
    if rc != Rhino.Commands.Result.Success:
        return rc
    plane = Rhino.Geometry.Plane(corners[0], corners[1], corners[2])
    beam_frame = Frame(plane[0], plane[1], plane[2])
    length = rs.GetReal("length", 4000, 300, None)

    #Generate unique name for the Beam
    name = create_id()

    #Create Beam
    model.rule_create_beam(beam_frame, length, 100, 100, name)

    #Save Derivation (Model is also saved)
    derivation.to_json(rhino_UI_utilities.get_json_file_location(),
                       pretty=True)

    #Visualization
    artist = MeshArtist(None, layer='BEAM::Beams_out')
    artist.clear_layer()
    for beam in model.beams:
        artist = MeshArtist(
            beam.mesh, layer='BEAM::Beams_out'
        )  #.mesh is not ideal fix in beam and assemble class
        artist.draw_faces(join_faces=True)
    return 0
def RunCommand(is_interactive):

    #load Derivation and delete last step
    derivation = Derivation.from_json(rhino_UI_utilities.get_json_file_location())

    continue_playback = True
    step_id = 0 
    while(continue_playback):
        #ask user for which step they would like to see
        derivation_last_step_index = derivation.count - 1
        
        step_id = rs.GetInteger("Enter which step to visualize (0 - "+ str(derivation_last_step_index) + " step) (Enter -1 for last step)", step_id, -1, derivation_last_step_index)
        if (step_id == -1): step_id = derivation_last_step_index
        if (step_id == None): break # Allow user to quite the command

        #load the selected model
        model = derivation.get_step(step_id)
        step_id = step_id + 1

        #Visualization 
        artist = MeshArtist(None, layer ='BEAM::Beams_out')
        artist.clear_layer()
        for beam in model.beams:
            artist = MeshArtist(beam.mesh, layer ='BEAM::Beams_out')
            artist.draw_faces(join_faces=True)
        artist.redraw()           
Пример #3
0
def RunCommand(is_interactive):
    """Interactive Rhino Command Creates 90 Lap joint on a seleceted Beam 

    Return:
    ------
    None
    """
    #load Derivation and model
    derivation = Derivation.from_json(rhino_UI_utilities.get_json_file_location())
    model = derivation.get_next_step()

    #Select mesh 
    Obj_ref = rs.GetObject(message = "select mesh(es)", filter = 32, preselect = False, subobjects = True)
    selected_beam_name = (rs.ObjectName(Obj_ref)[:-5])

    #Loop through all beams in model to identify the selected beam
    selected_beam = None
    for beam in model.beams:
        if(beam.name == selected_beam_name):
            selected_beam = beam
            break
    assert (selected_beam != None)

    #list of user inputs(face needs to be implemented through UI)
    face_id = rs.GetInteger("face_id",None,0,5)
    helper = UI_helpers()
    joint_point = helper.Get_SelectPointOnMeshEdge("Select mesh edge","Pick point on edge")

    ext_start = rs.GetReal("extension start ",200,None,None)
    ext_end = rs.GetReal("extension end ",200,None,None)
    name = create_id() 
    
    #adding joints to selected Beam 
    #joint_distance_from_start = Get_distancefromBeamYZFrame(selected_beam,joint_point)
    joint_distance_from_start = selected_beam.Get_distancefromBeamYZFrame(joint_point)
    match_beam_origin =  model.rule_90lap(selected_beam,joint_distance_from_start,face_id,ext_start,ext_end,name) 
     


    #Save Derivation (Model is also saved)
    derivation.to_json(rhino_UI_utilities.get_json_file_location(), pretty = True)

    #Visualization
    viz_point = []
    for pt in match_beam_origin:
        a = (pt[0],pt[1],pt[2])
        viz_point.append({
            'pos': a,
            'color': (0,255,0)
        })


    #Visualization 
    artist = MeshArtist(None, layer ='BEAM::Beams_out')
    artist.clear_layer()
    artist.draw_points(viz_point)
    for beam in model.beams:
        artist = MeshArtist(beam.mesh, layer ='BEAM::Beams_out')#.mesh is not ideal fix in beam and assemble class
        artist.draw_faces(join_faces=True)
Пример #4
0
def mesh_draw_vertices(mesh,
                       keys=None,
                       color=None,
                       layer=None,
                       clear_layer=False,
                       clear_vertices=False,
                       redraw=True):
    """Draw a selection of vertices of the mesh.

    Parameters
    ----------
    mesh : 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.
    layer : str (None)
        The layer in which the vertices are drawn.
        Default is to draw in the current layer.
    clear_layer : bool (False)
        Clear the drawing layer.
    redraw : bool (True)
        Redraw the view after adding the vertices.

    Notes
    -----
    The vertices are named using the following template:
    ``"{}.vertex.{}".format(self.mesh.attributes['name'], key)``.
    This name is used afterwards to identify vertices of the meshin the Rhino model.

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

    """
    artist = MeshArtist(mesh)
    artist.layer = layer

    if clear_layer:
        artist.clear_layer()

    if clear_vertices:
        artist.clear_vertices()

    guids = artist.draw_vertices(color=color)

    if redraw:
        artist.redraw()

    return guids
Пример #5
0
def mesh_draw_edges(mesh,
                    keys=None,
                    color=None,
                    layer=None,
                    clear_layer=False,
                    redraw=True):
    """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.
    color : str, tuple, dict
        The color specififcation for the edges.
        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 faces, provide a single color specification.
        Individual colors can be assigned using a dictionary of key-color pairs.
        Missing keys will be assigned the default face color (``self.defaults['face.color']``).
        Default is use the color of the parent layer.
    layer : str (None)
        The layer in which the edges are drawn.
        Default is to draw in the current layer.
    clear_layer : bool (False)
        Clear the drawing layer.
    redraw : bool (True)
        Redraw the view after adding the edges.

    Notes
    -----
    All edges are named using the following template:
    ``"{}.edge.{}-{}".fromat(self.mesh.attributes['name'], u, v)``.
    This name is used afterwards to identify edges of the mesh in the Rhino model.

    Examples
    --------
    >>> mesh_draw_edges(mesh)
    >>> mesh_draw_edges(mesh, color='#ff0000')
    >>> mesh_draw_edges(mesh, color=(255, 0, 0))
    >>> mesh_draw_edges(mesh, keys=mesh.edges_on_boundary())
    >>> mesh_draw_edges(mesh, color={(u, v): '#00ff00' for u, v in mesh.edges_on_boundary()})

    """
    artist = MeshArtist(mesh)
    artist.layer = layer

    if clear_layer:
        artist.clear_layer()

    artist.clear_edges()
    guids = artist.draw_edges(color=color)

    if redraw:
        artist.redraw()

    return guids
def RunCommand(is_interactive):

    #load Derivation and delete last step
    derivation = Derivation.from_json(
        rhino_UI_utilities.get_json_file_location())
    derivation.remove_last_step()
    print("New Derivation step count:", str(derivation.count))
    #load last model
    model = derivation.get_step(derivation.count - 1)

    #Visualization
    artist = MeshArtist(None, layer='BEAM::Beams_out')
    artist.clear_layer()
    for beam in model.beams:
        artist = MeshArtist(beam.mesh, layer='BEAM::Beams_out')
        artist.draw_faces(join_faces=True)

    #Save Derivation (Model is also saved)
    derivation.to_json(rhino_UI_utilities.get_json_file_location(),
                       pretty=True)
Пример #7
0
def main():
    #####################################
    ### NOTE: Run this file in Rhino. ###
    #####################################

    ### --- Load stl
    mesh = Mesh.from_stl(FILE)

    ### --- Get color list
    color_list = get_mesh_face_color_overhang(mesh,
                                              max_angle=85,
                                              mode="adaptive",
                                              infill=False)

    ### --- Create Rhino artist
    artist = MeshArtist(mesh, layer='COMPAS::MeshArtist')
    artist.clear_layer()
    artist.draw_faces(
        color={key: color_list[i]
               for i, key in enumerate(mesh.faces())})
    artist.redraw()
Пример #8
0
import os

from compas.datastructures import Mesh
from compas_rhino.artists import MeshArtist

HERE = os.path.dirname(__file__)

FILE_I = os.path.join(HERE, 'data', 'form.json')
FILE_O = os.path.join(HERE, 'data', 'form_trimesh.json')

form = Mesh.from_json(FILE_I)

form.quads_to_triangles()

form.to_json(FILE_O)

artist = MeshArtist(form, layer="RV2::TriMesh")
artist.clear_layer()
artist.draw_faces(join_faces=True)
Пример #9
0
polylines = []
for points in pointsets:
    points = [Point(*point) for point in points]
    polyline = Polyline(points)
    polylines.append(polyline)

# ==============================================================================
# Visualize
# ==============================================================================

meshartist = MeshArtist(None)

meshartist.mesh = Mesh.from_vertices_and_faces(*A)
meshartist.layer = "CGAL::Intersections::A"
meshartist.clear_layer()
meshartist.draw_faces(join_faces=True, color=hex_to_rgb('#222222'))

meshartist.mesh = Mesh.from_vertices_and_faces(*B)
meshartist.layer = "CGAL::Intersections::B"
meshartist.clear_layer()
meshartist.draw_faces(join_faces=True, color=hex_to_rgb('#888888'))

polylineartist = PolylineArtist(None, layer="CGAL::Intersections::Polylines")
polylineartist.clear_layer()
pointartist = PointArtist(None, layer='CGAL::Intersections::Points')
pointartist.clear_layer()

for polyline in polylines:
    polylineartist.primitive = polyline
    polylineartist.color = hex_to_rgb('#ffffff')
Пример #10
0
def mesh_draw(mesh,
              layer=None,
              clear_layer=False,
              clear_vertices=False,
              clear_faces=False,
              clear_edges=False,
              show_faces=True,
              show_vertices=False,
              show_edges=False,
              vertexcolor=None,
              edgecolor=None,
              facecolor=None):
    """
    Draw a mesh object in Rhino.

    Parameters
    ----------
    mesh : compas.datastructures.Mesh
        The mesh object.
    layer : str (None)
        The layer to draw in.
        Default is to draw in the current layer.
    clear_layer : bool (False)
        Clear the drawing layer.
    show_faces : bool (True)
        Draw the faces.
    show_vertices : bool (False)
        Draw the vertices.
    show_edges : bool (False)
        Draw the edges.
    vertexcolor : str, tuple, list, dict (None)
        The vertex color specification.
        Default is to use the color of the parent layer.
    edgecolor : str, tuple, list, dict (None)
        The edge color specification.
        Default is to use the color of the parent layer.
    facecolor : str, tuple, list, dict (None)
        The face color specification.
        Default is to use the color of the parent layer.

    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)
    artist.layer = layer

    if clear_layer:
        artist.clear_layer()

    if clear_vertices:
        artist.clear_vertices()
    if clear_edges:
        artist.clear_edges()
    if clear_faces:
        artist.clear_faces()

    if show_faces:
        artist.draw_faces(color=facecolor)
    if show_edges:
        artist.draw_edges(color=edgecolor)
    if show_vertices:
        artist.draw_vertices(color=vertexcolor)

    artist.redraw()
def RunCommand(is_interactive):

    #load Derivation and model
    derivation = Derivation.from_json(
        rhino_UI_utilities.get_json_file_location())
    model = derivation.get_next_step()

    #select beams
    selection_reference = []
    selection_reference.append(
        rs.GetObject(message="select start Beam", filter=32, preselect=True))
    selection_reference.extend(
        rs.GetObjects(message="select Beams to connect",
                      filter=32,
                      preselect=True))

    #load helpers
    helper = UI_helpers()

    #name search
    selected_beams = helper.extract_BeambyName(model, selection_reference)

    #check for parallel planes, uses the function above
    start_beam = selected_beams[0]
    beams_to_connect = selected_beams[1:]
    parallel_check = check_for_parallel_vectors(start_beam, beams_to_connect)
    if parallel_check != True:
        raise IndexError('beams are not parallel')
    else:
        print("beams are parallel")

    #check for coplanarity, uses the function above
    coplanar_planes = {}
    face_ids_coplanar_planes = {}
    for i in range(1, 5):
        start_beam_plane = start_beam.face_plane(i).copy()
        start_beam_origin = start_beam_plane.point
        a = get_coplanar_planes(start_beam_plane, start_beam_origin,
                                beams_to_connect)
        if a != False:
            coplanar_planes['' + str(i)] = a[0]
            face_ids_coplanar_planes['' + str(i)] = a[1]
        else:
            pass
    print("face_dictionary here", face_ids_coplanar_planes)
    if len(coplanar_planes.keys()) == 2:
        print("'success", coplanar_planes)
    else:
        raise IndexError('beams are not coplanar')

    #user inputs
    face_id = rs.GetInteger(("possible face connections " + "face_id " +
                             coplanar_planes.keys()[0] + " or face_id " +
                             coplanar_planes.keys()[1]), None, None, None)
    start_point = (helper.Get_SelectPointOnMeshEdge("Select mesh edge",
                                                    "Pick point on edge"))
    ext_start = rs.GetReal("extension length start", 200, None, None)
    ext_end = rs.GetReal("extension length end", 200, None, None)

    #list of coplanar planes extracted from coplanar_planes dict using face_id as key
    coplanar_planes_along_selected_face = []
    coplanar_planes_along_selected_face.append(
        start_beam.face_plane(face_id).copy())
    for key, value in coplanar_planes.items():
        if key == "" + str(face_id):
            coplanar_planes_along_selected_face.extend(value)

    #list of face_ids of coplanar planes
    coplanar_face_ids = []
    coplanar_face_ids.append(face_id)
    for key, value in face_ids_coplanar_planes.items():
        if key == "" + str(face_id):
            coplanar_face_ids.extend(value)

    #intersection points by passing a line from the origin of start beam to the adjacent planes of the coplanar planes of all beams
    points_to_compare = []
    for i in range(len(selected_beams)):
        beam = selected_beams[i]
        start_beam_selected_face_frame = selected_beams[0].face_frame(face_id)
        line_pt_a = start_beam_selected_face_frame.point
        normal = start_beam_selected_face_frame.normal
        line_pt_b = add_vectors(line_pt_a, scale_vector(normal, 0.3))
        line_to_intersect = Line(line_pt_a, line_pt_b)

        face_index = coplanar_face_ids[i]
        adjacent_planes = beam.neighbour_face_plane(face_index)
        for p in adjacent_planes:
            intersection_point = intersection_line_plane(line_to_intersect, p)
            points_to_compare.append(intersection_point)

    viz_pts = []
    #project distance from  points_to_compare to the plane of the start Beam
    distances = []
    start_beam_face_frame = start_beam.face_frame(face_id).copy()
    start_beam_Plane_perpendicular_to_face_id_Plane = Plane(
        start_beam_face_frame.point, start_beam_face_frame.normal)
    viz_pts.append(start_beam_Plane_perpendicular_to_face_id_Plane.point)
    for point in points_to_compare:
        viz_pts.append(point)
        vector = subtract_vectors(
            point, start_beam_Plane_perpendicular_to_face_id_Plane.point)
        distances.append(
            dot_vectors(
                vector,
                start_beam_Plane_perpendicular_to_face_id_Plane.normal))

    #search to find max point
    maximum_distance = max(distances)
    minimum_distance = min(distances)
    beam_length = (maximum_distance - minimum_distance) + ext_start + ext_end
    ext_len = maximum_distance + ext_start

    #project selected point to perpendicular planes of the beams to connect
    if coplanar_planes.keys()[0] == "1" or coplanar_planes.keys()[0] == "3":
        start_beam_perpendicular_plane = start_beam.face_plane(5).copy()

    elif coplanar_planes.keys()[0] == "2" or coplanar_planes.keys()[0] == "4":
        start_beam_perpendicular_plane = start_beam.face_plane(6).copy()

    tol = 1.0e-5
    # tol = 5.0
    perpendicular_plane = []
    for beam in beams_to_connect:
        for i in range(5, 7):
            beam_plane = beam.face_plane(i).copy()
            print("beam_plane", beam_plane)
            angle_check = start_beam_perpendicular_plane.normal.angle(
                beam_plane.normal)
            print("angle", angle_check)
            if (abs(angle_check) - 0) < tol or (abs(angle_check) - 180) < tol:
                perpendicular_plane.append(beam_plane)

    print(perpendicular_plane)
    print(len(perpendicular_plane))
    #project points
    projected_point_list = []
    new_start_point = project_points_plane([start_point],
                                           start_beam_perpendicular_plane)
    projected_point_list.extend(new_start_point)
    for plane in perpendicular_plane:
        new_point = project_points_plane(new_start_point, plane)
        projected_point_list.extend(new_point)

    #list of distance to move joints on match beam
    model.rule_Connect_90lap(selected_beams, projected_point_list,
                             coplanar_face_ids, beam_length, ext_len,
                             create_id())
    print(len(projected_point_list))
    print(projected_point_list)

    #Save Derivation (Model is also saved)
    derivation.to_json(rhino_UI_utilities.get_json_file_location(),
                       pretty=True)

    # Visualization
    viz_point = []
    for pt in projected_point_list:
        a = (pt[0], pt[1], pt[2])
        viz_point.append({'pos': a, 'color': (0, 255, 0)})

    artist = MeshArtist(None, layer='BEAM::Beams_out')
    artist.clear_layer()
    artist.draw_points(viz_point)
    for beam in model.beams:
        artist = MeshArtist(
            beam.mesh, layer='BEAM::Beams_out'
        )  #.mesh is not ideal fix in beam and assemble class
        artist.draw_faces(join_faces=True)
Пример #12
0
        'strip': '09'
    })),
    list(FABRIC.faces_where({
        'panel': 'RING',
        'strip': '10'
    })),
]

STRIPS = SOUTH + SW + WEST + NW + NORTH + RING

# ==============================================================================
# Visualise
# ==============================================================================

ARTIST = MeshArtist(FABRIC, layer="Fabric")
ARTIST.clear_layer()

# INTRADOS

ARTIST.mesh = IDOS

ARTIST.layer = "Fabric::Intrados"

for i, strip in enumerate(STRIPS):
    guid = ARTIST.draw_faces(keys=strip, join_faces=True)
    color = (255, 128, 128) if i % 2 else (255, 0, 0)
    rs.ObjectColor(guid, color)

ARTIST.layer = "Fabric::Normals"
ARTIST.draw_facenormals(color=(255, 0, 0), scale=0.05)
Пример #13
0
unload_modules('mysubdivision')

unload_modules('shapes')

# 2D Subdivision

vertices = [[0.5, 0.0, 0.0], [0.0, 1.0, 0.0], [-0.5, 0.0, 0.0],
            [1.0, 1.0, 0.0]]

faces = [[0, 1, 2], [1, 0, 3]]

my_mesh = Mesh.from_vertices_and_faces(vertices, faces)

artist = MeshArtist(my_mesh, layer="00_my_first mesh")

artist.clear_layer()
artist.draw_vertices()
artist.draw_faces()
artist.draw_edges()
artist.draw_vertexlabels()
artist.draw_facelabels()
artist.draw_edgelabels()

# iterate through the mesh
# for key,attr in my_mesh.vertices(True):
#     print (key, attr['x'], attr['y'], attr['z'])

# for key in my_mesh.faces():
#     print(key)

# for key in my_mesh.edges():
Пример #14
0
"""
width, length, height = 1, 1, 8
box = Box(F, width, length, height)

#create projection
projection_plane = Plane([0, 0, 0], [0, 0, 1])  #world XY plane
P = Projection.from_plane(projection_plane)  #orthogonal projection

print("Projection:\n", P)
"""
CREATE PROJECTED MESH
"""
mesh_01 = Mesh.from_shape(box)
projected_mesh = mesh_01

try:
    projected_mesh.transform(P)
except:
    print("Something went wrong with the projection")
"""
ARTISTS
"""
artist_01 = BoxArtist(box, layer='box')
artist_02 = MeshArtist(mesh_01, layer='box::projection edges')

artist_01.clear_layer()
artist_02.clear_layer()

artist_01.draw()
artist_02.draw_edges(color="#00ff00")