mirror of
https://github.com/hanetzer/sdraw_mods_cvr.git
synced 2025-09-05 11:29:23 +00:00
Rework of IK override
This commit is contained in:
parent
4e3d5dd6d4
commit
49b72a0711
5 changed files with 158 additions and 30 deletions
|
@ -13,6 +13,7 @@ namespace ml_amt
|
||||||
ms_instance = this;
|
ms_instance = this;
|
||||||
|
|
||||||
Settings.Init();
|
Settings.Init();
|
||||||
|
Settings.IKOverrideChange += this.OnIKOverrideChange;
|
||||||
Settings.CrouchLimitChange += this.OnCrouchLimitChange;
|
Settings.CrouchLimitChange += this.OnCrouchLimitChange;
|
||||||
|
|
||||||
HarmonyInstance.Patch(
|
HarmonyInstance.Patch(
|
||||||
|
@ -35,8 +36,16 @@ namespace ml_amt
|
||||||
yield return null;
|
yield return null;
|
||||||
|
|
||||||
m_localTweaker = PlayerSetup.Instance.gameObject.AddComponent<MotionTweaker>();
|
m_localTweaker = PlayerSetup.Instance.gameObject.AddComponent<MotionTweaker>();
|
||||||
|
m_localTweaker.SetIKOverride(Settings.IKOverride);
|
||||||
|
m_localTweaker.SetCrouchLimit(Settings.CrouchLimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void OnIKOverrideChange(bool p_state)
|
||||||
|
{
|
||||||
|
if(m_localTweaker != null)
|
||||||
|
m_localTweaker.SetIKOverride(p_state);
|
||||||
|
}
|
||||||
void OnCrouchLimitChange(float p_value)
|
void OnCrouchLimitChange(float p_value)
|
||||||
{
|
{
|
||||||
if(m_localTweaker != null)
|
if(m_localTweaker != null)
|
||||||
|
|
|
@ -27,18 +27,27 @@ namespace ml_amt
|
||||||
public int m_hash; // For local only
|
public int m_hash; // For local only
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum PoseState
|
||||||
|
{
|
||||||
|
Standing = 0,
|
||||||
|
Crouching,
|
||||||
|
Proning
|
||||||
|
}
|
||||||
|
|
||||||
static readonly Vector4 ms_pointVector = new Vector4(0f, 0f, 0f, 1f);
|
static readonly Vector4 ms_pointVector = new Vector4(0f, 0f, 0f, 1f);
|
||||||
|
|
||||||
CVR_IK_Calibrator m_ikCalibrator = null;
|
|
||||||
VRIK m_vrIk = null;
|
VRIK m_vrIk = null;
|
||||||
|
float m_locomotionWeight = 1f; // Original weight
|
||||||
|
|
||||||
bool m_ready = false;
|
bool m_avatarReady = false;
|
||||||
|
|
||||||
bool m_standing = true;
|
bool m_ikOverride = true;
|
||||||
float m_currentUpright = 1f;
|
float m_currentUpright = 1f;
|
||||||
float m_locomotionWeight = 1f;
|
PoseState m_poseState = PoseState.Standing;
|
||||||
|
|
||||||
float m_crouchLimit = 0.65f;
|
float m_crouchLimit = 0.65f;
|
||||||
bool m_customCrouchLimit = false;
|
bool m_customCrouchLimit = false;
|
||||||
|
float m_proneLimit = 0.3f; // Unused
|
||||||
|
|
||||||
bool m_customLocomotionOffset = false;
|
bool m_customLocomotionOffset = false;
|
||||||
Vector3 m_locomotionOffset = Vector3.zero;
|
Vector3 m_locomotionOffset = Vector3.zero;
|
||||||
|
@ -50,32 +59,24 @@ namespace ml_amt
|
||||||
m_parameters = new List<AdditionalParameterInfo>();
|
m_parameters = new List<AdditionalParameterInfo>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Start()
|
|
||||||
{
|
|
||||||
m_ikCalibrator = this.GetComponent<CVR_IK_Calibrator>();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
if(m_ready)
|
if(m_avatarReady)
|
||||||
{
|
{
|
||||||
// Update upright
|
// Update upright
|
||||||
Matrix4x4 l_hmdMatrix = PlayerSetup.Instance.transform.GetMatrix().inverse * (PlayerSetup.Instance._inVr ? PlayerSetup.Instance.vrHeadTracker.transform.GetMatrix() : PlayerSetup.Instance.desktopCameraRig.transform.GetMatrix());
|
Matrix4x4 l_hmdMatrix = PlayerSetup.Instance.transform.GetMatrix().inverse * (PlayerSetup.Instance._inVr ? PlayerSetup.Instance.vrHeadTracker.transform.GetMatrix() : PlayerSetup.Instance.desktopCameraRig.transform.GetMatrix());
|
||||||
float l_currentHeight = Mathf.Clamp((l_hmdMatrix * ms_pointVector).y, 0f, float.MaxValue);
|
float l_currentHeight = Mathf.Clamp((l_hmdMatrix * ms_pointVector).y, 0f, float.MaxValue);
|
||||||
float l_avatarViewHeight = Mathf.Clamp(PlayerSetup.Instance.GetViewPointHeight() * PlayerSetup.Instance._avatar.transform.localScale.y, 0f, float.MaxValue);
|
float l_avatarViewHeight = Mathf.Clamp(PlayerSetup.Instance.GetViewPointHeight() * PlayerSetup.Instance._avatar.transform.localScale.y, 0f, float.MaxValue);
|
||||||
m_currentUpright = Mathf.Clamp((((l_currentHeight > 0f) && (l_avatarViewHeight > 0f)) ? (l_currentHeight / l_avatarViewHeight) : 0f), 0f, 1f);
|
m_currentUpright = Mathf.Clamp((((l_currentHeight > 0f) && (l_avatarViewHeight > 0f)) ? (l_currentHeight / l_avatarViewHeight) : 0f), 0f, 1f);
|
||||||
bool l_standing = (m_currentUpright > m_crouchLimit);
|
PoseState l_poseState = (m_currentUpright <= m_proneLimit) ? PoseState.Proning : ((m_currentUpright <= m_crouchLimit) ? PoseState.Crouching : PoseState.Standing);
|
||||||
|
|
||||||
if(!m_ikCalibrator.avatarCalibratedAsFullBody && (m_vrIk != null) && m_vrIk.enabled && !PlayerSetup.Instance._movementSystem.sitting && (PlayerSetup.Instance._movementSystem.movementVector.magnitude <= Mathf.Epsilon))
|
if(m_ikOverride && (m_vrIk != null) && m_vrIk.enabled)
|
||||||
{
|
{
|
||||||
m_locomotionWeight = Mathf.Lerp(m_locomotionWeight, l_standing ? 1f : 0f, 0.5f);
|
if((m_poseState != l_poseState) && (l_poseState == PoseState.Standing))
|
||||||
m_vrIk.solver.locomotion.weight = m_locomotionWeight;
|
|
||||||
|
|
||||||
if(l_standing && (m_standing != l_standing))
|
|
||||||
ms_rootVelocity.SetValue(m_vrIk.solver, Vector3.zero);
|
ms_rootVelocity.SetValue(m_vrIk.solver, Vector3.zero);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_standing = l_standing;
|
m_poseState = l_poseState;
|
||||||
|
|
||||||
if(m_parameters.Count > 0)
|
if(m_parameters.Count > 0)
|
||||||
{
|
{
|
||||||
|
@ -104,12 +105,10 @@ namespace ml_amt
|
||||||
|
|
||||||
public void OnAvatarClear()
|
public void OnAvatarClear()
|
||||||
{
|
{
|
||||||
m_ready = false;
|
m_avatarReady = false;
|
||||||
m_vrIk = null;
|
m_vrIk = null;
|
||||||
m_standing = true;
|
m_poseState = PoseState.Standing;
|
||||||
m_parameters.Clear();
|
m_parameters.Clear();
|
||||||
m_locomotionWeight = 1f;
|
|
||||||
m_crouchLimit = 0.65f;
|
|
||||||
m_customCrouchLimit = false;
|
m_customCrouchLimit = false;
|
||||||
m_customLocomotionOffset = false;
|
m_customLocomotionOffset = false;
|
||||||
m_locomotionOffset = Vector3.zero;
|
m_locomotionOffset = Vector3.zero;
|
||||||
|
@ -155,11 +154,20 @@ namespace ml_amt
|
||||||
// Apply VRIK tweaks
|
// Apply VRIK tweaks
|
||||||
if(m_vrIk != null)
|
if(m_vrIk != null)
|
||||||
{
|
{
|
||||||
if(m_customLocomotionOffset && (m_vrIk.solver?.locomotion != null))
|
if(m_customLocomotionOffset)
|
||||||
m_vrIk.solver.locomotion.offset = m_locomotionOffset;
|
m_vrIk.solver.locomotion.offset = m_locomotionOffset;
|
||||||
|
|
||||||
|
m_vrIk.solver.OnPreUpdate += this.OnIKPreUpdate;
|
||||||
|
m_vrIk.solver.OnPostUpdate += this.OnIKPostUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_ready = true;
|
m_avatarReady = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void SetIKOverride(bool p_state)
|
||||||
|
{
|
||||||
|
m_ikOverride = p_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetCrouchLimit(float p_value)
|
public void SetCrouchLimit(float p_value)
|
||||||
|
@ -167,5 +175,26 @@ namespace ml_amt
|
||||||
if(!m_customCrouchLimit)
|
if(!m_customCrouchLimit)
|
||||||
m_crouchLimit = Mathf.Clamp(p_value, 0f, 1f);
|
m_crouchLimit = Mathf.Clamp(p_value, 0f, 1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetProneLimit(float p_value)
|
||||||
|
{
|
||||||
|
m_proneLimit = Mathf.Clamp(p_value, 0f, 1f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnIKPreUpdate()
|
||||||
|
{
|
||||||
|
if(m_ikOverride)
|
||||||
|
{
|
||||||
|
m_locomotionWeight = m_vrIk.solver.locomotion.weight;
|
||||||
|
if(m_poseState != PoseState.Standing)
|
||||||
|
m_vrIk.solver.locomotion.weight = 0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnIKPostUpdate()
|
||||||
|
{
|
||||||
|
if(m_ikOverride)
|
||||||
|
m_vrIk.solver.locomotion.weight = m_locomotionWeight;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
[assembly: AssemblyTitle("AvatarMotionTweaker")]
|
[assembly: AssemblyTitle("AvatarMotionTweaker")]
|
||||||
[assembly: AssemblyVersion("1.0.6")]
|
[assembly: AssemblyVersion("1.0.7")]
|
||||||
[assembly: AssemblyFileVersion("1.0.6")]
|
[assembly: AssemblyFileVersion("1.0.7")]
|
||||||
|
|
||||||
[assembly: MelonLoader.MelonInfo(typeof(ml_amt.AvatarMotionTweaker), "AvatarMotionTweaker", "1.0.6", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
|
[assembly: MelonLoader.MelonInfo(typeof(ml_amt.AvatarMotionTweaker), "AvatarMotionTweaker", "1.0.7", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
|
||||||
[assembly: MelonLoader.MelonGame(null, "ChilloutVR")]
|
[assembly: MelonLoader.MelonGame(null, "ChilloutVR")]
|
||||||
[assembly: MelonLoader.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
|
[assembly: MelonLoader.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
|
||||||
[assembly: MelonLoader.MelonPlatformDomain(MelonLoader.MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
|
[assembly: MelonLoader.MelonPlatformDomain(MelonLoader.MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
|
|
@ -2,7 +2,6 @@
|
||||||
using cohtml;
|
using cohtml;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace ml_amt
|
namespace ml_amt
|
||||||
{
|
{
|
||||||
|
@ -10,14 +9,17 @@ namespace ml_amt
|
||||||
{
|
{
|
||||||
enum ModSetting
|
enum ModSetting
|
||||||
{
|
{
|
||||||
CrouchLimit = 0
|
IKOverride = 0,
|
||||||
|
CrouchLimit
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static bool ms_ikOverride = true;
|
||||||
static float ms_crouchLimit = 0.65f;
|
static float ms_crouchLimit = 0.65f;
|
||||||
|
|
||||||
static MelonLoader.MelonPreferences_Category ms_category = null;
|
static MelonLoader.MelonPreferences_Category ms_category = null;
|
||||||
static List<MelonLoader.MelonPreferences_Entry> ms_entries = null;
|
static List<MelonLoader.MelonPreferences_Entry> ms_entries = null;
|
||||||
|
|
||||||
|
static public event Action<bool> IKOverrideChange;
|
||||||
static public event Action<float> CrouchLimitChange;
|
static public event Action<float> CrouchLimitChange;
|
||||||
|
|
||||||
public static void Init()
|
public static void Init()
|
||||||
|
@ -25,6 +27,7 @@ namespace ml_amt
|
||||||
ms_category = MelonLoader.MelonPreferences.CreateCategory("AMT");
|
ms_category = MelonLoader.MelonPreferences.CreateCategory("AMT");
|
||||||
|
|
||||||
ms_entries = new List<MelonLoader.MelonPreferences_Entry>();
|
ms_entries = new List<MelonLoader.MelonPreferences_Entry>();
|
||||||
|
ms_entries.Add(ms_category.CreateEntry(ModSetting.IKOverride.ToString(), true));
|
||||||
ms_entries.Add(ms_category.CreateEntry(ModSetting.CrouchLimit.ToString(), 65));
|
ms_entries.Add(ms_category.CreateEntry(ModSetting.CrouchLimit.ToString(), 65));
|
||||||
|
|
||||||
Load();
|
Load();
|
||||||
|
@ -44,6 +47,7 @@ namespace ml_amt
|
||||||
ViewManager.Instance.gameMenuView.Listener.ReadyForBindings += () =>
|
ViewManager.Instance.gameMenuView.Listener.ReadyForBindings += () =>
|
||||||
{
|
{
|
||||||
ViewManager.Instance.gameMenuView.View.BindCall("MelonMod_AMT_Call_InpSlider", new Action<string, string>(OnSliderUpdate));
|
ViewManager.Instance.gameMenuView.View.BindCall("MelonMod_AMT_Call_InpSlider", new Action<string, string>(OnSliderUpdate));
|
||||||
|
ViewManager.Instance.gameMenuView.View.BindCall("MelonMod_AMT_Call_InpToggle", new Action<string, string>(OnToggleUpdate));
|
||||||
};
|
};
|
||||||
ViewManager.Instance.gameMenuView.Listener.FinishLoad += (_) =>
|
ViewManager.Instance.gameMenuView.Listener.FinishLoad += (_) =>
|
||||||
{
|
{
|
||||||
|
@ -55,6 +59,7 @@ namespace ml_amt
|
||||||
|
|
||||||
static void Load()
|
static void Load()
|
||||||
{
|
{
|
||||||
|
ms_ikOverride = (bool)ms_entries[(int)ModSetting.IKOverride].BoxedValue;
|
||||||
ms_crouchLimit = ((int)ms_entries[(int)ModSetting.CrouchLimit].BoxedValue) * 0.01f;
|
ms_crouchLimit = ((int)ms_entries[(int)ModSetting.CrouchLimit].BoxedValue) * 0.01f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,18 +71,42 @@ namespace ml_amt
|
||||||
{
|
{
|
||||||
case ModSetting.CrouchLimit:
|
case ModSetting.CrouchLimit:
|
||||||
{
|
{
|
||||||
ms_crouchLimit = ((int)ms_entries[(int)ModSetting.CrouchLimit].BoxedValue) * 0.01f;
|
ms_crouchLimit = int.Parse(p_value) * 0.01f;
|
||||||
CrouchLimitChange?.Invoke(ms_crouchLimit);
|
CrouchLimitChange?.Invoke(ms_crouchLimit);
|
||||||
} break;
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ms_entries[(int)l_setting].BoxedValue = int.Parse(p_value);
|
ms_entries[(int)l_setting].BoxedValue = int.Parse(p_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void OnToggleUpdate(string p_name, string p_value)
|
||||||
|
{
|
||||||
|
if(Enum.TryParse(p_name, out ModSetting l_setting))
|
||||||
|
{
|
||||||
|
switch(l_setting)
|
||||||
|
{
|
||||||
|
case ModSetting.IKOverride:
|
||||||
|
{
|
||||||
|
ms_ikOverride = bool.Parse(p_value);
|
||||||
|
IKOverrideChange?.Invoke(ms_ikOverride);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ms_entries[(int)l_setting].BoxedValue = bool.Parse(p_value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static float CrouchLimit
|
public static float CrouchLimit
|
||||||
{
|
{
|
||||||
get => ms_crouchLimit;
|
get => ms_crouchLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IKOverride
|
||||||
|
{
|
||||||
|
get => ms_ikOverride;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,6 +123,54 @@ function inp_slider_mod_amt(_obj, _callbackName) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Modified from original `inp` types, because I have no js knowledge to hook stuff
|
||||||
|
function inp_toggle_mod_amt(_obj, _callbackName) {
|
||||||
|
this.obj = _obj;
|
||||||
|
this.callbackName = _callbackName;
|
||||||
|
this.value = _obj.getAttribute('data-current');
|
||||||
|
this.name = _obj.id;
|
||||||
|
this.type = _obj.getAttribute('data-type');
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
this.mouseDown = function (_e) {
|
||||||
|
self.value = self.value == "True" ? "False" : "True";
|
||||||
|
self.updateState();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.updateState = function () {
|
||||||
|
self.obj.classList.remove("checked");
|
||||||
|
if (self.value == "True") {
|
||||||
|
self.obj.classList.add("checked");
|
||||||
|
}
|
||||||
|
|
||||||
|
engine.call(self.callbackName, self.name, self.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
_obj.addEventListener('mousedown', this.mouseDown);
|
||||||
|
|
||||||
|
this.getValue = function () {
|
||||||
|
return self.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.updateValue = function (value) {
|
||||||
|
self.value = value;
|
||||||
|
|
||||||
|
self.obj.classList.remove("checked");
|
||||||
|
if (self.value == "True") {
|
||||||
|
self.obj.classList.add("checked");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.updateValue(this.value);
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: this.name,
|
||||||
|
value: this.getValue,
|
||||||
|
updateValue: this.updateValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add own menu
|
// Add own menu
|
||||||
{
|
{
|
||||||
let l_block = document.createElement('div');
|
let l_block = document.createElement('div');
|
||||||
|
@ -132,6 +180,13 @@ function inp_slider_mod_amt(_obj, _callbackName) {
|
||||||
<div class ="subcategory-description"></div>
|
<div class ="subcategory-description"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class ="row-wrapper">
|
||||||
|
<div class ="option-caption">IK override: </div>
|
||||||
|
<div class ="option-input">
|
||||||
|
<div id="IKOverride" class ="inp_toggle no-scroll" data-current="true"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class ="row-wrapper">
|
<div class ="row-wrapper">
|
||||||
<div class ="option-caption">Legs locomotion upright limit: </div>
|
<div class ="option-caption">Legs locomotion upright limit: </div>
|
||||||
<div class ="option-input">
|
<div class ="option-input">
|
||||||
|
@ -146,4 +201,10 @@ function inp_slider_mod_amt(_obj, _callbackName) {
|
||||||
for (var i = 0; i < l_sliders.length; i++) {
|
for (var i = 0; i < l_sliders.length; i++) {
|
||||||
g_modSettingsAMT[g_modSettingsAMT.length] = new inp_slider_mod_amt(l_sliders[i], 'MelonMod_AMT_Call_InpSlider');
|
g_modSettingsAMT[g_modSettingsAMT.length] = new inp_slider_mod_amt(l_sliders[i], 'MelonMod_AMT_Call_InpSlider');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update toggles in new menu block
|
||||||
|
let l_toggles = l_block.querySelectorAll('.inp_toggle');
|
||||||
|
for (var i = 0; i < l_toggles.length; i++) {
|
||||||
|
g_modSettingsAMT[g_modSettingsAMT.length] = new inp_toggle_mod_amt(l_toggles[i], 'MelonMod_AMT_Call_InpToggle');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue