This commit is contained in:
Guillaume Meunier
2024-01-28 11:33:34 +01:00
parent 7ee4e9a4d2
commit 8dbd47c859
12 changed files with 802 additions and 55 deletions
+1 -30
View File
@@ -279,35 +279,6 @@ input_profile::input_profile(const std::filesystem::path & json_profile, scene_l
}
}
static std::optional<std::pair<glm::vec3, glm::quat>> locate_controller(XrSpace space, XrSpace reference, XrTime time)
{
XrSpaceLocation location{.type = XR_TYPE_SPACE_LOCATION};
assert(space != XR_NULL_HANDLE);
assert(reference != XR_NULL_HANDLE);
xrLocateSpace(space, reference, time, &location);
auto req_flags = XR_SPACE_LOCATION_ORIENTATION_VALID_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT;
if ((location.locationFlags & req_flags) != req_flags)
return {};
glm::vec3 position{
location.pose.position.x,
location.pose.position.y,
location.pose.position.z,
};
glm::quat orientation{
location.pose.orientation.w,
location.pose.orientation.x,
location.pose.orientation.y,
location.pose.orientation.z,
};
return std::make_pair(position, orientation);
}
void apply_visual_response(scene_object_handle node, std::pair<input_profile::node_state_transform, input_profile::node_state_transform> transforms, float value)
{
node->translation = glm::mix(transforms.first.position, transforms.second.position, value);
@@ -323,7 +294,7 @@ void input_profile::apply(XrSpace world_space, XrTime predicted_display_time)
{
for (auto && [space, node]: model_handles)
{
if (auto location = locate_controller(space, world_space, predicted_display_time); location)
if (auto location = application::locate_controller(space, world_space, predicted_display_time); location)
{
node->visible = true;
node->translation = location->first;
+52
View File
@@ -90,9 +90,15 @@ scenes::lobby::lobby() :
teapot.import(loader("lobby.gltf"));
teapot.import(loader("imgui.gltf"));
imgui_material = teapot.find_material("imgui");
assert(imgui_material);
input = input_profile("controllers/" + choose_webxr_profile() + "/profile.json", loader, teapot);
spdlog::info("Loaded input profile {}", input->id);
imgui_ctx.emplace(device, queue_family_index, queue);
}
void scenes::lobby::rasterize_status_string()
@@ -262,6 +268,52 @@ void scenes::lobby::render()
input->apply(world_space, framestate.predictedDisplayTime);
std::array<imgui_inputs, 2> inputs;
if (auto location = application::locate_controller(application::left_aim(), world_space, framestate.predictedDisplayTime); location)
{
inputs[0].active = true;
inputs[0].controller_position = location->first;
inputs[0].controller_orientation = location->second;
auto act = application::get_action("/user/hand/left/select/trigger/value").first;
if (act)
inputs[0].trigger = application::read_action_bool(application::get_action("/user/hand/left/select/trigger/value").first).value_or(std::make_pair(0, 0)).second;
// inputs[0].trigger = application::read_action_float(application::get_action("/user/hand/left/input/trigger/value").first).value_or(std::make_pair(0, 0)).second;
// inputs[0].squeeze = application::read_action_float(application::get_action("/user/hand/left/input/squeeze/value").first).value_or(std::make_pair(0, 0)).second;
inputs[0].scroll = glm::vec2(0,0);
}
else
{
inputs[0].active = false;
}
if (auto location = application::locate_controller(application::right_aim(), world_space, framestate.predictedDisplayTime); location)
{
inputs[1].active = true;
inputs[1].controller_position = location->first;
inputs[1].controller_orientation = location->second;
auto act = application::get_action("/user/hand/right/select/trigger/value").first;
if (act)
inputs[1].trigger = application::read_action_bool(act).value_or(std::make_pair(0, 0)).second;
// inputs[1].trigger = application::read_action_float(application::get_action("/user/hand/right/input/trigger/value").first).value_or(std::make_pair(0, 0)).second;
// inputs[1].squeeze = application::read_action_float(application::get_action("/user/hand/right/input/squeeze/value").first).value_or(std::make_pair(0, 0)).second;
inputs[1].scroll = glm::vec2(1,1);
}
else
{
inputs[1].active = false;
}
imgui_ctx->new_frame(inputs);
ImGui::ShowDemoWindow();
// Render the GUI to the imgui material
imgui_material->base_color_texture->image_view = imgui_ctx->render();
imgui_material->ds_dirty = true;
std::vector<XrCompositionLayerProjectionView> layer_view;
std::vector<scene_renderer::frame_info> frames;
+6 -21
View File
@@ -19,6 +19,7 @@
#pragma once
#include "render/scene_data.h"
#include "scene.h"
#include <vulkan/vulkan_raii.hpp>
#include "wivrn_discover.h"
@@ -27,6 +28,7 @@
#include "render/scene_renderer.h"
#include "render/text_rasterizer.h"
#include "render/imgui_impl.h"
#include "input_profile.h"
namespace scenes
@@ -45,35 +47,18 @@ class lobby : public scene
vk::DescriptorSet status_string_image_descriptor_set;
text_rasterizer status_string_rasterizer;
// vk::raii::RenderPass renderpass = nullptr;
// vk::raii::PipelineLayout layout = nullptr;
// vk::raii::Pipeline pipeline = nullptr;
// vk::raii::Fence fence = nullptr;
// vk::raii::CommandBuffer command_buffer = nullptr;
// struct image_data
// {
// vk::raii::Framebuffer framebuffer;
// vk::raii::Semaphore render_finished;
// };
// std::vector<std::vector<image_data>> images_data;
std::optional<wivrn_discover> discover;
// std::vector<vk::DeviceMemory> model_memory;
// std::vector<vk::Buffer> model_buffers;
// std::vector<vk::Image> model_images;
// void load_model(const std::string & filename);
std::shared_ptr<stream> next_scene;
std::optional<scene_renderer> renderer;
scene_data teapot;
scene_data teapot; // Must be after the renderer so that the descriptor sets are freed before their pools
std::optional<input_profile> input;
std::optional<imgui_context> imgui_ctx;
std::shared_ptr<scene_data::material> imgui_material;
void rasterize_status_string();
public: