Skip to content

Commit

Permalink
Time-based pose function
Browse files Browse the repository at this point in the history
  • Loading branch information
Trainguy9512 committed Feb 25, 2025
1 parent b259765 commit b6f7815
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static AnimationDataContainer of(JointSkeleton jointSkeleton){
return new AnimationDataContainer(jointSkeleton);
}

@Override
public JointSkeleton getJointSkeleton(){
return this.jointSkeleton;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.trainguy9512.animationoverhaul.animation.data.driver.Driver;
import com.trainguy9512.animationoverhaul.animation.data.key.AnimationDataKey;
import com.trainguy9512.animationoverhaul.animation.data.key.AnimationDriverKey;
import com.trainguy9512.animationoverhaul.animation.joint.JointSkeleton;
import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose;
import com.trainguy9512.animationoverhaul.animation.pose.sampler.PoseSampler;
import com.trainguy9512.animationoverhaul.animation.pose.sampler.Sampleable;
Expand Down Expand Up @@ -36,4 +37,9 @@ public interface PoseCalculationDataContainer {
*/
public <P extends PoseSampler & SampleableFromInput> AnimationPose sample(AnimationDataKey<P> poseSamplerKey, AnimationPose animationPose, float partialTicks);

/**
* Returns the joint skeleton for the data container.
*/
public JointSkeleton getJointSkeleton();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.trainguy9512.animationoverhaul.animation.pose.function;

import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose;
import org.jetbrains.annotations.NotNull;

public class CachedPoseFunction implements PoseFunction {
@Override
public @NotNull AnimationPose compute(FunctionInterpolationContext context) {
return null;
}

@Override
public void tick(FunctionEvaluationState context) {

}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
package com.trainguy9512.animationoverhaul.animation.pose.function;

import com.trainguy9512.animationoverhaul.animation.data.OnTickDataContainer;
import com.trainguy9512.animationoverhaul.animation.data.PoseCalculationDataContainer;
import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose;
import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public interface PoseFunction {

AnimationPose calculate(PoseFunction.FunctionContext functionContext);
@NotNull AnimationPose compute(PoseFunction.FunctionInterpolationContext context);

void tick(FunctionEvaluationState evaluationState);

public record FunctionEvaluationState(OnTickDataContainer dataContainer, boolean isRelevant, boolean shouldReset){
public static FunctionEvaluationState of(OnTickDataContainer dataContainer, boolean isRelevant, boolean shouldReset){
return new FunctionEvaluationState(dataContainer, isRelevant, shouldReset);
}

public FunctionEvaluationState modify(boolean isRelevant, boolean shouldReset){
return FunctionEvaluationState.of(this.dataContainer, isRelevant, shouldReset);
}
}


public interface FunctionContext {
PoseCalculationDataContainer getDataContainer();
float getPartialTicks();
public interface FunctionInterpolationContext {
PoseCalculationDataContainer dataContainer();
float partialTicks();
}


}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.trainguy9512.animationoverhaul.animation.pose.function;

import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose;
import org.jetbrains.annotations.NotNull;

import java.util.function.Function;

public class TimeBasedPoseFunction implements PoseFunction {

Function<FunctionEvaluationState, Float> playRateFunction;
Function<FunctionEvaluationState, Boolean> isPlayingFunction;

protected float timeTicksElapsed;
protected float playRate;
protected boolean isPlaying;

private TimeBasedPoseFunction(){
this.playRateFunction = (interpolationContext) -> 1f;
this.isPlayingFunction = (interpolationContext) -> true;
this.timeTicksElapsed = 0;
}

@Override
public @NotNull AnimationPose compute(FunctionInterpolationContext context) {
return AnimationPose.of(context.dataContainer().getJointSkeleton());
}

@Override
public void tick(FunctionEvaluationState evaluationState) {
if(evaluationState.isRelevant()){
this.playRate = playRateFunction.apply(evaluationState);
this.isPlaying = isPlayingFunction.apply(evaluationState);

if(evaluationState.shouldReset()){
this.timeTicksElapsed = 0;
}
if(this.isPlaying){
this.timeTicksElapsed += this.playRate;
}
}
}

protected float getInterpolatedTimeElapsed(FunctionInterpolationContext context){
return this.timeTicksElapsed - (1 - context.partialTicks()) * this.playRate;
}
}

0 comments on commit b6f7815

Please sign in to comment.