[lua] Fix PathConstraint length spacing for zero length bones. See #1023.

This commit is contained in:
badlogic 2017-10-20 11:16:44 +02:00
parent cbb37a6096
commit 52a300eeae

View File

@ -55,6 +55,7 @@ PathConstraint.__index = PathConstraint
PathConstraint.NONE = -1 PathConstraint.NONE = -1
PathConstraint.BEFORE = -2 PathConstraint.BEFORE = -2
PathConstraint.AFTER = -3 PathConstraint.AFTER = -3
PathConstraint.epsilon = 0.00001
function PathConstraint.new (data, skeleton) function PathConstraint.new (data, skeleton)
if not data then error("data cannot be nil", 2) end if not data then error("data cannot be nil", 2) end
@ -118,13 +119,22 @@ function PathConstraint:update ()
while i < n do while i < n do
local bone = bones[i + 1]; local bone = bones[i + 1];
local setupLength = bone.data.length local setupLength = bone.data.length
if setupLength == 0 then setupLength = 0.0000001 end if setupLength < PathConstraint.epsilon then
local x = setupLength * bone.a if scale then lengths[i + 1] = 0 end
local y = setupLength * bone.c i = i + 1
local length = math_sqrt(x * x + y * y) spaces[i + 1] = 0
if scale then lengths[i + 1] = length end else
i = i + 1 local x = setupLength * bone.a
if lengthSpacing then spaces[i + 1] = (setupLength + spacing) * length / setupLength else spaces[i + 1] = spacing * length / setupLength end local y = setupLength * bone.c
local length = math_sqrt(x * x + y * y)
if scale then lengths[i + 1] = length end
i = i + 1
if lengthSpacing then
spaces[i + 1] = (setupLength + spacing) * length / setupLength
else
spaces[i + 1] = spacing * length / setupLength
end
end
end end
else else
local i = 1 local i = 1