BlueRoseNote/03-UnrealEngine/Animation/UE5动画重定向笔记.md

99 lines
3.2 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: UE5动画重定向笔记
date: 2023-08-18 18:08:12
excerpt:
tags:
rating: ⭐
---
# ConvertAnimation()
主要逻辑位于`UAnimationEditorUtilityLibrary::ConvertAnimation()`或者`FIKRetargetBatchOperation::ConvertAnimation()`。核心重定向逻辑为`UIKRetargetProcessor::RunRetargeter()`
## RunRootRetarget()
FRootRetargeter::EncodePose():
取得输入的根骨骼Transform数据并给`FRootSource Source`赋值。
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;
```
## RunFKRetarget()
FChainEncoderFK::EncodePose():
从骨骼链拷贝全局输入到CurrentGlobalTransforms
FChainDecoderFK::DecodePose():
## RunIKRetarget()
## RunPoleVectorMatching()
# UIKRetargetProcessor
# FBX
https://help.autodesk.com/view/FBX/2020/ENU/?guid=FBX_Developer_Help_welcome_to_the_fbx_sdk_html
使用之前建议**仔细查看文档**。FBX Sdk有三种库分别为动态链接库(dll + lib)、静态链接库(/MD)、静态链接库(/MT)。
- 动态链接库使用Qt的导入库功能导入动态库之后只需要再添加一行`DEFINES += FBXSDK_SHARED`即可。例如:
```qmake
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++17
DEFINES += FBXSDK_SHARED
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
Common/Common.cpp \
main.cpp \
mainwindow.cpp
HEADERS += \
Common/Common.h \
mainwindow.h
FORMS += \
mainwindow.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/FBXSdk/lib/vs2022/x64/release/ -llibfbxsdk
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/FBXSdk/lib/vs2022/x64/debug/ -llibfbxsdk
INCLUDEPATH += $$PWD/FBXSdk/lib/vs2022/x64/debug
DEPENDPATH += $$PWD/FBXSdk/lib/vs2022/x64/debug
INCLUDEPATH += $$PWD/FBXSdk/include
```
- 静态链接库(/MD)使用Qt的导入库功能导入静态库之后
- 静态链接库(/MT)使用Qt的导入库功能导入静态库之后
## Qt相关设置添加
https://blog.csdn.net/libaineu2004/article/details/105718847
Qt在pro中设置运行时库MT、MTd、MD、MDd重点关注QMAKE_CFLAGS
多线程调试Dll (/MDd) 对应的是MD_DynamicDebug
多线程Dll (/MD) 对应的是MD_DynamicRelease
多线程(/MT) 对应的是MD_StaticRelease
多线程(/MTd)对应的是MD_StaticDebug
##  /NODEFAULTLIB:library
```cpp
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../LIBRARYNAME/Lib/ -lLIBRARY /NODEFAULTLIB:library
```