Hide the hand model if the controller is tracked
This commit is contained in:
@@ -21,8 +21,7 @@
|
||||
#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)
|
||||
hand_model::hand_model(const std::filesystem::path & gltf_path, scene_loader & loader, scene_data & scene)
|
||||
{
|
||||
root_node = scene.new_node();
|
||||
root_node->name = gltf_path.stem();
|
||||
@@ -60,10 +59,8 @@ hand_model::hand_model(xr::hand_tracker & hand, const std::filesystem::path & gl
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
void hand_model::apply(XrSpace world_space, XrTime predicted_display_time)
|
||||
void hand_model::apply(const std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>>& joints_location)
|
||||
{
|
||||
auto joints_location = hand.locate(world_space, predicted_display_time);
|
||||
|
||||
if (joints_location)
|
||||
{
|
||||
root_node->visible = true;
|
||||
|
||||
@@ -24,12 +24,10 @@
|
||||
|
||||
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);
|
||||
hand_model(const std::filesystem::path & gltf_path, scene_loader& loader, scene_data& scene);
|
||||
|
||||
void apply(XrSpace world_space, XrTime predicted_display_time);
|
||||
void apply(const std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>>& joints);
|
||||
};
|
||||
|
||||
@@ -288,10 +288,22 @@ static void apply_visual_response(node_handle node, input_profile::node_state_vi
|
||||
node->visible = value > 0.5;
|
||||
}
|
||||
|
||||
void input_profile::apply(XrSpace world_space, XrTime predicted_display_time)
|
||||
void input_profile::apply(XrSpace world_space, XrTime predicted_display_time, bool hide_left, bool hide_right)
|
||||
{
|
||||
for (auto && [space, node]: model_handles)
|
||||
{
|
||||
if (space == application::left_grip() && hide_left)
|
||||
{
|
||||
node->visible = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (space == application::right_grip() && hide_right)
|
||||
{
|
||||
node->visible = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (auto location = application::locate_controller(space, world_space, predicted_display_time); location)
|
||||
{
|
||||
node->visible = true;
|
||||
|
||||
@@ -63,5 +63,5 @@ struct input_profile
|
||||
input_profile(const std::filesystem::path& json_profile, scene_loader& loader, scene_data& scene);
|
||||
|
||||
// application::poll_actions() must have been called before
|
||||
void apply(XrSpace world_space, XrTime predicted_display_time);
|
||||
void apply(XrSpace world_space, XrTime predicted_display_time, bool hide_left, bool hide_right);
|
||||
};
|
||||
|
||||
+27
-7
@@ -584,13 +584,33 @@ void scenes::lobby::render(XrTime predicted_display_time, bool should_render)
|
||||
auto [flags, views] = session.locate_views(viewconfig, predicted_display_time, world_space);
|
||||
assert(views.size() == swapchains_lobby.size());
|
||||
|
||||
input->apply(world_space, predicted_display_time);
|
||||
bool hide_left_controller = false;
|
||||
bool hide_right_controller = false;
|
||||
|
||||
if (left_hand)
|
||||
left_hand->apply(world_space, predicted_display_time);
|
||||
if (application::get_hand_tracking_supported())
|
||||
{
|
||||
if (left_hand)
|
||||
{
|
||||
auto& hand = application::get_left_hand();
|
||||
auto joints = hand.locate(world_space, predicted_display_time);
|
||||
left_hand->apply(joints);
|
||||
|
||||
if (right_hand)
|
||||
right_hand->apply(world_space, predicted_display_time);
|
||||
if (joints)
|
||||
hide_left_controller = true;
|
||||
}
|
||||
|
||||
if (right_hand)
|
||||
{
|
||||
auto& hand = application::get_right_hand();
|
||||
auto joints = hand.locate(world_space, predicted_display_time);
|
||||
right_hand->apply(joints);
|
||||
|
||||
if (joints)
|
||||
hide_right_controller = true;
|
||||
}
|
||||
}
|
||||
|
||||
input->apply(world_space, predicted_display_time, hide_left_controller, hide_right_controller);
|
||||
|
||||
XrCompositionLayerQuad imgui_layer = draw_gui(predicted_display_time);
|
||||
|
||||
@@ -688,8 +708,8 @@ void scenes::lobby::on_focused()
|
||||
|
||||
if (application::get_hand_tracking_supported())
|
||||
{
|
||||
left_hand.emplace(application::get_left_hand(), "left-hand.glb", loader, *controllers_scene);
|
||||
right_hand.emplace(application::get_right_hand(), "right-hand.glb", loader, *controllers_scene);
|
||||
left_hand.emplace( "left-hand.glb", loader, *controllers_scene);
|
||||
right_hand.emplace("right-hand.glb", loader, *controllers_scene);
|
||||
}
|
||||
|
||||
std::array imgui_inputs{
|
||||
|
||||
Reference in New Issue
Block a user