Show hand models, refactor the scene renderer

This commit is contained in:
Guillaume Meunier
2024-03-30 13:44:49 +01:00
parent cf054dda64
commit 889f1ad5e6
17 changed files with 522 additions and 275 deletions
+84
View File
@@ -0,0 +1,84 @@
/*
* WiVRn VR streaming
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "hand_model.h"
#include "openxr/openxr.h"
#include "utils/ranges.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->name = gltf_path.stem();
scene.import(loader(gltf_path), root_node);
joints.resize(XR_HAND_JOINT_COUNT_EXT);
// clang-format off
joints[XR_HAND_JOINT_PALM_EXT] = node_handle();
joints[XR_HAND_JOINT_WRIST_EXT] = scene.find_node(root_node, "wrist");
joints[XR_HAND_JOINT_THUMB_METACARPAL_EXT] = scene.find_node(root_node, "thumb-metacarpal");
joints[XR_HAND_JOINT_THUMB_PROXIMAL_EXT] = scene.find_node(root_node, "thumb-phalanx-proximal");
joints[XR_HAND_JOINT_THUMB_DISTAL_EXT] = scene.find_node(root_node, "thumb-phalanx-distal");
joints[XR_HAND_JOINT_THUMB_TIP_EXT] = scene.find_node(root_node, "thumb-tip");
joints[XR_HAND_JOINT_INDEX_METACARPAL_EXT] = scene.find_node(root_node, "index-finger-metacarpal");
joints[XR_HAND_JOINT_INDEX_PROXIMAL_EXT] = scene.find_node(root_node, "index-finger-phalanx-proximal");
joints[XR_HAND_JOINT_INDEX_INTERMEDIATE_EXT] = scene.find_node(root_node, "index-finger-phalanx-intermediate");
joints[XR_HAND_JOINT_INDEX_DISTAL_EXT] = scene.find_node(root_node, "index-finger-phalanx-distal");
joints[XR_HAND_JOINT_INDEX_TIP_EXT] = scene.find_node(root_node, "index-finger-tip");
joints[XR_HAND_JOINT_MIDDLE_METACARPAL_EXT] = scene.find_node(root_node, "middle-finger-metacarpal");
joints[XR_HAND_JOINT_MIDDLE_PROXIMAL_EXT] = scene.find_node(root_node, "middle-finger-phalanx-proximal");
joints[XR_HAND_JOINT_MIDDLE_INTERMEDIATE_EXT] = scene.find_node(root_node, "middle-finger-phalanx-intermediate");
joints[XR_HAND_JOINT_MIDDLE_DISTAL_EXT] = scene.find_node(root_node, "middle-finger-phalanx-distal");
joints[XR_HAND_JOINT_MIDDLE_TIP_EXT] = scene.find_node(root_node, "middle-finger-tip");
joints[XR_HAND_JOINT_RING_METACARPAL_EXT] = scene.find_node(root_node, "ring-finger-metacarpal");
joints[XR_HAND_JOINT_RING_PROXIMAL_EXT] = scene.find_node(root_node, "ring-finger-phalanx-proximal");
joints[XR_HAND_JOINT_RING_INTERMEDIATE_EXT] = scene.find_node(root_node, "ring-finger-phalanx-intermediate");
joints[XR_HAND_JOINT_RING_DISTAL_EXT] = scene.find_node(root_node, "ring-finger-phalanx-distal");
joints[XR_HAND_JOINT_RING_TIP_EXT] = scene.find_node(root_node, "ring-finger-tip");
joints[XR_HAND_JOINT_LITTLE_METACARPAL_EXT] = scene.find_node(root_node, "pinky-finger-metacarpal");
joints[XR_HAND_JOINT_LITTLE_PROXIMAL_EXT] = scene.find_node(root_node, "pinky-finger-phalanx-proximal");
joints[XR_HAND_JOINT_LITTLE_INTERMEDIATE_EXT] = scene.find_node(root_node, "pinky-finger-phalanx-intermediate");
joints[XR_HAND_JOINT_LITTLE_DISTAL_EXT] = scene.find_node(root_node, "pinky-finger-phalanx-distal");
joints[XR_HAND_JOINT_LITTLE_TIP_EXT] = scene.find_node(root_node, "pinky-finger-tip");
// clang-format on
}
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);
for(auto&& [joint, loc]: utils::zip(joints, joints_location))
{
if (!joint)
continue;
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
};
}
}
+34
View File
@@ -0,0 +1,34 @@
/*
* WiVRn VR streaming
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "xr/hand_tracker.h"
#include <render/scene_data.h>
#include <openxr/openxr.h>
struct hand_model
{
xr::hand_tracker& hand;
std::vector<node_handle> joints;
hand_model(xr::hand_tracker & hand, const std::filesystem::path & gltf_path, scene_loader& loader, scene_data& scene);
void apply(XrSpace world_space, XrTime predicted_display_time);
};
-2
View File
@@ -20,14 +20,12 @@
#include "application.h"
#include "asset.h"
#include <cstddef>
#include <magic_enum.hpp>
#include <simdjson.h>
#include <spdlog/spdlog.h>
#include <stdexcept>
#include <string>
#include <unordered_map>
#include <map>
#include <glm/gtc/quaternion.hpp>
namespace
+17
View File
@@ -586,6 +586,12 @@ void scenes::lobby::render(XrTime predicted_display_time, bool should_render)
input->apply(world_space, predicted_display_time);
if (left_hand)
left_hand->apply(world_space, predicted_display_time);
if (right_hand)
right_hand->apply(world_space, predicted_display_time);
XrCompositionLayerQuad imgui_layer = draw_gui(predicted_display_time);
assert(renderer);
@@ -680,6 +686,12 @@ void scenes::lobby::on_focused()
input = input_profile("controllers/" + choose_webxr_profile() + "/profile.json", loader, *controllers_scene);
spdlog::info("Loaded input profile {}", input->id);
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);
}
std::array imgui_inputs{
imgui_context::controller{
.aim = get_action_space("left_aim"),
@@ -732,6 +744,11 @@ void scenes::lobby::on_unfocused()
imgui_ctx.reset();
lobby_scene.reset(); // Must be reset before the renderer so that the descriptor sets are freed before their pools
controllers_scene.reset();
input.reset();
left_hand.reset();
right_hand.reset();
renderer.reset();
swapchains_lobby.clear();
swapchains_controllers.clear();
+3
View File
@@ -22,6 +22,7 @@
#include "render/scene_data.h"
#include "scene.h"
#include <vulkan/vulkan_raii.hpp>
#include "scenes/hand_model.h"
#include "wivrn_discover.h"
#include "xr/passthrough.h"
@@ -77,6 +78,8 @@ class lobby : public scene_impl<lobby>
std::optional<scene_data> lobby_scene;
std::optional<scene_data> controllers_scene;
std::optional<input_profile> input;
std::optional<hand_model> left_hand;
std::optional<hand_model> right_hand;
std::optional<imgui_context> imgui_ctx;
std::array<XrAction, 2> haptic_output;