【Unity博客节选】Timeline 的 AnimationOutputWeightProcessor 理解
注:软件版本Unity 6.0 + Timeline 1.8.7
作者:CSDN @ RingleaderWang
原文:《Unity第25期——Timeline结构及其源码浅析》
文章首发Github👍:《Timeline结构及其源码浅析》
Bilibili 视频版👍👍
:《Timeline结构及其源码解析》https://www.bilibili.com/video/BV1bHjYzNE35
AnimationPlayable的权重处理
Timeline构建graph过程中,对每个OutputTrack创建对应的playableOutput节点后,
如果是动画track的话,最后会为PlayableOutput注册一个权重处理回调m_EvaluateCallbacks.Add(new AnimationOutputWeightProcessor(animOutput))
,构造AnimationOutputWeightProcessor时将AnimationPlayaleOutput的权重设为0(默认是1)。这个Processor会在graph后续运行时触发WeightEvaluate方法处理Animation相关的权重(会重新调整权重)。
Timeline 会利用 AnimationOutputWeightProcessor Evaluate方法处理AnimationMixer 、AnimationLayer和 AnimationPlayableOutput的权重。
大概效果如下,设四个clip初始权重分别为0.26,0.14,0.19,0.13,连到各自Mixer和Layer后,如果输入权重和小于1,会按比例放大为:
mixer input0 weight
:0.65= 0.26/(0.26+0.14)*1mixer input1 weight
:0.35= 0.14/(0.26+0.14)*1layer input0 weight
:0.56=(0.26+0.14)/(0.26+0.14+0.19+0.13)*1AnimationOutput weight
: 0.72 = 0.26+0.14+0.19+0.13
如果输入权重和≥1,则只对≥1的输入钳值到1,不等比例缩小,且AnimationOutput weight 钳值为1.
比如四个clip初始权重分别为0.6,0.9,0.2,0.3,AnimationOutputWeightProcessor.Evaluate() 执行完后:
mixer input0 weight
:0.6 (0.6+0.9>1不缩放,且0.6<1 不钳值)mixer input1 weight
:0.9(0.6+0.9>1不缩放,且0.9<1 不钳值)layer input0 weight
:1 (0.6+0.9+0.2+0.3>1不缩放,且0.6+0.9>1 则钳值到1)layer input1 weight
: 0.5 (0.6+0.9+0.2+0.3>1不缩放,且0.2+0.3<1 不钳值)AnimationOutput weight
:1(0.6+0.9+0.2+0.3>1 钳值到1)
这么处理的目的按源码注释的说法:”对动画轨道上的权重进行后处理,以正确归一化混合器权重,从而避免混合时出现默认姿势,并确保子轨道、图层以及图层图正确混合。Does a post processing of the weights on an animation track to properly normalize the mixer weights so that blending does not bring default poses and subtracks, layers and layer graphs blend correctly ”
测试用例过长,参见:🔗TimelineTestForAnimationWeightInfo.