How to use the compas.datastructures.Mesh function in COMPAS

To help you get started, we’ve selected a few COMPAS examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github compas-dev / compas / tests / compas / datastructures / test_mesh_operations.py View on Github external
def mesh_0():
    vertices = [
        [1.0, 0.0, 0.0],
        [1.0, 2.0, 0.0],
        [0.0, 1.0, 0.0],
        [2.0, 1.0, 0.0],
        [0.0, 0.0, 0.0]
    ]
    faces = [
        [0, 1, 2],
        [0, 3, 1]
    ]

    return Mesh.from_vertices_and_faces(vertices, faces)
github compas-dev / compas / docs / .source / _examples / mesh-remeshing-on-mesh.py View on Github external
conduit.redraw(k)


# get the target mesh
# and its border

guid_target = compas_rhino.select_mesh()
guid_border = compas_rhino.select_polyline()

# get fixed points

points = compas_rhino.get_point_coordinates(compas_rhino.select_points())

# make a remeshing mesh

mesh = compas_rhino.mesh_from_guid(Mesh, guid_target)

mesh_quads_to_triangles(mesh)

# update its attributes

mesh.update_default_vertex_attributes({'is_fixed': False})

# make the target and border objects

target = RhinoMesh(guid_target)
border = RhinoCurve(guid_border)

# make a map of vertex coorindates
# with 1 float precision

gkey_key = {geometric_key(mesh.vertex_coordinates(key), '1f'): key for key in mesh.vertices()}
github compas-dev / compas / src / compas / viewers / __old / meshviewer.py View on Github external
def special(self, key, x, y):
        """
        Assign mesh functionality to function keys.
        """
        pass


# ==============================================================================
# Main
# ==============================================================================

if __name__ == '__main__':

    from compas.datastructures import Mesh

    mesh = Mesh.from_polyhedron(6)

    viewer = MeshViewer(mesh, width=600, height=600)

    viewer.axes_on = False
    viewer.grid_on = False

    for i in range(10):
        viewer.camera.zoom_in()

    viewer.setup()
    viewer.show()
github compas-dev / compas / src / compas / geometry / algorithms / planarisation.py View on Github external
#     solver.delete()


# ==============================================================================
# Main
# ==============================================================================

if __name__ == "__main__":

    import compas

    from compas.datastructures import Mesh
    from compas.plotters import MeshPlotter
    from compas.utilities import i_to_rgb

    mesh = Mesh.from_obj(compas.get('hypar.obj'))

    for key, attr in mesh.vertices(True):
        attr['is_fixed'] = mesh.vertex_degree(key) == 2

    fixed  = [key for key in mesh.vertices_where({'is_fixed': True})]
    radius = {key: (0.05 if key in fixed else 0.01) for key in mesh.vertices()}

    plotter = MeshPlotter(mesh, figsize=(10, 7))

    plotter.draw_vertices(radius=radius)
    plotter.draw_faces()
    plotter.draw_edges()

    def callback(k, args):
        print(k)
github compas-dev / compas / docs / reference / generated / compas-datastructures-trimesh_collapse_edge-1.py View on Github external
import compas

from compas.datastructures import Mesh
from compas.visualization import MeshPlotter

mesh = Mesh.from_obj(compas.get_data('faces.obj'))

plotter = MeshPlotter(mesh)

plotter.draw_vertices(text={key: key for key in mesh.vertices()}, radius=0.2)
plotter.draw_faces(text={fkey: fkey for fkey in mesh.faces()})

plotter.show()
github compas-dev / compas / docs / _downloads / mesh-stanford-bunny.py View on Github external
import compas
import compas_rhino

from compas.datastructures import Mesh


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


mesh = Mesh.from_ply(compas.get('stanford_bunny.ply'))

compas_rhino.mesh_draw(mesh)
github compas-dev / compas / src / compas / topology / triangulation.py View on Github external
#     mesh_smooth_area(mesh, fixed=mesh.vertices_on_boundary())

    #     plotter.update_edges()
    #     plotter.update(pause=2.0)
    #     plotter.show()

    from compas.geometry import pointcloud_xy
    from compas.datastructures import Mesh
    from compas.topology import delaunay_from_points
    from compas.plotters import MeshPlotter

    points = pointcloud_xy(10, (0, 10))
    faces = delaunay_from_points(points)

    delaunay = Mesh.from_vertices_and_faces(points, faces)

    plotter = MeshPlotter(delaunay)

    plotter.draw_vertices(radius=0.1)
    plotter.draw_faces()

    plotter.show()
github compas-dev / compas / docs / examples / gh / mesh-remeshing.py View on Github external
st[running_key] = False


if running_key not in st:
    st[running_key] = False

if mesh_key not in st or start:

    # divide the boundary curve into segments of a specific length
    points = rs.DivideCurve(boundary, rs.CurveLength(boundary) / length)

    # generate a delaunay triangulation from the points on the boundary
    faces = delaunay_from_points(points, boundary=points)

    # save mesh into sticky dictionary
    st[mesh_key] = Mesh.from_vertices_and_faces(points, faces)

# start or restart

if start and st[running_key] is False:
    thread = Thread(target=threaded_function)
    thread.start()
    st[running_key] = True

# make the result visible in the outlet 'mesh'

if rmesh_key in st:
    mesh = st[rmesh_key]
github compas-dev / compas / src / compas / datastructures / mesh / combinatorics.py View on Github external
return len(nodes) == mesh.number_of_vertices()


# ==============================================================================
# Main
# ==============================================================================

if __name__ == "__main__":

    import doctest
    import compas
    from compas.datastructures import Mesh
    from compas.datastructures import meshes_join
    from compas.geometry import translate_points_xy

    m1 = Mesh.from_obj(compas.get('faces.obj'))
    m2 = m1.copy()

    points = m2.get_vertices_attributes('xyz')
    x, y, z = zip(*points)
    xmin = min(x)
    xmax = max(x)
    points = translate_points_xy(points, [1.5 * (xmax - xmin), 0, 0])
    for key, attr in m2.vertices(True):
        attr['x'] = points[key][0]
        attr['y'] = points[key][1]
        attr['z'] = points[key][2]

    m3 = meshes_join([m1, m2])

    doctest.testmod()