From 0440baa84fdae7586ea7565e122bde2078567024 Mon Sep 17 00:00:00 2001 From: SDraw Date: Mon, 24 Apr 2023 22:18:30 +0300 Subject: [PATCH] Fingers values reset Hips transform restore after pose modification --- ml_lme/LeapInput.cs | 62 +++++++++++++++++++++++++++++++ ml_lme/LeapTracked.cs | 13 +++++++ ml_lme/Properties/AssemblyInfo.cs | 6 +-- ml_pam/ArmMover.cs | 15 ++++++++ ml_pam/Properties/AssemblyInfo.cs | 6 +-- 5 files changed, 96 insertions(+), 6 deletions(-) diff --git a/ml_lme/LeapInput.cs b/ml_lme/LeapInput.cs index 9cf5545..03b3762 100644 --- a/ml_lme/LeapInput.cs +++ b/ml_lme/LeapInput.cs @@ -15,6 +15,8 @@ namespace ml_lme bool m_inVR = false; bool m_gripToGrab = true; + bool m_handVisibleLeft = false; + bool m_handVisibleRight = false; ControllerRay m_handRayLeft = null; ControllerRay m_handRayRight = null; LineRenderer m_lineLeft = null; @@ -121,10 +123,32 @@ namespace ml_lme if(Settings.Enabled) { if(l_data.m_leftHand.m_present) + { SetFingersInput(l_data.m_leftHand, true); + m_handVisibleLeft = true; + } + else + { + if(m_handVisibleLeft) + { + ResetFingers(true); + m_handVisibleLeft = false; + } + } if(l_data.m_rightHand.m_present) + { SetFingersInput(l_data.m_rightHand, false); + m_handVisibleRight = true; + } + else + { + if(m_handVisibleRight) + { + ResetFingers(false); + m_handVisibleRight = false; + } + } if(m_inVR) { @@ -209,6 +233,8 @@ namespace ml_lme { OnInputChange(p_state && Settings.Input); UpdateFingerTracking(); + m_handVisibleLeft &= p_state; + m_handVisibleRight &= p_state; } void OnInputChange(bool p_state) @@ -251,6 +277,12 @@ namespace ml_lme { m_inputManager.individualFingerTracking = (Settings.Enabled || (m_inVR && Utils.AreKnucklesInUse() && !m_steamVrModule.GetIndexGestureToggle())); IKSystem.Instance.FingerSystem.controlActive = m_inputManager.individualFingerTracking; + + if(!Settings.Enabled) + { + ResetFingers(true); + ResetFingers(false); + } } void SetFingersInput(GestureMatcher.HandData p_hand, bool p_left) @@ -283,6 +315,36 @@ namespace ml_lme } } + void ResetFingers(bool p_left) + { + if(p_left) + { + m_inputManager.fingerCurlLeftThumb = 0f; + m_inputManager.fingerCurlLeftIndex = 0f; + m_inputManager.fingerCurlLeftMiddle = 0f; + m_inputManager.fingerCurlLeftRing = 0f; + m_inputManager.fingerCurlLeftPinky = 0f; + IKSystem.Instance.FingerSystem.leftThumbCurl = 0f; + IKSystem.Instance.FingerSystem.leftIndexCurl = 0f; + IKSystem.Instance.FingerSystem.leftMiddleCurl = 0f; + IKSystem.Instance.FingerSystem.leftRingCurl = 0f; + IKSystem.Instance.FingerSystem.leftPinkyCurl = 0f; + } + else + { + m_inputManager.fingerCurlRightThumb = 0f; + m_inputManager.fingerCurlRightIndex = 0f; + m_inputManager.fingerCurlRightMiddle = 0f; + m_inputManager.fingerCurlRightRing = 0f; + m_inputManager.fingerCurlRightPinky = 0f; + IKSystem.Instance.FingerSystem.rightThumbCurl = 0f; + IKSystem.Instance.FingerSystem.rightIndexCurl = 0f; + IKSystem.Instance.FingerSystem.rightMiddleCurl = 0f; + IKSystem.Instance.FingerSystem.rightRingCurl = 0f; + IKSystem.Instance.FingerSystem.rightPinkyCurl = 0f; + } + } + // Game settings void OnGameSettingBoolChange(string p_name, bool p_state) { diff --git a/ml_lme/LeapTracked.cs b/ml_lme/LeapTracked.cs index 7c8cfea..21ce9cb 100644 --- a/ml_lme/LeapTracked.cs +++ b/ml_lme/LeapTracked.cs @@ -232,7 +232,14 @@ namespace ml_lme if(PlayerSetup.Instance._animator.isHuman) { + Vector3 l_hipsPos = Vector3.zero; + Quaternion l_hipsRot = Quaternion.identity; m_hips = PlayerSetup.Instance._animator.GetBoneTransform(HumanBodyBones.Hips); + if(m_hips != null) + { + l_hipsPos = m_hips.localPosition; + l_hipsRot = m_hips.localRotation; + } if(!m_inVR) { @@ -308,6 +315,12 @@ namespace ml_lme m_vrIK.solver.OnPreUpdate += this.OnIKPreUpdate; m_vrIK.solver.OnPostUpdate += this.OnIKPostUpdate; } + + if(m_hips != null) + { + m_hips.localPosition = l_hipsPos; + m_hips.localRotation = l_hipsRot; + } } } diff --git a/ml_lme/Properties/AssemblyInfo.cs b/ml_lme/Properties/AssemblyInfo.cs index 892c296..ed513a5 100644 --- a/ml_lme/Properties/AssemblyInfo.cs +++ b/ml_lme/Properties/AssemblyInfo.cs @@ -1,10 +1,10 @@ using System.Reflection; [assembly: AssemblyTitle("LeapMotionExtension")] -[assembly: AssemblyVersion("1.3.4")] -[assembly: AssemblyFileVersion("1.3.4")] +[assembly: AssemblyVersion("1.3.5")] +[assembly: AssemblyFileVersion("1.3.5")] -[assembly: MelonLoader.MelonInfo(typeof(ml_lme.LeapMotionExtension), "LeapMotionExtension", "1.3.4", "SDraw", "https://github.com/SDraw/ml_mods_cvr")] +[assembly: MelonLoader.MelonInfo(typeof(ml_lme.LeapMotionExtension), "LeapMotionExtension", "1.3.5", "SDraw", "https://github.com/SDraw/ml_mods_cvr")] [assembly: MelonLoader.MelonGame(null, "ChilloutVR")] [assembly: MelonLoader.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)] [assembly: MelonLoader.MelonPlatformDomain(MelonLoader.MelonPlatformDomainAttribute.CompatibleDomains.MONO)] diff --git a/ml_pam/ArmMover.cs b/ml_pam/ArmMover.cs index c9940ae..68d0fe4 100644 --- a/ml_pam/ArmMover.cs +++ b/ml_pam/ArmMover.cs @@ -132,6 +132,15 @@ namespace ml_pam if(PlayerSetup.Instance._animator.isHuman) { + Vector3 l_hipsPos = Vector3.zero; + Quaternion l_hipsRot = Quaternion.identity; + Transform l_hips = PlayerSetup.Instance._animator.GetBoneTransform(HumanBodyBones.Hips); + if(l_hips != null) + { + l_hipsPos = l_hips.localPosition; + l_hipsRot = l_hips.localRotation; + } + HumanPose l_currentPose = new HumanPose(); HumanPoseHandler l_poseHandler = null; @@ -190,6 +199,12 @@ namespace ml_pam l_poseHandler?.SetHumanPose(ref l_currentPose); l_poseHandler?.Dispose(); + + if(l_hips != null) + { + l_hips.localPosition = l_hipsPos; + l_hips.localRotation = l_hipsRot; + } } if(m_enabled) diff --git a/ml_pam/Properties/AssemblyInfo.cs b/ml_pam/Properties/AssemblyInfo.cs index e7bee17..2bdb677 100644 --- a/ml_pam/Properties/AssemblyInfo.cs +++ b/ml_pam/Properties/AssemblyInfo.cs @@ -1,10 +1,10 @@ using System.Reflection; [assembly: AssemblyTitle("PickupArmMovement")] -[assembly: AssemblyVersion("1.0.3")] -[assembly: AssemblyFileVersion("1.0.3")] +[assembly: AssemblyVersion("1.0.4")] +[assembly: AssemblyFileVersion("1.0.4")] -[assembly: MelonLoader.MelonInfo(typeof(ml_pam.PickupArmMovement), "PickupArmMovement", "1.0.3", "SDraw", "https://github.com/SDraw/ml_mods_cvr")] +[assembly: MelonLoader.MelonInfo(typeof(ml_pam.PickupArmMovement), "PickupArmMovement", "1.0.4", "SDraw", "https://github.com/SDraw/ml_mods_cvr")] [assembly: MelonLoader.MelonGame(null, "ChilloutVR")] [assembly: MelonLoader.MelonPriority(1)] [assembly: MelonLoader.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]