When the runtime does not track the hands:
- Hide them in the lobby - Don't send tracking data in the stream
This commit is contained in:
@@ -19,11 +19,12 @@
|
||||
#include "hand_model.h"
|
||||
#include "openxr/openxr.h"
|
||||
#include "utils/ranges.h"
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
hand_model::hand_model(xr::hand_tracker & hand, const std::filesystem::path & gltf_path, scene_loader & loader, scene_data & scene) :
|
||||
hand(hand)
|
||||
{
|
||||
node_handle root_node = scene.new_node();
|
||||
root_node = scene.new_node();
|
||||
root_node->name = gltf_path.stem();
|
||||
|
||||
scene.import(loader(gltf_path), root_node);
|
||||
@@ -61,24 +62,33 @@ hand_model::hand_model(xr::hand_tracker & hand, const std::filesystem::path & gl
|
||||
|
||||
void hand_model::apply(XrSpace world_space, XrTime predicted_display_time)
|
||||
{
|
||||
std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT> joints_location = hand.locate(world_space, predicted_display_time);
|
||||
auto joints_location = hand.locate(world_space, predicted_display_time);
|
||||
|
||||
for(auto&& [joint, loc]: utils::zip(joints, joints_location))
|
||||
if (joints_location)
|
||||
{
|
||||
if (!joint)
|
||||
continue;
|
||||
root_node->visible = true;
|
||||
|
||||
joint->position = {
|
||||
loc.first.pose.position.x,
|
||||
loc.first.pose.position.y,
|
||||
loc.first.pose.position.z
|
||||
};
|
||||
for(auto&& [joint, loc]: utils::zip(joints, *joints_location))
|
||||
{
|
||||
if (!joint)
|
||||
continue;
|
||||
|
||||
joint->orientation = {
|
||||
loc.first.pose.orientation.w,
|
||||
loc.first.pose.orientation.x,
|
||||
loc.first.pose.orientation.y,
|
||||
loc.first.pose.orientation.z
|
||||
};
|
||||
joint->position = {
|
||||
loc.first.pose.position.x,
|
||||
loc.first.pose.position.y,
|
||||
loc.first.pose.position.z
|
||||
};
|
||||
|
||||
joint->orientation = {
|
||||
loc.first.pose.orientation.w,
|
||||
loc.first.pose.orientation.x,
|
||||
loc.first.pose.orientation.y,
|
||||
loc.first.pose.orientation.z
|
||||
};
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
root_node->visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ struct hand_model
|
||||
{
|
||||
xr::hand_tracker& hand;
|
||||
|
||||
node_handle root_node;
|
||||
std::vector<node_handle> joints;
|
||||
|
||||
hand_model(xr::hand_tracker & hand, const std::filesystem::path & gltf_path, scene_loader& loader, scene_data& scene);
|
||||
|
||||
@@ -63,40 +63,45 @@ static from_headset::tracking::pose locate_space(device_id device, XrSpace space
|
||||
return res;
|
||||
}
|
||||
|
||||
static std::array<from_headset::hand_tracking::pose, XR_HAND_JOINT_COUNT_EXT> locate_hands(xr::hand_tracker& hand, XrSpace space, XrTime time)
|
||||
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)
|
||||
{
|
||||
std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT> joints = hand.locate(space, time);
|
||||
auto joints = hand.locate(space, time);
|
||||
|
||||
std::array<from_headset::hand_tracking::pose, XR_HAND_JOINT_COUNT_EXT> poses;
|
||||
for(int i = 0; i < XR_HAND_JOINT_COUNT_EXT; i++)
|
||||
if (joints)
|
||||
{
|
||||
poses[i] = {
|
||||
.pose = joints[i].first.pose,
|
||||
.linear_velocity = joints[i].second.linearVelocity,
|
||||
.angular_velocity = joints[i].second.angularVelocity,
|
||||
.radius = joints[i].first.radius,
|
||||
};
|
||||
std::array<from_headset::hand_tracking::pose, XR_HAND_JOINT_COUNT_EXT> poses;
|
||||
for(int i = 0; i < XR_HAND_JOINT_COUNT_EXT; i++)
|
||||
{
|
||||
poses[i] = {
|
||||
.pose = (*joints)[i].first.pose,
|
||||
.linear_velocity = (*joints)[i].second.linearVelocity,
|
||||
.angular_velocity = (*joints)[i].second.angularVelocity,
|
||||
.radius = (*joints)[i].first.radius,
|
||||
};
|
||||
|
||||
if (joints[i].first.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT)
|
||||
poses[i].flags |= from_headset::hand_tracking::orientation_valid;
|
||||
if ((*joints)[i].first.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT)
|
||||
poses[i].flags |= from_headset::hand_tracking::orientation_valid;
|
||||
|
||||
if (joints[i].first.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT)
|
||||
poses[i].flags |= from_headset::hand_tracking::position_valid;
|
||||
if ((*joints)[i].first.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT)
|
||||
poses[i].flags |= from_headset::hand_tracking::position_valid;
|
||||
|
||||
if (joints[i].second.velocityFlags & XR_SPACE_VELOCITY_LINEAR_VALID_BIT)
|
||||
poses[i].flags |= from_headset::hand_tracking::linear_velocity_valid;
|
||||
if ((*joints)[i].second.velocityFlags & XR_SPACE_VELOCITY_LINEAR_VALID_BIT)
|
||||
poses[i].flags |= from_headset::hand_tracking::linear_velocity_valid;
|
||||
|
||||
if (joints[i].second.velocityFlags & XR_SPACE_VELOCITY_ANGULAR_VALID_BIT)
|
||||
poses[i].flags |= from_headset::hand_tracking::angular_velocity_valid;
|
||||
if ((*joints)[i].second.velocityFlags & XR_SPACE_VELOCITY_ANGULAR_VALID_BIT)
|
||||
poses[i].flags |= from_headset::hand_tracking::angular_velocity_valid;
|
||||
|
||||
if (joints[i].first.locationFlags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT)
|
||||
poses[i].flags |= from_headset::hand_tracking::orientation_tracked;
|
||||
if ((*joints)[i].first.locationFlags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT)
|
||||
poses[i].flags |= from_headset::hand_tracking::orientation_tracked;
|
||||
|
||||
if (joints[i].first.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT)
|
||||
poses[i].flags |= from_headset::hand_tracking::position_tracked;
|
||||
if ((*joints)[i].first.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT)
|
||||
poses[i].flags |= from_headset::hand_tracking::position_tracked;
|
||||
}
|
||||
|
||||
return poses;
|
||||
}
|
||||
|
||||
return poses;
|
||||
else
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void scenes::stream::tracking()
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include "hand_tracker.h"
|
||||
|
||||
|
||||
std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT> xr::hand_tracker::locate(XrSpace space, XrTime time)
|
||||
std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> xr::hand_tracker::locate(XrSpace space, XrTime time)
|
||||
{
|
||||
XrHandJointsLocateInfoEXT info{
|
||||
.type = XR_TYPE_HAND_JOINTS_LOCATE_INFO_EXT,
|
||||
@@ -49,9 +49,7 @@ std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT> xr::hand_tracker::l
|
||||
CHECK_XR(xrLocateHandJointsEXT(id, &info, &locations));
|
||||
|
||||
if (!locations.isActive)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
return std::nullopt;
|
||||
|
||||
std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT> joints;
|
||||
for(int i = 0; i < XR_HAND_JOINT_COUNT_EXT; i++)
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <openxr/openxr.h>
|
||||
#include <array>
|
||||
#include <utility>
|
||||
#include <optional>
|
||||
|
||||
#include "instance.h"
|
||||
|
||||
@@ -52,6 +53,6 @@ public:
|
||||
|
||||
using joint = std::pair<XrHandJointLocationEXT, XrHandJointVelocityEXT>;
|
||||
|
||||
std::array<joint, XR_HAND_JOINT_COUNT_EXT> locate(XrSpace space, XrTime time);
|
||||
std::optional<std::array<joint, XR_HAND_JOINT_COUNT_EXT>> locate(XrSpace space, XrTime time);
|
||||
};
|
||||
} // namespace xr
|
||||
|
||||
@@ -170,8 +170,8 @@ struct hand_tracking
|
||||
};
|
||||
|
||||
XrTime timestamp;
|
||||
std::array<pose, XR_HAND_JOINT_COUNT_EXT> left;
|
||||
std::array<pose, XR_HAND_JOINT_COUNT_EXT> right;
|
||||
std::optional<std::array<pose, XR_HAND_JOINT_COUNT_EXT>> left;
|
||||
std::optional<std::array<pose, XR_HAND_JOINT_COUNT_EXT>> right;
|
||||
};
|
||||
|
||||
struct inputs
|
||||
|
||||
@@ -88,26 +88,34 @@ static xrt_space_relation to_relation(const from_headset::hand_tracking::pose& p
|
||||
};
|
||||
}
|
||||
|
||||
static xrt_hand_joint_set convert_joints(const std::array<from_headset::hand_tracking::pose, XR_HAND_JOINT_COUNT_EXT>& input_joints)
|
||||
static xrt_hand_joint_set convert_joints(const std::optional<std::array<from_headset::hand_tracking::pose, XR_HAND_JOINT_COUNT_EXT>>& input_joints)
|
||||
{
|
||||
xrt_hand_joint_set output_joints;
|
||||
xrt_hand_joint_set output_joints{};
|
||||
|
||||
output_joints.is_active = true;
|
||||
output_joints.hand_pose = to_relation(input_joints[XRT_HAND_JOINT_WRIST]);
|
||||
|
||||
xrt_relation_chain rel_chain{};
|
||||
xrt_space_relation * joint_rel = m_relation_chain_reserve(&rel_chain);
|
||||
m_relation_chain_push_inverted_relation(&rel_chain, &output_joints.hand_pose);
|
||||
|
||||
for(int i = 0; i < XR_HAND_JOINT_COUNT_EXT; i++)
|
||||
if (input_joints)
|
||||
{
|
||||
xrt_hand_joint_value& res = output_joints.values.hand_joint_set_default[i];
|
||||
output_joints.is_active = true;
|
||||
output_joints.hand_pose = to_relation((*input_joints)[XRT_HAND_JOINT_WRIST]);
|
||||
|
||||
res.radius = input_joints[i].radius;
|
||||
*joint_rel = to_relation(input_joints[i]);
|
||||
xrt_relation_chain rel_chain{};
|
||||
xrt_space_relation * joint_rel = m_relation_chain_reserve(&rel_chain);
|
||||
m_relation_chain_push_inverted_relation(&rel_chain, &output_joints.hand_pose);
|
||||
|
||||
m_relation_chain_resolve(&rel_chain, &res.relation);
|
||||
for(int i = 0; i < XR_HAND_JOINT_COUNT_EXT; i++)
|
||||
{
|
||||
xrt_hand_joint_value& res = output_joints.values.hand_joint_set_default[i];
|
||||
|
||||
res.radius = (*input_joints)[i].radius;
|
||||
*joint_rel = to_relation((*input_joints)[i]);
|
||||
|
||||
m_relation_chain_resolve(&rel_chain, &res.relation);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
output_joints.is_active = false;
|
||||
}
|
||||
|
||||
return output_joints;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user