Forward body skeletons from headset
This commit is contained in:
@@ -191,8 +191,6 @@ configuration::configuration(xr::system & system, xr::session & session)
|
||||
|
||||
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();
|
||||
@@ -309,7 +307,6 @@ void configuration::save()
|
||||
json << ",\"forward_mouse\":" << std::boolalpha << forward_mouse;
|
||||
json << ",\"forward_gamepad\":" << std::boolalpha << forward_gamepad;
|
||||
json << ",\"fb_lower_body\":" << std::boolalpha << fb_lower_body;
|
||||
json << ",\"fb_hip\":" << std::boolalpha << fb_hip;
|
||||
json << ",\"enable_stream_gui\":" << std::boolalpha << enable_stream_gui;
|
||||
for (auto & [key, value]: features)
|
||||
json << "," << key << ":" << std::boolalpha << value;
|
||||
|
||||
@@ -74,7 +74,6 @@ public:
|
||||
bool forward_gamepad = false;
|
||||
|
||||
bool fb_lower_body = false;
|
||||
bool fb_hip = true;
|
||||
|
||||
bool enable_stream_gui = true;
|
||||
|
||||
|
||||
@@ -859,14 +859,14 @@ void scenes::lobby::gui_settings()
|
||||
}
|
||||
else
|
||||
{
|
||||
if (body_tracker == xr::body_tracker_type::fb)
|
||||
if (body_tracker == xr::body_tracker_type::fb or body_tracker == xr::body_tracker_type::meta)
|
||||
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 (body_tracker == xr::body_tracker_type::fb)
|
||||
if (body_tracker == xr::body_tracker_type::meta)
|
||||
{
|
||||
ImGui::BeginDisabled(not config.check_feature(feature::body_tracking));
|
||||
ImGui::Indent();
|
||||
@@ -878,16 +878,6 @@ void scenes::lobby::gui_settings()
|
||||
if (ImGui::IsItemHovered())
|
||||
imgui_ctx->tooltip(_("Estimate lower body joint positions using Generative Legs\nRequires 'Hand and body tracking' to be enabled in the Quest movement tracking settings"));
|
||||
|
||||
ImGui::BeginDisabled(not config.fb_lower_body);
|
||||
if (ImGui::Checkbox(_S("Enable hip tracking"), &config.fb_hip))
|
||||
{
|
||||
config.save();
|
||||
}
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (ImGui::IsItemHovered())
|
||||
imgui_ctx->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();
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "xr/face_tracker.h"
|
||||
#include "xr/fb_face_tracker2.h"
|
||||
#include "xr/space.h"
|
||||
#include "xr/system.h"
|
||||
#include <glm/gtc/matrix_access.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <magic_enum.hpp>
|
||||
@@ -295,21 +296,25 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
||||
}
|
||||
}
|
||||
|
||||
info.num_generic_trackers = 0;
|
||||
if (config.check_feature(feature::body_tracking))
|
||||
{
|
||||
switch (self->system.body_tracker_supported())
|
||||
{
|
||||
case xr::body_tracker_type::none:
|
||||
info.body_tracking = from_headset::body_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();
|
||||
info.body_tracking = from_headset::body_type::fb;
|
||||
break;
|
||||
case xr::body_tracker_type::htc:
|
||||
info.num_generic_trackers = application::get_generic_trackers().size();
|
||||
case xr::body_tracker_type::meta:
|
||||
info.body_tracking = config.fb_lower_body ? from_headset::body_type::meta : from_headset::body_type::fb;
|
||||
break;
|
||||
case xr::body_tracker_type::pico:
|
||||
info.num_generic_trackers = xr::pico_body_tracker::joint_whitelist.size();
|
||||
info.body_tracking = from_headset::body_type::bd;
|
||||
break;
|
||||
case xr::body_tracker_type::htc:
|
||||
info.body_tracking = from_headset::body_type::htc;
|
||||
info.num_generic_trackers = application::get_generic_trackers().size();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,7 +316,7 @@ void scenes::stream::tracking()
|
||||
XrTime t0 = instance.now();
|
||||
from_headset::tracking tracking;
|
||||
std::vector<from_headset::hand_tracking> hands;
|
||||
std::vector<from_headset::body_tracking> body;
|
||||
std::vector<std::variant<from_headset::meta_body, from_headset::bd_body, from_headset::htc_body>> body;
|
||||
std::vector<XrView> views;
|
||||
|
||||
std::vector<serialization_packet> packets;
|
||||
@@ -406,8 +406,7 @@ void scenes::stream::tracking()
|
||||
system,
|
||||
session,
|
||||
application::get_generic_trackers(),
|
||||
config.fb_lower_body,
|
||||
config.fb_hip);
|
||||
config.fb_lower_body);
|
||||
}
|
||||
else
|
||||
body_tracker.emplace<std::monostate>();
|
||||
@@ -554,11 +553,10 @@ void scenes::stream::tracking()
|
||||
std::visit(utils::overloaded{
|
||||
[](std::monostate &) {},
|
||||
[&](auto & b) {
|
||||
body.push_back(from_headset::body_tracking{
|
||||
.production_timestamp = tracking.production_timestamp,
|
||||
.timestamp = at_time,
|
||||
.poses = b.locate_spaces(at_time, world_space),
|
||||
});
|
||||
auto packet = b.locate_spaces(at_time, world_space);
|
||||
packet.timestamp = at_time;
|
||||
packet.production_timestamp = tracking.production_timestamp;
|
||||
body.push_back(packet);
|
||||
},
|
||||
},
|
||||
body_tracker);
|
||||
@@ -591,6 +589,18 @@ void scenes::stream::tracking()
|
||||
}
|
||||
#endif
|
||||
|
||||
if (auto fb = std::get_if<xr::fb_body_tracker>(&body_tracker); fb and fb->should_send_skeleton())
|
||||
{
|
||||
try
|
||||
{
|
||||
network_session->send_control(fb->get_skeleton());
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
spdlog::warn("Failed to send body skeleton: {}", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
packets.resize(std::max(packets.size(), 1 + hands.size() + body.size()));
|
||||
size_t packet_count = 0;
|
||||
|
||||
@@ -609,12 +619,14 @@ void scenes::stream::tracking()
|
||||
}
|
||||
for (const auto & i: body)
|
||||
{
|
||||
if (i.poses)
|
||||
{
|
||||
auto & packet = packets[packet_count++];
|
||||
packet.clear();
|
||||
wivrn_session::stream_socket_t::serialize(packet, i);
|
||||
}
|
||||
auto & packet = packets[packet_count++];
|
||||
packet.clear();
|
||||
std::visit(utils::overloaded{
|
||||
[&](auto & p) {
|
||||
wivrn_session::stream_socket_t::serialize(packet, p);
|
||||
},
|
||||
},
|
||||
i);
|
||||
}
|
||||
|
||||
network_session->send_stream(std::span(packets.data(), packet_count));
|
||||
|
||||
+23
-13
@@ -18,18 +18,23 @@
|
||||
|
||||
#include "body_tracker.h"
|
||||
|
||||
#include "xr/fb_body_tracker.h"
|
||||
#include "xr/htc_exts.h"
|
||||
#include "xr/instance.h"
|
||||
#include "xr/system.h"
|
||||
#include <openxr/openxr.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))
|
||||
if (instance.has_extension(XR_FB_BODY_TRACKING_EXTENSION_NAME))
|
||||
{
|
||||
auto fb_body_properties = system.fb_body_tracking_properties();
|
||||
if (fb_body_properties.supportsBodyTracking)
|
||||
bool body_supported = system.fb_body_tracking_properties().supportsBodyTracking;
|
||||
bool full_body_supported = instance.has_extension(XR_META_BODY_TRACKING_FULL_BODY_EXTENSION_NAME) and instance.has_extension(XR_META_BODY_TRACKING_FIDELITY_EXTENSION_NAME)
|
||||
? system.meta_body_tracking_properties().supportsFullBodyTracking
|
||||
: false;
|
||||
if (full_body_supported)
|
||||
return body_tracker_type::meta;
|
||||
if (body_supported)
|
||||
return body_tracker_type::fb;
|
||||
}
|
||||
|
||||
@@ -47,19 +52,24 @@ xr::body_tracker_type xr::body_tracker_supported(xr::instance & instance, xr::sy
|
||||
return xr::body_tracker_type::none;
|
||||
}
|
||||
|
||||
xr::body_tracker xr::make_body_tracker(xr::instance & instance, xr::system & system, xr::session & session, std::vector<std::pair<XrPath, xr::space>> & generic_trackers, bool full_body, bool hips)
|
||||
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)
|
||||
{
|
||||
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))
|
||||
if (instance.has_extension(XR_FB_BODY_TRACKING_EXTENSION_NAME))
|
||||
{
|
||||
auto fb_body_properties = system.fb_body_tracking_properties();
|
||||
if (fb_body_properties.supportsBodyTracking)
|
||||
bool body_supported = system.fb_body_tracking_properties().supportsBodyTracking;
|
||||
bool full_body_supported = instance.has_extension(XR_META_BODY_TRACKING_FULL_BODY_EXTENSION_NAME) and
|
||||
instance.has_extension(XR_META_BODY_TRACKING_FIDELITY_EXTENSION_NAME) and
|
||||
system.meta_body_tracking_properties().supportsFullBodyTracking;
|
||||
if (full_body_supported)
|
||||
return xr::body_tracker(std::in_place_type_t<xr::fb_body_tracker>(),
|
||||
instance,
|
||||
session,
|
||||
full_body,
|
||||
hips);
|
||||
full_body);
|
||||
if (body_supported)
|
||||
return xr::body_tracker(std::in_place_type_t<xr::fb_body_tracker>(),
|
||||
instance,
|
||||
session,
|
||||
false);
|
||||
}
|
||||
|
||||
if (not generic_trackers.empty())
|
||||
|
||||
@@ -36,7 +36,7 @@ class session;
|
||||
|
||||
using body_tracker = std::variant<std::monostate, xr::fb_body_tracker, xr::htc_body_tracker, xr::pico_body_tracker>;
|
||||
|
||||
body_tracker make_body_tracker(xr::instance &, xr::system &, xr::session &, std::vector<std::pair<XrPath, xr::space>> & generic_trackers, bool full_body, bool hips);
|
||||
body_tracker make_body_tracker(xr::instance &, xr::system &, xr::session &, std::vector<std::pair<XrPath, xr::space>> & generic_trackers, bool full_body);
|
||||
|
||||
body_tracker_type body_tracker_supported(xr::instance &, xr::system &);
|
||||
|
||||
|
||||
@@ -18,55 +18,52 @@
|
||||
|
||||
#include "fb_body_tracker.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "utils/overloaded.h"
|
||||
#include "xr/instance.h"
|
||||
#include "xr/session.h"
|
||||
#include "xr/to_string.h"
|
||||
#include <ranges>
|
||||
#include <stdexcept>
|
||||
#include <variant>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
static_assert(xr::fb_body_tracker::joint_whitelist.size() <= wivrn::from_headset::body_tracking::max_tracked_poses);
|
||||
|
||||
std::vector<XrFullBodyJointMETA> xr::fb_body_tracker::get_whitelisted_joints(bool full_body, bool hip)
|
||||
static uint8_t convert_flags(XrSpaceLocationFlags in_flags)
|
||||
{
|
||||
auto whitelisted_joints = std::ranges::filter_view(xr::fb_body_tracker::joint_whitelist, [=](auto joint) {
|
||||
if (!full_body && (joint == XR_FULL_BODY_JOINT_HIPS_META || joint >= XR_FULL_BODY_JOINT_LEFT_UPPER_LEG_META))
|
||||
return false;
|
||||
if (!hip && joint == XR_FULL_BODY_JOINT_HIPS_META)
|
||||
return false;
|
||||
uint8_t flags{};
|
||||
if (in_flags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT)
|
||||
flags |= wivrn::from_headset::meta_body::orientation_valid;
|
||||
if (in_flags & XR_SPACE_LOCATION_POSITION_VALID_BIT)
|
||||
flags |= wivrn::from_headset::meta_body::position_valid;
|
||||
if (in_flags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT)
|
||||
flags |= wivrn::from_headset::meta_body::orientation_tracked;
|
||||
if (in_flags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT)
|
||||
flags |= wivrn::from_headset::meta_body::position_tracked;
|
||||
|
||||
return true;
|
||||
});
|
||||
return {whitelisted_joints.begin(), whitelisted_joints.end()};
|
||||
return flags;
|
||||
}
|
||||
|
||||
xr::fb_body_tracker::fb_body_tracker(instance & inst, session & s, bool full_body, bool hip) :
|
||||
xr::fb_body_tracker::fb_body_tracker(instance & inst, session & s, bool lower_body) :
|
||||
handle(inst.get_proc<PFN_xrDestroyBodyTrackerFB>("xrDestroyBodyTrackerFB")),
|
||||
xrRequestBodyTrackingFidelityMETA(inst.get_proc<PFN_xrRequestBodyTrackingFidelityMETA>("xrRequestBodyTrackingFidelityMETA")),
|
||||
xrLocateBodyJointsFB(inst.get_proc<PFN_xrLocateBodyJointsFB>("xrLocateBodyJointsFB")),
|
||||
full_body(full_body),
|
||||
hip(hip)
|
||||
xrGetBodySkeletonFB(inst.get_proc<PFN_xrGetBodySkeletonFB>("xrGetBodySkeletonFB")),
|
||||
joint_set(lower_body ? XR_BODY_JOINT_SET_FULL_BODY_META : XR_BODY_JOINT_SET_DEFAULT_FB)
|
||||
{
|
||||
auto xrCreateBodyTrackerFB = inst.get_proc<PFN_xrCreateBodyTrackerFB>("xrCreateBodyTrackerFB");
|
||||
|
||||
XrBodyTrackerCreateInfoFB create_info{
|
||||
.type = XR_TYPE_BODY_TRACKER_CREATE_INFO_FB,
|
||||
.bodyJointSet = full_body
|
||||
? XR_BODY_JOINT_SET_FULL_BODY_META
|
||||
: XR_BODY_JOINT_SET_DEFAULT_FB,
|
||||
.bodyJointSet = joint_set,
|
||||
};
|
||||
|
||||
CHECK_XR(xrCreateBodyTrackerFB(s, &create_info, &id));
|
||||
|
||||
// Enable IOBT.
|
||||
CHECK_XR(xrRequestBodyTrackingFidelityMETA(id, XR_BODY_TRACKING_FIDELITY_HIGH_META));
|
||||
|
||||
whitelisted_joints = get_whitelisted_joints(full_body, hip);
|
||||
}
|
||||
|
||||
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)
|
||||
xr::fb_body_tracker::packet_type xr::fb_body_tracker::locate_spaces(XrTime time, XrSpace reference)
|
||||
{
|
||||
if (!id)
|
||||
return std::nullopt;
|
||||
xr::fb_body_tracker::packet_type ret{};
|
||||
|
||||
assert(xrLocateBodyJointsFB);
|
||||
|
||||
@@ -81,44 +78,84 @@ std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_h
|
||||
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),
|
||||
.jointCount = (uint32_t)(joint_set == XR_BODY_JOINT_SET_FULL_BODY_META
|
||||
? std::to_underlying(XR_FULL_BODY_JOINT_COUNT_META)
|
||||
: std::to_underlying(XR_BODY_JOINT_COUNT_FB)),
|
||||
.jointLocations = joints.data(),
|
||||
};
|
||||
|
||||
if (auto res = xrLocateBodyJointsFB(id, &locate_info, &joint_locations); !XR_SUCCEEDED(res))
|
||||
{
|
||||
spdlog::warn("xrLocateBodyJointsFB returned {}", xr::to_string(res));
|
||||
return std::nullopt;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!joint_locations.isActive)
|
||||
{
|
||||
spdlog::warn("Body tracker is not active.");
|
||||
return std::nullopt;
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses> poses{};
|
||||
int num_poses = 0;
|
||||
for (auto joint: whitelisted_joints)
|
||||
{
|
||||
const auto & joint_loc = joints[joint];
|
||||
wivrn::from_headset::body_tracking::pose pose{
|
||||
.pose = joint_loc.pose,
|
||||
.flags = 0,
|
||||
};
|
||||
skeleton_generation = joint_locations.skeletonChangedCount;
|
||||
ret.confidence = joint_locations.confidence;
|
||||
const auto & root = joints[XR_BODY_JOINT_ROOT_FB];
|
||||
|
||||
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;
|
||||
}
|
||||
if (joint_set == XR_BODY_JOINT_SET_FULL_BODY_META)
|
||||
ret.joints.emplace<wivrn::from_headset::meta_body::meta_joints>();
|
||||
else
|
||||
ret.joints.emplace<wivrn::from_headset::meta_body::fb_joints>();
|
||||
|
||||
poses[num_poses++] = pose;
|
||||
}
|
||||
return poses;
|
||||
std::visit(utils::overloaded{
|
||||
[](std::monostate) {},
|
||||
[&root, &joints](auto & o) {
|
||||
o.root = {
|
||||
.position = root.pose.position,
|
||||
.orientation = pack(root.pose.orientation),
|
||||
.flags = convert_flags(root.locationFlags),
|
||||
};
|
||||
for (size_t joint = XR_BODY_JOINT_HIPS_FB; joint < std::size(o.joints) + 1; joint++)
|
||||
{
|
||||
const auto & loc = joints[joint];
|
||||
o.joints[joint - 1] = {
|
||||
.position = {
|
||||
.x = int16_t((loc.pose.position.x - root.pose.position.x) * 10'000.f),
|
||||
.y = int16_t((loc.pose.position.y - root.pose.position.y) * 10'000.f),
|
||||
.z = int16_t((loc.pose.position.z - root.pose.position.z) * 10'000.f)},
|
||||
.orientation = pack(loc.pose.orientation),
|
||||
.flags = convert_flags(loc.locationFlags),
|
||||
};
|
||||
}
|
||||
},
|
||||
},
|
||||
ret.joints);
|
||||
|
||||
return ret;
|
||||
}
|
||||
bool xr::fb_body_tracker::should_send_skeleton()
|
||||
{
|
||||
return last_sent_skeleton_generation != skeleton_generation;
|
||||
}
|
||||
wivrn::from_headset::meta_body_skeleton xr::fb_body_tracker::get_skeleton()
|
||||
{
|
||||
wivrn::from_headset::meta_body_skeleton ret{};
|
||||
if (joint_set == XR_BODY_JOINT_SET_FULL_BODY_META)
|
||||
ret.skeleton.emplace<wivrn::from_headset::meta_body_skeleton::meta_skeleton>();
|
||||
else
|
||||
ret.skeleton.emplace<wivrn::from_headset::meta_body_skeleton::fb_skeleton>();
|
||||
|
||||
XrBodySkeletonFB skeleton{
|
||||
.type = XR_TYPE_BODY_SKELETON_FB,
|
||||
};
|
||||
std::visit(utils::overloaded{
|
||||
[&skeleton](auto & s) {
|
||||
skeleton.joints = s.joints.data();
|
||||
skeleton.jointCount = s.joints.size();
|
||||
}},
|
||||
ret.skeleton);
|
||||
if (auto res = xrGetBodySkeletonFB(id, &skeleton); !XR_SUCCEEDED(res))
|
||||
{
|
||||
throw std::runtime_error(std::format("xrGetBodySkeletonFB returned {}", xr::to_string(res)));
|
||||
}
|
||||
|
||||
last_sent_skeleton_generation = skeleton_generation;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -21,8 +21,6 @@
|
||||
#include "wivrn_packets.h"
|
||||
|
||||
#include "utils/handle.h"
|
||||
#include <array>
|
||||
#include <optional>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
namespace xr
|
||||
@@ -34,28 +32,19 @@ class fb_body_tracker : public utils::handle<XrBodyTrackerFB>
|
||||
{
|
||||
PFN_xrRequestBodyTrackingFidelityMETA xrRequestBodyTrackingFidelityMETA{};
|
||||
PFN_xrLocateBodyJointsFB xrLocateBodyJointsFB{};
|
||||
PFN_xrGetBodySkeletonFB xrGetBodySkeletonFB{};
|
||||
|
||||
bool full_body{};
|
||||
bool hip{};
|
||||
std::vector<XrFullBodyJointMETA> whitelisted_joints{};
|
||||
XrBodyJointSetFB joint_set{};
|
||||
uint32_t last_sent_skeleton_generation = static_cast<uint32_t>(-1);
|
||||
uint32_t skeleton_generation = 0;
|
||||
|
||||
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,
|
||||
using packet_type = wivrn::from_headset::meta_body;
|
||||
|
||||
XR_FULL_BODY_JOINT_LEFT_LOWER_LEG_META,
|
||||
XR_FULL_BODY_JOINT_RIGHT_LOWER_LEG_META,
|
||||
fb_body_tracker(instance & inst, session & s, bool lower_body);
|
||||
|
||||
XR_FULL_BODY_JOINT_LEFT_FOOT_TRANSVERSE_META,
|
||||
XR_FULL_BODY_JOINT_RIGHT_FOOT_TRANSVERSE_META,
|
||||
};
|
||||
static std::vector<XrFullBodyJointMETA> get_whitelisted_joints(bool full_body, bool hip);
|
||||
|
||||
fb_body_tracker(instance & inst, session & s, bool full_body, bool hip);
|
||||
|
||||
std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses>> locate_spaces(XrTime time, XrSpace reference);
|
||||
packet_type locate_spaces(XrTime time, XrSpace reference);
|
||||
bool should_send_skeleton();
|
||||
wivrn::from_headset::meta_body_skeleton get_skeleton() noexcept(false);
|
||||
};
|
||||
} // namespace xr
|
||||
|
||||
@@ -57,7 +57,7 @@ XrSpace xr::vive_xr_tracker::get_space() const
|
||||
return space;
|
||||
}
|
||||
|
||||
static wivrn::from_headset::body_tracking::pose locate_space(XrSpace space, XrSpace reference, XrTime time)
|
||||
static wivrn::from_headset::htc_body::pose locate_space(XrSpace space, XrSpace reference, XrTime time)
|
||||
{
|
||||
XrSpaceVelocity velocity{
|
||||
.type = XR_TYPE_SPACE_VELOCITY,
|
||||
@@ -70,22 +70,22 @@ static wivrn::from_headset::body_tracking::pose locate_space(XrSpace space, XrSp
|
||||
|
||||
xrLocateSpace(space, reference, time, &location);
|
||||
|
||||
wivrn::from_headset::body_tracking::pose res{
|
||||
wivrn::from_headset::htc_body::pose res{
|
||||
.pose = location.pose,
|
||||
.flags = 0,
|
||||
};
|
||||
|
||||
if (location.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT)
|
||||
res.flags |= wivrn::from_headset::body_tracking::orientation_valid;
|
||||
res.flags |= wivrn::from_headset::htc_body::orientation_valid;
|
||||
|
||||
if (location.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT)
|
||||
res.flags |= wivrn::from_headset::body_tracking::position_valid;
|
||||
res.flags |= wivrn::from_headset::htc_body::position_valid;
|
||||
|
||||
if (location.locationFlags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT)
|
||||
res.flags |= wivrn::from_headset::body_tracking::orientation_tracked;
|
||||
res.flags |= wivrn::from_headset::htc_body::orientation_tracked;
|
||||
|
||||
if (location.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT)
|
||||
res.flags |= wivrn::from_headset::body_tracking::position_tracked;
|
||||
res.flags |= wivrn::from_headset::htc_body::position_tracked;
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -104,22 +104,22 @@ void xr::htc_body_tracker::update_active()
|
||||
tracker.update_active(s);
|
||||
}
|
||||
|
||||
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)
|
||||
xr::htc_body_tracker::packet_type 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> poses{};
|
||||
xr::htc_body_tracker::packet_type ret{};
|
||||
|
||||
for (int i = 0; i < trackers.size(); i++)
|
||||
for (size_t i = 0; i < trackers.size(); i++)
|
||||
{
|
||||
auto & tracker = trackers[i];
|
||||
wivrn::from_headset::body_tracking::pose pose{
|
||||
wivrn::from_headset::htc_body::pose pose{
|
||||
.pose = {},
|
||||
.flags = 0,
|
||||
};
|
||||
if (tracker.get_active())
|
||||
pose = locate_space(tracker.get_space(), reference, time);
|
||||
|
||||
poses[i] = pose;
|
||||
ret.poses[i] = pose;
|
||||
}
|
||||
|
||||
return poses;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -49,9 +49,10 @@ class htc_body_tracker
|
||||
std::vector<vive_xr_tracker> trackers;
|
||||
|
||||
public:
|
||||
using packet_type = wivrn::from_headset::htc_body;
|
||||
htc_body_tracker(session & s, std::vector<std::pair<XrPath, xr::space>> & trackers);
|
||||
|
||||
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);
|
||||
packet_type locate_spaces(XrTime time, XrSpace reference);
|
||||
};
|
||||
} // namespace xr
|
||||
|
||||
@@ -23,8 +23,6 @@
|
||||
#include "xr/to_string.h"
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
static_assert(xr::pico_body_tracker::joint_whitelist.size() <= wivrn::from_headset::body_tracking::max_tracked_poses);
|
||||
|
||||
xr::pico_body_tracker::pico_body_tracker(instance & inst, session & s) :
|
||||
handle(inst.get_proc<PFN_xrDestroyBodyTrackerBD>("xrDestroyBodyTrackerBD"))
|
||||
{
|
||||
@@ -41,10 +39,11 @@ xr::pico_body_tracker::pico_body_tracker(instance & inst, session & s) :
|
||||
CHECK_XR(xrCreateBodyTrackerBD(s, &create_info, &id));
|
||||
}
|
||||
|
||||
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)
|
||||
xr::pico_body_tracker::packet_type xr::pico_body_tracker::locate_spaces(XrTime time, XrSpace reference)
|
||||
{
|
||||
xr::pico_body_tracker::packet_type ret{};
|
||||
if (!xrLocateBodyJointsBD)
|
||||
return std::nullopt;
|
||||
return ret;
|
||||
|
||||
XrBodyJointsLocateInfoBD locate_info{
|
||||
.type = XR_TYPE_BODY_JOINTS_LOCATE_INFO_BD,
|
||||
@@ -64,29 +63,26 @@ std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_h
|
||||
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;
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses> poses{};
|
||||
int num_poses = 0;
|
||||
for (auto joint: joint_whitelist)
|
||||
ret.all_tracked = joint_locations.allJointPosesTracked;
|
||||
for (size_t joint = XR_BODY_JOINT_PELVIS_BD; joint < XR_BODY_JOINT_COUNT_BD; joint++)
|
||||
{
|
||||
const auto & joint_loc = joints[joint];
|
||||
wivrn::from_headset::body_tracking::pose pose{
|
||||
.pose = joint_loc.pose,
|
||||
.flags = 0,
|
||||
auto & joint_loc = joints[joint];
|
||||
ret.joints[joint] = {
|
||||
.position = joint_loc.pose.position,
|
||||
.orientation = pack(joint_loc.pose.orientation),
|
||||
};
|
||||
|
||||
if (joint_loc.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT)
|
||||
pose.flags |= wivrn::from_headset::body_tracking::orientation_valid;
|
||||
ret.joints[joint].flags |= wivrn::from_headset::bd_body::orientation_valid;
|
||||
if (joint_loc.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT)
|
||||
pose.flags |= wivrn::from_headset::body_tracking::position_valid;
|
||||
ret.joints[joint].flags |= wivrn::from_headset::bd_body::position_valid;
|
||||
if (joint_loc.locationFlags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT)
|
||||
pose.flags |= wivrn::from_headset::body_tracking::orientation_tracked;
|
||||
ret.joints[joint].flags |= wivrn::from_headset::bd_body::orientation_tracked;
|
||||
if (joint_loc.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT)
|
||||
pose.flags |= wivrn::from_headset::body_tracking::position_tracked;
|
||||
|
||||
poses[num_poses++] = pose;
|
||||
ret.joints[joint].flags |= wivrn::from_headset::bd_body::position_tracked;
|
||||
}
|
||||
return poses;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -21,8 +21,6 @@
|
||||
#include "utils/handle.h"
|
||||
#include "wivrn_packets.h"
|
||||
|
||||
#include <array>
|
||||
#include <optional>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
namespace xr
|
||||
@@ -35,19 +33,9 @@ class pico_body_tracker : public utils::handle<XrBodyTrackerBD>
|
||||
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,
|
||||
};
|
||||
|
||||
using packet_type = wivrn::from_headset::bd_body;
|
||||
pico_body_tracker(instance & inst, session & s);
|
||||
|
||||
std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses>> locate_spaces(XrTime time, XrSpace reference);
|
||||
packet_type locate_spaces(XrTime time, XrSpace reference);
|
||||
};
|
||||
} // namespace xr
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "xr/check.h"
|
||||
#include "xr/instance.h"
|
||||
#include <cassert>
|
||||
#include <stdexcept>
|
||||
#include <openxr/openxr_platform.h>
|
||||
|
||||
xr::system::system(xr::instance & inst, XrFormFactor formfactor)
|
||||
@@ -205,6 +206,23 @@ XrSystemBodyTrackingPropertiesFB xr::system::fb_body_tracking_properties() const
|
||||
|
||||
return body_tracking_prop;
|
||||
}
|
||||
XrSystemPropertiesBodyTrackingFullBodyMETA xr::system::meta_body_tracking_properties() const
|
||||
{
|
||||
if (!id)
|
||||
throw std::invalid_argument("this");
|
||||
|
||||
XrSystemPropertiesBodyTrackingFullBodyMETA body_tracking_prop{
|
||||
.type = XR_TYPE_SYSTEM_PROPERTIES_BODY_TRACKING_FULL_BODY_META,
|
||||
};
|
||||
|
||||
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
|
||||
{
|
||||
|
||||
@@ -43,6 +43,7 @@ enum class body_tracker_type
|
||||
{
|
||||
none,
|
||||
fb,
|
||||
meta,
|
||||
htc,
|
||||
pico,
|
||||
};
|
||||
@@ -89,6 +90,7 @@ public:
|
||||
XrSystemFaceTrackingProperties2FB fb_face_tracking2_properties() const;
|
||||
XrSystemFacialTrackingPropertiesHTC htc_face_tracking_properties() const;
|
||||
XrSystemBodyTrackingPropertiesFB fb_body_tracking_properties() const;
|
||||
XrSystemPropertiesBodyTrackingFullBodyMETA meta_body_tracking_properties() const;
|
||||
XrSystemBodyTrackingPropertiesBD bd_body_tracking_properties() const;
|
||||
|
||||
bool hand_tracking_supported() const;
|
||||
|
||||
+97
-4
@@ -253,7 +253,7 @@ struct visibility_mask_changed
|
||||
uint8_t view_index;
|
||||
};
|
||||
|
||||
enum face_type : uint8_t
|
||||
enum class face_type : uint8_t
|
||||
{
|
||||
none,
|
||||
android,
|
||||
@@ -261,6 +261,15 @@ enum face_type : uint8_t
|
||||
htc,
|
||||
};
|
||||
|
||||
enum class body_type : uint8_t
|
||||
{
|
||||
none,
|
||||
fb,
|
||||
meta,
|
||||
bd,
|
||||
htc,
|
||||
};
|
||||
|
||||
struct settings_changed
|
||||
{
|
||||
float preferred_refresh_rate;
|
||||
@@ -300,6 +309,8 @@ struct headset_info_packet
|
||||
bool user_presence;
|
||||
bool passthrough;
|
||||
face_type face_tracking;
|
||||
body_type body_tracking;
|
||||
// htc body only
|
||||
uint32_t num_generic_trackers;
|
||||
std::vector<video_codec> supported_codecs; // from preferred to least preferred
|
||||
std::optional<uint8_t> bit_depth;
|
||||
@@ -434,7 +445,86 @@ struct hand_tracking
|
||||
std::optional<std::array<pose, XR_HAND_JOINT_COUNT_EXT>> joints;
|
||||
};
|
||||
|
||||
struct body_tracking
|
||||
struct meta_body
|
||||
{
|
||||
enum flags : uint8_t
|
||||
{
|
||||
orientation_valid = 1 << 0,
|
||||
position_valid = 1 << 1,
|
||||
orientation_tracked = 1 << 2,
|
||||
position_tracked = 1 << 3,
|
||||
};
|
||||
struct pose
|
||||
{
|
||||
XrVector3f position;
|
||||
packed_quaternion orientation;
|
||||
uint8_t flags;
|
||||
};
|
||||
struct packed_pose
|
||||
{
|
||||
struct
|
||||
{
|
||||
int16_t x, y, z; // 10th of mm relative to root
|
||||
} position;
|
||||
packed_quaternion orientation;
|
||||
uint8_t flags;
|
||||
};
|
||||
|
||||
XrTime production_timestamp;
|
||||
XrTime timestamp;
|
||||
float confidence;
|
||||
|
||||
struct fb_joints
|
||||
{
|
||||
pose root;
|
||||
// excluding root
|
||||
std::array<packed_pose, XR_BODY_JOINT_COUNT_FB - 1> joints;
|
||||
};
|
||||
struct meta_joints
|
||||
{
|
||||
pose root;
|
||||
// excluding root
|
||||
std::array<packed_pose, XR_FULL_BODY_JOINT_COUNT_META - 1> joints;
|
||||
};
|
||||
std::variant<std::monostate, fb_joints, meta_joints> joints;
|
||||
};
|
||||
|
||||
struct meta_body_skeleton
|
||||
{
|
||||
struct fb_skeleton
|
||||
{
|
||||
std::array<XrBodySkeletonJointFB, XR_BODY_JOINT_COUNT_FB> joints;
|
||||
};
|
||||
struct meta_skeleton
|
||||
{
|
||||
std::array<XrBodySkeletonJointFB, XR_FULL_BODY_JOINT_COUNT_META> joints;
|
||||
};
|
||||
std::variant<fb_skeleton, meta_skeleton> skeleton;
|
||||
};
|
||||
|
||||
struct bd_body
|
||||
{
|
||||
enum flags : uint8_t
|
||||
{
|
||||
orientation_valid = 1 << 0,
|
||||
position_valid = 1 << 1,
|
||||
orientation_tracked = 1 << 2,
|
||||
position_tracked = 1 << 3,
|
||||
};
|
||||
struct pose
|
||||
{
|
||||
XrVector3f position;
|
||||
packed_quaternion orientation;
|
||||
uint8_t flags;
|
||||
};
|
||||
|
||||
bool all_tracked;
|
||||
XrTime production_timestamp;
|
||||
XrTime timestamp;
|
||||
std::array<pose, XR_BODY_JOINT_COUNT_BD> joints;
|
||||
};
|
||||
|
||||
struct htc_body
|
||||
{
|
||||
inline static const size_t max_tracked_poses = 16;
|
||||
enum flags : uint8_t
|
||||
@@ -453,7 +543,7 @@ struct body_tracking
|
||||
|
||||
XrTime production_timestamp;
|
||||
XrTime timestamp;
|
||||
std::optional<std::array<pose, max_tracked_poses>> poses;
|
||||
std::array<pose, max_tracked_poses> poses;
|
||||
};
|
||||
|
||||
struct inputs
|
||||
@@ -607,7 +697,10 @@ using packets = std::variant<
|
||||
tracking,
|
||||
derived_pose,
|
||||
hand_tracking,
|
||||
body_tracking,
|
||||
meta_body,
|
||||
meta_body_skeleton,
|
||||
bd_body,
|
||||
htc_body,
|
||||
inputs,
|
||||
timesync_response,
|
||||
battery,
|
||||
|
||||
@@ -125,6 +125,7 @@ if (WIVRN_BUILD_SERVER)
|
||||
driver/wivrn_eye_tracker.cpp
|
||||
driver/wivrn_gamepad.cpp
|
||||
driver/wivrn_android_face_tracker.cpp
|
||||
driver/wivrn_body_tracker.cpp
|
||||
driver/wivrn_fb_face2_tracker.cpp
|
||||
driver/wivrn_htc_face_tracker.cpp
|
||||
driver/wivrn_generic_tracker.cpp
|
||||
|
||||
@@ -32,8 +32,8 @@ class hand_joints_list : public history<hand_joints_list, xrt_hand_joint_set>
|
||||
public:
|
||||
const int hand_id;
|
||||
|
||||
static xrt_hand_joint_set interpolate(const xrt_hand_joint_set & a, const xrt_hand_joint_set & b, float t);
|
||||
static xrt_hand_joint_set extrapolate(const xrt_hand_joint_set & a, const xrt_hand_joint_set & b, int64_t ta, int64_t tb, int64_t t);
|
||||
xrt_hand_joint_set interpolate(const xrt_hand_joint_set & a, const xrt_hand_joint_set & b, float t);
|
||||
xrt_hand_joint_set extrapolate(const xrt_hand_joint_set & a, const xrt_hand_joint_set & b, int64_t ta, int64_t tb, int64_t t);
|
||||
|
||||
hand_joints_list(int hand_id) :
|
||||
hand_id(hand_id) {}
|
||||
|
||||
@@ -105,7 +105,7 @@ public:
|
||||
{
|
||||
float t = float(after->at_timestamp_ns - at_timestamp_ns) /
|
||||
(after->at_timestamp_ns - before->at_timestamp_ns);
|
||||
return {produced, Derived::interpolate(*before, *after, t)};
|
||||
return {produced, static_cast<Derived *>(this)->interpolate(*before, *after, t)};
|
||||
}
|
||||
|
||||
if (before)
|
||||
|
||||
@@ -49,7 +49,7 @@ struct wivrn_android_face_data
|
||||
class android_face_list : public history<android_face_list, wivrn_android_face_data>
|
||||
{
|
||||
public:
|
||||
static wivrn_android_face_data interpolate(const wivrn_android_face_data & a, const wivrn_android_face_data & b, float t)
|
||||
wivrn_android_face_data interpolate(const wivrn_android_face_data & a, const wivrn_android_face_data & b, float t)
|
||||
{
|
||||
if (not a.is_valid)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,375 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
* Copyright (C) 2026 Sapphire <imsapphire0@gmail.com>
|
||||
*
|
||||
* 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 "wivrn_body_tracker.h"
|
||||
#include "driver/pose_list.h"
|
||||
#include "util/u_logging.h"
|
||||
#include "utils/method.h"
|
||||
#include "utils/overloaded.h"
|
||||
#include "wivrn_packets.h"
|
||||
#include "wivrn_session.h"
|
||||
#include "xrt_cast.h"
|
||||
|
||||
#include "xrt/xrt_defines.h"
|
||||
#include "xrt/xrt_results.h"
|
||||
|
||||
static_assert(std::to_underlying(XR_BODY_JOINT_COUNT_FB) == std::to_underlying(XRT_BODY_JOINT_COUNT_FB));
|
||||
static_assert(std::to_underlying(XR_FULL_BODY_JOINT_COUNT_META) == std::to_underlying(XRT_FULL_BODY_JOINT_COUNT_META));
|
||||
static_assert(XR_BODY_JOINT_COUNT_BD == XRT_BODY_JOINT_COUNT_BD);
|
||||
|
||||
static xrt_space_relation_flags cast_meta_flags(uint8_t in_flags)
|
||||
{
|
||||
std::underlying_type_t<xrt_space_relation_flags> flags = 0;
|
||||
if (in_flags & wivrn::from_headset::meta_body::position_valid)
|
||||
flags |= XRT_SPACE_RELATION_POSITION_VALID_BIT;
|
||||
|
||||
if (in_flags & wivrn::from_headset::meta_body::orientation_valid)
|
||||
flags |= XRT_SPACE_RELATION_ORIENTATION_VALID_BIT;
|
||||
|
||||
if (in_flags & wivrn::from_headset::meta_body::position_tracked)
|
||||
flags |= XRT_SPACE_RELATION_POSITION_TRACKED_BIT;
|
||||
|
||||
if (in_flags & wivrn::from_headset::meta_body::orientation_tracked)
|
||||
flags |= XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT;
|
||||
return xrt_space_relation_flags(flags);
|
||||
}
|
||||
|
||||
static xrt_space_relation_flags cast_bd_flags(uint8_t in_flags)
|
||||
{
|
||||
std::underlying_type_t<xrt_space_relation_flags> flags = 0;
|
||||
if (in_flags & wivrn::from_headset::bd_body::position_valid)
|
||||
flags |= XRT_SPACE_RELATION_POSITION_VALID_BIT;
|
||||
|
||||
if (in_flags & wivrn::from_headset::bd_body::orientation_valid)
|
||||
flags |= XRT_SPACE_RELATION_ORIENTATION_VALID_BIT;
|
||||
|
||||
if (in_flags & wivrn::from_headset::bd_body::position_tracked)
|
||||
flags |= XRT_SPACE_RELATION_POSITION_TRACKED_BIT;
|
||||
|
||||
if (in_flags & wivrn::from_headset::bd_body::orientation_tracked)
|
||||
flags |= XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT;
|
||||
return xrt_space_relation_flags(flags);
|
||||
}
|
||||
|
||||
static xrt_space_relation to_relation(const wivrn::from_headset::meta_body::pose & pose)
|
||||
{
|
||||
return {
|
||||
.relation_flags = cast_meta_flags(pose.flags),
|
||||
.pose = xrt_cast(XrPosef{
|
||||
.orientation = pose.orientation,
|
||||
.position = pose.position,
|
||||
}),
|
||||
};
|
||||
}
|
||||
static xrt_space_relation to_relation(const wivrn::from_headset::bd_body::pose & pose)
|
||||
{
|
||||
return {
|
||||
.relation_flags = cast_bd_flags(pose.flags),
|
||||
.pose = xrt_cast(XrPosef{
|
||||
.orientation = pose.orientation,
|
||||
.position = pose.position,
|
||||
}),
|
||||
};
|
||||
}
|
||||
static xrt_space_relation to_relation(const wivrn::from_headset::meta_body::pose & base, const wivrn::from_headset::meta_body::packed_pose & pose)
|
||||
{
|
||||
return {
|
||||
.relation_flags = cast_meta_flags(pose.flags),
|
||||
.pose = xrt_cast(XrPosef{
|
||||
.orientation = pose.orientation,
|
||||
.position = {
|
||||
.x = base.position.x + float(pose.position.x / 10'000.f),
|
||||
.y = base.position.y + float(pose.position.y / 10'000.f),
|
||||
.z = base.position.z + float(pose.position.z / 10'000.f),
|
||||
},
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
static inline bool is_joint_set_active(wivrn::from_headset::body_type body_type, const xrt_body_joint_set & set)
|
||||
{
|
||||
switch (body_type)
|
||||
{
|
||||
case wivrn::from_headset::body_type::fb:
|
||||
case wivrn::from_headset::body_type::meta:
|
||||
return set.base_body_joint_set_meta.is_active;
|
||||
case wivrn::from_headset::body_type::bd:
|
||||
return set.body_joint_set_bd.is_active;
|
||||
default:
|
||||
assert(false);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void interpolate_joints(const T & a, const T & b, T & out, float t)
|
||||
{
|
||||
for (auto [a, b, out]: std::views::zip(a.joint_locations, b.joint_locations, out.joint_locations))
|
||||
out.relation = wivrn::pose_list::interpolate(a.relation, b.relation, t);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void extrapolate_joints(const T & a, const T & b, T & out, int64_t ta, int64_t tb, int64_t t)
|
||||
{
|
||||
for (auto [a, b, out]: std::views::zip(a.joint_locations, b.joint_locations, out.joint_locations))
|
||||
out.relation = wivrn::pose_list::extrapolate(a.relation, b.relation, ta, tb, t);
|
||||
}
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
xrt_body_joint_set body_joints_list::interpolate(const xrt_body_joint_set & a, const xrt_body_joint_set & b, float t)
|
||||
{
|
||||
if (not is_joint_set_active(type, a))
|
||||
{
|
||||
// in case neither is valid, both will be zeroed,
|
||||
// so return the later one for timestamp's sake
|
||||
return b;
|
||||
}
|
||||
else if (not is_joint_set_active(type, b))
|
||||
{
|
||||
return a;
|
||||
}
|
||||
|
||||
xrt_body_joint_set result = b;
|
||||
switch (type)
|
||||
{
|
||||
case wivrn::from_headset::body_type::fb:
|
||||
interpolate_joints(a.body_joint_set_fb, b.body_joint_set_fb, result.body_joint_set_fb, t);
|
||||
break;
|
||||
case wivrn::from_headset::body_type::meta:
|
||||
interpolate_joints(a.full_body_joint_set_meta, b.full_body_joint_set_meta, result.full_body_joint_set_meta, t);
|
||||
break;
|
||||
case wivrn::from_headset::body_type::bd:
|
||||
interpolate_joints(a.body_joint_set_bd, b.body_joint_set_bd, result.body_joint_set_bd, t);
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
xrt_body_joint_set body_joints_list::extrapolate(const xrt_body_joint_set & a, const xrt_body_joint_set & b, int64_t ta, int64_t tb, int64_t t)
|
||||
{
|
||||
if (not is_joint_set_active(type, a))
|
||||
{
|
||||
// in case neither is valid, both will be zeroed,
|
||||
// so return the later one for timestamp's sake
|
||||
return b;
|
||||
}
|
||||
else if (not is_joint_set_active(type, b))
|
||||
{
|
||||
return a;
|
||||
}
|
||||
|
||||
xrt_body_joint_set result = b;
|
||||
switch (type)
|
||||
{
|
||||
case wivrn::from_headset::body_type::fb:
|
||||
extrapolate_joints(a.body_joint_set_fb, b.body_joint_set_fb, result.body_joint_set_fb, ta, tb, t);
|
||||
break;
|
||||
case wivrn::from_headset::body_type::meta:
|
||||
extrapolate_joints(a.full_body_joint_set_meta, b.full_body_joint_set_meta, result.full_body_joint_set_meta, ta, tb, t);
|
||||
break;
|
||||
case wivrn::from_headset::body_type::bd:
|
||||
extrapolate_joints(a.body_joint_set_bd, b.body_joint_set_bd, result.body_joint_set_bd, ta, tb, t);
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void body_joints_list::update_tracking(const wivrn::from_headset::meta_body & tracking, const clock_offset & offset)
|
||||
{
|
||||
assert(type == from_headset::body_type::fb or type == from_headset::body_type::meta);
|
||||
|
||||
xrt_body_joint_set s{
|
||||
.base_body_joint_set_meta = {
|
||||
.sample_time_ns = tracking.timestamp,
|
||||
.confidence = tracking.confidence,
|
||||
.is_active = not std::holds_alternative<std::monostate>(tracking.joints),
|
||||
},
|
||||
};
|
||||
if (s.base_body_joint_set_meta.is_active)
|
||||
{
|
||||
std::visit(utils::overloaded{
|
||||
[](std::monostate) {
|
||||
__builtin_unreachable();
|
||||
},
|
||||
[&](auto & joints) {
|
||||
s.body_joint_set_fb.joint_locations[XRT_BODY_JOINT_ROOT_FB].relation = to_relation(joints.root);
|
||||
for (size_t joint = XRT_BODY_JOINT_HIPS_FB; joint < std::size(joints.joints) + 1; joint++)
|
||||
{
|
||||
static_assert(offsetof(xrt_full_body_joint_set_meta, joint_locations) == offsetof(xrt_body_joint_set_fb, joint_locations));
|
||||
static_assert(sizeof(xrt_full_body_joint_set_meta::joint_locations[0]) == sizeof(xrt_body_joint_set_fb::joint_locations[0]));
|
||||
s.full_body_joint_set_meta.joint_locations[joint].relation = to_relation(joints.root, joints.joints[joint - 1]);
|
||||
}
|
||||
}},
|
||||
tracking.joints);
|
||||
}
|
||||
|
||||
add_sample(tracking.production_timestamp, tracking.timestamp, s, offset);
|
||||
}
|
||||
void body_joints_list::update_tracking(const wivrn::from_headset::bd_body & tracking, const clock_offset & offset)
|
||||
{
|
||||
assert(type == from_headset::body_type::bd);
|
||||
|
||||
xrt_body_joint_set s{
|
||||
.body_joint_set_bd = {
|
||||
.sample_time_ns = tracking.timestamp,
|
||||
.is_active = true, // FIXME: what is this supposed to be?
|
||||
.all_joint_poses_tracked = tracking.all_tracked,
|
||||
},
|
||||
};
|
||||
for (size_t joint = XRT_BODY_JOINT_PELVIS_BD; joint < XRT_BODY_JOINT_COUNT_BD; joint++)
|
||||
{
|
||||
s.body_joint_set_bd.joint_locations[joint].relation = to_relation(tracking.joints[joint]);
|
||||
}
|
||||
|
||||
add_sample(tracking.production_timestamp, tracking.timestamp, s, offset);
|
||||
}
|
||||
|
||||
wivrn_body_tracker::wivrn_body_tracker(xrt_device * hmd, wivrn::wivrn_session & cnx) :
|
||||
xrt_device{
|
||||
.name = XRT_DEVICE_FB_BODY_TRACKING, // FIXME: replace with something more appropriate, when there is one
|
||||
.device_type = XRT_DEVICE_TYPE_BODY_TRACKER,
|
||||
.tracking_origin = hmd->tracking_origin,
|
||||
.supported = {
|
||||
.body_tracking = true,
|
||||
},
|
||||
.update_inputs = method_pointer<&wivrn_body_tracker::update_inputs>,
|
||||
.get_body_skeleton = method_pointer<&wivrn_body_tracker::get_body_skeleton>,
|
||||
.get_body_joints = method_pointer<&wivrn_body_tracker::get_body_joints>,
|
||||
.destroy = [](xrt_device *) {},
|
||||
},
|
||||
joints_list(cnx.get_info().body_tracking),
|
||||
cnx(cnx)
|
||||
{
|
||||
switch (cnx.get_info().body_tracking)
|
||||
{
|
||||
case from_headset::body_type::meta:
|
||||
strcpy(str, "WiVRn Meta body tracker");
|
||||
strcpy(serial, "WiVRn Meta body tracker");
|
||||
inputs_array.push_back({
|
||||
.active = true,
|
||||
.name = XRT_INPUT_FB_BODY_TRACKING,
|
||||
});
|
||||
inputs_array.push_back({
|
||||
.active = true,
|
||||
.name = XRT_INPUT_META_FULL_BODY_TRACKING,
|
||||
});
|
||||
break;
|
||||
case from_headset::body_type::fb:
|
||||
strcpy(str, "WiVRn FB body tracker");
|
||||
strcpy(serial, "WiVRn FB body tracker");
|
||||
inputs_array.push_back({
|
||||
.active = true,
|
||||
.name = XRT_INPUT_FB_BODY_TRACKING,
|
||||
});
|
||||
break;
|
||||
case from_headset::body_type::bd:
|
||||
strcpy(str, "WiVRn BD body Tracker");
|
||||
strcpy(serial, "WiVRn BD body tracker");
|
||||
inputs_array.push_back({
|
||||
.active = true,
|
||||
.name = XRT_INPUT_BD_BODY_TRACKING,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
inputs = inputs_array.data();
|
||||
input_count = inputs_array.size();
|
||||
}
|
||||
|
||||
xrt_result_t wivrn_body_tracker::update_inputs()
|
||||
{
|
||||
return XRT_SUCCESS;
|
||||
}
|
||||
xrt_result_t wivrn_body_tracker::get_body_skeleton(xrt_input_name body_skeleton_type, xrt_body_skeleton * out_value)
|
||||
{
|
||||
if (!std::ranges::contains(inputs_array, body_skeleton_type, &xrt_input::name))
|
||||
{
|
||||
U_LOG_XDEV_UNSUPPORTED_INPUT(this, u_log_get_global_level(), body_skeleton_type);
|
||||
return XRT_ERROR_INPUT_UNSUPPORTED;
|
||||
}
|
||||
|
||||
auto s = this->meta_skeleton.lock();
|
||||
*out_value = *s;
|
||||
return XRT_SUCCESS;
|
||||
}
|
||||
xrt_result_t wivrn_body_tracker::get_body_joints(xrt_input_name body_tracking_type, int64_t at_timestamp_ns, xrt_body_joint_set * out_value)
|
||||
{
|
||||
if (!std::ranges::contains(inputs_array, body_tracking_type, &xrt_input::name))
|
||||
{
|
||||
U_LOG_XDEV_UNSUPPORTED_INPUT(this, u_log_get_global_level(), body_tracking_type);
|
||||
return XRT_ERROR_INPUT_UNSUPPORTED;
|
||||
}
|
||||
|
||||
XrTime production_timestamp;
|
||||
std::tie(production_timestamp, *out_value) = joints_list.get_at(at_timestamp_ns);
|
||||
out_value->body_pose = xrt_space_relation{
|
||||
.relation_flags = xrt_space_relation_flags(XRT_SPACE_RELATION_ORIENTATION_VALID_BIT | XRT_SPACE_RELATION_POSITION_VALID_BIT |
|
||||
XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT | XRT_SPACE_RELATION_POSITION_TRACKED_BIT),
|
||||
.pose = XRT_POSE_IDENTITY,
|
||||
};
|
||||
|
||||
if (body_tracking_type == XRT_INPUT_FB_BODY_TRACKING or body_tracking_type == XRT_INPUT_META_FULL_BODY_TRACKING)
|
||||
out_value->base_body_joint_set_meta.skeleton_changed_count = meta_skeleton_generation;
|
||||
|
||||
cnx.add_tracking_request(device_id::BODY, at_timestamp_ns, production_timestamp);
|
||||
return XRT_SUCCESS;
|
||||
}
|
||||
|
||||
void wivrn_body_tracker::update_tracking(const from_headset::meta_body & tracking, const clock_offset & offset)
|
||||
{
|
||||
joints_list.update_tracking(tracking, offset);
|
||||
}
|
||||
void wivrn_body_tracker::update_tracking(const from_headset::bd_body & tracking, const clock_offset & offset)
|
||||
{
|
||||
joints_list.update_tracking(tracking, offset);
|
||||
}
|
||||
void wivrn_body_tracker::update_skeleton(const from_headset::meta_body_skeleton & skeleton)
|
||||
{
|
||||
assert(std::ranges::contains(inputs_array, XRT_INPUT_FB_BODY_TRACKING, &xrt_input::name));
|
||||
|
||||
auto s = this->meta_skeleton.lock();
|
||||
std::visit(utils::overloaded{
|
||||
[&s](auto & skeleton) {
|
||||
for (size_t i = 0; i < skeleton.joints.size(); i++)
|
||||
{
|
||||
static_assert(offsetof(xrt_full_body_skeleton_meta, joints) == offsetof(xrt_body_skeleton_fb, joints));
|
||||
static_assert(sizeof(xrt_full_body_skeleton_meta::joints[0]) == sizeof(xrt_body_skeleton_fb::joints[0]));
|
||||
const auto & joint = skeleton.joints[i];
|
||||
s->full_body_skeleton_meta.joints[i] = xrt_body_skeleton_joint_fb{
|
||||
.pose = xrt_cast(joint.pose),
|
||||
.joint = joint.joint,
|
||||
.parent_joint = joint.parentJoint,
|
||||
};
|
||||
}
|
||||
}},
|
||||
skeleton.skeleton);
|
||||
meta_skeleton_generation++;
|
||||
}
|
||||
|
||||
} // namespace wivrn
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
* Copyright (C) 2026 Sapphire <imsapphire0@gmail.com>
|
||||
*
|
||||
* 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 "utils/thread_safe.h"
|
||||
#include "xrt/xrt_defines.h"
|
||||
#include "xrt/xrt_device.h"
|
||||
|
||||
#include "history.h"
|
||||
#include "pose_list.h"
|
||||
#include "wivrn_packets.h"
|
||||
|
||||
#include <atomic>
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
class wivrn_session;
|
||||
struct clock_offset;
|
||||
|
||||
class body_joints_list : public history<body_joints_list, xrt_body_joint_set>
|
||||
{
|
||||
wivrn::from_headset::body_type type;
|
||||
|
||||
public:
|
||||
body_joints_list(wivrn::from_headset::body_type type) : type(type) {}
|
||||
xrt_body_joint_set interpolate(const xrt_body_joint_set & a, const xrt_body_joint_set & b, float t);
|
||||
xrt_body_joint_set extrapolate(const xrt_body_joint_set & a, const xrt_body_joint_set & b, int64_t ta, int64_t tb, int64_t t);
|
||||
|
||||
void update_tracking(const wivrn::from_headset::meta_body & tracking, const clock_offset & offset);
|
||||
void update_tracking(const wivrn::from_headset::bd_body & tracking, const clock_offset & offset);
|
||||
};
|
||||
|
||||
class wivrn_body_tracker : public xrt_device
|
||||
{
|
||||
body_joints_list joints_list;
|
||||
std::vector<xrt_input> inputs_array;
|
||||
|
||||
wivrn_session & cnx;
|
||||
|
||||
thread_safe<xrt_body_skeleton> meta_skeleton;
|
||||
std::atomic_uint32_t meta_skeleton_generation;
|
||||
|
||||
public:
|
||||
using base_t = xrt_device;
|
||||
wivrn_body_tracker(xrt_device * hmd, wivrn_session & cnx);
|
||||
|
||||
xrt_result_t update_inputs();
|
||||
xrt_result_t get_body_skeleton(xrt_input_name body_tracking_type, xrt_body_skeleton * out_value);
|
||||
xrt_result_t get_body_joints(xrt_input_name body_tracking_type, int64_t at_timestamp_ns, xrt_body_joint_set * out_value);
|
||||
|
||||
void update_tracking(const from_headset::meta_body &, const clock_offset &);
|
||||
void update_tracking(const from_headset::bd_body &, const clock_offset &);
|
||||
void update_skeleton(const from_headset::meta_body_skeleton &);
|
||||
};
|
||||
|
||||
} // namespace wivrn
|
||||
@@ -54,7 +54,7 @@ struct wivrn_fb_face2_data
|
||||
class fb_face2_list : public history<fb_face2_list, wivrn_fb_face2_data>
|
||||
{
|
||||
public:
|
||||
static wivrn_fb_face2_data interpolate(const wivrn_fb_face2_data & a, const wivrn_fb_face2_data & b, float t)
|
||||
wivrn_fb_face2_data interpolate(const wivrn_fb_face2_data & a, const wivrn_fb_face2_data & b, float t)
|
||||
{
|
||||
if (not a.is_valid)
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
|
||||
* Copyright (C) 2026 Sapphire <imsapphire0@gmail.com>
|
||||
*
|
||||
* 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
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "util/u_logging.h"
|
||||
#include "utils/method.h"
|
||||
#include "wivrn_session.h"
|
||||
#include "xrt_cast.h"
|
||||
|
||||
#include "math/m_api.h"
|
||||
#include "math/m_eigen_interop.hpp"
|
||||
@@ -29,11 +30,27 @@
|
||||
#include "math/m_vec3.h"
|
||||
#include "xrt/xrt_defines.h"
|
||||
#include "xrt/xrt_results.h"
|
||||
#include "xrt_cast.h"
|
||||
#include <format>
|
||||
|
||||
using namespace xrt::auxiliary::math;
|
||||
|
||||
static xrt_space_relation_flags cast_flags(uint8_t in_flags)
|
||||
{
|
||||
std::underlying_type_t<xrt_space_relation_flags> flags{};
|
||||
if (in_flags & wivrn::from_headset::htc_body::orientation_valid)
|
||||
flags |= XRT_SPACE_RELATION_ORIENTATION_VALID_BIT;
|
||||
|
||||
if (in_flags & wivrn::from_headset::htc_body::position_valid)
|
||||
flags |= XRT_SPACE_RELATION_POSITION_VALID_BIT;
|
||||
|
||||
if (in_flags & wivrn::from_headset::htc_body::orientation_tracked)
|
||||
flags |= XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT;
|
||||
|
||||
if (in_flags & wivrn::from_headset::htc_body::position_tracked)
|
||||
flags |= XRT_SPACE_RELATION_POSITION_TRACKED_BIT;
|
||||
return xrt_space_relation_flags(flags);
|
||||
}
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
|
||||
@@ -70,35 +87,13 @@ xrt_space_relation tracker_pose_list::extrapolate(const xrt_space_relation & a,
|
||||
return res;
|
||||
}
|
||||
|
||||
void tracker_pose_list::update_tracking(XrTime produced_timestamp, XrTime timestamp, const from_headset::body_tracking::pose & pose, const clock_offset & offset)
|
||||
void tracker_pose_list::update_tracking(XrTime produced_timestamp, XrTime timestamp, const from_headset::htc_body::pose & pose, const clock_offset & offset)
|
||||
{
|
||||
add_sample(produced_timestamp, timestamp, convert_pose(pose), offset);
|
||||
}
|
||||
|
||||
static xrt_space_relation_flags convert_flags(uint8_t flags)
|
||||
{
|
||||
std::underlying_type_t<xrt_space_relation_flags> 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),
|
||||
xrt_space_relation rel{
|
||||
.relation_flags = cast_flags(pose.flags),
|
||||
.pose = xrt_cast(pose.pose),
|
||||
.linear_velocity = {},
|
||||
.angular_velocity = {},
|
||||
};
|
||||
add_sample(produced_timestamp, timestamp, rel, offset);
|
||||
}
|
||||
|
||||
wivrn_generic_tracker::wivrn_generic_tracker(int index, xrt_device * hmd, wivrn_session & cnx) :
|
||||
@@ -150,8 +145,8 @@ xrt_result_t wivrn_generic_tracker::get_tracked_pose(xrt_input_name name, int64_
|
||||
return XRT_ERROR_INPUT_UNSUPPORTED;
|
||||
}
|
||||
|
||||
void wivrn_generic_tracker::update_tracking(const from_headset::body_tracking & tracking, const from_headset::body_tracking::pose & pose, const clock_offset & offset)
|
||||
void wivrn_generic_tracker::update_tracking(XrTime produced_timestamp, XrTime timestamp, const from_headset::htc_body::pose & pose, const clock_offset & offset)
|
||||
{
|
||||
poses.update_tracking(tracking.production_timestamp, tracking.timestamp, pose, offset);
|
||||
poses.update_tracking(produced_timestamp, timestamp, pose, offset);
|
||||
}
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
|
||||
* Copyright (C) 2026 Sapphire <imsapphire0@gmail.com>
|
||||
*
|
||||
* 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
|
||||
@@ -18,9 +18,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "history.h"
|
||||
#include "xrt/xrt_device.h"
|
||||
|
||||
#include "history.h"
|
||||
#include "wivrn_packets.h"
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
class wivrn_session;
|
||||
@@ -29,14 +31,12 @@ struct clock_offset;
|
||||
class tracker_pose_list : public history<tracker_pose_list, xrt_space_relation>
|
||||
{
|
||||
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);
|
||||
xrt_space_relation interpolate(const xrt_space_relation & a, const xrt_space_relation & b, float t);
|
||||
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;
|
||||
|
||||
void update_tracking(XrTime produced_timestamp, XrTime timestamp, const from_headset::body_tracking::pose & pose, const clock_offset & offset);
|
||||
|
||||
static xrt_space_relation convert_pose(const wivrn::from_headset::body_tracking::pose &);
|
||||
void update_tracking(XrTime produced_timestamp, XrTime timestamp, const wivrn::from_headset::htc_body::pose & pose, const clock_offset & offset);
|
||||
};
|
||||
|
||||
class wivrn_generic_tracker : public xrt_device
|
||||
@@ -53,6 +53,6 @@ public:
|
||||
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);
|
||||
void update_tracking(XrTime produced_timestamp, XrTime timestamp, const wivrn::from_headset::htc_body::pose & pose, const clock_offset & offset);
|
||||
};
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -49,7 +49,7 @@ struct wivrn_htc_face_data
|
||||
class htc_face_list : public history<htc_face_list, wivrn_htc_face_data>
|
||||
{
|
||||
public:
|
||||
static wivrn_htc_face_data interpolate(const wivrn_htc_face_data & a, const wivrn_htc_face_data & b, float t)
|
||||
wivrn_htc_face_data interpolate(const wivrn_htc_face_data & a, const wivrn_htc_face_data & b, float t)
|
||||
{
|
||||
wivrn_htc_face_data result = b;
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
#include "audio/audio_setup.h"
|
||||
#include "wivrn_android_face_tracker.h"
|
||||
#include "wivrn_body_tracker.h"
|
||||
#include "wivrn_config.h"
|
||||
#include "wivrn_eye_tracker.h"
|
||||
#include "wivrn_fb_face2_tracker.h"
|
||||
@@ -194,27 +195,38 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
|
||||
else if (face == wivrn::from_headset::face_type::htc || is_forced_extension("HTC_facial_tracking"))
|
||||
static_xdevs[static_xdev_count++] = static_roles.face = &htc_face_tracker.emplace(&hmd, *this);
|
||||
|
||||
auto num_generic_trackers = get_info().num_generic_trackers;
|
||||
if (num_generic_trackers > 0)
|
||||
auto body = get_info().body_tracking;
|
||||
if (body != from_headset::body_type::none && body != from_headset::body_type::htc)
|
||||
{
|
||||
if (num_generic_trackers > from_headset::body_tracking::max_tracked_poses)
|
||||
static_xdevs[static_xdev_count++] = static_roles.body = &body_tracker.emplace(&hmd, *this);
|
||||
}
|
||||
if (body == from_headset::body_type::htc)
|
||||
{
|
||||
auto num_generic_trackers = get_info().num_generic_trackers;
|
||||
generic_trackers.reserve(num_generic_trackers);
|
||||
if (num_generic_trackers > 0)
|
||||
{
|
||||
U_LOG_W("reported generic trackers %d larger than maximum %lu",
|
||||
num_generic_trackers,
|
||||
from_headset::body_tracking::max_tracked_poses);
|
||||
num_generic_trackers = from_headset::body_tracking::max_tracked_poses;
|
||||
}
|
||||
if (num_generic_trackers + static_xdev_count > std::size(static_xdevs))
|
||||
{
|
||||
U_LOG_W("Too many generic trackers: %d, only %lu will be active",
|
||||
num_generic_trackers,
|
||||
std::size(static_xdevs) - static_xdev_count);
|
||||
num_generic_trackers = std::size(static_xdevs) - static_xdev_count;
|
||||
}
|
||||
U_LOG_I("Creating %d generic trackers", num_generic_trackers);
|
||||
if (num_generic_trackers > from_headset::htc_body::max_tracked_poses)
|
||||
{
|
||||
U_LOG_W("reported generic trackers %d larger than maximum %lu",
|
||||
num_generic_trackers,
|
||||
from_headset::htc_body::max_tracked_poses);
|
||||
num_generic_trackers = from_headset::htc_body::max_tracked_poses;
|
||||
}
|
||||
if (num_generic_trackers + static_xdev_count > std::size(static_xdevs))
|
||||
{
|
||||
U_LOG_W("Too many generic trackers: %d, only %lu will be active",
|
||||
num_generic_trackers,
|
||||
std::size(static_xdevs) - static_xdev_count);
|
||||
num_generic_trackers = std::size(static_xdevs) - static_xdev_count;
|
||||
}
|
||||
U_LOG_I("Creating %d generic trackers", num_generic_trackers);
|
||||
|
||||
for (int i = 0; i < num_generic_trackers; ++i)
|
||||
static_xdevs[static_xdev_count++] = &generic_trackers.emplace_back(i, &hmd, *this);
|
||||
for (int i = 0; i < num_generic_trackers; ++i)
|
||||
{
|
||||
static_xdevs[static_xdev_count++] = &generic_trackers.emplace_back(i, &hmd, *this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if WIVRN_FEATURE_SOLARXR
|
||||
@@ -669,12 +681,33 @@ void wivrn_session::operator()(from_headset::hand_tracking && hand_tracking)
|
||||
left_controller.update_hand_tracking(hand_tracking, offset);
|
||||
right_controller.update_hand_tracking(hand_tracking, offset);
|
||||
}
|
||||
void wivrn_session::operator()(from_headset::body_tracking && body_tracking)
|
||||
|
||||
void wivrn_session::operator()(from_headset::meta_body && body_tracking)
|
||||
{
|
||||
assert(body_tracker);
|
||||
|
||||
auto offset = offset_est.get_offset();
|
||||
body_tracker->update_tracking(body_tracking, offset);
|
||||
}
|
||||
void wivrn_session::operator()(from_headset::meta_body_skeleton && body_skeleton)
|
||||
{
|
||||
assert(body_tracker);
|
||||
|
||||
body_tracker->update_skeleton(body_skeleton);
|
||||
}
|
||||
void wivrn_session::operator()(from_headset::bd_body && body_tracking)
|
||||
{
|
||||
assert(body_tracker);
|
||||
|
||||
auto offset = offset_est.get_offset();
|
||||
body_tracker->update_tracking(body_tracking, offset);
|
||||
}
|
||||
void wivrn_session::operator()(from_headset::htc_body && body_tracking)
|
||||
{
|
||||
auto offset = offset_est.get_offset();
|
||||
|
||||
for (auto [tracker, pose]: std::ranges::zip_view(generic_trackers, *body_tracking.poses))
|
||||
tracker.update_tracking(body_tracking, pose, offset);
|
||||
for (auto [tracker, pose]: std::ranges::zip_view(generic_trackers, body_tracking.poses))
|
||||
tracker.update_tracking(body_tracking.production_timestamp, body_tracking.timestamp, pose, offset);
|
||||
}
|
||||
void wivrn_session::operator()(from_headset::inputs && inputs)
|
||||
{
|
||||
@@ -1209,6 +1242,7 @@ std::pair<bool, std::optional<std::string>> wivrn_session::validate_headset_info
|
||||
refuse |= prev_info.palm_pose != info.palm_pose;
|
||||
refuse |= prev_info.user_presence != info.user_presence;
|
||||
refuse |= prev_info.passthrough != info.passthrough;
|
||||
refuse |= prev_info.body_tracking != info.body_tracking;
|
||||
|
||||
refuse |= prev_info.available_refresh_rates != info.available_refresh_rates;
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "tracking_control.h"
|
||||
#include "utils/thread_safe.h"
|
||||
#include "wivrn_android_face_tracker.h"
|
||||
#include "wivrn_body_tracker.h"
|
||||
#include "wivrn_connection.h"
|
||||
#include "wivrn_controller.h"
|
||||
#include "wivrn_eye_tracker.h"
|
||||
@@ -58,6 +59,7 @@ class wivrn_eye_tracker;
|
||||
class wivrn_android_face_tracker;
|
||||
class wivrn_fb_face2_tracker;
|
||||
class wivrn_htc_face_tracker;
|
||||
class wivrn_body_tracker;
|
||||
class wivrn_generic_tracker;
|
||||
struct audio_device;
|
||||
|
||||
@@ -100,7 +102,8 @@ class wivrn_session : public xrt_system_devices
|
||||
std::optional<wivrn_android_face_tracker> android_face_tracker;
|
||||
std::optional<wivrn_fb_face2_tracker> fb_face2_tracker;
|
||||
std::optional<wivrn_htc_face_tracker> htc_face_tracker;
|
||||
beman::inplace_vector::inplace_vector<wivrn_generic_tracker, from_headset::body_tracking::max_tracked_poses> generic_trackers;
|
||||
std::optional<wivrn_body_tracker> body_tracker;
|
||||
beman::inplace_vector::inplace_vector<wivrn_generic_tracker, from_headset::htc_body::max_tracked_poses> generic_trackers;
|
||||
std::optional<wivrn_uinput> uinput_handler;
|
||||
bool gamepad_connected = false; // network thread only
|
||||
|
||||
@@ -167,7 +170,10 @@ 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::meta_body &&);
|
||||
void operator()(from_headset::meta_body_skeleton &&);
|
||||
void operator()(from_headset::bd_body &&);
|
||||
void operator()(from_headset::htc_body &&);
|
||||
void operator()(from_headset::inputs &&);
|
||||
void operator()(from_headset::hid::input && e);
|
||||
void operator()(from_headset::timesync_response &&);
|
||||
|
||||
Reference in New Issue
Block a user