1234567891011121314151617181920212223242526272829303132 |
- """Colorize a mesh cell by clicking on it"""
- from vedo import Mesh, Plotter, dataurl
- # Define the callback function to change the color of the clicked cell to red
- def func(evt):
- msh = evt.object
- if not msh:
- return
- pt = evt.picked3d
- idcell = msh.closest_point(pt, return_cell_id=True)
- idpoint = msh.closest_point(pt,return_point_id=True)
- #This works always
- # m.cellcolors[idcell] = [255,0,0,255] #RGBA
-
- #Points need to have the array removed first (BUG)
- m.pointdata.remove("PointsRGBA")
- m.pointcolors[idpoint] = [255,0,0,255]
- # Load a 3D mesh of a panther from a file and set its color to blue
- m = Mesh(dataurl + "panther.stl").c("blue7")
- # Make the mesh opaque and set its line width to 1
- # m.force_opaque().linewidth(1)
- # Create a Plotter object and add the callback function to it
- plt = Plotter()
- plt.add_callback("mouse click", func)
- # Display the mesh with the Plotter object and the docstring
- plt.show(m, __doc__, axes=1).close()
|