mirror of
https://github.com/hanetzer/sdraw_mods_cvr.git
synced 2025-09-03 18:39:23 +00:00
Preserve crouch and prone
Code simplification and possible pose copying fix Reworked finger tracking
This commit is contained in:
parent
4608f9f7bf
commit
1efcb8aaee
19 changed files with 194 additions and 206 deletions
|
@ -67,7 +67,7 @@ namespace ml_pmc
|
|||
if(CVRPlayerManager.Instance.GetPlayerPuppetMaster(p_id, out PuppetMaster l_puppetMaster))
|
||||
{
|
||||
if(IsInSight(MovementSystem.Instance.proxyCollider, l_puppetMaster.GetComponent<CapsuleCollider>(), Utils.GetWorldMovementLimit()))
|
||||
m_localCopycat.SetTarget(l_puppetMaster.gameObject);
|
||||
m_localCopycat.SetTarget(l_puppetMaster);
|
||||
else
|
||||
ModUi.ShowAlert("Selected player is too far away or obstructed");
|
||||
}
|
||||
|
|
|
@ -122,8 +122,7 @@ namespace ml_pmc
|
|||
// Currently broken in BTKUILib, waiting for fix
|
||||
static void UpdateToggleColor(bool p_state)
|
||||
{
|
||||
//(ms_uiElements[(int)UiIndex.Toggle] as Button).ButtonIcon = (p_state ? "PMC-Dancing-On" : "PMC-Dancing");
|
||||
//(ms_uiElements[(int)UiIndex.Toggle] as Button).ButtonText = (p_state ? "PMC-Dancing-On" : "PMC-Dancing");
|
||||
(ms_uiElements[(int)UiIndex.Toggle] as Button).ButtonIcon = (p_state ? "PMC-Dancing-On" : "PMC-Dancing");
|
||||
}
|
||||
|
||||
static Stream GetIconStream(string p_name)
|
||||
|
|
|
@ -49,12 +49,12 @@ namespace ml_pmc
|
|||
{
|
||||
m_sitting = (MovementSystem.Instance.lastSeat != null);
|
||||
|
||||
if(m_active && (m_puppetParser != null))
|
||||
if(m_active)
|
||||
{
|
||||
OverrideIK();
|
||||
|
||||
if(m_puppetParser.HasAnimator())
|
||||
if(m_puppetParser != null)
|
||||
{
|
||||
OverrideIK();
|
||||
|
||||
bool l_mirror = Settings.MirrorPose;
|
||||
|
||||
if(Settings.Gestures)
|
||||
|
@ -71,6 +71,7 @@ namespace ml_pmc
|
|||
IKSystem.Instance.FingerSystem.controlActive = true;
|
||||
|
||||
ref float[] l_curls = ref m_puppetParser.GetFingerCurls();
|
||||
ref float[] l_spreads = ref m_puppetParser.GetFingerSpreads();
|
||||
|
||||
CVRInputManager.Instance.fingerCurlLeftThumb = l_curls[l_mirror ? 5 : 0];
|
||||
CVRInputManager.Instance.fingerCurlLeftIndex = l_curls[l_mirror ? 6 : 1];
|
||||
|
@ -82,6 +83,17 @@ namespace ml_pmc
|
|||
CVRInputManager.Instance.fingerCurlRightMiddle = l_curls[l_mirror ? 2 : 7];
|
||||
CVRInputManager.Instance.fingerCurlRightRing = l_curls[l_mirror ? 3 : 8];
|
||||
CVRInputManager.Instance.fingerCurlRightPinky = l_curls[l_mirror ? 4 : 9];
|
||||
|
||||
CVRInputManager.Instance.fingerSpreadLeftThumb = l_spreads[l_mirror ? 5 : 0];
|
||||
CVRInputManager.Instance.fingerSpreadLeftIndex = l_spreads[l_mirror ? 6 : 1];
|
||||
CVRInputManager.Instance.fingerSpreadLeftMiddle = l_spreads[l_mirror ? 7 : 2];
|
||||
CVRInputManager.Instance.fingerSpreadLeftRing = l_spreads[l_mirror ? 8 : 3];
|
||||
CVRInputManager.Instance.fingerSpreadLeftPinky = l_spreads[l_mirror ? 9 : 4];
|
||||
CVRInputManager.Instance.fingerSpreadRightThumb = l_spreads[l_mirror ? 0 : 5];
|
||||
CVRInputManager.Instance.fingerSpreadRightIndex = l_spreads[l_mirror ? 1 : 6];
|
||||
CVRInputManager.Instance.fingerSpreadRightMiddle = l_spreads[l_mirror ? 2 : 7];
|
||||
CVRInputManager.Instance.fingerSpreadRightRing = l_spreads[l_mirror ? 3 : 8];
|
||||
CVRInputManager.Instance.fingerSpreadRightPinky = l_spreads[l_mirror ? 4 : 9];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -92,7 +104,7 @@ namespace ml_pmc
|
|||
}
|
||||
}
|
||||
|
||||
Matrix4x4 l_offset = m_puppetParser.GetOffset();
|
||||
Matrix4x4 l_offset = m_puppetParser.GetLastOffset();
|
||||
Vector3 l_pos = l_offset * ms_pointVector;
|
||||
Quaternion l_rot = l_offset.rotation;
|
||||
|
||||
|
@ -120,27 +132,26 @@ namespace ml_pmc
|
|||
else
|
||||
PlayerSetup.Instance.transform.rotation = l_result.rotation;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!m_puppetParser.IsWaitingAnimator())
|
||||
|
||||
if(Vector3.Distance(this.transform.position, m_puppetParser.transform.position) > m_distanceLimit)
|
||||
SetTarget(null);
|
||||
}
|
||||
|
||||
if(Vector3.Distance(this.transform.position, m_puppetParser.transform.position) > m_distanceLimit)
|
||||
else
|
||||
SetTarget(null);
|
||||
}
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
if(m_active && (m_animator != null) && (m_puppetParser != null) && m_puppetParser.IsPoseParsed())
|
||||
if(m_active && (m_animator != null) && (m_puppetParser != null))
|
||||
{
|
||||
OverrideIK();
|
||||
|
||||
m_puppetParser.GetPose().CopyTo(ref m_pose);
|
||||
|
||||
if(Settings.MirrorPose)
|
||||
Utils.MirrorPose(ref m_pose);
|
||||
|
||||
m_poseHandler.SetHumanPose(ref m_pose);
|
||||
}
|
||||
}
|
||||
|
@ -160,7 +171,11 @@ namespace ml_pmc
|
|||
|
||||
m_poseHandler?.Dispose();
|
||||
m_poseHandler = null;
|
||||
|
||||
if(m_active)
|
||||
OnActivityChange?.Invoke(false);
|
||||
m_active = false;
|
||||
|
||||
m_distanceLimit = float.MaxValue;
|
||||
m_fingerTracking = false;
|
||||
m_pose = new HumanPose();
|
||||
|
@ -222,15 +237,16 @@ namespace ml_pmc
|
|||
}
|
||||
|
||||
// Arbitrary
|
||||
public void SetTarget(GameObject p_target)
|
||||
public void SetTarget(PuppetMaster p_target)
|
||||
{
|
||||
if(m_animator != null)
|
||||
{
|
||||
if(!m_active)
|
||||
{
|
||||
if(p_target != null)
|
||||
if((p_target != null) && (p_target.animatorManager != null) && (p_target.animatorManager.animator != null) && p_target.animatorManager.animator.isHuman)
|
||||
{
|
||||
m_puppetParser = p_target.AddComponent<PuppetParser>();
|
||||
m_puppetParser = p_target.animatorManager.animator.gameObject.AddComponent<PuppetParser>();
|
||||
m_puppetParser.m_puppetMaster = p_target;
|
||||
m_distanceLimit = Utils.GetWorldMovementLimit();
|
||||
|
||||
m_active = true;
|
||||
|
@ -295,6 +311,17 @@ namespace ml_pmc
|
|||
CVRInputManager.Instance.fingerCurlRightMiddle = 0f;
|
||||
CVRInputManager.Instance.fingerCurlRightRing = 0f;
|
||||
CVRInputManager.Instance.fingerCurlRightPinky = 0f;
|
||||
|
||||
CVRInputManager.Instance.fingerSpreadLeftThumb = 0.5f;
|
||||
CVRInputManager.Instance.fingerSpreadLeftIndex = 0.5f;
|
||||
CVRInputManager.Instance.fingerSpreadLeftMiddle = 0.5f;
|
||||
CVRInputManager.Instance.fingerSpreadLeftRing = 0.5f;
|
||||
CVRInputManager.Instance.fingerSpreadLeftPinky = 0.5f;
|
||||
CVRInputManager.Instance.fingerSpreadRightThumb = 0.5f;
|
||||
CVRInputManager.Instance.fingerSpreadRightIndex = 0.5f;
|
||||
CVRInputManager.Instance.fingerSpreadRightMiddle = 0.5f;
|
||||
CVRInputManager.Instance.fingerSpreadRightRing = 0.5f;
|
||||
CVRInputManager.Instance.fingerSpreadRightPinky = 0.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using System.Reflection;
|
||||
|
||||
[assembly: MelonLoader.MelonInfo(typeof(ml_pmc.PlayerMovementCopycat), "PlayerMovementCopycat", "1.0.1", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
|
||||
[assembly: MelonLoader.MelonInfo(typeof(ml_pmc.PlayerMovementCopycat), "PlayerMovementCopycat", "1.0.2", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
|
||||
[assembly: MelonLoader.MelonGame(null, "ChilloutVR")]
|
||||
[assembly: MelonLoader.MelonPriority(3)]
|
||||
[assembly: MelonLoader.MelonAdditionalDependencies("BTKUILib")]
|
||||
|
|
|
@ -6,18 +6,12 @@ namespace ml_pmc
|
|||
[DisallowMultipleComponent]
|
||||
class PuppetParser : MonoBehaviour
|
||||
{
|
||||
static readonly Vector4 ms_pointVector = new Vector4(0f, 0f, 0f, 1f);
|
||||
|
||||
PuppetMaster m_puppetMaster = null;
|
||||
internal PuppetMaster m_puppetMaster = null;
|
||||
Animator m_animator = null;
|
||||
AnimatorCullingMode m_cullMode;
|
||||
float m_armatureScale = 1f;
|
||||
float m_armatureHeight = 0f;
|
||||
|
||||
bool m_waitAnimator = true;
|
||||
HumanPoseHandler m_poseHandler = null;
|
||||
HumanPose m_pose;
|
||||
bool m_poseParsed = false;
|
||||
|
||||
Matrix4x4 m_matrix = Matrix4x4.identity;
|
||||
Matrix4x4 m_offset = Matrix4x4.identity;
|
||||
|
@ -27,26 +21,34 @@ namespace ml_pmc
|
|||
float m_rightGesture = 0f;
|
||||
bool m_fingerTracking = false;
|
||||
float[] m_fingerCurls = null;
|
||||
float[] m_fingerSpreads = null;
|
||||
|
||||
internal PuppetParser()
|
||||
{
|
||||
m_fingerCurls = new float[10];
|
||||
m_fingerSpreads = new float[10];
|
||||
}
|
||||
|
||||
// Unity events
|
||||
void Start()
|
||||
{
|
||||
m_puppetMaster = this.GetComponent<PuppetMaster>();
|
||||
m_animator = this.GetComponent<Animator>();
|
||||
m_cullMode = m_animator.cullingMode;
|
||||
m_animator.cullingMode = AnimatorCullingMode.AlwaysAnimate;
|
||||
m_poseHandler = new HumanPoseHandler(m_animator.avatar, m_animator.transform);
|
||||
m_poseHandler.GetHumanPose(ref m_pose);
|
||||
m_matrix = this.transform.GetMatrix();
|
||||
StartCoroutine(WaitForAnimator());
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
m_puppetMaster = null;
|
||||
if(m_animator != null)
|
||||
m_animator.cullingMode = m_cullMode;
|
||||
m_animator = null;
|
||||
|
||||
m_poseHandler?.Dispose();
|
||||
m_poseHandler = null;
|
||||
}
|
||||
|
||||
void Update()
|
||||
|
@ -69,88 +71,38 @@ namespace ml_pmc
|
|||
m_fingerCurls[7] = m_puppetMaster.PlayerAvatarMovementDataInput.RightMiddleCurl;
|
||||
m_fingerCurls[8] = m_puppetMaster.PlayerAvatarMovementDataInput.RightRingCurl;
|
||||
m_fingerCurls[9] = m_puppetMaster.PlayerAvatarMovementDataInput.RightPinkyCurl;
|
||||
}
|
||||
}
|
||||
|
||||
if(!ReferenceEquals(m_animator, null))
|
||||
{
|
||||
if(m_animator != null)
|
||||
{
|
||||
Matrix4x4 l_current = this.transform.GetMatrix();
|
||||
m_offset = m_matrix.inverse * l_current;
|
||||
m_matrix = l_current;
|
||||
m_fingerSpreads[0] = m_puppetMaster.PlayerAvatarMovementDataInput.LeftThumbSpread;
|
||||
m_fingerSpreads[1] = m_puppetMaster.PlayerAvatarMovementDataInput.LeftIndexSpread;
|
||||
m_fingerSpreads[2] = m_puppetMaster.PlayerAvatarMovementDataInput.LeftMiddleSpread;
|
||||
m_fingerSpreads[3] = m_puppetMaster.PlayerAvatarMovementDataInput.LeftRingSpread;
|
||||
m_fingerSpreads[4] = m_puppetMaster.PlayerAvatarMovementDataInput.LeftPinkySpread;
|
||||
m_fingerSpreads[5] = m_puppetMaster.PlayerAvatarMovementDataInput.RightThumbSpread;
|
||||
m_fingerSpreads[6] = m_puppetMaster.PlayerAvatarMovementDataInput.RightIndexSpread;
|
||||
m_fingerSpreads[7] = m_puppetMaster.PlayerAvatarMovementDataInput.RightMiddleSpread;
|
||||
m_fingerSpreads[8] = m_puppetMaster.PlayerAvatarMovementDataInput.RightRingSpread;
|
||||
m_fingerSpreads[9] = m_puppetMaster.PlayerAvatarMovementDataInput.RightPinkySpread;
|
||||
}
|
||||
else
|
||||
Reset();
|
||||
|
||||
Matrix4x4 l_current = this.transform.GetMatrix();
|
||||
m_offset = m_matrix.inverse * l_current;
|
||||
m_matrix = l_current;
|
||||
}
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
if(m_animator != null)
|
||||
{
|
||||
if((m_animator != null) && (m_poseHandler != null))
|
||||
m_poseHandler.GetHumanPose(ref m_pose);
|
||||
m_pose.bodyPosition *= m_armatureScale;
|
||||
m_pose.bodyPosition.y += m_armatureHeight;
|
||||
m_poseParsed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Arbitrary
|
||||
System.Collections.IEnumerator WaitForAnimator()
|
||||
{
|
||||
while(m_puppetMaster.avatarObject == null)
|
||||
yield return null;
|
||||
|
||||
while(m_animator == null)
|
||||
{
|
||||
m_animator = m_puppetMaster.avatarObject.GetComponent<Animator>();
|
||||
yield return null;
|
||||
}
|
||||
|
||||
if(m_animator.isHuman)
|
||||
{
|
||||
m_cullMode = m_animator.cullingMode;
|
||||
m_animator.cullingMode = AnimatorCullingMode.AlwaysAnimate;
|
||||
|
||||
Transform l_hips = m_animator.GetBoneTransform(HumanBodyBones.Hips);
|
||||
if((l_hips != null) && (l_hips.parent != null))
|
||||
{
|
||||
m_armatureScale = l_hips.parent.localScale.y;
|
||||
m_armatureHeight = ((m_puppetMaster.transform.GetMatrix().inverse * l_hips.parent.GetMatrix()) * ms_pointVector).y;
|
||||
}
|
||||
|
||||
m_poseHandler = new HumanPoseHandler(m_animator.avatar, m_animator.transform);
|
||||
m_matrix = this.transform.GetMatrix();
|
||||
}
|
||||
else
|
||||
Reset();
|
||||
|
||||
m_waitAnimator = false;
|
||||
}
|
||||
|
||||
void Reset()
|
||||
{
|
||||
m_animator = null;
|
||||
m_poseHandler?.Dispose();
|
||||
m_poseHandler = null;
|
||||
m_pose = new HumanPose();
|
||||
m_poseParsed = false;
|
||||
m_offset = Matrix4x4.identity;
|
||||
m_sitting = false;
|
||||
m_leftGesture = 0f;
|
||||
m_rightGesture = 0f;
|
||||
}
|
||||
|
||||
public bool IsWaitingAnimator() => m_waitAnimator;
|
||||
public bool HasAnimator() => !ReferenceEquals(m_animator, null);
|
||||
public ref HumanPose GetPose() => ref m_pose;
|
||||
public bool IsPoseParsed() => m_poseParsed;
|
||||
public ref Matrix4x4 GetOffset() => ref m_offset;
|
||||
public ref Matrix4x4 GetLastOffset() => ref m_offset;
|
||||
public bool IsSitting() => m_sitting;
|
||||
public float GetLeftGesture() => m_leftGesture;
|
||||
public float GetRightGesture() => m_rightGesture;
|
||||
public bool HasFingerTracking() => m_fingerTracking;
|
||||
public ref float[] GetFingerCurls() => ref m_fingerCurls;
|
||||
public ref float[] GetFingerSpreads() => ref m_fingerSpreads;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<Authors>SDraw</Authors>
|
||||
<Company>None</Company>
|
||||
<Product>PlayerMovementCopycat</Product>
|
||||
<Version>1.0.1</Version>
|
||||
<Version>1.0.2</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue