test reset footsteps option

This commit is contained in:
NotAKidoS 2023-03-29 06:10:25 -05:00
parent fbd767036b
commit d3c2365a1d
4 changed files with 39 additions and 3 deletions

View file

@ -124,6 +124,7 @@ internal class DesktopVRIKSystem : MonoBehaviour
// DesktopVRIK Settings // DesktopVRIK Settings
public bool Setting_Enabled = true; public bool Setting_Enabled = true;
public bool Setting_PlantFeet = true; public bool Setting_PlantFeet = true;
public bool Setting_ResetFootsteps;
public float Setting_BodyLeanWeight; public float Setting_BodyLeanWeight;
public float Setting_BodyHeadingLimit; public float Setting_BodyHeadingLimit;
public float Setting_PelvisHeadingWeight; public float Setting_PelvisHeadingWeight;
@ -161,6 +162,8 @@ internal class DesktopVRIKSystem : MonoBehaviour
// VRIK Calibration Info // VRIK Calibration Info
Vector3 _leftKneeNormal; Vector3 _leftKneeNormal;
Vector3 _rightKneeNormal; Vector3 _rightKneeNormal;
Vector3 _initialFootStepLeft;
Vector3 _initialFootStepRight;
float _initialFootDistance; float _initialFootDistance;
float _initialStepThreshold; float _initialStepThreshold;
float _initialStepHeight; float _initialStepHeight;
@ -212,8 +215,8 @@ internal class DesktopVRIKSystem : MonoBehaviour
bool isFlying = movementSystem.flying; bool isFlying = movementSystem.flying;
// Why do it myself if VRIK already does the maths // Why do it myself if VRIK already does the maths
Vector3 headLocalPos = avatarIKSolver.spine.headPosition - avatarIKSolver.spine.rootPosition; Vector3 headLocalPos = avatarTransform.TransformPoint(avatarIKSolver.spine.headPosition);
float upright = 1f + (headLocalPos.y - avatarIKSolver.spine.headHeight); float upright = 1f + (avatarIKSolver.spine.headHeight - headLocalPos.y);
if (isMoving || isCrouching || isProne || isFlying || !isGrounded) if (isMoving || isCrouching || isProne || isFlying || !isGrounded)
{ {
@ -310,7 +313,7 @@ internal class DesktopVRIKSystem : MonoBehaviour
if (avatarVRIK == null) return; if (avatarVRIK == null) return;
if (isEmotePlaying == _isEmotePlaying) return; if (isEmotePlaying == _isEmotePlaying) return;
_isEmotePlaying = isEmotePlaying; _isEmotePlaying = isEmotePlaying;
if (avatarLookAtIK != null) if (avatarLookAtIK != null)
@ -359,6 +362,12 @@ internal class DesktopVRIKSystem : MonoBehaviour
if (_isEmotePlaying) return; if (_isEmotePlaying) return;
// Constantly reset footsteps until fully idle
if (_locomotionWeightLerp < 0.99f)
{
ResetFootsteps();
}
// Set plant feet // Set plant feet
avatarIKSolver.plantFeet = Setting_PlantFeet; avatarIKSolver.plantFeet = Setting_PlantFeet;
@ -401,6 +410,19 @@ internal class DesktopVRIKSystem : MonoBehaviour
_simulatedRootAngle = transform.eulerAngles.y; _simulatedRootAngle = transform.eulerAngles.y;
} }
void ResetFootsteps()
{
if (!Setting_ResetFootsteps) return;
IKSolverVR.Footstep footstepLeft = avatarIKSolver.locomotion.footsteps[0];
IKSolverVR.Footstep footstepRight = avatarIKSolver.locomotion.footsteps[1];
Vector3 globalLeft = movementSystem.transform.TransformPoint(_initialFootStepLeft);
Vector3 globalRight = movementSystem.transform.TransformPoint(_initialFootStepRight);
footstepLeft.Reset(avatarTransform.rotation, globalLeft, footstepLeft.stepToRot);
footstepRight.Reset(avatarTransform.rotation, globalRight, footstepRight.stepToRot);
//footstepRight.StepTo(globalRight, avatarTransform.rotation, 100f);
//footstepLeft.StepTo(globalLeft, avatarTransform.rotation, 100f);
}
void CalibrateDesktopVRIK() void CalibrateDesktopVRIK()
{ {
ScanAvatar(); ScanAvatar();
@ -514,6 +536,9 @@ internal class DesktopVRIKSystem : MonoBehaviour
// Calculate initial IK scaling values with IKPose // Calculate initial IK scaling values with IKPose
VRIKUtils.CalculateInitialIKScaling(avatarVRIK, out _initialFootDistance, out _initialStepThreshold, out _initialStepHeight); VRIKUtils.CalculateInitialIKScaling(avatarVRIK, out _initialFootDistance, out _initialStepThreshold, out _initialStepHeight);
// Calculate initial Footstep positions
VRIKUtils.CalculateInitialFootsteps(avatarVRIK, out _initialFootStepLeft, out _initialFootStepRight);
// Setup HeadIKTarget // Setup HeadIKTarget
VRIKUtils.SetupHeadIKTarget(avatarVRIK); VRIKUtils.SetupHeadIKTarget(avatarVRIK);

View file

@ -26,6 +26,7 @@ public static class BTKUIAddon
// General Settings // General Settings
AddMelonToggle(ref desktopVRIKCategory, DesktopVRIKMod.EntryEnabled); AddMelonToggle(ref desktopVRIKCategory, DesktopVRIKMod.EntryEnabled);
AddMelonToggle(ref desktopVRIKCategory, DesktopVRIKMod.EntryPlantFeet); AddMelonToggle(ref desktopVRIKCategory, DesktopVRIKMod.EntryPlantFeet);
AddMelonToggle(ref desktopVRIKCategory, DesktopVRIKMod.EntryResetFootstepsOnIdle);
// Calibration Settings // Calibration Settings
AddMelonToggle(ref desktopVRIKCategory, DesktopVRIKMod.EntryUseVRIKToes); AddMelonToggle(ref desktopVRIKCategory, DesktopVRIKMod.EntryUseVRIKToes);

View file

@ -18,6 +18,9 @@ public class DesktopVRIKMod : MelonMod
public static readonly MelonPreferences_Entry<bool> EntryUseVRIKToes = public static readonly MelonPreferences_Entry<bool> EntryUseVRIKToes =
CategoryDesktopVRIK.CreateEntry("Use VRIK Toes", false, description: "Determines if VRIK uses humanoid toes for IK solving, which can cause feet to idle behind the avatar."); CategoryDesktopVRIK.CreateEntry("Use VRIK Toes", false, description: "Determines if VRIK uses humanoid toes for IK solving, which can cause feet to idle behind the avatar.");
public static readonly MelonPreferences_Entry<bool> EntryResetFootstepsOnIdle =
CategoryDesktopVRIK.CreateEntry("Reset Footsteps on Idle", false, description: "Forces Locomotion Footsteps to reset to their initial position on return to idle. This is a bit aggressive.");
public static readonly MelonPreferences_Entry<bool> EntryFindUnmappedToes = public static readonly MelonPreferences_Entry<bool> EntryFindUnmappedToes =
CategoryDesktopVRIK.CreateEntry("Find Unmapped Toes", false, description: "Determines if DesktopVRIK should look for unmapped toe bones if the humanoid rig does not have any."); CategoryDesktopVRIK.CreateEntry("Find Unmapped Toes", false, description: "Determines if DesktopVRIK should look for unmapped toe bones if the humanoid rig does not have any.");
@ -55,6 +58,7 @@ public class DesktopVRIKMod : MelonMod
// DesktopVRIK Settings // DesktopVRIK Settings
DesktopVRIKSystem.Instance.Setting_Enabled = EntryEnabled.Value; DesktopVRIKSystem.Instance.Setting_Enabled = EntryEnabled.Value;
DesktopVRIKSystem.Instance.Setting_PlantFeet = EntryPlantFeet.Value; DesktopVRIKSystem.Instance.Setting_PlantFeet = EntryPlantFeet.Value;
DesktopVRIKSystem.Instance.Setting_ResetFootsteps = EntryResetFootstepsOnIdle.Value;
DesktopVRIKSystem.Instance.Setting_BodyLeanWeight = Mathf.Clamp01(EntryBodyLeanWeight.Value); DesktopVRIKSystem.Instance.Setting_BodyLeanWeight = Mathf.Clamp01(EntryBodyLeanWeight.Value);
DesktopVRIKSystem.Instance.Setting_BodyHeadingLimit = Mathf.Clamp(EntryBodyHeadingLimit.Value, 0f, 90f); DesktopVRIKSystem.Instance.Setting_BodyHeadingLimit = Mathf.Clamp(EntryBodyHeadingLimit.Value, 0f, 90f);

View file

@ -154,6 +154,12 @@ public static class VRIKUtils
initialStepHeight = Vector3.Distance(vrik.references.leftFoot.position, vrik.references.leftCalf.position) * 0.2f; initialStepHeight = Vector3.Distance(vrik.references.leftFoot.position, vrik.references.leftCalf.position) * 0.2f;
} }
public static void CalculateInitialFootsteps(VRIK vrik, out Vector3 initialFootstepLeft, out Vector3 initialFootstepRight)
{
initialFootstepLeft = vrik.references.root.InverseTransformPoint(vrik.references.leftFoot.position);
initialFootstepRight = vrik.references.root.InverseTransformPoint(vrik.references.rightFoot.position);
}
public static void SetupHeadIKTarget(VRIK vrik) public static void SetupHeadIKTarget(VRIK vrik)
{ {
// Lazy HeadIKTarget calibration // Lazy HeadIKTarget calibration