Attach callback to the event loop
node.py
# This script is just a small debug script
# to demonstrate how to attach something into the event loop
print("Executing node script!")
newScene()
loadGeometry("$VRED_EXAMPLES/geo/teddy.osb")
calcVertexNormals()
class ActionBase:
_active = 0
def recEvent(self, state):
if state == SWITCH_TOGGLE:
self._active = 1 - self._active
else:
self._active = state
def loop(self):
print("abstract!")
def setActive(self, s):
self.recEvent(s)
def isActive(self):
return self._active
class Bug(vrAEBase):
#class Bug(ActionBase):
def __init__(self):
vrAEBase.__init__(self)
self.addLoop()
def loop(self):
if self.isActive() == true:
print("loop: nodename = ", self.node.getName(), " nodeid = ", self.node.getID())
# create callback object and attach a node to it
bug = Bug()
bug.node = findNode("Nose");
# define key m to toggle activation of the loop callback
keyM = vrKey(Key_M)
keyM.connect(bug, SWITCH_TOGGLE)
keyM.connect("print 'Toggled loop callback'")
print("press key m to toggle activation of the loop callback")
updateScene()
print("Ende")