diff --git a/client/application.cpp b/client/application.cpp index 7dd09c1f..8cf3033d 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -1136,40 +1136,6 @@ void application::initialize() XrSystemEyeGazeInteractionPropertiesEXT eye_gaze_properties = xr_system_id.eye_gaze_interaction_properties(); spdlog::info(" Eye gaze support: {}", (bool)eye_gaze_properties.supportsEyeGazeInteraction); eye_gaze_supported = eye_gaze_properties.supportsEyeGazeInteraction; - - if (eye_gaze_supported) - { - switch (guess_model()) - { - case model::pico_4_pro: - case model::pico_4_enterprise: - pico_face_tracking_supported = true; - break; - default: - pico_face_tracking_supported = false; - break; - } - } - else - pico_face_tracking_supported = false; - - spdlog::info(" PICO face tracking support: {}", (bool)pico_face_tracking_supported); - } - - if (utils::contains(xr_extensions, XR_FB_FACE_TRACKING2_EXTENSION_NAME)) - { - XrSystemFaceTrackingProperties2FB fb_face2_properties = xr_system_id.fb_face_tracking2_properties(); - spdlog::info(" FB face tracking support: {}", (bool)fb_face2_properties.supportsVisualFaceTracking); - fb_face_tracking2_supported = fb_face2_properties.supportsVisualFaceTracking; - } - - if (utils::contains(xr_extensions, XR_HTC_FACIAL_TRACKING_EXTENSION_NAME)) - { - XrSystemFacialTrackingPropertiesHTC htc_face_properties = xr_system_id.htc_face_tracking_properties(); - spdlog::info(" HTC eye tracking support: {}", (bool)htc_face_properties.supportEyeFacialTracking); - spdlog::info(" HTC lip tracking support: {}", (bool)htc_face_properties.supportLipFacialTracking); - htc_face_tracking_eye_supported = htc_face_properties.supportEyeFacialTracking; - htc_face_tracking_lip_supported = htc_face_properties.supportLipFacialTracking; } if (utils::contains(xr_extensions, XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME)) @@ -1216,24 +1182,34 @@ void application::initialize() right_hand = xr_session.create_hand_tracker(XR_HAND_RIGHT_EXT); } - if (fb_face_tracking2_supported) + if (utils::contains(xr_extensions, XR_FB_FACE_TRACKING2_EXTENSION_NAME)) { - fb_face_tracker2 = xr_session.create_fb_face_tracker2(); + XrSystemFaceTrackingProperties2FB fb_face2_properties = xr_system_id.fb_face_tracking2_properties(); + spdlog::info(" FB face tracking support: {}", (bool)fb_face2_properties.supportsVisualFaceTracking); + if (fb_face2_properties.supportsVisualFaceTracking) + face_tracker = xr_session.create_fb_face_tracker2(); } - if (htc_face_tracking_eye_supported) + if (std::holds_alternative(face_tracker) && utils::contains(xr_extensions, XR_HTC_FACIAL_TRACKING_EXTENSION_NAME)) { - htc_face_tracker_eye = xr_session.create_htc_face_tracker(XR_FACIAL_TRACKING_TYPE_EYE_DEFAULT_HTC); + XrSystemFacialTrackingPropertiesHTC htc_face_properties = xr_system_id.htc_face_tracking_properties(); + spdlog::info(" HTC eye tracking support: {}", (bool)htc_face_properties.supportEyeFacialTracking); + spdlog::info(" HTC lip tracking support: {}", (bool)htc_face_properties.supportLipFacialTracking); + face_tracker = xr_session.create_htc_face_tracker(htc_face_properties.supportEyeFacialTracking, htc_face_properties.supportLipFacialTracking); } - if (htc_face_tracking_lip_supported) + if (std::holds_alternative(face_tracker) && eye_gaze_supported) { - htc_face_tracker_lip = xr_session.create_htc_face_tracker(XR_FACIAL_TRACKING_TYPE_LIP_DEFAULT_HTC); - } - - if (pico_face_tracking_supported) - { - pico_face_tracker = xr_session.create_pico_face_tracker(); + switch (guess_model()) + { + case model::pico_4_pro: + case model::pico_4_enterprise: + spdlog::info(" PICO face tracking support: true"); + face_tracker = xr_session.create_pico_face_tracker(); + break; + default: + break; + } } if (utils::contains_all(xr_extensions, std::array{XR_FB_BODY_TRACKING_EXTENSION_NAME, XR_META_BODY_TRACKING_FULL_BODY_EXTENSION_NAME, XR_META_BODY_TRACKING_FIDELITY_EXTENSION_NAME})) diff --git a/client/application.h b/client/application.h index 6a2d8af2..ebf482ca 100644 --- a/client/application.h +++ b/client/application.h @@ -129,17 +129,7 @@ class application : public singleton xr::hand_tracker left_hand; xr::hand_tracker right_hand; - bool fb_face_tracking2_supported = false; - xr::fb_face_tracker2 fb_face_tracker2; - - bool htc_face_tracking_eye_supported = false; - xr::htc_face_tracker htc_face_tracker_eye; - bool htc_face_tracking_lip_supported = false; - xr::htc_face_tracker htc_face_tracker_lip; - - bool pico_face_tracking_supported = false; - xr::pico_face_tracker pico_face_tracker; - + std::variant face_tracker; std::variant body_tracker; bool eye_gaze_supported = false; @@ -430,24 +420,9 @@ public: return instance().hand_tracking_supported; } - static bool get_fb_face_tracking2_supported() + static bool get_face_tracking_supported() { - return instance().fb_face_tracking2_supported; - } - - static bool get_htc_face_tracking_eye_supported() - { - return instance().htc_face_tracking_eye_supported; - } - - static bool get_htc_face_tracking_lip_supported() - { - return instance().htc_face_tracking_lip_supported; - } - - static bool get_pico_face_tracking_supported() - { - return instance().pico_face_tracking_supported; + return !std::holds_alternative(instance().face_tracker); } static bool get_body_tracking_supported() @@ -475,24 +450,9 @@ public: return instance().right_hand; } - static xr::fb_face_tracker2 & get_fb_face_tracker2() + static auto & get_face_tracker() { - return instance().fb_face_tracker2; - } - - static xr::htc_face_tracker & get_htc_face_tracker_eye() - { - return instance().htc_face_tracker_eye; - } - - static xr::htc_face_tracker & get_htc_face_tracker_lip() - { - return instance().htc_face_tracker_lip; - } - - static xr::pico_face_tracker & get_pico_face_tracker() - { - return instance().pico_face_tracker; + return instance().face_tracker; } static auto & get_body_tracker() diff --git a/client/configuration.cpp b/client/configuration.cpp index 82b1f140..13d8f1f9 100644 --- a/client/configuration.cpp +++ b/client/configuration.cpp @@ -106,18 +106,17 @@ bool configuration::check_feature(feature f) const { case model::htc_vive_focus_3: case model::htc_vive_focus_vision: - [[fallthrough]]; case model::htc_vive_xr_elite: - if (not(application::get_htc_face_tracking_eye_supported() or application::get_htc_face_tracking_lip_supported())) + if (not std::holds_alternative(application::get_face_tracker())) return false; break; case model::pico_4_pro: case model::pico_4_enterprise: - if (not application::get_pico_face_tracking_supported()) + if (not std::holds_alternative(application::get_face_tracker())) return false; break; default: - if (not application::get_fb_face_tracking2_supported()) + if (not std::holds_alternative(application::get_face_tracker())) return false; break; } diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index 564ef93c..d357b35a 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -728,7 +728,7 @@ void scenes::lobby::gui_settings() ImGui::EndDisabled(); } { - ImGui::BeginDisabled(not(application::get_fb_face_tracking2_supported() or application::get_htc_face_tracking_eye_supported() or application::get_htc_face_tracking_lip_supported() or application::get_pico_face_tracking_supported())); + ImGui::BeginDisabled(not application::get_face_tracking_supported()); bool enabled = config.check_feature(feature::face_tracking); if (ImGui::Checkbox(_S("Enable face tracking"), &enabled)) { @@ -1400,7 +1400,7 @@ static const char * get_face_icon(XrTime predicted_display_time) { static const auto w = face_weights(); wivrn::from_headset::tracking::fb_face2 expression; - application::get_fb_face_tracker2().get_weights(predicted_display_time, expression); + std::get(application::get_face_tracker()).get_weights(predicted_display_time, expression); if (not expression.is_valid) return ICON_FA_FACE_MEH; @@ -1464,24 +1464,16 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time) }); } - if (application::get_fb_face_tracking2_supported()) + if (application::get_face_tracking_supported()) { + const char * icon_enabled = std::holds_alternative(application::get_face_tracker()) + ? get_face_icon(predicted_display_time) + : ICON_FA_FACE_KISS_WINK_HEART; items.push_back({ .f = feature::face_tracking, .tooltip_enabled = _("Face tracking is enabled"), .tooltip_disabled = _("Face tracking is disabled"), - .icon_enabled = get_face_icon(predicted_display_time), - .icon_disabled = ICON_FA_FACE_MEH_BLANK, - }); - } - - if (application::get_htc_face_tracking_eye_supported() or application::get_htc_face_tracking_lip_supported() or application::get_pico_face_tracking_supported()) - { - items.push_back({ - .f = feature::face_tracking, - .tooltip_enabled = _("Face tracking is enabled"), - .tooltip_disabled = _("Face tracking is disabled"), - .icon_enabled = ICON_FA_FACE_KISS_WINK_HEART, + .icon_enabled = icon_enabled, .icon_disabled = ICON_FA_FACE_MEH_BLANK, }); } diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index e38448fd..e89605e5 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -18,6 +18,7 @@ */ #include "utils/overloaded.h" #include "xr/fb_body_tracker.h" +#include "xr/fb_face_tracker2.h" #include "xr/htc_body_tracker.h" #include "xr/pico_body_tracker.h" #define GLM_FORCE_RADIANS @@ -219,12 +220,21 @@ std::shared_ptr scenes::stream::create(std::unique_ptr(&face_tracker)) + face_pico->start(); } const bool body_tracking = config.check_feature(feature::body_tracking); @@ -430,29 +424,15 @@ void scenes::stream::tracking() }, body_tracker); - if (control.enabled[size_t(tid::face)]) + if (face_tracking && control.enabled[size_t(tid::face)]) { - switch (face_tracking) - { - case wivrn::from_headset::face_type::none: - break; - case wivrn::from_headset::face_type::fb2: - application::get_fb_face_tracker2().get_weights(t0 + Δt, packet.face.emplace()); - break; - case wivrn::from_headset::face_type::htc: { - auto & face_htc = packet.face.emplace(); - face_htc.eye_active = false; - face_htc.lip_active = false; - if (application::get_htc_face_tracking_eye_supported()) - application::get_htc_face_tracker_eye().get_weights(t0 + Δt, face_htc); - if (application::get_htc_face_tracking_lip_supported()) - application::get_htc_face_tracker_lip().get_weights(t0 + Δt, face_htc); - break; - } - case wivrn::from_headset::face_type::pico: - application::get_pico_face_tracker().get_weights(t0 + Δt, packet.face.emplace()); - break; - } + std::visit(utils::overloaded{ + [](std::monostate &) {}, + [&](auto & ft) { + ft.get_weights(t0 + Δt, packet.face.emplace::packet_type>()); + }, + }, + face_tracker); } } catch (const std::system_error & e) @@ -555,8 +535,8 @@ void scenes::stream::tracking() } } - if (face_tracking == from_headset::face_type::pico) - application::get_pico_face_tracker().stop(); + if (auto * face_pico = std::get_if(&face_tracker)) + face_pico->stop(); } void scenes::stream::operator()(to_headset::tracking_control && packet) diff --git a/client/xr/fb_face_tracker2.h b/client/xr/fb_face_tracker2.h index 29e0787c..86ef0f2d 100644 --- a/client/xr/fb_face_tracker2.h +++ b/client/xr/fb_face_tracker2.h @@ -34,9 +34,10 @@ class fb_face_tracker2 : public utils::handle + * Copyright (C) 2025 Sapphire * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,26 +20,50 @@ #include "htc_face_tracker.h" #include "wivrn_packets.h" #include "xr/instance.h" +#include "xr/session.h" #include -static PFN_xrDestroyFacialTrackerHTC xrDestroyFacialTrackerHTC{}; - -XrResult xr::destroy_htc_face_tracker(XrFacialTrackerHTC id) +xr::htc_face_tracker::htc_face_tracker(instance & inst, session & s, bool eye, bool lip) : + s(s) { - return xrDestroyFacialTrackerHTC(id); -} + if (!eye && !lip) + return; -xr::htc_face_tracker::htc_face_tracker(instance & inst, XrFacialTrackerHTC h, XrFacialTrackingTypeHTC facialTrackingTypeHTC) -{ - id = h; + xrCreateFacialTrackerHTC = inst.get_proc("xrCreateFacialTrackerHTC"); xrGetFacialExpressionsHTC = inst.get_proc("xrGetFacialExpressionsHTC"); xrDestroyFacialTrackerHTC = inst.get_proc("xrDestroyFacialTrackerHTC"); - trackerType = facialTrackingTypeHTC; + + XrFacialTrackerCreateInfoHTC create_info{ + .type = XR_TYPE_FACIAL_TRACKER_CREATE_INFO_HTC, + .next = nullptr, + }; + + if (eye) + { + create_info.facialTrackingType = XR_FACIAL_TRACKING_TYPE_EYE_DEFAULT_HTC; + xrCreateFacialTrackerHTC(s, &create_info, &this->eye); + } + if (lip) + { + create_info.facialTrackingType = XR_FACIAL_TRACKING_TYPE_LIP_DEFAULT_HTC; + xrCreateFacialTrackerHTC(s, &create_info, &this->lip); + } } -void xr::htc_face_tracker::get_weights(XrTime time, wivrn::from_headset::tracking::htc_face & out_expressions) +xr::htc_face_tracker::~htc_face_tracker() { - if (!id || !xrGetFacialExpressionsHTC) + if (!xrDestroyFacialTrackerHTC) + return; + + if (eye) + CHECK_XR(xrDestroyFacialTrackerHTC(std::exchange(eye, nullptr))); + if (lip) + CHECK_XR(xrDestroyFacialTrackerHTC(std::exchange(lip, nullptr))); +} + +void xr::htc_face_tracker::get_weights(XrTime time, packet_type & out_expressions) +{ + if (!(eye || lip) || !xrGetFacialExpressionsHTC) return; XrFacialExpressionsHTC expressions{ @@ -47,25 +72,18 @@ void xr::htc_face_tracker::get_weights(XrTime time, wivrn::from_headset::trackin .sampleTime = time, }; - bool * is_active; - - switch (trackerType) + if (eye) { - case XR_FACIAL_TRACKING_TYPE_EYE_DEFAULT_HTC: - expressions.expressionCount = out_expressions.eye.size(); - expressions.expressionWeightings = out_expressions.eye.data(); - is_active = &out_expressions.eye_active; - break; - case XR_FACIAL_TRACKING_TYPE_LIP_DEFAULT_HTC: - expressions.expressionCount = out_expressions.lip.size(); - expressions.expressionWeightings = out_expressions.lip.data(); - is_active = &out_expressions.lip_active; - break; - default: - throw std::system_error(1, std::generic_category(), "htc_face_tracker with unknown trackerType"); + expressions.expressionCount = out_expressions.eye.size(); + expressions.expressionWeightings = out_expressions.eye.data(); + CHECK_XR(xrGetFacialExpressionsHTC(eye, &expressions)); + out_expressions.eye_active = expressions.isActive; + } + if (lip) + { + expressions.expressionCount = out_expressions.lip.size(); + expressions.expressionWeightings = out_expressions.lip.data(); + CHECK_XR(xrGetFacialExpressionsHTC(lip, &expressions)); + out_expressions.lip_active = expressions.isActive; } - - CHECK_XR(xrGetFacialExpressionsHTC(id, &expressions)); - - *is_active = expressions.isActive; } diff --git a/client/xr/htc_face_tracker.h b/client/xr/htc_face_tracker.h index f8381b54..fecd802c 100644 --- a/client/xr/htc_face_tracker.h +++ b/client/xr/htc_face_tracker.h @@ -1,6 +1,7 @@ /* * WiVRn VR streaming * Copyright (C) 2024 galister + * Copyright (C) 2025 Sapphire * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,19 +26,23 @@ namespace xr { class instance; +class session; -XrResult destroy_htc_face_tracker(XrFacialTrackerHTC); - -class htc_face_tracker : public utils::handle +class htc_face_tracker { + XrSession s; + XrFacialTrackerHTC eye{}; + XrFacialTrackerHTC lip{}; + PFN_xrCreateFacialTrackerHTC xrCreateFacialTrackerHTC{}; PFN_xrGetFacialExpressionsHTC xrGetFacialExpressionsHTC{}; PFN_xrDestroyFacialTrackerHTC xrDestroyFacialTrackerHTC{}; - XrFacialTrackingTypeHTC trackerType{}; public: + using packet_type = wivrn::from_headset::tracking::htc_face; htc_face_tracker() = default; - htc_face_tracker(instance & inst, XrFacialTrackerHTC h, XrFacialTrackingTypeHTC facialTrackingTypeHTC); + htc_face_tracker(instance & inst, session & s, bool eye, bool lip); + ~htc_face_tracker(); - void get_weights(XrTime time, struct wivrn::from_headset::tracking::htc_face & out_expressions); + void get_weights(XrTime time, packet_type & out_expressions); }; } // namespace xr diff --git a/client/xr/pico_face_tracker.h b/client/xr/pico_face_tracker.h index bd006568..fd5a7d72 100644 --- a/client/xr/pico_face_tracker.h +++ b/client/xr/pico_face_tracker.h @@ -40,12 +40,13 @@ class pico_face_tracker bool started{}; public: + using packet_type = wivrn::from_headset::tracking::fb_face2; pico_face_tracker() = default; pico_face_tracker(instance & inst, session & s); ~pico_face_tracker(); void start(); void stop(); - void get_weights(XrTime time, struct wivrn::from_headset::tracking::fb_face2 & out_expressions); + void get_weights(XrTime time, packet_type & out_expressions); }; } // namespace xr diff --git a/client/xr/session.cpp b/client/xr/session.cpp index fe816159..34ee55c2 100644 --- a/client/xr/session.cpp +++ b/client/xr/session.cpp @@ -123,21 +123,9 @@ xr::fb_face_tracker2 xr::session::create_fb_face_tracker2() return {*inst, ft}; } -xr::htc_face_tracker xr::session::create_htc_face_tracker(XrFacialTrackingTypeHTC facialTrackingType) +xr::htc_face_tracker xr::session::create_htc_face_tracker(bool eye, bool lip) { - XrFacialTrackerCreateInfoHTC create_info{ - .type = XR_TYPE_FACIAL_TRACKER_CREATE_INFO_HTC, - .next = nullptr, - .facialTrackingType = facialTrackingType, - }; - - XrFacialTrackerHTC ft; - - auto xrCreateFacialTrackerHTC = inst->get_proc("xrCreateFacialTrackerHTC"); - assert(xrCreateFacialTrackerHTC); - - CHECK_XR(xrCreateFacialTrackerHTC(id, &create_info, &ft)); - return {*inst, ft, facialTrackingType}; + return {*inst, *this, eye, lip}; } xr::pico_face_tracker xr::session::create_pico_face_tracker() diff --git a/client/xr/session.h b/client/xr/session.h index 0086ce7f..a4a026d1 100644 --- a/client/xr/session.h +++ b/client/xr/session.h @@ -55,7 +55,7 @@ public: 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); fb_face_tracker2 create_fb_face_tracker2(); - htc_face_tracker create_htc_face_tracker(XrFacialTrackingTypeHTC); + htc_face_tracker create_htc_face_tracker(bool eye, bool lip); pico_face_tracker create_pico_face_tracker(); fb_body_tracker create_fb_body_tracker(); htc_body_tracker create_htc_body_tracker(); diff --git a/common/wivrn_packets.h b/common/wivrn_packets.h index 90dbb0fb..a4f34ae1 100644 --- a/common/wivrn_packets.h +++ b/common/wivrn_packets.h @@ -198,7 +198,6 @@ enum face_type : uint8_t none, fb2, htc, - pico, }; struct headset_info_packet diff --git a/server/driver/wivrn_session.cpp b/server/driver/wivrn_session.cpp index 7a3b025c..0bc1f236 100644 --- a/server/driver/wivrn_session.cpp +++ b/server/driver/wivrn_session.cpp @@ -211,7 +211,7 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr connection } auto face = get_info().face_tracking; - if (face == from_headset::face_type::fb2 || face == from_headset::face_type::pico || is_forced_extension("FB_face_tracking2")) + if (face == from_headset::face_type::fb2 || is_forced_extension("FB_face_tracking2")) { fb_face2_tracker = std::make_unique(&hmd, *this); static_roles.face = fb_face2_tracker.get();