interaction_modes2.py 772 B

12345678910111213141516171819202122232425
  1. """Use the mouse to select objects and vertices in a mesh.
  2. Middle-click and drag to interact with the scene."""
  3. from vedo import settings, Mesh, dataurl, Plotter, interactor_modes
  4. import numpy as np
  5. settings.enable_default_mouse_callbacks = False
  6. def mode_select(objs):
  7. print("Selected objects:", objs)
  8. d0 = mode.start_x, mode.start_y # display coords
  9. d1 = mode.end_x, mode.end_y
  10. frustum = plt.pick_area(d0, d1)
  11. infru = frustum.inside_points(mesh, return_ids=False)
  12. color = np.random.randint(0, 10)
  13. infru.ps(10).c(color)
  14. plt.add(frustum, infru).render()
  15. mesh = Mesh(dataurl+"cow.vtk").c("k5").lw(1)
  16. mode = interactor_modes.BlenderStyle()
  17. mode.callback_select = mode_select
  18. plt = Plotter()
  19. plt.show(mesh, __doc__, axes=1, mode=mode)