color_mesh_cells2.py 769 B

123456789101112131415161718192021222324
  1. """Colorize a mesh cell by clicking on it"""
  2. from vedo import Mesh, Plotter, dataurl
  3. # Define the callback function to change the color of the clicked cell to red
  4. def func(evt):
  5. msh = evt.object
  6. if not msh:
  7. return
  8. pt = evt.picked3d
  9. idcell = msh.closest_point(pt, return_cell_id=True)
  10. m.cellcolors[idcell] = [255,0,0,200] #RGBA
  11. # Load a 3D mesh of a panther from a file and set its color to blue
  12. m = Mesh(dataurl + "panther.stl").c("blue7")
  13. # Make the mesh opaque and set its line width to 1
  14. m.force_opaque().linewidth(1)
  15. # Create a Plotter object and add the callback function to it
  16. plt = Plotter()
  17. plt.add_callback("mouse click", func)
  18. # Display the mesh with the Plotter object and the docstring
  19. plt.show(m, __doc__, axes=1).close()