Skip to content

Commit

Permalink
Fix issues when hand-tracking is disabled in project settings (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsnopek authored Aug 25, 2024
1 parent 8f9488b commit 9ff21e6
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,14 @@ PackedStringArray OpenXRFbHandTrackingAimExtensionWrapper::_get_suggested_tracke
}

void OpenXRFbHandTrackingAimExtensionWrapper::_on_state_ready() {
is_project_setting_enabled = ProjectSettings::get_singleton()->get_setting_with_override("xr/openxr/extensions/hand_tracking_aim");
// It would be great to not even request the extension, but the ProjectSettings singleton isn't available early enough.
ProjectSettings *project_settings = ProjectSettings::get_singleton();
bool is_project_setting_enabled = (bool)project_settings->get_setting_with_override("xr/openxr/extensions/hand_tracking") && (bool)project_settings->get_setting_with_override("xr/openxr/extensions/hand_tracking_aim");
if (!is_project_setting_enabled) {
fb_hand_tracking_aim_ext = false;
}

if (!is_enabled()) {
return;
}

Expand Down Expand Up @@ -139,7 +145,7 @@ uint64_t OpenXRFbHandTrackingAimExtensionWrapper::_set_hand_joint_locations_and_
}

void OpenXRFbHandTrackingAimExtensionWrapper::_on_process() {
if (!is_enabled() || !is_project_setting_enabled) {
if (!is_enabled()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

#include "extensions/openxr_fb_hand_tracking_capsules_extension_wrapper.h"

#include <godot_cpp/classes/project_settings.hpp>

using namespace godot;

OpenXRFbHandTrackingCapsulesExtensionWrapper *OpenXRFbHandTrackingCapsulesExtensionWrapper::singleton = nullptr;
Expand Down Expand Up @@ -79,6 +81,14 @@ void OpenXRFbHandTrackingCapsulesExtensionWrapper::_on_instance_destroyed() {
cleanup();
}

void OpenXRFbHandTrackingCapsulesExtensionWrapper::_on_state_ready() {
// It would be great to not even request the extension, but the ProjectSettings singleton isn't available early enough.
bool is_project_setting_enabled = (bool)ProjectSettings::get_singleton()->get_setting_with_override("xr/openxr/extensions/hand_tracking");
if (!is_project_setting_enabled) {
fb_hand_tracking_capsules_ext = false;
}
}

uint64_t OpenXRFbHandTrackingCapsulesExtensionWrapper::_set_hand_joint_locations_and_get_next_pointer(int32_t p_hand_index, void *p_next_pointer) {
if (!fb_hand_tracking_capsules_ext) {
return reinterpret_cast<uint64_t>(p_next_pointer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "extensions/openxr_fb_hand_tracking_mesh_extension_wrapper.h"

#include <godot_cpp/classes/open_xrapi_extension.hpp>
#include <godot_cpp/classes/project_settings.hpp>
#include <godot_cpp/classes/xr_hand_tracker.hpp>
#include <godot_cpp/variant/utility_functions.hpp>

Expand Down Expand Up @@ -101,6 +102,14 @@ void OpenXRFbHandTrackingMeshExtensionWrapper::_on_instance_destroyed() {
cleanup();
}

void OpenXRFbHandTrackingMeshExtensionWrapper::_on_state_ready() {
// It would be great to not even request the extension, but the ProjectSettings singleton isn't available early enough.
bool is_project_setting_enabled = (bool)ProjectSettings::get_singleton()->get_setting_with_override("xr/openxr/extensions/hand_tracking");
if (!is_project_setting_enabled) {
fb_hand_tracking_mesh_ext = false;
}
}

uint64_t OpenXRFbHandTrackingMeshExtensionWrapper::_set_hand_joint_locations_and_get_next_pointer(int32_t p_hand_index, void *p_next_pointer) {
if (!fb_hand_tracking_mesh_ext) {
return reinterpret_cast<uint64_t>(p_next_pointer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class OpenXRFbHandTrackingAimExtensionWrapper : public OpenXRExtensionWrapperExt
const String TRACKER_NAME_RIGHT = "/user/fbhandaim/right";

bool fb_hand_tracking_aim_ext = false;
bool is_project_setting_enabled = false;

Ref<XRPositionalTracker> trackers[Hand::HAND_MAX];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class OpenXRFbHandTrackingCapsulesExtensionWrapper : public OpenXRExtensionWrapp
godot::Dictionary _get_requested_extensions() override;

void _on_instance_destroyed() override;
void _on_state_ready() override;

uint64_t _set_hand_joint_locations_and_get_next_pointer(int32_t p_hand_index, void *p_next_pointer) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ class OpenXRFbHandTrackingMeshExtensionWrapper : public OpenXRExtensionWrapperEx
godot::Dictionary _get_requested_extensions() override;

void _on_instance_created(uint64_t instance) override;

void _on_instance_destroyed() override;

void _on_state_ready() override;

uint64_t _set_hand_joint_locations_and_get_next_pointer(int32_t p_hand_index, void *p_next_pointer) override;

void _on_process() override;
Expand Down
1 change: 1 addition & 0 deletions samples/meta-body-tracking-sample/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ textures/vram_compression/import_etc2_astc=true

openxr/enabled=true
openxr/reference_space=2
openxr/extensions/hand_tracking=true
openxr/extensions/eye_gaze_interaction=true
shaders/enabled=true
1 change: 1 addition & 0 deletions samples/meta-hand-tracking-sample/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ textures/vram_compression/import_etc2_astc=true

openxr/enabled=true
openxr/reference_space=2
openxr/extensions/hand_tracking=true
shaders/enabled=true
openxr/extensions/hand_tracking_aim=true

0 comments on commit 9ff21e6

Please sign in to comment.