Exemple #1
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

    # 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.")
Exemple #3
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."
    )