openxr_interaction_profile_metadata.h 6.4 KB

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