Refactor the client GUI
This commit is contained in:
@@ -18,72 +18,113 @@
|
||||
|
||||
#include "hand_model.h"
|
||||
#include "openxr/openxr.h"
|
||||
#include <ranges>
|
||||
#include "render/scene_components.h"
|
||||
#include <entt/entt.hpp>
|
||||
#include <magic_enum.hpp>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
hand_model::hand_model(const std::filesystem::path & gltf_path, scene_loader & loader, scene_data & scene)
|
||||
namespace components
|
||||
{
|
||||
root_node = scene.new_node();
|
||||
root_node->name = gltf_path.stem();
|
||||
struct hand_joint
|
||||
{
|
||||
XrHandEXT hand;
|
||||
XrHandJointEXT joint;
|
||||
};
|
||||
} // namespace components
|
||||
|
||||
scene.import(loader(gltf_path), root_node);
|
||||
static const std::array<std::pair<XrHandJointEXT, std::string_view>, XR_HAND_JOINT_COUNT_EXT - 1 /* No palm in gltf */> joints{{
|
||||
// clang-format off
|
||||
{XR_HAND_JOINT_WRIST_EXT, "wrist"},
|
||||
{XR_HAND_JOINT_THUMB_METACARPAL_EXT, "thumb-metacarpal"},
|
||||
{XR_HAND_JOINT_THUMB_PROXIMAL_EXT, "thumb-phalanx-proximal"},
|
||||
{XR_HAND_JOINT_THUMB_DISTAL_EXT, "thumb-phalanx-distal"},
|
||||
{XR_HAND_JOINT_THUMB_TIP_EXT, "thumb-tip"},
|
||||
{XR_HAND_JOINT_INDEX_METACARPAL_EXT, "index-finger-metacarpal"},
|
||||
{XR_HAND_JOINT_INDEX_PROXIMAL_EXT, "index-finger-phalanx-proximal"},
|
||||
{XR_HAND_JOINT_INDEX_INTERMEDIATE_EXT, "index-finger-phalanx-intermediate"},
|
||||
{XR_HAND_JOINT_INDEX_DISTAL_EXT, "index-finger-phalanx-distal"},
|
||||
{XR_HAND_JOINT_INDEX_TIP_EXT, "index-finger-tip"},
|
||||
{XR_HAND_JOINT_MIDDLE_METACARPAL_EXT, "middle-finger-metacarpal"},
|
||||
{XR_HAND_JOINT_MIDDLE_PROXIMAL_EXT, "middle-finger-phalanx-proximal"},
|
||||
{XR_HAND_JOINT_MIDDLE_INTERMEDIATE_EXT, "middle-finger-phalanx-intermediate"},
|
||||
{XR_HAND_JOINT_MIDDLE_DISTAL_EXT, "middle-finger-phalanx-distal"},
|
||||
{XR_HAND_JOINT_MIDDLE_TIP_EXT, "middle-finger-tip"},
|
||||
{XR_HAND_JOINT_RING_METACARPAL_EXT, "ring-finger-metacarpal"},
|
||||
{XR_HAND_JOINT_RING_PROXIMAL_EXT, "ring-finger-phalanx-proximal"},
|
||||
{XR_HAND_JOINT_RING_INTERMEDIATE_EXT, "ring-finger-phalanx-intermediate"},
|
||||
{XR_HAND_JOINT_RING_DISTAL_EXT, "ring-finger-phalanx-distal"},
|
||||
{XR_HAND_JOINT_RING_TIP_EXT, "ring-finger-tip"},
|
||||
{XR_HAND_JOINT_LITTLE_METACARPAL_EXT, "pinky-finger-metacarpal"},
|
||||
{XR_HAND_JOINT_LITTLE_PROXIMAL_EXT, "pinky-finger-phalanx-proximal"},
|
||||
{XR_HAND_JOINT_LITTLE_INTERMEDIATE_EXT, "pinky-finger-phalanx-intermediate"},
|
||||
{XR_HAND_JOINT_LITTLE_DISTAL_EXT, "pinky-finger-phalanx-distal"},
|
||||
{XR_HAND_JOINT_LITTLE_TIP_EXT, "pinky-finger-tip"},
|
||||
// clang-format on
|
||||
}};
|
||||
|
||||
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::add_hand(scene & scene,
|
||||
XrHandEXT hand,
|
||||
const std::filesystem::path & gltf_path,
|
||||
uint32_t layer_mask)
|
||||
{
|
||||
auto && [entity, node] = scene.load_gltf(gltf_path, layer_mask);
|
||||
|
||||
node.name = gltf_path.stem();
|
||||
|
||||
for (auto [joint, name]: joints)
|
||||
{
|
||||
entt::entity joint_entity = find_node_by_name(scene.world, name, entity);
|
||||
|
||||
scene.world.emplace<components::hand_joint>(joint_entity, hand, joint);
|
||||
}
|
||||
|
||||
// Fake joint to hide the hand when it should not be visible
|
||||
scene.world.emplace<components::hand_joint>(entity, hand, (XrHandJointEXT)-1);
|
||||
}
|
||||
|
||||
void hand_model::apply(const std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> & joints_location)
|
||||
void hand_model::apply(entt::registry & scene,
|
||||
const std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> & left_hand,
|
||||
const std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> & right_hand)
|
||||
{
|
||||
if (joints_location and xr::hand_tracker::check_flags(*joints_location, XR_SPACE_LOCATION_POSITION_VALID_BIT | XR_SPACE_LOCATION_POSITION_TRACKED_BIT, 0))
|
||||
for (auto && [entity, hj, node]: scene.view<components::hand_joint, components::node>().each())
|
||||
{
|
||||
root_node->visible = true;
|
||||
auto f = [&](const std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> & joints) {
|
||||
if (joints.has_value())
|
||||
{
|
||||
node.visible = true;
|
||||
|
||||
for (auto && [joint, loc]: std::views::zip(joints, *joints_location))
|
||||
if (hj.joint < 0 or hj.joint > XR_HAND_JOINT_COUNT_EXT)
|
||||
return;
|
||||
|
||||
const auto & pose = (*joints)[hj.joint].first.pose;
|
||||
|
||||
node.position = {
|
||||
pose.position.x,
|
||||
pose.position.y,
|
||||
pose.position.z};
|
||||
|
||||
node.orientation = {
|
||||
pose.orientation.w,
|
||||
pose.orientation.x,
|
||||
pose.orientation.y,
|
||||
pose.orientation.z};
|
||||
}
|
||||
else
|
||||
{
|
||||
node.visible = false;
|
||||
}
|
||||
};
|
||||
|
||||
switch (hj.hand)
|
||||
{
|
||||
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};
|
||||
case XR_HAND_LEFT_EXT:
|
||||
f(left_hand);
|
||||
break;
|
||||
case XR_HAND_RIGHT_EXT:
|
||||
f(right_hand);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
root_node->visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,16 +18,20 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "scene.h"
|
||||
#include "xr/hand_tracker.h"
|
||||
#include <render/scene_data.h>
|
||||
#include <entt/fwd.hpp>
|
||||
#include <filesystem>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
struct hand_model
|
||||
namespace hand_model
|
||||
{
|
||||
node_handle root_node;
|
||||
std::vector<node_handle> joints;
|
||||
void add_hand(scene & scene,
|
||||
XrHandEXT hand,
|
||||
const std::filesystem::path & gltf_path,
|
||||
uint32_t layer_mask);
|
||||
|
||||
hand_model(const std::filesystem::path & gltf_path, scene_loader & loader, scene_data & scene);
|
||||
|
||||
void apply(const std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> & joints);
|
||||
};
|
||||
void apply(entt::registry & scene,
|
||||
const std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> & left_hand,
|
||||
const std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> & right_hand);
|
||||
}; // namespace hand_model
|
||||
|
||||
+130
-85
@@ -21,6 +21,9 @@
|
||||
#include "application.h"
|
||||
#include "asset.h"
|
||||
#include "hardware.h"
|
||||
#include "render/scene_components.h"
|
||||
#include "xr/space.h"
|
||||
#include <entt/entt.hpp>
|
||||
#include <glm/gtc/matrix_access.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <magic_enum.hpp>
|
||||
@@ -29,9 +32,47 @@
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <variant>
|
||||
|
||||
namespace components
|
||||
{
|
||||
namespace details
|
||||
{
|
||||
struct node_state_transform
|
||||
{
|
||||
glm::vec3 position;
|
||||
glm::quat orientation;
|
||||
};
|
||||
|
||||
struct node_state_visibility
|
||||
{
|
||||
};
|
||||
|
||||
using node_state = std::variant<std::pair<node_state_transform, node_state_transform>, node_state_visibility>;
|
||||
} // namespace details
|
||||
|
||||
// Component added to nodes affected by actions
|
||||
struct visual_response
|
||||
{
|
||||
XrAction action;
|
||||
XrActionType type;
|
||||
int axis; // Only if type is XR_ACTION_TYPE_VECTOR2F_INPUT
|
||||
float bias;
|
||||
float scale;
|
||||
|
||||
details::node_state state;
|
||||
};
|
||||
} // namespace components
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
// Component added to nodes bound to an action space
|
||||
struct bound_space
|
||||
{
|
||||
xr::spaces space;
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
const std::unordered_map<std::string, std::string> input_mappings = {
|
||||
{"xr-standard-squeeze" , "/input/squeeze/value" },
|
||||
@@ -125,14 +166,14 @@ struct json_visual_response
|
||||
component_type type;
|
||||
component_property property;
|
||||
std::string target_node;
|
||||
input_profile::node_state state;
|
||||
components::details::node_state state;
|
||||
|
||||
// OpenXR component path
|
||||
std::string component_subpath;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
input_profile::input_profile(const std::filesystem::path & json_profile, scene_loader & loader, scene_data & scene_controllers, scene_data & scene_rays)
|
||||
input_profile::input_profile(scene & scene, const std::filesystem::path & json_profile, uint32_t layer_mask_controller, uint32_t layer_mask_ray)
|
||||
{
|
||||
std::string json = asset(json_profile);
|
||||
|
||||
@@ -141,17 +182,20 @@ input_profile::input_profile(const std::filesystem::path & json_profile, scene_l
|
||||
|
||||
id = std::string(root["profileId"]);
|
||||
|
||||
// Don't load them into the scene right now in case there is an exception
|
||||
std::vector<std::pair<std::string, scene_data>> models;
|
||||
std::vector<std::tuple<std::string, entt::entity, entt::registry>> models;
|
||||
std::vector<json_visual_response> json_responses;
|
||||
|
||||
// Fill models with the different models to be loaded and their name ("left" or "right")
|
||||
// Don't load them into the scene right now in case there is an exception
|
||||
for (simdjson::dom::key_value_pair layout: simdjson::dom::object(root["layouts"]))
|
||||
{
|
||||
// TODO handle case where i.key is none and there is no left or right
|
||||
// std::string user_path = "/user/hand/" + std::string(layout.key);
|
||||
std::filesystem::path asset_path = json_profile.parent_path() / std::string(layout.value["assetPath"]);
|
||||
|
||||
scene_data & data = models.emplace_back(layout.key, loader(asset_path)).second;
|
||||
// scene.load_gltf(asset_path);
|
||||
|
||||
entt::registry & data = std::get<2>(models.emplace_back(layout.key, entt::null, (*scene.loader)(asset_path)));
|
||||
|
||||
for (simdjson::dom::key_value_pair component: simdjson::dom::object(layout.value["components"]))
|
||||
{
|
||||
@@ -177,40 +221,38 @@ input_profile::input_profile(const std::filesystem::path & json_profile, scene_l
|
||||
vr.component_subpath = component_subpath;
|
||||
|
||||
// Check if the node exists
|
||||
data.find_node(vr.target_node);
|
||||
find_node_by_name(data, vr.target_node);
|
||||
|
||||
auto node_property = parse_value_node_property(response.value["valueNodeProperty"]);
|
||||
switch (node_property)
|
||||
{
|
||||
case value_node_property::transform: {
|
||||
auto min_node = data.find_node(response.value["minNodeName"]);
|
||||
auto max_node = data.find_node(response.value["maxNodeName"]);
|
||||
auto min_node = data.get<components::node>(find_node_by_name(data, std::string(response.value["minNodeName"])));
|
||||
auto max_node = data.get<components::node>(find_node_by_name(data, std::string(response.value["maxNodeName"])));
|
||||
|
||||
node_state_transform min{
|
||||
min_node->position,
|
||||
min_node->orientation};
|
||||
components::details::node_state_transform min{
|
||||
min_node.position,
|
||||
min_node.orientation};
|
||||
|
||||
node_state_transform max{
|
||||
max_node->position,
|
||||
max_node->orientation};
|
||||
components::details::node_state_transform max{
|
||||
max_node.position,
|
||||
max_node.orientation};
|
||||
|
||||
vr.state = std::make_pair(min, max);
|
||||
}
|
||||
break;
|
||||
|
||||
case value_node_property::visibility:
|
||||
vr.state = node_state_visibility{};
|
||||
vr.state = components::details::node_state_visibility{};
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto && [layout, model]: models)
|
||||
// Add all models in the scene
|
||||
for (auto & [layout, entity, model]: models)
|
||||
{
|
||||
node_handle root_node = scene_controllers.new_node();
|
||||
root_node->name = layout;
|
||||
|
||||
xr::spaces space;
|
||||
if (layout == "left")
|
||||
space = xr::spaces::grip_left;
|
||||
@@ -223,9 +265,16 @@ input_profile::input_profile(const std::filesystem::path & json_profile, scene_l
|
||||
else
|
||||
continue;
|
||||
|
||||
model_handles.emplace_back(space, root_node);
|
||||
entity = scene.world.create();
|
||||
scene.world.emplace<bound_space>(entity, space);
|
||||
scene.world.emplace<components::node>(entity, components::node{
|
||||
.name = layout,
|
||||
.layer_mask = layer_mask_controller,
|
||||
});
|
||||
|
||||
scene_controllers.import(std::move(model), root_node);
|
||||
scene.loader->add_prefab(scene.world, std::move(model), entity);
|
||||
|
||||
spdlog::debug("Created entity {}", layout);
|
||||
}
|
||||
|
||||
for (simdjson::dom::key_value_pair layout: simdjson::dom::object(root["layouts"]))
|
||||
@@ -238,16 +287,16 @@ input_profile::input_profile(const std::filesystem::path & json_profile, scene_l
|
||||
else
|
||||
continue;
|
||||
|
||||
node_handle root_node = scene_rays.new_node();
|
||||
root_node->name = (std::string)layout.key + "_ray";
|
||||
model_handles.emplace_back(space, root_node);
|
||||
auto && [entity, node] = scene.load_gltf(controller_ray_model_name(), layer_mask_ray);
|
||||
node.name = (std::string)layout.key + "_ray";
|
||||
spdlog::debug("Created entity {}", node.name);
|
||||
|
||||
scene_rays.import(loader(controller_ray_model_name()), root_node);
|
||||
scene.world.emplace<bound_space>(entity, space);
|
||||
|
||||
if (layout.key == "left")
|
||||
left_ray = root_node;
|
||||
left_ray = entity;
|
||||
else if (layout.key == "right")
|
||||
right_ray = root_node;
|
||||
right_ray = entity;
|
||||
}
|
||||
|
||||
for (auto & json_response: json_responses)
|
||||
@@ -264,7 +313,7 @@ input_profile::input_profile(const std::filesystem::path & json_profile, scene_l
|
||||
continue;
|
||||
}
|
||||
|
||||
auto & response = responses.emplace_back();
|
||||
components::visual_response response;
|
||||
response.action = action.first;
|
||||
response.type = action.second;
|
||||
|
||||
@@ -289,101 +338,101 @@ input_profile::input_profile(const std::filesystem::path & json_profile, scene_l
|
||||
break;
|
||||
}
|
||||
|
||||
node_handle controller_root_node;
|
||||
for (auto && [i, j]: model_handles)
|
||||
entt::entity controller_entity = entt::null;
|
||||
for (const auto & [layout, entity, model]: models)
|
||||
{
|
||||
if (j->name == json_response.layout)
|
||||
if (layout == json_response.layout)
|
||||
{
|
||||
controller_root_node = j;
|
||||
assert(controller_root_node->name == json_response.layout);
|
||||
controller_entity = entity;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
response.target.node = scene_controllers.find_node(controller_root_node, json_response.target_node);
|
||||
response.target.state = json_response.state;
|
||||
response.state = json_response.state;
|
||||
|
||||
auto target = find_node_by_name(scene.world, json_response.target_node, controller_entity);
|
||||
scene.world.emplace<components::visual_response>(target, response);
|
||||
}
|
||||
|
||||
offset.fill({{0, 0, 0}, {1, 0, 0, 0}});
|
||||
}
|
||||
|
||||
static void apply_visual_response(node_handle node, std::pair<input_profile::node_state_transform, input_profile::node_state_transform> transforms, float value)
|
||||
static void apply_visual_response(components::node & node, std::pair<components::details::node_state_transform, components::details::node_state_transform> transforms, float value)
|
||||
{
|
||||
node->position = glm::mix(transforms.first.position, transforms.second.position, value);
|
||||
node->orientation = glm::slerp(transforms.first.orientation, transforms.second.orientation, value);
|
||||
node.position = glm::mix(transforms.first.position, transforms.second.position, value);
|
||||
node.orientation = glm::slerp(transforms.first.orientation, transforms.second.orientation, value);
|
||||
}
|
||||
|
||||
static void apply_visual_response(node_handle node, input_profile::node_state_visibility, float value)
|
||||
static void apply_visual_response(components::node & node, components::details::node_state_visibility, float value)
|
||||
{
|
||||
node->visible = value > 0.5;
|
||||
node.visible = value > 0.5;
|
||||
}
|
||||
|
||||
static void set_clipping_planes(node_handle node, std::span<glm::vec4> clipping_planes)
|
||||
static void set_clipping_planes(entt::registry & scene, entt::entity entity, std::span<glm::vec4> clipping_planes)
|
||||
{
|
||||
if (not node)
|
||||
return;
|
||||
|
||||
// If the ray starts on the wrong side of the GUI, hide it entirely
|
||||
// This assumes the node is a child of the root node
|
||||
components::node & node = scene.get<components::node>(entity);
|
||||
for (glm::vec4 & plane: clipping_planes)
|
||||
{
|
||||
if (glm::dot(plane, glm::vec4(node->position, 1)) < 0)
|
||||
if (glm::dot(plane, glm::vec4(node.position, 1)) < 0)
|
||||
{
|
||||
node->visible = false;
|
||||
scene.get<components::node>(entity).visible = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto child_node: node.children())
|
||||
// Apply the clipping planes on direct children of the target entity
|
||||
for (auto && [child_entity, child_node]: scene.view<components::node>().each())
|
||||
{
|
||||
size_t nb_clipping_planes = std::min(child_node->clipping_planes.size(), clipping_planes.size());
|
||||
if (child_node.parent == entity)
|
||||
{
|
||||
size_t nb_clipping_planes = std::min(child_node.clipping_planes.size(), clipping_planes.size());
|
||||
|
||||
auto copy_results = std::ranges::copy_n(
|
||||
clipping_planes.begin(),
|
||||
nb_clipping_planes,
|
||||
child_node->clipping_planes.begin());
|
||||
auto copy_results = std::ranges::copy_n(
|
||||
clipping_planes.begin(),
|
||||
nb_clipping_planes,
|
||||
child_node.clipping_planes.begin());
|
||||
|
||||
// Disable the remaining clipping planes
|
||||
std::ranges::fill_n(
|
||||
copy_results.out,
|
||||
child_node->clipping_planes.size() - nb_clipping_planes,
|
||||
glm::vec4(0, 0, 0, 1));
|
||||
// Disable the remaining clipping planes
|
||||
std::ranges::fill_n(
|
||||
copy_results.out,
|
||||
child_node.clipping_planes.size() - nb_clipping_planes,
|
||||
glm::vec4(0, 0, 0, 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void input_profile::apply(XrSpace world_space, XrTime predicted_display_time, bool hide_left, bool hide_right, std::span<glm::vec4> pointer_limits)
|
||||
void input_profile::apply(entt::registry & scene, XrSpace world_space, XrTime predicted_display_time, bool hide_left, bool hide_right, std::span<glm::vec4> pointer_limits)
|
||||
{
|
||||
for (auto && [space, node]: model_handles)
|
||||
for (auto && [entity, node, space]: scene.view<components::node, bound_space>().each())
|
||||
{
|
||||
if ((space == xr::spaces::grip_left or space == xr::spaces::aim_left) and hide_left)
|
||||
if ((space.space == xr::spaces::grip_left or space.space == xr::spaces::aim_left) and hide_left)
|
||||
{
|
||||
node->visible = false;
|
||||
node.visible = false;
|
||||
}
|
||||
else if ((space == xr::spaces::grip_right or space == xr::spaces::aim_right) and hide_right)
|
||||
else if ((space.space == xr::spaces::grip_right or space.space == xr::spaces::aim_right) and hide_right)
|
||||
{
|
||||
node->visible = false;
|
||||
node.visible = false;
|
||||
}
|
||||
else if (auto location = application::locate_controller(application::space(space), world_space, predicted_display_time); location)
|
||||
else if (auto location = application::locate_controller(application::space(space.space), world_space, predicted_display_time); location)
|
||||
{
|
||||
node->visible = true;
|
||||
node.visible = true;
|
||||
|
||||
assert((int)space >= 0);
|
||||
assert((int)space < offset.size());
|
||||
auto & [p, q] = offset[space];
|
||||
assert((int)space.space >= 0);
|
||||
assert((int)space.space < offset.size());
|
||||
auto & [p, q] = offset[space.space];
|
||||
|
||||
node->position = location->first + glm::mat3_cast(location->second * q) * p;
|
||||
node->orientation = location->second * q;
|
||||
node.position = location->first + glm::mat3_cast(location->second * q) * p;
|
||||
node.orientation = location->second * q;
|
||||
}
|
||||
else
|
||||
{
|
||||
node->visible = false;
|
||||
node.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
set_clipping_planes(left_ray, pointer_limits);
|
||||
set_clipping_planes(right_ray, pointer_limits);
|
||||
|
||||
for (auto & response: responses)
|
||||
for (auto && [entity, node, response]: scene.view<components::node, components::visual_response>().each())
|
||||
{
|
||||
assert(response.action);
|
||||
|
||||
@@ -435,20 +484,16 @@ void input_profile::apply(XrSpace world_space, XrTime predicted_display_time, bo
|
||||
|
||||
if ((scaled_value < 0) || (scaled_value > 1))
|
||||
{
|
||||
std::string full_name = response.target.node->name;
|
||||
|
||||
for (auto i = response.target.node; i; i = i.parent())
|
||||
{
|
||||
full_name = i->name + "/" + full_name;
|
||||
}
|
||||
|
||||
spdlog::warn("Out of range value {} (scaled to {}) for node {}", *value, scaled_value, full_name);
|
||||
spdlog::warn("Out of range value {} (scaled to {}) for node {}", *value, scaled_value, get_node_name(scene, entity));
|
||||
}
|
||||
|
||||
std::visit([&](auto & transform) {
|
||||
apply_visual_response(response.target.node, transform, scaled_value);
|
||||
apply_visual_response(node, transform, scaled_value);
|
||||
},
|
||||
response.target.state);
|
||||
response.state);
|
||||
}
|
||||
}
|
||||
|
||||
set_clipping_planes(scene, left_ray, pointer_limits);
|
||||
set_clipping_planes(scene, right_ray, pointer_limits);
|
||||
}
|
||||
|
||||
@@ -18,58 +18,27 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "scene.h"
|
||||
#include <cstdint>
|
||||
#include <entt/fwd.hpp>
|
||||
#include <filesystem>
|
||||
#include <glm/glm.hpp>
|
||||
#include <magic_enum_containers.hpp>
|
||||
#include <render/scene_data.h>
|
||||
#include <span>
|
||||
#include <variant>
|
||||
#include <xr/space.h>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
struct input_profile
|
||||
{
|
||||
struct node_state_transform
|
||||
{
|
||||
glm::vec3 position;
|
||||
glm::quat orientation;
|
||||
};
|
||||
|
||||
struct node_state_visibility
|
||||
{
|
||||
};
|
||||
|
||||
using node_state = std::variant<std::pair<node_state_transform, node_state_transform>, node_state_visibility>;
|
||||
|
||||
struct node_target
|
||||
{
|
||||
node_handle node;
|
||||
node_state state;
|
||||
};
|
||||
|
||||
struct visual_response
|
||||
{
|
||||
XrAction action;
|
||||
XrActionType type;
|
||||
int axis; // Only if type is XR_ACTION_TYPE_VECTOR2F_INPUT
|
||||
float bias;
|
||||
float scale;
|
||||
|
||||
node_target target;
|
||||
};
|
||||
|
||||
std::string id;
|
||||
|
||||
std::vector<visual_response> responses;
|
||||
std::vector<std::pair<xr::spaces, node_handle>> model_handles;
|
||||
|
||||
node_handle left_ray;
|
||||
node_handle right_ray;
|
||||
entt::entity left_ray;
|
||||
entt::entity right_ray;
|
||||
|
||||
magic_enum::containers::array<xr::spaces, std::pair<glm::vec3, glm::quat>> offset;
|
||||
|
||||
input_profile(const std::filesystem::path & json_profile, scene_loader & loader, scene_data & scene_controllers, scene_data & scene_rays);
|
||||
input_profile(scene & scene, const std::filesystem::path & json_profile, uint32_t layer_mask_controller, uint32_t layer_mask_ray);
|
||||
|
||||
// application::poll_actions() must have been called before
|
||||
void apply(XrSpace world_space, XrTime predicted_display_time, bool hide_left, bool hide_right, std::span<glm::vec4> pointer_limits);
|
||||
void apply(entt::registry & scene, XrSpace world_space, XrTime predicted_display_time, bool hide_left, bool hide_right, std::span<glm::vec4> pointer_limits);
|
||||
};
|
||||
|
||||
+140
-434
@@ -27,10 +27,12 @@
|
||||
#include "openxr/openxr.h"
|
||||
#include "protocol_version.h"
|
||||
#include "render/scene_data.h"
|
||||
#include "render/scene_loader.h"
|
||||
#include "render/scene_renderer.h"
|
||||
#include "stream.h"
|
||||
#include "utils/i18n.h"
|
||||
#include "utils/overloaded.h"
|
||||
#include "utils/ranges.h"
|
||||
#include "wivrn_client.h"
|
||||
#include "wivrn_discover.h"
|
||||
#include "wivrn_sockets.h"
|
||||
@@ -110,13 +112,24 @@ void scenes::lobby::move_gui(glm::vec3 head_position, glm::vec3 new_gui_position
|
||||
imgui_ctx->layers()[2].orientation = q * glm::quat(cos(keyboard_pitch / 2), sin(keyboard_pitch / 2), 0, 0);
|
||||
}
|
||||
|
||||
scenes::lobby::lobby()
|
||||
scenes::lobby::lobby() :
|
||||
scene_impl<lobby>(supported_color_formats, supported_depth_formats)
|
||||
{
|
||||
spdlog::info("Using formats {} and {}", vk::to_string(swapchain_format), vk::to_string(depth_format));
|
||||
// composition_layer_depth_test_supported = false;
|
||||
if (composition_layer_depth_test_supported)
|
||||
spdlog::info("Composition layer depth test supported");
|
||||
else
|
||||
spdlog::info("Composition layer depth test NOT supported");
|
||||
|
||||
if (composition_layer_color_scale_bias_supported)
|
||||
spdlog::info("Composition layer color scale/bias supported");
|
||||
else
|
||||
spdlog::info("Composition layer color scale/bias NOT supported");
|
||||
|
||||
if (std::getenv("WIVRN_AUTOCONNECT"))
|
||||
force_autoconnect = true;
|
||||
|
||||
passthrough_supported = system.passthrough_supported();
|
||||
|
||||
auto & servers = application::get_config().servers;
|
||||
spdlog::info("{} known server(s):", servers.size());
|
||||
for (auto & i: servers)
|
||||
@@ -124,61 +137,6 @@ scenes::lobby::lobby()
|
||||
spdlog::info(" {}", i.second.service.name);
|
||||
}
|
||||
|
||||
haptic_output[0] = get_action("left_haptic").first;
|
||||
haptic_output[1] = get_action("right_haptic").first;
|
||||
|
||||
swapchain_format = vk::Format::eUndefined;
|
||||
spdlog::info("Supported swapchain formats:");
|
||||
|
||||
for (auto format: session.get_swapchain_formats())
|
||||
{
|
||||
spdlog::info(" {}", vk::to_string(format));
|
||||
}
|
||||
|
||||
for (auto format: session.get_swapchain_formats())
|
||||
{
|
||||
if (std::find(supported_color_formats.begin(), supported_color_formats.end(), format) != supported_color_formats.end())
|
||||
{
|
||||
swapchain_format = format;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (swapchain_format == vk::Format::eUndefined)
|
||||
throw std::runtime_error(_("No supported swapchain format"));
|
||||
|
||||
auto views = system.view_configuration_views(viewconfig);
|
||||
stream_view = override_view(views[0], guess_model());
|
||||
uint32_t width = views[0].recommendedImageRectWidth;
|
||||
uint32_t height = views[0].recommendedImageRectHeight;
|
||||
|
||||
depth_format = scene_renderer::find_usable_image_format(
|
||||
physical_device,
|
||||
supported_depth_formats,
|
||||
{
|
||||
width,
|
||||
height,
|
||||
1,
|
||||
},
|
||||
vk::ImageUsageFlagBits::eDepthStencilAttachment);
|
||||
|
||||
spdlog::info("Using formats {} and {}", vk::to_string(swapchain_format), vk::to_string(depth_format));
|
||||
|
||||
composition_layer_depth_test_supported =
|
||||
instance.has_extension(XR_KHR_COMPOSITION_LAYER_DEPTH_EXTENSION_NAME) and
|
||||
instance.has_extension(XR_FB_COMPOSITION_LAYER_DEPTH_TEST_EXTENSION_NAME);
|
||||
|
||||
if (composition_layer_depth_test_supported)
|
||||
spdlog::info("Composition layer depth test supported");
|
||||
else
|
||||
spdlog::info("Composition layer depth test NOT supported");
|
||||
|
||||
composition_layer_color_scale_bias_supported = instance.has_extension(XR_KHR_COMPOSITION_LAYER_COLOR_SCALE_BIAS_EXTENSION_NAME);
|
||||
if (composition_layer_color_scale_bias_supported)
|
||||
spdlog::info("Composition layer color scale/bias supported");
|
||||
else
|
||||
spdlog::info("Composition layer color scale/bias NOT supported");
|
||||
|
||||
keyboard.set_layout(application::get_config().virtual_keyboard_layout);
|
||||
|
||||
const auto keypair_path = application::get_config_path() / "private_key.pem";
|
||||
@@ -346,37 +304,6 @@ std::unique_ptr<wivrn_session> scenes::lobby::connect_to_session(wivrn_discover:
|
||||
throw std::runtime_error(error);
|
||||
}
|
||||
|
||||
static glm::mat4 projection_matrix(XrFovf fov, float zn = 0.02)
|
||||
{
|
||||
float r = tan(fov.angleRight);
|
||||
float l = tan(fov.angleLeft);
|
||||
float t = tan(fov.angleUp);
|
||||
float b = tan(fov.angleDown);
|
||||
|
||||
// reversed Z projection, infinite far plane
|
||||
|
||||
// clang-format off
|
||||
return glm::mat4{
|
||||
{ 2/(r-l), 0, 0, 0 },
|
||||
{ 0, 2/(b-t), 0, 0 },
|
||||
{ (l+r)/(r-l), (t+b)/(b-t), 0, -1 },
|
||||
{ 0, 0, zn, 0 }
|
||||
};
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
static glm::mat4 view_matrix(XrPosef pose)
|
||||
{
|
||||
XrQuaternionf q = pose.orientation;
|
||||
XrVector3f pos = pose.position;
|
||||
|
||||
glm::mat4 inv_view_matrix = glm::mat4_cast(glm::quat(q.w, q.x, q.y, q.z));
|
||||
|
||||
inv_view_matrix = glm::translate(glm::mat4(1), glm::vec3(pos.x, pos.y, pos.z)) * inv_view_matrix;
|
||||
|
||||
return glm::inverse(inv_view_matrix);
|
||||
}
|
||||
|
||||
void scenes::lobby::update_server_list()
|
||||
{
|
||||
if (application::is_focused() && !discover)
|
||||
@@ -476,19 +403,27 @@ std::optional<glm::vec3> scenes::lobby::check_recenter_gesture(const std::array<
|
||||
std::optional<glm::vec3> scenes::lobby::check_recenter_action(XrTime predicted_display_time, glm::vec3 head_position)
|
||||
{
|
||||
std::optional<std::pair<glm::vec3, glm::quat>> aim;
|
||||
glm::vec3 offset_position;
|
||||
glm::quat offset_orientation;
|
||||
|
||||
if (application::read_action_bool(recenter_left_action).value_or(std::pair{0, false}).second)
|
||||
{
|
||||
aim = application::locate_controller(application::space(xr::spaces::aim_left), application::space(xr::spaces::world), predicted_display_time);
|
||||
std::tie(offset_position, offset_orientation) = input->offset[xr::spaces::aim_left];
|
||||
}
|
||||
|
||||
if (application::read_action_bool(recenter_right_action).value_or(std::pair{0, false}).second)
|
||||
{
|
||||
aim = application::locate_controller(application::space(xr::spaces::aim_right), application::space(xr::spaces::world), predicted_display_time);
|
||||
std::tie(offset_position, offset_orientation) = input->offset[xr::spaces::aim_right];
|
||||
}
|
||||
|
||||
if (aim)
|
||||
{
|
||||
// Handle controller offset
|
||||
aim->first = aim->first + glm::mat3_cast(aim->second * offset_orientation) * offset_position;
|
||||
aim->second = aim->second * offset_orientation;
|
||||
|
||||
if (not gui_recenter_position or not gui_recenter_distance)
|
||||
{
|
||||
// First frame where the recenter action is active
|
||||
@@ -572,80 +507,6 @@ std::optional<glm::vec3> scenes::lobby::check_recenter_gui(glm::vec3 head_positi
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
static std::pair<std::vector<XrCompositionLayerProjectionView>, std::vector<XrCompositionLayerDepthInfoKHR>> render_layer(
|
||||
std::vector<XrView> & views,
|
||||
std::vector<xr::swapchain> & color_swapchains,
|
||||
std::vector<xr::swapchain> & depth_swapchains,
|
||||
scene_renderer & renderer,
|
||||
scene_data & data,
|
||||
const std::array<float, 4> & clear_color)
|
||||
{
|
||||
std::vector<scene_renderer::frame_info> frames;
|
||||
frames.reserve(views.size());
|
||||
|
||||
std::vector<XrCompositionLayerProjectionView> proj_layer_views;
|
||||
std::vector<XrCompositionLayerDepthInfoKHR> depth_layer_views;
|
||||
proj_layer_views.reserve(views.size());
|
||||
depth_layer_views.reserve(views.size());
|
||||
|
||||
for (auto && [view, color_swapchain, depth_swapchain]: std::views::zip(views, color_swapchains, depth_swapchains))
|
||||
{
|
||||
int color_image_index = color_swapchain.acquire();
|
||||
color_swapchain.wait();
|
||||
|
||||
int depth_image_index = depth_swapchain ? depth_swapchain.acquire() : 0;
|
||||
if (depth_swapchain)
|
||||
depth_swapchain.wait();
|
||||
|
||||
frames.push_back({
|
||||
.destination = color_swapchain.images()[color_image_index].image,
|
||||
.depth_buffer = depth_swapchain ? depth_swapchain.images()[depth_image_index].image : vk::Image{},
|
||||
.projection = projection_matrix(view.fov, constants::lobby::near_plane),
|
||||
.view = view_matrix(view.pose),
|
||||
});
|
||||
|
||||
proj_layer_views.push_back({
|
||||
.type = XR_TYPE_COMPOSITION_LAYER_PROJECTION_VIEW,
|
||||
.pose = view.pose,
|
||||
.fov = view.fov,
|
||||
.subImage = {
|
||||
.swapchain = color_swapchain,
|
||||
.imageRect = {
|
||||
.offset = {0, 0},
|
||||
.extent = color_swapchain.extent(),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
depth_layer_views.push_back({
|
||||
.type = XR_TYPE_COMPOSITION_LAYER_DEPTH_INFO_KHR,
|
||||
.subImage = {
|
||||
.swapchain = depth_swapchain,
|
||||
.imageRect = {
|
||||
.offset = {0, 0},
|
||||
.extent = depth_swapchain.extent(),
|
||||
},
|
||||
},
|
||||
.minDepth = 0,
|
||||
.maxDepth = 1,
|
||||
.nearZ = std::numeric_limits<float>::infinity(),
|
||||
.farZ = constants::lobby::near_plane,
|
||||
});
|
||||
}
|
||||
|
||||
renderer.render(data, clear_color, frames);
|
||||
|
||||
return {proj_layer_views, depth_layer_views};
|
||||
}
|
||||
|
||||
static std::vector<XrCompositionLayerProjectionView> render_layer(std::vector<XrView> & views, std::vector<xr::swapchain> & color_swapchains, scene_renderer & renderer, scene_data & data, const std::array<float, 4> & clear_color)
|
||||
{
|
||||
std::vector<xr::swapchain> depth_swapchains;
|
||||
depth_swapchains.resize(color_swapchains.size());
|
||||
|
||||
return std::get<0>(render_layer(views, color_swapchains, depth_swapchains, renderer, data, clear_color));
|
||||
}
|
||||
|
||||
// Return the vector v such that dot(v, x) > 0 iff x is on the side where the composition layer is visible
|
||||
static glm::vec4 compute_ray_limits(const XrPosef & pose, float margin = 0)
|
||||
{
|
||||
@@ -737,7 +598,8 @@ void scenes::lobby::render(const XrFrameState & frame_state)
|
||||
|
||||
XrSpace world_space = application::space(xr::spaces::world);
|
||||
auto [flags, views] = session.locate_views(viewconfig, frame_state.predictedDisplayTime, world_space);
|
||||
assert(views.size() == swapchains_lobby.size());
|
||||
// assert(views.size() == swapchains_lobby.size());
|
||||
assert(views.size() == 2); // FIXME
|
||||
|
||||
bool hide_left_controller = false;
|
||||
bool hide_right_controller = false;
|
||||
@@ -753,75 +615,70 @@ void scenes::lobby::render(const XrFrameState & frame_state)
|
||||
|
||||
if (application::get_hand_tracking_supported())
|
||||
{
|
||||
if (left_hand)
|
||||
{
|
||||
auto & hand = application::get_left_hand();
|
||||
auto joints = hand.locate(world_space, frame_state.predictedDisplayTime);
|
||||
left_hand->apply(joints);
|
||||
auto left = application::get_left_hand().locate(world_space, frame_state.predictedDisplayTime);
|
||||
auto right = application::get_right_hand().locate(world_space, frame_state.predictedDisplayTime);
|
||||
|
||||
if (joints and xr::hand_tracker::check_flags(*joints, XR_SPACE_LOCATION_POSITION_TRACKED_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT, 0))
|
||||
{
|
||||
hide_left_controller = true;
|
||||
if (!new_gui_position)
|
||||
new_gui_position = check_recenter_gesture(*joints);
|
||||
}
|
||||
hand_model::apply(world, left, right);
|
||||
|
||||
if (left and xr::hand_tracker::check_flags(*left, XR_SPACE_LOCATION_POSITION_TRACKED_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT, 0))
|
||||
{
|
||||
hide_left_controller = true;
|
||||
if (!new_gui_position)
|
||||
new_gui_position = check_recenter_gesture(*left);
|
||||
}
|
||||
|
||||
if (right_hand)
|
||||
if (right and xr::hand_tracker::check_flags(*right, XR_SPACE_LOCATION_POSITION_TRACKED_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT, 0))
|
||||
{
|
||||
auto & hand = application::get_right_hand();
|
||||
auto joints = hand.locate(world_space, frame_state.predictedDisplayTime);
|
||||
right_hand->apply(joints);
|
||||
|
||||
if (joints and xr::hand_tracker::check_flags(*joints, XR_SPACE_LOCATION_POSITION_TRACKED_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT, 0))
|
||||
{
|
||||
hide_right_controller = true;
|
||||
if (!new_gui_position)
|
||||
new_gui_position = check_recenter_gesture(*joints);
|
||||
}
|
||||
hide_right_controller = true;
|
||||
if (!new_gui_position)
|
||||
new_gui_position = check_recenter_gesture(*right);
|
||||
}
|
||||
}
|
||||
|
||||
#if WIVRN_CLIENT_DEBUG_MENU
|
||||
if (display_debug_axes)
|
||||
{
|
||||
const xr::spaces left = display_grip_instead_of_aim ? xr::spaces::grip_left : xr::spaces::aim_left;
|
||||
const xr::spaces right = display_grip_instead_of_aim ? xr::spaces::grip_right : xr::spaces::aim_right;
|
||||
|
||||
if (hide_left_controller)
|
||||
xyz_axes_left_controller->visible = false;
|
||||
else if (auto location = application::locate_controller(application::space(left), world_space, frame_state.predictedDisplayTime))
|
||||
{
|
||||
xyz_axes_left_controller->visible = true;
|
||||
xyz_axes_left_controller->position = location->first;
|
||||
xyz_axes_left_controller->orientation = location->second;
|
||||
}
|
||||
else
|
||||
xyz_axes_left_controller->visible = false;
|
||||
|
||||
if (hide_right_controller)
|
||||
xyz_axes_right_controller->visible = false;
|
||||
else if (auto location = application::locate_controller(application::space(right), world_space, frame_state.predictedDisplayTime))
|
||||
{
|
||||
xyz_axes_right_controller->visible = true;
|
||||
xyz_axes_right_controller->position = location->first;
|
||||
xyz_axes_right_controller->orientation = location->second;
|
||||
}
|
||||
else
|
||||
xyz_axes_right_controller->visible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
xyz_axes_left_controller->visible = false;
|
||||
xyz_axes_right_controller->visible = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (head_position && new_gui_position)
|
||||
{
|
||||
move_gui(head_position->first, *new_gui_position);
|
||||
}
|
||||
|
||||
#if WIVRN_CLIENT_DEBUG_MENU
|
||||
{
|
||||
auto & left_node = world.get<components::node>(xyz_axes_left_controller);
|
||||
auto & right_node = world.get<components::node>(xyz_axes_right_controller);
|
||||
if (display_debug_axes)
|
||||
{
|
||||
const xr::spaces left = display_grip_instead_of_aim ? xr::spaces::grip_left : xr::spaces::aim_left;
|
||||
|
||||
if (hide_left_controller)
|
||||
left_node.visible = false;
|
||||
else if (auto location = application::locate_controller(application::space(left), world_space, frame_state.predictedDisplayTime))
|
||||
{
|
||||
left_node.visible = true;
|
||||
left_node.position = location->first;
|
||||
left_node.orientation = location->second;
|
||||
}
|
||||
else
|
||||
left_node.visible = false;
|
||||
|
||||
const xr::spaces right = display_grip_instead_of_aim ? xr::spaces::grip_right : xr::spaces::aim_right;
|
||||
if (hide_right_controller)
|
||||
right_node.visible = false;
|
||||
else if (auto location = application::locate_controller(application::space(right), world_space, frame_state.predictedDisplayTime))
|
||||
{
|
||||
right_node.visible = true;
|
||||
right_node.position = location->first;
|
||||
right_node.orientation = location->second;
|
||||
}
|
||||
else
|
||||
right_node.visible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
left_node.visible = false;
|
||||
right_node.visible = false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
std::vector<std::pair<int, XrCompositionLayerQuad>> imgui_layers = draw_gui(frame_state.predictedDisplayTime);
|
||||
|
||||
// Get the planes that limit the ray size from the composition layers
|
||||
@@ -832,182 +689,65 @@ void scenes::lobby::render(const XrFrameState & frame_state)
|
||||
ray_limits.push_back(compute_ray_limits(layer.pose));
|
||||
}
|
||||
|
||||
input->apply(world_space, frame_state.predictedDisplayTime, hide_left_controller, hide_right_controller, ray_limits);
|
||||
input->apply(world, world_space, frame_state.predictedDisplayTime, hide_left_controller, hide_right_controller, ray_limits);
|
||||
|
||||
assert(renderer);
|
||||
renderer->start_frame();
|
||||
|
||||
std::vector<XrCompositionLayerProjectionView> lobby_layer_views;
|
||||
std::vector<XrCompositionLayerDepthInfoKHR> lobby_depth_layer_views;
|
||||
std::vector<XrCompositionLayerProjectionView> controllers_layer_views;
|
||||
std::vector<XrCompositionLayerDepthInfoKHR> controllers_depth_layer_views;
|
||||
world.get<components::node>(lobby_entity).visible = not application::get_config().passthrough_enabled;
|
||||
|
||||
std::array<float, 4> clear_color;
|
||||
render_start(application::get_config().passthrough_enabled, frame_state.predictedDisplayTime);
|
||||
|
||||
lobby_handle->visible = not application::get_config().passthrough_enabled;
|
||||
|
||||
if (application::get_config().passthrough_enabled)
|
||||
clear_color = {0, 0, 0, 0};
|
||||
else
|
||||
clear_color = constants::lobby::sky_color;
|
||||
const XrColor4f clear_color = application::get_config().passthrough_enabled ? XrColor4f{0, 0, 0, 0} : constants::lobby::sky_color;
|
||||
render_world(
|
||||
XR_COMPOSITION_LAYER_BLEND_TEXTURE_SOURCE_ALPHA_BIT,
|
||||
world_space,
|
||||
views,
|
||||
width,
|
||||
height,
|
||||
composition_layer_depth_test_supported,
|
||||
composition_layer_depth_test_supported ? layer_lobby | layer_controllers : layer_lobby,
|
||||
clear_color);
|
||||
|
||||
if (composition_layer_depth_test_supported)
|
||||
set_depth_test(true, XR_COMPARE_OP_ALWAYS_FB);
|
||||
|
||||
bool dim_gui = imgui_ctx->is_modal_popup_shown() and composition_layer_color_scale_bias_supported;
|
||||
for (auto & [z_index, layer]: imgui_layers)
|
||||
{
|
||||
std::tie(lobby_layer_views, lobby_depth_layer_views) = render_layer(
|
||||
views,
|
||||
swapchains_lobby,
|
||||
swapchains_lobby_depth,
|
||||
*renderer,
|
||||
*lobby_scene,
|
||||
clear_color);
|
||||
for (auto [color, depth]: std::views::zip(lobby_layer_views, lobby_depth_layer_views))
|
||||
color.next = &depth;
|
||||
if (z_index < constants::lobby::zindex_recenter_tip)
|
||||
{
|
||||
add_quad_layer(layer.layerFlags, layer.space, layer.eyeVisibility, layer.subImage, layer.pose, layer.size);
|
||||
|
||||
std::tie(controllers_layer_views, controllers_depth_layer_views) = render_layer(
|
||||
views,
|
||||
swapchains_controllers,
|
||||
swapchains_controllers_depth,
|
||||
*renderer,
|
||||
*controllers_scene,
|
||||
{0, 0, 0, 0});
|
||||
for (auto [color, depth]: std::views::zip(controllers_layer_views, controllers_depth_layer_views))
|
||||
color.next = &depth;
|
||||
if (dim_gui)
|
||||
set_color_scale_bias(constants::lobby::dimming_scale, constants::lobby::dimming_bias);
|
||||
|
||||
renderer->end_frame();
|
||||
if (composition_layer_depth_test_supported)
|
||||
set_depth_test(true, XR_COMPARE_OP_LESS_OR_EQUAL_FB);
|
||||
|
||||
// After end_frame because the command buffers are submitted in end_frame
|
||||
for (auto & swapchain: swapchains_lobby)
|
||||
swapchain.release();
|
||||
|
||||
for (auto & swapchain: swapchains_lobby_depth)
|
||||
swapchain.release();
|
||||
|
||||
for (auto & swapchain: swapchains_controllers)
|
||||
swapchain.release();
|
||||
|
||||
for (auto & swapchain: swapchains_controllers_depth)
|
||||
swapchain.release();
|
||||
}
|
||||
else
|
||||
{
|
||||
lobby_layer_views = render_layer(
|
||||
views,
|
||||
swapchains_lobby,
|
||||
*renderer,
|
||||
*lobby_scene,
|
||||
clear_color);
|
||||
|
||||
controllers_layer_views = render_layer(
|
||||
views,
|
||||
swapchains_controllers,
|
||||
*renderer,
|
||||
*controllers_scene,
|
||||
{0, 0, 0, 0});
|
||||
|
||||
renderer->end_frame();
|
||||
|
||||
// After end_frame because the command buffers are submitted in end_frame
|
||||
for (auto & swapchain: swapchains_lobby)
|
||||
swapchain.release();
|
||||
|
||||
for (auto & swapchain: swapchains_controllers)
|
||||
swapchain.release();
|
||||
dim_gui = false; // Only dim the main window
|
||||
}
|
||||
}
|
||||
|
||||
XrCompositionLayerProjection lobby_layer{
|
||||
.type = XR_TYPE_COMPOSITION_LAYER_PROJECTION,
|
||||
.layerFlags = XR_COMPOSITION_LAYER_BLEND_TEXTURE_SOURCE_ALPHA_BIT,
|
||||
.space = world_space,
|
||||
.viewCount = (uint32_t)lobby_layer_views.size(),
|
||||
.views = lobby_layer_views.data(),
|
||||
};
|
||||
render_world(
|
||||
XR_COMPOSITION_LAYER_BLEND_TEXTURE_SOURCE_ALPHA_BIT,
|
||||
world_space,
|
||||
views,
|
||||
width,
|
||||
height,
|
||||
composition_layer_depth_test_supported,
|
||||
composition_layer_depth_test_supported ? layer_rays : layer_rays | layer_controllers,
|
||||
{0, 0, 0, 0});
|
||||
|
||||
XrCompositionLayerProjection controllers_layer{
|
||||
.type = XR_TYPE_COMPOSITION_LAYER_PROJECTION,
|
||||
.layerFlags = XR_COMPOSITION_LAYER_BLEND_TEXTURE_SOURCE_ALPHA_BIT,
|
||||
.space = world_space,
|
||||
.viewCount = (uint32_t)controllers_layer_views.size(),
|
||||
.views = controllers_layer_views.data(),
|
||||
};
|
||||
|
||||
XrEnvironmentBlendMode blend_mode = XR_ENVIRONMENT_BLEND_MODE_OPAQUE;
|
||||
std::vector<std::pair<int, XrCompositionLayerBaseHeader *>> layers_with_z_index;
|
||||
|
||||
if (application::get_config().passthrough_enabled)
|
||||
{
|
||||
std::visit(
|
||||
utils::overloaded{
|
||||
[&](std::monostate &) {
|
||||
assert(false);
|
||||
},
|
||||
[&](xr::passthrough_alpha_blend & p) {
|
||||
blend_mode = XR_ENVIRONMENT_BLEND_MODE_ALPHA_BLEND;
|
||||
},
|
||||
[&](auto & p) {
|
||||
layers_with_z_index.emplace_back(constants::lobby::zindex_passthrough, p.layer());
|
||||
}},
|
||||
session.get_passthrough());
|
||||
}
|
||||
|
||||
// Dimming settings if a popup window is displayed
|
||||
XrCompositionLayerColorScaleBiasKHR color_scale_bias{
|
||||
.type = XR_TYPE_COMPOSITION_LAYER_COLOR_SCALE_BIAS_KHR,
|
||||
.colorScale = constants::lobby::dimming_scale,
|
||||
.colorBias = constants::lobby::dimming_bias,
|
||||
};
|
||||
|
||||
// Add XrCompositionLayerDepthTestFB to lobby_layer and imgui_layer
|
||||
// The sky in the lobby layer and the passthrough layer have the same depth, so the operation must be:
|
||||
// - LESS when passthrough is enabled (to avoid overwriting the passthrough)
|
||||
// - LESS_OR_EQUAL when passthrough is disabled (so that the sky is visible)
|
||||
XrCompositionLayerDepthTestFB layer_depth_test{
|
||||
.type = XR_TYPE_COMPOSITION_LAYER_DEPTH_TEST_FB,
|
||||
.next = nullptr,
|
||||
.depthMask = true,
|
||||
.compareOp = application::get_config().passthrough_enabled ? XR_COMPARE_OP_LESS_FB : XR_COMPARE_OP_LESS_OR_EQUAL_FB,
|
||||
};
|
||||
XrCompositionLayerDepthTestFB layer_depth_test_bg{
|
||||
.type = XR_TYPE_COMPOSITION_LAYER_DEPTH_TEST_FB,
|
||||
.next = nullptr,
|
||||
.depthMask = true,
|
||||
.compareOp = XR_COMPARE_OP_ALWAYS_FB,
|
||||
};
|
||||
|
||||
// if (composition_layer_depth_test_supported or not application::get_config().passthrough_enabled)
|
||||
layers_with_z_index.emplace_back(constants::lobby::zindex_lobby, reinterpret_cast<XrCompositionLayerBaseHeader *>(&lobby_layer));
|
||||
if (composition_layer_depth_test_supported)
|
||||
set_depth_test(true, XR_COMPARE_OP_LESS_OR_EQUAL_FB);
|
||||
|
||||
for (auto & [z_index, layer]: imgui_layers)
|
||||
layers_with_z_index.emplace_back(z_index, reinterpret_cast<XrCompositionLayerBaseHeader *>(&layer));
|
||||
|
||||
layers_with_z_index.emplace_back(constants::lobby::zindex_controllers, reinterpret_cast<XrCompositionLayerBaseHeader *>(&controllers_layer));
|
||||
|
||||
if (composition_layer_depth_test_supported)
|
||||
{
|
||||
lobby_layer.next = &layer_depth_test_bg;
|
||||
|
||||
for (auto & [z_index, layer]: imgui_layers)
|
||||
{
|
||||
if (z_index != constants::lobby::zindex_recenter_tip)
|
||||
layer.next = &layer_depth_test;
|
||||
}
|
||||
|
||||
controllers_layer.next = &layer_depth_test;
|
||||
if (z_index == constants::lobby::zindex_recenter_tip)
|
||||
add_quad_layer(layer.layerFlags, layer.space, layer.eyeVisibility, layer.subImage, layer.pose, layer.size);
|
||||
}
|
||||
|
||||
if (imgui_ctx->is_modal_popup_shown() and composition_layer_color_scale_bias_supported)
|
||||
{
|
||||
color_scale_bias.next = imgui_layers.front().second.next;
|
||||
imgui_layers.front().second.next = &color_scale_bias;
|
||||
}
|
||||
|
||||
std::ranges::stable_sort(layers_with_z_index);
|
||||
|
||||
std::vector<XrCompositionLayerBaseHeader *> layers;
|
||||
layers.reserve(layers_with_z_index.size());
|
||||
for (auto & [z_index, layer]: layers_with_z_index)
|
||||
layers.push_back(layer);
|
||||
|
||||
session.end_frame(frame_state.predictedDisplayTime, layers, blend_mode);
|
||||
render_end();
|
||||
}
|
||||
|
||||
void scenes::lobby::on_focused()
|
||||
@@ -1015,53 +755,25 @@ void scenes::lobby::on_focused()
|
||||
recenter_gui = true;
|
||||
|
||||
auto views = system.view_configuration_views(viewconfig);
|
||||
assert(views.size() == 2); // FIXME
|
||||
stream_view = override_view(views[0], guess_model());
|
||||
uint32_t width = views[0].recommendedImageRectWidth;
|
||||
uint32_t height = views[0].recommendedImageRectHeight;
|
||||
width = views[0].recommendedImageRectWidth;
|
||||
height = views[0].recommendedImageRectHeight;
|
||||
|
||||
swapchains_lobby.reserve(views.size());
|
||||
swapchains_controllers.reserve(views.size());
|
||||
// assert(std::ranges::all_of(views, [width](const XrViewConfigurationView & view) { return view.recommendedImageRectWidth == width; }));
|
||||
// assert(std::ranges::all_of(views, [height](const XrViewConfigurationView & view) { return view.recommendedImageRectHeight == height; }));
|
||||
|
||||
if (composition_layer_depth_test_supported)
|
||||
swapchains_lobby_depth.reserve(views.size());
|
||||
renderer.emplace(device, physical_device, queue, commandpool);
|
||||
loader.emplace(device, physical_device, queue, application::queue_family_index(), renderer->get_default_material());
|
||||
|
||||
for ([[maybe_unused]] auto view: views)
|
||||
{
|
||||
assert(view.recommendedImageRectWidth == width);
|
||||
assert(view.recommendedImageRectHeight == height);
|
||||
lobby_entity = load_gltf("ground.gltf", layer_lobby).first;
|
||||
|
||||
swapchains_lobby.emplace_back(session, device, swapchain_format, width, height);
|
||||
swapchains_controllers.emplace_back(session, device, swapchain_format, width, height);
|
||||
|
||||
if (composition_layer_depth_test_supported)
|
||||
{
|
||||
swapchains_lobby_depth.emplace_back(session, device, depth_format, width, height);
|
||||
swapchains_controllers_depth.emplace_back(session, device, depth_format, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
spdlog::info("Created lobby swapchains: {}x{}", width, height);
|
||||
|
||||
vk::Extent2D output_size{width, height};
|
||||
|
||||
renderer.emplace(device, physical_device, queue, commandpool, output_size, swapchain_format, depth_format, 2, composition_layer_depth_test_supported);
|
||||
|
||||
scene_loader loader(device, physical_device, queue, application::queue_family_index(), renderer->get_default_material());
|
||||
|
||||
lobby_scene.emplace();
|
||||
lobby_handle = lobby_scene->new_node();
|
||||
lobby_scene->import(loader("ground.gltf"), lobby_handle);
|
||||
|
||||
controllers_scene.emplace();
|
||||
|
||||
scene_data & controllers_scene_data = composition_layer_depth_test_supported ? *lobby_scene : *controllers_scene;
|
||||
|
||||
auto profile = controller_name();
|
||||
input = input_profile(
|
||||
std::string profile = controller_name();
|
||||
input.emplace(
|
||||
*this,
|
||||
"controllers/" + profile + "/profile.json",
|
||||
loader,
|
||||
controllers_scene_data,
|
||||
*controllers_scene);
|
||||
layer_controllers,
|
||||
layer_rays);
|
||||
|
||||
spdlog::info("Loaded input profile {}", input->id);
|
||||
|
||||
@@ -1085,17 +797,14 @@ void scenes::lobby::on_focused()
|
||||
offset_orientation = glm::degrees(glm::eulerAngles(input->offset[xr::spaces::grip_left].second));
|
||||
ray_offset = input->offset[xr::spaces::aim_left].first.z;
|
||||
|
||||
xyz_axes_left_controller = controllers_scene_data.new_node();
|
||||
controllers_scene_data.import(loader("xyz-arrows.glb"), xyz_axes_left_controller);
|
||||
|
||||
xyz_axes_right_controller = controllers_scene_data.new_node();
|
||||
controllers_scene_data.import(loader("xyz-arrows.glb"), xyz_axes_right_controller);
|
||||
xyz_axes_left_controller = load_gltf("xyz-arrows.glb", layer_controllers).first;
|
||||
xyz_axes_right_controller = load_gltf("xyz-arrows.glb", layer_controllers).first;
|
||||
#endif
|
||||
|
||||
if (application::get_hand_tracking_supported())
|
||||
{
|
||||
left_hand.emplace("left-hand.glb", loader, controllers_scene_data);
|
||||
right_hand.emplace("right-hand.glb", loader, controllers_scene_data);
|
||||
hand_model::add_hand(*this, XR_HAND_LEFT_EXT, "left-hand.glb", layer_controllers);
|
||||
hand_model::add_hand(*this, XR_HAND_RIGHT_EXT, "right-hand.glb", layer_controllers);
|
||||
}
|
||||
|
||||
recenter_left_action = get_action("recenter_left").first;
|
||||
@@ -1108,6 +817,7 @@ void scenes::lobby::on_focused()
|
||||
.trigger = get_action("left_trigger").first,
|
||||
.squeeze = get_action("left_squeeze").first,
|
||||
.scroll = get_action("left_scroll").first,
|
||||
.haptic_output = get_action("left_haptic").first,
|
||||
},
|
||||
imgui_context::controller{
|
||||
.aim = get_action_space("right_aim"),
|
||||
@@ -1115,6 +825,7 @@ void scenes::lobby::on_focused()
|
||||
.trigger = get_action("right_trigger").first,
|
||||
.squeeze = get_action("right_squeeze").first,
|
||||
.scroll = get_action("right_scroll").first,
|
||||
.haptic_output = get_action("right_haptic").first,
|
||||
},
|
||||
};
|
||||
if (auto & hand = application::get_left_hand())
|
||||
@@ -1206,18 +917,13 @@ void scenes::lobby::on_unfocused()
|
||||
|
||||
about_picture = nullptr;
|
||||
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();
|
||||
world.clear(); // Must be cleared before the renderer so that the descriptor sets are freed before their pools
|
||||
|
||||
input.reset();
|
||||
left_hand.reset();
|
||||
right_hand.reset();
|
||||
|
||||
loader.reset();
|
||||
renderer.reset();
|
||||
swapchains_lobby.clear();
|
||||
swapchains_controllers.clear();
|
||||
swapchains_lobby_depth.clear();
|
||||
swapchains_controllers_depth.clear();
|
||||
clear_swapchains();
|
||||
swapchain_imgui = xr::swapchain();
|
||||
multicast.reset();
|
||||
}
|
||||
|
||||
+9
-26
@@ -22,9 +22,7 @@
|
||||
#include "asset.h"
|
||||
#include "configuration.h"
|
||||
#include "crypto.h"
|
||||
#include "render/scene_data.h"
|
||||
#include "scene.h"
|
||||
#include "scenes/hand_model.h"
|
||||
#include "scenes/lobby_keyboard.h"
|
||||
#include "utils/thread_safe.h"
|
||||
#include "wifi_lock.h"
|
||||
@@ -33,13 +31,10 @@
|
||||
#include "wivrn_packets.h"
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
|
||||
#include "xr/system.h"
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#include "input_profile.h"
|
||||
#include "render/imgui_impl.h"
|
||||
#include "render/scene_renderer.h"
|
||||
#include "utils/async.h"
|
||||
|
||||
class wivrn_session;
|
||||
@@ -65,37 +60,27 @@ class lobby : public scene_impl<lobby>
|
||||
std::string server_name;
|
||||
bool autoconnect_enabled = true;
|
||||
|
||||
std::optional<scene_renderer> renderer;
|
||||
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;
|
||||
node_handle lobby_handle;
|
||||
bool composition_layer_depth_test_supported;
|
||||
bool composition_layer_color_scale_bias_supported;
|
||||
entt::entity lobby_entity;
|
||||
|
||||
std::optional<imgui_context> imgui_ctx;
|
||||
std::array<XrAction, 2> haptic_output;
|
||||
|
||||
std::string selected_item;
|
||||
std::unique_ptr<asset> license;
|
||||
ImGuiID hovered_item;
|
||||
|
||||
std::vector<xr::swapchain> swapchains_lobby;
|
||||
std::vector<xr::swapchain> swapchains_lobby_depth;
|
||||
std::vector<xr::swapchain> swapchains_controllers;
|
||||
std::vector<xr::swapchain> swapchains_controllers_depth;
|
||||
static inline const uint32_t layer_lobby = 1 << 0;
|
||||
static inline const uint32_t layer_controllers = 1 << 1;
|
||||
static inline const uint32_t layer_rays = 1 << 2;
|
||||
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
xr::swapchain swapchain_imgui;
|
||||
vk::Format swapchain_format;
|
||||
vk::Format depth_format;
|
||||
xr::system::passthrough_type passthrough_supported;
|
||||
XrViewConfigurationView stream_view;
|
||||
|
||||
#if WIVRN_CLIENT_DEBUG_MENU
|
||||
// GUI debug
|
||||
node_handle xyz_axes_left_controller;
|
||||
node_handle xyz_axes_right_controller;
|
||||
entt::entity xyz_axes_left_controller;
|
||||
entt::entity xyz_axes_right_controller;
|
||||
bool display_debug_axes = false;
|
||||
bool display_grip_instead_of_aim = false;
|
||||
glm::vec3 offset_position{};
|
||||
@@ -158,8 +143,6 @@ class lobby : public scene_impl<lobby>
|
||||
|
||||
void setup_passthrough();
|
||||
|
||||
void vibrate_on_hover();
|
||||
|
||||
void connect(const configuration::server_data & data);
|
||||
std::unique_ptr<wivrn_session> connect_to_session(wivrn_discover::service service, bool manual_connection);
|
||||
|
||||
|
||||
+60
-76
@@ -185,12 +185,6 @@ void scenes::lobby::tooltip(std::string_view text)
|
||||
viewport->Size = size_backup;
|
||||
}
|
||||
|
||||
void scenes::lobby::vibrate_on_hover()
|
||||
{
|
||||
if (ImGui::IsItemHovered())
|
||||
hovered_item = ImGui::GetItemID();
|
||||
}
|
||||
|
||||
void scenes::lobby::gui_connecting(locked_notifiable<pin_request_data> & pin_request)
|
||||
{
|
||||
using constants::style::button_size;
|
||||
@@ -243,7 +237,7 @@ void scenes::lobby::gui_connecting(locked_notifiable<pin_request_data> & pin_req
|
||||
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
}
|
||||
|
||||
void scenes::lobby::gui_enter_pin(locked_notifiable<pin_request_data> & pin_request)
|
||||
@@ -288,7 +282,7 @@ void scenes::lobby::gui_enter_pin(locked_notifiable<pin_request_data> & pin_requ
|
||||
char button_text[] = {char('0' + i), 0};
|
||||
if (ImGui::Button(button_text, constants::style::pin_entry_key_size))
|
||||
pin_buffer += button_text;
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
if (j < 2)
|
||||
ImGui::SameLine();
|
||||
@@ -307,20 +301,20 @@ void scenes::lobby::gui_enter_pin(locked_notifiable<pin_request_data> & pin_requ
|
||||
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
ImGui::PopStyleColor(3);
|
||||
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("0", constants::style::pin_entry_key_size))
|
||||
pin_buffer += "0";
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
ImGui::EndDisabled();
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::BeginDisabled(pin_buffer.size() == 0);
|
||||
if (ImGui::Button(ICON_FA_DELETE_LEFT, constants::style::pin_entry_key_size))
|
||||
pin_buffer.resize(pin_buffer.size() - 1);
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
ImGui::EndDisabled();
|
||||
|
||||
ImGui::PopStyleVar(); // ImGuiStyleVar_ItemSpacing
|
||||
@@ -331,7 +325,7 @@ void scenes::lobby::gui_enter_pin(locked_notifiable<pin_request_data> & pin_requ
|
||||
pin_request->pin_requested = false;
|
||||
pin_request.notify_one();
|
||||
}
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
}
|
||||
|
||||
void scenes::lobby::gui_new_server()
|
||||
@@ -359,7 +353,7 @@ void scenes::lobby::gui_new_server()
|
||||
if (ImGui::IsWindowAppearing())
|
||||
ImGui::SetKeyboardFocusHere();
|
||||
InputText("##Name", add_server_window_prettyname, {ImGui::GetContentRegionAvail().x, 0}, 0);
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
@@ -368,7 +362,7 @@ void scenes::lobby::gui_new_server()
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
InputText("##Hostname", add_server_window_hostname, {ImGui::GetContentRegionAvail().x, 0}, 0);
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
@@ -377,12 +371,12 @@ void scenes::lobby::gui_new_server()
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::InputInt("##Port", &add_server_window_port, 1, 1, ImGuiInputTextFlags_CharsDecimal);
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::EndTable();
|
||||
|
||||
ImGui::Checkbox(_S("TCP only"), &add_server_tcp_only);
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
auto top_left = ImGui::GetWindowContentRegionMin();
|
||||
auto bottom_right = ImGui::GetWindowContentRegionMax();
|
||||
@@ -398,7 +392,7 @@ void scenes::lobby::gui_new_server()
|
||||
add_server_cookie = "";
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::SameLine(bottom_right.x - button_size.x);
|
||||
|
||||
@@ -429,7 +423,7 @@ void scenes::lobby::gui_new_server()
|
||||
add_server_cookie = "";
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::PopStyleVar(4); // ImGuiStyleVar_FrameRounding, ImGuiStyleVar_ItemSpacing, ImGuiStyleVar_CellPadding, ImGuiStyleVar_FramePadding
|
||||
}
|
||||
@@ -490,7 +484,7 @@ void scenes::lobby::gui_server_list()
|
||||
std::string label = _("Autoconnect") + "##" + cookie;
|
||||
if (ImGui::Checkbox(label.c_str(), &data.autoconnect))
|
||||
config.save();
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
}
|
||||
|
||||
ImVec2 button_position(ImGui::GetWindowContentRegionMax().x, pos.y + (list_item_height - button_size.y) / 2);
|
||||
@@ -518,7 +512,7 @@ void scenes::lobby::gui_server_list()
|
||||
connect(data);
|
||||
ImGui::OpenPopup("connecting");
|
||||
}
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
|
||||
{
|
||||
@@ -541,7 +535,7 @@ void scenes::lobby::gui_server_list()
|
||||
|
||||
if (ImGui::Button((ICON_FA_TRASH_CAN "##remove-" + cookie).c_str(), icon_button_size))
|
||||
cookie_to_remove = cookie;
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
ImGui::PopStyleColor(3);
|
||||
|
||||
button_position.x -= icon_button_size.x + style.WindowPadding.x + 10;
|
||||
@@ -555,7 +549,7 @@ void scenes::lobby::gui_server_list()
|
||||
add_server_tcp_only = data.service.tcp_only;
|
||||
ImGui::OpenPopup("add or edit server");
|
||||
}
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
}
|
||||
|
||||
pos.y += 120;
|
||||
@@ -632,7 +626,7 @@ void scenes::lobby::gui_settings()
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
if (config.preferred_refresh_rate == 0 and refresh_rates.size() > 2)
|
||||
{
|
||||
@@ -649,7 +643,7 @@ void scenes::lobby::gui_settings()
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -670,7 +664,7 @@ void scenes::lobby::gui_settings()
|
||||
config.resolution_scale = intScale * 0.01;
|
||||
config.save();
|
||||
}
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (width * config.resolution_scale > stream_view.maxImageRectWidth or height * config.resolution_scale > stream_view.maxImageRectHeight)
|
||||
{
|
||||
ImGui::TextColored(ImColor(0xf9, 0x73, 0x06) /*orange*/, ICON_FA_TRIANGLE_EXCLAMATION);
|
||||
@@ -686,7 +680,7 @@ void scenes::lobby::gui_settings()
|
||||
config.set_feature(feature::microphone, enabled);
|
||||
config.save();
|
||||
}
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
}
|
||||
{
|
||||
ImGui::BeginDisabled(not config.check_feature(feature::microphone));
|
||||
@@ -695,7 +689,7 @@ void scenes::lobby::gui_settings()
|
||||
{
|
||||
config.save();
|
||||
}
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (ImGui::IsItemHovered())
|
||||
tooltip(_("Force disable audio filters, such as noise cancellation"));
|
||||
ImGui::Unindent();
|
||||
@@ -709,7 +703,7 @@ void scenes::lobby::gui_settings()
|
||||
config.set_feature(feature::hand_tracking, enabled);
|
||||
config.save();
|
||||
}
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) and (ImGui::GetItemFlags() & ImGuiItemFlags_Disabled))
|
||||
tooltip(_("This feature is not supported by your headset"));
|
||||
ImGui::EndDisabled();
|
||||
@@ -722,7 +716,7 @@ void scenes::lobby::gui_settings()
|
||||
config.set_feature(feature::eye_gaze, enabled);
|
||||
config.save();
|
||||
}
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) and (ImGui::GetItemFlags() & ImGuiItemFlags_Disabled))
|
||||
tooltip(_("This feature is not supported by your headset"));
|
||||
ImGui::EndDisabled();
|
||||
@@ -738,7 +732,7 @@ void scenes::lobby::gui_settings()
|
||||
ImGui::EndDisabled();
|
||||
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) and (ImGui::GetItemFlags() & ImGuiItemFlags_Disabled))
|
||||
tooltip(_("This feature is not supported by your headset"));
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
}
|
||||
|
||||
{
|
||||
@@ -768,7 +762,7 @@ void scenes::lobby::gui_settings()
|
||||
}
|
||||
}
|
||||
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
}
|
||||
if (std::holds_alternative<xr::fb_body_tracker>(application::get_body_tracker()))
|
||||
{
|
||||
@@ -778,7 +772,7 @@ void scenes::lobby::gui_settings()
|
||||
{
|
||||
config.save();
|
||||
}
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (ImGui::IsItemHovered())
|
||||
tooltip(_("Estimate lower body joint positions using Generative Legs\nRequires 'Hand and body tracking' to be enabled in the Quest movement tracking settings"));
|
||||
|
||||
@@ -787,7 +781,7 @@ void scenes::lobby::gui_settings()
|
||||
{
|
||||
config.save();
|
||||
}
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (ImGui::IsItemHovered())
|
||||
tooltip(_("Only takes affect with lower body tracking enabled\nMay be desired when using another source of hip tracking"));
|
||||
ImGui::EndDisabled();
|
||||
@@ -802,14 +796,14 @@ void scenes::lobby::gui_settings()
|
||||
setup_passthrough();
|
||||
config.save();
|
||||
}
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) and (ImGui::GetItemFlags() & ImGuiItemFlags_Disabled))
|
||||
tooltip(_("This feature is not supported by your headset"));
|
||||
ImGui::EndDisabled();
|
||||
|
||||
if (ImGui::Checkbox(_S("Show performance metrics"), &config.show_performance_metrics))
|
||||
config.save();
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (ImGui::IsItemHovered())
|
||||
tooltip(_("Overlay can be toggled by pressing both thumbsticks"));
|
||||
|
||||
@@ -895,11 +889,11 @@ void scenes::lobby::gui_post_processing()
|
||||
config.openxr_post_processing.super_sampling = option;
|
||||
config.save();
|
||||
}
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
tooltip(_("Reduce flicker for high contrast edges.\nUseful when the input resolution is high compared to the headset display"));
|
||||
@@ -920,11 +914,11 @@ void scenes::lobby::gui_post_processing()
|
||||
config.openxr_post_processing.sharpening = option;
|
||||
config.save();
|
||||
}
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
tooltip(_("Improve clarity of high contrast edges and counteract blur.\nUseful when the input resolution is low compared to the headset display"));
|
||||
@@ -940,7 +934,7 @@ void scenes::lobby::gui_post_processing()
|
||||
{
|
||||
config.save();
|
||||
}
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
if (application::get_openxr_post_processing_supported())
|
||||
@@ -974,7 +968,7 @@ void scenes::lobby::gui_post_processing()
|
||||
config.sgsr.upscaling_factor = intScale * 0.01;
|
||||
config.save();
|
||||
}
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (width * current > stream_view.maxImageRectWidth or height * current > stream_view.maxImageRectHeight)
|
||||
{
|
||||
ImGui::TextColored(ImColor(0xf9, 0x73, 0x06) /*orange*/, ICON_FA_TRIANGLE_EXCLAMATION);
|
||||
@@ -987,7 +981,7 @@ void scenes::lobby::gui_post_processing()
|
||||
{
|
||||
config.save();
|
||||
}
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (ImGui::IsItemHovered())
|
||||
tooltip(_("Adds an additional performance cost"));
|
||||
}
|
||||
@@ -999,7 +993,7 @@ void scenes::lobby::gui_post_processing()
|
||||
config.sgsr.edge_threshold = float(intScale);
|
||||
config.save();
|
||||
}
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (ImGui::IsItemHovered())
|
||||
tooltip(fmt::format(_F("Recommended: {:.1f}"), 4.0));
|
||||
}
|
||||
@@ -1008,7 +1002,7 @@ void scenes::lobby::gui_post_processing()
|
||||
{
|
||||
config.save();
|
||||
}
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (ImGui::IsItemHovered())
|
||||
tooltip(fmt::format(_F("Recommended: {:.1f}"), 2.0));
|
||||
}
|
||||
@@ -1027,55 +1021,55 @@ void scenes::lobby::gui_debug()
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(20, 20));
|
||||
|
||||
ImGui::Checkbox("Display debug axes", &display_debug_axes);
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
if (display_debug_axes)
|
||||
{
|
||||
ImGui::Checkbox("Display grip instead of aim", &display_grip_instead_of_aim);
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
}
|
||||
|
||||
ImGui::SetNextItemWidth(140);
|
||||
ImGui::DragFloat("##offset x", &offset_position.x, 0.0001);
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(140);
|
||||
ImGui::DragFloat("##offset y", &offset_position.y, 0.0001);
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(140);
|
||||
ImGui::DragFloat("Position", &offset_position.z, 0.0001);
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Reset##position"))
|
||||
offset_position = {0, 0, 0};
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::SetNextItemWidth(140);
|
||||
ImGui::DragFloat("##offset roll", &offset_orientation.x, 0.01);
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(140);
|
||||
ImGui::DragFloat("##offset pitch", &offset_orientation.y, 0.01);
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(140);
|
||||
ImGui::DragFloat("Rotation", &offset_orientation.z, 0.01);
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Reset##orientation"))
|
||||
offset_orientation = {0, 0, 0};
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::SetNextItemWidth(140);
|
||||
ImGui::DragFloat("Ray offset", &ray_offset, 0.0001);
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
}
|
||||
@@ -1134,7 +1128,7 @@ void scenes::lobby::gui_licenses()
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (license)
|
||||
ImGui::TextUnformatted((const char *)license->data(), (const char *)license->data() + license->size());
|
||||
}
|
||||
@@ -1501,7 +1495,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
|
||||
// New server button
|
||||
if (ImGui::Button(_S("Add server")) && !ImGui::IsPopupOpen("add or edit server"))
|
||||
ImGui::OpenPopup("add or edit server");
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
ImGui::SameLine();
|
||||
|
||||
// Enabled features
|
||||
@@ -1521,7 +1515,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
|
||||
config.save();
|
||||
}
|
||||
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (ImGui::IsItemHovered())
|
||||
tooltip(i.enabled ? i.tooltip_enabled : i.tooltip_disabled);
|
||||
|
||||
@@ -1598,7 +1592,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
|
||||
|
||||
void scenes::lobby::gui_keyboard()
|
||||
{
|
||||
keyboard.display(hovered_item);
|
||||
keyboard.display(*imgui_ctx);
|
||||
|
||||
auto & config = application::get_config();
|
||||
|
||||
@@ -1646,9 +1640,6 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
|
||||
|
||||
const float TabWidth = 300;
|
||||
|
||||
auto last_hovered = hovered_item;
|
||||
hovered_item = 0;
|
||||
|
||||
if (ImGui::GetIO().WantTextInput)
|
||||
{
|
||||
ImGui::SetNextWindowPos(imgui_ctx->layers()[2].vp_center(), ImGuiCond_Always, {0.5, 0.5});
|
||||
@@ -1729,28 +1720,28 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10, 10));
|
||||
RadioButtonWithoutCheckBox(ICON_FA_COMPUTER " " + _("Server list"), ¤t_tab, tab::server_list, {TabWidth, 0});
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
RadioButtonWithoutCheckBox(ICON_FA_GEARS " " + _("Settings"), ¤t_tab, tab::settings, {TabWidth, 0});
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
RadioButtonWithoutCheckBox(ICON_FA_WAND_MAGIC_SPARKLES " " + _("Post-processing"), ¤t_tab, tab::post_processing, {TabWidth, 0});
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
#if WIVRN_CLIENT_DEBUG_MENU
|
||||
RadioButtonWithoutCheckBox(ICON_FA_BUG_SLASH " " + _("Debug"), ¤t_tab, tab::debug, {TabWidth, 0});
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
#endif
|
||||
|
||||
ImGui::SetCursorPosY(ImGui::GetContentRegionMax().y - 3 * ImGui::GetCurrentContext()->FontSize - 6 * style.FramePadding.y - 2 * style.ItemSpacing.y - style.WindowPadding.y);
|
||||
RadioButtonWithoutCheckBox(ICON_FA_CIRCLE_INFO " " + _("About"), ¤t_tab, tab::about, {TabWidth, 0});
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
RadioButtonWithoutCheckBox(ICON_FA_SCALE_BALANCED " " + _("Licenses"), ¤t_tab, tab::licenses, {TabWidth, 0});
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
RadioButtonWithoutCheckBox(ICON_FA_DOOR_OPEN " " + _("Exit"), ¤t_tab, tab::exit, {TabWidth, 0});
|
||||
vibrate_on_hover();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::PopStyleVar(); // ImGuiStyleVar_FramePadding
|
||||
ImGui::EndChild();
|
||||
@@ -1768,13 +1759,6 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
|
||||
display_recentering_tip(*imgui_ctx, _("Press A or X to move the main window"));
|
||||
}
|
||||
|
||||
if (hovered_item != last_hovered && hovered_item != 0)
|
||||
{
|
||||
size_t controller = imgui_ctx->get_focused_controller();
|
||||
if (controller < haptic_output.size())
|
||||
application::haptic_start(haptic_output[controller], XR_NULL_PATH, 10'000'000, 1000, 1);
|
||||
}
|
||||
|
||||
#if WIVRN_CLIENT_DEBUG_MENU
|
||||
{
|
||||
input->offset[xr::spaces::grip_left].first = offset_position;
|
||||
|
||||
@@ -462,7 +462,7 @@ void virtual_keyboard::press_single_key(const key & k)
|
||||
}
|
||||
}
|
||||
|
||||
void virtual_keyboard::display(ImGuiID & hovered_id)
|
||||
void virtual_keyboard::display(imgui_context & ctx)
|
||||
{
|
||||
ImGuiStyle & style = ImGui::GetStyle();
|
||||
|
||||
@@ -534,7 +534,7 @@ void virtual_keyboard::display(ImGuiID & hovered_id)
|
||||
|
||||
auto status = draw_single_key(key, id++, ImVec2{base_key_width * key.width - style.ItemSpacing.x, key_height}, window_hovered);
|
||||
if (status.hovered)
|
||||
hovered_id = ImGui::GetItemID();
|
||||
ctx.set_hovered_item();
|
||||
}
|
||||
|
||||
key_position.x += base_key_width * key.width;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "imgui.h"
|
||||
#include "render/imgui_impl.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -80,7 +81,7 @@ private:
|
||||
bool symbols_shown = false;
|
||||
|
||||
public:
|
||||
void display(ImGuiID & hovered);
|
||||
void display(imgui_context & ctx);
|
||||
const std::string_view get_layout() const;
|
||||
void set_layout(std::string_view layout_name);
|
||||
};
|
||||
|
||||
+22
-61
@@ -140,6 +140,11 @@ static const std::array supported_formats = {
|
||||
vk::Format::eB8G8R8A8Srgb,
|
||||
};
|
||||
|
||||
scenes::stream::stream() :
|
||||
scene_impl<stream>(supported_formats)
|
||||
{
|
||||
}
|
||||
|
||||
static from_headset::visibility_mask_changed::masks get_visibility_mask(xr::instance & inst, xr::session & session, int view)
|
||||
{
|
||||
assert(inst.has_extension(XR_KHR_VISIBILITY_MASK_EXTENSION_NAME));
|
||||
@@ -341,25 +346,6 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
||||
self->input_actions.emplace_back(it->second, action, action_type);
|
||||
}
|
||||
|
||||
self->swapchain_format = vk::Format::eUndefined;
|
||||
spdlog::info("Supported swapchain formats:");
|
||||
|
||||
for (auto format: self->session.get_swapchain_formats())
|
||||
{
|
||||
spdlog::info(" {}", vk::to_string(format));
|
||||
}
|
||||
for (auto format: self->session.get_swapchain_formats())
|
||||
{
|
||||
if (std::find(supported_formats.begin(), supported_formats.end(), format) != supported_formats.end())
|
||||
{
|
||||
self->swapchain_format = format;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (self->swapchain_format == vk::Format::eUndefined)
|
||||
throw std::runtime_error("No supported swapchain format");
|
||||
|
||||
spdlog::info("Using format {}", vk::to_string(self->swapchain_format));
|
||||
|
||||
self->query_pool = vk::raii::QueryPool(
|
||||
@@ -956,31 +942,18 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
vk::SubmitInfo submit_info;
|
||||
submit_info.setCommandBuffers(*command_buffer);
|
||||
queue.submit(submit_info, *fence);
|
||||
swapchain.release();
|
||||
|
||||
XrEnvironmentBlendMode blend_mode = XR_ENVIRONMENT_BLEND_MODE_OPAQUE;
|
||||
std::vector<XrCompositionLayerBaseHeader *> layers_base;
|
||||
// std::vector<XrCompositionLayerBaseHeader *> layers_base;
|
||||
std::vector<XrCompositionLayerProjectionView> layer_view(view_count);
|
||||
|
||||
if (use_alpha)
|
||||
{
|
||||
session.enable_passthrough(system);
|
||||
std::visit(
|
||||
utils::overloaded{
|
||||
[&](std::monostate &) {
|
||||
assert(false);
|
||||
},
|
||||
[&](xr::passthrough_alpha_blend & p) {
|
||||
blend_mode = XR_ENVIRONMENT_BLEND_MODE_ALPHA_BLEND;
|
||||
},
|
||||
[&](auto & p) {
|
||||
layers_base.push_back(p.layer());
|
||||
}},
|
||||
session.get_passthrough());
|
||||
}
|
||||
else
|
||||
session.disable_passthrough();
|
||||
|
||||
swapchain.release();
|
||||
render_start(use_alpha, frame_state.predictedDisplayTime);
|
||||
|
||||
for (uint32_t view = 0; view < view_count; view++)
|
||||
{
|
||||
layer_view[view] =
|
||||
@@ -999,45 +972,33 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
},
|
||||
};
|
||||
}
|
||||
add_projection_layer(
|
||||
XR_COMPOSITION_LAYER_BLEND_TEXTURE_SOURCE_ALPHA_BIT,
|
||||
application::space(xr::spaces::world),
|
||||
std::move(layer_view));
|
||||
|
||||
XrCompositionLayerProjection layer{
|
||||
.type = XR_TYPE_COMPOSITION_LAYER_PROJECTION,
|
||||
.layerFlags = XR_COMPOSITION_LAYER_BLEND_TEXTURE_SOURCE_ALPHA_BIT,
|
||||
.space = application::space(xr::spaces::world),
|
||||
.viewCount = (uint32_t)layer_view.size(),
|
||||
.views = layer_view.data(),
|
||||
};
|
||||
|
||||
XrCompositionLayerSettingsFB settings;
|
||||
const configuration::openxr_post_processing_settings openxr_post_processing = application::get_config().openxr_post_processing;
|
||||
if ((openxr_post_processing.sharpening | openxr_post_processing.super_sampling) > 0)
|
||||
{
|
||||
settings = {
|
||||
.type = XR_TYPE_COMPOSITION_LAYER_SETTINGS_FB,
|
||||
.layerFlags = openxr_post_processing.sharpening | openxr_post_processing.super_sampling,
|
||||
};
|
||||
layer.next = &settings;
|
||||
}
|
||||
if (const configuration::openxr_post_processing_settings openxr_post_processing = application::get_config().openxr_post_processing;
|
||||
(openxr_post_processing.sharpening | openxr_post_processing.super_sampling) > 0)
|
||||
set_layer_settings(openxr_post_processing.sharpening | openxr_post_processing.super_sampling);
|
||||
|
||||
std::vector<XrCompositionLayerQuad> imgui_layers;
|
||||
if (imgui_ctx)
|
||||
{
|
||||
accumulate_metrics(frame_state.predictedDisplayTime, current_blit_handles, timestamps);
|
||||
if (plots_visible)
|
||||
{
|
||||
imgui_layers = plot_performance_metrics(frame_state.predictedDisplayTime);
|
||||
}
|
||||
|
||||
layers_base.push_back(reinterpret_cast<XrCompositionLayerBaseHeader *>(&layer));
|
||||
for (auto & layer: imgui_layers)
|
||||
add_quad_layer(layer.layerFlags, layer.space, layer.eyeVisibility, layer.subImage, layer.pose, layer.size);
|
||||
|
||||
if (imgui_ctx and plots_visible)
|
||||
{
|
||||
for (auto & layer: imgui_layers)
|
||||
layers_base.push_back(reinterpret_cast<XrCompositionLayerBaseHeader *>(&layer));
|
||||
// TODO render controllers/hands
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
session.end_frame(frame_state.predictedDisplayTime, layers_base, blend_mode);
|
||||
render_end();
|
||||
}
|
||||
catch (std::system_error & e)
|
||||
{
|
||||
|
||||
@@ -119,7 +119,6 @@ private:
|
||||
|
||||
xr::swapchain swapchain;
|
||||
xr::swapchain swapchain_imgui;
|
||||
vk::Format swapchain_format;
|
||||
|
||||
std::optional<audio> audio_handle;
|
||||
|
||||
@@ -131,7 +130,7 @@ private:
|
||||
// Keep a reference to the resources needed to blit the images until vkWaitForFences
|
||||
std::vector<std::shared_ptr<wivrn::shard_accumulator::blit_handle>> current_blit_handles;
|
||||
|
||||
stream() = default;
|
||||
stream();
|
||||
|
||||
public:
|
||||
~stream();
|
||||
|
||||
Reference in New Issue
Block a user