diff --git a/client/render/imgui_impl.cpp b/client/render/imgui_impl.cpp index 041ac0c3..bdf43c69 100644 --- a/client/render/imgui_impl.cpp +++ b/client/render/imgui_impl.cpp @@ -580,10 +580,10 @@ std::vector imgui_context::read_controllers_sta current_aim_interaction = 1; if (ctrl.hand) { - if (auto hand = ctrl.hand->locate(world, display_time); hand.joints and hand.is_input_source()) + if (auto hand = ctrl.hand->locate(world, display_time).joints) { - XrHandJointLocationEXT & index_tip = (*hand.joints)[XR_HAND_JOINT_INDEX_TIP_EXT].first; - XrHandJointLocationEXT & palm = (*hand.joints)[XR_HAND_JOINT_PALM_EXT].first; + XrHandJointLocationEXT & index_tip = (*hand)[XR_HAND_JOINT_INDEX_TIP_EXT].first; + XrHandJointLocationEXT & palm = (*hand)[XR_HAND_JOINT_PALM_EXT].first; if (index_tip.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT) { diff --git a/client/scenes/lobby.cpp b/client/scenes/lobby.cpp index 6dc10aaa..6144f2f6 100644 --- a/client/scenes/lobby.cpp +++ b/client/scenes/lobby.cpp @@ -980,29 +980,27 @@ void scenes::lobby::render(const XrFrameState & frame_state) { auto windows = imgui_ctx->windows(); - auto left = left_hand->locate(world_space, frame_state.predictedDisplayTime); - if (left.joints) + auto left = left_hand->locate(world_space, frame_state.predictedDisplayTime).joints; + if (left) { - if (left.is_input_source()) - stick_finger_to_gui(*left.joints, windows); + stick_finger_to_gui(*left, windows); hide_left_controller = true; } - auto right = right_hand->locate(world_space, frame_state.predictedDisplayTime); - if (right.joints) + auto right = right_hand->locate(world_space, frame_state.predictedDisplayTime).joints; + if (right) { - if (right.is_input_source()) - stick_finger_to_gui(*right.joints, windows); + stick_finger_to_gui(*right, windows); hide_right_controller = true; } - hand_model::apply(world, left.joints ? &*left.joints : nullptr, right.joints ? &*right.joints : nullptr); + hand_model::apply(world, left ? &*left : nullptr, right ? &*right : nullptr); - if (not new_gui_position and head_position and left.joints and left.is_input_source()) - new_gui_position = check_recenter_gesture(xr::spaces::palm_left, *left.joints, *head_position); + if (not new_gui_position and head_position and left) + new_gui_position = check_recenter_gesture(xr::spaces::palm_left, *left, *head_position); - if (not new_gui_position and head_position and right.joints and right.is_input_source()) - new_gui_position = check_recenter_gesture(xr::spaces::palm_right, *right.joints, *head_position); + if (not new_gui_position and head_position and right) + new_gui_position = check_recenter_gesture(xr::spaces::palm_right, *right, *head_position); } if (head_position and new_gui_position) diff --git a/client/scenes/stream_gui.cpp b/client/scenes/stream_gui.cpp index 3b7fae3e..d2ce8a88 100644 --- a/client/scenes/stream_gui.cpp +++ b/client/scenes/stream_gui.cpp @@ -1095,15 +1095,15 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte if (left_hand and right_hand) { - auto left = left_hand->locate(world_space, predicted_display_time); - auto right = right_hand->locate(world_space, predicted_display_time); + auto left = left_hand->locate(world_space, predicted_display_time).joints; + auto right = right_hand->locate(world_space, predicted_display_time).joints; - if (left.joints and left.is_input_source() and - xr::hand_tracker::check_flags(*left.joints, XR_SPACE_LOCATION_POSITION_TRACKED_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT, 0)) + if (left and + xr::hand_tracker::check_flags(*left, XR_SPACE_LOCATION_POSITION_TRACKED_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT, 0)) hide_left_controller = true; - if (right.joints and right.is_input_source() and - xr::hand_tracker::check_flags(*right.joints, XR_SPACE_LOCATION_POSITION_TRACKED_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT, 0)) + if (right and + xr::hand_tracker::check_flags(*right, XR_SPACE_LOCATION_POSITION_TRACKED_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT, 0)) hide_right_controller = true; } diff --git a/client/scenes/stream_tracking.cpp b/client/scenes/stream_tracking.cpp index 0cbfe466..84aaa350 100644 --- a/client/scenes/stream_tracking.cpp +++ b/client/scenes/stream_tracking.cpp @@ -400,10 +400,14 @@ void scenes::stream::tracking() if (hand_tracking) { + std::array data_sources = { + XR_HAND_TRACKING_DATA_SOURCE_UNOBSTRUCTED_EXT, + XR_HAND_TRACKING_DATA_SOURCE_CONTROLLER_EXT, + }; if (std::ranges::contains(pattern, device_id::LEFT_HAND, &to_headset::tracking_control::sample::device)) { if (not left_hand) - left_hand = session.create_hand_tracker(XR_HAND_LEFT_EXT); + left_hand = session.create_hand_tracker(XR_HAND_LEFT_EXT, data_sources); } else left_hand.reset(); @@ -411,7 +415,7 @@ void scenes::stream::tracking() if (std::ranges::contains(pattern, device_id::RIGHT_HAND, &to_headset::tracking_control::sample::device)) { if (not right_hand) - right_hand = session.create_hand_tracker(XR_HAND_RIGHT_EXT); + right_hand = session.create_hand_tracker(XR_HAND_RIGHT_EXT, data_sources); } else right_hand.reset(); diff --git a/client/xr/hand_tracker.cpp b/client/xr/hand_tracker.cpp index 88221dcd..0831c48e 100644 --- a/client/xr/hand_tracker.cpp +++ b/client/xr/hand_tracker.cpp @@ -26,30 +26,25 @@ #include #include -xr::hand_tracker::hand_tracker(instance & inst, session & session, const XrHandTrackerCreateInfoEXT & info) : +xr::hand_tracker::hand_tracker(instance & inst, session & session, const XrHandTrackerCreateInfoEXT & info, std::span sources) : handle(inst.get_proc("xrDestroyHandTrackerEXT")), hand_{info.hand} { auto xrCreateHandTrackerEXT = inst.get_proc("xrCreateHandTrackerEXT"); assert(xrCreateHandTrackerEXT); xrLocateHandJointsEXT = inst.get_proc("xrLocateHandJointsEXT"); - hand_tracking_data_source_supported = inst.has_extension(XR_EXT_HAND_TRACKING_DATA_SOURCE_EXTENSION_NAME); + if (inst.has_extension(XR_FB_HAND_TRACKING_MESH_EXTENSION_NAME)) xrGetHandMeshFB = inst.get_proc("xrGetHandMeshFB"); - if (hand_tracking_data_source_supported) + if (not sources.empty() and inst.has_extension(XR_EXT_HAND_TRACKING_DATA_SOURCE_EXTENSION_NAME)) { - // request both sources, callers of locate() decide how to use the results - std::array data_sources = { - XR_HAND_TRACKING_DATA_SOURCE_UNOBSTRUCTED_EXT, - XR_HAND_TRACKING_DATA_SOURCE_CONTROLLER_EXT, - }; - + use_data_source = true; XrHandTrackingDataSourceInfoEXT data_source_info{ .type = XR_TYPE_HAND_TRACKING_DATA_SOURCE_INFO_EXT, .next = info.next, - .requestedDataSourceCount = static_cast(data_sources.size()), - .requestedDataSources = data_sources.data(), + .requestedDataSourceCount = static_cast(sources.size()), + .requestedDataSources = sources.data(), }; auto create_info = info; @@ -103,7 +98,7 @@ xr::hand_tracker::located_hand xr::hand_tracker::locate(XrSpace space, XrTime ti .jointCount = joints_pos.size(), .jointLocations = joints_pos.data(), }; - if (hand_tracking_data_source_supported) + if (use_data_source) locations.next = &data_source_state; CHECK_XR(xrLocateHandJointsEXT(id, &info, &locations)); @@ -126,7 +121,7 @@ xr::hand_tracker::located_hand xr::hand_tracker::locate(XrSpace space, XrTime ti } } - if (hand_tracking_data_source_supported) + if (use_data_source) { res.data_source = data_source_state.dataSource; if (not data_source_state.isActive) diff --git a/client/xr/hand_tracker.h b/client/xr/hand_tracker.h index fdc1c9ea..ef4d1941 100644 --- a/client/xr/hand_tracker.h +++ b/client/xr/hand_tracker.h @@ -22,6 +22,7 @@ #include "utils/handle.h" #include #include +#include #include #include #include @@ -41,13 +42,6 @@ public: { std::optional joints; std::optional data_source; - - // should these joints be used for input? - // true if UNOBSTRUCTED or XR_EXT_hand_tracking_data_source not supported - bool is_input_source() const - { - return !data_source or *data_source == XR_HAND_TRACKING_DATA_SOURCE_UNOBSTRUCTED_EXT; - } }; struct mesh_data @@ -66,13 +60,13 @@ public: private: PFN_xrLocateHandJointsEXT xrLocateHandJointsEXT{}; PFN_xrGetHandMeshFB xrGetHandMeshFB{}; - bool hand_tracking_data_source_supported = false; + bool use_data_source = false; std::optional cached_hand_mesh_fb; bool hand_mesh_fb_fetched = false; XrHandEXT hand_; public: - hand_tracker(instance & inst, session & session, const XrHandTrackerCreateInfoEXT & info); + hand_tracker(instance & inst, session & session, const XrHandTrackerCreateInfoEXT & info, std::span sources = {}); located_hand locate(XrSpace space, XrTime time); const mesh_data * mesh(); diff --git a/client/xr/session.cpp b/client/xr/session.cpp index a925e5be..ca04acbb 100644 --- a/client/xr/session.cpp +++ b/client/xr/session.cpp @@ -99,7 +99,7 @@ xr::space xr::session::create_action_space(XrAction action, const XrPosef & pose return s; } -xr::hand_tracker xr::session::create_hand_tracker(XrHandEXT hand, XrHandJointSetEXT hand_joint_set) +xr::hand_tracker xr::session::create_hand_tracker(XrHandEXT hand, std::span sources, XrHandJointSetEXT hand_joint_set) { return { *inst, @@ -109,7 +109,9 @@ xr::hand_tracker xr::session::create_hand_tracker(XrHandEXT hand, XrHandJointSet .next = nullptr, .hand = hand, .handJointSet = hand_joint_set, - }}; + }, + sources, + }; } std::vector xr::session::get_swapchain_formats() const diff --git a/client/xr/session.h b/client/xr/session.h index 52a37868..8fb5c6c7 100644 --- a/client/xr/session.h +++ b/client/xr/session.h @@ -62,7 +62,7 @@ public: std::vector get_reference_spaces() const; space create_reference_space(XrReferenceSpaceType ref, const XrPosef & pose = {{0, 0, 0, 1}, {0, 0, 0}}); space create_action_space(XrAction action, const XrPosef & pose = {{0, 0, 0, 1}, {0, 0, 0}}); - hand_tracker create_hand_tracker(XrHandEXT hand, XrHandJointSetEXT hand_joint_set = XR_HAND_JOINT_SET_DEFAULT_EXT); + hand_tracker create_hand_tracker(XrHandEXT hand, std::span sources = {}, XrHandJointSetEXT hand_joint_set = XR_HAND_JOINT_SET_DEFAULT_EXT); std::vector get_swapchain_formats() const;