client: support XR_META_foveation_eye_tracked (#1123)

This commit is contained in:
galister
2026-10-22 18:52:55 +02:00
committed by GitHub
parent 2e60fa75e4
commit 76da2e1cb7
20 changed files with 896 additions and 266 deletions
+48 -28
View File
@@ -26,6 +26,7 @@
#include "xr/face_tracker.h"
#include "xr/fb_body_tracker.h"
#include "xr/to_string.h"
#include <glm/gtc/quaternion.hpp>
#include <magic_enum.hpp>
#include <magic_enum_containers.hpp>
#include <ranges>
@@ -60,6 +61,37 @@ from_headset::tracking::pose locate_space(device_id device, XrSpace space, XrSpa
return {.device = device};
}
from_headset::tracking::pose make_eye_gaze_view_relative(
const from_headset::tracking::pose & gaze_pose,
const from_headset::tracking::pose & view_pose)
{
glm::quat gaze_quat(
gaze_pose.pose.orientation.w,
gaze_pose.pose.orientation.x,
gaze_pose.pose.orientation.y,
gaze_pose.pose.orientation.z);
const glm::quat view_quat(
view_pose.pose.orientation.w,
view_pose.pose.orientation.x,
view_pose.pose.orientation.y,
view_pose.pose.orientation.z);
gaze_quat = glm::conjugate(view_quat) * gaze_quat;
using flags = from_headset::pose_flags;
return {
.pose = {
.orientation = {
.x = gaze_quat.x,
.y = gaze_quat.y,
.z = gaze_quat.z,
.w = gaze_quat.w,
},
},
.device = gaze_pose.device,
.flags = uint8_t(gaze_pose.flags & view_pose.flags & ~(flags::linear_velocity_valid | flags::angular_velocity_valid)),
};
}
class locate_spaces_functor
{
std::vector<XrSpaceLocationData> locations;
@@ -253,6 +285,7 @@ void scenes::stream::tracking()
magic_enum::containers::array<device_id, XrSpace> spaces{};
const auto & config = application::get_config();
const bool eye_gaze_enabled = config.check_feature(feature::eye_gaze);
{
std::vector ids{
@@ -270,7 +303,7 @@ void scenes::stream::tracking()
ids.insert(ids.end(), {device_id::LEFT_PINCH_POSE, device_id::LEFT_POKE, device_id::RIGHT_PINCH_POSE, device_id::RIGHT_POKE});
}
if (config.check_feature(feature::eye_gaze))
if (eye_gaze_enabled)
ids.emplace_back(device_id::EYE_GAZE);
for (auto id: ids)
@@ -294,6 +327,17 @@ void scenes::stream::tracking()
};
float applied_height_offset = config.get_height_offset();
xr::space height_offset_space = make_height_offset_space(applied_height_offset);
XrSpace world_space = application::space(xr::spaces::world);
auto locate_eye_gaze = [&](XrTime time) {
// Eye gaze uses view pose as the origin.
if (application::get_hmd_traits().view_locate)
return locate_space(device_id::EYE_GAZE, spaces[device_id::EYE_GAZE], view_space, time);
// Pico headsets fail to locate gaze relative to view.
return make_eye_gaze_view_relative(
locate_space(device_id::EYE_GAZE, spaces[device_id::EYE_GAZE], world_space, time),
locate_space(device_id::EYE_GAZE, view_space, world_space, time));
};
from_headset::tracking tracking;
std::vector<from_headset::hand_tracking> hands;
@@ -464,6 +508,7 @@ void scenes::stream::tracking()
j.pose = i.pose;
j.fov = i.fov;
}
locate_spaces.add_space(item.device, view_space, tracking.timestamp, tracking.device_poses);
break;
case wivrn::device_id::LEFT_GRIP:
@@ -479,33 +524,8 @@ void scenes::stream::tracking()
locate_spaces.add_space(item.device, spaces[item.device], tracking.timestamp, tracking.device_poses);
break;
case wivrn::device_id::EYE_GAZE:
// Eye gaze uses view pose as the origin
if (application::get_hmd_traits().view_locate)
tracking.device_poses.push_back(locate_space(item.device, spaces[item.device], spaces[wivrn::device_id::HEAD], tracking.timestamp));
else
{
// Pico headsets fail to locate gaze relative to view
auto gaze = locate_space(item.device, spaces[item.device], height_offset_space, tracking.timestamp);
auto view_pose = locate_space(item.device, view_space, height_offset_space, tracking.timestamp);
glm::quat gaze_quat(gaze.pose.orientation.w, gaze.pose.orientation.x, gaze.pose.orientation.y, gaze.pose.orientation.z);
glm::quat view_quat(view_pose.pose.orientation.w, view_pose.pose.orientation.x, view_pose.pose.orientation.y, view_pose.pose.orientation.z);
gaze_quat = glm::conjugate(view_quat) * gaze_quat;
using flags = from_headset::pose_flags;
tracking.device_poses.push_back(
from_headset::tracking::pose{
// Zero position and velocities
.pose = {
.orientation = {
.x = gaze_quat.x,
.y = gaze_quat.y,
.z = gaze_quat.z,
.w = gaze_quat.w,
},
},
.device = item.device,
.flags = uint8_t(gaze.flags & view_pose.flags & ~(flags::linear_velocity_valid | flags::angular_velocity_valid)),
});
}
if (eye_gaze_enabled)
tracking.device_poses.push_back(locate_eye_gaze(tracking.timestamp));
break;
case wivrn::device_id::FACE:
std::visit(utils::overloaded{