Skip to content

Commit

Permalink
Add support for the OpenXR Eye gaze interaction extension
Browse files Browse the repository at this point in the history
  • Loading branch information
BastiaanOlij committed Jun 9, 2023
1 parent e188d61 commit 145c56d
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 2 deletions.
1 change: 1 addition & 0 deletions modules/openxr/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ if env["opengl3"]:

env_openxr.add_source_files(module_obj, "extensions/openxr_palm_pose_extension.cpp")
env_openxr.add_source_files(module_obj, "extensions/openxr_composition_layer_depth_extension.cpp")
env_openxr.add_source_files(module_obj, "extensions/openxr_eye_gaze_interaction.cpp")
env_openxr.add_source_files(module_obj, "extensions/openxr_htc_controller_extension.cpp")
env_openxr.add_source_files(module_obj, "extensions/openxr_htc_vive_tracker_extension.cpp")
env_openxr.add_source_files(module_obj, "extensions/openxr_huawei_controller_extension.cpp")
Expand Down
8 changes: 7 additions & 1 deletion modules/openxr/action_map/openxr_action_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ void OpenXRActionMap::create_default_action_sets() {
"/user/vive_tracker_htcx/role/waist,"
"/user/vive_tracker_htcx/role/chest,"
"/user/vive_tracker_htcx/role/camera,"
"/user/vive_tracker_htcx/role/keyboard");
"/user/vive_tracker_htcx/role/keyboard,"
"/user/eyes_ext");
Ref<OpenXRAction> aim_pose = action_set->add_new_action("aim_pose", "Aim pose", OpenXRAction::OPENXR_ACTION_POSE, "/user/hand/left,/user/hand/right");
Ref<OpenXRAction> grip_pose = action_set->add_new_action("grip_pose", "Grip pose", OpenXRAction::OPENXR_ACTION_POSE, "/user/hand/left,/user/hand/right");
Ref<OpenXRAction> palm_pose = action_set->add_new_action("palm_pose", "Palm pose", OpenXRAction::OPENXR_ACTION_POSE, "/user/hand/left,/user/hand/right");
Expand Down Expand Up @@ -502,6 +503,11 @@ void OpenXRActionMap::create_default_action_sets() {
"/user/vive_tracker_htcx/role/camera/output/haptic,"
"/user/vive_tracker_htcx/role/keyboard/output/haptic");
add_interaction_profile(profile);

// Create our eye gaze interaction profile
profile = OpenXRInteractionProfile::new_profile("/interaction_profiles/ext/eye_gaze_interaction");
profile->add_new_binding(default_pose, "/user/eyes_ext/input/gaze_ext/pose");
add_interaction_profile(profile);
}

void OpenXRActionMap::create_editor_action_sets() {
Expand Down
18 changes: 18 additions & 0 deletions modules/openxr/doc_classes/OpenXRInterface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
Returns display refresh rates supported by the current HMD. Only returned if this feature is supported by the OpenXR runtime and after the interface has been initialized.
</description>
</method>
<method name="get_eye_gaze_capabilities">
<return type="int" enum="OpenXRInterface.EyeGazeCapabilities" />
<description>
Returns the capabilities of the eye gaze interaction extension.
Note: this only returns a valid value after OpenXR has been initialized.
</description>
</method>
<method name="is_action_set_active" qualifiers="const">
<return type="bool" />
<param index="0" name="name" type="String" />
Expand Down Expand Up @@ -74,4 +81,15 @@
</description>
</signal>
</signals>
<constants>
<constant name="XR_EYE_GAZE_UNAVAILABLE" value="0" enum="EyeGazeCapabilities">
No eye gaze interaction functionality is available.
</constant>
<constant name="XR_EYE_GAZE_LIMITED" value="1" enum="EyeGazeCapabilities">
Limited eye gaze interaction functionality is available, pose data will be returned but is not accurate enough for aiming/targeting.
</constant>
<constant name="XR_EYE_GAZE_SUPPORTED" value="2" enum="EyeGazeCapabilities">
The eye gaze interaction functionality is fully supported.
</constant>
</constants>
</class>
89 changes: 89 additions & 0 deletions modules/openxr/extensions/openxr_eye_gaze_interaction.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**************************************************************************/
/* openxr_eye_gaze_interaction.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#include "openxr_eye_gaze_interaction.h"
#include "../action_map/openxr_interaction_profile_meta_data.h"

OpenXREyeGazeInteractionExtension *OpenXREyeGazeInteractionExtension::singleton = nullptr;

OpenXREyeGazeInteractionExtension::OpenXREyeGazeInteractionExtension() {
singleton = this;
}

OpenXREyeGazeInteractionExtension::~OpenXREyeGazeInteractionExtension() {
singleton = nullptr;
}

HashMap<String, bool *> OpenXREyeGazeInteractionExtension::get_requested_extensions() {
HashMap<String, bool *> request_extensions;

request_extensions[XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME] = &available;

return request_extensions;
}

void *OpenXREyeGazeInteractionExtension::set_system_properties_and_get_next_pointer(void *p_next_pointer) {
if (!available) {
return p_next_pointer;
}

properties.type = XR_TYPE_SYSTEM_EYE_GAZE_INTERACTION_PROPERTIES_EXT;
properties.next = p_next_pointer;
properties.supportsEyeGazeInteraction = false;

return &properties;
}

bool OpenXREyeGazeInteractionExtension::is_available() {
return available;
}

bool OpenXREyeGazeInteractionExtension::supports_eye_gaze() {
// note, supportsEyeGazeInteraction is somewhat confusingly named, it does not denote that this
// capability is not available even though the extension is, it denotes its limited.
//
// From the OpenXR Specification:
// supportsEyeGazeInteraction the runtime must set this value to XR_TRUE when eye gaze sufficient
// for use cases such as aiming or targeting is supported by the current device,
// otherwise the runtime must set this to XR_FALSE
return properties.supportsEyeGazeInteraction;
}

void OpenXREyeGazeInteractionExtension::on_register_metadata() {
OpenXRInteractionProfileMetaData *metadata = OpenXRInteractionProfileMetaData::get_singleton();
ERR_FAIL_NULL(metadata);

// Eyes top path
metadata->register_top_level_path("Eye gaze tracker", "/user/eyes_ext", XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME);

// Eye gaze interaction
metadata->register_interaction_profile("Eye gaze", "/interaction_profiles/ext/eye_gaze_interaction", XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME);
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);
}
58 changes: 58 additions & 0 deletions modules/openxr/extensions/openxr_eye_gaze_interaction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**************************************************************************/
/* openxr_eye_gaze_interaction.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef OPENXR_EYE_GAZE_INTERACTION_H
#define OPENXR_EYE_GAZE_INTERACTION_H

#include "openxr_extension_wrapper.h"

class OpenXREyeGazeInteractionExtension : public OpenXRExtensionWrapper {
public:
static OpenXREyeGazeInteractionExtension *get_singleton() { return singleton; }

OpenXREyeGazeInteractionExtension();
~OpenXREyeGazeInteractionExtension();

virtual HashMap<String, bool *> get_requested_extensions() override;
virtual void *set_system_properties_and_get_next_pointer(void *p_next_pointer) override;

bool is_available();
bool supports_eye_gaze();

virtual void on_register_metadata() override;

private:
static OpenXREyeGazeInteractionExtension *singleton;

bool available = false;
XrSystemEyeGazeInteractionPropertiesEXT properties;
};

#endif // OPENXR_EYE_GAZE_INTERACTION_H
31 changes: 30 additions & 1 deletion modules/openxr/openxr_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include "core/io/resource_saver.h"
#include "servers/rendering/rendering_server_globals.h"

#include "extensions/openxr_eye_gaze_interaction.h"

void OpenXRInterface::_bind_methods() {
// lifecycle signals
ADD_SIGNAL(MethodInfo("session_begun"));
Expand All @@ -57,6 +59,12 @@ void OpenXRInterface::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_action_sets"), &OpenXRInterface::get_action_sets);

ClassDB::bind_method(D_METHOD("get_available_display_refresh_rates"), &OpenXRInterface::get_available_display_refresh_rates);

ClassDB::bind_method(D_METHOD("get_eye_gaze_capabilities"), &OpenXRInterface::get_eye_gaze_capabilities);

BIND_ENUM_CONSTANT(XR_EYE_GAZE_UNAVAILABLE);
BIND_ENUM_CONSTANT(XR_EYE_GAZE_LIMITED);
BIND_ENUM_CONSTANT(XR_EYE_GAZE_SUPPORTED);
}

StringName OpenXRInterface::get_name() const {
Expand Down Expand Up @@ -90,7 +98,9 @@ PackedStringArray OpenXRInterface::get_suggested_tracker_names() const {
"/user/vive_tracker_htcx/role/waist",
"/user/vive_tracker_htcx/role/chest",
"/user/vive_tracker_htcx/role/camera",
"/user/vive_tracker_htcx/role/keyboard"
"/user/vive_tracker_htcx/role/keyboard",

"/user/eyes_ext",
};

return arr;
Expand Down Expand Up @@ -641,6 +651,25 @@ Array OpenXRInterface::get_available_display_refresh_rates() const {
}
}

OpenXRInterface::EyeGazeCapabilities OpenXRInterface::get_eye_gaze_capabilities() {
if (openxr_api == nullptr) {
return XR_EYE_GAZE_UNAVAILABLE;
} else if (!openxr_api->is_initialized()) {
return XR_EYE_GAZE_UNAVAILABLE;
} else {
OpenXREyeGazeInteractionExtension *eye_gaze_ext = OpenXREyeGazeInteractionExtension::get_singleton();
if (eye_gaze_ext == nullptr) {
return XR_EYE_GAZE_UNAVAILABLE;
} else if (!eye_gaze_ext->is_available()) {
return XR_EYE_GAZE_UNAVAILABLE;
} else if (eye_gaze_ext->supports_eye_gaze()) {
return XR_EYE_GAZE_SUPPORTED;
} else {
return XR_EYE_GAZE_LIMITED;
}
}
}

bool OpenXRInterface::is_action_set_active(const String &p_action_set) const {
for (ActionSet *action_set : action_sets) {
if (action_set->action_set_name == p_action_set) {
Expand Down
11 changes: 11 additions & 0 deletions modules/openxr/openxr_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ class OpenXRInterface : public XRInterface {
virtual PackedStringArray get_suggested_tracker_names() const override;
virtual TrackingStatus get_tracking_status() const override;

// Eye tracking
enum EyeGazeCapabilities {
XR_EYE_GAZE_UNAVAILABLE, // The eye gaze interaction is not available,
XR_EYE_GAZE_LIMITED, // The eye gaze interaction is available in limited form,
XR_EYE_GAZE_SUPPORTED, // The eye gaze interaction is supported
};

EyeGazeCapabilities get_eye_gaze_capabilities();

bool initialize_on_startup() const;
virtual bool is_initialized() const override;
virtual bool initialize() override;
Expand Down Expand Up @@ -166,4 +175,6 @@ class OpenXRInterface : public XRInterface {
~OpenXRInterface();
};

VARIANT_ENUM_CAST(OpenXRInterface::EyeGazeCapabilities);

#endif // OPENXR_INTERFACE_H
2 changes: 2 additions & 0 deletions modules/openxr/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#endif

#include "extensions/openxr_composition_layer_depth_extension.h"
#include "extensions/openxr_eye_gaze_interaction.h"
#include "extensions/openxr_fb_display_refresh_rate_extension.h"
#include "extensions/openxr_fb_passthrough_extension_wrapper.h"
#include "extensions/openxr_hand_tracking_extension.h"
Expand Down Expand Up @@ -94,6 +95,7 @@ void initialize_openxr_module(ModuleInitializationLevel p_level) {
#endif

// register our other extensions
OpenXRAPI::register_extension_wrapper(memnew(OpenXREyeGazeInteractionExtension));
OpenXRAPI::register_extension_wrapper(memnew(OpenXRPalmPoseExtension));
OpenXRAPI::register_extension_wrapper(memnew(OpenXRPicoControllerExtension));
OpenXRAPI::register_extension_wrapper(memnew(OpenXRCompositionLayerDepthExtension));
Expand Down

0 comments on commit 145c56d

Please sign in to comment.