vault backup: 2023-11-06 22:17:01
This commit is contained in:
parent
827f38819c
commit
b7c9fabdf5
@ -43,14 +43,50 @@ FRootRetargeter::EncodePose():
|
|||||||
|
|
||||||
FRootRetargeter::DecodePose():
|
FRootRetargeter::DecodePose():
|
||||||
```c++
|
```c++
|
||||||
// InitialTransform 为重定向Pose计算出的数值,通过比值计算出Target的Current数值
|
FVector Position;
|
||||||
const FTransform InitialTransform = SourceSkeleton.RetargetGlobalPose[Source.BoneIndex];
|
{
|
||||||
float InitialHeight = InitialTransform.GetTranslation().Z;
|
// 关键:InitialTransform 为重定向Pose计算出的数值,通过比值计算出Target的Current数值
|
||||||
Source.InitialHeightInverse = 1.0f / InitialHeight;
|
const FVector RetargetedPosition = Source.CurrentPositionNormalized * Target.InitialHeight;
|
||||||
Source.CurrentPositionNormalized = Source.CurrentPosition * Source.InitialHeightInverse;
|
// 根据RetargetSetting中设置的BlendToSourceWeights与BlendToSource,与SourcePosition进行混合。
|
||||||
|
Position = FMath::Lerp(RetargetedPosition, Source.CurrentPosition, Settings.BlendToSource*Settings.BlendToSourceWeights);
|
||||||
|
|
||||||
// generate basic retarget root position by scaling the normalized position by root height
|
// 应用vertical / horizontal的缩放
|
||||||
const FVector RetargetedPosition = Source.CurrentPositionNormalized * Target.InitialHeight;
|
FVector ScaledRetargetedPosition = Position;
|
||||||
|
ScaledRetargetedPosition.Z *= Settings.ScaleVertical;
|
||||||
|
const FVector HorizontalOffset = (ScaledRetargetedPosition - Target.InitialPosition) * FVector(Settings.ScaleHorizontal, Settings.ScaleHorizontal, 1.0f);
|
||||||
|
Position = Target.InitialPosition + HorizontalOffset;
|
||||||
|
// 应用RetargetSetting中Position偏移。
|
||||||
|
Position += Settings.TranslationOffset;
|
||||||
|
|
||||||
|
// blend with alpha
|
||||||
|
Position = FMath::Lerp(Target.InitialPosition, Position, Settings.TranslationAlpha);
|
||||||
|
|
||||||
|
// 记录偏差
|
||||||
|
Target.RootTranslationDelta = Position - RetargetedPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
FQuat Rotation;
|
||||||
|
{
|
||||||
|
// calc offset between initial source/target root rotations
|
||||||
|
const FQuat RotationDelta = Source.CurrentRotation * Source.InitialRotation.Inverse();
|
||||||
|
// add retarget pose delta to the current source rotation
|
||||||
|
const FQuat RetargetedRotation = RotationDelta * Target.InitialRotation;
|
||||||
|
|
||||||
|
// add static rotation offset
|
||||||
|
Rotation = RetargetedRotation * Settings.RotationOffset.Quaternion();
|
||||||
|
|
||||||
|
// blend with alpha
|
||||||
|
Rotation = FQuat::FastLerp(Target.InitialRotation, Rotation, Settings.RotationAlpha);
|
||||||
|
Rotation.Normalize();
|
||||||
|
|
||||||
|
// record the delta created by all the modifications made to the root rotation
|
||||||
|
Target.RootRotationDelta = RetargetedRotation * Target.InitialRotation.Inverse();
|
||||||
|
}
|
||||||
|
|
||||||
|
// apply to target
|
||||||
|
FTransform& TargetRootTransform = OutTargetGlobalPose[Target.BoneIndex];
|
||||||
|
TargetRootTransform.SetTranslation(Position);
|
||||||
|
TargetRootTransform.SetRotation(Rotation);
|
||||||
```
|
```
|
||||||
## RunFKRetarget()
|
## RunFKRetarget()
|
||||||
FChainEncoderFK::EncodePose():
|
FChainEncoderFK::EncodePose():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user