diff --git a/dist/leapify/resources/localization/localization_en_us.json b/dist/leapify/resources/localization/localization_en_us.json index 469aa5a..9434b9c 100644 --- a/dist/leapify/resources/localization/localization_en_us.json +++ b/dist/leapify/resources/localization/localization_en_us.json @@ -1,13 +1,14 @@ { - "language_tag": "en_US", + "language_tag": "en_US", - "Settings_Title": "Leapify", - "Setting_toggle_on": "Enabled", - "Setting_toggle_off": "Disabled", - "Setting_hand_tracking": "Hand Tracking", - "Setting_skeletal_passthrough": "Skeletal data passthrough", - "Setting_position_passthrough": "Position data passthrough", - "Setting_automatic_switch": "Auto Switch Hand Tracking And Controllers", - "Setting_automatic_offset": "Automatic Hand Offset", - "Setting_manual_offset": "Manual Hand Offset (mm)" + "Settings_Title": "Leapify", + "Setting_toggle_on": "Enabled", + "Setting_toggle_off": "Disabled", + "Setting_hand_tracking": "Hand Tracking", + "Setting_skeletal_passthrough": "Skeletal data passthrough", + "Setting_position_passthrough": "Position data passthrough", + "Setting_automatic_switch": "Auto Switch Hand Tracking And Controllers", + "Setting_automatic_offset": "Automatic Hand Offset", + "Setting_fallback_tracker": "Fallback to Tracker position", + "Setting_manual_offset": "Manual Hand Offset (mm)" } \ No newline at end of file diff --git a/dist/leapify/resources/settings/default.vrsettings b/dist/leapify/resources/settings/default.vrsettings index 7e48657..4675f13 100644 --- a/dist/leapify/resources/settings/default.vrsettings +++ b/dist/leapify/resources/settings/default.vrsettings @@ -8,6 +8,7 @@ "positionalDataPassthrough": false, "automaticControllerSwitching": false, "automaticHandOffset": true, - "manualHandOffset": 0.0 + "manualHandOffset": 0.0, + "fallbackTrackerPosition": false } } \ No newline at end of file diff --git a/dist/leapify/resources/settings/settingsschema.vrsettings b/dist/leapify/resources/settings/settingsschema.vrsettings index 9b4d7a8..7ffb578 100644 --- a/dist/leapify/resources/settings/settingsschema.vrsettings +++ b/dist/leapify/resources/settings/settingsschema.vrsettings @@ -40,6 +40,16 @@ "on_label": "#{leapify}Setting_toggle_on", "off_label": "#{leapify}Setting_toggle_off" }, + { + "name": "/settings/driver_leapify/fallbackTrackerPosition", + "control": "toggle", + "label": "#{leapify}Setting_fallback_tracker", + "on_label": "#{leapify}Setting_toggle_on", + "off_label": "#{leapify}Setting_toggle_off", + "requires": { + "/settings/driver_leapify/positionalDataPassthrough": false + } + }, { "name": "/settings/driver_leapify/manualHandOffset", "control": "slider", diff --git a/src/InterfaceHook.cpp b/src/InterfaceHook.cpp index b5400f2..b1d4b1b 100644 --- a/src/InterfaceHook.cpp +++ b/src/InterfaceHook.cpp @@ -49,7 +49,7 @@ void InterfaceHook::GetGenericInterface(void* interfacePtr, const char* pchInter auto pose = newPose; auto props = vr::VRProperties()->TrackedDeviceToPropertyContainer(unWhichDevice); auto manufacturer = vr::VRProperties()->GetStringProperty(props, vr::ETrackedDeviceProperty::Prop_ManufacturerName_String); - auto trackingSystem = vr::VRProperties()->GetStringProperty(props, vr::ETrackedDeviceProperty::Prop_TrackingSystemName_String); + auto type = vr::VRProperties()->GetStringProperty(props, vr::ETrackedDeviceProperty::Prop_ControllerType_String); auto device_class = vr::VRProperties()->GetInt32Property(props, vr::ETrackedDeviceProperty::Prop_DeviceClass_Int32); auto role = vr::VRProperties()->GetInt32Property(props, vr::ETrackedDeviceProperty::Prop_ControllerRoleHint_Int32); @@ -64,6 +64,17 @@ void InterfaceHook::GetGenericInterface(void* interfacePtr, const char* pchInter } } + if (device_class == vr::TrackedDeviceClass_GenericTracker) + { + if (vr::VRSettings()->GetBool("driver_leapify", "handTrackingEnabled") && vr::VRSettings()->GetBool("driver_leapify", "fallbackTrackerPosition")) + { + if (type == "vive_tracker_handed" || type == "lighthouse_tracker" || type == "etee_tracker_handed") + { + StateManager::Get().setFallbackPose(pose, static_cast(role)); + } + } + } + orig(self, unWhichDevice, pose, unPoseStructSize); }); diff --git a/src/StateManager.hpp b/src/StateManager.hpp index c9821f5..b483db9 100644 --- a/src/StateManager.hpp +++ b/src/StateManager.hpp @@ -73,6 +73,23 @@ class StateManager { else m_passthroughPoseRight = pose; } + + vr::DriverPose_t getFallbackPose(vr::ETrackedControllerRole role) const + { + if (role == vr::TrackedControllerRole_LeftHand) + return m_fallbackPoseLeft; + if (role == vr::TrackedControllerRole_RightHand) + return m_fallbackPoseRight; + return vr::DriverPose_t(); + } + + void setFallbackPose(vr::DriverPose_t pose, vr::ETrackedControllerRole role) + { + if (role == vr::TrackedControllerRole_LeftHand) + m_fallbackPoseLeft = pose; + else + m_fallbackPoseRight = pose; + } private: vr::VRBoneTransform_t* m_passThroughTransformLeft { nullptr }; vr::VRBoneTransform_t* m_passThroughTransformRight { nullptr }; @@ -80,4 +97,6 @@ class StateManager { std::map m_controllerStates { }; vr::DriverPose_t m_passthroughPoseLeft { }; vr::DriverPose_t m_passthroughPoseRight { }; + vr::DriverPose_t m_fallbackPoseLeft{ }; + vr::DriverPose_t m_fallbackPoseRight{ }; }; \ No newline at end of file diff --git a/src/TrackedController.cpp b/src/TrackedController.cpp index 7633e4f..1df413d 100644 --- a/src/TrackedController.cpp +++ b/src/TrackedController.cpp @@ -129,7 +129,8 @@ void TrackedController::DebugRequest(const char* pchRequest, char* pchResponseBu vr::DriverPose_t TrackedController::GetPose() { - StateManager::Get().setLeapPose(m_pose, m_role); + if (vr::VRSettings()->GetBool("driver_leapify", "positionalDataPassthrough")) + StateManager::Get().setLeapPose(m_pose, m_role); return m_pose; } @@ -233,6 +234,8 @@ void TrackedController::UpdatePose(LeapHand hand) vr::VRServerDriverHost()->TrackedDevicePoseUpdated(m_objectId, GetPose(), sizeof(vr::DriverPose_t)); } else { + if (vr::VRSettings()->GetBool("driver_leapify", "fallbackTrackerPosition")) + m_pose = StateManager::Get().getFallbackPose(m_role); vr::VRServerDriverHost()->TrackedDevicePoseUpdated(m_objectId, GetPose(), sizeof(vr::DriverPose_t)); } }