From 443c3c3670227a35b5bea66938384e82fcd64feb Mon Sep 17 00:00:00 2001 From: Trainguy9512 Date: Thu, 7 Mar 2024 04:25:33 -0600 Subject: [PATCH] Joint Rotations - Implemented a rotate joint function - Fixed the JointPose transformPoseStack method to actually use the transform mutliplier from before. - Temporarily fixed FP hand item positions with a 180 deg X rotation --- .../entity/FirstPersonPlayerAnimator.java | 6 ++++-- .../animation/pose/AnimationPose.java | 17 +++++++++++++++++ .../animation/pose/JointPose.java | 9 +++++---- .../mixin/MixinItemInHandRenderer.java | 3 ++- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/entity/FirstPersonPlayerAnimator.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/entity/FirstPersonPlayerAnimator.java index cbbf98f..e2ae656 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/entity/FirstPersonPlayerAnimator.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/entity/FirstPersonPlayerAnimator.java @@ -201,8 +201,10 @@ protected AnimationPose calculatePose() { pose = dampenArmRotation(pose); - Vector3f translation = new Vector3f(Mth.sin(getEntityAnimationVariable(TIME_TEST) * 1.3F) * 3F, 0, 0); - pose.translateJoint(FPPlayerLocators.rightArm, translation, AnimationPose.TransformSpace.ENTITY, false); + 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; 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 b89fe21..b6306a8 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/AnimationPose.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/AnimationPose.java @@ -150,6 +150,9 @@ private void convertChildrenSpaceEntityToLocal(Enum parent, Matrix4f parentMa } } + + + public void blend(AnimationPose animationPose, float alpha, Easing easing){ for(Enum locator : this.getSkeleton().getLocators()){ JointPose jointPoseA = this.getJointPoseCopy(locator); @@ -234,6 +237,20 @@ public AnimationPose translateJoint(Enum joint, Vector3f translation, Tran return this; } + public AnimationPose rotateJoint(Enum joint, Vector3f rotationXYZ, TransformSpace transformSpace, boolean replaceExisting){ + convertSpaceEntityToLocal(); + if(transformSpace == TransformSpace.ENTITY){ + convertSpaceLocalToEntity(joint); + } + if(replaceExisting){ + this.getJointPoseReference(joint).setEulerRotationXYZ(rotationXYZ); + } else { + this.getJointPoseReference(joint).rotate(rotationXYZ, transformSpace); + } + convertSpaceEntityToLocal(); + return this; + } + public void mirror(){ diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/JointPose.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/JointPose.java index 39c7332..0385c7e 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/JointPose.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/JointPose.java @@ -166,9 +166,10 @@ public JointPose translate(Vector3f translation, AnimationPose.TransformSpace tr public JointPose rotate(Quaternionf rotation, AnimationPose.TransformSpace transformSpace){ if(transformSpace == AnimationPose.TransformSpace.LOCAL){ - this.getTransformReference().rotateLocal(rotation); - } else { this.getTransformReference().rotate(rotation); + } else { + //this.getTransformReference().rotateLocal(rotation); + this.setRotation(this.getTransformCopy().getNormalizedRotation(new Quaternionf()).premul(rotation)); } return this; } @@ -313,7 +314,7 @@ public void rotatePoseStackInverse(PoseStack poseStack){ } public void transformPoseStack(PoseStack poseStack, float transformMultiplier){ - poseStack.mulPoseMatrix(this.getTransformCopy()); + poseStack.mulPoseMatrix(this.getTransformCopy().setTranslation(this.getTranslation().div(new Vector3f(transformMultiplier)))); //poseStack.translate(this.translation.x / transformMultiplier, this.translation.y / transformMultiplier, this.translation.z / transformMultiplier); //this.rotatePoseStack(poseStack); @@ -327,7 +328,7 @@ public void transformPoseStack(PoseStack poseStack, float transformMultiplier){ } public void transformPoseStack(PoseStack poseStack){ - this.transformPoseStack(poseStack, 16F); + this.transformPoseStack(poseStack, 1F); } public void transformModelPart(ModelPart modelPart){ diff --git a/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinItemInHandRenderer.java b/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinItemInHandRenderer.java index 2466d71..42f1f09 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinItemInHandRenderer.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinItemInHandRenderer.java @@ -148,7 +148,8 @@ private void renderItemInHand(AbstractClientPlayer abstractClientPlayer, ItemSta poseStack.pushPose(); //armPose.transformPoseStack(poseStack); //poseStack.translate((humanoidArm == HumanoidArm.LEFT ? 1 : -1) /16F, 9/16F, 0); - handPose.transformPoseStack(poseStack); + handPose.transformPoseStack(poseStack, 16F); + poseStack.mulPose(Axis.XP.rotationDegrees(180.0f)); //poseStack.mulPose(Axis.XP.rotationDegrees(-90.0f)); //poseStack.mulPose(Axis.YP.rotationDegrees(180.0f));