Skip to content

Commit

Permalink
Add vive tracker fallback position option
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyabsi committed Jul 30, 2024
1 parent 1dace41 commit 79af733
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 13 deletions.
21 changes: 11 additions & 10 deletions dist/leapify/resources/localization/localization_en_us.json
Original file line number Diff line number Diff line change
@@ -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)"
}
3 changes: 2 additions & 1 deletion dist/leapify/resources/settings/default.vrsettings
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"positionalDataPassthrough": false,
"automaticControllerSwitching": false,
"automaticHandOffset": true,
"manualHandOffset": 0.0
"manualHandOffset": 0.0,
"fallbackTrackerPosition": false
}
}
10 changes: 10 additions & 0 deletions dist/leapify/resources/settings/settingsschema.vrsettings
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 12 additions & 1 deletion src/InterfaceHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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<vr::ETrackedControllerRole>(role));
}
}
}

orig(self, unWhichDevice, pose, unPoseStructSize);
});

Expand Down
19 changes: 19 additions & 0 deletions src/StateManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,30 @@ 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 };
std::vector<TransformHook> m_transformHooks { };
std::map<int, bool> m_controllerStates { };
vr::DriverPose_t m_passthroughPoseLeft { };
vr::DriverPose_t m_passthroughPoseRight { };
vr::DriverPose_t m_fallbackPoseLeft{ };
vr::DriverPose_t m_fallbackPoseRight{ };
};
5 changes: 4 additions & 1 deletion src/TrackedController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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));
}
}
Expand Down

0 comments on commit 79af733

Please sign in to comment.