Skip to content

Commit dbe19d1

Browse files
Andrew Kimfacebook-github-bot
authored andcommitted
fix(Runtime): Add max stretch for CCDIK and update deformation
Summary: Add a max stretch parameter for CCDIK. This will limit the amount of stretching allowed for the arm to reach the position. Update deformation to avoid applying on shoulders. This allows for adjusting just the upper arm to hand weight independently from shoulders. Reviewed By: sohailshafiiWk Differential Revision: D50847609 fbshipit-source-id: 25eb753e6898f106eb7cbb9298feb163c11d46a3
1 parent cb2d5da commit dbe19d1

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

Runtime/Scripts/AnimationRigging/DeformationJob.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -513,20 +513,6 @@ private void InterpolateArms(AnimationStream stream, float weight)
513513
var leftArmOffsetWeight = weight * LeftArmOffsetWeight.Get(stream);
514514
var rightArmOffsetWeight = weight * RightArmOffsetWeight.Get(stream);
515515

516-
if (LeftShoulderBone.IsValid(stream))
517-
{
518-
var leftShoulderPos = LeftShoulderBone.GetPosition(stream);
519-
LeftShoulderBone.SetPosition(stream,
520-
Vector3.Lerp(_preDeformationLeftShoulderPos, leftShoulderPos, leftArmOffsetWeight));
521-
}
522-
523-
if (RightShoulderBone.IsValid(stream))
524-
{
525-
var rightShoulderPos = RightShoulderBone.GetPosition(stream);
526-
RightShoulderBone.SetPosition(stream,
527-
Vector3.Lerp(_preDeformationRightShoulderPos, rightShoulderPos, rightArmOffsetWeight));
528-
}
529-
530516
LeftUpperArmBone.SetPosition(stream,
531517
Vector3.Lerp(_preDeformationLeftUpperArmPos, leftUpperArmPos, leftArmOffsetWeight));
532518
RightUpperArmBone.SetPosition(stream,

Runtime/Scripts/RetargetingProcessing/RetargetingProcessorCorrectHand.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ public IKType HandIKType
4949
set => _handIKType = value;
5050
}
5151

52+
/// <summary>
53+
/// The maximum stretch for the hand to reach the target position that is allowed.
54+
/// </summary>
55+
[Tooltip(RetargetingLayerTooltips.MaxStretch)]
56+
[SerializeField]
57+
private float _maxStretch = 0.01f;
58+
/// <inheritdoc cref="_maxStretch" />
59+
public float MaxStretch
60+
{
61+
get => _maxStretch;
62+
set => _maxStretch = value;
63+
}
64+
5265
/// <summary>
5366
/// The maximum distance between the resulting position and target position that is allowed.
5467
/// </summary>
@@ -158,7 +171,7 @@ public override void ProcessRetargetingLayer(RetargetingLayer retargetingLayer,
158171
AnimationUtilities.SolveCCDIK(_armBones, targetPosition, IKTolerance, IKIterations);
159172
}
160173
}
161-
handBone.position = targetPosition;
174+
handBone.position = Vector3.MoveTowards(handBone.position, targetPosition, MaxStretch);
162175
handBone.rotation = handRotation;
163176
}
164177
}

Runtime/Scripts/Tooltips.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,9 @@ public static class RetargetingLayerTooltips
12151215
"The type of IK that should be applied to modify the arm bones toward the " +
12161216
"correct hand target.";
12171217

1218+
public const string MaxStretch =
1219+
"The maximum stretch for the hand to reach the target position that is allowed.";
1220+
12181221
public const string IKTolerance =
12191222
"The maximum distance between the resulting position and target position that is allowed.";
12201223

Samples/RetargetingProcessors/ArmatureCorrectLeftHand.asset

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ MonoBehaviour:
1717
_handIKType: 1
1818
_ikTolerance: 0.000001
1919
_ikIterations: 10
20+
_ikMaxStretch: 0.01

Samples/RetargetingProcessors/ArmatureCorrectRightHand.asset

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ MonoBehaviour:
1717
_handIKType: 1
1818
_ikTolerance: 0.000001
1919
_ikIterations: 10
20+
_ikMaxStretch: 0.01

0 commit comments

Comments
 (0)