From d48944a039954cfb1277ae8190df3e62f84d987d Mon Sep 17 00:00:00 2001 From: SDraw Date: Mon, 30 Jan 2023 19:52:08 +0300 Subject: [PATCH] Finally, good input --- ml_amt/MotionTweaker.cs | 10 ++-- ml_dht/HeadTracked.cs | 2 +- ml_lme/LeapInput.cs | 111 +++++++++++++++++++++++---------------- ml_lme/README.md | 3 +- ml_lme/Settings.cs | 40 +++++++------- ml_lme/Utils.cs | 5 +- ml_lme/resources/menu.js | 8 +-- 7 files changed, 102 insertions(+), 77 deletions(-) diff --git a/ml_amt/MotionTweaker.cs b/ml_amt/MotionTweaker.cs index c9077cd..c21e6cf 100644 --- a/ml_amt/MotionTweaker.cs +++ b/ml_amt/MotionTweaker.cs @@ -114,7 +114,7 @@ namespace ml_amt float l_currentHeight = Mathf.Clamp((l_hmdMatrix * ms_pointVector).y, 0f, float.MaxValue); float l_avatarScale = (m_avatarScale > 0f) ? (PlayerSetup.Instance._avatar.transform.localScale.y / m_avatarScale) : 0f; float l_avatarViewHeight = Mathf.Clamp(m_viewPointHeight * l_avatarScale, 0f, float.MaxValue); - m_upright = Mathf.Clamp(((l_avatarViewHeight > 0f) ? (l_currentHeight / l_avatarViewHeight) : 0f), 0f, 1f); + m_upright = Mathf.Clamp01((l_avatarViewHeight > 0f) ? (l_currentHeight / l_avatarViewHeight) : 0f); m_poseState = (m_upright <= Mathf.Min(m_proneLimit, m_crouchLimit)) ? PoseState.Proning : ((m_upright <= Mathf.Max(m_proneLimit, m_crouchLimit)) ? PoseState.Crouching : PoseState.Standing); if(m_avatarHips != null) @@ -216,11 +216,11 @@ namespace ml_amt Transform l_customTransform = PlayerSetup.Instance._avatar.transform.Find("CrouchLimit"); m_customCrouchLimit = (l_customTransform != null); - m_crouchLimit = m_customCrouchLimit ? Mathf.Clamp(l_customTransform.localPosition.y, 0f, 1f) : Settings.CrouchLimit; + m_crouchLimit = m_customCrouchLimit ? Mathf.Clamp01(l_customTransform.localPosition.y) : Settings.CrouchLimit; l_customTransform = PlayerSetup.Instance._avatar.transform.Find("ProneLimit"); m_customProneLimit = (l_customTransform != null); - m_proneLimit = m_customProneLimit ? Mathf.Clamp(l_customTransform.localPosition.y, 0f, 1f) : Settings.ProneLimit; + m_proneLimit = m_customProneLimit ? Mathf.Clamp01(l_customTransform.localPosition.y) : Settings.ProneLimit; l_customTransform = PlayerSetup.Instance._avatar.transform.Find("LocomotionOffset"); m_customLocomotionOffset = (l_customTransform != null); @@ -305,7 +305,7 @@ namespace ml_amt public void SetCrouchLimit(float p_value) { if(!m_customCrouchLimit) - m_crouchLimit = Mathf.Clamp(p_value, 0f, 1f); + m_crouchLimit = Mathf.Clamp01(p_value); } public void SetIKOverrideProne(bool p_state) { @@ -314,7 +314,7 @@ namespace ml_amt public void SetProneLimit(float p_value) { if(!m_customProneLimit) - m_proneLimit = Mathf.Clamp(p_value, 0f, 1f); + m_proneLimit = Mathf.Clamp01(p_value); } public void SetPoseTransitions(bool p_state) { diff --git a/ml_dht/HeadTracked.cs b/ml_dht/HeadTracked.cs index 7282ed3..a7ac529 100644 --- a/ml_dht/HeadTracked.cs +++ b/ml_dht/HeadTracked.cs @@ -106,7 +106,7 @@ namespace ml_dht if(m_avatarDescriptor != null) m_avatarDescriptor.useVisemeLipsync = false; - float l_weight = Mathf.Clamp(Mathf.InverseLerp(0.25f, 1f, Mathf.Abs(m_mouthShapes.y)), 0f, 1f) * 100f; + float l_weight = Mathf.Clamp01(Mathf.InverseLerp(0.25f, 1f, Mathf.Abs(m_mouthShapes.y))) * 100f; p_component.BlendShapeValues[(int)LipShape_v2.Jaw_Open] = m_mouthShapes.x * 100f; p_component.BlendShapeValues[(int)LipShape_v2.Mouth_Pout] = ((m_mouthShapes.y > 0f) ? l_weight : 0f); diff --git a/ml_lme/LeapInput.cs b/ml_lme/LeapInput.cs index 882c00a..697d95e 100644 --- a/ml_lme/LeapInput.cs +++ b/ml_lme/LeapInput.cs @@ -16,6 +16,7 @@ namespace ml_lme CVRInputManager m_inputManager = null; InputModuleSteamVR m_steamVrModule = null; bool m_inVR = false; + bool m_gripToGrab = true; ControllerRay m_handRayLeft = null; ControllerRay m_handRayRight = null; @@ -78,9 +79,21 @@ namespace ml_lme OnEnableChange(Settings.Enabled); OnInputChange(Settings.Input); + MelonLoader.MelonCoroutines.Start(WaitForSettings()); MelonLoader.MelonCoroutines.Start(WaitForMaterial()); } + IEnumerator WaitForSettings() + { + while(MetaPort.Instance == null) + yield return null; + while(MetaPort.Instance.settings == null) + yield return null; + + m_gripToGrab = MetaPort.Instance.settings.GetSettingsBool("ControlUseGripToGrab", true); + MetaPort.Instance.settings.settingBoolChanged.AddListener(this.OnGameSettingBoolChange); + } + IEnumerator WaitForMaterial() { while(PlayerSetup.Instance == null) @@ -114,8 +127,8 @@ namespace ml_lme SetFingersInput(l_data.m_rightHand, false); } - m_handRayLeft.enabled = (l_data.m_leftHand.m_present && (!m_inVR || (VRTrackerManager.Instance.leftHand == null) || !VRTrackerManager.Instance.leftHand.active || !Settings.FingersOnly)); - m_handRayRight.enabled = (l_data.m_rightHand.m_present && (!m_inVR || (VRTrackerManager.Instance.rightHand == null) || !VRTrackerManager.Instance.rightHand.active || !Settings.FingersOnly)); + m_handRayLeft.enabled = (l_data.m_leftHand.m_present && (!m_inVR || !Utils.IsLeftHandTracked() || !Settings.FingersOnly)); + m_handRayRight.enabled = (l_data.m_rightHand.m_present && (!m_inVR || !Utils.IsRightHandTracked() || !Settings.FingersOnly)); } public override void UpdateInput() @@ -124,56 +137,60 @@ namespace ml_lme { GestureMatcher.LeapData l_data = LeapManager.GetInstance().GetLatestData(); - if(l_data.m_leftHand.m_present && (!m_inVR || (VRTrackerManager.Instance.leftHand == null) || !VRTrackerManager.Instance.leftHand.active || !Settings.FingersOnly)) + if(l_data.m_leftHand.m_present && (!m_inVR || !Utils.IsLeftHandTracked() || !Settings.FingersOnly)) { float l_strength = l_data.m_leftHand.m_grabStrength; - if(m_interactLeft != (l_strength > Settings.HoldThreadhold)) - { - m_interactLeft = (l_strength > Settings.HoldThreadhold); - m_inputManager.interactLeftUp |= !m_interactLeft; - m_inputManager.interactLeftDown |= m_interactLeft; - } - if(m_interactLeft) - m_inputManager.interactLeftValue = Mathf.InverseLerp(Settings.HoldThreadhold, 1f, l_strength); - else - m_inputManager.interactLeftValue = Mathf.Max(0f, m_inputManager.interactLeftValue); - if(m_gripLeft != (l_strength < Settings.ReleaseThreadhold)) - { - m_gripLeft = (l_strength < Settings.ReleaseThreadhold); - m_inputManager.gripLeftUp |= !m_gripLeft; - m_inputManager.gripLeftDown |= m_gripLeft; - } - if(m_gripLeft) - m_inputManager.gripLeftValue = Mathf.InverseLerp(Settings.ReleaseThreadhold, 0f, l_strength); + float l_interactValue = 0f; + if(m_gripToGrab) + l_interactValue = Mathf.Clamp01(Mathf.InverseLerp(Mathf.Min(Settings.GripThreadhold, Settings.InteractThreadhold), Mathf.Max(Settings.GripThreadhold, Settings.InteractThreadhold), l_strength)); else - m_inputManager.gripLeftValue = Mathf.Max(0f, m_inputManager.gripLeftValue); + l_interactValue = Mathf.Clamp01(Mathf.InverseLerp(0f, Settings.InteractThreadhold, l_strength)); + m_inputManager.interactLeftValue = Mathf.Max(l_interactValue, m_inputManager.interactLeftValue); + + if(m_interactLeft != (l_strength > Settings.InteractThreadhold)) + { + m_interactLeft = (l_strength > Settings.InteractThreadhold); + m_inputManager.interactLeftDown |= m_interactLeft; + m_inputManager.interactLeftUp |= !m_interactLeft; + } + + float l_gripValue = Mathf.Clamp01(Mathf.InverseLerp(0f, Settings.GripThreadhold, l_strength)); + m_inputManager.gripLeftValue = Mathf.Max(l_gripValue, m_inputManager.gripLeftValue); + if(m_gripLeft != (l_strength > Settings.GripThreadhold)) + { + m_gripLeft = (l_strength > Settings.GripThreadhold); + m_inputManager.gripLeftDown |= m_gripLeft; + m_inputManager.gripLeftUp |= !m_gripLeft; + } } - if(l_data.m_rightHand.m_present && (!m_inVR || (VRTrackerManager.Instance.rightHand == null) || !VRTrackerManager.Instance.rightHand.active || !Settings.FingersOnly)) + if(l_data.m_rightHand.m_present && (!m_inVR || !Utils.IsRightHandTracked() || !Settings.FingersOnly)) { float l_strength = l_data.m_rightHand.m_grabStrength; - if(m_interactRight != (l_strength > Settings.HoldThreadhold)) - { - m_interactRight = (l_strength > Settings.HoldThreadhold); - m_inputManager.interactRightUp |= !m_interactRight; - m_inputManager.interactRightDown |= m_interactRight; - } - if(m_interactRight) - m_inputManager.interactRightValue = Mathf.InverseLerp(Settings.HoldThreadhold, 1f, l_strength); - else - m_inputManager.interactRightValue = Mathf.Max(0f, m_inputManager.interactRightValue); - if(m_gripRight != (l_strength < Settings.HoldThreadhold)) - { - m_gripRight = (l_strength < Settings.HoldThreadhold); - m_inputManager.gripRightUp |= !m_gripRight; - m_inputManager.gripRightDown |= m_gripRight; - } - if(m_gripRight) - m_inputManager.gripRightValue = Mathf.InverseLerp(Settings.ReleaseThreadhold, 0f, l_strength); + float l_interactValue = 0f; + if(m_gripToGrab) + l_interactValue = Mathf.Clamp01(Mathf.InverseLerp(Mathf.Min(Settings.GripThreadhold, Settings.InteractThreadhold), Mathf.Max(Settings.GripThreadhold, Settings.InteractThreadhold), l_strength)); else - m_inputManager.gripRightValue = Mathf.Max(0f, m_inputManager.gripRightValue); + l_interactValue = Mathf.Clamp01(Mathf.InverseLerp(0f, Settings.InteractThreadhold, l_strength)); + m_inputManager.interactRightValue = Mathf.Max(l_interactValue, m_inputManager.interactRightValue); + + if(m_interactRight != (l_strength > Settings.InteractThreadhold)) + { + m_interactRight = (l_strength > Settings.InteractThreadhold); + m_inputManager.interactRightDown |= m_interactRight; + m_inputManager.interactRightUp |= !m_interactRight; + } + + float l_gripValue = Mathf.Clamp01(Mathf.InverseLerp(0f, Settings.GripThreadhold, l_strength)); + m_inputManager.gripRightValue = Mathf.Max(l_gripValue, m_inputManager.gripRightValue); + if(m_gripRight != (l_strength > Settings.GripThreadhold)) + { + m_gripRight = (l_strength > Settings.GripThreadhold); + m_inputManager.gripRightDown |= m_gripRight; + m_inputManager.gripRightUp |= !m_gripRight; + } } } } @@ -187,8 +204,8 @@ namespace ml_lme void OnInputChange(bool p_state) { - (m_handRayLeft as MonoBehaviour).enabled = (p_state && Settings.Enabled); - (m_handRayRight as MonoBehaviour).enabled = (p_state && Settings.Enabled); + ((MonoBehaviour)m_handRayLeft).enabled = (p_state && Settings.Enabled); + ((MonoBehaviour)m_handRayRight).enabled = (p_state && Settings.Enabled); m_lineLeft.enabled = (p_state && Settings.Enabled); m_lineRight.enabled = (p_state && Settings.Enabled); @@ -259,5 +276,11 @@ namespace ml_lme IKSystem.Instance.FingerSystem.rightPinkyCurl = p_hand.m_bends[4]; } } + + void OnGameSettingBoolChange(string p_name, bool p_state) + { + if(p_name == "ControlUseGripToGrab") + m_gripToGrab = p_state; + } } } diff --git a/ml_lme/README.md b/ml_lme/README.md index 8b9f656..b9c5322 100644 --- a/ml_lme/README.md +++ b/ml_lme/README.md @@ -23,4 +23,5 @@ Available mod's settings in `Settings - Implementation - Leap Motion Tracking`: * **Model visibility:** show Leap Motion controller model, useful for tracking visualizing, disabled by default. * **Interaction input:** enables in-game interactions (props, menu and etc.); `true` by default. * Note: Suggested to use with disabled `Settings - Input & Key-Bindings - Use grip to grab`. -* **Hold/Release gesture threadhold:** limits for interaction/grip activation based on hand gesture; 50 by default. +* **Interact gesture threadhold:** activation limit for interaction based on hand gesture; 80 by default. +* **Grip gesture threadhold:** activation limit for grip based on hand gesture; 40 by default. diff --git a/ml_lme/Settings.cs b/ml_lme/Settings.cs index a28f0a2..0015b43 100644 --- a/ml_lme/Settings.cs +++ b/ml_lme/Settings.cs @@ -33,8 +33,8 @@ namespace ml_lme HeadZ, TrackElbows, Input, - HoldThreadhold, - ReleaseThreadhold + InteractThreadhold, + GripThreadhold }; static bool ms_enabled = false; @@ -47,8 +47,8 @@ namespace ml_lme static Vector3 ms_headOffset = new Vector3(0f, -0.3f, 0.15f); static bool ms_trackElbows = true; static bool ms_input = true; - static float ms_holdThreadhold = 0.5f; - static float ms_releaseThreadhold = 0.5f; + static float ms_interactThreadhold = 0.8f; + static float ms_gripThreadhold = 0.4f; static MelonLoader.MelonPreferences_Category ms_category = null; static List ms_entries = null; @@ -63,8 +63,8 @@ namespace ml_lme static public event Action HeadOffsetChange; static public event Action TrackElbowsChange; static public event Action InputChange; - static public event Action HoldThreadholdChange; - static public event Action ReleaseThreadholdChange; + static public event Action InteractThreadholdChange; + static public event Action GripThreadholdChange; internal static void Init() { @@ -88,8 +88,8 @@ namespace ml_lme ms_category.CreateEntry(ModSetting.HeadZ.ToString(), 15), ms_category.CreateEntry(ModSetting.TrackElbows.ToString(), true), ms_category.CreateEntry(ModSetting.Input.ToString(), true), - ms_category.CreateEntry(ModSetting.HoldThreadhold.ToString(), 50), - ms_category.CreateEntry(ModSetting.ReleaseThreadhold.ToString(), 50), + ms_category.CreateEntry(ModSetting.InteractThreadhold.ToString(), 80), + ms_category.CreateEntry(ModSetting.GripThreadhold.ToString(), 40), }; Load(); @@ -144,8 +144,8 @@ namespace ml_lme ) * 0.01f; ms_trackElbows = (bool)ms_entries[(int)ModSetting.TrackElbows].BoxedValue; ms_input = (bool)ms_entries[(int)ModSetting.Input].BoxedValue; - ms_holdThreadhold = (int)ms_entries[(int)ModSetting.HoldThreadhold].BoxedValue * 0.01f; - ms_releaseThreadhold = (int)ms_entries[(int)ModSetting.ReleaseThreadhold].BoxedValue * 0.01f; + ms_interactThreadhold = (int)ms_entries[(int)ModSetting.InteractThreadhold].BoxedValue * 0.01f; + ms_gripThreadhold = (int)ms_entries[(int)ModSetting.GripThreadhold].BoxedValue * 0.01f; } static void OnToggleUpdate(string p_name, string p_value) @@ -265,16 +265,16 @@ namespace ml_lme HeadOffsetChange?.Invoke(ms_headOffset); } break; - case ModSetting.HoldThreadhold: + case ModSetting.InteractThreadhold: { - ms_holdThreadhold = int.Parse(p_value) * 0.01f; - HoldThreadholdChange?.Invoke(ms_holdThreadhold); + ms_interactThreadhold = int.Parse(p_value) * 0.01f; + InteractThreadholdChange?.Invoke(ms_interactThreadhold); } break; - case ModSetting.ReleaseThreadhold: + case ModSetting.GripThreadhold: { - ms_releaseThreadhold = int.Parse(p_value) * 0.01f; - ReleaseThreadholdChange?.Invoke(ms_releaseThreadhold); + ms_gripThreadhold = int.Parse(p_value) * 0.01f; + GripThreadholdChange?.Invoke(ms_gripThreadhold); } break; } @@ -341,13 +341,13 @@ namespace ml_lme { get => ms_input; } - public static float HoldThreadhold + public static float InteractThreadhold { - get => ms_holdThreadhold; + get => ms_interactThreadhold; } - public static float ReleaseThreadhold + public static float GripThreadhold { - get => ms_releaseThreadhold; + get => ms_gripThreadhold; } } } diff --git a/ml_lme/Utils.cs b/ml_lme/Utils.cs index 1a05cef..a113e64 100644 --- a/ml_lme/Utils.cs +++ b/ml_lme/Utils.cs @@ -10,9 +10,10 @@ namespace ml_lme static readonly Quaternion ms_hmdRotationFix = new Quaternion(0f, 0.7071068f, 0.7071068f, 0f); static readonly Quaternion ms_screentopRotationFix = new Quaternion(0f, 0f, -1f, 0f); - public static bool AreKnucklesInUse() => PlayerSetup.Instance._trackerManager.trackerNames.Contains("knuckles"); - public static bool IsInVR() => ((ABI_RC.Core.Savior.CheckVR.Instance != null) && ABI_RC.Core.Savior.CheckVR.Instance.hasVrDeviceLoaded); + public static bool AreKnucklesInUse() => PlayerSetup.Instance._trackerManager.trackerNames.Contains("knuckles"); + public static bool IsLeftHandTracked() => ((VRTrackerManager.Instance.leftHand != null) && VRTrackerManager.Instance.leftHand.active); + public static bool IsRightHandTracked() => ((VRTrackerManager.Instance.rightHand != null) && VRTrackerManager.Instance.rightHand.active); public static Matrix4x4 GetMatrix(this Transform p_transform, bool p_pos = true, bool p_rot = true, bool p_scl = false) { diff --git a/ml_lme/resources/menu.js b/ml_lme/resources/menu.js index 8b8cd52..3a54314 100644 --- a/ml_lme/resources/menu.js +++ b/ml_lme/resources/menu.js @@ -393,16 +393,16 @@ function inp_dropdown_mod_lme(_obj, _callbackName) {
-
Hold gesture threadhold:
+
Interact gesture threadhold:
-
+
-
Release gesture threadhold:
+
Grip gesture threadhold:
-
+
`;