From 887b770f9e4bb56d247b3ae583013489d5411597 Mon Sep 17 00:00:00 2001 From: Mario Kleiner Date: Tue, 17 Jan 2023 05:11:49 +0100 Subject: [PATCH] aux/binding: Implement optional "steamvr_controllertypes" for SteamVR input bindings Add an optional switch -s or --steamvr to steamvr_profiles.py, which enables a different naming scheme for the "controller_type" field in the generated SteamVR profile json files. If the switch is provided and an interaction profile in bindings.json provides the optional new property "steamvr_controllertype", that property will be used for the "controller_type" field of the written out .json, instead of the regular auto-generated name. This allows to generate json files which use controller_type names normally used by SteamVR, so Monado provided controllers are mapped to the same OpenXR interaction profiles that SteamVR would normally map them to. E.g., the standard controller_type for Oculus touch controllers used by SteamVR is "oculus_touch" instead of Monado's "monado_oculus_touch_controller". That in turn allows OpenXR clients to use the SteamVR/OpenXR runtime to access controllers provided by Monado's SteamVR driver plugin. Without such compatible json files, only standard OpenVR clients can use controllers exposed by Monado's SteamVR driver by default, but not OpenXR clients. Tested with an Oculus Rift CV-1, and shown to now enable OpenXR clients to make full use of the Oculus touch controllers. The mappings for controllers other than Oculus Touch are derived from SteamVR log output, but not actually tested due to lack of suitable hw. Per discussion for the merge request, we enable this '-s' flag by default in the make file for SteamVR style naming scheme. Signed-off-by: Mario Kleiner --- src/xrt/auxiliary/bindings/bindings.json | 7 +++++++ src/xrt/auxiliary/bindings/bindings.py | 4 ++++ src/xrt/auxiliary/bindings/steamvr_profiles.py | 9 ++++++++- src/xrt/targets/steamvr_drv/CMakeLists.txt | 2 +- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/xrt/auxiliary/bindings/bindings.json b/src/xrt/auxiliary/bindings/bindings.json index 0000fc189..36f6a2c1a 100644 --- a/src/xrt/auxiliary/bindings/bindings.json +++ b/src/xrt/auxiliary/bindings/bindings.json @@ -3,6 +3,7 @@ "/interaction_profiles/khr/simple_controller": { "title": "Khronos Simple Controller", "type": "tracked_controller", + "steamvr_controllertype": "khr_simple_controller", "monado_device": "XRT_DEVICE_SIMPLE_CONTROLLER", "subaction_paths": [ "/user/hand/left", @@ -106,6 +107,7 @@ "/interaction_profiles/htc/vive_controller": { "title": "HTC Vive Controller", "type": "tracked_controller", + "steamvr_controllertype": "vive_controller", "monado_device": "XRT_DEVICE_VIVE_WAND", "subaction_paths": [ "/user/hand/left", @@ -191,6 +193,7 @@ "/interaction_profiles/htc/vive_pro": { "title": "HTC Vive Pro", "type": "tracked_hmd", + "steamvr_controllertype": "vive_pro", "monado_device": "XRT_DEVICE_VIVE_PRO", "subaction_paths": [ "/user/head" @@ -234,6 +237,7 @@ "/interaction_profiles/microsoft/motion_controller": { "title": "Microsoft Mixed Reality Motion Controller", "type": "tracked_controller", + "steamvr_controllertype": "holographic_controller", "monado_device": "XRT_DEVICE_WMR_CONTROLLER", "subaction_paths": [ "/user/hand/left", @@ -322,6 +326,7 @@ "/interaction_profiles/microsoft/xbox_controller": { "title": "Microsoft Xbox Controller", "type": "untracked_controller", + "steamvr_controllertype": "gamepad", "monado_device": "XRT_DEVICE_XBOX_CONTROLLER", "subaction_paths": [ "/user/gamepad" @@ -570,6 +575,7 @@ "/interaction_profiles/oculus/touch_controller": { "title": "Oculus Touch Controller", "type": "tracked_controller", + "steamvr_controllertype": "oculus_touch", "monado_device": "XRT_DEVICE_TOUCH_CONTROLLER", "subaction_paths": [ "/user/hand/left", @@ -703,6 +709,7 @@ "/interaction_profiles/valve/index_controller": { "title": "Valve Index Controller", "type": "tracked_controller", + "steamvr_controllertype": "knuckles", "monado_device": "XRT_DEVICE_INDEX_CONTROLLER", "subaction_paths": [ "/user/hand/left", diff --git a/src/xrt/auxiliary/bindings/bindings.py b/src/xrt/auxiliary/bindings/bindings.py index e15b3e239..ff1309109 100755 --- a/src/xrt/auxiliary/bindings/bindings.py +++ b/src/xrt/auxiliary/bindings/bindings.py @@ -273,6 +273,10 @@ class Profile: self.validation_func_name = profile_name.replace("/interaction_profiles/", "").replace("/", "_") self.identifiers = Identifer.parse_identifiers(json_profile) + self.steamvr_controller_type = None + if "steamvr_controllertype" in json_profile: + self.steamvr_controller_type = json_profile["steamvr_controllertype"] + self.components = [] for identifier in self.identifiers: for component in identifier.components: diff --git a/src/xrt/auxiliary/bindings/steamvr_profiles.py b/src/xrt/auxiliary/bindings/steamvr_profiles.py index 373f09e6b..abcbfabe6 100644 --- a/src/xrt/auxiliary/bindings/steamvr_profiles.py +++ b/src/xrt/auxiliary/bindings/steamvr_profiles.py @@ -54,6 +54,9 @@ def main(): 'bindings', help='Bindings file to use') parser.add_argument( 'output', type=str, help='Output directory') + parser.add_argument( + '-s', '--steamvr', action='store_true', + help='Use SteamVR standard controller type names') args = parser.parse_args() bindings = Bindings.load_and_parse(args.bindings) @@ -69,6 +72,10 @@ def main(): profile_type, vendor_name, fname = names(p) + controller_type = "monado_" + vendor_name + "_" + profile_type + if args.steamvr == True and p.steamvr_controller_type is not None: + controller_type = p.steamvr_controller_type + input_source = {} component: Component @@ -86,7 +93,7 @@ def main(): j = { "json_id": "input_profile", - "controller_type": "monado_" + vendor_name + "_" + profile_type, + "controller_type": controller_type, "device_class": device_class, "resource_root": "steamvr-monado", "driver_name": "monado", diff --git a/src/xrt/targets/steamvr_drv/CMakeLists.txt b/src/xrt/targets/steamvr_drv/CMakeLists.txt index 8dca2dbdc..52d6f5c77 100644 --- a/src/xrt/targets/steamvr_drv/CMakeLists.txt +++ b/src/xrt/targets/steamvr_drv/CMakeLists.txt @@ -9,7 +9,7 @@ add_custom_command( OUTPUT "${INPUT_PROFILES_OUTPUT_DIR}" COMMAND ${PYTHON_EXECUTABLE} ${INPUT_PROFILES_INPUT_DIR}/steamvr_profiles.py - ${INPUT_PROFILES_INPUT_DIR}/bindings.json "${INPUT_PROFILES_OUTPUT_DIR}" + ${INPUT_PROFILES_INPUT_DIR}/bindings.json "${INPUT_PROFILES_OUTPUT_DIR}" "-s" DEPENDS ${INPUT_PROFILES_INPUT_DIR}/bindings.py ${INPUT_PROFILES_INPUT_DIR}/bindings.json COMMENT "Generating SteamVR input profiles to ${INPUT_PROFILES_OUTPUT_DIR}" )