Make virtual tracker xdevs toggleable
Co-authored-by: Guillaume Meunier <guillaume.meunier@centraliens.net>
This commit is contained in:
co-authored by
Guillaume Meunier
parent
727445520e
commit
1cc61fd07a
@@ -189,8 +189,24 @@ configuration::configuration(xr::system & system, xr::session & session)
|
||||
if (auto val = root["forward_gamepad"]; val.is_bool())
|
||||
forward_gamepad = val.get_bool();
|
||||
|
||||
if (auto val = root["fb_lower_body"]; val.is_bool())
|
||||
fb_lower_body = val.get_bool();
|
||||
if (auto val = root["body_parts"]; val.is_object())
|
||||
{
|
||||
for (const auto & [b, name]: magic_enum::enum_entries<wivrn::from_headset::body_part_mask>())
|
||||
{
|
||||
const auto & body_part = val[name];
|
||||
if (!body_part.is_bool())
|
||||
continue;
|
||||
|
||||
if (body_part.get_bool())
|
||||
{
|
||||
body_part_mask |= std::to_underlying(b);
|
||||
}
|
||||
else
|
||||
{
|
||||
body_part_mask &= ~std::to_underlying(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (auto val = root["virtual_keyboard_layout"]; val.is_string())
|
||||
virtual_keyboard_layout = val.get_string().value();
|
||||
@@ -306,7 +322,21 @@ void configuration::save()
|
||||
json << ",\"forward_keyboard\":" << std::boolalpha << forward_keyboard;
|
||||
json << ",\"forward_mouse\":" << std::boolalpha << forward_mouse;
|
||||
json << ",\"forward_gamepad\":" << std::boolalpha << forward_gamepad;
|
||||
json << ",\"fb_lower_body\":" << std::boolalpha << fb_lower_body;
|
||||
|
||||
std::stringstream body_part_ss;
|
||||
for (const auto & [b, name]: magic_enum::enum_entries<wivrn::from_headset::body_part_mask>())
|
||||
{
|
||||
bool enabled = (body_part_mask & std::to_underlying(b)) != 0;
|
||||
body_part_ss << "\"" << name << "\":" << std::boolalpha << enabled << ",";
|
||||
}
|
||||
|
||||
std::string body_parts_str = body_part_ss.str();
|
||||
if (!body_parts_str.empty())
|
||||
{
|
||||
body_parts_str.pop_back(); // Remove last comma
|
||||
json << ",\"body_parts\":{" << body_parts_str << "}";
|
||||
}
|
||||
|
||||
json << ",\"enable_stream_gui\":" << std::boolalpha << enable_stream_gui;
|
||||
for (auto & [key, value]: features)
|
||||
json << "," << key << ":" << std::boolalpha << value;
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <optional>
|
||||
#include <simdjson.h>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
namespace xr
|
||||
@@ -73,7 +74,7 @@ public:
|
||||
bool forward_mouse = false;
|
||||
bool forward_gamepad = false;
|
||||
|
||||
bool fb_lower_body = false;
|
||||
std::underlying_type_t<wivrn::from_headset::body_part_mask> body_part_mask = ~0;
|
||||
|
||||
bool enable_stream_gui = true;
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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},
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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>();
|
||||
|
||||
+15
-15
@@ -48,33 +48,33 @@ xr::body_tracker_type xr::body_tracker_supported(xr::instance & instance, xr::sy
|
||||
return xr::body_tracker_type::none;
|
||||
}
|
||||
|
||||
xr::body_tracker xr::make_body_tracker(xr::instance & instance, xr::system & system, xr::session & session, std::vector<std::pair<XrPath, xr::space>> & generic_trackers, bool full_body)
|
||||
xr::body_tracker xr::make_body_tracker(xr::instance & instance, xr::system & system, xr::session & session, std::vector<std::pair<XrPath, xr::space>> & generic_trackers)
|
||||
{
|
||||
if (instance.has_extension(XR_FB_BODY_TRACKING_EXTENSION_NAME))
|
||||
switch (body_tracker_supported(instance, system))
|
||||
{
|
||||
if (instance.has_extension(XR_META_BODY_TRACKING_FULL_BODY_EXTENSION_NAME) and system.meta_body_tracking_properties().supportsFullBodyTracking)
|
||||
case body_tracker_type::meta:
|
||||
return xr::body_tracker(std::in_place_type_t<xr::fb_body_tracker>(),
|
||||
instance,
|
||||
session,
|
||||
full_body);
|
||||
if (system.fb_body_tracking_properties().supportsBodyTracking)
|
||||
true);
|
||||
case body_tracker_type::fb:
|
||||
return xr::body_tracker(std::in_place_type_t<xr::fb_body_tracker>(),
|
||||
instance,
|
||||
session,
|
||||
false);
|
||||
}
|
||||
|
||||
if (not generic_trackers.empty())
|
||||
return xr::body_tracker(std::in_place_type_t<xr::htc_body_tracker>(),
|
||||
session,
|
||||
generic_trackers);
|
||||
|
||||
if (instance.has_extension(XR_BD_BODY_TRACKING_EXTENSION_NAME))
|
||||
{
|
||||
if (system.bd_body_tracking_properties().supportsBodyTracking)
|
||||
case body_tracker_type::pico:
|
||||
return xr::body_tracker(std::in_place_type_t<xr::pico_body_tracker>(),
|
||||
instance,
|
||||
session);
|
||||
case body_tracker_type::htc:
|
||||
if (not generic_trackers.empty())
|
||||
return xr::body_tracker(std::in_place_type_t<xr::htc_body_tracker>(),
|
||||
session,
|
||||
generic_trackers);
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return std::monostate();
|
||||
|
||||
@@ -36,7 +36,7 @@ class session;
|
||||
|
||||
using body_tracker = std::variant<std::monostate, xr::fb_body_tracker, xr::htc_body_tracker, xr::pico_body_tracker>;
|
||||
|
||||
body_tracker make_body_tracker(xr::instance &, xr::system &, xr::session &, std::vector<std::pair<XrPath, xr::space>> & generic_trackers, bool full_body);
|
||||
body_tracker make_body_tracker(xr::instance &, xr::system &, xr::session &, std::vector<std::pair<XrPath, xr::space>> & generic_trackers);
|
||||
|
||||
body_tracker_type body_tracker_supported(xr::instance &, xr::system &);
|
||||
|
||||
|
||||
@@ -27,14 +27,14 @@
|
||||
#include <variant>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
xr::fb_body_tracker::fb_body_tracker(instance & inst, session & s, bool lower_body) :
|
||||
xr::fb_body_tracker::fb_body_tracker(instance & inst, session & s, bool full_body) :
|
||||
handle(inst.get_proc<PFN_xrDestroyBodyTrackerFB>("xrDestroyBodyTrackerFB")),
|
||||
xrRequestBodyTrackingFidelityMETA(inst.has_extension(XR_META_BODY_TRACKING_FIDELITY_EXTENSION_NAME)
|
||||
? inst.get_proc<PFN_xrRequestBodyTrackingFidelityMETA>("xrRequestBodyTrackingFidelityMETA")
|
||||
: nullptr),
|
||||
xrLocateBodyJointsFB(inst.get_proc<PFN_xrLocateBodyJointsFB>("xrLocateBodyJointsFB")),
|
||||
xrGetBodySkeletonFB(inst.get_proc<PFN_xrGetBodySkeletonFB>("xrGetBodySkeletonFB")),
|
||||
joint_set(lower_body ? XR_BODY_JOINT_SET_FULL_BODY_META : XR_BODY_JOINT_SET_DEFAULT_FB)
|
||||
joint_set(full_body ? XR_BODY_JOINT_SET_FULL_BODY_META : XR_BODY_JOINT_SET_DEFAULT_FB)
|
||||
{
|
||||
auto xrCreateBodyTrackerFB = inst.get_proc<PFN_xrCreateBodyTrackerFB>("xrCreateBodyTrackerFB");
|
||||
|
||||
@@ -47,7 +47,7 @@ xr::fb_body_tracker::fb_body_tracker(instance & inst, session & s, bool lower_bo
|
||||
|
||||
// Enable IOBT.
|
||||
if (xrRequestBodyTrackingFidelityMETA)
|
||||
CHECK_XR(xrRequestBodyTrackingFidelityMETA(id, XR_BODY_TRACKING_FIDELITY_HIGH_META));
|
||||
xrRequestBodyTrackingFidelityMETA(id, XR_BODY_TRACKING_FIDELITY_HIGH_META);
|
||||
}
|
||||
|
||||
xr::fb_body_tracker::packet_type xr::fb_body_tracker::locate_spaces(XrTime time, XrSpace reference)
|
||||
|
||||
@@ -41,7 +41,7 @@ class fb_body_tracker : public utils::handle<XrBodyTrackerFB>
|
||||
public:
|
||||
using packet_type = wivrn::from_headset::meta_body;
|
||||
|
||||
fb_body_tracker(instance & inst, session & s, bool lower_body);
|
||||
fb_body_tracker(instance & inst, session & s, bool full_body);
|
||||
|
||||
packet_type locate_spaces(XrTime time, XrSpace reference);
|
||||
bool should_send_skeleton();
|
||||
|
||||
@@ -22,11 +22,13 @@
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <magic_enum.hpp>
|
||||
#include <netinet/in.h>
|
||||
#include <openssl/aes.h>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
#include <vulkan/vulkan_core.h>
|
||||
@@ -270,6 +272,19 @@ enum class body_type : uint8_t
|
||||
htc,
|
||||
};
|
||||
|
||||
enum class body_part_mask : uint32_t
|
||||
{
|
||||
chest = 1 << 0,
|
||||
left_elbow = 1 << 1,
|
||||
right_elbow = 1 << 2,
|
||||
hip = 1 << 3,
|
||||
left_knee = 1 << 4,
|
||||
right_knee = 1 << 5,
|
||||
left_foot = 1 << 6,
|
||||
right_foot = 1 << 7,
|
||||
max,
|
||||
};
|
||||
|
||||
struct settings_changed
|
||||
{
|
||||
float preferred_refresh_rate;
|
||||
@@ -282,6 +297,8 @@ struct settings_changed
|
||||
// Whether the server should mirror the gamepad to a virtual uinput device;
|
||||
// gamepad inputs are always forwarded for the OpenXR path
|
||||
bool mirror_gamepad = false;
|
||||
// which virtual trackers should be enabled for body tracking
|
||||
std::underlying_type_t<body_part_mask> enabled_body_parts;
|
||||
};
|
||||
|
||||
struct headset_info_packet
|
||||
@@ -940,3 +957,10 @@ using packets = std::variant<
|
||||
running_applications>;
|
||||
} // namespace to_headset
|
||||
} // namespace wivrn
|
||||
|
||||
template <>
|
||||
struct magic_enum::customize::enum_range<wivrn::from_headset::body_part_mask>
|
||||
{
|
||||
static constexpr int min = 0;
|
||||
static constexpr int max = static_cast<int>(wivrn::from_headset::body_part_mask::max) - 1;
|
||||
};
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
#include "xrt/xrt_defines.h"
|
||||
#include "xrt/xrt_results.h"
|
||||
#include <unordered_map>
|
||||
|
||||
static_assert(std::to_underlying(XR_BODY_JOINT_COUNT_FB) == std::to_underlying(XRT_BODY_JOINT_COUNT_FB));
|
||||
static_assert(std::to_underlying(XR_FULL_BODY_JOINT_COUNT_META) == std::to_underlying(XRT_FULL_BODY_JOINT_COUNT_META));
|
||||
@@ -178,9 +179,9 @@ void body_joints_list::update_tracking(const wivrn::from_headset::meta_body & tr
|
||||
};
|
||||
std::visit(utils::overloaded{
|
||||
[&](std::monostate) {
|
||||
for (auto & [_, t]: parent.virtual_trackers)
|
||||
for (auto & [_, tracker]: parent.virtual_trackers)
|
||||
{
|
||||
t.update_tracking(tracking.production_timestamp, tracking.timestamp, {}, offset);
|
||||
tracker.update_tracking(tracking.production_timestamp, tracking.timestamp, {}, offset);
|
||||
}
|
||||
},
|
||||
[&](auto & joints) {
|
||||
@@ -194,7 +195,9 @@ void body_joints_list::update_tracking(const wivrn::from_headset::meta_body & tr
|
||||
|
||||
if (auto it = parent.virtual_trackers.find(joint); it != parent.virtual_trackers.cend())
|
||||
{
|
||||
it->second.update_tracking(tracking.production_timestamp, tracking.timestamp, pose, offset);
|
||||
const auto body_part = parent.joint_body_parts.at(joint);
|
||||
auto & tracker = it->second;
|
||||
tracker.update_tracking(tracking.production_timestamp, tracking.timestamp, pose, offset);
|
||||
}
|
||||
}
|
||||
}},
|
||||
@@ -220,7 +223,9 @@ void body_joints_list::update_tracking(const wivrn::from_headset::bd_body & trac
|
||||
|
||||
if (auto it = parent.virtual_trackers.find(joint); it != parent.virtual_trackers.cend())
|
||||
{
|
||||
it->second.update_tracking(tracking.production_timestamp, tracking.timestamp, pose, offset);
|
||||
const auto body_part = parent.joint_body_parts.at(joint);
|
||||
auto & tracker = it->second;
|
||||
tracker.update_tracking(tracking.production_timestamp, tracking.timestamp, pose, offset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,8 +248,17 @@ wivrn_body_tracker::wivrn_body_tracker(xrt_device * hmd, wivrn::wivrn_session &
|
||||
joints_list(cnx.get_info().body_tracking, *this),
|
||||
cnx(cnx)
|
||||
{
|
||||
// joint id, pretty name
|
||||
std::map<uint32_t, std::string> virtual_joints{};
|
||||
static const std::unordered_map<from_headset::body_part_mask, std::string> body_part_pretty_names{
|
||||
{from_headset::body_part_mask::chest, "Chest"},
|
||||
{from_headset::body_part_mask::left_elbow, "Left Elbow"},
|
||||
{from_headset::body_part_mask::right_elbow, "Right Elbow"},
|
||||
{from_headset::body_part_mask::hip, "Hip"},
|
||||
{from_headset::body_part_mask::left_knee, "Left Knee"},
|
||||
{from_headset::body_part_mask::right_knee, "Right Knee"},
|
||||
{from_headset::body_part_mask::left_foot, "Left Foot"},
|
||||
{from_headset::body_part_mask::right_foot, "Right Foot"},
|
||||
};
|
||||
|
||||
switch (cnx.get_info().body_tracking)
|
||||
{
|
||||
case from_headset::body_type::meta:
|
||||
@@ -259,14 +273,14 @@ wivrn_body_tracker::wivrn_body_tracker(xrt_device * hmd, wivrn::wivrn_session &
|
||||
.name = XRT_INPUT_META_FULL_BODY_TRACKING,
|
||||
});
|
||||
|
||||
virtual_joints.emplace(XRT_FULL_BODY_JOINT_CHEST_META, "Chest");
|
||||
virtual_joints.emplace(XRT_FULL_BODY_JOINT_LEFT_ARM_LOWER_META, "Left Elbow");
|
||||
virtual_joints.emplace(XRT_FULL_BODY_JOINT_RIGHT_ARM_LOWER_META, "Right Elbow");
|
||||
virtual_joints.emplace(XRT_FULL_BODY_JOINT_HIPS_META, "Hip");
|
||||
virtual_joints.emplace(XRT_FULL_BODY_JOINT_LEFT_LOWER_LEG_META, "Left Knee");
|
||||
virtual_joints.emplace(XRT_FULL_BODY_JOINT_RIGHT_LOWER_LEG_META, "Right Knee");
|
||||
virtual_joints.emplace(XRT_FULL_BODY_JOINT_LEFT_FOOT_TRANSVERSE_META, "Left Foot");
|
||||
virtual_joints.emplace(XRT_FULL_BODY_JOINT_RIGHT_FOOT_TRANSVERSE_META, "Right Foot");
|
||||
joint_body_parts.emplace(XRT_FULL_BODY_JOINT_CHEST_META, from_headset::body_part_mask::chest);
|
||||
joint_body_parts.emplace(XRT_FULL_BODY_JOINT_LEFT_ARM_LOWER_META, from_headset::body_part_mask::left_elbow);
|
||||
joint_body_parts.emplace(XRT_FULL_BODY_JOINT_RIGHT_ARM_LOWER_META, from_headset::body_part_mask::right_elbow);
|
||||
joint_body_parts.emplace(XRT_FULL_BODY_JOINT_HIPS_META, from_headset::body_part_mask::hip);
|
||||
joint_body_parts.emplace(XRT_FULL_BODY_JOINT_LEFT_LOWER_LEG_META, from_headset::body_part_mask::left_knee);
|
||||
joint_body_parts.emplace(XRT_FULL_BODY_JOINT_RIGHT_LOWER_LEG_META, from_headset::body_part_mask::right_knee);
|
||||
joint_body_parts.emplace(XRT_FULL_BODY_JOINT_LEFT_FOOT_TRANSVERSE_META, from_headset::body_part_mask::left_foot);
|
||||
joint_body_parts.emplace(XRT_FULL_BODY_JOINT_RIGHT_FOOT_TRANSVERSE_META, from_headset::body_part_mask::right_foot);
|
||||
break;
|
||||
case from_headset::body_type::fb:
|
||||
strcpy(str, "WiVRn FB body tracker");
|
||||
@@ -276,10 +290,10 @@ wivrn_body_tracker::wivrn_body_tracker(xrt_device * hmd, wivrn::wivrn_session &
|
||||
.name = XRT_INPUT_FB_BODY_TRACKING,
|
||||
});
|
||||
|
||||
virtual_joints.emplace(XRT_BODY_JOINT_CHEST_FB, "Chest");
|
||||
virtual_joints.emplace(XRT_BODY_JOINT_LEFT_ARM_LOWER_FB, "Left Elbow");
|
||||
virtual_joints.emplace(XRT_BODY_JOINT_RIGHT_ARM_LOWER_FB, "Right Elbow");
|
||||
virtual_joints.emplace(XRT_BODY_JOINT_HIPS_FB, "Hip");
|
||||
joint_body_parts.emplace(XRT_BODY_JOINT_CHEST_FB, from_headset::body_part_mask::chest);
|
||||
joint_body_parts.emplace(XRT_BODY_JOINT_LEFT_ARM_LOWER_FB, from_headset::body_part_mask::left_elbow);
|
||||
joint_body_parts.emplace(XRT_BODY_JOINT_RIGHT_ARM_LOWER_FB, from_headset::body_part_mask::right_elbow);
|
||||
joint_body_parts.emplace(XRT_BODY_JOINT_HIPS_FB, from_headset::body_part_mask::hip);
|
||||
break;
|
||||
case from_headset::body_type::bd:
|
||||
strcpy(str, "WiVRn BD body tracker");
|
||||
@@ -289,14 +303,14 @@ wivrn_body_tracker::wivrn_body_tracker(xrt_device * hmd, wivrn::wivrn_session &
|
||||
.name = XRT_INPUT_BD_BODY_TRACKING,
|
||||
});
|
||||
|
||||
virtual_joints.emplace(XRT_BODY_JOINT_SPINE3_BD, "Chest");
|
||||
virtual_joints.emplace(XRT_BODY_JOINT_LEFT_ELBOW_BD, "Left Elbow");
|
||||
virtual_joints.emplace(XRT_BODY_JOINT_RIGHT_ELBOW_BD, "Right Elbow");
|
||||
virtual_joints.emplace(XRT_BODY_JOINT_PELVIS_BD, "Hip");
|
||||
virtual_joints.emplace(XRT_BODY_JOINT_LEFT_KNEE_BD, "Left Knee");
|
||||
virtual_joints.emplace(XRT_BODY_JOINT_RIGHT_KNEE_BD, "Right Knee");
|
||||
virtual_joints.emplace(XRT_BODY_JOINT_LEFT_FOOT_BD, "Left Foot");
|
||||
virtual_joints.emplace(XRT_BODY_JOINT_RIGHT_FOOT_BD, "Right Foot");
|
||||
joint_body_parts.emplace(XRT_BODY_JOINT_SPINE3_BD, from_headset::body_part_mask::chest);
|
||||
joint_body_parts.emplace(XRT_BODY_JOINT_LEFT_ELBOW_BD, from_headset::body_part_mask::left_elbow);
|
||||
joint_body_parts.emplace(XRT_BODY_JOINT_RIGHT_ELBOW_BD, from_headset::body_part_mask::right_elbow);
|
||||
joint_body_parts.emplace(XRT_BODY_JOINT_PELVIS_BD, from_headset::body_part_mask::hip);
|
||||
joint_body_parts.emplace(XRT_BODY_JOINT_LEFT_KNEE_BD, from_headset::body_part_mask::left_knee);
|
||||
joint_body_parts.emplace(XRT_BODY_JOINT_RIGHT_KNEE_BD, from_headset::body_part_mask::right_knee);
|
||||
joint_body_parts.emplace(XRT_BODY_JOINT_LEFT_FOOT_BD, from_headset::body_part_mask::left_foot);
|
||||
joint_body_parts.emplace(XRT_BODY_JOINT_RIGHT_FOOT_BD, from_headset::body_part_mask::right_foot);
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
@@ -306,12 +320,16 @@ wivrn_body_tracker::wivrn_body_tracker(xrt_device * hmd, wivrn::wivrn_session &
|
||||
inputs = inputs_array.data();
|
||||
input_count = inputs_array.size();
|
||||
|
||||
for (auto & [joint, name]: virtual_joints)
|
||||
for (auto & [joint, body_part]: joint_body_parts)
|
||||
{
|
||||
auto [it, success] = virtual_trackers.try_emplace(joint, name, hmd, cnx);
|
||||
auto & name = body_part_pretty_names.at(body_part);
|
||||
auto [it, success] = virtual_trackers.emplace(std::piecewise_construct,
|
||||
std::forward_as_tuple(joint),
|
||||
std::forward_as_tuple(name, hmd, cnx));
|
||||
assert(success);
|
||||
device_add_callback(it->second);
|
||||
}
|
||||
(*this)(*cnx.get_settings());
|
||||
}
|
||||
|
||||
xrt_result_t wivrn_body_tracker::update_inputs()
|
||||
@@ -384,4 +402,12 @@ void wivrn_body_tracker::update_skeleton(const from_headset::meta_body_skeleton
|
||||
meta_skeleton_generation++;
|
||||
}
|
||||
|
||||
} // namespace wivrn
|
||||
void wivrn_body_tracker::operator()(const from_headset::settings_changed & settings)
|
||||
{
|
||||
for (auto & [joint, tracker]: virtual_trackers)
|
||||
{
|
||||
const auto body_part = joint_body_parts.at(joint);
|
||||
tracker.set_enabled(settings.enabled_body_parts & std::to_underlying(body_part));
|
||||
}
|
||||
}
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#include "wivrn_packets.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
@@ -65,7 +65,10 @@ class wivrn_body_tracker : public xrt_device
|
||||
std::atomic_uint32_t meta_skeleton_generation;
|
||||
|
||||
protected:
|
||||
std::map<uint32_t, wivrn_generic_tracker> virtual_trackers;
|
||||
// key is joint
|
||||
std::unordered_map<uint32_t, from_headset::body_part_mask> joint_body_parts;
|
||||
// key is joint
|
||||
std::unordered_map<uint32_t, wivrn_generic_tracker> virtual_trackers;
|
||||
|
||||
public:
|
||||
using base_t = xrt_device;
|
||||
@@ -78,6 +81,8 @@ public:
|
||||
void update_tracking(const from_headset::meta_body &, const clock_offset &);
|
||||
void update_tracking(const from_headset::bd_body &, const clock_offset &);
|
||||
void update_skeleton(const from_headset::meta_body_skeleton &);
|
||||
|
||||
void operator()(const from_headset::settings_changed & settings);
|
||||
};
|
||||
|
||||
} // namespace wivrn
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -117,6 +117,9 @@ xrt_result_t wivrn_generic_tracker::get_tracked_pose(xrt_input_name name, int64_
|
||||
{
|
||||
XrTime production_timestamp;
|
||||
|
||||
if (!enabled)
|
||||
return XRT_ERROR_INPUT_UNSUPPORTED;
|
||||
|
||||
if (name == XRT_INPUT_GENERIC_TRACKER_POSE)
|
||||
{
|
||||
std::tie(production_timestamp, *res) = poses.get_at(at_timestamp_ns);
|
||||
@@ -133,4 +136,9 @@ void wivrn_generic_tracker::update_tracking(XrTime produced_timestamp, XrTime ti
|
||||
{
|
||||
poses.update_tracking(produced_timestamp, timestamp, pose, offset);
|
||||
}
|
||||
|
||||
void wivrn_generic_tracker::set_enabled(bool enabled)
|
||||
{
|
||||
this->enabled = enabled;
|
||||
}
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -44,6 +44,7 @@ class wivrn_generic_tracker : public xrt_device
|
||||
xrt_input pose_input;
|
||||
|
||||
wivrn_session & cnx;
|
||||
bool enabled = true;
|
||||
|
||||
public:
|
||||
using base_t = xrt_device;
|
||||
@@ -53,5 +54,7 @@ public:
|
||||
xrt_result_t get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns, xrt_space_relation * out_relation);
|
||||
|
||||
void update_tracking(XrTime produced_timestamp, XrTime timestamp, const xrt_space_relation & pose, const clock_offset & offset);
|
||||
|
||||
void set_enabled(bool enabled);
|
||||
};
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -507,6 +507,9 @@ void wivrn_session::operator()(const from_headset::settings_changed & settings)
|
||||
if (not settings.mirror_gamepad and uinput_handler)
|
||||
uinput_handler->destroy_gamepad();
|
||||
|
||||
if (body_tracker)
|
||||
(*body_tracker)(settings);
|
||||
|
||||
wivrn_ipc_socket_monado->send(std::move(settings));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user