예제 #1
0
    points = []

    while count < 1000:
        x = (random.random() - 0.5) * radius * 2
        y = (random.random() - 0.5) * radius * 2
        z = (random.random() - 0.5) * radius * 2
        pt = x, y, z

        if distance_point_point(origin, pt) <= radius:
            points.append(pt)
            count += 1

    vertices, faces = convex_hull_numpy(points)

    i_index = {i: index for index, i in enumerate(vertices)}

    vertices = [points[index] for index in vertices]
    faces = [[i_index[i] for i in face] for face in faces]
    # faces = unify_cycles(vertices, faces)

    mesh = Mesh.from_vertices_and_faces(vertices, faces)

    mesh_unify_cycles(mesh)
    # mesh_flip_cycles(mesh)

    viewer = MeshViewer()

    viewer.mesh = mesh

    viewer.show()
예제 #2
0
    stl = STL(filepath, precision='6f')

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

    vertexgroups = connected_components(mesh.halfedge)
    facegroups = [[] for _ in range(len(vertexgroups))]

    vertexsets = list(map(set, vertexgroups))

    for fkey in mesh.faces():
        vertices = set(mesh.face_vertices(fkey))

        for i, vertexset in enumerate(vertexsets):
            if vertices.issubset(vertexset):
                facegroups[i].append(fkey)
                break

    meshes = []

    for vertexgroup, facegroup in zip(vertexgroups, facegroups):
        key_index = {key: index for index, key in enumerate(vertexgroup)}
        vertices = mesh.get_vertices_attributes('xyz', keys=vertexgroup)
        faces = [[key_index[key] for key in mesh.face_vertices(fkey)]
                 for fkey in facegroup]

        meshes.append(Mesh.from_vertices_and_faces(vertices, faces))

    viewer = MeshViewer()
    viewer.mesh = meshes[0]
    viewer.show()