File: keypress.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-- 844 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
"""Implement a custom function that is triggered by
pressing a keyboard button when the rendering window
is in interactive mode.
Place the pointer anywhere on the mesh and press c"""
from vedo import dataurl, printc, Plotter, Point, Mesh

#############################################################
def myfnc(evt):
    mesh = evt.object
    # printc('dump event info', evt)
    if not mesh or evt.keypress != "c":
        printc("click mesh and press c", c="r", invert=True)
        return
    printc("point:", mesh.picked3d, c="v")
    cpt = Point(mesh.picked3d)
    cpt.color("violet").ps(20).pickable(False)
    plt.add(cpt).render()

##############################################################
plt = Plotter(axes=1)
plt+= Mesh(dataurl+"bunny.obj").color("gold")
plt+= __doc__
plt.add_callback('on key press', myfnc)
plt.show().close()