Combine a custom and a default device interaction¶
This example is based on the “Implementation of a custom device interaction” example, which should be reviewed first. Here, the same functionality is provided with the addition of using a default interaction in the same interaction group. This is achieved by getting the default interaction object and adding support for the same interaction group.
19teleport = vrDeviceService.getInteraction("Teleport")
20teleport.addSupportedInteractionGroup("CustomGroup")
In addition the actions of the teleport are remapped. In this case, the custom trigger is used, which is an extended trigger that supports touch and untouched events.
21teleport.setControllerActionMapping("prepare", "right-customtrigger-touched")
22teleport.setControllerActionMapping("abort", "right-customtrigger-untouched")
23teleport.setControllerActionMapping("execute", "right-customtrigger-pressed")
In addition to the printouts triggered by the left controller, it is also possible to teleport with the right controller using the trigger.
vr/combineCustomAndDefaultInteraction.py¶
1# © 2024 Autodesk, Inc. All rights reserved.
2
3# Define actions as python functions
4class ExampleInteraction:
5 def __init__(self):
6 self.active = False
7 # Create new interaction
8 self.customInteraction = vrDeviceService.createInteraction("CustomInteraction")
9 # Limit the interaction to a new mode to not interfere with other interactions
10 self.customInteraction.setSupportedInteractionGroups(["CustomGroup"])
11
12 # Create action objects that a triggered by some input
13 self.pressed = self.customInteraction.createControllerAction("left-trigger-pressed")
14 self.released = self.customInteraction.createControllerAction("left-trigger-released")
15
16 # Connect these actions to the actual python functions
17 self.pressed.signal().triggered.connect(self.pressMethod)
18 self.released.signal().triggered.connect(self.releaseMethod)
19
20 # Get the teleport interaction and add the interaction group
21 teleport = vrDeviceService.getInteraction("Teleport")
22 teleport.addSupportedInteractionGroup("CustomGroup")
23 teleport.setControllerActionMapping("prepare", "right-customtrigger-touched")
24 teleport.setControllerActionMapping("abort", "right-customtrigger-untouched")
25 teleport.setControllerActionMapping("execute", "right-customtrigger-pressed")
26
27 # Activate the mode that supports the new interaction
28 vrDeviceService.setActiveInteractionGroup("CustomGroup")
29
30 def pressMethod(self, action, device):
31 print("Press")
32 self.active = True
33 device.signal().moved.connect(self.moveMethod)
34
35 def releaseMethod(self, action, device):
36 print("Release")
37 self.active = False
38 device.signal().moved.disconnect(self.moveMethod)
39
40 def moveMethod(self, device):
41 print("Move")
42
43interaction = ExampleInteraction()