openxr_interaction_profile_meta_data.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*************************************************************************/
  2. /* openxr_interaction_profile_meta_data.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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_META_DATA_H
  31. #define OPENXR_INTERACTION_PROFILE_META_DATA_H
  32. #include "openxr_action.h"
  33. ///////////////////////////////////////////////////////////////////////////
  34. // Stores available interaction profile meta data
  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. #include "core/object/object.h"
  53. #define XR_PATH_UNSUPPORTED_NAME "unsupported"
  54. class OpenXRInteractionProfileMetaData : public Object {
  55. public:
  56. struct TopLevelPath {
  57. String display_name; // User friendly display name (i.e. Left controller)
  58. String openxr_path; // Path in OpenXR (i.e. /user/hand/left)
  59. String openxr_extension_name; // If set, only available if extension is enabled (i.e. XR_HTCX_vive_tracker_interaction)
  60. };
  61. struct IOPath {
  62. String display_name; // User friendly display name (i.e. Grip pose (left controller))
  63. String top_level_path; // Top level path identifying the usage of the device in relation to this input/output
  64. String openxr_path; // Path in OpenXR (i.e. /user/hand/left/input/grip/pose)
  65. String openxr_extension_name; // If set, only available if extension is enabled (i.e. XR_EXT_palm_pose)
  66. OpenXRAction::ActionType action_type; // Type of input/output
  67. };
  68. struct InteractionProfile {
  69. String display_name; // User friendly display name (i.e. Simple controller)
  70. String openxr_path; // Path in OpenXR (i.e. /interaction_profiles/khr/simple_controller)
  71. String openxr_extension_name; // If set, only available if extension is enabled (i.e. XR_HTCX_vive_tracker_interaction)
  72. Vector<IOPath> io_paths; // Inputs and outputs for this device
  73. bool has_io_path(const String p_io_path) const;
  74. const IOPath *get_io_path(const String p_io_path) const;
  75. };
  76. private:
  77. static OpenXRInteractionProfileMetaData *singleton;
  78. Vector<TopLevelPath> top_level_paths;
  79. Vector<InteractionProfile> interaction_profiles;
  80. void _register_core_metadata();
  81. protected:
  82. static void _bind_methods();
  83. public:
  84. static OpenXRInteractionProfileMetaData *get_singleton() { return singleton; }
  85. OpenXRInteractionProfileMetaData();
  86. ~OpenXRInteractionProfileMetaData();
  87. void register_top_level_path(const String &p_display_name, const String &p_openxr_path, const String &p_openxr_extension_name);
  88. bool has_top_level_path(const String p_openxr_path) const;
  89. String get_top_level_name(const String p_openxr_path) const;
  90. String get_top_level_extension(const String p_openxr_path) const;
  91. void register_interaction_profile(const String &p_display_name, const String &p_openxr_path, const String &p_openxr_extension_name);
  92. bool has_interaction_profile(const String p_openxr_path) const;
  93. String get_interaction_profile_extension(const String p_openxr_path) const;
  94. const InteractionProfile *get_profile(const String p_openxr_path) const;
  95. PackedStringArray get_interaction_profile_paths() const;
  96. 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);
  97. const IOPath *get_io_path(const String p_interaction_profile, const String p_io_path) const;
  98. };
  99. #endif // OPENXR_INTERACTION_PROFILE_META_DATA_H