/* * WiVRn VR streaming * Copyright (C) 2024 galister * Copyright (C) 2025 Sapphire * * 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 . */ #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 xr::pico_face_tracker::pico_face_tracker(instance & inst, session & s_) : s(s_) { xrStartEyeTrackingPICO = inst.get_proc("xrStartEyeTrackingPICO"); xrStopEyeTrackingPICO = inst.get_proc("xrStopEyeTrackingPICO"); xrSetTrackingModePICO = inst.get_proc("xrSetTrackingModePICO"); xrGetFaceTrackingStatePICO = inst.get_proc("xrGetFaceTrackingStatePICO"); xrGetFaceTrackingDataPICO = inst.get_proc("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; }