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.
@@ -3008,16 +3008,17 @@ var init_UVMapper = __esm({
3008
3008
  positions[textureKey] = [x, y];
3009
3009
  const [width, height] = sizes[textureKey];
3010
3010
  const sequence = frames[textureKey];
3011
- const drawFrame = (index) => {
3011
+ const getFrameData = (index) => {
3012
3012
  const columns = texture.width / width;
3013
- image.putData(texture.getSectionData(
3013
+ return texture.getSectionData(
3014
3014
  index % columns * width,
3015
3015
  Math.floor(index / columns) * height,
3016
3016
  width,
3017
3017
  height
3018
- ), x, y);
3018
+ );
3019
3019
  };
3020
- drawFrame(sequence?.[0].index ?? 0);
3020
+ const firstFrame = getFrameData(sequence?.[0].index ?? 0);
3021
+ image.putData(firstFrame, x, y);
3021
3022
  if (texture.hasTransparency) {
3022
3023
  hasTransparency = true;
3023
3024
  }
@@ -3025,13 +3026,28 @@ var init_UVMapper = __esm({
3025
3026
  hasAnimation = true;
3026
3027
  let t = 0;
3027
3028
  let f = 0;
3029
+ const interpolated = metaMap[textureKey]?.animation?.interpolate ? image.context.createImageData(width, height) : void 0;
3030
+ let currentFrame = firstFrame;
3031
+ let nextFrame = interpolated ? getFrameData(sequence[1].index) : firstFrame;
3028
3032
  animatorFunctions[textureKey] = () => {
3029
- if (++t < sequence[f].time) return false;
3030
- t = 0;
3031
- const previous = sequence[f].index;
3032
- f = (f + 1) % sequence.length;
3033
- if (sequence[f].index === previous) return false;
3034
- drawFrame(sequence[f].index);
3033
+ if (++t >= sequence[f].time) {
3034
+ t = 0;
3035
+ const previous = sequence[f].index;
3036
+ f = (f + 1) % sequence.length;
3037
+ if (interpolated) {
3038
+ currentFrame = nextFrame;
3039
+ nextFrame = getFrameData(sequence[(f + 1) % sequence.length].index);
3040
+ }
3041
+ if (sequence[f].index === previous) return false;
3042
+ image.putData(interpolated ? currentFrame : getFrameData(sequence[f].index), x, y);
3043
+ return true;
3044
+ }
3045
+ if (!interpolated || sequence[f].index === sequence[(f + 1) % sequence.length].index) return false;
3046
+ const progress = Math.floor(Math.fround(Math.fround(t / sequence[f].time) * 1e3)) / 1e3;
3047
+ for (let i = 0; i < interpolated.data.length; i++) {
3048
+ interpolated.data[i] = currentFrame.data[i] + (nextFrame.data[i] - currentFrame.data[i]) * progress;
3049
+ }
3050
+ image.putData(interpolated, x, y);
3035
3051
  return true;
3036
3052
  };
3037
3053
  }