openxr_eye_gaze_interaction.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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/os/os.h"
  32. #include "../action_map/openxr_interaction_profile_metadata.h"
  33. OpenXREyeGazeInteractionExtension *OpenXREyeGazeInteractionExtension::singleton = nullptr;
  34. OpenXREyeGazeInteractionExtension *OpenXREyeGazeInteractionExtension::get_singleton() {
  35. ERR_FAIL_NULL_V(singleton, nullptr);
  36. return singleton;
  37. }
  38. OpenXREyeGazeInteractionExtension::OpenXREyeGazeInteractionExtension() {
  39. singleton = this;
  40. }
  41. OpenXREyeGazeInteractionExtension::~OpenXREyeGazeInteractionExtension() {
  42. singleton = nullptr;
  43. }
  44. HashMap<String, bool *> OpenXREyeGazeInteractionExtension::get_requested_extensions() {
  45. HashMap<String, bool *> request_extensions;
  46. request_extensions[XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME] = &available;
  47. return request_extensions;
  48. }
  49. void *OpenXREyeGazeInteractionExtension::set_system_properties_and_get_next_pointer(void *p_next_pointer) {
  50. if (!available) {
  51. return p_next_pointer;
  52. }
  53. properties.type = XR_TYPE_SYSTEM_EYE_GAZE_INTERACTION_PROPERTIES_EXT;
  54. properties.next = p_next_pointer;
  55. properties.supportsEyeGazeInteraction = false;
  56. return &properties;
  57. }
  58. bool OpenXREyeGazeInteractionExtension::is_available() {
  59. return available;
  60. }
  61. bool OpenXREyeGazeInteractionExtension::supports_eye_gaze_interaction() {
  62. // The extension being available only means that the OpenXR Runtime supports the extension.
  63. // The `supportsEyeGazeInteraction` is set to true if the device also supports this.
  64. // Thus both need to be true.
  65. // In addition, on mobile runtimes, the proper permission needs to be granted.
  66. if (available && properties.supportsEyeGazeInteraction) {
  67. return !OS::get_singleton()->has_feature("mobile") || OS::get_singleton()->has_feature("PERMISSION_XR_EXT_eye_gaze_interaction");
  68. }
  69. return false;
  70. }
  71. void OpenXREyeGazeInteractionExtension::on_register_metadata() {
  72. OpenXRInteractionProfileMetadata *metadata = OpenXRInteractionProfileMetadata::get_singleton();
  73. ERR_FAIL_NULL(metadata);
  74. // Eyes top path
  75. metadata->register_top_level_path("Eye gaze tracker", "/user/eyes_ext", XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME);
  76. // Eye gaze interaction
  77. metadata->register_interaction_profile("Eye gaze", "/interaction_profiles/ext/eye_gaze_interaction", XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME);
  78. 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);
  79. }