diff --git a/core/src/main/java/com/zigythebird/playeranimcore/animation/AnimationController.java b/core/src/main/java/com/zigythebird/playeranimcore/animation/AnimationController.java index 9b2f0fee..6ef93c50 100644 --- a/core/src/main/java/com/zigythebird/playeranimcore/animation/AnimationController.java +++ b/core/src/main/java/com/zigythebird/playeranimcore/animation/AnimationController.java @@ -74,7 +74,6 @@ public abstract class AnimationController implements IAnimation { public static KeyframeLocation EMPTY_SCALE_KEYFRAME_LOCATION = new KeyframeLocation(new Keyframe(0, Collections.singletonList(FloatExpression.ONE), Collections.singletonList(FloatExpression.ONE)), 0); protected final AnimationStateHandler stateHandler; - protected final Map bonePositions; protected final Map bones = new Object2ObjectOpenHashMap<>(); protected final Map activeBones = new Object2ObjectOpenHashMap<>(); protected final Map pivotBones = new Object2ObjectOpenHashMap<>(); @@ -111,12 +110,10 @@ public abstract class AnimationController implements IAnimation { * Instantiates a new {@code AnimationController} * * @param animationHandler The {@link AnimationStateHandler} animation state handler responsible for deciding which animations to play - * @param bonePositions Map of bones and their pivots * @param molangRuntime A function that provides the MoLang runtime engine for this animation controller when applied */ - public AnimationController(AnimationStateHandler animationHandler, Map bonePositions, Function> molangRuntime) { + public AnimationController(AnimationStateHandler animationHandler, Function> molangRuntime) { this.stateHandler = animationHandler; - this.bonePositions = bonePositions; this.molangRuntime = molangRuntime.apply(this); registerBones(); @@ -540,9 +537,6 @@ private void processCurrentAnimation(float adjustedTick, AnimationData animation for (AdvancedPlayerAnimBone bone : this.bones.values()) { bone.setToInitialPose(); } - for (PlayerAnimBone bone : this.pivotBones.values()) { - bone.setToInitialPose(); - } return; } else { @@ -560,9 +554,6 @@ private void processCurrentAnimation(float adjustedTick, AnimationData animation for (PlayerAnimBone bone : this.bones.values()) { bone.setToInitialPose(); } - for (PlayerAnimBone bone : this.pivotBones.values()) { - bone.setToInitialPose(); - } for (Map.Entry entry : animation.boneAnimations().entrySet()) { PlayerAnimBone bone = this.bones.getOrDefault(entry.getKey(), null); @@ -649,7 +640,7 @@ private void processBoneHierarchy(PlayerAnimBone bone, Map paren processBoneHierarchy(parent, parentsMap, processedBones); this.activeBones.put(boneName, bone); - MatrixUtil.applyParentsToChild(bone, Collections.singletonList(parent), this::getBonePosition); + MatrixUtil.applyParentsToChild(bone, Collections.singletonList(parent), _ -> null); processedBones.add(boneName); } @@ -927,12 +918,6 @@ public void setupAnim(AnimationData state) { else process(state); } - public Vec3f getBonePosition(String name) { - if (bonePositions.containsKey(name)) return bonePositions.get(name); - if (pivotBones.containsKey(name)) return pivotBones.get(name).getPivot(); - return Vec3f.ZERO; - } - /** * PLEASE DON'T USE THIS UNLESS YOU KNOW WHAT YOU'RE DOING. * THE {@link AnimationController#linkModifiers()} METHOD MUST BE CALLED EVERYTIME ANYTHING IN THE MODIFIER LIST IS CHANGED. @@ -1001,8 +986,8 @@ protected void linkModifiers() { } } - public AdvancedPlayerAnimBone registerPlayerAnimBone(String name) { - return registerPlayerAnimBone(new AdvancedPlayerAnimBone(name)); + public AdvancedPlayerAnimBone registerPlayerAnimBone(String name, Vec3f pivot) { + return registerPlayerAnimBone(new AdvancedPlayerAnimBone(name, pivot)); } /** diff --git a/core/src/main/java/com/zigythebird/playeranimcore/animation/HumanoidAnimationController.java b/core/src/main/java/com/zigythebird/playeranimcore/animation/HumanoidAnimationController.java index 259ab2ac..edf7e45f 100644 --- a/core/src/main/java/com/zigythebird/playeranimcore/animation/HumanoidAnimationController.java +++ b/core/src/main/java/com/zigythebird/playeranimcore/animation/HumanoidAnimationController.java @@ -67,18 +67,7 @@ public abstract class HumanoidAnimationController extends AnimationController { * @param molangRuntime A function that provides the MoLang runtime engine for this animation controller when applied */ public HumanoidAnimationController(AnimationStateHandler animationHandler, Function> molangRuntime) { - this(animationHandler, BONE_POSITIONS, molangRuntime); - } - - /** - * Instantiates a new {@code AnimationController} - * - * @param animationHandler The {@link AnimationStateHandler} animation state handler responsible for deciding which animations to play - * @param bonePositions Map of bones and their pivots - * @param molangRuntime A function that provides the MoLang runtime engine for this animation controller when applied - */ - public HumanoidAnimationController(AnimationStateHandler animationHandler, Map bonePositions, Function> molangRuntime) { - super(animationHandler, bonePositions, molangRuntime); + super(animationHandler, molangRuntime); } @Override @@ -103,6 +92,10 @@ public void registerTopPlayerAnimBone(String name) { this.registerPlayerAnimBone(name); } + public void registerPlayerAnimBone(String name) { + this.registerPlayerAnimBone(name, BONE_POSITIONS.getOrDefault(name, Vec3f.ZERO)); + } + @Override public void process(AnimationData state) { super.process(state); @@ -122,7 +115,7 @@ public PlayerAnimBone get3DTransformRaw(@NotNull PlayerAnimBone bone) { bone = super.get3DTransformRaw(bone); String name = bone.getName(); if (this.torsoBendSign != 0 && this.top_bones.contains(name)) { - float offset = getBonePosition(name).y() - 18; + float offset = BONE_POSITIONS.get(name).y() - 18; bone.rotation.x += this.torsoBend; bone.position.x += (offset * this.torsoBendZPosMultiplier - offset) * this.torsoBendSign; bone.position.y += offset * this.torsoBendYPosMultiplier; diff --git a/core/src/main/java/com/zigythebird/playeranimcore/bones/AdvancedPlayerAnimBone.java b/core/src/main/java/com/zigythebird/playeranimcore/bones/AdvancedPlayerAnimBone.java index 6300fca2..0e7bd0b4 100644 --- a/core/src/main/java/com/zigythebird/playeranimcore/bones/AdvancedPlayerAnimBone.java +++ b/core/src/main/java/com/zigythebird/playeranimcore/bones/AdvancedPlayerAnimBone.java @@ -1,6 +1,10 @@ package com.zigythebird.playeranimcore.bones; -public class AdvancedPlayerAnimBone extends ToggleablePlayerAnimBone { +import com.zigythebird.playeranimcore.math.Vec3f; + +public class AdvancedPlayerAnimBone extends ToggleablePlayerAnimBone implements IPivotBone { + public Vec3f pivot = null; + public Float scaleXTransitionLength = null; public Float scaleYTransitionLength = null; public Float scaleZTransitionLength = null; @@ -15,12 +19,15 @@ public class AdvancedPlayerAnimBone extends ToggleablePlayerAnimBone { public Float bendTransitionLength = null; - public AdvancedPlayerAnimBone(String name) { + public AdvancedPlayerAnimBone(String name, Vec3f pivot) { super(name); + this.pivot = pivot; } public AdvancedPlayerAnimBone(PlayerAnimBone bone) { super(bone); + if (bone instanceof IPivotBone pivotBone) + this.pivot = pivotBone.getPivot(); } public void setEnabled(boolean enabled) { @@ -78,4 +85,9 @@ public void setScaleYTransitionLength(Float scaleYTransitionLength) { public void setScaleXTransitionLength(Float scaleXTransitionLength) { this.scaleXTransitionLength = scaleXTransitionLength; } + + @Override + public Vec3f getPivot() { + return this.pivot; + } } diff --git a/core/src/main/java/com/zigythebird/playeranimcore/bones/IPivotBone.java b/core/src/main/java/com/zigythebird/playeranimcore/bones/IPivotBone.java new file mode 100644 index 00000000..9fe9e1c4 --- /dev/null +++ b/core/src/main/java/com/zigythebird/playeranimcore/bones/IPivotBone.java @@ -0,0 +1,7 @@ +package com.zigythebird.playeranimcore.bones; + +import com.zigythebird.playeranimcore.math.Vec3f; + +public interface IPivotBone { + Vec3f getPivot(); +} diff --git a/core/src/main/java/com/zigythebird/playeranimcore/loading/PlayerAnimatorLoader.java b/core/src/main/java/com/zigythebird/playeranimcore/loading/PlayerAnimatorLoader.java index 6b70f3b6..ba65fed1 100644 --- a/core/src/main/java/com/zigythebird/playeranimcore/loading/PlayerAnimatorLoader.java +++ b/core/src/main/java/com/zigythebird/playeranimcore/loading/PlayerAnimatorLoader.java @@ -239,7 +239,7 @@ public static EasingType easingTypeFromString(String string) { return easingType; } - private static final Map DEFAULT_VALUES = Map.of( + public static final Map DEFAULT_VALUES = Map.of( "right_arm", new Vec3f(-5, 2, 0), "left_arm", new Vec3f(5, 2, 0), "left_leg", new Vec3f(1.9f, 12, 0.1f), diff --git a/core/src/main/java/com/zigythebird/playeranimcore/util/MatrixUtil.java b/core/src/main/java/com/zigythebird/playeranimcore/util/MatrixUtil.java index e17ab1db..9a813320 100644 --- a/core/src/main/java/com/zigythebird/playeranimcore/util/MatrixUtil.java +++ b/core/src/main/java/com/zigythebird/playeranimcore/util/MatrixUtil.java @@ -1,6 +1,7 @@ package com.zigythebird.playeranimcore.util; import com.zigythebird.playeranimcore.bones.CustomBone; +import com.zigythebird.playeranimcore.bones.IPivotBone; import com.zigythebird.playeranimcore.bones.PlayerAnimBone; import com.zigythebird.playeranimcore.math.Vec3f; import org.joml.Matrix4f; @@ -46,7 +47,7 @@ public static void applyParentsToChild(PlayerAnimBone child, Iterable