Browse Source

[lua] port of PathConstraint changes, see #1109.

badlogic 7 years ago
parent
commit
8d087341ac
1 changed files with 19 additions and 6 deletions
  1. 19 6
      spine-lua/PathConstraint.lua

+ 19 - 6
spine-lua/PathConstraint.lua

@@ -99,9 +99,8 @@ function PathConstraint:update ()
 	local rotate = rotateMix > 0
 	if not translate and not rotate then return end
 
-	local data = self.data;
-	local spacingMode = data.spacingMode
-	local lengthSpacing = spacingMode == PathConstraintData.SpacingMode.length
+	local data = self.data;	
+	local percentSpacing = data.spacingMode == PathConstraintData.SpacingMode.percent
 	local rotateMode = data.rotateMode
 	local tangents = rotateMode == PathConstraintData.RotateMode.tangent
 	local scale = rotateMode == PathConstraintData.RotateMode.chainscale
@@ -112,8 +111,9 @@ function PathConstraint:update ()
 	local spaces = utils.setArraySize(self.spaces, spacesCount)
 	local lengths = nil
 	local spacing = self.spacing
-	if scale or lengthSpacing then
+	if scale or not percentSpacing then
 		if scale then lengths = utils.setArraySize(self.lengths, boneCount) end
+		local lengthSpacing = data.spacingMode == PathConstraintData.SpacingMode.length
 		local i = 0
 		local n = spacesCount - 1
 		while i < n do
@@ -123,6 +123,15 @@ function PathConstraint:update ()
         if scale then lengths[i + 1] = 0 end
         i = i + 1
         spaces[i + 1] = 0
+			elseif percentSpacing then
+				if scale then
+					local x = setupLength * bone.a
+					local y = setupLength * bone.c
+					local length = math_sqrt(x * x + y * y)
+					lengths[i + 1] = length
+				end
+				i = i + 1
+				spaces[i + 1] = spacing
       else
    			local x = setupLength * bone.a
         local y = setupLength * bone.c
@@ -144,7 +153,7 @@ function PathConstraint:update ()
 		end
 	end
 
-	local positions = self:computeWorldPositions(attachment, spacesCount, tangents, data.positionMode == PathConstraintData.PositionMode.percent, spacingMode == PathConstraintData.SpacingMode.percent)
+	local positions = self:computeWorldPositions(attachment, spacesCount, tangents, data.positionMode == PathConstraintData.PositionMode.percent, percentSpacing)
 	local boneX = positions[1]
 	local boneY = positions[2]
 	local offsetRotation = data.offsetRotation
@@ -380,7 +389,11 @@ function PathConstraint:computeWorldPositions (path, spacesCount, tangents, perc
 		i = i + 1
 		w = w + 6
 	end
-	if percentPosition then position = position * pathLength end
+	if percentPosition then 
+		position = position * pathLength
+	else
+		position = position * pathLength / path.lengths[curveCount];
+	end
 	if percentSpacing then
 		local i = 0
 		while i < spacesCount do