Creating and deleting touch sensors¶
touchsensors.vpb¶
1# This example shows how to create touch sensors and
2# connect them to a variant set.
3# It also contains a function that deletes a touch sensor
4# from a node.
5
6def createTouchSensor(node):
7 # Create the touch sensor first. This will create the needed
8 # attachment and register the touch sensor in VRED.
9 touchSensor = vrTouchSensor(node)
10
11 # To add a variant set, that will be called whenever the touch
12 # sensor is activated, we need to modify the attachement and
13 # add the variant set directly.
14 touchSensorAtt = node.getAttachment("TouchSensorAttachment")
15 touchSensorAttAccess = vrFieldAccess(touchSensorAtt)
16
17 # Note: this takes a list as parameter, so you can trigger multiple
18 # variant sets
19 touchSensorAttAccess.setMString("variantSets", ["toggleColor"])
20
21 return touchSensor
22
23
24def deleteTouchSensor(node):
25 # To delete a touch sensor from a node, the touch sensor attachment
26 # must be removed:
27 if node.hasAttachment("TouchSensorAttachment"):
28 att = node.getAttachment("TouchSensorAttachment")
29 node.subAttachment(att)
30
31
32tsensor1 = createTouchSensor(findNode("Cone"))
33tsensor2 = createTouchSensor(findNode("Box"))
34
35# Refresh the Touch Sensor UI
36vrController.updateTouchSensors()
37# Refresh the Scenegraph UI
38vrScenegraph.updateScenegraph(False)