Set the default teleport to a virtual button.¶
This example shows how the default teleport can be remapped to a previously defined virtual touchpad button of the VR controller. Further information of how virtual buttons can be added to the touchpad can be found in the “Define and use virtual buttons on the touchpad of a VR controller” example. After the touchpad is set up, the virtual buttons can be used for remapping.
When this example is executed, the default teleport will work as usual but only the lower quarter of the touchpad will actually activate and execute the teleport. This way, other parts of the touchpad can be mapped to other interactions.
vr/setTeleportToVirtualButton.py¶
1# © 2024 Autodesk, Inc. All rights reserved.
2
3# Get the left controller
4leftController = vrDeviceService.getVRDevice("left-controller")
5# Get the right controller
6rightController = vrDeviceService.getVRDevice("right-controller")
7
8# Define the description of the virtual buttons on the touchpad.
9# These description consist of a name, a radius 0 - 1 and an angle 0 - 360,
10# where on the circular touchpad the button is located
11padCenter = vrdVirtualTouchpadButton("padcenter", 0.0, 0.5, 0.0, 360.0)
12padLeft = vrdVirtualTouchpadButton("padleft", 0.5, 1.0, 225.0, 315.0)
13padUp = vrdVirtualTouchpadButton("padup", 0.5, 1.0, 315.0, 45.0)
14padRight = vrdVirtualTouchpadButton("padright", 0.5, 1.0, 45.0, 135.0)
15padDown = vrdVirtualTouchpadButton("paddown", 0.5, 1.0, 135.0, 225.0)
16
17# Add the descirptions for the virtual buttons to the left controller
18leftController.addVirtualButton(padCenter, "touchpad")
19leftController.addVirtualButton(padLeft, "touchpad")
20leftController.addVirtualButton(padUp, "touchpad")
21leftController.addVirtualButton(padRight, "touchpad")
22leftController.addVirtualButton(padDown, "touchpad")
23
24# Also add the descriptions to the right controller
25# Note that each controller can have different tochpad layouts, if
26# it is needed.
27rightController.addVirtualButton(padLeft, "touchpad")
28rightController.addVirtualButton(padUp, "touchpad")
29rightController.addVirtualButton(padRight, "touchpad")
30rightController.addVirtualButton(padDown, "touchpad")
31rightController.addVirtualButton(padCenter, "touchpad")
32
33# Get the interaction which actions should be remapped to the virtual buttons
34teleport = vrDeviceService.getInteraction("Teleport")
35# Set the mapping of the actions to the new virtual buttons
36teleport.setControllerActionMapping("prepare", "any-paddown-touched")
37teleport.setControllerActionMapping("abort", "any-paddown-untouched")
38teleport.setControllerActionMapping("execute", "any-paddown-pressed")