[IKFixes] Updates for 2023r171

Removed unneeded settings. Fixed halfbody fake root angle option.
Added Reset Settings UIExpansionKit button.
This commit is contained in:
NotAKidoS 2023-09-15 21:15:50 -05:00
parent 3c52f8c60c
commit e31bf87609
7 changed files with 141 additions and 202 deletions

View file

@ -2,11 +2,11 @@
using ABI_RC.Core.Player;
using ABI_RC.Systems.IK;
using ABI_RC.Systems.IK.SubSystems;
using ABI_RC.Systems.InputManagement;
using ABI_RC.Systems.MovementSystem;
using HarmonyLib;
using RootMotion.FinalIK;
using UnityEngine;
using UnityEngine.Events;
namespace NAK.IKFixes.HarmonyPatches;
@ -22,7 +22,7 @@ internal static class BodySystemPatches
{
Transform parent = null;
float offsetDistance = 0f;
switch (trackingPoint.assignedRole)
{
case TrackingPoint.TrackingRole.LeftKnee:
@ -42,27 +42,27 @@ internal static class BodySystemPatches
offsetDistance = -0.15f;
break;
}
if (parent != null)
{
// Set the offset transform's parent and reset its local position and rotation
trackingPoint.offsetTransform.parent = parent;
trackingPoint.offsetTransform.localPosition = Vector3.zero;
trackingPoint.offsetTransform.localRotation = Quaternion.identity;
trackingPoint.offsetTransform.parent = trackingPoint.referenceTransform;
// Apply additional offset based on the assigned role
Vector3 additionalOffset = IKSystem.vrik.references.root.forward * offsetDistance;
trackingPoint.offsetTransform.position += additionalOffset;
// Game originally sets them to about half a meter out, which fucks with slime tracker users and
// makes the bendGoals less responsive/less accurate.
//Funny thing is that IKTweaks specifically made this an option, which should be added to both CVR & Standable for the same reason.
/// Elbow / knee / chest bend goal offset - controls how far bend goal targets will be away from the actual joint.
/// Lower values should produce better precision with bent joint, higher values - better stability with straight joint.
/// Sensible range of values is between 0 and 1.
}
if (parent == null)
continue;
// Set the offset transform's parent and reset its local position and rotation
trackingPoint.offsetTransform.parent = parent;
trackingPoint.offsetTransform.localPosition = Vector3.zero;
trackingPoint.offsetTransform.localRotation = Quaternion.identity;
trackingPoint.offsetTransform.parent = trackingPoint.referenceTransform;
// Apply additional offset based on the assigned role
Vector3 additionalOffset = IKSystem.vrik.references.root.forward * offsetDistance;
trackingPoint.offsetTransform.position += additionalOffset;
// Game originally sets them to about half a meter out, which fucks with slime tracker users and
// makes the bendGoals less responsive/less accurate.
//Funny thing is that IKTweaks specifically made this an option, which should be added to both CVR & Standable for the same reason.
/// Elbow / knee / chest bend goal offset - controls how far bend goal targets will be away from the actual joint.
/// Lower values should produce better precision with bent joint, higher values - better stability with straight joint.
/// Sensible range of values is between 0 and 1.
}
}
@ -73,7 +73,6 @@ internal static class BodySystemPatches
arm.shoulderRotationWeight = weight;
arm.shoulderTwistWeight = weight;
// assumed fix of bend goal weight if arms disabled with elbows (havent tested)
// why is there no "usingElbowTracker" flag like knees? where is the consistancy???
arm.bendGoalWeight = arm.bendGoal != null ? weight : 0f;
}
@ -130,25 +129,33 @@ internal static class BodySystemPatches
float maxRootAngle = 25f;
float rootHeadingOffset = 0f;
if (BodySystem.isCalibratedAsFullBody || IKFixes.EntryUseFakeRootAngle.Value)
if (BodySystem.isCalibratedAsFullBody
|| IKFixes.EntryUseFakeRootAngle.Value
|| CVRInputManager.Instance.movementVector.sqrMagnitude > 0f)
maxRootAngle = 0f;
// fixes body being wrong direction while playing emotes (root rotation)
if (PlayerSetup.Instance._emotePlaying)
maxRootAngle = 180f;
// fixes feet always pointing toward head direction
if (IKFixes.EntryUseFakeRootAngle.Value && !BodySystem.isCalibratedAsFullBody)
{
float weightedAngleLimit = IKFixes.EntryFakeRootAngleLimit.Value * solver.locomotion.weight;
float pivotAngle = MovementSystem.Instance.rotationPivot.eulerAngles.y;
float deltaAngleRoot = Mathf.DeltaAngle(pivotAngle, _ikSimulatedRootAngle);
float absDeltaAngleRoot = Mathf.Abs(deltaAngleRoot);
deltaAngleRoot = Mathf.Clamp(deltaAngleRoot, -weightedAngleLimit, weightedAngleLimit);
_ikSimulatedRootAngle = Mathf.MoveTowardsAngle(_ikSimulatedRootAngle, pivotAngle, absDeltaAngleRoot - weightedAngleLimit);
float playerDirection = MovementSystem.Instance.rotationPivot.eulerAngles.y;
float deltaAngleRoot = Mathf.DeltaAngle(playerDirection, _ikSimulatedRootAngle);
float angleOverLimit = Mathf.Abs(deltaAngleRoot) - weightedAngleLimit;
if (angleOverLimit > 0)
{
deltaAngleRoot = Mathf.Sign(deltaAngleRoot) * weightedAngleLimit;
_ikSimulatedRootAngle = Mathf.MoveTowardsAngle(_ikSimulatedRootAngle, playerDirection, angleOverLimit);
}
rootHeadingOffset = deltaAngleRoot;
}
solver.spine.maxRootAngle = maxRootAngle;
solver.spine.rootHeadingOffset = rootHeadingOffset;
@ -207,7 +214,7 @@ internal static class BodySystemPatches
if (BodySystem.isCalibratedAsFullBody && BodySystem.TrackingPositionWeight > 0f)
{
bool isRunning = MovementSystem.Instance.movementVector.magnitude > 0f;
bool isRunning = MovementSystem.Instance.movementVector.sqrMagnitude > 0f;
bool isGrounded = MovementSystem.Instance._isGrounded;
bool isFlying = MovementSystem.Instance.flying;
bool playRunningAnimation = BodySystem.PlayRunningAnimationInFullBody;
@ -257,128 +264,6 @@ internal static class IKSystemPatches
__instance.applyOriginalHipPosition = true;
__instance.applyOriginalHipRotation = true;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(IKSystem), nameof(IKSystem.InitializeHalfBodyIK))]
private static void Postfix_IKSystem_InitializeHalfBodyIK(ref IKSystem __instance)
{
if (!IKFixes.EntryUseIKPose.Value) return;
__instance._poseHandler.GetHumanPose(ref __instance.humanPose);
for (int i = 0; i < IKPoseMuscles.Length; i++)
{
__instance.ApplyMuscleValue((MuscleIndex)i, IKPoseMuscles[i], ref __instance.humanPose.muscles);
}
__instance.humanPose.bodyPosition = Vector3.up;
__instance.humanPose.bodyRotation = Quaternion.identity;
__instance._poseHandler.SetHumanPose(ref __instance.humanPose);
// recentering avatar so it doesnt need to step from random place on switch
IKSystem.vrik.transform.localPosition = Vector3.zero;
IKSystem.vrik.transform.localRotation = Quaternion.identity;
// janky fix, initializing early with correct pose
IKSystem.vrik.solver.Initiate(IKSystem.vrik.transform);
}
private static readonly float[] IKPoseMuscles = new float[]
{
0.00133321f,
8.195831E-06f,
8.537738E-07f,
-0.002669832f,
-7.651234E-06f,
-0.001659694f,
0f,
0f,
0f,
0.04213953f,
0.0003007996f,
-0.008032114f,
-0.03059979f,
-0.0003182998f,
0.009640567f,
0f,
0f,
0f,
0f,
0f,
0f,
0.5768794f,
0.01061097f,
-0.1127839f,
0.9705755f,
0.07972051f,
-0.0268422f,
0.007237188f,
0f,
0.5768792f,
0.01056608f,
-0.1127519f,
0.9705756f,
0.07971933f,
-0.02682396f,
0.007229362f,
0f,
-5.651802E-06f,
-3.034899E-07f,
0.4100508f,
0.3610304f,
-0.0838329f,
0.9262537f,
0.1353517f,
-0.03578902f,
0.06005657f,
-4.95989E-06f,
-1.43007E-06f,
0.4096187f,
0.363263f,
-0.08205152f,
0.9250782f,
0.1345718f,
-0.03572125f,
0.06055461f,
-1.079177f,
0.2095419f,
0.6140652f,
0.6365265f,
0.6683931f,
-0.4764312f,
0.8099416f,
0.8099371f,
0.6658203f,
-0.7327053f,
0.8113618f,
0.8114051f,
0.6643661f,
-0.40341f,
0.8111364f,
0.8111367f,
0.6170399f,
-0.2524227f,
0.8138723f,
0.8110135f,
-1.079171f,
0.2095456f,
0.6140658f,
0.6365255f,
0.6683878f,
-0.4764301f,
0.8099402f,
0.8099376f,
0.6658241f,
-0.7327023f,
0.8113653f,
0.8113793f,
0.664364f,
-0.4034042f,
0.811136f,
0.8111364f,
0.6170469f,
-0.2524345f,
0.8138595f,
0.8110138f
};
}
internal static class PlayerSetupPatches
@ -392,34 +277,30 @@ internal static class PlayerSetupPatches
[HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.ResetIk))]
private static bool Prefix_PlayerSetup_ResetIk()
{
if (IKSystem.vrik == null) return false;
if (IKSystem.vrik == null)
return false;
CVRMovementParent currentParent = MovementSystem.Instance._currentParent;
if (currentParent != null && currentParent._referencePoint != null)
{
// Get current position, VR pivots around VR camera
Vector3 currentPosition = MovementSystem.Instance.rotationPivot.transform.position;
currentPosition.y = IKSystem.vrik.transform.position.y; // set pivot to floor
Quaternion currentRotation = Quaternion.Euler(0f, currentParent.transform.rotation.eulerAngles.y, 0f);
if (currentParent == null || currentParent._referencePoint == null)
return true;
// Get current position, VR pivots around VR camera
Vector3 currentPosition = MovementSystem.Instance.rotationPivot.transform.position;
currentPosition.y = IKSystem.vrik.transform.position.y; // set pivot to floor
Quaternion currentRotation = Quaternion.Euler(0f, currentParent.transform.rotation.eulerAngles.y, 0f);
// Convert to delta position (how much changed since last frame)
Vector3 deltaPosition = currentPosition - lastMovementPosition;
Quaternion deltaRotation = Quaternion.Inverse(lastMovementRotation) * currentRotation;
// Convert to delta position (how much changed since last frame)
Vector3 deltaPosition = currentPosition - lastMovementPosition;
Quaternion deltaRotation = Quaternion.Inverse(lastMovementRotation) * currentRotation;
// Prevent targeting other parent position
if (lastMovementParent == currentParent || lastMovementParent == null)
{
// Add platform motion to IK solver
IKSystem.vrik.solver.AddPlatformMotion(deltaPosition, deltaRotation, currentPosition);
}
// Store for next frame
lastMovementParent = currentParent;
lastMovementPosition = currentPosition;
lastMovementRotation = currentRotation;
return false;
}
return true;
// Prevent targeting previous movement parent
if (lastMovementParent == currentParent || lastMovementParent == null)
IKSystem.vrik.solver.AddPlatformMotion(deltaPosition, deltaRotation, currentPosition);
lastMovementParent = currentParent;
lastMovementPosition = currentPosition;
lastMovementRotation = currentRotation;
return false;
}
}