mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 17:26:01 +08:00
Got rid of the "key" in "keyframes".
We only deal with keyframes in all the animation stuff, it's cleaner without. Sorry if this breaks anyone! Easy fix at least.
This commit is contained in:
parent
40835845be
commit
24538adb1a
@ -127,26 +127,26 @@ public class Animation {
|
||||
|
||||
private final float[] curves; // dfx, dfy, ddfx, ddfy, dddfx, dddfy, ...
|
||||
|
||||
public CurveTimeline (int keyframeCount) {
|
||||
curves = new float[(keyframeCount - 1) * 6];
|
||||
public CurveTimeline (int frameCount) {
|
||||
curves = new float[(frameCount - 1) * 6];
|
||||
}
|
||||
|
||||
public int getKeyframeCount () {
|
||||
public int getFrameCount () {
|
||||
return curves.length / 6 + 1;
|
||||
}
|
||||
|
||||
public void setLinear (int keyframeIndex) {
|
||||
curves[keyframeIndex * 6] = LINEAR;
|
||||
public void setLinear (int frameIndex) {
|
||||
curves[frameIndex * 6] = LINEAR;
|
||||
}
|
||||
|
||||
public void setStepped (int keyframeIndex) {
|
||||
curves[keyframeIndex * 6] = STEPPED;
|
||||
public void setStepped (int frameIndex) {
|
||||
curves[frameIndex * 6] = STEPPED;
|
||||
}
|
||||
|
||||
/** Sets the control handle positions for an interpolation bezier curve used to transition from this keyframe to the next.
|
||||
* cx1 and cx2 are from 0 to 1, representing the percent of time between the two keyframes. cy1 and cy2 are the percent of
|
||||
* the difference between the keyframe's values. */
|
||||
public void setCurve (int keyframeIndex, float cx1, float cy1, float cx2, float cy2) {
|
||||
public void setCurve (int frameIndex, float cx1, float cy1, float cx2, float cy2) {
|
||||
float subdiv_step = 1f / BEZIER_SEGMENTS;
|
||||
float subdiv_step2 = subdiv_step * subdiv_step;
|
||||
float subdiv_step3 = subdiv_step2 * subdiv_step;
|
||||
@ -158,7 +158,7 @@ public class Animation {
|
||||
float tmp1y = -cy1 * 2 + cy2;
|
||||
float tmp2x = (cx1 - cx2) * 3 + 1;
|
||||
float tmp2y = (cy1 - cy2) * 3 + 1;
|
||||
int i = keyframeIndex * 6;
|
||||
int i = frameIndex * 6;
|
||||
float[] curves = this.curves;
|
||||
curves[i] = cx1 * pre1 + tmp1x * pre2 + tmp2x * subdiv_step3;
|
||||
curves[i + 1] = cy1 * pre1 + tmp1y * pre2 + tmp2y * subdiv_step3;
|
||||
@ -168,8 +168,8 @@ public class Animation {
|
||||
curves[i + 5] = tmp2y * pre5;
|
||||
}
|
||||
|
||||
public float getCurvePercent (int keyframeIndex, float percent) {
|
||||
int curveIndex = keyframeIndex * 6;
|
||||
public float getCurvePercent (int frameIndex, float percent) {
|
||||
int curveIndex = frameIndex * 6;
|
||||
float[] curves = this.curves;
|
||||
float dfx = curves[curveIndex];
|
||||
if (dfx == LINEAR) return percent;
|
||||
@ -207,9 +207,9 @@ public class Animation {
|
||||
private int boneIndex;
|
||||
private final float[] frames; // time, value, ...
|
||||
|
||||
public RotateTimeline (int keyframeCount) {
|
||||
super(keyframeCount);
|
||||
frames = new float[keyframeCount * 2];
|
||||
public RotateTimeline (int frameCount) {
|
||||
super(frameCount);
|
||||
frames = new float[frameCount * 2];
|
||||
}
|
||||
|
||||
public void setBoneIndex (int boneIndex) {
|
||||
@ -220,15 +220,15 @@ public class Animation {
|
||||
return boneIndex;
|
||||
}
|
||||
|
||||
public float[] getKeyframes () {
|
||||
public float[] getFrames () {
|
||||
return frames;
|
||||
}
|
||||
|
||||
/** Sets the time and value of the specified keyframe. */
|
||||
public void setKeyframe (int keyframeIndex, float time, float value) {
|
||||
keyframeIndex *= 2;
|
||||
frames[keyframeIndex] = time;
|
||||
frames[keyframeIndex + 1] = value;
|
||||
public void setFrame (int frameIndex, float time, float value) {
|
||||
frameIndex *= 2;
|
||||
frames[frameIndex] = time;
|
||||
frames[frameIndex + 1] = value;
|
||||
}
|
||||
|
||||
public void apply (Skeleton skeleton, float time, float alpha) {
|
||||
@ -276,9 +276,9 @@ public class Animation {
|
||||
int boneIndex;
|
||||
final float[] frames; // time, value, value, ...
|
||||
|
||||
public TranslateTimeline (int keyframeCount) {
|
||||
super(keyframeCount);
|
||||
frames = new float[keyframeCount * 3];
|
||||
public TranslateTimeline (int frameCount) {
|
||||
super(frameCount);
|
||||
frames = new float[frameCount * 3];
|
||||
}
|
||||
|
||||
public void setBoneIndex (int boneIndex) {
|
||||
@ -289,16 +289,16 @@ public class Animation {
|
||||
return boneIndex;
|
||||
}
|
||||
|
||||
public float[] getKeyframes () {
|
||||
public float[] getFrames () {
|
||||
return frames;
|
||||
}
|
||||
|
||||
/** Sets the time and value of the specified keyframe. */
|
||||
public void setKeyframe (int keyframeIndex, float time, float x, float y) {
|
||||
keyframeIndex *= 3;
|
||||
frames[keyframeIndex] = time;
|
||||
frames[keyframeIndex + 1] = x;
|
||||
frames[keyframeIndex + 2] = y;
|
||||
public void setFrame (int frameIndex, float time, float x, float y) {
|
||||
frameIndex *= 3;
|
||||
frames[frameIndex] = time;
|
||||
frames[frameIndex + 1] = x;
|
||||
frames[frameIndex + 2] = y;
|
||||
}
|
||||
|
||||
public void apply (Skeleton skeleton, float time, float alpha) {
|
||||
@ -327,8 +327,8 @@ public class Animation {
|
||||
}
|
||||
|
||||
static public class ScaleTimeline extends TranslateTimeline {
|
||||
public ScaleTimeline (int keyframeCount) {
|
||||
super(keyframeCount);
|
||||
public ScaleTimeline (int frameCount) {
|
||||
super(frameCount);
|
||||
}
|
||||
|
||||
public void apply (Skeleton skeleton, float time, float alpha) {
|
||||
@ -367,9 +367,9 @@ public class Animation {
|
||||
private int slotIndex;
|
||||
private final float[] frames; // time, r, g, b, a, ...
|
||||
|
||||
public ColorTimeline (int keyframeCount) {
|
||||
super(keyframeCount);
|
||||
frames = new float[keyframeCount * 5];
|
||||
public ColorTimeline (int frameCount) {
|
||||
super(frameCount);
|
||||
frames = new float[frameCount * 5];
|
||||
}
|
||||
|
||||
public void setSlotIndex (int slotIndex) {
|
||||
@ -380,18 +380,18 @@ public class Animation {
|
||||
return slotIndex;
|
||||
}
|
||||
|
||||
public float[] getKeyframes () {
|
||||
public float[] getFrames () {
|
||||
return frames;
|
||||
}
|
||||
|
||||
/** Sets the time and value of the specified keyframe. */
|
||||
public void setKeyframe (int keyframeIndex, float time, float r, float g, float b, float a) {
|
||||
keyframeIndex *= 5;
|
||||
frames[keyframeIndex] = time;
|
||||
frames[keyframeIndex + 1] = r;
|
||||
frames[keyframeIndex + 2] = g;
|
||||
frames[keyframeIndex + 3] = b;
|
||||
frames[keyframeIndex + 4] = a;
|
||||
public void setFrame (int frameIndex, float time, float r, float g, float b, float a) {
|
||||
frameIndex *= 5;
|
||||
frames[frameIndex] = time;
|
||||
frames[frameIndex + 1] = r;
|
||||
frames[frameIndex + 2] = g;
|
||||
frames[frameIndex + 3] = b;
|
||||
frames[frameIndex + 4] = a;
|
||||
}
|
||||
|
||||
public void apply (Skeleton skeleton, float time, float alpha) {
|
||||
@ -436,12 +436,12 @@ public class Animation {
|
||||
private final float[] frames; // time, ...
|
||||
private final String[] attachmentNames;
|
||||
|
||||
public AttachmentTimeline (int keyframeCount) {
|
||||
frames = new float[keyframeCount];
|
||||
attachmentNames = new String[keyframeCount];
|
||||
public AttachmentTimeline (int frameCount) {
|
||||
frames = new float[frameCount];
|
||||
attachmentNames = new String[frameCount];
|
||||
}
|
||||
|
||||
public int getKeyframeCount () {
|
||||
public int getFrameCount () {
|
||||
return frames.length;
|
||||
}
|
||||
|
||||
@ -453,7 +453,7 @@ public class Animation {
|
||||
this.slotIndex = slotIndex;
|
||||
}
|
||||
|
||||
public float[] getKeyframes () {
|
||||
public float[] getFrames () {
|
||||
return frames;
|
||||
}
|
||||
|
||||
@ -462,9 +462,9 @@ public class Animation {
|
||||
}
|
||||
|
||||
/** Sets the time and value of the specified keyframe. */
|
||||
public void setKeyframe (int keyframeIndex, float time, String attachmentName) {
|
||||
frames[keyframeIndex] = time;
|
||||
attachmentNames[keyframeIndex] = attachmentName;
|
||||
public void setFrame (int frameIndex, float time, String attachmentName) {
|
||||
frames[frameIndex] = time;
|
||||
attachmentNames[frameIndex] = attachmentName;
|
||||
}
|
||||
|
||||
public void apply (Skeleton skeleton, float time, float alpha) {
|
||||
|
||||
@ -206,11 +206,11 @@ public class SkeletonBinary {
|
||||
RotateTimeline timeline = new RotateTimeline(keyCount);
|
||||
timeline.setBoneIndex(boneIndex);
|
||||
for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++) {
|
||||
timeline.setKeyframe(keyframeIndex, input.readFloat(), input.readFloat());
|
||||
timeline.setFrame(keyframeIndex, input.readFloat(), input.readFloat());
|
||||
if (keyframeIndex < keyCount - 1) readCurve(input, keyframeIndex, timeline);
|
||||
}
|
||||
timelines.add(timeline);
|
||||
duration = Math.max(duration, timeline.getKeyframes()[keyCount * 2 - 2]);
|
||||
duration = Math.max(duration, timeline.getFrames()[keyCount * 2 - 2]);
|
||||
break;
|
||||
}
|
||||
case TIMELINE_TRANSLATE:
|
||||
@ -225,12 +225,12 @@ public class SkeletonBinary {
|
||||
}
|
||||
timeline.setBoneIndex(boneIndex);
|
||||
for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++) {
|
||||
timeline.setKeyframe(keyframeIndex, input.readFloat(), input.readFloat() * timelineScale, input.readFloat()
|
||||
timeline.setFrame(keyframeIndex, input.readFloat(), input.readFloat() * timelineScale, input.readFloat()
|
||||
* timelineScale);
|
||||
if (keyframeIndex < keyCount - 1) readCurve(input, keyframeIndex, timeline);
|
||||
}
|
||||
timelines.add(timeline);
|
||||
duration = Math.max(duration, timeline.getKeyframes()[keyCount * 3 - 3]);
|
||||
duration = Math.max(duration, timeline.getFrames()[keyCount * 3 - 3]);
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Invalid timeline type for a bone: " + timelineType + " (" + boneName + ")");
|
||||
@ -253,20 +253,20 @@ public class SkeletonBinary {
|
||||
for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++) {
|
||||
float time = input.readFloat();
|
||||
Color.rgba8888ToColor(tempColor, input.readInt());
|
||||
timeline.setKeyframe(keyframeIndex, time, tempColor.r, tempColor.g, tempColor.b, tempColor.a);
|
||||
timeline.setFrame(keyframeIndex, time, tempColor.r, tempColor.g, tempColor.b, tempColor.a);
|
||||
if (keyframeIndex < keyCount - 1) readCurve(input, keyframeIndex, timeline);
|
||||
}
|
||||
timelines.add(timeline);
|
||||
duration = Math.max(duration, timeline.getKeyframes()[keyCount * 5 - 5]);
|
||||
duration = Math.max(duration, timeline.getFrames()[keyCount * 5 - 5]);
|
||||
break;
|
||||
}
|
||||
case TIMELINE_ATTACHMENT:
|
||||
AttachmentTimeline timeline = new AttachmentTimeline(keyCount);
|
||||
timeline.setSlotIndex(slotIndex);
|
||||
for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++)
|
||||
timeline.setKeyframe(keyframeIndex, input.readFloat(), input.readString());
|
||||
timeline.setFrame(keyframeIndex, input.readFloat(), input.readString());
|
||||
timelines.add(timeline);
|
||||
duration = Math.max(duration, timeline.getKeyframes()[keyCount - 1]);
|
||||
duration = Math.max(duration, timeline.getFrames()[keyCount - 1]);
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Invalid timeline type for a slot: " + timelineType + " (" + slotName + ")");
|
||||
|
||||
@ -206,12 +206,12 @@ public class SkeletonJson {
|
||||
int keyframeIndex = 0;
|
||||
for (OrderedMap valueMap : values) {
|
||||
float time = (Float)valueMap.get("time");
|
||||
timeline.setKeyframe(keyframeIndex, time, (Float)valueMap.get("angle"));
|
||||
timeline.setFrame(keyframeIndex, time, (Float)valueMap.get("angle"));
|
||||
readCurve(timeline, keyframeIndex, valueMap);
|
||||
keyframeIndex++;
|
||||
}
|
||||
timelines.add(timeline);
|
||||
duration = Math.max(duration, timeline.getKeyframes()[timeline.getKeyframeCount() * 2 - 2]);
|
||||
duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() * 2 - 2]);
|
||||
|
||||
} else if (timelineName.equals(TIMELINE_TRANSLATE) || timelineName.equals(TIMELINE_SCALE)) {
|
||||
TranslateTimeline timeline;
|
||||
@ -228,13 +228,13 @@ public class SkeletonJson {
|
||||
for (OrderedMap valueMap : values) {
|
||||
float time = (Float)valueMap.get("time");
|
||||
Float x = (Float)valueMap.get("x"), y = (Float)valueMap.get("y");
|
||||
timeline.setKeyframe(keyframeIndex, time, x == null ? 0 : (x * timelineScale), y == null ? 0
|
||||
timeline.setFrame(keyframeIndex, time, x == null ? 0 : (x * timelineScale), y == null ? 0
|
||||
: (y * timelineScale));
|
||||
readCurve(timeline, keyframeIndex, valueMap);
|
||||
keyframeIndex++;
|
||||
}
|
||||
timelines.add(timeline);
|
||||
duration = Math.max(duration, timeline.getKeyframes()[timeline.getKeyframeCount() * 3 - 3]);
|
||||
duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() * 3 - 3]);
|
||||
|
||||
} else
|
||||
throw new RuntimeException("Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")");
|
||||
@ -259,12 +259,12 @@ public class SkeletonJson {
|
||||
for (OrderedMap valueMap : values) {
|
||||
float time = (Float)valueMap.get("time");
|
||||
Color color = Color.valueOf((String)valueMap.get("color"));
|
||||
timeline.setKeyframe(keyframeIndex, time, color.r, color.g, color.b, color.a);
|
||||
timeline.setFrame(keyframeIndex, time, color.r, color.g, color.b, color.a);
|
||||
readCurve(timeline, keyframeIndex, valueMap);
|
||||
keyframeIndex++;
|
||||
}
|
||||
timelines.add(timeline);
|
||||
duration = Math.max(duration, timeline.getKeyframes()[timeline.getKeyframeCount() * 5 - 5]);
|
||||
duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() * 5 - 5]);
|
||||
|
||||
} else if (timelineName.equals(TIMELINE_ATTACHMENT)) {
|
||||
AttachmentTimeline timeline = new AttachmentTimeline(values.size);
|
||||
@ -273,10 +273,10 @@ public class SkeletonJson {
|
||||
int keyframeIndex = 0;
|
||||
for (OrderedMap valueMap : values) {
|
||||
float time = (Float)valueMap.get("time");
|
||||
timeline.setKeyframe(keyframeIndex++, time, (String)valueMap.get("name"));
|
||||
timeline.setFrame(keyframeIndex++, time, (String)valueMap.get("name"));
|
||||
}
|
||||
timelines.add(timeline);
|
||||
duration = Math.max(duration, timeline.getKeyframes()[timeline.getKeyframeCount() - 1]);
|
||||
duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() - 1]);
|
||||
|
||||
} else
|
||||
throw new RuntimeException("Invalid timeline type for a slot: " + timelineName + " (" + slotName + ")");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user