[runtimes] Fixed handling of zero length bones in PathConstraint if spacing is length based. Closes #957

This commit is contained in:
badlogic 2017-07-31 11:29:03 +02:00
parent 687d774082
commit 84fe30a2bf
22 changed files with 49 additions and 20 deletions

View File

@ -87,7 +87,9 @@ package spine {
}
for (var i : int = 0, n : int = spacesCount - 1; i < n;) {
var bone : Bone = bones[i];
var setupLength : Number = bone.data.length, x : Number = setupLength * bone.a, y : Number = setupLength * bone.c;
var setupLength : Number = bone.data.length;
if (setupLength == 0) setupLength = 0.000000001;
var x : Number = setupLength * bone.a, y : Number = setupLength * bone.c;
var length : Number = Math.sqrt(x * x + y * y);
if (scale) lengths[i] = length;
spaces[++i] = (lengthSpacing ? setupLength + spacing : spacing) * length / setupLength;

View File

@ -114,7 +114,9 @@ void spPathConstraint_apply (spPathConstraint* self) {
}
for (i = 0, n = spacesCount - 1; i < n;) {
spBone* bone = bones[i];
setupLength = bone->data->length, x = setupLength * bone->a, y = setupLength * bone->c;
setupLength = bone->data->length;
if (setupLength == 0) setupLength = 0.000000001f;
x = setupLength * bone->a, y = setupLength * bone->c;
length = SQRT(x * x + y * y);
if (scale) lengths[i] = length;
spaces[++i] = (lengthSpacing ? setupLength + spacing : spacing) * length / setupLength;

View File

@ -85,9 +85,9 @@ end
-- table.insert(skeletons, loadSkeleton("spineboy.atlas", "spineboy-ess.json", 240, 300, 0.4, "walk"))
table.insert(skeletons, loadSkeleton("raptor.atlas", "raptor-pro.json", 200, 300, 0.25, "walk"))
-- table.insert(skeletons, loadSkeleton("goblins.atlas", "goblins-pro.json", 240, 300, 0.8, "walk", "goblin"))
-- table.insert(skeletons, loadSkeleton("stretchyman.atlas", "stretchyman-pro.json", 40, 300, 0.5, "sneak"))
table.insert(skeletons, loadSkeleton("stretchyman.atlas", "stretchyman-pro.json", 40, 300, 0.5, "sneak"))
-- table.insert(skeletons, loadSkeleton("tank.atlas", "tank-pro.json", 400, 300, 0.2, "drive"))
-- table.insert(skeletons, loadSkeleton("vine.atlas", "vine-pro.json", 240, 300, 0.3, "grow"))
table.insert(skeletons, loadSkeleton("vine.atlas", "vine-pro.json", 240, 300, 0.3, "grow"))
local triangulator = spine.Triangulator.new()
local polygon = { 411, 219, 199, 230, 161, 362, 534, 407, 346, 305, 596, 265 }

View File

@ -91,7 +91,9 @@ namespace Spine {
if (scale) lengths = this.lengths.Resize(boneCount);
for (int i = 0, n = spacesCount - 1; i < n;) {
Bone bone = bonesItems[i];
float setupLength = bone.data.length, x = setupLength * bone.a, y = setupLength * bone.c;
float setupLength = bone.data.length
if (setupLength == 0) setupLength = 0.000000001;
float x = setupLength * bone.a, y = setupLength * bone.c;
float length = (float)Math.Sqrt(x * x + y * y);
if (scale) lengths.Items[i] = setupLength;
spaces.Items[++i] = (lengthSpacing ? Math.Max(0, setupLength + spacing) : spacing) * length / setupLength;

View File

@ -112,7 +112,9 @@ public class PathConstraint implements Constraint {
if (scale) lengths = this.lengths.setSize(boneCount);
for (int i = 0, n = spacesCount - 1; i < n;) {
Bone bone = (Bone)bones[i];
float setupLength = bone.data.length, x = setupLength * bone.a, y = setupLength * bone.c;
float setupLength = bone.data.length;
if (setupLength == 0) setupLength = 0.000000001f;
float x = setupLength * bone.a, y = setupLength * bone.c;
float length = (float)Math.sqrt(x * x + y * y);
if (scale) lengths[i] = length;
spaces[++i] = (lengthSpacing ? setupLength + spacing : spacing) * length / setupLength;

View File

@ -118,6 +118,7 @@ function PathConstraint:update ()
while i < n do
local bone = bones[i + 1];
local setupLength = bone.data.length
if setupLength == 0 then setupLength = 0.0000001 end
local x = setupLength * bone.a
local y = setupLength * bone.c
local length = math_sqrt(x * x + y * y)

View File

@ -2628,7 +2628,10 @@ var spine;
lengths = spine.Utils.setArraySize(this.lengths, boneCount);
for (var i = 0, n = spacesCount - 1; i < n;) {
var bone = bones[i];
var setupLength = bone.data.length, x = setupLength * bone.a, y = setupLength * bone.c;
var setupLength = bone.data.length;
if (setupLength == 0)
setupLength = 0.0000001;
var x = setupLength * bone.a, y = setupLength * bone.c;
var length_1 = Math.sqrt(x * x + y * y);
if (scale)
lengths[i] = length_1;

File diff suppressed because one or more lines are too long

View File

@ -2628,7 +2628,10 @@ var spine;
lengths = spine.Utils.setArraySize(this.lengths, boneCount);
for (var i = 0, n = spacesCount - 1; i < n;) {
var bone = bones[i];
var setupLength = bone.data.length, x = setupLength * bone.a, y = setupLength * bone.c;
var setupLength = bone.data.length;
if (setupLength == 0)
setupLength = 0.0000001;
var x = setupLength * bone.a, y = setupLength * bone.c;
var length_1 = Math.sqrt(x * x + y * y);
if (scale)
lengths[i] = length_1;

File diff suppressed because one or more lines are too long

View File

@ -2628,7 +2628,10 @@ var spine;
lengths = spine.Utils.setArraySize(this.lengths, boneCount);
for (var i = 0, n = spacesCount - 1; i < n;) {
var bone = bones[i];
var setupLength = bone.data.length, x = setupLength * bone.a, y = setupLength * bone.c;
var setupLength = bone.data.length;
if (setupLength == 0)
setupLength = 0.0000001;
var x = setupLength * bone.a, y = setupLength * bone.c;
var length_1 = Math.sqrt(x * x + y * y);
if (scale)
lengths[i] = length_1;

File diff suppressed because one or more lines are too long

View File

@ -2628,7 +2628,10 @@ var spine;
lengths = spine.Utils.setArraySize(this.lengths, boneCount);
for (var i = 0, n = spacesCount - 1; i < n;) {
var bone = bones[i];
var setupLength = bone.data.length, x = setupLength * bone.a, y = setupLength * bone.c;
var setupLength = bone.data.length;
if (setupLength == 0)
setupLength = 0.0000001;
var x = setupLength * bone.a, y = setupLength * bone.c;
var length_1 = Math.sqrt(x * x + y * y);
if (scale)
lengths[i] = length_1;

File diff suppressed because one or more lines are too long

View File

@ -2628,7 +2628,10 @@ var spine;
lengths = spine.Utils.setArraySize(this.lengths, boneCount);
for (var i = 0, n = spacesCount - 1; i < n;) {
var bone = bones[i];
var setupLength = bone.data.length, x = setupLength * bone.a, y = setupLength * bone.c;
var setupLength = bone.data.length;
if (setupLength == 0)
setupLength = 0.0000001;
var x = setupLength * bone.a, y = setupLength * bone.c;
var length_1 = Math.sqrt(x * x + y * y);
if (scale)
lengths[i] = length_1;

File diff suppressed because one or more lines are too long

View File

@ -2628,7 +2628,10 @@ var spine;
lengths = spine.Utils.setArraySize(this.lengths, boneCount);
for (var i = 0, n = spacesCount - 1; i < n;) {
var bone = bones[i];
var setupLength = bone.data.length, x = setupLength * bone.a, y = setupLength * bone.c;
var setupLength = bone.data.length;
if (setupLength == 0)
setupLength = 0.0000001;
var x = setupLength * bone.a, y = setupLength * bone.c;
var length_1 = Math.sqrt(x * x + y * y);
if (scale)
lengths[i] = length_1;

File diff suppressed because one or more lines are too long

View File

@ -80,7 +80,9 @@ module spine {
if (scale) lengths = Utils.setArraySize(this.lengths, boneCount);
for (let i = 0, n = spacesCount - 1; i < n;) {
let bone = bones[i];
let setupLength = bone.data.length, x = setupLength * bone.a, y = setupLength * bone.c;
let setupLength = bone.data.length;
if (setupLength == 0) setupLength = 0.0000001;
let x = setupLength * bone.a, y = setupLength * bone.c;
let length = Math.sqrt(x * x + y * y);
if (scale) lengths[i] = length;
spaces[++i] = (lengthSpacing ? setupLength + spacing : spacing) * length / setupLength;