2020-12-17 01:27:24 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# Copyright 2020, Collabora, Ltd.
|
|
|
|
# SPDX-License-Identifier: BSL-1.0
|
|
|
|
"""Generate SteamVR input profiles from a JSON file describing interaction
|
|
|
|
profiles and bindings."""
|
|
|
|
|
|
|
|
from bindings import *
|
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
import errno
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
|
|
def names(p):
|
|
|
|
hw_name = str(p.name.split("/")[-1])
|
|
|
|
vendor_name = str(p.name.split("/")[-2])
|
|
|
|
|
|
|
|
fname = vendor_name + "_" + hw_name + "_profile.json"
|
|
|
|
|
|
|
|
return hw_name, vendor_name, fname
|
|
|
|
|
|
|
|
|
|
|
|
def open_file(args, fname):
|
|
|
|
out_dir = str(args.output)
|
|
|
|
try:
|
|
|
|
os.makedirs(out_dir)
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno != errno.EEXIST:
|
|
|
|
raise
|
|
|
|
|
|
|
|
fname = out_dir + "/" + fname
|
|
|
|
|
|
|
|
f = open(fname, "w")
|
|
|
|
return f
|
|
|
|
|
2022-01-11 20:15:28 +00:00
|
|
|
def get_required_components(path_type):
|
2021-01-12 18:54:29 +00:00
|
|
|
if path_type == "button":
|
|
|
|
return ["click", "touch"]
|
|
|
|
if path_type == "trigger":
|
|
|
|
return ["click", "touch", "value", "force"]
|
|
|
|
if path_type == "joystick":
|
|
|
|
return ["click", "touch"]
|
|
|
|
if path_type == "pose":
|
|
|
|
return []
|
|
|
|
if path_type == "vibration":
|
|
|
|
return []
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
2020-12-17 01:27:24 +00:00
|
|
|
def main():
|
|
|
|
"""Handle command line and generate a file."""
|
|
|
|
parser = argparse.ArgumentParser(description='Bindings generator.')
|
|
|
|
parser.add_argument(
|
|
|
|
'bindings', help='Bindings file to use')
|
|
|
|
parser.add_argument(
|
|
|
|
'output', type=str, help='Output directory')
|
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 <mario.kleiner.de@gmail.com>
2023-01-17 04:11:49 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'-s', '--steamvr', action='store_true',
|
|
|
|
help='Use SteamVR standard controller type names')
|
2020-12-17 01:27:24 +00:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
bindings = Bindings.load_and_parse(args.bindings)
|
|
|
|
|
|
|
|
for p in bindings.profiles:
|
|
|
|
|
|
|
|
device_class = ""
|
2022-01-13 12:51:55 +00:00
|
|
|
if p.profile_type == "tracked_controller":
|
2020-12-17 01:27:24 +00:00
|
|
|
device_class = "TrackedDeviceClass_Controller"
|
|
|
|
else:
|
|
|
|
# TODO: profile for non-controller hw
|
|
|
|
continue
|
|
|
|
|
2022-01-13 12:51:55 +00:00
|
|
|
profile_type, vendor_name, fname = names(p)
|
2020-12-17 01:27:24 +00:00
|
|
|
|
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 <mario.kleiner.de@gmail.com>
2023-01-17 04:11:49 +00:00
|
|
|
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
|
|
|
|
|
2020-12-17 01:27:24 +00:00
|
|
|
input_source = {}
|
|
|
|
|
2022-01-11 20:15:28 +00:00
|
|
|
component: Component
|
|
|
|
for idx, component in enumerate(p.components):
|
aux/binding: Implement optional "steamvr_path" for SteamVR input bindings
When using the Monado SteamVR driver plugin together with an Oculus
Rift CV-1 and Oculus touch controllers, the grip / squeeze sensors
(e.g., /user/hand/left/input/squeeze/value) and the thumbsticks did not
work.
This because SteamVR expects those controls to be exposed under a
different path than what one would use for OpenXR, e.g.,
OpenXR /input/squeeze --> SteamVR /input/grip and
OpenXR /input/thumbstick --> SteamVR /input/joystick
The same is true for some other controller types.
To fix this, add some new code for input subpath substitution, to perform
this remapping, depending on binding type:
For type "trigger": Substitute squeeze with grip
For type "joystick": Substitute thumbstick with joystick
For rare controller types where this would be the wrong thing to do,
e.g., Valve Index (for type "joystick", needs the path to remain
"thumbstick" as before), and for special cases not covered, we add
a new optional parameter 'steamvr_path' which can be used in bindings.json
to handle such mismatches in path flexibly to allow a dedicated path
name for SteamVR, overriding the regular "OpenXR style" input path or
auto-substituted path is if the parameter is omitted.
This makes the Oculus Rift CV-1 touch controllers fully work under SteamVR.
I haven't tested this with other controllers, as I only have Oculus
controllers for testing atm. But after reading about the HTC Vive controllers,
i did add a "steamvr_path" override for /input/menu -> /input/application_menu.
Cfe. https://github.com/ValveSoftware/openvr/wiki/IVRDriverInput-Overview
Also, a minor typo fix in steamvr_profiles.py as a bonus.
Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com>
2023-01-16 21:21:25 +00:00
|
|
|
subpath_name = component.steamvr_path
|
2020-12-17 01:27:24 +00:00
|
|
|
|
2022-01-13 12:51:55 +00:00
|
|
|
input_source[subpath_name] = {
|
|
|
|
"type": component.subpath_type,
|
2020-12-17 01:27:24 +00:00
|
|
|
"binding_image_point": [0, 0], # TODO
|
|
|
|
"order": idx
|
|
|
|
}
|
2021-01-12 18:54:29 +00:00
|
|
|
|
2022-01-13 12:51:55 +00:00
|
|
|
for req in get_required_components(component.subpath_type):
|
|
|
|
input_source[subpath_name][req] = req in component.components_for_subpath
|
2020-12-17 01:27:24 +00:00
|
|
|
|
|
|
|
j = {
|
|
|
|
"json_id": "input_profile",
|
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 <mario.kleiner.de@gmail.com>
2023-01-17 04:11:49 +00:00
|
|
|
"controller_type": controller_type,
|
2020-12-17 01:27:24 +00:00
|
|
|
"device_class": device_class,
|
|
|
|
"resource_root": "steamvr-monado",
|
|
|
|
"driver_name": "monado",
|
|
|
|
# "legacy_binding": None, # TODO
|
|
|
|
"input_bindingui_mode": "controller_handed",
|
aux/binding: Implement optional "steamvr_path" for SteamVR input bindings
When using the Monado SteamVR driver plugin together with an Oculus
Rift CV-1 and Oculus touch controllers, the grip / squeeze sensors
(e.g., /user/hand/left/input/squeeze/value) and the thumbsticks did not
work.
This because SteamVR expects those controls to be exposed under a
different path than what one would use for OpenXR, e.g.,
OpenXR /input/squeeze --> SteamVR /input/grip and
OpenXR /input/thumbstick --> SteamVR /input/joystick
The same is true for some other controller types.
To fix this, add some new code for input subpath substitution, to perform
this remapping, depending on binding type:
For type "trigger": Substitute squeeze with grip
For type "joystick": Substitute thumbstick with joystick
For rare controller types where this would be the wrong thing to do,
e.g., Valve Index (for type "joystick", needs the path to remain
"thumbstick" as before), and for special cases not covered, we add
a new optional parameter 'steamvr_path' which can be used in bindings.json
to handle such mismatches in path flexibly to allow a dedicated path
name for SteamVR, overriding the regular "OpenXR style" input path or
auto-substituted path is if the parameter is omitted.
This makes the Oculus Rift CV-1 touch controllers fully work under SteamVR.
I haven't tested this with other controllers, as I only have Oculus
controllers for testing atm. But after reading about the HTC Vive controllers,
i did add a "steamvr_path" override for /input/menu -> /input/application_menu.
Cfe. https://github.com/ValveSoftware/openvr/wiki/IVRDriverInput-Overview
Also, a minor typo fix in steamvr_profiles.py as a bonus.
Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com>
2023-01-16 21:21:25 +00:00
|
|
|
"should_show_binding_errors": True,
|
2020-12-17 01:27:24 +00:00
|
|
|
"input_bindingui_left": {
|
|
|
|
"image": "{indexcontroller}/icons/indexcontroller_left.svg" # TODO
|
|
|
|
},
|
|
|
|
"input_bindingui_right": {
|
|
|
|
"image": "{indexcontroller}/icons/indexcontroller_right.svg" # TODO
|
|
|
|
},
|
|
|
|
"input_source": input_source
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
f = open_file(args, fname)
|
|
|
|
|
|
|
|
# print("Creating SteamVR input profile", f.name)
|
|
|
|
|
|
|
|
json.dump(j, f, indent=2)
|
|
|
|
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|