diff --git a/.gitignore b/.gitignore
index b2fae216..a16fdcd7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,12 +1,15 @@
*~
.cxx/
.cache/
+.direnv/
.gradle/
_deps/
.idea/
+.vscode/
build/
build-*/
+**/result
*.so
a.out
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 9df29233..6bb9d6b9 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -39,12 +39,14 @@
+
+
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d1319d7f..0fdcbe2e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -223,9 +223,9 @@ if (WIVRN_BUILD_CLIENT AND NOT ANDROID)
find_package(Fontconfig REQUIRED)
if (WIVRN_USE_SYSTEM_OPENXR STREQUAL "AUTO")
- find_package(OpenXR 1.0.26)
+ find_package(OpenXR 1.1.48)
elseif(WIVRN_USE_SYSTEM_OPENXR STREQUAL "ON")
- find_package(OpenXR 1.0.26 REQUIRED)
+ find_package(OpenXR 1.1.48 REQUIRED)
endif()
endif()
@@ -264,8 +264,8 @@ FetchContent_Declare(fastgltf EXCLUDE_FROM_ALL SYSTEM URL https://github.co
URL_HASH SHA256=44bcb025dd5cd480236a3bc7a3f8c9a708a801ed773b7859677440d22e0e1e7c)
FetchContent_Declare(glm EXCLUDE_FROM_ALL SYSTEM URL https://github.com/g-truc/glm/archive/refs/tags/1.0.1.tar.gz
URL_HASH SHA256=9f3174561fd26904b23f0db5e560971cbf9b3cbda0b280f04d5c379d03bf234c)
-FetchContent_Declare(openxr_loader EXCLUDE_FROM_ALL SYSTEM URL https://github.com/KhronosGroup/OpenXR-SDK/archive/refs/tags/release-1.0.34.tar.gz
- URL_HASH SHA256=5fa2fac1b442a31e267ea522799a247e3aff6e6f5a418b1e31c337b8ca835b69)
+FetchContent_Declare(openxr_loader EXCLUDE_FROM_ALL SYSTEM URL https://github.com/KhronosGroup/OpenXR-SDK/archive/refs/tags/release-1.1.48.tar.gz
+ URL_HASH SHA256=c9372992dcdfac643e28796e41d4dbd36c4cdf0388d01fa89245628edae9d411)
FetchContent_Declare(spdlog EXCLUDE_FROM_ALL SYSTEM URL https://github.com/gabime/spdlog/archive/refs/tags/v1.14.1.tar.gz
URL_HASH SHA256=1586508029a7d0670dfcb2d97575dcdc242d3868a259742b69f100801ab4e16b)
FetchContent_Declare(stb EXCLUDE_FROM_ALL SYSTEM URL https://github.com/nothings/stb/archive/013ac3beddff3dbffafd5177e7972067cd2b5083.zip
diff --git a/client/application.cpp b/client/application.cpp
index 404d4c22..ebcca4c2 100644
--- a/client/application.cpp
+++ b/client/application.cpp
@@ -31,7 +31,7 @@
#include "wifi_lock.h"
#include "xr/actionset.h"
#include "xr/check.h"
-#include "xr/pico_eye_types.h"
+#include "xr/meta_body_tracking_fidelity.h"
#include "xr/xr.h"
#include
#include
@@ -1041,6 +1041,10 @@ void application::initialize()
opt_extensions.push_back(XR_HTC_PASSTHROUGH_EXTENSION_NAME);
opt_extensions.push_back(XR_HTC_FACIAL_TRACKING_EXTENSION_NAME);
opt_extensions.push_back(XR_FB_FACE_TRACKING2_EXTENSION_NAME);
+ opt_extensions.push_back(XR_FB_BODY_TRACKING_EXTENSION_NAME);
+ opt_extensions.push_back(XR_META_BODY_TRACKING_FULL_BODY_EXTENSION_NAME);
+ opt_extensions.push_back(XR_META_BODY_TRACKING_FIDELITY_EXTENSION_NAME);
+ opt_extensions.push_back(XR_BD_BODY_TRACKING_EXTENSION_NAME);
opt_extensions.push_back(XR_EXT_PALM_POSE_EXTENSION_NAME);
opt_extensions.push_back(XR_KHR_COMPOSITION_LAYER_DEPTH_EXTENSION_NAME);
opt_extensions.push_back(XR_FB_COMPOSITION_LAYER_DEPTH_TEST_EXTENSION_NAME);
@@ -1141,6 +1145,20 @@ void application::initialize()
htc_face_tracking_lip_supported = htc_face_properties.supportLipFacialTracking;
}
+ 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);
+ fb_body_tracking_supported = fb_body_properties.supportsBodyTracking;
+ }
+
+ if (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);
+ pico_body_tracking_supported = bd_body_properties.supportsBodyTracking;
+ }
+
if (utils::contains(xr_extensions, XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME))
{
spdlog::info(" OpenXR post-processing extension support: true");
@@ -1205,6 +1223,18 @@ void application::initialize()
pico_face_tracker = xr_session.create_pico_face_tracker();
}
+ if (fb_body_tracking_supported)
+ {
+ fb_body_tracker = xr_session.create_fb_body_tracker();
+ // HACK: always have an active body tracker so the quest runtime doesn't blow up (crash in random functions, controllers not working)
+ fb_body_tracker.start(false, false);
+ }
+
+ if (pico_body_tracking_supported)
+ {
+ pico_body_tracker = xr_session.create_pico_body_tracker();
+ }
+
vk::CommandPoolCreateInfo cmdpool_create_info;
cmdpool_create_info.queueFamilyIndex = vk_queue_family_index;
cmdpool_create_info.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer;
diff --git a/client/application.h b/client/application.h
index 67758507..b429cf50 100644
--- a/client/application.h
+++ b/client/application.h
@@ -21,6 +21,7 @@
#include "configuration.h"
#include "wifi_lock.h"
+#include "xr/fb_body_tracker.h"
#include "xr/fb_face_tracker2.h"
#include "xr/hand_tracker.h"
#include "xr/htc_face_tracker.h"
@@ -137,6 +138,11 @@ class application : public singleton
bool pico_face_tracking_supported = false;
xr::pico_face_tracker pico_face_tracker;
+ bool fb_body_tracking_supported = false;
+ xr::fb_body_tracker fb_body_tracker;
+ bool pico_body_tracking_supported = false;
+ xr::pico_body_tracker pico_body_tracker;
+
bool eye_gaze_supported = false;
bool openxr_post_processing_supported = false;
@@ -445,6 +451,16 @@ public:
return instance().pico_face_tracking_supported;
}
+ static bool get_fb_body_tracking_supported()
+ {
+ return instance().fb_body_tracking_supported;
+ }
+
+ static bool get_pico_body_tracking_supported()
+ {
+ return instance().pico_body_tracking_supported;
+ }
+
static bool get_eye_gaze_supported()
{
return instance().eye_gaze_supported;
@@ -485,6 +501,16 @@ public:
return instance().pico_face_tracker;
}
+ static xr::fb_body_tracker & get_fb_body_tracker()
+ {
+ return instance().fb_body_tracker;
+ }
+
+ static xr::pico_body_tracker & get_pico_body_tracker()
+ {
+ return instance().pico_body_tracker;
+ }
+
static const std::vector & get_xr_extensions()
{
return instance().xr_extensions;
diff --git a/client/configuration.cpp b/client/configuration.cpp
index cf52494d..ca8685e6 100644
--- a/client/configuration.cpp
+++ b/client/configuration.cpp
@@ -121,6 +121,27 @@ bool configuration::check_feature(feature f) const
return false;
break;
}
+ break;
+ case feature::body_tracking:
+ switch (guess_model())
+ {
+ case model::meta_quest_3:
+ case model::meta_quest_3s:
+ if (not application::get_fb_body_tracking_supported())
+ 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 application::get_pico_body_tracking_supported())
+ return false;
+ break;
+ default:
+ break;
+ }
+ break;
}
}
#ifdef __ANDROID__
@@ -203,6 +224,11 @@ configuration::configuration(xr::system & system)
if (auto val = root["mic_unprocessed_audio"]; val.is_bool())
mic_unprocessed_audio = val.get_bool();
+ if (auto val = root["fb_lower_body"]; val.is_bool())
+ fb_lower_body = val.get_bool();
+ if (auto val = root["fb_hip"]; val.is_bool())
+ fb_hip = val.get_bool();
+
if (auto val = root["virtual_keyboard_layout"]; val.is_string())
virtual_keyboard_layout = val.get_string().value();
@@ -325,6 +351,8 @@ void configuration::save()
write_openxr_post_processing(json, openxr_post_processing);
json << ",\"passthrough_enabled\":" << std::boolalpha << passthrough_enabled;
json << ",\"mic_unprocessed_audio\":" << std::boolalpha << mic_unprocessed_audio;
+ json << ",\"fb_lower_body\":" << std::boolalpha << fb_lower_body;
+ json << ",\"fb_hip\":" << std::boolalpha << fb_hip;
for (auto & [key, value]: features)
json << "," << key << ":" << std::boolalpha << value;
json << ",\"virtual_keyboard_layout\":" << json_string(virtual_keyboard_layout);
diff --git a/client/configuration.h b/client/configuration.h
index e261a87c..cdfdd8f5 100644
--- a/client/configuration.h
+++ b/client/configuration.h
@@ -54,6 +54,9 @@ public:
bool passthrough_enabled = false;
bool mic_unprocessed_audio = false;
+ bool fb_lower_body = false;
+ bool fb_hip = true;
+
// Snapdragon Game Super Resolution
struct sgsr_settings
{
diff --git a/client/hardware.cpp b/client/hardware.cpp
index 0e7cccb0..c12960de 100644
--- a/client/hardware.cpp
+++ b/client/hardware.cpp
@@ -251,6 +251,15 @@ const char * permission_name(feature f)
return nullptr;
}
__builtin_unreachable();
+ case feature::body_tracking:
+ switch (guess_model())
+ {
+ case model::meta_quest_3:
+ case model::meta_quest_3s:
+ return "com.oculus.permission.BODY_TRACKING";
+ default:
+ return nullptr;
+ }
}
__builtin_unreachable();
}
diff --git a/client/hardware.h b/client/hardware.h
index 608aa644..29d73cbd 100644
--- a/client/hardware.h
+++ b/client/hardware.h
@@ -50,6 +50,7 @@ enum class feature
hand_tracking,
eye_gaze,
face_tracking,
+ body_tracking,
};
model guess_model();
diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp
index 274709aa..740c08fa 100644
--- a/client/scenes/lobby_gui.cpp
+++ b/client/scenes/lobby_gui.cpp
@@ -740,6 +740,58 @@ void scenes::lobby::gui_settings()
vibrate_on_hover();
}
+ {
+ ImGui::BeginDisabled(not(application::get_fb_body_tracking_supported() or application::get_pico_body_tracking_supported()));
+ bool enabled = config.check_feature(feature::body_tracking);
+ if (ImGui::Checkbox(_S("Enable body tracking"), &enabled))
+ {
+ config.set_feature(feature::body_tracking, enabled);
+ config.save();
+ }
+ ImGui::EndDisabled();
+ if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
+ {
+ if (ImGui::GetItemFlags() & ImGuiItemFlags_Disabled)
+ {
+ tooltip(_("This feature is not supported by your headset"));
+ }
+ else
+ {
+ if (application::get_fb_body_tracking_supported())
+ 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"));
+ else if (application::get_pico_body_tracking_supported())
+ tooltip(_("Uses the Pico Motion Trackers to track body joint positions"));
+ }
+ }
+
+ vibrate_on_hover();
+ }
+ if (application::get_fb_body_tracking_supported())
+ {
+ 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();
+ }
+ vibrate_on_hover();
+ if (ImGui::IsItemHovered())
+ tooltip(_("Estimate lower body joint positions using Generative Legs\nRequires 'Hand and body tracking' to be enabled in the Quest movement tracking settings"));
+
+ ImGui::BeginDisabled(not config.fb_lower_body);
+ if (ImGui::Checkbox(_S("Enable hip tracking"), &config.fb_hip))
+ {
+ config.save();
+ }
+ vibrate_on_hover();
+ if (ImGui::IsItemHovered())
+ tooltip(_("Only takes affect with lower body tracking enabled\nMay be desired when using another source of hip tracking"));
+ ImGui::EndDisabled();
+
+ ImGui::Unindent();
+ ImGui::EndDisabled();
+ }
+
ImGui::BeginDisabled(passthrough_supported == xr::system::passthrough_type::no_passthrough);
if (ImGui::Checkbox(_S("Enable video passthrough in lobby"), &config.passthrough_enabled))
{
@@ -1433,6 +1485,16 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
});
}
+ if (application::get_fb_body_tracking_supported() or application::get_pico_body_tracking_supported())
+ {
+ items.push_back({
+ .f = feature::body_tracking,
+ .tooltip_enabled = _("Body tracking is enabled"),
+ .tooltip_disabled = _("Body tracking is disabled"),
+ .icon_enabled = ICON_FA_PERSON,
+ });
+ }
+
// Get statuses
for (auto & i: items)
{
@@ -1459,7 +1521,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
if (&i != &items.front())
ImGui::SameLine();
auto pos = ImGui::GetCursorPos();
- if (ImGui::Button(i.enabled ? i.icon_enabled : i.icon_disabled))
+ if (ImGui::Button(fmt::format("{}##{}", i.enabled ? i.icon_enabled : i.icon_disabled, i.icon_enabled).c_str()))
{
// button doesn't alter the bool
config.set_feature(i.f, not i.enabled);
diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp
index 010cc84a..1f64c129 100644
--- a/client/scenes/stream.cpp
+++ b/client/scenes/stream.cpp
@@ -17,6 +17,7 @@
* along with this program. If not, see .
*/
#include "utils/overloaded.h"
+#include "xr/fb_body_tracker.h"
#define GLM_FORCE_RADIANS
#include "stream.h"
@@ -224,6 +225,24 @@ std::shared_ptr scenes::stream::create(std::unique_ptrsystem.passthrough_supported() != xr::system::passthrough_type::no_passthrough;
info.system_name = std::string(self->system.properties().systemName);
diff --git a/client/scenes/stream_tracking.cpp b/client/scenes/stream_tracking.cpp
index aa6a76bc..2bfe7d17 100644
--- a/client/scenes/stream_tracking.cpp
+++ b/client/scenes/stream_tracking.cpp
@@ -232,9 +232,11 @@ void scenes::stream::tracking()
XrTime t0 = instance.now();
XrTime last_hand_sample = t0;
+ XrTime last_body_sample = t0;
std::vector tracking;
std::vector tracking_pool; // pre-allocated objects
std::vector hands;
+ std::vector body;
std::vector views;
std::vector merged_tracking;
@@ -258,6 +260,27 @@ void scenes::stream::tracking()
}
}
+ enum
+ {
+ body_none,
+ body_fb,
+ body_pico,
+ } body_tracking = body_none;
+
+ if (config.check_feature(feature::body_tracking))
+ {
+ if (application::get_fb_body_tracking_supported())
+ {
+ body_tracking = body_fb;
+ // We start the tracker on connection because there are toggleable settings.
+ // TODO maybe handle reconnection better, if the settings are changed the tracker count will mismatch and stuff might break
+ application::get_fb_body_tracker().stop();
+ application::get_fb_body_tracker().start(config.fb_lower_body, config.fb_hip);
+ }
+ else if (application::get_pico_body_tracking_supported())
+ body_tracking = body_pico;
+ }
+
on_interaction_profile_changed({});
while (not exiting)
@@ -266,6 +289,7 @@ void scenes::stream::tracking()
{
tracking.clear();
hands.clear();
+ body.clear();
XrTime now = instance.now();
if (now < t0)
@@ -335,6 +359,30 @@ void scenes::stream::tracking()
locate_hands(application::get_right_hand(), world_space, t0 + Δt));
}
+ if (body_tracking != body_none and 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)])
+ {
+ auto & body_packet = body.emplace_back(from_headset::body_tracking{
+ .production_timestamp = t0,
+ .timestamp = t0 + Δt,
+ });
+ switch (body_tracking)
+ {
+ case body_none:
+ __builtin_unreachable();
+ case body_fb:
+ body_packet.poses = application::get_fb_body_tracker().locate_spaces(t0 + Δt, world_space);
+ break;
+ case body_pico:
+ body_packet.poses = application::get_pico_body_tracker().locate_spaces(t0 + Δt, world_space);
+ break;
+ }
+ }
+ }
+
if (control.enabled[size_t(tid::face)])
{
switch (face_tracking)
@@ -408,7 +456,7 @@ void scenes::stream::tracking()
merged_tracking.back().items.emplace_back(std::move(item));
}
- packets.resize(std::max(packets.size(), merged_tracking.size() + hands.size()));
+ packets.resize(std::max(packets.size(), merged_tracking.size() + hands.size() + body.size()));
size_t packet_count = 0;
for (const auto & i: merged_tracking)
{
@@ -425,6 +473,15 @@ void scenes::stream::tracking()
wivrn_session::stream_socket_t::serialize(packet, i);
}
}
+ for (const auto & i: body)
+ {
+ if (i.poses)
+ {
+ auto & packet = packets[packet_count++];
+ packet.clear();
+ wivrn_session::stream_socket_t::serialize(packet, i);
+ }
+ }
network_session->send_stream(std::span(packets.data(), packet_count));
diff --git a/client/xr/fb_body_tracker.cpp b/client/xr/fb_body_tracker.cpp
new file mode 100644
index 00000000..606e5082
--- /dev/null
+++ b/client/xr/fb_body_tracker.cpp
@@ -0,0 +1,131 @@
+/*
+ * WiVRn VR streaming
+ * Copyright (C) 2025 Sapphire
+ *
+ * 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 "fb_body_tracker.h"
+#include "spdlog/spdlog.h"
+#include "xr/meta_body_tracking_fidelity.h"
+#include "xr/xr.h"
+#include
+
+static_assert(xr::pico_body_tracker::joint_whitelist.size() <= wivrn::from_headset::body_tracking::max_tracked_poses);
+
+xr::fb_body_tracker::fb_body_tracker(instance & inst, session & s) :
+ s(s)
+{
+ xrCreateBodyTrackerFB = inst.get_proc("xrCreateBodyTrackerFB");
+ xrRequestBodyTrackingFidelityMETA = inst.get_proc("xrRequestBodyTrackingFidelityMETA");
+ xrLocateBodyJointsFB = inst.get_proc("xrLocateBodyJointsFB");
+ 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,
+ };
+ 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));
+
+ // Enable IOBT.
+ CHECK_XR(xrRequestBodyTrackingFidelityMETA(handle, XR_BODY_TRACKING_FIDELITY_HIGH_META));
+}
+void xr::fb_body_tracker::stop()
+{
+ assert(xrDestroyBodyTrackerFB);
+ full_body = false;
+ if (handle)
+ CHECK_XR(xrDestroyBodyTrackerFB(std::exchange(handle, nullptr)));
+}
+
+std::optional> xr::fb_body_tracker::locate_spaces(XrTime time, XrSpace reference)
+{
+ if (!handle)
+ return std::nullopt;
+
+ assert(xrLocateBodyJointsFB);
+
+ XrBodyJointsLocateInfoFB locate_info{
+ .type = XR_TYPE_BODY_JOINTS_LOCATE_INFO_FB,
+ .next = nullptr,
+ .baseSpace = reference,
+ .time = time,
+ };
+
+ std::array joints{};
+ XrBodyJointLocationsFB joint_locations{
+ .type = XR_TYPE_BODY_JOINT_LOCATIONS_FB,
+ .next = nullptr,
+ .jointCount = (uint32_t)(full_body ? XR_FULL_BODY_JOINT_COUNT_META : (XrFullBodyJointMETA)XR_BODY_JOINT_COUNT_FB),
+ .jointLocations = joints.data(),
+ };
+
+ if (auto res = xrLocateBodyJointsFB(handle, &locate_info, &joint_locations); !XR_SUCCEEDED(res))
+ {
+ spdlog::warn("xrLocateBodyJointsFB returned {}", xr::to_string(res));
+ return std::nullopt;
+ }
+
+ if (!joint_locations.isActive)
+ {
+ spdlog::warn("Body tracker is not active.");
+ return std::nullopt;
+ }
+
+ std::array poses{};
+ int num_poses = 0;
+ for (int i = 0; i < joint_whitelist.size(); i++)
+ {
+ auto joint = joint_whitelist[i];
+ if (!full_body && (joint == XR_FULL_BODY_JOINT_HIPS_META || joint >= XR_FULL_BODY_JOINT_LEFT_UPPER_LEG_META))
+ continue;
+ if (!hip && joint == XR_FULL_BODY_JOINT_HIPS_META)
+ continue;
+
+ const auto & joint_loc = joints[joint];
+ wivrn::from_headset::body_tracking::pose pose{
+ .pose = joint_loc.pose,
+ .flags = 0,
+ };
+
+ if (joint_loc.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT)
+ {
+ pose.flags |= wivrn::from_headset::body_tracking::orientation_valid;
+ pose.flags |= wivrn::from_headset::body_tracking::orientation_tracked;
+ }
+ if (joint_loc.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT)
+ {
+ pose.flags |= wivrn::from_headset::body_tracking::position_valid;
+ pose.flags |= wivrn::from_headset::body_tracking::position_tracked;
+ }
+
+ poses[num_poses++] = pose;
+ }
+ return poses;
+}
diff --git a/client/xr/fb_body_tracker.h b/client/xr/fb_body_tracker.h
new file mode 100644
index 00000000..b1c67345
--- /dev/null
+++ b/client/xr/fb_body_tracker.h
@@ -0,0 +1,69 @@
+/*
+ * WiVRn VR streaming
+ * Copyright (C) 2025 Sapphire
+ *
+ * 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 "wivrn_packets.h"
+
+#include "xr/meta_body_tracking_fidelity.h"
+#include
+#include
+#include
+
+namespace xr
+{
+class instance;
+class session;
+
+class fb_body_tracker
+{
+ XrSession s;
+ XrBodyTrackerFB handle{};
+
+ PFN_xrCreateBodyTrackerFB xrCreateBodyTrackerFB{};
+ PFN_xrRequestBodyTrackingFidelityMETA xrRequestBodyTrackingFidelityMETA{};
+ PFN_xrLocateBodyJointsFB xrLocateBodyJointsFB{};
+ PFN_xrDestroyBodyTrackerFB xrDestroyBodyTrackerFB{};
+
+ bool full_body{};
+ bool hip{};
+
+public:
+ static constexpr std::array joint_whitelist{
+ XR_FULL_BODY_JOINT_HIPS_META,
+ XR_FULL_BODY_JOINT_CHEST_META,
+ XR_FULL_BODY_JOINT_LEFT_ARM_LOWER_META,
+ XR_FULL_BODY_JOINT_RIGHT_ARM_LOWER_META,
+
+ XR_FULL_BODY_JOINT_LEFT_LOWER_LEG_META,
+ XR_FULL_BODY_JOINT_RIGHT_LOWER_LEG_META,
+
+ XR_FULL_BODY_JOINT_LEFT_FOOT_TRANSVERSE_META,
+ XR_FULL_BODY_JOINT_RIGHT_FOOT_TRANSVERSE_META,
+ };
+
+ fb_body_tracker() = default;
+ fb_body_tracker(instance & inst, session & s);
+ ~fb_body_tracker();
+
+ void start(bool lower_body, bool hip);
+ void stop();
+
+ std::optional> locate_spaces(XrTime time, XrSpace reference);
+};
+} // namespace xr
diff --git a/client/xr/pico_body_tracker.cpp b/client/xr/pico_body_tracker.cpp
new file mode 100644
index 00000000..5f6a7bb6
--- /dev/null
+++ b/client/xr/pico_body_tracker.cpp
@@ -0,0 +1,86 @@
+/*
+ * WiVRn VR streaming
+ * Copyright (C) 2025 Sapphire
+ *
+ * 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 "pico_body_tracker.h"
+#include "spdlog/spdlog.h"
+#include "xr/xr.h"
+#include
+
+static_assert(xr::pico_body_tracker::joint_whitelist.size() <= wivrn::from_headset::body_tracking::max_tracked_poses);
+
+static PFN_xrDestroyBodyTrackerBD xrDestroyBodyTrackerBD{};
+
+XrResult xr::destroy_pico_body_tracker(XrBodyTrackerBD id)
+{
+ return xrDestroyBodyTrackerBD(id);
+}
+
+xr::pico_body_tracker::pico_body_tracker(instance & inst, XrBodyTrackerBD h)
+{
+ id = h;
+ xrLocateBodyJointsBD = inst.get_proc("xrLocateBodyJointsBD");
+}
+
+std::optional> xr::pico_body_tracker::locate_spaces(XrTime time, XrSpace reference)
+{
+ if (!xrLocateBodyJointsBD)
+ return std::nullopt;
+
+ XrBodyJointsLocateInfoBD locate_info{
+ .type = XR_TYPE_BODY_JOINTS_LOCATE_INFO_BD,
+ .next = nullptr,
+ .baseSpace = reference,
+ .time = time,
+ };
+
+ std::array joints{};
+ XrBodyJointLocationsBD joint_locations{
+ .type = XR_TYPE_BODY_JOINT_LOCATIONS_BD,
+ .next = nullptr,
+ .jointLocationCount = joints.size(),
+ .jointLocations = joints.data(),
+ };
+
+ if (auto res = xrLocateBodyJointsBD(id, &locate_info, &joint_locations); !XR_SUCCEEDED(res))
+ {
+ spdlog::warn("Unable to get body joints: xrLocateBodyJointsBD returned {}", xr::to_string(res));
+ return std::nullopt;
+ }
+
+ std::array poses{};
+ for (int i = 0; i < joint_whitelist.size(); i++)
+ {
+ const auto & joint_loc = joints[joint_whitelist[i]];
+ wivrn::from_headset::body_tracking::pose pose{
+ .pose = joint_loc.pose,
+ .flags = 0,
+ };
+
+ if (joint_loc.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT)
+ pose.flags |= wivrn::from_headset::body_tracking::orientation_valid;
+ if (joint_loc.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT)
+ pose.flags |= wivrn::from_headset::body_tracking::position_valid;
+ if (joint_loc.locationFlags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT)
+ pose.flags |= wivrn::from_headset::body_tracking::orientation_tracked;
+ if (joint_loc.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT)
+ pose.flags |= wivrn::from_headset::body_tracking::position_tracked;
+
+ poses[i] = pose;
+ }
+ return poses;
+}
diff --git a/client/xr/pico_body_tracker.h b/client/xr/pico_body_tracker.h
new file mode 100644
index 00000000..3cb0dfbf
--- /dev/null
+++ b/client/xr/pico_body_tracker.h
@@ -0,0 +1,55 @@
+/*
+ * WiVRn VR streaming
+ * Copyright (C) 2025 Sapphire
+ *
+ * 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 "utils/handle.h"
+#include "wivrn_packets.h"
+
+#include
+#include
+#include
+
+namespace xr
+{
+class instance;
+
+XrResult destroy_pico_body_tracker(XrBodyTrackerBD);
+
+class pico_body_tracker : public utils::handle
+{
+ PFN_xrLocateBodyJointsBD xrLocateBodyJointsBD{};
+
+public:
+ static constexpr std::array joint_whitelist{
+ XR_BODY_JOINT_PELVIS_BD,
+ XR_BODY_JOINT_LEFT_ELBOW_BD,
+ XR_BODY_JOINT_RIGHT_ELBOW_BD,
+
+ XR_BODY_JOINT_LEFT_KNEE_BD,
+ XR_BODY_JOINT_RIGHT_KNEE_BD,
+ XR_BODY_JOINT_LEFT_FOOT_BD,
+ XR_BODY_JOINT_RIGHT_FOOT_BD,
+ };
+
+ pico_body_tracker() = default;
+ pico_body_tracker(instance & inst, XrBodyTrackerBD h);
+
+ std::optional> locate_spaces(XrTime time, XrSpace reference);
+};
+} // namespace xr
diff --git a/client/xr/session.cpp b/client/xr/session.cpp
index ab6e6978..5c92a8e7 100644
--- a/client/xr/session.cpp
+++ b/client/xr/session.cpp
@@ -23,7 +23,9 @@
#include "details/enumerate.h"
#include "openxr/openxr.h"
#include "utils/contains.h"
+#include "xr/fb_body_tracker.h"
#include "xr/instance.h"
+#include "xr/pico_body_tracker.h"
#include "xr/system.h"
#include
#include
@@ -142,6 +144,28 @@ xr::pico_face_tracker xr::session::create_pico_face_tracker()
return {*inst, *this};
}
+xr::fb_body_tracker xr::session::create_fb_body_tracker()
+{
+ return {*inst, *this};
+}
+
+xr::pico_body_tracker xr::session::create_pico_body_tracker()
+{
+ XrBodyTrackerCreateInfoBD create_info{
+ .type = XR_TYPE_BODY_TRACKER_CREATE_INFO_BD,
+ .next = nullptr,
+ .jointSet = XR_BODY_JOINT_SET_FULL_BODY_JOINTS_BD,
+ };
+
+ XrBodyTrackerBD bt;
+
+ auto xrCreateBodyTrackerBD = inst->get_proc("xrCreateBodyTrackerBD");
+ assert(xrCreateBodyTrackerBD);
+
+ CHECK_XR(xrCreateBodyTrackerBD(id, &create_info, &bt));
+ return {*inst, bt};
+}
+
std::vector xr::session::get_swapchain_formats() const
{
std::vector formats;
diff --git a/client/xr/session.h b/client/xr/session.h
index bd43147f..e3c31647 100644
--- a/client/xr/session.h
+++ b/client/xr/session.h
@@ -26,10 +26,12 @@
#include
#include
+#include "fb_body_tracker.h"
#include "fb_face_tracker2.h"
#include "hand_tracker.h"
#include "htc_face_tracker.h"
#include "passthrough.h"
+#include "pico_body_tracker.h"
#include "pico_face_tracker.h"
#include "space.h"
@@ -54,6 +56,8 @@ public:
fb_face_tracker2 create_fb_face_tracker2();
htc_face_tracker create_htc_face_tracker(XrFacialTrackingTypeHTC);
pico_face_tracker create_pico_face_tracker();
+ fb_body_tracker create_fb_body_tracker();
+ pico_body_tracker create_pico_body_tracker();
std::vector get_swapchain_formats() const;
diff --git a/client/xr/system.cpp b/client/xr/system.cpp
index 33769ba7..0c88054d 100644
--- a/client/xr/system.cpp
+++ b/client/xr/system.cpp
@@ -141,6 +141,42 @@ XrSystemFacialTrackingPropertiesHTC xr::system::htc_face_tracking_properties() c
return face_tracking_prop;
}
+XrSystemBodyTrackingPropertiesFB xr::system::fb_body_tracking_properties() const
+{
+ if (!id)
+ throw std::invalid_argument("this");
+
+ XrSystemBodyTrackingPropertiesFB body_tracking_prop{
+ .type = XR_TYPE_SYSTEM_BODY_TRACKING_PROPERTIES_FB,
+ };
+
+ XrSystemProperties prop{
+ .type = XR_TYPE_SYSTEM_PROPERTIES,
+ .next = &body_tracking_prop,
+ };
+ CHECK_XR(xrGetSystemProperties(*inst, id, &prop));
+
+ return body_tracking_prop;
+}
+
+XrSystemBodyTrackingPropertiesBD xr::system::bd_body_tracking_properties() const
+{
+ if (!id)
+ throw std::invalid_argument("this");
+
+ XrSystemBodyTrackingPropertiesBD body_tracking_prop{
+ .type = XR_TYPE_SYSTEM_BODY_TRACKING_PROPERTIES_BD,
+ };
+
+ XrSystemProperties prop{
+ .type = XR_TYPE_SYSTEM_PROPERTIES,
+ .next = &body_tracking_prop,
+ };
+ CHECK_XR(xrGetSystemProperties(*inst, id, &prop));
+
+ return body_tracking_prop;
+}
+
xr::system::passthrough_type xr::system::passthrough_supported() const
{
if (utils::contains(environment_blend_modes(XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO), XR_ENVIRONMENT_BLEND_MODE_ALPHA_BLEND))
diff --git a/client/xr/system.h b/client/xr/system.h
index 0a1b76fc..45e7729b 100644
--- a/client/xr/system.h
+++ b/client/xr/system.h
@@ -64,6 +64,8 @@ public:
XrSystemEyeGazeInteractionPropertiesEXT eye_gaze_interaction_properties() const;
XrSystemFaceTrackingProperties2FB fb_face_tracking2_properties() const;
XrSystemFacialTrackingPropertiesHTC htc_face_tracking_properties() const;
+ XrSystemBodyTrackingPropertiesFB fb_body_tracking_properties() const;
+ XrSystemBodyTrackingPropertiesBD bd_body_tracking_properties() const;
passthrough_type passthrough_supported() const;
XrGraphicsRequirementsVulkan2KHR graphics_requirements() const;
diff --git a/common/wivrn_packets.h b/common/wivrn_packets.h
index a44a3f64..1d4cbcab 100644
--- a/common/wivrn_packets.h
+++ b/common/wivrn_packets.h
@@ -220,6 +220,7 @@ struct headset_info_packet
bool palm_pose;
bool passthrough;
face_type face_tracking;
+ uint32_t num_generic_trackers;
std::vector supported_codecs; // from preferred to least preferred
std::string system_name;
};
@@ -337,6 +338,28 @@ struct hand_tracking
std::optional> joints;
};
+struct body_tracking
+{
+ inline static const size_t max_tracked_poses = 16;
+ enum flags : uint8_t
+ {
+ orientation_valid = 1 << 0,
+ position_valid = 1 << 1,
+ orientation_tracked = 1 << 2,
+ position_tracked = 1 << 3,
+ };
+ struct pose
+ {
+ XrPosef pose{};
+ // maybe add velocity?
+ uint8_t flags{0};
+ };
+
+ XrTime production_timestamp;
+ XrTime timestamp;
+ std::optional> poses;
+};
+
struct inputs
{
struct input_value
@@ -399,6 +422,7 @@ using packets = std::variant<
trackings,
derived_pose,
hand_tracking,
+ body_tracking,
inputs,
timesync_response,
battery,
@@ -571,6 +595,7 @@ struct tracking_control
left_hand,
right_hand,
face,
+ generic_tracker,
battery,
microphone,
diff --git a/common/xr/meta_body_tracking_fidelity.h b/common/xr/meta_body_tracking_fidelity.h
new file mode 100644
index 00000000..acb31417
--- /dev/null
+++ b/common/xr/meta_body_tracking_fidelity.h
@@ -0,0 +1,41 @@
+// clang-format off
+#pragma once
+
+#include
+
+// XR_META_body_tracking_fidelity is a preprocessor guard. Do not pass it to API calls.
+#define XR_META_body_tracking_fidelity 1
+#define XR_META_body_tracking_fidelity_SPEC_VERSION 1
+#define XR_META_BODY_TRACKING_FIDELITY_EXTENSION_NAME "XR_META_body_tracking_fidelity"
+static const XrStructureType XR_TYPE_BODY_TRACKING_FIDELITY_STATUS_META = (XrStructureType) 1000284000;
+static const XrStructureType XR_TYPE_SYSTEM_PROPERTIES_BODY_TRACKING_FIDELITY_META = (XrStructureType) 1000284001;
+
+typedef enum XrBodyTrackingFidelityMETA {
+ XR_BODY_TRACKING_FIDELITY_LOW_META = 1,
+ XR_BODY_TRACKING_FIDELITY_HIGH_META = 2,
+ XR_BODY_TRACKING_FIDELITY_MAX_ENUM_META = 0x7FFFFFFF
+} XrBodyTrackingFidelityMETA;
+typedef struct XrSystemPropertiesBodyTrackingFidelityMETA {
+ XrStructureType type;
+ void* XR_MAY_ALIAS next;
+ XrBool32 supportsBodyTrackingFidelity;
+} XrSystemPropertiesBodyTrackingFidelityMETA;
+
+// XrBodyTrackingFidelityStatusMETA extends XrBodyJointLocationsFB
+typedef struct XrBodyTrackingFidelityStatusMETA {
+ XrStructureType type;
+ const void* XR_MAY_ALIAS next;
+ XrBodyTrackingFidelityMETA fidelity;
+} XrBodyTrackingFidelityStatusMETA;
+
+typedef XrResult (XRAPI_PTR *PFN_xrRequestBodyTrackingFidelityMETA)(XrBodyTrackerFB bodyTracker, const XrBodyTrackingFidelityMETA fidelity);
+
+#ifndef XR_NO_PROTOTYPES
+#ifdef XR_EXTENSION_PROTOTYPES
+XRAPI_ATTR XrResult XRAPI_CALL xrRequestBodyTrackingFidelityMETA(
+ XrBodyTrackerFB bodyTracker,
+ const XrBodyTrackingFidelityMETA fidelity);
+#endif /* XR_EXTENSION_PROTOTYPES */
+#endif /* !XR_NO_PROTOTYPES */
+
+// clang-format on
diff --git a/flake.nix b/flake.nix
index 1121315e..fbbd5071 100644
--- a/flake.nix
+++ b/flake.nix
@@ -5,19 +5,20 @@
outputs = inputs@{ nixpkgs, flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "x86_64-linux" ];
- perSystem = { pkgs, ... }: let
+ perSystem = { lib, pkgs, ... }: let
# Tools used for development work (clangd, clang-format)
devTools = with pkgs; [
clang-tools
+ gdb
+ ktx-tools
];
# Extra build inputs not yet in the nixpkgs recipe.
- # Should be submitted to nixpkgs on release
extraBuildInputs = with pkgs; [
# XRT_FEATURE_DEBUG_GUI requires SDL2
sdl2-compat
];
- package = pkgs.wivrn.overrideAttrs (finalAttrs: oldAttrs: {
+ package = pkgs.enableDebugging (pkgs.wivrn.overrideAttrs (finalAttrs: oldAttrs: {
src = ./.;
version = "next";
@@ -25,6 +26,8 @@
# We also don't need the check since we read the revision from the monado-rev file.
postUnpack = null;
+ separateDebugInfo = false;
+
monado = pkgs.applyPatches {
inherit (oldAttrs.monado) patches postPatch;
# Force a refetch when the monado rev changes.
@@ -39,7 +42,19 @@
};
buildInputs = oldAttrs.buildInputs ++ extraBuildInputs;
- });
+
+ dontWrapQtApps = true;
+
+ preFixup = ''
+ wrapQtApp "$out/bin/wivrn-dashboard" \
+ --prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ pkgs.vulkan-loader ]}
+ '';
+ postFixup = null;
+
+ cmakeFlags = (oldAttrs.cmakeFlags or [ ]) ++ [
+ (lib.cmakeFeature "CMAKE_BUILD_TYPE" "Debug")
+ ];
+ }));
in {
packages.default = package;
devShells.default = package.overrideAttrs (oldAttrs: {
@@ -47,4 +62,4 @@
});
};
};
-}
\ No newline at end of file
+}
diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt
index 9530ff85..28d53657 100644
--- a/server/CMakeLists.txt
+++ b/server/CMakeLists.txt
@@ -97,6 +97,7 @@ if (WIVRN_BUILD_SERVER)
driver/wivrn_eye_tracker.cpp
driver/wivrn_fb_face2_tracker.cpp
driver/wivrn_htc_face_tracker.cpp
+ driver/wivrn_generic_tracker.cpp
driver/wivrn_foveation.cpp
driver/pose_list.cpp
driver/view_list.cpp
diff --git a/server/driver/wivrn_controller.cpp b/server/driver/wivrn_controller.cpp
index 8592be65..f757f604 100644
--- a/server/driver/wivrn_controller.cpp
+++ b/server/driver/wivrn_controller.cpp
@@ -234,6 +234,7 @@ static input_data map_input(device_id id)
return {WIVRN_CONTROLLER_THUMBREST_FORCE, wivrn_input_type::FLOAT, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
case device_id::RIGHT_STYLUS_FORCE:
return {WIVRN_CONTROLLER_STYLUS_FORCE, wivrn_input_type::FLOAT, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
+ default:
break;
}
throw std::range_error("bad input id " + std::to_string((int)id));
diff --git a/server/driver/wivrn_generic_tracker.cpp b/server/driver/wivrn_generic_tracker.cpp
new file mode 100644
index 00000000..379e17dc
--- /dev/null
+++ b/server/driver/wivrn_generic_tracker.cpp
@@ -0,0 +1,176 @@
+/*
+ * WiVRn VR streaming
+ * Copyright (C) 2022 Guillaume Meunier
+ * Copyright (C) 2022 Patrick Nicolas
+ * Copyright (C) 2025 Sapphire
+ *
+ * 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 "wivrn_generic_tracker.h"
+#include "util/u_logging.h"
+#include "utils/method.h"
+#include "wivrn_session.h"
+
+#include "math/m_api.h"
+#include "math/m_eigen_interop.hpp"
+#include "math/m_space.h"
+#include "math/m_vec3.h"
+#include "xrt/xrt_defines.h"
+#include "xrt/xrt_results.h"
+#include "xrt_cast.h"
+#include
+#include
+
+using namespace xrt::auxiliary::math;
+
+namespace wivrn
+{
+
+xrt_space_relation tracker_pose_list::interpolate(const xrt_space_relation & a, const xrt_space_relation & b, float t)
+{
+ xrt_space_relation result;
+ xrt_space_relation_flags flags = xrt_space_relation_flags(a.relation_flags & b.relation_flags);
+ m_space_relation_interpolate(const_cast(&a), const_cast(&b), t, flags, &result);
+ return result;
+}
+
+xrt_space_relation tracker_pose_list::extrapolate(const xrt_space_relation & a, const xrt_space_relation & b, int64_t ta, int64_t tb, int64_t t)
+{
+ float h = (tb - ta) / 1.e9;
+
+ xrt_space_relation res = t < ta ? a : b;
+
+ xrt_vec3 lin_vel = res.relation_flags & XRT_SPACE_RELATION_LINEAR_VELOCITY_VALID_BIT ? res.linear_velocity : (b.pose.position - a.pose.position) / h;
+
+ float dt = (t - tb) / 1.e9;
+
+ float dt2_over_2 = dt * dt / 2;
+ res.pose.position = res.pose.position + lin_vel * dt;
+
+ if (res.relation_flags & XRT_SPACE_RELATION_ANGULAR_VELOCITY_VALID_BIT)
+ {
+ xrt_vec3 dtheta = res.angular_velocity * dt;
+ xrt_quat dq;
+ math_quat_exp(&dtheta, &dq);
+
+ map_quat(res.pose.orientation) = map_quat(res.pose.orientation) * map_quat(dq);
+ }
+
+ return res;
+}
+
+bool tracker_pose_list::update_tracking(XrTime produced_timestamp, XrTime timestamp, const from_headset::body_tracking::pose & pose, const clock_offset & offset)
+{
+ return add_sample(produced_timestamp, timestamp, convert_pose(pose), offset);
+}
+
+std::pair tracker_pose_list::get_pose_at(XrTime at_timestamp_ns)
+{
+ return get_at(at_timestamp_ns);
+}
+
+static xrt_space_relation_flags convert_flags(uint8_t flags)
+{
+ std::underlying_type_t out_flags = 0;
+ if (flags & from_headset::body_tracking::orientation_valid)
+ out_flags |= XRT_SPACE_RELATION_ORIENTATION_VALID_BIT;
+ if (flags & from_headset::body_tracking::position_valid)
+ out_flags |= XRT_SPACE_RELATION_POSITION_VALID_BIT;
+
+ if (flags & from_headset::body_tracking::orientation_tracked)
+ out_flags |= XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT;
+ if (flags & from_headset::body_tracking::position_tracked)
+ out_flags |= XRT_SPACE_RELATION_POSITION_TRACKED_BIT;
+
+ return xrt_space_relation_flags(out_flags);
+}
+
+xrt_space_relation tracker_pose_list::convert_pose(const from_headset::body_tracking::pose & pose)
+{
+ return xrt_space_relation{
+ .relation_flags = convert_flags(pose.flags),
+ .pose = xrt_cast(pose.pose),
+ .linear_velocity = {},
+ .angular_velocity = {},
+ };
+}
+
+wivrn_generic_tracker::wivrn_generic_tracker(int index, xrt_device * hmd, wivrn_session & cnx) :
+ xrt_device{
+ .name = XRT_DEVICE_VIVE_TRACKER,
+ .device_type = XRT_DEVICE_TYPE_GENERIC_TRACKER,
+ .hmd = nullptr,
+ .tracking_origin = hmd->tracking_origin,
+ .orientation_tracking_supported = true,
+ .position_tracking_supported = true,
+ .update_inputs = method_pointer<&wivrn_generic_tracker::update_inputs>,
+ .get_tracked_pose = method_pointer<&wivrn_generic_tracker::get_tracked_pose>,
+ .destroy = [](xrt_device *) {},
+ },
+ cnx(cnx),
+ index(index)
+{
+ auto unique_name = std::format("WiVRn Generic Tracker #{}", index + 1);
+ strlcpy(str, unique_name.c_str(), std::size(str));
+ strlcpy(serial, unique_name.c_str(), std::size(serial));
+
+ pose_input.name = XRT_INPUT_GENERIC_TRACKER_POSE;
+ pose_input.active = true;
+
+ inputs = &pose_input;
+ input_count = 1;
+}
+
+#define XRT_INPUT_NAME_CASE(NAME, VALUE) \
+ case VALUE: \
+ return #NAME;
+
+const char * input_name_str(xrt_input_name name)
+{
+ switch (name)
+ {
+ XRT_INPUT_LIST(XRT_INPUT_NAME_CASE)
+ default:
+ return "Unknown";
+ }
+}
+
+xrt_result_t wivrn_generic_tracker::update_inputs()
+{
+ return XRT_SUCCESS;
+}
+xrt_result_t wivrn_generic_tracker::get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns, xrt_space_relation * res)
+{
+ std::chrono::nanoseconds extrapolation_time;
+
+ if (name == XRT_INPUT_GENERIC_TRACKER_POSE)
+ {
+ std::tie(extrapolation_time, *res) = poses.get_pose_at(at_timestamp_ns);
+
+ cnx.set_tracker_enabled(index, true);
+ cnx.add_predict_offset(extrapolation_time);
+ return XRT_SUCCESS;
+ }
+
+ U_LOG_D("Unknown input name %s", input_name_str(name));
+ return XRT_ERROR_NOT_IMPLEMENTED;
+}
+
+void wivrn_generic_tracker::update_tracking(const from_headset::body_tracking & tracking, const from_headset::body_tracking::pose & pose, const clock_offset & offset)
+{
+ if (!poses.update_tracking(tracking.production_timestamp, tracking.timestamp, pose, offset))
+ cnx.set_tracker_enabled(index, false);
+}
+} // namespace wivrn
\ No newline at end of file
diff --git a/server/driver/wivrn_generic_tracker.h b/server/driver/wivrn_generic_tracker.h
new file mode 100644
index 00000000..8cb974c3
--- /dev/null
+++ b/server/driver/wivrn_generic_tracker.h
@@ -0,0 +1,61 @@
+/*
+ * WiVRn VR streaming
+ * Copyright (C) 2025 Sapphire
+ *
+ * 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 "history.h"
+#include "xrt/xrt_device.h"
+
+namespace wivrn
+{
+class wivrn_session;
+struct clock_offset;
+
+class tracker_pose_list : public history
+{
+public:
+ static xrt_space_relation interpolate(const xrt_space_relation & a, const xrt_space_relation & b, float t);
+ static xrt_space_relation extrapolate(const xrt_space_relation & a, const xrt_space_relation & b, int64_t ta, int64_t tb, int64_t t);
+
+ tracker_pose_list() = default;
+
+ bool update_tracking(XrTime produced_timestamp, XrTime timestamp, const from_headset::body_tracking::pose & pose, const clock_offset & offset);
+
+ std::pair get_pose_at(XrTime at_timestamp_ns);
+
+ static xrt_space_relation convert_pose(const wivrn::from_headset::body_tracking::pose &);
+};
+
+class wivrn_generic_tracker : public xrt_device
+{
+ tracker_pose_list poses;
+ xrt_input pose_input;
+
+ wivrn_session & cnx;
+ int index;
+
+public:
+ using base = xrt_device;
+ wivrn_generic_tracker(int index, xrt_device * hmd, wivrn_session & cnx);
+
+ xrt_result_t update_inputs();
+ xrt_result_t get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns, xrt_space_relation * out_relation);
+
+ void update_tracking(const from_headset::body_tracking & tracking, const from_headset::body_tracking::pose & pose, const clock_offset & offset);
+};
+} // namespace wivrn
\ No newline at end of file
diff --git a/server/driver/wivrn_session.cpp b/server/driver/wivrn_session.cpp
index 6fd8d0da..c702c87c 100644
--- a/server/driver/wivrn_session.cpp
+++ b/server/driver/wivrn_session.cpp
@@ -34,12 +34,15 @@
#include "wivrn_config.h"
#include "wivrn_eye_tracker.h"
#include "wivrn_fb_face2_tracker.h"
+#include "wivrn_generic_tracker.h"
#include "wivrn_htc_face_tracker.h"
#include "wivrn_ipc.h"
#include "wivrn_packets.h"
#include "xrt/xrt_device.h"
#include "xrt/xrt_session.h"
+#include
+#include
#include
#include
#include
@@ -116,12 +119,19 @@ void wivrn::tracking_control_t::send(wivrn_connection & connection, bool now)
next_sample += std::chrono::seconds(1);
}
+bool wivrn::tracking_control_t::get_enabled(to_headset::tracking_control::id id)
+{
+ std::lock_guard lock(mutex);
+ return this->enabled[size_t(id)];
+}
bool wivrn::tracking_control_t::set_enabled(to_headset::tracking_control::id id, bool enabled)
{
std::lock_guard lock(mutex);
bool changed = enabled != this->enabled[size_t(id)];
- if (changed)
- U_LOG_I("%s tracking: %s", std::string(magic_enum::enum_name(id)).c_str(), enabled ? "enabled" : "disabled");
+ if (!changed)
+ return false;
+
+ U_LOG_I("%s tracking: %s", std::string(magic_enum::enum_name(id)).c_str(), enabled ? "enabled" : "disabled");
this->enabled[size_t(id)] = enabled;
return changed;
}
@@ -215,6 +225,21 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr connection
xdevs[xdev_count++] = htc_face_tracker.get();
}
+ num_generic_trackers = get_info().num_generic_trackers;
+ enabled_trackers.fill(false);
+ if (num_generic_trackers > 0)
+ {
+ U_LOG_I("Creating %d generic trackers", num_generic_trackers);
+
+ for (int i = 0; i < num_generic_trackers; ++i)
+ {
+ auto dev = std::make_unique(i, &hmd, *this);
+ xdevs[xdev_count++] = dev.get();
+ generic_trackers[i] = std::move(dev);
+ enabled_trackers[i] = true;
+ }
+ }
+
#if WIVRN_FEATURE_SOLARXR
uint32_t num_devs = solarxr_device_create_xdevs(&hmd.tracking_origin, &xdevs[xdev_count], ARRAY_SIZE(xdevs) - xdev_count);
if (num_devs != 0)
@@ -429,6 +454,19 @@ void wivrn_session::operator()(from_headset::hand_tracking && hand_tracking)
left_hand.update_hand_tracking(hand_tracking, offset);
right_hand.update_hand_tracking(hand_tracking, offset);
}
+void wivrn_session::operator()(from_headset::body_tracking && body_tracking)
+{
+ auto offset = offset_est.get_offset();
+
+ for (int i = 0; i < num_generic_trackers; i++)
+ {
+ auto pose = body_tracking.poses ? body_tracking.poses->at(i) : from_headset::body_tracking::pose{
+ .pose = {},
+ .flags = 0,
+ };
+ generic_trackers[i]->update_tracking(body_tracking, pose, offset);
+ }
+}
void wivrn_session::operator()(from_headset::inputs && inputs)
{
auto offset = get_offset();
@@ -475,6 +513,14 @@ void wivrn_session::set_enabled(device_id id, bool enabled)
if (tracking_control.set_enabled(to_tracking_control(id), enabled) and enabled)
tracking_control.send(*connection, true);
}
+void wivrn_session::set_tracker_enabled(int index, bool enabled)
+{
+ assert(index < std::size(enabled_trackers));
+ enabled_trackers[index] = enabled;
+ bool keep_active = std::ranges::any_of(enabled_trackers, [](bool b) { return b; });
+ if (tracking_control.set_enabled(to_headset::tracking_control::id::generic_tracker, keep_active))
+ tracking_control.send(*connection, true);
+}
void wivrn_session::operator()(from_headset::feedback && feedback)
{
diff --git a/server/driver/wivrn_session.h b/server/driver/wivrn_session.h
index 4fe0ddce..1c6a234a 100644
--- a/server/driver/wivrn_session.h
+++ b/server/driver/wivrn_session.h
@@ -33,6 +33,7 @@
#include
#include
#include
+#include
struct u_system;
struct xrt_space_overseer;
@@ -44,6 +45,7 @@ namespace wivrn
class wivrn_eye_tracker;
class wivrn_fb_face2_tracker;
class wivrn_htc_face_tracker;
+class wivrn_generic_tracker;
struct audio_device;
struct wivrn_comp_target;
struct wivrn_comp_target_factory;
@@ -80,6 +82,7 @@ public:
}
void send(wivrn_connection & connection, bool now = false);
+ bool get_enabled(to_headset::tracking_control::id id);
// Return true if value changed
bool set_enabled(to_headset::tracking_control::id id, bool enabled);
};
@@ -107,6 +110,9 @@ class wivrn_session : public xrt_system_devices
std::unique_ptr eye_tracker;
std::unique_ptr fb_face2_tracker;
std::unique_ptr htc_face_tracker;
+ uint32_t num_generic_trackers;
+ std::array, from_headset::body_tracking::max_tracked_poses> generic_trackers;
+ std::array enabled_trackers;
std::shared_ptr comp_target;
clock_offset_estimator offset_est;
@@ -152,6 +158,7 @@ public:
void set_enabled(to_headset::tracking_control::id id, bool enabled);
void set_enabled(device_id id, bool enabled);
+ void set_tracker_enabled(int index, bool enabled);
void operator()(from_headset::crypto_handshake &&) {}
void operator()(from_headset::pin_check_1 &&) {}
@@ -162,6 +169,7 @@ public:
void operator()(const from_headset::tracking &);
void operator()(from_headset::derived_pose &&);
void operator()(from_headset::hand_tracking &&);
+ void operator()(from_headset::body_tracking &&);
void operator()(from_headset::inputs &&);
void operator()(from_headset::timesync_response &&);
void operator()(from_headset::feedback &&);