From 6a553b218a22df37c0a2f9a222f29f1e3b830719 Mon Sep 17 00:00:00 2001 From: Guillaume Meunier Date: Sun, 24 Mar 2024 17:15:16 +0100 Subject: [PATCH] Hide the hand model if the controller is tracked --- client/scenes/hand_model.cpp | 7 ++----- client/scenes/hand_model.h | 6 ++---- client/scenes/input_profile.cpp | 14 +++++++++++++- client/scenes/input_profile.h | 2 +- client/scenes/lobby.cpp | 34 ++++++++++++++++++++++++++------- 5 files changed, 45 insertions(+), 18 deletions(-) diff --git a/client/scenes/hand_model.cpp b/client/scenes/hand_model.cpp index 3dfda926..057bb9f8 100644 --- a/client/scenes/hand_model.cpp +++ b/client/scenes/hand_model.cpp @@ -21,8 +21,7 @@ #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) +hand_model::hand_model(const std::filesystem::path & gltf_path, scene_loader & loader, scene_data & scene) { root_node = scene.new_node(); root_node->name = gltf_path.stem(); @@ -60,10 +59,8 @@ hand_model::hand_model(xr::hand_tracker & hand, const std::filesystem::path & gl // clang-format on } -void hand_model::apply(XrSpace world_space, XrTime predicted_display_time) +void hand_model::apply(const std::optional>& joints_location) { - auto joints_location = hand.locate(world_space, predicted_display_time); - if (joints_location) { root_node->visible = true; diff --git a/client/scenes/hand_model.h b/client/scenes/hand_model.h index c66f6db7..f91109a5 100644 --- a/client/scenes/hand_model.h +++ b/client/scenes/hand_model.h @@ -24,12 +24,10 @@ 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); + hand_model(const std::filesystem::path & gltf_path, scene_loader& loader, scene_data& scene); - void apply(XrSpace world_space, XrTime predicted_display_time); + void apply(const std::optional>& joints); }; diff --git a/client/scenes/input_profile.cpp b/client/scenes/input_profile.cpp index 54a5d6db..012cf905 100644 --- a/client/scenes/input_profile.cpp +++ b/client/scenes/input_profile.cpp @@ -288,10 +288,22 @@ static void apply_visual_response(node_handle node, input_profile::node_state_vi node->visible = value > 0.5; } -void input_profile::apply(XrSpace world_space, XrTime predicted_display_time) +void input_profile::apply(XrSpace world_space, XrTime predicted_display_time, bool hide_left, bool hide_right) { for (auto && [space, node]: model_handles) { + if (space == application::left_grip() && hide_left) + { + node->visible = false; + continue; + } + + if (space == application::right_grip() && hide_right) + { + node->visible = false; + continue; + } + if (auto location = application::locate_controller(space, world_space, predicted_display_time); location) { node->visible = true; diff --git a/client/scenes/input_profile.h b/client/scenes/input_profile.h index c4eae8fa..357131d1 100644 --- a/client/scenes/input_profile.h +++ b/client/scenes/input_profile.h @@ -63,5 +63,5 @@ struct input_profile input_profile(const std::filesystem::path& json_profile, scene_loader& loader, scene_data& scene); // application::poll_actions() must have been called before - void apply(XrSpace world_space, XrTime predicted_display_time); + void apply(XrSpace world_space, XrTime predicted_display_time, bool hide_left, bool hide_right); }; diff --git a/client/scenes/lobby.cpp b/client/scenes/lobby.cpp index 56b8ddc6..72b3a27d 100644 --- a/client/scenes/lobby.cpp +++ b/client/scenes/lobby.cpp @@ -584,13 +584,33 @@ void scenes::lobby::render(XrTime predicted_display_time, bool should_render) auto [flags, views] = session.locate_views(viewconfig, predicted_display_time, world_space); assert(views.size() == swapchains_lobby.size()); - input->apply(world_space, predicted_display_time); + bool hide_left_controller = false; + bool hide_right_controller = false; - if (left_hand) - left_hand->apply(world_space, predicted_display_time); + if (application::get_hand_tracking_supported()) + { + if (left_hand) + { + auto& hand = application::get_left_hand(); + auto joints = hand.locate(world_space, predicted_display_time); + left_hand->apply(joints); - if (right_hand) - right_hand->apply(world_space, predicted_display_time); + if (joints) + hide_left_controller = true; + } + + if (right_hand) + { + auto& hand = application::get_right_hand(); + auto joints = hand.locate(world_space, predicted_display_time); + right_hand->apply(joints); + + if (joints) + hide_right_controller = true; + } + } + + input->apply(world_space, predicted_display_time, hide_left_controller, hide_right_controller); XrCompositionLayerQuad imgui_layer = draw_gui(predicted_display_time); @@ -688,8 +708,8 @@ void scenes::lobby::on_focused() if (application::get_hand_tracking_supported()) { - left_hand.emplace(application::get_left_hand(), "left-hand.glb", loader, *controllers_scene); - right_hand.emplace(application::get_right_hand(), "right-hand.glb", loader, *controllers_scene); + left_hand.emplace( "left-hand.glb", loader, *controllers_scene); + right_hand.emplace("right-hand.glb", loader, *controllers_scene); } std::array imgui_inputs{