Finger tracking sync only if hands are tracked

This commit is contained in:
SDraw 2023-03-16 09:23:22 +03:00
parent cae6a8a19c
commit c90119e20a
No known key found for this signature in database
GPG key ID: BB95B4DAB2BB8BB5
2 changed files with 15 additions and 6 deletions

View file

@ -11,8 +11,6 @@ namespace ml_lme
[DisallowMultipleComponent] [DisallowMultipleComponent]
class LeapInput : CVRInputModule class LeapInput : CVRInputModule
{ {
static readonly FieldInfo ms_indexGestureToggle = typeof(InputModuleOpenXR).GetField("_steamVrIndexGestureToggleValue", BindingFlags.Instance | BindingFlags.NonPublic);
CVRInputManager m_inputManager = null; CVRInputManager m_inputManager = null;
InputModuleOpenXR m_openXrModule = null; InputModuleOpenXR m_openXrModule = null;
bool m_inVR = false; bool m_inVR = false;
@ -123,8 +121,18 @@ namespace ml_lme
{ {
if(l_data.m_leftHand.m_present) if(l_data.m_leftHand.m_present)
SetFingersInput(l_data.m_leftHand, true); SetFingersInput(l_data.m_leftHand, true);
if(l_data.m_rightHand.m_present) if(l_data.m_rightHand.m_present)
SetFingersInput(l_data.m_rightHand, false); SetFingersInput(l_data.m_rightHand, false);
if(m_inVR)
{
m_inputManager.individualFingerTracking = !m_openXrModule.GetIndexGestureToggle();
m_inputManager.individualFingerTracking |= (l_data.m_leftHand.m_present || l_data.m_rightHand.m_present);
}
else
m_inputManager.individualFingerTracking = (l_data.m_leftHand.m_present || l_data.m_rightHand.m_present);
IKSystem.Instance.FingerSystem.controlActive = m_inputManager.individualFingerTracking;
} }
m_handRayLeft.enabled = (l_data.m_leftHand.m_present && (!m_inVR || !Utils.IsLeftHandTracked() || !Settings.FingersOnly)); m_handRayLeft.enabled = (l_data.m_leftHand.m_present && (!m_inVR || !Utils.IsLeftHandTracked() || !Settings.FingersOnly));
@ -240,15 +248,12 @@ namespace ml_lme
// Arbitrary // Arbitrary
void UpdateFingerTracking() void UpdateFingerTracking()
{ {
m_inputManager.individualFingerTracking = (Settings.Enabled || (m_inVR && m_openXrModule.AreKnucklesInUse() && !(bool)ms_indexGestureToggle.GetValue(m_openXrModule))); m_inputManager.individualFingerTracking = (Settings.Enabled || (m_inVR && m_openXrModule.AreKnucklesInUse() && !m_openXrModule.GetIndexGestureToggle()));
IKSystem.Instance.FingerSystem.controlActive = m_inputManager.individualFingerTracking; IKSystem.Instance.FingerSystem.controlActive = m_inputManager.individualFingerTracking;
} }
void SetFingersInput(GestureMatcher.HandData p_hand, bool p_left) void SetFingersInput(GestureMatcher.HandData p_hand, bool p_left)
{ {
m_inputManager.individualFingerTracking = true;
IKSystem.Instance.FingerSystem.controlActive = true;
if(p_left) if(p_left)
{ {
m_inputManager.fingerCurlLeftThumb = p_hand.m_bends[0]; m_inputManager.fingerCurlLeftThumb = p_hand.m_bends[0];
@ -267,6 +272,7 @@ namespace ml_lme
} }
} }
// Game settings
void OnGameSettingBoolChange(string p_name, bool p_state) void OnGameSettingBoolChange(string p_name, bool p_state)
{ {
if(p_name == "ControlUseGripToGrab") if(p_name == "ControlUseGripToGrab")

View file

@ -12,11 +12,14 @@ namespace ml_lme
static readonly Quaternion ms_screentopRotationFix = new Quaternion(0f, 0f, -1f, 0f); static readonly Quaternion ms_screentopRotationFix = new Quaternion(0f, 0f, -1f, 0f);
static readonly FieldInfo ms_leftControllerName = typeof(InputModuleOpenXR).GetField("_leftHandControllerName", BindingFlags.NonPublic | BindingFlags.Instance); static readonly FieldInfo ms_leftControllerName = typeof(InputModuleOpenXR).GetField("_leftHandControllerName", BindingFlags.NonPublic | BindingFlags.Instance);
static readonly FieldInfo ms_rightControllerName = typeof(InputModuleOpenXR).GetField("_rightHandControllerName", BindingFlags.NonPublic | BindingFlags.Instance); static readonly FieldInfo ms_rightControllerName = typeof(InputModuleOpenXR).GetField("_rightHandControllerName", BindingFlags.NonPublic | BindingFlags.Instance);
static readonly FieldInfo ms_indexGestureToggle = typeof(InputModuleOpenXR).GetField("_steamVrIndexGestureToggleValue", BindingFlags.Instance | BindingFlags.NonPublic);
public static bool IsInVR() => ((CheckVR.Instance != null) && CheckVR.Instance.hasVrDeviceLoaded); public static bool IsInVR() => ((CheckVR.Instance != null) && CheckVR.Instance.hasVrDeviceLoaded);
public static bool AreKnucklesInUse(this InputModuleOpenXR p_module) => (((string)ms_leftControllerName.GetValue(p_module)).Contains("Index") || ((string)ms_rightControllerName.GetValue(p_module)).Contains("Index")); public static bool AreKnucklesInUse(this InputModuleOpenXR p_module) => (((string)ms_leftControllerName.GetValue(p_module)).Contains("Index") || ((string)ms_rightControllerName.GetValue(p_module)).Contains("Index"));
public static bool GetIndexGestureToggle(this InputModuleOpenXR p_module) => (bool)ms_indexGestureToggle.GetValue(p_module);
public static bool IsLeftHandTracked() => InputDevices.GetDeviceAtXRNode(XRNode.LeftHand).isValid; public static bool IsLeftHandTracked() => InputDevices.GetDeviceAtXRNode(XRNode.LeftHand).isValid;
public static bool IsRightHandTracked() => InputDevices.GetDeviceAtXRNode(XRNode.RightHand).isValid; public static bool IsRightHandTracked() => InputDevices.GetDeviceAtXRNode(XRNode.RightHand).isValid;
public static Matrix4x4 GetMatrix(this Transform p_transform, bool p_pos = true, bool p_rot = true, bool p_scl = false) public static Matrix4x4 GetMatrix(this Transform p_transform, bool p_pos = true, bool p_rot = true, bool p_scl = false)
{ {