galacean / engine-lottie

A WebGL runtime of lottie based on Galacean Engine
MIT License
13 stars 10 forks source link

Fix `from` and `to` error #71

Closed cptbtptpbcptdtptp closed 1 year ago

cptbtptpbcptdtptp commented 1 year ago

当数据为 [{t:0,s:any,e:any},{t:10}] ,此时传入大于 10 的帧数,数据曲线变化的起点与终点有误,具体出错代码:

   // Find current frame
    for (let i = 0, l = value.length - 1; i < l; i++) {
      keyData = value[i];
      nextKeyData = value[i + 1];

      if (nextKeyData.t > frameNum) {
        this._lastPoint = 0;
        this._addedLength = 0;
        break;
      }
    }

如上方给出的例子,此时假设传入帧数为 50,后续的数据采样会依旧在 0 ~ 10 之间插值。 处理办法是,若超出变化区间,直接将 value 置为 endValue。

    if (frameNum > nextKeyData.t) {
      for (let i = 0, len = this.v.length; i < len; i++) {
        this.v[i] = this.getValue(frameNum, i, keyData, nextKeyData) * this.mult;
      }
      return;
    }