mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 06:19:22 +00:00
push
This commit is contained in:
parent
cbd65aa813
commit
a27d42d876
3 changed files with 113 additions and 105 deletions
|
@ -30,7 +30,6 @@ public class DesktopVRIK : MonoBehaviour
|
|||
private float
|
||||
ik_SimulatedRootAngle;
|
||||
private bool
|
||||
ms_lastGrounded,
|
||||
ps_emoteIsPlaying;
|
||||
static readonly FieldInfo ms_isGrounded = typeof(MovementSystem).GetField("_isGrounded", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
|
||||
|
@ -45,26 +44,31 @@ public class DesktopVRIK : MonoBehaviour
|
|||
{
|
||||
if (!Setting_Enabled) return;
|
||||
Calibrator.SetupDesktopVRIK();
|
||||
ik_SimulatedRootAngle = transform.eulerAngles.y;
|
||||
ResetDesktopVRIK();
|
||||
}
|
||||
|
||||
//public void OnReCalibrateAvatar()
|
||||
//{
|
||||
// Calibrator.RecalibrateDesktopVRIK();
|
||||
// ik_SimulatedRootAngle = transform.eulerAngles.y;
|
||||
//}
|
||||
|
||||
public bool OnApplyAvatarScaleToIk(float height)
|
||||
public bool OnSetupIKScaling(float avatarHeight, float scaleDifference)
|
||||
{
|
||||
if (Calibrator.vrik != null)
|
||||
{
|
||||
Calibrator.vrik.solver.locomotion.footDistance = Calibrator.initialFootDistance * height;
|
||||
Calibrator.vrik.solver.locomotion.stepThreshold = Calibrator.initialStepThreshold * height;
|
||||
Calibrator.vrik.solver.locomotion.footDistance = Calibrator.initialFootDistance * scaleDifference;
|
||||
Calibrator.vrik.solver.locomotion.stepThreshold = Calibrator.initialStepThreshold * scaleDifference;
|
||||
DesktopVRIK.ScaleStepHeight(Calibrator.vrik.solver.locomotion.stepHeight, Calibrator.initialStepHeight * scaleDifference);
|
||||
Calibrator.vrik.solver.Reset();
|
||||
ResetDesktopVRIK();
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void ScaleStepHeight(AnimationCurve stepHeightCurve, float mag)
|
||||
{
|
||||
Keyframe[] keyframes = stepHeightCurve.keys;
|
||||
keyframes[1].value = mag;
|
||||
stepHeightCurve.keys = keyframes;
|
||||
}
|
||||
|
||||
public void OnPlayerSetupUpdate(bool isEmotePlaying)
|
||||
{
|
||||
bool changed = isEmotePlaying != ps_emoteIsPlaying;
|
||||
|
@ -79,12 +83,21 @@ public class DesktopVRIK : MonoBehaviour
|
|||
}
|
||||
BodySystem.TrackingEnabled = !isEmotePlaying;
|
||||
Calibrator.vrik.solver?.Reset();
|
||||
ResetDesktopVRIK();
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetDesktopVRIK()
|
||||
{
|
||||
ik_SimulatedRootAngle = transform.eulerAngles.y;
|
||||
}
|
||||
|
||||
public void OnPreSolverUpdate()
|
||||
{
|
||||
if (ps_emoteIsPlaying) return;
|
||||
if (ps_emoteIsPlaying)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool isGrounded = (bool)ms_isGrounded.GetValue(MovementSystem.Instance);
|
||||
|
||||
|
@ -103,16 +116,6 @@ public class DesktopVRIK : MonoBehaviour
|
|||
// This is nice for walk cycles
|
||||
//Calibrator.vrik.solver.spine.rotateChestByHands = Setting_RotateChestByHands * weight;
|
||||
|
||||
//reset solver if weight changes dramatically
|
||||
if (Setting_ResetOnLand)
|
||||
{
|
||||
if (isGrounded && !ms_lastGrounded)
|
||||
{
|
||||
Calibrator.vrik.solver.Reset();
|
||||
}
|
||||
ms_lastGrounded = isGrounded;
|
||||
}
|
||||
|
||||
// Old VRChat hip movement emulation
|
||||
if (Setting_BodyLeanWeight > 0)
|
||||
{
|
||||
|
|
|
@ -40,35 +40,23 @@ public class DesktopVRIKCalibrator
|
|||
public Transform avatarTransform;
|
||||
public VRIK vrik;
|
||||
public LookAtIK lookAtIK;
|
||||
// Calibration
|
||||
public HumanPoseHandler humanPoseHandler;
|
||||
public HumanPose initialHumanPose;
|
||||
// Calibrator
|
||||
public bool fixTransformsRequired;
|
||||
public float initialFootDistance;
|
||||
public float initialStepThreshold;
|
||||
public float initialFootDistance, initialStepThreshold, initialStepHeight;
|
||||
|
||||
// Traverse
|
||||
private IKSystem ikSystem;
|
||||
private PlayerSetup playerSetup;
|
||||
private Traverse _vrikTraverse;
|
||||
private Traverse _lookIKTraverse;
|
||||
private Traverse _avatarTraverse;
|
||||
private Traverse _animatorManagerTraverse;
|
||||
private Traverse _poseHandlerTraverse;
|
||||
private Traverse _avatarRootHeightTraverse;
|
||||
|
||||
//public void RecalibrateDesktopVRIK()
|
||||
//{
|
||||
// if (avatar != null)
|
||||
// {
|
||||
// //calibrate VRIK
|
||||
// CalibrateDesktopVRIK();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //we never calibrated
|
||||
// SetupDesktopVRIK();
|
||||
// }
|
||||
//}
|
||||
private Traverse
|
||||
_vrikTraverse,
|
||||
_lookIKTraverse,
|
||||
_avatarTraverse,
|
||||
_animatorManagerTraverse,
|
||||
_poseHandlerTraverse,
|
||||
_avatarRootHeightTraverse;
|
||||
|
||||
public void SetupDesktopVRIK()
|
||||
{
|
||||
|
@ -92,9 +80,9 @@ public class DesktopVRIKCalibrator
|
|||
//calibrate VRIK
|
||||
PrepareAvatarVRIK();
|
||||
SetAvatarIKPose(true);
|
||||
CalculateInitialIKScaling();
|
||||
CalibrateHeadIK();
|
||||
ForceInitiateVRIKSolver();
|
||||
CalculateInitialIKScaling();
|
||||
SetAvatarIKPose(false);
|
||||
}
|
||||
|
||||
|
@ -220,18 +208,19 @@ public class DesktopVRIKCalibrator
|
|||
|
||||
private void CalculateInitialIKScaling()
|
||||
{
|
||||
// Get distance between feets and thighs (fixes some weird armatures)
|
||||
// Get distance between feets and thighs
|
||||
float footDistance = Vector3.Distance(vrik.references.leftFoot.position, vrik.references.rightFoot.position);
|
||||
float thighDistance = Vector3.Distance(vrik.references.leftThigh.position, vrik.references.rightThigh.position);
|
||||
float greatestDistance = Mathf.Min(footDistance, thighDistance);
|
||||
initialFootDistance = greatestDistance * 0.5f;
|
||||
initialStepThreshold = greatestDistance * 0.4f;
|
||||
initialFootDistance = footDistance * 0.5f;
|
||||
initialStepThreshold = footDistance * 0.4f;
|
||||
initialStepHeight = Vector3.Distance(vrik.references.leftFoot.position, vrik.references.leftCalf.position) * 0.2f;
|
||||
|
||||
//set initial values now, as avatars without scaling dont apply it
|
||||
// Set initial values
|
||||
vrik.solver.locomotion.footDistance = initialFootDistance;
|
||||
vrik.solver.locomotion.stepThreshold = initialStepThreshold;
|
||||
DesktopVRIK.ScaleStepHeight(vrik.solver.locomotion.stepHeight, initialStepHeight);
|
||||
}
|
||||
|
||||
|
||||
private void CalibrateHeadIK()
|
||||
{
|
||||
// Lazy HeadIKTarget calibration
|
||||
|
@ -262,12 +251,7 @@ public class DesktopVRIKCalibrator
|
|||
if (enforceTPose)
|
||||
{
|
||||
humanPoseHandler.GetHumanPose(ref initialHumanPose);
|
||||
humanPoseHandler.GetHumanPose(ref ikSystem.humanPose);
|
||||
for (int i = 0; i < IKPoseMuscles.Length; i++)
|
||||
{
|
||||
IKSystem.Instance.ApplyMuscleValue((MuscleIndex)i, IKPoseMuscles[i], ref ikSystem.humanPose.muscles);
|
||||
}
|
||||
humanPoseHandler.SetHumanPose(ref ikSystem.humanPose);
|
||||
SetCustomPose(IKPoseMuscles);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -275,6 +259,16 @@ public class DesktopVRIKCalibrator
|
|||
}
|
||||
}
|
||||
|
||||
private void SetCustomPose(float[] muscleValues)
|
||||
{
|
||||
humanPoseHandler.GetHumanPose(ref ikSystem.humanPose);
|
||||
for (int i = 0; i < muscleValues.Length; i++)
|
||||
{
|
||||
IKSystem.Instance.ApplyMuscleValue((MuscleIndex)i, muscleValues[i], ref ikSystem.humanPose.muscles);
|
||||
}
|
||||
humanPoseHandler.SetHumanPose(ref ikSystem.humanPose);
|
||||
}
|
||||
|
||||
private void ForceInitiateVRIKSolver()
|
||||
{
|
||||
//force immediate calibration before animator decides to fuck us
|
||||
|
@ -286,17 +280,8 @@ public class DesktopVRIKCalibrator
|
|||
{
|
||||
fixTransformsRequired = false;
|
||||
|
||||
Transform leftShoulderBone = vrik.references.leftShoulder;
|
||||
Transform rightShoulderBone = vrik.references.rightShoulder;
|
||||
Transform assumedChest = leftShoulderBone?.parent;
|
||||
|
||||
// Repair chest & spine bone references (valve models were messed up)
|
||||
if (assumedChest != null && rightShoulderBone.parent == assumedChest &&
|
||||
vrik.references.chest != assumedChest)
|
||||
{
|
||||
vrik.references.chest = assumedChest;
|
||||
vrik.references.spine = assumedChest.parent;
|
||||
}
|
||||
//might not work over netik
|
||||
FixChestAndSpineReferences();
|
||||
|
||||
if (!Setting_UseVRIKToes)
|
||||
{
|
||||
|
@ -304,36 +289,48 @@ public class DesktopVRIKCalibrator
|
|||
vrik.references.rightToes = null;
|
||||
}
|
||||
else if (Setting_FindUnmappedToes)
|
||||
{
|
||||
//doesnt work with netik, but its toes...
|
||||
FindAndSetUnmappedToes();
|
||||
}
|
||||
|
||||
//bullshit fix to not cause death
|
||||
FixFingerBonesError();
|
||||
}
|
||||
|
||||
private void FixChestAndSpineReferences()
|
||||
{
|
||||
Transform leftShoulderBone = vrik.references.leftShoulder;
|
||||
Transform rightShoulderBone = vrik.references.rightShoulder;
|
||||
Transform assumedChest = leftShoulderBone?.parent;
|
||||
|
||||
if (assumedChest != null && rightShoulderBone.parent == assumedChest &&
|
||||
vrik.references.chest != assumedChest)
|
||||
{
|
||||
vrik.references.chest = assumedChest;
|
||||
vrik.references.spine = assumedChest.parent;
|
||||
}
|
||||
}
|
||||
|
||||
private void FindAndSetUnmappedToes()
|
||||
{
|
||||
Transform leftToes = vrik.references.leftToes;
|
||||
Transform rightToes = vrik.references.rightToes;
|
||||
|
||||
if (leftToes == null && rightToes == null)
|
||||
{
|
||||
leftToes = FindUnmappedToe(vrik.references.leftFoot);
|
||||
rightToes = FindUnmappedToe(vrik.references.rightFoot);
|
||||
|
||||
if (leftToes != null && rightToes != null)
|
||||
{
|
||||
fixTransformsRequired = true;
|
||||
vrik.references.leftToes = leftToes;
|
||||
vrik.references.rightToes = rightToes;
|
||||
fixTransformsRequired = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fix error when there is no finger bones
|
||||
// Making up bullshit cause VRIK is evil otherwise
|
||||
if (vrik.references.leftHand.childCount == 0)
|
||||
{
|
||||
vrik.solver.leftArm.wristToPalmAxis = Vector3.up;
|
||||
vrik.solver.leftArm.palmToThumbAxis = -Vector3.forward;
|
||||
}
|
||||
if (vrik.references.rightHand.childCount == 0)
|
||||
{
|
||||
vrik.solver.rightArm.wristToPalmAxis = Vector3.up;
|
||||
vrik.solver.rightArm.palmToThumbAxis = Vector3.forward;
|
||||
}
|
||||
}
|
||||
|
||||
private Transform FindUnmappedToe(Transform foot)
|
||||
{
|
||||
foreach (Transform bone in foot)
|
||||
|
@ -348,6 +345,21 @@ public class DesktopVRIKCalibrator
|
|||
return null;
|
||||
}
|
||||
|
||||
private void FixFingerBonesError()
|
||||
{
|
||||
FixFingerBones(vrik.references.leftHand, vrik.solver.leftArm);
|
||||
FixFingerBones(vrik.references.rightHand, vrik.solver.rightArm);
|
||||
}
|
||||
|
||||
private void FixFingerBones(Transform hand, IKSolverVR.Arm armSolver)
|
||||
{
|
||||
if (hand.childCount == 0)
|
||||
{
|
||||
armSolver.wristToPalmAxis = Vector3.up;
|
||||
armSolver.palmToThumbAxis = hand == vrik.references.leftHand ? -Vector3.forward : Vector3.forward;
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly float[] IKPoseMuscles = new float[]
|
||||
{
|
||||
0.00133321f,
|
||||
|
|
|
@ -40,12 +40,12 @@ class PlayerSetupPatches
|
|||
DesktopVRIK.Instance?.OnPlayerSetupUpdate(____emotePlaying);
|
||||
}
|
||||
|
||||
//[HarmonyPostfix]
|
||||
//[HarmonyPatch(typeof(PlayerSetup), "ReCalibrateAvatar")]
|
||||
//static void Postfix_PlayerSetup_ReCalibrateAvatar()
|
||||
//{
|
||||
// DesktopVRIK.Instance?.OnReCalibrateAvatar();
|
||||
//}
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(PlayerSetup), "SetupIKScaling")]
|
||||
private static bool Prefix_PlayerSetup_SetupIKScaling(float height, ref Vector3 ___scaleDifference)
|
||||
{
|
||||
return !(bool)DesktopVRIK.Instance?.OnSetupIKScaling(height, 1f + ___scaleDifference.y);
|
||||
}
|
||||
}
|
||||
|
||||
class IKSystemPatches
|
||||
|
@ -56,11 +56,4 @@ class IKSystemPatches
|
|||
{
|
||||
__instance.gameObject.AddComponent<DesktopVRIK>();
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(IKSystem), "ApplyAvatarScaleToIk")]
|
||||
private static bool Prefix_IKSystem_ApplyAvatarScaleToIk(float height)
|
||||
{
|
||||
return !(bool)DesktopVRIK.Instance?.OnApplyAvatarScaleToIk(height);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue