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