Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose OpenXR hand tracker handles #88566

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions modules/openxr/doc_classes/OpenXRAPIExtension.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
Returns an error string for the given [url=https://registry.khronos.org/OpenXR/specs/1.0/man/html/XrResult.html]XrResult[/url].
</description>
</method>
<method name="get_hand_tracker">
<return type="int" />
<param index="0" name="hand_index" type="int" />
<description>
Returns the corresponding [code]XRHandTrackerEXT[/code] handle for the given hand index value.
</description>
</method>
<method name="get_instance">
<return type="int" />
<description>
Expand Down
7 changes: 7 additions & 0 deletions modules/openxr/openxr_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "extensions/openxr_fb_display_refresh_rate_extension.h"
#include "extensions/openxr_fb_foveation_extension.h"
#include "extensions/openxr_fb_update_swapchain_extension.h"
#include "extensions/openxr_hand_tracking_extension.h"

#ifdef ANDROID_ENABLED
#define OPENXR_LOADER_NAME "libopenxr_loader.so"
Expand Down Expand Up @@ -1536,6 +1537,12 @@ void OpenXRAPI::cleanup_extension_wrappers() {
registered_extension_wrappers.clear();
}

XrHandTrackerEXT OpenXRAPI::get_hand_tracker(int p_hand_index) {
ERR_FAIL_INDEX_V(p_hand_index, OpenXRHandTrackingExtension::HandTrackedHands::OPENXR_MAX_TRACKED_HANDS, XR_NULL_HANDLE);
OpenXRHandTrackingExtension::HandTrackedHands hand = static_cast<OpenXRHandTrackingExtension::HandTrackedHands>(p_hand_index);
return OpenXRHandTrackingExtension::get_singleton()->get_hand_tracker(hand)->hand_tracker;
}

Size2 OpenXRAPI::get_recommended_target_size() {
ERR_FAIL_NULL_V(view_configuration_views, Size2());

Expand Down
2 changes: 2 additions & 0 deletions modules/openxr/openxr_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ class OpenXRAPI {
XrTime get_next_frame_time() { return frame_state.predictedDisplayTime + frame_state.predictedDisplayPeriod; }
bool can_render() { return instance != XR_NULL_HANDLE && session != XR_NULL_HANDLE && running && view_pose_valid && frame_state.shouldRender; }

XrHandTrackerEXT get_hand_tracker(int p_hand_index);

Size2 get_recommended_target_size();
XRPose::TrackingConfidence get_head_center(Transform3D &r_transform, Vector3 &r_linear_velocity, Vector3 &r_angular_velocity);
bool get_view_transform(uint32_t p_view, Transform3D &r_transform);
Expand Down
7 changes: 7 additions & 0 deletions modules/openxr/openxr_api_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ void OpenXRAPIExtension::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_next_frame_time"), &OpenXRAPIExtension::get_next_frame_time);
ClassDB::bind_method(D_METHOD("can_render"), &OpenXRAPIExtension::can_render);

ClassDB::bind_method(D_METHOD("get_hand_tracker", "hand_index"), &OpenXRAPIExtension::get_hand_tracker);

ClassDB::bind_method(D_METHOD("register_composition_layer_provider", "extension"), &OpenXRAPIExtension::register_composition_layer_provider);
ClassDB::bind_method(D_METHOD("unregister_composition_layer_provider", "extension"), &OpenXRAPIExtension::unregister_composition_layer_provider);

Expand Down Expand Up @@ -138,6 +140,11 @@ bool OpenXRAPIExtension::can_render() {
return OpenXRAPI::get_singleton()->can_render();
}

uint64_t OpenXRAPIExtension::get_hand_tracker(int p_hand_index) {
ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), 0);
return (uint64_t)OpenXRAPI::get_singleton()->get_hand_tracker(p_hand_index);
}

void OpenXRAPIExtension::register_composition_layer_provider(OpenXRExtensionWrapperExtension *p_extension) {
ERR_FAIL_NULL(OpenXRAPI::get_singleton());
OpenXRAPI::get_singleton()->register_composition_layer_provider(p_extension);
Expand Down
2 changes: 2 additions & 0 deletions modules/openxr/openxr_api_extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class OpenXRAPIExtension : public RefCounted {
int64_t get_next_frame_time();
bool can_render();

uint64_t get_hand_tracker(int p_hand_index);

void register_composition_layer_provider(OpenXRExtensionWrapperExtension *p_extension);
void unregister_composition_layer_provider(OpenXRExtensionWrapperExtension *p_extension);

Expand Down
Loading