From b7c9fabdf5e44278ae7204de2e587bb89910309c Mon Sep 17 00:00:00 2001 From: BlueRose <378100977@qq.com> Date: Mon, 6 Nov 2023 22:17:01 +0800 Subject: [PATCH] vault backup: 2023-11-06 22:17:01 --- .../Animation/UE5动画重定向核心逻辑笔记.md | 52 ++++++++++++++++--- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/03-UnrealEngine/Animation/UE5动画重定向核心逻辑笔记.md b/03-UnrealEngine/Animation/UE5动画重定向核心逻辑笔记.md index 9c4acc3..ae02ac4 100644 --- a/03-UnrealEngine/Animation/UE5动画重定向核心逻辑笔记.md +++ b/03-UnrealEngine/Animation/UE5动画重定向核心逻辑笔记.md @@ -43,14 +43,50 @@ FRootRetargeter::EncodePose(): FRootRetargeter::DecodePose(): ```c++ -// InitialTransform 为重定向Pose计算出的数值,通过比值计算出Target的Current数值 -const FTransform InitialTransform = SourceSkeleton.RetargetGlobalPose[Source.BoneIndex]; -float InitialHeight = InitialTransform.GetTranslation().Z; -Source.InitialHeightInverse = 1.0f / InitialHeight; -Source.CurrentPositionNormalized = Source.CurrentPosition * Source.InitialHeightInverse; - -// generate basic retarget root position by scaling the normalized position by root height -const FVector RetargetedPosition = Source.CurrentPositionNormalized * Target.InitialHeight; +FVector Position; +{ + // 关键:InitialTransform 为重定向Pose计算出的数值,通过比值计算出Target的Current数值 + const FVector RetargetedPosition = Source.CurrentPositionNormalized * Target.InitialHeight; + // 根据RetargetSetting中设置的BlendToSourceWeights与BlendToSource,与SourcePosition进行混合。 + Position = FMath::Lerp(RetargetedPosition, Source.CurrentPosition, Settings.BlendToSource*Settings.BlendToSourceWeights); + + // 应用vertical / horizontal的缩放 + 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() FChainEncoderFK::EncodePose():