issue_908.py 994 B

1234567891011121314151617181920212223242526272829303132
  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. idpoint = msh.closest_point(pt,return_point_id=True)
  11. #This works always
  12. # m.cellcolors[idcell] = [255,0,0,255] #RGBA
  13. #Points need to have the array removed first (BUG)
  14. m.pointdata.remove("PointsRGBA")
  15. m.pointcolors[idpoint] = [255,0,0,255]
  16. # Load a 3D mesh of a panther from a file and set its color to blue
  17. m = Mesh(dataurl + "panther.stl").c("blue7")
  18. # Make the mesh opaque and set its line width to 1
  19. # m.force_opaque().linewidth(1)
  20. # Create a Plotter object and add the callback function to it
  21. plt = Plotter()
  22. plt.add_callback("mouse click", func)
  23. # Display the mesh with the Plotter object and the docstring
  24. plt.show(m, __doc__, axes=1).close()