mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-01 12:46:12 +00:00
aux/bindings: Add OpenXR Identifier
This commit is contained in:
parent
003acb4d5f
commit
f0a5f1977c
|
@ -39,48 +39,39 @@ class Component:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_components(component_cls, json_profile):
|
def parse_components(component_cls,
|
||||||
"""Turn a profile's input paths into a list of Component objects."""
|
subaction_path,
|
||||||
|
identifier_path,
|
||||||
json_subaction_paths = json_profile["subaction_paths"]
|
json_subpath):
|
||||||
json_subpaths = json_profile["subpaths"]
|
"""Turn a Identifier's component paths into a list of Component objects."""
|
||||||
|
|
||||||
component_list = []
|
component_list = []
|
||||||
for subaction_path in json_subaction_paths: # /user/hand/*
|
for component_name in json_subpath["components"]: # click, touch, ...
|
||||||
for json_sub_path_itm in json_subpaths.items(): # /input/*, /output/*
|
monado_binding = None
|
||||||
subpath_name = json_sub_path_itm[0] # /input/trackpad
|
if component_name in json_subpath["monado_bindings"]:
|
||||||
json_subpath = json_sub_path_itm[1] # json object associated with a subpath (type, localized_name, ...)
|
monado_binding = json_subpath["monado_bindings"][component_name]
|
||||||
|
|
||||||
# Oculus Touch a,b/x,y components only exist on one controller
|
c = Component(subaction_path,
|
||||||
if "side" in json_subpath and "/user/hand/" + json_subpath["side"] != subaction_path:
|
identifier_path,
|
||||||
continue
|
json_subpath["localized_name"],
|
||||||
|
json_subpath["type"],
|
||||||
for component_name in json_subpath["components"]: # click, touch, ...
|
component_name,
|
||||||
monado_binding = None
|
monado_binding,
|
||||||
if component_name in json_subpath["monado_bindings"]:
|
json_subpath["components"])
|
||||||
monado_binding = json_subpath["monado_bindings"][component_name]
|
component_list.append(c)
|
||||||
|
|
||||||
c = Component(subaction_path,
|
|
||||||
subpath_name,
|
|
||||||
json_subpath["localized_name"],
|
|
||||||
json_subpath["type"],
|
|
||||||
component_name,
|
|
||||||
monado_binding,
|
|
||||||
json_subpath["components"])
|
|
||||||
component_list.append(c)
|
|
||||||
|
|
||||||
return component_list
|
return component_list
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
subaction_path,
|
subaction_path,
|
||||||
subpath_name,
|
identifier_path,
|
||||||
subpath_localized_name,
|
subpath_localized_name,
|
||||||
subpath_type,
|
subpath_type,
|
||||||
component_name,
|
component_name,
|
||||||
monado_binding,
|
monado_binding,
|
||||||
components_for_subpath):
|
components_for_subpath):
|
||||||
self.subaction_path = subaction_path
|
self.subaction_path = subaction_path
|
||||||
self.subpath_name = subpath_name # note: starts with a slash
|
self.identifier_path = identifier_path # note: starts with a slash
|
||||||
self.subpath_localized_name = subpath_localized_name
|
self.subpath_localized_name = subpath_localized_name
|
||||||
self.subpath_type = subpath_type
|
self.subpath_type = subpath_type
|
||||||
self.component_name = component_name
|
self.component_name = component_name
|
||||||
|
@ -95,7 +86,7 @@ class Component:
|
||||||
"""
|
"""
|
||||||
paths = []
|
paths = []
|
||||||
|
|
||||||
basepath = self.subaction_path + self.subpath_name
|
basepath = self.subaction_path + self.identifier_path
|
||||||
|
|
||||||
if self.component_name == "position":
|
if self.component_name == "position":
|
||||||
paths.append(basepath + "/" + "x")
|
paths.append(basepath + "/" + "x")
|
||||||
|
@ -115,6 +106,52 @@ class Component:
|
||||||
return not self.is_input()
|
return not self.is_input()
|
||||||
|
|
||||||
|
|
||||||
|
class Identifer:
|
||||||
|
"""A Identifier is a OpenXR identifier with a user path, such as button
|
||||||
|
X, a trackpad, a pose such as aim. It can have one or more features, even
|
||||||
|
tho outputs doesn't include a component/feature path a output indentifier
|
||||||
|
will have a haptic output feature.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def parse_identifiers(indentifer_cls, json_profile):
|
||||||
|
"""Turn a profile's input paths into a list of Component objects."""
|
||||||
|
|
||||||
|
json_subaction_paths = json_profile["subaction_paths"]
|
||||||
|
json_subpaths = json_profile["subpaths"]
|
||||||
|
|
||||||
|
identifier_list = []
|
||||||
|
for subaction_path in json_subaction_paths: # /user/hand/*
|
||||||
|
for json_sub_path_itm in json_subpaths.items(): # /input/*, /output/*
|
||||||
|
identifier_path = json_sub_path_itm[0] # /input/trackpad
|
||||||
|
json_subpath = json_sub_path_itm[1] # json object associated with a subpath (type, localized_name, ...)
|
||||||
|
|
||||||
|
# Oculus Touch a,b/x,y components only exist on one controller
|
||||||
|
if "side" in json_subpath and "/user/hand/" + json_subpath["side"] != subaction_path:
|
||||||
|
continue
|
||||||
|
|
||||||
|
component_list = Component.parse_components(subaction_path,
|
||||||
|
identifier_path,
|
||||||
|
json_subpath)
|
||||||
|
|
||||||
|
i = Identifer(subaction_path,
|
||||||
|
identifier_path,
|
||||||
|
component_list)
|
||||||
|
identifier_list.append(i)
|
||||||
|
|
||||||
|
return identifier_list
|
||||||
|
|
||||||
|
def __init__(self,
|
||||||
|
subaction_path,
|
||||||
|
identifier_path,
|
||||||
|
component_list):
|
||||||
|
self.subaction_path = subaction_path
|
||||||
|
self.identifier_path = identifier_path
|
||||||
|
self.path = subaction_path + identifier_path
|
||||||
|
self.components = component_list
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
class Profile:
|
class Profile:
|
||||||
"""An interactive bindings profile."""
|
"""An interactive bindings profile."""
|
||||||
|
|
||||||
|
@ -125,7 +162,12 @@ class Profile:
|
||||||
self.profile_type = json_profile["type"]
|
self.profile_type = json_profile["type"]
|
||||||
self.monado_device_enum = json_profile["monado_device"]
|
self.monado_device_enum = json_profile["monado_device"]
|
||||||
self.validation_func_name = profile_name.replace("/interaction_profiles/", "").replace("/", "_")
|
self.validation_func_name = profile_name.replace("/interaction_profiles/", "").replace("/", "_")
|
||||||
self.components = Component.parse_components(json_profile)
|
self.identifiers = Identifer.parse_identifiers(json_profile)
|
||||||
|
|
||||||
|
self.components = []
|
||||||
|
for identifier in self.identifiers:
|
||||||
|
for component in identifier.components:
|
||||||
|
self.components.append(component)
|
||||||
|
|
||||||
collector = PathsByLengthCollector()
|
collector = PathsByLengthCollector()
|
||||||
for component in self.components:
|
for component in self.components:
|
||||||
|
@ -219,7 +261,7 @@ def generate_bindings_c(file, p):
|
||||||
component: Component
|
component: Component
|
||||||
for idx, component in enumerate(profile.components):
|
for idx, component in enumerate(profile.components):
|
||||||
|
|
||||||
steamvr_path = component.subpath_name
|
steamvr_path = component.identifier_path
|
||||||
if component.component_name in ["click", "touch", "force", "value"]:
|
if component.component_name in ["click", "touch", "force", "value"]:
|
||||||
steamvr_path += "/" + component.component_name
|
steamvr_path += "/" + component.component_name
|
||||||
|
|
||||||
|
|
|
@ -36,9 +36,9 @@ def open_file(args, fname):
|
||||||
|
|
||||||
def steamvr_subpath_name(component):
|
def steamvr_subpath_name(component):
|
||||||
if component.subpath_type == "pose":
|
if component.subpath_type == "pose":
|
||||||
return component.subpath_name.replace("/input/", "/pose/")
|
return component.identifier_path.replace("/input/", "/pose/")
|
||||||
|
|
||||||
return component.subpath_name
|
return component.identifier_path
|
||||||
|
|
||||||
|
|
||||||
def get_required_components(path_type):
|
def get_required_components(path_type):
|
||||||
|
|
Loading…
Reference in a new issue