Use separate packet to send generic tracker poses
This commit is contained in:
@@ -232,9 +232,11 @@ void scenes::stream::tracking()
|
||||
|
||||
XrTime t0 = instance.now();
|
||||
XrTime last_hand_sample = t0;
|
||||
XrTime last_body_sample = t0;
|
||||
std::vector<from_headset::tracking> tracking;
|
||||
std::vector<from_headset::tracking> tracking_pool; // pre-allocated objects
|
||||
std::vector<from_headset::hand_tracking> hands;
|
||||
std::vector<from_headset::body_tracking> body;
|
||||
std::vector<XrView> views;
|
||||
|
||||
std::vector<from_headset::trackings> merged_tracking;
|
||||
@@ -286,6 +288,7 @@ void scenes::stream::tracking()
|
||||
{
|
||||
tracking.clear();
|
||||
hands.clear();
|
||||
body.clear();
|
||||
|
||||
XrTime now = instance.now();
|
||||
if (now < t0)
|
||||
@@ -355,6 +358,30 @@ void scenes::stream::tracking()
|
||||
locate_hands(application::get_right_hand(), world_space, t0 + Δt));
|
||||
}
|
||||
|
||||
if (body_tracking != body_none and t0 >= last_body_sample + period and
|
||||
(Δt == 0 or Δt >= prediction - 2 * period))
|
||||
{
|
||||
last_body_sample = t0;
|
||||
if (control.enabled[size_t(tid::generic_tracker)])
|
||||
{
|
||||
auto & body_packet = body.emplace_back(from_headset::body_tracking{
|
||||
.production_timestamp = t0,
|
||||
.timestamp = t0 + Δt,
|
||||
});
|
||||
switch (body_tracking)
|
||||
{
|
||||
case body_none:
|
||||
__builtin_unreachable();
|
||||
case body_fb:
|
||||
body_packet.poses = application::get_fb_body_tracker().locate_spaces(t0 + Δt, world_space);
|
||||
break;
|
||||
case body_pico:
|
||||
body_packet.poses = application::get_pico_body_tracker().locate_spaces(t0 + Δt, world_space);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (control.enabled[size_t(tid::face)])
|
||||
{
|
||||
switch (face_tracking)
|
||||
@@ -379,21 +406,6 @@ void scenes::stream::tracking()
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (control.enabled[size_t(tid::generic_tracker)])
|
||||
{
|
||||
switch (body_tracking)
|
||||
{
|
||||
case body_none:
|
||||
break;
|
||||
case body_fb:
|
||||
application::get_fb_body_tracker().locate_spaces(t0 + Δt, packet.device_poses, world_space);
|
||||
break;
|
||||
case body_pico:
|
||||
application::get_pico_body_tracker().locate_spaces(t0 + Δt, packet.device_poses, world_space);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const std::system_error & e)
|
||||
{
|
||||
@@ -443,7 +455,7 @@ void scenes::stream::tracking()
|
||||
merged_tracking.back().items.emplace_back(std::move(item));
|
||||
}
|
||||
|
||||
packets.resize(std::max(packets.size(), merged_tracking.size() + hands.size()));
|
||||
packets.resize(std::max(packets.size(), merged_tracking.size() + hands.size() + body.size()));
|
||||
size_t packet_count = 0;
|
||||
for (const auto & i: merged_tracking)
|
||||
{
|
||||
@@ -460,6 +472,15 @@ void scenes::stream::tracking()
|
||||
wivrn_session::stream_socket_t::serialize(packet, i);
|
||||
}
|
||||
}
|
||||
for (const auto & i: body)
|
||||
{
|
||||
if (i.poses)
|
||||
{
|
||||
auto & packet = packets[packet_count++];
|
||||
packet.clear();
|
||||
wivrn_session::stream_socket_t::serialize(packet, i);
|
||||
}
|
||||
}
|
||||
|
||||
network_session->send_stream(std::span(packets.data(), packet_count));
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#include "xr/xr.h"
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
static_assert(xr::pico_body_tracker::joint_whitelist.size() <= wivrn::from_headset::body_tracking::max_tracked_poses);
|
||||
|
||||
xr::fb_body_tracker::fb_body_tracker(instance & inst, session & s) :
|
||||
s(s)
|
||||
{
|
||||
@@ -61,26 +63,11 @@ void xr::fb_body_tracker::stop()
|
||||
CHECK_XR(xrDestroyBodyTrackerFB(std::exchange(handle, nullptr)));
|
||||
}
|
||||
|
||||
void xr::fb_body_tracker::locate_spaces(XrTime time, std::vector<wivrn::from_headset::tracking::pose> & out_poses, XrSpace reference)
|
||||
std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses>> xr::fb_body_tracker::locate_spaces(XrTime time, XrSpace reference)
|
||||
{
|
||||
auto fill_poses = [&]() {
|
||||
for (auto joint: joint_whitelist)
|
||||
{
|
||||
if (!full_body && joint >= XR_FULL_BODY_JOINT_LEFT_UPPER_LEG_META)
|
||||
return;
|
||||
|
||||
wivrn::from_headset::tracking::pose pose{
|
||||
.pose = {},
|
||||
.device = wivrn::device_id::GENERIC_TRACKER,
|
||||
.flags = 0,
|
||||
};
|
||||
out_poses.push_back(std::move(pose));
|
||||
}
|
||||
};
|
||||
if (!handle)
|
||||
{
|
||||
fill_poses();
|
||||
return;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
assert(xrLocateBodyJointsFB);
|
||||
@@ -103,40 +90,38 @@ void xr::fb_body_tracker::locate_spaces(XrTime time, std::vector<wivrn::from_hea
|
||||
if (auto res = xrLocateBodyJointsFB(handle, &locate_info, &joint_locations); !XR_SUCCEEDED(res))
|
||||
{
|
||||
spdlog::warn("xrLocateBodyJointsFB returned {}", xr::to_string(res));
|
||||
|
||||
fill_poses();
|
||||
return;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (!joint_locations.isActive)
|
||||
{
|
||||
spdlog::warn("Body tracker is not active.");
|
||||
fill_poses();
|
||||
return;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
for (auto joint: joint_whitelist)
|
||||
std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses> poses{};
|
||||
for (int i = 0; i < joint_whitelist.size(); i++)
|
||||
{
|
||||
auto joint = joint_whitelist[i];
|
||||
if (!full_body && joint >= XR_FULL_BODY_JOINT_LEFT_UPPER_LEG_META)
|
||||
return;
|
||||
break;
|
||||
|
||||
auto joint_pose = joints[joint];
|
||||
wivrn::from_headset::tracking::pose pose{
|
||||
wivrn::from_headset::body_tracking::pose pose{
|
||||
.pose = joint_pose.pose,
|
||||
.device = wivrn::device_id::GENERIC_TRACKER,
|
||||
.flags = 0,
|
||||
};
|
||||
|
||||
if (joint_pose.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT)
|
||||
pose.flags |= wivrn::from_headset::tracking::position_valid;
|
||||
if (joint_pose.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT)
|
||||
pose.flags |= wivrn::from_headset::tracking::orientation_valid;
|
||||
if (joint_pose.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT)
|
||||
pose.flags |= wivrn::from_headset::tracking::position_tracked;
|
||||
pose.flags |= wivrn::from_headset::body_tracking::orientation_valid;
|
||||
if (joint_pose.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT)
|
||||
pose.flags |= wivrn::from_headset::body_tracking::position_valid;
|
||||
if (joint_pose.locationFlags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT)
|
||||
pose.flags |= wivrn::from_headset::tracking::orientation_tracked;
|
||||
pose.flags |= wivrn::from_headset::body_tracking::orientation_tracked;
|
||||
if (joint_pose.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT)
|
||||
pose.flags |= wivrn::from_headset::body_tracking::position_tracked;
|
||||
|
||||
out_poses.push_back(std::move(pose));
|
||||
poses[i] = std::move(pose);
|
||||
}
|
||||
return;
|
||||
return poses;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,8 @@
|
||||
#include "wivrn_packets.h"
|
||||
|
||||
#include "xr/meta_body_tracking_fidelity.h"
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <optional>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
namespace xr
|
||||
@@ -64,6 +65,6 @@ public:
|
||||
void start(bool lower_body);
|
||||
void stop();
|
||||
|
||||
void locate_spaces(XrTime time, std::vector<wivrn::from_headset::tracking::pose> & out_poses, XrSpace reference);
|
||||
std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses>> locate_spaces(XrTime time, XrSpace reference);
|
||||
};
|
||||
} // namespace xr
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#include "xr/xr.h"
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
static_assert(xr::pico_body_tracker::joint_whitelist.size() <= wivrn::from_headset::body_tracking::max_tracked_poses);
|
||||
|
||||
static PFN_xrDestroyBodyTrackerBD xrDestroyBodyTrackerBD{};
|
||||
|
||||
XrResult xr::destroy_pico_body_tracker(XrBodyTrackerBD id)
|
||||
@@ -34,24 +36,11 @@ xr::pico_body_tracker::pico_body_tracker(instance & inst, XrBodyTrackerBD h)
|
||||
xrLocateBodyJointsBD = inst.get_proc<PFN_xrLocateBodyJointsBD>("xrLocateBodyJointsBD");
|
||||
}
|
||||
|
||||
void xr::pico_body_tracker::locate_spaces(XrTime time, std::vector<wivrn::from_headset::tracking::pose> & out_poses, XrSpace reference)
|
||||
std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses>> xr::pico_body_tracker::locate_spaces(XrTime time, XrSpace reference)
|
||||
{
|
||||
auto fill_poses = [&]() {
|
||||
for (auto _: joint_whitelist)
|
||||
{
|
||||
wivrn::from_headset::tracking::pose pose{
|
||||
.pose = {},
|
||||
.device = wivrn::device_id::GENERIC_TRACKER,
|
||||
.flags = 0,
|
||||
};
|
||||
out_poses.push_back(std::move(pose));
|
||||
}
|
||||
};
|
||||
|
||||
if (!xrLocateBodyJointsBD)
|
||||
{
|
||||
fill_poses();
|
||||
return;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
XrBodyJointsLocateInfoBD locate_info{
|
||||
@@ -72,28 +61,28 @@ void xr::pico_body_tracker::locate_spaces(XrTime time, std::vector<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));
|
||||
fill_poses();
|
||||
return;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
for (auto & joint: joint_whitelist)
|
||||
std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses> poses{};
|
||||
for (int i = 0; i < joint_whitelist.size(); i++)
|
||||
{
|
||||
auto & joint_location = joints[joint];
|
||||
wivrn::from_headset::tracking::pose pose{
|
||||
auto & joint_location = joints[joint_whitelist[i]];
|
||||
wivrn::from_headset::body_tracking::pose pose{
|
||||
.pose = joint_location.pose,
|
||||
.device = wivrn::device_id::GENERIC_TRACKER,
|
||||
.flags = 0,
|
||||
};
|
||||
|
||||
if (joint_location.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT)
|
||||
pose.flags |= wivrn::from_headset::tracking::position_valid;
|
||||
if (joint_location.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT)
|
||||
pose.flags |= wivrn::from_headset::tracking::orientation_valid;
|
||||
if (joint_location.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT)
|
||||
pose.flags |= wivrn::from_headset::tracking::position_tracked;
|
||||
pose.flags |= wivrn::from_headset::body_tracking::orientation_valid;
|
||||
if (joint_location.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT)
|
||||
pose.flags |= wivrn::from_headset::body_tracking::position_valid;
|
||||
if (joint_location.locationFlags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT)
|
||||
pose.flags |= wivrn::from_headset::tracking::orientation_tracked;
|
||||
pose.flags |= wivrn::from_headset::body_tracking::orientation_tracked;
|
||||
if (joint_location.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT)
|
||||
pose.flags |= wivrn::from_headset::body_tracking::position_tracked;
|
||||
|
||||
out_poses.push_back(std::move(pose));
|
||||
poses[i] = std::move(pose);
|
||||
}
|
||||
return poses;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,8 @@
|
||||
#include "utils/handle.h"
|
||||
#include "wivrn_packets.h"
|
||||
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <optional>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
namespace xr
|
||||
@@ -52,6 +53,6 @@ public:
|
||||
pico_body_tracker() = default;
|
||||
pico_body_tracker(instance & inst, XrBodyTrackerBD h);
|
||||
|
||||
void locate_spaces(XrTime time, std::vector<wivrn::from_headset::tracking::pose> & out_poses, XrSpace reference);
|
||||
std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses>> locate_spaces(XrTime time, XrSpace reference);
|
||||
};
|
||||
} // namespace xr
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
#include "openxr/openxr.h"
|
||||
#include "utils/contains.h"
|
||||
#include "xr/fb_body_tracker.h"
|
||||
#include "xr/pico_body_tracker.h"
|
||||
#include "xr/instance.h"
|
||||
#include "xr/pico_body_tracker.h"
|
||||
#include "xr/system.h"
|
||||
#include <ranges>
|
||||
#include <vulkan/vulkan.h>
|
||||
@@ -152,9 +152,9 @@ xr::fb_body_tracker xr::session::create_fb_body_tracker()
|
||||
xr::pico_body_tracker xr::session::create_pico_body_tracker()
|
||||
{
|
||||
XrBodyTrackerCreateInfoBD create_info{
|
||||
.type = XR_TYPE_BODY_TRACKER_CREATE_INFO_BD,
|
||||
.next = nullptr,
|
||||
.jointSet = XR_BODY_JOINT_SET_FULL_BODY_JOINTS_BD,
|
||||
.type = XR_TYPE_BODY_TRACKER_CREATE_INFO_BD,
|
||||
.next = nullptr,
|
||||
.jointSet = XR_BODY_JOINT_SET_FULL_BODY_JOINTS_BD,
|
||||
};
|
||||
|
||||
XrBodyTrackerBD bt;
|
||||
|
||||
+2
-2
@@ -26,12 +26,12 @@
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
#include "fb_body_tracker.h"
|
||||
#include "fb_face_tracker2.h"
|
||||
#include "hand_tracker.h"
|
||||
#include "htc_face_tracker.h"
|
||||
#include "fb_body_tracker.h"
|
||||
#include "pico_body_tracker.h"
|
||||
#include "passthrough.h"
|
||||
#include "pico_body_tracker.h"
|
||||
#include "pico_face_tracker.h"
|
||||
#include "space.h"
|
||||
|
||||
|
||||
@@ -147,12 +147,12 @@ XrSystemBodyTrackingPropertiesFB xr::system::fb_body_tracking_properties() const
|
||||
throw std::invalid_argument("this");
|
||||
|
||||
XrSystemBodyTrackingPropertiesFB body_tracking_prop{
|
||||
.type = XR_TYPE_SYSTEM_BODY_TRACKING_PROPERTIES_FB,
|
||||
.type = XR_TYPE_SYSTEM_BODY_TRACKING_PROPERTIES_FB,
|
||||
};
|
||||
|
||||
XrSystemProperties prop{
|
||||
.type = XR_TYPE_SYSTEM_PROPERTIES,
|
||||
.next = &body_tracking_prop,
|
||||
.type = XR_TYPE_SYSTEM_PROPERTIES,
|
||||
.next = &body_tracking_prop,
|
||||
};
|
||||
CHECK_XR(xrGetSystemProperties(*inst, id, &prop));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user