From 83725fbc77d122e79985f39144a97aad0166d8dc Mon Sep 17 00:00:00 2001 From: Trainguy9512 Date: Tue, 12 Mar 2024 03:56:57 -0500 Subject: [PATCH] Big WIP on restructuring everything --- .../AnimationOverhaulMain.java | 4 +- .../access/LivingEntityAccess.java | 6 +- .../animation/AnimatorDispatcher.java | 70 --- .../EntityJointAnimatorDispatcher.java | 124 +++++ .../LivingEntityAnimatorRegistry.java | 8 +- .../animator/FirstPersonPlayerAnimator.java | 496 ------------------ .../FirstPersonPlayerJointAnimator.java | 307 +++++++++++ .../animation/animator/JointAnimator.java | 25 + .../animator/entity/EntityJointAnimator.java | 70 +++ .../animator/entity/LivingEntityAnimator.java | 147 ------ .../entity/LivingEntityJointAnimator.java | 16 + ...Animator.java => PlayerJointAnimator.java} | 21 +- .../data/AnimationDataContainer.java | 42 +- .../animation/pose/AnimationPose.java | 26 +- .../animation/pose/BakedAnimationPose.java | 2 +- .../sample/AnimationBlendSpacePlayer.java | 22 +- .../pose/sample/AnimationMontage.java | 6 +- .../pose/sample/AnimationMontageTrack.java | 20 +- .../pose/sample/AnimationSequencePlayer.java | 8 +- .../pose/sample/AnimationStateMachine.java | 20 +- .../animation/pose/sample/PoseSampler.java | 31 ++ .../pose/sample/SampleableAnimationState.java | 31 -- .../pose/sample/TestReferenceSampler.java | 8 +- ...onState.java => TimeBasedPoseSampler.java} | 4 +- .../mixin/MixinElytraLayer.java | 4 +- .../mixin/MixinGameRenderer.java | 23 +- .../mixin/MixinItemInHandRenderer.java | 22 +- .../mixin/MixinLivingEntityRenderer.java | 8 +- .../mixin/MixinMinecraft.java | 14 +- ...ocatorSkeleton.java => JointSkeleton.java} | 24 +- 30 files changed, 721 insertions(+), 888 deletions(-) delete mode 100644 src/main/java/com/trainguy9512/animationoverhaul/animation/AnimatorDispatcher.java create mode 100644 src/main/java/com/trainguy9512/animationoverhaul/animation/EntityJointAnimatorDispatcher.java delete mode 100644 src/main/java/com/trainguy9512/animationoverhaul/animation/animator/FirstPersonPlayerAnimator.java create mode 100644 src/main/java/com/trainguy9512/animationoverhaul/animation/animator/FirstPersonPlayerJointAnimator.java create mode 100644 src/main/java/com/trainguy9512/animationoverhaul/animation/animator/JointAnimator.java create mode 100644 src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/EntityJointAnimator.java delete mode 100644 src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/LivingEntityAnimator.java create mode 100644 src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/LivingEntityJointAnimator.java rename src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/{PlayerPartAnimator.java => PlayerJointAnimator.java} (87%) create mode 100644 src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/PoseSampler.java delete mode 100644 src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/SampleableAnimationState.java rename src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/{TimeBasedAnimationState.java => TimeBasedPoseSampler.java} (94%) rename src/main/java/com/trainguy9512/animationoverhaul/util/animation/{LocatorSkeleton.java => JointSkeleton.java} (92%) diff --git a/src/main/java/com/trainguy9512/animationoverhaul/AnimationOverhaulMain.java b/src/main/java/com/trainguy9512/animationoverhaul/AnimationOverhaulMain.java index d020cb2..43c807d 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/AnimationOverhaulMain.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/AnimationOverhaulMain.java @@ -2,11 +2,13 @@ import com.trainguy9512.animationoverhaul.animation.LivingEntityAnimatorRegistry; +import com.trainguy9512.animationoverhaul.animation.animator.entity.PlayerJointAnimator; import com.trainguy9512.animationoverhaul.animation.data.TimelineGroupDataLoader; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.resource.ResourceManagerHelper; import net.minecraft.server.packs.PackType; import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -53,7 +55,7 @@ public void onInitialize() { private static void registerEntityAnimators(){ - //ENTITY_ANIMATORS.register(EntityType.PLAYER, new PlayerPartAnimator()); + ENTITY_ANIMATORS.register(EntityType.PLAYER, new PlayerJointAnimator()); } /* diff --git a/src/main/java/com/trainguy9512/animationoverhaul/access/LivingEntityAccess.java b/src/main/java/com/trainguy9512/animationoverhaul/access/LivingEntityAccess.java index d18a714..1e819a9 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/access/LivingEntityAccess.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/access/LivingEntityAccess.java @@ -1,6 +1,6 @@ package com.trainguy9512.animationoverhaul.access; -import com.trainguy9512.animationoverhaul.util.animation.LocatorSkeleton; +import com.trainguy9512.animationoverhaul.util.animation.JointSkeleton; import net.minecraft.core.BlockPos; public interface LivingEntityAccess { @@ -16,6 +16,6 @@ public interface LivingEntityAccess { boolean getUseInventoryRenderer(); void setUseInventoryRenderer(boolean bool); - LocatorSkeleton getLocatorRig(); - void storeLocatorRig(LocatorSkeleton locatorRig); + JointSkeleton getLocatorRig(); + void storeLocatorRig(JointSkeleton locatorRig); } diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/AnimatorDispatcher.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/AnimatorDispatcher.java deleted file mode 100644 index 44338bb..0000000 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/AnimatorDispatcher.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.trainguy9512.animationoverhaul.animation; - -import com.google.common.collect.Maps; -import com.mojang.blaze3d.vertex.PoseStack; -import com.trainguy9512.animationoverhaul.AnimationOverhaulMain; -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; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.LivingEntity; -import org.jetbrains.annotations.Nullable; - -import java.util.HashMap; -import java.util.UUID; - -public class AnimatorDispatcher { - public static final AnimatorDispatcher INSTANCE = new AnimatorDispatcher(); - - private final HashMap entityAnimationDataMap = Maps.newHashMap(); - private final HashMap> bakedPoseMap = Maps.newHashMap(); - - public AnimatorDispatcher(){ - } - - public void tickEntity(LivingEntity livingEntity, LivingEntityAnimator livingEntityPartAnimator){ - if(!entityAnimationDataMap.containsKey(livingEntity.getUUID())){ - entityAnimationDataMap.put(livingEntity.getUUID(), new AnimationDataContainer()); - } - livingEntityPartAnimator.tick(livingEntity); - } - - public , L extends Enum> boolean animateEntity(T livingEntity, M entityModel, PoseStack poseStack, float partialTicks){ - if(entityAnimationDataMap.containsKey(livingEntity.getUUID())){ - if(AnimationOverhaulMain.ENTITY_ANIMATORS.contains(livingEntity.getType())){ - LivingEntityAnimator livingEntityPartAnimator = (LivingEntityAnimator) AnimationOverhaulMain.ENTITY_ANIMATORS.get(livingEntity.getType()); - livingEntityPartAnimator.applyBakedPose(livingEntity, entityModel, poseStack, entityAnimationDataMap.get(livingEntity.getUUID()), partialTicks); - return true; - } - } - return false; - } - - public void saveBakedPose(UUID uuid, BakedAnimationPose bakedPose){ - this.bakedPoseMap.put(uuid, bakedPose); - } - - @Nullable - public > BakedAnimationPose getBakedPose(UUID uuid){ - if(this.bakedPoseMap.containsKey(uuid)){ - return (BakedAnimationPose) this.bakedPoseMap.get(uuid); - } - return null; - } - - public boolean hasAnimationData(UUID uuid){ - return this.entityAnimationDataMap.containsKey(uuid); - } - - public AnimationDataContainer getEntityAnimationData(UUID uuid){ - if(entityAnimationDataMap.containsKey(uuid)){ - return entityAnimationDataMap.get(uuid); - } - return new AnimationDataContainer(); - } - - public AnimationDataContainer getEntityAnimationData(T entity){ - return getEntityAnimationData(entity.getUUID()); - } -} diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/EntityJointAnimatorDispatcher.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/EntityJointAnimatorDispatcher.java new file mode 100644 index 0000000..6b8b422 --- /dev/null +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/EntityJointAnimatorDispatcher.java @@ -0,0 +1,124 @@ +package com.trainguy9512.animationoverhaul.animation; + +import com.google.common.collect.Maps; +import com.mojang.blaze3d.vertex.PoseStack; +import com.trainguy9512.animationoverhaul.AnimationOverhaulMain; +import com.trainguy9512.animationoverhaul.animation.animator.entity.EntityJointAnimator; +import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; +import com.trainguy9512.animationoverhaul.animation.pose.BakedAnimationPose; +import com.trainguy9512.animationoverhaul.animation.data.AnimationDataContainer; +import com.trainguy9512.animationoverhaul.util.animation.JointSkeleton; +import net.minecraft.client.model.EntityModel; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.world.entity.Entity; + +import java.util.HashMap; +import java.util.UUID; + +public class EntityJointAnimatorDispatcher { + public static final EntityJointAnimatorDispatcher INSTANCE = new EntityJointAnimatorDispatcher(); + + private final HashMap entityAnimationDataMap = Maps.newHashMap(); + private final HashMap> bakedPoseMap = Maps.newHashMap(); + + public EntityJointAnimatorDispatcher(){ + } + + public > void tickEntity(T entity, EntityJointAnimator entityJointAnimator){ + + UUID entityUUID = entity.getUUID(); + if(!entityAnimationDataMap.containsKey(entityUUID)){ + entityAnimationDataMap.put(entityUUID, new AnimationDataContainer()); + } + + BakedAnimationPose bakedPose = (BakedAnimationPose) INSTANCE.getBakedPose(entityUUID); + AnimationDataContainer animationDataContainer = EntityJointAnimatorDispatcher.INSTANCE.getEntityAnimationDataReference(entityUUID); + JointSkeleton jointSkeleton = (JointSkeleton) entityJointAnimator.getJointSkeleton(); + + // First tick the entity part animator + entityJointAnimator.tick(entity, animationDataContainer); + + animationDataContainer.tickAnimationStates(); + + + /* + if(bakedPose == null){ + bakedPose = new BakedAnimationPose<>(); + } + */ + if(!bakedPose.hasPose){ + bakedPose.setPose(AnimationPose.of(jointSkeleton)); + bakedPose.hasPose = true; + } + bakedPose.pushToOld(); + + + AnimationPose calculatedAnimationPose = entityJointAnimator.calculatePose(entity, animationDataContainer); + if (calculatedAnimationPose == null){ + calculatedAnimationPose = AnimationPose.of(jointSkeleton); + } + calculatedAnimationPose.convertSpaceEntityToLocal(); + + //TODO: Rewrite how pose offsets are done + calculatedAnimationPose.applyDefaultPoseOffset(); + + bakedPose.setPose(new AnimationPose(calculatedAnimationPose)); + + //TODO: Should this be a reference to the static instance and not itself? + EntityJointAnimatorDispatcher.INSTANCE.saveBakedPose(entityUUID, bakedPose); + + + //livingEntityPartAnimator.overallTick(livingEntity); + } + + public , L extends Enum> boolean animateEntity(T livingEntity, M entityModel, PoseStack poseStack, float partialTicks){ + if(entityAnimationDataMap.containsKey(livingEntity.getUUID())){ + if(AnimationOverhaulMain.ENTITY_ANIMATORS.contains(livingEntity.getType())){ + EntityJointAnimator entityJointAnimator = (EntityJointAnimator) AnimationOverhaulMain.ENTITY_ANIMATORS.get(livingEntity.getType()); + applyBakedPose(livingEntity, entityModel, entityJointAnimator, partialTicks); + return true; + } + } + return false; + } + + private , L extends Enum> void applyBakedPose(T entity, M entityModel, EntityJointAnimator entityJointAnimator, float partialTicks){ + BakedAnimationPose bakedPose = EntityJointAnimatorDispatcher.INSTANCE.getBakedPose(entity.getUUID()); + + if(bakedPose != null){ + ModelPart rootModelPart = entityJointAnimator.getRoot(entityModel); + + bakedPose.bakeToModelParts(rootModelPart, partialTicks); + entityJointAnimator.finalizeModelParts(entityModel, rootModelPart); + } + } + + public > void saveBakedPose(UUID uuid, BakedAnimationPose bakedPose){ + this.bakedPoseMap.put(uuid, bakedPose); + } + + public BakedAnimationPose getBakedPose(UUID uuid){ + return this.bakedPoseMap.getOrDefault(uuid, new BakedAnimationPose<>()); + /* + if(this.bakedPoseMap.containsKey(uuid)){ + return this.bakedPoseMap.get(uuid); + } + return null; + */ + } + + public boolean hasAnimationData(UUID uuid){ + return this.entityAnimationDataMap.containsKey(uuid); + } + + public AnimationDataContainer getEntityAnimationDataReference(UUID uuid){ + if(entityAnimationDataMap.containsKey(uuid)){ + return entityAnimationDataMap.get(uuid); + } + return new AnimationDataContainer(); + } + + public AnimationDataContainer getEntityAnimationData(T entity){ + return getEntityAnimationDataReference(entity.getUUID()); + } +} diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/LivingEntityAnimatorRegistry.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/LivingEntityAnimatorRegistry.java index 0ff23e0..2549d2e 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/LivingEntityAnimatorRegistry.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/LivingEntityAnimatorRegistry.java @@ -1,19 +1,19 @@ package com.trainguy9512.animationoverhaul.animation; import com.google.common.collect.Maps; -import com.trainguy9512.animationoverhaul.animation.animator.entity.LivingEntityAnimator; +import com.trainguy9512.animationoverhaul.animation.animator.entity.EntityJointAnimator; import net.minecraft.world.entity.EntityType; import java.util.HashMap; public class LivingEntityAnimatorRegistry { - private final HashMap, LivingEntityAnimator> livingEntityPartAnimatorHashMap = Maps.newHashMap(); + private final HashMap, EntityJointAnimator> livingEntityPartAnimatorHashMap = Maps.newHashMap(); public LivingEntityAnimatorRegistry(){ } - public void register(EntityType entityType, LivingEntityAnimator livingEntityPartAnimator){ + public void register(EntityType entityType, EntityJointAnimator livingEntityPartAnimator){ livingEntityPartAnimatorHashMap.put(entityType, livingEntityPartAnimator); } @@ -21,7 +21,7 @@ public boolean contains(EntityType entityType){ return livingEntityPartAnimatorHashMap.containsKey(entityType); } - public LivingEntityAnimator get(EntityType entityType){ + public EntityJointAnimator get(EntityType entityType){ return livingEntityPartAnimatorHashMap.get(entityType); } } diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/FirstPersonPlayerAnimator.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/FirstPersonPlayerAnimator.java deleted file mode 100644 index 7ba3883..0000000 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/FirstPersonPlayerAnimator.java +++ /dev/null @@ -1,496 +0,0 @@ -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.*; -import com.trainguy9512.animationoverhaul.util.animation.LocatorSkeleton; -import com.trainguy9512.animationoverhaul.animation.data.AnimationDataContainer; -import com.trainguy9512.animationoverhaul.animation.data.TimelineGroupData; -import net.minecraft.client.Minecraft; -import net.minecraft.client.model.PlayerModel; -import net.minecraft.client.model.geom.PartPose; -import net.minecraft.client.player.LocalPlayer; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.Mth; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.item.ItemStack; -import org.joml.Vector3f; - -public class FirstPersonPlayerAnimator extends LivingEntityAnimator, FirstPersonPlayerAnimator.FPPlayerLocators> { - - public static FirstPersonPlayerAnimator INSTANCE = new FirstPersonPlayerAnimator(); - - public AnimationDataContainer localAnimationDataContainer = new AnimationDataContainer(); - public BakedAnimationPose localBakedPose; - - - public enum FPPlayerLocators { - root, - camera, - armBuffer, - rightArmBuffer, - leftArmBuffer, - rightArm, - leftArm, - rightHand, - leftHand; - - public static final FPPlayerLocators[] arms = new FPPlayerLocators[] { - rightArm, - leftArm, - rightArmBuffer, - leftArmBuffer, - rightHand, - leftHand - }; - - public static final FPPlayerLocators[] armBufferLocators = new FPPlayerLocators[] { - rightArmBuffer, - leftArmBuffer - }; - - public static final FPPlayerLocators[] armPoseLocators = new FPPlayerLocators[] { - rightArm, - leftArm - }; - - public static final FPPlayerLocators[] handLocators = new FPPlayerLocators[] { - rightHand, - leftHand - }; - } - - - public static final ResourceLocation ANIMATION_FP_PLAYER_IDLE = TimelineGroupData.getNativeResourceLocation(TimelineGroupData.FIRST_PERSON_PLAYER_KEY, "fp_player_idle"); - - - public static final AnimationVariableKey TIME_TEST = AnimationVariableKey.of(() -> 0F).setDebugIdentifier("time_test").build(); - - - - public static final AnimationVariableKey CAMERA_ROTATION = AnimationVariableKey.of(() -> new Vector3f(0, 0, 0)).setDebugIdentifier("camera_rotation").build(); - public static final AnimationVariableKey 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); - - - - enum TestStates { - IDLE, - MOVING - } - - - - - - - /* - enum ItemSwitchStates { - EMPTY, - EMPTY_RAISING, - BASIC_ITEM, - BASIC_ITEM_RAISING, - LOWERING - } - private static final AnimationStateMachine MAINHAND_ITEMSWITCH_STATE_MACHINE = AnimationStateMachine.of("main_hand_state_machine", ItemSwitchStates.values()) - .addStateTransition(ItemSwitchStates.EMPTY, ItemSwitchStates.LOWERING, 2) - .addStateTransition(ItemSwitchStates.LOWERING, ItemSwitchStates.EMPTY_RAISING, 1, 2) - .addStateTransition(ItemSwitchStates.EMPTY_RAISING, ItemSwitchStates.EMPTY, 2) - .addStateTransition(ItemSwitchStates.BASIC_ITEM, ItemSwitchStates.LOWERING, 2) - .addStateTransition(ItemSwitchStates.LOWERING, ItemSwitchStates.BASIC_ITEM_RAISING, 1, 1) - .addStateTransition(ItemSwitchStates.BASIC_ITEM_RAISING, ItemSwitchStates.BASIC_ITEM, 2); - - - - enum JumpingStates { - JUMPING, - FALLING, - LANDING, - ON_GROUND - } - private static final AnimationStateMachine JUMP_STATE_MACHINE = AnimationStateMachine.of("jump_state_machine", JumpingStates.values()) - .addStateTransition(JumpingStates.ON_GROUND, JumpingStates.JUMPING, 1, 1) - .addStateTransition(JumpingStates.ON_GROUND, JumpingStates.FALLING, 3, 2) - .addStateTransition(JumpingStates.JUMPING, JumpingStates.FALLING, 4, 1) - .addStateTransition(JumpingStates.JUMPING, JumpingStates.LANDING, 1, 2) - .addStateTransition(JumpingStates.FALLING, JumpingStates.LANDING, 1, 1) - .addStateTransition(JumpingStates.LANDING, JumpingStates.JUMPING, 1, 2) - .addStateTransition(JumpingStates.LANDING, JumpingStates.FALLING, 3, 3) - .addStateTransition(JumpingStates.LANDING, JumpingStates.ON_GROUND, 4, 1); - - - enum MiningStates { - IDLE, - BEGIN, - LOOPING - } - private static final AnimationStateMachine MINING_STATE_MACHINE = AnimationStateMachine.of("mining_state_machine", MiningStates.values()) - .addStateTransition(MiningStates.IDLE, MiningStates.BEGIN, 2) - .addStateTransition(MiningStates.BEGIN, MiningStates.LOOPING, 1) - .addStateTransition(MiningStates.BEGIN, MiningStates.IDLE, 2) - .addStateTransition(MiningStates.LOOPING, MiningStates.IDLE, 2); - - - */ - - - private static final AnimationMontageTrack MAIN_HAND_EMPTY_PUNCH_MONTAGE_TRACK = AnimationMontageTrack.of("main_hand_empty_punch_montage_track"); - /* - private static final AnimationMontage MAIN_HAND_EMPTY_PUNCH_MONTAGE = AnimationMontage.of(ANIMATION_FP_RIGHT_EMPTY_PUNCH) - .setLength(TickTimeUtils.ticksFromMayaFrames(10F)) - .setBlendInDuration(1) - .setBlendOutDuration(TickTimeUtils.ticksFromMayaFrames(8F)); - private static final AnimationMontage MAIN_HAND_EMPTY_USE_ITEM_MONTAGE = AnimationMontage.of(ANIMATION_FP_RIGHT_EMPTY_USE_ITEM) - .setLength(TickTimeUtils.ticksFromMayaFrames(9F)) - .setBlendInDuration(1) - .setBlendOutDuration(TickTimeUtils.ticksFromMayaFrames(5F)); - - */ - - - - /* - private static final AnimationBlendSpacePlayer MAIN_HAND_EMPTY_WALK_BLENDSPACE_PLAYER = AnimationBlendSpacePlayer.of("main_hand_empty_walk_blendspace_player") - .addEntry(0, ANIMATION_FP_RIGHT_EMPTY_WALK, 0F) - .addEntry(2, ANIMATION_FP_RIGHT_EMPTY_WALK, 2.9F); - - */ - - - public FirstPersonPlayerAnimator(){ - super(); - } - - @Override - protected LocatorSkeleton buildRig() { - return LocatorSkeleton.of(FPPlayerLocators.root) - .addChildLocator(FPPlayerLocators.camera) - .addChildLocator(FPPlayerLocators.armBuffer) - .addChildLocator(FPPlayerLocators.leftArmBuffer, FPPlayerLocators.armBuffer) - .addChildLocator(FPPlayerLocators.rightArmBuffer, FPPlayerLocators.armBuffer) - .addChildLocator(FPPlayerLocators.leftArm, FPPlayerLocators.leftArmBuffer) - .addChildLocator(FPPlayerLocators.rightArm, FPPlayerLocators.rightArmBuffer) - .addChildLocator(FPPlayerLocators.leftHand, FPPlayerLocators.leftArm) - .addChildLocator(FPPlayerLocators.rightHand, FPPlayerLocators.rightArm) - .setLocatorDefaultPose(FPPlayerLocators.leftHand, PartPose.offsetAndRotation(1, 10, -2, -Mth.HALF_PI, 0, Mth.PI)) - .setLocatorDefaultPose(FPPlayerLocators.rightHand, PartPose.offsetAndRotation(-1, 10, -2, -Mth.HALF_PI, 0, Mth.PI)) - .setLocatorMirror(FPPlayerLocators.rightArm, FPPlayerLocators.leftArm) - .setLocatorMirror(FPPlayerLocators.rightHand, FPPlayerLocators.leftHand); - - } - - @Override - protected AnimationPose calculatePose() { - // Update main hand item based on the anim notify - //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()); - } - */ - - - - // Set the poses for the main hand item switch state machine - /* - getAnimationState(MAINHAND_ITEMSWITCH_STATE_MACHINE) - .setPose(ItemSwitchStates.EMPTY, getMainEmptyLocomotionPose(getStaticMainEmptyPose(), true, false)) - .setPose(ItemSwitchStates.EMPTY_RAISING, getMainHandRaisePose(getStaticMainEmptyPose())) - .setPose(ItemSwitchStates.BASIC_ITEM, getMainEmptyLocomotionPose(getStaticMainBasicItemPose(), true, true)) - .setPose(ItemSwitchStates.BASIC_ITEM_RAISING, getMainHandRaisePose(getStaticMainBasicItemPose())) - .setPose(ItemSwitchStates.LOWERING, getMainHandLowerPose(getStaticMainEmptyPose())); - AnimationPose pose = sampleAnimationState(MAINHAND_ITEMSWITCH_STATE_MACHINE); - pose = pose.getSelectedByLocators(getCameraPose(), List.of(FPPlayerLocators.camera)); - */ - - - AnimationPose pose = sampleAnimationState(TEST_IDLE_SEQUENCE_PLAYER); - - pose = dampenArmRotation(pose); - - - Vector3f rotation = new Vector3f(Mth.sin(getEntityAnimationVariable(TIME_TEST) * 0.2F) * Mth.HALF_PI * 0.7f, 0, 0); - //Vector3f translation = new Vector3f(Mth.sin(getEntityAnimationVariable(TIME_TEST) * 1.3F) * 3F, 0, 0); - //pose.translateJoint(FPPlayerLocators.rightArm, translation, AnimationPose.TransformSpace.ENTITY, false); - //pose.rotateJoint(FPPlayerLocators.rightArm, rotation, AnimationPose.TransformSpace.ENTITY, false); - - - return pose; - } - - /* - Get the pose with the added dampened camera rotation - */ - private AnimationPose dampenArmRotation(AnimationPose pose){ - Vector3f cameraRotation = getEntityAnimationVariable(CAMERA_ROTATION); - Vector3f dampenedCameraRotation = getEntityAnimationVariable(DAMPENED_CAMERA_ROTATION); - - Vector3f cameraDampWeight = new Vector3f(0.6F, 0.3F, 0.1F); - - pose.setJointPose( - FPPlayerLocators.armBuffer, - pose.getJointPoseCopy(FPPlayerLocators.armBuffer).rotate( - new Vector3f( - (dampenedCameraRotation.x() - cameraRotation.x()) * (cameraDampWeight.x() * 0.01F), - (dampenedCameraRotation.y() - cameraRotation.y()) * (cameraDampWeight.y() * 0.01F), - (dampenedCameraRotation.z() - cameraRotation.z()) * (cameraDampWeight.z() * 0.01F) - ), - AnimationPose.TransformSpace.ENTITY - )); - return pose; - } - - // Gets the camera pose - private AnimationPose getCameraPose(){ - /* - return getMainEmptyLocomotionPose(this.getStaticMainEmptyPose(), true, false); - - */ - return AnimationPose.of(this.locatorSkeleton); - } - - /* - private AnimationPose getMainEmptyLocomotionPose(AnimationPose basePose, boolean applyPunch, boolean applyAdditive){ - AnimationPose pose = sampleAnimationState(MAIN_EMPTY_IDLE_SEQUENCE_PLAYER); - pose.blendLinear(sampleAnimationState(MAIN_HAND_EMPTY_WALK_BLENDSPACE_PLAYER), getEntityAnimationVariable(WALK_WEIGHT)); - - getAnimationState(JUMP_STATE_MACHINE) - .setPose(JumpingStates.ON_GROUND, pose) - .setPose(JumpingStates.JUMPING, sampleAnimationState(MAIN_EMPTY_JUMP_SEQUENCE_PLAYER)) - .setPose(JumpingStates.FALLING, - AnimationPose.fromChannelTimeline(this.locatorSkeleton, ANIMATION_FP_RIGHT_EMPTY_JUMP, 0.5F) - .getBlendedLinear( - sampleAnimationState(MAIN_EMPTY_FALLING_SEQUENCE_PLAYER), - Mth.clampedMap( - this.livingEntity.fallDistance, - 0, - 10, - 0.5F, - 1.2F - ) - )) - .setPose(JumpingStates.LANDING, sampleAnimationState(MAIN_EMPTY_LAND_SEQUENCE_PLAYER)); - pose = sampleAnimationState(JUMP_STATE_MACHINE); - - - if(applyPunch){ - AnimationPose punchPose = sampleAnimationStateFromInputPose(MAIN_HAND_EMPTY_PUNCH_MONTAGE_TRACK, pose); - - AnimationPose cameraAdditivePose = sampleAnimationStateFromInputPose(MAIN_HAND_EMPTY_PUNCH_MONTAGE_TRACK, AnimationPose.of(this.locatorSkeleton)); - pose = punchPose.getSelectedByLocators(pose.getAdded(cameraAdditivePose), List.of(FPPlayerLocators.camera)); - - getAnimationState(MINING_STATE_MACHINE) - .setPose(MiningStates.IDLE, pose) - .setPose(MiningStates.BEGIN, sampleAnimationState(MAIN_EMPTY_MINING_BEGIN_SEQUENCE_PLAYER)) - .setPose(MiningStates.LOOPING, sampleAnimationState(MAIN_EMPTY_MINING_LOOP_SEQUENCE_PLAYER)); - pose = sampleAnimationState(MINING_STATE_MACHINE); - } - - //AnimationPose additivePose = basePose.getSubtracted(getStaticMainEmptyPose()); - //return pose.getAdded(additivePose); - if(applyAdditive) { - AnimationPose additivePose = getStaticMainEmptyPose().getSubtracted(basePose); - pose = pose.getAdded(additivePose); - - //AnimationPose unAddedPose = pose.getSubtracted(getStaticMainEmptyPose()); - //pose = unAddedPose.getAdded(basePose); - } - return pose; - - } - - private AnimationPose getMainHandRaisePose(AnimationPose basePose){ - AnimationPose pose = sampleAnimationState(MAIN_EMPTY_RAISE_SEQUENCE_PLAYER); - return pose.getSubtracted(getStaticMainEmptyPose()).getAdded(basePose); - } - - private AnimationPose getMainHandLowerPose(AnimationPose basePose){ - AnimationPose pose = sampleAnimationState(MAIN_EMPTY_LOWER_SEQUENCE_PLAYER); - return pose.getSubtracted(getStaticMainEmptyPose()).getAdded(basePose); - } - - - private AnimationPose getStaticMainEmptyPose(){ - return AnimationPose.fromChannelTimeline(this.locatorSkeleton, ANIMATION_FP_RIGHT_EMPTY_PUNCH, 0); - } - - private AnimationPose getStaticMainBasicItemPose(){ - return AnimationPose.fromChannelTimeline(this.locatorSkeleton, ANIMATION_FP_RIGHT_BASICITEM_POSE, 0); - } - - */ - - - public void tick(LivingEntity livingEntity, AnimationDataContainer entityAnimationData){ - - - - - this.setEntityAnimationVariable(TIME_TEST, this.getEntityAnimationVariable(TIME_TEST) + 1); - - - - /* - Tick the dampened camera rotation. - */ - - Vector3f dampenSpeed = new Vector3f(0.5F, 0.5F, 0.2F); - - // First, set the target camera rotation from the living entity. - Vector3f targetRotation = new Vector3f(this.livingEntity.getXRot(), this.livingEntity.getYRot(), this.livingEntity.getYRot()); - setEntityAnimationVariable(CAMERA_ROTATION, targetRotation); - - Vector3f dampenedCameraRotation = getEntityAnimationVariable(DAMPENED_CAMERA_ROTATION); - - // If the dampened camera rotation is 0 (which is what it is upon initialization), set it to the target - if(dampenedCameraRotation.x() == 0F && dampenedCameraRotation.y() == 0F){ - dampenedCameraRotation = targetRotation; - } else { - // Lerp the dampened camera rotation towards the normal camera rotation - dampenedCameraRotation.set( - Mth.lerp(dampenSpeed.x(), dampenedCameraRotation.x(), targetRotation.x()), - Mth.lerp(dampenSpeed.y(), dampenedCameraRotation.y(), targetRotation.y()), - Mth.lerp(dampenSpeed.z(), dampenedCameraRotation.z(), targetRotation.z()) - ); - //dampenedCameraRotation.lerp(targetRotation, 0.5F); - } - setEntityAnimationVariable(DAMPENED_CAMERA_ROTATION, dampenedCameraRotation); - - - - - // Tick the main hand lower/empty sequence players based on active states - /* - getAnimationState(MAIN_EMPTY_LOWER_SEQUENCE_PLAYER).playFromStartOnStateActive(getAnimationState(MAINHAND_ITEMSWITCH_STATE_MACHINE), - ItemSwitchStates.LOWERING); - getAnimationState(MAIN_EMPTY_RAISE_SEQUENCE_PLAYER).playFromStartOnStateActive(getAnimationState(MAINHAND_ITEMSWITCH_STATE_MACHINE), List.of( - ItemSwitchStates.EMPTY_RAISING, - ItemSwitchStates.BASIC_ITEM_RAISING - )); - - // Update the conditions for the maind hand empty item switching - getAnimationState(MAINHAND_ITEMSWITCH_STATE_MACHINE).setTransitionCondition(ItemSwitchStates.EMPTY, ItemSwitchStates.LOWERING, this.compareVariableItemStackWithEntityItemStack(MAIN_HAND_ITEM, this.livingEntity.getMainHandItem())); - getAnimationState(MAINHAND_ITEMSWITCH_STATE_MACHINE).setTransitionCondition(ItemSwitchStates.EMPTY_RAISING, ItemSwitchStates.EMPTY, getAnimationState(MAINHAND_ITEMSWITCH_STATE_MACHINE).getTimeElapsed() > TickTimeUtils.ticksFromMayaFrames(4)); - getAnimationState(MAINHAND_ITEMSWITCH_STATE_MACHINE).setTransitionCondition(ItemSwitchStates.LOWERING, ItemSwitchStates.EMPTY_RAISING, getAnimationState(MAINHAND_ITEMSWITCH_STATE_MACHINE).getTimeElapsed() > TickTimeUtils.ticksFromMayaFrames(4) && getEntityAnimationVariable(MAIN_HAND_ITEM).isEmpty()); - getAnimationState(MAINHAND_ITEMSWITCH_STATE_MACHINE).setTransitionCondition(ItemSwitchStates.BASIC_ITEM, ItemSwitchStates.LOWERING, this.compareVariableItemStackWithEntityItemStack(MAIN_HAND_ITEM, this.livingEntity.getMainHandItem())); - getAnimationState(MAINHAND_ITEMSWITCH_STATE_MACHINE).setTransitionCondition(ItemSwitchStates.BASIC_ITEM_RAISING, ItemSwitchStates.BASIC_ITEM, getAnimationState(MAINHAND_ITEMSWITCH_STATE_MACHINE).getTimeElapsed() > TickTimeUtils.ticksFromMayaFrames(4)); - getAnimationState(MAINHAND_ITEMSWITCH_STATE_MACHINE).setTransitionCondition(ItemSwitchStates.LOWERING, ItemSwitchStates.BASIC_ITEM_RAISING, getAnimationState(MAINHAND_ITEMSWITCH_STATE_MACHINE).getTimeElapsed() > TickTimeUtils.ticksFromMayaFrames(4) && !getEntityAnimationVariable(MAIN_HAND_ITEM).isEmpty()); - // Debug - //AnimationOverhaulMain.LOGGER.info("Current: {} New: {} Condition: {}", getEntityAnimationVariable(MAIN_HAND_ITEM).getItem(), this.livingEntity.getMainHandItem().getItem(), this.compareVariableItemStackWithEntityItemStack(MAIN_HAND_ITEM, this.livingEntity.getMainHandItem())); - - - // Set variables for jumping and falling - setEntityAnimationVariable(IS_JUMPING, - this.livingEntity.input.jumping - && !this.livingEntity.getAbilities().flying - && !this.livingEntity.isPassenger() - ); - setEntityAnimationVariable(IS_FALLING, - !this.livingEntity.onGround() - && !this.livingEntity.onClimbable() - ); - getAnimationState(JUMP_STATE_MACHINE) - .setTransitionCondition(JumpingStates.ON_GROUND, JumpingStates.JUMPING, getEntityAnimationVariable(IS_FALLING) && getEntityAnimationVariable(IS_JUMPING)) - .setTransitionCondition(JumpingStates.ON_GROUND, JumpingStates.FALLING, getEntityAnimationVariable(IS_FALLING)) - .setTransitionCondition(JumpingStates.JUMPING, JumpingStates.FALLING, getAnimationState(JUMP_STATE_MACHINE).getTimeElapsed() > TickTimeUtils.ticksFromMayaFrames(6) && getEntityAnimationVariable(IS_FALLING)) - .setTransitionCondition(JumpingStates.JUMPING, JumpingStates.LANDING, !getEntityAnimationVariable(IS_FALLING)) - .setTransitionCondition(JumpingStates.FALLING, JumpingStates.LANDING, !getEntityAnimationVariable(IS_FALLING)) - .setTransitionCondition(JumpingStates.LANDING, JumpingStates.JUMPING, getEntityAnimationVariable(IS_FALLING) && getEntityAnimationVariable(IS_JUMPING)) - .setTransitionCondition(JumpingStates.LANDING, JumpingStates.FALLING, getEntityAnimationVariable(IS_FALLING)) - .setTransitionCondition(JumpingStates.LANDING, JumpingStates.ON_GROUND, getAnimationState(JUMP_STATE_MACHINE).getTimeElapsed() > TickTimeUtils.ticksFromMayaFrames(3) && !getEntityAnimationVariable(IS_FALLING)); - getAnimationState(MAIN_EMPTY_JUMP_SEQUENCE_PLAYER).playFromStartOnStateActive(JUMP_STATE_MACHINE, JumpingStates.JUMPING); - getAnimationState(MAIN_EMPTY_LAND_SEQUENCE_PLAYER).playFromStartOnStateActive(JUMP_STATE_MACHINE, JumpingStates.LANDING); - getAnimationState(MAIN_EMPTY_FALLING_SEQUENCE_PLAYER).setPlayRate(Mth.clampedMap(this.livingEntity.fallDistance, 0, 20, 1, 2)); - - - - // Set the conditions for the mining state machine, and reset the two animation sequences based on the state status - getAnimationState(MINING_STATE_MACHINE) - .setTransitionCondition(MiningStates.IDLE, MiningStates.BEGIN, getEntityAnimationVariable(IS_MINING) && !getAnimationState(MAIN_HAND_EMPTY_PUNCH_MONTAGE_TRACK).isActive()) - .setTransitionCondition(MiningStates.BEGIN, MiningStates.LOOPING, getAnimationState(MINING_STATE_MACHINE).getTimeElapsed() > TickTimeUtils.ticksFromMayaFrames(4)) - .setTransitionCondition(MiningStates.BEGIN, MiningStates.IDLE, !getEntityAnimationVariable(IS_MINING)) - .setTransitionCondition(MiningStates.LOOPING, MiningStates.IDLE, !getEntityAnimationVariable(IS_MINING)); - getAnimationState(MAIN_EMPTY_MINING_BEGIN_SEQUENCE_PLAYER).playFromStartOnStateActive(MINING_STATE_MACHINE, MiningStates.BEGIN); - getAnimationState(MAIN_EMPTY_MINING_LOOP_SEQUENCE_PLAYER).playFromStartOnStateActive(MINING_STATE_MACHINE, MiningStates.LOOPING); - getAnimationState(MAIN_EMPTY_MINING_LOOP_SEQUENCE_PLAYER).progressTimeIfStateActive(MINING_STATE_MACHINE, MiningStates.LOOPING); - - - if(getEntityAnimationVariable(IS_ATTACKING) && !getEntityAnimationVariable(IS_MINING)){ - setEntityAnimationVariable(IS_ATTACKING, false); - - // Only play the attack animation if not mining - if(getAnimationState(MINING_STATE_MACHINE).getActiveState() == MiningStates.IDLE){ - - // Play the attack montage based on the main hand item switch state. Does not play for raising/lowering states. - ItemSwitchStates state = getAnimationState(MAINHAND_ITEMSWITCH_STATE_MACHINE).getActiveState(); - switch (state){ - case EMPTY, BASIC_ITEM: - getAnimationState(MAIN_HAND_EMPTY_PUNCH_MONTAGE_TRACK).playMontage(MAIN_HAND_EMPTY_PUNCH_MONTAGE); - } - } - } - if(getEntityAnimationVariable(IS_USING_ITEM)){ - setEntityAnimationVariable(IS_USING_ITEM, false); - ItemSwitchStates state = getAnimationState(MAINHAND_ITEMSWITCH_STATE_MACHINE).getActiveState(); - switch (state){ - case EMPTY, BASIC_ITEM: - getAnimationState(MAIN_HAND_EMPTY_PUNCH_MONTAGE_TRACK).playMontage(MAIN_HAND_EMPTY_USE_ITEM_MONTAGE); - } - } - - boolean isInputtingMovement = - this.livingEntity.input.forwardImpulse != 0 || - this.livingEntity.input.leftImpulse != 0; - //AnimationOverhaulMain.LOGGER.info("{}, {}", this.livingEntity.input.forwardImpulse, this.livingEntity.animationSpeed); - getEntityAnimationData().incrementInFramesFromCondition(WALK_WEIGHT, isInputtingMovement, 2, 4); - getAnimationState(MAIN_HAND_EMPTY_WALK_BLENDSPACE_PLAYER).setValue(this.getWalkAnimationSpeed()); - */ - - } - - public void tickExternal(){ - LocalPlayer player = Minecraft.getInstance().player; - this.setEntity(player); - - this.tick(player, getEntityAnimationData()); - getEntityAnimationData().tickAnimationStates(); - - if(this.localBakedPose == null){ - this.localBakedPose = new BakedAnimationPose(); - this.localBakedPose.setPose(AnimationPose.of(this.locatorSkeleton)); - } - if(!this.localBakedPose.hasPose){ - this.localBakedPose.setPose(AnimationPose.of(this.locatorSkeleton)); - this.localBakedPose.hasPose = true; - } - this.localBakedPose.pushToOld(); - - AnimationPose animationPose = this.calculatePose(); - if (animationPose == null){ - animationPose = AnimationPose.of(this.locatorSkeleton); - } - animationPose.applyDefaultPoseOffset(); - - - - - this.localBakedPose.setPose(new AnimationPose(animationPose)); - } - - private boolean compareVariableItemStackWithEntityItemStack(AnimationVariableKey itemStackDataKey, ItemStack entityItemStack){ - ItemStack currentItemStack = getEntityAnimationVariable(itemStackDataKey); - if(currentItemStack.getItem() != null && entityItemStack.getItem() == null || currentItemStack.getItem() == null && entityItemStack.getItem() != null) { - return true; - } - return currentItemStack.getItem() != entityItemStack.getItem(); - } - - @Override - protected AnimationDataContainer getEntityAnimationData() { - return this.localAnimationDataContainer; - } -} diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/FirstPersonPlayerJointAnimator.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/FirstPersonPlayerJointAnimator.java new file mode 100644 index 0000000..9e7d9b9 --- /dev/null +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/FirstPersonPlayerJointAnimator.java @@ -0,0 +1,307 @@ +package com.trainguy9512.animationoverhaul.animation.animator; + +import com.trainguy9512.animationoverhaul.animation.animator.entity.EntityJointAnimator; +import com.trainguy9512.animationoverhaul.animation.animator.entity.LivingEntityJointAnimator; +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.*; +import com.trainguy9512.animationoverhaul.util.animation.JointSkeleton; +import com.trainguy9512.animationoverhaul.animation.data.AnimationDataContainer; +import com.trainguy9512.animationoverhaul.animation.data.TimelineGroupData; +import net.minecraft.client.Minecraft; +import net.minecraft.client.model.PlayerModel; +import net.minecraft.client.model.geom.PartPose; +import net.minecraft.client.player.LocalPlayer; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; +import net.minecraft.world.item.ItemStack; +import org.joml.Vector3f; + +public class FirstPersonPlayerJointAnimator extends LivingEntityJointAnimator, FirstPersonPlayerJointAnimator.FPPlayerLocators> { + + public static FirstPersonPlayerJointAnimator INSTANCE = new FirstPersonPlayerJointAnimator(); + + public AnimationDataContainer localAnimationDataContainer = new AnimationDataContainer(); + public BakedAnimationPose localBakedPose; + + + public enum FPPlayerLocators { + root, + camera, + armBuffer, + rightArmBuffer, + leftArmBuffer, + rightArm, + leftArm, + rightHand, + leftHand; + + public static final FPPlayerLocators[] arms = new FPPlayerLocators[] { + rightArm, + leftArm, + rightArmBuffer, + leftArmBuffer, + rightHand, + leftHand + }; + + public static final FPPlayerLocators[] armBufferLocators = new FPPlayerLocators[] { + rightArmBuffer, + leftArmBuffer + }; + + public static final FPPlayerLocators[] armPoseLocators = new FPPlayerLocators[] { + rightArm, + leftArm + }; + + public static final FPPlayerLocators[] handLocators = new FPPlayerLocators[] { + rightHand, + leftHand + }; + } + + + public static final ResourceLocation ANIMATION_FP_PLAYER_IDLE = TimelineGroupData.getNativeResourceLocation(TimelineGroupData.FIRST_PERSON_PLAYER_KEY, "fp_player_idle"); + + + public static final AnimationVariableKey TIME_TEST = AnimationVariableKey.of(() -> 0F).setDebugIdentifier("time_test").build(); + + + + public static final AnimationVariableKey CAMERA_ROTATION = AnimationVariableKey.of(() -> new Vector3f(0, 0, 0)).setDebugIdentifier("camera_rotation").build(); + public static final AnimationVariableKey DAMPENED_CAMERA_ROTATION = AnimationVariableKey.of(() -> new Vector3f(0, 0, 0)).setDebugIdentifier("dampened_camera_rotation").build(); + public static final AnimationVariableKey MAIN_HAND_ITEM = AnimationVariableKey.of(() -> ItemStack.EMPTY).setDebugIdentifier("main_hand_item_stack").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); + + + + enum TestStates { + IDLE, + MOVING + } + + + + + + + /* + enum ItemSwitchStates { + EMPTY, + EMPTY_RAISING, + BASIC_ITEM, + BASIC_ITEM_RAISING, + LOWERING + } + private static final AnimationStateMachine MAINHAND_ITEMSWITCH_STATE_MACHINE = AnimationStateMachine.of("main_hand_state_machine", ItemSwitchStates.values()) + .addStateTransition(ItemSwitchStates.EMPTY, ItemSwitchStates.LOWERING, 2) + .addStateTransition(ItemSwitchStates.LOWERING, ItemSwitchStates.EMPTY_RAISING, 1, 2) + .addStateTransition(ItemSwitchStates.EMPTY_RAISING, ItemSwitchStates.EMPTY, 2) + .addStateTransition(ItemSwitchStates.BASIC_ITEM, ItemSwitchStates.LOWERING, 2) + .addStateTransition(ItemSwitchStates.LOWERING, ItemSwitchStates.BASIC_ITEM_RAISING, 1, 1) + .addStateTransition(ItemSwitchStates.BASIC_ITEM_RAISING, ItemSwitchStates.BASIC_ITEM, 2); + + + + enum JumpingStates { + JUMPING, + FALLING, + LANDING, + ON_GROUND + } + private static final AnimationStateMachine JUMP_STATE_MACHINE = AnimationStateMachine.of("jump_state_machine", JumpingStates.values()) + .addStateTransition(JumpingStates.ON_GROUND, JumpingStates.JUMPING, 1, 1) + .addStateTransition(JumpingStates.ON_GROUND, JumpingStates.FALLING, 3, 2) + .addStateTransition(JumpingStates.JUMPING, JumpingStates.FALLING, 4, 1) + .addStateTransition(JumpingStates.JUMPING, JumpingStates.LANDING, 1, 2) + .addStateTransition(JumpingStates.FALLING, JumpingStates.LANDING, 1, 1) + .addStateTransition(JumpingStates.LANDING, JumpingStates.JUMPING, 1, 2) + .addStateTransition(JumpingStates.LANDING, JumpingStates.FALLING, 3, 3) + .addStateTransition(JumpingStates.LANDING, JumpingStates.ON_GROUND, 4, 1); + + + enum MiningStates { + IDLE, + BEGIN, + LOOPING + } + private static final AnimationStateMachine MINING_STATE_MACHINE = AnimationStateMachine.of("mining_state_machine", MiningStates.values()) + .addStateTransition(MiningStates.IDLE, MiningStates.BEGIN, 2) + .addStateTransition(MiningStates.BEGIN, MiningStates.LOOPING, 1) + .addStateTransition(MiningStates.BEGIN, MiningStates.IDLE, 2) + .addStateTransition(MiningStates.LOOPING, MiningStates.IDLE, 2); + + + */ + + + private static final AnimationMontageTrack MAIN_HAND_EMPTY_PUNCH_MONTAGE_TRACK = AnimationMontageTrack.of("main_hand_empty_punch_montage_track"); + /* + private static final AnimationMontage MAIN_HAND_EMPTY_PUNCH_MONTAGE = AnimationMontage.of(ANIMATION_FP_RIGHT_EMPTY_PUNCH) + .setLength(TickTimeUtils.ticksFromMayaFrames(10F)) + .setBlendInDuration(1) + .setBlendOutDuration(TickTimeUtils.ticksFromMayaFrames(8F)); + private static final AnimationMontage MAIN_HAND_EMPTY_USE_ITEM_MONTAGE = AnimationMontage.of(ANIMATION_FP_RIGHT_EMPTY_USE_ITEM) + .setLength(TickTimeUtils.ticksFromMayaFrames(9F)) + .setBlendInDuration(1) + .setBlendOutDuration(TickTimeUtils.ticksFromMayaFrames(5F)); + + */ + + + + /* + private static final AnimationBlendSpacePlayer MAIN_HAND_EMPTY_WALK_BLENDSPACE_PLAYER = AnimationBlendSpacePlayer.of("main_hand_empty_walk_blendspace_player") + .addEntry(0, ANIMATION_FP_RIGHT_EMPTY_WALK, 0F) + .addEntry(2, ANIMATION_FP_RIGHT_EMPTY_WALK, 2.9F); + + */ + + + public FirstPersonPlayerJointAnimator(){ + super(); + } + + protected JointSkeleton buildRig() { + return JointSkeleton.of(FPPlayerLocators.root) + .addChildLocator(FPPlayerLocators.camera) + .addChildLocator(FPPlayerLocators.armBuffer) + .addChildLocator(FPPlayerLocators.leftArmBuffer, FPPlayerLocators.armBuffer) + .addChildLocator(FPPlayerLocators.rightArmBuffer, FPPlayerLocators.armBuffer) + .addChildLocator(FPPlayerLocators.leftArm, FPPlayerLocators.leftArmBuffer) + .addChildLocator(FPPlayerLocators.rightArm, FPPlayerLocators.rightArmBuffer) + .addChildLocator(FPPlayerLocators.leftHand, FPPlayerLocators.leftArm) + .addChildLocator(FPPlayerLocators.rightHand, FPPlayerLocators.rightArm) + .setLocatorDefaultPose(FPPlayerLocators.leftHand, PartPose.offsetAndRotation(1, 10, -2, -Mth.HALF_PI, 0, Mth.PI)) + .setLocatorDefaultPose(FPPlayerLocators.rightHand, PartPose.offsetAndRotation(-1, 10, -2, -Mth.HALF_PI, 0, Mth.PI)) + .setLocatorMirror(FPPlayerLocators.rightArm, FPPlayerLocators.leftArm) + .setLocatorMirror(FPPlayerLocators.rightHand, FPPlayerLocators.leftHand); + + } + + @Override + public AnimationPose calculatePose(LocalPlayer localPlayer, AnimationDataContainer animationDataContainer) { + // Update main hand item based on the anim notify + + setEntityAnimationVariable(MAIN_HAND_ITEM, this.livingEntity.getMainHandItem().copy()); + + AnimationPose pose = sampleAnimationState(TEST_IDLE_SEQUENCE_PLAYER); + + pose = dampenArmRotation(pose); + + + Vector3f rotation = new Vector3f(Mth.sin(getEntityAnimationVariable(TIME_TEST) * 0.2F) * Mth.HALF_PI * 0.7f, 0, 0); + //Vector3f translation = new Vector3f(Mth.sin(getEntityAnimationVariable(TIME_TEST) * 1.3F) * 3F, 0, 0); + //pose.translateJoint(FPPlayerLocators.rightArm, translation, AnimationPose.TransformSpace.ENTITY, false); + //pose.rotateJoint(FPPlayerLocators.rightArm, rotation, AnimationPose.TransformSpace.ENTITY, false); + + + return pose; + } + + /* + Get the pose with the added dampened camera rotation + */ + private AnimationPose dampenArmRotation(AnimationPose pose){ + Vector3f cameraRotation = getEntityAnimationVariable(CAMERA_ROTATION); + Vector3f dampenedCameraRotation = getEntityAnimationVariable(DAMPENED_CAMERA_ROTATION); + + Vector3f cameraDampWeight = new Vector3f(0.6F, 0.3F, 0.1F); + + pose.setJointPose( + FPPlayerLocators.armBuffer, + pose.getJointPoseCopy(FPPlayerLocators.armBuffer).rotate( + new Vector3f( + (dampenedCameraRotation.x() - cameraRotation.x()) * (cameraDampWeight.x() * 0.01F), + (dampenedCameraRotation.y() - cameraRotation.y()) * (cameraDampWeight.y() * 0.01F), + (dampenedCameraRotation.z() - cameraRotation.z()) * (cameraDampWeight.z() * 0.01F) + ), + AnimationPose.TransformSpace.ENTITY + )); + return pose; + } + + + @Override + public void tick(LocalPlayer localPlayer, AnimationDataContainer entityAnimationData){ + + + + + this.setEntityAnimationVariable(TIME_TEST, this.getEntityAnimationVariable(TIME_TEST) + 1); + + + + /* + Tick the dampened camera rotation. + */ + + Vector3f dampenSpeed = new Vector3f(0.5F, 0.5F, 0.2F); + + // First, set the target camera rotation from the living entity. + Vector3f targetRotation = new Vector3f(this.livingEntity.getXRot(), this.livingEntity.getYRot(), this.livingEntity.getYRot()); + setEntityAnimationVariable(CAMERA_ROTATION, targetRotation); + + Vector3f dampenedCameraRotation = getEntityAnimationVariable(DAMPENED_CAMERA_ROTATION); + + // If the dampened camera rotation is 0 (which is what it is upon initialization), set it to the target + if(dampenedCameraRotation.x() == 0F && dampenedCameraRotation.y() == 0F){ + dampenedCameraRotation = targetRotation; + } else { + // Lerp the dampened camera rotation towards the normal camera rotation + dampenedCameraRotation.set( + Mth.lerp(dampenSpeed.x(), dampenedCameraRotation.x(), targetRotation.x()), + Mth.lerp(dampenSpeed.y(), dampenedCameraRotation.y(), targetRotation.y()), + Mth.lerp(dampenSpeed.z(), dampenedCameraRotation.z(), targetRotation.z()) + ); + //dampenedCameraRotation.lerp(targetRotation, 0.5F); + } + setEntityAnimationVariable(DAMPENED_CAMERA_ROTATION, dampenedCameraRotation); + + + } + + + //TODO: Move this elsewhere + + public void tickExternal(){ + LocalPlayer player = Minecraft.getInstance().player; + AnimationDataContainer animationDataContainer = this.localAnimationDataContainer; + + this.tick(player, animationDataContainer); + animationDataContainer.tickAnimationStates(); + + if(this.localBakedPose == null){ + this.localBakedPose = new BakedAnimationPose(); + this.localBakedPose.setPose(AnimationPose.of(this.jointSkeleton)); + } + if(!this.localBakedPose.hasPose){ + this.localBakedPose.setPose(AnimationPose.of(this.jointSkeleton)); + this.localBakedPose.hasPose = true; + } + this.localBakedPose.pushToOld(); + + AnimationPose animationPose = this.calculatePose(player, animationDataContainer); + if (animationPose == null){ + animationPose = AnimationPose.of(this.jointSkeleton); + } + animationPose.applyDefaultPoseOffset(); + + + + + this.localBakedPose.setPose(new AnimationPose(animationPose)); + } + + private boolean compareVariableItemStackWithEntityItemStack(AnimationVariableKey itemStackDataKey, ItemStack entityItemStack){ + ItemStack currentItemStack = getEntityAnimationVariable(itemStackDataKey); + if(currentItemStack.getItem() != null && entityItemStack.getItem() == null || currentItemStack.getItem() == null && entityItemStack.getItem() != null) { + return true; + } + return currentItemStack.getItem() != entityItemStack.getItem(); + } +} diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/JointAnimator.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/JointAnimator.java new file mode 100644 index 0000000..31a3ec6 --- /dev/null +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/JointAnimator.java @@ -0,0 +1,25 @@ +package com.trainguy9512.animationoverhaul.animation.animator; + +import com.trainguy9512.animationoverhaul.animation.data.AnimationDataContainer; +import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; +import com.trainguy9512.animationoverhaul.util.animation.JointSkeleton; +import net.minecraft.world.entity.Entity; + +public abstract class JointAnimator> { + + protected final JointSkeleton jointSkeleton; + + protected JointAnimator() { + this.jointSkeleton = buildRig(); + } + + public JointSkeleton getJointSkeleton(){ + return this.jointSkeleton; + } + + protected abstract JointSkeleton buildRig(); + + public abstract void tick(T animatedObjectReference, AnimationDataContainer entityAnimationData); + + public abstract AnimationPose calculatePose(T animatedObjectReference, AnimationDataContainer entityAnimationData); +} diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/EntityJointAnimator.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/EntityJointAnimator.java new file mode 100644 index 0000000..57a4909 --- /dev/null +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/EntityJointAnimator.java @@ -0,0 +1,70 @@ +package com.trainguy9512.animationoverhaul.animation.animator.entity; + +import com.mojang.blaze3d.vertex.PoseStack; +import com.trainguy9512.animationoverhaul.access.ModelAccess; +import com.trainguy9512.animationoverhaul.animation.EntityJointAnimatorDispatcher; +import com.trainguy9512.animationoverhaul.animation.animator.JointAnimator; +import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; +import com.trainguy9512.animationoverhaul.animation.pose.BakedAnimationPose; +import com.trainguy9512.animationoverhaul.animation.data.AnimationDataContainer; +import net.minecraft.client.model.EntityModel; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; + +public abstract class EntityJointAnimator, L extends Enum> extends JointAnimator { + + + //protected AnimationDataContainer entityAnimationData; + + public EntityJointAnimator(){ + super(); + } + + /* + protected WalkAnimationState getWalkAnimationState(){ + return this.livingEntity != null ? this.livingEntity.walkAnimation : new WalkAnimationState(); + } + + */ + + /* + public void overallTick(LivingEntity livingEntity){ + BakedAnimationPose bakedPose = EntityJointAnimatorDispatcher.INSTANCE.getBakedPose(livingEntity.getUUID()); + AnimationDataContainer entityAnimationData = EntityJointAnimatorDispatcher.INSTANCE.getEntityAnimationData(livingEntity.getUUID()); + + this.tick(livingEntity, entityAnimationData); + + entityAnimationData.tickAnimationStates(); + + if(bakedPose == null){ + bakedPose = new BakedAnimationPose(); + } + if(!bakedPose.hasPose){ + bakedPose.setPose(AnimationPose.of(this.jointSkeleton)); + bakedPose.hasPose = true; + } + bakedPose.pushToOld(); + + //this.locatorRig.resetRig(); + AnimationPose animationPose = this.calculatePose(); + if (animationPose == null){ + animationPose = AnimationPose.of(this.jointSkeleton); + } + animationPose.applyDefaultPoseOffset(); + + bakedPose.setPose(animationPose.getCopy()); + EntityJointAnimatorDispatcher.INSTANCE.saveBakedPose(livingEntity.getUUID(), bakedPose); + } + + */ + + + + public void finalizeModelParts(M entityModel, ModelPart rootModelPart){ + } + + public ModelPart getRoot(M entityModel){ + return ((ModelAccess)entityModel).getRootModelPart(); + } +} diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/LivingEntityAnimator.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/LivingEntityAnimator.java deleted file mode 100644 index 437e880..0000000 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/LivingEntityAnimator.java +++ /dev/null @@ -1,147 +0,0 @@ -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.*; -import com.trainguy9512.animationoverhaul.util.animation.LocatorSkeleton; -import com.trainguy9512.animationoverhaul.animation.data.AnimationDataContainer; -import net.minecraft.client.model.EntityModel; -import net.minecraft.client.model.geom.ModelPart; -import net.minecraft.world.entity.LivingEntity; - -import java.util.Random; - -public abstract class LivingEntityAnimator, L extends Enum> { - - protected T livingEntity; - protected M entityModel; - protected final LocatorSkeleton locatorSkeleton; - - protected AnimationDataContainer entityAnimationData; - protected final Random random = new Random(); - - public LivingEntityAnimator(){ - this.locatorSkeleton = buildRig(); - } - - public void setEntity(T livingEntity){ - this.livingEntity = livingEntity; - } - - public void setEntityModel(M entityModel){ - this.entityModel = entityModel; - } - - protected LocatorSkeleton buildRig(){ - return new LocatorSkeleton(); - } - - public void tick(LivingEntity livingEntity, AnimationDataContainer entityAnimationData){ - - } - - protected AnimationPose calculatePose(){ - return null; - } - - protected void finalizeModelParts(ModelPart rootModelPart){ - } - - protected AnimationDataContainer getEntityAnimationData(){ - return this.entityAnimationData; - } - - protected AnimationDataContainer.AnimationVariable getEntityAnimationVariableObject(AnimationVariableKey dataKey){ - return getEntityAnimationData().get(dataKey); - } - - protected D getEntityAnimationVariable(AnimationVariableKey dataKey){ - return getEntityAnimationVariableObject(dataKey).get(); - } - - protected void setEntityAnimationVariable(AnimationVariableKey dataKey, D value){ - getEntityAnimationData().setValue(dataKey, value); - } - - protected AnimationPose sampleAnimationState(SampleableAnimationState sampleableAnimationState){ - return getEntityAnimationData().sampleAnimationState(this.locatorSkeleton, sampleableAnimationState); - } - - protected AnimationPose sampleAnimationStateFromInputPose(SampleableAnimationState sampleableAnimationState, AnimationPose inputPose){ - return getEntityAnimationData().sampleAnimationStateFromInputPose(inputPose.getCopy(), this.locatorSkeleton, sampleableAnimationState); - } - - protected D getAnimationState(D sampleableAnimationState){ - return getEntityAnimationData().getAnimationState(sampleableAnimationState); - } - - /* - protected WalkAnimationState getWalkAnimationState(){ - return this.livingEntity != null ? this.livingEntity.walkAnimation : new WalkAnimationState(); - } - - */ - - protected float getWalkAnimationSpeed(){ - return this.livingEntity.walkAnimation.speed(); - } - - protected float getWalkAnimationPosition(){ - - - - - return this.livingEntity.walkAnimation.position(); - - } - - public void tick(LivingEntity livingEntity){ - BakedAnimationPose bakedPose = AnimatorDispatcher.INSTANCE.getBakedPose(livingEntity.getUUID()); - AnimationDataContainer entityAnimationData = AnimatorDispatcher.INSTANCE.getEntityAnimationData(livingEntity.getUUID()); - this.entityAnimationData = entityAnimationData; - this.setEntity((T)livingEntity); - //this.livingEntity = (T)livingEntity; - - this.tick(livingEntity, entityAnimationData); - getEntityAnimationData().tickAnimationStates(); - - if(bakedPose == null){ - bakedPose = new BakedAnimationPose(); - } - if(!bakedPose.hasPose){ - bakedPose.setPose(AnimationPose.of(this.locatorSkeleton)); - bakedPose.hasPose = true; - } - bakedPose.pushToOld(); - - //this.locatorRig.resetRig(); - AnimationPose animationPose = this.calculatePose(); - if (animationPose == null){ - animationPose = AnimationPose.of(this.locatorSkeleton); - } - animationPose.applyDefaultPoseOffset(); - - bakedPose.setPose(animationPose.getCopy()); - AnimatorDispatcher.INSTANCE.saveBakedPose(livingEntity.getUUID(), bakedPose); - } - - public void applyBakedPose(T livingEntity, M entityModel, PoseStack poseStack, AnimationDataContainer entityAnimationData, float partialTicks){ - setEntity(livingEntity); - setEntityModel(entityModel); - - BakedAnimationPose bakedPose = AnimatorDispatcher.INSTANCE.getBakedPose(livingEntity.getUUID()); - - ModelPart rootModelPart = getRoot(entityModel); - assert bakedPose != null; - bakedPose.bakeToModelParts(rootModelPart, partialTicks); - finalizeModelParts(rootModelPart); - } - - protected ModelPart getRoot(M entityModel){ - return ((ModelAccess)entityModel).getRootModelPart(); - } -} diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/LivingEntityJointAnimator.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/LivingEntityJointAnimator.java new file mode 100644 index 0000000..2ceb172 --- /dev/null +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/LivingEntityJointAnimator.java @@ -0,0 +1,16 @@ +package com.trainguy9512.animationoverhaul.animation.animator.entity; + +import com.trainguy9512.animationoverhaul.animation.animator.JointAnimator; +import net.minecraft.client.model.EntityModel; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; + +public abstract class LivingEntityJointAnimator, L extends Enum> extends EntityJointAnimator { + protected float getWalkAnimationSpeed(T entity){ + return entity.walkAnimation.speed(); + } + + protected float getWalkAnimationPosition(T livingEntity){ + return livingEntity.walkAnimation.position(); + } +} diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/PlayerPartAnimator.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/PlayerJointAnimator.java similarity index 87% rename from src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/PlayerPartAnimator.java rename to src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/PlayerJointAnimator.java index ce7fc2f..b75fe2b 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/PlayerPartAnimator.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/PlayerJointAnimator.java @@ -1,7 +1,7 @@ package com.trainguy9512.animationoverhaul.animation.animator.entity; import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; -import com.trainguy9512.animationoverhaul.util.animation.LocatorSkeleton; +import com.trainguy9512.animationoverhaul.util.animation.JointSkeleton; import com.trainguy9512.animationoverhaul.animation.data.AnimationDataContainer; import net.minecraft.client.model.PlayerModel; import net.minecraft.client.model.geom.ModelPart; @@ -9,8 +9,9 @@ import net.minecraft.util.Mth; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; +import org.jetbrains.annotations.NotNull; -public class PlayerPartAnimator extends LivingEntityAnimator, PlayerPartAnimator.ModelPartLocators> { +public class PlayerJointAnimator extends LivingEntityJointAnimator, PlayerJointAnimator.ModelPartLocators> { private static final String MODEL_PART_ROOT = "root"; private static final String MODEL_PART_HEAD = "head"; @@ -35,17 +36,17 @@ public enum ModelPartLocators{ } - public PlayerPartAnimator(){ + public PlayerJointAnimator(){ super(); } // Building the locator rig @Override - protected LocatorSkeleton buildRig() { + protected JointSkeleton buildRig() { //TODO: Adjust rig with proper parenting and no more offsets on the legs. - return LocatorSkeleton.of(ModelPartLocators.root) + return JointSkeleton.of(ModelPartLocators.root) .addChildLocator(ModelPartLocators.body) .addChildLocator(ModelPartLocators.cape) .addChildLocator(ModelPartLocators.leftArm) @@ -86,7 +87,7 @@ protected LocatorSkeleton buildRig() { // Ticking every sampleable animation state, in this case updating the state machine conditions @Override - public void tick(LivingEntity livingEntity, AnimationDataContainer entityAnimationData) { + public void tick(Player player, AnimationDataContainer entityAnimationData) { @@ -94,13 +95,13 @@ public void tick(LivingEntity livingEntity, AnimationDataContainer entityAnimati // This is the function for getting the final pose every tick @Override - protected AnimationPose calculatePose() { - return AnimationPose.of(this.locatorSkeleton); + public AnimationPose calculatePose(Player player, AnimationDataContainer animationDataContainer) { + return AnimationPose.of(this.jointSkeleton); } // Post-processing on the animation, copying stuff to the second layer and whatnot @Override - protected void finalizeModelParts(ModelPart rootModelPart) { + public void finalizeModelParts(PlayerModel playerModel, ModelPart rootModelPart) { rootModelPart.getChild("left_pants").copyFrom(rootModelPart.getChild("left_leg")); rootModelPart.getChild("right_pants").copyFrom(rootModelPart.getChild("right_leg")); rootModelPart.getChild("left_sleeve").copyFrom(rootModelPart.getChild("left_arm")); @@ -109,7 +110,7 @@ protected void finalizeModelParts(ModelPart rootModelPart) { rootModelPart.getChild("hat").copyFrom(rootModelPart.getChild("head")); rootModelPart.getChild("cloak").xRot *= -1F; // Removes the vanilla transformation done for the crouch pose - if(this.entityModel.crouching){ + if(playerModel.crouching){ for(ModelPart modelPart : rootModelPart.getAllParts().toList()){ modelPart.y -= 2; } diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/data/AnimationDataContainer.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/data/AnimationDataContainer.java index fb24126..5498e3d 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/data/AnimationDataContainer.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/data/AnimationDataContainer.java @@ -1,14 +1,10 @@ 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 com.trainguy9512.animationoverhaul.util.animation.JointSkeleton; import net.minecraft.util.Mth; -import org.jetbrains.annotations.NotNull; import java.util.*; import java.util.function.Supplier; @@ -16,7 +12,7 @@ public class AnimationDataContainer { private final HashMap, AnimationVariable> animationVariables; - private final HashMap entitySampleableAnimationStates; + private final HashMap entitySampleableAnimationStates; private final CachedPoseContainer cachedPoseContainer = new CachedPoseContainer(); public AnimationDataContainer(){ @@ -25,12 +21,12 @@ public AnimationDataContainer(){ } public void tickAnimationStates(){ - for(SampleableAnimationState sampleableAnimationState : entitySampleableAnimationStates.values()){ - sampleableAnimationState.tick(); + for(PoseSampler poseSampler : entitySampleableAnimationStates.values()){ + poseSampler.tick(); } } - public D getAnimationState(D sampleableAnimationState){ + public D getAnimationState(D sampleableAnimationState){ for(String identifier : this.entitySampleableAnimationStates.keySet()){ if (Objects.equals(sampleableAnimationState.getIdentifier(), identifier)){ return (D) this.entitySampleableAnimationStates.get(identifier); @@ -40,32 +36,32 @@ public D getAnimationState(D sampleableAnim return sampleableAnimationState; } - public > AnimationPose sampleAnimationState(LocatorSkeleton locatorSkeleton, SampleableAnimationState sampleableAnimationState){ + public > AnimationPose sampleAnimationState(JointSkeleton jointSkeleton, PoseSampler poseSampler){ for(String identifier : this.entitySampleableAnimationStates.keySet()){ - if (Objects.equals(sampleableAnimationState.getIdentifier(), identifier)){ - return this.entitySampleableAnimationStates.get(identifier).sample(locatorSkeleton, cachedPoseContainer); + if (Objects.equals(poseSampler.getIdentifier(), identifier)){ + return this.entitySampleableAnimationStates.get(identifier).sample(jointSkeleton, cachedPoseContainer); } } - this.entitySampleableAnimationStates.put(sampleableAnimationState.getIdentifier(), sampleableAnimationState); - return (this.entitySampleableAnimationStates.get(sampleableAnimationState.getIdentifier())).sample(locatorSkeleton, cachedPoseContainer); + this.entitySampleableAnimationStates.put(poseSampler.getIdentifier(), poseSampler); + return (this.entitySampleableAnimationStates.get(poseSampler.getIdentifier())).sample(jointSkeleton, cachedPoseContainer); } - public > AnimationPose sampleAnimationStateFromInputPose(AnimationPose inputPose, LocatorSkeleton locatorSkeleton, SampleableAnimationState sampleableAnimationState){ + public > AnimationPose sampleAnimationStateFromInputPose(AnimationPose inputPose, JointSkeleton jointSkeleton, PoseSampler poseSampler){ for(String identifier : this.entitySampleableAnimationStates.keySet()){ - if (Objects.equals(sampleableAnimationState.getIdentifier(), identifier)){ - return this.entitySampleableAnimationStates.get(identifier).sampleFromInputPose(inputPose, locatorSkeleton, cachedPoseContainer); + if (Objects.equals(poseSampler.getIdentifier(), identifier)){ + return this.entitySampleableAnimationStates.get(identifier).sampleFromInputPose(inputPose, jointSkeleton, cachedPoseContainer); } } - this.entitySampleableAnimationStates.put(sampleableAnimationState.getIdentifier(), sampleableAnimationState); - return (this.entitySampleableAnimationStates.get(sampleableAnimationState.getIdentifier())).sampleFromInputPose(inputPose, locatorSkeleton, cachedPoseContainer); + this.entitySampleableAnimationStates.put(poseSampler.getIdentifier(), poseSampler); + return (this.entitySampleableAnimationStates.get(poseSampler.getIdentifier())).sampleFromInputPose(inputPose, jointSkeleton, cachedPoseContainer); } public > void saveCachedPose(String identifier, AnimationPose animationPose){ this.cachedPoseContainer.saveCachedPose(identifier, animationPose); } - public > AnimationPose getCachedPose(String identifier, LocatorSkeleton locatorSkeleton){ - return this.cachedPoseContainer.getCachedPose(identifier, locatorSkeleton); + public > AnimationPose getCachedPose(String identifier, JointSkeleton jointSkeleton){ + return this.cachedPoseContainer.getCachedPose(identifier, jointSkeleton); } public class CachedPoseContainer { @@ -78,11 +74,11 @@ public void saveCachedPose(String identifier, AnimationPose animationPose){ this.poses.put(identifier, animationPose); } - public AnimationPose getCachedPose(String identifier, LocatorSkeleton locatorSkeleton){ + public AnimationPose getCachedPose(String identifier, JointSkeleton jointSkeleton){ if(this.poses.containsKey(identifier)){ return this.poses.get(identifier); } - return AnimationPose.of(locatorSkeleton); + return AnimationPose.of(jointSkeleton); } } diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/AnimationPose.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/AnimationPose.java index b6306a8..5307afc 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/AnimationPose.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/AnimationPose.java @@ -2,7 +2,7 @@ import com.google.common.collect.Maps; import com.mojang.blaze3d.vertex.PoseStack; -import com.trainguy9512.animationoverhaul.util.animation.LocatorSkeleton; +import com.trainguy9512.animationoverhaul.util.animation.JointSkeleton; import com.trainguy9512.animationoverhaul.util.time.Easing; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.NotNull; @@ -14,25 +14,25 @@ public class AnimationPose> { - private final LocatorSkeleton locatorSkeleton; + private final JointSkeleton jointSkeleton; private final HashMap, JointPose> pose; - private AnimationPose(LocatorSkeleton locatorSkeleton){ - this.locatorSkeleton = locatorSkeleton; + private AnimationPose(JointSkeleton jointSkeleton){ + this.jointSkeleton = jointSkeleton; this.pose = Maps.newHashMap(); - for(Enum locator : locatorSkeleton.getLocators()){ + for(Enum locator : jointSkeleton.getLocators()){ this.setJointPose(locator, JointPose.ZERO); } } public AnimationPose(AnimationPose animationPose){ - this.locatorSkeleton = animationPose.locatorSkeleton; + this.jointSkeleton = animationPose.jointSkeleton; this.pose = new HashMap<>(animationPose.pose); } - public static > AnimationPose of(LocatorSkeleton locatorSkeleton){ - return new AnimationPose<>(locatorSkeleton); + public static > AnimationPose of(JointSkeleton jointSkeleton){ + return new AnimationPose<>(jointSkeleton); } @Deprecated @@ -48,8 +48,8 @@ public AnimationPose getCopy(){ */ } - public LocatorSkeleton getSkeleton(){ - return this.locatorSkeleton; + public JointSkeleton getSkeleton(){ + return this.jointSkeleton; } public void applyDefaultPoseOffset(){ @@ -281,9 +281,9 @@ public void mirrorBlended(float alpha){ */ } - public static > AnimationPose fromChannelTimeline(LocatorSkeleton locatorSkeleton, ResourceLocation resourceLocation, float time){ - AnimationPose animationPose = AnimationPose.of(locatorSkeleton); - for(Enum locator : locatorSkeleton.getLocators()){ + public static > AnimationPose fromChannelTimeline(JointSkeleton jointSkeleton, ResourceLocation resourceLocation, float time){ + AnimationPose animationPose = AnimationPose.of(jointSkeleton); + for(Enum locator : jointSkeleton.getLocators()){ animationPose.setJointPose(locator, JointPose.getJointPoseFromChannelTimeline(resourceLocation, locator.toString(), time)); } return animationPose; diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/BakedAnimationPose.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/BakedAnimationPose.java index 3ba6a28..ac590ba 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/BakedAnimationPose.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/BakedAnimationPose.java @@ -27,7 +27,7 @@ public AnimationPose getBlendedPose(float partialTicks){ } public void bakeToModelParts(ModelPart rootModelPart, float partialTicks){ - AnimationPose blendedPose = getBlendedPose(partialTicks); + AnimationPose blendedPose = this.getBlendedPose(partialTicks); for(Enum locator : this.pose.getSkeleton().getLocators()){ if(this.pose.getSkeleton().getLocatorUsesModelPart(locator)){ ModelPart finalModelPart = rootModelPart; diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/AnimationBlendSpacePlayer.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/AnimationBlendSpacePlayer.java index bc49ab0..6a57927 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/AnimationBlendSpacePlayer.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/AnimationBlendSpacePlayer.java @@ -1,7 +1,7 @@ package com.trainguy9512.animationoverhaul.animation.pose.sample; import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; -import com.trainguy9512.animationoverhaul.util.animation.LocatorSkeleton; +import com.trainguy9512.animationoverhaul.util.animation.JointSkeleton; import com.trainguy9512.animationoverhaul.animation.data.AnimationDataContainer; import com.trainguy9512.animationoverhaul.animation.data.TimelineGroupData; import net.minecraft.resources.ResourceLocation; @@ -9,7 +9,7 @@ import java.util.TreeMap; -public class AnimationBlendSpacePlayer extends TimeBasedAnimationState { +public class AnimationBlendSpacePlayer extends TimeBasedPoseSampler { private final TreeMap blendSpaceEntryTreeMap = new TreeMap(); private float currentValue = 0; @@ -60,26 +60,26 @@ private float getPlayRateBlended(){ } @Override - public > AnimationPose sample(LocatorSkeleton locatorSkeleton, AnimationDataContainer.CachedPoseContainer cachedPoseContainer) { + public > AnimationPose sample(JointSkeleton jointSkeleton, AnimationDataContainer.CachedPoseContainer cachedPoseContainer) { if(this.blendSpaceEntryTreeMap.entrySet().size() == 0){ - return AnimationPose.of(locatorSkeleton); + return AnimationPose.of(jointSkeleton); } var firstEntry = this.blendSpaceEntryTreeMap.floorEntry(this.currentValue); var secondEntry = this.blendSpaceEntryTreeMap.ceilingEntry(this.currentValue); if (firstEntry == null) - return secondEntry.getValue().sampleEntry(locatorSkeleton, this.getTimeElapsed()); + return secondEntry.getValue().sampleEntry(jointSkeleton, this.getTimeElapsed()); if (secondEntry == null) - return firstEntry.getValue().sampleEntry(locatorSkeleton, this.getTimeElapsed()); + return firstEntry.getValue().sampleEntry(jointSkeleton, this.getTimeElapsed()); // If they're both the same frame if (firstEntry.getKey().equals(secondEntry.getKey())) - return firstEntry.getValue().sampleEntry(locatorSkeleton, this.getTimeElapsed()); + return firstEntry.getValue().sampleEntry(jointSkeleton, this.getTimeElapsed()); float relativeTime = (this.currentValue - firstEntry.getKey()) / (secondEntry.getKey() - firstEntry.getKey()); - return firstEntry.getValue().sampleEntry(locatorSkeleton, this.getTimeElapsed()).getBlendedLinear( - secondEntry.getValue().sampleEntry(locatorSkeleton, this.getTimeElapsed()), + return firstEntry.getValue().sampleEntry(jointSkeleton, this.getTimeElapsed()).getBlendedLinear( + secondEntry.getValue().sampleEntry(jointSkeleton, this.getTimeElapsed()), relativeTime ); } @@ -104,8 +104,8 @@ private float getTimeFromTicks(float time) { return (time % frameLength) / frameLength; } - private> AnimationPose sampleEntry(LocatorSkeleton locatorSkeleton, float time) { - return AnimationPose.fromChannelTimeline(locatorSkeleton, this.resourceLocation, this.getTimeFromTicks(time)); + private> AnimationPose sampleEntry(JointSkeleton jointSkeleton, float time) { + return AnimationPose.fromChannelTimeline(jointSkeleton, this.resourceLocation, this.getTimeFromTicks(time)); } } } diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/AnimationMontage.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/AnimationMontage.java index 8a03e19..7bcb658 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/AnimationMontage.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/AnimationMontage.java @@ -1,7 +1,7 @@ package com.trainguy9512.animationoverhaul.animation.pose.sample; import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; -import com.trainguy9512.animationoverhaul.util.animation.LocatorSkeleton; +import com.trainguy9512.animationoverhaul.util.animation.JointSkeleton; import com.trainguy9512.animationoverhaul.animation.data.TimelineGroupData; import com.trainguy9512.animationoverhaul.util.time.Easing; import net.minecraft.resources.ResourceLocation; @@ -44,8 +44,8 @@ public void tick(){ setBlendWeight(Mth.clamp(isActive() ? getBlendWeight() + getBlendSpeed(true) : getBlendWeight() - getBlendSpeed(false), 0, 1)); } - public > AnimationPose getAnimationPose(LocatorSkeleton locatorSkeleton){ - return AnimationPose.fromChannelTimeline(locatorSkeleton, this.resourceLocation, (this.timeElapsed + this.startOffset) / TimelineGroupData.INSTANCE.get(resourceLocation).getFrameLength()); + public > AnimationPose getAnimationPose(JointSkeleton jointSkeleton){ + return AnimationPose.fromChannelTimeline(jointSkeleton, this.resourceLocation, (this.timeElapsed + this.startOffset) / TimelineGroupData.INSTANCE.get(resourceLocation).getFrameLength()); } /** diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/AnimationMontageTrack.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/AnimationMontageTrack.java index cf1de35..da53ed1 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/AnimationMontageTrack.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/AnimationMontageTrack.java @@ -1,12 +1,12 @@ package com.trainguy9512.animationoverhaul.animation.pose.sample; import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; -import com.trainguy9512.animationoverhaul.util.animation.LocatorSkeleton; +import com.trainguy9512.animationoverhaul.util.animation.JointSkeleton; import com.trainguy9512.animationoverhaul.animation.data.AnimationDataContainer; import net.minecraft.util.Mth; import java.util.ArrayList; -public class AnimationMontageTrack extends SampleableAnimationState { +public class AnimationMontageTrack extends PoseSampler { private final ArrayList activeMontages = new ArrayList(); @@ -38,22 +38,22 @@ public void tick(){ } @Override - public > AnimationPose sample(LocatorSkeleton locatorSkeleton, AnimationDataContainer.CachedPoseContainer cachedPoseContainer){ - return AnimationPose.of(locatorSkeleton); + public > AnimationPose sample(JointSkeleton jointSkeleton, AnimationDataContainer.CachedPoseContainer cachedPoseContainer){ + return AnimationPose.of(jointSkeleton); } @Override - public > AnimationPose sampleFromInputPose(AnimationPose inputPose, LocatorSkeleton locatorSkeleton, AnimationDataContainer.CachedPoseContainer cachedPoseContainer) { - return getBlendedPose(inputPose, locatorSkeleton); + public > AnimationPose sampleFromInputPose(AnimationPose inputPose, JointSkeleton jointSkeleton, AnimationDataContainer.CachedPoseContainer cachedPoseContainer) { + return getBlendedPose(inputPose, jointSkeleton); } public boolean isActive(){ return this.activeMontages.size() > 0; } - private > AnimationPose getBlendedPose(AnimationPose inputPose, LocatorSkeleton locatorSkeleton){ + private > AnimationPose getBlendedPose(AnimationPose inputPose, JointSkeleton jointSkeleton){ // Initialize the animation pose - AnimationPose animationPose = AnimationPose.of(locatorSkeleton); + AnimationPose animationPose = AnimationPose.of(jointSkeleton); // Only do this stuff if there's any loaded animation montages if(this.activeMontages.size() > 0){ @@ -61,9 +61,9 @@ private > AnimationPose getBlendedPose(AnimationPose inp for(int i = 0; i < this.activeMontages.size(); i++){ AnimationMontage animationMontage = this.activeMontages.get(i); if(i == 0){ - animationPose = animationMontage.getAnimationPose(locatorSkeleton); + animationPose = animationMontage.getAnimationPose(jointSkeleton); } else { - animationPose.blendLinear(animationMontage.getAnimationPose(locatorSkeleton), animationMontage.getBlendWeightEased() + animationPose.blendLinear(animationMontage.getAnimationPose(jointSkeleton), animationMontage.getBlendWeightEased() ); } } diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/AnimationSequencePlayer.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/AnimationSequencePlayer.java index 37cecaa..3b9231b 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/AnimationSequencePlayer.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/AnimationSequencePlayer.java @@ -2,7 +2,7 @@ import com.google.common.collect.Maps; import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; -import com.trainguy9512.animationoverhaul.util.animation.LocatorSkeleton; +import com.trainguy9512.animationoverhaul.util.animation.JointSkeleton; import com.trainguy9512.animationoverhaul.animation.data.AnimationDataContainer; import com.trainguy9512.animationoverhaul.animation.data.TimelineGroupData; import net.minecraft.resources.ResourceLocation; @@ -10,7 +10,7 @@ import java.util.HashMap; -public class AnimationSequencePlayer extends TimeBasedAnimationState { +public class AnimationSequencePlayer extends TimeBasedPoseSampler { private boolean looping = true; private ResourceLocation resourceLocation; @@ -95,8 +95,8 @@ public boolean isAnimNotityActive(String identifier){ } @Override - public > AnimationPose sample(LocatorSkeleton locatorSkeleton, AnimationDataContainer.CachedPoseContainer cachedPoseContainer){ - return AnimationPose.fromChannelTimeline(locatorSkeleton, this.resourceLocation, this.getTimeFromTicks()); + public > AnimationPose sample(JointSkeleton jointSkeleton, AnimationDataContainer.CachedPoseContainer cachedPoseContainer){ + return AnimationPose.fromChannelTimeline(jointSkeleton, this.resourceLocation, this.getTimeFromTicks()); //return super.sample(locatorSkeleton); } diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/AnimationStateMachine.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/AnimationStateMachine.java index 5329511..4f04b50 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/AnimationStateMachine.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/AnimationStateMachine.java @@ -3,7 +3,7 @@ import com.google.common.collect.Maps; import com.trainguy9512.animationoverhaul.AnimationOverhaulMain; import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; -import com.trainguy9512.animationoverhaul.util.animation.LocatorSkeleton; +import com.trainguy9512.animationoverhaul.util.animation.JointSkeleton; import com.trainguy9512.animationoverhaul.animation.data.AnimationDataContainer; import com.trainguy9512.animationoverhaul.util.time.Easing; import net.minecraft.util.Mth; @@ -13,7 +13,7 @@ // Enum S is for state defintions, Enum T is for transition definitions -public class AnimationStateMachine> extends TimeBasedAnimationState { +public class AnimationStateMachine> extends TimeBasedPoseSampler { private final HashMap statesHashMap = Maps.newHashMap(); private final ArrayList activeStates = new ArrayList<>(); @@ -175,18 +175,18 @@ public > AnimationStateMachine setPose(S identifier, Animat return this; } - private > AnimationPose getPoseFromState(Enum identifier, LocatorSkeleton locatorSkeleton){ - return (AnimationPose) this.statesHashMap.get(identifier).getAnimationPose(locatorSkeleton); + private > AnimationPose getPoseFromState(Enum identifier, JointSkeleton jointSkeleton){ + return (AnimationPose) this.statesHashMap.get(identifier).getAnimationPose(jointSkeleton); } @Override - public > AnimationPose sample(LocatorSkeleton locatorSkeleton, AnimationDataContainer.CachedPoseContainer cachedPoseContainer) { + public > AnimationPose sample(JointSkeleton jointSkeleton, AnimationDataContainer.CachedPoseContainer cachedPoseContainer) { if(this.activeStates.size() > 0){ - AnimationPose animationPose = this.getPoseFromState(this.activeStates.get(0), locatorSkeleton); + AnimationPose animationPose = this.getPoseFromState(this.activeStates.get(0), jointSkeleton); if(this.activeStates.size() > 1){ for(Enum stateIdentifier : this.activeStates){ animationPose.blend( - this.getPoseFromState(stateIdentifier, locatorSkeleton), + this.getPoseFromState(stateIdentifier, jointSkeleton), this.statesHashMap.get(stateIdentifier).getWeight(), this.statesHashMap.get(stateIdentifier).getCurrentTransition().getEasing()); } @@ -195,7 +195,7 @@ public > AnimationPose sample(LocatorSkeleton locatorSke return animationPose; } AnimationOverhaulMain.LOGGER.warn("No active states in state machine {}", this.getIdentifier()); - return AnimationPose.of(locatorSkeleton); + return AnimationPose.of(jointSkeleton); } @Override @@ -310,8 +310,8 @@ private void tick(){ } @Nullable - public AnimationPose getAnimationPose(LocatorSkeleton locatorSkeleton){ - return this.animationPose != null ? this.animationPose : AnimationPose.of(locatorSkeleton); + public AnimationPose getAnimationPose(JointSkeleton jointSkeleton){ + return this.animationPose != null ? this.animationPose : AnimationPose.of(jointSkeleton); } public void setAnimationPose(AnimationPose animationPose){ diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/PoseSampler.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/PoseSampler.java new file mode 100644 index 0000000..b2bf148 --- /dev/null +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/PoseSampler.java @@ -0,0 +1,31 @@ +package com.trainguy9512.animationoverhaul.animation.pose.sample; + +import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; +import com.trainguy9512.animationoverhaul.util.animation.JointSkeleton; +import com.trainguy9512.animationoverhaul.animation.data.AnimationDataContainer; + +public class PoseSampler { + + private final String identifier; + + public PoseSampler(String identifier){ + this.identifier = identifier; + } + + public > AnimationPose sample(JointSkeleton jointSkeleton, AnimationDataContainer.CachedPoseContainer cachedPoseContainer) { + return AnimationPose.of(jointSkeleton); + } + + public > AnimationPose sampleFromInputPose(AnimationPose inputPose, JointSkeleton jointSkeleton, AnimationDataContainer.CachedPoseContainer cachedPoseContainer){ + return this.sample(jointSkeleton, cachedPoseContainer); + } + + public void tick(){ + + } + + public String getIdentifier(){ + return this.identifier; + } + +} diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/SampleableAnimationState.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/SampleableAnimationState.java deleted file mode 100644 index cd0fa1a..0000000 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/SampleableAnimationState.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.trainguy9512.animationoverhaul.animation.pose.sample; - -import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; -import com.trainguy9512.animationoverhaul.util.animation.LocatorSkeleton; -import com.trainguy9512.animationoverhaul.animation.data.AnimationDataContainer; - -public class SampleableAnimationState { - - private final String identifier; - - public SampleableAnimationState(String identifier){ - this.identifier = identifier; - } - - public > AnimationPose sample(LocatorSkeleton locatorSkeleton, AnimationDataContainer.CachedPoseContainer cachedPoseContainer) { - return AnimationPose.of(locatorSkeleton); - } - - public > AnimationPose sampleFromInputPose(AnimationPose inputPose, LocatorSkeleton locatorSkeleton, AnimationDataContainer.CachedPoseContainer cachedPoseContainer){ - return this.sample(locatorSkeleton, cachedPoseContainer); - } - - public void tick(){ - - } - - public String getIdentifier(){ - return this.identifier; - } - -} diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/TestReferenceSampler.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/TestReferenceSampler.java index 0165fa8..a00a8da 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/TestReferenceSampler.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/TestReferenceSampler.java @@ -1,10 +1,10 @@ package com.trainguy9512.animationoverhaul.animation.pose.sample; import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; -import com.trainguy9512.animationoverhaul.util.animation.LocatorSkeleton; +import com.trainguy9512.animationoverhaul.util.animation.JointSkeleton; import com.trainguy9512.animationoverhaul.animation.data.AnimationDataContainer; -public class TestReferenceSampler extends SampleableAnimationState { +public class TestReferenceSampler extends PoseSampler { private String cachedPoseIdentifier; @@ -18,8 +18,8 @@ public static TestReferenceSampler of(String identifier, String cachedPoseIdenti } @Override - public AnimationPose sample(LocatorSkeleton locatorSkeleton, AnimationDataContainer.CachedPoseContainer cachedPoseContainer) { - return cachedPoseContainer.getCachedPose(this.cachedPoseIdentifier, locatorSkeleton); + public AnimationPose sample(JointSkeleton jointSkeleton, AnimationDataContainer.CachedPoseContainer cachedPoseContainer) { + return cachedPoseContainer.getCachedPose(this.cachedPoseIdentifier, jointSkeleton); } public void tick(){ diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/TimeBasedAnimationState.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/TimeBasedPoseSampler.java similarity index 94% rename from src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/TimeBasedAnimationState.java rename to src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/TimeBasedPoseSampler.java index e159796..c160f9d 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/TimeBasedAnimationState.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/sample/TimeBasedPoseSampler.java @@ -2,13 +2,13 @@ import java.util.List; -public class TimeBasedAnimationState extends SampleableAnimationState { +public class TimeBasedPoseSampler extends PoseSampler { private float timeElapsed = 0; private float playRate = 1; private boolean playing = true; - public TimeBasedAnimationState(String identifier) { + public TimeBasedPoseSampler(String identifier) { super(identifier); } diff --git a/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinElytraLayer.java b/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinElytraLayer.java index b9501f3..68e322b 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinElytraLayer.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinElytraLayer.java @@ -1,7 +1,7 @@ package com.trainguy9512.animationoverhaul.mixin; import com.mojang.blaze3d.vertex.PoseStack; -import com.trainguy9512.animationoverhaul.animation.AnimatorDispatcher; +import com.trainguy9512.animationoverhaul.animation.EntityJointAnimatorDispatcher; import net.minecraft.client.model.EntityModel; import net.minecraft.client.model.HumanoidModel; import net.minecraft.client.model.geom.ModelPart; @@ -38,6 +38,6 @@ private void transformElytraFinalized(PoseStack poseStack, MultiBufferSource mul } private boolean isValidForElytraTransformation(LivingEntity livingEntity){ - return AnimatorDispatcher.INSTANCE.hasAnimationData(livingEntity.getUUID()); + return EntityJointAnimatorDispatcher.INSTANCE.hasAnimationData(livingEntity.getUUID()); } } diff --git a/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinGameRenderer.java b/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinGameRenderer.java index 6772fa7..3523e08 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinGameRenderer.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinGameRenderer.java @@ -3,13 +3,14 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Axis; import com.trainguy9512.animationoverhaul.AnimationOverhaulMain; -import com.trainguy9512.animationoverhaul.animation.AnimatorDispatcher; -import com.trainguy9512.animationoverhaul.animation.animator.FirstPersonPlayerAnimator; -import com.trainguy9512.animationoverhaul.animation.animator.entity.LivingEntityAnimator; +import com.trainguy9512.animationoverhaul.animation.EntityJointAnimatorDispatcher; +import com.trainguy9512.animationoverhaul.animation.animator.FirstPersonPlayerJointAnimator; +import com.trainguy9512.animationoverhaul.animation.animator.entity.EntityJointAnimator; import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; import com.trainguy9512.animationoverhaul.animation.pose.JointPose; import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; +import net.minecraft.client.model.EntityModel; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; @@ -56,18 +57,18 @@ private void adjustTimersForAllEntities(float f, long l, PoseStack poseStack, Ca @Shadow @Final private Camera mainCamera; @Inject(method = "tick", at = @At("TAIL")) - private void tickEntityInformation(CallbackInfo ci){ + private > void tickEntityInformation(CallbackInfo ci){ if(this.minecraft.level != null){ for(Entity entity : this.minecraft.level.entitiesForRendering()){ if(entity instanceof LivingEntity){ EntityType entityType = entity.getType(); if(AnimationOverhaulMain.ENTITY_ANIMATORS.contains(entityType)){ - LivingEntityAnimator livingEntityAnimator = AnimationOverhaulMain.ENTITY_ANIMATORS.get(entityType); - AnimatorDispatcher.INSTANCE.tickEntity((LivingEntity) entity, livingEntityAnimator); + EntityJointAnimator livingEntityAnimator = (EntityJointAnimator) AnimationOverhaulMain.ENTITY_ANIMATORS.get(entityType); + EntityJointAnimatorDispatcher.INSTANCE.tickEntity((T) entity, livingEntityAnimator); } } } - FirstPersonPlayerAnimator.INSTANCE.tickExternal(); + FirstPersonPlayerJointAnimator.INSTANCE.tickExternal(); } } @@ -83,10 +84,10 @@ private void removeVanillaCameraRotation(PoseStack instance, Quaternionf quatern @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;setInverseViewRotationMatrix(Lorg/joml/Matrix3f;)V")) private void injectCameraRotation(float f, long l, PoseStack poseStack, CallbackInfo ci){ if(this.minecraft.options.getCameraType().isFirstPerson() && this.renderHand){ - if(FirstPersonPlayerAnimator.INSTANCE.localBakedPose != null){ - AnimationPose animationPose = FirstPersonPlayerAnimator.INSTANCE.localBakedPose.getBlendedPose(f); - JointPose cameraPose = animationPose.getJointPoseCopy(FirstPersonPlayerAnimator.FPPlayerLocators.camera); - JointPose rootPose = animationPose.getJointPoseCopy(FirstPersonPlayerAnimator.FPPlayerLocators.root); + if(FirstPersonPlayerJointAnimator.INSTANCE.localBakedPose != null){ + AnimationPose animationPose = FirstPersonPlayerJointAnimator.INSTANCE.localBakedPose.getBlendedPose(f); + JointPose cameraPose = animationPose.getJointPoseCopy(FirstPersonPlayerJointAnimator.FPPlayerLocators.camera); + JointPose rootPose = animationPose.getJointPoseCopy(FirstPersonPlayerJointAnimator.FPPlayerLocators.root); cameraPose.multiplyPose(rootPose); //poseStack.translate(cameraPose.y / 16F, cameraPose.x / -16F, cameraPose.z / -16F); diff --git a/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinItemInHandRenderer.java b/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinItemInHandRenderer.java index 1446912..5e94719 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinItemInHandRenderer.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinItemInHandRenderer.java @@ -2,7 +2,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Axis; -import com.trainguy9512.animationoverhaul.animation.animator.FirstPersonPlayerAnimator; +import com.trainguy9512.animationoverhaul.animation.animator.FirstPersonPlayerJointAnimator; import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; import com.trainguy9512.animationoverhaul.animation.pose.JointPose; import net.minecraft.client.Minecraft; @@ -42,12 +42,12 @@ public abstract class MixinItemInHandRenderer { @Inject(method = "renderHandsWithItems", at = @At("HEAD"), cancellable = true) private void overwriteItemInHandRendering(float f, PoseStack poseStack, MultiBufferSource.BufferSource bufferSource, LocalPlayer localPlayer, int i, CallbackInfo ci){ - if(FirstPersonPlayerAnimator.INSTANCE.localBakedPose != null){ - AnimationPose animationPose = FirstPersonPlayerAnimator.INSTANCE.localBakedPose.getBlendedPose(f); - JointPose rightArmPose = animationPose.getJointPoseCopy(FirstPersonPlayerAnimator.FPPlayerLocators.rightArm); - JointPose leftArmPose = animationPose.getJointPoseCopy(FirstPersonPlayerAnimator.FPPlayerLocators.leftArm); - JointPose rightHandPose = animationPose.getJointPoseCopy(FirstPersonPlayerAnimator.FPPlayerLocators.rightHand); - JointPose leftHandPose = animationPose.getJointPoseCopy(FirstPersonPlayerAnimator.FPPlayerLocators.leftHand); + if(FirstPersonPlayerJointAnimator.INSTANCE.localBakedPose != null){ + AnimationPose animationPose = FirstPersonPlayerJointAnimator.INSTANCE.localBakedPose.getBlendedPose(f); + JointPose rightArmPose = animationPose.getJointPoseCopy(FirstPersonPlayerJointAnimator.FPPlayerLocators.rightArm); + JointPose leftArmPose = animationPose.getJointPoseCopy(FirstPersonPlayerJointAnimator.FPPlayerLocators.leftArm); + JointPose rightHandPose = animationPose.getJointPoseCopy(FirstPersonPlayerJointAnimator.FPPlayerLocators.rightHand); + JointPose leftHandPose = animationPose.getJointPoseCopy(FirstPersonPlayerJointAnimator.FPPlayerLocators.leftHand); poseStack.pushPose(); poseStack.mulPose(Axis.ZP.rotationDegrees(180)); @@ -125,7 +125,7 @@ private void overwriteItemInHandRendering(float f, PoseStack poseStack, MultiBuf - this.renderItemInHand(abstractClientPlayer, FirstPersonPlayerAnimator.INSTANCE.localAnimationDataContainer.get(FirstPersonPlayerAnimator.MAIN_HAND_ITEM).get(), poseStack, HumanoidArm.RIGHT, animationPose, bufferSource, i); + this.renderItemInHand(abstractClientPlayer, FirstPersonPlayerJointAnimator.INSTANCE.localAnimationDataContainer.get(FirstPersonPlayerJointAnimator.MAIN_HAND_ITEM).get(), poseStack, HumanoidArm.RIGHT, animationPose, bufferSource, i); //this.renderItemInHand(abstractClientPlayer, ItemStack.EMPTY, poseStack, HumanoidArm.LEFT, animationPose, bufferSource, i); @@ -138,10 +138,10 @@ private void overwriteItemInHandRendering(float f, PoseStack poseStack, MultiBuf ci.cancel(); } - private void renderItemInHand(AbstractClientPlayer abstractClientPlayer, ItemStack itemStack, PoseStack poseStack, HumanoidArm humanoidArm, AnimationPose animationPose, MultiBufferSource multiBufferSource, int i){ + private void renderItemInHand(AbstractClientPlayer abstractClientPlayer, ItemStack itemStack, PoseStack poseStack, HumanoidArm humanoidArm, AnimationPose animationPose, MultiBufferSource multiBufferSource, int i){ - JointPose armPose = animationPose.getJointPoseCopy(humanoidArm == HumanoidArm.LEFT ? FirstPersonPlayerAnimator.FPPlayerLocators.leftArm : FirstPersonPlayerAnimator.FPPlayerLocators.rightArm); - JointPose handPose = animationPose.getJointPoseCopy(humanoidArm == HumanoidArm.LEFT ? FirstPersonPlayerAnimator.FPPlayerLocators.leftHand : FirstPersonPlayerAnimator.FPPlayerLocators.rightHand); + JointPose armPose = animationPose.getJointPoseCopy(humanoidArm == HumanoidArm.LEFT ? FirstPersonPlayerJointAnimator.FPPlayerLocators.leftArm : FirstPersonPlayerJointAnimator.FPPlayerLocators.rightArm); + JointPose handPose = animationPose.getJointPoseCopy(humanoidArm == HumanoidArm.LEFT ? FirstPersonPlayerJointAnimator.FPPlayerLocators.leftHand : FirstPersonPlayerJointAnimator.FPPlayerLocators.rightHand); diff --git a/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinLivingEntityRenderer.java b/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinLivingEntityRenderer.java index 0986665..559acd9 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinLivingEntityRenderer.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinLivingEntityRenderer.java @@ -2,7 +2,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Axis; -import com.trainguy9512.animationoverhaul.animation.AnimatorDispatcher; +import com.trainguy9512.animationoverhaul.animation.EntityJointAnimatorDispatcher; import com.trainguy9512.animationoverhaul.animation.pose.BakedAnimationPose; import net.minecraft.client.model.EntityModel; import net.minecraft.client.renderer.MultiBufferSource; @@ -35,7 +35,7 @@ protected MixinLivingEntityRenderer(EntityRendererProvider.Context context) { @Redirect(method = "render(Lnet/minecraft/world/entity/LivingEntity;FFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/model/EntityModel;setupAnim(Lnet/minecraft/world/entity/Entity;FFFFF)V")) private void redirectSetupAnim(M entityModel, Entity t, float a, float b, float c, float d, float e, T livingEntity, float f, float g, PoseStack poseStack){ - if(!AnimatorDispatcher.INSTANCE.animateEntity(livingEntity, entityModel, poseStack, g)){ + if(!EntityJointAnimatorDispatcher.INSTANCE.animateEntity(livingEntity, entityModel, poseStack, g)){ entityModel.setupAnim(livingEntity, a, b, c, d, e); } } @@ -46,7 +46,7 @@ private void overwriteSetupRotations(LivingEntityRenderer instance, T livin //poseStack.translate(Mth.sin(bob / 6), 0, 0); //poseStack.mulPose(Vector3f.ZP.rotation(Mth.sin(bob / 6) / 4)); - BakedAnimationPose bakedPose = AnimatorDispatcher.INSTANCE.getBakedPose(livingEntity.getUUID()); + BakedAnimationPose bakedPose = EntityJointAnimatorDispatcher.INSTANCE.getBakedPose(livingEntity.getUUID()); if(shouldUseAlternateRotations(bakedPose)){ @@ -74,7 +74,7 @@ private void overwriteSetupRotations(LivingEntityRenderer instance, T livin @Redirect(method = "render(Lnet/minecraft/world/entity/LivingEntity;FFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;translate(FFF)V", ordinal = 0)) private void removeBedTranslation(PoseStack instance, float d, float e, float f, T livingEntity){ - BakedAnimationPose bakedPose = AnimatorDispatcher.INSTANCE.getBakedPose(livingEntity.getUUID()); + BakedAnimationPose bakedPose = EntityJointAnimatorDispatcher.INSTANCE.getBakedPose(livingEntity.getUUID()); if(shouldUseAlternateRotations(bakedPose)){ } else { diff --git a/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinMinecraft.java b/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinMinecraft.java index 1ae1004..563aefc 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinMinecraft.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinMinecraft.java @@ -1,6 +1,6 @@ package com.trainguy9512.animationoverhaul.mixin; -import com.trainguy9512.animationoverhaul.animation.animator.FirstPersonPlayerAnimator; +import com.trainguy9512.animationoverhaul.animation.animator.FirstPersonPlayerJointAnimator; import net.minecraft.client.Minecraft; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -11,23 +11,27 @@ @Mixin(Minecraft.class) public class MixinMinecraft { + /* + @Inject(method = "startAttack", at = @At("HEAD")) public void injectOnStartAttack(CallbackInfoReturnable cir){ - FirstPersonPlayerAnimator.INSTANCE.localAnimationDataContainer.setValue(FirstPersonPlayerAnimator.IS_ATTACKING, true); + FirstPersonPlayerJointAnimator.INSTANCE.localAnimationDataContainer.setValue(FirstPersonPlayerJointAnimator.IS_ATTACKING, true); } @Inject(method = "startUseItem", at = @At("HEAD")) public void injectOnStartUseItem(CallbackInfo ci){ - FirstPersonPlayerAnimator.INSTANCE.localAnimationDataContainer.setValue(FirstPersonPlayerAnimator.IS_USING_ITEM, true); + FirstPersonPlayerJointAnimator.INSTANCE.localAnimationDataContainer.setValue(FirstPersonPlayerJointAnimator.IS_USING_ITEM, true); } @Inject(method = "continueAttack", at = @At("HEAD")) public void injectOnContinueAttackIsNotMining(boolean bl, CallbackInfo ci){ - FirstPersonPlayerAnimator.INSTANCE.localAnimationDataContainer.setValue(FirstPersonPlayerAnimator.IS_MINING, false); + FirstPersonPlayerJointAnimator.INSTANCE.localAnimationDataContainer.setValue(FirstPersonPlayerJointAnimator.IS_MINING, false); } @Inject(method = "continueAttack", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/ParticleEngine;crack(Lnet/minecraft/core/BlockPos;Lnet/minecraft/core/Direction;)V")) public void injectOnContinueAttackIsMining(boolean bl, CallbackInfo ci){ - FirstPersonPlayerAnimator.INSTANCE.localAnimationDataContainer.setValue(FirstPersonPlayerAnimator.IS_MINING, true); + FirstPersonPlayerJointAnimator.INSTANCE.localAnimationDataContainer.setValue(FirstPersonPlayerJointAnimator.IS_MINING, true); } + + */ } diff --git a/src/main/java/com/trainguy9512/animationoverhaul/util/animation/LocatorSkeleton.java b/src/main/java/com/trainguy9512/animationoverhaul/util/animation/JointSkeleton.java similarity index 92% rename from src/main/java/com/trainguy9512/animationoverhaul/util/animation/LocatorSkeleton.java rename to src/main/java/com/trainguy9512/animationoverhaul/util/animation/JointSkeleton.java index b7e36dd..18635b7 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/util/animation/LocatorSkeleton.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/util/animation/JointSkeleton.java @@ -10,17 +10,17 @@ /** * Structure used for associating locator enums with data such as transform hierarchy, default offset poses, model parts, and mirrors. */ -public class LocatorSkeleton> { +public class JointSkeleton> { private final HashMap, LocatorEntry> locatorHashMap = Maps.newHashMap(); private final Enum rootLocator; - public LocatorSkeleton(Enum rootLocator){ + public JointSkeleton(Enum rootLocator){ this.rootLocator = rootLocator; this.addLocator(rootLocator); } - public LocatorSkeleton(){ + public JointSkeleton(){ this.rootLocator = null; } @@ -30,8 +30,8 @@ public LocatorSkeleton(){ * @param rootLocator The locator to be used as the hierarchical root * @return This locator skeleton */ - public static > LocatorSkeleton of(Enum rootLocator){ - return new LocatorSkeleton(rootLocator); + public static > JointSkeleton of(Enum rootLocator){ + return new JointSkeleton(rootLocator); } /** @@ -41,7 +41,7 @@ public static > LocatorSkeleton of(Enum rootLocator){ * @return This locator skeleton */ @Deprecated - private LocatorSkeleton addLocators(Enum[] locators){ + private JointSkeleton addLocators(Enum[] locators){ for(Enum locator : locators){ this.addLocator(locator); } @@ -56,12 +56,12 @@ private LocatorSkeleton addLocators(Enum[] locators){ * @return This locator skeleton */ - private LocatorSkeleton addLocator(Enumlocator){ + private JointSkeleton addLocator(Enumlocator){ this.locatorHashMap.put(locator, new LocatorEntry(locator)); return this; } - public LocatorSkeleton addChildLocator(Enum locatorChild, Enum locatorParent){ + public JointSkeleton addChildLocator(Enum locatorChild, Enum locatorParent){ if(this.locatorHashMap.keySet().contains(locatorParent)){ this.addLocator(locatorChild); this.locatorHashMap.get(locatorParent).addChild(locatorChild); @@ -70,7 +70,7 @@ public LocatorSkeleton addChildLocator(Enum locatorChild, Enum locatorP return this; } - public LocatorSkeleton addChildLocator(Enum locatorChild){ + public JointSkeleton addChildLocator(Enum locatorChild){ return this.addChildLocator(locatorChild, this.rootLocator); } @@ -152,7 +152,7 @@ public PartPose getLocatorDefaultPose(Enum locator){ * @param mirrored The enum locator that the target will use as a mirror * @return This locator skeleton */ - public LocatorSkeleton setLocatorMirror(Enum locator, Enum mirrored){ + public JointSkeleton setLocatorMirror(Enum locator, Enum mirrored){ this.locatorHashMap.get(locator).setMirroredLocator(mirrored); this.locatorHashMap.get(mirrored).setMirroredLocator(locator); return this; @@ -185,7 +185,7 @@ public boolean getLocatorUsesModelPart(Enum locator){ * @param pose The part pose used as the default pose * @return This skeleton */ - public LocatorSkeleton setLocatorDefaultPose(Enum locator, PartPose pose){ + public JointSkeleton setLocatorDefaultPose(Enum locator, PartPose pose){ this.locatorHashMap.get(locator).setDefaultPose(pose); return this; } @@ -197,7 +197,7 @@ public LocatorSkeleton setLocatorDefaultPose(Enum locator, PartPose pose){ * @param modelPartIdentifier The model part identifier associated with the locator * @return This skeleton */ - public LocatorSkeleton setLocatorModelPart(Enum locator, String modelPartIdentifier){ + public JointSkeleton setLocatorModelPart(Enum locator, String modelPartIdentifier){ this.locatorHashMap.get(locator).setModelPartIdentifier(modelPartIdentifier); return this; }