mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 22:34:53 +08:00
Fixed loader scale for paths.
This commit is contained in:
parent
40950eded7
commit
07bb307b72
@ -66,12 +66,12 @@ public class PathConstraint implements Updatable {
|
||||
if (!translate && !rotate) return;
|
||||
|
||||
PathConstraintData data = this.data;
|
||||
Object[] bones = this.bones.items;
|
||||
SpacingMode spacingMode = data.spacingMode;
|
||||
boolean lengthSpacing = spacingMode == SpacingMode.length;
|
||||
RotateMode rotateMode = data.rotateMode;
|
||||
boolean tangents = rotateMode == RotateMode.tangent, scale = rotateMode == RotateMode.chainScale;
|
||||
boolean lengthSpacing = spacingMode == SpacingMode.length;
|
||||
int boneCount = this.bones.size, spacesCount = tangents ? boneCount : boneCount + 1;
|
||||
Object[] bones = this.bones.items;
|
||||
float[] spaces = this.spaces.setSize(spacesCount), lengths = null;
|
||||
float spacing = this.spacing;
|
||||
if (scale || lengthSpacing) {
|
||||
@ -96,8 +96,8 @@ public class PathConstraint implements Updatable {
|
||||
boolean tip = rotateMode == RotateMode.chain && offsetRotation == 0;
|
||||
for (int i = 0, p = 3; i < boneCount; i++, p += 3) {
|
||||
Bone bone = (Bone)bones[i];
|
||||
bone.worldX += (boneX - bone.worldX) * translateMix - skeletonX;
|
||||
bone.worldY += (boneY - bone.worldY) * translateMix - skeletonY;
|
||||
bone.worldX += (boneX - skeletonX - bone.worldX) * translateMix;
|
||||
bone.worldY += (boneY - skeletonY - bone.worldY) * translateMix;
|
||||
float x = positions[p], y = positions[p + 1], dx = x - boneX, dy = y - boneY;
|
||||
if (scale) {
|
||||
float length = lengths[i];
|
||||
@ -149,14 +149,18 @@ public class PathConstraint implements Updatable {
|
||||
boolean closed = path.getClosed();
|
||||
|
||||
if (!path.getConstantSpeed()) {
|
||||
float pathLength = path.getLength();
|
||||
float[] lengths = path.getLengths().items;
|
||||
float pathLength;
|
||||
if (closed) {
|
||||
curveCount--;
|
||||
pathLength = lengths[curveCount];
|
||||
} else
|
||||
pathLength = lengths[curveCount - 2];
|
||||
if (percentPosition) position *= pathLength;
|
||||
if (percentSpacing) {
|
||||
for (int i = 0; i < spacesCount; i++)
|
||||
spaces[i] *= pathLength;
|
||||
}
|
||||
curveCount--;
|
||||
float[] curveLengths = path.getCurveLengths().items;
|
||||
world = this.world.setSize(8);
|
||||
for (int i = 0, o = 0, curve = 0; i < spacesCount; i++, o += 3) {
|
||||
float space = spaces[i];
|
||||
@ -185,17 +189,16 @@ public class PathConstraint implements Updatable {
|
||||
|
||||
// Determine curve containing position.
|
||||
for (;; curve++) {
|
||||
float length = curveLengths[curve];
|
||||
float length = lengths[curve];
|
||||
if (p > length) continue;
|
||||
if (curve == 0)
|
||||
p /= length;
|
||||
else {
|
||||
float prev = curveLengths[curve - 1];
|
||||
float prev = lengths[curve - 1];
|
||||
p = (p - prev) / (length - prev);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (curve != lastCurve) {
|
||||
lastCurve = curve;
|
||||
if (closed && curve == curveCount) {
|
||||
|
||||
@ -237,8 +237,6 @@ public class Skeleton {
|
||||
|
||||
for (int i = 0, n = bones.size; i < n; i++)
|
||||
sortBone(bones.get(i));
|
||||
|
||||
System.out.println(updateCache);
|
||||
}
|
||||
|
||||
private void sortBone (Bone bone) {
|
||||
|
||||
@ -240,7 +240,9 @@ public class SkeletonBinary {
|
||||
data.rotateMode = RotateMode.values[input.readInt(true)];
|
||||
data.offsetRotation = input.readFloat();
|
||||
data.position = input.readFloat();
|
||||
if (data.positionMode == PositionMode.fixed) data.position *= scale;
|
||||
data.spacing = input.readFloat();
|
||||
if (data.spacingMode == SpacingMode.length || data.spacingMode == SpacingMode.fixed) data.spacing *= scale;
|
||||
data.rotateMix = input.readFloat();
|
||||
data.translateMix = input.readFloat();
|
||||
skeletonData.pathConstraints.add(data);
|
||||
@ -428,21 +430,19 @@ public class SkeletonBinary {
|
||||
boolean constantSpeed = input.readBoolean();
|
||||
int vertexCount = input.readInt(true);
|
||||
Vertices vertices = readVertices(input, vertexCount);
|
||||
float length = input.readFloat();
|
||||
float[] curveLengths = new float[vertexCount / 3];
|
||||
for (int i = 0, n = curveLengths.length; i < n; i++)
|
||||
curveLengths[i] = input.readFloat();
|
||||
float[] lengths = new float[vertexCount / 3];
|
||||
for (int i = 0, n = lengths.length; i < n; i++)
|
||||
lengths[i] = input.readFloat() * scale;
|
||||
int color = nonessential ? input.readInt() : 0;
|
||||
|
||||
PathAttachment path = attachmentLoader.newPathAttachment(skin, name);
|
||||
if (path == null) return null;
|
||||
path.setClosed(closed);
|
||||
path.setConstantSpeed(constantSpeed);
|
||||
path.setLength(length);
|
||||
path.setWorldVerticesLength(vertexCount << 1);
|
||||
path.setVertices(vertices.vertices);
|
||||
path.setBones(vertices.bones);
|
||||
path.getCurveLengths().addAll(curveLengths);
|
||||
path.getLengths().addAll(lengths);
|
||||
if (nonessential) Color.rgba8888ToColor(path.getColor(), color);
|
||||
return path;
|
||||
}
|
||||
@ -609,6 +609,7 @@ public class SkeletonBinary {
|
||||
// Path constraint timelines.
|
||||
for (int i = 0, n = input.readInt(true); i < n; i++) {
|
||||
int index = input.readInt(true);
|
||||
PathConstraintData data = skeletonData.getPathConstraints().get(index);
|
||||
for (int ii = 0, nn = input.readInt(true); ii < nn; ii++) {
|
||||
int timelineType = input.readByte();
|
||||
int frameCount = input.readInt(true);
|
||||
@ -616,13 +617,17 @@ public class SkeletonBinary {
|
||||
case PATH_POSITION:
|
||||
case PATH_SPACING: {
|
||||
PathConstraintPositionTimeline timeline;
|
||||
if (timelineType == PATH_SPACING)
|
||||
float timelineScale = 1;
|
||||
if (timelineType == PATH_SPACING) {
|
||||
timeline = new PathConstraintSpacingTimeline(frameCount);
|
||||
else
|
||||
if (data.spacingMode == SpacingMode.length || data.spacingMode == SpacingMode.fixed) timelineScale = scale;
|
||||
} else {
|
||||
timeline = new PathConstraintPositionTimeline(frameCount);
|
||||
if (data.positionMode == PositionMode.fixed) timelineScale = scale;
|
||||
}
|
||||
timeline.pathConstraintIndex = index;
|
||||
for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) {
|
||||
timeline.setFrame(frameIndex, input.readFloat(), input.readFloat());
|
||||
timeline.setFrame(frameIndex, input.readFloat(), input.readFloat() * timelineScale);
|
||||
if (frameIndex < frameCount - 1) readCurve(input, frameIndex, timeline);
|
||||
}
|
||||
timelines.add(timeline);
|
||||
|
||||
@ -222,7 +222,9 @@ public class SkeletonJson {
|
||||
data.rotateMode = RotateMode.valueOf(constraintMap.getString("rotateMode", "tangent"));
|
||||
data.offsetRotation = constraintMap.getFloat("rotation", 0);
|
||||
data.position = constraintMap.getFloat("position", 0);
|
||||
if (data.positionMode == PositionMode.fixed) data.position *= scale;
|
||||
data.spacing = constraintMap.getFloat("spacing", 0);
|
||||
if (data.spacingMode == SpacingMode.length || data.spacingMode == SpacingMode.fixed) data.spacing *= scale;
|
||||
data.rotateMix = constraintMap.getFloat("rotateMix", 1);
|
||||
data.translateMix = constraintMap.getFloat("translateMix", 1);
|
||||
|
||||
@ -353,15 +355,14 @@ public class SkeletonJson {
|
||||
if (path == null) return null;
|
||||
path.setClosed(map.getBoolean("closed", false));
|
||||
path.setConstantSpeed(map.getBoolean("constantSpeed", true));
|
||||
path.setLength(map.getFloat("length"));
|
||||
|
||||
int vertexCount = map.getInt("vertexCount");
|
||||
readVertices(map, path, vertexCount << 1);
|
||||
|
||||
float[] curveLengths = path.getCurveLengths().setSize(vertexCount / 3);
|
||||
float[] lengths = path.getLengths().setSize(vertexCount / 3);
|
||||
int i = 0;
|
||||
for (JsonValue curves = map.get("curves").child; curves != null; curves = curves.next)
|
||||
curveLengths[i++] = curves.asFloat();
|
||||
for (JsonValue curves = map.require("lengths").child; curves != null; curves = curves.next)
|
||||
lengths[i++] = curves.asFloat() * scale;
|
||||
|
||||
String color = map.getString("color", null);
|
||||
if (color != null) path.getColor().set(Color.valueOf(color));
|
||||
@ -521,18 +522,23 @@ public class SkeletonJson {
|
||||
for (JsonValue constraintMap = map.getChild("paths"); constraintMap != null; constraintMap = constraintMap.next) {
|
||||
int index = skeletonData.findPathConstraintIndex(constraintMap.name);
|
||||
if (index == -1) throw new SerializationException("Path constraint not found: " + constraintMap.name);
|
||||
PathConstraintData data = skeletonData.getPathConstraints().get(index);
|
||||
for (JsonValue timelineMap = constraintMap.child; timelineMap != null; timelineMap = timelineMap.next) {
|
||||
String timelineName = timelineMap.name;
|
||||
if (timelineName.equals("position") || timelineName.equals("spacing")) {
|
||||
PathConstraintPositionTimeline timeline;
|
||||
if (timelineName.equals("spacing"))
|
||||
float timelineScale = 1;
|
||||
if (timelineName.equals("spacing")) {
|
||||
timeline = new PathConstraintSpacingTimeline(timelineMap.size);
|
||||
else
|
||||
if (data.spacingMode == SpacingMode.length || data.spacingMode == SpacingMode.fixed) timelineScale = scale;
|
||||
} else {
|
||||
timeline = new PathConstraintPositionTimeline(timelineMap.size);
|
||||
if (data.positionMode == PositionMode.fixed) timelineScale = scale;
|
||||
}
|
||||
timeline.pathConstraintIndex = index;
|
||||
int frameIndex = 0;
|
||||
for (JsonValue valueMap = timelineMap.child; valueMap != null; valueMap = valueMap.next) {
|
||||
timeline.setFrame(frameIndex, valueMap.getFloat("time"), valueMap.getFloat(timelineName, 0));
|
||||
timeline.setFrame(frameIndex, valueMap.getFloat("time"), valueMap.getFloat(timelineName, 0) * timelineScale);
|
||||
readCurve(valueMap, timeline, frameIndex);
|
||||
frameIndex++;
|
||||
}
|
||||
|
||||
@ -36,7 +36,6 @@ import com.badlogic.gdx.utils.FloatArray;
|
||||
import com.esotericsoftware.spine.Slot;
|
||||
|
||||
public class PathAttachment extends VertexAttachment {
|
||||
float length;
|
||||
final FloatArray lengths = new FloatArray();
|
||||
boolean closed, constantSpeed;
|
||||
|
||||
@ -71,17 +70,8 @@ public class PathAttachment extends VertexAttachment {
|
||||
this.constantSpeed = constantSpeed;
|
||||
}
|
||||
|
||||
/** Returns the length of the path in the setup pose. */
|
||||
public float getLength () {
|
||||
return length;
|
||||
}
|
||||
|
||||
public void setLength (float totalLength) {
|
||||
this.length = totalLength;
|
||||
}
|
||||
|
||||
/** Returns the distance in the setup pose from the start of the path to the end of each curve. */
|
||||
public FloatArray getCurveLengths () {
|
||||
/** Returns the length in the setup pose from the start of the path to the end of each curve. */
|
||||
public FloatArray getLengths () {
|
||||
return lengths;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user