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