Merge remote-tracking branch 'upstream/master'
This commit is contained in:
+84
-59
@@ -26,7 +26,6 @@
|
|||||||
#include "spdlog/spdlog.h"
|
#include "spdlog/spdlog.h"
|
||||||
#include "utils/contains.h"
|
#include "utils/contains.h"
|
||||||
#include "utils/files.h"
|
#include "utils/files.h"
|
||||||
#include "utils/named_thread.h"
|
|
||||||
#include "vk/check.h"
|
#include "vk/check.h"
|
||||||
#include "wifi_lock.h"
|
#include "wifi_lock.h"
|
||||||
#include "xr/actionset.h"
|
#include "xr/actionset.h"
|
||||||
@@ -51,6 +50,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
|
#include "utils/named_thread.h"
|
||||||
#include <android/native_activity.h>
|
#include <android/native_activity.h>
|
||||||
#include <sys/system_properties.h>
|
#include <sys/system_properties.h>
|
||||||
|
|
||||||
@@ -66,15 +66,16 @@ struct interaction_profile
|
|||||||
{
|
{
|
||||||
std::string profile_name;
|
std::string profile_name;
|
||||||
std::vector<std::string> required_extensions;
|
std::vector<std::string> required_extensions;
|
||||||
|
XrVersion min_version = XR_MAKE_VERSION(1, 0, 0);
|
||||||
|
XrVersion max_version = XR_MAKE_VERSION(2, 0, 0); // exclusive
|
||||||
std::vector<std::string> input_sources;
|
std::vector<std::string> input_sources;
|
||||||
bool available;
|
bool available;
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::vector<interaction_profile> interaction_profiles{
|
static std::vector<interaction_profile> interaction_profiles{
|
||||||
interaction_profile{
|
interaction_profile{
|
||||||
"/interaction_profiles/khr/simple_controller",
|
.profile_name = "/interaction_profiles/khr/simple_controller",
|
||||||
{},
|
.input_sources = {
|
||||||
{
|
|
||||||
"/user/hand/left/output/haptic",
|
"/user/hand/left/output/haptic",
|
||||||
"/user/hand/right/output/haptic",
|
"/user/hand/right/output/haptic",
|
||||||
|
|
||||||
@@ -90,11 +91,11 @@ static std::vector<interaction_profile> interaction_profiles{
|
|||||||
"/user/hand/right/input/menu/click",
|
"/user/hand/right/input/menu/click",
|
||||||
"/user/hand/right/input/select/click",
|
"/user/hand/right/input/select/click",
|
||||||
|
|
||||||
}},
|
},
|
||||||
|
},
|
||||||
interaction_profile{
|
interaction_profile{
|
||||||
"/interaction_profiles/oculus/touch_controller",
|
.profile_name = "/interaction_profiles/oculus/touch_controller",
|
||||||
{},
|
.input_sources = {
|
||||||
{
|
|
||||||
"/user/hand/left/output/haptic",
|
"/user/hand/left/output/haptic",
|
||||||
"/user/hand/right/output/haptic",
|
"/user/hand/right/output/haptic",
|
||||||
|
|
||||||
@@ -129,11 +130,13 @@ static std::vector<interaction_profile> interaction_profiles{
|
|||||||
"/user/hand/right/input/thumbstick/click",
|
"/user/hand/right/input/thumbstick/click",
|
||||||
"/user/hand/right/input/thumbstick/touch",
|
"/user/hand/right/input/thumbstick/touch",
|
||||||
"/user/hand/right/input/thumbrest/touch",
|
"/user/hand/right/input/thumbrest/touch",
|
||||||
}},
|
},
|
||||||
|
},
|
||||||
interaction_profile{
|
interaction_profile{
|
||||||
"/interaction_profiles/facebook/touch_controller_pro",
|
.profile_name = "/interaction_profiles/facebook/touch_controller_pro",
|
||||||
{"XR_FB_touch_controller_pro"},
|
.required_extensions = {"XR_FB_touch_controller_pro"},
|
||||||
{
|
.max_version = XR_MAKE_VERSION(1, 1, 0),
|
||||||
|
.input_sources = {
|
||||||
"/user/hand/left/output/haptic",
|
"/user/hand/left/output/haptic",
|
||||||
"/user/hand/left/output/haptic_trigger_fb",
|
"/user/hand/left/output/haptic_trigger_fb",
|
||||||
"/user/hand/left/output/haptic_thumb_fb",
|
"/user/hand/left/output/haptic_thumb_fb",
|
||||||
@@ -184,11 +187,12 @@ static std::vector<interaction_profile> interaction_profiles{
|
|||||||
"/user/hand/right/input/trigger/slide_fb",
|
"/user/hand/right/input/trigger/slide_fb",
|
||||||
"/user/hand/right/input/trigger/proximity_fb",
|
"/user/hand/right/input/trigger/proximity_fb",
|
||||||
"/user/hand/right/input/thumb_fb/proximity_fb",
|
"/user/hand/right/input/thumb_fb/proximity_fb",
|
||||||
}},
|
},
|
||||||
|
},
|
||||||
interaction_profile{
|
interaction_profile{
|
||||||
"/interaction_profiles/meta/touch_pro_controller",
|
.profile_name = "/interaction_profiles/meta/touch_pro_controller",
|
||||||
{"XR_VERSION_1_1"},
|
.min_version = XR_MAKE_VERSION(1, 1, 0),
|
||||||
{
|
.input_sources = {
|
||||||
"/user/hand/left/output/haptic",
|
"/user/hand/left/output/haptic",
|
||||||
"/user/hand/left/output/haptic_trigger",
|
"/user/hand/left/output/haptic_trigger",
|
||||||
"/user/hand/left/output/haptic_thumb",
|
"/user/hand/left/output/haptic_thumb",
|
||||||
@@ -239,12 +243,13 @@ static std::vector<interaction_profile> interaction_profiles{
|
|||||||
"/user/hand/right/input/thumbrest/touch",
|
"/user/hand/right/input/thumbrest/touch",
|
||||||
"/user/hand/right/input/thumbrest/force",
|
"/user/hand/right/input/thumbrest/force",
|
||||||
"/user/hand/right/input/stylus/force",
|
"/user/hand/right/input/stylus/force",
|
||||||
|
},
|
||||||
}},
|
},
|
||||||
interaction_profile{
|
interaction_profile{
|
||||||
"/interaction_profiles/meta/touch_controller_plus",
|
.profile_name = "/interaction_profiles/meta/touch_controller_plus",
|
||||||
{"XR_META_touch_controller_plus"},
|
.required_extensions = {"XR_META_touch_controller_plus"},
|
||||||
{
|
.max_version = XR_MAKE_VERSION(1, 1, 0),
|
||||||
|
.input_sources = {
|
||||||
"/user/hand/left/output/haptic",
|
"/user/hand/left/output/haptic",
|
||||||
"/user/hand/right/output/haptic",
|
"/user/hand/right/output/haptic",
|
||||||
|
|
||||||
@@ -288,11 +293,12 @@ static std::vector<interaction_profile> interaction_profiles{
|
|||||||
"/user/hand/right/input/trigger/slide_meta",
|
"/user/hand/right/input/trigger/slide_meta",
|
||||||
"/user/hand/right/input/trigger/force",
|
"/user/hand/right/input/trigger/force",
|
||||||
|
|
||||||
}},
|
},
|
||||||
|
},
|
||||||
interaction_profile{
|
interaction_profile{
|
||||||
"/interaction_profiles/meta/touch_plus_controller",
|
.profile_name = "/interaction_profiles/meta/touch_plus_controller",
|
||||||
{"XR_VERSION_1_1"},
|
.min_version = XR_MAKE_VERSION(1, 1, 0),
|
||||||
{
|
.input_sources = {
|
||||||
"/user/hand/left/output/haptic",
|
"/user/hand/left/output/haptic",
|
||||||
"/user/hand/right/output/haptic",
|
"/user/hand/right/output/haptic",
|
||||||
|
|
||||||
@@ -338,11 +344,12 @@ static std::vector<interaction_profile> interaction_profiles{
|
|||||||
"/user/hand/right/input/thumbstick/touch",
|
"/user/hand/right/input/thumbstick/touch",
|
||||||
"/user/hand/right/input/thumbrest/touch",
|
"/user/hand/right/input/thumbrest/touch",
|
||||||
|
|
||||||
}},
|
},
|
||||||
|
},
|
||||||
interaction_profile{
|
interaction_profile{
|
||||||
"/interaction_profiles/bytedance/pico_neo3_controller",
|
.profile_name = "/interaction_profiles/bytedance/pico_neo3_controller",
|
||||||
{"XR_BD_controller_interaction"},
|
.required_extensions = {"XR_BD_controller_interaction"},
|
||||||
{
|
.input_sources = {
|
||||||
"/user/hand/left/output/haptic",
|
"/user/hand/left/output/haptic",
|
||||||
"/user/hand/right/output/haptic",
|
"/user/hand/right/output/haptic",
|
||||||
|
|
||||||
@@ -380,11 +387,12 @@ static std::vector<interaction_profile> interaction_profiles{
|
|||||||
"/user/hand/right/input/thumbstick/click",
|
"/user/hand/right/input/thumbstick/click",
|
||||||
"/user/hand/right/input/thumbstick/touch",
|
"/user/hand/right/input/thumbstick/touch",
|
||||||
|
|
||||||
}},
|
},
|
||||||
|
},
|
||||||
interaction_profile{
|
interaction_profile{
|
||||||
"/interaction_profiles/bytedance/pico4_controller",
|
.profile_name = "/interaction_profiles/bytedance/pico4_controller",
|
||||||
{"XR_BD_controller_interaction"},
|
.required_extensions = {"XR_BD_controller_interaction"},
|
||||||
{
|
.input_sources = {
|
||||||
"/user/hand/left/output/haptic",
|
"/user/hand/left/output/haptic",
|
||||||
"/user/hand/right/output/haptic",
|
"/user/hand/right/output/haptic",
|
||||||
|
|
||||||
@@ -422,11 +430,12 @@ static std::vector<interaction_profile> interaction_profiles{
|
|||||||
"/user/hand/right/input/thumbstick/touch",
|
"/user/hand/right/input/thumbstick/touch",
|
||||||
"/user/hand/right/input/squeeze/click",
|
"/user/hand/right/input/squeeze/click",
|
||||||
"/user/hand/right/input/squeeze/value",
|
"/user/hand/right/input/squeeze/value",
|
||||||
}},
|
},
|
||||||
|
},
|
||||||
interaction_profile{
|
interaction_profile{
|
||||||
"/interaction_profiles/bytedance/pico4s_controller",
|
.profile_name = "/interaction_profiles/bytedance/pico4s_controller",
|
||||||
{"XR_BD_controller_interaction"},
|
.required_extensions = {"XR_BD_controller_interaction"},
|
||||||
{
|
.input_sources = {
|
||||||
"/user/hand/left/output/haptic",
|
"/user/hand/left/output/haptic",
|
||||||
"/user/hand/right/output/haptic",
|
"/user/hand/right/output/haptic",
|
||||||
|
|
||||||
@@ -464,11 +473,12 @@ static std::vector<interaction_profile> interaction_profiles{
|
|||||||
"/user/hand/right/input/thumbstick/touch",
|
"/user/hand/right/input/thumbstick/touch",
|
||||||
"/user/hand/right/input/squeeze/click",
|
"/user/hand/right/input/squeeze/click",
|
||||||
"/user/hand/right/input/squeeze/value",
|
"/user/hand/right/input/squeeze/value",
|
||||||
}},
|
},
|
||||||
|
},
|
||||||
interaction_profile{
|
interaction_profile{
|
||||||
"/interaction_profiles/htc/vive_focus3_controller",
|
.profile_name = "/interaction_profiles/htc/vive_focus3_controller",
|
||||||
{"XR_HTC_vive_focus3_controller_interaction"},
|
.required_extensions = {"XR_HTC_vive_focus3_controller_interaction"},
|
||||||
{
|
.input_sources = {
|
||||||
"/user/hand/left/output/haptic",
|
"/user/hand/left/output/haptic",
|
||||||
"/user/hand/right/output/haptic",
|
"/user/hand/right/output/haptic",
|
||||||
|
|
||||||
@@ -505,18 +515,19 @@ static std::vector<interaction_profile> interaction_profiles{
|
|||||||
"/user/hand/right/input/thumbstick/click",
|
"/user/hand/right/input/thumbstick/click",
|
||||||
"/user/hand/right/input/thumbstick/touch",
|
"/user/hand/right/input/thumbstick/touch",
|
||||||
"/user/hand/right/input/thumbrest/touch",
|
"/user/hand/right/input/thumbrest/touch",
|
||||||
}},
|
},
|
||||||
interaction_profile{
|
|
||||||
"/interaction_profiles/htc/vive_xr_tracker",
|
|
||||||
{"XR_HTC_vive_xr_tracker_interaction", "XR_HTC_path_enumeration"},
|
|
||||||
{},
|
|
||||||
},
|
},
|
||||||
interaction_profile{
|
interaction_profile{
|
||||||
"/interaction_profiles/ext/eye_gaze_interaction",
|
.profile_name = "/interaction_profiles/htc/vive_xr_tracker",
|
||||||
{"XR_EXT_eye_gaze_interaction"},
|
.required_extensions = {"XR_HTC_vive_xr_tracker_interaction", "XR_HTC_path_enumeration"},
|
||||||
{
|
},
|
||||||
|
interaction_profile{
|
||||||
|
.profile_name = "/interaction_profiles/ext/eye_gaze_interaction",
|
||||||
|
.required_extensions = {"XR_EXT_eye_gaze_interaction"},
|
||||||
|
.input_sources = {
|
||||||
"/user/eyes_ext/input/gaze_ext/pose",
|
"/user/eyes_ext/input/gaze_ext/pose",
|
||||||
}},
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static const std::pair<std::string_view, XrActionType> action_suffixes[] =
|
static const std::pair<std::string_view, XrActionType> action_suffixes[] =
|
||||||
@@ -910,12 +921,29 @@ void application::initialize_actions()
|
|||||||
|
|
||||||
std::unordered_map<std::string, std::vector<XrActionSuggestedBinding>> suggested_bindings;
|
std::unordered_map<std::string, std::vector<XrActionSuggestedBinding>> suggested_bindings;
|
||||||
|
|
||||||
|
XrVersion api_version = xr_instance.get_api_version();
|
||||||
// Build the list of all possible input sources, without duplicates,
|
// Build the list of all possible input sources, without duplicates,
|
||||||
// checking which profiles are supported by the runtime
|
// checking which profiles are supported by the runtime
|
||||||
std::vector<std::string> sources;
|
std::vector<std::string> sources;
|
||||||
for (auto & profile: interaction_profiles)
|
for (auto & profile: interaction_profiles)
|
||||||
{
|
{
|
||||||
profile.available = utils::contains_all(xr_extensions, profile.required_extensions);
|
profile.available = utils::contains_all(xr_extensions, profile.required_extensions) and profile.min_version <= api_version and profile.max_version > api_version;
|
||||||
|
|
||||||
|
if (profile.profile_name.ends_with("khr/simple_controller"))
|
||||||
|
{
|
||||||
|
switch (guess_model())
|
||||||
|
{
|
||||||
|
// Quest hand tracking creates a fake khr/simple_controller when hand tracking
|
||||||
|
// is enabled, this messes with native hand tracking
|
||||||
|
case model::meta_quest_3:
|
||||||
|
case model::meta_quest_pro:
|
||||||
|
case model::meta_quest_3s:
|
||||||
|
case model::oculus_quest_2:
|
||||||
|
profile.available = false;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!profile.available)
|
if (!profile.available)
|
||||||
continue;
|
continue;
|
||||||
@@ -1080,13 +1108,7 @@ void application::initialize()
|
|||||||
opt_extensions.push_back(XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME);
|
opt_extensions.push_back(XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME);
|
||||||
|
|
||||||
for (const auto & i: interaction_profiles)
|
for (const auto & i: interaction_profiles)
|
||||||
{
|
opt_extensions.insert(opt_extensions.end(), i.required_extensions.begin(), i.required_extensions.end());
|
||||||
for (const auto & j: i.required_extensions)
|
|
||||||
{
|
|
||||||
if (not j.starts_with("XR_VERSION"))
|
|
||||||
opt_extensions.push_back(j);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto & i: xr::instance::extensions())
|
for (const auto & i: xr::instance::extensions())
|
||||||
{
|
{
|
||||||
@@ -1107,7 +1129,10 @@ void application::initialize()
|
|||||||
xr_instance = xr::instance(app_info.name, extensions);
|
xr_instance = xr::instance(app_info.name, extensions);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
spdlog::info("Created OpenXR instance, runtime {}, version {}", xr_instance.get_runtime_name(), xr_instance.get_runtime_version());
|
spdlog::info("Created OpenXR instance, runtime {}, version {}, API version {}",
|
||||||
|
xr_instance.get_runtime_name(),
|
||||||
|
xr_instance.get_runtime_version(),
|
||||||
|
xr::to_string(xr_instance.get_api_version()));
|
||||||
|
|
||||||
xr_system_id = xr::system(xr_instance, app_info.formfactor);
|
xr_system_id = xr::system(xr_instance, app_info.formfactor);
|
||||||
spdlog::info("Created OpenXR system for form factor {}", xr::to_string(app_info.formfactor));
|
spdlog::info("Created OpenXR system for form factor {}", xr::to_string(app_info.formfactor));
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "utils/overloaded.h"
|
#include "utils/overloaded.h"
|
||||||
#include "wivrn_packets.h"
|
#include "wivrn_packets.h"
|
||||||
#include "xr/fb_body_tracker.h"
|
#include "xr/fb_body_tracker.h"
|
||||||
|
#include <magic_enum.hpp>
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
@@ -35,46 +36,28 @@ using tid = to_headset::tracking_control::id;
|
|||||||
static const XrDuration min_tracking_period = 2'000'000;
|
static const XrDuration min_tracking_period = 2'000'000;
|
||||||
static const XrDuration max_tracking_period = 5'000'000;
|
static const XrDuration max_tracking_period = 5'000'000;
|
||||||
|
|
||||||
static from_headset::tracking::pose locate_space(device_id device, XrSpace space, XrSpace reference, XrTime time)
|
static uint8_t cast_flags(XrSpaceLocationFlags location, XrSpaceVelocityFlags velocity)
|
||||||
{
|
{
|
||||||
XrSpaceVelocity velocity{
|
uint8_t flags = 0;
|
||||||
.type = XR_TYPE_SPACE_VELOCITY,
|
if (location & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT)
|
||||||
};
|
flags |= from_headset::tracking::orientation_valid;
|
||||||
|
|
||||||
XrSpaceLocation location{
|
if (location & XR_SPACE_LOCATION_POSITION_VALID_BIT)
|
||||||
.type = XR_TYPE_SPACE_LOCATION,
|
flags |= from_headset::tracking::position_valid;
|
||||||
.next = &velocity,
|
|
||||||
};
|
|
||||||
|
|
||||||
xrLocateSpace(space, reference, time, &location);
|
if (velocity & XR_SPACE_VELOCITY_LINEAR_VALID_BIT)
|
||||||
|
flags |= from_headset::tracking::linear_velocity_valid;
|
||||||
|
|
||||||
from_headset::tracking::pose res{
|
if (velocity & XR_SPACE_VELOCITY_ANGULAR_VALID_BIT)
|
||||||
.pose = location.pose,
|
flags |= from_headset::tracking::angular_velocity_valid;
|
||||||
.linear_velocity = velocity.linearVelocity,
|
|
||||||
.angular_velocity = velocity.angularVelocity,
|
|
||||||
.device = device,
|
|
||||||
.flags = 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (location.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT)
|
if (location & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT)
|
||||||
res.flags |= from_headset::tracking::orientation_valid;
|
flags |= from_headset::tracking::orientation_tracked;
|
||||||
|
|
||||||
if (location.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT)
|
if (location & XR_SPACE_LOCATION_POSITION_TRACKED_BIT)
|
||||||
res.flags |= from_headset::tracking::position_valid;
|
flags |= from_headset::tracking::position_tracked;
|
||||||
|
|
||||||
if (velocity.velocityFlags & XR_SPACE_VELOCITY_LINEAR_VALID_BIT)
|
return flags;
|
||||||
res.flags |= from_headset::tracking::linear_velocity_valid;
|
|
||||||
|
|
||||||
if (velocity.velocityFlags & XR_SPACE_VELOCITY_ANGULAR_VALID_BIT)
|
|
||||||
res.flags |= from_headset::tracking::angular_velocity_valid;
|
|
||||||
|
|
||||||
if (location.locationFlags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT)
|
|
||||||
res.flags |= from_headset::tracking::orientation_tracked;
|
|
||||||
|
|
||||||
if (location.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT)
|
|
||||||
res.flags |= from_headset::tracking::position_tracked;
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@@ -92,6 +75,122 @@ public:
|
|||||||
return instance.now() - start;
|
return instance.now() - start;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
from_headset::tracking::pose locate_space(device_id device, XrSpace space, XrSpace reference, XrTime time)
|
||||||
|
{
|
||||||
|
XrSpaceVelocity velocity{
|
||||||
|
.type = XR_TYPE_SPACE_VELOCITY,
|
||||||
|
};
|
||||||
|
|
||||||
|
XrSpaceLocation location{
|
||||||
|
.type = XR_TYPE_SPACE_LOCATION,
|
||||||
|
.next = &velocity,
|
||||||
|
};
|
||||||
|
|
||||||
|
auto res = xrLocateSpace(space, reference, time, &location);
|
||||||
|
|
||||||
|
if (XR_SUCCEEDED(res))
|
||||||
|
return {
|
||||||
|
.pose = location.pose,
|
||||||
|
.linear_velocity = velocity.linearVelocity,
|
||||||
|
.angular_velocity = velocity.angularVelocity,
|
||||||
|
.device = device,
|
||||||
|
.flags = cast_flags(location.locationFlags, velocity.velocityFlags),
|
||||||
|
};
|
||||||
|
spdlog::warn("xrLocateSpace failed for {}: {}", magic_enum::enum_name(device), xr::to_string(res));
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
class locate_spaces_functor
|
||||||
|
{
|
||||||
|
std::vector<XrSpaceLocationData> locations;
|
||||||
|
std::vector<XrSpaceVelocityData> velocities;
|
||||||
|
std::vector<wivrn::device_id> devices;
|
||||||
|
std::vector<XrSpace> spaces;
|
||||||
|
XrSpace reference;
|
||||||
|
PFN_xrLocateSpaces locate_spaces = nullptr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
locate_spaces_functor(xr::instance & instance, XrSpace reference) :
|
||||||
|
reference(reference)
|
||||||
|
{
|
||||||
|
if (instance.get_api_version() >= XR_MAKE_VERSION(1, 1, 0))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
locate_spaces = instance.get_proc<PFN_xrLocateSpaces>("xrLocateSpaces");
|
||||||
|
}
|
||||||
|
catch (std::exception & e)
|
||||||
|
{
|
||||||
|
spdlog::warn("Failed to load xrLocateSpaces function, fallback to xrLocateSpace");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void add_space(wivrn::device_id device, XrSpace space, XrTime t, std::vector<from_headset::tracking::pose> & out)
|
||||||
|
{
|
||||||
|
if (not locate_spaces)
|
||||||
|
{
|
||||||
|
// store, will be located later
|
||||||
|
devices.push_back(device);
|
||||||
|
spaces.push_back(space);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
out.push_back(locate_space(device, space, reference, t));
|
||||||
|
}
|
||||||
|
|
||||||
|
void resolve(
|
||||||
|
xr::session & session,
|
||||||
|
XrTime t,
|
||||||
|
std::vector<from_headset::tracking::pose> & out)
|
||||||
|
{
|
||||||
|
assert(devices.size() == spaces.size());
|
||||||
|
if (locate_spaces)
|
||||||
|
{
|
||||||
|
locations.resize(spaces.size());
|
||||||
|
velocities.resize(spaces.size());
|
||||||
|
XrSpaceVelocities spc_velocities{
|
||||||
|
.type = XR_TYPE_SPACE_VELOCITIES,
|
||||||
|
.velocityCount = uint32_t(velocities.size()),
|
||||||
|
.velocities = velocities.data(),
|
||||||
|
};
|
||||||
|
XrSpaceLocations spc_locations{
|
||||||
|
.type = XR_TYPE_SPACE_LOCATIONS,
|
||||||
|
.locationCount = uint32_t(locations.size()),
|
||||||
|
.locations = locations.data(),
|
||||||
|
};
|
||||||
|
XrSpacesLocateInfo info{
|
||||||
|
.type = XR_TYPE_SPACES_LOCATE_INFO,
|
||||||
|
.baseSpace = reference,
|
||||||
|
.time = t,
|
||||||
|
.spaceCount = uint32_t(spaces.size()),
|
||||||
|
.spaces = spaces.data(),
|
||||||
|
};
|
||||||
|
auto res = locate_spaces(session, &info, &spc_locations);
|
||||||
|
if (XR_SUCCEEDED(res))
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < devices.size(); ++i)
|
||||||
|
{
|
||||||
|
const auto & location = locations[i];
|
||||||
|
const auto & velocity = velocities[i];
|
||||||
|
|
||||||
|
out.push_back({
|
||||||
|
.pose = location.pose,
|
||||||
|
.linear_velocity = velocity.linearVelocity,
|
||||||
|
.angular_velocity = velocity.angularVelocity,
|
||||||
|
.device = devices[i],
|
||||||
|
.flags = cast_flags(location.locationFlags, velocity.velocityFlags),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
spdlog::warn("xrLocateSpaces failed: {}", xr::to_string(res));
|
||||||
|
devices.clear();
|
||||||
|
spaces.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
static std::optional<std::array<from_headset::hand_tracking::pose, XR_HAND_JOINT_COUNT_EXT>> locate_hands(xr::hand_tracker & hand, XrSpace space, XrTime time)
|
static std::optional<std::array<from_headset::hand_tracking::pose, XR_HAND_JOINT_COUNT_EXT>> locate_hands(xr::hand_tracker & hand, XrSpace space, XrTime time)
|
||||||
@@ -246,20 +345,6 @@ void scenes::stream::tracking()
|
|||||||
std::vector<serialization_packet> packets;
|
std::vector<serialization_packet> packets;
|
||||||
|
|
||||||
const bool hand_tracking = config.check_feature(feature::hand_tracking);
|
const bool hand_tracking = config.check_feature(feature::hand_tracking);
|
||||||
// Quest hand tracking creates a fake khr/simple_controller when hand tracking
|
|
||||||
// is enabled, let's not send it when hand tracking data is invalid
|
|
||||||
bool block_khr_simple_controller = false;
|
|
||||||
switch (guess_model())
|
|
||||||
{
|
|
||||||
case model::meta_quest_3:
|
|
||||||
case model::meta_quest_pro:
|
|
||||||
case model::meta_quest_3s:
|
|
||||||
case model::oculus_quest_2:
|
|
||||||
block_khr_simple_controller = hand_tracking;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
const bool face_tracking = config.check_feature(feature::face_tracking);
|
const bool face_tracking = config.check_feature(feature::face_tracking);
|
||||||
auto & face_tracker = application::get_face_tracker();
|
auto & face_tracker = application::get_face_tracker();
|
||||||
@@ -286,6 +371,8 @@ void scenes::stream::tracking()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
locate_spaces_functor locate_spaces{instance, world_space};
|
||||||
|
|
||||||
on_interaction_profile_changed({});
|
on_interaction_profile_changed({});
|
||||||
|
|
||||||
while (not exiting)
|
while (not exiting)
|
||||||
@@ -345,63 +432,31 @@ void scenes::stream::tracking()
|
|||||||
if (control.enabled[size_t(tid::left_hand)])
|
if (control.enabled[size_t(tid::left_hand)])
|
||||||
{
|
{
|
||||||
auto joints = locate_hands(application::get_left_hand(), world_space, t0 + Δt);
|
auto joints = locate_hands(application::get_left_hand(), world_space, t0 + Δt);
|
||||||
should_skip_simple_controllers[0] = !joints.has_value();
|
|
||||||
hands.emplace_back(
|
hands.emplace_back(
|
||||||
t0,
|
t0,
|
||||||
t0 + Δt,
|
t0 + Δt,
|
||||||
from_headset::hand_tracking::left,
|
from_headset::hand_tracking::left,
|
||||||
joints);
|
joints);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
should_skip_simple_controllers[0] = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (control.enabled[size_t(tid::right_hand)])
|
if (control.enabled[size_t(tid::right_hand)])
|
||||||
{
|
{
|
||||||
auto joints = locate_hands(application::get_right_hand(), world_space, t0 + Δt);
|
auto joints = locate_hands(application::get_right_hand(), world_space, t0 + Δt);
|
||||||
should_skip_simple_controllers[1] = !joints.has_value();
|
|
||||||
hands.emplace_back(
|
hands.emplace_back(
|
||||||
t0,
|
t0,
|
||||||
t0 + Δt,
|
t0 + Δt,
|
||||||
from_headset::hand_tracking::right,
|
from_headset::hand_tracking::right,
|
||||||
joints);
|
joints);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
should_skip_simple_controllers[1] = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
packet.device_poses.clear();
|
packet.device_poses.clear();
|
||||||
for (auto [device, space]: spaces)
|
for (auto [device, space]: spaces)
|
||||||
{
|
{
|
||||||
if (enabled(control, device))
|
if (enabled(control, device))
|
||||||
{
|
locate_spaces.add_space(device, space, t0 + Δt, packet.device_poses);
|
||||||
switch (device)
|
|
||||||
{
|
|
||||||
case device_id::LEFT_AIM:
|
|
||||||
case device_id::LEFT_GRIP:
|
|
||||||
case device_id::LEFT_PALM:
|
|
||||||
case device_id::RIGHT_AIM:
|
|
||||||
case device_id::RIGHT_GRIP:
|
|
||||||
case device_id::RIGHT_PALM: {
|
|
||||||
const bool right = device > device_id::LEFT_PALM;
|
|
||||||
if (block_khr_simple_controller and interaction_profiles[right].load() == interaction_profile::khr_simple_controller and should_skip_simple_controllers[right])
|
|
||||||
{
|
|
||||||
packet.device_poses.emplace_back(from_headset::tracking::pose{
|
|
||||||
.device = device,
|
|
||||||
});
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
[[fallthrough]];
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
packet.device_poses.emplace_back(locate_space(device, space, world_space, t0 + Δt));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
locate_spaces.resolve(session, t0 + Δt, packet.device_poses);
|
||||||
|
|
||||||
if (body_tracking)
|
if (body_tracking)
|
||||||
std::visit(utils::overloaded{
|
std::visit(utils::overloaded{
|
||||||
|
|||||||
+21
-3
@@ -40,6 +40,26 @@ static XrBool32 debug_callback(
|
|||||||
return XR_FALSE;
|
return XR_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::pair<XrVersion, XrInstance> create_instance(XrInstanceCreateInfo & info)
|
||||||
|
{
|
||||||
|
XrResult res;
|
||||||
|
for (XrVersion version: {
|
||||||
|
XR_API_VERSION_1_1,
|
||||||
|
XR_API_VERSION_1_0,
|
||||||
|
})
|
||||||
|
{
|
||||||
|
info.applicationInfo.apiVersion = version;
|
||||||
|
XrInstance inst;
|
||||||
|
res = xrCreateInstance(&info, &inst);
|
||||||
|
if (XR_SUCCEEDED(res))
|
||||||
|
return {version, inst};
|
||||||
|
spdlog::info("Failed to create OpenXR instance version {}: {}",
|
||||||
|
xr::to_string(version),
|
||||||
|
xr::to_string(res));
|
||||||
|
}
|
||||||
|
throw std::system_error(res, xr::error_category(), "Failed to create OpenXR instance");
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(XR_USE_PLATFORM_ANDROID)
|
#if defined(XR_USE_PLATFORM_ANDROID)
|
||||||
xr::instance::instance(std::string_view application_name, void * applicationVM, void * applicationActivity, std::vector<const char *> extensions)
|
xr::instance::instance(std::string_view application_name, void * applicationVM, void * applicationActivity, std::vector<const char *> extensions)
|
||||||
#else
|
#else
|
||||||
@@ -122,7 +142,6 @@ xr::instance::instance(std::string_view application_name, std::vector<const char
|
|||||||
|
|
||||||
XrInstanceCreateInfo create_info{
|
XrInstanceCreateInfo create_info{
|
||||||
.type = XR_TYPE_INSTANCE_CREATE_INFO,
|
.type = XR_TYPE_INSTANCE_CREATE_INFO,
|
||||||
.applicationInfo = {.apiVersion = XR_MAKE_VERSION(1, 0, 0)},
|
|
||||||
.enabledApiLayerCount = (uint32_t)layers.size(),
|
.enabledApiLayerCount = (uint32_t)layers.size(),
|
||||||
.enabledApiLayerNames = layers.data(),
|
.enabledApiLayerNames = layers.data(),
|
||||||
.enabledExtensionCount = (uint32_t)extensions.size(),
|
.enabledExtensionCount = (uint32_t)extensions.size(),
|
||||||
@@ -139,8 +158,7 @@ xr::instance::instance(std::string_view application_name, std::vector<const char
|
|||||||
create_info.next = &instanceCreateInfoAndroid;
|
create_info.next = &instanceCreateInfoAndroid;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CHECK_XR(xrCreateInstance(&create_info, &id));
|
std::tie(api_version, id) = create_instance(create_info);
|
||||||
assert(id != XR_NULL_HANDLE);
|
|
||||||
|
|
||||||
if (debug_utils_found)
|
if (debug_utils_found)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ class instance : public utils::handle<XrInstance, xrDestroyInstance>
|
|||||||
std::string runtime_version;
|
std::string runtime_version;
|
||||||
std::string runtime_name;
|
std::string runtime_name;
|
||||||
std::unordered_map<std::string, uint32_t> loaded_extensions;
|
std::unordered_map<std::string, uint32_t> loaded_extensions;
|
||||||
|
XrVersion api_version;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
#if defined(XR_USE_PLATFORM_ANDROID)
|
#if defined(XR_USE_PLATFORM_ANDROID)
|
||||||
@@ -70,6 +71,11 @@ public:
|
|||||||
return runtime_name;
|
return runtime_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XrVersion get_api_version() const
|
||||||
|
{
|
||||||
|
return api_version;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
F get_proc(const char * name)
|
F get_proc(const char * name)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user