mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 22:34:53 +08:00
Fixed binary path loading.
This commit is contained in:
parent
07bb307b72
commit
8d19504bd7
@ -144,18 +144,14 @@ public class PathConstraint implements Updatable {
|
||||
boolean percentSpacing) {
|
||||
Slot target = this.target;
|
||||
float position = this.position;
|
||||
int verticesLength = path.getWorldVerticesLength(), curveCount = verticesLength / 6, lastCurve = NONE;
|
||||
float[] spaces = this.spaces.items, out = this.positions.setSize(spacesCount * 3 + 2), world;
|
||||
boolean closed = path.getClosed();
|
||||
int verticesLength = path.getWorldVerticesLength(), curveCount = verticesLength / 6, prevCurve = NONE;
|
||||
|
||||
if (!path.getConstantSpeed()) {
|
||||
float[] lengths = path.getLengths().items;
|
||||
float pathLength;
|
||||
if (closed) {
|
||||
curveCount--;
|
||||
pathLength = lengths[curveCount];
|
||||
} else
|
||||
pathLength = lengths[curveCount - 2];
|
||||
float[] lengths = path.getLengths();
|
||||
curveCount -= closed ? 1 : 2;
|
||||
float pathLength = lengths[curveCount];
|
||||
if (percentPosition) position *= pathLength;
|
||||
if (percentSpacing) {
|
||||
for (int i = 0; i < spacesCount; i++)
|
||||
@ -172,15 +168,15 @@ public class PathConstraint implements Updatable {
|
||||
if (p < 0) p += pathLength;
|
||||
curve = 0;
|
||||
} else if (p < 0) {
|
||||
if (lastCurve != BEFORE) {
|
||||
lastCurve = BEFORE;
|
||||
if (prevCurve != BEFORE) {
|
||||
prevCurve = BEFORE;
|
||||
path.computeWorldVertices(target, 2, 4, world, 0);
|
||||
}
|
||||
addBeforePosition(p, world, 0, out, o);
|
||||
continue;
|
||||
} else if (p > pathLength) {
|
||||
if (lastCurve != AFTER) {
|
||||
lastCurve = AFTER;
|
||||
if (prevCurve != AFTER) {
|
||||
prevCurve = AFTER;
|
||||
path.computeWorldVertices(target, verticesLength - 6, 4, world, 0);
|
||||
}
|
||||
addAfterPosition(p - pathLength, world, 0, out, o);
|
||||
@ -199,8 +195,8 @@ public class PathConstraint implements Updatable {
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (curve != lastCurve) {
|
||||
lastCurve = curve;
|
||||
if (curve != prevCurve) {
|
||||
prevCurve = curve;
|
||||
if (closed && curve == curveCount) {
|
||||
path.computeWorldVertices(target, verticesLength - 4, 4, world, 0);
|
||||
path.computeWorldVertices(target, 0, 4, world, 4);
|
||||
@ -303,8 +299,8 @@ public class PathConstraint implements Updatable {
|
||||
}
|
||||
|
||||
// Curve segment lengths.
|
||||
if (curve != lastCurve) {
|
||||
lastCurve = curve;
|
||||
if (curve != prevCurve) {
|
||||
prevCurve = curve;
|
||||
int ii = curve * 6;
|
||||
x1 = world[ii];
|
||||
y1 = world[ii + 1];
|
||||
|
||||
@ -31,6 +31,7 @@
|
||||
|
||||
package com.esotericsoftware.spine;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
@ -138,6 +139,8 @@ public class SkeletonBinary {
|
||||
for (int i = 0; i < byteCount;) {
|
||||
int b = read();
|
||||
switch (b >> 4) {
|
||||
case -1:
|
||||
throw new EOFException();
|
||||
case 12:
|
||||
case 13:
|
||||
chars[charCount++] = (char)((b & 0x1F) << 6 | read() & 0x3F);
|
||||
@ -442,7 +445,7 @@ public class SkeletonBinary {
|
||||
path.setWorldVerticesLength(vertexCount << 1);
|
||||
path.setVertices(vertices.vertices);
|
||||
path.setBones(vertices.bones);
|
||||
path.getLengths().addAll(lengths);
|
||||
path.setLengths(lengths);
|
||||
if (nonessential) Color.rgba8888ToColor(path.getColor(), color);
|
||||
return path;
|
||||
}
|
||||
@ -632,6 +635,7 @@ public class SkeletonBinary {
|
||||
}
|
||||
timelines.add(timeline);
|
||||
duration = Math.max(duration, timeline.getFrames()[(frameCount - 1) * PathConstraintPositionTimeline.ENTRIES]);
|
||||
break;
|
||||
}
|
||||
case PATH_MIX: {
|
||||
PathConstraintMixTimeline timeline = new PathConstraintMixTimeline(frameCount);
|
||||
@ -642,6 +646,7 @@ public class SkeletonBinary {
|
||||
}
|
||||
timelines.add(timeline);
|
||||
duration = Math.max(duration, timeline.getFrames()[(frameCount - 1) * PathConstraintMixTimeline.ENTRIES]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -744,11 +749,7 @@ public class SkeletonBinary {
|
||||
timelines.add(timeline);
|
||||
duration = Math.max(duration, timeline.getFrames()[eventCount - 1]);
|
||||
}
|
||||
} catch (
|
||||
|
||||
IOException ex)
|
||||
|
||||
{
|
||||
} catch (IOException ex) {
|
||||
throw new SerializationException("Error reading skeleton file.", ex);
|
||||
}
|
||||
|
||||
|
||||
@ -359,10 +359,11 @@ public class SkeletonJson {
|
||||
int vertexCount = map.getInt("vertexCount");
|
||||
readVertices(map, path, vertexCount << 1);
|
||||
|
||||
float[] lengths = path.getLengths().setSize(vertexCount / 3);
|
||||
float[] lengths = new float[vertexCount / 3];
|
||||
int i = 0;
|
||||
for (JsonValue curves = map.require("lengths").child; curves != null; curves = curves.next)
|
||||
lengths[i++] = curves.asFloat() * scale;
|
||||
path.setLengths(lengths);
|
||||
|
||||
String color = map.getString("color", null);
|
||||
if (color != null) path.getColor().set(Color.valueOf(color));
|
||||
|
||||
@ -32,11 +32,10 @@
|
||||
package com.esotericsoftware.spine.attachments;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.FloatArray;
|
||||
import com.esotericsoftware.spine.Slot;
|
||||
|
||||
public class PathAttachment extends VertexAttachment {
|
||||
final FloatArray lengths = new FloatArray();
|
||||
float[] lengths;
|
||||
boolean closed, constantSpeed;
|
||||
|
||||
// Nonessential.
|
||||
@ -71,10 +70,14 @@ public class PathAttachment extends VertexAttachment {
|
||||
}
|
||||
|
||||
/** Returns the length in the setup pose from the start of the path to the end of each curve. */
|
||||
public FloatArray getLengths () {
|
||||
public float[] getLengths () {
|
||||
return lengths;
|
||||
}
|
||||
|
||||
public void setLengths (float[] lengths) {
|
||||
this.lengths = lengths;
|
||||
}
|
||||
|
||||
public Color getColor () {
|
||||
return color;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user