diff --git a/client/application.cpp b/client/application.cpp index 384dee76..c7c976e8 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -1236,12 +1236,7 @@ void application::initialize() spdlog::info(" Orientation tracking: {}", (bool)properties.trackingProperties.orientationTracking); spdlog::info(" Position tracking: {}", (bool)properties.trackingProperties.positionTracking); - if (utils::contains(xr_extensions, XR_EXT_HAND_TRACKING_EXTENSION_NAME)) - { - XrSystemHandTrackingPropertiesEXT hand_tracking_properties = xr_system_id.hand_tracking_properties(); - spdlog::info(" Hand tracking support: {}", (bool)hand_tracking_properties.supportsHandTracking); - hand_tracking_supported = hand_tracking_properties.supportsHandTracking; - } + spdlog::info(" Hand tracking support: {}", xr_system_id.hand_tracking_supported()); if (utils::contains(xr_extensions, XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME)) { @@ -1288,12 +1283,6 @@ void application::initialize() config.emplace(xr_system_id); - if (hand_tracking_supported) - { - left_hand = xr_session.create_hand_tracker(XR_HAND_LEFT_EXT); - right_hand = xr_session.create_hand_tracker(XR_HAND_RIGHT_EXT); - } - if (utils::contains(xr_extensions, XR_FB_FACE_TRACKING2_EXTENSION_NAME)) { XrSystemFaceTrackingProperties2FB fb_face2_properties = xr_system_id.fb_face_tracking2_properties(); diff --git a/client/application.h b/client/application.h index cb17f87e..69120199 100644 --- a/client/application.h +++ b/client/application.h @@ -126,10 +126,6 @@ class application : public singleton xr::actionset xr_actionset; std::vector> actions; - bool hand_tracking_supported = false; - xr::hand_tracker left_hand; - xr::hand_tracker right_hand; - std::variant face_tracker; std::variant body_tracker; @@ -396,6 +392,11 @@ public: return instance().vk_instance; } + static xr::system & get_system() + { + return instance().xr_system_id; + } + static vk::raii::PipelineCache & get_pipeline_cache() { return instance().pipeline_cache; @@ -416,11 +417,6 @@ public: return instance().last_scene_cpu_time; } - static bool get_hand_tracking_supported() - { - return instance().hand_tracking_supported; - } - static bool get_face_tracking_supported() { return !std::holds_alternative(instance().face_tracker); @@ -441,16 +437,6 @@ public: return instance().openxr_post_processing_supported; } - static xr::hand_tracker & get_left_hand() - { - return instance().left_hand; - } - - static xr::hand_tracker & get_right_hand() - { - return instance().right_hand; - } - static auto & get_face_tracker() { return instance().face_tracker; diff --git a/client/configuration.cpp b/client/configuration.cpp index ea0ec8d8..ccb34b20 100644 --- a/client/configuration.cpp +++ b/client/configuration.cpp @@ -94,7 +94,7 @@ bool configuration::check_feature(feature f) const case feature::microphone: break; case feature::hand_tracking: - if (not application::get_hand_tracking_supported()) + if (not application::get_system().hand_tracking_supported()) return false; break; case feature::eye_gaze: @@ -182,7 +182,7 @@ void configuration::set_feature(feature f, bool state) configuration::configuration(xr::system & system) { passthrough_enabled = system.passthrough_supported() == xr::system::passthrough_type::color; - features[feature::hand_tracking] = application::get_hand_tracking_supported(); + features[feature::hand_tracking] = system.hand_tracking_supported(); try { simdjson::dom::parser parser; diff --git a/client/scenes/lobby.cpp b/client/scenes/lobby.cpp index 98aaa0a7..54345fcb 100644 --- a/client/scenes/lobby.cpp +++ b/client/scenes/lobby.cpp @@ -649,10 +649,10 @@ void scenes::lobby::render(const XrFrameState & frame_state) if (!new_gui_position and head_position) new_gui_position = check_recenter_action(frame_state.predictedDisplayTime, head_position->first); - if (application::get_hand_tracking_supported()) + if (left_hand and right_hand) { - auto left = application::get_left_hand().locate(world_space, frame_state.predictedDisplayTime); - auto right = application::get_right_hand().locate(world_space, frame_state.predictedDisplayTime); + auto left = left_hand->locate(world_space, frame_state.predictedDisplayTime); + auto right = right_hand->locate(world_space, frame_state.predictedDisplayTime); hand_model::apply(world, left, right); @@ -835,12 +835,6 @@ void scenes::lobby::on_focused() xyz_axes_right_controller = load_gltf("xyz-arrows.glb", layer_controllers).first; #endif - if (application::get_hand_tracking_supported()) - { - hand_model::add_hand(*this, XR_HAND_LEFT_EXT, "left-hand.glb", layer_controllers); - hand_model::add_hand(*this, XR_HAND_RIGHT_EXT, "right-hand.glb", layer_controllers); - } - recenter_left_action = get_action("recenter_left").first; recenter_right_action = get_action("recenter_right").first; @@ -862,19 +856,15 @@ void scenes::lobby::on_focused() .haptic_output = get_action("right_haptic").first, }, }; - if (auto & hand = application::get_left_hand()) + + if (system.hand_tracking_supported()) { - imgui_inputs.push_back( - { - .hand = &hand, - }); - } - if (auto & hand = application::get_right_hand()) - { - imgui_inputs.push_back( - { - .hand = &hand, - }); + left_hand = session.create_hand_tracker(XR_HAND_LEFT_EXT); + right_hand = session.create_hand_tracker(XR_HAND_RIGHT_EXT); + hand_model::add_hand(*this, XR_HAND_LEFT_EXT, "left-hand.glb", layer_controllers); + hand_model::add_hand(*this, XR_HAND_RIGHT_EXT, "right-hand.glb", layer_controllers); + imgui_inputs.push_back({.hand = &*left_hand}); + imgui_inputs.push_back({.hand = &*right_hand}); } // 0.4mm / pixel @@ -966,6 +956,8 @@ void scenes::lobby::on_unfocused() world.clear(); // Must be cleared before the renderer so that the descriptor sets are freed before their pools input.reset(); + left_hand.reset(); + right_hand.reset(); loader.reset(); renderer.reset(); diff --git a/client/scenes/lobby.h b/client/scenes/lobby.h index e68040ce..81d6afd3 100644 --- a/client/scenes/lobby.h +++ b/client/scenes/lobby.h @@ -66,6 +66,9 @@ class lobby : public scene_impl std::optional imgui_ctx; + std::optional left_hand; + std::optional right_hand; + std::string selected_item; std::unique_ptr license; diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index ad7e3533..9c3029b9 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -889,7 +889,7 @@ void scenes::lobby::gui_settings() ImGui::EndDisabled(); } { - ImGui::BeginDisabled(not application::get_hand_tracking_supported()); + ImGui::BeginDisabled(not system.hand_tracking_supported()); bool enabled = config.check_feature(feature::hand_tracking); if (ImGui::Checkbox(_S("Enable hand tracking"), &enabled)) { @@ -1690,7 +1690,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time) .icon_disabled = ICON_FA_MICROPHONE_SLASH, }); - if (application::get_hand_tracking_supported()) + if (system.hand_tracking_supported()) { items.push_back({ .f = feature::hand_tracking, @@ -2028,7 +2028,7 @@ std::vector> scenes::lobby::draw_gui(XrTi if (not is_gui_visible(*imgui_ctx, predicted_display_time)) { - if (application::get_hand_tracking_supported()) + if (system.hand_tracking_supported()) display_recentering_tip(*imgui_ctx, _("Press the grip button or put your palm up\nto move the main window")); else display_recentering_tip(*imgui_ctx, _("Press the grip button to move the main window")); diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index 50dca0a8..68a6f9a7 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -493,6 +493,8 @@ void scenes::stream::on_unfocused() loader.reset(); renderer.reset(); clear_swapchains(); + left_hand.reset(); + right_hand.reset(); imgui_ctx.reset(); swapchain_imgui = xr::swapchain(); diff --git a/client/scenes/stream.h b/client/scenes/stream.h index 391d2a9b..a7cbd2ce 100644 --- a/client/scenes/stream.h +++ b/client/scenes/stream.h @@ -129,6 +129,8 @@ private: std::optional