minerender 2.1.0-alpha.65 → 2.1.0-alpha.66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2922,16 +2922,17 @@ var init_UVMapper = __esm({
2922
2922
  positions[textureKey] = [x, y];
2923
2923
  const [width, height] = sizes[textureKey];
2924
2924
  const sequence = frames[textureKey];
2925
- const drawFrame = (index) => {
2925
+ const getFrameData = (index) => {
2926
2926
  const columns = texture.width / width;
2927
- image.putData(texture.getSectionData(
2927
+ return texture.getSectionData(
2928
2928
  index % columns * width,
2929
2929
  Math.floor(index / columns) * height,
2930
2930
  width,
2931
2931
  height
2932
- ), x, y);
2932
+ );
2933
2933
  };
2934
- drawFrame(sequence?.[0].index ?? 0);
2934
+ const firstFrame = getFrameData(sequence?.[0].index ?? 0);
2935
+ image.putData(firstFrame, x, y);
2935
2936
  if (texture.hasTransparency) {
2936
2937
  hasTransparency = true;
2937
2938
  }
@@ -2939,13 +2940,28 @@ var init_UVMapper = __esm({
2939
2940
  hasAnimation = true;
2940
2941
  let t = 0;
2941
2942
  let f = 0;
2943
+ const interpolated = metaMap[textureKey]?.animation?.interpolate ? image.context.createImageData(width, height) : void 0;
2944
+ let currentFrame = firstFrame;
2945
+ let nextFrame = interpolated ? getFrameData(sequence[1].index) : firstFrame;
2942
2946
  animatorFunctions[textureKey] = () => {
2943
- if (++t < sequence[f].time) return false;
2944
- t = 0;
2945
- const previous = sequence[f].index;
2946
- f = (f + 1) % sequence.length;
2947
- if (sequence[f].index === previous) return false;
2948
- drawFrame(sequence[f].index);
2947
+ if (++t >= sequence[f].time) {
2948
+ t = 0;
2949
+ const previous = sequence[f].index;
2950
+ f = (f + 1) % sequence.length;
2951
+ if (interpolated) {
2952
+ currentFrame = nextFrame;
2953
+ nextFrame = getFrameData(sequence[(f + 1) % sequence.length].index);
2954
+ }
2955
+ if (sequence[f].index === previous) return false;
2956
+ image.putData(interpolated ? currentFrame : getFrameData(sequence[f].index), x, y);
2957
+ return true;
2958
+ }
2959
+ if (!interpolated || sequence[f].index === sequence[(f + 1) % sequence.length].index) return false;
2960
+ const progress = Math.floor(Math.fround(Math.fround(t / sequence[f].time) * 1e3)) / 1e3;
2961
+ for (let i = 0; i < interpolated.data.length; i++) {
2962
+ interpolated.data[i] = currentFrame.data[i] + (nextFrame.data[i] - currentFrame.data[i]) * progress;
2963
+ }
2964
+ image.putData(interpolated, x, y);
2949
2965
  return true;
2950
2966
  };
2951
2967
  }