Skip to content
Draft
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 @@ -243,14 +243,15 @@ private static KeyframeStack buildKeyframeStack(List<FloatObjectPair<JsonElement
List<Expression> xPrev = null;
List<Expression> yPrev = null;
List<Expression> zPrev = null;
FloatObjectPair<JsonElement> prevEntry = null;

float prevTimeX = 0;
float prevTimeY = 0;
float prevTimeZ = 0;

for (FloatObjectPair<JsonElement> entry : entries) {
JsonElement element = entry.right();

float prevTime = prevEntry != null ? prevEntry.leftFloat() : 0;
float curTime = entry.leftFloat();
float timeDelta = curTime - prevTime;

boolean isForRotation = type == TransformType.ROTATION || type == TransformType.BEND;
Expression defaultValue = type == TransformType.SCALE ? FloatExpression.ONE : FloatExpression.ZERO;
Expand All @@ -264,14 +265,21 @@ private static KeyframeStack buildKeyframeStack(List<FloatObjectPair<JsonElement
EasingType easingType = getEasingForAxis(entryObj, null, EasingType.LINEAR);
List<List<Expression>> easingArgs = getEasingArgsForAxis(entryObj, null, new ObjectArrayList<>());

xFrames.add(new Keyframe(timeDelta * 20, prevEntry == null ? xValue : xPrev, xValue, getEasingForAxis(entryObj, Axis.X, easingType), getEasingArgsForAxis(entryObj, Axis.X, easingArgs)));
yFrames.add(new Keyframe(timeDelta * 20, prevEntry == null ? yValue : yPrev, yValue, getEasingForAxis(entryObj, Axis.Y, easingType), getEasingArgsForAxis(entryObj, Axis.Y, easingArgs)));
zFrames.add(new Keyframe(timeDelta * 20, prevEntry == null ? zValue : zPrev, zValue, getEasingForAxis(entryObj, Axis.Z, easingType), getEasingArgsForAxis(entryObj, Axis.Z, easingArgs)));

xPrev = xValue;
yPrev = yValue;
zPrev = zValue;
prevEntry = entry;
if (isEnabled(xValue)) {
xFrames.add(new Keyframe((curTime - prevTimeX) * 20, xPrev == null ? xValue : xPrev, xValue, getEasingForAxis(entryObj, Axis.X, easingType), getEasingArgsForAxis(entryObj, Axis.X, easingArgs)));
xPrev = xValue;
prevTimeX = curTime;
}
if (isEnabled(yValue)) {
yFrames.add(new Keyframe((curTime - prevTimeY) * 20, yPrev == null ? yValue : yPrev, yValue, getEasingForAxis(entryObj, Axis.Y, easingType), getEasingArgsForAxis(entryObj, Axis.Y, easingArgs)));
yPrev = yValue;
prevTimeY = curTime;
}
if (isEnabled(zValue)) {
zFrames.add(new Keyframe((curTime - prevTimeZ) * 20, zPrev == null ? zValue : zPrev, zValue, getEasingForAxis(entryObj, Axis.Z, easingType), getEasingArgsForAxis(entryObj, Axis.Z, easingArgs)));
zPrev = zValue;
prevTimeZ = curTime;
}
}

return new KeyframeStack(addArgsForKeyframes(xFrames), addArgsForKeyframes(yFrames), addArgsForKeyframes(zFrames));
Expand All @@ -292,11 +300,6 @@ private static List<List<Expression>> getEasingArgsForAxis(JsonObject entryObj,
}

private static List<Keyframe> addArgsForKeyframes(List<Keyframe> frames) {
if (frames.getFirst().startValue().getFirst() instanceof AccessExpression accessExpression
&& "disabled".equals(accessExpression.property()) && accessExpression.object() instanceof IdentifierExpression identifierExpression
&& "pal".equals(identifierExpression.name()))
return Collections.emptyList();

if (frames.size() == 1) {
Keyframe frame = frames.getFirst();

Expand Down Expand Up @@ -335,6 +338,13 @@ else if (frame.easingType() == EasingType.BEZIER) {
return frames;
}


private static boolean isEnabled(List<Expression> expressions) {
return expressions.size() != 1 || !(expressions.getFirst() instanceof AccessExpression accessExpression)
|| !"disabled".equals(accessExpression.property()) || !(accessExpression.object() instanceof IdentifierExpression identifierExpression)
|| !"pal".equals(identifierExpression.name());
}

public static float calculateAnimationLength(Map<String, BoneAnimation> boneAnimations) {
float length = 0;

Expand Down