Skip to content

Commit cc57dee

Browse files
Andrew Kimfacebook-github-bot
authored andcommitted
feat(Runtime): Add an option for using world hand position as the target
Summary: In cases where the character is scaled, the world hand position might be desired. This adds an option for that capability. Reviewed By: sohailshafiiWk Differential Revision: D53066093 fbshipit-source-id: 3be58db233496ed93bd64a7e6a4fa6bf50cffaca
1 parent c3e8cde commit cc57dee

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

Runtime/Scripts/AnimationRigging/RiggingUtilities.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,24 @@ public static bool IsFiniteVector3(Vector3 v)
118118
}
119119

120120
/// <summary>
121-
/// Returns the result of diving a Vector3 by another Vector3.
121+
/// Returns the result of dividing a Vector3 by another Vector3.
122122
/// </summary>
123123
/// <param name="dividend">The Vector3 dividend.</param>
124124
/// <param name="divisor">The Vector3 divisor.</param>
125125
/// <returns>The divided Vector3.</returns>
126126
public static Vector3 DivideVector3(Vector3 dividend, Vector3 divisor)
127127
{
128-
Vector3 targetScale = Vector3.one;
128+
Vector3 targetScale;
129129
if (Vector3IsNonZero(divisor))
130130
{
131131
targetScale = new Vector3(
132132
dividend.x / divisor.x, dividend.y / divisor.y, dividend.z / divisor.z);
133133
}
134+
else
135+
{
136+
Debug.LogError("Zero detected inside divisor. Returning dividend.");
137+
return dividend;
138+
}
134139

135140
return targetScale;
136141
}

Runtime/Scripts/RetargetingProcessing/RetargetingProcessorCorrectHand.cs

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

52+
[Tooltip(RetargetingLayerTooltips.UseWorldHandPosition)]
53+
[SerializeField]
54+
private bool _useWorldHandPosition = true;
55+
/// <inheritdoc cref="_useWorldHandPosition" />
56+
public bool UseWorldHandPosition
57+
{
58+
get => _useWorldHandPosition;
59+
set => _useWorldHandPosition = value;
60+
}
61+
5262
/// <summary>
5363
/// The maximum stretch for the hand to reach the target position that is allowed.
5464
/// </summary>
@@ -157,6 +167,11 @@ public override void PrepareRetargetingProcessor(RetargetingLayer retargetingLay
157167
/// <inheritdoc />
158168
public override void ProcessRetargetingLayer(RetargetingLayer retargetingLayer, IList<OVRBone> ovrBones)
159169
{
170+
if (Weight < float.Epsilon)
171+
{
172+
return;
173+
}
174+
160175
var isFullBody = retargetingLayer.GetSkeletonType() == OVRSkeleton.SkeletonType.FullBody;
161176
var leftHandWristIndex = isFullBody ? (int)OVRSkeleton.BoneId.FullBody_LeftHandWrist :
162177
(int)OVRSkeleton.BoneId.Body_LeftHandWrist;
@@ -179,10 +194,17 @@ public override void ProcessRetargetingLayer(RetargetingLayer retargetingLayer,
179194
return;
180195
}
181196

197+
var targetHandPosition = targetHand.position;
198+
if (_useWorldHandPosition)
199+
{
200+
var localScale = retargetingLayer.transform.localScale;
201+
targetHandPosition = RiggingUtilities.DivideVector3(targetHandPosition, localScale);
202+
}
203+
182204
var handBone = _armBones[0];
183205
handBone.position = _originalHandPosition;
184206
var handRotation = handBone.rotation;
185-
Vector3 targetPosition = Vector3.Lerp(handBone.position, targetHand.position, Weight);
207+
Vector3 targetPosition = Vector3.Lerp(handBone.position, targetHandPosition, Weight);
186208
bool solvedIK = false;
187209
if (Weight > 0.0f)
188210
{

Runtime/Scripts/Tooltips.cs

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

1309+
public const string UseWorldHandPosition =
1310+
"If true, use the world hand position for placing the hand instead of the scaled position.";
1311+
13091312
public const string MaxHandStretch =
13101313
"The maximum stretch for the hand to reach the target position that is allowed.";
13111314

0 commit comments

Comments
 (0)