mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 06:19:22 +00:00
[AlternateIKSystem] Slight cleanup of BodyControls
This commit is contained in:
parent
16e44f7c35
commit
684b330a4c
4 changed files with 71 additions and 65 deletions
|
@ -1,42 +1,12 @@
|
||||||
using RootMotion.FinalIK;
|
using ABI_RC.Core.Player;
|
||||||
|
using ABI_RC.Systems.MovementSystem;
|
||||||
|
using RootMotion.FinalIK;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace NAK.AlternateIKSystem.IK;
|
namespace NAK.AlternateIKSystem.IK;
|
||||||
|
|
||||||
public static class BodyControl
|
public class BodyControl
|
||||||
{
|
{
|
||||||
#region Tracking Controls
|
|
||||||
|
|
||||||
public static bool TrackingAll = true;
|
|
||||||
public static bool TrackingHead = true;
|
|
||||||
public static bool TrackingPelvis = true;
|
|
||||||
public static bool TrackingLeftArm = true;
|
|
||||||
public static bool TrackingRightArm = true;
|
|
||||||
public static bool TrackingLeftLeg = true;
|
|
||||||
public static bool TrackingRightLeg = true;
|
|
||||||
|
|
||||||
//TODO: dont do this, it is effective but lazy
|
|
||||||
public static bool TrackingLocomotion
|
|
||||||
{
|
|
||||||
get => _trackingLocomotion;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (_trackingLocomotion == value)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_trackingLocomotion = value;
|
|
||||||
IKManager.solver?.Reset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private static bool _trackingLocomotion = true;
|
|
||||||
|
|
||||||
public static float TrackingPositionWeight = 1f;
|
|
||||||
|
|
||||||
// TODO: decide if these are considered "Tracking Controls"
|
|
||||||
public static float TrackingUpright = 1f;
|
|
||||||
public static float TrackingMaxRootAngle = 0f;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Player Settings
|
#region Player Settings
|
||||||
|
|
||||||
public static bool useHipTracking = true;
|
public static bool useHipTracking = true;
|
||||||
|
@ -53,12 +23,68 @@ public static class BodyControl
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Tracking Controls
|
||||||
|
|
||||||
|
public static bool TrackingAll = true;
|
||||||
|
public static bool TrackingHead = true;
|
||||||
|
public static bool TrackingPelvis = true;
|
||||||
|
public static bool TrackingLeftArm = true;
|
||||||
|
public static bool TrackingRightArm = true;
|
||||||
|
public static bool TrackingLeftLeg = true;
|
||||||
|
public static bool TrackingRightLeg = true;
|
||||||
|
public static bool TrackingLocomotion = true;
|
||||||
|
public static float TrackingPositionWeight = 1f;
|
||||||
|
|
||||||
|
// TODO: decide if this is considered "Tracking Controls"
|
||||||
|
public static float TrackingMaxRootAngle = 0f;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Avatar Info
|
||||||
|
|
||||||
|
public static float AvatarUpright = 1f;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region BodyControl Configuration
|
#region BodyControl Configuration
|
||||||
|
|
||||||
public static float InvalidTrackerDistance = 1f;
|
public static float InvalidTrackerDistance = 1f;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
TrackingAll = ShouldTrackAll();
|
||||||
|
TrackingLocomotion = ShouldTrackLocomotion();
|
||||||
|
AvatarUpright = GetPlayerUpright();
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Private Methods
|
||||||
|
|
||||||
|
private static bool ShouldTrackAll()
|
||||||
|
{
|
||||||
|
return !PlayerSetup.Instance._emotePlaying;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool ShouldTrackLocomotion()
|
||||||
|
{
|
||||||
|
return !(MovementSystem.Instance.movementVector.magnitude > 0f
|
||||||
|
|| MovementSystem.Instance.crouching
|
||||||
|
|| MovementSystem.Instance.prone
|
||||||
|
|| MovementSystem.Instance.flying
|
||||||
|
|| MovementSystem.Instance.sitting
|
||||||
|
|| !MovementSystem.Instance._isGrounded);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float GetPlayerUpright()
|
||||||
|
{
|
||||||
|
float avatarHeight = PlayerSetup.Instance._avatarHeight;
|
||||||
|
float currentHeight = PlayerSetup.Instance.GetViewRelativePosition().y;
|
||||||
|
return Mathf.Clamp01((avatarHeight > 0f) ? (currentHeight / avatarHeight) : 0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Solver Weight Helpers
|
#region Solver Weight Helpers
|
||||||
|
|
||||||
public static void SetHeadWeight(IKSolverVR.Spine spine, LookAtIK lookAtIk, float weight)
|
public static void SetHeadWeight(IKSolverVR.Spine spine, LookAtIK lookAtIk, float weight)
|
||||||
|
|
|
@ -124,7 +124,7 @@ internal class IKHandlerDesktop : IKHandler
|
||||||
{
|
{
|
||||||
// Lerp locomotion weight, lerp to BodyControl.TrackingUpright???
|
// Lerp locomotion weight, lerp to BodyControl.TrackingUpright???
|
||||||
float targetWeight =
|
float targetWeight =
|
||||||
(BodyControl.TrackingAll && BodyControl.TrackingLocomotion && BodyControl.TrackingUpright > 0.8f)
|
(BodyControl.TrackingAll && BodyControl.TrackingLocomotion && BodyControl.AvatarUpright > 0.8f)
|
||||||
? 1f
|
? 1f
|
||||||
: 0.0f;
|
: 0.0f;
|
||||||
_locomotionWeight = Mathf.Lerp(_locomotionWeight, targetWeight, Time.deltaTime * 20f);
|
_locomotionWeight = Mathf.Lerp(_locomotionWeight, targetWeight, Time.deltaTime * 20f);
|
||||||
|
|
|
@ -14,6 +14,8 @@ public class IKManager : MonoBehaviour
|
||||||
{
|
{
|
||||||
public static IKManager Instance;
|
public static IKManager Instance;
|
||||||
|
|
||||||
|
public BodyControl BodyControl = new BodyControl();
|
||||||
|
|
||||||
public static VRIK vrik => _vrik;
|
public static VRIK vrik => _vrik;
|
||||||
private static VRIK _vrik;
|
private static VRIK _vrik;
|
||||||
public static IKSolverVR solver => _vrik?.solver;
|
public static IKSolverVR solver => _vrik?.solver;
|
||||||
|
@ -60,9 +62,7 @@ public class IKManager : MonoBehaviour
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
BodyControl.TrackingAll = ShouldTrackAll();
|
BodyControl.Update();
|
||||||
BodyControl.TrackingUpright = GetPlayerUpright();
|
|
||||||
BodyControl.TrackingLocomotion = ShouldTrackLocomotion();
|
|
||||||
|
|
||||||
if (!_isAvatarInitialized)
|
if (!_isAvatarInitialized)
|
||||||
return;
|
return;
|
||||||
|
@ -171,32 +171,6 @@ public class IKManager : MonoBehaviour
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Private Methods
|
|
||||||
|
|
||||||
private bool ShouldTrackAll()
|
|
||||||
{
|
|
||||||
return !PlayerSetup.Instance._emotePlaying;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool ShouldTrackLocomotion()
|
|
||||||
{
|
|
||||||
return !(MovementSystem.Instance.movementVector.magnitude > 0f
|
|
||||||
|| MovementSystem.Instance.crouching
|
|
||||||
|| MovementSystem.Instance.prone
|
|
||||||
|| MovementSystem.Instance.flying
|
|
||||||
|| MovementSystem.Instance.sitting
|
|
||||||
|| !MovementSystem.Instance._isGrounded);
|
|
||||||
}
|
|
||||||
|
|
||||||
private float GetPlayerUpright()
|
|
||||||
{
|
|
||||||
float avatarHeight = PlayerSetup.Instance._avatarHeight;
|
|
||||||
float currentHeight = PlayerSetup.Instance.GetViewRelativePosition().y;
|
|
||||||
return Mathf.Clamp01((avatarHeight > 0f) ? (currentHeight / avatarHeight) : 0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IK Initialization
|
#region IK Initialization
|
||||||
|
|
||||||
private void InitializeDesktopIk()
|
private void InitializeDesktopIk()
|
||||||
|
|
|
@ -77,6 +77,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EzCurls", "EzCurls\EzCurls.
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AlternateIKSystem", "AlternateIKSystem\AlternateIKSystem.csproj", "{CAB05E13-B529-4CDA-A2B5-B62E122408F8}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AlternateIKSystem", "AlternateIKSystem\AlternateIKSystem.csproj", "{CAB05E13-B529-4CDA-A2B5-B62E122408F8}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NoDepthOnlyFlat", "NoDepthOnlyFlat\NoDepthOnlyFlat.csproj", "{6F2F8774-40CF-4DE1-BC6C-DC00CA76D6A8}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
@ -231,6 +233,10 @@ Global
|
||||||
{CAB05E13-B529-4CDA-A2B5-B62E122408F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{CAB05E13-B529-4CDA-A2B5-B62E122408F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{CAB05E13-B529-4CDA-A2B5-B62E122408F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{CAB05E13-B529-4CDA-A2B5-B62E122408F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{CAB05E13-B529-4CDA-A2B5-B62E122408F8}.Release|Any CPU.Build.0 = Release|Any CPU
|
{CAB05E13-B529-4CDA-A2B5-B62E122408F8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{6F2F8774-40CF-4DE1-BC6C-DC00CA76D6A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{6F2F8774-40CF-4DE1-BC6C-DC00CA76D6A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{6F2F8774-40CF-4DE1-BC6C-DC00CA76D6A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{6F2F8774-40CF-4DE1-BC6C-DC00CA76D6A8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue