mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 22:39:22 +00:00
fixes
This commit is contained in:
parent
bf1dbf5e01
commit
ae3e6ffa42
3 changed files with 140 additions and 7 deletions
|
@ -1,5 +1,8 @@
|
|||
using ABI_RC.Systems.IK;
|
||||
using ABI.CCK.Components;
|
||||
using ABI_RC.Core.Player;
|
||||
using ABI_RC.Systems.IK;
|
||||
using ABI_RC.Systems.IK.SubSystems;
|
||||
using ABI_RC.Systems.MovementSystem;
|
||||
using HarmonyLib;
|
||||
using RootMotion.FinalIK;
|
||||
using UnityEngine;
|
||||
|
@ -38,13 +41,105 @@ internal static class BodySystemPatches
|
|||
}
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(BodySystem), "Update")]
|
||||
private static void Postfix_BodySystem_Update()
|
||||
private static bool Prefix_BodySystem_Update(ref BodySystem __instance)
|
||||
{
|
||||
if (IKSystem.vrik == null) return false;
|
||||
IKSolverVR solver = IKSystem.vrik.solver;
|
||||
|
||||
// Allow avatar to rotate seperatly from Player (Desktop&VR)
|
||||
// FBT needs avatar root to follow head
|
||||
if (IKSystem.vrik != null)
|
||||
IKSystem.vrik.solver.spine.maxRootAngle = BodySystem.isCalibratedAsFullBody ? 0f : 180f;
|
||||
solver.spine.maxRootAngle = BodySystem.isCalibratedAsFullBody ? 0f : 180f;
|
||||
|
||||
if (BodySystem.TrackingEnabled)
|
||||
{
|
||||
IKSystem.vrik.enabled = true;
|
||||
solver.IKPositionWeight = BodySystem.TrackingPositionWeight;
|
||||
solver.locomotion.weight = BodySystem.TrackingLocomotionEnabled ? 1f : 0f;
|
||||
|
||||
// fixes arm weights not being set if leftArm & rightArm targets are null
|
||||
// game handles TrackingLegs in PlayerSetup, but not for knee goals
|
||||
SetArmWeight(solver.leftArm, BodySystem.TrackingLeftArmEnabled && solver.leftArm.target != null ? 1f : 0f);
|
||||
SetArmWeight(solver.rightArm, BodySystem.TrackingRightArmEnabled && solver.rightArm.target != null ? 1f : 0f);
|
||||
SetLegWeight(solver.leftLeg, BodySystem.TrackingLeftLegEnabled && solver.leftLeg.target != null ? 1f : 0f);
|
||||
SetLegWeight(solver.rightLeg, BodySystem.TrackingRightLegEnabled && solver.leftLeg.target != null ? 1f : 0f);
|
||||
SetPelvisWeight(solver.spine, solver.spine.pelvisTarget != null ? 1f : 0f);
|
||||
|
||||
// makes running animation look better
|
||||
if (BodySystem.isCalibratedAsFullBody)
|
||||
{
|
||||
bool isRunning = BodySystem.PlayRunningAnimationInFullBody && MovementSystem.Instance.movementVector.magnitude > 0f;
|
||||
SetPelvisWeight(solver.spine, isRunning ? 0f : 1f);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
IKSystem.vrik.enabled = false;
|
||||
solver.IKPositionWeight = 0f;
|
||||
solver.locomotion.weight = 0f;
|
||||
|
||||
SetArmWeight(solver.leftArm, 0f);
|
||||
SetArmWeight(solver.rightArm, 0f);
|
||||
SetLegWeight(solver.leftLeg, 0f);
|
||||
SetLegWeight(solver.rightLeg, 0f);
|
||||
SetPelvisWeight(solver.spine, 0f);
|
||||
}
|
||||
|
||||
int num = 0;
|
||||
int count = IKSystem.Instance.AllTrackingPoints.FindAll((TrackingPoint m) => m.isActive && m.isValid && m.suggestedRole > TrackingPoint.TrackingRole.Invalid).Count;
|
||||
|
||||
// fixes having all tracking points disabled forcing calibration
|
||||
if (count == 0)
|
||||
{
|
||||
__instance._fbtAvailable = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
// solid body count block
|
||||
if (BodySystem.enableLeftFootTracking) num++;
|
||||
if (BodySystem.enableRightFootTracking) num++;
|
||||
if (BodySystem.enableHipTracking) num++;
|
||||
if (BodySystem.enableLeftKneeTracking) num++;
|
||||
if (BodySystem.enableRightKneeTracking) num++;
|
||||
if (BodySystem.enableChestTracking) num++;
|
||||
if (BodySystem.enableLeftElbowTracking) num++;
|
||||
if (BodySystem.enableRightElbowTracking) num++;
|
||||
|
||||
__instance._fbtAvailable = (count >= num);
|
||||
|
||||
void SetArmWeight(IKSolverVR.Arm arm, float weight)
|
||||
{
|
||||
arm.positionWeight = weight;
|
||||
arm.rotationWeight = weight;
|
||||
arm.shoulderRotationWeight = weight;
|
||||
arm.shoulderTwistWeight = weight;
|
||||
// assumed fix of bend goal weight if arms disabled with elbows (havent tested)
|
||||
arm.bendGoalWeight = arm.bendGoal != null ? weight : 0f;
|
||||
}
|
||||
void SetLegWeight(IKSolverVR.Leg leg, float weight)
|
||||
{
|
||||
leg.positionWeight = weight;
|
||||
leg.rotationWeight = weight;
|
||||
// fixes knees bending to tracker if feet disabled (running anim)
|
||||
leg.bendGoalWeight = leg.bendGoal != null ? weight : 0f;
|
||||
}
|
||||
void SetPelvisWeight(IKSolverVR.Spine spine, float weight)
|
||||
{
|
||||
// looks better when hips are disabled while running
|
||||
if (spine.pelvisTarget != null)
|
||||
{
|
||||
spine.pelvisPositionWeight = weight;
|
||||
spine.pelvisRotationWeight = weight;
|
||||
}
|
||||
else
|
||||
{
|
||||
spine.pelvisPositionWeight = 0f;
|
||||
spine.pelvisRotationWeight = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,4 +184,41 @@ internal static class VRIKPatches
|
|||
if (__instance.usingKneeTracker)
|
||||
__instance.ApplyBendGoal();
|
||||
}
|
||||
}
|
||||
|
||||
internal static class PlayerSetupPatches
|
||||
{
|
||||
// Last Movement Parent Info
|
||||
static Vector3 lastMovementPosition;
|
||||
static Quaternion lastMovementRotation;
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(PlayerSetup), "ResetIk")]
|
||||
private static bool Prefix_PlayerSetup_ResetIk()
|
||||
{
|
||||
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);
|
||||
|
||||
// Convert to delta position (how much changed since last frame)
|
||||
Vector3 deltaPosition = currentPosition - lastMovementPosition;
|
||||
Quaternion deltaRotation = Quaternion.Inverse(lastMovementRotation) * currentRotation;
|
||||
|
||||
// Add platform motion to IK solver
|
||||
IKSystem.vrik.solver.AddPlatformMotion(deltaPosition, deltaRotation, currentPosition);
|
||||
|
||||
// Store for next frame
|
||||
lastMovementPosition = currentPosition;
|
||||
lastMovementRotation = currentRotation;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue