Only ask actual hand tracking in lobby
This commit is contained in:
@@ -580,10 +580,10 @@ std::vector<imgui_context::controller_state> imgui_context::read_controllers_sta
|
||||
current_aim_interaction = 1;
|
||||
if (ctrl.hand)
|
||||
{
|
||||
if (auto hand = ctrl.hand->locate(world, display_time); hand.joints and hand.is_input_source())
|
||||
if (auto hand = ctrl.hand->locate(world, display_time).joints)
|
||||
{
|
||||
XrHandJointLocationEXT & index_tip = (*hand.joints)[XR_HAND_JOINT_INDEX_TIP_EXT].first;
|
||||
XrHandJointLocationEXT & palm = (*hand.joints)[XR_HAND_JOINT_PALM_EXT].first;
|
||||
XrHandJointLocationEXT & index_tip = (*hand)[XR_HAND_JOINT_INDEX_TIP_EXT].first;
|
||||
XrHandJointLocationEXT & palm = (*hand)[XR_HAND_JOINT_PALM_EXT].first;
|
||||
|
||||
if (index_tip.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT)
|
||||
{
|
||||
|
||||
+11
-13
@@ -980,29 +980,27 @@ void scenes::lobby::render(const XrFrameState & frame_state)
|
||||
{
|
||||
auto windows = imgui_ctx->windows();
|
||||
|
||||
auto left = left_hand->locate(world_space, frame_state.predictedDisplayTime);
|
||||
if (left.joints)
|
||||
auto left = left_hand->locate(world_space, frame_state.predictedDisplayTime).joints;
|
||||
if (left)
|
||||
{
|
||||
if (left.is_input_source())
|
||||
stick_finger_to_gui(*left.joints, windows);
|
||||
stick_finger_to_gui(*left, windows);
|
||||
hide_left_controller = true;
|
||||
}
|
||||
|
||||
auto right = right_hand->locate(world_space, frame_state.predictedDisplayTime);
|
||||
if (right.joints)
|
||||
auto right = right_hand->locate(world_space, frame_state.predictedDisplayTime).joints;
|
||||
if (right)
|
||||
{
|
||||
if (right.is_input_source())
|
||||
stick_finger_to_gui(*right.joints, windows);
|
||||
stick_finger_to_gui(*right, windows);
|
||||
hide_right_controller = true;
|
||||
}
|
||||
|
||||
hand_model::apply(world, left.joints ? &*left.joints : nullptr, right.joints ? &*right.joints : nullptr);
|
||||
hand_model::apply(world, left ? &*left : nullptr, right ? &*right : nullptr);
|
||||
|
||||
if (not new_gui_position and head_position and left.joints 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 and left)
|
||||
new_gui_position = check_recenter_gesture(xr::spaces::palm_left, *left, *head_position);
|
||||
|
||||
if (not new_gui_position and head_position and right.joints and right.is_input_source())
|
||||
new_gui_position = check_recenter_gesture(xr::spaces::palm_right, *right.joints, *head_position);
|
||||
if (not new_gui_position and head_position and right)
|
||||
new_gui_position = check_recenter_gesture(xr::spaces::palm_right, *right, *head_position);
|
||||
}
|
||||
|
||||
if (head_position and new_gui_position)
|
||||
|
||||
@@ -1095,15 +1095,15 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
|
||||
if (left_hand and right_hand)
|
||||
{
|
||||
auto left = left_hand->locate(world_space, predicted_display_time);
|
||||
auto right = right_hand->locate(world_space, predicted_display_time);
|
||||
auto left = left_hand->locate(world_space, predicted_display_time).joints;
|
||||
auto right = right_hand->locate(world_space, predicted_display_time).joints;
|
||||
|
||||
if (left.joints 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))
|
||||
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;
|
||||
|
||||
if (right.joints 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))
|
||||
if (right and
|
||||
xr::hand_tracker::check_flags(*right, XR_SPACE_LOCATION_POSITION_TRACKED_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT, 0))
|
||||
hide_right_controller = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -400,10 +400,14 @@ void scenes::stream::tracking()
|
||||
|
||||
if (hand_tracking)
|
||||
{
|
||||
std::array data_sources = {
|
||||
XR_HAND_TRACKING_DATA_SOURCE_UNOBSTRUCTED_EXT,
|
||||
XR_HAND_TRACKING_DATA_SOURCE_CONTROLLER_EXT,
|
||||
};
|
||||
if (std::ranges::contains(pattern, device_id::LEFT_HAND, &to_headset::tracking_control::sample::device))
|
||||
{
|
||||
if (not left_hand)
|
||||
left_hand = session.create_hand_tracker(XR_HAND_LEFT_EXT);
|
||||
left_hand = session.create_hand_tracker(XR_HAND_LEFT_EXT, data_sources);
|
||||
}
|
||||
else
|
||||
left_hand.reset();
|
||||
@@ -411,7 +415,7 @@ void scenes::stream::tracking()
|
||||
if (std::ranges::contains(pattern, device_id::RIGHT_HAND, &to_headset::tracking_control::sample::device))
|
||||
{
|
||||
if (not right_hand)
|
||||
right_hand = session.create_hand_tracker(XR_HAND_RIGHT_EXT);
|
||||
right_hand = session.create_hand_tracker(XR_HAND_RIGHT_EXT, data_sources);
|
||||
}
|
||||
else
|
||||
right_hand.reset();
|
||||
|
||||
@@ -26,30 +26,25 @@
|
||||
#include <cassert>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
xr::hand_tracker::hand_tracker(instance & inst, session & session, const XrHandTrackerCreateInfoEXT & info) :
|
||||
xr::hand_tracker::hand_tracker(instance & inst, session & session, const XrHandTrackerCreateInfoEXT & info, std::span<XrHandTrackingDataSourceEXT> sources) :
|
||||
handle(inst.get_proc<PFN_xrDestroyHandTrackerEXT>("xrDestroyHandTrackerEXT")),
|
||||
hand_{info.hand}
|
||||
{
|
||||
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");
|
||||
|
||||
if (hand_tracking_data_source_supported)
|
||||
if (not sources.empty() and inst.has_extension(XR_EXT_HAND_TRACKING_DATA_SOURCE_EXTENSION_NAME))
|
||||
{
|
||||
// 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,
|
||||
};
|
||||
|
||||
use_data_source = true;
|
||||
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(),
|
||||
.requestedDataSourceCount = static_cast<uint32_t>(sources.size()),
|
||||
.requestedDataSources = sources.data(),
|
||||
};
|
||||
|
||||
auto create_info = info;
|
||||
@@ -103,7 +98,7 @@ xr::hand_tracker::located_hand xr::hand_tracker::locate(XrSpace space, XrTime ti
|
||||
.jointCount = joints_pos.size(),
|
||||
.jointLocations = joints_pos.data(),
|
||||
};
|
||||
if (hand_tracking_data_source_supported)
|
||||
if (use_data_source)
|
||||
locations.next = &data_source_state;
|
||||
|
||||
CHECK_XR(xrLocateHandJointsEXT(id, &info, &locations));
|
||||
@@ -126,7 +121,7 @@ xr::hand_tracker::located_hand xr::hand_tracker::locate(XrSpace space, XrTime ti
|
||||
}
|
||||
}
|
||||
|
||||
if (hand_tracking_data_source_supported)
|
||||
if (use_data_source)
|
||||
{
|
||||
res.data_source = data_source_state.dataSource;
|
||||
if (not data_source_state.isActive)
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "utils/handle.h"
|
||||
#include <array>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <openxr/openxr.h>
|
||||
@@ -41,13 +42,6 @@ public:
|
||||
{
|
||||
std::optional<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
|
||||
@@ -66,13 +60,13 @@ public:
|
||||
private:
|
||||
PFN_xrLocateHandJointsEXT xrLocateHandJointsEXT{};
|
||||
PFN_xrGetHandMeshFB xrGetHandMeshFB{};
|
||||
bool hand_tracking_data_source_supported = false;
|
||||
bool use_data_source = false;
|
||||
std::optional<mesh_data> cached_hand_mesh_fb;
|
||||
bool hand_mesh_fb_fetched = false;
|
||||
XrHandEXT hand_;
|
||||
|
||||
public:
|
||||
hand_tracker(instance & inst, session & session, const XrHandTrackerCreateInfoEXT & info);
|
||||
hand_tracker(instance & inst, session & session, const XrHandTrackerCreateInfoEXT & info, std::span<XrHandTrackingDataSourceEXT> sources = {});
|
||||
|
||||
located_hand locate(XrSpace space, XrTime time);
|
||||
const mesh_data * mesh();
|
||||
|
||||
@@ -99,7 +99,7 @@ xr::space xr::session::create_action_space(XrAction action, const XrPosef & pose
|
||||
return s;
|
||||
}
|
||||
|
||||
xr::hand_tracker xr::session::create_hand_tracker(XrHandEXT hand, XrHandJointSetEXT hand_joint_set)
|
||||
xr::hand_tracker xr::session::create_hand_tracker(XrHandEXT hand, std::span<XrHandTrackingDataSourceEXT> sources, XrHandJointSetEXT hand_joint_set)
|
||||
{
|
||||
return {
|
||||
*inst,
|
||||
@@ -109,7 +109,9 @@ xr::hand_tracker xr::session::create_hand_tracker(XrHandEXT hand, XrHandJointSet
|
||||
.next = nullptr,
|
||||
.hand = hand,
|
||||
.handJointSet = hand_joint_set,
|
||||
}};
|
||||
},
|
||||
sources,
|
||||
};
|
||||
}
|
||||
|
||||
std::vector<vk::Format> xr::session::get_swapchain_formats() const
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ public:
|
||||
std::vector<XrReferenceSpaceType> get_reference_spaces() const;
|
||||
space create_reference_space(XrReferenceSpaceType ref, const XrPosef & pose = {{0, 0, 0, 1}, {0, 0, 0}});
|
||||
space create_action_space(XrAction action, const XrPosef & pose = {{0, 0, 0, 1}, {0, 0, 0}});
|
||||
hand_tracker create_hand_tracker(XrHandEXT hand, XrHandJointSetEXT hand_joint_set = XR_HAND_JOINT_SET_DEFAULT_EXT);
|
||||
hand_tracker create_hand_tracker(XrHandEXT hand, std::span<XrHandTrackingDataSourceEXT> sources = {}, XrHandJointSetEXT hand_joint_set = XR_HAND_JOINT_SET_DEFAULT_EXT);
|
||||
|
||||
std::vector<vk::Format> get_swapchain_formats() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user