Attach callback to the event loop¶
node.py¶
1# © 2024 Autodesk, Inc. All rights reserved.
2
3# This script is just a small debug script
4# to demonstrate how to attach something into the event loop
5print("Executing node script!")
6
7newScene()
8loadGeometry("$VRED_EXAMPLES/geo/teddy.osb")
9calcVertexNormals()
10
11class ActionBase:
12 _active = 0
13 def recEvent(self, state):
14 if state == SWITCH_TOGGLE:
15 self._active = 1 - self._active
16 else:
17 self._active = state
18 def loop(self):
19 print("abstract!")
20 def setActive(self, s):
21 self.recEvent(s)
22 def isActive(self):
23 return self._active
24
25class Bug(vrAEBase):
26#class Bug(ActionBase):
27 def __init__(self):
28 vrAEBase.__init__(self)
29 self.addLoop()
30 def loop(self):
31 if self.isActive() == true:
32 print("loop: nodename = ", self.node.getName(), " nodeid = ", self.node.getID())
33
34# create callback object and attach a node to it
35bug = Bug()
36bug.node = findNode("Nose");
37
38# define key m to toggle activation of the loop callback
39keyM = vrKey(Key_M)
40keyM.connect(bug, SWITCH_TOGGLE)
41keyM.connect("print 'Toggled loop callback'")
42print("press key m to toggle activation of the loop callback")
43
44updateScene()
45
46print("Ende")