mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 14:29:25 +00:00
Move many mods to Deprecated folder, fix spelling
This commit is contained in:
parent
5e822cec8d
commit
0042590aa6
539 changed files with 7475 additions and 3120 deletions
231
.Deprecated/DesktopVRIK/IK/IKCalibrator.cs
Normal file
231
.Deprecated/DesktopVRIK/IK/IKCalibrator.cs
Normal file
|
@ -0,0 +1,231 @@
|
|||
using RootMotion.FinalIK;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace NAK.DesktopVRIK.IK;
|
||||
|
||||
internal static class IKCalibrator
|
||||
{
|
||||
#region VRIK Solver Setup
|
||||
|
||||
public static VRIK SetupVrIk(Animator animator)
|
||||
{
|
||||
if (animator.gameObject.TryGetComponent(out VRIK vrik))
|
||||
Object.DestroyImmediate(vrik);
|
||||
|
||||
vrik = animator.gameObject.AddComponent<VRIK>();
|
||||
vrik.AutoDetectReferences();
|
||||
|
||||
if (!ModSettings.EntryUseToesForVRIK.Value)
|
||||
{
|
||||
vrik.references.leftToes = null;
|
||||
vrik.references.rightToes = null;
|
||||
}
|
||||
|
||||
vrik.solver.SetToReferences(vrik.references);
|
||||
|
||||
GuessWristPalmAxis(vrik.references.leftHand, vrik.references.leftForearm, vrik.solver.leftArm);
|
||||
GuessWristPalmAxis(vrik.references.rightHand, vrik.references.rightForearm, vrik.solver.rightArm);
|
||||
|
||||
SafePalmToThumbAxis(vrik.references.leftHand, vrik.references.leftForearm, vrik.solver.leftArm,
|
||||
animator.GetBoneTransform(HumanBodyBones.LeftThumbProximal));
|
||||
SafePalmToThumbAxis(vrik.references.rightHand, vrik.references.rightForearm, vrik.solver.rightArm,
|
||||
animator.GetBoneTransform(HumanBodyBones.RightThumbProximal));
|
||||
|
||||
AddTwistRelaxer(vrik.references.leftForearm, vrik, vrik.references.leftHand);
|
||||
AddTwistRelaxer(vrik.references.rightForearm, vrik, vrik.references.rightHand);
|
||||
|
||||
//vrik.solver.leftArm.shoulderRotationMode = (IKSolverVR.Arm.ShoulderRotationMode)IkTweaksSettings.ShoulderMode;
|
||||
//vrik.solver.rightArm.shoulderRotationMode = (IKSolverVR.Arm.ShoulderRotationMode)IkTweaksSettings.ShoulderMode;
|
||||
|
||||
// zero all weights controlled by BodyControl
|
||||
vrik.solver.locomotion.weight = 0f;
|
||||
vrik.solver.IKPositionWeight = 0f;
|
||||
|
||||
vrik.solver.spine.pelvisPositionWeight = 0f;
|
||||
vrik.solver.spine.pelvisRotationWeight = 0f;
|
||||
vrik.solver.spine.positionWeight = 0f;
|
||||
vrik.solver.spine.rotationWeight = 0f;
|
||||
|
||||
vrik.solver.leftLeg.positionWeight = 0f;
|
||||
vrik.solver.leftLeg.rotationWeight = 0f;
|
||||
vrik.solver.rightLeg.positionWeight = 0f;
|
||||
vrik.solver.rightLeg.rotationWeight = 0f;
|
||||
vrik.solver.leftArm.positionWeight = 0f;
|
||||
vrik.solver.leftArm.rotationWeight = 0f;
|
||||
vrik.solver.rightArm.positionWeight = 0f;
|
||||
vrik.solver.rightArm.rotationWeight = 0f;
|
||||
|
||||
vrik.solver.leftLeg.bendGoalWeight = 0f;
|
||||
vrik.solver.rightLeg.bendGoalWeight = 0f;
|
||||
|
||||
// these weights are fine
|
||||
vrik.solver.leftArm.shoulderRotationWeight = 0.8f;
|
||||
vrik.solver.rightArm.shoulderRotationWeight = 0.8f;
|
||||
|
||||
vrik.solver.leftLeg.bendToTargetWeight = 0.75f;
|
||||
vrik.solver.rightLeg.bendToTargetWeight = 0.75f;
|
||||
|
||||
// hack to prevent death
|
||||
vrik.fixTransforms = !animator.enabled;
|
||||
|
||||
// Avatar Motion Tweaker uses this hack!
|
||||
vrik.solver.leftLeg.useAnimatedBendNormal = false;
|
||||
vrik.solver.rightLeg.useAnimatedBendNormal = false;
|
||||
|
||||
// purposefully initiating early
|
||||
vrik.solver.Initiate(vrik.transform);
|
||||
vrik.solver.Reset();
|
||||
|
||||
return vrik;
|
||||
}
|
||||
|
||||
private static void GuessWristPalmAxis(Transform hand, Transform forearm, IKSolverVR.Arm arm)
|
||||
{
|
||||
arm.wristToPalmAxis = VRIKCalibrator.GuessWristToPalmAxis(
|
||||
hand,
|
||||
forearm
|
||||
);
|
||||
}
|
||||
|
||||
private static void SafePalmToThumbAxis(Transform hand, Transform forearm, IKSolverVR.Arm arm, Transform thumbBone = null)
|
||||
{
|
||||
if (hand.childCount == 0)
|
||||
{
|
||||
arm.palmToThumbAxis = Vector3.one;
|
||||
return;
|
||||
}
|
||||
|
||||
arm.palmToThumbAxis = VRIKCalibrator.GuessPalmToThumbAxis(
|
||||
hand,
|
||||
forearm,
|
||||
thumbBone
|
||||
);
|
||||
}
|
||||
|
||||
private static void AddTwistRelaxer(Transform forearm, VRIK ik, Transform hand)
|
||||
{
|
||||
if (forearm == null) return;
|
||||
TwistRelaxer twistRelaxer = forearm.gameObject.AddComponent<TwistRelaxer>();
|
||||
twistRelaxer.ik = ik;
|
||||
twistRelaxer.weight = 0.5f;
|
||||
twistRelaxer.child = hand;
|
||||
twistRelaxer.parentChildCrossfade = 0.8f;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region VRIK Configuration
|
||||
|
||||
public static void ConfigureDesktopVrIk(VRIK vrik)
|
||||
{
|
||||
// From DesktopVRIK
|
||||
// https://github.com/NotAKidoS/NAK_CVR_Mods/blob/fca0a32257311f044d1a9d6e68269baa4a65a45c/DesktopVRIK/DesktopVRIKCalibrator.cs#L219C2-L247C103
|
||||
|
||||
vrik.solver.spine.bodyPosStiffness = 1f;
|
||||
vrik.solver.spine.bodyRotStiffness = 0.2f;
|
||||
vrik.solver.spine.neckStiffness = 0.0001f;
|
||||
vrik.solver.spine.rotateChestByHands = 0f;
|
||||
|
||||
vrik.solver.spine.minHeadHeight = 0f;
|
||||
vrik.solver.locomotion.angleThreshold = 30f;
|
||||
vrik.solver.locomotion.maxLegStretch = 1f;
|
||||
|
||||
vrik.solver.spine.chestClampWeight = 0f;
|
||||
vrik.solver.spine.headClampWeight = 0.2f;
|
||||
|
||||
vrik.solver.spine.maintainPelvisPosition = 0f;
|
||||
vrik.solver.spine.moveBodyBackWhenCrouching = 0f;
|
||||
|
||||
vrik.solver.locomotion.velocityFactor = 0f;
|
||||
vrik.solver.locomotion.maxVelocity = 0f;
|
||||
vrik.solver.locomotion.rootSpeed = 1000f;
|
||||
|
||||
vrik.solver.spine.positionWeight = 0f;
|
||||
vrik.solver.spine.rotationWeight = 1f;
|
||||
|
||||
vrik.solver.spine.maxRootAngle = 180f;
|
||||
|
||||
vrik.solver.plantFeet = true;
|
||||
}
|
||||
|
||||
public static void ConfigureHalfBodyVrIk(VRIK vrik)
|
||||
{
|
||||
// From IKTweaks
|
||||
// https://github.com/knah/VRCMods/blob/a22bb73a5e40c75152c6e5db2a7a9afb13e42ba5/IKTweaks/FullBodyHandling.cs#L384C1-L394C71
|
||||
|
||||
vrik.solver.spine.bodyPosStiffness = 1f;
|
||||
vrik.solver.spine.bodyRotStiffness = 0f;
|
||||
vrik.solver.spine.neckStiffness = 0.5f;
|
||||
vrik.solver.spine.rotateChestByHands = .25f;
|
||||
|
||||
vrik.solver.spine.minHeadHeight = -100f;
|
||||
vrik.solver.locomotion.angleThreshold = 60f;
|
||||
vrik.solver.locomotion.maxLegStretch = 1f;
|
||||
|
||||
vrik.solver.spine.chestClampWeight = 0f;
|
||||
vrik.solver.spine.headClampWeight = 0f;
|
||||
|
||||
vrik.solver.spine.maintainPelvisPosition = 0f;
|
||||
vrik.solver.spine.moveBodyBackWhenCrouching = 0f;
|
||||
|
||||
vrik.solver.locomotion.velocityFactor = 0.4f;
|
||||
vrik.solver.locomotion.maxVelocity = 0.4f;
|
||||
vrik.solver.locomotion.rootSpeed = 20f;
|
||||
|
||||
vrik.solver.spine.positionWeight = 1f;
|
||||
vrik.solver.spine.rotationWeight = 1f;
|
||||
|
||||
vrik.solver.spine.maxRootAngle = 25f;
|
||||
|
||||
vrik.solver.plantFeet = false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region VRIK Calibration
|
||||
|
||||
public static void SetupHeadIKTarget(VRIK vrik, Transform parent = null)
|
||||
{
|
||||
Transform existingTarget = parent?.Find("Head IK Target");
|
||||
if (existingTarget != null)
|
||||
Object.DestroyImmediate(existingTarget.gameObject);
|
||||
|
||||
parent ??= vrik.references.head;
|
||||
|
||||
vrik.solver.spine.headTarget = new GameObject("Head IK Target").transform;
|
||||
vrik.solver.spine.headTarget.SetParent(parent);
|
||||
vrik.solver.spine.headTarget.localPosition = Vector3.zero;
|
||||
vrik.solver.spine.headTarget.localRotation = parent == vrik.references.head
|
||||
? Quaternion.identity
|
||||
: CalculateLocalRotation(vrik.references.root, vrik.references.head);
|
||||
}
|
||||
|
||||
public static void SetupHandIKTarget(VRIK vrik, Transform handAnchor, bool isLeft)
|
||||
{
|
||||
Transform parent = handAnchor.parent;
|
||||
Transform handRef = isLeft ? vrik.references.leftHand : vrik.references.rightHand;
|
||||
|
||||
handAnchor.SetParent(parent);
|
||||
handAnchor.localPosition = Vector3.zero;
|
||||
handAnchor.localRotation = CalculateLocalRotation(vrik.references.root, handRef);
|
||||
|
||||
if (isLeft)
|
||||
vrik.solver.leftArm.target = handAnchor;
|
||||
else
|
||||
vrik.solver.rightArm.target = handAnchor;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private static Quaternion CalculateLocalRotation(Transform root, Transform reference)
|
||||
{
|
||||
Vector3 forward = Quaternion.Inverse(reference.rotation) * root.forward;
|
||||
Vector3 upwards = Quaternion.Inverse(reference.rotation) * root.up;
|
||||
return Quaternion.Inverse(reference.rotation * Quaternion.LookRotation(forward, upwards)) * reference.rotation;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
163
.Deprecated/DesktopVRIK/IK/IKHandlers/IKHandler.cs
Normal file
163
.Deprecated/DesktopVRIK/IK/IKHandlers/IKHandler.cs
Normal file
|
@ -0,0 +1,163 @@
|
|||
using ABI_RC.Core.InteractionSystem;
|
||||
using ABI.CCK.Components;
|
||||
using ABI_RC.Systems.IK.SubSystems;
|
||||
using NAK.DesktopVRIK.IK.VRIKHelpers;
|
||||
using RootMotion.FinalIK;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.DesktopVRIK.IK.IKHandlers;
|
||||
|
||||
internal abstract class IKHandler
|
||||
{
|
||||
#region Variables
|
||||
|
||||
internal VRIK _vrik;
|
||||
internal IKSolverVR _solver;
|
||||
|
||||
// VRIK Calibration Info
|
||||
internal VRIKLocomotionData _locomotionData;
|
||||
|
||||
// Last Movement Parent Info
|
||||
internal Vector3 _movementPosition;
|
||||
internal Quaternion _movementRotation;
|
||||
internal CVRMovementParent _movementParent;
|
||||
|
||||
// Solver Info
|
||||
internal float _scaleDifference = 1f;
|
||||
internal float _ikWeight = 1f;
|
||||
internal float _locomotionWeight = 1f;
|
||||
internal float _ikSimulatedRootAngle;
|
||||
internal bool _wasTrackingLocomotion;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Virtual Game Methods
|
||||
|
||||
public virtual void OnInitializeIk() { }
|
||||
|
||||
public virtual void OnPlayerScaled(float scaleDifference)
|
||||
{
|
||||
VRIKUtils.ApplyScaleToVRIK
|
||||
(
|
||||
_vrik,
|
||||
_locomotionData,
|
||||
_scaleDifference = scaleDifference
|
||||
);
|
||||
}
|
||||
|
||||
public virtual void OnPlayerHandleMovementParent(CVRMovementParent currentParent, Vector3 platformPivot)
|
||||
{
|
||||
Vector3 currentPosition = currentParent._referencePoint.position;
|
||||
Quaternion currentRotation = Quaternion.Euler(0f, currentParent.transform.rotation.eulerAngles.y, 0f);
|
||||
|
||||
if (_movementParent != null && _movementParent == currentParent)
|
||||
{
|
||||
Vector3 deltaPosition = currentPosition - _movementPosition;
|
||||
Quaternion deltaRotation = Quaternion.identity;
|
||||
|
||||
if (currentParent.orientationMode == CVRMovementParent.OrientationMode.RotateWithParent)
|
||||
deltaRotation = Quaternion.Inverse(_movementRotation) * currentRotation;
|
||||
|
||||
_solver.AddPlatformMotion(deltaPosition, deltaRotation, platformPivot);
|
||||
_ikSimulatedRootAngle = Mathf.Repeat(_ikSimulatedRootAngle + deltaRotation.eulerAngles.y, 360f);
|
||||
}
|
||||
|
||||
_movementParent = currentParent;
|
||||
_movementPosition = currentPosition;
|
||||
_movementRotation = currentRotation;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Virtual IK Weights
|
||||
|
||||
public virtual void UpdateWeights()
|
||||
{
|
||||
Update_HeadWeight();
|
||||
|
||||
Update_LeftArmWeight();
|
||||
Update_RightArmWeight();
|
||||
|
||||
Update_LeftLegWeight();
|
||||
Update_RightLegWeight();
|
||||
|
||||
Update_PelvisWeight();
|
||||
|
||||
Update_LocomotionWeight();
|
||||
|
||||
Update_IKPositionWeight();
|
||||
}
|
||||
|
||||
public virtual void UpdateTracking() { }
|
||||
|
||||
protected virtual void Update_HeadWeight()
|
||||
{
|
||||
// There is no Head tracking setting
|
||||
_solver.spine.rotationWeight = _solver.spine.positionWeight =
|
||||
GetTargetWeight(BodySystem.TrackingEnabled, _solver.spine.headTarget != null);
|
||||
}
|
||||
|
||||
protected virtual void Update_LeftArmWeight()
|
||||
{
|
||||
_solver.leftArm.rotationWeight = _solver.leftArm.positionWeight =
|
||||
GetTargetWeight(BodySystem.TrackingLeftArmEnabled, _solver.leftArm.target != null);
|
||||
}
|
||||
|
||||
protected virtual void Update_RightArmWeight()
|
||||
{
|
||||
_solver.rightArm.rotationWeight = _solver.rightArm.positionWeight =
|
||||
GetTargetWeight(BodySystem.TrackingRightArmEnabled, _solver.rightArm.target != null);
|
||||
}
|
||||
|
||||
protected virtual void Update_LeftLegWeight()
|
||||
{
|
||||
_solver.leftLeg.rotationWeight = _solver.leftLeg.positionWeight =
|
||||
GetTargetWeight(BodySystem.TrackingLeftLegEnabled, _solver.leftLeg.target != null);
|
||||
}
|
||||
|
||||
protected virtual void Update_RightLegWeight()
|
||||
{
|
||||
_solver.rightLeg.rotationWeight = _solver.rightLeg.positionWeight =
|
||||
GetTargetWeight(BodySystem.TrackingRightLegEnabled, _solver.rightLeg.target != null);
|
||||
}
|
||||
|
||||
protected virtual void Update_PelvisWeight()
|
||||
{
|
||||
// There is no Pelvis tracking setting
|
||||
_solver.spine.pelvisRotationWeight = _solver.spine.pelvisPositionWeight =
|
||||
GetTargetWeight(BodySystem.TrackingEnabled, _solver.spine.pelvisTarget != null);
|
||||
}
|
||||
|
||||
protected virtual void Update_LocomotionWeight()
|
||||
{
|
||||
_solver.locomotion.weight = _locomotionWeight = Mathf.Lerp(_locomotionWeight, BodySystem.TrackingLocomotionEnabled ? 1f : 0f,
|
||||
Time.deltaTime * ModSettings.EntryIKLerpSpeed.Value * 2f);
|
||||
}
|
||||
|
||||
protected virtual void Update_IKPositionWeight()
|
||||
{
|
||||
_solver.IKPositionWeight = _ikWeight = Mathf.Lerp(_ikWeight, BodySystem.TrackingEnabled ? BodySystem.TrackingPositionWeight : 0f,
|
||||
Time.deltaTime * ModSettings.EntryIKLerpSpeed.Value);
|
||||
}
|
||||
|
||||
public virtual void Reset()
|
||||
{
|
||||
_ikSimulatedRootAngle = _vrik.transform.eulerAngles.y;
|
||||
|
||||
_solver.Reset();
|
||||
|
||||
if(ModSettings.EntryResetFootstepsOnIdle.Value)
|
||||
VRIKUtils.ResetToInitialFootsteps(_vrik, _locomotionData, _scaleDifference);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private float GetTargetWeight(bool isTracking, bool hasTarget)
|
||||
{
|
||||
return isTracking && hasTarget ? 1f : 0f;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
126
.Deprecated/DesktopVRIK/IK/IKHandlers/IKHandlerDesktop.cs
Normal file
126
.Deprecated/DesktopVRIK/IK/IKHandlers/IKHandlerDesktop.cs
Normal file
|
@ -0,0 +1,126 @@
|
|||
using ABI_RC.Core.Player;
|
||||
using ABI_RC.Systems.IK.SubSystems;
|
||||
using ABI_RC.Systems.MovementSystem;
|
||||
using NAK.DesktopVRIK.IK.VRIKHelpers;
|
||||
using RootMotion.FinalIK;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.DesktopVRIK.IK.IKHandlers;
|
||||
|
||||
internal class IKHandlerDesktop : IKHandler
|
||||
{
|
||||
public IKHandlerDesktop(VRIK vrik)
|
||||
{
|
||||
_vrik = vrik;
|
||||
_solver = vrik.solver;
|
||||
}
|
||||
|
||||
#region Game Overrides
|
||||
|
||||
public override void OnInitializeIk()
|
||||
{
|
||||
_vrik.onPreSolverUpdate.AddListener(OnPreSolverUpdateDesktop);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Weight Overrides
|
||||
|
||||
public override void UpdateWeights()
|
||||
{
|
||||
// Reset avatar local position
|
||||
_vrik.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
|
||||
|
||||
base.UpdateWeights();
|
||||
}
|
||||
|
||||
public override void UpdateTracking()
|
||||
{
|
||||
BodySystem.TrackingEnabled = ShouldTrackAll();
|
||||
BodySystem.TrackingLocomotionEnabled = BodySystem.TrackingEnabled && ShouldTrackLocomotion();
|
||||
ResetSolverIfNeeded();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region VRIK Solver Events
|
||||
|
||||
private void OnPreSolverUpdateDesktop()
|
||||
{
|
||||
// Reset avatar local position
|
||||
_vrik.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
|
||||
|
||||
_solver.plantFeet = ModSettings.EntryPlantFeet.Value;
|
||||
|
||||
// Emulate old VRChat hip movement
|
||||
if (ModSettings.EntryBodyLeanWeight.Value > 0)
|
||||
{
|
||||
float weightedAngle = ModSettings.EntryBodyLeanWeight.Value * (ModSettings.EntryProneThrusting.Value ? 1f: _solver.locomotion.weight);
|
||||
float angle = IKManager.Instance._desktopCamera.localEulerAngles.x;
|
||||
angle = angle > 180 ? angle - 360 : angle;
|
||||
Quaternion rotation = Quaternion.AngleAxis(angle * weightedAngle, _vrik.transform.right);
|
||||
_solver.spine.headRotationOffset *= rotation;
|
||||
}
|
||||
|
||||
// Make root heading follow within a set limit
|
||||
if (ModSettings.EntryBodyHeadingLimit.Value > 0)
|
||||
{
|
||||
float weightedAngleLimit = ModSettings.EntryBodyHeadingLimit.Value * _solver.locomotion.weight;
|
||||
float deltaAngleRoot = Mathf.DeltaAngle(IKManager.Instance.transform.eulerAngles.y, _ikSimulatedRootAngle);
|
||||
float absDeltaAngleRoot = Mathf.Abs(deltaAngleRoot);
|
||||
|
||||
if (absDeltaAngleRoot > weightedAngleLimit)
|
||||
{
|
||||
deltaAngleRoot = Mathf.Sign(deltaAngleRoot) * weightedAngleLimit;
|
||||
_ikSimulatedRootAngle = Mathf.MoveTowardsAngle(_ikSimulatedRootAngle, IKManager.Instance.transform.eulerAngles.y, absDeltaAngleRoot - weightedAngleLimit);
|
||||
}
|
||||
|
||||
_solver.spine.rootHeadingOffset = deltaAngleRoot;
|
||||
|
||||
if (ModSettings.EntryPelvisHeadingWeight.Value > 0)
|
||||
{
|
||||
_solver.spine.pelvisRotationOffset *= Quaternion.Euler(0f, deltaAngleRoot * ModSettings.EntryPelvisHeadingWeight.Value, 0f);
|
||||
_solver.spine.chestRotationOffset *= Quaternion.Euler(0f, -deltaAngleRoot * ModSettings.EntryPelvisHeadingWeight.Value, 0f);
|
||||
}
|
||||
|
||||
if (ModSettings.EntryChestHeadingWeight.Value > 0)
|
||||
{
|
||||
_solver.spine.chestRotationOffset *= Quaternion.Euler(0f, deltaAngleRoot * ModSettings.EntryChestHeadingWeight.Value, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private bool ShouldTrackAll()
|
||||
{
|
||||
return !PlayerSetup.Instance._emotePlaying;
|
||||
}
|
||||
|
||||
private bool ShouldTrackLocomotion()
|
||||
{
|
||||
bool isMoving = MovementSystem.Instance.movementVector.magnitude > 0f;
|
||||
bool isGrounded = MovementSystem.Instance._isGrounded;
|
||||
bool isCrouching = MovementSystem.Instance.crouching;
|
||||
bool isProne = MovementSystem.Instance.prone;
|
||||
bool isFlying = MovementSystem.Instance.flying;
|
||||
bool isSitting = MovementSystem.Instance.sitting;
|
||||
bool isSwimming = MovementSystem.Instance.GetSubmerged();
|
||||
bool isStanding = PlayerSetup.Instance.avatarUpright >=
|
||||
Mathf.Max(PlayerSetup.Instance.avatarProneLimit, PlayerSetup.Instance.avatarCrouchLimit);
|
||||
|
||||
return !(isMoving || isCrouching || isProne || isFlying || isSwimming || isSitting || !isGrounded || !isStanding);
|
||||
}
|
||||
|
||||
private void ResetSolverIfNeeded()
|
||||
{
|
||||
if (_wasTrackingLocomotion == BodySystem.TrackingLocomotionEnabled) return;
|
||||
_wasTrackingLocomotion = BodySystem.TrackingLocomotionEnabled;
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
416
.Deprecated/DesktopVRIK/IK/IKManager.cs
Normal file
416
.Deprecated/DesktopVRIK/IK/IKManager.cs
Normal file
|
@ -0,0 +1,416 @@
|
|||
using ABI.CCK.Components;
|
||||
using ABI_RC.Core.Player;
|
||||
using ABI_RC.Core.Savior;
|
||||
using ABI_RC.Systems.IK.SubSystems;
|
||||
using ABI_RC.Systems.MovementSystem;
|
||||
using NAK.DesktopVRIK.IK.IKHandlers;
|
||||
using NAK.DesktopVRIK.IK.VRIKHelpers;
|
||||
using RootMotion.FinalIK;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.DesktopVRIK.IK;
|
||||
|
||||
public class IKManager : MonoBehaviour
|
||||
{
|
||||
public static IKManager Instance;
|
||||
|
||||
#region Variables
|
||||
|
||||
private static VRIK _vrik;
|
||||
private static IKSolverVR _solver;
|
||||
|
||||
private bool _isAvatarInitialized;
|
||||
|
||||
// IK Handling
|
||||
private IKHandler _ikHandler;
|
||||
|
||||
// Player Info
|
||||
internal Transform _desktopCamera;
|
||||
internal Transform _vrCamera;
|
||||
|
||||
// Avatar Info
|
||||
private Animator _animator;
|
||||
internal Transform _hipTransform;
|
||||
|
||||
// Animator Info
|
||||
private int _animLocomotionLayer = -1;
|
||||
private int _animIKPoseLayer = -1;
|
||||
private const string _locomotionLayerName = "Locomotion/Emotes";
|
||||
private const string _ikposeLayerName = "IKPose";
|
||||
|
||||
// Pose Info
|
||||
internal HumanPoseHandler _humanPoseHandler;
|
||||
internal HumanPose _humanPose;
|
||||
internal HumanPose _humanPoseInitial;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Unity Methods
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (Instance != null)
|
||||
{
|
||||
Destroy(this);
|
||||
return;
|
||||
}
|
||||
Instance = this;
|
||||
|
||||
_desktopCamera = PlayerSetup.Instance.desktopCamera.transform;
|
||||
_vrCamera = PlayerSetup.Instance.vrCamera.transform;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
_ikHandler?.UpdateWeights();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Avatar Events
|
||||
|
||||
public void OnAvatarInitialized(GameObject inAvatar)
|
||||
{
|
||||
if (MetaPort.Instance.isUsingVr)
|
||||
return;
|
||||
|
||||
if (_isAvatarInitialized)
|
||||
return;
|
||||
|
||||
if (!inAvatar.TryGetComponent(out _animator))
|
||||
return;
|
||||
|
||||
if (_animator.avatar == null || !_animator.avatar.isHuman)
|
||||
return;
|
||||
|
||||
_animator.cullingMode = AnimatorCullingMode.AlwaysAnimate;
|
||||
|
||||
_animIKPoseLayer = _animator.GetLayerIndex(_ikposeLayerName);
|
||||
_animLocomotionLayer = _animator.GetLayerIndex(_locomotionLayerName);
|
||||
|
||||
_hipTransform = _animator.GetBoneTransform(HumanBodyBones.Hips);
|
||||
|
||||
_humanPoseHandler?.Dispose();
|
||||
_humanPoseHandler = new HumanPoseHandler(_animator.avatar, _animator.transform);
|
||||
|
||||
_humanPoseHandler.GetHumanPose(ref _humanPose);
|
||||
_humanPoseHandler.GetHumanPose(ref _humanPoseInitial);
|
||||
|
||||
InitializeDesktopIk();
|
||||
|
||||
_isAvatarInitialized = true;
|
||||
}
|
||||
|
||||
public void OnAvatarDestroyed()
|
||||
{
|
||||
if (!_isAvatarInitialized)
|
||||
return;
|
||||
|
||||
_vrik = null;
|
||||
_solver = null;
|
||||
_animator = null;
|
||||
_animIKPoseLayer = -1;
|
||||
_animLocomotionLayer = -1;
|
||||
_hipTransform = null;
|
||||
_humanPoseHandler?.Dispose();
|
||||
_humanPoseHandler = null;
|
||||
_ikHandler = null;
|
||||
|
||||
_isAvatarInitialized = false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Game Events
|
||||
|
||||
public bool OnPlayerScaled(float scaleDifference)
|
||||
{
|
||||
if (_ikHandler == null)
|
||||
return false;
|
||||
|
||||
DesktopVRIK.Logger.Msg(scaleDifference);
|
||||
|
||||
_ikHandler.OnPlayerScaled(scaleDifference);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void OnPlayerSeatedStateChanged(bool isSitting)
|
||||
{
|
||||
if (_ikHandler == null)
|
||||
return;
|
||||
|
||||
_ikHandler.Reset();
|
||||
}
|
||||
|
||||
public bool OnPlayerHandleMovementParent(CVRMovementParent movementParent)
|
||||
{
|
||||
if (_ikHandler == null)
|
||||
return false;
|
||||
|
||||
_ikHandler.OnPlayerHandleMovementParent(movementParent, GetPlayerPosition());
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool OnPlayerTeleported()
|
||||
{
|
||||
if (_ikHandler == null)
|
||||
return false;
|
||||
|
||||
_ikHandler.Reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void OnPlayerUpdate()
|
||||
{
|
||||
if (_ikHandler == null)
|
||||
return;
|
||||
|
||||
_ikHandler.UpdateTracking();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IK Initialization
|
||||
|
||||
private void InitializeDesktopIk()
|
||||
{
|
||||
SetupIkGeneral();
|
||||
|
||||
IKCalibrator.ConfigureDesktopVrIk(_vrik);
|
||||
_ikHandler = new IKHandlerDesktop(_vrik);
|
||||
|
||||
IKCalibrator.SetupHeadIKTarget(_vrik);
|
||||
|
||||
InitializeIkGeneral();
|
||||
|
||||
_ikHandler.OnInitializeIk();
|
||||
}
|
||||
|
||||
private void SetupIkGeneral()
|
||||
{
|
||||
_animator.transform.position = GetPlayerPosition();
|
||||
_animator.transform.rotation = GetPlayerRotation();
|
||||
SetAvatarPose(AvatarPose.Default);
|
||||
_vrik = IKCalibrator.SetupVrIk(_animator);
|
||||
_solver = _vrik.solver;
|
||||
}
|
||||
|
||||
private void InitializeIkGeneral()
|
||||
{
|
||||
SetAvatarPose(AvatarPose.IKPose);
|
||||
|
||||
VRIKUtils.CalculateInitialIKScaling(_vrik, ref _ikHandler._locomotionData);
|
||||
VRIKUtils.CalculateInitialFootsteps(_vrik, ref _ikHandler._locomotionData);
|
||||
_solver.Initiate(_vrik.transform); // initiate a second time
|
||||
|
||||
SetAvatarPose(AvatarPose.Initial);
|
||||
|
||||
VRIKUtils.ApplyScaleToVRIK(_vrik, _ikHandler._locomotionData, 1f);
|
||||
_vrik.onPreSolverUpdate.AddListener(OnPreSolverUpdateGeneral);
|
||||
_vrik.onPreSolverUpdate.AddListener(OnPreSolverUpdateDesktopSwimming);
|
||||
_vrik.onPostSolverUpdate.AddListener(OnPostSolverUpdateGeneral);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public bool IsAvatarInitialized()
|
||||
{
|
||||
return _isAvatarInitialized;
|
||||
}
|
||||
|
||||
public Vector3 GetPlayerPosition()
|
||||
{
|
||||
if (!MetaPort.Instance.isUsingVr)
|
||||
return transform.position;
|
||||
|
||||
Vector3 vrPosition = _vrCamera.transform.position;
|
||||
vrPosition.y = transform.position.y;
|
||||
return vrPosition;
|
||||
}
|
||||
|
||||
public Quaternion GetPlayerRotation()
|
||||
{
|
||||
if (!MetaPort.Instance.isUsingVr)
|
||||
return transform.rotation;
|
||||
|
||||
Vector3 vrForward = _vrCamera.transform.forward;
|
||||
vrForward.y = 0f;
|
||||
return Quaternion.LookRotation(vrForward, Vector3.up);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#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()
|
||||
{
|
||||
if (_solver.IKPositionWeight < 0.9f)
|
||||
return;
|
||||
|
||||
Vector3 hipPos = _hipTransform.position;
|
||||
Quaternion hipRot = _hipTransform.rotation;
|
||||
|
||||
_humanPoseHandler.GetHumanPose(ref _humanPose);
|
||||
|
||||
for (var i = 0; i < _humanPose.muscles.Length; i++)
|
||||
{
|
||||
switch (BodySystem.boneResetMasks[i])
|
||||
{
|
||||
case BodySystem.BoneResetMask.Never:
|
||||
break;
|
||||
case BodySystem.BoneResetMask.Spine:
|
||||
_humanPose.muscles[i] *= 1 - _solver.spine.pelvisPositionWeight;
|
||||
break;
|
||||
case BodySystem.BoneResetMask.LeftArm:
|
||||
_humanPose.muscles[i] *= 1 - _solver.leftArm.positionWeight;
|
||||
break;
|
||||
case BodySystem.BoneResetMask.RightArm:
|
||||
_humanPose.muscles[i] *= 1 - _solver.rightArm.positionWeight;
|
||||
break;
|
||||
case BodySystem.BoneResetMask.LeftLeg:
|
||||
_humanPose.muscles[i] *= 1 - _solver.leftLeg.positionWeight;
|
||||
break;
|
||||
case BodySystem.BoneResetMask.RightLeg:
|
||||
_humanPose.muscles[i] *= 1 - _solver.rightLeg.positionWeight;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
_humanPoseHandler.SetHumanPose(ref _humanPose);
|
||||
|
||||
_hipTransform.position = hipPos;
|
||||
_hipTransform.rotation = hipRot;
|
||||
}
|
||||
|
||||
// "NetIk Pass", or "Additional Humanoid Pass" hack
|
||||
private void OnPostSolverUpdateGeneral()
|
||||
{
|
||||
Vector3 hipPos = _hipTransform.position;
|
||||
Quaternion hipRot = _hipTransform.rotation;
|
||||
|
||||
_humanPoseHandler.GetHumanPose(ref _humanPose);
|
||||
_humanPoseHandler.SetHumanPose(ref _humanPose);
|
||||
|
||||
_hipTransform.position = hipPos;
|
||||
_hipTransform.rotation = hipRot;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Avatar Pose Utilities
|
||||
|
||||
private enum AvatarPose
|
||||
{
|
||||
Default = 0,
|
||||
Initial = 1,
|
||||
IKPose = 2,
|
||||
TPose = 3,
|
||||
APose = 4
|
||||
}
|
||||
|
||||
private void SetAvatarPose(AvatarPose pose)
|
||||
{
|
||||
switch (pose)
|
||||
{
|
||||
case AvatarPose.Default:
|
||||
SetMusclesToValue(0f);
|
||||
break;
|
||||
case AvatarPose.Initial:
|
||||
if (HasCustomIKPose())
|
||||
SetCustomLayersWeights(0f, 1f);
|
||||
_humanPoseHandler.SetHumanPose(ref _humanPoseInitial);
|
||||
break;
|
||||
case AvatarPose.IKPose:
|
||||
if (HasCustomIKPose())
|
||||
{
|
||||
SetCustomLayersWeights(1f, 0f);
|
||||
return;
|
||||
}
|
||||
SetMusclesToPose(MusclePoses.IKPoseMuscles);
|
||||
break;
|
||||
case AvatarPose.TPose:
|
||||
SetMusclesToPose(MusclePoses.TPoseMuscles);
|
||||
break;
|
||||
case AvatarPose.APose:
|
||||
SetMusclesToPose(MusclePoses.APoseMuscles);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private bool HasCustomIKPose()
|
||||
{
|
||||
return _animLocomotionLayer != -1 && _animIKPoseLayer != -1;
|
||||
}
|
||||
|
||||
private void SetCustomLayersWeights(float customIKPoseLayerWeight, float locomotionLayerWeight)
|
||||
{
|
||||
_animator.SetLayerWeight(_animIKPoseLayer, customIKPoseLayerWeight);
|
||||
_animator.SetLayerWeight(_animLocomotionLayer, locomotionLayerWeight);
|
||||
_animator.Update(0f);
|
||||
}
|
||||
|
||||
private void SetMusclesToValue(float value)
|
||||
{
|
||||
_humanPoseHandler.GetHumanPose(ref _humanPose);
|
||||
|
||||
for (var i = 0; i < BodySystem.boneResetMasks.Length; i++)
|
||||
{
|
||||
if (BodySystem.boneResetMasks[i] != BodySystem.BoneResetMask.Never)
|
||||
_humanPose.muscles[i] = value;
|
||||
}
|
||||
|
||||
_humanPose.bodyPosition = Vector3.up;
|
||||
_humanPose.bodyRotation = Quaternion.identity;
|
||||
_humanPoseHandler.SetHumanPose(ref _humanPose);
|
||||
}
|
||||
|
||||
private void SetMusclesToPose(float[] muscles)
|
||||
{
|
||||
_humanPoseHandler.GetHumanPose(ref _humanPose);
|
||||
|
||||
for (var i = 0; i < BodySystem.boneResetMasks.Length; i++)
|
||||
{
|
||||
if (BodySystem.boneResetMasks[i] != BodySystem.BoneResetMask.Never)
|
||||
_humanPose.muscles[i] = muscles[i];
|
||||
}
|
||||
|
||||
_humanPose.bodyPosition = Vector3.up;
|
||||
_humanPose.bodyRotation = Quaternion.identity;
|
||||
_humanPoseHandler.SetHumanPose(ref _humanPose);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
46
.Deprecated/DesktopVRIK/IK/MusclePoses.cs
Normal file
46
.Deprecated/DesktopVRIK/IK/MusclePoses.cs
Normal file
|
@ -0,0 +1,46 @@
|
|||
namespace NAK.DesktopVRIK.IK;
|
||||
|
||||
public static class MusclePoses
|
||||
{
|
||||
public static readonly float[] TPoseMuscles =
|
||||
{
|
||||
0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0.6001086f, 8.6213E-05f,
|
||||
-0.0003308152f, 0.9999163f, -9.559652E-06f, 3.41413E-08f, -3.415095E-06f, -1.024528E-07f, 0.6001086f,
|
||||
8.602679E-05f, -0.0003311098f, 0.9999163f, -9.510122E-06f, 1.707468E-07f, -2.732077E-06f, 2.035554E-15f,
|
||||
-2.748694E-07f, 2.619475E-07f, 0.401967f, 0.3005583f, 0.04102772f, 0.9998822f, -0.04634236f, 0.002522987f,
|
||||
0.0003842837f, -2.369134E-07f, -2.232262E-07f, 0.4019674f, 0.3005582f, 0.04103433f, 0.9998825f,
|
||||
-0.04634996f, 0.00252335f, 0.000383302f, -1.52127f, 0.2634507f, 0.4322457f, 0.6443988f, 0.6669409f,
|
||||
-0.4663372f, 0.8116828f, 0.8116829f, 0.6678119f, -0.6186608f, 0.8116842f, 0.8116842f, 0.6677991f,
|
||||
-0.619225f, 0.8116842f, 0.811684f, 0.6670032f, -0.465875f, 0.811684f, 0.8116836f, -1.520098f, 0.2613016f,
|
||||
0.432256f, 0.6444503f, 0.6668426f, -0.4670413f, 0.8116828f, 0.8116828f, 0.6677986f, -0.6192409f, 0.8116841f,
|
||||
0.811684f, 0.6677839f, -0.6198869f, 0.8116839f, 0.8116838f, 0.6668782f, -0.4667901f, 0.8116842f, 0.811684f
|
||||
};
|
||||
|
||||
public static readonly float[] APoseMuscles =
|
||||
{
|
||||
0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0.6001087f, 0f,
|
||||
-0.0003306383f, 0.9999163f, 0f, 0f, 0f, 0f, 0.6001087f, 0f, -0.0003306384f, 0.9999163f, 0f, 0f, 0f, 0f, 0f,
|
||||
0f, -0.1071228f, 0.258636f, 0.1567371f, 0.9998825f, -0.0463457f, 0.002523606f, 0.0003833446f, 0f, 0f,
|
||||
-0.1036742f, 0.2589961f, 0.1562322f, 0.9998825f, -0.04634446f, 0.002522176f, 0.0003835156f, -1.52127f,
|
||||
0.2634749f, 0.4322476f, 0.6443989f, 0.6669405f, -0.4663376f, 0.8116828f, 0.8116829f, 0.6678116f,
|
||||
-0.6186616f, 0.8116839f, 0.8116837f, 0.6677991f, -0.6192248f, 0.8116839f, 0.8116842f, 0.6670038f,
|
||||
-0.4658763f, 0.8116841f, 0.811684f, -1.520108f, 0.2612858f, 0.4322585f, 0.6444519f, 0.6668428f, -0.4670413f,
|
||||
0.8116831f, 0.8116828f, 0.6677985f, -0.6192364f, 0.8116842f, 0.8116842f, 0.667784f, -0.6198866f, 0.8116841f,
|
||||
0.8116835f, 0.6668782f, -0.4667891f, 0.8116841f, 0.811684f
|
||||
};
|
||||
|
||||
public static readonly float[] IKPoseMuscles =
|
||||
{
|
||||
0.00133321f, 8.195831E-06f, 8.537738E-07f, -0.002669832f, -7.651234E-06f, -0.001659694f, 0f, 0f, 0f,
|
||||
0.04213953f, 0.0003007996f, -0.008032114f, -0.03059979f, -0.0003182998f, 0.009640567f, 0f, 0f, 0f, 0f, 0f,
|
||||
0f, 0.5768794f, 0.01061097f, -0.1127839f, 0.9705755f, 0.07972051f, -0.0268422f, 0.007237188f, 0f,
|
||||
0.5768792f, 0.01056608f, -0.1127519f, 0.9705756f, 0.07971933f, -0.02682396f, 0.007229362f, 0f,
|
||||
-5.651802E-06f, -3.034899E-07f, 0.4100508f, 0.3610304f, -0.0838329f, 0.9262537f, 0.1353517f, -0.03578902f,
|
||||
0.06005657f, -4.95989E-06f, -1.43007E-06f, 0.4096187f, 0.363263f, -0.08205152f, 0.9250782f, 0.1345718f,
|
||||
-0.03572125f, 0.06055461f, -1.079177f, 0.2095419f, 0.6140652f, 0.6365265f, 0.6683931f, -0.4764312f,
|
||||
0.8099416f, 0.8099371f, 0.6658203f, -0.7327053f, 0.8113618f, 0.8114051f, 0.6643661f, -0.40341f, 0.8111364f,
|
||||
0.8111367f, 0.6170399f, -0.2524227f, 0.8138723f, 0.8110135f, -1.079171f, 0.2095456f, 0.6140658f, 0.6365255f,
|
||||
0.6683878f, -0.4764301f, 0.8099402f, 0.8099376f, 0.6658241f, -0.7327023f, 0.8113653f, 0.8113793f, 0.664364f,
|
||||
-0.4034042f, 0.811136f, 0.8111364f, 0.6170469f, -0.2524345f, 0.8138595f, 0.8110138f
|
||||
};
|
||||
}
|
25
.Deprecated/DesktopVRIK/IK/VRIKHelpers/VRIKLocomotionData.cs
Normal file
25
.Deprecated/DesktopVRIK/IK/VRIKHelpers/VRIKLocomotionData.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace NAK.DesktopVRIK.IK.VRIKHelpers;
|
||||
|
||||
public struct VRIKLocomotionData
|
||||
{
|
||||
public Vector3 InitialFootPosLeft;
|
||||
public Vector3 InitialFootPosRight;
|
||||
public Quaternion InitialFootRotLeft;
|
||||
public Quaternion InitialFootRotRight;
|
||||
public float InitialFootDistance;
|
||||
public float InitialStepThreshold;
|
||||
public float InitialStepHeight;
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
InitialFootPosLeft = Vector3.zero;
|
||||
InitialFootPosRight = Vector3.zero;
|
||||
InitialFootRotLeft = Quaternion.identity;
|
||||
InitialFootRotRight = Quaternion.identity;
|
||||
InitialFootDistance = 0f;
|
||||
InitialStepThreshold = 0f;
|
||||
InitialStepHeight = 0f;
|
||||
}
|
||||
}
|
62
.Deprecated/DesktopVRIK/IK/VRIKHelpers/VRIKUtils.cs
Normal file
62
.Deprecated/DesktopVRIK/IK/VRIKHelpers/VRIKUtils.cs
Normal file
|
@ -0,0 +1,62 @@
|
|||
using RootMotion.FinalIK;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.DesktopVRIK.IK.VRIKHelpers;
|
||||
|
||||
public static class VRIKUtils
|
||||
{
|
||||
public static void CalculateInitialIKScaling(VRIK vrik, ref VRIKLocomotionData locomotionData)
|
||||
{
|
||||
// Get distance between feet and thighs
|
||||
float scaleModifier = Mathf.Max(1f, vrik.references.pelvis.lossyScale.x);
|
||||
float footDistance = Vector3.Distance(vrik.references.leftFoot.position, vrik.references.rightFoot.position);
|
||||
|
||||
locomotionData.InitialFootDistance = footDistance * 0.5f;
|
||||
locomotionData.InitialStepThreshold = footDistance * scaleModifier;
|
||||
locomotionData.InitialStepHeight = Vector3.Distance(vrik.references.leftFoot.position, vrik.references.leftCalf.position) * 0.2f;
|
||||
}
|
||||
|
||||
public static void CalculateInitialFootsteps(VRIK vrik, ref VRIKLocomotionData locomotionData)
|
||||
{
|
||||
Transform root = vrik.references.root;
|
||||
Transform leftFoot = vrik.references.leftFoot;
|
||||
Transform rightFoot = vrik.references.rightFoot;
|
||||
|
||||
// Calculate the world rotation of the root bone at the current frame
|
||||
Quaternion rootWorldRot = root.rotation;
|
||||
|
||||
// Calculate the world rotation of the left and right feet relative to the root bone
|
||||
locomotionData.InitialFootPosLeft = root.InverseTransformPoint(leftFoot.position);
|
||||
locomotionData.InitialFootPosRight = root.InverseTransformPoint(rightFoot.position);
|
||||
locomotionData.InitialFootRotLeft = Quaternion.Inverse(rootWorldRot) * leftFoot.rotation;
|
||||
locomotionData.InitialFootRotRight = Quaternion.Inverse(rootWorldRot) * rightFoot.rotation;
|
||||
}
|
||||
|
||||
public static void ResetToInitialFootsteps(VRIK vrik, VRIKLocomotionData locomotionData, float scaleModifier)
|
||||
{
|
||||
Transform root = vrik.references.root;
|
||||
Quaternion rootWorldRot = vrik.references.root.rotation;
|
||||
|
||||
// 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;
|
||||
footsteps[0].Reset(rootWorldRot, root.TransformPoint(locomotionData.InitialFootPosLeft),
|
||||
rootWorldRot * locomotionData.InitialFootRotLeft);
|
||||
footsteps[1].Reset(rootWorldRot, root.TransformPoint(locomotionData.InitialFootPosRight),
|
||||
rootWorldRot * locomotionData.InitialFootRotRight);
|
||||
}
|
||||
|
||||
public static void ApplyScaleToVRIK(VRIK vrik, VRIKLocomotionData locomotionData, float scaleModifier)
|
||||
{
|
||||
IKSolverVR.Locomotion locomotionSolver = vrik.solver.locomotion;
|
||||
locomotionSolver.footDistance = locomotionData.InitialFootDistance * scaleModifier;
|
||||
locomotionSolver.stepThreshold = locomotionData.InitialStepThreshold * scaleModifier;
|
||||
ScaleStepHeight(locomotionSolver.stepHeight, locomotionData.InitialStepHeight * scaleModifier);
|
||||
}
|
||||
|
||||
private static void ScaleStepHeight(AnimationCurve stepHeightCurve, float mag)
|
||||
{
|
||||
var keyframes = stepHeightCurve.keys;
|
||||
keyframes[1].value = mag;
|
||||
stepHeightCurve.keys = keyframes;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue