mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-03 14:59:23 +00:00
[DesktopVRIK] wip
This commit is contained in:
parent
3c27df5274
commit
a3cee41021
3 changed files with 106 additions and 53 deletions
|
@ -184,7 +184,7 @@ internal class DesktopVRIKSystem : MonoBehaviour
|
|||
// Last Movement Parent Info
|
||||
Vector3 _movementPosition;
|
||||
Quaternion _movementRotation;
|
||||
CVRMovementParent _currentParent;
|
||||
CVRMovementParent _movementParent;
|
||||
|
||||
DesktopVRIKSystem()
|
||||
{
|
||||
|
@ -316,38 +316,48 @@ internal class DesktopVRIKSystem : MonoBehaviour
|
|||
avatarTransform.localRotation = Quaternion.identity;
|
||||
}
|
||||
|
||||
public void OnSetupAvatarDesktop()
|
||||
public void OnSetupAvatarDesktop(Animator animator)
|
||||
{
|
||||
if (!Setting_Enabled) return;
|
||||
|
||||
// only run for humanoid avatars
|
||||
if (animator != null && animator.avatar != null && animator.avatar.isHuman)
|
||||
{
|
||||
CalibrateDesktopVRIK();
|
||||
ResetDesktopVRIK();
|
||||
}
|
||||
}
|
||||
|
||||
public bool OnSetupIKScaling(float scaleDifference)
|
||||
{
|
||||
if (avatarVRIK == null) return false;
|
||||
|
||||
_scaleDifference = scaleDifference;
|
||||
|
||||
VRIKUtils.ApplyScaleToVRIK
|
||||
(
|
||||
avatarVRIK,
|
||||
_vrikInitialFootDistance,
|
||||
_vrikInitialStepThreshold,
|
||||
_vrikInitialStepHeight,
|
||||
scaleDifference
|
||||
_scaleDifference
|
||||
);
|
||||
|
||||
_scaleDifference = scaleDifference;
|
||||
//VRIKUtils.SetFootsteps
|
||||
//(
|
||||
// avatarVRIK,
|
||||
// _vrikInitialFootPosLeft * _scaleDifference,
|
||||
// _vrikInitialFootPosRight * _scaleDifference,
|
||||
// _vrikInitialFootRotLeft,
|
||||
// _vrikInitialFootRotRight
|
||||
//);
|
||||
|
||||
avatarIKSolver.Reset();
|
||||
ResetDesktopVRIK();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void OnPlayerSetupUpdate(bool isEmotePlaying)
|
||||
{
|
||||
if (avatarVRIK == null) return;
|
||||
|
||||
if (isEmotePlaying == _ikEmotePlaying) return;
|
||||
_ikEmotePlaying = isEmotePlaying;
|
||||
|
||||
|
@ -360,14 +370,18 @@ internal class DesktopVRIKSystem : MonoBehaviour
|
|||
ResetDesktopVRIK();
|
||||
}
|
||||
|
||||
public bool OnPlayerSetupResetIk()
|
||||
public void OnPlayerSetupSetSitting()
|
||||
{
|
||||
if (avatarVRIK == null) return false;
|
||||
avatarIKSolver.Reset();
|
||||
ResetDesktopVRIK();
|
||||
}
|
||||
|
||||
public void OnPlayerSetupResetIk()
|
||||
{
|
||||
// Check if PlayerSetup.ResetIk() was called for movement parent
|
||||
CVRMovementParent currentParent = movementSystem._currentParent;
|
||||
if (currentParent == null || currentParent._referencePoint == null) return false;
|
||||
|
||||
if (currentParent != null && currentParent._referencePoint != null)
|
||||
{
|
||||
// Get current position
|
||||
var currentPosition = currentParent._referencePoint.position;
|
||||
var currentRotation = Quaternion.Euler(0f, currentParent.transform.rotation.eulerAngles.y, 0f);
|
||||
|
@ -380,7 +394,7 @@ internal class DesktopVRIKSystem : MonoBehaviour
|
|||
var platformPivot = transform.position;
|
||||
|
||||
// Prevent targeting other parent position
|
||||
if (_currentParent == currentParent)
|
||||
if (_movementParent == currentParent)
|
||||
{
|
||||
// Add platform motion to IK solver
|
||||
avatarIKSolver.AddPlatformMotion(deltaPosition, deltaRotation, platformPivot);
|
||||
|
@ -388,11 +402,17 @@ internal class DesktopVRIKSystem : MonoBehaviour
|
|||
}
|
||||
|
||||
// Store for next frame
|
||||
_currentParent = currentParent;
|
||||
_movementParent = currentParent;
|
||||
_movementPosition = currentPosition;
|
||||
_movementRotation = currentRotation;
|
||||
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
// if not for movementparent, reset ik solver
|
||||
avatarIKSolver.Reset();
|
||||
ResetDesktopVRIK();
|
||||
//IKResetFootsteps();
|
||||
}
|
||||
|
||||
public void OnPreSolverUpdate()
|
||||
|
|
|
@ -28,40 +28,70 @@ namespace NAK.DesktopVRIK.HarmonyPatches;
|
|||
class PlayerSetupPatches
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(PlayerSetup), "Start")]
|
||||
[HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.Start))]
|
||||
static void Postfix_PlayerSetup_Start(ref PlayerSetup __instance)
|
||||
{
|
||||
__instance.gameObject.AddComponent<DesktopVRIKSystem>();
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(PlayerSetup), "SetupAvatarDesktop")]
|
||||
[HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.SetupAvatarDesktop))]
|
||||
static void Postfix_PlayerSetup_SetupAvatarDesktop(ref Animator ____animator)
|
||||
{
|
||||
if (____animator != null && ____animator.avatar != null && ____animator.avatar.isHuman)
|
||||
// only intercept if DesktopVRIK is being used
|
||||
if (DesktopVRIKSystem.Instance != null)
|
||||
{
|
||||
DesktopVRIKSystem.Instance?.OnSetupAvatarDesktop();
|
||||
DesktopVRIKSystem.Instance.OnSetupAvatarDesktop(____animator);
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(PlayerSetup), "Update")]
|
||||
[HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.Update))]
|
||||
static void Postfix_PlayerSetup_Update(ref bool ____emotePlaying)
|
||||
{
|
||||
DesktopVRIKSystem.Instance?.OnPlayerSetupUpdate(____emotePlaying);
|
||||
// only intercept if DesktopVRIK is being used
|
||||
if (DesktopVRIKSystem.Instance?.avatarVRIK != null)
|
||||
{
|
||||
DesktopVRIKSystem.Instance.OnPlayerSetupUpdate(____emotePlaying);
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(PlayerSetup), "SetupIKScaling")]
|
||||
[HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.SetupIKScaling))]
|
||||
private static bool Prefix_PlayerSetup_SetupIKScaling(float height, ref Vector3 ___scaleDifference)
|
||||
{
|
||||
return !(bool)DesktopVRIKSystem.Instance?.OnSetupIKScaling(1f + ___scaleDifference.y);
|
||||
// only intercept if DesktopVRIK is being used
|
||||
if (DesktopVRIKSystem.Instance?.avatarVRIK != null)
|
||||
{
|
||||
DesktopVRIKSystem.Instance.OnSetupIKScaling(1f + ___scaleDifference.y);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.SetSitting))]
|
||||
static void Postfix_PlayerSetup_SetSitting()
|
||||
{
|
||||
// only intercept if DesktopVRIK is being used
|
||||
if (DesktopVRIKSystem.Instance?.avatarVRIK != null)
|
||||
{
|
||||
DesktopVRIKSystem.Instance.OnPlayerSetupSetSitting();
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(PlayerSetup), "ResetIk")]
|
||||
[HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.ResetIk))]
|
||||
static bool Prefix_PlayerSetup_ResetIk()
|
||||
{
|
||||
return !(bool)DesktopVRIKSystem.Instance?.OnPlayerSetupResetIk();
|
||||
// only intercept if DesktopVRIK is being used
|
||||
if (DesktopVRIKSystem.Instance?.avatarVRIK != null)
|
||||
{
|
||||
DesktopVRIKSystem.Instance.OnPlayerSetupResetIk();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -136,9 +136,11 @@ public static class VRIKUtils
|
|||
var footstepLeft = footsteps[0];
|
||||
var footstepRight = footsteps[1];
|
||||
|
||||
var root = vrik.references.root;
|
||||
var rootWorldRot = vrik.references.root.rotation;
|
||||
footstepLeft.Reset(rootWorldRot, vrik.transform.TransformPoint(footPosLeft), rootWorldRot * footRotLeft);
|
||||
footstepRight.Reset(rootWorldRot, vrik.transform.TransformPoint(footPosRight), rootWorldRot * footRotRight);
|
||||
// hack, use parent transform instead as setting feet position moves root
|
||||
footstepLeft.Reset(rootWorldRot, root.parent.TransformPoint(footPosLeft), rootWorldRot * footRotLeft);
|
||||
footstepRight.Reset(rootWorldRot, root.parent.TransformPoint(footPosRight), rootWorldRot * footRotRight);
|
||||
}
|
||||
|
||||
public static void SetupHeadIKTarget(VRIK vrik)
|
||||
|
@ -155,9 +157,10 @@ public static class VRIKUtils
|
|||
|
||||
public static void ApplyScaleToVRIK(VRIK vrik, float footDistance, float stepThreshold, float stepHeight, float modifier)
|
||||
{
|
||||
vrik.solver.locomotion.footDistance = footDistance * modifier;
|
||||
vrik.solver.locomotion.stepThreshold = stepThreshold * modifier;
|
||||
ScaleStepHeight(vrik.solver.locomotion.stepHeight, stepHeight * modifier);
|
||||
var locomotionSolver = vrik.solver.locomotion;
|
||||
locomotionSolver.footDistance = footDistance * modifier;
|
||||
locomotionSolver.stepThreshold = stepThreshold * modifier;
|
||||
ScaleStepHeight(locomotionSolver.stepHeight, stepHeight * modifier);
|
||||
}
|
||||
|
||||
private static void ScaleStepHeight(AnimationCurve stepHeightCurve, float mag)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue