Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Vindicus999
2025-12-10 01:55:41 +00:00
10 changed files with 303 additions and 663 deletions
+11
View File
@@ -1061,6 +1061,17 @@ void application::initialize_actions()
}
}
// Patch profile to add pinch_ext/pose and poke_ext/pose
if (!profile.profile_name.ends_with("ext/hand_interaction_ext") && xr_instance.has_extension(XR_EXT_HAND_INTERACTION_EXTENSION_NAME))
{
spdlog::info("Adding pinch_ext/pose for interaction profile {}", profile.profile_name);
profile.input_sources.push_back("/user/hand/left/input/pinch_ext/pose");
profile.input_sources.push_back("/user/hand/right/input/pinch_ext/pose");
spdlog::info("Adding poke_ext/pose for interaction profile {}", profile.profile_name);
profile.input_sources.push_back("/user/hand/left/input/poke_ext/pose");
profile.input_sources.push_back("/user/hand/right/input/poke_ext/pose");
}
// Dynamically add VIVE XR Trackers to the profile if available
if (utils::contains(profile.required_extensions, XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME) and
xr_instance.has_extension(XR_HTC_PATH_ENUMERATION_EXTENSION_NAME))
+22 -1
View File
@@ -671,9 +671,13 @@ static device_id derived_from(device_id target)
{
case device_id::LEFT_AIM:
case device_id::LEFT_PALM:
case device_id::LEFT_PINCH_POSE:
case device_id::LEFT_POKE:
return device_id::LEFT_GRIP;
case device_id::RIGHT_AIM:
case device_id::RIGHT_PALM:
case device_id::RIGHT_PINCH_POSE:
case device_id::RIGHT_POKE:
return device_id::RIGHT_GRIP;
default:
assert(false);
@@ -725,6 +729,19 @@ void scenes::stream::on_interaction_profile_changed(const XrEventDataInteraction
DO_PROFILE(meta, touch_controller_quest_2)
DO_PROFILE(samsung, odyssey_controller)
DO_PROFILE(valve, index_controller)
// FIXME: remove once support for pre-1.1 profiles is dropped
if (profile == "/interaction_profiles/facebook/touch_controller_pro")
{
interaction_profiles[i] = interaction_profile::meta_touch_pro_controller;
continue;
}
if (profile == "/interaction_profiles/meta/touch_controller_plus")
{
interaction_profiles[i] = interaction_profile::meta_touch_plus_controller;
continue;
}
spdlog::warn("unknown interaction profile {}", profile);
}
catch (std::exception & e)
{
@@ -737,12 +754,16 @@ void scenes::stream::on_interaction_profile_changed(const XrEventDataInteraction
for (device_id target: {
device_id::LEFT_AIM,
device_id::LEFT_PALM,
device_id::LEFT_PINCH_POSE,
device_id::LEFT_POKE,
device_id::RIGHT_AIM,
device_id::RIGHT_PALM,
device_id::RIGHT_PINCH_POSE,
device_id::RIGHT_POKE,
})
{
// don't do derived poses for hand interaction
const bool right = target >= device_id::RIGHT_GRIP && target <= device_id::RIGHT_PALM;
const bool right = (target >= device_id::RIGHT_GRIP && target <= device_id::RIGHT_PALM) || target == device_id::RIGHT_PINCH_POSE || target == device_id::RIGHT_POKE;
if (interaction_profiles[right].load() == interaction_profile::ext_hand_interaction_ext)
{
network_session->send_control(from_headset::derived_pose{
+77 -56
View File
@@ -8,8 +8,8 @@ msgid ""
msgstr ""
"Project-Id-Version: WiVRn\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-12-03 02:57+0800\n"
"PO-Revision-Date: 2025-12-03 21:11+0800\n"
"POT-Creation-Date: 2025-12-09 17:10+0800\n"
"PO-Revision-Date: 2025-12-09 21:21+0800\n"
"Last-Translator: BERADQ <adqber123@outlook.com>\n"
"Language-Team: Chinese (China)\n"
"Language: zh_CN\n"
@@ -68,11 +68,11 @@ msgstr "无法连接至 {} ({}): {}"
msgid "Waiting for connection"
msgstr "等待连接"
#: client/scenes/lobby.cpp:1310
#: client/scenes/lobby.cpp:1308
msgid "Passthrough"
msgstr "透视"
#: client/scenes/lobby.cpp:1322
#: client/scenes/lobby.cpp:1320
msgid "Default environment"
msgstr "默认环境"
@@ -92,13 +92,13 @@ msgid "Disabled"
msgstr "停用"
#: client/scenes/lobby_gui.cpp:112 client/scenes/lobby_gui.cpp:256
#: client/scenes/stream_gui.cpp:967
#: client/scenes/stream_gui.cpp:1012
msgid "Disconnect"
msgstr "终止连接"
#: client/scenes/lobby_gui.cpp:132 client/scenes/lobby_gui_customize.cpp:749
#: client/scenes/lobby_gui_customize.cpp:840
#: client/scenes/lobby_gui_customize.cpp:896 client/scenes/stream_gui.cpp:963
#: client/scenes/lobby_gui_customize.cpp:896 client/scenes/stream_gui.cpp:1008
msgid "Close"
msgstr "关闭"
@@ -136,7 +136,7 @@ msgid "TCP only"
msgstr "仅限 TCP"
#: client/scenes/lobby_gui.cpp:317 client/scenes/lobby_gui_customize.cpp:651
#: client/scenes/stream_gui.cpp:920
#: client/scenes/stream_gui.cpp:965
msgid "Cancel"
msgstr "取消"
@@ -181,17 +181,17 @@ msgstr "语言"
msgid "System language"
msgstr "系统语言"
#: client/scenes/lobby_gui.cpp:577 client/scenes/stream_gui.cpp:415
#: client/scenes/lobby_gui.cpp:577 client/scenes/stream_gui.cpp:418
msgid "Refresh rate"
msgstr "刷新率"
#: client/scenes/lobby_gui.cpp:577 client/scenes/lobby_gui.cpp:579
#: client/scenes/stream_gui.cpp:415 client/scenes/stream_gui.cpp:417
#: client/scenes/stream_gui.cpp:418 client/scenes/stream_gui.cpp:420
msgctxt "automatic refresh rate"
msgid "Automatic"
msgstr "自动"
#: client/scenes/lobby_gui.cpp:586 client/scenes/stream_gui.cpp:425
#: client/scenes/lobby_gui.cpp:586 client/scenes/stream_gui.cpp:428
msgid ""
"Select refresh rate based on measured application performance.\n"
"May cause flicker when a change happens."
@@ -199,7 +199,7 @@ msgstr ""
"根据测量的应用程序性能选择刷新率。\n"
"更改时可能会造成闪烁。"
#: client/scenes/lobby_gui.cpp:603 client/scenes/stream_gui.cpp:443
#: client/scenes/lobby_gui.cpp:603 client/scenes/stream_gui.cpp:446
msgid "Minimum refresh rate"
msgstr "最低刷新率"
@@ -309,15 +309,15 @@ msgstr ""
"在游戏串流期间启用配置窗口显示\n"
"若启用此功能,同时按下两只摇杆,将会显示该窗口。"
#: client/scenes/lobby_gui.cpp:805 client/scenes/stream_gui.cpp:463
#: client/scenes/lobby_gui.cpp:805 client/scenes/stream_gui.cpp:480
msgid "OpenXR post-processing"
msgstr "OpenXR 后处理"
#: client/scenes/lobby_gui.cpp:809 client/scenes/stream_gui.cpp:467
#: client/scenes/lobby_gui.cpp:809 client/scenes/stream_gui.cpp:484
msgid "Supersampling"
msgstr "超采样"
#: client/scenes/lobby_gui.cpp:829 client/scenes/stream_gui.cpp:488
#: client/scenes/lobby_gui.cpp:829 client/scenes/stream_gui.cpp:505
msgid ""
"Reduce flicker for high contrast edges.\n"
"Useful when the input resolution is high compared to the headset display"
@@ -325,11 +325,11 @@ msgstr ""
"减少高对比度边缘的闪烁。\n"
"当串流分辨率高于头显原生分辨率时很有用"
#: client/scenes/lobby_gui.cpp:834 client/scenes/stream_gui.cpp:493
#: client/scenes/lobby_gui.cpp:834 client/scenes/stream_gui.cpp:510
msgid "Sharpening"
msgstr "锐化"
#: client/scenes/lobby_gui.cpp:854 client/scenes/stream_gui.cpp:514
#: client/scenes/lobby_gui.cpp:854 client/scenes/stream_gui.cpp:531
msgid ""
"Improve clarity of high contrast edges and counteract blur.\n"
"Useful when the input resolution is low compared to the headset display"
@@ -375,91 +375,91 @@ msgstr "是否启用身体追踪?"
msgid "Welcome to WiVRn"
msgstr "欢迎使用 WiVRn"
#: client/scenes/lobby_gui.cpp:1169
#: client/scenes/lobby_gui.cpp:1171
msgid "Yes"
msgstr "是"
#: client/scenes/lobby_gui.cpp:1176
#: client/scenes/lobby_gui.cpp:1178
msgid "No"
msgstr "否"
#: client/scenes/lobby_gui.cpp:1195 client/scenes/lobby_gui.cpp:1836
#: client/scenes/lobby_gui.cpp:1197 client/scenes/lobby_gui.cpp:1843
msgid "Licenses"
msgstr "许可证"
#: client/scenes/lobby_gui.cpp:1470
#: client/scenes/lobby_gui.cpp:1473
msgid "Microphone is enabled"
msgstr "麦克风已启用"
#: client/scenes/lobby_gui.cpp:1471
#: client/scenes/lobby_gui.cpp:1474
msgid "Microphone is disabled"
msgstr "麦克风已停用"
#: client/scenes/lobby_gui.cpp:1480
#: client/scenes/lobby_gui.cpp:1483
msgid "Hand tracking is enabled"
msgstr "手部追踪已启用"
#: client/scenes/lobby_gui.cpp:1481
#: client/scenes/lobby_gui.cpp:1484
msgid "Hand tracking is disabled"
msgstr "手部追踪已停用"
#: client/scenes/lobby_gui.cpp:1490
#: client/scenes/lobby_gui.cpp:1493
msgid "Eye tracking is enabled"
msgstr "眼动追踪已启用"
#: client/scenes/lobby_gui.cpp:1491
#: client/scenes/lobby_gui.cpp:1494
msgid "Eye tracking is disabled"
msgstr "眼动追踪已停用"
#: client/scenes/lobby_gui.cpp:1501
#: client/scenes/lobby_gui.cpp:1504
msgid "Face tracking is enabled"
msgstr "面部追踪已启用"
#: client/scenes/lobby_gui.cpp:1502
#: client/scenes/lobby_gui.cpp:1505
msgid "Face tracking is disabled"
msgstr "面部追踪已停用"
#: client/scenes/lobby_gui.cpp:1512
#: client/scenes/lobby_gui.cpp:1519
msgid "Body tracking is enabled"
msgstr "身体追踪已启用"
#: client/scenes/lobby_gui.cpp:1513
#: client/scenes/lobby_gui.cpp:1520
msgid "Body tracking is disabled"
msgstr "身体追踪已停用"
#: client/scenes/lobby_gui.cpp:1529
#: client/scenes/lobby_gui.cpp:1536
msgid "Add server"
msgstr "新增服务器"
#: client/scenes/lobby_gui.cpp:1815
#: client/scenes/lobby_gui.cpp:1822
msgid "Server list"
msgstr "服务器列表"
#: client/scenes/lobby_gui.cpp:1818 client/scenes/stream_gui.cpp:948
#: client/scenes/lobby_gui.cpp:1825 client/scenes/stream_gui.cpp:993
msgid "Settings"
msgstr "设置"
#: client/scenes/lobby_gui.cpp:1821
#: client/scenes/lobby_gui.cpp:1828
msgid "Post-processing"
msgstr "后处理"
#: client/scenes/lobby_gui.cpp:1824
#: client/scenes/lobby_gui.cpp:1831
msgid "Customize"
msgstr "自定义"
#: client/scenes/lobby_gui.cpp:1828
#: client/scenes/lobby_gui.cpp:1835
msgid "Debug"
msgstr "Debug"
#: client/scenes/lobby_gui.cpp:1833
#: client/scenes/lobby_gui.cpp:1840
msgid "About"
msgstr "关于"
#: client/scenes/lobby_gui.cpp:1839
#: client/scenes/lobby_gui.cpp:1846
msgid "Exit"
msgstr "退出"
#: client/scenes/lobby_gui.cpp:1856
#: client/scenes/lobby_gui.cpp:1863
msgid ""
"Press the grip button or put your palm up\n"
"to move the main window"
@@ -467,7 +467,7 @@ msgstr ""
"按下抓握键,或手掌向上\n"
"以移动主窗口"
#: client/scenes/lobby_gui.cpp:1858
#: client/scenes/lobby_gui.cpp:1865
msgid "Press the grip button to move the main window"
msgstr "按下抓握键以移动主窗口"
@@ -612,7 +612,7 @@ msgstr "估计从运动到显示延迟: {}ms"
msgid "Press the grip button to move the window"
msgstr "按下抓握键来移动窗口"
#: client/scenes/stream_gui.cpp:354 client/scenes/stream_gui.cpp:880
#: client/scenes/stream_gui.cpp:354 client/scenes/stream_gui.cpp:921
msgid "Press both thumbsticks to display the WiVRn window"
msgstr "同时按下两侧摇杆以显示 WiVRn 窗口"
@@ -620,69 +620,90 @@ msgstr "同时按下两侧摇杆以显示 WiVRn 窗口"
msgid "Motion to photon latency"
msgstr "从动作到显示的延迟"
#: client/scenes/stream_gui.cpp:521
#: client/scenes/stream_gui.cpp:465
msgid "Bitrate:"
msgstr "码率:"
#: client/scenes/stream_gui.cpp:475
msgid "Click to adjust bitrate"
msgstr "点击以调整码率"
#: client/scenes/stream_gui.cpp:538
msgid "Foveation center override"
msgstr "注视点渲染位置覆盖"
#: client/scenes/stream_gui.cpp:524
#: client/scenes/stream_gui.cpp:541
msgid "Enable"
msgstr "启用"
#: client/scenes/stream_gui.cpp:532 client/scenes/stream_gui.cpp:579
#: client/scenes/stream_gui.cpp:549 client/scenes/stream_gui.cpp:617
#, c++-format
msgid "Height {:.1f} deg"
msgstr "俯仰 {:.1f}°"
#: client/scenes/stream_gui.cpp:533 client/scenes/stream_gui.cpp:580
#: client/scenes/stream_gui.cpp:550 client/scenes/stream_gui.cpp:618
#, c++-format
msgid "Distance {:.2f} m"
msgstr "距离 {:.2f}m"
#: client/scenes/stream_gui.cpp:534
#: client/scenes/stream_gui.cpp:551
msgid "Default"
msgstr "默认"
#: client/scenes/stream_gui.cpp:545
#: client/scenes/stream_gui.cpp:562
msgid "Change"
msgstr "变更"
#: client/scenes/stream_gui.cpp:577
#: client/scenes/stream_gui.cpp:594
msgid "Use the right thumbstick to adjust the bitrate"
msgstr "使用右摇杆来调节码率"
#: client/scenes/stream_gui.cpp:595
msgid "Press A to go back"
msgstr "按下 A 以返回"
#: client/scenes/stream_gui.cpp:596
#, c++-format
msgid "Bitrate: {}Mbit/s"
msgstr "码率:{}Mbit/s"
#: client/scenes/stream_gui.cpp:615
msgid "Use the thumbsticks to move the foveation center"
msgstr "使用摇杆移动注视点中心"
#: client/scenes/stream_gui.cpp:578
#: client/scenes/stream_gui.cpp:616
msgid "Press A to save or B to cancel"
msgstr "按下 A 保存或 B 取消"
#: client/scenes/stream_gui.cpp:636
#: client/scenes/stream_gui.cpp:674
msgid "Running XR applications:"
msgstr "运行 XR 应用程序中:"
#: client/scenes/stream_gui.cpp:653
#: client/scenes/stream_gui.cpp:691
msgid "Overlays"
msgstr "叠加层"
#: client/scenes/stream_gui.cpp:692
#: client/scenes/stream_gui.cpp:730
msgid "Request to quit, may be ignored by the application"
msgstr "退出请求可能会被应用程序忽略"
#: client/scenes/stream_gui.cpp:935
#: client/scenes/stream_gui.cpp:980
msgid "Applications"
msgstr "应用程序"
#: client/scenes/stream_gui.cpp:938
#: client/scenes/stream_gui.cpp:983
msgid "Start"
msgstr "启动"
#: client/scenes/stream_gui.cpp:951
#: client/scenes/stream_gui.cpp:996
msgid "Stats"
msgstr "统计"
#: client/scenes/stream_gui.cpp:957
#: client/scenes/stream_gui.cpp:1002
msgid "Statistics overlay"
msgstr "统计数据叠加"
#: client/scenes/stream_gui.cpp:960
#: client/scenes/stream_gui.cpp:1005
msgid "Compact view"
msgstr "概览"
-1
View File
@@ -100,7 +100,6 @@ if (WIVRN_BUILD_SERVER)
driver/wivrn_pacer.cpp
driver/wivrn_comp_target.cpp
driver/wivrn_controller.cpp
driver/wivrn_hand_interaction.cpp
driver/wivrn_eye_tracker.cpp
driver/wivrn_android_face_tracker.cpp
driver/wivrn_fb_face2_tracker.cpp
+181 -91
View File
@@ -2,6 +2,7 @@
* WiVRn VR streaming
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
* 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
@@ -26,11 +27,12 @@
#include "util/u_logging.h"
#include <array>
#include <format>
#include <fstream>
#include <magic_enum.hpp>
#include <numbers>
#include <optional>
#include <fstream>
#include <stdexcept>
#include "xrt/xrt_defines.h"
@@ -81,6 +83,16 @@ enum wivrn_controller_input_index
WIVRN_CONTROLLER_TRACKPAD_TOUCH, // /user/hand/XXXX/input/trackpad/touch
WIVRN_CONTROLLER_STYLUS_FORCE, // /user/hand/XXXX/input/stylus_fb/force
// XR_EXT_hand_interaction
WIVRN_CONTROLLER_PINCH_POSE, // /user/hand/XXXX/input/pinch_ext/pose
WIVRN_CONTROLLER_PINCH_VALUE, // /user/hand/XXXX/input/pinch_ext/value
WIVRN_CONTROLLER_PINCH_READY, // /user/hand/XXXX/input/pinch_ext/ready_ext
WIVRN_CONTROLLER_POKE_POSE, // /user/hand/XXXX/input/poke_ext/pose
WIVRN_CONTROLLER_AIM_ACTIVATE_VALUE, // /user/hand/XXXX/input/aim_activate_ext/value
WIVRN_CONTROLLER_AIM_ACTIVATE_READY, // /user/hand/XXXX/input/aim_activate_ext/ready_ext
WIVRN_CONTROLLER_GRASP_VALUE, // /user/hand/XXXX/input/grasp_ext/value
WIVRN_CONTROLLER_GRASP_READY, // /user/hand/XXXX/input/ready_ext/value
WIVRN_CONTROLLER_INPUT_COUNT
};
@@ -237,16 +249,44 @@ input_data map_input(device_id id)
return {WIVRN_CONTROLLER_THUMBREST_FORCE, wivrn_input_type::FLOAT, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
case device_id::RIGHT_STYLUS_FORCE:
return {WIVRN_CONTROLLER_STYLUS_FORCE, wivrn_input_type::FLOAT, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
// XR_EXT_hand_interaction
case device_id::LEFT_PINCH_POSE:
return {WIVRN_CONTROLLER_PINCH_POSE, wivrn_input_type::POSE, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::LEFT_PINCH_VALUE:
return {WIVRN_CONTROLLER_PINCH_VALUE, wivrn_input_type::FLOAT, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::LEFT_PINCH_READY:
return {WIVRN_CONTROLLER_PINCH_READY, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::RIGHT_PINCH_POSE:
return {WIVRN_CONTROLLER_PINCH_POSE, wivrn_input_type::POSE, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
case device_id::RIGHT_PINCH_VALUE:
return {WIVRN_CONTROLLER_PINCH_VALUE, wivrn_input_type::FLOAT, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
case device_id::RIGHT_PINCH_READY:
return {WIVRN_CONTROLLER_PINCH_READY, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
case device_id::LEFT_POKE:
return {WIVRN_CONTROLLER_POKE_POSE, wivrn_input_type::POSE, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::RIGHT_POKE:
return {WIVRN_CONTROLLER_POKE_POSE, wivrn_input_type::POSE, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
case device_id::LEFT_AIM_ACTIVATE_VALUE:
return {WIVRN_CONTROLLER_AIM_ACTIVATE_VALUE, wivrn_input_type::FLOAT, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::LEFT_AIM_ACTIVATE_READY:
return {WIVRN_CONTROLLER_AIM_ACTIVATE_READY, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::RIGHT_AIM_ACTIVATE_VALUE:
return {WIVRN_CONTROLLER_AIM_ACTIVATE_VALUE, wivrn_input_type::FLOAT, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
case device_id::RIGHT_AIM_ACTIVATE_READY:
return {WIVRN_CONTROLLER_AIM_ACTIVATE_READY, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
case device_id::LEFT_GRASP_VALUE:
return {WIVRN_CONTROLLER_GRASP_VALUE, wivrn_input_type::FLOAT, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::LEFT_GRASP_READY:
return {WIVRN_CONTROLLER_GRASP_READY, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::RIGHT_GRASP_VALUE:
return {WIVRN_CONTROLLER_GRASP_VALUE, wivrn_input_type::FLOAT, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
case device_id::RIGHT_GRASP_READY:
return {WIVRN_CONTROLLER_GRASP_READY, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
default:
break;
}
// If the headset supports hand_interaction_ext, upon switch
// to/from hand tracking we may get the inputs packet before
// the interaction profile change, so if we get a bad input
// just return an invalid index so we can ignore it
U_LOG_D("wivrn_controller: bad input id %s", std::string(magic_enum::enum_name(id)).c_str());
// the type here doesn't really matter
return {WIVRN_CONTROLLER_INPUT_INVALID, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_UNKNOWN};
throw std::range_error("bad input id " + std::string(magic_enum::enum_name(id)));
}
xrt_binding_input_pair simple_input_binding[] = {
@@ -254,6 +294,8 @@ xrt_binding_input_pair simple_input_binding[] = {
{XRT_INPUT_SIMPLE_MENU_CLICK, XRT_INPUT_TOUCH_MENU_CLICK},
{XRT_INPUT_SIMPLE_GRIP_POSE, XRT_INPUT_TOUCH_GRIP_POSE},
{XRT_INPUT_SIMPLE_AIM_POSE, XRT_INPUT_TOUCH_AIM_POSE},
{XRT_INPUT_HAND_PINCH_POSE, XRT_INPUT_HAND_PINCH_POSE},
{XRT_INPUT_HAND_POKE_POSE, XRT_INPUT_HAND_POKE_POSE},
};
xrt_binding_output_pair simple_output_binding[] = {
@@ -280,6 +322,8 @@ xrt_binding_input_pair index_input_binding_left[] = {
{XRT_INPUT_INDEX_TRACKPAD_TOUCH, XRT_INPUT_INDEX_TRACKPAD_TOUCH},
{XRT_INPUT_INDEX_GRIP_POSE, XRT_INPUT_TOUCH_GRIP_POSE},
{XRT_INPUT_INDEX_AIM_POSE, XRT_INPUT_TOUCH_AIM_POSE},
{XRT_INPUT_HAND_PINCH_POSE, XRT_INPUT_HAND_PINCH_POSE},
{XRT_INPUT_HAND_POKE_POSE, XRT_INPUT_HAND_POKE_POSE},
};
xrt_binding_input_pair index_input_binding_right[] = {
@@ -302,6 +346,8 @@ xrt_binding_input_pair index_input_binding_right[] = {
{XRT_INPUT_INDEX_TRACKPAD_TOUCH, XRT_INPUT_INDEX_TRACKPAD_TOUCH},
{XRT_INPUT_INDEX_GRIP_POSE, XRT_INPUT_TOUCH_GRIP_POSE},
{XRT_INPUT_INDEX_AIM_POSE, XRT_INPUT_TOUCH_AIM_POSE},
{XRT_INPUT_HAND_PINCH_POSE, XRT_INPUT_HAND_PINCH_POSE},
{XRT_INPUT_HAND_POKE_POSE, XRT_INPUT_HAND_POKE_POSE},
};
xrt_binding_output_pair index_output_binding[] = {
@@ -327,6 +373,8 @@ xrt_binding_input_pair focus3_input_binding[] = {
{XRT_INPUT_VIVE_FOCUS3_THUMBREST_TOUCH, XRT_INPUT_TOUCH_THUMBREST_TOUCH},
{XRT_INPUT_VIVE_FOCUS3_GRIP_POSE, XRT_INPUT_TOUCH_GRIP_POSE},
{XRT_INPUT_VIVE_FOCUS3_AIM_POSE, XRT_INPUT_TOUCH_AIM_POSE},
{XRT_INPUT_HAND_PINCH_POSE, XRT_INPUT_HAND_PINCH_POSE},
{XRT_INPUT_HAND_POKE_POSE, XRT_INPUT_HAND_POKE_POSE},
};
xrt_binding_output_pair focus3_output_binding[] = {
@@ -359,6 +407,8 @@ xrt_binding_input_pair touch_pro_input_binding[] = {
{XRT_INPUT_TOUCH_PRO_TRIGGER_CURL, XRT_INPUT_TOUCH_PRO_TRIGGER_CURL},
{XRT_INPUT_TOUCH_PRO_TRIGGER_SLIDE, XRT_INPUT_TOUCH_PRO_TRIGGER_SLIDE},
{XRT_INPUT_TOUCH_PRO_STYLUS_FORCE, XRT_INPUT_TOUCH_PRO_STYLUS_FORCE},
{XRT_INPUT_HAND_PINCH_POSE, XRT_INPUT_HAND_PINCH_POSE},
{XRT_INPUT_HAND_POKE_POSE, XRT_INPUT_HAND_POKE_POSE},
};
xrt_binding_output_pair touch_pro_output_binding[] = {
@@ -392,6 +442,8 @@ xrt_binding_input_pair touch_plus_input_binding[] = {
{XRT_INPUT_TOUCH_PLUS_THUMB_PROXIMITY, XRT_INPUT_TOUCH_THUMB_PROXIMITY},
{XRT_INPUT_TOUCH_PLUS_TRIGGER_CURL, XRT_INPUT_TOUCH_PRO_TRIGGER_CURL},
{XRT_INPUT_TOUCH_PLUS_TRIGGER_SLIDE, XRT_INPUT_TOUCH_PRO_TRIGGER_SLIDE},
{XRT_INPUT_HAND_PINCH_POSE, XRT_INPUT_HAND_PINCH_POSE},
{XRT_INPUT_HAND_POKE_POSE, XRT_INPUT_HAND_POKE_POSE},
};
xrt_binding_output_pair touch_plus_output_binding[] = {
@@ -419,6 +471,8 @@ xrt_binding_input_pair pico_neo3_input_binding[] = {
{XRT_INPUT_PICO_NEO3_A_TOUCH, XRT_INPUT_TOUCH_A_TOUCH},
{XRT_INPUT_PICO_NEO3_B_CLICK, XRT_INPUT_TOUCH_B_CLICK},
{XRT_INPUT_PICO_NEO3_B_TOUCH, XRT_INPUT_TOUCH_B_TOUCH},
{XRT_INPUT_HAND_PINCH_POSE, XRT_INPUT_HAND_PINCH_POSE},
{XRT_INPUT_HAND_POKE_POSE, XRT_INPUT_HAND_POKE_POSE},
};
xrt_binding_output_pair pico_neo3_output_binding[] = {
@@ -446,6 +500,8 @@ xrt_binding_input_pair pico4_input_binding[] = {
{XRT_INPUT_PICO4_B_CLICK, XRT_INPUT_TOUCH_B_CLICK},
{XRT_INPUT_PICO4_B_TOUCH, XRT_INPUT_TOUCH_B_TOUCH},
{XRT_INPUT_PICO4_MENU_CLICK, XRT_INPUT_TOUCH_MENU_CLICK},
{XRT_INPUT_HAND_PINCH_POSE, XRT_INPUT_HAND_PINCH_POSE},
{XRT_INPUT_HAND_POKE_POSE, XRT_INPUT_HAND_POKE_POSE},
};
xrt_binding_output_pair pico4_output_binding[] = {
@@ -511,8 +567,24 @@ make_binding_profiles()
});
}
constexpr auto wivrn_per_hand_binding_profiles = std::to_array({make_binding_profiles<0>(),
make_binding_profiles<1>()});
constexpr auto controller_per_hand_binding_profiles = std::to_array({make_binding_profiles<0>(),
make_binding_profiles<1>()});
xrt_binding_input_pair hand_interaction_simple_input_binding[] = {
{XRT_INPUT_SIMPLE_SELECT_CLICK, XRT_INPUT_HAND_PINCH_VALUE},
{XRT_INPUT_SIMPLE_GRIP_POSE, XRT_INPUT_HAND_GRIP_POSE},
{XRT_INPUT_SIMPLE_AIM_POSE, XRT_INPUT_HAND_AIM_POSE},
};
xrt_binding_profile hand_interaction_binding_profiles[] = {
{
.name = XRT_DEVICE_SIMPLE_CONTROLLER,
.inputs = hand_interaction_simple_input_binding,
.input_count = std::size(hand_interaction_simple_input_binding),
.outputs = nullptr,
.output_count = 0,
},
};
struct xrt_space_relation_csv_header
{};
@@ -536,21 +608,22 @@ std::ostream & operator<<(std::ostream & out, const xrt_space_relation_csv_heade
}
} // namespace
wivrn_controller::wivrn_controller(int hand_id,
wivrn_controller::wivrn_controller(xrt_device_name name,
int hand_id,
xrt_device * hmd,
wivrn::wivrn_session * cnx) :
xrt_device{
.name = XRT_DEVICE_TOUCH_CONTROLLER,
.name = name,
.device_type = hand_id == 0 ? XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER : XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER,
.hmd = nullptr,
.tracking_origin = hmd->tracking_origin,
.binding_profile_count = wivrn_per_hand_binding_profiles[hand_id].size(),
.binding_profiles = (struct xrt_binding_profile *)wivrn_per_hand_binding_profiles[hand_id].data(),
.binding_profile_count = name != XRT_DEVICE_EXT_HAND_INTERACTION ? controller_per_hand_binding_profiles[hand_id].size() : std::size(hand_interaction_binding_profiles),
.binding_profiles = name != XRT_DEVICE_EXT_HAND_INTERACTION ? (struct xrt_binding_profile *)controller_per_hand_binding_profiles[hand_id].data() : hand_interaction_binding_profiles,
.input_count = WIVRN_CONTROLLER_INPUT_COUNT,
.supported = {
.orientation_tracking = true,
.position_tracking = true,
.hand_tracking = cnx->get_info().hand_tracking,
.hand_tracking = name != XRT_DEVICE_EXT_HAND_INTERACTION and cnx->get_info().hand_tracking,
},
.update_inputs = method_pointer<&wivrn_controller::update_inputs>,
.get_tracked_pose = method_pointer<&wivrn_controller::get_tracked_pose>,
@@ -561,6 +634,8 @@ wivrn_controller::wivrn_controller(int hand_id,
grip(hand_id == 0 ? device_id::LEFT_GRIP : device_id::RIGHT_GRIP),
aim(hand_id == 0 ? device_id::LEFT_AIM : device_id::RIGHT_AIM),
palm(hand_id == 0 ? device_id::LEFT_PALM : device_id::RIGHT_PALM),
pinch_ext(hand_id == 0 ? device_id::LEFT_PINCH_POSE : device_id::RIGHT_PINCH_POSE),
poke_ext(hand_id == 0 ? device_id::LEFT_POKE : device_id::RIGHT_POKE),
joints(hand_id),
inputs_array(input_count, xrt_input{}),
cnx(cnx)
@@ -575,10 +650,6 @@ wivrn_controller::wivrn_controller(int hand_id,
inputs[WIVRN_CONTROLLER_##NAME].active = true; \
} while (0)
SET_INPUT(TOUCH, AIM_POSE);
SET_INPUT(TOUCH, GRIP_POSE);
SET_INPUT(GENERIC, PALM_POSE);
if (auto grip_surface = configuration().grip_surface)
{
std::array<float, 3> angles = grip_surface.value();
@@ -596,81 +667,86 @@ wivrn_controller::wivrn_controller(int hand_id,
cnx->set_enabled(palm.device, false);
}
if (hand_id == 0)
if (name != XRT_DEVICE_EXT_HAND_INTERACTION)
{
inputs[WIVRN_CONTROLLER_HAND_TRACKING_LEFT].name = XRT_INPUT_HT_UNOBSTRUCTED_LEFT;
inputs[WIVRN_CONTROLLER_HAND_TRACKING_LEFT].active = true;
SET_INPUT(TOUCH, MENU_CLICK);
SET_INPUT(TOUCH, X_CLICK);
SET_INPUT(TOUCH, Y_CLICK);
SET_INPUT(TOUCH, X_TOUCH);
SET_INPUT(TOUCH, Y_TOUCH);
SET_INPUT(TOUCH, AIM_POSE);
SET_INPUT(TOUCH, GRIP_POSE);
SET_INPUT(GENERIC, PALM_POSE);
SET_INPUT(HAND, PINCH_POSE);
SET_INPUT(HAND, POKE_POSE);
if (hand_id == 0)
{
inputs[WIVRN_CONTROLLER_HAND_TRACKING_LEFT].name = XRT_INPUT_HT_UNOBSTRUCTED_LEFT;
inputs[WIVRN_CONTROLLER_HAND_TRACKING_LEFT].active = true;
SET_INPUT(TOUCH, MENU_CLICK);
SET_INPUT(TOUCH, X_CLICK);
SET_INPUT(TOUCH, Y_CLICK);
SET_INPUT(TOUCH, X_TOUCH);
SET_INPUT(TOUCH, Y_TOUCH);
}
else
{
inputs[WIVRN_CONTROLLER_HAND_TRACKING_RIGHT].name = XRT_INPUT_HT_UNOBSTRUCTED_RIGHT;
inputs[WIVRN_CONTROLLER_HAND_TRACKING_RIGHT].active = true;
SET_INPUT(TOUCH, SYSTEM_CLICK);
SET_INPUT(TOUCH, A_CLICK);
SET_INPUT(TOUCH, B_CLICK);
SET_INPUT(TOUCH, A_TOUCH);
SET_INPUT(TOUCH, B_TOUCH);
}
SET_INPUT(VIVE_FOCUS3, SQUEEZE_CLICK);
SET_INPUT(INDEX, SQUEEZE_FORCE);
SET_INPUT(TOUCH, SQUEEZE_VALUE);
SET_INPUT(INDEX, TRIGGER_CLICK);
SET_INPUT(TOUCH, TRIGGER_VALUE);
SET_INPUT(TOUCH, TRIGGER_TOUCH);
SET_INPUT(TOUCH, TRIGGER_PROXIMITY);
SET_INPUT(TOUCH_PRO, TRIGGER_CURL);
SET_INPUT(TOUCH_PRO, TRIGGER_SLIDE);
SET_INPUT(TOUCH_PLUS, TRIGGER_FORCE);
SET_INPUT(TOUCH, THUMBSTICK);
SET_INPUT(TOUCH, THUMBSTICK_CLICK);
SET_INPUT(TOUCH, THUMBSTICK_TOUCH);
SET_INPUT(TOUCH, THUMBREST_TOUCH);
SET_INPUT(TOUCH_PRO, THUMBREST_FORCE);
SET_INPUT(TOUCH, THUMB_PROXIMITY);
SET_INPUT(INDEX, TRACKPAD);
SET_INPUT(VIVE, TRACKPAD_CLICK);
SET_INPUT(INDEX, TRACKPAD_FORCE);
SET_INPUT(INDEX, TRACKPAD_TOUCH);
SET_INPUT(TOUCH_PRO, STYLUS_FORCE);
outputs_array = {
{.name = XRT_OUTPUT_NAME_TOUCH_HAPTIC},
{.name = XRT_OUTPUT_NAME_TOUCH_PRO_HAPTIC_THUMB},
{.name = XRT_OUTPUT_NAME_TOUCH_PRO_HAPTIC_TRIGGER},
};
output_count = outputs_array.size();
outputs = outputs_array.data();
}
else
{
inputs[WIVRN_CONTROLLER_HAND_TRACKING_RIGHT].name = XRT_INPUT_HT_UNOBSTRUCTED_RIGHT;
inputs[WIVRN_CONTROLLER_HAND_TRACKING_RIGHT].active = true;
SET_INPUT(TOUCH, SYSTEM_CLICK);
SET_INPUT(TOUCH, A_CLICK);
SET_INPUT(TOUCH, B_CLICK);
SET_INPUT(TOUCH, A_TOUCH);
SET_INPUT(TOUCH, B_TOUCH);
SET_INPUT(HAND, AIM_POSE);
SET_INPUT(HAND, GRIP_POSE);
SET_INPUT(GENERIC, PALM_POSE);
SET_INPUT(HAND, PINCH_POSE);
SET_INPUT(HAND, PINCH_VALUE);
SET_INPUT(HAND, PINCH_READY);
SET_INPUT(HAND, POKE_POSE);
SET_INPUT(HAND, AIM_ACTIVATE_VALUE);
SET_INPUT(HAND, AIM_ACTIVATE_READY);
SET_INPUT(HAND, GRASP_VALUE);
SET_INPUT(HAND, GRASP_READY);
}
SET_INPUT(VIVE_FOCUS3, SQUEEZE_CLICK);
SET_INPUT(INDEX, SQUEEZE_FORCE);
SET_INPUT(TOUCH, SQUEEZE_VALUE);
SET_INPUT(INDEX, TRIGGER_CLICK);
SET_INPUT(TOUCH, TRIGGER_VALUE);
SET_INPUT(TOUCH, TRIGGER_TOUCH);
SET_INPUT(TOUCH, TRIGGER_PROXIMITY);
SET_INPUT(TOUCH_PRO, TRIGGER_CURL);
SET_INPUT(TOUCH_PRO, TRIGGER_SLIDE);
SET_INPUT(TOUCH_PLUS, TRIGGER_FORCE);
SET_INPUT(TOUCH, THUMBSTICK);
SET_INPUT(TOUCH, THUMBSTICK_CLICK);
SET_INPUT(TOUCH, THUMBSTICK_TOUCH);
SET_INPUT(TOUCH, THUMBREST_TOUCH);
SET_INPUT(TOUCH_PRO, THUMBREST_FORCE);
SET_INPUT(TOUCH, THUMB_PROXIMITY);
SET_INPUT(INDEX, TRACKPAD);
SET_INPUT(VIVE, TRACKPAD_CLICK);
SET_INPUT(INDEX, TRACKPAD_FORCE);
SET_INPUT(INDEX, TRACKPAD_TOUCH);
SET_INPUT(TOUCH_PRO, STYLUS_FORCE);
#undef SET_INPUT
inputs_staging = inputs_array;
// Make sure everything is mapped
for (const auto & item: inputs_array)
{
assert(item.name);
}
outputs_array = {
{.name = XRT_OUTPUT_NAME_TOUCH_HAPTIC},
{.name = XRT_OUTPUT_NAME_TOUCH_PRO_HAPTIC_THUMB},
{.name = XRT_OUTPUT_NAME_TOUCH_PRO_HAPTIC_TRIGGER},
};
output_count = outputs_array.size();
outputs = outputs_array.data();
switch (hand_id)
{
case 0:
// Print name.
strcpy(str, "WiVRn left controller");
strcpy(serial, "WiVRn left controller");
break;
case 1:
// Print name.
strcpy(str, "WiVRn right controller");
strcpy(serial, "WiVRn right controller");
break;
default:
throw std::runtime_error("Invalid hand ID");
}
auto name_str = std::format("WiVRn {} {}", hand_id == 0 ? "left" : "right", name != XRT_DEVICE_EXT_HAND_INTERACTION ? "controller" : "hand interaction");
// Print name.
strcpy(str, name_str.c_str());
strcpy(serial, name_str.c_str());
}
xrt_result_t wivrn_controller::update_inputs()
@@ -738,21 +814,27 @@ xrt_result_t wivrn_controller::get_tracked_pose(xrt_input_name name, int64_t at_
switch (name)
{
case XRT_INPUT_TOUCH_AIM_POSE:
case XRT_INPUT_HAND_AIM_POSE:
std::tie(extrapolation_time, *res, device) = aim.get_pose_at(at_timestamp_ns);
cnx->set_enabled(device, true);
break;
case XRT_INPUT_TOUCH_GRIP_POSE:
case XRT_INPUT_HAND_GRIP_POSE:
std::tie(extrapolation_time, *res, device) = grip.get_pose_at(at_timestamp_ns);
cnx->set_enabled(device, true);
break;
case XRT_INPUT_GENERIC_PALM_POSE:
std::tie(extrapolation_time, *res, device) = palm.get_pose_at(at_timestamp_ns);
cnx->set_enabled(device, true);
break;
case XRT_INPUT_HAND_PINCH_POSE:
std::tie(extrapolation_time, *res, device) = pinch_ext.get_pose_at(at_timestamp_ns);
break;
case XRT_INPUT_HAND_POKE_POSE:
std::tie(extrapolation_time, *res, device) = poke_ext.get_pose_at(at_timestamp_ns);
break;
default:
U_LOG_XDEV_UNSUPPORTED_INPUT(this, u_log_get_global_level(), name);
return XRT_ERROR_INPUT_UNSUPPORTED;
}
cnx->set_enabled(device, true);
cnx->add_predict_offset(extrapolation_time);
if (auto out = tracking_dump())
{
@@ -762,6 +844,8 @@ xrt_result_t wivrn_controller::get_tracked_pose(xrt_input_name name, int64_t at_
case XRT_INPUT_TOUCH_AIM_POSE: return aim.device;
case XRT_INPUT_TOUCH_GRIP_POSE: return grip.device;
case XRT_INPUT_GENERIC_PALM_POSE: return palm.device;
case XRT_INPUT_HAND_PINCH_POSE: return pinch_ext.device;
case XRT_INPUT_HAND_POKE_POSE: return poke_ext.device;
default:
assert(false);
__builtin_unreachable();
@@ -800,7 +884,7 @@ xrt_result_t wivrn_controller::get_hand_tracking(xrt_input_name name, int64_t de
void wivrn_controller::set_derived_pose(const from_headset::derived_pose & derived)
{
auto list = [this](device_id id) -> pose_list * {
for (auto item: {&grip, &aim, &palm})
for (auto item: {&grip, &aim, &palm, &pinch_ext, &poke_ext})
{
if (item->device == id)
return item;
@@ -825,13 +909,17 @@ void wivrn_controller::update_tracking(const from_headset::tracking & tracking,
cnx->set_enabled(grip.device, false);
if (not palm.update_tracking(tracking, offset))
cnx->set_enabled(palm.device, false);
if (not pinch_ext.update_tracking(tracking, offset))
cnx->set_enabled(pinch_ext.device, false);
if (not poke_ext.update_tracking(tracking, offset))
cnx->set_enabled(poke_ext.device, false);
if (auto out = tracking_dump(); out and offset)
{
auto locked = out->lock();
auto now = os_monotonic_get_ns();
for (const auto & pose: tracking.device_poses)
{
if (pose.device == aim.device or pose.device == grip.device or pose.device == palm.device)
if (pose.device == aim.device or pose.device == grip.device or pose.device == palm.device or pose.device == pinch_ext.device or pose.device == poke_ext.device)
*locked << magic_enum::enum_name(pose.device) << ','
<< now << ','
<< offset.from_headset(tracking.timestamp) << ','
@@ -887,6 +975,8 @@ void wivrn_controller::reset_history()
grip.reset();
aim.reset();
palm.reset();
pinch_ext.reset();
poke_ext.reset();
}
thread_safe<std::ofstream> * wivrn_controller::tracking_dump()
+4 -1
View File
@@ -2,6 +2,7 @@
* WiVRn VR streaming
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
* 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
@@ -40,6 +41,8 @@ class wivrn_controller : public xrt_device
pose_list grip;
pose_list aim;
pose_list palm;
pose_list pinch_ext;
pose_list poke_ext;
hand_joints_list joints;
std::vector<xrt_input> inputs_staging;
@@ -50,7 +53,7 @@ class wivrn_controller : public xrt_device
public:
using base = xrt_device;
wivrn_controller(int hand_id, xrt_device * hmd, wivrn::wivrn_session * cnx);
wivrn_controller(xrt_device_name name, int hand_id, xrt_device * hmd, wivrn::wivrn_session * cnx);
xrt_result_t update_inputs();
-440
View File
@@ -1,440 +0,0 @@
/*
* WiVRn VR streaming
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
* 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 "wivrn_hand_interaction.h"
#include "configuration.h"
#include "driver/xrt_cast.h"
#include "math/m_api.h"
#include "utils/method.h"
#include "wivrn_session.h"
#include "util/u_logging.h"
#include <array>
#include <magic_enum.hpp>
#include <numbers>
#include <optional>
#include "xrt/xrt_defines.h"
namespace wivrn
{
namespace
{
enum wivrn_hand_interaction_input_index
{
WIVRN_HAND_INTERACTION_INPUT_INVALID = -1,
WIVRN_HAND_INTERACTION_AIM_POSE,
WIVRN_HAND_INTERACTION_GRIP_POSE,
WIVRN_HAND_INTERACTION_PALM_POSE,
WIVRN_HAND_INTERACTION_PINCH_POSE, // /user/hand/XXXX/input/pinch_ext/pose
WIVRN_HAND_INTERACTION_PINCH_VALUE, // /user/hand/XXXX/input/pinch_ext/value
WIVRN_HAND_INTERACTION_PINCH_READY, // /user/hand/XXXX/input/pinch_ext/ready_ext
WIVRN_HAND_INTERACTION_POKE_POSE, // /user/hand/XXXX/input/poke_ext/pose
WIVRN_HAND_INTERACTION_AIM_ACTIVATE_VALUE, // /user/hand/XXXX/input/aim_activate_ext/value
WIVRN_HAND_INTERACTION_AIM_ACTIVATE_READY, // /user/hand/XXXX/input/aim_activate_ext/ready_ext
WIVRN_HAND_INTERACTION_GRASP_VALUE, // /user/hand/XXXX/input/grasp_ext/value
WIVRN_HAND_INTERACTION_GRASP_READY, // /user/hand/XXXX/input/ready_ext/value
WIVRN_HAND_INTERACTION_INPUT_COUNT
};
enum class wivrn_input_type
{
BOOL,
FLOAT,
VEC2_X,
VEC2_Y,
POSE,
};
struct input_data
{
wivrn_hand_interaction_input_index index;
wivrn_input_type type;
xrt_device_type device;
};
input_data map_input(device_id id)
{
switch (id)
{
case device_id::LEFT_GRIP:
return {WIVRN_HAND_INTERACTION_GRIP_POSE, wivrn_input_type::POSE, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::RIGHT_GRIP:
return {WIVRN_HAND_INTERACTION_GRIP_POSE, wivrn_input_type::POSE, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
case device_id::LEFT_AIM:
return {WIVRN_HAND_INTERACTION_AIM_POSE, wivrn_input_type::POSE, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::RIGHT_AIM:
return {WIVRN_HAND_INTERACTION_AIM_POSE, wivrn_input_type::POSE, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
case device_id::LEFT_PALM:
return {WIVRN_HAND_INTERACTION_PALM_POSE, wivrn_input_type::POSE, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::RIGHT_PALM:
return {WIVRN_HAND_INTERACTION_PALM_POSE, wivrn_input_type::POSE, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
// XR_EXT_hand_interaction
case device_id::LEFT_PINCH_POSE:
return {WIVRN_HAND_INTERACTION_PINCH_POSE, wivrn_input_type::POSE, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::LEFT_PINCH_VALUE:
return {WIVRN_HAND_INTERACTION_PINCH_VALUE, wivrn_input_type::FLOAT, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::LEFT_PINCH_READY:
return {WIVRN_HAND_INTERACTION_PINCH_READY, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::RIGHT_PINCH_POSE:
return {WIVRN_HAND_INTERACTION_PINCH_POSE, wivrn_input_type::POSE, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
case device_id::RIGHT_PINCH_VALUE:
return {WIVRN_HAND_INTERACTION_PINCH_VALUE, wivrn_input_type::FLOAT, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
case device_id::RIGHT_PINCH_READY:
return {WIVRN_HAND_INTERACTION_PINCH_READY, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
case device_id::LEFT_POKE:
return {WIVRN_HAND_INTERACTION_POKE_POSE, wivrn_input_type::POSE, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::RIGHT_POKE:
return {WIVRN_HAND_INTERACTION_POKE_POSE, wivrn_input_type::POSE, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
case device_id::LEFT_AIM_ACTIVATE_VALUE:
return {WIVRN_HAND_INTERACTION_AIM_ACTIVATE_VALUE, wivrn_input_type::FLOAT, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::LEFT_AIM_ACTIVATE_READY:
return {WIVRN_HAND_INTERACTION_AIM_ACTIVATE_READY, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::LEFT_GRASP_VALUE:
return {WIVRN_HAND_INTERACTION_GRASP_VALUE, wivrn_input_type::FLOAT, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::LEFT_GRASP_READY:
return {WIVRN_HAND_INTERACTION_GRASP_READY, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::RIGHT_AIM_ACTIVATE_VALUE:
return {WIVRN_HAND_INTERACTION_AIM_ACTIVATE_VALUE, wivrn_input_type::FLOAT, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
case device_id::RIGHT_AIM_ACTIVATE_READY:
return {WIVRN_HAND_INTERACTION_AIM_ACTIVATE_READY, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
case device_id::RIGHT_GRASP_VALUE:
return {WIVRN_HAND_INTERACTION_GRASP_VALUE, wivrn_input_type::FLOAT, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
case device_id::RIGHT_GRASP_READY:
return {WIVRN_HAND_INTERACTION_GRASP_READY, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
default:
break;
}
// If the headset supports hand_interaction_ext, upon switch
// to/from hand tracking we may get the inputs packet before
// the interaction profile change, so if we get a bad input
// just return an invalid index so we can ignore it
U_LOG_D("wivrn_hand_interaction: bad input id %s", std::string(magic_enum::enum_name(id)).c_str());
// the type here doesn't really matter
return {WIVRN_HAND_INTERACTION_INPUT_INVALID, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_UNKNOWN};
}
xrt_binding_input_pair hand_interaction_input_binding[] = {
{XRT_INPUT_HAND_GRIP_POSE, XRT_INPUT_HAND_GRIP_POSE},
{XRT_INPUT_HAND_AIM_POSE, XRT_INPUT_HAND_AIM_POSE},
{XRT_INPUT_HAND_PINCH_POSE, XRT_INPUT_HAND_PINCH_POSE},
{XRT_INPUT_HAND_PINCH_VALUE, XRT_INPUT_HAND_PINCH_VALUE},
{XRT_INPUT_HAND_PINCH_READY, XRT_INPUT_HAND_PINCH_READY},
{XRT_INPUT_HAND_POKE_POSE, XRT_INPUT_HAND_POKE_POSE},
{XRT_INPUT_HAND_AIM_ACTIVATE_READY, XRT_INPUT_HAND_AIM_ACTIVATE_READY},
{XRT_INPUT_HAND_AIM_ACTIVATE_VALUE, XRT_INPUT_HAND_AIM_ACTIVATE_VALUE},
{XRT_INPUT_HAND_GRASP_VALUE, XRT_INPUT_HAND_GRASP_VALUE},
{XRT_INPUT_HAND_GRASP_READY, XRT_INPUT_HAND_GRASP_READY},
};
xrt_binding_input_pair simple_input_binding[] = {
{XRT_INPUT_SIMPLE_SELECT_CLICK, XRT_INPUT_HAND_PINCH_VALUE},
{XRT_INPUT_SIMPLE_GRIP_POSE, XRT_INPUT_HAND_GRIP_POSE},
{XRT_INPUT_SIMPLE_AIM_POSE, XRT_INPUT_HAND_AIM_POSE},
};
xrt_binding_profile wivrn_binding_profiles[] = {
{
.name = XRT_DEVICE_EXT_HAND_INTERACTION,
.inputs = hand_interaction_input_binding,
.input_count = std::size(hand_interaction_input_binding),
.outputs = nullptr,
.output_count = 0,
},
{
.name = XRT_DEVICE_SIMPLE_CONTROLLER,
.inputs = simple_input_binding,
.input_count = std::size(simple_input_binding),
.outputs = nullptr,
.output_count = 0,
},
};
} // namespace
wivrn_hand_interaction::wivrn_hand_interaction(int hand_id,
xrt_device * hmd,
wivrn::wivrn_session * cnx) :
xrt_device{
.name = XRT_DEVICE_EXT_HAND_INTERACTION,
.device_type = hand_id == 0 ? XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER : XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER,
.hmd = nullptr,
.tracking_origin = hmd->tracking_origin,
.binding_profile_count = std::size(wivrn_binding_profiles),
.binding_profiles = wivrn_binding_profiles,
.input_count = WIVRN_HAND_INTERACTION_INPUT_COUNT,
.supported = {
.orientation_tracking = true,
.position_tracking = true,
},
.update_inputs = method_pointer<&wivrn_hand_interaction::update_inputs>,
.get_tracked_pose = method_pointer<&wivrn_hand_interaction::get_tracked_pose>,
.destroy = [](xrt_device *) {},
},
grip(hand_id == 0 ? device_id::LEFT_GRIP : device_id::RIGHT_GRIP),
aim(hand_id == 0 ? device_id::LEFT_AIM : device_id::RIGHT_AIM),
palm(hand_id == 0 ? device_id::LEFT_PALM : device_id::RIGHT_PALM),
pinch_ext(hand_id == 0 ? device_id::LEFT_PINCH_POSE : device_id::RIGHT_PINCH_POSE),
poke_ext(hand_id == 0 ? device_id::LEFT_POKE : device_id::RIGHT_POKE),
inputs_array(input_count, xrt_input{}),
cnx(cnx)
{
inputs = inputs_array.data();
// Setup input.
#define SET_INPUT(VENDOR, NAME) \
do \
{ \
inputs[WIVRN_HAND_INTERACTION_##NAME].name = XRT_INPUT_##VENDOR##_##NAME; \
inputs[WIVRN_HAND_INTERACTION_##NAME].active = true; \
} while (0)
if (auto grip_surface = configuration().grip_surface)
{
std::array<float, 3> angles = grip_surface.value();
float deg_2_rad = std::numbers::pi / 180.0;
xrt_vec3 rotation_angles{angles[0] * deg_2_rad, angles[1] * deg_2_rad, angles[2] * deg_2_rad};
xrt_pose offset = XRT_POSE_IDENTITY;
math_quat_from_euler_angles(&rotation_angles, &offset.orientation);
palm.set_derived(&grip, offset, true);
cnx->set_enabled(palm.device, false);
}
else if (not cnx->get_info().palm_pose)
{
palm.set_derived(&grip, XRT_POSE_IDENTITY, false);
cnx->set_enabled(palm.device, false);
}
SET_INPUT(HAND, AIM_POSE);
SET_INPUT(HAND, GRIP_POSE);
SET_INPUT(GENERIC, PALM_POSE);
SET_INPUT(HAND, PINCH_POSE);
SET_INPUT(HAND, PINCH_VALUE);
SET_INPUT(HAND, PINCH_READY);
SET_INPUT(HAND, POKE_POSE);
SET_INPUT(HAND, AIM_ACTIVATE_VALUE);
SET_INPUT(HAND, AIM_ACTIVATE_READY);
SET_INPUT(HAND, GRASP_VALUE);
SET_INPUT(HAND, GRASP_READY);
#undef SET_INPUT
inputs_staging = inputs_array;
// Make sure everything is mapped
for (const auto & item: inputs_array)
{
assert(item.name);
}
outputs = nullptr;
output_count = 0;
switch (hand_id)
{
case 0:
// Print name.
strcpy(str, "WiVRn left hand interaction");
strcpy(serial, "WiVRn left hand interaction");
break;
case 1:
// Print name.
strcpy(str, "WiVRn right hand interaction");
strcpy(serial, "WiVRn right hand interaction");
break;
default:
throw std::runtime_error("Invalid hand ID");
}
}
xrt_result_t wivrn_hand_interaction::update_inputs()
{
std::lock_guard _{mutex};
inputs_array = inputs_staging;
return XRT_SUCCESS;
}
void wivrn_hand_interaction::set_inputs(const from_headset::inputs & inputs, const clock_offset & clock_offset)
{
std::lock_guard lock{mutex};
for (auto & input: inputs_staging)
{
switch (XRT_GET_INPUT_TYPE(input.name))
{
case XRT_INPUT_TYPE_VEC1_ZERO_TO_ONE:
case XRT_INPUT_TYPE_VEC1_MINUS_ONE_TO_ONE:
case XRT_INPUT_TYPE_VEC2_MINUS_ONE_TO_ONE:
case XRT_INPUT_TYPE_VEC3_MINUS_ONE_TO_ONE:
case XRT_INPUT_TYPE_BOOLEAN:
input.active = false;
case XRT_INPUT_TYPE_POSE:
case XRT_INPUT_TYPE_HAND_TRACKING:
case XRT_INPUT_TYPE_FACE_TRACKING:
case XRT_INPUT_TYPE_BODY_TRACKING:
break;
}
}
for (const auto & input: inputs.values)
{
int64_t last_change_time = input.last_change_time ? clock_offset.from_headset(input.last_change_time) : 0;
auto [index, type, device] = map_input(input.id);
if (device != device_type)
continue;
assert(index > 0 and index < input_count);
inputs_staging[index].timestamp = last_change_time;
inputs_staging[index].active = true;
switch (type)
{
case wivrn_input_type::BOOL:
inputs_staging[index].value.boolean = (input.value != 0);
break;
case wivrn_input_type::FLOAT:
inputs_staging[index].value.vec1.x = input.value;
break;
case wivrn_input_type::VEC2_X:
inputs_staging[index].value.vec2.x = input.value;
break;
case wivrn_input_type::VEC2_Y:
inputs_staging[index].value.vec2.y = input.value;
break;
case wivrn_input_type::POSE:
// Pose should not be in the inputs array
U_LOG_W("Unexpected input id %d", int(input.id));
}
}
}
xrt_result_t wivrn_hand_interaction::get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns, xrt_space_relation * res)
{
std::chrono::nanoseconds extrapolation_time;
device_id device;
switch (name)
{
case XRT_INPUT_HAND_AIM_POSE:
std::tie(extrapolation_time, *res, device) = aim.get_pose_at(at_timestamp_ns);
cnx->set_enabled(device, true);
break;
case XRT_INPUT_HAND_GRIP_POSE:
std::tie(extrapolation_time, *res, device) = grip.get_pose_at(at_timestamp_ns);
cnx->set_enabled(device, true);
break;
case XRT_INPUT_GENERIC_PALM_POSE:
std::tie(extrapolation_time, *res, device) = palm.get_pose_at(at_timestamp_ns);
cnx->set_enabled(device, true);
break;
case XRT_INPUT_HAND_PINCH_POSE:
std::tie(extrapolation_time, *res, device) = pinch_ext.get_pose_at(at_timestamp_ns);
cnx->set_enabled(device, true);
break;
case XRT_INPUT_HAND_POKE_POSE:
std::tie(extrapolation_time, *res, device) = poke_ext.get_pose_at(at_timestamp_ns);
cnx->set_enabled(device, true);
break;
default:
U_LOG_XDEV_UNSUPPORTED_INPUT(this, u_log_get_global_level(), name);
return XRT_ERROR_INPUT_UNSUPPORTED;
}
cnx->add_predict_offset(extrapolation_time);
if (auto out = wivrn_controller::tracking_dump())
{
auto device = [&] {
switch (name)
{
case XRT_INPUT_HAND_AIM_POSE: return aim.device;
case XRT_INPUT_HAND_GRIP_POSE: return grip.device;
case XRT_INPUT_GENERIC_PALM_POSE: return palm.device;
case XRT_INPUT_HAND_PINCH_POSE: return pinch_ext.device;
case XRT_INPUT_HAND_POKE_POSE: return poke_ext.device;
default:
assert(false);
__builtin_unreachable();
} }();
*out->lock() << magic_enum::enum_name(device) << ','
<< os_monotonic_get_ns() << ','
<< at_timestamp_ns << ','
<< extrapolation_time.count() << ','
<< "g,"
<< *res << std::endl;
;
}
return XRT_SUCCESS;
}
void wivrn_hand_interaction::set_derived_pose(const from_headset::derived_pose & derived)
{
auto list = [this](device_id id) -> pose_list * {
for (auto item: {&grip, &aim, &palm})
{
if (item->device == id)
return item;
}
return nullptr;
};
auto source = list(derived.source);
auto target = list(derived.target);
if (source and target)
{
target->set_derived(source, xrt_cast(derived.relation));
if (source != target)
cnx->set_enabled(derived.target, false);
}
}
void wivrn_hand_interaction::update_tracking(const from_headset::tracking & tracking, const clock_offset & offset)
{
if (not aim.update_tracking(tracking, offset))
cnx->set_enabled(aim.device, false);
if (not grip.update_tracking(tracking, offset))
cnx->set_enabled(grip.device, false);
if (not palm.update_tracking(tracking, offset))
cnx->set_enabled(palm.device, false);
if (not pinch_ext.update_tracking(tracking, offset))
cnx->set_enabled(pinch_ext.device, false);
if (not poke_ext.update_tracking(tracking, offset))
cnx->set_enabled(poke_ext.device, false);
if (auto out = wivrn_controller::tracking_dump(); out and offset)
{
auto now = os_monotonic_get_ns();
auto locked = out->lock();
for (const auto & pose: tracking.device_poses)
{
if (pose.device == aim.device or pose.device == grip.device or pose.device == palm.device)
*locked << magic_enum::enum_name(pose.device) << ','
<< now << ','
<< offset.from_headset(tracking.timestamp) << ','
<< tracking.timestamp - tracking.production_timestamp << ','
<< "r,"
<< pose_list::convert_pose(pose) << std::endl;
}
}
}
void wivrn_hand_interaction::reset_history()
{
aim.reset();
grip.reset();
palm.reset();
pinch_ext.reset();
poke_ext.reset();
}
} // namespace wivrn
-65
View File
@@ -1,65 +0,0 @@
/*
* WiVRn VR streaming
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
* 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 "xrt/xrt_device.h"
#include "hand_joints_list.h"
#include "pose_list.h"
#include <mutex>
#include <vector>
namespace wivrn
{
class wivrn_session;
class wivrn_hand_interaction : public xrt_device
{
std::mutex mutex;
pose_list grip;
pose_list aim;
pose_list palm;
pose_list pinch_ext;
pose_list poke_ext;
std::vector<xrt_input> inputs_staging;
std::vector<xrt_input> inputs_array;
wivrn::wivrn_session * cnx;
public:
using base = xrt_device;
wivrn_hand_interaction(int hand_id, xrt_device * hmd, wivrn::wivrn_session * cnx);
xrt_result_t update_inputs();
xrt_result_t get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns, xrt_space_relation * out_relation);
void set_inputs(const from_headset::inputs &, const clock_offset &);
void set_derived_pose(const from_headset::derived_pose &);
void update_tracking(const from_headset::tracking &, const clock_offset &);
void reset_history();
};
} // namespace wivrn
+5 -4
View File
@@ -46,6 +46,7 @@
#include "wivrn_packets.h"
#include "xr/to_string.h"
#include "xrt/xrt_defines.h"
#include "xrt/xrt_device.h"
#include "xrt/xrt_session.h"
#include <algorithm>
@@ -151,10 +152,10 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
connection(std::move(connection)),
xrt_system(system),
hmd(this, get_info()),
left_controller(0, &hmd, this),
left_hand_interaction(0, &hmd, this),
right_controller(1, &hmd, this),
right_hand_interaction(1, &hmd, this)
left_controller(XRT_DEVICE_TOUCH_CONTROLLER, 0, &hmd, this),
right_controller(XRT_DEVICE_TOUCH_CONTROLLER, 1, &hmd, this),
left_hand_interaction(XRT_DEVICE_EXT_HAND_INTERACTION, 0, &hmd, this),
right_hand_interaction(XRT_DEVICE_EXT_HAND_INTERACTION, 1, &hmd, this)
{
try
{
+3 -4
View File
@@ -24,7 +24,6 @@
#include "utils/thread_safe.h"
#include "wivrn_connection.h"
#include "wivrn_controller.h"
#include "wivrn_hand_interaction.h"
#include "wivrn_hmd.h"
#include "wivrn_ipc.h"
#include "wivrn_packets.h"
@@ -117,11 +116,11 @@ class wivrn_session : public xrt_system_devices
wivrn_hmd hmd;
wivrn_controller left_controller;
int32_t left_controller_index;
wivrn_hand_interaction left_hand_interaction;
int32_t left_hand_interaction_index;
wivrn_controller right_controller;
int32_t right_controller_index;
wivrn_hand_interaction right_hand_interaction;
wivrn_controller left_hand_interaction;
int32_t left_hand_interaction_index;
wivrn_controller right_hand_interaction;
int32_t right_hand_interaction_index;
std::unique_ptr<wivrn_eye_tracker> eye_tracker;
std::unique_ptr<wivrn_android_face_tracker> android_face_tracker;