I add some spheres to my Pyvista plot and try to make them pickable:
for index, center in enumerate(centers):
sphere = pv.Sphere(radius=radius, center=center)
plotter.add_mesh(sphere, color=thisColor, pickable=True)
plotter.enable_cell_picking(mesh=sphere, callback=makePickCallback(index), show=True, show_message=True, through=False)
I assume that each sphere would get an individual callback, constructed using the following function:
def makePickCallback(index):
indexCopy = deepcopy(index)
return lambda p: print(str(indexCopy) + " " + str(p))
But it seems that all spheres, and every other element in the plot just calls the callback that was constructed in the last iteration of the for
loop.
Now I wonder - how can I install a different picking callback for each mesh in the scene? Or how can I identify which mesh was clicked?