mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-07 19:26:54 +08:00
Minor updates.
This commit is contained in:
parent
48cfd1d874
commit
7a08bad7c7
@ -115,8 +115,9 @@ public class Animation {
|
|||||||
|
|
||||||
/** Base class for frames that use an interpolation bezier curve. */
|
/** Base class for frames that use an interpolation bezier curve. */
|
||||||
abstract static public class CurveTimeline implements Timeline {
|
abstract static public class CurveTimeline implements Timeline {
|
||||||
static private final float LINEAR = 0;
|
static public final float LINEAR = 0;
|
||||||
static private final float STEPPED = -1;
|
static public final float STEPPED = -1;
|
||||||
|
static public final float BEZIER = -2;
|
||||||
static private final int BEZIER_SEGMENTS = 10;
|
static private final int BEZIER_SEGMENTS = 10;
|
||||||
|
|
||||||
private final float[] curves; // dfx, dfy, ddfx, ddfy, dddfx, dddfy, ...
|
private final float[] curves; // dfx, dfy, ddfx, ddfy, dddfx, dddfy, ...
|
||||||
@ -137,6 +138,15 @@ public class Animation {
|
|||||||
curves[frameIndex * 6] = STEPPED;
|
curves[frameIndex * 6] = STEPPED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getCurveType (int frameIndex) {
|
||||||
|
int index = frameIndex * 6;
|
||||||
|
if (index == curves.length) return LINEAR;
|
||||||
|
float type = curves[index];
|
||||||
|
if (type == LINEAR) return LINEAR;
|
||||||
|
if (type == STEPPED) return STEPPED;
|
||||||
|
return BEZIER;
|
||||||
|
}
|
||||||
|
|
||||||
/** Sets the control handle positions for an interpolation bezier curve used to transition from this keyframe to the next.
|
/** 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
|
* 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. */
|
* the difference between the keyframe's values. */
|
||||||
|
|||||||
@ -215,9 +215,9 @@ public class SkeletonBinary {
|
|||||||
case TIMELINE_ROTATE: {
|
case TIMELINE_ROTATE: {
|
||||||
RotateTimeline timeline = new RotateTimeline(keyCount);
|
RotateTimeline timeline = new RotateTimeline(keyCount);
|
||||||
timeline.setBoneIndex(boneIndex);
|
timeline.setBoneIndex(boneIndex);
|
||||||
for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++) {
|
for (int frameIndex = 0; frameIndex < keyCount; frameIndex++) {
|
||||||
timeline.setFrame(keyframeIndex, input.readFloat(), input.readFloat());
|
timeline.setFrame(frameIndex, input.readFloat(), input.readFloat());
|
||||||
if (keyframeIndex < keyCount - 1) readCurve(input, keyframeIndex, timeline);
|
if (frameIndex < keyCount - 1) readCurve(input, frameIndex, timeline);
|
||||||
}
|
}
|
||||||
timelines.add(timeline);
|
timelines.add(timeline);
|
||||||
duration = Math.max(duration, timeline.getFrames()[keyCount * 2 - 2]);
|
duration = Math.max(duration, timeline.getFrames()[keyCount * 2 - 2]);
|
||||||
@ -234,10 +234,10 @@ public class SkeletonBinary {
|
|||||||
timelineScale = scale;
|
timelineScale = scale;
|
||||||
}
|
}
|
||||||
timeline.setBoneIndex(boneIndex);
|
timeline.setBoneIndex(boneIndex);
|
||||||
for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++) {
|
for (int frameIndex = 0; frameIndex < keyCount; frameIndex++) {
|
||||||
timeline.setFrame(keyframeIndex, input.readFloat(), input.readFloat() * timelineScale, input.readFloat()
|
timeline.setFrame(frameIndex, input.readFloat(), input.readFloat() * timelineScale, input.readFloat()
|
||||||
* timelineScale);
|
* timelineScale);
|
||||||
if (keyframeIndex < keyCount - 1) readCurve(input, keyframeIndex, timeline);
|
if (frameIndex < keyCount - 1) readCurve(input, frameIndex, timeline);
|
||||||
}
|
}
|
||||||
timelines.add(timeline);
|
timelines.add(timeline);
|
||||||
duration = Math.max(duration, timeline.getFrames()[keyCount * 3 - 3]);
|
duration = Math.max(duration, timeline.getFrames()[keyCount * 3 - 3]);
|
||||||
@ -260,11 +260,11 @@ public class SkeletonBinary {
|
|||||||
case TIMELINE_COLOR: {
|
case TIMELINE_COLOR: {
|
||||||
ColorTimeline timeline = new ColorTimeline(keyCount);
|
ColorTimeline timeline = new ColorTimeline(keyCount);
|
||||||
timeline.setSlotIndex(slotIndex);
|
timeline.setSlotIndex(slotIndex);
|
||||||
for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++) {
|
for (int frameIndex = 0; frameIndex < keyCount; frameIndex++) {
|
||||||
float time = input.readFloat();
|
float time = input.readFloat();
|
||||||
Color.rgba8888ToColor(tempColor, input.readInt());
|
Color.rgba8888ToColor(tempColor, input.readInt());
|
||||||
timeline.setFrame(keyframeIndex, time, tempColor.r, tempColor.g, tempColor.b, tempColor.a);
|
timeline.setFrame(frameIndex, time, tempColor.r, tempColor.g, tempColor.b, tempColor.a);
|
||||||
if (keyframeIndex < keyCount - 1) readCurve(input, keyframeIndex, timeline);
|
if (frameIndex < keyCount - 1) readCurve(input, frameIndex, timeline);
|
||||||
}
|
}
|
||||||
timelines.add(timeline);
|
timelines.add(timeline);
|
||||||
duration = Math.max(duration, timeline.getFrames()[keyCount * 5 - 5]);
|
duration = Math.max(duration, timeline.getFrames()[keyCount * 5 - 5]);
|
||||||
@ -273,8 +273,8 @@ public class SkeletonBinary {
|
|||||||
case TIMELINE_ATTACHMENT:
|
case TIMELINE_ATTACHMENT:
|
||||||
AttachmentTimeline timeline = new AttachmentTimeline(keyCount);
|
AttachmentTimeline timeline = new AttachmentTimeline(keyCount);
|
||||||
timeline.setSlotIndex(slotIndex);
|
timeline.setSlotIndex(slotIndex);
|
||||||
for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++)
|
for (int frameIndex = 0; frameIndex < keyCount; frameIndex++)
|
||||||
timeline.setFrame(keyframeIndex, input.readFloat(), input.readString());
|
timeline.setFrame(frameIndex, input.readFloat(), input.readString());
|
||||||
timelines.add(timeline);
|
timelines.add(timeline);
|
||||||
duration = Math.max(duration, timeline.getFrames()[keyCount - 1]);
|
duration = Math.max(duration, timeline.getFrames()[keyCount - 1]);
|
||||||
break;
|
break;
|
||||||
@ -291,14 +291,18 @@ public class SkeletonBinary {
|
|||||||
skeletonData.addAnimation(new Animation(name, timelines, duration));
|
skeletonData.addAnimation(new Animation(name, timelines, duration));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readCurve (DataInput input, int keyframeIndex, CurveTimeline timeline) throws IOException {
|
private void readCurve (DataInput input, int frameIndex, CurveTimeline timeline) throws IOException {
|
||||||
switch (input.readByte()) {
|
switch (input.readByte()) {
|
||||||
case CURVE_STEPPED:
|
case CURVE_STEPPED:
|
||||||
timeline.setStepped(keyframeIndex);
|
timeline.setStepped(frameIndex);
|
||||||
break;
|
break;
|
||||||
case CURVE_BEZIER:
|
case CURVE_BEZIER:
|
||||||
timeline.setCurve(keyframeIndex, input.readFloat(), input.readFloat(), input.readFloat(), input.readFloat());
|
setCurve(timeline, frameIndex, input.readFloat(), input.readFloat(), input.readFloat(), input.readFloat());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setCurve (CurveTimeline timeline, int frameIndex, float cx1, float cy1, float cx2, float cy2) {
|
||||||
|
timeline.setCurve(frameIndex, cx1, cy1, cx2, cy2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -269,7 +269,7 @@ public class SkeletonJson {
|
|||||||
skeletonData.addAnimation(new Animation(name, timelines, duration));
|
skeletonData.addAnimation(new Animation(name, timelines, duration));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readCurve (CurveTimeline timeline, int frameIndex, JsonValue valueMap) {
|
void readCurve (CurveTimeline timeline, int frameIndex, JsonValue valueMap) {
|
||||||
JsonValue curve = valueMap.get("curve");
|
JsonValue curve = valueMap.get("curve");
|
||||||
if (curve == null) return;
|
if (curve == null) return;
|
||||||
if (curve.isString() && curve.asString().equals("stepped"))
|
if (curve.isString() && curve.asString().equals("stepped"))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user