Skip to content

Commit

Permalink
Expose the tracking confidence for the tracked hands
Browse files Browse the repository at this point in the history
This also resolves the issue where we were not receiving 'menu' gestures.
  • Loading branch information
m4gr3d committed Apr 13, 2022
1 parent e35e914 commit 35b870b
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 13 deletions.
2 changes: 1 addition & 1 deletion android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
package="org.godotengine.plugin.vr.openxr"
android:versionCode="10300"
android:versionName="1.3.0.beta6">
android:versionName="1.3.0.beta7">

<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="30" />

Expand Down
2 changes: 1 addition & 1 deletion config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ext {
ndkVersion : "21.4.7075529",
javaVersion : JavaVersion.VERSION_1_8,
versionCode : 10300, // Also update 'src/main/AndroidManifest.xml#versionCode' value
versionName : '1.3.0.beta6', // Also update 'src/main/AndroidManifest.xml#versionName' value
versionName : '1.3.0.beta7', // Also update 'src/main/AndroidManifest.xml#versionName' value
godotVersion : '3.4.4.stable',
]

Expand Down
2 changes: 2 additions & 0 deletions demo/Main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ camera = NodePath("../ARVRCamera")
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.109138, 0 )
controller_id = 3
script = ExtResource( 23 )
hide_for_no_tracking_confidence = true

[node name="AimPointer" parent="FPController/LeftHandAim" instance=ExtResource( 24 )]

Expand All @@ -192,6 +193,7 @@ camera = NodePath("../../ARVRCamera")
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.165836, 0.103508, 0 )
controller_id = 4
script = ExtResource( 23 )
hide_for_no_tracking_confidence = true

[node name="AimPointer" parent="FPController/RightHandAim" instance=ExtResource( 24 )]

Expand Down
25 changes: 19 additions & 6 deletions demo/addons/godot-openxr/scenes/controller.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,27 @@ extends ARVRController
signal activated
signal deactivated

export var hide_for_no_tracking_confidence = false

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
var should_be_visible = true
if get_is_active():
if !visible:
visible = true
if hide_for_no_tracking_confidence:
# Get the tracking confidence
var configuration = get_node("../Configuration")
if configuration:
var tracking_confidence = configuration.get_tracking_confidence(controller_id)
if tracking_confidence == 0:
should_be_visible = false
else:
should_be_visible = false

if visible != should_be_visible:
visible = should_be_visible
if should_be_visible:
print("Activated " + name)
emit_signal("activated")
elif visible:
visible = false
print("Deactivated " + name)
emit_signal("deactivated")
else:
print("Deactivated " + name)
emit_signal("deactivated")
9 changes: 8 additions & 1 deletion src/gdclasses/OpenXRConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ OpenXRConfig::OpenXRConfig() {
foveation_wrapper = XRFbFoveationExtensionWrapper::get_singleton();
performance_settings_wrapper = XRExtPerformanceSettingsExtensionWrapper::get_singleton();
passthrough_wrapper = XRFbPassthroughExtensionWrapper::get_singleton();
hand_tracking_wrapper = XRExtHandTrackingExtensionWrapper::get_singleton();
}

OpenXRConfig::~OpenXRConfig() {
Expand All @@ -83,6 +84,10 @@ OpenXRConfig::~OpenXRConfig() {
}
color_space_wrapper = nullptr;
display_refresh_rate_wrapper = nullptr;
foveation_wrapper = nullptr;
performance_settings_wrapper = nullptr;
passthrough_wrapper = nullptr;
hand_tracking_wrapper = nullptr;
}

void OpenXRConfig::_init() {
Expand Down Expand Up @@ -218,8 +223,10 @@ godot::Array OpenXRConfig::get_enabled_extensions() const {

int OpenXRConfig::get_tracking_confidence(const int p_godot_controller) const {
int confidence = 0;
if (openxr_api) {
if (openxr_api && openxr_api->is_input_map_controller(p_godot_controller)) {
confidence = int(openxr_api->get_controller_tracking_confidence(p_godot_controller));
} else if (hand_tracking_wrapper && hand_tracking_wrapper->is_hand_tracker_controller(p_godot_controller)) {
confidence = int(hand_tracking_wrapper->get_hand_tracker_tracking_confidence(p_godot_controller));
}
return confidence;
}
Expand Down
2 changes: 2 additions & 0 deletions src/gdclasses/OpenXRConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define OPENXR_CONFIG_H

#include "openxr/OpenXRApi.h"
#include "openxr/extensions/xr_ext_hand_tracking_extension_wrapper.h"
#include "openxr/extensions/xr_ext_performance_settings_extension_wrapper.h"
#include "openxr/extensions/xr_fb_color_space_extension_wrapper.h"
#include "openxr/extensions/xr_fb_display_refresh_rate_extension_wrapper.h"
Expand All @@ -23,6 +24,7 @@ class OpenXRConfig : public Node {
XRFbFoveationExtensionWrapper *foveation_wrapper = nullptr;
XRExtPerformanceSettingsExtensionWrapper *performance_settings_wrapper = nullptr;
XRFbPassthroughExtensionWrapper *passthrough_wrapper = nullptr;
XRExtHandTrackingExtensionWrapper *hand_tracking_wrapper = nullptr;

public:
static void _register_methods();
Expand Down
15 changes: 12 additions & 3 deletions src/openxr/OpenXRApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2593,10 +2593,19 @@ godot::Array OpenXRApi::get_enabled_extensions() const {
return arr;
}

bool OpenXRApi::is_input_map_controller(int p_godot_controller) {
for (const auto &inputmap : inputmaps) {
if (inputmap.godot_controller == p_godot_controller) {
return true;
}
}
return false;
}

TrackingConfidence OpenXRApi::get_controller_tracking_confidence(const int p_godot_controller) const {
for (int i = 0; i < USER_INPUT_MAX; i++) {
if (inputmaps[i].godot_controller == p_godot_controller) {
return inputmaps[i].tracking_confidence;
for (const auto &inputmap : inputmaps) {
if (inputmap.godot_controller == p_godot_controller) {
return inputmap.tracking_confidence;
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/openxr/OpenXRApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ class OpenXRApi {

godot::Array get_enabled_extensions() const;

bool is_input_map_controller(int p_godot_controller);

TrackingConfidence get_controller_tracking_confidence(const int p_godot_controller) const;

static const char *default_action_sets_json;
Expand Down
25 changes: 24 additions & 1 deletion src/openxr/extensions/xr_ext_hand_tracking_extension_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ bool XRExtHandTrackingExtensionWrapper::initialize_hand_tracking() {
hand_trackers[i].is_initialised = false;
hand_trackers[i].hand_tracker = XR_NULL_HANDLE;
hand_trackers[i].aim_state_godot_controller = -1;
hand_trackers[i].tracking_confidence = TrackingConfidence::TRACKING_CONFIDENCE_NONE;
}

#ifdef DEBUG
Expand All @@ -172,6 +173,7 @@ void XRExtHandTrackingExtensionWrapper::cleanup_hand_tracking() {
hand_trackers[i].is_initialised = false;
hand_trackers[i].hand_tracker = XR_NULL_HANDLE;
hand_trackers[i].aim_state_godot_controller = -1;
hand_trackers[i].tracking_confidence = TrackingConfidence::TRACKING_CONFIDENCE_NONE;
}
}
}
Expand Down Expand Up @@ -199,6 +201,24 @@ void XRExtHandTrackingExtensionWrapper::set_motion_range(uint32_t p_hand, XrHand
}
}

bool XRExtHandTrackingExtensionWrapper::is_hand_tracker_controller(const int p_godot_controller) {
for (const auto &hand_tracker : hand_trackers) {
if (hand_tracker.aim_state_godot_controller == p_godot_controller) {
return true;
}
}
return false;
}

TrackingConfidence XRExtHandTrackingExtensionWrapper::get_hand_tracker_tracking_confidence(const int p_godot_controller) {
for (const auto &hand_tracker : hand_trackers) {
if (hand_tracker.aim_state_godot_controller == p_godot_controller) {
return hand_tracker.tracking_confidence;
}
}
return TRACKING_CONFIDENCE_NONE;
}

void XRExtHandTrackingExtensionWrapper::update_handtracking() {
if (!hand_tracking_supported) {
return;
Expand Down Expand Up @@ -283,7 +303,7 @@ void XRExtHandTrackingExtensionWrapper::update_handtracking() {
hand_trackers[i].locations.isActive = false; // workaround, make sure its inactive
}

if (hand_tracking_aim_state_ext && hand_trackers[i].locations.isActive && check_bit(XR_HAND_TRACKING_AIM_VALID_BIT_FB, hand_trackers[i].aimState.status)) {
if (hand_tracking_aim_state_ext && hand_trackers[i].locations.isActive) {
// Controllers are updated based on the aim state's pose and pinches' strength
if (hand_trackers[i].aim_state_godot_controller == -1) {
hand_trackers[i].aim_state_godot_controller =
Expand All @@ -294,6 +314,8 @@ void XRExtHandTrackingExtensionWrapper::update_handtracking() {
true);
}

hand_trackers[i].tracking_confidence = check_bit(XR_HAND_TRACKING_AIM_VALID_BIT_FB, hand_trackers[i].aimState.status) ? TrackingConfidence::TRACKING_CONFIDENCE_HIGH : TrackingConfidence::TRACKING_CONFIDENCE_NONE;

int controller = hand_trackers[i].aim_state_godot_controller;

const float ws = ARVRServer::get_singleton()->get_world_scale();
Expand Down Expand Up @@ -361,6 +383,7 @@ void XRExtHandTrackingExtensionWrapper::update_handtracking() {
// Remove the controller, it's no longer active
arvr_api->godot_arvr_remove_controller(hand_trackers[i].aim_state_godot_controller);
hand_trackers[i].aim_state_godot_controller = -1;
hand_trackers[i].tracking_confidence = TrackingConfidence::TRACKING_CONFIDENCE_NONE;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class HandTracker {
XrHandJointLocationsEXT locations;

godot_int aim_state_godot_controller = -1;
TrackingConfidence tracking_confidence = TrackingConfidence::TRACKING_CONFIDENCE_NONE;
};

// Wrapper for the XR hand tracking related extensions.
Expand Down Expand Up @@ -52,6 +53,10 @@ class XRExtHandTrackingExtensionWrapper : public XRExtensionWrapper {

void set_motion_range(uint32_t p_hand, XrHandJointsMotionRangeEXT p_motion_range);

bool is_hand_tracker_controller(const int p_godot_controller);

TrackingConfidence get_hand_tracker_tracking_confidence(const int p_godot_controller);

protected:
XRExtHandTrackingExtensionWrapper();
~XRExtHandTrackingExtensionWrapper();
Expand Down

0 comments on commit 35b870b

Please sign in to comment.