openxr_eye_gaze_interaction.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /**************************************************************************/
  2. /* openxr_eye_gaze_interaction.cpp */
  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. #include "openxr_eye_gaze_interaction.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/os/os.h"
  33. #include "../action_map/openxr_interaction_profile_metadata.h"
  34. OpenXREyeGazeInteractionExtension *OpenXREyeGazeInteractionExtension::singleton = nullptr;
  35. OpenXREyeGazeInteractionExtension *OpenXREyeGazeInteractionExtension::get_singleton() {
  36. ERR_FAIL_NULL_V(singleton, nullptr);
  37. return singleton;
  38. }
  39. OpenXREyeGazeInteractionExtension::OpenXREyeGazeInteractionExtension() {
  40. singleton = this;
  41. }
  42. OpenXREyeGazeInteractionExtension::~OpenXREyeGazeInteractionExtension() {
  43. singleton = nullptr;
  44. }
  45. HashMap<String, bool *> OpenXREyeGazeInteractionExtension::get_requested_extensions() {
  46. HashMap<String, bool *> request_extensions;
  47. // Only enable this extension when requested.
  48. // We still register our meta data or the action map editor will fail.
  49. if (GLOBAL_GET("xr/openxr/extensions/eye_gaze_interaction") && (!OS::get_singleton()->has_feature("mobile") || OS::get_singleton()->has_feature(XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME))) {
  50. request_extensions[XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME] = &available;
  51. }
  52. return request_extensions;
  53. }
  54. void *OpenXREyeGazeInteractionExtension::set_system_properties_and_get_next_pointer(void *p_next_pointer) {
  55. if (!available) {
  56. return p_next_pointer;
  57. }
  58. properties.type = XR_TYPE_SYSTEM_EYE_GAZE_INTERACTION_PROPERTIES_EXT;
  59. properties.next = p_next_pointer;
  60. properties.supportsEyeGazeInteraction = false;
  61. return &properties;
  62. }
  63. PackedStringArray OpenXREyeGazeInteractionExtension::get_suggested_tracker_names() {
  64. PackedStringArray arr = { "/user/eyes_ext" };
  65. return arr;
  66. }
  67. bool OpenXREyeGazeInteractionExtension::is_available() {
  68. return available;
  69. }
  70. bool OpenXREyeGazeInteractionExtension::supports_eye_gaze_interaction() {
  71. // The extension being available only means that the OpenXR Runtime supports the extension.
  72. // The `supportsEyeGazeInteraction` is set to true if the device also supports this.
  73. // Thus both need to be true.
  74. // In addition, on mobile runtimes, the proper permission needs to be granted.
  75. if (available && properties.supportsEyeGazeInteraction) {
  76. return !OS::get_singleton()->has_feature("mobile") || OS::get_singleton()->has_feature("PERMISSION_XR_EXT_eye_gaze_interaction");
  77. }
  78. return false;
  79. }
  80. void OpenXREyeGazeInteractionExtension::on_register_metadata() {
  81. OpenXRInteractionProfileMetadata *metadata = OpenXRInteractionProfileMetadata::get_singleton();
  82. ERR_FAIL_NULL(metadata);
  83. // Eyes top path
  84. metadata->register_top_level_path("Eye gaze tracker", "/user/eyes_ext", XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME);
  85. // Eye gaze interaction
  86. metadata->register_interaction_profile("Eye gaze", "/interaction_profiles/ext/eye_gaze_interaction", XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME);
  87. metadata->register_io_path("/interaction_profiles/ext/eye_gaze_interaction", "Gaze pose", "/user/eyes_ext", "/user/eyes_ext/input/gaze_ext/pose", "", OpenXRAction::OPENXR_ACTION_POSE);
  88. }