[libgdx] Fixed path constraint spacing for zero length bones.

This commit is contained in:
Nathan Sweet 2020-11-22 20:37:08 -08:00
parent 3cab1615ad
commit 1b4973628c
2 changed files with 17 additions and 16 deletions

View File

@ -29,6 +29,8 @@
package com.esotericsoftware.spine; package com.esotericsoftware.spine;
import java.util.Arrays;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.FloatArray; import com.badlogic.gdx.utils.FloatArray;
@ -106,20 +108,19 @@ public class PathConstraint implements Updatable {
switch (data.spacingMode) { switch (data.spacingMode) {
case percent: case percent:
for (int i = 0, n = spacesCount - 1; i < n;) { if (scale) {
Bone bone = (Bone)bones[i]; for (int i = 0, n = spacesCount - 1; i < n;) {
float setupLength = bone.data.length; Bone bone = (Bone)bones[i];
if (setupLength < epsilon) { float setupLength = bone.data.length;
if (scale) lengths[i] = 0; if (setupLength < epsilon)
spaces[++i] = 0; lengths[i] = 0;
} else { else {
if (scale) {
float x = setupLength * bone.a, y = setupLength * bone.c; float x = setupLength * bone.a, y = setupLength * bone.c;
lengths[i] = (float)Math.sqrt(x * x + y * y); lengths[i] = (float)Math.sqrt(x * x + y * y);
} }
spaces[++i] = spacing;
} }
} }
Arrays.fill(spaces, 1, spacesCount, spacing);
break; break;
case proportional: case proportional:
float sum = 0; float sum = 0;
@ -128,7 +129,7 @@ public class PathConstraint implements Updatable {
float setupLength = bone.data.length; float setupLength = bone.data.length;
if (setupLength < epsilon) { if (setupLength < epsilon) {
if (scale) lengths[i] = 0; if (scale) lengths[i] = 0;
spaces[++i] = 0; spaces[++i] = spacing;
} else { } else {
float x = setupLength * bone.a, y = setupLength * bone.c; float x = setupLength * bone.a, y = setupLength * bone.c;
float length = (float)Math.sqrt(x * x + y * y); float length = (float)Math.sqrt(x * x + y * y);
@ -137,9 +138,11 @@ public class PathConstraint implements Updatable {
sum += length; sum += length;
} }
} }
sum = spacesCount / sum * spacing; if (sum > 0) {
for (int i = 1; i < spacesCount; i++) sum = spacesCount / sum * spacing;
spaces[i] *= sum; for (int i = 1; i < spacesCount; i++)
spaces[i] *= sum;
}
break; break;
default: default:
boolean lengthSpacing = data.spacingMode == SpacingMode.length; boolean lengthSpacing = data.spacingMode == SpacingMode.length;
@ -148,7 +151,7 @@ public class PathConstraint implements Updatable {
float setupLength = bone.data.length; float setupLength = bone.data.length;
if (setupLength < epsilon) { if (setupLength < epsilon) {
if (scale) lengths[i] = 0; if (scale) lengths[i] = 0;
spaces[++i] = 0; spaces[++i] = spacing;
} else { } else {
float x = setupLength * bone.a, y = setupLength * bone.c; float x = setupLength * bone.a, y = setupLength * bone.c;
float length = (float)Math.sqrt(x * x + y * y); float length = (float)Math.sqrt(x * x + y * y);

View File

@ -140,8 +140,6 @@ public class SkeletonBinary extends SkeletonLoader {
skeletonData.hash = hash == 0 ? null : Long.toString(hash); skeletonData.hash = hash == 0 ? null : Long.toString(hash);
skeletonData.version = input.readString(); skeletonData.version = input.readString();
if (skeletonData.version.isEmpty()) skeletonData.version = null; if (skeletonData.version.isEmpty()) skeletonData.version = null;
if ("3.8.75".equals(skeletonData.version))
throw new RuntimeException("Unsupported skeleton data, please export with a newer version of Spine.");
skeletonData.x = input.readFloat(); skeletonData.x = input.readFloat();
skeletonData.y = input.readFloat(); skeletonData.y = input.readFloat();
skeletonData.width = input.readFloat(); skeletonData.width = input.readFloat();