1 | /**************************************************************************/ |
2 | /* openxr_interaction_profile_metadata.h */ |
3 | /**************************************************************************/ |
4 | /* This file is part of: */ |
5 | /* GODOT ENGINE */ |
6 | /* https://godotengine.org */ |
7 | /**************************************************************************/ |
8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
10 | /* */ |
11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
12 | /* a copy of this software and associated documentation files (the */ |
13 | /* "Software"), to deal in the Software without restriction, including */ |
14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
17 | /* the following conditions: */ |
18 | /* */ |
19 | /* The above copyright notice and this permission notice shall be */ |
20 | /* included in all copies or substantial portions of the Software. */ |
21 | /* */ |
22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
29 | /**************************************************************************/ |
30 | |
31 | #ifndef OPENXR_INTERACTION_PROFILE_METADATA_H |
32 | #define OPENXR_INTERACTION_PROFILE_METADATA_H |
33 | |
34 | /////////////////////////////////////////////////////////////////////////// |
35 | // Stores available interaction profile metadata |
36 | // |
37 | // OpenXR defines and hardcodes all the supported input devices and their |
38 | // paths as part of the OpenXR spec. When support for new devices is |
39 | // introduced this often starts life as an extension that needs to be enabled |
40 | // until it's adopted into the core. As there is no interface to |
41 | // enumerate the possibly paths, and that any OpenXR runtime would likely |
42 | // limit such enumeration to those input devices supported by that runtime |
43 | // there is no other option than to hardcode this. |
44 | // |
45 | // Note that we need to include paths of our extensions in our action map |
46 | // regardless of whether the developers machine supports the extension or |
47 | // not. Unsupported paths are filtered out when the action map is submitted |
48 | // to the OpenXR runtime. |
49 | // |
50 | // Note on action type that automatic conversions between boolean and float |
51 | // are supported but otherwise action types should match between action and |
52 | // input/output paths. |
53 | |
54 | #include "openxr_action.h" |
55 | |
56 | #include "core/object/object.h" |
57 | #include "core/templates/hash_map.h" |
58 | |
59 | #define XR_PATH_UNSUPPORTED_NAME "unsupported" |
60 | |
61 | class OpenXRInteractionProfileMetadata : public Object { |
62 | GDCLASS(OpenXRInteractionProfileMetadata, Object); |
63 | |
64 | public: |
65 | struct TopLevelPath { |
66 | String display_name; // User friendly display name (i.e. Left controller) |
67 | String openxr_path; // Path in OpenXR (i.e. /user/hand/left) |
68 | String openxr_extension_name; // If set, only available if extension is enabled (i.e. XR_HTCX_vive_tracker_interaction) |
69 | }; |
70 | |
71 | struct IOPath { |
72 | String display_name; // User friendly display name (i.e. Grip pose (left controller)) |
73 | String top_level_path; // Top level path identifying the usage of the device in relation to this input/output |
74 | String openxr_path; // Path in OpenXR (i.e. /user/hand/left/input/grip/pose) |
75 | String openxr_extension_name; // If set, only available if extension is enabled (i.e. XR_EXT_palm_pose) |
76 | OpenXRAction::ActionType action_type; // Type of input/output |
77 | }; |
78 | |
79 | struct InteractionProfile { |
80 | String display_name; // User friendly display name (i.e. Simple controller) |
81 | String openxr_path; // Path in OpenXR (i.e. /interaction_profiles/khr/simple_controller) |
82 | String openxr_extension_name; // If set, only available if extension is enabled (i.e. XR_HTCX_vive_tracker_interaction) |
83 | Vector<IOPath> io_paths; // Inputs and outputs for this device |
84 | |
85 | bool has_io_path(const String p_io_path) const; |
86 | const IOPath *get_io_path(const String p_io_path) const; |
87 | }; |
88 | |
89 | private: |
90 | static OpenXRInteractionProfileMetadata *singleton; |
91 | |
92 | HashMap<String, String> profile_renames; |
93 | Vector<TopLevelPath> top_level_paths; |
94 | Vector<InteractionProfile> interaction_profiles; |
95 | |
96 | void _register_core_metadata(); |
97 | |
98 | protected: |
99 | static void _bind_methods(); |
100 | |
101 | public: |
102 | static OpenXRInteractionProfileMetadata *get_singleton() { return singleton; } |
103 | |
104 | OpenXRInteractionProfileMetadata(); |
105 | ~OpenXRInteractionProfileMetadata(); |
106 | |
107 | void register_profile_rename(const String &p_old_name, const String &p_new_name); |
108 | String check_profile_name(const String &p_name) const; |
109 | |
110 | void register_top_level_path(const String &p_display_name, const String &p_openxr_path, const String &p_openxr_extension_name); |
111 | bool has_top_level_path(const String p_openxr_path) const; |
112 | String get_top_level_name(const String p_openxr_path) const; |
113 | String get_top_level_extension(const String p_openxr_path) const; |
114 | |
115 | void register_interaction_profile(const String &p_display_name, const String &p_openxr_path, const String &p_openxr_extension_name); |
116 | bool has_interaction_profile(const String p_openxr_path) const; |
117 | String get_interaction_profile_extension(const String p_openxr_path) const; |
118 | const InteractionProfile *get_profile(const String p_openxr_path) const; |
119 | PackedStringArray get_interaction_profile_paths() const; |
120 | |
121 | void register_io_path(const String &p_interaction_profile, const String &p_display_name, const String &p_toplevel_path, const String &p_openxr_path, const String &p_openxr_extension_name, OpenXRAction::ActionType p_action_type); |
122 | const IOPath *get_io_path(const String p_interaction_profile, const String p_io_path) const; |
123 | }; |
124 | |
125 | #endif // OPENXR_INTERACTION_PROFILE_METADATA_H |
126 | |