Forward XR_EXT_hand_interaction

* Fix binds

* hand_interaction tids
This commit is contained in:
Sapphire
2025-07-09 10:33:32 +02:00
committed by xytovl
parent 74befe1f4a
commit 8f0ca7b04c
9 changed files with 350 additions and 118 deletions
+73 -10
View File
@@ -517,6 +517,35 @@ static std::vector<interaction_profile> interaction_profiles{
"/user/hand/right/input/thumbrest/touch",
},
},
interaction_profile{
.profile_name = "/interaction_profiles/ext/hand_interaction_ext",
.required_extensions = {"XR_EXT_hand_interaction"},
.input_sources = {
"/user/hand/left/input/aim/pose",
"/user/hand/left/input/grip/pose",
"/user/hand/left/input/pinch_ext/pose",
"/user/hand/left/input/pinch_ext/value",
"/user/hand/left/input/pinch_ext/ready_ext",
"/user/hand/left/input/poke_ext/pose",
"/user/hand/left/input/aim_activate_ext/value",
"/user/hand/left/input/aim_activate_ext/ready_ext",
"/user/hand/left/input/grasp_ext/value",
"/user/hand/left/input/grasp_ext/ready_ext",
"/user/hand/right/input/aim/pose",
"/user/hand/right/input/grip/pose",
"/user/hand/right/input/pinch_ext/pose",
"/user/hand/right/input/pinch_ext/value",
"/user/hand/right/input/pinch_ext/ready_ext",
"/user/hand/right/input/poke_ext/pose",
"/user/hand/right/input/aim_activate_ext/value",
"/user/hand/right/input/aim_activate_ext/ready_ext",
"/user/hand/right/input/grasp_ext/value",
"/user/hand/right/input/grasp_ext/ready_ext",
},
},
interaction_profile{
.profile_name = "/interaction_profiles/htc/vive_xr_tracker",
.required_extensions = {"XR_HTC_vive_xr_tracker_interaction", "XR_HTC_path_enumeration"},
@@ -556,6 +585,9 @@ static const std::pair<std::string_view, XrActionType> action_suffixes[] =
{"/joystick", XR_ACTION_TYPE_VECTOR2F_INPUT},
{"/trackball", XR_ACTION_TYPE_VECTOR2F_INPUT},
// XR_EXT_hand_interaction
{"/ready_ext", XR_ACTION_TYPE_BOOLEAN_INPUT},
// Output paths
{"/haptic", XR_ACTION_TYPE_VIBRATION_OUTPUT},
{"/haptic_trigger", XR_ACTION_TYPE_VIBRATION_OUTPUT},
@@ -949,19 +981,41 @@ void application::initialize_actions()
continue;
// Patch profile to add grip_surface or palm_ext
if ((api_version >= XR_MAKE_VERSION(1, 1, 0) or utils::contains(xr_extensions, XR_KHR_MAINTENANCE1_EXTENSION_NAME)) //
and utils::contains(profile.input_sources, "/user/hand/left/input/grip/pose") //
and not utils::contains(profile.input_sources, "/user/hand/left/input/grip_surface/pose"))
bool add_palms = true;
if (profile.profile_name.ends_with("ext/hand_interaction_ext"))
{
profile.input_sources.push_back("/user/hand/left/input/grip_surface/pose");
profile.input_sources.push_back("/user/hand/right/input/grip_surface/pose");
switch (guess_model())
{
// Quest breaks spec and does not support grip_surface for ext/hand_interaction_ext
case model::meta_quest_3:
case model::meta_quest_pro:
case model::meta_quest_3s:
case model::oculus_quest_2:
case model::oculus_quest:
add_palms = false;
break;
default:
break;
}
}
else if (utils::contains(xr_extensions, XR_EXT_PALM_POSE_EXTENSION_NAME) //
and utils::contains(profile.input_sources, "/user/hand/left/input/grip/pose") //
and not utils::contains(profile.input_sources, "/user/hand/left/input/palm_ext/pose"))
if (add_palms)
{
profile.input_sources.push_back("/user/hand/left/input/palm_ext/pose");
profile.input_sources.push_back("/user/hand/right/input/palm_ext/pose");
if ((api_version >= XR_MAKE_VERSION(1, 1, 0) or utils::contains(xr_extensions, XR_KHR_MAINTENANCE1_EXTENSION_NAME)) //
and utils::contains(profile.input_sources, "/user/hand/left/input/grip/pose") //
and not utils::contains(profile.input_sources, "/user/hand/left/input/grip_surface/pose"))
{
spdlog::info("Adding grip_surface/pose for interaction profile {}", profile.profile_name);
profile.input_sources.push_back("/user/hand/left/input/grip_surface/pose");
profile.input_sources.push_back("/user/hand/right/input/grip_surface/pose");
}
else if (utils::contains(xr_extensions, XR_EXT_PALM_POSE_EXTENSION_NAME) //
and utils::contains(profile.input_sources, "/user/hand/left/input/grip/pose") //
and not utils::contains(profile.input_sources, "/user/hand/left/input/palm_ext/pose"))
{
spdlog::info("Adding palm_ext/pose for interaction profile {}", profile.profile_name);
profile.input_sources.push_back("/user/hand/left/input/palm_ext/pose");
profile.input_sources.push_back("/user/hand/right/input/palm_ext/pose");
}
}
// Dynamically add VIVE XR Trackers to the profile if available
@@ -1004,12 +1058,20 @@ void application::initialize_actions()
spaces[size_t(xr::spaces::aim_left)] = xr_session.create_action_space(a);
else if (name == "/user/hand/left/input/palm_ext/pose" or name == "/user/hand/left/input/grip_surface/pose")
spaces[size_t(xr::spaces::palm_left)] = xr_session.create_action_space(a);
else if (name == "/user/hand/left/input/pinch_ext/pose")
spaces[size_t(xr::spaces::pinch_left)] = xr_session.create_action_space(a);
else if (name == "/user/hand/left/input/poke_ext/pose")
spaces[size_t(xr::spaces::poke_left)] = xr_session.create_action_space(a);
else if (name == "/user/hand/right/input/grip/pose")
spaces[size_t(xr::spaces::grip_right)] = xr_session.create_action_space(a);
else if (name == "/user/hand/right/input/aim/pose")
spaces[size_t(xr::spaces::aim_right)] = xr_session.create_action_space(a);
else if (name == "/user/hand/right/input/palm_ext/pose" or name == "/user/hand/right/input/grip_surface/pose")
spaces[size_t(xr::spaces::palm_right)] = xr_session.create_action_space(a);
else if (name == "/user/hand/right/input/pinch_ext/pose")
spaces[size_t(xr::spaces::pinch_right)] = xr_session.create_action_space(a);
else if (name == "/user/hand/right/input/poke_ext/pose")
spaces[size_t(xr::spaces::poke_right)] = xr_session.create_action_space(a);
else if (name == "/user/eyes_ext/input/gaze_ext/pose")
spaces[size_t(xr::spaces::eye_gaze)] = xr_session.create_action_space(a);
else if (name.contains("/input/entity_htc/pose") && htc_body)
@@ -1098,6 +1160,7 @@ void application::initialize()
opt_extensions.push_back(XR_KHR_MAINTENANCE1_EXTENSION_NAME);
opt_extensions.push_back(XR_FB_DISPLAY_REFRESH_RATE_EXTENSION_NAME);
opt_extensions.push_back(XR_EXT_HAND_TRACKING_EXTENSION_NAME);
opt_extensions.push_back(XR_EXT_HAND_INTERACTION_EXTENSION_NAME);
opt_extensions.push_back(XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME);
opt_extensions.push_back(XR_FB_PASSTHROUGH_EXTENSION_NAME);
opt_extensions.push_back(XR_HTC_PASSTHROUGH_EXTENSION_NAME);
+15
View File
@@ -117,6 +117,21 @@ static const std::unordered_map<std::string, device_id> device_ids = {
{"/user/hand/right/input/trackpad/force", device_id::RIGHT_TRACKPAD_FORCE},
{"/user/hand/right/input/stylus/force", device_id::RIGHT_STYLUS_FORCE},
{"/user/hand/right/input/stylus_fb/force", device_id::RIGHT_STYLUS_FORCE},
// XR_EXT_hand_interaction
{"/user/hand/left/input/pinch_ext/value", device_id::LEFT_PINCH_VALUE},
{"/user/hand/left/input/pinch_ext/ready_ext", device_id::LEFT_PINCH_READY},
{"/user/hand/left/input/aim_activate_ext/value",device_id::LEFT_AIM_ACTIVATE_VALUE},
{"/user/hand/left/input/aim_activate_ext/ready_ext",device_id::LEFT_AIM_ACTIVATE_READY},
{"/user/hand/left/input/grasp_ext/value", device_id::LEFT_GRASP_VALUE},
{"/user/hand/left/input/grasp_ext/ready_ext", device_id::LEFT_GRASP_READY},
{"/user/hand/right/input/pinch_ext/value", device_id::RIGHT_PINCH_VALUE},
{"/user/hand/right/input/pinch_ext/ready_ext", device_id::RIGHT_PINCH_READY},
{"/user/hand/right/input/aim_activate_ext/value",device_id::RIGHT_AIM_ACTIVATE_VALUE},
{"/user/hand/right/input/aim_activate_ext/ready_ext",device_id::RIGHT_AIM_ACTIVATE_READY},
{"/user/hand/right/input/grasp_ext/value", device_id::RIGHT_GRASP_VALUE},
{"/user/hand/right/input/grasp_ext/ready_ext", device_id::RIGHT_GRASP_READY},
};
// clang-format on
+67 -37
View File
@@ -234,31 +234,6 @@ static std::optional<std::array<from_headset::hand_tracking::pose, XR_HAND_JOINT
return std::nullopt;
}
static bool enabled(const to_headset::tracking_control & control, device_id id)
{
switch (id)
{
case device_id::HEAD:
case device_id::EYE_GAZE:
return true;
case device_id::LEFT_AIM:
return control.enabled[size_t(tid::left_aim)];
case device_id::LEFT_GRIP:
return control.enabled[size_t(tid::left_grip)];
case device_id::LEFT_PALM:
return control.enabled[size_t(tid::left_palm)];
case device_id::RIGHT_AIM:
return control.enabled[size_t(tid::right_aim)];
case device_id::RIGHT_GRIP:
return control.enabled[size_t(tid::right_grip)];
case device_id::RIGHT_PALM:
return control.enabled[size_t(tid::right_palm)];
default:
break;
}
__builtin_unreachable();
}
template <typename T>
static T & from_pool(std::vector<T> & container, std::vector<T> & pool)
{
@@ -283,12 +258,20 @@ static xr::spaces device_to_space(device_id id)
return xr::spaces::grip_left;
case device_id::LEFT_PALM:
return xr::spaces::palm_left;
case device_id::LEFT_PINCH_POSE:
return xr::spaces::pinch_left;
case device_id::LEFT_POKE:
return xr::spaces::poke_left;
case device_id::RIGHT_AIM:
return xr::spaces::aim_right;
case device_id::RIGHT_GRIP:
return xr::spaces::grip_right;
case device_id::RIGHT_PALM:
return xr::spaces::palm_right;
case device_id::RIGHT_PINCH_POSE:
return xr::spaces::pinch_right;
case device_id::RIGHT_POKE:
return xr::spaces::poke_right;
default:
assert(false);
__builtin_unreachable();
@@ -306,20 +289,66 @@ void scenes::stream::tracking()
#endif
std::vector<std::pair<device_id, XrSpace>> spaces;
for (auto id: {
device_id::HEAD,
device_id::LEFT_AIM,
device_id::LEFT_GRIP,
device_id::LEFT_PALM,
device_id::RIGHT_AIM,
device_id::RIGHT_GRIP,
device_id::RIGHT_PALM,
})
{
if (XrSpace space = application::space(device_to_space(id)))
spaces.emplace_back(id, space);
std::vector ids{
device_id::HEAD,
device_id::LEFT_AIM,
device_id::LEFT_GRIP,
device_id::LEFT_PALM,
device_id::RIGHT_AIM,
device_id::RIGHT_GRIP,
device_id::RIGHT_PALM,
};
if (instance.has_extension("XR_EXT_hand_interaction"))
{
spdlog::info("Adding hand_interaction poses to device list");
ids.insert(ids.end(), {device_id::LEFT_PINCH_POSE, device_id::LEFT_POKE, device_id::RIGHT_PINCH_POSE, device_id::RIGHT_POKE});
}
for (auto id: ids)
{
if (XrSpace space = application::space(device_to_space(id)))
spaces.emplace_back(id, space);
else
spdlog::warn("Missing space for device {}", magic_enum::enum_name(id));
}
}
auto enabled = [this](const to_headset::tracking_control & control, device_id id) -> bool {
switch (id)
{
case device_id::HEAD:
case device_id::EYE_GAZE:
return true;
case device_id::LEFT_AIM:
return control.enabled[size_t(tid::left_aim)];
case device_id::LEFT_GRIP:
return control.enabled[size_t(tid::left_grip)];
case device_id::LEFT_PALM:
return control.enabled[size_t(tid::left_palm)];
case device_id::LEFT_PINCH_POSE:
case device_id::LEFT_POKE: {
const auto tracking_id = id == device_id::LEFT_PINCH_POSE ? tid::left_pinch : tid::left_poke;
return control.enabled[size_t(tracking_id)] and interaction_profiles[0].load() == interaction_profile::ext_hand_interaction_ext;
}
case device_id::RIGHT_AIM:
return control.enabled[size_t(tid::right_aim)];
case device_id::RIGHT_GRIP:
return control.enabled[size_t(tid::right_grip)];
case device_id::RIGHT_PALM:
return control.enabled[size_t(tid::right_palm)];
case device_id::RIGHT_PINCH_POSE:
case device_id::RIGHT_POKE: {
const auto tracking_id = id == device_id::RIGHT_PINCH_POSE ? tid::right_pinch : tid::right_poke;
return control.enabled[size_t(tracking_id)] and interaction_profiles[1].load() == interaction_profile::ext_hand_interaction_ext;
}
default:
break;
}
throw std::runtime_error("enabled called on unhandled device " + std::string(magic_enum::enum_name(id)));
};
const auto & config = application::get_config();
if (config.check_feature(feature::eye_gaze))
@@ -712,6 +741,7 @@ void scenes::stream::on_interaction_profile_changed(const XrEventDataInteraction
auto profile = session.get_current_interaction_profile(path[i]);
spdlog::info("interaction profile for {}: {}", path[i], profile);
DO_PROFILE(khr, simple_controller)
DO_PROFILE(ext, hand_interaction_ext)
DO_PROFILE(bytedance, pico_neo3_controller)
DO_PROFILE(bytedance, pico4_controller)
DO_PROFILE(bytedance, pico4s_controller)
@@ -737,7 +767,7 @@ void scenes::stream::on_interaction_profile_changed(const XrEventDataInteraction
}
catch (std::exception & e)
{
spdlog::warn("Failed to get current interation profile: {}", e.what());
spdlog::warn("Failed to get current interaction profile: {}", e.what());
}
interaction_profiles[i] = interaction_profile::none;
}
+5
View File
@@ -37,6 +37,11 @@ enum class spaces
aim_right,
palm_left,
palm_right,
// hand_interaction_ext
pinch_left,
pinch_right,
poke_left,
poke_right,
count
};