Beispiel #1
0
def load_session(session):
    print("loading session")
    scene = get_scene()
    scene.clear()
    if 'settings' in session:
        scene.settings = session['settings']
    if 'data' in session:
        data = session['data']
        if 'pattern' in data and data['pattern']:
            pattern = Pattern.from_data(data['pattern'])
            scene.add(pattern, name="pattern")
        else:
            if 'form' in data and data['form']:
                form = FormDiagram.from_data(data['form'])
                thrust = form.copy(
                    cls=ThrustDiagram)  # this is not a good idea
                scene.add(form, name="form")
                scene.add(thrust, name="thrust")

            if 'force' in data and data['force']:
                force = ForceDiagram.from_data(data['force'])
                force.primal = form
                form.dual = force
                force.update_angle_deviations()
                scene.add(force, name="force")
    scene.update()
Beispiel #2
0
def RunCommand(is_interactive):
    scene = get_scene()
    if not scene:
        return

    # get untrimmed surface(s) -------------------------------------------------
    guid = compas_rhino.select_surface(
        message='select an untrimmed surface or a polysurface')

    if not guid:
        return

    compas_rhino.rs.HideObjects(guid)

    # make subd object ---------------------------------------------------------
    subdobject = SubdObject.from_guid(guid)

    if not subdobject:
        return

    compas_rhino.rs.HideObjects(guid)
    subdobject.draw_coarse()
    subdobject.get_draw_default_subd()
    subdobject.draw_subd()

    # interactively  modify subdivision ----------------------------------------
    while True:
        menu = CommandMenu(config)
        action = menu.select_action()

        if not action or action is None:
            subdobject.clear()
            print("Pattern from surface(s) aborted!")
            compas_rhino.rs.ShowObjects(guid)
            return

        if action['name'] == 'Finish':
            break

        action['action'](subdobject)

    # make pattern -------------------------------------------------------------
    mesh = subdobject.subd
    xyz = mesh.vertices_attributes('xyz')
    faces = [mesh.face_vertices(fkey) for fkey in mesh.faces()]
    pattern = Pattern.from_vertices_and_faces(xyz, faces)

    # clear skeleton
    layer = subdobject.settings['layer']
    subdobject.clear()
    compas_rhino.delete_layers([layer])

    scene.clear()
    scene.add(pattern, name='pattern')
    scene.update()

    print(
        "Pattern object successfully created. Input surface(s) have been hidden."
    )
def RunCommand(is_interactive):

    scene = get_scene()
    if not scene:
        return

    guids = compas_rhino.select_lines()
    if not guids:
        return

    lines = compas_rhino.get_line_coordinates(guids)
    pattern = Pattern.from_lines(lines, delete_boundary_face=True)

    if not pattern.face:
        print("No faces found! Pattern object was not created.")
        return

    compas_rhino.rs.HideObjects(guids)

    scene.clear()
    scene.add(pattern, name='pattern')
    scene.update()

    print("Pattern object successfully created.")
def RunCommand(is_interactive):
    scene = get_scene()
    if not scene:
        return

    proxy = get_proxy()
    if not proxy:
        return

    delaunay = proxy.function('compas.geometry.delaunay_from_points_numpy')

    # Get input data.
    surf_guid = compas_rhino.select_surface("Select a surface to decompose.")
    if not surf_guid:
        return
    point_guids = compas_rhino.select_points(
        "Select points to include in the decomposition.")
    curve_guids = []

    compas_rhino.rs.HideObjects([surf_guid] + point_guids + curve_guids)

    surface = RhinoSurface.from_guid(surf_guid)
    curves = [RhinoCurve.from_guid(guid) for guid in curve_guids]
    points = [RhinoPoint.from_guid(guid) for guid in point_guids]

    # Compute the feature discretisation length.
    box = compas_rhino.rs.BoundingBox([surf_guid])
    diagonal = compas_rhino.rs.Distance(box[0], box[6])
    D = 0.05 * diagonal

    # Get the target length for the final quad mesh.
    L = compas_rhino.rs.GetReal(
        "Define the target edge length of the pattern.", 1.0)

    # Generate the pattern
    pattern = Pattern.from_surface_and_features(D,
                                                L,
                                                surf_guid,
                                                curve_guids,
                                                point_guids,
                                                delaunay=delaunay)

    scene.clear()
    scene.add(pattern, name='pattern')
    scene.update()

    kmax = 10

    # Constrain mesh components to the feature geometry.
    constraints = automated_smoothing_surface_constraints(pattern, surface)
    constraints.update(
        automated_smoothing_constraints(pattern,
                                        rhinopoints=points,
                                        rhinocurves=curves))

    while True:
        option = compas_rhino.rs.GetString("Smoothen the pattern?", "No",
                                           ["Yes", "No"])
        if not option:
            break
        if option != "Yes":
            break

        constrained_smoothing(pattern,
                              kmax=kmax,
                              damping=0.5,
                              constraints=constraints,
                              algorithm="area")
        scene.update()

    print('Pattern object successfully created. Input object has been hidden.')
def RunCommand(is_interactive):
    scene = get_scene()
    if not scene:
        return

    # skeleton from single point or a set of lines
    guids_temp = compas_rhino.rs.GetObjects(
        message="Select a single point or a group of lines",
        filter=compas_rhino.rs.filter.point | compas_rhino.rs.filter.curve)

    if not guids_temp:
        return

    # detect input object type
    guids_points = []
    guids_lines = []
    for guid in guids_temp:
        if is_curve_line(guid):
            guids_lines.append(guid)

        if compas_rhino.rs.IsPoint(guid):
            guids_points.append(guid)

    if len(guids_points) == 1 and len(guids_lines) == 0:
        guids = guids_points
        point = compas_rhino.get_point_coordinates(guids)[0]
        skeleton = Skeleton.from_center_point(point)

    elif len(guids_points) == 0 and len(guids_lines) > 0:
        guids = guids_lines
        lines = compas_rhino.get_line_coordinates(guids)
        skeleton = Skeleton.from_skeleton_lines(lines)

    if not skeleton:
        return

    compas_rhino.rs.HideObjects(guids)
    skeletonobject = SkeletonObject(skeleton)
    skeletonobject.draw()
    skeletonobject.dynamic_draw_widths()

    # modify skeleton
    while True:
        menu = CommandMenu(config)
        action = menu.select_action()
        if not action:
            return

        if action['name'] == 'Finish':
            break

        action['action'](skeletonobject)
        skeletonobject.draw()

    # make pattern
    mesh = skeletonobject.skeleton.to_mesh()
    xyz = mesh.vertices_attributes('xyz')
    faces = [mesh.face_vertices(fkey) for fkey in mesh.faces()]
    pattern = Pattern.from_vertices_and_faces(xyz, faces)

    # clear skeleton
    layer = skeletonobject.settings['layer']
    skeletonobject.clear()
    compas_rhino.delete_layers([layer])

    scene.clear()
    scene.add(pattern, name='pattern')
    scene.update()

    print("Pattern object successfully created. Input lines have been hidden.")
def RunCommand(is_interactive):

    scene = get_scene()
    if not scene:
        return

    proxy = get_proxy()
    if not proxy:
        return

    srf_guid = compas_rhino.select_surface("Select a surface.")
    if not srf_guid:
        return

    crv_guids = []
    pt_guids = compas_rhino.select_points(
        "Step 1/3 (Optional) - Select points for pole singularities.") or []

    box = compas_rhino.rs.BoundingBox([srf_guid])
    input_subdivision_spacing = 0.01 * compas_rhino.rs.Distance(box[0], box[6])

    mesh_edge_length = compas_rhino.rs.GetReal(
        "Step 2/3 - Enter target length for edges.", 1.0)

    delaunay = proxy.function(
        "compas.geometry.triangulation.triangulation_numpy.delaunay_from_points_numpy"
    )

    pattern = Pattern.from_surface_and_features(input_subdivision_spacing,
                                                mesh_edge_length, srf_guid,
                                                crv_guids, pt_guids, delaunay)

    scene.clear()
    scene.add(pattern, name='pattern')
    scene.update()

    kmax = 10

    while True:
        option = compas_rhino.rs.GetString(
            "Step 3/3 (Optional) - Press Enter to run constrained Laplacian smoothing or ESC to skip.",
            strings=['Iterations'])

        if option is None:
            break

        if not option:
            constraints = automated_smoothing_surface_constraints(
                pattern, srf_guid)
            constraints.update(
                automated_smoothing_constraints(pattern,
                                                points=pt_guids,
                                                curves=crv_guids))
            constrained_smoothing(pattern,
                                  kmax=kmax,
                                  damping=0.5,
                                  constraints=constraints,
                                  algorithm='area')
            objs = set(constraints.values())
            inputs = [srf_guid] + crv_guids + pt_guids
            for obj in objs:
                if obj not in inputs:
                    compas_rhino.rs.DeleteObject(obj)
            compas_rhino.rs.HideObjects(inputs)
            break

        if option == 'Iterations':
            new_kmax = compas_rhino.rs.GetInteger("Number of iterations:",
                                                  kmax)
            if new_kmax or new_kmax is not None:
                kmax = new_kmax

    scene.update()

    print('Pattern object successfully created. Input object has been hidden.')
Beispiel #7
0
def RunCommand(is_interactive):

    scene = get_scene()
    if not scene:
        return

    proxy = get_proxy()
    if not proxy:
        return

    conforming_delaunay_triangulation = proxy.function(
        'compas.geometry.conforming_delaunay_triangulation')

    boundary_guids = compas_rhino.select_curves('Select outer boundary.')
    if not boundary_guids:
        return

    hole_guids = compas_rhino.select_curves('Select inner boundaries.')
    segments_guids = compas_rhino.select_curves('Select constraint curves.')

    target_length = rs.GetReal('Specifiy target edge length.', 1.0)
    if not target_length:
        return

    gkey_constraints = {}

    # outer boundary
    boundary = []
    for guid in boundary_guids:
        compas_rhino.rs.EnableRedraw(False)
        segments = compas_rhino.rs.ExplodeCurves(guid)
        for segment in segments:
            curve = RhinoCurve.from_guid(segment)
            N = max(int(curve.length() / target_length), 1)
            points = map(list, curve.divide(N, over_space=True))
            for point in points:
                gkey = geometric_key(point)
                if gkey not in gkey_constraints:
                    gkey_constraints[gkey] = []
                gkey_constraints[gkey].append(segment)
            boundary.extend(points)
        compas_rhino.delete_objects(segments, purge=True)
        compas_rhino.rs.EnableRedraw(True)

    # constraint polylines
    polylines = []
    if segments_guids:
        for guid in segments_guids:
            curve = RhinoCurve.from_guid(guid)
            N = int(curve.length() / target_length) or 1
            points = map(list, curve.divide(N, over_space=True))
            for point in points:
                gkey = geometric_key(point)
                if gkey not in gkey_constraints:
                    gkey_constraints[gkey] = []
                gkey_constraints[gkey].append(guid)
            polylines.append(points)

    # hole polygons
    polygons = []
    if hole_guids:
        for guid in hole_guids:
            curve = RhinoCurve.from_guid(guid)
            N = int(curve.length() / target_length) or 1
            points = map(list, curve.divide(N, over_space=True))
            for point in points[:-1]:
                gkey = geometric_key(point)
                if gkey not in gkey_constraints:
                    gkey_constraints[gkey] = []
                gkey_constraints[gkey].append(guid)
            polygons.append(points)

    area = target_length**2 * 0.5 * 0.5 * 1.732

    vertices, faces = conforming_delaunay_triangulation(boundary,
                                                        polylines=polylines,
                                                        polygons=polygons,
                                                        angle=30,
                                                        area=area)
    # vertices, faces = constrained_delaunay_triangulation(boundary, polylines=polylines, polygons=polygons)
    vertices[:] = [[float(x), float(y), float(z)] for x, y, z in vertices]

    pattern = Pattern.from_vertices_and_faces(vertices, faces)

    gkey_key = {
        geometric_key(pattern.vertex_coordinates(key)): key
        for key in pattern.vertices()
    }

    for gkey in gkey_constraints:
        guids = gkey_constraints[gkey]
        if gkey in gkey_key:
            key = gkey_key[gkey]
            if len(guids) > 1:
                pattern.vertex_attribute(key, 'is_fixed', True)
            pattern.vertex_attribute(key, 'constraints',
                                     [str(guid) for guid in guids])

    compas_rhino.rs.HideObject(boundary_guids + hole_guids + segments_guids)

    scene.clear()
    scene.add(pattern, name='pattern')
    scene.update()

    print(
        "Pattern object successfully created. Input geometry have been hidden."
    )