diff --git a/modules/openxr/extensions/openxr_hand_tracking_extension.cpp b/modules/openxr/extensions/openxr_hand_tracking_extension.cpp index 617a23cfac..4c151fcb4b 100644 --- a/modules/openxr/extensions/openxr_hand_tracking_extension.cpp +++ b/modules/openxr/extensions/openxr_hand_tracking_extension.cpp @@ -171,6 +171,14 @@ void OpenXRHandTrackingExtension::on_process() { hand_trackers[i].velocities.jointVelocities = hand_trackers[i].joint_velocities; next_pointer = &hand_trackers[i].velocities; + if (hand_tracking_source_ext) { + hand_trackers[i].data_source.type = XR_TYPE_HAND_TRACKING_DATA_SOURCE_STATE_EXT; + hand_trackers[i].data_source.next = next_pointer; + hand_trackers[i].data_source.isActive = false; + hand_trackers[i].data_source.dataSource = XrHandTrackingDataSourceEXT(0); + next_pointer = &hand_trackers[i].data_source; + } + hand_trackers[i].locations.type = XR_TYPE_HAND_JOINT_LOCATIONS_EXT; hand_trackers[i].locations.next = next_pointer; hand_trackers[i].locations.isActive = false; @@ -189,11 +197,6 @@ void OpenXRHandTrackingExtension::on_process() { next_pointer = &motion_range_info; } - XrHandTrackingDataSourceStateEXT data_source_state = { XR_TYPE_HAND_TRACKING_DATA_SOURCE_STATE_EXT, next_pointer, false, XrHandTrackingDataSourceEXT(0) }; - if (hand_tracking_source_ext) { - next_pointer = &data_source_state; - } - XrHandJointsLocateInfoEXT locateInfo = { XR_TYPE_HAND_JOINTS_LOCATE_INFO_EXT, // type next_pointer, // next @@ -214,18 +217,6 @@ void OpenXRHandTrackingExtension::on_process() { !hand_trackers[i].locations.isActive || isnan(palm.position.x) || palm.position.x < -1000000.00 || palm.position.x > 1000000.00) { hand_trackers[i].locations.isActive = false; // workaround, make sure its inactive } - - if (hand_tracking_source_ext && data_source_state.isActive) { - if (data_source_state.dataSource == XR_HAND_TRACKING_DATA_SOURCE_UNOBSTRUCTED_EXT) { - hand_trackers[i].source = OPENXR_SOURCE_UNOBSTRUCTED; - } else if (data_source_state.dataSource == XR_HAND_TRACKING_DATA_SOURCE_CONTROLLER_EXT) { - hand_trackers[i].source = OPENXR_SOURCE_CONTROLLER; - } else { - hand_trackers[i].source = OPENXR_SOURCE_UNKNOWN; - } - } else { - hand_trackers[i].source = OPENXR_SOURCE_UNKNOWN; - } } } } @@ -268,7 +259,17 @@ XrHandJointsMotionRangeEXT OpenXRHandTrackingExtension::get_motion_range(HandTra OpenXRHandTrackingExtension::HandTrackedSource OpenXRHandTrackingExtension::get_hand_tracking_source(HandTrackedHands p_hand) const { ERR_FAIL_UNSIGNED_INDEX_V(p_hand, OPENXR_MAX_TRACKED_HANDS, OPENXR_SOURCE_UNKNOWN); - return hand_trackers[p_hand].source; + if (hand_tracking_source_ext && hand_trackers[p_hand].data_source.isActive) { + switch (hand_trackers[p_hand].data_source.dataSource) { + case XR_HAND_TRACKING_DATA_SOURCE_UNOBSTRUCTED_EXT: + return OPENXR_SOURCE_UNOBSTRUCTED; + + case XR_HAND_TRACKING_DATA_SOURCE_CONTROLLER_EXT: + return OPENXR_SOURCE_CONTROLLER; + } + } + + return OPENXR_SOURCE_UNKNOWN; } void OpenXRHandTrackingExtension::set_motion_range(HandTrackedHands p_hand, XrHandJointsMotionRangeEXT p_motion_range) { diff --git a/modules/openxr/extensions/openxr_hand_tracking_extension.h b/modules/openxr/extensions/openxr_hand_tracking_extension.h index 10ed48a97c..071a828768 100644 --- a/modules/openxr/extensions/openxr_hand_tracking_extension.h +++ b/modules/openxr/extensions/openxr_hand_tracking_extension.h @@ -53,11 +53,11 @@ public: struct HandTracker { bool is_initialized = false; XrHandJointsMotionRangeEXT motion_range = XR_HAND_JOINTS_MOTION_RANGE_UNOBSTRUCTED_EXT; - HandTrackedSource source = OPENXR_SOURCE_UNKNOWN; XrHandTrackerEXT hand_tracker = XR_NULL_HANDLE; XrHandJointLocationEXT joint_locations[XR_HAND_JOINT_COUNT_EXT]; XrHandJointVelocityEXT joint_velocities[XR_HAND_JOINT_COUNT_EXT]; + XrHandTrackingDataSourceStateEXT data_source; XrHandJointVelocitiesEXT velocities; XrHandJointLocationsEXT locations;