Minor code changes and fixes

Sometimes I dream about cheese
This commit is contained in:
SDraw 2022-10-18 21:46:10 +03:00
parent 7fcfb04e0f
commit fd48185bdd
No known key found for this signature in database
GPG key ID: BB95B4DAB2BB8BB5
14 changed files with 183 additions and 177 deletions

View file

@ -1,12 +1,12 @@
Merged set of MelonLoader mods for ChilloutVR. Merged set of MelonLoader mods for ChilloutVR.
**State table for game build 2022r169:** **State table for game build 2022r169p1:**
| Full name | Short name | Latest version | Available in [CVRMA](https://github.com/knah/CVRMelonAssistant) | Current Status | Notes | | Full name | Short name | Latest version | Available in [CVRMA](https://github.com/knah/CVRMelonAssistant) | Current Status | Notes |
|-----------|------------|----------------|-----------------------------------------------------------------|----------------|-------| |-----------|------------|----------------|-----------------------------------------------------------------|----------------|-------|
| Avatar Change Info | ml_aci | 1.0.3 | Yes | Working | | Avatar Change Info | ml_aci | 1.0.3 | Yes | Working |
| Avatar Motion Tweaker | ml_amt | 1.1.3 | Yes | Working | | Avatar Motion Tweaker | ml_amt | 1.1.4 | On review | Working |
| Desktop Head Tracking | ml_dht | 1.0.6 | Yes | Working | | Desktop Head Tracking | ml_dht | 1.0.7 | On review | Working |
| Desktop Reticle Switch | ml_drs | 1.0.0 | Yes | Working | | Desktop Reticle Switch | ml_drs | 1.0.0 | Yes | Working |
| Four Point Tracking | ml_fpt | 1.0.8 | Yes | Working | | Four Point Tracking | ml_fpt | 1.0.9 | On review | Working |
| Leap Motion Extension | ml_lme | 1.2.3 | On review | Working | | Leap Motion Extension | ml_lme | 1.2.4 | On review | Working |
| Server Connection Info | ml_sci | 1.0.2 | Yes | Working | | Server Connection Info | ml_sci | 1.0.2 | Yes | Working |

View file

@ -15,14 +15,6 @@ namespace ml_amt
ms_instance = this; ms_instance = this;
Settings.Init(); Settings.Init();
Settings.IKOverrideCrouchChange += this.OnIKOverrideCrouchChange;
Settings.CrouchLimitChange += this.OnCrouchLimitChange;
Settings.IKOverrideProneChange += this.OnIKOverrideProneChange;
Settings.ProneLimitChange += this.OnProneLimitChange;
Settings.PoseTransitionsChange += this.OnPoseTransitonsChange;
Settings.AdjustedMovementChange += this.OnAdjustedMovementChange;
Settings.IKOverrideFlyChange += this.OnIKOverrideFlyChange;
Settings.DetectEmotesChange += this.OnDetectEmotesChange;
HarmonyInstance.Patch( HarmonyInstance.Patch(
typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.ClearAvatar)), typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.ClearAvatar)),
@ -54,45 +46,12 @@ namespace ml_amt
m_localTweaker.SetDetectEmotes(Settings.DetectEmotes); m_localTweaker.SetDetectEmotes(Settings.DetectEmotes);
} }
void OnIKOverrideCrouchChange(bool p_state) public override void OnDeinitializeMelon()
{ {
if(m_localTweaker != null) if(ms_instance == this)
m_localTweaker.SetIKOverrideCrouch(p_state); ms_instance = null;
}
void OnCrouchLimitChange(float p_value) m_localTweaker = null;
{
if(m_localTweaker != null)
m_localTweaker.SetCrouchLimit(p_value);
}
void OnIKOverrideProneChange(bool p_state)
{
if(m_localTweaker != null)
m_localTweaker.SetIKOverrideProne(p_state);
}
void OnProneLimitChange(float p_value)
{
if(m_localTweaker != null)
m_localTweaker.SetProneLimit(p_value);
}
void OnPoseTransitonsChange(bool p_state)
{
if(m_localTweaker != null)
m_localTweaker.SetPoseTransitions(p_state);
}
void OnAdjustedMovementChange(bool p_state)
{
if(m_localTweaker != null)
m_localTweaker.SetAdjustedMovement(p_state);
}
void OnIKOverrideFlyChange(bool p_state)
{
if(m_localTweaker != null)
m_localTweaker.SetIKOverrideFly(p_state);
}
void OnDetectEmotesChange(bool p_state)
{
if(m_localTweaker != null)
m_localTweaker.SetDetectEmotes(p_state);
} }
static void OnAvatarClear_Postfix() => ms_instance?.OnAvatarClear(); static void OnAvatarClear_Postfix() => ms_instance?.OnAvatarClear();

View file

@ -78,6 +78,30 @@ namespace ml_amt
{ {
m_parameters = new List<AdditionalParameterInfo>(); m_parameters = new List<AdditionalParameterInfo>();
} }
void Start()
{
Settings.IKOverrideCrouchChange += this.SetIKOverrideCrouch;
Settings.CrouchLimitChange += this.SetCrouchLimit;
Settings.IKOverrideProneChange += this.SetIKOverrideProne;
Settings.ProneLimitChange += this.SetProneLimit;
Settings.PoseTransitionsChange += this.SetPoseTransitions;
Settings.AdjustedMovementChange += this.SetAdjustedMovement;
Settings.IKOverrideFlyChange += this.SetIKOverrideFly;
Settings.DetectEmotesChange += this.SetDetectEmotes;
}
void OnDestroy()
{
Settings.IKOverrideCrouchChange -= this.SetIKOverrideCrouch;
Settings.CrouchLimitChange -= this.SetCrouchLimit;
Settings.IKOverrideProneChange -= this.SetIKOverrideProne;
Settings.ProneLimitChange -= this.SetProneLimit;
Settings.PoseTransitionsChange -= this.SetPoseTransitions;
Settings.AdjustedMovementChange -= this.SetAdjustedMovement;
Settings.IKOverrideFlyChange -= this.SetIKOverrideFly;
Settings.DetectEmotesChange -= this.SetDetectEmotes;
}
void Update() void Update()
{ {
@ -123,13 +147,12 @@ namespace ml_amt
m_poseState = l_poseState; m_poseState = l_poseState;
m_emoteActive = false;
if(m_detectEmotes && (m_locomotionLayer >= 0)) if(m_detectEmotes && (m_locomotionLayer >= 0))
{ {
AnimatorStateInfo l_animState = PlayerSetup.Instance._animator.GetCurrentAnimatorStateInfo(m_locomotionLayer); AnimatorStateInfo l_animState = PlayerSetup.Instance._animator.GetCurrentAnimatorStateInfo(m_locomotionLayer);
m_emoteActive = (l_animState.tagHash == ms_emoteHash); m_emoteActive = (l_animState.tagHash == ms_emoteHash);
} }
else
m_emoteActive = false;
if(m_parameters.Count > 0) if(m_parameters.Count > 0)
{ {

View file

@ -1,10 +1,10 @@
using System.Reflection; using System.Reflection;
[assembly: AssemblyTitle("AvatarMotionTweaker")] [assembly: AssemblyTitle("AvatarMotionTweaker")]
[assembly: AssemblyVersion("1.1.3")] [assembly: AssemblyVersion("1.1.4")]
[assembly: AssemblyFileVersion("1.1.3")] [assembly: AssemblyFileVersion("1.1.4")]
[assembly: MelonLoader.MelonInfo(typeof(ml_amt.AvatarMotionTweaker), "AvatarMotionTweaker", "1.1.3", "SDraw", "https://github.com/SDraw/ml_mods_cvr")] [assembly: MelonLoader.MelonInfo(typeof(ml_amt.AvatarMotionTweaker), "AvatarMotionTweaker", "1.1.4", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
[assembly: MelonLoader.MelonGame(null, "ChilloutVR")] [assembly: MelonLoader.MelonGame(null, "ChilloutVR")]
[assembly: MelonLoader.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)] [assembly: MelonLoader.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
[assembly: MelonLoader.MelonPlatformDomain(MelonLoader.MelonPlatformDomainAttribute.CompatibleDomains.MONO)] [assembly: MelonLoader.MelonPlatformDomain(MelonLoader.MelonPlatformDomainAttribute.CompatibleDomains.MONO)]

View file

@ -34,6 +34,19 @@ namespace ml_dht
void Start() void Start()
{ {
m_camera = PlayerSetup.Instance.desktopCamera.transform; m_camera = PlayerSetup.Instance.desktopCamera.transform;
Settings.EnabledChange += this.SetEnabled;
Settings.SmoothingChange += this.SetSmoothing;
Settings.MirroredChange += this.SetMirrored;
Settings.FaceOverrideChange += this.SetFaceOverride;
}
void OnDestroy()
{
Settings.EnabledChange -= this.SetEnabled;
Settings.SmoothingChange -= this.SetSmoothing;
Settings.MirroredChange -= this.SetMirrored;
Settings.FaceOverrideChange -= this.SetFaceOverride;
} }
public void UpdateTrackingData(ref TrackingData p_data) public void UpdateTrackingData(ref TrackingData p_data)

View file

@ -20,10 +20,6 @@ namespace ml_dht
ms_instance = this; ms_instance = this;
Settings.Init(); Settings.Init();
Settings.EnabledChange += this.OnEnabledChanged;
Settings.MirroredChange += this.OnMirroredChanged;
Settings.SmoothingChange += this.OnSmoothingChanged;
Settings.FaceOverrideChange += this.OnFaceOverrideChange;
m_mapReader = new MemoryMapReader(); m_mapReader = new MemoryMapReader();
m_buffer = new byte[1024]; m_buffer = new byte[1024];
@ -64,6 +60,18 @@ namespace ml_dht
m_localTracked.SetEnabled(Settings.Enabled); m_localTracked.SetEnabled(Settings.Enabled);
m_localTracked.SetMirrored(Settings.Mirrored); m_localTracked.SetMirrored(Settings.Mirrored);
m_localTracked.SetSmoothing(Settings.Smoothing); m_localTracked.SetSmoothing(Settings.Smoothing);
m_localTracked.SetFaceOverride(Settings.FaceOverride);
}
public override void OnDeinitializeMelon()
{
if(ms_instance == this)
ms_instance = null;
m_mapReader?.Close();
m_mapReader = null;
m_buffer = null;
m_localTracked = null;
} }
public override void OnUpdate() public override void OnUpdate()
@ -76,27 +84,6 @@ namespace ml_dht
} }
} }
void OnEnabledChanged(bool p_state)
{
if(m_localTracked != null)
m_localTracked.SetEnabled(p_state);
}
void OnMirroredChanged(bool p_state)
{
if(m_localTracked != null)
m_localTracked.SetMirrored(p_state);
}
void OnSmoothingChanged(float p_value)
{
if(m_localTracked != null)
m_localTracked.SetSmoothing(p_value);
}
void OnFaceOverrideChange(bool p_state)
{
if(m_localTracked != null)
m_localTracked.SetFaceOverride(p_state);
}
static void OnCalibrateAvatar_Postfix() => ms_instance?.OnCalibrateAvatar(); static void OnCalibrateAvatar_Postfix() => ms_instance?.OnCalibrateAvatar();
void OnCalibrateAvatar() void OnCalibrateAvatar()
{ {

View file

@ -1,10 +1,10 @@
using System.Reflection; using System.Reflection;
[assembly: AssemblyTitle("DesktopHeadTracking")] [assembly: AssemblyTitle("DesktopHeadTracking")]
[assembly: AssemblyVersion("1.0.6")] [assembly: AssemblyVersion("1.0.7")]
[assembly: AssemblyFileVersion("1.0.6")] [assembly: AssemblyFileVersion("1.0.7")]
[assembly: MelonLoader.MelonInfo(typeof(ml_dht.DesktopHeadTracking), "DesktopHeadTracking", "1.0.6", "SDraw", "https://github.com/SDraw/ml_mods_cvr")] [assembly: MelonLoader.MelonInfo(typeof(ml_dht.DesktopHeadTracking), "DesktopHeadTracking", "1.0.7", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
[assembly: MelonLoader.MelonGame(null, "ChilloutVR")] [assembly: MelonLoader.MelonGame(null, "ChilloutVR")]
[assembly: MelonLoader.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)] [assembly: MelonLoader.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
[assembly: MelonLoader.MelonPlatformDomain(MelonLoader.MelonPlatformDomainAttribute.CompatibleDomains.MONO)] [assembly: MelonLoader.MelonPlatformDomain(MelonLoader.MelonPlatformDomainAttribute.CompatibleDomains.MONO)]

View file

@ -18,7 +18,7 @@ namespace ml_fpt
bool m_ready = false; bool m_ready = false;
IndexIK m_indexIk = null; IndexIK m_indexIK = null;
RootMotion.FinalIK.VRIK m_vrIK = null; RootMotion.FinalIK.VRIK m_vrIK = null;
RuntimeAnimatorController m_runtimeAnimator = null; RuntimeAnimatorController m_runtimeAnimator = null;
List<CVRAdvancedSettingsFileProfileValue> m_aasParameters = null; List<CVRAdvancedSettingsFileProfileValue> m_aasParameters = null;
@ -78,11 +78,28 @@ namespace ml_fpt
while(PlayerSetup.Instance == null) while(PlayerSetup.Instance == null)
yield return null; yield return null;
m_indexIk = PlayerSetup.Instance.gameObject.GetComponent<IndexIK>(); m_indexIK = PlayerSetup.Instance.gameObject.GetComponent<IndexIK>();
m_ready = true; m_ready = true;
} }
public override void OnDeinitializeMelon()
{
if(ms_instance == this)
ms_instance = null;
m_ready = false;
m_aasParameters?.Clear();
m_aasParameters = null;
m_avatarCalibrations?.Clear();
m_avatarCalibrations = null;
m_hipsTrackerIndex = -1;
if(m_calibrationTask != null)
MelonLoader.MelonCoroutines.Stop(m_calibrationTask);
m_calibrationTask = null;
}
void StartCalibration() void StartCalibration()
{ {
if(m_ready && !m_calibrationActive && PlayerSetup.Instance._inVr && !PlayerSetup.Instance.avatarIsLoading && PlayerSetup.Instance._animator.isHuman && !BodySystem.isCalibrating && !BodySystem.isCalibratedAsFullBody) if(m_ready && !m_calibrationActive && PlayerSetup.Instance._inVr && !PlayerSetup.Instance.avatarIsLoading && PlayerSetup.Instance._animator.isHuman && !BodySystem.isCalibrating && !BodySystem.isCalibratedAsFullBody)
@ -128,7 +145,7 @@ namespace ml_fpt
if(m_vrIK != null) if(m_vrIK != null)
m_vrIK.enabled = false; m_vrIK.enabled = false;
m_indexIk.enabled = false; m_indexIK.enabled = false;
PlayerSetup.Instance._trackerManager.trackers[m_hipsTrackerIndex].ShowLine(true, m_hips); PlayerSetup.Instance._trackerManager.trackers[m_hipsTrackerIndex].ShowLine(true, m_hips);
@ -155,7 +172,7 @@ namespace ml_fpt
m_vrIK.enabled = true; m_vrIK.enabled = true;
} }
m_indexIk.enabled = true; m_indexIK.enabled = true;
PlayerSetup.Instance._animator.runtimeAnimatorController = m_runtimeAnimator; PlayerSetup.Instance._animator.runtimeAnimatorController = m_runtimeAnimator;
PlayerSetup.Instance.animatorManager.SetAnimator(PlayerSetup.Instance._animator, m_runtimeAnimator); PlayerSetup.Instance.animatorManager.SetAnimator(PlayerSetup.Instance._animator, m_runtimeAnimator);
@ -213,7 +230,7 @@ namespace ml_fpt
if(m_calibrationTask != null) if(m_calibrationTask != null)
MelonLoader.MelonCoroutines.Stop(m_calibrationTask); MelonLoader.MelonCoroutines.Stop(m_calibrationTask);
m_indexIk.enabled = true; m_indexIK.enabled = true;
IKSystem.Instance.leftHandModel.SetActive(false); IKSystem.Instance.leftHandModel.SetActive(false);
IKSystem.Instance.rightHandModel.SetActive(false); IKSystem.Instance.rightHandModel.SetActive(false);

View file

@ -1,10 +1,10 @@
using System.Reflection; using System.Reflection;
[assembly: AssemblyTitle("FourPointTracking")] [assembly: AssemblyTitle("FourPointTracking")]
[assembly: AssemblyVersion("1.0.8")] [assembly: AssemblyVersion("1.0.9")]
[assembly: AssemblyFileVersion("1.0.8")] [assembly: AssemblyFileVersion("1.0.9")]
[assembly: MelonLoader.MelonInfo(typeof(ml_fpt.FourPointTracking), "FourPointTracking", "1.0.8", "SDraw", "https://github.com/SDraw/ml_mods_cvr")] [assembly: MelonLoader.MelonInfo(typeof(ml_fpt.FourPointTracking), "FourPointTracking", "1.0.9", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
[assembly: MelonLoader.MelonGame(null, "ChilloutVR")] [assembly: MelonLoader.MelonGame(null, "ChilloutVR")]
[assembly: MelonLoader.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)] [assembly: MelonLoader.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
[assembly: MelonLoader.MelonPlatformDomain(MelonLoader.MelonPlatformDomainAttribute.CompatibleDomains.MONO)] [assembly: MelonLoader.MelonPlatformDomain(MelonLoader.MelonPlatformDomainAttribute.CompatibleDomains.MONO)]

View file

@ -22,7 +22,7 @@ namespace ml_lme
public bool[] m_handsPresenses = null; public bool[] m_handsPresenses = null;
public Vector3[] m_handsPositons = null; public Vector3[] m_handsPositons = null;
public Quaternion[] m_handsRotations = null; public Quaternion[] m_handsRotations = null;
public Vector3[] m_elbowPositions = null; public Vector3[] m_elbowsPositions = null;
public float[] m_leftFingersBends = null; public float[] m_leftFingersBends = null;
public float[] m_leftFingersSpreads = null; public float[] m_leftFingersSpreads = null;
public float[] m_rightFingersBends = null; public float[] m_rightFingersBends = null;
@ -33,7 +33,7 @@ namespace ml_lme
m_handsPresenses = new bool[ms_handsCount]; m_handsPresenses = new bool[ms_handsCount];
m_handsPositons = new Vector3[ms_handsCount]; m_handsPositons = new Vector3[ms_handsCount];
m_handsRotations = new Quaternion[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_leftFingersBends = new float[ms_fingersCount];
m_leftFingersSpreads = new float[ms_fingersCount]; m_leftFingersSpreads = new float[ms_fingersCount];
m_rightFingersBends = new float[ms_fingersCount]; m_rightFingersBends = new float[ms_fingersCount];
@ -63,7 +63,7 @@ namespace ml_lme
p_data.m_handsPresenses[l_sideID] = true; p_data.m_handsPresenses[l_sideID] = true;
FillHandPosition(l_hand, ref p_data.m_handsPositons[l_sideID]); FillHandPosition(l_hand, ref p_data.m_handsPositons[l_sideID]);
FillHandRotation(l_hand, ref p_data.m_handsRotations[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) switch(l_sideID)
{ {
case 0: case 0:

View file

@ -53,40 +53,36 @@ namespace ml_lme
m_rightHandTarget.localPosition = Vector3.zero; m_rightHandTarget.localPosition = Vector3.zero;
m_rightHandTarget.localRotation = Quaternion.identity; 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) public void SetEnabled(bool p_state)
{ {
m_enabled = p_state; m_enabled = p_state;
if(m_indexIK != null) RefreshFingersTracking();
{ RefreshArmIK();
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);
}
if(!m_enabled || m_fingersOnly) if(!m_enabled || m_fingersOnly)
RestoreIK(); RestoreVRIK();
} }
public void SetFingersOnly(bool p_state) public void SetFingersOnly(bool p_state)
{ {
m_fingersOnly = p_state; m_fingersOnly = p_state;
if((m_leftIK != null) && (m_rightIK != null)) RefreshArmIK();
{
m_leftIK.enabled = (m_enabled && !m_fingersOnly);
m_rightIK.enabled = (m_enabled && !m_fingersOnly);
}
if(!m_enabled || m_fingersOnly) if(!m_enabled || m_fingersOnly)
RestoreIK(); RestoreVRIK();
} }
public void SetTrackElbows(bool p_state) 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.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_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.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]) if(p_gesturesData.m_handsPresenses[0])
@ -203,6 +199,7 @@ namespace ml_lme
public void OnAvatarClear() public void OnAvatarClear()
{ {
m_vrIK = null; m_vrIK = null;
m_armsWeights = Vector2.zero;
m_leftIK = null; m_leftIK = null;
m_rightIK = null; m_rightIK = null;
m_leftTargetActive = false; m_leftTargetActive = false;
@ -212,8 +209,6 @@ namespace ml_lme
m_leftHandTarget.localRotation = Quaternion.identity; m_leftHandTarget.localRotation = Quaternion.identity;
m_rightHandTarget.localPosition = Vector3.zero; m_rightHandTarget.localPosition = Vector3.zero;
m_rightHandTarget.localRotation = Quaternion.identity; m_rightHandTarget.localRotation = Quaternion.identity;
m_armsWeights.Set(0f, 0f);
} }
public void OnCalibrateAvatar() public void OnCalibrateAvatar()
@ -223,8 +218,7 @@ namespace ml_lme
if(m_indexIK != null) if(m_indexIK != null)
{ {
m_indexIK.avatarAnimator = PlayerSetup.Instance._animator; m_indexIK.avatarAnimator = PlayerSetup.Instance._animator;
m_indexIK.activeControl = (m_enabled || Utils.AreKnucklesInUse()); RefreshFingersTracking();
CVRInputManager.Instance.individualFingerTracking = (m_enabled || Utils.AreKnucklesInUse());
} }
if(PlayerSetup.Instance._animator.isHuman) if(PlayerSetup.Instance._animator.isHuman)
@ -330,7 +324,7 @@ namespace ml_lme
m_vrIK.solver.rightArm.rotationWeight = m_armsWeights.y; m_vrIK.solver.rightArm.rotationWeight = m_armsWeights.y;
} }
void RestoreIK() void RestoreVRIK()
{ {
if(m_vrIK != null) 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());
}
}
} }
} }

View file

@ -8,9 +8,6 @@ namespace ml_lme
public class LeapMotionExtension : MelonLoader.MelonMod 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; static LeapMotionExtension ms_instance = null;
Leap.Controller m_leapController = null; Leap.Controller m_leapController = null;
@ -32,13 +29,11 @@ namespace ml_lme
Settings.Init(); Settings.Init();
Settings.EnabledChange += this.OnEnableChange; Settings.EnabledChange += this.OnEnableChange;
Settings.DesktopOffsetChange += this.OnDesktopOffsetChange; Settings.DesktopOffsetChange += this.OnDesktopOffsetChange;
Settings.FingersOnlyChange += this.OnFingersOptionChange;
Settings.ModelVisibilityChange += this.OnModelVisibilityChange; Settings.ModelVisibilityChange += this.OnModelVisibilityChange;
Settings.TrackingModeChange += this.OnTrackingModeChange; Settings.TrackingModeChange += this.OnTrackingModeChange;
Settings.RootAngleChange += this.OnRootAngleChange; Settings.RootAngleChange += this.OnRootAngleChange;
Settings.HeadAttachChange += this.OnHeadAttachChange; Settings.HeadAttachChange += this.OnHeadAttachChange;
Settings.HeadOffsetChange += this.OnHeadOffsetChange; Settings.HeadOffsetChange += this.OnHeadOffsetChange;
Settings.TrackElbowsChange += this.OnTrackElbowsChange;
m_leapController = new Leap.Controller(); m_leapController = new Leap.Controller();
m_leapController.Device += this.OnLeapDeviceInitialized; m_leapController.Device += this.OnLeapDeviceInitialized;
@ -109,15 +104,28 @@ namespace ml_lme
// Player setup // Player setup
m_leapTracked = PlayerSetup.Instance.gameObject.AddComponent<LeapTracked>(); 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.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.SetTrackElbows(Settings.TrackElbows);
m_leapTracked.SetFingersOnly(Settings.FingersOnly);
OnEnableChange(Settings.Enabled); OnEnableChange(Settings.Enabled);
OnFingersOptionChange(Settings.FingersOnly);
OnModelVisibilityChange(Settings.ModelVisibility); OnModelVisibilityChange(Settings.ModelVisibility);
OnTrackingModeChange(Settings.TrackingMode); OnTrackingModeChange(Settings.TrackingMode);
OnHeadAttachChange(Settings.HeadAttach); // Includes offsets and parenting 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() public override void OnUpdate()
{ {
if(Settings.Enabled) if(Settings.Enabled)
@ -138,12 +146,12 @@ namespace ml_lme
{ {
Vector3 l_pos = m_gesturesData.m_handsPositons[i]; Vector3 l_pos = m_gesturesData.m_handsPositons[i];
Quaternion l_rot = m_gesturesData.m_handsRotations[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.localPosition = l_pos;
m_leapHands[i].transform.localRotation = l_rot; m_leapHands[i].transform.localRotation = l_rot;
l_pos = m_gesturesData.m_elbowPositions[i]; l_pos = m_gesturesData.m_elbowsPositions[i];
ReorientateLeapToUnity(ref l_pos, ref l_rot, Settings.TrackingMode); Utils.LeapToUnity(ref l_pos, ref l_rot, Settings.TrackingMode);
m_leapElbows[i].transform.localPosition = l_pos; m_leapElbows[i].transform.localPosition = l_pos;
} }
} }
@ -165,9 +173,6 @@ namespace ml_lme
} }
else else
m_leapController?.StopConnection(); m_leapController?.StopConnection();
if(m_leapTracked != null)
m_leapTracked.SetEnabled(p_state);
} }
void OnDesktopOffsetChange(Vector3 p_offset) 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) void OnModelVisibilityChange(bool p_state)
{ {
if(m_leapControllerModel != null) if(m_leapControllerModel != null)
@ -270,12 +269,6 @@ namespace ml_lme
m_leapTrackingRoot.transform.localPosition = p_offset; m_leapTrackingRoot.transform.localPosition = p_offset;
} }
} }
void OnTrackElbowsChange(bool p_state)
{
if(m_leapTracked != null)
m_leapTracked.SetTrackElbows(p_state);
}
// Internal utility // Internal utility
void UpdateDeviceTrackingMode() void UpdateDeviceTrackingMode()
@ -347,7 +340,7 @@ namespace ml_lme
MelonLoader.MelonLogger.Error(e); MelonLoader.MelonLogger.Error(e);
} }
} }
static void OnCalibrateAvatar_Postfix() => ms_instance?.OnCalibrateAvatar(); static void OnCalibrateAvatar_Postfix() => ms_instance?.OnCalibrateAvatar();
void OnCalibrateAvatar() void OnCalibrateAvatar()
{ {
@ -363,33 +356,5 @@ namespace ml_lme
MelonLoader.MelonLogger.Error(e); 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;
}
}
} }
} }

View file

@ -1,10 +1,10 @@
using System.Reflection; using System.Reflection;
[assembly: AssemblyTitle("LeapMotionExtension")] [assembly: AssemblyTitle("LeapMotionExtension")]
[assembly: AssemblyVersion("1.2.3")] [assembly: AssemblyVersion("1.2.4")]
[assembly: AssemblyFileVersion("1.2.3")] [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.MelonGame(null, "ChilloutVR")]
[assembly: MelonLoader.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)] [assembly: MelonLoader.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
[assembly: MelonLoader.MelonPlatformDomain(MelonLoader.MelonPlatformDomainAttribute.CompatibleDomains.MONO)] [assembly: MelonLoader.MelonPlatformDomain(MelonLoader.MelonPlatformDomainAttribute.CompatibleDomains.MONO)]

View file

@ -6,12 +6,42 @@ namespace ml_lme
{ {
static class Utils 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 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) 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); 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) public static void Swap<T>(ref T lhs, ref T rhs)
{ {