Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/openxr/action_map/openxr_interaction_profile_metadata.h
10278 views
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
#pragma once
32
33
///////////////////////////////////////////////////////////////////////////
34
// Stores available interaction profile metadata
35
//
36
// OpenXR defines and hardcodes all the supported input devices and their
37
// paths as part of the OpenXR spec. When support for new devices is
38
// introduced this often starts life as an extension that needs to be enabled
39
// until it's adopted into the core. As there is no interface to
40
// enumerate the possibly paths, and that any OpenXR runtime would likely
41
// limit such enumeration to those input devices supported by that runtime
42
// there is no other option than to hardcode this.
43
//
44
// Note that we need to include paths of our extensions in our action map
45
// regardless of whether the developers machine supports the extension or
46
// not. Unsupported paths are filtered out when the action map is submitted
47
// to the OpenXR runtime.
48
//
49
// Note on action type that automatic conversions between boolean and float
50
// are supported but otherwise action types should match between action and
51
// input/output paths.
52
53
#include "openxr_action.h"
54
55
#include "core/object/object.h"
56
#include "core/templates/hash_map.h"
57
58
#define XR_PATH_UNSUPPORTED_NAME "unsupported"
59
60
class OpenXRInteractionProfileMetadata : public Object {
61
GDCLASS(OpenXRInteractionProfileMetadata, Object);
62
63
public:
64
struct TopLevelPath {
65
String display_name; // User friendly display name (i.e. Left controller)
66
String openxr_path; // Path in OpenXR (i.e. /user/hand/left)
67
String openxr_extension_name; // If set, only available if extension is enabled (i.e. XR_HTCX_vive_tracker_interaction)
68
};
69
70
struct IOPath {
71
String display_name; // User friendly display name (i.e. Grip pose (left controller))
72
String top_level_path; // Top level path identifying the usage of the device in relation to this input/output
73
String openxr_path; // Path in OpenXR (i.e. /user/hand/left/input/grip/pose)
74
String openxr_extension_name; // If set, only available if extension is enabled (i.e. XR_EXT_palm_pose)
75
OpenXRAction::ActionType action_type; // Type of input/output
76
};
77
78
struct InteractionProfile {
79
String display_name; // User friendly display name (i.e. Simple controller)
80
String openxr_path; // Path in OpenXR (i.e. /interaction_profiles/khr/simple_controller)
81
String openxr_extension_name; // If set, only available if extension is enabled (i.e. XR_HTCX_vive_tracker_interaction)
82
Vector<IOPath> io_paths; // Inputs and outputs for this device
83
84
bool has_io_path(const String p_io_path) const;
85
const IOPath *get_io_path(const String p_io_path) const;
86
};
87
88
private:
89
static OpenXRInteractionProfileMetadata *singleton;
90
91
HashMap<String, String> profile_renames;
92
Vector<TopLevelPath> top_level_paths;
93
Vector<InteractionProfile> interaction_profiles;
94
95
void _register_core_metadata();
96
97
protected:
98
static void _bind_methods();
99
100
public:
101
static OpenXRInteractionProfileMetadata *get_singleton() { return singleton; }
102
103
OpenXRInteractionProfileMetadata();
104
~OpenXRInteractionProfileMetadata();
105
106
void register_profile_rename(const String &p_old_name, const String &p_new_name);
107
String check_profile_name(const String &p_name) const;
108
109
void register_top_level_path(const String &p_display_name, const String &p_openxr_path, const String &p_openxr_extension_name);
110
bool has_top_level_path(const String p_openxr_path) const;
111
String get_top_level_name(const String p_openxr_path) const;
112
String get_top_level_extension(const String p_openxr_path) const;
113
114
void register_interaction_profile(const String &p_display_name, const String &p_openxr_path, const String &p_openxr_extension_name);
115
bool has_interaction_profile(const String p_openxr_path) const;
116
String get_interaction_profile_extension(const String p_openxr_path) const;
117
const InteractionProfile *get_profile(const String p_openxr_path) const;
118
PackedStringArray get_interaction_profile_paths() const;
119
120
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);
121
const IOPath *get_io_path(const String p_interaction_profile, const String p_io_path) const;
122
};
123
124