Beispiel #1
0
            if (a, b) in edges or (b, a) in edges:
                break

            edges.append((a, b))

    return edges


if __name__ == '__main__':

    crvs = rs.GetObjects("Select mesh edges", 4)
    lines = get_line_coordinates(crvs)

    mesh = Mesh.from_lines(lines, delete_boundary_face=True)

    artist = MeshArtist(mesh, layer='new_lines')
    artist.draw_edges()
    artist.redraw()

    # select edge
    rs.HideObjects(crvs)
    edge = mesh_select_edge(mesh, "select a mesh edge")
    rs.ShowObjects(crvs)

    # select edge
    artist.clear_edges()

    # find "every second" edge (joint lines)
    new_lines = []

    para_edges = get_parallel_edges(mesh, edge)
# ==============================================================================

if __name__ == "__main__":

    import time

    from compas.datastructures.mesh import Mesh
    from compas.geometry.elements import Polyhedron

    from compas_rhino.artists.meshartist import MeshArtist

    poly = Polyhedron.generate(12)

    mesh = Mesh.from_vertices_and_faces(poly.vertices, poly.faces)

    artist = MeshArtist(mesh, layer='MeshArtist')

    artist.clear_layer()

    artist.draw_vertices()
    artist.redraw()
    time.sleep(2.0)

    artist.draw_faces()
    artist.redraw()
    time.sleep(2.0)

    artist.draw_edges()
    artist.redraw()
    time.sleep(2.0)
                "message": "Select (ESC to exit)",
                "default": "openings",
                "show": None,
                "ID": "interface_1"
            }

            flag = command_line_menu(interface_1)

            if flag == "openings":
                set_openings(mesh)
            elif flag == "triangle_corner":
                if not set_tri_corners(mesh):
                    print "no triangles in mesh"
            elif flag == "target_length":
                trg_len = rs.GetReal("Insert target length: ", trg_len)
                if not trg_len:
                    break
            else:
                break

    coons_mesh = meshes_join([coons_mesh],
                             cull_duplicates=True,
                             precision=precision)
    fixed = coons_mesh.vertices_on_boundary()

    #mesh_smooth_area(coons_mesh, fixed=fixed, kmax=25,damping=0.5)
    #mesh_smooth_centroid(coons_mesh, fixed=fixed, kmax=25,damping=0.5)

    artist = MeshArtist(coons_mesh, layer='form_quad')
    artist.draw()
Beispiel #4
0
        pts_a = [mesh.get_vertex_attribute(key, 'point_a') for key in vertices]
        pts_b = [mesh.get_vertex_attribute(key, 'point_b') for key in vertices]

        # initialize mesh for voussoir
        mesh_v = Mesh()
        # vertices for voussoir
        for pt in pts_a + pts_b:
            x, y, z = pt
            mesh_v.add_vertex(key=geometric_key(pt), x=x, y=y, z=z)

        # side surfaces
        for i, _ in enumerate(pts_a):
            face = [
                geometric_key(pts_a[i - 1]),
                geometric_key(pts_b[i - 1]),
                geometric_key(pts_b[i]),
                geometric_key(pts_a[i])
            ]
            mesh_v.add_face(face)

        # top and bottom surface
        face = [geometric_key(pt) for pt in pts_a]
        mesh_v.add_face(face)
        face = [geometric_key(pt) for pt in pts_b[::-1]]
        mesh_v.add_face(face)

        artist = MeshArtist(mesh_v, layer='voussoir_hex')
        artist.draw_faces(join_faces=True)

    artist.redraw()
Beispiel #5
0
        attr['y'] = y
        attr['z'] = z
        
    conduit.redraw()

if __name__ == '__main__':
    
    guid = rs.GetObject("Select mesh", 32)
    srf = rs.GetObject("Select nurbs srf", 8)
    
    mesh = mesh_from_guid(Mesh,guid)
    fixed = set(mesh.vertices_on_boundary())

    for key in mesh.vertices():
        mesh.set_vertex_attribute(key, 'srf', srf)

    # initialize conduit
    conduit = MeshConduit(mesh, refreshrate=1)

    # run smoothing with conduit
    with conduit.enabled():
        mesh_smooth_centroid(mesh, 
                            fixed=fixed, 
                            kmax=100, 
                            damping=0.5, 
                            callback=callback)
        
    artist = MeshArtist(mesh, layer='relaxed_mesh_on_surface')
    artist.draw()
    
Beispiel #6
0
# ==============================================================================

if __name__ == "__main__":
    
    import os

    from compas.datastructures import Mesh
    from compas.geometry import Polyhedron

    from compas_rhino.artists.meshartist import MeshArtist

    poly = Polyhedron.generate(12)

    mesh = Mesh.from_vertices_and_faces(poly.vertices, poly.faces)

    artist = MeshArtist(mesh)

    artist.clear()

    artist.draw_vertices()
    artist.redraw(0.0)

    artist.draw_vertexlabels()
    artist.redraw(1.0)

    artist.draw_faces()
    artist.redraw(1.0)

    artist.draw_facelabels()
    artist.redraw(1.0)
Beispiel #7
0
    pts = project_points_plane(pts, planes[i])
    pts_uv.append(pts)

# create mesh object
trans_mesh = Mesh()

# add vertices
for u in xrange(len(pts_uv)):
    for v in xrange(len(pts_uv[u])):
        x, y, z = pts_uv[u][v]
        trans_mesh.add_vertex((u, v), x=x, y=y, z=z)

# add faces
for u in xrange(len(pts_uv) - 1):
    for v in xrange(len(pts_uv[u]) - 1):
        trans_mesh.add_face([(u, v), (u + 1, v), (u + 1, v + 1), (u, v + 1)])

artist = MeshArtist(trans_mesh, layer='voussoir_hex')
artist.draw_faces(join_faces=True)

# create fins
#dis = 0.5
#for u, v in trans_mesh.edges():
#    normal_u = trans_mesh.vertex_normal(u)
#    normal_v = trans_mesh.vertex_normal(v)
#    pt1 = trans_mesh.vertex_coordinates(u)
#    pt2 = trans_mesh.vertex_coordinates(v)
#    pt3 = add_vectors(pt2, scale_vector(normal_v, dis))
#    pt4 = add_vectors(pt1, scale_vector(normal_u, dis))
#    rs.AddSrfPt([pt1, pt2, pt3, pt4])
Beispiel #8
0
    # construct delaunay mesh
    faces = delaunay_from_points(points, boundary=points)
    mesh = Mesh.from_vertices_and_faces(points, faces)

    # set fixed vertices
    fixed = set(mesh.vertices_on_boundary())

    #    artist = MeshArtist(mesh, layer='delaunay')
    #    artist.draw_faces(join_faces=True)

    conduit = MeshConduit(mesh, refreshrate=2)

    # run remeshing algorithm
    with conduit.enabled():
        trimesh_remesh(mesh,
                       target=trg_l,
                       kmax=kmax,
                       tol=0.1,
                       divergence=0.01,
                       allow_boundary_split=True,
                       allow_boundary_swap=True,
                       allow_boundary_collapse=False,
                       smooth=True,
                       fixed=fixed,
                       callback=callback,
                       callback_args=[srf])

    artist = MeshArtist(mesh, layer='remeshed')
    artist.draw()
    # check for the right uv tuples. Ordered as in mesh.edges()
    edgeset = set(list(mesh.edges()))
    return [(u, v) if (u, v) in edgeset else (v, u) for u, v in edges]


if __name__ == '__main__':

    edge_crvs = rs.GetObjects("Select edges", 4)
    lines = get_line_coordinates(edge_crvs)
    rs.DeleteObjects(edge_crvs)

    mesh = Mesh.from_lines(lines, delete_boundary_face=True)

    # draw edges for selection
    artist = MeshArtist(mesh, layer='edges')
    artist.draw_edges()
    artist.redraw()

    # select edge
    edges = mesh_select_edges(mesh)

    # clear edges
    artist.clear_edges()

    # find "every second" edge (joint lines)
    joint_lines = []
    for i, uv in enumerate(edges):
        para_edges = get_parallel_edges(mesh, uv)
        for u, v in para_edges[i % 2::2]:
            joint_lines.append((u, v))
Beispiel #10
0
import rhinoscriptsyntax as rs

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

from compas_rhino.utilities import get_line_coordinates
from compas.geometry import mesh_smooth_centroid

if __name__ == '__main__':

    edge_crvs = rs.GetObjects("Select edges", 4)
    lines = get_line_coordinates(edge_crvs)

    mesh = Mesh.from_lines(lines, delete_boundary_face=True)

    fixed = set(mesh.vertices_on_boundary())
    mesh_smooth_centroid(mesh, fixed=fixed, kmax=1, damping=0.5)

    # draw edges for selection
    artist = MeshArtist(mesh, layer='edges_hex')
    artist.draw_edges()
    artist.redraw()
if __name__ == '__main__':

    # select rhino mesh
    guid = rs.GetObject("Select mesh", 32)
    # create compas mesh object from rhino mesh
    mesh = mesh_from_guid(Mesh, guid)

    # set vertices on boundary as fixed
    fixed = set(mesh.vertices_on_boundary())

    # run smoothing
    mesh_smooth_centroid(mesh,
                         fixed=fixed,
                         kmax=100,
                         damping=0.5,
                         callback=None,
                         callback_args=None)

    # draw mesh
    artist = MeshArtist(mesh, layer='relaxed_mesh_laplacian')
    artist.draw()

    mesh_smooth_area(mesh,
                     fixed=fixed,
                     kmax=100,
                     damping=0.5,
                     callback=None,
                     callback_args=None)
    artist = MeshArtist(mesh, layer='relaxed_mesh_area')
    artist.draw()
Beispiel #12
0
            faces[key] = fkeys

    for key, (x, y, z) in vertices.items():
        dual.add_vertex(key, x=x, y=y, z=z)

    for fkey, vertices in faces.items():
        dual.add_face(vertices, fkey=fkey)

    return dual


if __name__ == '__main__':

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

    # call the function from the compas dual_mesh
    # dual_mesh = mesh_dual(mesh)
    compas_rhino.clear_layer('my_dual')

    # make my own dula mesh with edge condition
    dual_mesh = my_mesh_dual(mesh)
    # print(dual_mesh)

    artist = MeshArtist(dual_mesh, layer='my_dual')
    artist.draw_edges(color=[255, 0, 0])

    # artist.draw_faces(join_faces=True)

    artist.redraw()
Beispiel #13
0
    # set fixed vertices
    fixed = set(mesh.vertices_on_boundary())

    #    artist = MeshArtist(mesh, layer='delaunay')
    #    artist.draw_faces(join_faces=True)

    conduit = MeshConduit(mesh, refreshrate=2)

    # run remeshing algorithm
    with conduit.enabled():
        trimesh_remesh(mesh,
                       target=trg_l,
                       kmax=kmax,
                       tol=0.1,
                       divergence=0.01,
                       allow_boundary_split=True,
                       allow_boundary_swap=True,
                       allow_boundary_collapse=False,
                       smooth=True,
                       fixed=fixed,
                       callback=callback,
                       callback_args=[srf])

    artist = MeshArtist(mesh, layer='remeshed')
    artist.draw_faces(join_faces=True)

    dual_mesh = mesh_dual(mesh)

    artist = MeshArtist(dual_mesh, layer='dual')
    artist.draw_edges(color=[255, 0, 0])
    artist.redraw()
        for u, v in mesh.face_halfedges(fkey):
            # add top vertices of face
            x, y, z = vertices_list[key_index_a[u]]
            voussoir_mesh.add_vertex(key_index_a[u], x=x, y=y, z=z)

            # add bottom vertices of face
            x, y, z = vertices_list[key_index_b[u]]
            voussoir_mesh.add_vertex(key_index_b[u], x=x, y=y, z=z)

            # add interfaces
            face = [
                key_index_a[v], key_index_a[u], key_index_b[u], key_index_b[v]
            ]
            voussoir_mesh.add_face(face)

        # add top and bottom faces
        face_a = [key_index_a[key] for key in mesh.face_vertices(fkey)]
        face_b = [key_index_b[key] for key in mesh.face_vertices(fkey)]
        face_b.reverse()
        voussoir_mesh.add_face(face_a)
        voussoir_mesh.add_face(face_b)

        voussoirs_meshes[fkey] = voussoir_mesh

    # draw all voussoir meshes
    for fkey, voussoir_mesh in voussoirs_meshes.items():
        artist = MeshArtist(voussoir_mesh, layer=layer)
        artist.draw_faces(join_faces=True)

    artist.redraw()
    new_sets_pts[2].reverse()
    new_sets_pts[3].reverse()

    return new_sets_pts


if __name__ == '__main__':

    # division in both directions
    div = 15

    # select curves
    crvs = rs.GetObjects("Select four curves (in cw order)", 4)

    # divide curves
    sets_pts = [rs.DivideCurve(crv, div) for crv in crvs]

    # sort points
    sets_pts = sort_pts(sets_pts)

    # create coons patch
    ab, bc, dc, ad = sets_pts
    points, faces = discrete_coons_patch(ab, bc, dc, ad)

    # create mesh object from points and faces
    mesh = Mesh.from_vertices_and_faces(points, faces)

    # draw coons mesh
    artist = MeshArtist(mesh, layer='coons_mesh')
    artist.draw()
Beispiel #16
0
# ==============================================================================
# Main
# ==============================================================================

if __name__ == "__main__":

    from compas.datastructures import Mesh
    from compas.geometry import Polyhedron

    from compas_rhino.artists.meshartist import MeshArtist

    poly = Polyhedron.generate(12)

    mesh = Mesh.from_vertices_and_faces(poly.vertices, poly.faces)

    artist = MeshArtist(mesh)

    artist.clear()

    artist.draw_vertices()
    artist.redraw(0.0)

    artist.draw_vertexlabels()
    artist.redraw(1.0)

    artist.draw_faces()
    artist.redraw(1.0)

    artist.draw_facelabels()
    artist.redraw(1.0)
from compas.datastructures import Mesh

from compas_rhino.artists.meshartist import MeshArtist
from compas_rhino.helpers import mesh_select_face

if __name__ == '__main__':

    # get mesh from json
    mesh = Mesh.from_json('tessellation_mesh.json')

    # draw tessellation mesh
    artist = MeshArtist(mesh, layer='tessellation_mesh')
    artist.draw_edges()
    artist.draw_facelabels()
    artist.redraw()

    # select a face
    fkey = mesh_select_face(mesh, message='Select face.')

    artist.clear_facelabels()

    # find neighboring faces
    fkeys = list(mesh.face_neighbors(fkey)) + [fkey]
    for fkey in fkeys:
        # get voussoir meshes stored as face attribute
        data = mesh.get_face_attribute(fkey, 'voussoir')
        voussoir_mesh = Mesh.from_data(data)
        # draw neighboring voussoir mesh
        artist = MeshArtist(voussoir_mesh, layer='voussoir_meshes')
        artist.draw_faces(join_faces=True)
Beispiel #18
0
        holes = attr['hole_polygons']
        #create flat list of all points
        points = polygon + [item for hole in holes for item in hole]

        #compute initial delaunay mesh based on all points for the current face
        faces = delaunay_from_points(points, boundary=polygon, holes=holes)
        delaunay = Mesh.from_vertices_and_faces(points, faces)

        rs.Prompt('Computing triangular mesh for face {} of {}'.format(
            count, mesh.number_of_faces()))

        #compute the remeshed delaunay for the current face
        trimesh_remesh(delaunay,
                       target=trg_length,
                       tol=0.05,
                       kmax=300,
                       allow_boundary_split=False,
                       allow_boundary_swap=True,
                       verbose=False)

        delaunay_meshes.append(delaunay)
        count += 1

    #join all meshes created per face
    mesh_diagram = join_meshes(delaunay_meshes,
                               cull_duplicates=True,
                               precision=precision)

    artist = MeshArtist(mesh_diagram, layer='form_tri')
    artist.draw()