当前位置:网站首页>UE4 source code reading_ Bone model and animation system_ Animation compression
UE4 source code reading_ Bone model and animation system_ Animation compression
2022-07-03 08:25:00 【_ lazycat】
0. Write it at the front
This article is a collection of personal learning notes , If there is a mistake , I hope you can point out .
1. UE4 Animation compression scheme

Remove linear key compression is used by default
1.1 lossless compression Least Destructive

- Set translation data (Translation) Compression format for :ACF_None, Uncompressed
- Set rotation data (Rotation) Compression format for :ACF_Float96NoW,3 individual 32 position Float To store rotation data . Bone rotation data is stored in quaternions , Here, take out w component .
- Perform bit compression
1.2 Bit compression Bitwise Compress Only
Key and Track:
Key : Keyframe data , Data describing the position and rotation of a single bone at a specific time .
Track : A set of keyframes that describe the movement of a single bone over time .For every bone , Extract the original animation data into translation 、 rotate 、 Zoom three Track in
SeparateRawDataIntoTracks( CompressibleAnimData.RawAnimationData, CompressibleAnimData.SequenceLength, TranslationData, RotationData, ScaleData );Remove redundant Track data : Be a bone Track When the data does not change ( That is, the bone does not participate in translation, rotation or scaling under this animation , Remove everything except the first frame .
FilterTrivialKeys, Respectively called FilterTrivialRotationKeys、FilterTrivialPositionKeys、FilterTrivialScaleKeys Check the rotation 、 translation 、 Whether the scaling data has changed , If there has been any change , Then the whole Track Retain , without , Then only the first frame data is retained .According to the panel settings , Specify translation 、 rotate 、 Zoom encoding format :AnimationFormat_SetInterfaceLinks
ACF_None
ACF_Float96NoW
ACF_Fixed48NoW
ACF_IntervalFixed32NoW
ACF_Fixed32NoW
ACF_Float32NoW
ACF_IdentityPerform bitwise compression :BitwiseCompressAnimationTracks
Simple quantization Simple quantization algorithm
That is to normalize floating-point numbers within a certain range , And shrink it to N Range of bit integers , And then rounded to N An integer- ACF_None: Uncompressed , If it is translation data , use 332 position float. If it is rotating data , use 432 position float( contain w component )
- ACF_Float96NoW: Corresponding CompressTranslation_Uncompressed Algorithm , use 3*32 position float, It doesn't contain w component
- ACF_Fixed48NoW: Corresponding CompressTranslation_16_16_16 Algorithm , take 332 position float Compress the data to 3uint16.

- ACF_IntervalFixed32NoW: Corresponding CompressTranslation_10_11_11 Algorithm , take 332 position float Compress the data to 1uint32.
take XYZ Data mapping , To calculate Track The minimum value of the data in MinX、MinY and MinZ, as well as Track Range of data in Range(Max-Min)
adopt value = (V - Vmin)/ Range mapping
And then save it together to a 32 position int data , among 21-31 Bitstore Z, 10-20 Bitstore Y, 0-9 Bitstore X
1.3 Remove trivial frame compression Remove Trivial Keys
Trivial frame : Redundancy without change Track data , Keep only the first frame , In fact, the key frame information will not be deleted , Just keep only one copy of the same data . Basically, other compression schemes will deal with trivial frames first .
- SeparateRawDataIntoTracks: Separate the original data into 3 individual Track
- FilterTrivialKeys: Remove trivial frames
- AnimationFormat_SetInterfaceLinks: Set the compression encoding format , It is used here without compression
- BitwiseCompressAnimationTracks: Perform bitwise compression
1.4 Remove compression every other frame Remove Every Second Key
On the basis of removing trivial frames, an alternate frame removal is added , You can specify how many frames to remove , You can also specify how many frames to start the removal
FilterIntermittentKeys, Respectively called
FilterIntermittentRotationKeys(RotationTracks, StartIndex, Interval);
FilterIntermittentPositionKeys(PositionTracks, StartIndex, Interval);
Yes position Each track, Traverse keyframes , Step at regular intervals , Join the new Track.Rotation Empathy
Finally, call the encoding format set by the user for bit compression
1.5 Remove linear frame compression Remove Linear Keys
Delete the key frames that can be obtained by linear interpolation of adjacent frames
principle :
- Select a key frame
- Calculate the value obtained from its two neighbor linear interpolation
- If the resulting trajectory error is acceptable, remove this key
The algorithms for selecting key frames in the first step above can be diverse , And will produce different compression results (UE4 What is the ?)
The third step is UE4 Medium is MaxPosDiff、MaxAngleDiff and MaxScaleDiff,UE4 It also provides 3 Parameters ,MaxEffectorDiff、MinEffectorDiff and EffectorDiffSocket, because UE4 In addition to checking the difference between a keyframe of an interpolated bone and the original data , Also check if after applying this data , Effect on the terminal bone , That is, the error of the end bone .
Related parameters :
Detailed process :
SeparateRawDataIntoTracks:
Separate Track dataFilterBeforeMainKeyRemoval:
call FilterTrivialKeys Delete trivial framesCompressUsingUnderlyingCompressor
call BitwiseCompressAnimationTracks Perform a bit compression before filtering linear framesProcessAnimationTracks: Remove keyframes that can be approximated by linear interpolation
The main logic is FilterLinearKeysTemplate
Filtering rules :
① Definition LowKey, From the second frame ( Subscript to be 1) To traverse the
② Definition GoodHighKey、BadHighKey Two moving subscripts , stay LowKey Draw a window at the end of the frame
③ Definition HighKey by Good and Bad The middle subscript of , from LowKey The next frame of continues to HighKey Traverse in position ( Dichotomy )
④ Traversed in step 3 KeyValue, adopt Alpha Variables and critical values (LowKey、HighKeyValue) Calculate an interpolation data , Compare interpolated data with raw data , If it is less than the configured allowable error value , Then continue to check the end bone data error affected by the bone .
Calculate the data error of the end bone , Convert to world coordinates ( Global posture ) compare ( Before, we compared the local posture ), Record the maximum error , Check whether it is greater than the configured end maximum error .
Alpha The calculation of :
If you want to calculate Key(3) Linear interpolation data of position , Then you can Key(3) Neighbor calculation Alpha=(3-2)/(4-2)=0.5, Interpolated Value=lerp(0.35, 0.85, alpha) = 0.6
⑤ If the error is not too large after the fourth step , Will GoodHighKey The value of is updated to HighKey, Description from LowKey To HighKey The previous data can be obtained by linear interpolation . If there is too much error in step 4 , Will BadHighKey The value of is updated to HighKey, Then go back to step three , Recalculate HighKey.
⑥ Gradually shrink from step 3 to step 5 GoodHighKey and BadHighKey The window of , Until the window is small enough to stop , And then GoodHighKey The corresponding data is added to a new Track( Record TimeValue and KeyValue), This Track What is saved is to remove the data after the frame that can be obtained by linear interpolationProcessAnimationTracks The function will be applied to three of each bone Track( translation 、 rotate 、 The zoom ) All implemented FilterLinearKeysTemplate To filter
After removing the linear approximation frame , Perform bit compression again on the final remaining data :CompressUsingUnderlyingCompressor
1.6 Independent track compression Compress each track independently
According to different Track Compress separately , Inherited from the class that removes linear frame compression , Call directly UAnimCompress_RemoveLinearKeys::DoReduction, Yes RemoveLinearKeys Rewrite some key functions of , That is, do additional processing on the basis of linear compression
Related parameters :
LinearKeyRemoval Consistent with the effect of linear compression 
1. FilterBeforeMainKeyRemoval
a. ResampleKeys: Resample the original animation data
If I check that Resampling, And the animation key frame sampling data is greater than MinKeysForResampling, The original data will be resampled according to the set sampling frame interval .
b. CalculateTrackHeights and TallyErrorsFromPerturbation:
Check AdaptiveError or AdaptiveError2 Time processing , Tentatively .
The above three configurations are not processed by default
c. FilterTrivialKeys: Delete trivial frames
2. CompressUsingUnderlyingCompressor
2. Reference material
http://nfrechette.github.io/2016/10/21/anim_compression_toc/
边栏推荐
- Easy touch plug-in
- ArrayList
- jupyter远程服务器配置以及服务器开机自启
- 【更新中】微信小程序学习笔记_3
- 數據庫應用技術課程設計之商城管理系統
- MySQL containerization (1) docker installation MySQL
- C language - Introduction - essence Edition - take you into programming (I)
- Osgearth north arrow display
- Golang string segmentation, substitution and interception
- Unity one click AssetBundle
猜你喜欢

Simply start with the essence and principle of SOM neural network

Oracle insert single quotation mark

Transfinite hacker cognition

Thymeleaf 404 reports an error: there was unexpected error (type=not found, status=404)

Transplantation of freetype Library

L'installateur a été installé avec une erreur inattendue
![[end of 2021] National Meteorological Short Video (Kwai, Tiktok) influence list in December](/img/51/81ceaf8746ec7455ea8abf9f038e81.jpg)
[end of 2021] National Meteorological Short Video (Kwai, Tiktok) influence list in December

基于SSM的校园失物招领平台,源码,数据库脚本,项目导入运行视频教程,论文撰写教程

Abstract classes and interfaces

the installer has encountered an unexpected error installing this package
随机推荐
unity2019_ Input management
【更新中】微信小程序学习笔记_3
【K&R】中文第二版 个人题解 Chapter1
Swagger document configuration
了解小程序的笔记 2022/7/3
Minimap plug-in
P1596 [USACO10OCT]Lake Counting S
Huawei interview summary during the epidemic
Student educational administration management system of C # curriculum design
數據庫應用技術課程設計之商城管理系統
Osgearth north arrow display
MXone Pro自适应2.0影视模板西瓜视频主题苹果cmsV10模板
Puhua PLM empowers the whole scene product lifecycle management and helps the enterprise digital transformation of the main line of products
Basic operation and process control 2
P2704 [noi2001] artillery position (shape pressure DP)
Youyou1 of xlua knapsack system
MySQL 8
Golang 中string和int类型相互转换
[global product discovery 2] the first pure cloud augmented reality (AR) platform - Israel
Wpf: solve the problem that materialdesign:dialoghost cannot be closed