Skip to content

Commit

Permalink
Fingers values reset
Browse files Browse the repository at this point in the history
Hips transform restore after pose modification
SDraw committed Apr 24, 2023
1 parent 7ef112d commit 0440baa
Showing 5 changed files with 96 additions and 6 deletions.
62 changes: 62 additions & 0 deletions ml_lme/LeapInput.cs
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@ class LeapInput : CVRInputModule
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 @@ void Update()
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 @@ void OnEnableChange(bool p_state)
{
OnInputChange(p_state && Settings.Input);
UpdateFingerTracking();
m_handVisibleLeft &= p_state;
m_handVisibleRight &= p_state;
}

void OnInputChange(bool p_state)
@@ -251,6 +277,12 @@ void UpdateFingerTracking()
{
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 @@ void SetFingersInput(GestureMatcher.HandData p_hand, bool p_left)
}
}

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)
{
13 changes: 13 additions & 0 deletions ml_lme/LeapTracked.cs
Original file line number Diff line number Diff line change
@@ -232,7 +232,14 @@ internal void OnAvatarSetup()

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 @@ internal void OnAvatarSetup()
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;
}
}
}

6 changes: 3 additions & 3 deletions ml_lme/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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)]
15 changes: 15 additions & 0 deletions ml_pam/ArmMover.cs
Original file line number Diff line number Diff line change
@@ -132,6 +132,15 @@ internal void OnAvatarSetup()

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 @@ internal void OnAvatarSetup()

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)
6 changes: 3 additions & 3 deletions ml_pam/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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)]

0 comments on commit 0440baa

Please sign in to comment.