WIP: Pico 4 Pro face tracking

This commit is contained in:
Sapphire
2025-06-01 10:21:47 +02:00
committed by xytovl
parent 5130bdeda5
commit 908d21ffec
23 changed files with 655 additions and 3 deletions
+69
View File
@@ -0,0 +1,69 @@
/*
* WiVRn VR streaming
* Copyright (C) 2024 galister <galister@librevr.org>
* 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_face_tracker.h"
#include "spdlog/common.h"
#include "spdlog/spdlog.h"
#include "wivrn_packets.h"
#include "xr/instance.h"
#include "xr/session.h"
#include "xr/xr.h"
#include <openxr/openxr.h>
xr::pico_face_tracker::pico_face_tracker(instance & inst, session & s_) :
s(s_)
{
xrStartEyeTrackingPICO = inst.get_proc<PFN_xrStartEyeTrackingPICO>("xrStartEyeTrackingPICO");
xrStopEyeTrackingPICO = inst.get_proc<PFN_xrStopEyeTrackingPICO>("xrStopEyeTrackingPICO");
xrSetTrackingModePICO = inst.get_proc<PFN_xrSetTrackingModePICO>("xrSetTrackingModePICO");
xrGetFaceTrackingStatePICO = inst.get_proc<PFN_xrGetFaceTrackingStatePICO>("xrGetFaceTrackingStatePICO");
xrGetFaceTrackingDataPICO = inst.get_proc<PFN_xrGetFaceTrackingDataPICO>("xrGetFaceTrackingDataPICO");
CHECK_XR(xrStartEyeTrackingPICO(s));
CHECK_XR(xrSetTrackingModePICO(s, XR_TRACKING_MODE_FACE_BIT_PICO));
}
xr::pico_face_tracker::~pico_face_tracker()
{
if (auto res = xrStopEyeTrackingPICO(s, XR_TRACKING_MODE_FACE_BIT_PICO); res != XR_SUCCESS)
spdlog::warn("Failed to deactivate face tracking: {}", xr::to_string(res));
}
void xr::pico_face_tracker::get_weights(XrTime time, wivrn::from_headset::tracking::pico_face & out_expressions)
{
if (!xrGetFaceTrackingDataPICO)
return;
XrFaceTrackingDataPICO face_tracking{.time = 0};
if (auto res = xrGetFaceTrackingDataPICO(s, time, XR_GET_FACE_DATA_DEFAULT_PICO, &face_tracking); res != XR_SUCCESS)
{
XrTrackingModeFlagsPICO mode;
XrTrackingStateCodePICO code;
if (xrGetFaceTrackingStatePICO(s, &mode, &code) == XR_SUCCESS)
spdlog::warn("Unable to get face tracking data: xrGetFaceTrackingDataPICO returned {}, tracking mode state {}, flags {}", xr::to_string(res), xr::to_string(code), mode);
else
spdlog::warn("Unable to get face tracking data: xrGetFaceTrackingDataPICO returned {}", xr::to_string(res));
out_expressions.is_valid = false;
return;
}
std::copy_n(face_tracking.blendShapeWeight, std::size(face_tracking.blendShapeWeight), out_expressions.weights.data());
out_expressions.is_valid = face_tracking.time != 0;
}
+49
View File
@@ -0,0 +1,49 @@
/*
* WiVRn VR streaming
* Copyright (C) 2024 galister <galister@librevr.org>
* 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/pico_eye_types.h"
#include "xr/pico_eye_types_reflection.h"
#include <openxr/openxr.h>
namespace xr
{
class instance;
class session;
class pico_face_tracker
{
PFN_xrStartEyeTrackingPICO xrStartEyeTrackingPICO{};
PFN_xrStopEyeTrackingPICO xrStopEyeTrackingPICO{};
PFN_xrSetTrackingModePICO xrSetTrackingModePICO{};
PFN_xrGetFaceTrackingStatePICO xrGetFaceTrackingStatePICO{};
PFN_xrGetFaceTrackingDataPICO xrGetFaceTrackingDataPICO{};
XrSession s;
public:
pico_face_tracker() = default;
pico_face_tracker(instance & inst, session & s);
~pico_face_tracker();
void get_weights(XrTime time, struct wivrn::from_headset::tracking::pico_face & out_expressions);
};
} // namespace xr
+6
View File
@@ -136,6 +136,12 @@ xr::htc_face_tracker xr::session::create_htc_face_tracker(XrFacialTrackingTypeHT
CHECK_XR(xrCreateFacialTrackerHTC(id, &create_info, &ft));
return {*inst, ft, facialTrackingType};
}
xr::pico_face_tracker xr::session::create_pico_face_tracker()
{
return {*inst, *this};
}
std::vector<vk::Format> xr::session::get_swapchain_formats() const
{
std::vector<vk::Format> formats;
+2
View File
@@ -30,6 +30,7 @@
#include "hand_tracker.h"
#include "htc_face_tracker.h"
#include "passthrough.h"
#include "pico_face_tracker.h"
#include "space.h"
namespace xr
@@ -52,6 +53,7 @@ public:
hand_tracker create_hand_tracker(XrHandEXT hand, XrHandJointSetEXT hand_joint_set = XR_HAND_JOINT_SET_DEFAULT_EXT);
fb_face_tracker2 create_fb_face_tracker2();
htc_face_tracker create_htc_face_tracker(XrFacialTrackingTypeHTC);
pico_face_tracker create_pico_face_tracker();
std::vector<vk::Format> get_swapchain_formats() const;
+4
View File
@@ -26,6 +26,8 @@
#include "swapchain.h"
#include "system.h"
#include "xr/check.h"
#include "xr/pico_eye_types.h"
#include "xr/pico_eye_types_reflection.h"
#include <cstddef>
#include <string>
@@ -56,6 +58,8 @@ XR_ENUM_STR(XrSessionState);
XR_ENUM_STR(XrObjectType);
XR_ENUM_STR(XrStructureType);
XR_ENUM_STR(XrTrackingStateCodePICO);
std::string to_string(XrVersion version);
} // namespace xr