mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 14:29:25 +00:00
[DesktopVRIK] Fixes for r173
This commit is contained in:
parent
0d4e6e6331
commit
892ff611b5
8 changed files with 72 additions and 23 deletions
|
@ -1,5 +1,6 @@
|
||||||
using ABI.CCK.Components;
|
using ABI.CCK.Components;
|
||||||
using ABI_RC.Core.Player;
|
using ABI_RC.Core.Player;
|
||||||
|
using ABI_RC.Systems.IK;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using NAK.DesktopVRIK.IK;
|
using NAK.DesktopVRIK.IK;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
@ -100,6 +101,26 @@ internal class PlayerSetupPatches
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HarmonyPrefix]
|
||||||
|
[HarmonyPatch(typeof(IKSystem), nameof(IKSystem.OffsetMovementParent))]
|
||||||
|
private static void Prefix_IKSystem_OffsetMovementParent(CVRMovementParent currentParent, ref IKSystem __instance, ref bool __runOriginal)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
__runOriginal = true;
|
||||||
|
if (IKManager.Instance == null || !IKManager.Instance.IsAvatarInitialized())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (currentParent != null && currentParent._referencePoint != null)
|
||||||
|
__runOriginal = IKManager.Instance.OnPlayerHandleMovementParent(currentParent);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
DesktopVRIK.Logger.Error($"Error during the patched method {nameof(Prefix_IKSystem_OffsetMovementParent)}");
|
||||||
|
DesktopVRIK.Logger.Error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
[HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.ResetIk))]
|
[HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.ResetIk))]
|
||||||
private static void Prefix_PlayerSetup_ResetIk(ref PlayerSetup __instance, ref bool __runOriginal)
|
private static void Prefix_PlayerSetup_ResetIk(ref PlayerSetup __instance, ref bool __runOriginal)
|
||||||
|
@ -112,9 +133,9 @@ internal class PlayerSetupPatches
|
||||||
|
|
||||||
CVRMovementParent currentParent = __instance._movementSystem._currentParent;
|
CVRMovementParent currentParent = __instance._movementSystem._currentParent;
|
||||||
if (currentParent != null && currentParent._referencePoint != null)
|
if (currentParent != null && currentParent._referencePoint != null)
|
||||||
IKManager.Instance.OnPlayerHandleMovementParent(currentParent);
|
__runOriginal = IKManager.Instance.OnPlayerHandleMovementParent(currentParent);
|
||||||
else
|
else
|
||||||
IKManager.Instance.OnPlayerTeleported();
|
__runOriginal = IKManager.Instance.OnPlayerTeleported();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using ABI.CCK.Components;
|
using ABI_RC.Core.InteractionSystem;
|
||||||
|
using ABI.CCK.Components;
|
||||||
using ABI_RC.Systems.IK.SubSystems;
|
using ABI_RC.Systems.IK.SubSystems;
|
||||||
using NAK.DesktopVRIK.IK.VRIKHelpers;
|
using NAK.DesktopVRIK.IK.VRIKHelpers;
|
||||||
using RootMotion.FinalIK;
|
using RootMotion.FinalIK;
|
||||||
|
@ -143,10 +144,10 @@ internal abstract class IKHandler
|
||||||
{
|
{
|
||||||
_ikSimulatedRootAngle = _vrik.transform.eulerAngles.y;
|
_ikSimulatedRootAngle = _vrik.transform.eulerAngles.y;
|
||||||
|
|
||||||
|
_solver.Reset();
|
||||||
|
|
||||||
if(ModSettings.EntryResetFootstepsOnIdle.Value)
|
if(ModSettings.EntryResetFootstepsOnIdle.Value)
|
||||||
VRIKUtils.ResetToInitialFootsteps(_vrik, _locomotionData, _scaleDifference);
|
VRIKUtils.ResetToInitialFootsteps(_vrik, _locomotionData, _scaleDifference);
|
||||||
|
|
||||||
_solver.Reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
@ -107,10 +107,11 @@ internal class IKHandlerDesktop : IKHandler
|
||||||
bool isProne = MovementSystem.Instance.prone;
|
bool isProne = MovementSystem.Instance.prone;
|
||||||
bool isFlying = MovementSystem.Instance.flying;
|
bool isFlying = MovementSystem.Instance.flying;
|
||||||
bool isSitting = MovementSystem.Instance.sitting;
|
bool isSitting = MovementSystem.Instance.sitting;
|
||||||
|
bool isSwimming = MovementSystem.Instance.GetSubmerged();
|
||||||
bool isStanding = PlayerSetup.Instance.avatarUpright >=
|
bool isStanding = PlayerSetup.Instance.avatarUpright >=
|
||||||
Mathf.Max(PlayerSetup.Instance.avatarProneLimit, PlayerSetup.Instance.avatarCrouchLimit);
|
Mathf.Max(PlayerSetup.Instance.avatarProneLimit, PlayerSetup.Instance.avatarCrouchLimit);
|
||||||
|
|
||||||
return !(isMoving || isCrouching || isProne || isFlying || isSitting || !isGrounded || !isStanding);
|
return !(isMoving || isCrouching || isProne || isFlying || isSwimming || isSitting || !isGrounded || !isStanding);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ResetSolverIfNeeded()
|
private void ResetSolverIfNeeded()
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
using ABI_RC.Core.Player;
|
using ABI_RC.Core.Player;
|
||||||
using ABI_RC.Core.Savior;
|
using ABI_RC.Core.Savior;
|
||||||
using ABI_RC.Systems.IK.SubSystems;
|
using ABI_RC.Systems.IK.SubSystems;
|
||||||
|
using ABI_RC.Systems.MovementSystem;
|
||||||
using NAK.DesktopVRIK.IK.IKHandlers;
|
using NAK.DesktopVRIK.IK.IKHandlers;
|
||||||
using NAK.DesktopVRIK.IK.VRIKHelpers;
|
using NAK.DesktopVRIK.IK.VRIKHelpers;
|
||||||
using RootMotion.FinalIK;
|
using RootMotion.FinalIK;
|
||||||
|
@ -29,7 +30,7 @@ public class IKManager : MonoBehaviour
|
||||||
|
|
||||||
// Avatar Info
|
// Avatar Info
|
||||||
private Animator _animator;
|
private Animator _animator;
|
||||||
private Transform _hipTransform;
|
internal Transform _hipTransform;
|
||||||
|
|
||||||
// Animator Info
|
// Animator Info
|
||||||
private int _animLocomotionLayer = -1;
|
private int _animLocomotionLayer = -1;
|
||||||
|
@ -38,9 +39,9 @@ public class IKManager : MonoBehaviour
|
||||||
private const string _ikposeLayerName = "IKPose";
|
private const string _ikposeLayerName = "IKPose";
|
||||||
|
|
||||||
// Pose Info
|
// Pose Info
|
||||||
private HumanPoseHandler _humanPoseHandler;
|
internal HumanPoseHandler _humanPoseHandler;
|
||||||
private HumanPose _humanPose;
|
internal HumanPose _humanPose;
|
||||||
private HumanPose _humanPoseInitial;
|
internal HumanPose _humanPoseInitial;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -127,6 +128,8 @@ public class IKManager : MonoBehaviour
|
||||||
if (_ikHandler == null)
|
if (_ikHandler == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
DesktopVRIK.Logger.Msg(scaleDifference);
|
||||||
|
|
||||||
_ikHandler.OnPlayerScaled(scaleDifference);
|
_ikHandler.OnPlayerScaled(scaleDifference);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -204,6 +207,7 @@ public class IKManager : MonoBehaviour
|
||||||
|
|
||||||
VRIKUtils.ApplyScaleToVRIK(_vrik, _ikHandler._locomotionData, 1f);
|
VRIKUtils.ApplyScaleToVRIK(_vrik, _ikHandler._locomotionData, 1f);
|
||||||
_vrik.onPreSolverUpdate.AddListener(OnPreSolverUpdateGeneral);
|
_vrik.onPreSolverUpdate.AddListener(OnPreSolverUpdateGeneral);
|
||||||
|
_vrik.onPreSolverUpdate.AddListener(OnPreSolverUpdateDesktopSwimming);
|
||||||
_vrik.onPostSolverUpdate.AddListener(OnPostSolverUpdateGeneral);
|
_vrik.onPostSolverUpdate.AddListener(OnPostSolverUpdateGeneral);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,6 +244,35 @@ public class IKManager : MonoBehaviour
|
||||||
|
|
||||||
#region VRIK Solver Events General
|
#region VRIK Solver Events General
|
||||||
|
|
||||||
|
private void OnPreSolverUpdateDesktopSwimming()
|
||||||
|
{
|
||||||
|
if (_solver.IKPositionWeight < 0.9f)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Vector3 headPosition = _animator.GetBoneTransform(HumanBodyBones.Head).position;
|
||||||
|
|
||||||
|
// rotate hips around head bone to simulate diving
|
||||||
|
if (MovementSystem.Instance._playerIsSubmerged)
|
||||||
|
{
|
||||||
|
const float maxAngleForward = 85f;
|
||||||
|
const float maxAngleBackward = -85f;
|
||||||
|
|
||||||
|
float lookAngle = _desktopCamera.localEulerAngles.x;
|
||||||
|
if (lookAngle > 180) lookAngle -= 360;
|
||||||
|
|
||||||
|
lookAngle = Mathf.Clamp(lookAngle, maxAngleBackward, maxAngleForward);
|
||||||
|
float multiplier = Mathf.Lerp(0f, 1f, (MovementSystem.Instance.movementVector.magnitude - 0.5f) * 2f); // blend in when moving w/ sprint
|
||||||
|
multiplier *= (-1f * MovementSystem.Instance.GetDepth()); // blend out when at surface
|
||||||
|
|
||||||
|
_solver.IKPositionWeight = 1f - (-1f * multiplier); // disable IK completely when fast swimming (only applicable to DesktopVRIK)
|
||||||
|
_hipTransform.RotateAround(headPosition, _animator.transform.right, lookAngle * multiplier);
|
||||||
|
}
|
||||||
|
|
||||||
|
// offset avatar hips so head bone is centered on avatar root
|
||||||
|
// this fixes animations becoming scrunched up once VRIK solves!
|
||||||
|
_hipTransform.position -= (headPosition - _animator.transform.position) with { y = 0f };
|
||||||
|
}
|
||||||
|
|
||||||
private void OnPreSolverUpdateGeneral()
|
private void OnPreSolverUpdateGeneral()
|
||||||
{
|
{
|
||||||
if (_solver.IKPositionWeight < 0.9f)
|
if (_solver.IKPositionWeight < 0.9f)
|
||||||
|
|
|
@ -39,9 +39,9 @@ public static class VRIKUtils
|
||||||
|
|
||||||
// hack, use parent transform instead as setting feet position moves root (root.parent), but does not work for VR
|
// hack, use parent transform instead as setting feet position moves root (root.parent), but does not work for VR
|
||||||
var footsteps = vrik.solver.locomotion.footsteps;
|
var footsteps = vrik.solver.locomotion.footsteps;
|
||||||
footsteps[0].Reset(rootWorldRot, root.TransformPoint(locomotionData.InitialFootPosLeft * scaleModifier),
|
footsteps[0].Reset(rootWorldRot, root.TransformPoint(locomotionData.InitialFootPosLeft),
|
||||||
rootWorldRot * locomotionData.InitialFootRotLeft);
|
rootWorldRot * locomotionData.InitialFootRotLeft);
|
||||||
footsteps[1].Reset(rootWorldRot, root.TransformPoint(locomotionData.InitialFootPosRight * scaleModifier),
|
footsteps[1].Reset(rootWorldRot, root.TransformPoint(locomotionData.InitialFootPosRight),
|
||||||
rootWorldRot * locomotionData.InitialFootRotRight);
|
rootWorldRot * locomotionData.InitialFootRotRight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,11 +40,4 @@ public static class ModSettings
|
||||||
|
|
||||||
public static readonly MelonPreferences_Entry<bool> EntryProneThrusting =
|
public static readonly MelonPreferences_Entry<bool> EntryProneThrusting =
|
||||||
Category.CreateEntry("Prone Thrusting", false, description: "Allows Body Lean Weight to take effect while crouched or prone.");
|
Category.CreateEntry("Prone Thrusting", false, description: "Allows Body Lean Weight to take effect while crouched or prone.");
|
||||||
|
|
||||||
public static readonly MelonPreferences_Entry<bool> EntryNetIKPass =
|
|
||||||
Category.CreateEntry("Network IK Pass", true, description: "Should NetIK pass be applied? This fixes a bunch of small rotation errors after VRIK is run.");
|
|
||||||
|
|
||||||
public static readonly MelonPreferences_Entry<bool> EntryIntegrationAMT =
|
|
||||||
Category.CreateEntry("AMT Integration", true, description: "Relies on AvatarMotionTweaker to handle VRIK Locomotion weights if available.");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,6 @@ using System.Reflection;
|
||||||
namespace NAK.DesktopVRIK.Properties;
|
namespace NAK.DesktopVRIK.Properties;
|
||||||
internal static class AssemblyInfoParams
|
internal static class AssemblyInfoParams
|
||||||
{
|
{
|
||||||
public const string Version = "4.2.7";
|
public const string Version = "4.2.9";
|
||||||
public const string Author = "NotAKidoS";
|
public const string Author = "NotAKidoS";
|
||||||
}
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
{
|
{
|
||||||
"_id": 117,
|
"_id": 117,
|
||||||
"name": "DesktopVRIK",
|
"name": "DesktopVRIK",
|
||||||
"modversion": "4.2.7",
|
"modversion": "4.2.9",
|
||||||
"gameversion": "2023r172",
|
"gameversion": "2023r173",
|
||||||
"loaderversion": "0.6.1",
|
"loaderversion": "0.6.1",
|
||||||
"modtype": "Mod",
|
"modtype": "Mod",
|
||||||
"author": "NotAKidoS",
|
"author": "NotAKidoS",
|
||||||
|
@ -19,6 +19,6 @@
|
||||||
],
|
],
|
||||||
"downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r22/DesktopVRIK.dll",
|
"downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r22/DesktopVRIK.dll",
|
||||||
"sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/DesktopVRIK/",
|
"sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/DesktopVRIK/",
|
||||||
"changelog": "- Fixed Prone Thrusting option ignoring set Body Leaning weight.\n- Potential fix for avatars feet randomly targeting far away while stutter-stepping.",
|
"changelog": "- Fixes for 2023r173.\n- Fixed ResetFootstepsOnIdle not working as intended.\n- Added swimming pitch control.\n- Added active body offset.",
|
||||||
"embedcolor": "#9b59b6"
|
"embedcolor": "#9b59b6"
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue