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
95
.Deprecated/AlternateIKSystem/IK/BodyControl.cs
Normal file
95
.Deprecated/AlternateIKSystem/IK/BodyControl.cs
Normal file
|
@ -0,0 +1,95 @@
|
|||
using ABI_RC.Core.Player;
|
||||
using ABI_RC.Systems.MovementSystem;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.AlternateIKSystem.IK;
|
||||
|
||||
public class BodyControl
|
||||
{
|
||||
#region Player Settings
|
||||
|
||||
public static bool useHipTracking = true;
|
||||
public static bool useChestTracking = true;
|
||||
public static bool useLeftFootTracking = true;
|
||||
public static bool useRightFootTracking = true;
|
||||
|
||||
public static bool useLeftElbowTracking = false;
|
||||
public static bool useRightElbowTracking = false;
|
||||
public static bool useLeftKneeTracking = false;
|
||||
public static bool useRightKneeTracking = false;
|
||||
|
||||
public static bool useLocomotionAnimations = true;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Tracking Controls
|
||||
|
||||
public static bool TrackingAll = true;
|
||||
public static bool TrackingHead = true;
|
||||
public static bool TrackingPelvis = true;
|
||||
public static bool TrackingLeftArm = true;
|
||||
public static bool TrackingRightArm = true;
|
||||
public static bool TrackingLeftLeg = true;
|
||||
public static bool TrackingRightLeg = true;
|
||||
public static bool TrackingLocomotion = true;
|
||||
public static float TrackingIKPositionWeight = 1f;
|
||||
|
||||
// TODO: decide if this is considered "Tracking Controls"
|
||||
public static float TrackingMaxRootAngle = 0f;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Avatar Info
|
||||
|
||||
public static float AvatarUpright = 1f;
|
||||
|
||||
#endregion
|
||||
|
||||
#region BodyControl Configuration
|
||||
|
||||
public static float InvalidTrackerDistance = 1f;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
TrackingAll = ShouldTrackAll();
|
||||
TrackingLocomotion = ShouldTrackLocomotion();
|
||||
AvatarUpright = GetPlayerUpright();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private static bool ShouldTrackAll()
|
||||
{
|
||||
return !PlayerSetup.Instance._emotePlaying;
|
||||
}
|
||||
|
||||
private static bool ShouldTrackLocomotion()
|
||||
{
|
||||
return !(MovementSystem.Instance.movementVector.magnitude > 0f
|
||||
|| MovementSystem.Instance.crouching
|
||||
|| MovementSystem.Instance.prone
|
||||
|| MovementSystem.Instance.flying
|
||||
|| MovementSystem.Instance.sitting
|
||||
|| !MovementSystem.Instance._isGrounded);
|
||||
}
|
||||
|
||||
private static float GetPlayerUpright()
|
||||
{
|
||||
float avatarHeight = PlayerSetup.Instance._avatarHeight;
|
||||
float currentHeight = PlayerSetup.Instance.GetViewRelativePosition().y;
|
||||
return Mathf.Clamp01((avatarHeight > 0f) ? (currentHeight / avatarHeight) : 0f);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
229
.Deprecated/AlternateIKSystem/IK/IKCalibrator.cs
Normal file
229
.Deprecated/AlternateIKSystem/IK/IKCalibrator.cs
Normal file
|
@ -0,0 +1,229 @@
|
|||
using RootMotion.FinalIK;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace NAK.AlternateIKSystem.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 = 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
|
||||
}
|
170
.Deprecated/AlternateIKSystem/IK/IKHandlers/IKHandler.cs
Normal file
170
.Deprecated/AlternateIKSystem/IK/IKHandlers/IKHandler.cs
Normal file
|
@ -0,0 +1,170 @@
|
|||
using ABI.CCK.Components;
|
||||
using NAK.AlternateIKSystem.VRIKHelpers;
|
||||
using RootMotion.FinalIK;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.AlternateIKSystem.IK.IKHandlers;
|
||||
|
||||
internal abstract class IKHandler
|
||||
{
|
||||
#region Variables
|
||||
|
||||
internal VRIK _vrik;
|
||||
internal IKSolverVR _solver;
|
||||
|
||||
internal bool shouldTrackAll = true;
|
||||
internal bool shouldTrackHead = true;
|
||||
internal bool shouldTrackLeftArm = true;
|
||||
internal bool shouldTrackRightArm = true;
|
||||
internal bool shouldTrackLeftLeg = true;
|
||||
internal bool shouldTrackRightLeg = true;
|
||||
internal bool shouldTrackPelvis = true;
|
||||
internal bool shouldTrackLocomotion = true;
|
||||
|
||||
// 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 _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);
|
||||
|
||||
Vector3 deltaPosition = currentPosition - _movementPosition;
|
||||
Quaternion deltaRotation = Quaternion.Inverse(_movementRotation) * currentRotation;
|
||||
|
||||
if (_movementParent == currentParent)
|
||||
{
|
||||
_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()
|
||||
{
|
||||
if (!shouldTrackAll)
|
||||
return;
|
||||
|
||||
if (shouldTrackHead)
|
||||
Update_HeadWeight();
|
||||
|
||||
if (shouldTrackLeftArm)
|
||||
Update_LeftArmWeight();
|
||||
|
||||
if (shouldTrackRightArm)
|
||||
Update_RightArmWeight();
|
||||
|
||||
if (shouldTrackLeftLeg)
|
||||
Update_LeftLegWeight();
|
||||
|
||||
if (shouldTrackRightLeg)
|
||||
Update_RightLegWeight();
|
||||
|
||||
if (shouldTrackPelvis)
|
||||
Update_PelvisWeight();
|
||||
|
||||
if (shouldTrackLocomotion)
|
||||
{
|
||||
Update_LocomotionWeight();
|
||||
ResetSolverIfNeeded();
|
||||
}
|
||||
|
||||
Update_IKPositionWeight();
|
||||
}
|
||||
|
||||
protected virtual void Update_HeadWeight()
|
||||
{
|
||||
float targetWeight = GetTargetWeight(BodyControl.TrackingHead, true);
|
||||
}
|
||||
|
||||
protected virtual void Update_LeftArmWeight()
|
||||
{
|
||||
float leftArmWeight = GetTargetWeight(BodyControl.TrackingLeftArm, _solver.leftArm.target != null);
|
||||
}
|
||||
|
||||
protected virtual void Update_RightArmWeight()
|
||||
{
|
||||
float rightArmWeight = GetTargetWeight(BodyControl.TrackingRightArm, _solver.rightArm.target != null);
|
||||
}
|
||||
|
||||
protected virtual void Update_LeftLegWeight()
|
||||
{
|
||||
float leftLegWeight = GetTargetWeight(BodyControl.TrackingLeftLeg, _solver.leftLeg.target != null);
|
||||
}
|
||||
|
||||
protected virtual void Update_RightLegWeight()
|
||||
{
|
||||
float rightLegWeight = GetTargetWeight(BodyControl.TrackingRightLeg, _solver.rightLeg.target != null);
|
||||
}
|
||||
|
||||
protected virtual void Update_PelvisWeight()
|
||||
{
|
||||
float pelvisWeight = GetTargetWeight(BodyControl.TrackingPelvis, _solver.spine.pelvisTarget != null);
|
||||
}
|
||||
|
||||
protected virtual void Update_LocomotionWeight()
|
||||
{
|
||||
_locomotionWeight = Mathf.Lerp(_locomotionWeight, BodyControl.TrackingLocomotion ? 1f : 0f,
|
||||
Time.deltaTime * ModSettings.EntryIKLerpSpeed.Value * 2f);
|
||||
}
|
||||
|
||||
protected virtual void Update_IKPositionWeight()
|
||||
{
|
||||
float ikPositionWeight = BodyControl.TrackingAll ? BodyControl.TrackingIKPositionWeight : 0f;
|
||||
}
|
||||
|
||||
protected virtual float GetTargetWeight(bool isTracking, bool hasTarget)
|
||||
{
|
||||
return isTracking && hasTarget ? 1f : 0f;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private void ResetSolverIfNeeded()
|
||||
{
|
||||
if (_wasTrackingLocomotion == BodyControl.TrackingLocomotion)
|
||||
return;
|
||||
|
||||
_wasTrackingLocomotion = BodyControl.TrackingLocomotion;
|
||||
VRIKUtils.ResetToInitialFootsteps(_vrik, _locomotionData, _scaleDifference);
|
||||
_solver.Reset();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
using NAK.AlternateIKSystem.IK.WeightManipulators;
|
||||
using RootMotion.FinalIK;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.AlternateIKSystem.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.localPosition = Vector3.zero;
|
||||
_vrik.transform.localRotation = Quaternion.identity;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region VRIK Solver Events
|
||||
|
||||
private void OnPreSolverUpdateDesktop()
|
||||
{
|
||||
_solver.plantFeet = ModSettings.EntryPlantFeet.Value;
|
||||
|
||||
// Emulate old VRChat hip movement
|
||||
if (ModSettings.EntryBodyLeanWeight.Value > 0)
|
||||
{
|
||||
float weightedAngle = ModSettings.EntryProneThrusting.Value ? 1f : ModSettings.EntryBodyLeanWeight.Value * _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
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
using NAK.AlternateIKSystem.IK.WeightManipulators;
|
||||
using RootMotion.FinalIK;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.AlternateIKSystem.IK.IKHandlers;
|
||||
|
||||
internal class IKHandlerHalfBody : IKHandler
|
||||
{
|
||||
public IKHandlerHalfBody(VRIK vrik)
|
||||
{
|
||||
_vrik = vrik;
|
||||
_solver = vrik.solver;
|
||||
}
|
||||
|
||||
#region Game Overrides
|
||||
|
||||
public override void OnInitializeIk()
|
||||
{
|
||||
_vrik.onPreSolverUpdate.AddListener(OnPreSolverUpdateHalfBody);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region VRIK Solver Events
|
||||
|
||||
private void OnPreSolverUpdateHalfBody()
|
||||
{
|
||||
_solver.plantFeet = ModSettings.EntryPlantFeet.Value;
|
||||
|
||||
// Make root heading follow within a set limit
|
||||
if (ModSettings.EntryBodyHeadingLimit.Value > 0)
|
||||
{
|
||||
float weightedAngleLimit = ModSettings.EntryBodyHeadingLimit.Value * _solver.locomotion.weight;
|
||||
float currentRotation = IKManager.Instance.GetPlayerRotation().y;
|
||||
float deltaAngleRoot = Mathf.DeltaAngle(currentRotation, _ikSimulatedRootAngle);
|
||||
|
||||
if (Mathf.Abs(deltaAngleRoot) > weightedAngleLimit)
|
||||
{
|
||||
deltaAngleRoot = Mathf.Sign(deltaAngleRoot) * weightedAngleLimit;
|
||||
_ikSimulatedRootAngle = Mathf.MoveTowardsAngle(_ikSimulatedRootAngle, currentRotation, Mathf.Abs(deltaAngleRoot) - weightedAngleLimit);
|
||||
}
|
||||
|
||||
_solver.spine.rootHeadingOffset = deltaAngleRoot;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
474
.Deprecated/AlternateIKSystem/IK/IKManager.cs
Normal file
474
.Deprecated/AlternateIKSystem/IK/IKManager.cs
Normal file
|
@ -0,0 +1,474 @@
|
|||
using ABI.CCK.Components;
|
||||
using ABI_RC.Core.Player;
|
||||
using ABI_RC.Core.Savior;
|
||||
using NAK.AlternateIKSystem.IK.IKHandlers;
|
||||
using NAK.AlternateIKSystem.IK.WeightManipulators;
|
||||
using NAK.AlternateIKSystem.VRIKHelpers;
|
||||
using RootMotion.FinalIK;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.AlternateIKSystem.IK;
|
||||
|
||||
public class IKManager : MonoBehaviour
|
||||
{
|
||||
public static IKManager Instance;
|
||||
|
||||
#region Variables
|
||||
|
||||
public BodyControl BodyControl = new BodyControl();
|
||||
|
||||
public static VRIK vrik => _vrik;
|
||||
private static VRIK _vrik;
|
||||
public static IKSolverVR solver => _vrik?.solver;
|
||||
private static LookAtIK _lookAtIk;
|
||||
public static LookAtIK lookAtIk => _lookAtIk;
|
||||
|
||||
private bool _isAvatarInitialized;
|
||||
|
||||
// IK Handling
|
||||
private IKHandler _ikHandler;
|
||||
|
||||
// Player Info
|
||||
internal Transform _desktopCamera;
|
||||
internal Transform _vrCamera;
|
||||
internal Transform _vrHeadTarget;
|
||||
|
||||
// Controller Info
|
||||
private Transform _leftController;
|
||||
private Transform _rightController;
|
||||
private Transform _leftHandTarget;
|
||||
private Transform _leftHandRotations;
|
||||
private Transform _rightHandTarget;
|
||||
private Transform _rightHandRotations;
|
||||
|
||||
// Hand Anchor Offsets (the magic numbers that make or break the game)
|
||||
private readonly Vector3 _handAnchorPositionOffset = new Vector3(-0.048f, 0.0389f, -0.138f);
|
||||
private readonly Vector3 _handAnchorRotationOffset = new Vector3(70f, 0f, 50f);
|
||||
|
||||
// Avatar Info
|
||||
private Animator _animator;
|
||||
private 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
|
||||
private HumanPoseHandler _humanPoseHandler;
|
||||
private HumanPose _humanPose;
|
||||
private 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;
|
||||
_vrHeadTarget = PlayerSetup.Instance.vrHeadTracker.transform;
|
||||
_leftController = PlayerSetup.Instance.vrLeftHandTracker.transform;
|
||||
_rightController = PlayerSetup.Instance.vrRightHandTracker.transform;
|
||||
|
||||
// ouchie
|
||||
_leftHandTarget = _leftController.Find("LeftHandTarget");
|
||||
_leftHandRotations = _leftHandTarget.Find("LeftHandRotations");
|
||||
_rightHandTarget = _rightController.Find("RightHandTarget");
|
||||
_rightHandRotations = _rightHandTarget.Find("RightHandRotations");
|
||||
|
||||
BodyControl.Start();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!_isAvatarInitialized)
|
||||
return;
|
||||
|
||||
BodyControl.Update();
|
||||
|
||||
_ikHandler?.UpdateWeights();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Avatar Events
|
||||
|
||||
public void OnAvatarInitialized(GameObject inAvatar)
|
||||
{
|
||||
if (_isAvatarInitialized)
|
||||
return;
|
||||
|
||||
if (!inAvatar.TryGetComponent(out _animator))
|
||||
return;
|
||||
|
||||
if (_animator.avatar == null || !_animator.avatar.isHuman)
|
||||
return;
|
||||
|
||||
_lookAtIk = inAvatar.GetComponent<LookAtIK>();
|
||||
|
||||
_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);
|
||||
|
||||
if (MetaPort.Instance.isUsingVr)
|
||||
{
|
||||
InitializeHalfBodyIk();
|
||||
}
|
||||
else
|
||||
{
|
||||
InitializeDesktopIk();
|
||||
}
|
||||
|
||||
_isAvatarInitialized = true;
|
||||
}
|
||||
|
||||
public void OnAvatarDestroyed()
|
||||
{
|
||||
if (!_isAvatarInitialized)
|
||||
return;
|
||||
|
||||
_vrik = null;
|
||||
_lookAtIk = 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 (!_isAvatarInitialized)
|
||||
return false;
|
||||
|
||||
_ikHandler?.OnPlayerScaled(scaleDifference);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void OnPlayerSeatedStateChanged(bool isSitting)
|
||||
{
|
||||
if (!_isAvatarInitialized)
|
||||
return;
|
||||
|
||||
// update immediately, ShouldTrackLocomotion() will catch up next frame
|
||||
if (isSitting)
|
||||
BodyControl.TrackingLocomotion = false;
|
||||
}
|
||||
|
||||
public bool OnPlayerHandleMovementParent(CVRMovementParent movementParent)
|
||||
{
|
||||
if (!_isAvatarInitialized)
|
||||
return false;
|
||||
|
||||
_ikHandler?.OnPlayerHandleMovementParent(movementParent, GetPlayerPosition());
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool OnPlayerTeleported()
|
||||
{
|
||||
if (!_isAvatarInitialized)
|
||||
return false;
|
||||
|
||||
_vrik?.solver.Reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IK Initialization
|
||||
|
||||
private void InitializeDesktopIk()
|
||||
{
|
||||
SetupIkGeneral();
|
||||
|
||||
IKCalibrator.ConfigureDesktopVrIk(_vrik);
|
||||
_ikHandler = new IKHandlerDesktop(_vrik);
|
||||
|
||||
IKCalibrator.SetupHeadIKTarget(_vrik);
|
||||
|
||||
InitializeIkGeneral();
|
||||
|
||||
_ikHandler.OnInitializeIk();
|
||||
}
|
||||
|
||||
private void InitializeHalfBodyIk()
|
||||
{
|
||||
SetupIkGeneral();
|
||||
|
||||
IKCalibrator.ConfigureHalfBodyVrIk(_vrik);
|
||||
_ikHandler = new IKHandlerHalfBody(_vrik);
|
||||
|
||||
IKCalibrator.SetupHeadIKTarget(_vrik, _vrHeadTarget);
|
||||
IKCalibrator.SetupHandIKTarget(_vrik, _leftHandRotations, true);
|
||||
IKCalibrator.SetupHandIKTarget(_vrik, _rightHandRotations, false);
|
||||
|
||||
// Configure controller offsets
|
||||
_leftHandTarget.localPosition = _handAnchorPositionOffset;
|
||||
_leftHandTarget.localEulerAngles = _handAnchorRotationOffset;
|
||||
_rightHandTarget.localPosition = Vector3.Scale(_handAnchorPositionOffset, new Vector3(-1, 1, 1));
|
||||
_rightHandTarget.localEulerAngles = Vector3.Scale(_handAnchorRotationOffset, new Vector3(1, -1, -1));
|
||||
|
||||
InitializeIkGeneral();
|
||||
|
||||
_ikHandler.OnInitializeIk();
|
||||
}
|
||||
|
||||
private void SetupIkGeneral()
|
||||
{
|
||||
_animator.transform.position = GetPlayerPosition();
|
||||
_animator.transform.rotation = GetPlayerRotation();
|
||||
SetAvatarPose(AvatarPose.Default);
|
||||
_vrik = IKCalibrator.SetupVrIk(_animator);
|
||||
}
|
||||
|
||||
private void InitializeIkGeneral()
|
||||
{
|
||||
SetAvatarPose(AvatarPose.IKPose);
|
||||
|
||||
VRIKUtils.CalculateInitialIKScaling(_vrik, ref _ikHandler._locomotionData);
|
||||
VRIKUtils.CalculateInitialFootsteps(_vrik, ref _ikHandler._locomotionData);
|
||||
_vrik.solver.Initiate(_vrik.transform); // initiate a second time
|
||||
|
||||
SetAvatarPose(AvatarPose.Initial);
|
||||
|
||||
VRIKUtils.ApplyScaleToVRIK(_vrik, _ikHandler._locomotionData, 1f);
|
||||
_vrik.onPreSolverUpdate.AddListener(OnPreSolverUpdateGeneral);
|
||||
_vrik.onPostSolverUpdate.AddListener(OnPostSolverUpdateGeneral);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
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 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++)
|
||||
{
|
||||
//if (IkTweaksSettings.IgnoreAnimationsModeParsed == IgnoreAnimationsMode.All && IKTweaksMod.ourRandomPuck.activeInHierarchy)
|
||||
//{
|
||||
// muscles[i] *= ourBoneResetMasks[i] == BoneResetMask.Never ? 1 : 0;
|
||||
// continue;
|
||||
//}
|
||||
switch (ourBoneResetMasks[i])
|
||||
{
|
||||
case BoneResetMask.Never:
|
||||
break;
|
||||
case BoneResetMask.Spine:
|
||||
_humanPose.muscles[i] *= 1 - solver.spine.pelvisPositionWeight;
|
||||
break;
|
||||
case BoneResetMask.LeftArm:
|
||||
_humanPose.muscles[i] *= 1 - solver.leftArm.positionWeight;
|
||||
break;
|
||||
case BoneResetMask.RightArm:
|
||||
_humanPose.muscles[i] *= 1 - solver.rightArm.positionWeight;
|
||||
break;
|
||||
case BoneResetMask.LeftLeg:
|
||||
_humanPose.muscles[i] *= 1 - solver.leftLeg.positionWeight;
|
||||
break;
|
||||
case 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 < ourBoneResetMasks.Length; i++)
|
||||
{
|
||||
if (ourBoneResetMasks[i] != 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 < ourBoneResetMasks.Length; i++)
|
||||
{
|
||||
if (ourBoneResetMasks[i] != BoneResetMask.Never)
|
||||
_humanPose.muscles[i] = muscles[i];
|
||||
}
|
||||
|
||||
_humanPose.bodyPosition = Vector3.up;
|
||||
_humanPose.bodyRotation = Quaternion.identity;
|
||||
_humanPoseHandler.SetHumanPose(ref _humanPose);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region BodyHandling
|
||||
|
||||
public enum BoneResetMask
|
||||
{
|
||||
Never,
|
||||
Spine,
|
||||
LeftArm,
|
||||
RightArm,
|
||||
LeftLeg,
|
||||
RightLeg,
|
||||
}
|
||||
|
||||
private static readonly string[] ourNeverBones = { "Index", "Thumb", "Middle", "Ring", "Little", "Jaw", "Eye" };
|
||||
private static readonly string[] ourArmBones = { "Arm", "Forearm", "Hand", "Shoulder" };
|
||||
private static readonly string[] ourLegBones = { "Leg", "Foot", "Toes" };
|
||||
|
||||
private static BoneResetMask JudgeBone(string name)
|
||||
{
|
||||
if (ourNeverBones.Any(name.Contains))
|
||||
return BoneResetMask.Never;
|
||||
|
||||
if (ourArmBones.Any(name.Contains))
|
||||
{
|
||||
return name.Contains("Left") ? BoneResetMask.LeftArm : BoneResetMask.RightArm;
|
||||
}
|
||||
|
||||
if (ourLegBones.Any(name.Contains))
|
||||
return name.Contains("Left") ? BoneResetMask.LeftLeg : BoneResetMask.RightLeg;
|
||||
|
||||
return BoneResetMask.Spine;
|
||||
}
|
||||
|
||||
internal static readonly BoneResetMask[] ourBoneResetMasks = HumanTrait.MuscleName.Select(JudgeBone).ToArray();
|
||||
|
||||
#endregion
|
||||
}
|
46
.Deprecated/AlternateIKSystem/IK/MusclePoses.cs
Normal file
46
.Deprecated/AlternateIKSystem/IK/MusclePoses.cs
Normal file
|
@ -0,0 +1,46 @@
|
|||
namespace NAK.AlternateIKSystem.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
|
||||
};
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
using UnityEngine;
|
||||
using Valve.VR;
|
||||
|
||||
namespace AlternateIKSystem.IK.Tracking;
|
||||
|
||||
public class SteamVR_TrackerManager : MonoBehaviour
|
||||
{
|
||||
public static SteamVR_TrackerManager Instance { get; private set; }
|
||||
|
||||
private readonly Dictionary<uint, TrackedPoint> trackedPoints = new Dictionary<uint, TrackedPoint>();
|
||||
private int lastPosesCount = 0;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance != null)
|
||||
{
|
||||
DestroyImmediate(this);
|
||||
return;
|
||||
}
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
SteamVR_Events.NewPoses.AddListener(OnNewPoses);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
SteamVR_Events.NewPoses.RemoveListener(OnNewPoses);
|
||||
}
|
||||
|
||||
private void OnNewPoses(TrackedDevicePose_t[] poses)
|
||||
{
|
||||
if (lastPosesCount < poses.Length)
|
||||
{
|
||||
// If the count has increased, a new tracker has been connected.
|
||||
for (uint i = (uint)lastPosesCount; i < poses.Length; i++)
|
||||
{
|
||||
if (OpenVR.System.GetTrackedDeviceClass(i) == ETrackedDeviceClass.GenericTracker)
|
||||
trackedPoints.Add(i, new TrackedPoint(i));
|
||||
}
|
||||
}
|
||||
else if (lastPosesCount > poses.Length)
|
||||
{
|
||||
// If the count has decreased, a tracker has been disconnected.
|
||||
for (uint i = (uint)poses.Length; i < lastPosesCount; i++)
|
||||
{
|
||||
if (!trackedPoints.ContainsKey(i))
|
||||
continue;
|
||||
|
||||
trackedPoints[i].Destroy();
|
||||
trackedPoints.Remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
for (uint i = 0; i < poses.Length; i++)
|
||||
{
|
||||
if (trackedPoints.TryGetValue(i, out TrackedPoint point))
|
||||
{
|
||||
point.UpdatePose(poses[i]);
|
||||
}
|
||||
}
|
||||
|
||||
lastPosesCount = poses.Length;
|
||||
}
|
||||
|
||||
private class TrackedPoint
|
||||
{
|
||||
private uint i;
|
||||
|
||||
public TrackedPoint(uint i)
|
||||
{
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
public void UpdatePose(TrackedDevicePose_t pose)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Destroy()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace NAK.AlternateIKSystem.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/AlternateIKSystem/IK/VRIKHelpers/VRIKUtils.cs
Normal file
62
.Deprecated/AlternateIKSystem/IK/VRIKHelpers/VRIKUtils.cs
Normal file
|
@ -0,0 +1,62 @@
|
|||
using RootMotion.FinalIK;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.AlternateIKSystem.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 * scaleModifier),
|
||||
rootWorldRot * locomotionData.InitialFootRotLeft);
|
||||
footsteps[1].Reset(rootWorldRot, root.TransformPoint(locomotionData.InitialFootPosRight * scaleModifier),
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
using RootMotion.FinalIK;
|
||||
|
||||
namespace NAK.AlternateIKSystem.IK.WeightManipulators.BodyParts;
|
||||
|
||||
public abstract class BodyPart
|
||||
{
|
||||
protected float positionWeight = 1f;
|
||||
protected float rotationWeight = 1f;
|
||||
protected bool isEnabled = true;
|
||||
|
||||
public void SetPositionWeight(float weight)
|
||||
{
|
||||
this.positionWeight *= weight;
|
||||
}
|
||||
|
||||
public void SetRotationWeight(float weight)
|
||||
{
|
||||
this.rotationWeight *= weight;
|
||||
}
|
||||
|
||||
public void SetEnabled(bool isEnabled)
|
||||
{
|
||||
this.isEnabled = isEnabled;
|
||||
}
|
||||
|
||||
public abstract void ApplyWeightToSolver(IKSolverVR solver);
|
||||
}
|
||||
|
||||
public class Head : BodyPart
|
||||
{
|
||||
public override void ApplyWeightToSolver(IKSolverVR solver)
|
||||
{
|
||||
if (!isEnabled) return;
|
||||
solver.spine.positionWeight *= positionWeight;
|
||||
solver.spine.rotationWeight *= rotationWeight;
|
||||
}
|
||||
}
|
||||
|
||||
public class Pelvis : BodyPart
|
||||
{
|
||||
public override void ApplyWeightToSolver(IKSolverVR solver)
|
||||
{
|
||||
if (!isEnabled) return;
|
||||
solver.spine.pelvisPositionWeight *= positionWeight;
|
||||
solver.spine.pelvisRotationWeight *= rotationWeight;
|
||||
}
|
||||
}
|
||||
|
||||
public class LeftArm : BodyPart
|
||||
{
|
||||
private float bendGoalWeight = 1f;
|
||||
|
||||
public void SetBendGoalWeight(float weight)
|
||||
{
|
||||
this.bendGoalWeight *= weight;
|
||||
}
|
||||
|
||||
public override void ApplyWeightToSolver(IKSolverVR solver)
|
||||
{
|
||||
if (!isEnabled) return;
|
||||
|
||||
solver.leftArm.positionWeight *= positionWeight;
|
||||
solver.leftArm.rotationWeight *= rotationWeight;
|
||||
solver.leftArm.bendGoalWeight *= bendGoalWeight;
|
||||
}
|
||||
}
|
||||
|
||||
public class RightArm : BodyPart
|
||||
{
|
||||
private float bendGoalWeight = 1f;
|
||||
|
||||
public void SetBendGoalWeight(float weight)
|
||||
{
|
||||
this.bendGoalWeight *= weight;
|
||||
}
|
||||
|
||||
public override void ApplyWeightToSolver(IKSolverVR solver)
|
||||
{
|
||||
if (!isEnabled) return;
|
||||
|
||||
solver.rightArm.positionWeight *= positionWeight;
|
||||
solver.rightArm.rotationWeight *= rotationWeight;
|
||||
solver.rightArm.bendGoalWeight *= bendGoalWeight;
|
||||
}
|
||||
}
|
||||
|
||||
public class LeftLeg : BodyPart
|
||||
{
|
||||
private float bendGoalWeight = 1f;
|
||||
|
||||
public void SetBendGoalWeight(float weight)
|
||||
{
|
||||
this.bendGoalWeight *= weight;
|
||||
}
|
||||
|
||||
public override void ApplyWeightToSolver(IKSolverVR solver)
|
||||
{
|
||||
if (!isEnabled) return;
|
||||
|
||||
solver.leftLeg.positionWeight *= positionWeight;
|
||||
solver.leftLeg.rotationWeight *= rotationWeight;
|
||||
solver.leftLeg.bendGoalWeight *= bendGoalWeight;
|
||||
}
|
||||
}
|
||||
|
||||
public class RightLeg : BodyPart
|
||||
{
|
||||
private float bendGoalWeight = 1f;
|
||||
|
||||
public void SetBendGoalWeight(float weight)
|
||||
{
|
||||
this.bendGoalWeight *= weight;
|
||||
}
|
||||
|
||||
public override void ApplyWeightToSolver(IKSolverVR solver)
|
||||
{
|
||||
if (!isEnabled) return;
|
||||
|
||||
solver.rightLeg.positionWeight *= positionWeight;
|
||||
solver.rightLeg.rotationWeight *= rotationWeight;
|
||||
solver.rightLeg.bendGoalWeight *= bendGoalWeight;
|
||||
}
|
||||
}
|
||||
|
||||
public class Locomotion : BodyPart
|
||||
{
|
||||
public override void ApplyWeightToSolver(IKSolverVR solver)
|
||||
{
|
||||
if (!isEnabled) return;
|
||||
solver.locomotion.weight *= positionWeight;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
using NAK.AlternateIKSystem.IK.WeightManipulators.Interface;
|
||||
using RootMotion.FinalIK;
|
||||
|
||||
namespace NAK.AlternateIKSystem.IK.WeightManipulators;
|
||||
|
||||
public class DeviceControlManipulator : IWeightManipulator
|
||||
{
|
||||
public static bool shouldTrackAll = true;
|
||||
public static bool shouldTrackHead = true;
|
||||
public static bool shouldTrackPelvis = true;
|
||||
public static bool shouldTrackLeftArm = true;
|
||||
public static bool shouldTrackRightArm = true;
|
||||
public static bool shouldTrackLeftLeg = true;
|
||||
public static bool shouldTrackRightLeg = true;
|
||||
public static bool shouldTrackLocomotion = true;
|
||||
|
||||
public WeightManipulatorManager Manager { get; set; }
|
||||
|
||||
// Manipulator for Connected Devices (Has final say)
|
||||
public void Update(IKSolverVR solver)
|
||||
{
|
||||
Manager.TrackAll &= shouldTrackAll;
|
||||
Manager.TrackHead &= shouldTrackHead;
|
||||
Manager.TrackPelvis &= shouldTrackPelvis;
|
||||
Manager.TrackLeftArm &= shouldTrackLeftArm;
|
||||
Manager.TrackRightArm &= shouldTrackRightArm;
|
||||
Manager.TrackLeftLeg &= shouldTrackLeftLeg;
|
||||
Manager.TrackRightLeg &= shouldTrackRightLeg;
|
||||
Manager.TrackLocomotion &= shouldTrackLocomotion;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
using RootMotion.FinalIK;
|
||||
|
||||
namespace NAK.AlternateIKSystem.IK.WeightManipulators.Interface;
|
||||
|
||||
public interface IWeightManipulator
|
||||
{
|
||||
WeightManipulatorManager Manager { get; set; }
|
||||
void Update(IKSolverVR solver);
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
using NAK.AlternateIKSystem.IK.WeightManipulators.Interface;
|
||||
using RootMotion.FinalIK;
|
||||
|
||||
namespace NAK.AlternateIKSystem.IK.WeightManipulators;
|
||||
|
||||
public class TrackingControlManipulator : IWeightManipulator
|
||||
{
|
||||
public WeightManipulatorManager Manager { get; set; }
|
||||
|
||||
// Manipulator for External Control (Auto, State Behaviour)
|
||||
public void Update(IKSolverVR solver)
|
||||
{
|
||||
Manager.TrackAll |= BodyControl.TrackingAll;
|
||||
Manager.TrackHead |= BodyControl.TrackingHead;
|
||||
Manager.TrackPelvis |= BodyControl.TrackingPelvis;
|
||||
Manager.TrackLeftArm |= BodyControl.TrackingLeftArm;
|
||||
Manager.TrackRightArm |= BodyControl.TrackingRightArm;
|
||||
Manager.TrackLeftLeg |= BodyControl.TrackingLeftLeg;
|
||||
Manager.TrackRightLeg |= BodyControl.TrackingRightLeg;
|
||||
Manager.TrackLocomotion |= BodyControl.TrackingLocomotion;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
using NAK.AlternateIKSystem.IK.WeightManipulators.BodyParts;
|
||||
using NAK.AlternateIKSystem.IK.WeightManipulators.Interface;
|
||||
using RootMotion.FinalIK;
|
||||
|
||||
namespace NAK.AlternateIKSystem.IK.WeightManipulators;
|
||||
|
||||
public enum BodyPartEnum
|
||||
{
|
||||
Head,
|
||||
Pelvis,
|
||||
LeftArm,
|
||||
RightArm,
|
||||
LeftLeg,
|
||||
RightLeg,
|
||||
Locomotion,
|
||||
All
|
||||
}
|
||||
|
||||
public class WeightManipulatorManager
|
||||
{
|
||||
private readonly Dictionary<BodyPartEnum, BodyPart> _bodyParts = new Dictionary<BodyPartEnum, BodyPart>();
|
||||
|
||||
public WeightManipulatorManager()
|
||||
{
|
||||
_bodyParts.Add(BodyPartEnum.Head, new Head());
|
||||
_bodyParts.Add(BodyPartEnum.Pelvis, new Pelvis());
|
||||
_bodyParts.Add(BodyPartEnum.LeftArm, new LeftArm());
|
||||
_bodyParts.Add(BodyPartEnum.RightArm, new RightArm());
|
||||
_bodyParts.Add(BodyPartEnum.LeftLeg, new LeftLeg());
|
||||
_bodyParts.Add(BodyPartEnum.RightLeg, new RightLeg());
|
||||
_bodyParts.Add(BodyPartEnum.Locomotion, new Locomotion());
|
||||
}
|
||||
|
||||
public void SetWeight(BodyPartEnum bodyPartName, float positionWeight, float rotationWeight)
|
||||
{
|
||||
var bodyPart = _bodyParts[bodyPartName];
|
||||
bodyPart.SetPositionWeight(positionWeight);
|
||||
bodyPart.SetRotationWeight(rotationWeight);
|
||||
}
|
||||
|
||||
public void SetEnabled(BodyPartEnum bodyPartName, bool isEnabled)
|
||||
{
|
||||
var bodyPart = _bodyParts[bodyPartName];
|
||||
bodyPart.SetEnabled(isEnabled);
|
||||
}
|
||||
|
||||
public void ApplyWeightsToSolver(IKSolverVR solver)
|
||||
{
|
||||
foreach (var bodyPart in _bodyParts.Values)
|
||||
{
|
||||
bodyPart.ApplyWeightToSolver(solver);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class BodyControl
|
||||
{
|
||||
private readonly WeightManipulatorManager _manager;
|
||||
|
||||
public BodyControl(WeightManipulatorManager manager)
|
||||
{
|
||||
_manager = manager;
|
||||
}
|
||||
|
||||
public void SetWeight(string bodyPartName, float positionWeight, float rotationWeight)
|
||||
{
|
||||
_manager.SetWeight(bodyPartName, positionWeight, rotationWeight);
|
||||
}
|
||||
}
|
||||
|
||||
public class DeviceControl
|
||||
{
|
||||
private readonly WeightManipulatorManager _manager;
|
||||
|
||||
public DeviceControl(WeightManipulatorManager manager)
|
||||
{
|
||||
_manager = manager;
|
||||
}
|
||||
|
||||
public void SetEnabled(string bodyPartName, bool isEnabled)
|
||||
{
|
||||
_manager.SetEnabled(bodyPartName, isEnabled);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue