Skip to content

Commit

Permalink
1.2.5
Browse files Browse the repository at this point in the history
added: pre/post frames
bugfix: allow single frame
  • Loading branch information
LouisQuepierts committed Aug 25, 2024
1 parent 35fdd6f commit 39f497c
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 96 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public static <T> T interpolation(KeyFrame<T>[] keyframes, T out, float time) {
float localT = (time - kf1.getTime()) / (kf2.getTime() - kf1.getTime());

switch (kf2.getMode()) {
case LINEAR -> out = kf2.linerInterpolation(kf1.getValue(), kf2.getValue(), localT);
case CATMULLROM -> out = kf2.catmullRomInterpolation(kf0.getValue(), kf1.getValue(), kf2.getValue(), kf3.getValue(), localT);
case STEP -> out = kf1.getValue();
case LINEAR -> out = kf2.linerInterpolation(kf1.getPost(), kf2.getPre(), localT);
case CATMULLROM -> out = kf2.catmullRomInterpolation(kf0.getPost(), kf1.getPost(), kf2.getPost(), kf3.getPost(), localT);
case STEP -> out = kf1.getPre();
}

return out;
Expand Down Expand Up @@ -75,6 +75,14 @@ public static Vector3f linerInterpolation(Vector3f p1, Vector3f p2, float delta)
);
}

public static Vector3f linerInterpolation(Vector3f p1, Vector3f p2, Vector3f out, float delta) {
return out.set(
p1.x * (1.0F - delta) + p2.x * delta,
p1.y * (1.0F - delta) + p2.y * delta,
p1.z * (1.0F - delta) + p2.z * delta
);
}

public static Vector3f catmullRomInterpolation(Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3, float delta) {
float t2 = delta * delta;
float t3 = t2 * delta;
Expand All @@ -84,6 +92,15 @@ public static Vector3f catmullRomInterpolation(Vector3f p0, Vector3f p1, Vector3
return new Vector3f(x, y, z);
}

public static Vector3f catmullRomInterpolation(Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3, Vector3f out, float delta) {
float t2 = delta * delta;
float t3 = t2 * delta;
float x = 0.5F * (2.0F * p1.x + (-p0.x + p2.x) * delta + (2.0F * p0.x - 5.0F * p1.x + 4.0F * p2.x - p3.x) * t2 + (-p0.x + 3.0F * p1.x - 3.0F * p2.x + p3.x) * t3);
float y = 0.5F * (2.0F * p1.y + (-p0.y + p2.y) * delta + (2.0F * p0.y - 5.0F * p1.y + 4.0F * p2.y - p3.y) * t2 + (-p0.y + 3.0F * p1.y - 3.0F * p2.y + p3.y) * t3);
float z = 0.5F * (2.0F * p1.z + (-p0.z + p2.z) * delta + (2.0F * p0.z - 5.0F * p1.z + 4.0F * p2.z - p3.z) * t2 + (-p0.z + 3.0F * p1.z - 3.0F * p2.z + p3.z) * t3);
return out.set(x, y, z);
}

public static Quaternionf linerInterpolation(Quaternionf p1, Quaternionf p2, float delta) {

Quaternionf dest = new Quaternionf();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@
public abstract class KeyFrame<T> {
protected final float time;
protected final LerpMode mode;
protected final T value;
protected final T pre;
protected T post;

public KeyFrame(FriendlyByteBuf byteBuf, Function<FriendlyByteBuf, T> decoder) {
this.time = byteBuf.readFloat();
this.mode = byteBuf.readEnum(LerpMode.class);
this.value = decoder.apply(byteBuf);
this.pre = decoder.apply(byteBuf);
this.post = decoder.apply(byteBuf);
}

public KeyFrame(float time, T obj, LerpMode mode) {
public KeyFrame(float time, T pre, T post, LerpMode mode) {
this.time = time;
this.value = obj;
this.pre = pre;
this.post = post;
this.mode = mode;
}

Expand All @@ -31,8 +34,12 @@ public LerpMode getMode() {
return mode;
}

public T getValue() {
return value;
public T getPre() {
return pre;
}

public T getPost() {
return post;
}

public void toNetwork(FriendlyByteBuf byteBuf) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ private static Quaternionf readValue(FriendlyByteBuf byteBuf) {
return byteBuf.readQuaternion();
}

public QuaternionKeyFrame(float time, Quaternionf obj, LerpMode mode) {
super(time, obj, mode);
public QuaternionKeyFrame(float time, Quaternionf pre, Quaternionf post, LerpMode mode) {
super(time, pre, post, mode);
}

@Override
public void toNetwork(FriendlyByteBuf byteBuf) {
super.toNetwork(byteBuf);
byteBuf.writeQuaternion(this.value);
byteBuf.writeQuaternion(this.pre);
byteBuf.writeQuaternion(this.post);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ public VariableKeyFrame(FriendlyByteBuf byteBuf) {
super(byteBuf, VariableHolder::decode);
}

public VariableKeyFrame(float time, VariableHolder obj, LerpMode mode) {
super(time, obj, mode);
public VariableKeyFrame(float time, VariableHolder pre, VariableHolder post, LerpMode mode) {
super(time, pre, post, mode);
}

@Override
public void toNetwork(FriendlyByteBuf byteBuf) {
super.toNetwork(byteBuf);
this.value.toNetwork(byteBuf);
this.pre.toNetwork(byteBuf);
this.post.toNetwork(byteBuf);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ private static Vector3f readValue(FriendlyByteBuf byteBuf) {
return byteBuf.readVector3f();
}

public VectorKeyFrame(float time, Vector3f obj, LerpMode mode) {
super(time, obj, mode);
public VectorKeyFrame(float time, Vector3f pre, Vector3f post, LerpMode mode) {
super(time, pre, post, mode);
}

@Override
public void toNetwork(FriendlyByteBuf byteBuf) {
super.toNetwork(byteBuf);
byteBuf.writeVector3f(this.value);
byteBuf.writeVector3f(this.pre);
byteBuf.writeVector3f(this.post);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package net.quepierts.simpleanimator.core.proxy;

import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.client.player.RemotePlayer;
import net.minecraft.resources.ResourceLocation;
import net.quepierts.simpleanimator.api.IAnimateHandler;
import net.quepierts.simpleanimator.core.animation.Animator;
import net.quepierts.simpleanimator.core.client.ClientAnimator;
import net.quepierts.simpleanimator.core.client.ClientAnimatorManager;
import net.quepierts.simpleanimator.core.client.ClientPlayerNavigator;
import net.quepierts.simpleanimator.core.config.ClientConfiguration;
import org.joml.Vector3f;

public class ClientProxy extends CommonProxy {
private final ClientPlayerNavigator navigator;
Expand Down Expand Up @@ -33,4 +40,12 @@ public void setup() {
public ClientConfiguration getClientConfiguration() {
return config;
}

public void example(AbstractClientPlayer player) {
Animator animator = ((IAnimateHandler) player).simpleanimator$getAnimator();
animator.play(ResourceLocation.fromNamespaceAndPath("id", "anim_name"));

ClientAnimator clientAnimator = (ClientAnimator) animator;
Vector3f name = clientAnimator.getVariable("name").getAsVector3f();
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ enabled_platforms=fabric,neoforge


archives_base_name=SimpleAnimator
mod_version=1.2.4
mod_version=1.2.5
maven_group=net.quepierts

architectury_version=${ARCHITECTURY_API_VERSION}
Expand Down
8 changes: 8 additions & 0 deletions neoforge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ architectury {
neoForge()
}

loom {
runs {
configureEach {
vmArgs.addAll "-XX:+IgnoreUnrecognizedVMOptions", "-XX:+AllowEnhancedClassRedefinition", "-XX:ReservedCodeCacheSize=484M", "-XX:NonNMethodCodeHeapSize=4M", "-XX:NonProfiledCodeHeapSize=240M", "-XX:ProfiledCodeHeapSize=240M"
}
}
}

configurations {
common {
canBeResolved = true
Expand Down

0 comments on commit 39f497c

Please sign in to comment.