From 9f80c1da7c3ca46b80e64c57a9029c275b6acf4f Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Mon, 18 Aug 2025 13:55:25 +0200 Subject: [PATCH] Remove body trackers from application.h --- client/application.cpp | 56 ++++++-------------- client/application.h | 11 ++-- client/configuration.cpp | 27 ++-------- client/scenes/lobby_gui.cpp | 19 +++---- client/scenes/stream.cpp | 28 +++++----- client/scenes/stream.h | 1 + client/scenes/stream_tracking.cpp | 69 ++++++++++++++----------- client/xr/body_tracker.cpp | 80 +++++++++++++++++++++++++++++ client/xr/body_tracker.h | 49 ++++++++++++++++++ client/xr/fb_body_tracker.cpp | 64 +++++++++-------------- client/xr/fb_body_tracker.h | 18 ++----- client/xr/htc_body_tracker.cpp | 85 ++++++++++--------------------- client/xr/htc_body_tracker.h | 21 +++----- client/xr/instance.cpp | 17 ++++++- client/xr/instance.h | 2 + client/xr/pico_body_tracker.cpp | 4 -- client/xr/pico_body_tracker.h | 1 - 17 files changed, 293 insertions(+), 259 deletions(-) create mode 100644 client/xr/body_tracker.cpp create mode 100644 client/xr/body_tracker.h diff --git a/client/application.cpp b/client/application.cpp index a6fa51da..e49bc994 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -30,8 +30,8 @@ #include "wifi_lock.h" #include "xr/actionset.h" #include "xr/check.h" +#include "xr/htc_exts.h" #include "xr/meta_body_tracking_fidelity.h" -#include "xr/xr.h" #include #include #include @@ -961,8 +961,6 @@ void application::initialize_actions() { spdlog::debug("Initializing actions"); - auto * htc_body = std::get_if(&body_tracker); - // Build an action set with all possible input sources std::vector action_sets; xr_actionset = xr::actionset(xr_instance, "all_actions", "All actions"); @@ -1036,14 +1034,15 @@ void application::initialize_actions() } // Dynamically add VIVE XR Trackers to the profile if available - if (htc_body && utils::contains(profile.required_extensions, XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME)) + if (utils::contains(profile.required_extensions, XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME) and + xr_instance.has_extension(XR_HTC_PATH_ENUMERATION_EXTENSION_NAME)) { - for (const auto & user_path: htc_body->get_paths()) + XrPath tracker_profile = xr_instance.string_to_path("/interaction_profiles/htc/vive_xr_tracker"); + for (const auto & user_path: xr_instance.enumerate_paths_for_interaction_profile(tracker_profile)) { - for (const auto & input_path: htc_body->get_paths(user_path)) - { - profile.input_sources.push_back(path_to_string(user_path) + path_to_string(input_path)); - } + generic_trackers.emplace_back(user_path, nullptr); + for (const auto & input_path: xr_instance.enumerate_paths_for_interaction_profile(tracker_profile, user_path)) + profile.input_sources.push_back(xr_instance.path_to_string(user_path) + xr_instance.path_to_string(input_path)); } } @@ -1091,8 +1090,14 @@ void application::initialize_actions() spaces[size_t(xr::spaces::poke_right)] = xr_session.create_action_space(a); else if (name == "/user/eyes_ext/input/gaze_ext/pose") spaces[size_t(xr::spaces::eye_gaze)] = xr_session.create_action_space(a); - else if (name.contains("/input/entity_htc/pose") && htc_body) - htc_body->add(xr_session.create_action_space(a)); + else if (name.contains("/input/entity_htc/pose")) + { + for (auto & [path, action]: generic_trackers) + { + if (name.starts_with(path_to_string(path))) + action = xr_session.create_action_space(a); + } + } } // Build an action set for each scene @@ -1286,28 +1291,6 @@ void application::initialize() config.emplace(xr_system_id); - 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})) - { - XrSystemBodyTrackingPropertiesFB fb_body_properties = xr_system_id.fb_body_tracking_properties(); - spdlog::info(" FB body tracking support: {}", (bool)fb_body_properties.supportsBodyTracking); - if (fb_body_properties.supportsBodyTracking) - body_tracker.emplace(xr_instance, xr_session); - } - - if (std::holds_alternative(body_tracker) && utils::contains_all(xr_extensions, std::array{XR_HTC_PATH_ENUMERATION_EXTENSION_NAME, XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME})) - { - spdlog::info(" HTC body tracking support: true"); - body_tracker.emplace(xr_instance, xr_session); - } - - if (std::holds_alternative(body_tracker) && utils::contains(xr_extensions, XR_BD_BODY_TRACKING_EXTENSION_NAME)) - { - XrSystemBodyTrackingPropertiesBD bd_body_properties = xr_system_id.bd_body_tracking_properties(); - spdlog::info(" PICO body tracking support: {}", (bool)bd_body_properties.supportsBodyTracking); - if (bd_body_properties.supportsBodyTracking) - body_tracker.emplace(xr_instance, xr_session); - } - vk::CommandPoolCreateInfo cmdpool_create_info; cmdpool_create_info.queueFamilyIndex = vk_queue_family_index; cmdpool_create_info.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer; @@ -1842,13 +1825,6 @@ void application::poll_events() exit_requested = true; } break; - case XR_TYPE_EVENT_DATA_INTERACTION_PROFILE_CHANGED: { - if (auto * htc_body = std::get_if(&body_tracker)) - { - htc_body->update_active(); - } - } - break; case XR_TYPE_EVENT_DATA_REFERENCE_SPACE_CHANGE_PENDING: break; case XR_TYPE_EVENT_DATA_SESSION_STATE_CHANGED: { diff --git a/client/application.h b/client/application.h index cbedae51..de208576 100644 --- a/client/application.h +++ b/client/application.h @@ -123,7 +123,7 @@ class application : public singleton xr::actionset xr_actionset; std::vector> actions; - std::variant body_tracker; + std::vector> generic_trackers; bool eye_gaze_supported = false; @@ -423,11 +423,6 @@ public: return instance().last_scene_cpu_time; } - static bool get_body_tracking_supported() - { - return !std::holds_alternative(instance().body_tracker); - } - static bool get_eye_gaze_supported() { return instance().eye_gaze_supported; @@ -438,9 +433,9 @@ public: return instance().openxr_post_processing_supported; } - static auto & get_body_tracker() + static auto & get_generic_trackers() { - return instance().body_tracker; + return instance().generic_trackers; } static const std::vector & get_xr_extensions() diff --git a/client/configuration.cpp b/client/configuration.cpp index 9a1019a4..2ea37c41 100644 --- a/client/configuration.cpp +++ b/client/configuration.cpp @@ -20,6 +20,7 @@ #include "configuration.h" #include "application.h" +#include "xr/body_tracker.h" #include "xr/face_tracker.h" #include #include @@ -111,30 +112,8 @@ bool configuration::check_feature(feature f) const return false; break; case feature::body_tracking: - switch (guess_model()) - { - case model::meta_quest_3: - case model::meta_quest_3s: - if (not std::holds_alternative(application::get_body_tracker())) - return false; - break; - case model::htc_vive_focus_3: - case model::htc_vive_xr_elite: - case model::htc_vive_focus_vision: - if (not std::holds_alternative(application::get_body_tracker())) - return false; - break; - case model::pico_neo_3: - case model::pico_4: - case model::pico_4s: - case model::pico_4_pro: - case model::pico_4_enterprise: - if (not std::holds_alternative(application::get_body_tracker())) - return false; - break; - default: - break; - } + if (xr::body_tracker_supported(instance, system) == xr::body_tracker_type::none) + return false; break; } } diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index 1458e0be..33a60dd8 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -34,6 +34,7 @@ #include "utils/overloaded.h" #include "utils/ranges.h" #include "version.h" +#include "xr/body_tracker.h" #include #include #include @@ -925,8 +926,9 @@ void scenes::lobby::gui_settings() imgui_ctx->vibrate_on_hover(); } + auto body_tracker = xr::body_tracker_supported(instance, system); { - ImGui::BeginDisabled(not application::get_body_tracking_supported()); + ImGui::BeginDisabled(body_tracker == xr::body_tracker_type::none); bool enabled = config.check_feature(feature::body_tracking); if (ImGui::Checkbox(_S("Enable body tracking"), &enabled)) { @@ -941,19 +943,14 @@ void scenes::lobby::gui_settings() } else { - std::visit(utils::overloaded{ - [](auto &) {}, - [this](xr::fb_body_tracker &) { - imgui_ctx->tooltip(_("Requires 'Hand and body tracking' to be enabled in the Quest movement tracking settings,\notherwise body data will be guessed from controller and headset positions")); - }, - }, - application::get_body_tracker()); + if (body_tracker == xr::body_tracker_type::fb) + imgui_ctx->tooltip(_("Requires 'Hand and body tracking' to be enabled in the Quest movement tracking settings,\notherwise body data will be guessed from controller and headset positions")); } } imgui_ctx->vibrate_on_hover(); } - if (std::holds_alternative(application::get_body_tracker())) + if (body_tracker == xr::body_tracker_type::fb) { ImGui::BeginDisabled(not config.check_feature(feature::body_tracking)); ImGui::Indent(); @@ -1313,7 +1310,7 @@ void scenes::lobby::gui_first_run() item{ .f = feature::body_tracking, .text = _S("Enable body tracking?"), - .supported = application::get_body_tracking_supported(), + .supported = xr::body_tracker_supported(instance, system) != xr::body_tracker_type::none, }, }; @@ -1733,7 +1730,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time) }); } - if (application::get_body_tracking_supported()) + if (xr::body_tracker_supported(instance, system) != xr::body_tracker_type::none) { items.push_back({ .f = feature::body_tracking, diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index 9be0f108..fad4731e 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -17,12 +17,9 @@ * along with this program. If not, see . */ #include "constants.h" -#include "utils/overloaded.h" +#include "xr/body_tracker.h" #include "xr/face_tracker.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" #include "xr/space.h" #include #include @@ -275,15 +272,20 @@ std::shared_ptr scenes::stream::create(std::unique_ptrinstance, self->system)) + { + case xr::body_tracker_type::none: + break; + case xr::body_tracker_type::fb: + info.num_generic_trackers = xr::fb_body_tracker::get_whitelisted_joints(config.fb_lower_body, config.fb_hip).size(); + break; + case xr::body_tracker_type::htc: + info.num_generic_trackers = application::get_generic_trackers().size(); + break; + case xr::body_tracker_type::pico: + info.num_generic_trackers = xr::pico_body_tracker::joint_whitelist.size(); + break; + } } info.palm_pose = application::space(xr::spaces::palm_left) or application::space(xr::spaces::palm_right); diff --git a/client/scenes/stream.h b/client/scenes/stream.h index a7cbd2ce..146b6752 100644 --- a/client/scenes/stream.h +++ b/client/scenes/stream.h @@ -86,6 +86,7 @@ private: std::thread network_thread; thread_safe tracking_control{}; std::array, 2> interaction_profiles; // left and right hand + std::atomic interaction_profile_changed = false; std::atomic recenter_requested = false; std::atomic display_time_phase = 0; std::atomic display_time_period = 0; diff --git a/client/scenes/stream_tracking.cpp b/client/scenes/stream_tracking.cpp index 8ff3e3d0..6370ae61 100644 --- a/client/scenes/stream_tracking.cpp +++ b/client/scenes/stream_tracking.cpp @@ -21,6 +21,7 @@ #include "stream.h" #include "utils/overloaded.h" #include "wivrn_packets.h" +#include "xr/body_tracker.h" #include "xr/face_tracker.h" #include "xr/fb_body_tracker.h" #include @@ -393,18 +394,7 @@ void scenes::stream::tracking() xr::face_tracker face_tracker; const bool body_tracking = config.check_feature(feature::body_tracking); - auto & body_tracker = application::get_body_tracker(); - if (body_tracking) - { - if (auto * body_fb = std::get_if(&body_tracker)) - { - // TODO maybe handle reconnection better, if the settings are changed since - // last connection to running server, the tracker count will mismatch and - // stuff might break - body_fb->stop(); - body_fb->start(config.fb_lower_body, config.fb_hip); - } - } + xr::body_tracker body_tracker; locate_spaces_functor locate_spaces{instance, world_space}; @@ -429,6 +419,7 @@ void scenes::stream::tracking() int samples = 0; auto control = *tracking_control.lock(); + bool interaction_profile_changed = this->interaction_profile_changed.exchange(false); if (control.enabled[size_t(tid::left_hand)]) { @@ -454,6 +445,24 @@ void scenes::stream::tracking() else face_tracker.emplace(); + if (body_tracking and control.enabled[size_t(tid::generic_tracker)]) + { + if (std::holds_alternative(body_tracker)) + body_tracker = xr::make_body_tracker( + instance, + system, + session, + application::get_generic_trackers(), + config.fb_lower_body, + config.fb_hip); + } + else + body_tracker.emplace(); + + if (interaction_profile_changed) + if (auto htc = std::get_if(&body_tracker)) + htc->update_active(); + XrDuration prediction = std::clamp(control.max_offset.count(), 0, 80'000'000); auto period = std::max(display_time_period.load(), 1'000'000); for (XrDuration Δt = display_time_phase - t0 % period + (control.min_offset.count() / period) * period; @@ -513,26 +522,25 @@ void scenes::stream::tracking() } locate_spaces.resolve(session, t0 + Δt, packet.device_poses); - if (body_tracking) - std::visit(utils::overloaded{ - [](std::monostate &) {}, - [&](auto & b) { - if (t0 >= last_body_sample + period and - (Δt == 0 or Δt >= prediction - 2 * period)) + std::visit(utils::overloaded{ + [](std::monostate &) {}, + [&](auto & b) { + if (t0 >= last_body_sample + period and + (Δt == 0 or Δt >= prediction - 2 * period)) + { + last_body_sample = t0; + if (control.enabled[size_t(tid::generic_tracker)]) { - last_body_sample = t0; - if (control.enabled[size_t(tid::generic_tracker)]) - { - body.push_back(from_headset::body_tracking{ - .production_timestamp = t0, - .timestamp = t0 + Δt, - .poses = b.locate_spaces(t0 + Δt, world_space), - }); - } + body.push_back(from_headset::body_tracking{ + .production_timestamp = t0, + .timestamp = t0 + Δt, + .poses = b.locate_spaces(t0 + Δt, world_space), + }); } - }, - }, - body_tracker); + } + }, + }, + body_tracker); std::visit(utils::overloaded{ [](std::monostate &) {}, @@ -672,6 +680,7 @@ static device_id derived_from(device_id target) void scenes::stream::on_interaction_profile_changed(const XrEventDataInteractionProfileChanged &) { + interaction_profile_changed = true; std::array path = { "/user/hand/left", "/user/hand/right", diff --git a/client/xr/body_tracker.cpp b/client/xr/body_tracker.cpp new file mode 100644 index 00000000..33247b93 --- /dev/null +++ b/client/xr/body_tracker.cpp @@ -0,0 +1,80 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2025 Patrick Nicolas + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "body_tracker.h" + +#include "xr/htc_exts.h" +#include "xr/instance.h" +#include "xr/system.h" + +xr::body_tracker_type xr::body_tracker_supported(xr::instance & instance, xr::system & system) +{ + if (instance.has_extension(XR_FB_BODY_TRACKING_EXTENSION_NAME) and + instance.has_extension(XR_META_BODY_TRACKING_FULL_BODY_EXTENSION_NAME) and + instance.has_extension(XR_META_BODY_TRACKING_FIDELITY_EXTENSION_NAME)) + { + auto fb_body_properties = system.fb_body_tracking_properties(); + if (fb_body_properties.supportsBodyTracking) + return body_tracker_type::fb; + } + + if (instance.has_extension(XR_HTC_PATH_ENUMERATION_EXTENSION_NAME) and + instance.has_extension(XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME)) + return body_tracker_type::htc; + + if (instance.has_extension(XR_BD_BODY_TRACKING_EXTENSION_NAME)) + { + auto bd_body_properties = system.bd_body_tracking_properties(); + if (bd_body_properties.supportsBodyTracking) + return body_tracker_type::pico; + } + + return xr::body_tracker_type::none; +} + +xr::body_tracker xr::make_body_tracker(xr::instance & instance, xr::system & system, xr::session & session, std::vector> & generic_trackers, bool full_body, bool hips) +{ + if (instance.has_extension(XR_FB_BODY_TRACKING_EXTENSION_NAME) and + instance.has_extension(XR_META_BODY_TRACKING_FULL_BODY_EXTENSION_NAME) and + instance.has_extension(XR_META_BODY_TRACKING_FIDELITY_EXTENSION_NAME)) + { + auto fb_body_properties = system.fb_body_tracking_properties(); + if (fb_body_properties.supportsBodyTracking) + return xr::body_tracker(std::in_place_type_t(), + instance, + session, + full_body, + hips); + } + + if (not generic_trackers.empty()) + return xr::body_tracker(std::in_place_type_t(), + session, + generic_trackers); + + if (instance.has_extension(XR_BD_BODY_TRACKING_EXTENSION_NAME)) + { + auto bd_body_properties = system.bd_body_tracking_properties(); + if (bd_body_properties.supportsBodyTracking) + return xr::body_tracker(std::in_place_type_t(), + instance, + session); + } + + return std::monostate(); +} diff --git a/client/xr/body_tracker.h b/client/xr/body_tracker.h new file mode 100644 index 00000000..375579db --- /dev/null +++ b/client/xr/body_tracker.h @@ -0,0 +1,49 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2025 Patrick Nicolas + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include "fb_body_tracker.h" +#include "htc_body_tracker.h" +#include "pico_body_tracker.h" + +#include +#include +#include + +namespace xr +{ + +class instance; +class system; + +enum class body_tracker_type +{ + none, + fb, + htc, + pico, +}; + +using body_tracker = std::variant; + +body_tracker_type body_tracker_supported(xr::instance &, xr::system &); + +body_tracker make_body_tracker(xr::instance &, xr::system &, xr::session &, std::vector> & generic_trackers, bool full_body, bool hips); + +} // namespace xr diff --git a/client/xr/fb_body_tracker.cpp b/client/xr/fb_body_tracker.cpp index f3d30dd1..f6416078 100644 --- a/client/xr/fb_body_tracker.cpp +++ b/client/xr/fb_body_tracker.cpp @@ -17,15 +17,23 @@ */ #include "fb_body_tracker.h" -#include "application.h" #include "spdlog/spdlog.h" +#include "xr/instance.h" #include "xr/meta_body_tracking_fidelity.h" -#include "xr/xr.h" +#include "xr/session.h" +#include "xr/to_string.h" #include #include static_assert(xr::fb_body_tracker::joint_whitelist.size() <= wivrn::from_headset::body_tracking::max_tracked_poses); +static PFN_xrDestroyBodyTrackerFB xrDestroyBodyTrackerFB{}; + +XrResult xr::destroy_fb_body_tracker(XrBodyTrackerFB id) +{ + return xrDestroyBodyTrackerFB(id); +} + std::vector xr::fb_body_tracker::get_whitelisted_joints(bool full_body, bool hip) { auto whitelisted_joints = std::ranges::filter_view(xr::fb_body_tracker::joint_whitelist, [=](auto joint) { @@ -39,59 +47,33 @@ std::vector xr::fb_body_tracker::get_whitelisted_joints(boo return {whitelisted_joints.begin(), whitelisted_joints.end()}; } -xr::fb_body_tracker::fb_body_tracker(instance & inst, session & s) : - s(s) +xr::fb_body_tracker::fb_body_tracker(instance & inst, session & s, bool full_body, bool hip) : + xrRequestBodyTrackingFidelityMETA(inst.get_proc("xrRequestBodyTrackingFidelityMETA")), + xrLocateBodyJointsFB(inst.get_proc("xrLocateBodyJointsFB")), + full_body(full_body), + hip(hip) { - xrCreateBodyTrackerFB = inst.get_proc("xrCreateBodyTrackerFB"); - xrRequestBodyTrackingFidelityMETA = inst.get_proc("xrRequestBodyTrackingFidelityMETA"); - xrLocateBodyJointsFB = inst.get_proc("xrLocateBodyJointsFB"); + auto xrCreateBodyTrackerFB = inst.get_proc("xrCreateBodyTrackerFB"); xrDestroyBodyTrackerFB = inst.get_proc("xrDestroyBodyTrackerFB"); -} -xr::fb_body_tracker::~fb_body_tracker() -{ - stop(); -} - -void xr::fb_body_tracker::start(bool full_body, bool hip) -{ - assert(xrCreateBodyTrackerFB); - this->full_body = full_body; - this->hip = hip; XrBodyTrackerCreateInfoFB create_info{ .type = XR_TYPE_BODY_TRACKER_CREATE_INFO_FB, - .next = nullptr, + .bodyJointSet = full_body + ? XR_BODY_JOINT_SET_FULL_BODY_META + : XR_BODY_JOINT_SET_DEFAULT_FB, }; - create_info.bodyJointSet = full_body - ? XR_BODY_JOINT_SET_FULL_BODY_META - : XR_BODY_JOINT_SET_DEFAULT_FB; - CHECK_XR(xrCreateBodyTrackerFB(s, &create_info, &handle)); + CHECK_XR(xrCreateBodyTrackerFB(s, &create_info, &id)); // Enable IOBT. - CHECK_XR(xrRequestBodyTrackingFidelityMETA(handle, XR_BODY_TRACKING_FIDELITY_HIGH_META)); + CHECK_XR(xrRequestBodyTrackingFidelityMETA(id, XR_BODY_TRACKING_FIDELITY_HIGH_META)); whitelisted_joints = get_whitelisted_joints(full_body, hip); } -void xr::fb_body_tracker::stop() -{ - full_body = false; - hip = false; - if (handle) - { - assert(xrDestroyBodyTrackerFB); - CHECK_XR(xrDestroyBodyTrackerFB(std::exchange(handle, nullptr))); - } -} -size_t xr::fb_body_tracker::count() const -{ - const auto & config = application::get_config(); - return get_whitelisted_joints(config.fb_lower_body, config.fb_hip).size(); -} std::optional> xr::fb_body_tracker::locate_spaces(XrTime time, XrSpace reference) { - if (!handle) + if (!id) return std::nullopt; assert(xrLocateBodyJointsFB); @@ -111,7 +93,7 @@ std::optional #include @@ -30,15 +31,12 @@ namespace xr class instance; class session; -class fb_body_tracker -{ - XrSession s; - XrBodyTrackerFB handle{}; +XrResult destroy_fb_body_tracker(XrBodyTrackerFB); - PFN_xrCreateBodyTrackerFB xrCreateBodyTrackerFB{}; +class fb_body_tracker : public utils::handle +{ PFN_xrRequestBodyTrackingFidelityMETA xrRequestBodyTrackingFidelityMETA{}; PFN_xrLocateBodyJointsFB xrLocateBodyJointsFB{}; - PFN_xrDestroyBodyTrackerFB xrDestroyBodyTrackerFB{}; bool full_body{}; bool hip{}; @@ -59,13 +57,7 @@ public: }; static std::vector get_whitelisted_joints(bool full_body, bool hip); - fb_body_tracker() = default; - fb_body_tracker(instance & inst, session & s); - ~fb_body_tracker(); - - void start(bool lower_body, bool hip); - void stop(); - size_t count() const; + fb_body_tracker(instance & inst, session & s, bool full_body, bool hip); std::optional> locate_spaces(XrTime time, XrSpace reference); }; diff --git a/client/xr/htc_body_tracker.cpp b/client/xr/htc_body_tracker.cpp index b2d0b2ab..9f675203 100644 --- a/client/xr/htc_body_tracker.cpp +++ b/client/xr/htc_body_tracker.cpp @@ -2,6 +2,7 @@ * WiVRn VR streaming * Copyright (C) 2025 Awzri * Copyright (C) 2025 Sapphire + * Copyright (C) 2025 Patrick Nicolas * * 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,8 +20,7 @@ #include "htc_body_tracker.h" #include "xr/details/enumerate.h" -#include "xr/htc_exts.h" -#include "xr/xr.h" +#include "xr/session.h" #include // Note: This utilizes extensions not present in the OpenXR spec! @@ -28,11 +28,25 @@ // https://hub.vive.com/apidoc/api/VIVE.OpenXR.Tracker.ViveXRTracker.html // https://hub.vive.com/apidoc/api/VIVE.OpenXR.VivePathEnumerationHelper.xrEnumeratePathsForInteractionProfileHTCDelegate.html -xr::vive_xr_tracker::vive_xr_tracker(xr::space && space) : - space(std::move(space)) {} -void xr::vive_xr_tracker::set_active(bool active) +xr::vive_xr_tracker::vive_xr_tracker(XrPath path, xr::space & space, XrSession session) : + path(path), + space(space) { - is_active = active; + update_active(session); +} + +void xr::vive_xr_tracker::update_active(XrSession session) +{ + XrInputSourceLocalizedNameGetInfo get_info{ + .type = XR_TYPE_INPUT_SOURCE_LOCALIZED_NAME_GET_INFO, + .next = nullptr, + .sourcePath = path, + .whichComponents = XR_INPUT_SOURCE_LOCALIZED_NAME_USER_PATH_BIT, + }; + + auto role = xr::details::enumerate(xrGetInputSourceLocalizedName, session, &get_info); + + is_active = not role.contains("_"); } bool xr::vive_xr_tracker::get_active() const { @@ -76,63 +90,18 @@ static wivrn::from_headset::body_tracking::pose locate_space(XrSpace space, XrSp return res; } -std::vector xr::htc_body_tracker::get_roles() -{ - auto paths = get_paths(); - std::vector roles{}; - roles.reserve(paths.size()); - - for (auto & path: paths) - { - XrInputSourceLocalizedNameGetInfo get_info{ - .type = XR_TYPE_INPUT_SOURCE_LOCALIZED_NAME_GET_INFO, - .next = nullptr, - .sourcePath = path, - .whichComponents = XR_INPUT_SOURCE_LOCALIZED_NAME_USER_PATH_BIT, - }; - - roles.emplace_back(xr::details::enumerate(xrGetInputSourceLocalizedName, s, &get_info)); - } - - return roles; -} - -xr::htc_body_tracker::htc_body_tracker(instance & inst, session & s) : - inst(&inst), +xr::htc_body_tracker::htc_body_tracker(session & s, std::vector> & trackers) : s(s) { - xrEnumeratePathsForInteractionProfileHTC = inst.get_proc("xrEnumeratePathsForInteractionProfileHTC"); -} - -std::vector xr::htc_body_tracker::get_paths(XrPath user_path) -{ - assert(xrEnumeratePathsForInteractionProfileHTC); - XrPath tracker_profile = inst->string_to_path("/interaction_profiles/htc/vive_xr_tracker"); - - XrPathsForInteractionProfileEnumerateInfoHTC profile_info{ - .type = XR_TYPE_UNKNOWN, - .next = nullptr, - .interactionProfile = tracker_profile, - .userPath = user_path, - }; - return xr::details::enumerate(xrEnumeratePathsForInteractionProfileHTC, *inst, profile_info); -} - -void xr::htc_body_tracker::add(xr::space && space) -{ - trackers.emplace_back(std::move(space)); -} -size_t xr::htc_body_tracker::count() const -{ - return trackers.size(); + this->trackers.reserve(trackers.size()); + for (auto & [path, space]: trackers) + this->trackers.emplace_back(path, space, s); } void xr::htc_body_tracker::update_active() { - auto roles = get_roles(); - assert(roles.size() >= trackers.size()); - for (int i = 0; i < trackers.size(); i++) - trackers[i].set_active(!roles[i].contains('_')); + for (auto & tracker: trackers) + tracker.update_active(s); } std::array xr::htc_body_tracker::locate_spaces(XrTime time, XrSpace reference) @@ -141,7 +110,7 @@ std::array * Copyright (C) 2025 Sapphire + * Copyright (C) 2025 Patrick Nicolas * * 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 @@ -20,9 +21,7 @@ #pragma once #include "wivrn_packets.h" -#include "xr/htc_exts.h" #include "xr/space.h" -#include #include #include @@ -34,32 +33,24 @@ class session; class vive_xr_tracker { bool is_active = false; - xr::space space; + XrPath path; + xr::space & space; public: - vive_xr_tracker(xr::space && s); - void set_active(bool active); + vive_xr_tracker(XrPath path, xr::space & s, XrSession session); + void update_active(XrSession session); bool get_active() const; XrSpace get_space() const; }; class htc_body_tracker { - instance * inst; XrSession s; std::vector trackers; - PFN_xrEnumeratePathsForInteractionProfileHTC xrEnumeratePathsForInteractionProfileHTC{}; - - std::vector get_roles(); - public: - htc_body_tracker() = default; - htc_body_tracker(instance & inst, session & s); + htc_body_tracker(session & s, std::vector> & trackers); - std::vector get_paths(XrPath user_path = XR_NULL_PATH); - void add(xr::space && space); - size_t count() const; void update_active(); std::array locate_spaces(XrTime time, XrSpace reference); }; diff --git a/client/xr/instance.cpp b/client/xr/instance.cpp index 39ecb1ce..4f95679d 100644 --- a/client/xr/instance.cpp +++ b/client/xr/instance.cpp @@ -19,8 +19,9 @@ #include "instance.h" -#include "xr.h" #include "xr/details/enumerate.h" +#include "xr/htc_exts.h" +#include "xr/to_string.h" #include #include #include @@ -212,6 +213,20 @@ XrPath xr::instance::string_to_path(const std::string & path) return p; } +std::vector xr::instance::enumerate_paths_for_interaction_profile(XrPath interaction_profile, XrPath user_path) +{ + assert(has_extension(XR_HTC_PATH_ENUMERATION_EXTENSION_NAME)); + static auto xrEnumeratePathsForInteractionProfileHTC = get_proc("xrEnumeratePathsForInteractionProfileHTC"); + + XrPathsForInteractionProfileEnumerateInfoHTC profile_info{ + .type = XR_TYPE_UNKNOWN, + .next = nullptr, + .interactionProfile = interaction_profile, + .userPath = user_path, + }; + return xr::details::enumerate(xrEnumeratePathsForInteractionProfileHTC, id, profile_info); +} + bool xr::instance::poll_event(xr::event & buffer) { buffer.header.type = XR_TYPE_EVENT_DATA_BUFFER; diff --git a/client/xr/instance.h b/client/xr/instance.h index e4c28f5f..16929299 100644 --- a/client/xr/instance.h +++ b/client/xr/instance.h @@ -90,6 +90,8 @@ public: XrPath string_to_path(const std::string & path); std::string path_to_string(XrPath path); + std::vector enumerate_paths_for_interaction_profile(XrPath interaction_profile, XrPath user_path = XR_NULL_PATH); + void suggest_bindings(const std::string & interaction_profile, std::vector & bindings); diff --git a/client/xr/pico_body_tracker.cpp b/client/xr/pico_body_tracker.cpp index 3376f661..80b2d2f2 100644 --- a/client/xr/pico_body_tracker.cpp +++ b/client/xr/pico_body_tracker.cpp @@ -45,10 +45,6 @@ xr::pico_body_tracker::pico_body_tracker(instance & inst, session & s) CHECK_XR(xrCreateBodyTrackerBD(s, &create_info, &id)); } -size_t xr::pico_body_tracker::count() const -{ - return joint_whitelist.size(); -} std::optional> xr::pico_body_tracker::locate_spaces(XrTime time, XrSpace reference) { if (!xrLocateBodyJointsBD) diff --git a/client/xr/pico_body_tracker.h b/client/xr/pico_body_tracker.h index fafd0fef..1ca5dbfb 100644 --- a/client/xr/pico_body_tracker.h +++ b/client/xr/pico_body_tracker.h @@ -51,7 +51,6 @@ public: pico_body_tracker() = default; pico_body_tracker(instance & inst, session & s); - size_t count() const; std::optional> locate_spaces(XrTime time, XrSpace reference); }; } // namespace xr