mirror of
https://github.com/hanetzer/sdraw_mods_cvr.git
synced 2025-09-04 02:49:23 +00:00
Minor code changes and fixes
Sometimes I dream about cheese
This commit is contained in:
parent
7fcfb04e0f
commit
fd48185bdd
14 changed files with 183 additions and 177 deletions
|
@ -22,7 +22,7 @@ namespace ml_lme
|
|||
public bool[] m_handsPresenses = null;
|
||||
public Vector3[] m_handsPositons = null;
|
||||
public Quaternion[] m_handsRotations = null;
|
||||
public Vector3[] m_elbowPositions = null;
|
||||
public Vector3[] m_elbowsPositions = null;
|
||||
public float[] m_leftFingersBends = null;
|
||||
public float[] m_leftFingersSpreads = null;
|
||||
public float[] m_rightFingersBends = null;
|
||||
|
@ -33,7 +33,7 @@ namespace ml_lme
|
|||
m_handsPresenses = new bool[ms_handsCount];
|
||||
m_handsPositons = new Vector3[ms_handsCount];
|
||||
m_handsRotations = new Quaternion[ms_handsCount];
|
||||
m_elbowPositions = new Vector3[ms_handsCount];
|
||||
m_elbowsPositions = new Vector3[ms_handsCount];
|
||||
m_leftFingersBends = new float[ms_fingersCount];
|
||||
m_leftFingersSpreads = new float[ms_fingersCount];
|
||||
m_rightFingersBends = new float[ms_fingersCount];
|
||||
|
@ -63,7 +63,7 @@ namespace ml_lme
|
|||
p_data.m_handsPresenses[l_sideID] = true;
|
||||
FillHandPosition(l_hand, ref p_data.m_handsPositons[l_sideID]);
|
||||
FillHandRotation(l_hand, ref p_data.m_handsRotations[l_sideID]);
|
||||
FillElbowPosition(l_hand, ref p_data.m_elbowPositions[l_sideID]);
|
||||
FillElbowPosition(l_hand, ref p_data.m_elbowsPositions[l_sideID]);
|
||||
switch(l_sideID)
|
||||
{
|
||||
case 0:
|
||||
|
|
|
@ -53,40 +53,36 @@ namespace ml_lme
|
|||
m_rightHandTarget.localPosition = Vector3.zero;
|
||||
m_rightHandTarget.localRotation = Quaternion.identity;
|
||||
}
|
||||
|
||||
Settings.EnabledChange += this.SetEnabled;
|
||||
Settings.FingersOnlyChange += this.SetFingersOnly;
|
||||
Settings.TrackElbowsChange += this.SetTrackElbows;
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
Settings.EnabledChange -= this.SetEnabled;
|
||||
Settings.FingersOnlyChange -= this.SetFingersOnly;
|
||||
Settings.TrackElbowsChange -= this.SetTrackElbows;
|
||||
}
|
||||
|
||||
public void SetEnabled(bool p_state)
|
||||
{
|
||||
m_enabled = p_state;
|
||||
|
||||
if(m_indexIK != null)
|
||||
{
|
||||
m_indexIK.activeControl = (m_enabled || Utils.AreKnucklesInUse());
|
||||
CVRInputManager.Instance.individualFingerTracking = (m_enabled || Utils.AreKnucklesInUse());
|
||||
}
|
||||
|
||||
if((m_leftIK != null) && (m_rightIK != null))
|
||||
{
|
||||
m_leftIK.enabled = (m_enabled && !m_fingersOnly);
|
||||
m_rightIK.enabled = (m_enabled && !m_fingersOnly);
|
||||
}
|
||||
|
||||
RefreshFingersTracking();
|
||||
RefreshArmIK();
|
||||
if(!m_enabled || m_fingersOnly)
|
||||
RestoreIK();
|
||||
RestoreVRIK();
|
||||
}
|
||||
|
||||
public void SetFingersOnly(bool p_state)
|
||||
{
|
||||
m_fingersOnly = p_state;
|
||||
|
||||
if((m_leftIK != null) && (m_rightIK != null))
|
||||
{
|
||||
m_leftIK.enabled = (m_enabled && !m_fingersOnly);
|
||||
m_rightIK.enabled = (m_enabled && !m_fingersOnly);
|
||||
}
|
||||
|
||||
RefreshArmIK();
|
||||
if(!m_enabled || m_fingersOnly)
|
||||
RestoreIK();
|
||||
RestoreVRIK();
|
||||
}
|
||||
|
||||
public void SetTrackElbows(bool p_state)
|
||||
|
@ -126,7 +122,7 @@ namespace ml_lme
|
|||
m_leftIK.solver.IKPositionWeight = Mathf.Lerp(m_leftIK.solver.IKPositionWeight, (p_gesturesData.m_handsPresenses[0] && !m_fingersOnly) ? 1f : 0f, 0.25f);
|
||||
m_leftIK.solver.IKRotationWeight = Mathf.Lerp(m_leftIK.solver.IKRotationWeight, (p_gesturesData.m_handsPresenses[0] && !m_fingersOnly) ? 1f : 0f, 0.25f);
|
||||
m_rightIK.solver.IKPositionWeight = Mathf.Lerp(m_rightIK.solver.IKPositionWeight, (p_gesturesData.m_handsPresenses[1] && !m_fingersOnly) ? 1f : 0f, 0.25f);
|
||||
m_rightIK.solver.IKRotationWeight = Mathf.Lerp(m_rightIK.solver.IKPositionWeight, (p_gesturesData.m_handsPresenses[1] && !m_fingersOnly) ? 1f : 0f, 0.25f);
|
||||
m_rightIK.solver.IKRotationWeight = Mathf.Lerp(m_rightIK.solver.IKRotationWeight, (p_gesturesData.m_handsPresenses[1] && !m_fingersOnly) ? 1f : 0f, 0.25f);
|
||||
}
|
||||
|
||||
if(p_gesturesData.m_handsPresenses[0])
|
||||
|
@ -203,6 +199,7 @@ namespace ml_lme
|
|||
public void OnAvatarClear()
|
||||
{
|
||||
m_vrIK = null;
|
||||
m_armsWeights = Vector2.zero;
|
||||
m_leftIK = null;
|
||||
m_rightIK = null;
|
||||
m_leftTargetActive = false;
|
||||
|
@ -212,8 +209,6 @@ namespace ml_lme
|
|||
m_leftHandTarget.localRotation = Quaternion.identity;
|
||||
m_rightHandTarget.localPosition = Vector3.zero;
|
||||
m_rightHandTarget.localRotation = Quaternion.identity;
|
||||
|
||||
m_armsWeights.Set(0f, 0f);
|
||||
}
|
||||
|
||||
public void OnCalibrateAvatar()
|
||||
|
@ -223,8 +218,7 @@ namespace ml_lme
|
|||
if(m_indexIK != null)
|
||||
{
|
||||
m_indexIK.avatarAnimator = PlayerSetup.Instance._animator;
|
||||
m_indexIK.activeControl = (m_enabled || Utils.AreKnucklesInUse());
|
||||
CVRInputManager.Instance.individualFingerTracking = (m_enabled || Utils.AreKnucklesInUse());
|
||||
RefreshFingersTracking();
|
||||
}
|
||||
|
||||
if(PlayerSetup.Instance._animator.isHuman)
|
||||
|
@ -330,7 +324,7 @@ namespace ml_lme
|
|||
m_vrIK.solver.rightArm.rotationWeight = m_armsWeights.y;
|
||||
}
|
||||
|
||||
void RestoreIK()
|
||||
void RestoreVRIK()
|
||||
{
|
||||
if(m_vrIK != null)
|
||||
{
|
||||
|
@ -350,5 +344,23 @@ namespace ml_lme
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RefreshArmIK()
|
||||
{
|
||||
if((m_leftIK != null) && (m_rightIK != null))
|
||||
{
|
||||
m_leftIK.enabled = (m_enabled && !m_fingersOnly);
|
||||
m_rightIK.enabled = (m_enabled && !m_fingersOnly);
|
||||
}
|
||||
}
|
||||
|
||||
void RefreshFingersTracking()
|
||||
{
|
||||
if(m_indexIK != null)
|
||||
{
|
||||
m_indexIK.activeControl = (m_enabled || Utils.AreKnucklesInUse());
|
||||
CVRInputManager.Instance.individualFingerTracking = (m_enabled || Utils.AreKnucklesInUse());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,9 +8,6 @@ namespace ml_lme
|
|||
|
||||
public class LeapMotionExtension : MelonLoader.MelonMod
|
||||
{
|
||||
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 LeapMotionExtension ms_instance = null;
|
||||
|
||||
Leap.Controller m_leapController = null;
|
||||
|
@ -32,13 +29,11 @@ namespace ml_lme
|
|||
Settings.Init();
|
||||
Settings.EnabledChange += this.OnEnableChange;
|
||||
Settings.DesktopOffsetChange += this.OnDesktopOffsetChange;
|
||||
Settings.FingersOnlyChange += this.OnFingersOptionChange;
|
||||
Settings.ModelVisibilityChange += this.OnModelVisibilityChange;
|
||||
Settings.TrackingModeChange += this.OnTrackingModeChange;
|
||||
Settings.RootAngleChange += this.OnRootAngleChange;
|
||||
Settings.HeadAttachChange += this.OnHeadAttachChange;
|
||||
Settings.HeadOffsetChange += this.OnHeadOffsetChange;
|
||||
Settings.TrackElbowsChange += this.OnTrackElbowsChange;
|
||||
|
||||
m_leapController = new Leap.Controller();
|
||||
m_leapController.Device += this.OnLeapDeviceInitialized;
|
||||
|
@ -109,15 +104,28 @@ namespace ml_lme
|
|||
// Player setup
|
||||
m_leapTracked = PlayerSetup.Instance.gameObject.AddComponent<LeapTracked>();
|
||||
m_leapTracked.SetTransforms(m_leapHands[0].transform, m_leapHands[1].transform, m_leapElbows[0].transform, m_leapElbows[1].transform);
|
||||
m_leapTracked.SetEnabled(Settings.Enabled);
|
||||
m_leapTracked.SetTrackElbows(Settings.TrackElbows);
|
||||
m_leapTracked.SetFingersOnly(Settings.FingersOnly);
|
||||
|
||||
OnEnableChange(Settings.Enabled);
|
||||
OnFingersOptionChange(Settings.FingersOnly);
|
||||
OnModelVisibilityChange(Settings.ModelVisibility);
|
||||
OnTrackingModeChange(Settings.TrackingMode);
|
||||
OnHeadAttachChange(Settings.HeadAttach); // Includes offsets and parenting
|
||||
}
|
||||
|
||||
public override void OnDeinitializeMelon()
|
||||
{
|
||||
if(ms_instance == this)
|
||||
ms_instance = null;
|
||||
|
||||
m_leapController?.StopConnection();
|
||||
m_leapController?.Dispose();
|
||||
m_leapController = null;
|
||||
|
||||
m_gesturesData = null;
|
||||
}
|
||||
|
||||
public override void OnUpdate()
|
||||
{
|
||||
if(Settings.Enabled)
|
||||
|
@ -138,12 +146,12 @@ namespace ml_lme
|
|||
{
|
||||
Vector3 l_pos = m_gesturesData.m_handsPositons[i];
|
||||
Quaternion l_rot = m_gesturesData.m_handsRotations[i];
|
||||
ReorientateLeapToUnity(ref l_pos, ref l_rot, Settings.TrackingMode);
|
||||
Utils.LeapToUnity(ref l_pos, ref l_rot, Settings.TrackingMode);
|
||||
m_leapHands[i].transform.localPosition = l_pos;
|
||||
m_leapHands[i].transform.localRotation = l_rot;
|
||||
|
||||
l_pos = m_gesturesData.m_elbowPositions[i];
|
||||
ReorientateLeapToUnity(ref l_pos, ref l_rot, Settings.TrackingMode);
|
||||
l_pos = m_gesturesData.m_elbowsPositions[i];
|
||||
Utils.LeapToUnity(ref l_pos, ref l_rot, Settings.TrackingMode);
|
||||
m_leapElbows[i].transform.localPosition = l_pos;
|
||||
}
|
||||
}
|
||||
|
@ -165,9 +173,6 @@ namespace ml_lme
|
|||
}
|
||||
else
|
||||
m_leapController?.StopConnection();
|
||||
|
||||
if(m_leapTracked != null)
|
||||
m_leapTracked.SetEnabled(p_state);
|
||||
}
|
||||
|
||||
void OnDesktopOffsetChange(Vector3 p_offset)
|
||||
|
@ -181,12 +186,6 @@ namespace ml_lme
|
|||
}
|
||||
}
|
||||
|
||||
void OnFingersOptionChange(bool p_state)
|
||||
{
|
||||
if(m_leapTracked != null)
|
||||
m_leapTracked.SetFingersOnly(p_state);
|
||||
}
|
||||
|
||||
void OnModelVisibilityChange(bool p_state)
|
||||
{
|
||||
if(m_leapControllerModel != null)
|
||||
|
@ -270,12 +269,6 @@ namespace ml_lme
|
|||
m_leapTrackingRoot.transform.localPosition = p_offset;
|
||||
}
|
||||
}
|
||||
|
||||
void OnTrackElbowsChange(bool p_state)
|
||||
{
|
||||
if(m_leapTracked != null)
|
||||
m_leapTracked.SetTrackElbows(p_state);
|
||||
}
|
||||
|
||||
// Internal utility
|
||||
void UpdateDeviceTrackingMode()
|
||||
|
@ -347,7 +340,7 @@ namespace ml_lme
|
|||
MelonLoader.MelonLogger.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void OnCalibrateAvatar_Postfix() => ms_instance?.OnCalibrateAvatar();
|
||||
void OnCalibrateAvatar()
|
||||
{
|
||||
|
@ -363,33 +356,5 @@ namespace ml_lme
|
|||
MelonLoader.MelonLogger.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
// Utilities
|
||||
static void ReorientateLeapToUnity(ref Vector3 p_pos, ref Quaternion p_rot, Settings.LeapTrackingMode p_mode)
|
||||
{
|
||||
p_pos *= 0.001f;
|
||||
p_pos.z *= -1f;
|
||||
p_rot.x *= -1f;
|
||||
p_rot.y *= -1f;
|
||||
|
||||
switch(p_mode)
|
||||
{
|
||||
case Settings.LeapTrackingMode.Screentop:
|
||||
{
|
||||
p_pos.x *= -1f;
|
||||
p_pos.y *= -1f;
|
||||
p_rot = (ms_screentopRotationFix * p_rot);
|
||||
}
|
||||
break;
|
||||
|
||||
case Settings.LeapTrackingMode.HMD:
|
||||
{
|
||||
p_pos.x *= -1f;
|
||||
Utils.Swap(ref p_pos.y, ref p_pos.z);
|
||||
p_rot = (ms_hmdRotationFix * p_rot);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
using System.Reflection;
|
||||
|
||||
[assembly: AssemblyTitle("LeapMotionExtension")]
|
||||
[assembly: AssemblyVersion("1.2.3")]
|
||||
[assembly: AssemblyFileVersion("1.2.3")]
|
||||
[assembly: AssemblyVersion("1.2.4")]
|
||||
[assembly: AssemblyFileVersion("1.2.4")]
|
||||
|
||||
[assembly: MelonLoader.MelonInfo(typeof(ml_lme.LeapMotionExtension), "LeapMotionExtension", "1.2.3", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
|
||||
[assembly: MelonLoader.MelonInfo(typeof(ml_lme.LeapMotionExtension), "LeapMotionExtension", "1.2.4", "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)]
|
||||
|
|
|
@ -6,12 +6,42 @@ namespace ml_lme
|
|||
{
|
||||
static class Utils
|
||||
{
|
||||
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 Matrix4x4 GetMatrix(this Transform p_transform, bool p_pos = true, bool p_rot = true, bool p_scl = false)
|
||||
{
|
||||
return Matrix4x4.TRS(p_pos ? p_transform.position : Vector3.zero, p_rot ? p_transform.rotation : Quaternion.identity, p_scl ? p_transform.lossyScale : Vector3.one);
|
||||
}
|
||||
|
||||
public static void LeapToUnity(ref Vector3 p_pos, ref Quaternion p_rot, Settings.LeapTrackingMode p_mode)
|
||||
{
|
||||
p_pos *= 0.001f;
|
||||
p_pos.z *= -1f;
|
||||
p_rot.x *= -1f;
|
||||
p_rot.y *= -1f;
|
||||
|
||||
switch(p_mode)
|
||||
{
|
||||
case Settings.LeapTrackingMode.Screentop:
|
||||
{
|
||||
p_pos.x *= -1f;
|
||||
p_pos.y *= -1f;
|
||||
p_rot = (ms_screentopRotationFix * p_rot);
|
||||
}
|
||||
break;
|
||||
|
||||
case Settings.LeapTrackingMode.HMD:
|
||||
{
|
||||
p_pos.x *= -1f;
|
||||
Swap(ref p_pos.y, ref p_pos.z);
|
||||
p_rot = (ms_hmdRotationFix * p_rot);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Swap<T>(ref T lhs, ref T rhs)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue