From d77afcc0093900a6a37c867b1ef8794c4e2565b2 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Wed, 26 Jul 2023 08:27:28 -0500 Subject: [PATCH] push what i have --- AlternateIKSystem/IK/BodyControl.cs | 62 +------- AlternateIKSystem/IK/IKHandlers/IKHandler.cs | 10 -- .../IK/IKHandlers/IKHandlerDesktop.cs | 22 ++- .../IK/IKHandlers/IKHandlerHalfBody.cs | 17 +-- AlternateIKSystem/IK/IKManager.cs | 14 +- .../IK/Tracking/SteamVRTrackerManager.cs | 87 ++++++++++++ .../WeightManipulators/BodyParts/BodyPart.cs | 132 ++++++++++++++++++ .../DeviceControlManipulator.cs | 31 ++++ .../Interface/IWeightManipulator.cs | 9 ++ .../TrackingControlManipulator.cs | 22 +++ .../WeightManipulatorManager.cs | 84 +++++++++++ AlternateIKSystem/Integrations/BTKUIAddon.cs | 2 +- NAK_CVR_Mods.sln | 6 + ViewpointHeadScaleFix/Main.cs | 55 ++++++++ .../Properties/AssemblyInfo.cs | 32 +++++ .../ViewpointHeadScaleFix.csproj | 2 + 16 files changed, 496 insertions(+), 91 deletions(-) create mode 100644 AlternateIKSystem/IK/Tracking/SteamVRTrackerManager.cs create mode 100644 AlternateIKSystem/IK/WeightManipulators/BodyParts/BodyPart.cs create mode 100644 AlternateIKSystem/IK/WeightManipulators/DeviceControlManipulator.cs create mode 100644 AlternateIKSystem/IK/WeightManipulators/Interface/IWeightManipulator.cs create mode 100644 AlternateIKSystem/IK/WeightManipulators/TrackingControlManipulator.cs create mode 100644 AlternateIKSystem/IK/WeightManipulators/WeightManipulatorManager.cs create mode 100644 ViewpointHeadScaleFix/Main.cs create mode 100644 ViewpointHeadScaleFix/Properties/AssemblyInfo.cs create mode 100644 ViewpointHeadScaleFix/ViewpointHeadScaleFix.csproj diff --git a/AlternateIKSystem/IK/BodyControl.cs b/AlternateIKSystem/IK/BodyControl.cs index 0fb517a..d1c85d3 100644 --- a/AlternateIKSystem/IK/BodyControl.cs +++ b/AlternateIKSystem/IK/BodyControl.cs @@ -1,6 +1,5 @@ using ABI_RC.Core.Player; using ABI_RC.Systems.MovementSystem; -using RootMotion.FinalIK; using UnityEngine; namespace NAK.AlternateIKSystem.IK; @@ -54,6 +53,11 @@ public class BodyControl #region Public Methods + public void Start() + { + + } + public void Update() { TrackingAll = ShouldTrackAll(); @@ -88,60 +92,4 @@ public class BodyControl } #endregion - - #region Solver Weight Helpers - - // I am unsure on this...? - - public static void SetLookAtWeight(LookAtIK lookAtIk, float weight) - { - if (lookAtIk != null) - lookAtIk.solver.IKPositionWeight = weight; - } - - public static void SetHeadWeight(IKSolverVR.Spine spine, float weight) - { - spine.positionWeight = weight; - spine.rotationWeight = weight; - } - - public static void SetArmWeight(IKSolverVR.Arm arm, float weight) - { - arm.positionWeight = weight; - arm.rotationWeight = weight; - //arm.shoulderRotationWeight = weight; - //arm.shoulderTwistWeight = weight; - arm.bendGoalWeight = arm.bendGoal != null ? weight : 0f; - } - - public static void SetLegWeight(IKSolverVR.Leg leg, float weight) - { - leg.positionWeight = weight; - leg.rotationWeight = weight; - leg.bendGoalWeight = leg.usingKneeTracker ? weight : 0f; - } - - public static void SetPelvisWeight(IKSolverVR.Spine spine, float weight) - { - spine.pelvisPositionWeight = weight; - spine.pelvisRotationWeight = weight; - } - - public static void SetLocomotionWeight(IKSolverVR.Locomotion locomotion, float weight) - { - locomotion.weight = weight; - } - - public static void SetIKPositionWeight(IKSolverVR solver, float weight) - { - solver.IKPositionWeight = weight; - } - - public static void SetIKPositionWeight(LookAtIK lookAtIk, float weight) - { - if (lookAtIk != null) - lookAtIk.solver.IKPositionWeight = weight; - } - - #endregion } \ No newline at end of file diff --git a/AlternateIKSystem/IK/IKHandlers/IKHandler.cs b/AlternateIKSystem/IK/IKHandlers/IKHandler.cs index 66b4fab..898f67d 100644 --- a/AlternateIKSystem/IK/IKHandlers/IKHandler.cs +++ b/AlternateIKSystem/IK/IKHandlers/IKHandler.cs @@ -109,52 +109,42 @@ internal abstract class IKHandler protected virtual void Update_HeadWeight() { float targetWeight = GetTargetWeight(BodyControl.TrackingHead, true); - BodyControl.SetHeadWeight(_solver.spine, targetWeight); - BodyControl.SetLookAtWeight(IKManager.lookAtIk, targetWeight); } protected virtual void Update_LeftArmWeight() { float leftArmWeight = GetTargetWeight(BodyControl.TrackingLeftArm, _solver.leftArm.target != null); - BodyControl.SetArmWeight(_solver.leftArm, leftArmWeight); } protected virtual void Update_RightArmWeight() { float rightArmWeight = GetTargetWeight(BodyControl.TrackingRightArm, _solver.rightArm.target != null); - BodyControl.SetArmWeight(_solver.rightArm, rightArmWeight); } protected virtual void Update_LeftLegWeight() { float leftLegWeight = GetTargetWeight(BodyControl.TrackingLeftLeg, _solver.leftLeg.target != null); - BodyControl.SetLegWeight(_solver.leftLeg, leftLegWeight); } protected virtual void Update_RightLegWeight() { float rightLegWeight = GetTargetWeight(BodyControl.TrackingRightLeg, _solver.rightLeg.target != null); - BodyControl.SetLegWeight(_solver.rightLeg, rightLegWeight); } protected virtual void Update_PelvisWeight() { float pelvisWeight = GetTargetWeight(BodyControl.TrackingPelvis, _solver.spine.pelvisTarget != null); - BodyControl.SetPelvisWeight(_solver.spine, pelvisWeight); } protected virtual void Update_LocomotionWeight() { _locomotionWeight = Mathf.Lerp(_locomotionWeight, BodyControl.TrackingLocomotion ? 1f : 0f, Time.deltaTime * ModSettings.EntryIKLerpSpeed.Value * 2f); - BodyControl.SetLocomotionWeight(_solver.locomotion, _locomotionWeight); } protected virtual void Update_IKPositionWeight() { float ikPositionWeight = BodyControl.TrackingAll ? BodyControl.TrackingIKPositionWeight : 0f; - BodyControl.SetIKPositionWeight(_solver, ikPositionWeight); - BodyControl.SetIKPositionWeight(IKManager.lookAtIk, ikPositionWeight); } protected virtual float GetTargetWeight(bool isTracking, bool hasTarget) diff --git a/AlternateIKSystem/IK/IKHandlers/IKHandlerDesktop.cs b/AlternateIKSystem/IK/IKHandlers/IKHandlerDesktop.cs index 5c7b27b..088b42b 100644 --- a/AlternateIKSystem/IK/IKHandlers/IKHandlerDesktop.cs +++ b/AlternateIKSystem/IK/IKHandlers/IKHandlerDesktop.cs @@ -1,4 +1,5 @@ -using RootMotion.FinalIK; +using NAK.AlternateIKSystem.IK.WeightManipulators; +using RootMotion.FinalIK; using UnityEngine; namespace NAK.AlternateIKSystem.IK.IKHandlers; @@ -16,13 +17,13 @@ internal class IKHandlerDesktop : IKHandler public override void OnInitializeIk() { // Default tracking for Desktop - shouldTrackHead = true; - shouldTrackLeftArm = false; - shouldTrackRightArm = false; - shouldTrackLeftLeg = false; - shouldTrackRightLeg = false; - shouldTrackPelvis = false; - shouldTrackLocomotion = true; + DeviceControlManipulator.shouldTrackHead = true; + DeviceControlManipulator.shouldTrackLeftArm = false; + DeviceControlManipulator.shouldTrackRightArm = false; + DeviceControlManipulator.shouldTrackLeftLeg = false; + DeviceControlManipulator.shouldTrackRightLeg = false; + DeviceControlManipulator.shouldTrackPelvis = false; + DeviceControlManipulator.shouldTrackLocomotion = true; _vrik.onPreSolverUpdate.AddListener(OnPreSolverUpdateDesktop); } @@ -36,11 +37,6 @@ internal class IKHandlerDesktop : IKHandler // Reset avatar local position _vrik.transform.localPosition = Vector3.zero; _vrik.transform.localRotation = Quaternion.identity; - - base.UpdateWeights(); - - // Desktop should never have head position weight - _solver.spine.positionWeight = 0f; } #endregion diff --git a/AlternateIKSystem/IK/IKHandlers/IKHandlerHalfBody.cs b/AlternateIKSystem/IK/IKHandlers/IKHandlerHalfBody.cs index eef6c36..9af02ac 100644 --- a/AlternateIKSystem/IK/IKHandlers/IKHandlerHalfBody.cs +++ b/AlternateIKSystem/IK/IKHandlers/IKHandlerHalfBody.cs @@ -1,4 +1,5 @@ -using RootMotion.FinalIK; +using NAK.AlternateIKSystem.IK.WeightManipulators; +using RootMotion.FinalIK; using UnityEngine; namespace NAK.AlternateIKSystem.IK.IKHandlers; @@ -16,13 +17,13 @@ internal class IKHandlerHalfBody : IKHandler public override void OnInitializeIk() { // Default tracking for HalfBody - shouldTrackHead = true; - shouldTrackLeftArm = true; - shouldTrackRightArm = true; - shouldTrackLeftLeg = false; - shouldTrackRightLeg = false; - shouldTrackPelvis = false; - shouldTrackLocomotion = true; + DeviceControlManipulator.shouldTrackHead = true; + DeviceControlManipulator.shouldTrackLeftArm = true; + DeviceControlManipulator.shouldTrackRightArm = true; + DeviceControlManipulator.shouldTrackLeftLeg = false; + DeviceControlManipulator.shouldTrackRightLeg = false; + DeviceControlManipulator.shouldTrackPelvis = false; + DeviceControlManipulator.shouldTrackLocomotion = true; _vrik.onPreSolverUpdate.AddListener(OnPreSolverUpdateHalfBody); } diff --git a/AlternateIKSystem/IK/IKManager.cs b/AlternateIKSystem/IK/IKManager.cs index 70f145f..263ff33 100644 --- a/AlternateIKSystem/IK/IKManager.cs +++ b/AlternateIKSystem/IK/IKManager.cs @@ -2,6 +2,7 @@ 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; @@ -15,6 +16,7 @@ public class IKManager : MonoBehaviour #region Variables public BodyControl BodyControl = new BodyControl(); + public WeightManipulatorManager WeightManipulator = new WeightManipulatorManager(); public static VRIK vrik => _vrik; private static VRIK _vrik; @@ -83,15 +85,23 @@ public class IKManager : MonoBehaviour _leftHandRotations = _leftHandTarget.Find("LeftHandRotations"); _rightHandTarget = _rightController.Find("RightHandTarget"); _rightHandRotations = _rightHandTarget.Find("RightHandRotations"); + + WeightManipulator.AddOverride(new TrackingControlManipulator()); + WeightManipulator.AddOverride(new DeviceControlManipulator()); + + BodyControl.Start(); } private void Update() { - BodyControl.Update(); - if (!_isAvatarInitialized) return; + BodyControl.Update(); + + if (vrik.solver != null) + WeightManipulator.UpdateWeights(vrik.solver); + _ikHandler?.UpdateWeights(); } diff --git a/AlternateIKSystem/IK/Tracking/SteamVRTrackerManager.cs b/AlternateIKSystem/IK/Tracking/SteamVRTrackerManager.cs new file mode 100644 index 0000000..6c0b5c1 --- /dev/null +++ b/AlternateIKSystem/IK/Tracking/SteamVRTrackerManager.cs @@ -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 trackedPoints = new Dictionary(); + 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() + { + + } + } +} \ No newline at end of file diff --git a/AlternateIKSystem/IK/WeightManipulators/BodyParts/BodyPart.cs b/AlternateIKSystem/IK/WeightManipulators/BodyParts/BodyPart.cs new file mode 100644 index 0000000..f590382 --- /dev/null +++ b/AlternateIKSystem/IK/WeightManipulators/BodyParts/BodyPart.cs @@ -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; + } +} diff --git a/AlternateIKSystem/IK/WeightManipulators/DeviceControlManipulator.cs b/AlternateIKSystem/IK/WeightManipulators/DeviceControlManipulator.cs new file mode 100644 index 0000000..e120c1e --- /dev/null +++ b/AlternateIKSystem/IK/WeightManipulators/DeviceControlManipulator.cs @@ -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; + } +} \ No newline at end of file diff --git a/AlternateIKSystem/IK/WeightManipulators/Interface/IWeightManipulator.cs b/AlternateIKSystem/IK/WeightManipulators/Interface/IWeightManipulator.cs new file mode 100644 index 0000000..7462b46 --- /dev/null +++ b/AlternateIKSystem/IK/WeightManipulators/Interface/IWeightManipulator.cs @@ -0,0 +1,9 @@ +using RootMotion.FinalIK; + +namespace NAK.AlternateIKSystem.IK.WeightManipulators.Interface; + +public interface IWeightManipulator +{ + WeightManipulatorManager Manager { get; set; } + void Update(IKSolverVR solver); +} \ No newline at end of file diff --git a/AlternateIKSystem/IK/WeightManipulators/TrackingControlManipulator.cs b/AlternateIKSystem/IK/WeightManipulators/TrackingControlManipulator.cs new file mode 100644 index 0000000..c4899f5 --- /dev/null +++ b/AlternateIKSystem/IK/WeightManipulators/TrackingControlManipulator.cs @@ -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; + } +} \ No newline at end of file diff --git a/AlternateIKSystem/IK/WeightManipulators/WeightManipulatorManager.cs b/AlternateIKSystem/IK/WeightManipulators/WeightManipulatorManager.cs new file mode 100644 index 0000000..3656222 --- /dev/null +++ b/AlternateIKSystem/IK/WeightManipulators/WeightManipulatorManager.cs @@ -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 _bodyParts = new Dictionary(); + + 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); + } +} diff --git a/AlternateIKSystem/Integrations/BTKUIAddon.cs b/AlternateIKSystem/Integrations/BTKUIAddon.cs index 24e421d..c55a8bc 100644 --- a/AlternateIKSystem/Integrations/BTKUIAddon.cs +++ b/AlternateIKSystem/Integrations/BTKUIAddon.cs @@ -43,7 +43,7 @@ public static class BTKUIAddon // Fake root heading limit AddMelonSlider(ref generalIKPage, ModSettings.EntryBodyHeadingLimit, 0, 90f, 0); - + // Lerp Speed AddMelonSlider(ref generalIKPage, ModSettings.EntryIKLerpSpeed, 0, 20f, 0); } diff --git a/NAK_CVR_Mods.sln b/NAK_CVR_Mods.sln index 04f941b..6a3ccdb 100644 --- a/NAK_CVR_Mods.sln +++ b/NAK_CVR_Mods.sln @@ -79,6 +79,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AlternateIKSystem", "Altern EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NoDepthOnlyFlat", "NoDepthOnlyFlat\NoDepthOnlyFlat.csproj", "{6F2F8774-40CF-4DE1-BC6C-DC00CA76D6A8}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ViewpointHeadScaleFix", "ViewpointHeadScaleFix\ViewpointHeadScaleFix.csproj", "{337A284D-C4AC-4B1B-B094-B6F758278BD8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -237,6 +239,10 @@ Global {6F2F8774-40CF-4DE1-BC6C-DC00CA76D6A8}.Debug|Any CPU.Build.0 = Debug|Any CPU {6F2F8774-40CF-4DE1-BC6C-DC00CA76D6A8}.Release|Any CPU.ActiveCfg = Release|Any CPU {6F2F8774-40CF-4DE1-BC6C-DC00CA76D6A8}.Release|Any CPU.Build.0 = Release|Any CPU + {337A284D-C4AC-4B1B-B094-B6F758278BD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {337A284D-C4AC-4B1B-B094-B6F758278BD8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {337A284D-C4AC-4B1B-B094-B6F758278BD8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {337A284D-C4AC-4B1B-B094-B6F758278BD8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ViewpointHeadScaleFix/Main.cs b/ViewpointHeadScaleFix/Main.cs new file mode 100644 index 0000000..c353053 --- /dev/null +++ b/ViewpointHeadScaleFix/Main.cs @@ -0,0 +1,55 @@ +using ABI_RC.Core.Player; +using ABI_RC.Core.Savior; +using MelonLoader; +using System.Reflection; +using UnityEngine; + +namespace NAK.ViewpointHeadScaleFix; + +// Makes initialCameraPos scale with head bone scale + +public class ViewpointHeadScaleFix : MelonMod +{ + public override void OnInitializeMelon() + { + HarmonyInstance.Patch( + typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.CalibrateAvatar)), + postfix: new HarmonyLib.HarmonyMethod(typeof(ViewpointHeadScaleFix).GetMethod(nameof(OnPlayerSetupCalibrateAvatar_Postfix), BindingFlags.NonPublic | BindingFlags.Static)) + ); + HarmonyInstance.Patch( + typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.SetViewPointOffset)), + prefix: new HarmonyLib.HarmonyMethod(typeof(ViewpointHeadScaleFix).GetMethod(nameof(OnPlayerSetupSetViewPointOffset_Prefix), BindingFlags.NonPublic | BindingFlags.Static)) + ); + } + + private static void OnPlayerSetupCalibrateAvatar_Postfix(ref PlayerSetup __instance) + { + if (!MetaPort.Instance.isUsingVr) + return; + + Transform headTransform = __instance._animator.GetBoneTransform(HumanBodyBones.Head); + if (headTransform == null) + return; + + _originalCameraPos = __instance.initialCameraPos; + _initialHeadScale = headTransform.localScale; + } + + private static void OnPlayerSetupSetViewPointOffset_Prefix(ref PlayerSetup __instance) + { + if (!MetaPort.Instance.isUsingVr) + return; + + Transform headTransform = __instance._animator.GetBoneTransform(HumanBodyBones.Head); + if (headTransform == null) + return; + + __instance.initialCameraPos = __instance.MultiplyVectors( + _originalCameraPos, + __instance.DivideVectors(headTransform.localScale, _initialHeadScale) + ); + } + + private static Vector3 _originalCameraPos = Vector3.one; + private static Vector3 _initialHeadScale = Vector3.one; +} \ No newline at end of file diff --git a/ViewpointHeadScaleFix/Properties/AssemblyInfo.cs b/ViewpointHeadScaleFix/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..fb76b63 --- /dev/null +++ b/ViewpointHeadScaleFix/Properties/AssemblyInfo.cs @@ -0,0 +1,32 @@ +using MelonLoader; +using NAK.ViewpointHeadScaleFix.Properties; +using System.Reflection; + +[assembly: AssemblyVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyFileVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyInformationalVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyTitle(nameof(NAK.ViewpointHeadScaleFix))] +[assembly: AssemblyCompany(AssemblyInfoParams.Author)] +[assembly: AssemblyProduct(nameof(NAK.ViewpointHeadScaleFix))] + +[assembly: MelonInfo( + typeof(NAK.ViewpointHeadScaleFix.ViewpointHeadScaleFix), + nameof(NAK.ViewpointHeadScaleFix), + AssemblyInfoParams.Version, + AssemblyInfoParams.Author, + downloadLink: "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/AvatarScale" +)] + +[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")] +[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)] +[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)] +[assembly: MelonColor(255, 241, 200, 82)] +[assembly: MelonAuthorColor(255, 114, 17, 25)] +[assembly: HarmonyDontPatchAll] + +namespace NAK.ViewpointHeadScaleFix.Properties; +internal static class AssemblyInfoParams +{ + public const string Version = "1.0.0"; + public const string Author = "NotAKidoS"; +} \ No newline at end of file diff --git a/ViewpointHeadScaleFix/ViewpointHeadScaleFix.csproj b/ViewpointHeadScaleFix/ViewpointHeadScaleFix.csproj new file mode 100644 index 0000000..66a50a8 --- /dev/null +++ b/ViewpointHeadScaleFix/ViewpointHeadScaleFix.csproj @@ -0,0 +1,2 @@ + +