当前位置:网站首页>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/
边栏推荐
- Redis data structure
- [usaco12mar]cows in a skyscraper g (state compression DP)
- php-fpm软件的安装+openresty高速缓存搭建
- Golang 时间格式整理
- Sequence of map implementation classes
- Solution détaillée de toutes les formules de fonction de transfert (fonction d'activation) du réseau neuronal MATLAB
- [end of 2021] National Meteorological Short Video (Kwai, Tiktok) influence list in December
- Kwai 20200412 recruitment
- P1896 [scoi2005] non aggression (shape pressure DP)
- matlab神经网络所有传递函数(激活函数)公式详解
猜你喜欢

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

MXone Pro自适应2.0影视模板西瓜视频主题苹果cmsV10模板

Mxone Pro adaptive 2.0 film and television template watermelon video theme apple cmsv10 template

MySQL 8

【云原生】微服务之Feign的介绍与使用

Chocolate installation
![[cloud native] introduction and use of feign of microservices](/img/39/05cf7673155954c90e75a8a2eecd96.jpg)
[cloud native] introduction and use of feign of microservices
![P1596 [USACO10OCT]Lake Counting S](/img/a7/07a84c93ee476788d9443c0add808b.png)
P1596 [USACO10OCT]Lake Counting S

Scite change background color
随机推荐
Base64和Base64URL
Ilruntime learning - start from scratch
Golang's range
Initial unity
Use filechannel to copy files
796 · unlock
【音视频】ijkplayer错误码
Gradle's method of dynamically modifying APK package name
Pulitzer Prize in the field of information graphics - malofiej Award
UE4 plug in development
Dealing with duplicate data in Excel with xlwings
Creation and content of mapnode -- osgearth rendering engine series (2)
LinkList
Unity performance optimization
[end of 2021] National Meteorological Short Video (Kwai, Tiktok) influence list in December
Golang time format sorting
Exe file running window embedding QT window
Oracle insert single quotation mark
Golang的range
How to establish rectangular coordinate system in space