From 43edc40b5321c98a9640c74f1775f3b948e73a17 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Tue, 19 Sep 2023 21:15:29 +0200 Subject: [PATCH] Fix unstable humanoid pose when using pose and simpleSpineIK --- .../HumanoidControl/HumanoidControl_Editor.cs | 1 + .../Targets/FootTarget_Editor.cs | 51 ++++++++++--------- .../Targets/HandTarget_Editor.cs | 5 +- .../Targets/HeadTarget_Editor.cs | 7 +-- .../Targets/HipsTarget_Editor.cs | 5 +- .../Scripts/HumanoidControl.cs | 2 +- 6 files changed, 38 insertions(+), 33 deletions(-) diff --git a/Editor/HumanoidControl/HumanoidControl_Editor.cs b/Editor/HumanoidControl/HumanoidControl_Editor.cs index 0711efb..6d7b0cc 100644 --- a/Editor/HumanoidControl/HumanoidControl_Editor.cs +++ b/Editor/HumanoidControl/HumanoidControl_Editor.cs @@ -855,6 +855,7 @@ namespace Passer { else { humanoid.pose.Show(humanoid); humanoid.CopyRigToTargets(); + humanoid.MatchTargetsToAvatar(); } } diff --git a/Editor/HumanoidControl/Targets/FootTarget_Editor.cs b/Editor/HumanoidControl/Targets/FootTarget_Editor.cs index bfab7f9..72d6880 100644 --- a/Editor/HumanoidControl/Targets/FootTarget_Editor.cs +++ b/Editor/HumanoidControl/Targets/FootTarget_Editor.cs @@ -63,9 +63,9 @@ namespace Passer { }; } -#endregion + #endregion -#region Disable + #region Disable public void OnDisable() { if (humanoid == null) { // This target is not connected to a humanoid, so we delete it @@ -82,9 +82,9 @@ namespace Passer { foreach (TargetProps props in allProps) props.SetSensor2Target(); } -#endregion + #endregion -#region Inspector + #region Inspector public override void OnInspectorGUI() { if (footTarget == null || humanoid == null) return; @@ -142,7 +142,7 @@ namespace Passer { return foundHumanoid; } -#region Sensors + #region Sensors private static bool showControllers = true; private void ControllerInspectors(FootTarget footTarget) { showControllers = EditorGUILayout.Foldout(showControllers, "Controllers", true); @@ -157,9 +157,9 @@ namespace Passer { EditorGUI.indentLevel--; } } -#endregion + #endregion -#region Configuration + #region Configuration private void InitConfiguration(FootTarget footTarget) { if (footTarget.humanoid.avatarRig == null) return; @@ -200,7 +200,7 @@ namespace Passer { UpdateToesBones(target.toes); } -#region UpperLeg + #region UpperLeg //private string upperLegXname; //private SerializedProperty upperLegMinX; //private SerializedProperty upperLegMaxX; @@ -276,9 +276,9 @@ namespace Passer { //upperLeg.bone.maxAngles.z = upperLegMaxZ.floatValue; } -#endregion + #endregion -#region LowerLeg + #region LowerLeg //private string lowerLegYname; //private SerializedProperty lowerLegMinX; //private SerializedProperty lowerLegMaxX; @@ -326,9 +326,9 @@ namespace Passer { //lowerLeg.bone.minAngles.x = lowerLegMinX.floatValue; //lowerLeg.bone.maxAngles.x = lowerLegMaxX.floatValue; } -#endregion + #endregion -#region Foot + #region Foot //private string footXname; //private SerializedProperty footMinX; //private SerializedProperty footMaxX; @@ -390,9 +390,9 @@ namespace Passer { //foot.bone.minAngles.z = footMinZ.floatValue; //foot.bone.maxAngles.z = footMaxZ.floatValue; } -#endregion + #endregion -#region Toes + #region Toes //private string toesXname; //private SerializedProperty toesMinX; //private SerializedProperty toesMaxX; @@ -441,10 +441,10 @@ namespace Passer { //toes.bone.maxAngles.x = toesMaxX.floatValue; } -#endregion -#endregion + #endregion + #endregion -#region Settings + #region Settings private SerializedProperty rotationSpeedLimitationProp; private SerializedProperty slidePreventionProp; @@ -470,9 +470,9 @@ namespace Passer { EditorGUI.indentLevel--; } } -#endregion + #endregion -#region Events + #region Events protected SerializedProperty groundEventProp; @@ -534,11 +534,11 @@ namespace Passer { // } //} -#endregion + #endregion -#endregion + #endregion -#region Scene + #region Scene public void OnSceneGUI() { if (footTarget == null || humanoid == null) @@ -551,12 +551,13 @@ namespace Passer { humanoid.pose.UpdatePose(humanoid); else { humanoid.pose.Show(humanoid); - footTarget.CopyRigToTarget(); + humanoid.CopyRigToTargets(); + humanoid.MatchTargetsToAvatar(); } } // update the target rig from the current foot target - footTarget.CopyTargetToRig(); + humanoid.CopyTargetsToRig(); // update the avatar bones from the target rig humanoid.UpdateMovements(); // match the target rig with the new avatar pose @@ -568,7 +569,7 @@ namespace Passer { humanoid.UpdateSensorsFromTargets(); } -#endregion + #endregion public abstract class TargetProps { public SerializedProperty enabledProp; diff --git a/Editor/HumanoidControl/Targets/HandTarget_Editor.cs b/Editor/HumanoidControl/Targets/HandTarget_Editor.cs index 045fdc9..7f26119 100644 --- a/Editor/HumanoidControl/Targets/HandTarget_Editor.cs +++ b/Editor/HumanoidControl/Targets/HandTarget_Editor.cs @@ -695,12 +695,13 @@ namespace Passer.Humanoid { humanoid.pose.UpdatePose(humanoid); else { humanoid.pose.Show(humanoid); - handTarget.CopyRigToTarget(); + humanoid.CopyRigToTargets(); + humanoid.MatchTargetsToAvatar(); } } // update the target rig from the current hand target - handTarget.CopyTargetToRig(); + humanoid.CopyTargetsToRig(); // update the avatar bones from the target rig humanoid.UpdateMovements(); // match the target rig with the new avatar pose diff --git a/Editor/HumanoidControl/Targets/HeadTarget_Editor.cs b/Editor/HumanoidControl/Targets/HeadTarget_Editor.cs index bf29b96..d5f472c 100644 --- a/Editor/HumanoidControl/Targets/HeadTarget_Editor.cs +++ b/Editor/HumanoidControl/Targets/HeadTarget_Editor.cs @@ -275,7 +275,7 @@ namespace Passer.Humanoid { if (headTarget.humanoid == null) return; - SerializedProperty animatorProp = serializedObject.FindProperty(nameof(HeadTarget.headAnimator)+ "." +nameof(HeadTarget.headAnimator.enabled)); + SerializedProperty animatorProp = serializedObject.FindProperty(nameof(HeadTarget.headAnimator) + "." + nameof(HeadTarget.headAnimator.enabled)); if (animatorProp != null && headTarget.humanoid.animatorEnabled) { GUIContent text = new GUIContent( @@ -482,12 +482,13 @@ namespace Passer.Humanoid { humanoid.pose.UpdatePose(humanoid); else { humanoid.pose.Show(humanoid); - headTarget.CopyRigToTarget(); + humanoid.CopyRigToTargets(); + humanoid.MatchTargetsToAvatar(); } } // update the target rig from the current head target - headTarget.CopyTargetToRig(); + humanoid.CopyTargetToRig(); // update the avatar bones from the target rig humanoid.UpdateMovements(); // match the target rig with the new avatar pose diff --git a/Editor/HumanoidControl/Targets/HipsTarget_Editor.cs b/Editor/HumanoidControl/Targets/HipsTarget_Editor.cs index e6d9d43..27bdd95 100644 --- a/Editor/HumanoidControl/Targets/HipsTarget_Editor.cs +++ b/Editor/HumanoidControl/Targets/HipsTarget_Editor.cs @@ -276,12 +276,13 @@ namespace Passer { humanoid.pose.UpdatePose(humanoid); else { humanoid.pose.Show(humanoid); - hipsTarget.CopyRigToTarget(); + humanoid.CopyRigToTargets(); + humanoid.MatchTargetsToAvatar(); } } // update the target rig from the current hips target - hipsTarget.CopyTargetToRig(); + humanoid.CopyTargetsToRig(); // update the avatar bones to match the target rig humanoid.UpdateMovements(); // match the target rig with the new avatar pose diff --git a/Runtime/HumanoidControl/Scripts/HumanoidControl.cs b/Runtime/HumanoidControl/Scripts/HumanoidControl.cs index 271a925..4d0070d 100644 --- a/Runtime/HumanoidControl/Scripts/HumanoidControl.cs +++ b/Runtime/HumanoidControl/Scripts/HumanoidControl.cs @@ -751,7 +751,7 @@ namespace Passer.Humanoid { } /// Copies the pose of the target rig to the avatar - private void CopyTargetsToRig() { + public void CopyTargetsToRig() { hipsTarget.CopyTargetToRig(); headTarget.CopyTargetToRig(); leftHandTarget.CopyTargetToRig();