Forward body skeletons from headset

This commit is contained in:
Sapphire
2026-07-10 13:22:05 -05:00
parent 41c2c0b727
commit 2e28b0a4ad
28 changed files with 858 additions and 236 deletions
+2 -2
View File
@@ -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) {}
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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)
{
+375
View File
@@ -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
+74
View File
@@ -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
+1 -1
View File
@@ -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)
{
+25 -30
View File
@@ -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
+8 -8
View File
@@ -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
+1 -1
View File
@@ -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;
+55 -21
View File
@@ -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;
+8 -2
View File
@@ -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 &&);