Quest and Pico body tracking
* Update OpenXR SDK to 1.1.48
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "fb_body_tracker.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "xr/meta_body_tracking_fidelity.h"
|
||||
#include "xr/xr.h"
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
xr::fb_body_tracker::fb_body_tracker(instance & inst, session & s) :
|
||||
s(s)
|
||||
{
|
||||
xrCreateBodyTrackerFB = inst.get_proc<PFN_xrCreateBodyTrackerFB>("xrCreateBodyTrackerFB");
|
||||
xrRequestBodyTrackingFidelityMETA = inst.get_proc<PFN_xrRequestBodyTrackingFidelityMETA>("xrRequestBodyTrackingFidelityMETA");
|
||||
xrLocateBodyJointsFB = inst.get_proc<PFN_xrLocateBodyJointsFB>("xrLocateBodyJointsFB");
|
||||
xrDestroyBodyTrackerFB = inst.get_proc<PFN_xrDestroyBodyTrackerFB>("xrDestroyBodyTrackerFB");
|
||||
}
|
||||
xr::fb_body_tracker::~fb_body_tracker()
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
void xr::fb_body_tracker::start(bool full_body)
|
||||
{
|
||||
assert(xrCreateBodyTrackerFB);
|
||||
this->full_body = full_body;
|
||||
|
||||
XrBodyTrackerCreateInfoFB create_info{
|
||||
.type = XR_TYPE_BODY_TRACKER_CREATE_INFO_FB,
|
||||
.next = nullptr,
|
||||
};
|
||||
create_info.bodyJointSet = full_body
|
||||
? XR_BODY_JOINT_SET_FULL_BODY_META
|
||||
: XR_BODY_JOINT_SET_DEFAULT_FB;
|
||||
|
||||
CHECK_XR(xrCreateBodyTrackerFB(s, &create_info, &handle));
|
||||
|
||||
// Enable IOBT.
|
||||
CHECK_XR(xrRequestBodyTrackingFidelityMETA(handle, XR_BODY_TRACKING_FIDELITY_HIGH_META));
|
||||
}
|
||||
void xr::fb_body_tracker::stop()
|
||||
{
|
||||
assert(xrDestroyBodyTrackerFB);
|
||||
full_body = false;
|
||||
if (handle)
|
||||
CHECK_XR(xrDestroyBodyTrackerFB(std::exchange(handle, nullptr)));
|
||||
}
|
||||
|
||||
void xr::fb_body_tracker::locate_spaces(XrTime time, std::vector<wivrn::from_headset::tracking::pose> & out_poses, XrSpace reference)
|
||||
{
|
||||
auto fill_poses = [&]() {
|
||||
for (auto joint: joint_whitelist)
|
||||
{
|
||||
if (!full_body && joint >= XR_FULL_BODY_JOINT_LEFT_UPPER_LEG_META)
|
||||
return;
|
||||
|
||||
wivrn::from_headset::tracking::pose pose{
|
||||
.pose = {},
|
||||
.device = wivrn::device_id::GENERIC_TRACKER,
|
||||
.flags = 0,
|
||||
};
|
||||
out_poses.push_back(std::move(pose));
|
||||
}
|
||||
};
|
||||
if (!handle)
|
||||
{
|
||||
fill_poses();
|
||||
return;
|
||||
}
|
||||
|
||||
assert(xrLocateBodyJointsFB);
|
||||
|
||||
XrBodyJointsLocateInfoFB locate_info{
|
||||
.type = XR_TYPE_BODY_JOINTS_LOCATE_INFO_FB,
|
||||
.next = nullptr,
|
||||
.baseSpace = reference,
|
||||
.time = time,
|
||||
};
|
||||
|
||||
std::array<XrBodyJointLocationFB, XR_FULL_BODY_JOINT_COUNT_META> joints{};
|
||||
XrBodyJointLocationsFB joint_locations{
|
||||
.type = XR_TYPE_BODY_JOINT_LOCATIONS_FB,
|
||||
.next = nullptr,
|
||||
.jointCount = (uint32_t)(full_body ? XR_FULL_BODY_JOINT_COUNT_META : (XrFullBodyJointMETA)XR_BODY_JOINT_COUNT_FB),
|
||||
.jointLocations = joints.data(),
|
||||
};
|
||||
|
||||
if (auto res = xrLocateBodyJointsFB(handle, &locate_info, &joint_locations); !XR_SUCCEEDED(res))
|
||||
{
|
||||
spdlog::warn("xrLocateBodyJointsFB returned {}", xr::to_string(res));
|
||||
|
||||
fill_poses();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!joint_locations.isActive)
|
||||
{
|
||||
spdlog::warn("Body tracker is not active.");
|
||||
fill_poses();
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto joint: joint_whitelist)
|
||||
{
|
||||
if (!full_body && joint >= XR_FULL_BODY_JOINT_LEFT_UPPER_LEG_META)
|
||||
return;
|
||||
|
||||
auto joint_pose = joints[joint];
|
||||
wivrn::from_headset::tracking::pose pose{
|
||||
.pose = joint_pose.pose,
|
||||
.device = wivrn::device_id::GENERIC_TRACKER,
|
||||
.flags = 0,
|
||||
};
|
||||
|
||||
if (joint_pose.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT)
|
||||
pose.flags |= wivrn::from_headset::tracking::position_valid;
|
||||
if (joint_pose.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT)
|
||||
pose.flags |= wivrn::from_headset::tracking::orientation_valid;
|
||||
if (joint_pose.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT)
|
||||
pose.flags |= wivrn::from_headset::tracking::position_tracked;
|
||||
if (joint_pose.locationFlags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT)
|
||||
pose.flags |= wivrn::from_headset::tracking::orientation_tracked;
|
||||
|
||||
out_poses.push_back(std::move(pose));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "wivrn_packets.h"
|
||||
|
||||
#include "xr/meta_body_tracking_fidelity.h"
|
||||
#include <vector>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
namespace xr
|
||||
{
|
||||
class instance;
|
||||
class session;
|
||||
|
||||
class fb_body_tracker
|
||||
{
|
||||
XrSession s;
|
||||
XrBodyTrackerFB handle{};
|
||||
|
||||
PFN_xrCreateBodyTrackerFB xrCreateBodyTrackerFB{};
|
||||
PFN_xrRequestBodyTrackingFidelityMETA xrRequestBodyTrackingFidelityMETA{};
|
||||
PFN_xrLocateBodyJointsFB xrLocateBodyJointsFB{};
|
||||
PFN_xrDestroyBodyTrackerFB xrDestroyBodyTrackerFB{};
|
||||
|
||||
bool full_body{};
|
||||
|
||||
public:
|
||||
static constexpr std::array joint_whitelist{
|
||||
XR_FULL_BODY_JOINT_HIPS_META,
|
||||
XR_FULL_BODY_JOINT_CHEST_META,
|
||||
XR_FULL_BODY_JOINT_LEFT_ARM_UPPER_META,
|
||||
XR_FULL_BODY_JOINT_RIGHT_ARM_UPPER_META,
|
||||
XR_FULL_BODY_JOINT_LEFT_ARM_LOWER_META,
|
||||
XR_FULL_BODY_JOINT_RIGHT_ARM_LOWER_META,
|
||||
|
||||
XR_FULL_BODY_JOINT_LEFT_LOWER_LEG_META,
|
||||
XR_FULL_BODY_JOINT_RIGHT_LOWER_LEG_META,
|
||||
|
||||
XR_FULL_BODY_JOINT_LEFT_FOOT_TRANSVERSE_META,
|
||||
XR_FULL_BODY_JOINT_RIGHT_FOOT_TRANSVERSE_META,
|
||||
};
|
||||
|
||||
fb_body_tracker() = default;
|
||||
fb_body_tracker(instance & inst, session & s);
|
||||
~fb_body_tracker();
|
||||
|
||||
void start(bool lower_body);
|
||||
void stop();
|
||||
|
||||
void locate_spaces(XrTime time, std::vector<wivrn::from_headset::tracking::pose> & out_poses, XrSpace reference);
|
||||
};
|
||||
} // namespace xr
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "pico_body_tracker.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "xr/xr.h"
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
static PFN_xrDestroyBodyTrackerBD xrDestroyBodyTrackerBD{};
|
||||
|
||||
XrResult xr::destroy_pico_body_tracker(XrBodyTrackerBD id)
|
||||
{
|
||||
return xrDestroyBodyTrackerBD(id);
|
||||
}
|
||||
|
||||
xr::pico_body_tracker::pico_body_tracker(instance & inst, XrBodyTrackerBD h)
|
||||
{
|
||||
id = h;
|
||||
xrLocateBodyJointsBD = inst.get_proc<PFN_xrLocateBodyJointsBD>("xrLocateBodyJointsBD");
|
||||
}
|
||||
|
||||
void xr::pico_body_tracker::locate_spaces(XrTime time, std::vector<wivrn::from_headset::tracking::pose> & out_poses, XrSpace reference)
|
||||
{
|
||||
auto fill_poses = [&]() {
|
||||
for (auto _: joint_whitelist)
|
||||
{
|
||||
wivrn::from_headset::tracking::pose pose{
|
||||
.pose = {},
|
||||
.device = wivrn::device_id::GENERIC_TRACKER,
|
||||
.flags = 0,
|
||||
};
|
||||
out_poses.push_back(std::move(pose));
|
||||
}
|
||||
};
|
||||
|
||||
if (!xrLocateBodyJointsBD)
|
||||
{
|
||||
fill_poses();
|
||||
return;
|
||||
}
|
||||
|
||||
XrBodyJointsLocateInfoBD locate_info{
|
||||
.type = XR_TYPE_BODY_JOINTS_LOCATE_INFO_BD,
|
||||
.next = nullptr,
|
||||
.baseSpace = reference,
|
||||
.time = time,
|
||||
};
|
||||
|
||||
std::array<XrBodyJointLocationBD, XR_BODY_JOINT_COUNT_BD> joints{};
|
||||
XrBodyJointLocationsBD joint_locations{
|
||||
.type = XR_TYPE_BODY_JOINT_LOCATIONS_BD,
|
||||
.next = nullptr,
|
||||
.jointLocationCount = joints.size(),
|
||||
.jointLocations = joints.data(),
|
||||
};
|
||||
|
||||
if (auto res = xrLocateBodyJointsBD(id, &locate_info, &joint_locations); !XR_SUCCEEDED(res))
|
||||
{
|
||||
spdlog::warn("Unable to get body joints: xrLocateBodyJointsBD returned {}", xr::to_string(res));
|
||||
fill_poses();
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto & joint: joint_whitelist)
|
||||
{
|
||||
auto & joint_location = joints[joint];
|
||||
wivrn::from_headset::tracking::pose pose{
|
||||
.pose = joint_location.pose,
|
||||
.device = wivrn::device_id::GENERIC_TRACKER,
|
||||
.flags = 0,
|
||||
};
|
||||
|
||||
if (joint_location.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT)
|
||||
pose.flags |= wivrn::from_headset::tracking::position_valid;
|
||||
if (joint_location.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT)
|
||||
pose.flags |= wivrn::from_headset::tracking::orientation_valid;
|
||||
if (joint_location.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT)
|
||||
pose.flags |= wivrn::from_headset::tracking::position_tracked;
|
||||
if (joint_location.locationFlags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT)
|
||||
pose.flags |= wivrn::from_headset::tracking::orientation_tracked;
|
||||
|
||||
out_poses.push_back(std::move(pose));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils/handle.h"
|
||||
#include "wivrn_packets.h"
|
||||
|
||||
#include <vector>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
namespace xr
|
||||
{
|
||||
class instance;
|
||||
class session;
|
||||
|
||||
XrResult destroy_pico_body_tracker(XrBodyTrackerBD);
|
||||
|
||||
class pico_body_tracker : public utils::handle<XrBodyTrackerBD, destroy_pico_body_tracker>
|
||||
{
|
||||
PFN_xrLocateBodyJointsBD xrLocateBodyJointsBD{};
|
||||
|
||||
public:
|
||||
static constexpr std::array joint_whitelist{
|
||||
XR_BODY_JOINT_PELVIS_BD,
|
||||
XR_BODY_JOINT_LEFT_SHOULDER_BD,
|
||||
XR_BODY_JOINT_RIGHT_SHOULDER_BD,
|
||||
XR_BODY_JOINT_LEFT_ELBOW_BD,
|
||||
XR_BODY_JOINT_RIGHT_ELBOW_BD,
|
||||
|
||||
XR_BODY_JOINT_LEFT_KNEE_BD,
|
||||
XR_BODY_JOINT_RIGHT_KNEE_BD,
|
||||
XR_BODY_JOINT_LEFT_FOOT_BD,
|
||||
XR_BODY_JOINT_RIGHT_FOOT_BD,
|
||||
};
|
||||
|
||||
pico_body_tracker() = default;
|
||||
pico_body_tracker(instance & inst, XrBodyTrackerBD h);
|
||||
|
||||
void locate_spaces(XrTime time, std::vector<wivrn::from_headset::tracking::pose> & out_poses, XrSpace reference);
|
||||
};
|
||||
} // namespace xr
|
||||
@@ -23,6 +23,8 @@
|
||||
#include "details/enumerate.h"
|
||||
#include "openxr/openxr.h"
|
||||
#include "utils/contains.h"
|
||||
#include "xr/fb_body_tracker.h"
|
||||
#include "xr/pico_body_tracker.h"
|
||||
#include "xr/instance.h"
|
||||
#include "xr/system.h"
|
||||
#include <ranges>
|
||||
@@ -142,6 +144,28 @@ xr::pico_face_tracker xr::session::create_pico_face_tracker()
|
||||
return {*inst, *this};
|
||||
}
|
||||
|
||||
xr::fb_body_tracker xr::session::create_fb_body_tracker()
|
||||
{
|
||||
return {*inst, *this};
|
||||
}
|
||||
|
||||
xr::pico_body_tracker xr::session::create_pico_body_tracker()
|
||||
{
|
||||
XrBodyTrackerCreateInfoBD create_info{
|
||||
.type = XR_TYPE_BODY_TRACKER_CREATE_INFO_BD,
|
||||
.next = nullptr,
|
||||
.jointSet = XR_BODY_JOINT_SET_FULL_BODY_JOINTS_BD,
|
||||
};
|
||||
|
||||
XrBodyTrackerBD bt;
|
||||
|
||||
auto xrCreateBodyTrackerBD = inst->get_proc<PFN_xrCreateBodyTrackerBD>("xrCreateBodyTrackerBD");
|
||||
assert(xrCreateBodyTrackerBD);
|
||||
|
||||
CHECK_XR(xrCreateBodyTrackerBD(id, &create_info, &bt));
|
||||
return {*inst, bt};
|
||||
}
|
||||
|
||||
std::vector<vk::Format> xr::session::get_swapchain_formats() const
|
||||
{
|
||||
std::vector<vk::Format> formats;
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
#include "fb_face_tracker2.h"
|
||||
#include "hand_tracker.h"
|
||||
#include "htc_face_tracker.h"
|
||||
#include "fb_body_tracker.h"
|
||||
#include "pico_body_tracker.h"
|
||||
#include "passthrough.h"
|
||||
#include "pico_face_tracker.h"
|
||||
#include "space.h"
|
||||
@@ -54,6 +56,8 @@ public:
|
||||
fb_face_tracker2 create_fb_face_tracker2();
|
||||
htc_face_tracker create_htc_face_tracker(XrFacialTrackingTypeHTC);
|
||||
pico_face_tracker create_pico_face_tracker();
|
||||
fb_body_tracker create_fb_body_tracker();
|
||||
pico_body_tracker create_pico_body_tracker();
|
||||
|
||||
std::vector<vk::Format> get_swapchain_formats() const;
|
||||
|
||||
|
||||
@@ -141,6 +141,42 @@ XrSystemFacialTrackingPropertiesHTC xr::system::htc_face_tracking_properties() c
|
||||
return face_tracking_prop;
|
||||
}
|
||||
|
||||
XrSystemBodyTrackingPropertiesFB xr::system::fb_body_tracking_properties() const
|
||||
{
|
||||
if (!id)
|
||||
throw std::invalid_argument("this");
|
||||
|
||||
XrSystemBodyTrackingPropertiesFB body_tracking_prop{
|
||||
.type = XR_TYPE_SYSTEM_BODY_TRACKING_PROPERTIES_FB,
|
||||
};
|
||||
|
||||
XrSystemProperties prop{
|
||||
.type = XR_TYPE_SYSTEM_PROPERTIES,
|
||||
.next = &body_tracking_prop,
|
||||
};
|
||||
CHECK_XR(xrGetSystemProperties(*inst, id, &prop));
|
||||
|
||||
return body_tracking_prop;
|
||||
}
|
||||
|
||||
XrSystemBodyTrackingPropertiesBD xr::system::bd_body_tracking_properties() const
|
||||
{
|
||||
if (!id)
|
||||
throw std::invalid_argument("this");
|
||||
|
||||
XrSystemBodyTrackingPropertiesBD body_tracking_prop{
|
||||
.type = XR_TYPE_SYSTEM_BODY_TRACKING_PROPERTIES_BD,
|
||||
};
|
||||
|
||||
XrSystemProperties prop{
|
||||
.type = XR_TYPE_SYSTEM_PROPERTIES,
|
||||
.next = &body_tracking_prop,
|
||||
};
|
||||
CHECK_XR(xrGetSystemProperties(*inst, id, &prop));
|
||||
|
||||
return body_tracking_prop;
|
||||
}
|
||||
|
||||
xr::system::passthrough_type xr::system::passthrough_supported() const
|
||||
{
|
||||
if (utils::contains(environment_blend_modes(XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO), XR_ENVIRONMENT_BLEND_MODE_ALPHA_BLEND))
|
||||
|
||||
@@ -64,6 +64,8 @@ public:
|
||||
XrSystemEyeGazeInteractionPropertiesEXT eye_gaze_interaction_properties() const;
|
||||
XrSystemFaceTrackingProperties2FB fb_face_tracking2_properties() const;
|
||||
XrSystemFacialTrackingPropertiesHTC htc_face_tracking_properties() const;
|
||||
XrSystemBodyTrackingPropertiesFB fb_body_tracking_properties() const;
|
||||
XrSystemBodyTrackingPropertiesBD bd_body_tracking_properties() const;
|
||||
passthrough_type passthrough_supported() const;
|
||||
|
||||
XrGraphicsRequirementsVulkan2KHR graphics_requirements() const;
|
||||
|
||||
Reference in New Issue
Block a user