buildmesh.py 840 B

1234567891011121314151617181920212223
  1. """Manually build a mesh from points and faces"""
  2. from vedo import Mesh, show
  3. # Define the vertices and faces that make up the mesh
  4. verts = [(50,50,50), (70,40,50), (50,40,80), (80,70,50)]
  5. cells = [(0,1,2), (2,1,3), (1,0,3)] # cells same as faces
  6. # Build the polygonal Mesh object from the vertices and faces
  7. mesh = Mesh([verts, cells])
  8. # Set the backcolor of the mesh to violet
  9. # and show edges with a linewidth of 2
  10. mesh.backcolor('violet').linecolor('tomato').linewidth(2)
  11. # Create labels for all vertices in the mesh showing their ID
  12. labs = mesh.labels2d('pointid')
  13. # Print the points and faces of the mesh as numpy arrays
  14. print('vertices:', mesh.vertices) # same as mesh.points or mesh.coordinates
  15. print('faces :', mesh.cells)
  16. # Show the mesh, vertex labels, and docstring
  17. show(mesh, labs, __doc__, viewup='z', axes=1).close()