Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package com.zigythebird.playeranimcore.animation;

import com.zigythebird.playeranimcore.PlayerAnimLib;
import com.zigythebird.playeranimcore.animation.keyframe.*;
import com.zigythebird.playeranimcore.animation.keyframe.event.CustomKeyFrameEvents;
import com.zigythebird.playeranimcore.animation.keyframe.event.data.CustomInstructionKeyframeData;
Expand Down Expand Up @@ -639,19 +640,27 @@ protected void applyCustomPivotPoints() {
bones1.add(pivotBone);
}

List<String> processedBones = new ArrayList<>();

for (PlayerAnimBone bone : bones1) {
if (parentsMap.containsKey(bone.getName())) {
this.activeBones.put(bone.getName(), bone);

List<PivotBone> parents = new ArrayList<>();
PivotBone currentParent = this.pivotBones.get(parentsMap.get(bone.getName()));
parents.add(currentParent);
List<PlayerAnimBone> parents = new ArrayList<>();
PlayerAnimBone currentParent = bone;
while (parentsMap.containsKey(currentParent.getName())) {
currentParent = this.pivotBones.get(parentsMap.get(currentParent.getName()));
String parentName = parentsMap.get(currentParent.getName());
currentParent = this.pivotBones.containsKey(parentName) ? this.pivotBones.get(parentName) : this.bones.getOrDefault(parentName, null);
if (currentParent == null) {
PlayerAnimLib.LOGGER.error("Failed to find parent bone called {}", parentName);
break;
}
parents.addFirst(currentParent);
if (processedBones.contains(currentParent.getName())) break;
}

MatrixUtil.applyParentsToChild(bone, parents, this::getBonePosition);
processedBones.add(bone.getName());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
* Used for applying custom pivot bones to player bones
*/
public class MatrixUtil {
public static void translateMatrixForBone(ModMatrix4f matrix, PlayerAnimBone bone) {
matrix.translate(-bone.getPosX(), bone.getPosY(), -bone.getPosZ());
}

public static void rotateMatrixAroundBone(ModMatrix4f matrix, PlayerAnimBone bone) {
if (bone.getRotZ() != 0 || bone.getRotY() != 0 || bone.getRotX() != 0)
matrix.rotateZ(bone.getRotZ()).rotateY(bone.getRotY()).rotateX(bone.getRotX());
Expand All @@ -31,6 +35,7 @@ public static void translateAwayFromPivotPoint(ModMatrix4f matrix, Vec3f pivot)

public static void prepMatrixForBone(ModMatrix4f matrix, PlayerAnimBone bone, Vec3f pivot) {
translateToPivotPoint(matrix, pivot);
translateMatrixForBone(matrix, bone);
rotateMatrixAroundBone(matrix, bone);
scaleMatrixForBone(matrix, bone);
translateAwayFromPivotPoint(matrix, pivot);
Expand All @@ -42,7 +47,6 @@ public static void applyParentsToChild(PlayerAnimBone child, Iterable<? extends
for (PlayerAnimBone parent : parents) {
Vec3f pivot = parent instanceof PivotBone pivotBone ? pivotBone.getPivot() : positions.apply(parent.getName());
MatrixUtil.prepMatrixForBone(matrix, parent, pivot);
child.addPos(parent.getPosX(), parent.getPosY(), parent.getPosZ());
}

Vec3f defaultPos = positions.apply(child.getName());
Expand Down