Skip to content

Commit

Permalink
Animation Variable Keys WIP. Probably won't compile rn
Browse files Browse the repository at this point in the history
  • Loading branch information
Trainguy9512 committed Mar 10, 2024
1 parent 14ac0d8 commit 096bb95
Show file tree
Hide file tree
Showing 14 changed files with 115 additions and 142 deletions.
@@ -1,7 +1,7 @@
package com.trainguy9512.animationoverhaul;


import com.trainguy9512.animationoverhaul.animation.data.LivingEntityAnimatorRegistry;
import com.trainguy9512.animationoverhaul.animation.LivingEntityAnimatorRegistry;
import com.trainguy9512.animationoverhaul.animation.data.TimelineGroupDataLoader;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
Expand Down
Expand Up @@ -3,7 +3,7 @@
import com.google.common.collect.Maps;
import com.mojang.blaze3d.vertex.PoseStack;
import com.trainguy9512.animationoverhaul.AnimationOverhaulMain;
import com.trainguy9512.animationoverhaul.animation.entity.LivingEntityAnimator;
import com.trainguy9512.animationoverhaul.animation.animator.entity.LivingEntityAnimator;
import com.trainguy9512.animationoverhaul.animation.pose.BakedAnimationPose;
import com.trainguy9512.animationoverhaul.animation.data.AnimationDataContainer;
import net.minecraft.client.model.EntityModel;
Expand Down
@@ -1,7 +1,7 @@
package com.trainguy9512.animationoverhaul.animation.data;
package com.trainguy9512.animationoverhaul.animation;

import com.google.common.collect.Maps;
import com.trainguy9512.animationoverhaul.animation.entity.LivingEntityAnimator;
import com.trainguy9512.animationoverhaul.animation.animator.entity.LivingEntityAnimator;
import net.minecraft.world.entity.EntityType;

import java.util.HashMap;
Expand Down
@@ -1,5 +1,7 @@
package com.trainguy9512.animationoverhaul.animation.entity;
package com.trainguy9512.animationoverhaul.animation.animator;

import com.trainguy9512.animationoverhaul.animation.animator.entity.LivingEntityAnimator;
import com.trainguy9512.animationoverhaul.animation.data.AnimationVariableKey;
import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose;
import com.trainguy9512.animationoverhaul.animation.pose.BakedAnimationPose;
import com.trainguy9512.animationoverhaul.animation.pose.sample.*;
Expand All @@ -16,7 +18,7 @@
import net.minecraft.world.item.ItemStack;
import org.joml.Vector3f;

public class FirstPersonPlayerAnimator extends LivingEntityAnimator<LocalPlayer, PlayerModel<LocalPlayer>, FirstPersonPlayerAnimator.FPPlayerLocators>{
public class FirstPersonPlayerAnimator extends LivingEntityAnimator<LocalPlayer, PlayerModel<LocalPlayer>, FirstPersonPlayerAnimator.FPPlayerLocators> {

public static FirstPersonPlayerAnimator INSTANCE = new FirstPersonPlayerAnimator();

Expand Down Expand Up @@ -64,16 +66,12 @@ public enum FPPlayerLocators {
public static final ResourceLocation ANIMATION_FP_PLAYER_IDLE = TimelineGroupData.getNativeResourceLocation(TimelineGroupData.FIRST_PERSON_PLAYER_KEY, "fp_player_idle");


public static final AnimationDataContainer.DataKey<Float> TIME_TEST = new AnimationDataContainer.DataKey<>("time_test", 0F);
public static final AnimationDataContainer.DataKey<Vector3f> CAMERA_ROTATION = new AnimationDataContainer.DataKey<>("camera_rotation", new Vector3f(0, 0, 0));
public static final AnimationDataContainer.DataKey<Vector3f> DAMPENED_CAMERA_ROTATION = new AnimationDataContainer.DataKey<>("camera_rotation", new Vector3f(0, 0, 0));
public static final AnimationDataContainer.DataKey<ItemStack> MAIN_HAND_ITEM = new AnimationDataContainer.DataKey<>("main_hand_item_stack", ItemStack.EMPTY);
public static final AnimationDataContainer.DataKey<Boolean> IS_ATTACKING = new AnimationDataContainer.DataKey<>("is_attacking", false);
public static final AnimationDataContainer.DataKey<Boolean> IS_USING_ITEM = new AnimationDataContainer.DataKey<>("is_using_item", false);
public static final AnimationDataContainer.DataKey<Boolean> IS_MINING = new AnimationDataContainer.DataKey<>("is_mining", false);
public static final AnimationDataContainer.DataKey<Float> WALK_WEIGHT = new AnimationDataContainer.DataKey<>("walk_weight", 0F);
public static final AnimationDataContainer.DataKey<Boolean> IS_FALLING = new AnimationDataContainer.DataKey<>("is_falling", false);
public static final AnimationDataContainer.DataKey<Boolean> IS_JUMPING = new AnimationDataContainer.DataKey<>("is_jumping", false);
public static final AnimationVariableKey<Float> TIME_TEST = AnimationVariableKey.of(() -> 0F).setDebugIdentifier("time_test").build();



public static final AnimationVariableKey<Vector3f> CAMERA_ROTATION = AnimationVariableKey.of(() -> new Vector3f(0, 0, 0)).setDebugIdentifier("camera_rotation").build();
public static final AnimationVariableKey<Vector3f> DAMPENED_CAMERA_ROTATION = AnimationVariableKey.of(() -> new Vector3f(0, 0, 0)).setDebugIdentifier("dampened_camera_rotation").build();

private static final AnimationSequencePlayer IDLE_SEQUENCE_PLAYER = AnimationSequencePlayer.of("idle_sequence_player", ANIMATION_FP_PLAYER_IDLE).setDefaultPlayRate(0F);
private static final AnimationSequencePlayer TEST_IDLE_SEQUENCE_PLAYER = AnimationSequencePlayer.of("test_idle_sequence_player", ANIMATION_FP_PLAYER_IDLE).setDefaultPlayRate(1F).setStartTime(70);
Expand Down Expand Up @@ -188,7 +186,7 @@ protected LocatorSkeleton<FPPlayerLocators> buildRig() {
@Override
protected AnimationPose<FPPlayerLocators> calculatePose() {
// Update main hand item based on the anim notify
setEntityAnimationVariable(MAIN_HAND_ITEM, this.livingEntity.getMainHandItem().copy());
//setEntityAnimationVariable(MAIN_HAND_ITEM, this.livingEntity.getMainHandItem().copy());
/*
if(getAnimationState(MAIN_EMPTY_LOWER_SEQUENCE_PLAYER).isAnimNotityActive(ITEM_SWITCH_NOTIFY)){
setEntityAnimationVariable(MAIN_HAND_ITEM, this.livingEntity.getMainHandItem().copy());
Expand Down Expand Up @@ -483,7 +481,7 @@ public void tickExternal(){
this.localBakedPose.setPose(new AnimationPose(animationPose));
}

private boolean compareVariableItemStackWithEntityItemStack(AnimationDataContainer.DataKey<ItemStack> itemStackDataKey, ItemStack entityItemStack){
private boolean compareVariableItemStackWithEntityItemStack(AnimationVariableKey<ItemStack> itemStackDataKey, ItemStack entityItemStack){
ItemStack currentItemStack = getEntityAnimationVariable(itemStackDataKey);
if(currentItemStack.getItem() != null && entityItemStack.getItem() == null || currentItemStack.getItem() == null && entityItemStack.getItem() != null) {
return true;
Expand Down
@@ -1,8 +1,9 @@
package com.trainguy9512.animationoverhaul.animation.entity;
package com.trainguy9512.animationoverhaul.animation.animator.entity;

import com.mojang.blaze3d.vertex.PoseStack;
import com.trainguy9512.animationoverhaul.access.ModelAccess;
import com.trainguy9512.animationoverhaul.animation.AnimatorDispatcher;
import com.trainguy9512.animationoverhaul.animation.data.AnimationVariableKey;
import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose;
import com.trainguy9512.animationoverhaul.animation.pose.BakedAnimationPose;
import com.trainguy9512.animationoverhaul.animation.pose.sample.*;
Expand Down Expand Up @@ -54,15 +55,15 @@ protected AnimationDataContainer getEntityAnimationData(){
return this.entityAnimationData;
}

protected <D> AnimationDataContainer.AnimationVariable<D> getEntityAnimationVariableObject(AnimationDataContainer.DataKey<D> dataKey){
protected <D> AnimationDataContainer.AnimationVariable<D> getEntityAnimationVariableObject(AnimationVariableKey<D> dataKey){
return getEntityAnimationData().get(dataKey);
}

protected <D> D getEntityAnimationVariable(AnimationDataContainer.DataKey<D> dataKey){
protected <D> D getEntityAnimationVariable(AnimationVariableKey<D> dataKey){
return getEntityAnimationVariableObject(dataKey).get();
}

protected <D> void setEntityAnimationVariable(AnimationDataContainer.DataKey<D> dataKey, D value){
protected <D> void setEntityAnimationVariable(AnimationVariableKey<D> dataKey, D value){
getEntityAnimationData().setValue(dataKey, value);
}

Expand Down
@@ -1,4 +1,4 @@
package com.trainguy9512.animationoverhaul.animation.entity;
package com.trainguy9512.animationoverhaul.animation.animator.entity;

import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose;
import com.trainguy9512.animationoverhaul.util.animation.LocatorSkeleton;
Expand Down
@@ -1,4 +1,4 @@
package com.trainguy9512.animationoverhaul.animation.entity;
package com.trainguy9512.animationoverhaul.animation.animator.entity;

/*
public class PlayerPartAnimatorOld extends LivingEntityPartAnimator<Player, PlayerModel<Player>> {
Expand Down
@@ -1,23 +1,26 @@
package com.trainguy9512.animationoverhaul.animation.data;

import com.google.common.collect.Maps;
import com.trainguy9512.animationoverhaul.AnimationOverhaulMain;
import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose;
import com.trainguy9512.animationoverhaul.animation.pose.sample.*;
import com.trainguy9512.animationoverhaul.util.animation.LocatorSkeleton;
import com.trainguy9512.animationoverhaul.util.time.Easing;
import com.trainguy9512.animationoverhaul.util.time.TickTimeUtils;
import net.minecraft.util.Mth;
import org.jetbrains.annotations.NotNull;

import java.util.*;
import java.util.function.Supplier;

public class AnimationDataContainer {

private final HashMap<DataKey<?>, AnimationVariable<?>> entityAnimationVariables;
private final HashMap<AnimationVariableKey<?>, AnimationVariable<?>> animationVariables;
private final HashMap<String, SampleableAnimationState> entitySampleableAnimationStates;
private final CachedPoseContainer cachedPoseContainer = new CachedPoseContainer();

public AnimationDataContainer(){
this.entityAnimationVariables = Maps.newHashMap();
this.animationVariables = Maps.newHashMap();
this.entitySampleableAnimationStates = Maps.newHashMap();
}

Expand Down Expand Up @@ -83,72 +86,38 @@ public AnimationPose<?> getCachedPose(String identifier, LocatorSkeleton<?> loca
}
}

public <D> AnimationVariable<D> get(DataKey<D> dataKey){
if(!entityAnimationVariables.containsKey(dataKey)){
entityAnimationVariables.put(dataKey, new AnimationVariable<>(dataKey));
public <D> AnimationVariable<D> get(AnimationVariableKey<D> dataKey){
if(!animationVariables.containsKey(dataKey)){
animationVariables.put(dataKey, new AnimationVariable<>(dataKey));
}
return (AnimationVariable<D>) entityAnimationVariables.get(dataKey);
return (AnimationVariable<D>) animationVariables.get(dataKey);
}

public TreeMap<String, AnimationVariable<?>> getDebugData(){
TreeMap<String, AnimationVariable<?>> finalList = Maps.newTreeMap();
for(DataKey<?> dataKey : this.entityAnimationVariables.keySet()){
AnimationVariable<?> data = entityAnimationVariables.get(dataKey);
for(AnimationVariableKey<?> dataKey : this.animationVariables.keySet()){
AnimationVariable<?> data = animationVariables.get(dataKey);

String[] typeSplitted = data.get().getClass().toString().split("\\.");
String type = typeSplitted[typeSplitted.length - 1];

typeSplitted = type.split("\\$");
type = typeSplitted[typeSplitted.length - 1];

String debugIdentifier = dataKey.getIdentifier() + " (" + type + "):";
String debugIdentifier = dataKey.getDebugIdentifier() + " (" + type + "):";
finalList.put(debugIdentifier, data);
}
return finalList;
}

public <D> void setValue(DataKey<D> dataKey, D value){
public <D> void setValue(AnimationVariableKey<D> dataKey, D value){
this.get(dataKey).set(value);
}

public <D> D getValue(DataKey<D> dataKey){
public <D> D getValue(AnimationVariableKey<D> dataKey){
return this.get(dataKey).get();
}

/**
* Obtains a float value by linearly interpolating the current and old values
*
* @param dataKey Float data key
* @param partialTicks Time in ticks since the last full tick
* @return Final interpolated float
*/
public float getLerped(DataKey<Float> dataKey, float partialTicks){
return Mth.lerp(partialTicks, this.get(dataKey).getOld(), this.get(dataKey).get());
}

/**
* Obtains a float value by interpolating the current and old values and then applying an easing
*
* @param dataKey Float data key
* @param easing Easing object to apply the lerped float value onto
* @param partialTicks Time in ticks since the last full tick
* @return Final eased float
*/
public float getEased(DataKey<Float> dataKey, Easing easing, float partialTicks){
return easing.ease(this.getLerped(dataKey, partialTicks));
}

public float getEased(DataKey<Float> dataKey, Easing easing){
return getEased(dataKey, easing, 1);
}

public float getDataValueEasedQuad(AnimationDataContainer.DataKey<Float> dataKey){
return getEased(dataKey, Easing.CubicBezier.bezierInOutQuad());
}

public float getDataValueEasedCondition(AnimationDataContainer.DataKey<Float> dataKey, Easing easing1, Easing easing2, boolean condition){
return getEased(dataKey, condition ? easing1 : easing2);
}

/**
* Increments a float value based on a condition, incremented in ticks
Expand All @@ -158,34 +127,21 @@ public float getDataValueEasedCondition(AnimationDataContainer.DataKey<Float> da
* @param ticksToIncrement Time in ticks to increment from 0 to 1
* @param ticksToDecrement Time in ticks to decrement from 1 to 0
*/
public void incrementInTicksFromCondition(DataKey<Float> dataKey, boolean condition, float ticksToIncrement, float ticksToDecrement){
public void incrementInTicksFromCondition(AnimationVariableKey<Float> dataKey, boolean condition, float ticksToIncrement, float ticksToDecrement){
ticksToIncrement = Math.max(1, ticksToIncrement);
ticksToDecrement = Math.max(1, ticksToDecrement);
AnimationVariable<Float> data = this.get(dataKey);
data.set(Mth.clamp((data.get()) + (condition ? 1/ticksToIncrement : -1/ticksToDecrement), 0, 1));
}

/**
* Increments a float value based on a condition, incremented in frames
*
* @param dataKey Float data key
* @param condition Boolean condition to decide whether the value should increment or decrement
* @param framesToIncrement Time in frames to increment from 0 to 1
* @param framesToDecrement Time in frames to decrement from 1 to 0
*/
@Deprecated
public void incrementInFramesFromCondition(DataKey<Float> dataKey, boolean condition, float framesToIncrement, float framesToDecrement){
this.incrementInTicksFromCondition(dataKey, condition, TickTimeUtils.ticksFromMayaFrames(framesToIncrement), TickTimeUtils.ticksFromMayaFrames(framesToDecrement));
}

/**
* Increments or resets a value based on a condition, incremented in ticks
*
* @param dataKey Float data key
* @param condition Boolean condition to decide whether the value should reset to 0 or increment
* @param ticksToIncrement Time in ticks to increment from 0 to 1
*/
public void incrementInTicksOrResetFromCondition(DataKey<Float> dataKey, boolean condition, float ticksToIncrement){
public void incrementInTicksOrResetFromCondition(AnimationVariableKey<Float> dataKey, boolean condition, float ticksToIncrement){
AnimationVariable<Float> data = this.get(dataKey);
if(condition){
data.set(0F);
Expand All @@ -195,18 +151,6 @@ public void incrementInTicksOrResetFromCondition(DataKey<Float> dataKey, boolean
}
}

/**
* Increments or resets a value based on a condition, incremented in frames
*
* @param dataKey Float data key
* @param condition Boolean condition to decide whether the value should reset to 0 or increment
* @param framesToIncrement Time in frames to increment from 0 to 1
*/
@Deprecated
public void incrementInFramesOrResetFromCondition(DataKey<Float> dataKey, boolean condition, float framesToIncrement){
this.incrementInTicksOrResetFromCondition(dataKey, condition, TickTimeUtils.ticksFromMayaFrames(framesToIncrement));
}

/**
* Increments or resets a value based on a condition, incremented in ticks
*
Expand All @@ -217,7 +161,7 @@ public void incrementInFramesOrResetFromCondition(DataKey<Float> dataKey, boolea
* @param ticksToIncrement Time in ticks to increment from 0 to 1
* @param random Java random object used to pick a random index within numberOfAnimations
*/
public void incrementInTicksOrResetRandomFromCondition(DataKey<Float> dataKeyMain, DataKey<Integer> dataKeyIndex, int numberOfAnimations, boolean condition, float ticksToIncrement, Random random){
public void incrementInTicksOrResetRandomFromCondition(AnimationVariableKey<Float> dataKeyMain, AnimationVariableKey<Integer> dataKeyIndex, int numberOfAnimations, boolean condition, float ticksToIncrement, Random random){
AnimationVariable<Float> dataMain = this.get(dataKeyMain);
AnimationVariable<Integer> dataIndex = this.get(dataKeyIndex);
if(condition){
Expand All @@ -229,20 +173,7 @@ public void incrementInTicksOrResetRandomFromCondition(DataKey<Float> dataKeyMai
}
}

/**
* Increments or resets a value based on a condition, incremented in frames
*
* @param dataKeyMain Main float data key
* @param dataKeyIndex Index data key
* @param numberOfAnimations Number of animations to pick from
* @param condition Boolean condition to decide whether the value should reset to 0 or increment
* @param framesToIncrement Time in frames to increment from 0 to 1
* @param random Java random object used to pick a random index within numberOfAnimations
*/
public void incrementInFramesOrResetRandomFromCondition(DataKey<Float> dataKeyMain, DataKey<Integer> dataKeyIndex, int numberOfAnimations, boolean condition, float framesToIncrement, Random random){
incrementInTicksOrResetRandomFromCondition(dataKeyMain, dataKeyIndex, numberOfAnimations, condition, framesToIncrement / 1.2F, random);
}

/*
public static class DataKey<D>{
private final String identifier;
Expand All @@ -258,16 +189,19 @@ public String getIdentifier(){
}
}
*/


public static class AnimationVariable<D>{

private D value;
private D valueOld;
private final D defaultValue;
private final Supplier<D> defaultValue;

public AnimationVariable(DataKey<D> dataKey){
this.value = dataKey.defaultValue;
this.valueOld = dataKey.defaultValue;
this.defaultValue = dataKey.defaultValue;
private AnimationVariable(AnimationVariableKey<D> dataKey){
this.defaultValue = dataKey.getDefaultValue();
this.value = dataKey.getDefaultValue().get();
this.valueOld = dataKey.getDefaultValue().get();
}

public D get(){
Expand All @@ -283,11 +217,15 @@ public void set(D value){
if(value != null){
this.value = value;
} else {
this.value = defaultValue;
this.value = defaultValue.get();
}
}

private boolean isFloat(){
public void setDefaultValue(){
this.set(this.defaultValue.get());
}

public boolean isFloat(){
return this.value instanceof Float;
}
}
Expand Down

This file was deleted.

0 comments on commit 096bb95

Please sign in to comment.