Make virtual tracker xdevs toggleable

Co-authored-by: Guillaume Meunier <guillaume.meunier@centraliens.net>
This commit is contained in:
Sapphire
2026-07-10 14:52:50 -05:00
co-authored by Guillaume Meunier
parent 727445520e
commit 1cc61fd07a
18 changed files with 268 additions and 67 deletions
+82
View File
@@ -21,11 +21,14 @@
#include "application.h"
#include "configuration.h"
#include "constants.h"
#include "render/imgui_impl.h"
#include "utils/i18n.h"
#include "wivrn_packets.h"
#include "xr/instance.h"
#include "xr/session.h"
#include "xr/system.h"
#include "imgui.h"
#include "imgui_internal.h"
@@ -117,6 +120,85 @@ bool refresh_rate(
return changed;
}
bool body_tracking_parts(
xr::system & system,
imgui_context & imgui_ctx,
configuration & config)
{
auto body_tracker = system.body_tracker_supported();
if (body_tracker == xr::body_tracker_type::none or body_tracker == xr::body_tracker_type::htc)
return false;
const std::array body_parts{
std::make_pair(from_headset::body_part_mask::chest, _C("virtual body tracker selection", "Chest")),
std::make_pair(from_headset::body_part_mask::left_elbow, _C("virtual body tracker selection", "Left elbow")),
std::make_pair(from_headset::body_part_mask::right_elbow, _C("virtual body tracker selection", "Right elbow")),
std::make_pair(from_headset::body_part_mask::hip, _C("virtual body tracker selection", "Hip")),
std::make_pair(from_headset::body_part_mask::left_knee, _C("virtual body tracker selection", "Left knee")),
std::make_pair(from_headset::body_part_mask::right_knee, _C("virtual body tracker selection", "Right knee")),
std::make_pair(from_headset::body_part_mask::left_foot, _C("virtual body tracker selection", "Left foot")),
std::make_pair(from_headset::body_part_mask::right_foot, _C("virtual body tracker selection", "Right foot")),
};
bool changed = false;
bool button_pressed = ImGui::ArrowButton("##OpenBodyPartMenu", ImGuiDir_Down);
ImGui::SameLine(0.f, ImGui::GetStyle().ItemInnerSpacing.x);
ImGui::Text("%s", _S("Virtual body trackers"));
if (button_pressed)
ImGui::OpenPopup("body part menu");
const auto & popup_layer = imgui_ctx.layers()[1];
const glm::vec2 popup_layer_center = popup_layer.vp_origin + popup_layer.vp_size / 2;
ImGui::SetNextWindowPos({popup_layer_center.x, popup_layer_center.y}, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, constants::style::window_padding);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, constants::style::window_rounding);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, constants::style::window_border_size);
if (ImGui::BeginPopupModal("body part menu", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize))
{
const float height = ImGui::GetFrameHeight();
const ImVec2 size(height, height);
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.2f, 0.2f, 0.40f));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.8f, 0.2f, 0.2f, 1.00f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 0.1f, 0.1f, 1.00f));
ImGui::SetCursorPosX(ImGui::GetWindowContentRegionMax().x - size.x);
if (ImGui::Button("X", size))
ImGui::CloseCurrentPopup();
imgui_ctx.vibrate_on_hover();
ImGui::PopStyleColor(3); // ImGuiCol_Button, ImGuiCol_ButtonHovered, ImGuiCol_ButtonActive
for (const auto & [bit, name]: body_parts)
{
if (body_tracker == xr::body_tracker_type::fb and bit > from_headset::body_part_mask::hip)
continue;
const auto underlying = std::to_underlying(bit);
bool enabled = config.body_part_mask & underlying;
if (ImGui::Checkbox(name.c_str(), &enabled))
{
if (enabled)
{
config.body_part_mask |= underlying;
}
else
{
config.body_part_mask &= ~underlying;
}
config.save();
changed = true;
imgui_ctx.vibrate_on_hover();
}
}
ImGui::EndPopup();
}
ImGui::PopStyleVar(3); // ImGuiStyleVar_WindowPadding, ImGuiStyleVar_WindowRounding, ImGuiStyleVar_WindowBorderSize
return changed;
}
static std::string openxr_post_processing_flag_name(XrCompositionLayerSettingsFlagsFB flag)
{
switch (flag)
+6
View File
@@ -26,6 +26,7 @@ namespace xr
{
class instance;
class session;
class system;
} // namespace xr
namespace wivrn
@@ -40,6 +41,11 @@ bool refresh_rate(
imgui_context & imgui_ctx,
configuration & config);
bool body_tracking_parts(
xr::system & system,
imgui_context & imgui_ctx,
configuration & config);
bool post_processing(
imgui_context & imgui_ctx,
configuration & config);
+1 -7
View File
@@ -866,18 +866,12 @@ void scenes::lobby::gui_settings()
imgui_ctx->vibrate_on_hover();
if (body_tracker == xr::body_tracker_type::meta)
{
ImGui::BeginDisabled(not config.check_feature(feature::body_tracking));
ImGui::Indent();
if (ImGui::Checkbox(_S("Enable lower body tracking"), &config.fb_lower_body))
{
config.save();
gui::body_tracking_parts(system, *imgui_ctx, config);
}
imgui_ctx->vibrate_on_hover();
if (ImGui::IsItemHovered())
imgui_ctx->tooltip(_("Estimate lower body joint positions using Generative Legs\nRequires 'Hand and body tracking' to be enabled in the Quest movement tracking settings"));
ImGui::Unindent();
ImGui::EndDisabled();
}
+11 -2
View File
@@ -267,6 +267,7 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
info.settings.bitrate_bps = config.bitrate_bps;
info.settings.mirror_gamepad = config.forward_gamepad;
info.settings.enabled_body_parts = config.body_part_mask;
info.hand_tracking = config.check_feature(feature::hand_tracking);
info.eye_gaze = config.check_feature(feature::eye_gaze);
@@ -307,7 +308,7 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
info.body_tracking = from_headset::body_type::fb;
break;
case xr::body_tracker_type::meta:
info.body_tracking = config.fb_lower_body ? from_headset::body_type::meta : from_headset::body_type::fb;
info.body_tracking = from_headset::body_type::meta;
break;
case xr::body_tracker_type::pico:
info.body_tracking = from_headset::body_type::bd;
@@ -502,17 +503,25 @@ void scenes::stream::on_focused()
session,
device,
swapchain_format,
1800,
3600,
1200);
std::vector<imgui_context::viewport> vps{
{
// Main window
.space = xr::spaces::world,
// Position and orientation are set at each frame
.size = {1.2, 0.6666},
.vp_origin = {0, 0},
.vp_size = {1800, 1000},
},
{
// Popup window
.space = xr::spaces::world,
.size = {1.2, 0.6666},
.vp_origin = {1800, 0},
.vp_size = {1800, 1000},
},
{
.space = xr::spaces::world,
.size = {1.2, 0.1333},
+11
View File
@@ -388,6 +388,7 @@ static void send_settings_changed_packet(xr::session & session, wivrn_session *
.fps_divider = config.fps_divider,
.bitrate_bps = config.bitrate_bps,
.mirror_gamepad = config.forward_gamepad,
.enabled_body_parts = config.body_part_mask,
});
}
@@ -415,6 +416,12 @@ void scenes::stream::gui_settings(float predicted_display_period)
imgui_ctx->tooltip(_("Click to adjust bitrate"));
}
if (config.check_feature(feature::body_tracking))
{
if (gui::body_tracking_parts(system, *imgui_ctx, config))
send_settings_changed_packet(session, network_session.get(), config);
}
gui::post_processing(*imgui_ctx, config);
bool send_packet = false;
@@ -761,6 +768,10 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
imgui_ctx->layers()[0].position = world_gui_position;
break;
}
// Position popup layer
imgui_ctx->layers()[1].orientation = imgui_ctx->layers()[0].orientation;
imgui_ctx->layers()[1].position = imgui_ctx->layers()[0].position + imgui_ctx->layers()[0].orientation * constants::lobby::popup_position;
}
const float tab_width = 300;
+1 -2
View File
@@ -365,8 +365,7 @@ void scenes::stream::tracking()
instance,
system,
session,
application::get_generic_trackers(),
config.fb_lower_body);
application::get_generic_trackers());
}
else
body_tracker.emplace<std::monostate>();