Finally, good input

This commit is contained in:
SDraw 2023-01-30 19:52:08 +03:00
parent d8c79ed15c
commit d48944a039
No known key found for this signature in database
GPG key ID: BB95B4DAB2BB8BB5
7 changed files with 102 additions and 77 deletions

View file

@ -114,7 +114,7 @@ namespace ml_amt
float l_currentHeight = Mathf.Clamp((l_hmdMatrix * ms_pointVector).y, 0f, float.MaxValue); 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_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); 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); 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) if(m_avatarHips != null)
@ -216,11 +216,11 @@ namespace ml_amt
Transform l_customTransform = PlayerSetup.Instance._avatar.transform.Find("CrouchLimit"); Transform l_customTransform = PlayerSetup.Instance._avatar.transform.Find("CrouchLimit");
m_customCrouchLimit = (l_customTransform != null); 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"); l_customTransform = PlayerSetup.Instance._avatar.transform.Find("ProneLimit");
m_customProneLimit = (l_customTransform != null); 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"); l_customTransform = PlayerSetup.Instance._avatar.transform.Find("LocomotionOffset");
m_customLocomotionOffset = (l_customTransform != null); m_customLocomotionOffset = (l_customTransform != null);
@ -305,7 +305,7 @@ namespace ml_amt
public void SetCrouchLimit(float p_value) public void SetCrouchLimit(float p_value)
{ {
if(!m_customCrouchLimit) if(!m_customCrouchLimit)
m_crouchLimit = Mathf.Clamp(p_value, 0f, 1f); m_crouchLimit = Mathf.Clamp01(p_value);
} }
public void SetIKOverrideProne(bool p_state) public void SetIKOverrideProne(bool p_state)
{ {
@ -314,7 +314,7 @@ namespace ml_amt
public void SetProneLimit(float p_value) public void SetProneLimit(float p_value)
{ {
if(!m_customProneLimit) if(!m_customProneLimit)
m_proneLimit = Mathf.Clamp(p_value, 0f, 1f); m_proneLimit = Mathf.Clamp01(p_value);
} }
public void SetPoseTransitions(bool p_state) public void SetPoseTransitions(bool p_state)
{ {

View file

@ -106,7 +106,7 @@ namespace ml_dht
if(m_avatarDescriptor != null) if(m_avatarDescriptor != null)
m_avatarDescriptor.useVisemeLipsync = false; 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.Jaw_Open] = m_mouthShapes.x * 100f;
p_component.BlendShapeValues[(int)LipShape_v2.Mouth_Pout] = ((m_mouthShapes.y > 0f) ? l_weight : 0f); p_component.BlendShapeValues[(int)LipShape_v2.Mouth_Pout] = ((m_mouthShapes.y > 0f) ? l_weight : 0f);

View file

@ -16,6 +16,7 @@ namespace ml_lme
CVRInputManager m_inputManager = null; CVRInputManager m_inputManager = null;
InputModuleSteamVR m_steamVrModule = null; InputModuleSteamVR m_steamVrModule = null;
bool m_inVR = false; bool m_inVR = false;
bool m_gripToGrab = true;
ControllerRay m_handRayLeft = null; ControllerRay m_handRayLeft = null;
ControllerRay m_handRayRight = null; ControllerRay m_handRayRight = null;
@ -78,9 +79,21 @@ namespace ml_lme
OnEnableChange(Settings.Enabled); OnEnableChange(Settings.Enabled);
OnInputChange(Settings.Input); OnInputChange(Settings.Input);
MelonLoader.MelonCoroutines.Start(WaitForSettings());
MelonLoader.MelonCoroutines.Start(WaitForMaterial()); 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() IEnumerator WaitForMaterial()
{ {
while(PlayerSetup.Instance == null) while(PlayerSetup.Instance == null)
@ -114,8 +127,8 @@ namespace ml_lme
SetFingersInput(l_data.m_rightHand, false); 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_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 || (VRTrackerManager.Instance.rightHand == null) || !VRTrackerManager.Instance.rightHand.active || !Settings.FingersOnly)); m_handRayRight.enabled = (l_data.m_rightHand.m_present && (!m_inVR || !Utils.IsRightHandTracked() || !Settings.FingersOnly));
} }
public override void UpdateInput() public override void UpdateInput()
@ -124,56 +137,60 @@ namespace ml_lme
{ {
GestureMatcher.LeapData l_data = LeapManager.GetInstance().GetLatestData(); 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; 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)) float l_interactValue = 0f;
{ if(m_gripToGrab)
m_gripLeft = (l_strength < Settings.ReleaseThreadhold); l_interactValue = Mathf.Clamp01(Mathf.InverseLerp(Mathf.Min(Settings.GripThreadhold, Settings.InteractThreadhold), Mathf.Max(Settings.GripThreadhold, Settings.InteractThreadhold), l_strength));
m_inputManager.gripLeftUp |= !m_gripLeft;
m_inputManager.gripLeftDown |= m_gripLeft;
}
if(m_gripLeft)
m_inputManager.gripLeftValue = Mathf.InverseLerp(Settings.ReleaseThreadhold, 0f, l_strength);
else 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; 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)) float l_interactValue = 0f;
{ if(m_gripToGrab)
m_gripRight = (l_strength < Settings.HoldThreadhold); l_interactValue = Mathf.Clamp01(Mathf.InverseLerp(Mathf.Min(Settings.GripThreadhold, Settings.InteractThreadhold), Mathf.Max(Settings.GripThreadhold, Settings.InteractThreadhold), l_strength));
m_inputManager.gripRightUp |= !m_gripRight;
m_inputManager.gripRightDown |= m_gripRight;
}
if(m_gripRight)
m_inputManager.gripRightValue = Mathf.InverseLerp(Settings.ReleaseThreadhold, 0f, l_strength);
else 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) void OnInputChange(bool p_state)
{ {
(m_handRayLeft as MonoBehaviour).enabled = (p_state && Settings.Enabled); ((MonoBehaviour)m_handRayLeft).enabled = (p_state && Settings.Enabled);
(m_handRayRight as MonoBehaviour).enabled = (p_state && Settings.Enabled); ((MonoBehaviour)m_handRayRight).enabled = (p_state && Settings.Enabled);
m_lineLeft.enabled = (p_state && Settings.Enabled); m_lineLeft.enabled = (p_state && Settings.Enabled);
m_lineRight.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]; 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;
}
} }
} }

View file

@ -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. * **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. * **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`. * 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.

View file

@ -33,8 +33,8 @@ namespace ml_lme
HeadZ, HeadZ,
TrackElbows, TrackElbows,
Input, Input,
HoldThreadhold, InteractThreadhold,
ReleaseThreadhold GripThreadhold
}; };
static bool ms_enabled = false; static bool ms_enabled = false;
@ -47,8 +47,8 @@ namespace ml_lme
static Vector3 ms_headOffset = new Vector3(0f, -0.3f, 0.15f); static Vector3 ms_headOffset = new Vector3(0f, -0.3f, 0.15f);
static bool ms_trackElbows = true; static bool ms_trackElbows = true;
static bool ms_input = true; static bool ms_input = true;
static float ms_holdThreadhold = 0.5f; static float ms_interactThreadhold = 0.8f;
static float ms_releaseThreadhold = 0.5f; static float ms_gripThreadhold = 0.4f;
static MelonLoader.MelonPreferences_Category ms_category = null; static MelonLoader.MelonPreferences_Category ms_category = null;
static List<MelonLoader.MelonPreferences_Entry> ms_entries = null; static List<MelonLoader.MelonPreferences_Entry> ms_entries = null;
@ -63,8 +63,8 @@ namespace ml_lme
static public event Action<Vector3> HeadOffsetChange; static public event Action<Vector3> HeadOffsetChange;
static public event Action<bool> TrackElbowsChange; static public event Action<bool> TrackElbowsChange;
static public event Action<bool> InputChange; static public event Action<bool> InputChange;
static public event Action<float> HoldThreadholdChange; static public event Action<float> InteractThreadholdChange;
static public event Action<float> ReleaseThreadholdChange; static public event Action<float> GripThreadholdChange;
internal static void Init() internal static void Init()
{ {
@ -88,8 +88,8 @@ namespace ml_lme
ms_category.CreateEntry(ModSetting.HeadZ.ToString(), 15), ms_category.CreateEntry(ModSetting.HeadZ.ToString(), 15),
ms_category.CreateEntry(ModSetting.TrackElbows.ToString(), true), ms_category.CreateEntry(ModSetting.TrackElbows.ToString(), true),
ms_category.CreateEntry(ModSetting.Input.ToString(), true), ms_category.CreateEntry(ModSetting.Input.ToString(), true),
ms_category.CreateEntry(ModSetting.HoldThreadhold.ToString(), 50), ms_category.CreateEntry(ModSetting.InteractThreadhold.ToString(), 80),
ms_category.CreateEntry(ModSetting.ReleaseThreadhold.ToString(), 50), ms_category.CreateEntry(ModSetting.GripThreadhold.ToString(), 40),
}; };
Load(); Load();
@ -144,8 +144,8 @@ namespace ml_lme
) * 0.01f; ) * 0.01f;
ms_trackElbows = (bool)ms_entries[(int)ModSetting.TrackElbows].BoxedValue; ms_trackElbows = (bool)ms_entries[(int)ModSetting.TrackElbows].BoxedValue;
ms_input = (bool)ms_entries[(int)ModSetting.Input].BoxedValue; ms_input = (bool)ms_entries[(int)ModSetting.Input].BoxedValue;
ms_holdThreadhold = (int)ms_entries[(int)ModSetting.HoldThreadhold].BoxedValue * 0.01f; ms_interactThreadhold = (int)ms_entries[(int)ModSetting.InteractThreadhold].BoxedValue * 0.01f;
ms_releaseThreadhold = (int)ms_entries[(int)ModSetting.ReleaseThreadhold].BoxedValue * 0.01f; ms_gripThreadhold = (int)ms_entries[(int)ModSetting.GripThreadhold].BoxedValue * 0.01f;
} }
static void OnToggleUpdate(string p_name, string p_value) static void OnToggleUpdate(string p_name, string p_value)
@ -265,16 +265,16 @@ namespace ml_lme
HeadOffsetChange?.Invoke(ms_headOffset); HeadOffsetChange?.Invoke(ms_headOffset);
} }
break; break;
case ModSetting.HoldThreadhold: case ModSetting.InteractThreadhold:
{ {
ms_holdThreadhold = int.Parse(p_value) * 0.01f; ms_interactThreadhold = int.Parse(p_value) * 0.01f;
HoldThreadholdChange?.Invoke(ms_holdThreadhold); InteractThreadholdChange?.Invoke(ms_interactThreadhold);
} }
break; break;
case ModSetting.ReleaseThreadhold: case ModSetting.GripThreadhold:
{ {
ms_releaseThreadhold = int.Parse(p_value) * 0.01f; ms_gripThreadhold = int.Parse(p_value) * 0.01f;
ReleaseThreadholdChange?.Invoke(ms_releaseThreadhold); GripThreadholdChange?.Invoke(ms_gripThreadhold);
} }
break; break;
} }
@ -341,13 +341,13 @@ namespace ml_lme
{ {
get => ms_input; 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;
} }
} }
} }

View file

@ -10,9 +10,10 @@ namespace ml_lme
static readonly Quaternion ms_hmdRotationFix = new Quaternion(0f, 0.7071068f, 0.7071068f, 0f); static readonly Quaternion ms_hmdRotationFix = new Quaternion(0f, 0.7071068f, 0.7071068f, 0f);
static readonly Quaternion ms_screentopRotationFix = new Quaternion(0f, 0f, -1f, 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 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) public static Matrix4x4 GetMatrix(this Transform p_transform, bool p_pos = true, bool p_rot = true, bool p_scl = false)
{ {

View file

@ -393,16 +393,16 @@ function inp_dropdown_mod_lme(_obj, _callbackName) {
</div> </div>
<div class ="row-wrapper"> <div class ="row-wrapper">
<div class ="option-caption">Hold gesture threadhold: </div> <div class ="option-caption">Interact gesture threadhold: </div>
<div class ="option-input"> <div class ="option-input">
<div id="HoldThreadhold" class ="inp_slider no-scroll" data-min="0" data-max="100" data-current="50"></div> <div id="InteractThreadhold" class ="inp_slider no-scroll" data-min="0" data-max="100" data-current="80"></div>
</div> </div>
</div> </div>
<div class ="row-wrapper"> <div class ="row-wrapper">
<div class ="option-caption">Release gesture threadhold: </div> <div class ="option-caption">Grip gesture threadhold: </div>
<div class ="option-input"> <div class ="option-input">
<div id="ReleaseThreadhold" class ="inp_slider no-scroll" data-min="0" data-max="100" data-current="50"></div> <div id="GripThreadhold" class ="inp_slider no-scroll" data-min="0" data-max="100" data-current="40"></div>
</div> </div>
</div> </div>
`; `;