pythonnumpypymeshlab

Using just vertices to generate faces in PyMeshLab


I have an array of vertices representing some 3D point cloud, and I would like to import this into PyMeshLab to generate faces for the object (sort of like generating a convex hull, but if the 3D object were vertices of a human's hand, it would wrap around each finger correctly). Does PyMeshLab (or other libraries) offer this functionality? The below code of usually doing it using a .obj that has both vertices and faces works, but not so when given something with just vertices.

ms = pymeshlab.MeshSet()

ms.load_new_mesh('vertices.npy')
ms.generate_surface_reconstruction_ball_pivoting()
ms.save_current_mesh('vertices.obj')

# get a reference to the current mesh
m = ms.current_mesh()

# get numpy arrays of vertices and faces of the current mesh
v_matrix = m.vertex_matrix()
f_matrix = m.face_matrix() # <- I would like to generate this, but I'm not allowed so with just a faces input

Solution

  • The PyVista library does that for sure. Honestly, I don't know if MeshLab can do that as well, I have to check that.

    As an example, let's consider the Standford bunny. I have imported its mesh and got its vertices. The reconstruct_surface method did the trick. You have to tweak the method's parameters to get the desired result. For further details look here.

    import pyvista as pv
    
    bunny = pv.read("Stanford_Bunny.ply")
    
    points = pv.wrap(bunny.points)
    surf = points.reconstruct_surface(nbr_sz=10)
    
    pl = pv.Plotter(shape=(1, 2))
    pl.add_mesh(points)
    pl.add_title("Point Cloud of 3D Surface")
    pl.subplot(0, 1)
    pl.add_mesh(surf, color=True, show_edges=True)
    pl.add_title("Reconstructed Surface")
    pl.show()
    

    enter image description here

    If you just wanted the convex hull check this scipy method.