How to use the compas.datastructures.Mesh.from_vertices_and_faces 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 / docs / _downloads / mesh-remeshing.py View on Github external
__copyright__ = 'Copyright 2017, BRG - ETH Zurich',
__license__   = 'MIT'
__email__     = 'van.mele@arch.ethz.ch'


def callback(mesh, k, args):
    conduit = args[0]
    conduit.redraw(k)


boundary = rs.GetObject("Select Boundary Curve", 4)
length   = rs.GetReal("Select Edge Target Length", 2.0)
points   = rs.DivideCurve(boundary, rs.CurveLength(boundary) / length)

faces = mesh_delaunay_from_points(points, points)
mesh  = Mesh.from_vertices_and_faces(points, faces)

conduit = MeshConduit(mesh, refreshrate=2)

with conduit.enabled():
    trimesh_remesh(
        mesh,
        target=length,
        kmax=500,
        allow_boundary_split=True,
        allow_boundary_swap=True,
        callback=callback,
        callback_args=(conduit, )
    )

compas_rhino.mesh_draw(mesh, vertexcolor={key: '#ff0000' for key in mesh.vertices_on_boundary()})
github compas-dev / compas / src / compas_blender / utilities / objects.py View on Github external
def mesh_from_bmesh(bmesh):
    vertices = [list(vertex.co) for vertex in bmesh.data.vertices]
    faces = [list(face.vertices) for face in bmesh.data.polygons]
    return Mesh.from_vertices_and_faces(vertices=vertices, faces=faces)
github compas-dev / compas / docs / reference / generated / compas-datastructures-trimesh_optimise_topology-1.py View on Github external
vertices = [
    (0.0, 0.0, 0.0),
    (10.0, 0.0, 0.0),
    (10.0, 10.0, 0.0),
    (0.0, 10.0, 0.0),
    (5.0, 5.0, 0.0)
]
faces = [
    (0, 1, 4),
    (1, 2, 4),
    (2, 3, 4),
    (3, 0, 4)
]

mesh = Mesh.from_vertices_and_faces(vertices, faces)

trimesh_optimise_topology(
    mesh,
    target=0.5,
    tol=0.05,
    kmax=300,
    allow_boundary_split=True,
    allow_boundary_swap=True,
    verbose=False
)

plotter = MeshPlotter(mesh)

plotter.draw_vertices(radius=0.05)
plotter.draw_faces()
github compas-dev / compas / docs / examples / rhino / mesh-delaunay-from-points.py View on Github external
from compas.datastructures import Mesh
from compas.geometry import delaunay_from_points

from compas_rhino.artists import MeshArtist

# select the points
# and get their coordinates

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


# make a mesh from the delaunay triangulation of the points

faces = delaunay_from_points(points)
mesh = Mesh.from_vertices_and_faces(points, faces)


# draw in Rhino

artist = MeshArtist(mesh)
artist.draw_faces(join_faces=True)
artist.redraw()
github compas-dev / compas / docs / reference / generated / compas-datastructures-mesh_delaunay_from_points-1.py View on Github external
import compas
from compas.datastructures import Mesh
from compas.datastructures import mesh_delaunay_from_points

from compas.visualization import MeshPlotter

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

vertices = [mesh.vertex_coordinates(key) for key in mesh.vertices()]
faces = mesh_delaunay_from_points(vertices)

delaunay = Mesh.from_vertices_and_faces(vertices, faces)

plotter = MeshPlotter(delaunay)

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

plotter.show()
github compas-dev / compas / examples / mesh-subd-modeling.py View on Github external
from compas.datastructures import Mesh
from compas.geometry import Polyhedron
from compas.datastructures import mesh_subdivide


__author__    = ['Tom Van Mele', ]
__copyright__ = 'Copyright 2017, BRG - ETH Zurich',
__license__   = 'MIT'
__email__     = 'van.mele@arch.ethz.ch'


# make a control mesh

cube = Polyhedron.generate(6)
mesh = Mesh.from_vertices_and_faces(cube.vertices, cube.faces)

# give it a name
# and set default vertex attributes

mesh.attributes['name'] = 'Control'
mesh.update_default_vertex_attributes({'is_fixed': False})

# draw the control mesh
# with showing the faces

compas_rhino.mesh_draw(
    mesh,
    layer='SubdModeling::Control',
    clear_layer=True,
    show_faces=False,
    show_vertices=True,
github compas-dev / compas / src / compas / files / ply.py View on Github external
self.vertices = [(vertex['x'], vertex['y'], vertex['z']) for vertex in self.reader.vertices]
        self.faces = [face[self.reader.face_properties[0][0]] for face in self.reader.faces]

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


if __name__ == "__main__":

    import compas
    from compas.datastructures import Mesh

    ply = PLY(compas.get_bunny())

    mesh = Mesh.from_vertices_and_faces(ply.parser.vertices, ply.parser.faces)

    print(mesh.summary())
github compas-dev / compas / src / compas_blender / _ / helpers / mesh.py View on Github external
def mesh_from_bmesh(bmesh):
    """ Create a Mesh datastructure from a Blender mesh.

    Parameters:
        bmesh (obj): Blender mesh object.

    Returns:
        obj: Mesh object.
    """
    blendermesh = BlenderMesh(bmesh)
    vertices = blendermesh.get_vertex_coordinates()
    faces = blendermesh.get_face_vertex_indices()
    mesh = Mesh.from_vertices_and_faces(vertices=vertices, faces=faces)
    return mesh
github compas-dev / compas / examples / mesh-delaunay-with-boundary.py View on Github external
__license__   = 'MIT'
__email__     = 'van.mele@arch.ethz.ch'


guids = compas_rhino.select_points()
vertices = compas_rhino.get_point_coordinates(guids)

guid = compas_rhino.select_polyline("Select boundary.")
boundary = compas_rhino.get_polyline_coordinates(guid)

guids = compas_rhino.select_polylines("Select holes.")
holes = [compas_rhino.get_polyline_coordinates(guid) for guid in guids]

faces = delaunay_from_points(vertices, boundary, holes)

mesh = Mesh.from_vertices_and_faces(vertices, faces)

compas_rhino.mesh_draw(mesh)
github compas-dev / compas / docs / _examples / mesh-delaunay-with-boundary.py View on Github external
guids = compas_rhino.select_points("Select points.")
points = compas_rhino.get_point_coordinates(guids)

guid = compas_rhino.select_polyline("Select boundary.")
boundary = compas_rhino.get_polyline_coordinates(guid)

guids = compas_rhino.select_polylines("Select holes.")
holes = [compas_rhino.get_polyline_coordinates(guid) for guid in guids]


# make a delaunay triangulation
# within the boundary
# and around the holes

faces = delaunay_from_points(points, boundary=boundary, holes=holes)
mesh = Mesh.from_vertices_and_faces(points, faces)


# draw the result

artist = MeshArtist(mesh)
artist.draw_faces(join_faces=True)
artist.redraw()