client: xrHandTrackingDataSourceExt to filter out controller-based HT
This commit is contained in:
@@ -1367,6 +1367,7 @@ void application::initialize()
|
||||
XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME,
|
||||
XR_EXT_HAND_INTERACTION_EXTENSION_NAME,
|
||||
XR_EXT_HAND_TRACKING_EXTENSION_NAME,
|
||||
XR_EXT_HAND_TRACKING_DATA_SOURCE_EXTENSION_NAME,
|
||||
XR_FB_HAND_TRACKING_MESH_EXTENSION_NAME,
|
||||
XR_EXT_PALM_POSE_EXTENSION_NAME,
|
||||
XR_EXT_PERFORMANCE_SETTINGS_EXTENSION_NAME,
|
||||
|
||||
@@ -344,6 +344,7 @@ void hmd_traits::init()
|
||||
if (panel_width_override > 0)
|
||||
break;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
spdlog::info("HMD traits initialized");
|
||||
|
||||
@@ -581,10 +581,10 @@ std::vector<imgui_context::controller_state> imgui_context::read_controllers_sta
|
||||
current_aim_interaction = 1;
|
||||
if (ctrl.hand)
|
||||
{
|
||||
if (auto joints = ctrl.hand->locate(world, display_time))
|
||||
if (auto hand = ctrl.hand->locate(world, display_time); hand and hand->is_input_source())
|
||||
{
|
||||
XrHandJointLocationEXT & index_tip = (*joints)[XR_HAND_JOINT_INDEX_TIP_EXT].first;
|
||||
XrHandJointLocationEXT & palm = (*joints)[XR_HAND_JOINT_PALM_EXT].first;
|
||||
XrHandJointLocationEXT & index_tip = hand->joints[XR_HAND_JOINT_INDEX_TIP_EXT].first;
|
||||
XrHandJointLocationEXT & palm = hand->joints[XR_HAND_JOINT_PALM_EXT].first;
|
||||
|
||||
if (index_tip.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT)
|
||||
{
|
||||
|
||||
@@ -289,13 +289,13 @@ void hand_model::add_hand(scene & scene,
|
||||
}
|
||||
|
||||
void hand_model::apply(entt::registry & scene,
|
||||
const std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> & left_hand,
|
||||
const std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> & right_hand)
|
||||
const xr::hand_tracker::joint_array * left_hand,
|
||||
const xr::hand_tracker::joint_array * right_hand)
|
||||
{
|
||||
for (auto && [entity, hj, node]: scene.view<components::hand_joint, components::node>().each())
|
||||
{
|
||||
auto f = [&](const std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> & joints) {
|
||||
if (joints.has_value())
|
||||
auto f = [&](const xr::hand_tracker::joint_array * joints) {
|
||||
if (joints)
|
||||
{
|
||||
node.visible = true;
|
||||
|
||||
|
||||
@@ -37,6 +37,6 @@ void add_hand(scene & scene,
|
||||
uint32_t layer_mask);
|
||||
|
||||
void apply(entt::registry & scene,
|
||||
const std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> & left_hand,
|
||||
const std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> & right_hand);
|
||||
const xr::hand_tracker::joint_array * left_hand,
|
||||
const xr::hand_tracker::joint_array * right_hand);
|
||||
}; // namespace hand_model
|
||||
|
||||
+45
-46
@@ -438,57 +438,54 @@ void scenes::lobby::connect(const configuration::server_data & data)
|
||||
|
||||
std::optional<glm::vec3> scenes::lobby::check_recenter_gesture(
|
||||
xr::spaces space,
|
||||
const std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> & joints,
|
||||
const xr::hand_tracker::joint_array & joints,
|
||||
const std::pair<glm::vec3, glm::quat> & head_pose)
|
||||
{
|
||||
if (recentering_context and std::get<0>(*recentering_context) != space)
|
||||
return std::nullopt;
|
||||
|
||||
if (joints)
|
||||
const auto & palm = joints[XR_HAND_JOINT_PALM_EXT].first;
|
||||
const auto palm_y = glm::rotate(glm_cast(palm.pose.orientation), glm::vec3(0, 1, 0));
|
||||
|
||||
for (XrHandJointEXT index: {
|
||||
XR_HAND_JOINT_INDEX_PROXIMAL_EXT,
|
||||
XR_HAND_JOINT_INDEX_INTERMEDIATE_EXT,
|
||||
XR_HAND_JOINT_INDEX_DISTAL_EXT,
|
||||
|
||||
XR_HAND_JOINT_MIDDLE_PROXIMAL_EXT,
|
||||
XR_HAND_JOINT_MIDDLE_INTERMEDIATE_EXT,
|
||||
XR_HAND_JOINT_MIDDLE_DISTAL_EXT,
|
||||
|
||||
XR_HAND_JOINT_RING_PROXIMAL_EXT,
|
||||
XR_HAND_JOINT_RING_INTERMEDIATE_EXT,
|
||||
XR_HAND_JOINT_RING_DISTAL_EXT,
|
||||
|
||||
XR_HAND_JOINT_LITTLE_PROXIMAL_EXT,
|
||||
XR_HAND_JOINT_LITTLE_INTERMEDIATE_EXT,
|
||||
XR_HAND_JOINT_LITTLE_DISTAL_EXT,
|
||||
})
|
||||
{
|
||||
const auto & palm = (*joints)[XR_HAND_JOINT_PALM_EXT].first;
|
||||
const auto palm_y = glm::rotate(glm_cast(palm.pose.orientation), glm::vec3(0, 1, 0));
|
||||
const auto fingertip_y = glm::rotate(glm_cast(joints[index].first.pose.orientation), glm::vec3(0, 1, 0));
|
||||
|
||||
for (XrHandJointEXT index: {
|
||||
XR_HAND_JOINT_INDEX_PROXIMAL_EXT,
|
||||
XR_HAND_JOINT_INDEX_INTERMEDIATE_EXT,
|
||||
XR_HAND_JOINT_INDEX_DISTAL_EXT,
|
||||
|
||||
XR_HAND_JOINT_MIDDLE_PROXIMAL_EXT,
|
||||
XR_HAND_JOINT_MIDDLE_INTERMEDIATE_EXT,
|
||||
XR_HAND_JOINT_MIDDLE_DISTAL_EXT,
|
||||
|
||||
XR_HAND_JOINT_RING_PROXIMAL_EXT,
|
||||
XR_HAND_JOINT_RING_INTERMEDIATE_EXT,
|
||||
XR_HAND_JOINT_RING_DISTAL_EXT,
|
||||
|
||||
XR_HAND_JOINT_LITTLE_PROXIMAL_EXT,
|
||||
XR_HAND_JOINT_LITTLE_INTERMEDIATE_EXT,
|
||||
XR_HAND_JOINT_LITTLE_DISTAL_EXT,
|
||||
})
|
||||
if (glm::dot(palm_y, fingertip_y) < constants::lobby::recenter_cos_fingertip_angle_max)
|
||||
{
|
||||
const auto fingertip_y = glm::rotate(glm_cast((*joints)[index].first.pose.orientation), glm::vec3(0, 1, 0));
|
||||
|
||||
if (glm::dot(palm_y, fingertip_y) < constants::lobby::recenter_cos_fingertip_angle_max)
|
||||
{
|
||||
recentering_context.reset();
|
||||
return std::nullopt;
|
||||
}
|
||||
recentering_context.reset();
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
const auto q = glm_cast(palm.pose.orientation);
|
||||
const auto x = glm_cast(palm.pose.position);
|
||||
const auto q = glm_cast(palm.pose.orientation);
|
||||
const auto x = glm_cast(palm.pose.position);
|
||||
|
||||
// Make the up vector orthogonal to forward
|
||||
const glm::vec3 forward = glm::rotate(head_pose.second, glm::vec3{0, 0, -1});
|
||||
const glm::vec3 up = glm::normalize(glm::vec3{0, 1, 0} - forward * glm::dot(forward, {0, 1, 0}));
|
||||
// Make the up vector orthogonal to forward
|
||||
const glm::vec3 forward = glm::rotate(head_pose.second, glm::vec3{0, 0, -1});
|
||||
const glm::vec3 up = glm::normalize(glm::vec3{0, 1, 0} - forward * glm::dot(forward, {0, 1, 0}));
|
||||
|
||||
// Y is pointing to the back of the hand
|
||||
if (glm::dot(q * glm::vec3(0, -1, 0), up) > constants::lobby::recenter_cos_palm_angle_min)
|
||||
{
|
||||
recentering_context.emplace(space, glm::vec3{}, 0);
|
||||
return x + glm::rotate(q, glm::vec3{0, -constants::lobby::recenter_distance_up, -constants::lobby::recenter_distance_front});
|
||||
}
|
||||
// Y is pointing to the back of the hand
|
||||
if (glm::dot(q * glm::vec3(0, -1, 0), up) > constants::lobby::recenter_cos_palm_angle_min)
|
||||
{
|
||||
recentering_context.emplace(space, glm::vec3{}, 0);
|
||||
return x + glm::rotate(q, glm::vec3{0, -constants::lobby::recenter_distance_up, -constants::lobby::recenter_distance_front});
|
||||
}
|
||||
|
||||
recentering_context.reset();
|
||||
@@ -973,24 +970,26 @@ void scenes::lobby::render(const XrFrameState & frame_state)
|
||||
auto left = left_hand->locate(world_space, frame_state.predictedDisplayTime);
|
||||
if (left)
|
||||
{
|
||||
stick_finger_to_gui(*left, windows);
|
||||
if (left->is_input_source())
|
||||
stick_finger_to_gui(left->joints, windows);
|
||||
hide_left_controller = true;
|
||||
}
|
||||
|
||||
auto right = right_hand->locate(world_space, frame_state.predictedDisplayTime);
|
||||
if (right)
|
||||
{
|
||||
stick_finger_to_gui(*right, windows);
|
||||
if (right->is_input_source())
|
||||
stick_finger_to_gui(right->joints, windows);
|
||||
hide_right_controller = true;
|
||||
}
|
||||
|
||||
hand_model::apply(world, left, right);
|
||||
hand_model::apply(world, left ? &left->joints : nullptr, right ? &right->joints : nullptr);
|
||||
|
||||
if (not new_gui_position and head_position)
|
||||
new_gui_position = check_recenter_gesture(xr::spaces::palm_left, left, *head_position);
|
||||
if (not new_gui_position and head_position and left and left->is_input_source())
|
||||
new_gui_position = check_recenter_gesture(xr::spaces::palm_left, left->joints, *head_position);
|
||||
|
||||
if (not new_gui_position and head_position)
|
||||
new_gui_position = check_recenter_gesture(xr::spaces::palm_right, right, *head_position);
|
||||
if (not new_gui_position and head_position and right and right->is_input_source())
|
||||
new_gui_position = check_recenter_gesture(xr::spaces::palm_right, right->joints, *head_position);
|
||||
}
|
||||
|
||||
if (head_position and new_gui_position)
|
||||
|
||||
@@ -252,7 +252,7 @@ class lobby : public scene_impl<lobby>
|
||||
void connect(const configuration::server_data & data);
|
||||
std::unique_ptr<wivrn_session> connect_to_session(wivrn_discover::service service, bool manual_connection);
|
||||
|
||||
std::optional<glm::vec3> check_recenter_gesture(xr::spaces space, const std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> & joints, const std::pair<glm::vec3, glm::quat> & head_pose);
|
||||
std::optional<glm::vec3> check_recenter_gesture(xr::spaces space, const xr::hand_tracker::joint_array & joints, const std::pair<glm::vec3, glm::quat> & head_pose);
|
||||
std::optional<glm::vec3> check_recenter_action(XrTime predicted_display_time, glm::vec3 head_position);
|
||||
std::optional<glm::vec3> check_recenter_gui(glm::vec3 head_position, glm::quat head_orientation);
|
||||
|
||||
|
||||
@@ -1099,10 +1099,12 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
auto left = left_hand->locate(world_space, predicted_display_time);
|
||||
auto right = right_hand->locate(world_space, predicted_display_time);
|
||||
|
||||
if (left and xr::hand_tracker::check_flags(*left, XR_SPACE_LOCATION_POSITION_TRACKED_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT, 0))
|
||||
if (left and left->is_input_source() and
|
||||
xr::hand_tracker::check_flags(left->joints, XR_SPACE_LOCATION_POSITION_TRACKED_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT, 0))
|
||||
hide_left_controller = true;
|
||||
|
||||
if (right and xr::hand_tracker::check_flags(*right, XR_SPACE_LOCATION_POSITION_TRACKED_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT, 0))
|
||||
if (right and right->is_input_source() and
|
||||
xr::hand_tracker::check_flags(right->joints, XR_SPACE_LOCATION_POSITION_TRACKED_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT, 0))
|
||||
hide_right_controller = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -160,14 +160,14 @@ public:
|
||||
|
||||
static std::optional<std::array<from_headset::hand_tracking::pose, XR_HAND_JOINT_COUNT_EXT>> locate_hands(xr::hand_tracker & hand, XrSpace space, XrTime time)
|
||||
{
|
||||
auto joints = hand.locate(space, time);
|
||||
auto located = hand.locate(space, time);
|
||||
|
||||
if (joints)
|
||||
if (located and located->is_input_source())
|
||||
{
|
||||
std::array<from_headset::hand_tracking::pose, XR_HAND_JOINT_COUNT_EXT> poses;
|
||||
for (int i = 0; i < XR_HAND_JOINT_COUNT_EXT; i++)
|
||||
{
|
||||
const auto & joint = (*joints)[i];
|
||||
const auto & joint = located->joints[i];
|
||||
poses[i] = {
|
||||
.position = joint.first.pose.position,
|
||||
.orientation = pack(joint.first.pose.orientation),
|
||||
|
||||
@@ -32,12 +32,36 @@ xr::hand_tracker::hand_tracker(instance & inst, session & session, const XrHandT
|
||||
auto xrCreateHandTrackerEXT = inst.get_proc<PFN_xrCreateHandTrackerEXT>("xrCreateHandTrackerEXT");
|
||||
assert(xrCreateHandTrackerEXT);
|
||||
xrLocateHandJointsEXT = inst.get_proc<PFN_xrLocateHandJointsEXT>("xrLocateHandJointsEXT");
|
||||
hand_tracking_data_source_supported = inst.has_extension(XR_EXT_HAND_TRACKING_DATA_SOURCE_EXTENSION_NAME);
|
||||
if (inst.has_extension(XR_FB_HAND_TRACKING_MESH_EXTENSION_NAME))
|
||||
xrGetHandMeshFB = inst.get_proc<PFN_xrGetHandMeshFB>("xrGetHandMeshFB");
|
||||
CHECK_XR(xrCreateHandTrackerEXT(session, &info, &id));
|
||||
|
||||
if (hand_tracking_data_source_supported)
|
||||
{
|
||||
// request both sources, callers of locate() decide how to use the results
|
||||
std::array<XrHandTrackingDataSourceEXT, 2> data_sources = {
|
||||
XR_HAND_TRACKING_DATA_SOURCE_UNOBSTRUCTED_EXT,
|
||||
XR_HAND_TRACKING_DATA_SOURCE_CONTROLLER_EXT,
|
||||
};
|
||||
|
||||
XrHandTrackingDataSourceInfoEXT data_source_info{
|
||||
.type = XR_TYPE_HAND_TRACKING_DATA_SOURCE_INFO_EXT,
|
||||
.next = info.next,
|
||||
.requestedDataSourceCount = static_cast<uint32_t>(data_sources.size()),
|
||||
.requestedDataSources = data_sources.data(),
|
||||
};
|
||||
|
||||
auto create_info = info;
|
||||
create_info.next = &data_source_info;
|
||||
CHECK_XR(xrCreateHandTrackerEXT(session, &create_info, &id));
|
||||
}
|
||||
else
|
||||
{
|
||||
CHECK_XR(xrCreateHandTrackerEXT(session, &info, &id));
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> xr::hand_tracker::locate(XrSpace space, XrTime time)
|
||||
std::optional<xr::hand_tracker::located_hand> xr::hand_tracker::locate(XrSpace space, XrTime time)
|
||||
{
|
||||
if (!id || !xrLocateHandJointsEXT)
|
||||
return std::nullopt;
|
||||
@@ -67,29 +91,45 @@ std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> xr::
|
||||
.jointVelocities = joints_vel.data(),
|
||||
};
|
||||
|
||||
XrHandTrackingDataSourceStateEXT data_source_state{
|
||||
.type = XR_TYPE_HAND_TRACKING_DATA_SOURCE_STATE_EXT,
|
||||
.next = &velocities,
|
||||
};
|
||||
|
||||
XrHandJointLocationsEXT locations{
|
||||
.type = XR_TYPE_HAND_JOINT_LOCATIONS_EXT,
|
||||
.next = &velocities,
|
||||
.jointCount = joints_pos.size(),
|
||||
.jointLocations = joints_pos.data(),
|
||||
};
|
||||
if (hand_tracking_data_source_supported)
|
||||
locations.next = &data_source_state;
|
||||
|
||||
CHECK_XR(xrLocateHandJointsEXT(id, &info, &locations));
|
||||
|
||||
if (!locations.isActive)
|
||||
return std::nullopt;
|
||||
|
||||
if (hand_tracking_data_source_supported && !data_source_state.isActive)
|
||||
// returned joints are not valid
|
||||
return std::nullopt;
|
||||
|
||||
// bail if any of the joint is invalid
|
||||
if (std::ranges::any_of(joints_pos, [](const auto & loc) { return loc.locationFlags == 0; }))
|
||||
return std::nullopt;
|
||||
|
||||
std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT> joints;
|
||||
joint_array joints;
|
||||
for (int i = 0; i < XR_HAND_JOINT_COUNT_EXT; i++)
|
||||
{
|
||||
joints[i] = {joints_pos[i], joints_vel[i]};
|
||||
}
|
||||
|
||||
return joints;
|
||||
return located_hand{
|
||||
.joints = joints,
|
||||
.data_source = hand_tracking_data_source_supported
|
||||
? std::optional{data_source_state.dataSource}
|
||||
: std::nullopt,
|
||||
};
|
||||
}
|
||||
|
||||
const xr::hand_tracker::mesh_data * xr::hand_tracker::mesh()
|
||||
@@ -207,7 +247,7 @@ const xr::hand_tracker::mesh_data * xr::hand_tracker::mesh()
|
||||
return &*cached_hand_mesh_fb;
|
||||
}
|
||||
|
||||
bool xr::hand_tracker::check_flags(const std::array<joint, XR_HAND_JOINT_COUNT_EXT> & joints, XrSpaceLocationFlags position, XrSpaceVelocityFlags velocity)
|
||||
bool xr::hand_tracker::check_flags(const joint_array & joints, XrSpaceLocationFlags position, XrSpaceVelocityFlags velocity)
|
||||
{
|
||||
return std::ranges::all_of(joints, [position, velocity](const auto & joint) {
|
||||
return (joint.first.locationFlags & position) == position and (joint.second.velocityFlags & velocity) == velocity;
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "utils/handle.h"
|
||||
#include <array>
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
@@ -34,6 +35,20 @@ class hand_tracker : public utils::handle<XrHandTrackerEXT>
|
||||
{
|
||||
public:
|
||||
using joint = std::pair<XrHandJointLocationEXT, XrHandJointVelocityEXT>;
|
||||
using joint_array = std::array<joint, XR_HAND_JOINT_COUNT_EXT>;
|
||||
|
||||
struct located_hand
|
||||
{
|
||||
joint_array joints;
|
||||
std::optional<XrHandTrackingDataSourceEXT> data_source;
|
||||
|
||||
// should these joints be used for input?
|
||||
// true if UNOBSTRUCTED or XR_EXT_hand_tracking_data_source not supported
|
||||
bool is_input_source() const
|
||||
{
|
||||
return !data_source or *data_source == XR_HAND_TRACKING_DATA_SOURCE_UNOBSTRUCTED_EXT;
|
||||
}
|
||||
};
|
||||
|
||||
struct mesh_data
|
||||
{
|
||||
@@ -51,15 +66,16 @@ public:
|
||||
private:
|
||||
PFN_xrLocateHandJointsEXT xrLocateHandJointsEXT{};
|
||||
PFN_xrGetHandMeshFB xrGetHandMeshFB{};
|
||||
bool hand_tracking_data_source_supported = false;
|
||||
std::optional<mesh_data> cached_hand_mesh_fb;
|
||||
bool hand_mesh_fb_fetched = false;
|
||||
|
||||
public:
|
||||
hand_tracker(instance & inst, session & session, const XrHandTrackerCreateInfoEXT & info);
|
||||
|
||||
std::optional<std::array<joint, XR_HAND_JOINT_COUNT_EXT>> locate(XrSpace space, XrTime time);
|
||||
std::optional<located_hand> locate(XrSpace space, XrTime time);
|
||||
const mesh_data * mesh();
|
||||
|
||||
static bool check_flags(const std::array<joint, XR_HAND_JOINT_COUNT_EXT> & joints, XrSpaceLocationFlags position, XrSpaceVelocityFlags velocity);
|
||||
static bool check_flags(const joint_array & joints, XrSpaceLocationFlags position, XrSpaceVelocityFlags velocity);
|
||||
};
|
||||
} // namespace xr
|
||||
|
||||
Reference in New Issue
Block a user