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."
    )
Exemple #2
0
def from_surface(root):
    # add option for uv versus heighfield?
    # add option for patches?
    guid = compas_rhino.select_surface()
    if not guid:
        return
    form = FormDiagram.from_rhinosurface(guid)
    return form
def RunCommand(is_interactive):

    scene = get_scene()
    if not scene:
        return

    guid = compas_rhino.select_surface()
    if not guid:
        return

    u = PatternObject.SETTINGS['from_surface.density.U']
    v = PatternObject.SETTINGS['from_surface.density.V']

    options = ['U', 'V']
    while True:
        option = compas_rhino.rs.GetString("Enter values for U and V:",
                                           strings=options)

        if not option:
            break

        if option == 'U':
            u = compas_rhino.rs.GetInteger("Density U", u, 2, 100)
            continue
        if option == 'V':
            v = compas_rhino.rs.GetInteger("Density V", v, 2, 100)
            continue

    density = u + 1, v + 1
    pattern = RhinoSurface.from_guid(guid).uv_to_compas(cls=Pattern,
                                                        density=density)

    compas_rhino.rs.HideObject(guid)

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

    print(
        "Pattern object successfully created. Input surface has been hidden.")
Exemple #4
0
            point = self.closest_point(xyz)
            dx, dy, dz = subtract_vectors(point, xyz)
            mesh.vertex[key]['x'] += d * dx
            mesh.vertex[key]['y'] += d * dy
            mesh.vertex[key]['z'] += d * dz


# ==============================================================================
# Debugging
# ==============================================================================

if __name__ == '__main__':

    import compas_rhino

    guid = compas_rhino.select_surface()

    surface = RhinoSurface(guid)

    points = []
    for xyz in surface.heightfield():
        points.append({
            'pos': xyz,
            'name': 'heightfield',
            'color': (0, 255, 0),
        })

    compas_rhino.xdraw_points(points,
                              layer='Layer 01',
                              clear=True,
                              redraw=True)
Exemple #5
0
 def from_selection(cls):
     guid = compas_rhino.select_surface()
     return cls.from_guid(guid)
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.')
Exemple #7
0
from compas.datastructures import Mesh

from compas.geometry import planarize_faces
from compas.geometry import flatness

__author__ = [
    'Tom Van Mele',
]
__copyright__ = 'Copyright 2016 - Block Research Group, ETH Zurich'
__license__ = 'MIT License'
__email__ = '*****@*****.**'

# select an input surface and convert it to a mesh

guid = compas_rhino.select_surface('Select an input surface.')
mesh = compas_rhino.mesh_from_surface_heightfield(Mesh, guid, density=(20, 10))

# create a surface constraint

surf = RhinoSurface(guid)

# vertices and faces

key_index = mesh.key_index()

vertices_0 = mesh.get_vertices_attributes('xyz')
vertices_1 = deepcopy(vertices_0)

faces = [[key_index[key] for key in mesh.face_vertices(fkey)]
         for fkey in mesh.faces()]
Exemple #8
0
def create_cablenet_from_surface(settings):
    guid = compas_rhino.select_surface()
    if not guid:
        return
    cablenet = Cablenet.from_rhinosurface(guid)
    return cablenet
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.')

def callback(mesh, k, args):
    conduit, surf, fixed = args

    # pull the not fixed points back to the target surface
    surf.pull_mesh(mesh, fixed=fixed)

    # update the conduit
    conduit.redraw(k)


guid = rhino.select_mesh()
mesh = rhino.mesh_from_guid(Mesh, guid)

guid = rhino.select_surface()
surf = RhinoSurface(guid)

fixed = mesh.vertices_on_boundary()

conduit = MeshConduit(mesh, color=(255, 255, 255), refreshrate=2)

with conduit.enabled():
    smooth_mesh_area(mesh,
                     fixed,
                     kmax=100,
                     callback=callback,
                     callback_args=(conduit, surf, fixed))

rhino.draw_mesh(mesh)