Remove face tracker from application.h

This commit is contained in:
Patrick Nicolas
2025-08-19 19:14:10 +02:00
parent 1e37261cfa
commit 4b8295b7c7
12 changed files with 350 additions and 247 deletions
+3
View File
@@ -867,6 +867,8 @@ void scenes::lobby::on_focused()
imgui_inputs.push_back({.hand = &*right_hand});
}
face_tracker = xr::make_face_tracker(instance, system, session);
// 0.4mm / pixel
std::vector<imgui_context::viewport> vps{
{
@@ -958,6 +960,7 @@ void scenes::lobby::on_unfocused()
input.reset();
left_hand.reset();
right_hand.reset();
face_tracker.emplace<std::monostate>();
loader.reset();
renderer.reset();
+3
View File
@@ -29,6 +29,7 @@
#include "wivrn_config.h"
#include "wivrn_discover.h"
#include "wivrn_packets.h"
#include "xr/face_tracker.h"
#include <vulkan/vulkan_raii.hpp>
#include <openxr/openxr.h>
@@ -69,6 +70,8 @@ class lobby : public scene_impl<lobby>
std::optional<xr::hand_tracker> left_hand;
std::optional<xr::hand_tracker> right_hand;
xr::face_tracker face_tracker;
std::string selected_item;
std::unique_ptr<asset> license;
+17 -9
View File
@@ -913,7 +913,7 @@ void scenes::lobby::gui_settings()
ImGui::EndDisabled();
}
{
ImGui::BeginDisabled(not application::get_face_tracking_supported());
ImGui::BeginDisabled(std::holds_alternative<std::monostate>(face_tracker));
bool enabled = config.check_feature(feature::face_tracking);
if (ImGui::Checkbox(_S("Enable face tracking"), &enabled))
{
@@ -1308,7 +1308,7 @@ void scenes::lobby::gui_first_run()
item{
.f = feature::face_tracking,
.text = _S("Enable face tracking?"),
.supported = application::get_face_tracking_supported(),
.supported = not std::holds_alternative<std::monostate>(face_tracker),
},
item{
.f = feature::body_tracking,
@@ -1643,11 +1643,22 @@ static auto face_weights()
return res;
}
static const char * get_face_icon(XrTime predicted_display_time)
static const char * get_face_icon(XrTime predicted_display_time, xr::face_tracker & face_tracker)
{
static const auto w = face_weights();
wivrn::from_headset::tracking::fb_face2 expression;
std::get<xr::fb_face_tracker2>(application::get_face_tracker()).get_weights(predicted_display_time, expression);
const char * result = nullptr;
std::visit(utils::overloaded{
[](std::monostate &) {},
[&](xr::htc_face_tracker &) { result = ICON_FA_FACE_SMILE_WINK; },
[&](auto & ft) {
ft.get_weights(predicted_display_time, expression);
},
},
face_tracker);
if (result)
return result;
if (not expression.is_valid)
return ICON_FA_FACE_MEH;
@@ -1711,16 +1722,13 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
});
}
if (application::get_face_tracking_supported())
if (not std::holds_alternative<std::monostate>(face_tracker))
{
const char * icon_enabled = std::holds_alternative<xr::fb_face_tracker2>(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 = icon_enabled,
.icon_enabled = get_face_icon(predicted_display_time, face_tracker),
.icon_disabled = ICON_FA_FACE_MEH_BLANK,
});
}
+14 -15
View File
@@ -18,6 +18,7 @@
*/
#include "constants.h"
#include "utils/overloaded.h"
#include "xr/face_tracker.h"
#include "xr/fb_body_tracker.h"
#include "xr/fb_face_tracker2.h"
#include "xr/htc_body_tracker.h"
@@ -256,21 +257,19 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
if (config.check_feature(feature::face_tracking))
{
info.face_tracking = std::visit(utils::overloaded{
[](std::monostate &) {
return from_headset::face_type::none;
},
[](xr::fb_face_tracker2 &) {
return from_headset::face_type::fb2;
},
[](xr::htc_face_tracker &) {
return from_headset::face_type::htc;
},
[](xr::pico_face_tracker &) {
return from_headset::face_type::fb2;
},
},
application::get_face_tracker());
switch (xr::face_tracker_supported(self->instance, self->system))
{
case xr::face_tracker_type::none:
info.face_tracking = from_headset::face_type::none;
break;
case xr::face_tracker_type::fb:
case xr::face_tracker_type::pico:
info.face_tracking = from_headset::face_type::fb2;
break;
case xr::face_tracker_type::htc:
info.face_tracking = from_headset::face_type::htc;
break;
}
}
info.num_generic_trackers = 0;
+17 -22
View File
@@ -21,6 +21,7 @@
#include "stream.h"
#include "utils/overloaded.h"
#include "wivrn_packets.h"
#include "xr/face_tracker.h"
#include "xr/fb_body_tracker.h"
#include <magic_enum.hpp>
#include <ranges>
@@ -389,15 +390,7 @@ void scenes::stream::tracking()
std::optional<xr::hand_tracker> right_hand;
const bool face_tracking = config.check_feature(feature::face_tracking);
auto & face_tracker = application::get_face_tracker();
if (face_tracking)
{
// We can't start the face tracking on application initialisation like we do for
// other face trackers due to a Pico runtime bug where face tracking freezes when
// the headset is taken off or the application is quit.
if (auto * face_pico = std::get_if<xr::pico_face_tracker>(&face_tracker))
face_pico->start();
}
xr::face_tracker face_tracker;
const bool body_tracking = config.check_feature(feature::body_tracking);
auto & body_tracker = application::get_body_tracker();
@@ -453,6 +446,14 @@ void scenes::stream::tracking()
else
right_hand.reset();
if (face_tracking and control.enabled[size_t(tid::face)])
{
if (std::holds_alternative<std::monostate>(face_tracker))
face_tracker = xr::make_face_tracker(instance, system, session);
}
else
face_tracker.emplace<std::monostate>();
XrDuration prediction = std::clamp<XrDuration>(control.max_offset.count(), 0, 80'000'000);
auto period = std::max<XrDuration>(display_time_period.load(), 1'000'000);
for (XrDuration Δt = display_time_phase - t0 % period + (control.min_offset.count() / period) * period;
@@ -533,16 +534,13 @@ void scenes::stream::tracking()
},
body_tracker);
if (face_tracking && control.enabled[size_t(tid::face)])
{
std::visit(utils::overloaded{
[](std::monostate &) {},
[&](auto & ft) {
ft.get_weights(t0 + Δt, packet.face.emplace<typename std::remove_reference_t<decltype(ft)>::packet_type>());
},
},
face_tracker);
}
std::visit(utils::overloaded{
[](std::monostate &) {},
[&](auto & ft) {
ft.get_weights(t0 + Δt, packet.face.emplace<typename std::remove_reference_t<decltype(ft)>::packet_type>());
},
},
face_tracker);
}
catch (const std::system_error & e)
{
@@ -643,9 +641,6 @@ void scenes::stream::tracking()
exit();
}
}
if (auto * face_pico = std::get_if<xr::pico_face_tracker>(&face_tracker))
face_pico->stop();
}
void scenes::stream::operator()(to_headset::tracking_control && packet)