Remove hand tracker from application.h

This commit is contained in:
Patrick Nicolas
2025-08-19 19:14:10 +02:00
parent 5f6641c38f
commit 0acfe7cd24
12 changed files with 79 additions and 64 deletions
+1 -12
View File
@@ -1236,12 +1236,7 @@ void application::initialize()
spdlog::info(" Orientation tracking: {}", (bool)properties.trackingProperties.orientationTracking); spdlog::info(" Orientation tracking: {}", (bool)properties.trackingProperties.orientationTracking);
spdlog::info(" Position tracking: {}", (bool)properties.trackingProperties.positionTracking); spdlog::info(" Position tracking: {}", (bool)properties.trackingProperties.positionTracking);
if (utils::contains(xr_extensions, XR_EXT_HAND_TRACKING_EXTENSION_NAME)) spdlog::info(" Hand tracking support: {}", xr_system_id.hand_tracking_supported());
{
XrSystemHandTrackingPropertiesEXT hand_tracking_properties = xr_system_id.hand_tracking_properties();
spdlog::info(" Hand tracking support: {}", (bool)hand_tracking_properties.supportsHandTracking);
hand_tracking_supported = hand_tracking_properties.supportsHandTracking;
}
if (utils::contains(xr_extensions, XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME)) if (utils::contains(xr_extensions, XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME))
{ {
@@ -1288,12 +1283,6 @@ void application::initialize()
config.emplace(xr_system_id); config.emplace(xr_system_id);
if (hand_tracking_supported)
{
left_hand = xr_session.create_hand_tracker(XR_HAND_LEFT_EXT);
right_hand = xr_session.create_hand_tracker(XR_HAND_RIGHT_EXT);
}
if (utils::contains(xr_extensions, XR_FB_FACE_TRACKING2_EXTENSION_NAME)) if (utils::contains(xr_extensions, XR_FB_FACE_TRACKING2_EXTENSION_NAME))
{ {
XrSystemFaceTrackingProperties2FB fb_face2_properties = xr_system_id.fb_face_tracking2_properties(); XrSystemFaceTrackingProperties2FB fb_face2_properties = xr_system_id.fb_face_tracking2_properties();
+5 -19
View File
@@ -126,10 +126,6 @@ class application : public singleton<application>
xr::actionset xr_actionset; xr::actionset xr_actionset;
std::vector<std::tuple<XrAction, XrActionType, std::string>> actions; std::vector<std::tuple<XrAction, XrActionType, std::string>> actions;
bool hand_tracking_supported = false;
xr::hand_tracker left_hand;
xr::hand_tracker right_hand;
std::variant<std::monostate, xr::fb_face_tracker2, xr::htc_face_tracker, xr::pico_face_tracker> face_tracker; std::variant<std::monostate, xr::fb_face_tracker2, xr::htc_face_tracker, xr::pico_face_tracker> face_tracker;
std::variant<std::monostate, xr::fb_body_tracker, xr::htc_body_tracker, xr::pico_body_tracker> body_tracker; std::variant<std::monostate, xr::fb_body_tracker, xr::htc_body_tracker, xr::pico_body_tracker> body_tracker;
@@ -396,6 +392,11 @@ public:
return instance().vk_instance; return instance().vk_instance;
} }
static xr::system & get_system()
{
return instance().xr_system_id;
}
static vk::raii::PipelineCache & get_pipeline_cache() static vk::raii::PipelineCache & get_pipeline_cache()
{ {
return instance().pipeline_cache; return instance().pipeline_cache;
@@ -416,11 +417,6 @@ public:
return instance().last_scene_cpu_time; return instance().last_scene_cpu_time;
} }
static bool get_hand_tracking_supported()
{
return instance().hand_tracking_supported;
}
static bool get_face_tracking_supported() static bool get_face_tracking_supported()
{ {
return !std::holds_alternative<std::monostate>(instance().face_tracker); return !std::holds_alternative<std::monostate>(instance().face_tracker);
@@ -441,16 +437,6 @@ public:
return instance().openxr_post_processing_supported; return instance().openxr_post_processing_supported;
} }
static xr::hand_tracker & get_left_hand()
{
return instance().left_hand;
}
static xr::hand_tracker & get_right_hand()
{
return instance().right_hand;
}
static auto & get_face_tracker() static auto & get_face_tracker()
{ {
return instance().face_tracker; return instance().face_tracker;
+2 -2
View File
@@ -94,7 +94,7 @@ bool configuration::check_feature(feature f) const
case feature::microphone: case feature::microphone:
break; break;
case feature::hand_tracking: case feature::hand_tracking:
if (not application::get_hand_tracking_supported()) if (not application::get_system().hand_tracking_supported())
return false; return false;
break; break;
case feature::eye_gaze: case feature::eye_gaze:
@@ -182,7 +182,7 @@ void configuration::set_feature(feature f, bool state)
configuration::configuration(xr::system & system) configuration::configuration(xr::system & system)
{ {
passthrough_enabled = system.passthrough_supported() == xr::system::passthrough_type::color; passthrough_enabled = system.passthrough_supported() == xr::system::passthrough_type::color;
features[feature::hand_tracking] = application::get_hand_tracking_supported(); features[feature::hand_tracking] = system.hand_tracking_supported();
try try
{ {
simdjson::dom::parser parser; simdjson::dom::parser parser;
+13 -21
View File
@@ -649,10 +649,10 @@ void scenes::lobby::render(const XrFrameState & frame_state)
if (!new_gui_position and head_position) if (!new_gui_position and head_position)
new_gui_position = check_recenter_action(frame_state.predictedDisplayTime, head_position->first); new_gui_position = check_recenter_action(frame_state.predictedDisplayTime, head_position->first);
if (application::get_hand_tracking_supported()) if (left_hand and right_hand)
{ {
auto left = application::get_left_hand().locate(world_space, frame_state.predictedDisplayTime); auto left = left_hand->locate(world_space, frame_state.predictedDisplayTime);
auto right = application::get_right_hand().locate(world_space, frame_state.predictedDisplayTime); auto right = right_hand->locate(world_space, frame_state.predictedDisplayTime);
hand_model::apply(world, left, right); hand_model::apply(world, left, right);
@@ -835,12 +835,6 @@ void scenes::lobby::on_focused()
xyz_axes_right_controller = load_gltf("xyz-arrows.glb", layer_controllers).first; xyz_axes_right_controller = load_gltf("xyz-arrows.glb", layer_controllers).first;
#endif #endif
if (application::get_hand_tracking_supported())
{
hand_model::add_hand(*this, XR_HAND_LEFT_EXT, "left-hand.glb", layer_controllers);
hand_model::add_hand(*this, XR_HAND_RIGHT_EXT, "right-hand.glb", layer_controllers);
}
recenter_left_action = get_action("recenter_left").first; recenter_left_action = get_action("recenter_left").first;
recenter_right_action = get_action("recenter_right").first; recenter_right_action = get_action("recenter_right").first;
@@ -862,19 +856,15 @@ void scenes::lobby::on_focused()
.haptic_output = get_action("right_haptic").first, .haptic_output = get_action("right_haptic").first,
}, },
}; };
if (auto & hand = application::get_left_hand())
if (system.hand_tracking_supported())
{ {
imgui_inputs.push_back( left_hand = session.create_hand_tracker(XR_HAND_LEFT_EXT);
{ right_hand = session.create_hand_tracker(XR_HAND_RIGHT_EXT);
.hand = &hand, hand_model::add_hand(*this, XR_HAND_LEFT_EXT, "left-hand.glb", layer_controllers);
}); hand_model::add_hand(*this, XR_HAND_RIGHT_EXT, "right-hand.glb", layer_controllers);
} imgui_inputs.push_back({.hand = &*left_hand});
if (auto & hand = application::get_right_hand()) imgui_inputs.push_back({.hand = &*right_hand});
{
imgui_inputs.push_back(
{
.hand = &hand,
});
} }
// 0.4mm / pixel // 0.4mm / pixel
@@ -966,6 +956,8 @@ void scenes::lobby::on_unfocused()
world.clear(); // Must be cleared before the renderer so that the descriptor sets are freed before their pools world.clear(); // Must be cleared before the renderer so that the descriptor sets are freed before their pools
input.reset(); input.reset();
left_hand.reset();
right_hand.reset();
loader.reset(); loader.reset();
renderer.reset(); renderer.reset();
+3
View File
@@ -66,6 +66,9 @@ class lobby : public scene_impl<lobby>
std::optional<imgui_context> imgui_ctx; std::optional<imgui_context> imgui_ctx;
std::optional<xr::hand_tracker> left_hand;
std::optional<xr::hand_tracker> right_hand;
std::string selected_item; std::string selected_item;
std::unique_ptr<asset> license; std::unique_ptr<asset> license;
+3 -3
View File
@@ -889,7 +889,7 @@ void scenes::lobby::gui_settings()
ImGui::EndDisabled(); ImGui::EndDisabled();
} }
{ {
ImGui::BeginDisabled(not application::get_hand_tracking_supported()); ImGui::BeginDisabled(not system.hand_tracking_supported());
bool enabled = config.check_feature(feature::hand_tracking); bool enabled = config.check_feature(feature::hand_tracking);
if (ImGui::Checkbox(_S("Enable hand tracking"), &enabled)) if (ImGui::Checkbox(_S("Enable hand tracking"), &enabled))
{ {
@@ -1690,7 +1690,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
.icon_disabled = ICON_FA_MICROPHONE_SLASH, .icon_disabled = ICON_FA_MICROPHONE_SLASH,
}); });
if (application::get_hand_tracking_supported()) if (system.hand_tracking_supported())
{ {
items.push_back({ items.push_back({
.f = feature::hand_tracking, .f = feature::hand_tracking,
@@ -2028,7 +2028,7 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
if (not is_gui_visible(*imgui_ctx, predicted_display_time)) if (not is_gui_visible(*imgui_ctx, predicted_display_time))
{ {
if (application::get_hand_tracking_supported()) if (system.hand_tracking_supported())
display_recentering_tip(*imgui_ctx, _("Press the grip button or put your palm up\nto move the main window")); display_recentering_tip(*imgui_ctx, _("Press the grip button or put your palm up\nto move the main window"));
else else
display_recentering_tip(*imgui_ctx, _("Press the grip button to move the main window")); display_recentering_tip(*imgui_ctx, _("Press the grip button to move the main window"));
+2
View File
@@ -493,6 +493,8 @@ void scenes::stream::on_unfocused()
loader.reset(); loader.reset();
renderer.reset(); renderer.reset();
clear_swapchains(); clear_swapchains();
left_hand.reset();
right_hand.reset();
imgui_ctx.reset(); imgui_ctx.reset();
swapchain_imgui = xr::swapchain(); swapchain_imgui = xr::swapchain();
+2
View File
@@ -129,6 +129,8 @@ private:
std::optional<audio> audio_handle; std::optional<audio> audio_handle;
std::optional<xr::hand_tracker> left_hand;
std::optional<xr::hand_tracker> right_hand;
std::optional<input_profile> input; std::optional<input_profile> input;
static inline const uint32_t layer_controllers = 1 << 0; static inline const uint32_t layer_controllers = 1 << 0;
static inline const uint32_t layer_rays = 1 << 1; static inline const uint32_t layer_rays = 1 << 1;
+16 -3
View File
@@ -645,6 +645,19 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
break; break;
} }
imgui_ctx->set_controllers_enabled(interactable); imgui_ctx->set_controllers_enabled(interactable);
if (interactable)
{
if (system.hand_tracking_supported())
{
left_hand = session.create_hand_tracker(XR_HAND_LEFT_EXT);
right_hand = session.create_hand_tracker(XR_HAND_RIGHT_EXT);
}
}
else
{
left_hand.reset();
right_hand.reset();
}
if (gui_status != last_gui_status) if (gui_status != last_gui_status)
{ {
@@ -876,10 +889,10 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
bool hide_left_controller = false; bool hide_left_controller = false;
bool hide_right_controller = false; bool hide_right_controller = false;
if (application::get_hand_tracking_supported()) if (left_hand and right_hand)
{ {
auto left = application::get_left_hand().locate(world_space, predicted_display_time); auto left = left_hand->locate(world_space, predicted_display_time);
auto right = application::get_right_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 xr::hand_tracker::check_flags(*left, XR_SPACE_LOCATION_POSITION_TRACKED_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT, 0))
hide_left_controller = true; hide_left_controller = true;
+22 -4
View File
@@ -385,6 +385,8 @@ void scenes::stream::tracking()
std::vector<serialization_packet> packets; std::vector<serialization_packet> packets;
const bool hand_tracking = config.check_feature(feature::hand_tracking); const bool hand_tracking = config.check_feature(feature::hand_tracking);
std::optional<xr::hand_tracker> left_hand;
std::optional<xr::hand_tracker> right_hand;
const bool face_tracking = config.check_feature(feature::face_tracking); const bool face_tracking = config.check_feature(feature::face_tracking);
auto & face_tracker = application::get_face_tracker(); auto & face_tracker = application::get_face_tracker();
@@ -435,6 +437,22 @@ void scenes::stream::tracking()
auto control = *tracking_control.lock(); auto control = *tracking_control.lock();
if (control.enabled[size_t(tid::left_hand)])
{
if (not left_hand and system.hand_tracking_supported())
left_hand = session.create_hand_tracker(XR_HAND_LEFT_EXT);
}
else
left_hand.reset();
if (control.enabled[size_t(tid::right_hand)])
{
if (not right_hand and system.hand_tracking_supported())
right_hand = session.create_hand_tracker(XR_HAND_RIGHT_EXT);
}
else
right_hand.reset();
XrDuration prediction = std::clamp<XrDuration>(control.max_offset.count(), 0, 80'000'000); XrDuration prediction = std::clamp<XrDuration>(control.max_offset.count(), 0, 80'000'000);
auto period = std::max<XrDuration>(display_time_period.load(), 1'000'000); auto period = std::max<XrDuration>(display_time_period.load(), 1'000'000);
for (XrDuration Δt = display_time_phase - t0 % period + (control.min_offset.count() / period) * period; for (XrDuration Δt = display_time_phase - t0 % period + (control.min_offset.count() / period) * period;
@@ -465,9 +483,9 @@ void scenes::stream::tracking()
(Δt == 0 or Δt >= prediction - 2 * period)) (Δt == 0 or Δt >= prediction - 2 * period))
{ {
last_hand_sample = t0; last_hand_sample = t0;
if (control.enabled[size_t(tid::left_hand)]) if (left_hand)
{ {
auto joints = locate_hands(application::get_left_hand(), world_space, t0 + Δt); auto joints = locate_hands(*left_hand, world_space, t0 + Δt);
hands.emplace_back( hands.emplace_back(
t0, t0,
t0 + Δt, t0 + Δt,
@@ -475,9 +493,9 @@ void scenes::stream::tracking()
joints); joints);
} }
if (control.enabled[size_t(tid::right_hand)]) if (right_hand)
{ {
auto joints = locate_hands(application::get_right_hand(), world_space, t0 + Δt); auto joints = locate_hands(*right_hand, world_space, t0 + Δt);
hands.emplace_back( hands.emplace_back(
t0, t0,
t0 + Δt, t0 + Δt,
+8
View File
@@ -41,6 +41,9 @@ xr::system::system(xr::instance & inst, XrFormFactor formfactor)
CHECK_XR(xrGetSystem(inst, &system_info, &id)); CHECK_XR(xrGetSystem(inst, &system_info, &id));
assert(id != XR_NULL_SYSTEM_ID); assert(id != XR_NULL_SYSTEM_ID);
if (inst.has_extension(XR_EXT_HAND_TRACKING_EXTENSION_NAME))
hand_tracking_supported_ = hand_tracking_properties().supportsHandTracking;
} }
XrGraphicsRequirementsVulkan2KHR xr::system::graphics_requirements() const XrGraphicsRequirementsVulkan2KHR xr::system::graphics_requirements() const
@@ -236,6 +239,11 @@ xr::system::passthrough_type xr::system::passthrough_supported() const
return passthrough_type::no_passthrough; return passthrough_type::no_passthrough;
} }
bool xr::system::hand_tracking_supported() const
{
return hand_tracking_supported_;
}
vk::raii::PhysicalDevice xr::system::physical_device(vk::raii::Instance & vulkan) const vk::raii::PhysicalDevice xr::system::physical_device(vk::raii::Instance & vulkan) const
{ {
auto xrGetVulkanGraphicsDevice2KHR = auto xrGetVulkanGraphicsDevice2KHR =
+2
View File
@@ -36,6 +36,7 @@ class system
{ {
instance * inst = nullptr; instance * inst = nullptr;
XrSystemId id = XR_NULL_SYSTEM_ID; XrSystemId id = XR_NULL_SYSTEM_ID;
bool hand_tracking_supported_ = false;
public: public:
enum class passthrough_type enum class passthrough_type
@@ -68,6 +69,7 @@ public:
XrSystemBodyTrackingPropertiesFB fb_body_tracking_properties() const; XrSystemBodyTrackingPropertiesFB fb_body_tracking_properties() const;
XrSystemBodyTrackingPropertiesBD bd_body_tracking_properties() const; XrSystemBodyTrackingPropertiesBD bd_body_tracking_properties() const;
passthrough_type passthrough_supported() const; passthrough_type passthrough_supported() const;
bool hand_tracking_supported() const;
XrGraphicsRequirementsVulkan2KHR graphics_requirements() const; XrGraphicsRequirementsVulkan2KHR graphics_requirements() const;
vk::raii::PhysicalDevice physical_device(vk::raii::Instance & vulkan) const; vk::raii::PhysicalDevice physical_device(vk::raii::Instance & vulkan) const;