File: interaction_modes2.py

package info (click to toggle)
vedo 2025.5.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,404 kB
  • sloc: python: 64,792; javascript: 1,932; xml: 437; sh: 139; makefile: 6
file content (24 lines) | stat: -rw-r--r-- 704 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""Use the mouse to select objects and vertices in a mesh.
Middle-click and drag to interact with the scene."""
from vedo import *

settings.enable_default_mouse_callbacks = False

def mode_select(objs):
    print("Selected objects:", objs)
    d0 = mode.start_x, mode.start_y  # display coords
    d1 = mode.end_x,   mode.end_y

    frustum = plt.pick_area(d0, d1)
    infru = frustum.inside_points(mesh, return_ids=False)
    color = np.random.randint(0, 10)
    infru.ps(10).c(color)
    plt.add(frustum, infru).render()

mesh = Mesh(dataurl+"cow.vtk").c("k5").lw(1)

mode = interactor_modes.BlenderStyle()
mode.callback_select = mode_select

plt = Plotter()
plt.show(mesh, __doc__, axes=1, mode=mode)