From 99a5685c34b5ecd25946952ed17285232b680835 Mon Sep 17 00:00:00 2001 From: Guillaume Meunier Date: Sun, 24 Mar 2024 14:30:43 +0100 Subject: [PATCH] When the runtime does not track the hands: - Hide them in the lobby - Don't send tracking data in the stream --- client/scenes/hand_model.cpp | 42 ++++++++++++++--------- client/scenes/hand_model.h | 1 + client/scenes/stream_tracking.cpp | 53 ++++++++++++++++-------------- client/xr/hand_tracker.cpp | 6 ++-- client/xr/hand_tracker.h | 3 +- common/wivrn_packets.h | 4 +-- server/driver/hand_joints_list.cpp | 36 ++++++++++++-------- 7 files changed, 84 insertions(+), 61 deletions(-) diff --git a/client/scenes/hand_model.cpp b/client/scenes/hand_model.cpp index ebedb817..3dfda926 100644 --- a/client/scenes/hand_model.cpp +++ b/client/scenes/hand_model.cpp @@ -19,11 +19,12 @@ #include "hand_model.h" #include "openxr/openxr.h" #include "utils/ranges.h" +#include hand_model::hand_model(xr::hand_tracker & hand, const std::filesystem::path & gltf_path, scene_loader & loader, scene_data & scene) : hand(hand) { - node_handle root_node = scene.new_node(); + root_node = scene.new_node(); root_node->name = gltf_path.stem(); scene.import(loader(gltf_path), root_node); @@ -61,24 +62,33 @@ hand_model::hand_model(xr::hand_tracker & hand, const std::filesystem::path & gl void hand_model::apply(XrSpace world_space, XrTime predicted_display_time) { - std::array joints_location = hand.locate(world_space, predicted_display_time); + auto joints_location = hand.locate(world_space, predicted_display_time); - for(auto&& [joint, loc]: utils::zip(joints, joints_location)) + if (joints_location) { - if (!joint) - continue; + root_node->visible = true; - joint->position = { - loc.first.pose.position.x, - loc.first.pose.position.y, - loc.first.pose.position.z - }; + for(auto&& [joint, loc]: utils::zip(joints, *joints_location)) + { + if (!joint) + continue; - joint->orientation = { - loc.first.pose.orientation.w, - loc.first.pose.orientation.x, - loc.first.pose.orientation.y, - loc.first.pose.orientation.z - }; + joint->position = { + loc.first.pose.position.x, + loc.first.pose.position.y, + loc.first.pose.position.z + }; + + joint->orientation = { + loc.first.pose.orientation.w, + loc.first.pose.orientation.x, + loc.first.pose.orientation.y, + loc.first.pose.orientation.z + }; + } + } + else + { + root_node->visible = false; } } diff --git a/client/scenes/hand_model.h b/client/scenes/hand_model.h index 659fd8d1..c66f6db7 100644 --- a/client/scenes/hand_model.h +++ b/client/scenes/hand_model.h @@ -26,6 +26,7 @@ struct hand_model { xr::hand_tracker& hand; + node_handle root_node; std::vector joints; hand_model(xr::hand_tracker & hand, const std::filesystem::path & gltf_path, scene_loader& loader, scene_data& scene); diff --git a/client/scenes/stream_tracking.cpp b/client/scenes/stream_tracking.cpp index 627622df..dff75251 100644 --- a/client/scenes/stream_tracking.cpp +++ b/client/scenes/stream_tracking.cpp @@ -63,40 +63,45 @@ static from_headset::tracking::pose locate_space(device_id device, XrSpace space return res; } -static std::array locate_hands(xr::hand_tracker& hand, XrSpace space, XrTime time) +static std::optional> locate_hands(xr::hand_tracker& hand, XrSpace space, XrTime time) { - std::array joints = hand.locate(space, time); + auto joints = hand.locate(space, time); - std::array poses; - for(int i = 0; i < XR_HAND_JOINT_COUNT_EXT; i++) + if (joints) { - poses[i] = { - .pose = joints[i].first.pose, - .linear_velocity = joints[i].second.linearVelocity, - .angular_velocity = joints[i].second.angularVelocity, - .radius = joints[i].first.radius, - }; + std::array poses; + for(int i = 0; i < XR_HAND_JOINT_COUNT_EXT; i++) + { + poses[i] = { + .pose = (*joints)[i].first.pose, + .linear_velocity = (*joints)[i].second.linearVelocity, + .angular_velocity = (*joints)[i].second.angularVelocity, + .radius = (*joints)[i].first.radius, + }; - if (joints[i].first.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT) - poses[i].flags |= from_headset::hand_tracking::orientation_valid; + if ((*joints)[i].first.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT) + poses[i].flags |= from_headset::hand_tracking::orientation_valid; - if (joints[i].first.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT) - poses[i].flags |= from_headset::hand_tracking::position_valid; + if ((*joints)[i].first.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT) + poses[i].flags |= from_headset::hand_tracking::position_valid; - if (joints[i].second.velocityFlags & XR_SPACE_VELOCITY_LINEAR_VALID_BIT) - poses[i].flags |= from_headset::hand_tracking::linear_velocity_valid; + if ((*joints)[i].second.velocityFlags & XR_SPACE_VELOCITY_LINEAR_VALID_BIT) + poses[i].flags |= from_headset::hand_tracking::linear_velocity_valid; - if (joints[i].second.velocityFlags & XR_SPACE_VELOCITY_ANGULAR_VALID_BIT) - poses[i].flags |= from_headset::hand_tracking::angular_velocity_valid; + if ((*joints)[i].second.velocityFlags & XR_SPACE_VELOCITY_ANGULAR_VALID_BIT) + poses[i].flags |= from_headset::hand_tracking::angular_velocity_valid; - if (joints[i].first.locationFlags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT) - poses[i].flags |= from_headset::hand_tracking::orientation_tracked; + if ((*joints)[i].first.locationFlags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT) + poses[i].flags |= from_headset::hand_tracking::orientation_tracked; - if (joints[i].first.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT) - poses[i].flags |= from_headset::hand_tracking::position_tracked; + if ((*joints)[i].first.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT) + poses[i].flags |= from_headset::hand_tracking::position_tracked; + } + + return poses; } - - return poses; + else + return std::nullopt; } void scenes::stream::tracking() diff --git a/client/xr/hand_tracker.cpp b/client/xr/hand_tracker.cpp index ce729564..b039be1c 100644 --- a/client/xr/hand_tracker.cpp +++ b/client/xr/hand_tracker.cpp @@ -20,7 +20,7 @@ #include "hand_tracker.h" -std::array xr::hand_tracker::locate(XrSpace space, XrTime time) +std::optional> xr::hand_tracker::locate(XrSpace space, XrTime time) { XrHandJointsLocateInfoEXT info{ .type = XR_TYPE_HAND_JOINTS_LOCATE_INFO_EXT, @@ -49,9 +49,7 @@ std::array xr::hand_tracker::l CHECK_XR(xrLocateHandJointsEXT(id, &info, &locations)); if (!locations.isActive) - { - // TODO - } + return std::nullopt; std::array joints; for(int i = 0; i < XR_HAND_JOINT_COUNT_EXT; i++) diff --git a/client/xr/hand_tracker.h b/client/xr/hand_tracker.h index 07f01ba2..dda9636d 100644 --- a/client/xr/hand_tracker.h +++ b/client/xr/hand_tracker.h @@ -23,6 +23,7 @@ #include #include #include +#include #include "instance.h" @@ -52,6 +53,6 @@ public: using joint = std::pair; - std::array locate(XrSpace space, XrTime time); + std::optional> locate(XrSpace space, XrTime time); }; } // namespace xr diff --git a/common/wivrn_packets.h b/common/wivrn_packets.h index a2b3ebed..065a8911 100644 --- a/common/wivrn_packets.h +++ b/common/wivrn_packets.h @@ -170,8 +170,8 @@ struct hand_tracking }; XrTime timestamp; - std::array left; - std::array right; + std::optional> left; + std::optional> right; }; struct inputs diff --git a/server/driver/hand_joints_list.cpp b/server/driver/hand_joints_list.cpp index 0e730788..3e6eaa7a 100644 --- a/server/driver/hand_joints_list.cpp +++ b/server/driver/hand_joints_list.cpp @@ -88,26 +88,34 @@ static xrt_space_relation to_relation(const from_headset::hand_tracking::pose& p }; } -static xrt_hand_joint_set convert_joints(const std::array& input_joints) +static xrt_hand_joint_set convert_joints(const std::optional>& input_joints) { - xrt_hand_joint_set output_joints; + xrt_hand_joint_set output_joints{}; - output_joints.is_active = true; - output_joints.hand_pose = to_relation(input_joints[XRT_HAND_JOINT_WRIST]); - - xrt_relation_chain rel_chain{}; - xrt_space_relation * joint_rel = m_relation_chain_reserve(&rel_chain); - m_relation_chain_push_inverted_relation(&rel_chain, &output_joints.hand_pose); - - for(int i = 0; i < XR_HAND_JOINT_COUNT_EXT; i++) + if (input_joints) { - xrt_hand_joint_value& res = output_joints.values.hand_joint_set_default[i]; + output_joints.is_active = true; + output_joints.hand_pose = to_relation((*input_joints)[XRT_HAND_JOINT_WRIST]); - res.radius = input_joints[i].radius; - *joint_rel = to_relation(input_joints[i]); + xrt_relation_chain rel_chain{}; + xrt_space_relation * joint_rel = m_relation_chain_reserve(&rel_chain); + m_relation_chain_push_inverted_relation(&rel_chain, &output_joints.hand_pose); - m_relation_chain_resolve(&rel_chain, &res.relation); + for(int i = 0; i < XR_HAND_JOINT_COUNT_EXT; i++) + { + xrt_hand_joint_value& res = output_joints.values.hand_joint_set_default[i]; + + res.radius = (*input_joints)[i].radius; + *joint_rel = to_relation((*input_joints)[i]); + + m_relation_chain_resolve(&rel_chain, &res.relation); + } } + else + { + output_joints.is_active = false; + } + return output_joints; }