Remove body trackers from application.h

This commit is contained in:
Patrick Nicolas
2025-08-20 22:07:06 +02:00
parent 4b8295b7c7
commit 9f80c1da7c
17 changed files with 293 additions and 259 deletions
+16 -40
View File
@@ -30,8 +30,8 @@
#include "wifi_lock.h" #include "wifi_lock.h"
#include "xr/actionset.h" #include "xr/actionset.h"
#include "xr/check.h" #include "xr/check.h"
#include "xr/htc_exts.h"
#include "xr/meta_body_tracking_fidelity.h" #include "xr/meta_body_tracking_fidelity.h"
#include "xr/xr.h"
#include <algorithm> #include <algorithm>
#include <boost/locale.hpp> #include <boost/locale.hpp>
#include <boost/url/parse.hpp> #include <boost/url/parse.hpp>
@@ -961,8 +961,6 @@ void application::initialize_actions()
{ {
spdlog::debug("Initializing actions"); spdlog::debug("Initializing actions");
auto * htc_body = std::get_if<xr::htc_body_tracker>(&body_tracker);
// Build an action set with all possible input sources // Build an action set with all possible input sources
std::vector<XrActionSet> action_sets; std::vector<XrActionSet> action_sets;
xr_actionset = xr::actionset(xr_instance, "all_actions", "All actions"); 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 // 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)) 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(path_to_string(user_path) + path_to_string(input_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); spaces[size_t(xr::spaces::poke_right)] = xr_session.create_action_space(a);
else if (name == "/user/eyes_ext/input/gaze_ext/pose") else if (name == "/user/eyes_ext/input/gaze_ext/pose")
spaces[size_t(xr::spaces::eye_gaze)] = xr_session.create_action_space(a); spaces[size_t(xr::spaces::eye_gaze)] = xr_session.create_action_space(a);
else if (name.contains("/input/entity_htc/pose") && htc_body) else if (name.contains("/input/entity_htc/pose"))
htc_body->add(xr_session.create_action_space(a)); {
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 // Build an action set for each scene
@@ -1286,28 +1291,6 @@ void application::initialize()
config.emplace(xr_system_id); 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::fb_body_tracker>(xr_instance, xr_session);
}
if (std::holds_alternative<std::monostate>(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::htc_body_tracker>(xr_instance, xr_session);
}
if (std::holds_alternative<std::monostate>(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::pico_body_tracker>(xr_instance, xr_session);
}
vk::CommandPoolCreateInfo cmdpool_create_info; vk::CommandPoolCreateInfo cmdpool_create_info;
cmdpool_create_info.queueFamilyIndex = vk_queue_family_index; cmdpool_create_info.queueFamilyIndex = vk_queue_family_index;
cmdpool_create_info.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer; cmdpool_create_info.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer;
@@ -1842,13 +1825,6 @@ void application::poll_events()
exit_requested = true; exit_requested = true;
} }
break; break;
case XR_TYPE_EVENT_DATA_INTERACTION_PROFILE_CHANGED: {
if (auto * htc_body = std::get_if<xr::htc_body_tracker>(&body_tracker))
{
htc_body->update_active();
}
}
break;
case XR_TYPE_EVENT_DATA_REFERENCE_SPACE_CHANGE_PENDING: case XR_TYPE_EVENT_DATA_REFERENCE_SPACE_CHANGE_PENDING:
break; break;
case XR_TYPE_EVENT_DATA_SESSION_STATE_CHANGED: { case XR_TYPE_EVENT_DATA_SESSION_STATE_CHANGED: {
+3 -8
View File
@@ -123,7 +123,7 @@ class application : public singleton<application>
xr::actionset xr_actionset; xr::actionset xr_actionset;
std::vector<std::tuple<XrAction, XrActionType, std::string>> actions; std::vector<std::tuple<XrAction, XrActionType, std::string>> actions;
std::variant<std::monostate, xr::fb_body_tracker, xr::htc_body_tracker, xr::pico_body_tracker> body_tracker; std::vector<std::pair<XrPath, xr::space>> generic_trackers;
bool eye_gaze_supported = false; bool eye_gaze_supported = false;
@@ -423,11 +423,6 @@ public:
return instance().last_scene_cpu_time; return instance().last_scene_cpu_time;
} }
static bool get_body_tracking_supported()
{
return !std::holds_alternative<std::monostate>(instance().body_tracker);
}
static bool get_eye_gaze_supported() static bool get_eye_gaze_supported()
{ {
return instance().eye_gaze_supported; return instance().eye_gaze_supported;
@@ -438,9 +433,9 @@ public:
return instance().openxr_post_processing_supported; 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<std::string> & get_xr_extensions() static const std::vector<std::string> & get_xr_extensions()
+3 -24
View File
@@ -20,6 +20,7 @@
#include "configuration.h" #include "configuration.h"
#include "application.h" #include "application.h"
#include "xr/body_tracker.h"
#include "xr/face_tracker.h" #include "xr/face_tracker.h"
#include <fstream> #include <fstream>
#include <magic_enum.hpp> #include <magic_enum.hpp>
@@ -111,30 +112,8 @@ bool configuration::check_feature(feature f) const
return false; return false;
break; break;
case feature::body_tracking: case feature::body_tracking:
switch (guess_model()) if (xr::body_tracker_supported(instance, system) == xr::body_tracker_type::none)
{ return false;
case model::meta_quest_3:
case model::meta_quest_3s:
if (not std::holds_alternative<xr::fb_body_tracker>(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<xr::htc_body_tracker>(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<xr::pico_body_tracker>(application::get_body_tracker()))
return false;
break;
default:
break;
}
break; break;
} }
} }
+8 -11
View File
@@ -34,6 +34,7 @@
#include "utils/overloaded.h" #include "utils/overloaded.h"
#include "utils/ranges.h" #include "utils/ranges.h"
#include "version.h" #include "version.h"
#include "xr/body_tracker.h"
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include <chrono> #include <chrono>
@@ -925,8 +926,9 @@ void scenes::lobby::gui_settings()
imgui_ctx->vibrate_on_hover(); 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); bool enabled = config.check_feature(feature::body_tracking);
if (ImGui::Checkbox(_S("Enable body tracking"), &enabled)) if (ImGui::Checkbox(_S("Enable body tracking"), &enabled))
{ {
@@ -941,19 +943,14 @@ void scenes::lobby::gui_settings()
} }
else else
{ {
std::visit(utils::overloaded{ if (body_tracker == xr::body_tracker_type::fb)
[](auto &) {}, 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"));
[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());
} }
} }
imgui_ctx->vibrate_on_hover(); imgui_ctx->vibrate_on_hover();
} }
if (std::holds_alternative<xr::fb_body_tracker>(application::get_body_tracker())) if (body_tracker == xr::body_tracker_type::fb)
{ {
ImGui::BeginDisabled(not config.check_feature(feature::body_tracking)); ImGui::BeginDisabled(not config.check_feature(feature::body_tracking));
ImGui::Indent(); ImGui::Indent();
@@ -1313,7 +1310,7 @@ void scenes::lobby::gui_first_run()
item{ item{
.f = feature::body_tracking, .f = feature::body_tracking,
.text = _S("Enable 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({ items.push_back({
.f = feature::body_tracking, .f = feature::body_tracking,
+15 -13
View File
@@ -17,12 +17,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include "constants.h" #include "constants.h"
#include "utils/overloaded.h" #include "xr/body_tracker.h"
#include "xr/face_tracker.h" #include "xr/face_tracker.h"
#include "xr/fb_body_tracker.h"
#include "xr/fb_face_tracker2.h" #include "xr/fb_face_tracker2.h"
#include "xr/htc_body_tracker.h"
#include "xr/pico_body_tracker.h"
#include "xr/space.h" #include "xr/space.h"
#include <glm/gtc/matrix_access.hpp> #include <glm/gtc/matrix_access.hpp>
#include <glm/gtc/quaternion.hpp> #include <glm/gtc/quaternion.hpp>
@@ -275,15 +272,20 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
info.num_generic_trackers = 0; info.num_generic_trackers = 0;
if (config.check_feature(feature::body_tracking)) if (config.check_feature(feature::body_tracking))
{ {
info.num_generic_trackers = std::visit(utils::overloaded{ switch (xr::body_tracker_supported(self->instance, self->system))
[&](std::monostate &) { {
return size_t(0); case xr::body_tracker_type::none:
}, break;
[&](auto & b) { case xr::body_tracker_type::fb:
return b.count(); 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:
application::get_body_tracker()); 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); info.palm_pose = application::space(xr::spaces::palm_left) or application::space(xr::spaces::palm_right);
+1
View File
@@ -86,6 +86,7 @@ private:
std::thread network_thread; std::thread network_thread;
thread_safe<to_headset::tracking_control> tracking_control{}; thread_safe<to_headset::tracking_control> tracking_control{};
std::array<std::atomic<interaction_profile>, 2> interaction_profiles; // left and right hand std::array<std::atomic<interaction_profile>, 2> interaction_profiles; // left and right hand
std::atomic<bool> interaction_profile_changed = false;
std::atomic<bool> recenter_requested = false; std::atomic<bool> recenter_requested = false;
std::atomic<XrDuration> display_time_phase = 0; std::atomic<XrDuration> display_time_phase = 0;
std::atomic<XrDuration> display_time_period = 0; std::atomic<XrDuration> display_time_period = 0;
+39 -30
View File
@@ -21,6 +21,7 @@
#include "stream.h" #include "stream.h"
#include "utils/overloaded.h" #include "utils/overloaded.h"
#include "wivrn_packets.h" #include "wivrn_packets.h"
#include "xr/body_tracker.h"
#include "xr/face_tracker.h" #include "xr/face_tracker.h"
#include "xr/fb_body_tracker.h" #include "xr/fb_body_tracker.h"
#include <magic_enum.hpp> #include <magic_enum.hpp>
@@ -393,18 +394,7 @@ void scenes::stream::tracking()
xr::face_tracker face_tracker; xr::face_tracker face_tracker;
const bool body_tracking = config.check_feature(feature::body_tracking); const bool body_tracking = config.check_feature(feature::body_tracking);
auto & body_tracker = application::get_body_tracker(); xr::body_tracker body_tracker;
if (body_tracking)
{
if (auto * body_fb = std::get_if<xr::fb_body_tracker>(&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);
}
}
locate_spaces_functor locate_spaces{instance, world_space}; locate_spaces_functor locate_spaces{instance, world_space};
@@ -429,6 +419,7 @@ void scenes::stream::tracking()
int samples = 0; int samples = 0;
auto control = *tracking_control.lock(); auto control = *tracking_control.lock();
bool interaction_profile_changed = this->interaction_profile_changed.exchange(false);
if (control.enabled[size_t(tid::left_hand)]) if (control.enabled[size_t(tid::left_hand)])
{ {
@@ -454,6 +445,24 @@ void scenes::stream::tracking()
else else
face_tracker.emplace<std::monostate>(); face_tracker.emplace<std::monostate>();
if (body_tracking and control.enabled[size_t(tid::generic_tracker)])
{
if (std::holds_alternative<std::monostate>(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<std::monostate>();
if (interaction_profile_changed)
if (auto htc = std::get_if<xr::htc_body_tracker>(&body_tracker))
htc->update_active();
XrDuration prediction = std::clamp<XrDuration>(control.max_offset.count(), 0, 80'000'000); 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); 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; 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); locate_spaces.resolve(session, t0 + Δt, packet.device_poses);
if (body_tracking) std::visit(utils::overloaded{
std::visit(utils::overloaded{ [](std::monostate &) {},
[](std::monostate &) {}, [&](auto & b) {
[&](auto & b) { if (t0 >= last_body_sample + period and
if (t0 >= last_body_sample + period and (Δt == 0 or Δt >= prediction - 2 * period))
(Δt == 0 or Δt >= prediction - 2 * period)) {
last_body_sample = t0;
if (control.enabled[size_t(tid::generic_tracker)])
{ {
last_body_sample = t0; body.push_back(from_headset::body_tracking{
if (control.enabled[size_t(tid::generic_tracker)]) .production_timestamp = t0,
{ .timestamp = t0 + Δt,
body.push_back(from_headset::body_tracking{ .poses = b.locate_spaces(t0 + Δt, world_space),
.production_timestamp = t0, });
.timestamp = t0 + Δt,
.poses = b.locate_spaces(t0 + Δt, world_space),
});
}
} }
}, }
}, },
body_tracker); },
body_tracker);
std::visit(utils::overloaded{ std::visit(utils::overloaded{
[](std::monostate &) {}, [](std::monostate &) {},
@@ -672,6 +680,7 @@ static device_id derived_from(device_id target)
void scenes::stream::on_interaction_profile_changed(const XrEventDataInteractionProfileChanged &) void scenes::stream::on_interaction_profile_changed(const XrEventDataInteractionProfileChanged &)
{ {
interaction_profile_changed = true;
std::array path = { std::array path = {
"/user/hand/left", "/user/hand/left",
"/user/hand/right", "/user/hand/right",
+80
View File
@@ -0,0 +1,80 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
*
* 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 <https://www.gnu.org/licenses/>.
*/
#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<std::pair<XrPath, xr::space>> & 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<xr::fb_body_tracker>(),
instance,
session,
full_body,
hips);
}
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))
{
auto bd_body_properties = system.bd_body_tracking_properties();
if (bd_body_properties.supportsBodyTracking)
return xr::body_tracker(std::in_place_type_t<xr::pico_body_tracker>(),
instance,
session);
}
return std::monostate();
}
+49
View File
@@ -0,0 +1,49 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
*
* 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 <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "fb_body_tracker.h"
#include "htc_body_tracker.h"
#include "pico_body_tracker.h"
#include <utility>
#include <variant>
#include <vector>
namespace xr
{
class instance;
class system;
enum class body_tracker_type
{
none,
fb,
htc,
pico,
};
using body_tracker = std::variant<std::monostate, xr::fb_body_tracker, xr::htc_body_tracker, xr::pico_body_tracker>;
body_tracker_type body_tracker_supported(xr::instance &, xr::system &);
body_tracker make_body_tracker(xr::instance &, xr::system &, xr::session &, std::vector<std::pair<XrPath, xr::space>> & generic_trackers, bool full_body, bool hips);
} // namespace xr
+23 -41
View File
@@ -17,15 +17,23 @@
*/ */
#include "fb_body_tracker.h" #include "fb_body_tracker.h"
#include "application.h"
#include "spdlog/spdlog.h" #include "spdlog/spdlog.h"
#include "xr/instance.h"
#include "xr/meta_body_tracking_fidelity.h" #include "xr/meta_body_tracking_fidelity.h"
#include "xr/xr.h" #include "xr/session.h"
#include "xr/to_string.h"
#include <ranges> #include <ranges>
#include <openxr/openxr.h> #include <openxr/openxr.h>
static_assert(xr::fb_body_tracker::joint_whitelist.size() <= wivrn::from_headset::body_tracking::max_tracked_poses); 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<XrFullBodyJointMETA> xr::fb_body_tracker::get_whitelisted_joints(bool full_body, bool hip) std::vector<XrFullBodyJointMETA> 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) { auto whitelisted_joints = std::ranges::filter_view(xr::fb_body_tracker::joint_whitelist, [=](auto joint) {
@@ -39,59 +47,33 @@ std::vector<XrFullBodyJointMETA> xr::fb_body_tracker::get_whitelisted_joints(boo
return {whitelisted_joints.begin(), whitelisted_joints.end()}; return {whitelisted_joints.begin(), whitelisted_joints.end()};
} }
xr::fb_body_tracker::fb_body_tracker(instance & inst, session & s) : xr::fb_body_tracker::fb_body_tracker(instance & inst, session & s, bool full_body, bool hip) :
s(s) xrRequestBodyTrackingFidelityMETA(inst.get_proc<PFN_xrRequestBodyTrackingFidelityMETA>("xrRequestBodyTrackingFidelityMETA")),
xrLocateBodyJointsFB(inst.get_proc<PFN_xrLocateBodyJointsFB>("xrLocateBodyJointsFB")),
full_body(full_body),
hip(hip)
{ {
xrCreateBodyTrackerFB = inst.get_proc<PFN_xrCreateBodyTrackerFB>("xrCreateBodyTrackerFB"); auto xrCreateBodyTrackerFB = inst.get_proc<PFN_xrCreateBodyTrackerFB>("xrCreateBodyTrackerFB");
xrRequestBodyTrackingFidelityMETA = inst.get_proc<PFN_xrRequestBodyTrackingFidelityMETA>("xrRequestBodyTrackingFidelityMETA");
xrLocateBodyJointsFB = inst.get_proc<PFN_xrLocateBodyJointsFB>("xrLocateBodyJointsFB");
xrDestroyBodyTrackerFB = inst.get_proc<PFN_xrDestroyBodyTrackerFB>("xrDestroyBodyTrackerFB"); xrDestroyBodyTrackerFB = inst.get_proc<PFN_xrDestroyBodyTrackerFB>("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{ XrBodyTrackerCreateInfoFB create_info{
.type = XR_TYPE_BODY_TRACKER_CREATE_INFO_FB, .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. // 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); 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<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses>> xr::fb_body_tracker::locate_spaces(XrTime time, XrSpace reference) std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses>> xr::fb_body_tracker::locate_spaces(XrTime time, XrSpace reference)
{ {
if (!handle) if (!id)
return std::nullopt; return std::nullopt;
assert(xrLocateBodyJointsFB); assert(xrLocateBodyJointsFB);
@@ -111,7 +93,7 @@ std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_h
.jointLocations = joints.data(), .jointLocations = joints.data(),
}; };
if (auto res = xrLocateBodyJointsFB(handle, &locate_info, &joint_locations); !XR_SUCCEEDED(res)) if (auto res = xrLocateBodyJointsFB(id, &locate_info, &joint_locations); !XR_SUCCEEDED(res))
{ {
spdlog::warn("xrLocateBodyJointsFB returned {}", xr::to_string(res)); spdlog::warn("xrLocateBodyJointsFB returned {}", xr::to_string(res));
return std::nullopt; return std::nullopt;
+5 -13
View File
@@ -20,6 +20,7 @@
#include "wivrn_packets.h" #include "wivrn_packets.h"
#include "utils/handle.h"
#include "xr/meta_body_tracking_fidelity.h" #include "xr/meta_body_tracking_fidelity.h"
#include <array> #include <array>
#include <optional> #include <optional>
@@ -30,15 +31,12 @@ namespace xr
class instance; class instance;
class session; class session;
class fb_body_tracker XrResult destroy_fb_body_tracker(XrBodyTrackerFB);
{
XrSession s;
XrBodyTrackerFB handle{};
PFN_xrCreateBodyTrackerFB xrCreateBodyTrackerFB{}; class fb_body_tracker : public utils::handle<XrBodyTrackerFB, destroy_fb_body_tracker>
{
PFN_xrRequestBodyTrackingFidelityMETA xrRequestBodyTrackingFidelityMETA{}; PFN_xrRequestBodyTrackingFidelityMETA xrRequestBodyTrackingFidelityMETA{};
PFN_xrLocateBodyJointsFB xrLocateBodyJointsFB{}; PFN_xrLocateBodyJointsFB xrLocateBodyJointsFB{};
PFN_xrDestroyBodyTrackerFB xrDestroyBodyTrackerFB{};
bool full_body{}; bool full_body{};
bool hip{}; bool hip{};
@@ -59,13 +57,7 @@ public:
}; };
static std::vector<XrFullBodyJointMETA> get_whitelisted_joints(bool full_body, bool hip); static std::vector<XrFullBodyJointMETA> get_whitelisted_joints(bool full_body, bool hip);
fb_body_tracker() = default; fb_body_tracker(instance & inst, session & s, bool full_body, bool hip);
fb_body_tracker(instance & inst, session & s);
~fb_body_tracker();
void start(bool lower_body, bool hip);
void stop();
size_t count() const;
std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses>> locate_spaces(XrTime time, XrSpace reference); std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses>> locate_spaces(XrTime time, XrSpace reference);
}; };
+27 -58
View File
@@ -2,6 +2,7 @@
* WiVRn VR streaming * WiVRn VR streaming
* Copyright (C) 2025 Awzri <awzri@awzricat.com> * Copyright (C) 2025 Awzri <awzri@awzricat.com>
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com> * Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -19,8 +20,7 @@
#include "htc_body_tracker.h" #include "htc_body_tracker.h"
#include "xr/details/enumerate.h" #include "xr/details/enumerate.h"
#include "xr/htc_exts.h" #include "xr/session.h"
#include "xr/xr.h"
#include <openxr/openxr.h> #include <openxr/openxr.h>
// Note: This utilizes extensions not present in the OpenXR spec! // 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.Tracker.ViveXRTracker.html
// https://hub.vive.com/apidoc/api/VIVE.OpenXR.VivePathEnumerationHelper.xrEnumeratePathsForInteractionProfileHTCDelegate.html // https://hub.vive.com/apidoc/api/VIVE.OpenXR.VivePathEnumerationHelper.xrEnumeratePathsForInteractionProfileHTCDelegate.html
xr::vive_xr_tracker::vive_xr_tracker(xr::space && space) : xr::vive_xr_tracker::vive_xr_tracker(XrPath path, xr::space & space, XrSession session) :
space(std::move(space)) {} path(path),
void xr::vive_xr_tracker::set_active(bool active) 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<char>(xrGetInputSourceLocalizedName, session, &get_info);
is_active = not role.contains("_");
} }
bool xr::vive_xr_tracker::get_active() const 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; return res;
} }
std::vector<std::string> xr::htc_body_tracker::get_roles() xr::htc_body_tracker::htc_body_tracker(session & s, std::vector<std::pair<XrPath, xr::space>> & trackers) :
{
auto paths = get_paths();
std::vector<std::string> 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<char>(xrGetInputSourceLocalizedName, s, &get_info));
}
return roles;
}
xr::htc_body_tracker::htc_body_tracker(instance & inst, session & s) :
inst(&inst),
s(s) s(s)
{ {
xrEnumeratePathsForInteractionProfileHTC = inst.get_proc<PFN_xrEnumeratePathsForInteractionProfileHTC>("xrEnumeratePathsForInteractionProfileHTC"); this->trackers.reserve(trackers.size());
} for (auto & [path, space]: trackers)
this->trackers.emplace_back(path, space, s);
std::vector<XrPath> 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<XrPath>(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();
} }
void xr::htc_body_tracker::update_active() void xr::htc_body_tracker::update_active()
{ {
auto roles = get_roles(); for (auto & tracker: trackers)
assert(roles.size() >= trackers.size()); tracker.update_active(s);
for (int i = 0; i < trackers.size(); i++)
trackers[i].set_active(!roles[i].contains('_'));
} }
std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses> xr::htc_body_tracker::locate_spaces(XrTime time, XrSpace reference) std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses> xr::htc_body_tracker::locate_spaces(XrTime time, XrSpace reference)
@@ -141,7 +110,7 @@ std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_t
for (int i = 0; i < trackers.size(); i++) for (int i = 0; i < trackers.size(); i++)
{ {
auto & tracker = trackers.at(i); auto & tracker = trackers[i];
wivrn::from_headset::body_tracking::pose pose{ wivrn::from_headset::body_tracking::pose pose{
.pose = {}, .pose = {},
.flags = 0, .flags = 0,
+6 -15
View File
@@ -2,6 +2,7 @@
* WiVRn VR streaming * WiVRn VR streaming
* Copyright (C) 2025 Awzri <awzri@awzricat.com> * Copyright (C) 2025 Awzri <awzri@awzricat.com>
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com> * Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -20,9 +21,7 @@
#pragma once #pragma once
#include "wivrn_packets.h" #include "wivrn_packets.h"
#include "xr/htc_exts.h"
#include "xr/space.h" #include "xr/space.h"
#include <string>
#include <vector> #include <vector>
#include <openxr/openxr.h> #include <openxr/openxr.h>
@@ -34,32 +33,24 @@ class session;
class vive_xr_tracker class vive_xr_tracker
{ {
bool is_active = false; bool is_active = false;
xr::space space; XrPath path;
xr::space & space;
public: public:
vive_xr_tracker(xr::space && s); vive_xr_tracker(XrPath path, xr::space & s, XrSession session);
void set_active(bool active); void update_active(XrSession session);
bool get_active() const; bool get_active() const;
XrSpace get_space() const; XrSpace get_space() const;
}; };
class htc_body_tracker class htc_body_tracker
{ {
instance * inst;
XrSession s; XrSession s;
std::vector<vive_xr_tracker> trackers; std::vector<vive_xr_tracker> trackers;
PFN_xrEnumeratePathsForInteractionProfileHTC xrEnumeratePathsForInteractionProfileHTC{};
std::vector<std::string> get_roles();
public: public:
htc_body_tracker() = default; htc_body_tracker(session & s, std::vector<std::pair<XrPath, xr::space>> & trackers);
htc_body_tracker(instance & inst, session & s);
std::vector<XrPath> get_paths(XrPath user_path = XR_NULL_PATH);
void add(xr::space && space);
size_t count() const;
void update_active(); void update_active();
std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses> locate_spaces(XrTime time, XrSpace reference); std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses> locate_spaces(XrTime time, XrSpace reference);
}; };
+16 -1
View File
@@ -19,8 +19,9 @@
#include "instance.h" #include "instance.h"
#include "xr.h"
#include "xr/details/enumerate.h" #include "xr/details/enumerate.h"
#include "xr/htc_exts.h"
#include "xr/to_string.h"
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
@@ -212,6 +213,20 @@ XrPath xr::instance::string_to_path(const std::string & path)
return p; return p;
} }
std::vector<XrPath> 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<PFN_xrEnumeratePathsForInteractionProfileHTC>("xrEnumeratePathsForInteractionProfileHTC");
XrPathsForInteractionProfileEnumerateInfoHTC profile_info{
.type = XR_TYPE_UNKNOWN,
.next = nullptr,
.interactionProfile = interaction_profile,
.userPath = user_path,
};
return xr::details::enumerate<XrPath>(xrEnumeratePathsForInteractionProfileHTC, id, profile_info);
}
bool xr::instance::poll_event(xr::event & buffer) bool xr::instance::poll_event(xr::event & buffer)
{ {
buffer.header.type = XR_TYPE_EVENT_DATA_BUFFER; buffer.header.type = XR_TYPE_EVENT_DATA_BUFFER;
+2
View File
@@ -90,6 +90,8 @@ public:
XrPath string_to_path(const std::string & path); XrPath string_to_path(const std::string & path);
std::string path_to_string(XrPath path); std::string path_to_string(XrPath path);
std::vector<XrPath> enumerate_paths_for_interaction_profile(XrPath interaction_profile, XrPath user_path = XR_NULL_PATH);
void suggest_bindings(const std::string & interaction_profile, void suggest_bindings(const std::string & interaction_profile,
std::vector<XrActionSuggestedBinding> & bindings); std::vector<XrActionSuggestedBinding> & bindings);
-4
View File
@@ -45,10 +45,6 @@ xr::pico_body_tracker::pico_body_tracker(instance & inst, session & s)
CHECK_XR(xrCreateBodyTrackerBD(s, &create_info, &id)); CHECK_XR(xrCreateBodyTrackerBD(s, &create_info, &id));
} }
size_t xr::pico_body_tracker::count() const
{
return joint_whitelist.size();
}
std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses>> xr::pico_body_tracker::locate_spaces(XrTime time, XrSpace reference) std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses>> xr::pico_body_tracker::locate_spaces(XrTime time, XrSpace reference)
{ {
if (!xrLocateBodyJointsBD) if (!xrLocateBodyJointsBD)
-1
View File
@@ -51,7 +51,6 @@ public:
pico_body_tracker() = default; pico_body_tracker() = default;
pico_body_tracker(instance & inst, session & s); pico_body_tracker(instance & inst, session & s);
size_t count() const;
std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses>> locate_spaces(XrTime time, XrSpace reference); std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses>> locate_spaces(XrTime time, XrSpace reference);
}; };
} // namespace xr } // namespace xr