Skip to content

Commit 5999837

Browse files
sohailshafiiWkfacebook-github-bot
authored andcommitted
feat(Runtime): All animation rigging jobs use the weight field
Summary: Our animation rigging jobs don't respect the weight parameter for the most part, and we should use it so that people can reduce the effect of each constraint. Reviewed By: andkim-meta Differential Revision: D46653823 fbshipit-source-id: 2a6dc96a662aff7ae03db0fe65f343f7412f6d6c
1 parent 89e017f commit 5999837

File tree

4 files changed

+31
-19
lines changed

4 files changed

+31
-19
lines changed

Runtime/Scripts/AnimationRigging/DeformationJob.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,11 @@ public void ProcessAnimation(AnimationStream stream)
172172
if (SpineCorrectionType != DeformationData.SpineTranslationCorrectionType.None &&
173173
(!CorrectSpineOnce || (CorrectSpineOnce && !_correctedSpine)))
174174
{
175-
ProcessSpineCorrection(stream);
175+
ProcessSpineCorrection(stream, weight);
176176
_correctedSpine = true;
177177
}
178-
ProcessDeformation(stream);
179-
ProcessArms(stream);
178+
ProcessDeformation(stream, weight);
179+
ProcessArms(stream, weight);
180180
}
181181
else
182182
{
@@ -195,7 +195,7 @@ public void ProcessAnimation(AnimationStream stream)
195195
}
196196
}
197197

198-
private void ProcessSpineCorrection(AnimationStream stream)
198+
private void ProcessSpineCorrection(AnimationStream stream, float weight)
199199
{
200200
var currentDirection = HipsToHeadBones[HipsBonesIndex].GetPosition(stream) -
201201
HipsToHeadBones[HeadBonesIndex].GetPosition(stream);
@@ -211,13 +211,13 @@ private void ProcessSpineCorrection(AnimationStream stream)
211211
}
212212

213213
var bone = HipsToHeadBones[i];
214-
var targetPos = bone.GetPosition(stream);
215-
bone.SetPosition(stream, targetPos + offset);
214+
var currentPosition = bone.GetPosition(stream);
215+
bone.SetPosition(stream, Vector3.Lerp(currentPosition, currentPosition + offset, weight));
216216
HipsToHeadBones[i] = bone;
217217
}
218218
}
219219

220-
private void ProcessDeformation(AnimationStream stream)
220+
private void ProcessDeformation(AnimationStream stream, float weight)
221221
{
222222
for (int i = 0; i < StartBones.Length; i++)
223223
{
@@ -246,20 +246,22 @@ private void ProcessDeformation(AnimationStream stream)
246246
{
247247
BonePositions[i] = targetPos;
248248
}
249-
EndBones[i].SetPosition(stream, BonePositions[i]);
249+
EndBones[i].SetPosition(stream, Vector3.Lerp(startPos, BonePositions[i], weight));
250250
}
251251

252252
_initializedBonePositions = true;
253253
}
254254

255-
private void ProcessArms(AnimationStream stream)
255+
private void ProcessArms(AnimationStream stream, float weight)
256256
{
257257
var leftLowerArmPos = LeftLowerArmBone.GetPosition(stream);
258258
var rightLowerArmPos = RightLowerArmBone.GetPosition(stream);
259259
var leftArmOffset = LeftUpperArmBone.GetPosition(stream) - _originalLeftUpperArmPos;
260260
var rightArmOffset = RightUpperArmBone.GetPosition(stream) - _originalRightUpperArmPos;
261-
LeftLowerArmBone.SetPosition(stream, leftLowerArmPos + leftArmOffset * LeftArmOffsetWeight);
262-
RightLowerArmBone.SetPosition(stream, rightLowerArmPos + rightArmOffset * RightArmOffsetWeight);
261+
LeftLowerArmBone.SetPosition(stream,
262+
Vector3.Lerp(leftLowerArmPos, leftLowerArmPos + leftArmOffset * LeftArmOffsetWeight, weight));
263+
RightLowerArmBone.SetPosition(stream,
264+
Vector3.Lerp(rightLowerArmPos, rightLowerArmPos + rightArmOffset * RightArmOffsetWeight, weight));
263265
}
264266
}
265267

Runtime/Scripts/AnimationRigging/GroundingJob.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,20 @@ public void ProcessAnimation(AnimationStream stream)
104104
// Leg position + rotation.
105105
var hipsLocalRotation = Hips.GetLocalRotation(stream);
106106
var hipsLocalPosition = Hips.GetLocalPosition(stream);
107-
Leg.SetLocalPosition(stream, hipsLocalPosition + hipsLocalRotation * LegPosOffset);
108-
Leg.SetLocalRotation(stream, hipsLocalRotation * LegRotOffset);
107+
Leg.SetLocalPosition(stream,
108+
Vector3.Lerp(hipsLocalPosition,
109+
hipsLocalPosition + hipsLocalRotation * LegPosOffset, weight));
110+
Leg.SetLocalRotation(stream,
111+
Quaternion.Slerp(hipsLocalRotation,
112+
hipsLocalRotation * LegRotOffset, weight));
109113

110114
// Foot position.
111115
if (IsGrounding[0])
112116
{
113117
var footPos = Vector3.Lerp(_prevFootPos, TargetFootPos[0], MoveProgress[0]);
114118
float footDist = Vector3.Distance(_prevFootPos, TargetFootPos[0]);
115119
footPos.y += StepHeight * Mathf.Clamp01(footDist / StepHeightScaleDist) * StepProgress[0];
116-
FootTarget.SetPosition(stream, footPos);
120+
FootTarget.SetPosition(stream, Vector3.Lerp(FootTarget.GetPosition(stream), footPos, weight));
117121
}
118122

119123
// Record foot position.
@@ -125,7 +129,8 @@ public void ProcessAnimation(AnimationStream stream)
125129
// Foot rotation.
126130
var lookRot = Quaternion.LookRotation(HipsTarget.GetLocalPosition(stream) - KneeTarget.GetLocalPosition(stream)) *
127131
FootRotationOffset;
128-
FootTarget.SetRotation(stream, lookRot);
132+
FootTarget.SetRotation(stream,
133+
Quaternion.Slerp(FootTarget.GetRotation(stream), lookRot, weight));
129134
}
130135
else
131136
{

Runtime/Scripts/AnimationRigging/HipPinningJob.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,15 @@ public void ProcessAnimation(AnimationStream stream)
6262
if (bone.IsValid(stream))
6363
{
6464
var bonePos = bone.GetLocalPosition(stream);
65-
bone.SetLocalPosition(stream, bonePos + hipPosDelta);
65+
bone.SetLocalPosition(stream,
66+
Vector3.Lerp(bonePos, bonePos + hipPosDelta, weight));
6667
}
6768
}
6869
}
6970

7071
// Set the hips position.
71-
Hips.SetLocalPosition(stream, TargetHipPos[0]);
72+
Hips.SetLocalPosition(stream,
73+
Vector3.Lerp(trackedHipPos, TargetHipPos[0], weight));
7274
}
7375
else
7476
{

Runtime/Scripts/AnimationRigging/TwistDistributionJob.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,18 @@ public void ProcessAnimation(AnimationStream stream)
106106
ReadWriteTransformHandle twistTransform = TwistTransforms[i];
107107

108108
// Apply spacing
109-
twistTransform.SetPosition(stream, SpacingPositions[i]);
109+
twistTransform.SetPosition(stream,
110+
Vector3.Lerp(twistTransform.GetPosition(stream), SpacingPositions[i], weight));
110111

111112
// Apply twist
112113
Quaternion twistRotation = Quaternion.LookRotation(SegmentDirections[0], SegmentUpAxis[i]);
113114
Quaternion targetRotation = Quaternion.Slerp(
114115
parentRotation * TwistBindRotations[i],
115116
twistRotation * TwistAxisOffset,
116117
WeightBuffer[i] * weight);
117-
twistTransform.SetLocalRotation(stream, inverseParentRotation * targetRotation);
118+
twistTransform.SetLocalRotation(stream,
119+
Quaternion.Slerp(twistTransform.GetLocalRotation(stream),
120+
inverseParentRotation * targetRotation, weight));
118121
TwistTransforms[i] = twistTransform;
119122
}
120123
}

0 commit comments

Comments
 (0)