python3dmplot3dtrimesh

Plot Trimesh object like with Axes3D.plot_trisurf()


I have a Trimesh object and I can't figure out how to plot it. My goal is something like the Axes3D.plot_trisurf() function from mplot3d would produce (see below). The Trimesh object even has an attribute containing the faces, but I don't know where to get the coordinates of the grid points.

Thanks for any idea!

trisurf plot from mplot3d


Solution

  • You can just do this, where mesh is your Trimesh object:

    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    ax.plot_trisurf(mesh.vertices[:, 0], mesh.vertices[:,1], triangles=mesh.faces, Z=mesh.vertices[:,2]) 
    plt.show()
    

    messy trimesh plotted with plot_trisurf

    You may have to play with the scale, aspect, rotation, etc.