Skip to content

Commit

Permalink
fix scale
Browse files Browse the repository at this point in the history
  • Loading branch information
iam4722202468 committed Mar 28, 2024
1 parent e4b6bf6 commit 69992db
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.minestom.server.coordinate.Point;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.coordinate.Vec;
import net.worldseed.multipart.ModelEngine;
import net.worldseed.multipart.ModelLoader;
import net.worldseed.multipart.model_bones.ModelBone;
Expand Down Expand Up @@ -89,7 +89,10 @@ public void tick() {
}

public Point getTransform() {
if (!this.playing) return Pos.ZERO;
if (!this.playing) return switch (this.type) {
case ROTATION, TRANSLATION -> Vec.ZERO;
case SCALE -> Vec.ONE;
};
return this.frameProvider.getFrame(tick);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@

public class CachedFrameProvider implements FrameProvider {
private final Map<Short, Point> interpolationCache;
private final ModelLoader.AnimationType type;

public CachedFrameProvider(int length, LinkedHashMap<Double, BoneAnimationImpl.PointInterpolation> transform, ModelLoader.AnimationType type) {
this.interpolationCache = calculateAllTransforms(length, transform, type);
this.type = type;
}

private Map<Short, Point> calculateAllTransforms(double animationTime, LinkedHashMap<Double, BoneAnimationImpl.PointInterpolation> t, ModelLoader.AnimationType type) {
Expand Down Expand Up @@ -44,6 +46,9 @@ private Point calculateTransform(int tick, LinkedHashMap<Double, BoneAnimationIm

@Override
public Point getFrame(int tick) {
return interpolationCache.getOrDefault((short) tick, Vec.ZERO);
return interpolationCache.getOrDefault((short) tick, switch (type) {
case TRANSLATION, ROTATION -> Vec.ZERO;
case SCALE -> Vec.ONE;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
import net.minestom.server.coordinate.Point;
import net.minestom.server.coordinate.Vec;
import net.worldseed.multipart.Quaternion;
import net.worldseed.multipart.mql.MQLPoint;
import org.jetbrains.annotations.Nullable;

import java.util.LinkedHashMap;

public class Interpolator {
private static StartEnd getStartEnd(double time, LinkedHashMap<Double, BoneAnimationImpl.PointInterpolation> transform, double animationTime) {
if (transform.isEmpty())
return new StartEnd(new BoneAnimationImpl.PointInterpolation(MQLPoint.ZERO, "linear"), new BoneAnimationImpl.PointInterpolation(MQLPoint.ZERO, "linear"), 0, 0);
private static @Nullable StartEnd getStartEnd(double time, LinkedHashMap<Double, BoneAnimationImpl.PointInterpolation> transform, double animationTime) {
if (transform.isEmpty()) return null;
BoneAnimationImpl.PointInterpolation lastPoint = transform.get(transform.keySet().iterator().next());
double lastTime = 0;

Expand Down Expand Up @@ -62,6 +61,7 @@ static Quaternion slerp(Quaternion qa, Quaternion qb, double t) {

static Point interpolateRotation(double time, LinkedHashMap<Double, BoneAnimationImpl.PointInterpolation> transform, double animationTime) {
StartEnd points = getStartEnd(time, transform, animationTime);
if (points == null) return Vec.ZERO;

double timeDiff = points.et - points.st;

Expand All @@ -84,6 +84,7 @@ static Point interpolateRotation(double time, LinkedHashMap<Double, BoneAnimatio

static Point interpolateTranslation(double time, LinkedHashMap<Double, BoneAnimationImpl.PointInterpolation> transform, double animationTime) {
StartEnd points = getStartEnd(time, transform, animationTime);
if (points == null) return Vec.ZERO;

double timeDiff = points.et - points.st;

Expand All @@ -98,6 +99,7 @@ static Point interpolateTranslation(double time, LinkedHashMap<Double, BoneAnima

public static Point interpolateScale(double time, LinkedHashMap<Double, BoneAnimationImpl.PointInterpolation> transform, double animationTime) {
StartEnd points = getStartEnd(time, transform, animationTime);
if (points == null) return Vec.ONE;

double timeDiff = points.et - points.st;

Expand Down

0 comments on commit 69992db

Please sign in to comment.