diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 94195bab1f..1e012beea1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -403,6 +403,8 @@ jobs: run: | g++ -std=c++17 -Wall -Wextra -Werror -pthread tools/vr/tests/test_xr_tracking.cpp -o /tmp/test-xr-tracking /tmp/test-xr-tracking + g++ -std=c++17 -Wall -Wextra -Werror tools/vr/tests/test_xr_touch.cpp -o /tmp/test-xr-touch + /tmp/test-xr-touch g++ -std=c++17 -Wall -Wextra -Werror -pthread tools/vr/tests/test_xr_vsync.cpp -o /tmp/test-xr-vsync /tmp/test-xr-vsync g++ -std=c++17 -Wall -Wextra -Werror -pthread tools/vr/tests/test_xr_frames.cpp -o /tmp/test-xr-frames diff --git a/docs/development/quest-openxr.md b/docs/development/quest-openxr.md index 199d9e5aa1..247d71d00e 100644 --- a/docs/development/quest-openxr.md +++ b/docs/development/quest-openxr.md @@ -309,6 +309,27 @@ bundled into the user-facing runtime. A valid already-signaled SYNC_FD value of ## Remaining stages +### Touch input profile + +Fresh XR controller activation now selects SteamVR's built-in `oculus_touch` +profile and handed Quest Plus render model instead of presenting real Touch +controllers as Vive wands. Face buttons, joystick click, left menu, analog grip +and capacitive touches are separate inputs. A/B and X/Y no longer double as +trackpad or menu clicks; the Quest's reserved system button is not fabricated +from its left application menu. Native OpenXR captures trigger, thumbstick, +thumbrest and face-button touch actions in previously unused button bits, keeping +the 296-byte tracking layout and existing low click bits compatible. Inactive +hands clear every input; invalid analog values are sanitized. The flat Cardboard +gamepad path retains its existing Vive profile and mappings. + +Host tests cover the input decoder's independent clicks, touch-versus-press, +handed menu, analog ranges and inactive reset. The Android native frontend and +Linux driver compile locally. SteamVR profile acceptance, game bindings and the +physical right controller still require connected-device validation. Profile +and component paths follow the [OpenXR Touch profile](https://registry.khronos.org/OpenXR/specs/1.0-khr/html/xrspec.html#_oculus_touch_controller_profile) +and ALVR's [OpenVR properties](https://github.com/alvr-org/ALVR/blob/ebec107b7e5f81677fb9c631d239daf2110bf573/alvr/server_openvr/src/props.rs) +and [input paths](https://github.com/alvr-org/ALVR/blob/ebec107b7e5f81677fb9c631d239daf2110bf573/alvr/server_openvr/cpp/alvr_server/Paths.cpp). + ### Experimental producer lease `DROIDDECK_VR_PRODUCER_LEASE=1` opts the compositor into a private, same-UID, diff --git a/questxr/src/main/cpp/quest_xr.cpp b/questxr/src/main/cpp/quest_xr.cpp index 4566691f00..8f0de07498 100644 --- a/questxr/src/main/cpp/quest_xr.cpp +++ b/questxr/src/main/cpp/quest_xr.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -150,6 +151,8 @@ private: XrAction grip_ = XR_NULL_HANDLE, trigger_ = XR_NULL_HANDLE, vibration_ = XR_NULL_HANDLE; XrAction squeeze_ = XR_NULL_HANDLE, stick_ = XR_NULL_HANDLE, stickClick_ = XR_NULL_HANDLE; XrAction primary_ = XR_NULL_HANDLE, secondary_ = XR_NULL_HANDLE, menu_ = XR_NULL_HANDLE; + XrAction triggerTouch_ = XR_NULL_HANDLE, stickTouch_ = XR_NULL_HANDLE, primaryTouch_ = XR_NULL_HANDLE; + XrAction secondaryTouch_ = XR_NULL_HANDLE, thumbrestTouch_ = XR_NULL_HANDLE; DroidDeckXrHand inputs_[2]{}; PFN_xrConvertTimeToTimespecTimeKHR convertTime_ = nullptr; bool timespecSupported_ = false; @@ -347,17 +350,27 @@ private: action("primary", XR_ACTION_TYPE_BOOLEAN_INPUT, &primary_); action("secondary", XR_ACTION_TYPE_BOOLEAN_INPUT, &secondary_); action("menu", XR_ACTION_TYPE_BOOLEAN_INPUT, &menu_); + action("trigger_touch", XR_ACTION_TYPE_BOOLEAN_INPUT, &triggerTouch_); + action("stick_touch", XR_ACTION_TYPE_BOOLEAN_INPUT, &stickTouch_); + action("primary_touch", XR_ACTION_TYPE_BOOLEAN_INPUT, &primaryTouch_); + action("secondary_touch", XR_ACTION_TYPE_BOOLEAN_INPUT, &secondaryTouch_); + action("thumbrest_touch", XR_ACTION_TYPE_BOOLEAN_INPUT, &thumbrestTouch_); action("vibration", XR_ACTION_TYPE_VIBRATION_OUTPUT, &vibration_); std::vector bindings; for (const char *hand : {"left", "right"}) { std::string root = std::string("/user/hand/") + hand; bindings.push_back({grip_, path((root + "/input/grip/pose").c_str())}); bindings.push_back({trigger_, path((root + "/input/trigger/value").c_str())}); + bindings.push_back({triggerTouch_, path((root + "/input/trigger/touch").c_str())}); bindings.push_back({squeeze_, path((root + "/input/squeeze/value").c_str())}); bindings.push_back({stick_, path((root + "/input/thumbstick").c_str())}); bindings.push_back({stickClick_, path((root + "/input/thumbstick/click").c_str())}); + bindings.push_back({stickTouch_, path((root + "/input/thumbstick/touch").c_str())}); + bindings.push_back({thumbrestTouch_, path((root + "/input/thumbrest/touch").c_str())}); bindings.push_back({primary_, path((root + (std::strcmp(hand, "left") == 0 ? "/input/x/click" : "/input/a/click")).c_str())}); bindings.push_back({secondary_, path((root + (std::strcmp(hand, "left") == 0 ? "/input/y/click" : "/input/b/click")).c_str())}); + bindings.push_back({primaryTouch_, path((root + (std::strcmp(hand, "left") == 0 ? "/input/x/touch" : "/input/a/touch")).c_str())}); + bindings.push_back({secondaryTouch_, path((root + (std::strcmp(hand, "left") == 0 ? "/input/y/touch" : "/input/b/touch")).c_str())}); bindings.push_back({vibration_, path((root + "/output/haptic").c_str())}); } bindings.push_back({menu_, path("/user/hand/left/input/menu/click")}); @@ -703,11 +716,16 @@ private: inputs_[hand].stick[0] = stick.isActive ? stick.currentState.x : 0; inputs_[hand].stick[1] = stick.isActive ? stick.currentState.y : 0; inputs_[hand].buttons = 0; - XrAction buttons[] = {stickClick_, primary_, secondary_, menu_}; - for (int button = 0; button < 4; button++) { - get.action = buttons[button]; + const std::pair buttons[] = { + {stickClick_, DROIDDECK_XR_STICK_CLICK}, {primary_, DROIDDECK_XR_PRIMARY_CLICK}, + {secondary_, DROIDDECK_XR_SECONDARY_CLICK}, {menu_, DROIDDECK_XR_MENU_CLICK}, + {triggerTouch_, DROIDDECK_XR_TRIGGER_TOUCH}, {stickTouch_, DROIDDECK_XR_STICK_TOUCH}, + {primaryTouch_, DROIDDECK_XR_PRIMARY_TOUCH}, {secondaryTouch_, DROIDDECK_XR_SECONDARY_TOUCH}, + {thumbrestTouch_, DROIDDECK_XR_THUMBREST_TOUCH}}; + for (const auto &button : buttons) { + get.action = button.first; XrActionStateBoolean value{XR_TYPE_ACTION_STATE_BOOLEAN}; check(xrGetActionStateBoolean(session_, &get, &value), "button state"); - if (value.isActive && value.currentState) inputs_[hand].buttons |= 1u << button; + if (value.isActive && value.currentState) inputs_[hand].buttons |= button.second; } bool pressed = trigger.isActive && trigger.currentState > 0.8f; if (pressed && !pressed_[hand]) { diff --git a/tools/vr/src/driver_droiddeck.cpp b/tools/vr/src/driver_droiddeck.cpp index e9b4b432e7..273c3c157d 100644 --- a/tools/vr/src/driver_droiddeck.cpp +++ b/tools/vr/src/driver_droiddeck.cpp @@ -20,6 +20,7 @@ #include "xr_tracking_file.h" #include "xr_frame_math.h" #include "xr_vsync_timing.h" +#include "xr_touch_input.h" #define DD_EXPORT extern "C" __attribute__((visibility("default"))) @@ -385,12 +386,17 @@ public: EVRInitError Activate(uint32_t id) override { id_ = id; PropertyContainerHandle_t c = VRProperties()->TrackedDeviceToPropertyContainer(id_); - VRProperties()->SetStringProperty(c, Prop_ModelNumber_String, "DroidDeck Pad Hand"); - VRProperties()->SetStringProperty(c, Prop_ManufacturerName_String, "DroidDeck"); + XrTrackingFile tracking; + DroidDeckXrTracking packet{}; + xrMode_ = tracking.Read(&packet) && XrTrackingFile::Fresh(packet); + VRProperties()->SetStringProperty(c, Prop_ModelNumber_String, xrMode_ ? "DroidDeck Quest Touch" : "DroidDeck Pad Hand"); + VRProperties()->SetStringProperty(c, Prop_ManufacturerName_String, xrMode_ ? "Meta" : "DroidDeck"); VRProperties()->SetStringProperty(c, Prop_TrackingSystemName_String, "droiddeck"); - VRProperties()->SetStringProperty(c, Prop_RenderModelName_String, "generic_controller"); - VRProperties()->SetStringProperty(c, Prop_ControllerType_String, "vive_controller"); - VRProperties()->SetStringProperty(c, Prop_InputProfilePath_String, "{htc}/input/vive_controller_profile.json"); + VRProperties()->SetStringProperty(c, Prop_RenderModelName_String, xrMode_ ? + (right_ ? "oculus_quest_plus_controller_right" : "oculus_quest_plus_controller_left") : "generic_controller"); + VRProperties()->SetStringProperty(c, Prop_ControllerType_String, xrMode_ ? "oculus_touch" : "vive_controller"); + VRProperties()->SetStringProperty(c, Prop_InputProfilePath_String, xrMode_ ? + "{oculus}/input/touch_profile.json" : "{htc}/input/vive_controller_profile.json"); VRProperties()->SetInt32Property(c, Prop_ControllerRoleHint_Int32, right_ ? TrackedControllerRole_RightHand : TrackedControllerRole_LeftHand); VRProperties()->SetInt32Property(c, Prop_DeviceClass_Int32, TrackedDeviceClass_Controller); @@ -400,12 +406,21 @@ public: in->CreateBooleanComponent(c, "/input/grip/click", &grip_); in->CreateBooleanComponent(c, "/input/trigger/click", &triggerClick_); in->CreateScalarComponent(c, "/input/trigger/value", &trigger_, VRScalarType_Absolute, VRScalarUnits_NormalizedOneSided); - in->CreateScalarComponent(c, "/input/trackpad/x", &padX_, VRScalarType_Absolute, VRScalarUnits_NormalizedTwoSided); - in->CreateScalarComponent(c, "/input/trackpad/y", &padY_, VRScalarType_Absolute, VRScalarUnits_NormalizedTwoSided); - in->CreateBooleanComponent(c, "/input/trackpad/click", &padClick_); - in->CreateBooleanComponent(c, "/input/trackpad/touch", &padTouch_); + in->CreateScalarComponent(c, xrMode_ ? "/input/joystick/x" : "/input/trackpad/x", &padX_, VRScalarType_Absolute, VRScalarUnits_NormalizedTwoSided); + in->CreateScalarComponent(c, xrMode_ ? "/input/joystick/y" : "/input/trackpad/y", &padY_, VRScalarType_Absolute, VRScalarUnits_NormalizedTwoSided); + in->CreateBooleanComponent(c, xrMode_ ? "/input/joystick/click" : "/input/trackpad/click", &padClick_); + in->CreateBooleanComponent(c, xrMode_ ? "/input/joystick/touch" : "/input/trackpad/touch", &padTouch_); + if (xrMode_) { + in->CreateScalarComponent(c, "/input/grip/value", &gripValue_, VRScalarType_Absolute, VRScalarUnits_NormalizedOneSided); + in->CreateBooleanComponent(c, "/input/trigger/touch", &triggerTouch_); + in->CreateBooleanComponent(c, right_ ? "/input/a/click" : "/input/x/click", &primaryClick_); + in->CreateBooleanComponent(c, right_ ? "/input/b/click" : "/input/y/click", &secondaryClick_); + in->CreateBooleanComponent(c, right_ ? "/input/a/touch" : "/input/x/touch", &primaryTouch_); + in->CreateBooleanComponent(c, right_ ? "/input/b/touch" : "/input/y/touch", &secondaryTouch_); + in->CreateBooleanComponent(c, "/input/thumbrest/touch", &thumbrestTouch_); + } in->CreateHapticComponent(c, "/output/haptic", &haptic_); - Log("%s hand activated (game pad)", right_ ? "right" : "left"); + Log("%s hand activated (%s)", right_ ? "right" : "left", xrMode_ ? "Quest Touch" : "game pad"); return VRInitError_None; } void Deactivate() override { id_ = k_unTrackedDeviceIndexInvalid; } @@ -430,16 +445,26 @@ public: pose.result = pose.poseIsValid ? TrackingResult_Running_OK : TrackingResult_Running_OutOfRange; pose_ = pose; VRServerDriverHost()->TrackedDevicePoseUpdated(id_, pose, sizeof(pose)); - VRDriverInput()->UpdateScalarComponent(trigger_, hand.active ? hand.trigger : 0, 0); - VRDriverInput()->UpdateBooleanComponent(triggerClick_, hand.active && hand.trigger > 0.6f, 0); - VRDriverInput()->UpdateBooleanComponent(grip_, hand.active && hand.squeeze > 0.6f, 0); - VRDriverInput()->UpdateScalarComponent(padX_, hand.active ? hand.stick[0] : 0, 0); - VRDriverInput()->UpdateScalarComponent(padY_, hand.active ? hand.stick[1] : 0, 0); - VRDriverInput()->UpdateBooleanComponent(padClick_, hand.active && (hand.buttons & 3u), 0); - VRDriverInput()->UpdateBooleanComponent(padTouch_, hand.active && - (std::abs(hand.stick[0]) + std::abs(hand.stick[1]) > 0.01f || (hand.buttons & 1u)), 0); - VRDriverInput()->UpdateBooleanComponent(menu_, hand.active && (hand.buttons & 12u), 0); - VRDriverInput()->UpdateBooleanComponent(system_, hand.active && !right_ && (hand.buttons & 8u), 0); + XrTouchInput input = xr_touch_input(hand, right_); + auto driverInput = VRDriverInput(); + driverInput->UpdateScalarComponent(trigger_, input.trigger, 0); + driverInput->UpdateBooleanComponent(triggerClick_, input.triggerClick, 0); + driverInput->UpdateBooleanComponent(grip_, input.gripClick, 0); + driverInput->UpdateScalarComponent(padX_, input.stickX, 0); + driverInput->UpdateScalarComponent(padY_, input.stickY, 0); + driverInput->UpdateBooleanComponent(padClick_, input.stickClick, 0); + driverInput->UpdateBooleanComponent(padTouch_, input.stickTouch, 0); + driverInput->UpdateBooleanComponent(menu_, input.menuClick, 0); + driverInput->UpdateBooleanComponent(system_, false, 0); + if (xrMode_) { + driverInput->UpdateScalarComponent(gripValue_, input.grip, 0); + driverInput->UpdateBooleanComponent(triggerTouch_, input.triggerTouch, 0); + driverInput->UpdateBooleanComponent(primaryClick_, input.primaryClick, 0); + driverInput->UpdateBooleanComponent(secondaryClick_, input.secondaryClick, 0); + driverInput->UpdateBooleanComponent(primaryTouch_, input.primaryTouch, 0); + driverInput->UpdateBooleanComponent(secondaryTouch_, input.secondaryTouch, 0); + driverInput->UpdateBooleanComponent(thumbrestTouch_, input.thumbrestTouch, 0); + } } void Update(const HmdQuaternion_t &head, const PadState *pad) { @@ -479,10 +504,13 @@ public: private: bool right_; + bool xrMode_ = false; uint32_t id_ = k_unTrackedDeviceIndexInvalid; DriverPose_t pose_ = {}; VRInputComponentHandle_t system_ = 0, menu_ = 0, grip_ = 0, triggerClick_ = 0, trigger_ = 0, padX_ = 0, padY_ = 0, padClick_ = 0, padTouch_ = 0, haptic_ = 0; + VRInputComponentHandle_t gripValue_ = 0, triggerTouch_ = 0, primaryClick_ = 0, secondaryClick_ = 0, + primaryTouch_ = 0, secondaryTouch_ = 0, thumbrestTouch_ = 0; }; class CardboardHmd : public ITrackedDeviceServerDriver, public IVRDisplayComponent { diff --git a/tools/vr/src/xr_touch_input.h b/tools/vr/src/xr_touch_input.h new file mode 100644 index 0000000000..d35273396f --- /dev/null +++ b/tools/vr/src/xr_touch_input.h @@ -0,0 +1,33 @@ +#pragma once +#include "xr_tracking.h" +#include +#include + +struct XrTouchInput { + float trigger = 0, grip = 0, stickX = 0, stickY = 0; + bool triggerClick = false, gripClick = false, stickClick = false; + bool primaryClick = false, secondaryClick = false, menuClick = false; + bool triggerTouch = false, stickTouch = false, primaryTouch = false, secondaryTouch = false, thumbrestTouch = false; +}; + +inline XrTouchInput xr_touch_input(const DroidDeckXrHand &hand, bool right) { + XrTouchInput input; + if (!hand.active) return input; + auto scalar = [](float value, float minimum) { return std::isfinite(value) ? std::clamp(value, minimum, 1.f) : 0.f; }; + input.trigger = scalar(hand.trigger, 0); + input.grip = scalar(hand.squeeze, 0); + input.stickX = scalar(hand.stick[0], -1); + input.stickY = scalar(hand.stick[1], -1); + input.triggerClick = input.trigger > 0.6f; + input.gripClick = input.grip > 0.6f; + input.stickClick = hand.buttons & DROIDDECK_XR_STICK_CLICK; + input.primaryClick = hand.buttons & DROIDDECK_XR_PRIMARY_CLICK; + input.secondaryClick = hand.buttons & DROIDDECK_XR_SECONDARY_CLICK; + input.menuClick = !right && (hand.buttons & DROIDDECK_XR_MENU_CLICK); + input.triggerTouch = hand.buttons & DROIDDECK_XR_TRIGGER_TOUCH; + input.stickTouch = hand.buttons & DROIDDECK_XR_STICK_TOUCH; + input.primaryTouch = hand.buttons & DROIDDECK_XR_PRIMARY_TOUCH; + input.secondaryTouch = hand.buttons & DROIDDECK_XR_SECONDARY_TOUCH; + input.thumbrestTouch = hand.buttons & DROIDDECK_XR_THUMBREST_TOUCH; + return input; +} diff --git a/tools/vr/src/xr_tracking.h b/tools/vr/src/xr_tracking.h index 8289e66c9c..aa864fa4a8 100644 --- a/tools/vr/src/xr_tracking.h +++ b/tools/vr/src/xr_tracking.h @@ -4,6 +4,15 @@ #define DROIDDECK_XR_MAGIC 0x52584444u #define DROIDDECK_XR_VERSION 1u #define DROIDDECK_XR_FILE "droiddeck-xr-tracking" +#define DROIDDECK_XR_STICK_CLICK (1u << 0) +#define DROIDDECK_XR_PRIMARY_CLICK (1u << 1) +#define DROIDDECK_XR_SECONDARY_CLICK (1u << 2) +#define DROIDDECK_XR_MENU_CLICK (1u << 3) +#define DROIDDECK_XR_TRIGGER_TOUCH (1u << 4) +#define DROIDDECK_XR_STICK_TOUCH (1u << 5) +#define DROIDDECK_XR_PRIMARY_TOUCH (1u << 6) +#define DROIDDECK_XR_SECONDARY_TOUCH (1u << 7) +#define DROIDDECK_XR_THUMBREST_TOUCH (1u << 8) struct DroidDeckXrPose { float orientation[4]; diff --git a/tools/vr/tests/test_xr_touch.cpp b/tools/vr/tests/test_xr_touch.cpp new file mode 100644 index 0000000000..24e86a45c9 --- /dev/null +++ b/tools/vr/tests/test_xr_touch.cpp @@ -0,0 +1,49 @@ +#include "../src/xr_touch_input.h" +#include +#include +#include + +int main() { + DroidDeckXrHand hand{}; + hand.active = 1; + hand.trigger = 0.7f; hand.squeeze = 0.8f; + hand.stick[0] = -0.4f; hand.stick[1] = 0.9f; + auto input = xr_touch_input(hand, false); + assert(input.trigger == hand.trigger && input.grip == hand.squeeze && input.triggerClick && input.gripClick); + assert(input.stickX == -0.4f && input.stickY == 0.9f); + assert(!input.stickTouch && !input.stickClick && !input.primaryClick && !input.secondaryClick && !input.menuClick); + hand.buttons = DROIDDECK_XR_PRIMARY_CLICK; + input = xr_touch_input(hand, false); + assert(input.primaryClick && !input.secondaryClick && !input.stickClick && !input.menuClick && !input.primaryTouch); + hand.buttons = DROIDDECK_XR_SECONDARY_CLICK; + input = xr_touch_input(hand, true); + assert(input.secondaryClick && !input.primaryClick && !input.menuClick && !input.stickClick); + hand.buttons = DROIDDECK_XR_STICK_CLICK; + input = xr_touch_input(hand, true); + assert(input.stickClick && !input.primaryClick && !input.stickTouch); + hand.buttons = DROIDDECK_XR_MENU_CLICK; + assert(xr_touch_input(hand, false).menuClick); + assert(!xr_touch_input(hand, true).menuClick); + hand.buttons = DROIDDECK_XR_TRIGGER_TOUCH | DROIDDECK_XR_STICK_TOUCH | DROIDDECK_XR_PRIMARY_TOUCH | + DROIDDECK_XR_SECONDARY_TOUCH | DROIDDECK_XR_THUMBREST_TOUCH; + hand.trigger = hand.squeeze = 0; + input = xr_touch_input(hand, false); + assert(input.triggerTouch && input.stickTouch && input.primaryTouch && input.secondaryTouch && input.thumbrestTouch); + assert(!input.triggerClick && !input.gripClick && !input.primaryClick && !input.secondaryClick && !input.stickClick); + hand.trigger = 2; hand.squeeze = -2; hand.stick[0] = -3; hand.stick[1] = 3; + input = xr_touch_input(hand, false); + assert(input.trigger == 1 && input.grip == 0 && input.stickX == -1 && input.stickY == 1); + hand.trigger = std::numeric_limits::quiet_NaN(); + hand.squeeze = std::numeric_limits::infinity(); + hand.stick[0] = hand.trigger; hand.stick[1] = -hand.squeeze; + input = xr_touch_input(hand, false); + assert(input.trigger == 0 && input.grip == 0 && input.stickX == 0 && input.stickY == 0); + hand.active = 0; + hand.buttons = UINT32_MAX; + hand.trigger = hand.squeeze = hand.stick[0] = hand.stick[1] = 1; + input = xr_touch_input(hand, false); + assert(input.trigger == 0 && input.grip == 0 && input.stickX == 0 && input.stickY == 0); + assert(!input.triggerClick && !input.gripClick && !input.stickClick && !input.primaryClick && !input.secondaryClick && !input.menuClick); + assert(!input.triggerTouch && !input.stickTouch && !input.primaryTouch && !input.secondaryTouch && !input.thumbrestTouch); + std::puts("Touch input: independent face/stick/menu, real capacitive touch, analog grip, clamping and inactive reset passed"); +}