mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[lua] Manually merged PR #1103.
This commit is contained in:
parent
0f7b813c38
commit
71a50183c7
@ -34,7 +34,7 @@ function loadSkeleton(atlasFile, jsonFile, x, y, scale, animation, skin)
|
|||||||
|
|
||||||
-- create an animation state object to apply animations to the skeleton
|
-- create an animation state object to apply animations to the skeleton
|
||||||
local animationStateData = spine.AnimationStateData.new(skeletonData)
|
local animationStateData = spine.AnimationStateData.new(skeletonData)
|
||||||
animationStateData.defaultMix = 0.2
|
animationStateData.defaultMix = 0.5
|
||||||
local animationState = spine.AnimationState.new(animationStateData)
|
local animationState = spine.AnimationState.new(animationStateData)
|
||||||
|
|
||||||
-- set the skeleton invisible
|
-- set the skeleton invisible
|
||||||
|
|||||||
@ -28,7 +28,7 @@
|
|||||||
-- POSSIBILITY OF SUCH DAMAGE.
|
-- POSSIBILITY OF SUCH DAMAGE.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
spine = {}
|
local spine = {}
|
||||||
|
|
||||||
spine.utils = require "spine-lua.utils"
|
spine.utils = require "spine-lua.utils"
|
||||||
spine.SkeletonJson = require "spine-lua.SkeletonJson"
|
spine.SkeletonJson = require "spine-lua.SkeletonJson"
|
||||||
@ -88,7 +88,7 @@ local QUAD_TRIANGLES = { 1, 2, 3, 3, 4, 1 }
|
|||||||
spine.Skeleton.new_super = spine.Skeleton.new
|
spine.Skeleton.new_super = spine.Skeleton.new
|
||||||
spine.Skeleton.updateWorldTransform_super = spine.Skeleton.updateWorldTransform
|
spine.Skeleton.updateWorldTransform_super = spine.Skeleton.updateWorldTransform
|
||||||
spine.Skeleton.new = function(skeletonData, group)
|
spine.Skeleton.new = function(skeletonData, group)
|
||||||
self = spine.Skeleton.new_super(skeletonData)
|
local self = spine.Skeleton.new_super(skeletonData)
|
||||||
self.group = group or display.newGroup()
|
self.group = group or display.newGroup()
|
||||||
self.drawingGroup = nil
|
self.drawingGroup = nil
|
||||||
self.premultipliedAlpha = false
|
self.premultipliedAlpha = false
|
||||||
@ -156,7 +156,7 @@ function spine.Skeleton:updateWorldTransform()
|
|||||||
uvs = nil
|
uvs = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for i,slot in ipairs(drawOrder) do
|
for _,slot in ipairs(drawOrder) do
|
||||||
local attachment = slot.attachment
|
local attachment = slot.attachment
|
||||||
local vertices = nil
|
local vertices = nil
|
||||||
local uvs = nil
|
local uvs = nil
|
||||||
|
|||||||
@ -198,6 +198,7 @@ function TrackEntry:setTimelineData(to, mixingToArray, propertyIDs)
|
|||||||
local timelineDipMix = self.timelineDipMix
|
local timelineDipMix = self.timelineDipMix
|
||||||
|
|
||||||
local i = 1
|
local i = 1
|
||||||
|
local skip
|
||||||
while i <= timelinesCount do
|
while i <= timelinesCount do
|
||||||
local id = "" .. timelines[i]:getPropertyId()
|
local id = "" .. timelines[i]:getPropertyId()
|
||||||
if not (propertyIDs[id] == nil) then
|
if not (propertyIDs[id] == nil) then
|
||||||
@ -208,7 +209,7 @@ function TrackEntry:setTimelineData(to, mixingToArray, propertyIDs)
|
|||||||
local ii = mixingToLast
|
local ii = mixingToLast
|
||||||
while ii > 0 do
|
while ii > 0 do
|
||||||
local entry = mixingTo[ii]
|
local entry = mixingTo[ii]
|
||||||
local skip = false
|
skip = false
|
||||||
if not entry:hasTimeline(id) then
|
if not entry:hasTimeline(id) then
|
||||||
if entry.mixDuration > 0 then
|
if entry.mixDuration > 0 then
|
||||||
timelineData[i] = DIP_MIX
|
timelineData[i] = DIP_MIX
|
||||||
@ -345,9 +346,6 @@ function AnimationState:updateMixingFrom (to, delta)
|
|||||||
|
|
||||||
local finished = self:updateMixingFrom(from, delta)
|
local finished = self:updateMixingFrom(from, delta)
|
||||||
|
|
||||||
from.animationLast = from.nextAnimationLast
|
|
||||||
from.trackLast = from.nextTrackLast
|
|
||||||
|
|
||||||
-- Require mixTime > 0 to ensure the mixing from entry was applied at least once.
|
-- Require mixTime > 0 to ensure the mixing from entry was applied at least once.
|
||||||
if (to.mixTime > 0 and (to.mixTime >= to.mixDuration or to.timeScale == 0)) then
|
if (to.mixTime > 0 and (to.mixTime >= to.mixDuration or to.timeScale == 0)) then
|
||||||
-- Require totalAlpha == 0 to ensure mixing is complete, unless mixDuration == 0 (the transition is a single frame).
|
-- Require totalAlpha == 0 to ensure mixing is complete, unless mixDuration == 0 (the transition is a single frame).
|
||||||
@ -359,6 +357,8 @@ function AnimationState:updateMixingFrom (to, delta)
|
|||||||
return finished
|
return finished
|
||||||
end
|
end
|
||||||
|
|
||||||
|
from.animationLast = from.nextAnimationLast
|
||||||
|
from.trackLast = from.nextTrackLast
|
||||||
from.trackTime = from.trackTime + delta * from.timeScale
|
from.trackTime = from.trackTime + delta * from.timeScale
|
||||||
to.mixTime = to.mixTime + delta * to.timeScale
|
to.mixTime = to.mixTime + delta * to.timeScale
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -33,13 +33,13 @@ local Atlas = {}
|
|||||||
function Atlas.parse(atlasPath, atlasBase)
|
function Atlas.parse(atlasPath, atlasBase)
|
||||||
local function parseIntTuple4( l )
|
local function parseIntTuple4( l )
|
||||||
local a,b,c,d = string.match( l , " ? ?%a+: ([+-]?%d+), ?([+-]?%d+), ?([+-]?%d+), ?([+-]?%d+)" )
|
local a,b,c,d = string.match( l , " ? ?%a+: ([+-]?%d+), ?([+-]?%d+), ?([+-]?%d+), ?([+-]?%d+)" )
|
||||||
local a,b,c,d = tonumber( a ), tonumber( b ), tonumber( c ), tonumber( d )
|
a,b,c,d = tonumber( a ), tonumber( b ), tonumber( c ), tonumber( d )
|
||||||
return a and b and c and d and {a, b, c ,d}
|
return a and b and c and d and {a, b, c ,d}
|
||||||
end
|
end
|
||||||
|
|
||||||
local function parseIntTuple2( l )
|
local function parseIntTuple2( l )
|
||||||
local a,b = string.match( l , " ? ?%a+: ([+-]?%d+), ?([+-]?%d+)" )
|
local a,b = string.match( l , " ? ?%a+: ([+-]?%d+), ?([+-]?%d+)" )
|
||||||
local a,b = tonumber( a ), tonumber( b )
|
a,b = tonumber( a ), tonumber( b )
|
||||||
return a and b and {a, b}
|
return a and b and {a, b}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -69,10 +69,6 @@ function AtlasAttachmentLoader:newMeshAttachment (skin, name, path)
|
|||||||
return attachment
|
return attachment
|
||||||
end
|
end
|
||||||
|
|
||||||
function AtlasAttachmentLoader:newSkinningMeshAttachment (skin, name, path)
|
|
||||||
return SkinningMeshAttachment.new(name)
|
|
||||||
end
|
|
||||||
|
|
||||||
function AtlasAttachmentLoader:newBoundingBoxAttachment (skin, name)
|
function AtlasAttachmentLoader:newBoundingBoxAttachment (skin, name)
|
||||||
return BoundingBoxAttachment.new(name)
|
return BoundingBoxAttachment.new(name)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -48,10 +48,6 @@ function AttachmentLoader.new ()
|
|||||||
return MeshAttachment.new(name)
|
return MeshAttachment.new(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
function self:newSkinningMeshAttachment (skin, name, path)
|
|
||||||
return SkinningMeshAttachment.new(name)
|
|
||||||
end
|
|
||||||
|
|
||||||
function self:newBoundingBoxAttachment (skin, name)
|
function self:newBoundingBoxAttachment (skin, name)
|
||||||
return BoundingBoxAttachment.new(name)
|
return BoundingBoxAttachment.new(name)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -240,7 +240,7 @@ function Bone:getWorldScaleY ()
|
|||||||
return math_sqrt(self.b * self.b + self.d * self.d)
|
return math_sqrt(self.b * self.b + self.d * self.d)
|
||||||
end
|
end
|
||||||
|
|
||||||
function updateAppliedTransform ()
|
function Bone:updateAppliedTransform ()
|
||||||
local parent = self.parent
|
local parent = self.parent
|
||||||
if parent == nil then
|
if parent == nil then
|
||||||
self.ax = self.worldX
|
self.ax = self.worldX
|
||||||
|
|||||||
@ -57,7 +57,7 @@ function IkConstraint.new (data, skeleton)
|
|||||||
setmetatable(self, IkConstraint)
|
setmetatable(self, IkConstraint)
|
||||||
|
|
||||||
local self_bones = self.bones
|
local self_bones = self.bones
|
||||||
for i,boneData in ipairs(data.bones) do
|
for _,boneData in ipairs(data.bones) do
|
||||||
table_insert(self_bones, skeleton:findBone(boneData.name))
|
table_insert(self_bones, skeleton:findBone(boneData.name))
|
||||||
end
|
end
|
||||||
self.target = skeleton:findBone(data.target.name)
|
self.target = skeleton:findBone(data.target.name)
|
||||||
|
|||||||
@ -78,7 +78,7 @@ function PathConstraint.new (data, skeleton)
|
|||||||
}
|
}
|
||||||
setmetatable(self, PathConstraint)
|
setmetatable(self, PathConstraint)
|
||||||
|
|
||||||
for i,boneData in ipairs(data.bones) do
|
for _,boneData in ipairs(data.bones) do
|
||||||
table_insert(self.bones, skeleton:findBone(boneData.name))
|
table_insert(self.bones, skeleton:findBone(boneData.name))
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -244,6 +244,7 @@ function PathConstraint:computeWorldPositions (path, spacesCount, tangents, perc
|
|||||||
local verticesLength = path.worldVerticesLength
|
local verticesLength = path.worldVerticesLength
|
||||||
local curveCount = verticesLength / 6
|
local curveCount = verticesLength / 6
|
||||||
local prevCurve = PathConstraint.NONE
|
local prevCurve = PathConstraint.NONE
|
||||||
|
local i = 0
|
||||||
|
|
||||||
if not path.constantSpeed then
|
if not path.constantSpeed then
|
||||||
local lengths = path.lengths
|
local lengths = path.lengths
|
||||||
@ -251,14 +252,14 @@ function PathConstraint:computeWorldPositions (path, spacesCount, tangents, perc
|
|||||||
local pathLength = lengths[curveCount + 1];
|
local pathLength = lengths[curveCount + 1];
|
||||||
if percentPosition then position = position * pathLength end
|
if percentPosition then position = position * pathLength end
|
||||||
if percentSpacing then
|
if percentSpacing then
|
||||||
local i = 0
|
i = 0
|
||||||
while i < spacesCount do
|
while i < spacesCount do
|
||||||
spaces[i + 1] = spaces[i + 1] * pathLength
|
spaces[i + 1] = spaces[i + 1] * pathLength
|
||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
world = utils.setArraySize(self.world, 8);
|
world = utils.setArraySize(self.world, 8);
|
||||||
local i = 0
|
i = 0
|
||||||
local o = 0
|
local o = 0
|
||||||
local curve = 0
|
local curve = 0
|
||||||
while i < spacesCount do
|
while i < spacesCount do
|
||||||
@ -354,7 +355,6 @@ function PathConstraint:computeWorldPositions (path, spacesCount, tangents, perc
|
|||||||
local ddfy = 0
|
local ddfy = 0
|
||||||
local dfx = 0
|
local dfx = 0
|
||||||
local dfy = 0
|
local dfy = 0
|
||||||
i = 0
|
|
||||||
local w = 2
|
local w = 2
|
||||||
while i < curveCount do
|
while i < curveCount do
|
||||||
cx1 = world[w + 1]
|
cx1 = world[w + 1]
|
||||||
@ -395,7 +395,7 @@ function PathConstraint:computeWorldPositions (path, spacesCount, tangents, perc
|
|||||||
position = position * pathLength / path.lengths[curveCount];
|
position = position * pathLength / path.lengths[curveCount];
|
||||||
end
|
end
|
||||||
if percentSpacing then
|
if percentSpacing then
|
||||||
local i = 0
|
i = 0
|
||||||
while i < spacesCount do
|
while i < spacesCount do
|
||||||
spaces[i + 1] = spaces[i + 1] * pathLength
|
spaces[i + 1] = spaces[i + 1] * pathLength
|
||||||
i = i + 1
|
i = i + 1
|
||||||
@ -404,7 +404,7 @@ function PathConstraint:computeWorldPositions (path, spacesCount, tangents, perc
|
|||||||
|
|
||||||
local segments = self.segments
|
local segments = self.segments
|
||||||
local curveLength = 0
|
local curveLength = 0
|
||||||
local i = 0
|
i = 0
|
||||||
local o = 0
|
local o = 0
|
||||||
local curve = 0
|
local curve = 0
|
||||||
local segment = 0
|
local segment = 0
|
||||||
|
|||||||
@ -85,6 +85,7 @@ function RegionAttachment.new (name)
|
|||||||
y = y + bone.worldY
|
y = y + bone.worldY
|
||||||
local m00, m01, m10, m11 = bone.m00, bone.m01, bone.m10, bone.m11
|
local m00, m01, m10, m11 = bone.m00, bone.m01, bone.m10, bone.m11
|
||||||
local offset = self.offset
|
local offset = self.offset
|
||||||
|
local vertices = self.vertices;
|
||||||
vertices[0] = offset[0] * m00 + offset[1] * m01 + x
|
vertices[0] = offset[0] * m00 + offset[1] * m01 + x
|
||||||
vertices[1] = offset[0] * m10 + offset[1] * m11 + y
|
vertices[1] = offset[0] * m10 + offset[1] * m11 + y
|
||||||
vertices[2] = offset[2] * m00 + offset[3] * m01 + x
|
vertices[2] = offset[2] * m00 + offset[3] * m01 + x
|
||||||
|
|||||||
@ -68,7 +68,7 @@ function Skeleton.new (data)
|
|||||||
}
|
}
|
||||||
setmetatable(self, Skeleton)
|
setmetatable(self, Skeleton)
|
||||||
|
|
||||||
for i,boneData in ipairs(data.bones) do
|
for _,boneData in ipairs(data.bones) do
|
||||||
local bone = nil
|
local bone = nil
|
||||||
if boneData.parent == nil then
|
if boneData.parent == nil then
|
||||||
bone = Bone.new(boneData, self, nil)
|
bone = Bone.new(boneData, self, nil)
|
||||||
@ -80,7 +80,7 @@ function Skeleton.new (data)
|
|||||||
table_insert(self.bones, bone)
|
table_insert(self.bones, bone)
|
||||||
end
|
end
|
||||||
|
|
||||||
for i,slotData in ipairs(data.slots) do
|
for _,slotData in ipairs(data.slots) do
|
||||||
local bone = self.bones[slotData.boneData.index]
|
local bone = self.bones[slotData.boneData.index]
|
||||||
local slot = Slot.new(slotData, bone)
|
local slot = Slot.new(slotData, bone)
|
||||||
table_insert(self.slots, slot)
|
table_insert(self.slots, slot)
|
||||||
@ -88,15 +88,15 @@ function Skeleton.new (data)
|
|||||||
table_insert(self.drawOrder, slot)
|
table_insert(self.drawOrder, slot)
|
||||||
end
|
end
|
||||||
|
|
||||||
for i,ikConstraintData in ipairs(data.ikConstraints) do
|
for _, ikConstraintData in ipairs(data.ikConstraints) do
|
||||||
table_insert(self.ikConstraints, IkConstraint.new(ikConstraintData, self))
|
table_insert(self.ikConstraints, IkConstraint.new(ikConstraintData, self))
|
||||||
end
|
end
|
||||||
|
|
||||||
for i, transformConstraintData in ipairs(data.transformConstraints) do
|
for _, transformConstraintData in ipairs(data.transformConstraints) do
|
||||||
table_insert(self.transformConstraints, TransformConstraint.new(transformConstraintData, self))
|
table_insert(self.transformConstraints, TransformConstraint.new(transformConstraintData, self))
|
||||||
end
|
end
|
||||||
|
|
||||||
for i, pathConstraintData in ipairs(data.pathConstraints) do
|
for _, pathConstraintData in ipairs(data.pathConstraints) do
|
||||||
table_insert(self.pathConstraints, PathConstraint.new(pathConstraintData, self))
|
table_insert(self.pathConstraints, PathConstraint.new(pathConstraintData, self))
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ function Skeleton:updateCache ()
|
|||||||
self.updateCacheReset = {}
|
self.updateCacheReset = {}
|
||||||
|
|
||||||
local bones = self.bones
|
local bones = self.bones
|
||||||
for i, bone in ipairs(bones) do
|
for _, bone in ipairs(bones) do
|
||||||
bone.sorted = false
|
bone.sorted = false
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ function Skeleton:updateCache ()
|
|||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
for i, bone in ipairs(self.bones) do
|
for _, bone in ipairs(self.bones) do
|
||||||
self:sortBone(bone)
|
self:sortBone(bone)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -183,7 +183,7 @@ function Skeleton:sortIkConstraint (constraint)
|
|||||||
if #constrained > 1 then
|
if #constrained > 1 then
|
||||||
local child = constrained[#constrained]
|
local child = constrained[#constrained]
|
||||||
local contains = false
|
local contains = false
|
||||||
for i,updatable in ipairs(self._updateCache) do
|
for _, updatable in ipairs(self._updateCache) do
|
||||||
if updatable == child then
|
if updatable == child then
|
||||||
contains = true
|
contains = true
|
||||||
break
|
break
|
||||||
@ -202,11 +202,11 @@ function Skeleton:sortPathConstraint(constraint)
|
|||||||
local slot = constraint.target
|
local slot = constraint.target
|
||||||
local slotIndex = slot.data.index
|
local slotIndex = slot.data.index
|
||||||
local slotBone = slot.bone
|
local slotBone = slot.bone
|
||||||
if self.skin then self:sortPathConstraintAttachment(skin, slotIndex, slotBone) end
|
if self.skin then self:sortPathConstraintAttachment(self.skin, slotIndex, slotBone) end
|
||||||
if self.data.defaultSkin and not (self.data.defaultSkin == skin) then
|
if self.data.defaultSkin and not (self.data.defaultSkin == self.skin) then
|
||||||
self:sortPathConstraintAttachment(self.data.defaultSkin, slotIndex, slotBone)
|
self:sortPathConstraintAttachment(self.data.defaultSkin, slotIndex, slotBone)
|
||||||
end
|
end
|
||||||
for i,skin in ipairs(self.data.skins) do
|
for _,skin in ipairs(self.data.skins) do
|
||||||
self:sortPathConstraintAttachment(skin, slotIndex, slotBone)
|
self:sortPathConstraintAttachment(skin, slotIndex, slotBone)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -214,17 +214,17 @@ function Skeleton:sortPathConstraint(constraint)
|
|||||||
if attachment and attachment.type == AttachmentType.path then self:sortPathConstraintAttachmentWith(attachment, slotBone) end
|
if attachment and attachment.type == AttachmentType.path then self:sortPathConstraintAttachmentWith(attachment, slotBone) end
|
||||||
|
|
||||||
local constrained = constraint.bones
|
local constrained = constraint.bones
|
||||||
for i,bone in ipairs(constrained) do
|
for _,bone in ipairs(constrained) do
|
||||||
self:sortBone(bone)
|
self:sortBone(bone)
|
||||||
end
|
end
|
||||||
|
|
||||||
table_insert(self._updateCache, constraint)
|
table_insert(self._updateCache, constraint)
|
||||||
|
|
||||||
for i,bone in ipairs(constrained) do
|
for _,bone in ipairs(constrained) do
|
||||||
self:sortReset(bone.children)
|
self:sortReset(bone.children)
|
||||||
end
|
end
|
||||||
|
|
||||||
for i,bone in ipairs(constrained) do
|
for _,bone in ipairs(constrained) do
|
||||||
bone.sorted = true
|
bone.sorted = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -234,11 +234,11 @@ function Skeleton:sortTransformConstraint(constraint)
|
|||||||
|
|
||||||
local constrained = constraint.bones
|
local constrained = constraint.bones
|
||||||
if constraint.data.local_ then
|
if constraint.data.local_ then
|
||||||
for i,bone in ipairs(constrained) do
|
for _,bone in ipairs(constrained) do
|
||||||
local child = constrained[#constrained]
|
local child = constrained[#constrained]
|
||||||
local contains = false
|
local contains = false
|
||||||
sortBone(child.parent)
|
self:sortBone(child.parent)
|
||||||
for i,updatable in ipairs(self._updateCache) do
|
for _,updatable in ipairs(self._updateCache) do
|
||||||
if updatable == child then
|
if updatable == child then
|
||||||
contains = true
|
contains = true
|
||||||
break
|
break
|
||||||
@ -247,18 +247,18 @@ function Skeleton:sortTransformConstraint(constraint)
|
|||||||
if not contains then table_insert(self.updateCacheReset, child) end
|
if not contains then table_insert(self.updateCacheReset, child) end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
for i,bone in ipairs(constrained) do
|
for _,bone in ipairs(constrained) do
|
||||||
self:sortBone(bone)
|
self:sortBone(bone)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
table_insert(self._updateCache, constraint)
|
table_insert(self._updateCache, constraint)
|
||||||
|
|
||||||
for i,bone in ipairs(constrained) do
|
for _,bone in ipairs(constrained) do
|
||||||
self:sortReset(bone.children)
|
self:sortReset(bone.children)
|
||||||
end
|
end
|
||||||
|
|
||||||
for i,bone in ipairs(constrained) do
|
for _,bone in ipairs(constrained) do
|
||||||
bone.sorted = true
|
bone.sorted = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -266,7 +266,7 @@ end
|
|||||||
function Skeleton:sortPathConstraintAttachment(skin, slotIndex, slotBone)
|
function Skeleton:sortPathConstraintAttachment(skin, slotIndex, slotBone)
|
||||||
local attachments = skin.attachments[slotIndex]
|
local attachments = skin.attachments[slotIndex]
|
||||||
if not attachments then return end
|
if not attachments then return end
|
||||||
for key,attachment in pairs(attachments) do
|
for _,attachment in pairs(attachments) do
|
||||||
self:sortPathConstraintAttachmentWith(attachment, slotBone)
|
self:sortPathConstraintAttachmentWith(attachment, slotBone)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -301,7 +301,7 @@ function Skeleton:sortBone(bone)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Skeleton:sortReset(bones)
|
function Skeleton:sortReset(bones)
|
||||||
for i, bone in ipairs(bones) do
|
for _, bone in ipairs(bones) do
|
||||||
if bone.sorted then self:sortReset(bone.children) end
|
if bone.sorted then self:sortReset(bone.children) end
|
||||||
bone.sorted = false
|
bone.sorted = false
|
||||||
end
|
end
|
||||||
@ -310,7 +310,7 @@ end
|
|||||||
-- Updates the world transform for each bone and applies IK constraints.
|
-- Updates the world transform for each bone and applies IK constraints.
|
||||||
function Skeleton:updateWorldTransform ()
|
function Skeleton:updateWorldTransform ()
|
||||||
local updateCacheReset = self.updateCacheReset
|
local updateCacheReset = self.updateCacheReset
|
||||||
for i,bone in ipairs(updateCacheReset) do
|
for _,bone in ipairs(updateCacheReset) do
|
||||||
bone.ax = bone.x
|
bone.ax = bone.x
|
||||||
bone.ay = bone.y
|
bone.ay = bone.y
|
||||||
bone.arotation = bone.rotation
|
bone.arotation = bone.rotation
|
||||||
@ -322,7 +322,7 @@ function Skeleton:updateWorldTransform ()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local updateCache = self._updateCache
|
local updateCache = self._updateCache
|
||||||
for i, updatable in ipairs(updateCache) do
|
for _, updatable in ipairs(updateCache) do
|
||||||
updatable:update()
|
updatable:update()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -333,17 +333,17 @@ function Skeleton:setToSetupPose ()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Skeleton:setBonesToSetupPose ()
|
function Skeleton:setBonesToSetupPose ()
|
||||||
for i,bone in ipairs(self.bones) do
|
for _,bone in ipairs(self.bones) do
|
||||||
bone:setToSetupPose()
|
bone:setToSetupPose()
|
||||||
end
|
end
|
||||||
|
|
||||||
for i,ikConstraint in ipairs(self.ikConstraints) do
|
for _,ikConstraint in ipairs(self.ikConstraints) do
|
||||||
ikConstraint.bendDirection = ikConstraint.data.bendDirection
|
ikConstraint.bendDirection = ikConstraint.data.bendDirection
|
||||||
ikConstraint.mix = ikConstraint.data.mix
|
ikConstraint.mix = ikConstraint.data.mix
|
||||||
end
|
end
|
||||||
|
|
||||||
local transformConstraints = self.transformConstraints
|
local transformConstraints = self.transformConstraints
|
||||||
for i, constraint in ipairs(transformConstraints) do
|
for _, constraint in ipairs(transformConstraints) do
|
||||||
local data = constraint.data
|
local data = constraint.data
|
||||||
constraint.rotateMix = data.rotateMix
|
constraint.rotateMix = data.rotateMix
|
||||||
constraint.translateMix = data.translateMix
|
constraint.translateMix = data.translateMix
|
||||||
@ -352,7 +352,7 @@ function Skeleton:setBonesToSetupPose ()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local pathConstraints = self.pathConstraints
|
local pathConstraints = self.pathConstraints
|
||||||
for i, constraint in ipairs(pathConstraints) do
|
for _, constraint in ipairs(pathConstraints) do
|
||||||
local data = constraint.data
|
local data = constraint.data
|
||||||
constraint.position = data.position
|
constraint.position = data.position
|
||||||
constraint.spacing = data.spacing
|
constraint.spacing = data.spacing
|
||||||
@ -374,7 +374,7 @@ end
|
|||||||
|
|
||||||
function Skeleton:findBone (boneName)
|
function Skeleton:findBone (boneName)
|
||||||
if not boneName then error("boneName cannot be nil.", 2) end
|
if not boneName then error("boneName cannot be nil.", 2) end
|
||||||
for i,bone in ipairs(self.bones) do
|
for _,bone in ipairs(self.bones) do
|
||||||
if bone.data.name == boneName then return bone end
|
if bone.data.name == boneName then return bone end
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
@ -463,8 +463,8 @@ end
|
|||||||
|
|
||||||
function Skeleton:findIkConstraint(constraintName)
|
function Skeleton:findIkConstraint(constraintName)
|
||||||
if not constraintName then error("constraintName cannot be null.", 2) end
|
if not constraintName then error("constraintName cannot be null.", 2) end
|
||||||
local ikConstaints = self.ikConstraints
|
local ikConstraints = self.ikConstraints
|
||||||
for i, ikConstraint in ipairs(ikConstraints) do
|
for _, ikConstraint in ipairs(ikConstraints) do
|
||||||
if ikConstraint.data.name == constraintName then return ikConstraint end
|
if ikConstraint.data.name == constraintName then return ikConstraint end
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
@ -473,7 +473,7 @@ end
|
|||||||
function Skeleton:findTransformConstraint(constraintName)
|
function Skeleton:findTransformConstraint(constraintName)
|
||||||
if not constraintName then error("constraintName cannot be null.", 2) end
|
if not constraintName then error("constraintName cannot be null.", 2) end
|
||||||
local transformConstraints = self.transformConstraints
|
local transformConstraints = self.transformConstraints
|
||||||
for i, transformConstraint in ipairs(transformConstraints) do
|
for _, transformConstraint in ipairs(transformConstraints) do
|
||||||
if transformConstraint.data.name == constraintName then return transformConstraint end
|
if transformConstraint.data.name == constraintName then return transformConstraint end
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
@ -482,7 +482,7 @@ end
|
|||||||
function Skeleton:findPathConstraint(constraintName)
|
function Skeleton:findPathConstraint(constraintName)
|
||||||
if not constraintName then error("constraintName cannot be null.", 2) end
|
if not constraintName then error("constraintName cannot be null.", 2) end
|
||||||
local pathConstraints = self.pathConstraints
|
local pathConstraints = self.pathConstraints
|
||||||
for i, pathConstraint in ipairs(pathConstraints) do
|
for _, pathConstraint in ipairs(pathConstraints) do
|
||||||
if pathConstraint.data.name == constraintName then return pathConstraint end
|
if pathConstraint.data.name == constraintName then return pathConstraint end
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
@ -496,7 +496,7 @@ function Skeleton:getBounds(offset, size)
|
|||||||
local minY = 99999999
|
local minY = 99999999
|
||||||
local maxX = -99999999
|
local maxX = -99999999
|
||||||
local maxY = -99999999
|
local maxY = -99999999
|
||||||
for i, slot in ipairs(drawOrder) do
|
for _, slot in ipairs(drawOrder) do
|
||||||
local vertices = {}
|
local vertices = {}
|
||||||
local attachment = slot.attachment
|
local attachment = slot.attachment
|
||||||
if attachment then
|
if attachment then
|
||||||
|
|||||||
@ -59,7 +59,7 @@ function SkeletonBounds:update (skeleton, updateAabb)
|
|||||||
self.polygons = polygons
|
self.polygons = polygons
|
||||||
local slots = skeleton.slots
|
local slots = skeleton.slots
|
||||||
|
|
||||||
for i,slot in ipairs(skeleton.slots) do
|
for _,slot in ipairs(skeleton.slots) do
|
||||||
local attachment = slot.attachment
|
local attachment = slot.attachment
|
||||||
if attachment and attachment.type == AttachmentType.boundingbox then
|
if attachment and attachment.type == AttachmentType.boundingbox then
|
||||||
local boundingBox = attachment
|
local boundingBox = attachment
|
||||||
@ -85,7 +85,7 @@ end
|
|||||||
function SkeletonBounds:aabbCompute ()
|
function SkeletonBounds:aabbCompute ()
|
||||||
local minX, minY, maxX, maxY = 9999999, 9999999, -9999999, -9999999
|
local minX, minY, maxX, maxY = 9999999, 9999999, -9999999, -9999999
|
||||||
local polygons = self.polygons
|
local polygons = self.polygons
|
||||||
for i,vertices in ipairs(polygons) do
|
for _,vertices in ipairs(polygons) do
|
||||||
local count = #vertices
|
local count = #vertices
|
||||||
for ii = 1, count, 2 do
|
for ii = 1, count, 2 do
|
||||||
local x = vertices[ii]
|
local x = vertices[ii]
|
||||||
@ -179,7 +179,7 @@ function SkeletonBounds:polygonIntersectsSegment (polygon, x1, y1, x2, y2)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function SkeletonBounds:getPolygon (attachment)
|
function SkeletonBounds:getPolygon (attachment)
|
||||||
local index = spine.utils.indexOf(self.boundingBoxes, attachment)
|
local index = utils.indexOf(self.boundingBoxes, attachment)
|
||||||
if index == -1 then
|
if index == -1 then
|
||||||
return nil
|
return nil
|
||||||
else
|
else
|
||||||
|
|||||||
@ -66,7 +66,7 @@ function SkeletonClipping:clipStart(slot, clip)
|
|||||||
clip:computeWorldVertices(slot, 0, n, vertices, 0, 2)
|
clip:computeWorldVertices(slot, 0, n, vertices, 0, 2)
|
||||||
self:makeClockwise(self.clippingPolygon)
|
self:makeClockwise(self.clippingPolygon)
|
||||||
self.clippingPolygons = self.triangulator:decompose(self.clippingPolygon, self.triangulator:triangulate(self.clippingPolygon))
|
self.clippingPolygons = self.triangulator:decompose(self.clippingPolygon, self.triangulator:triangulate(self.clippingPolygon))
|
||||||
for i,polygon in ipairs(self.clippingPolygons) do
|
for _,polygon in ipairs(self.clippingPolygons) do
|
||||||
self:makeClockwise(polygon)
|
self:makeClockwise(polygon)
|
||||||
table_insert(polygon, polygon[1])
|
table_insert(polygon, polygon[1])
|
||||||
table_insert(polygon, polygon[2])
|
table_insert(polygon, polygon[2])
|
||||||
@ -274,7 +274,7 @@ function SkeletonClipping:clip(x1, y1, x2, y2, x3, y3, clippingArea, output)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if outputStart == #output then -- All edges outside.
|
if outputStart == #output then -- All edges outside.
|
||||||
for i, v in ipairs(originalOutput) do
|
for i, _ in ipairs(originalOutput) do
|
||||||
originalOutput[i] = nil
|
originalOutput[i] = nil
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
@ -286,7 +286,7 @@ function SkeletonClipping:clip(x1, y1, x2, y2, x3, y3, clippingArea, output)
|
|||||||
if (i == clippingVerticesLast) then break end
|
if (i == clippingVerticesLast) then break end
|
||||||
local temp = output
|
local temp = output
|
||||||
output = input
|
output = input
|
||||||
for i, v in ipairs(output) do
|
for i, _ in ipairs(output) do
|
||||||
output[i] = nil
|
output[i] = nil
|
||||||
end
|
end
|
||||||
input = temp
|
input = temp
|
||||||
@ -294,7 +294,7 @@ function SkeletonClipping:clip(x1, y1, x2, y2, x3, y3, clippingArea, output)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if originalOutput ~= output then
|
if originalOutput ~= output then
|
||||||
for i, v in ipairs(originalOutput) do
|
for i, _ in ipairs(originalOutput) do
|
||||||
originalOutput[i] = nil
|
originalOutput[i] = nil
|
||||||
end
|
end
|
||||||
i = 1
|
i = 1
|
||||||
|
|||||||
@ -56,7 +56,7 @@ end
|
|||||||
|
|
||||||
function SkeletonData:findBone (boneName)
|
function SkeletonData:findBone (boneName)
|
||||||
if not boneName then error("boneName cannot be nil.", 2) end
|
if not boneName then error("boneName cannot be nil.", 2) end
|
||||||
for i,bone in ipairs(self.bones) do
|
for _,bone in ipairs(self.bones) do
|
||||||
if bone.name == boneName then return bone end
|
if bone.name == boneName then return bone end
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
@ -85,7 +85,7 @@ end
|
|||||||
|
|
||||||
function SkeletonData:findSkin (skinName)
|
function SkeletonData:findSkin (skinName)
|
||||||
if not skinName then error("skinName cannot be nil.", 2) end
|
if not skinName then error("skinName cannot be nil.", 2) end
|
||||||
for i,skin in ipairs(self.skins) do
|
for _,skin in ipairs(self.skins) do
|
||||||
if skin.name == skinName then return skin end
|
if skin.name == skinName then return skin end
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
@ -93,7 +93,7 @@ end
|
|||||||
|
|
||||||
function SkeletonData:findEvent (eventName)
|
function SkeletonData:findEvent (eventName)
|
||||||
if not eventName then error("eventName cannot be nil.", 2) end
|
if not eventName then error("eventName cannot be nil.", 2) end
|
||||||
for i,event in ipairs(self.events) do
|
for _,event in ipairs(self.events) do
|
||||||
if event.name == eventName then return event end
|
if event.name == eventName then return event end
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
@ -101,7 +101,7 @@ end
|
|||||||
|
|
||||||
function SkeletonData:findAnimation (animationName)
|
function SkeletonData:findAnimation (animationName)
|
||||||
if not animationName then error("animationName cannot be nil.", 2) end
|
if not animationName then error("animationName cannot be nil.", 2) end
|
||||||
for i,animation in ipairs(self.animations) do
|
for _,animation in ipairs(self.animations) do
|
||||||
if animation.name == animationName then return animation end
|
if animation.name == animationName then return animation end
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
@ -109,7 +109,7 @@ end
|
|||||||
|
|
||||||
function SkeletonData:findIkConstraint (constraintName)
|
function SkeletonData:findIkConstraint (constraintName)
|
||||||
if not constraintName then error("constraintName cannot be nil.", 2) end
|
if not constraintName then error("constraintName cannot be nil.", 2) end
|
||||||
for i,constraint in ipairs(self.ikConstraints) do
|
for _,constraint in ipairs(self.ikConstraints) do
|
||||||
if constraint.name == constraintName then return constraint end
|
if constraint.name == constraintName then return constraint end
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
@ -117,7 +117,7 @@ end
|
|||||||
|
|
||||||
function SkeletonData:findTransformConstraint (constraintName)
|
function SkeletonData:findTransformConstraint (constraintName)
|
||||||
if not constraintName then error("constraintName cannot be nil.", 2) end
|
if not constraintName then error("constraintName cannot be nil.", 2) end
|
||||||
for i,constraint in ipairs(self.transformConstraints) do
|
for _,constraint in ipairs(self.transformConstraints) do
|
||||||
if constraint.name == constraintName then return constraint end
|
if constraint.name == constraintName then return constraint end
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
@ -125,7 +125,7 @@ end
|
|||||||
|
|
||||||
function SkeletonData:findPathConstraint (constraintName)
|
function SkeletonData:findPathConstraint (constraintName)
|
||||||
if not constraintName then error("constraintName cannot be nil.", 2) end
|
if not constraintName then error("constraintName cannot be nil.", 2) end
|
||||||
for i,constraint in ipairs(self.pathConstraints) do
|
for _,constraint in ipairs(self.pathConstraints) do
|
||||||
if constraint.name == constraintName then return constraint end
|
if constraint.name == constraintName then return constraint end
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@ -60,7 +60,7 @@ function SkeletonJson.new (attachmentLoader)
|
|||||||
}
|
}
|
||||||
|
|
||||||
function self:readSkeletonDataFile (fileName, base)
|
function self:readSkeletonDataFile (fileName, base)
|
||||||
return self:readSkeletonData(spine.utils.readFile(fileName, base))
|
return self:readSkeletonData(utils.readFile(fileName, base))
|
||||||
end
|
end
|
||||||
|
|
||||||
local readAttachment
|
local readAttachment
|
||||||
@ -76,7 +76,7 @@ function SkeletonJson.new (attachmentLoader)
|
|||||||
function self:readSkeletonData (jsonText)
|
function self:readSkeletonData (jsonText)
|
||||||
local scale = self.scale
|
local scale = self.scale
|
||||||
local skeletonData = SkeletonData.new(self.attachmentLoader)
|
local skeletonData = SkeletonData.new(self.attachmentLoader)
|
||||||
local root = spine.utils.readJSON(jsonText)
|
local root = utils.readJSON(jsonText)
|
||||||
if not root then error("Invalid JSON: " .. jsonText, 2) end
|
if not root then error("Invalid JSON: " .. jsonText, 2) end
|
||||||
|
|
||||||
-- Skeleton.
|
-- Skeleton.
|
||||||
@ -117,7 +117,6 @@ function SkeletonJson.new (attachmentLoader)
|
|||||||
-- Slots.
|
-- Slots.
|
||||||
if root["slots"] then
|
if root["slots"] then
|
||||||
for i,slotMap in ipairs(root["slots"]) do
|
for i,slotMap in ipairs(root["slots"]) do
|
||||||
local index = i
|
|
||||||
local slotName = slotMap["name"]
|
local slotName = slotMap["name"]
|
||||||
local boneName = slotMap["bone"]
|
local boneName = slotMap["bone"]
|
||||||
local boneData = skeletonData:findBone(boneName)
|
local boneData = skeletonData:findBone(boneName)
|
||||||
@ -151,11 +150,11 @@ function SkeletonJson.new (attachmentLoader)
|
|||||||
|
|
||||||
-- IK constraints.
|
-- IK constraints.
|
||||||
if root["ik"] then
|
if root["ik"] then
|
||||||
for i,constraintMap in ipairs(root["ik"]) do
|
for _,constraintMap in ipairs(root["ik"]) do
|
||||||
local data = IkConstraintData.new(constraintMap["name"])
|
local data = IkConstraintData.new(constraintMap["name"])
|
||||||
data.order = getValue(constraintMap, "order", 0)
|
data.order = getValue(constraintMap, "order", 0)
|
||||||
|
|
||||||
for i,boneName in ipairs(constraintMap["bones"]) do
|
for _,boneName in ipairs(constraintMap["bones"]) do
|
||||||
local bone = skeletonData:findBone(boneName)
|
local bone = skeletonData:findBone(boneName)
|
||||||
if not bone then error("IK bone not found: " .. boneName) end
|
if not bone then error("IK bone not found: " .. boneName) end
|
||||||
table_insert(data.bones, bone)
|
table_insert(data.bones, bone)
|
||||||
@ -174,11 +173,11 @@ function SkeletonJson.new (attachmentLoader)
|
|||||||
|
|
||||||
-- Transform constraints
|
-- Transform constraints
|
||||||
if root["transform"] then
|
if root["transform"] then
|
||||||
for i,constraintMap in ipairs(root["transform"]) do
|
for _,constraintMap in ipairs(root["transform"]) do
|
||||||
data = TransformConstraintData.new(constraintMap.name)
|
local data = TransformConstraintData.new(constraintMap.name)
|
||||||
data.order = getValue(constraintMap, "order", 0)
|
data.order = getValue(constraintMap, "order", 0)
|
||||||
|
|
||||||
for i,boneName in ipairs(constraintMap.bones) do
|
for _,boneName in ipairs(constraintMap.bones) do
|
||||||
local bone = skeletonData:findBone(boneName)
|
local bone = skeletonData:findBone(boneName)
|
||||||
if not bone then error("Transform constraint bone not found: " .. boneName, 2) end
|
if not bone then error("Transform constraint bone not found: " .. boneName, 2) end
|
||||||
table_insert(data.bones, bone)
|
table_insert(data.bones, bone)
|
||||||
@ -186,7 +185,7 @@ function SkeletonJson.new (attachmentLoader)
|
|||||||
|
|
||||||
local targetName = constraintMap.target
|
local targetName = constraintMap.target
|
||||||
data.target = skeletonData:findBone(targetName)
|
data.target = skeletonData:findBone(targetName)
|
||||||
if not data.target then error("Transform constraint target bone not found: " .. boneName, 2) end
|
if not data.target then error("Transform constraint target bone not found: " .. (targetName or "none"), 2) end
|
||||||
|
|
||||||
data.offsetRotation = getValue(constraintMap, "rotation", 0);
|
data.offsetRotation = getValue(constraintMap, "rotation", 0);
|
||||||
data.offsetX = getValue(constraintMap, "x", 0) * scale;
|
data.offsetX = getValue(constraintMap, "x", 0) * scale;
|
||||||
@ -206,11 +205,11 @@ function SkeletonJson.new (attachmentLoader)
|
|||||||
|
|
||||||
-- Path constraints
|
-- Path constraints
|
||||||
if root["path"] then
|
if root["path"] then
|
||||||
for i,constraintMap in ipairs(root.path) do
|
for _,constraintMap in ipairs(root.path) do
|
||||||
local data = PathConstraintData.new(constraintMap.name);
|
local data = PathConstraintData.new(constraintMap.name);
|
||||||
data.order = getValue(constraintMap, "order", 0)
|
data.order = getValue(constraintMap, "order", 0)
|
||||||
|
|
||||||
for i,boneName in ipairs(constraintMap.bones) do
|
for _,boneName in ipairs(constraintMap.bones) do
|
||||||
local bone = skeletonData:findBone(boneName)
|
local bone = skeletonData:findBone(boneName)
|
||||||
if not bone then error("Path constraint bone not found: " .. boneName, 2) end
|
if not bone then error("Path constraint bone not found: " .. boneName, 2) end
|
||||||
table_insert(data.bones, bone)
|
table_insert(data.bones, bone)
|
||||||
@ -254,7 +253,7 @@ function SkeletonJson.new (attachmentLoader)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Linked meshes
|
-- Linked meshes
|
||||||
for i, linkedMesh in ipairs(self.linkedMeshes) do
|
for _, linkedMesh in ipairs(self.linkedMeshes) do
|
||||||
local skin = skeletonData.defaultSkin
|
local skin = skeletonData.defaultSkin
|
||||||
if linkedMesh.skin then skin = skeletonData:findSkin(linkedMesh.skin) end
|
if linkedMesh.skin then skin = skeletonData:findSkin(linkedMesh.skin) end
|
||||||
if not skin then error("Skin not found: " .. linkedMesh.skin) end
|
if not skin then error("Skin not found: " .. linkedMesh.skin) end
|
||||||
@ -331,7 +330,7 @@ function SkeletonJson.new (attachmentLoader)
|
|||||||
|
|
||||||
elseif type == AttachmentType.mesh or type == AttachmentType.linkedmesh then
|
elseif type == AttachmentType.mesh or type == AttachmentType.linkedmesh then
|
||||||
local mesh = attachmentLoader:newMeshAttachment(skin, name, path)
|
local mesh = attachmentLoader:newMeshAttachment(skin, name, path)
|
||||||
if not mesh then return null end
|
if not mesh then return nil end
|
||||||
mesh.path = path
|
mesh.path = path
|
||||||
|
|
||||||
local color = map.color
|
local color = map.color
|
||||||
@ -487,7 +486,7 @@ function SkeletonJson.new (attachmentLoader)
|
|||||||
timeline.slotIndex = slotIndex
|
timeline.slotIndex = slotIndex
|
||||||
|
|
||||||
local frameIndex = 0
|
local frameIndex = 0
|
||||||
for i,valueMap in ipairs(values) do
|
for _,valueMap in ipairs(values) do
|
||||||
local color = valueMap["color"]
|
local color = valueMap["color"]
|
||||||
timeline:setFrame(
|
timeline:setFrame(
|
||||||
frameIndex, valueMap["time"],
|
frameIndex, valueMap["time"],
|
||||||
@ -506,7 +505,7 @@ function SkeletonJson.new (attachmentLoader)
|
|||||||
timeline.slotIndex = slotIndex
|
timeline.slotIndex = slotIndex
|
||||||
|
|
||||||
local frameIndex = 0
|
local frameIndex = 0
|
||||||
for i,valueMap in ipairs(values) do
|
for _,valueMap in ipairs(values) do
|
||||||
local light = valueMap["light"]
|
local light = valueMap["light"]
|
||||||
local dark = valueMap["dark"]
|
local dark = valueMap["dark"]
|
||||||
timeline:setFrame(
|
timeline:setFrame(
|
||||||
@ -529,7 +528,7 @@ function SkeletonJson.new (attachmentLoader)
|
|||||||
timeline.slotIndex = slotIndex
|
timeline.slotIndex = slotIndex
|
||||||
|
|
||||||
local frameIndex = 0
|
local frameIndex = 0
|
||||||
for i,valueMap in ipairs(values) do
|
for _,valueMap in ipairs(values) do
|
||||||
local attachmentName = valueMap["name"]
|
local attachmentName = valueMap["name"]
|
||||||
timeline:setFrame(frameIndex, valueMap["time"], attachmentName)
|
timeline:setFrame(frameIndex, valueMap["time"], attachmentName)
|
||||||
frameIndex = frameIndex + 1
|
frameIndex = frameIndex + 1
|
||||||
@ -557,7 +556,7 @@ function SkeletonJson.new (attachmentLoader)
|
|||||||
timeline.boneIndex = boneIndex
|
timeline.boneIndex = boneIndex
|
||||||
|
|
||||||
local frameIndex = 0
|
local frameIndex = 0
|
||||||
for i,valueMap in ipairs(values) do
|
for _,valueMap in ipairs(values) do
|
||||||
timeline:setFrame(frameIndex, valueMap["time"], valueMap["angle"])
|
timeline:setFrame(frameIndex, valueMap["time"], valueMap["angle"])
|
||||||
readCurve(valueMap, timeline, frameIndex)
|
readCurve(valueMap, timeline, frameIndex)
|
||||||
frameIndex = frameIndex + 1
|
frameIndex = frameIndex + 1
|
||||||
@ -579,7 +578,7 @@ function SkeletonJson.new (attachmentLoader)
|
|||||||
timeline.boneIndex = boneIndex
|
timeline.boneIndex = boneIndex
|
||||||
|
|
||||||
local frameIndex = 0
|
local frameIndex = 0
|
||||||
for i,valueMap in ipairs(values) do
|
for _,valueMap in ipairs(values) do
|
||||||
local x = (valueMap["x"] or 0) * timelineScale
|
local x = (valueMap["x"] or 0) * timelineScale
|
||||||
local y = (valueMap["y"] or 0) * timelineScale
|
local y = (valueMap["y"] or 0) * timelineScale
|
||||||
timeline:setFrame(frameIndex, valueMap["time"], x, y)
|
timeline:setFrame(frameIndex, valueMap["time"], x, y)
|
||||||
@ -608,7 +607,7 @@ function SkeletonJson.new (attachmentLoader)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
local frameIndex = 0
|
local frameIndex = 0
|
||||||
for i,valueMap in ipairs(values) do
|
for _,valueMap in ipairs(values) do
|
||||||
local mix = 1
|
local mix = 1
|
||||||
if valueMap["mix"] ~= nil then mix = valueMap["mix"] end
|
if valueMap["mix"] ~= nil then mix = valueMap["mix"] end
|
||||||
local bendPositive = 1
|
local bendPositive = 1
|
||||||
@ -635,7 +634,7 @@ function SkeletonJson.new (attachmentLoader)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
local frameIndex = 0
|
local frameIndex = 0
|
||||||
for i,valueMap in ipairs(values) do
|
for _,valueMap in ipairs(values) do
|
||||||
timeline:setFrame(frameIndex, valueMap.time, getValue(valueMap, "rotateMix", 1), getValue(valueMap, "translateMix", 1), getValue(valueMap, "scaleMix", 1), getValue(valueMap, "shearMix", 1))
|
timeline:setFrame(frameIndex, valueMap.time, getValue(valueMap, "rotateMix", 1), getValue(valueMap, "translateMix", 1), getValue(valueMap, "scaleMix", 1), getValue(valueMap, "shearMix", 1))
|
||||||
readCurve(valueMap, timeline, frameIndex)
|
readCurve(valueMap, timeline, frameIndex)
|
||||||
frameIndex = frameIndex + 1
|
frameIndex = frameIndex + 1
|
||||||
@ -664,7 +663,7 @@ function SkeletonJson.new (attachmentLoader)
|
|||||||
end
|
end
|
||||||
timeline.pathConstraintIndex = index
|
timeline.pathConstraintIndex = index
|
||||||
local frameIndex = 0
|
local frameIndex = 0
|
||||||
for i,valueMap in ipairs(timelineMap) do
|
for _,valueMap in ipairs(timelineMap) do
|
||||||
timeline:setFrame(frameIndex, valueMap.time, getValue(valueMap, timelineName, 0) * timelineScale)
|
timeline:setFrame(frameIndex, valueMap.time, getValue(valueMap, timelineName, 0) * timelineScale)
|
||||||
readCurve(valueMap, timeline, frameIndex)
|
readCurve(valueMap, timeline, frameIndex)
|
||||||
frameIndex = frameIndex + 1
|
frameIndex = frameIndex + 1
|
||||||
@ -675,7 +674,7 @@ function SkeletonJson.new (attachmentLoader)
|
|||||||
local timeline = Animation.PathConstraintMixTimeline.new(#timelineMap)
|
local timeline = Animation.PathConstraintMixTimeline.new(#timelineMap)
|
||||||
timeline.pathConstraintIndex = index
|
timeline.pathConstraintIndex = index
|
||||||
local frameIndex = 0
|
local frameIndex = 0
|
||||||
for i,valueMap in ipairs(timelineMap) do
|
for _,valueMap in ipairs(timelineMap) do
|
||||||
timeline:setFrame(frameIndex, valueMap.time, getValue(valueMap, "rotateMix", 1), getValue(valueMap, "translateMix", 1))
|
timeline:setFrame(frameIndex, valueMap.time, getValue(valueMap, "rotateMix", 1), getValue(valueMap, "translateMix", 1))
|
||||||
readCurve(valueMap, timeline, frameIndex)
|
readCurve(valueMap, timeline, frameIndex)
|
||||||
frameIndex = frameIndex + 1
|
frameIndex = frameIndex + 1
|
||||||
@ -708,7 +707,7 @@ function SkeletonJson.new (attachmentLoader)
|
|||||||
timeline.attachment = attachment
|
timeline.attachment = attachment
|
||||||
|
|
||||||
local frameIndex = 0
|
local frameIndex = 0
|
||||||
for i,valueMap in ipairs(timelineMap) do
|
for _,valueMap in ipairs(timelineMap) do
|
||||||
local deform = nil
|
local deform = nil
|
||||||
local verticesValue = getValue(valueMap, "vertices", nil)
|
local verticesValue = getValue(valueMap, "vertices", nil)
|
||||||
if verticesValue == nil then
|
if verticesValue == nil then
|
||||||
@ -754,7 +753,7 @@ function SkeletonJson.new (attachmentLoader)
|
|||||||
local timeline = Animation.DrawOrderTimeline.new(#drawOrderValues)
|
local timeline = Animation.DrawOrderTimeline.new(#drawOrderValues)
|
||||||
local slotCount = #skeletonData.slots
|
local slotCount = #skeletonData.slots
|
||||||
local frameIndex = 0
|
local frameIndex = 0
|
||||||
for i,drawOrderMap in ipairs(drawOrderValues) do
|
for _,drawOrderMap in ipairs(drawOrderValues) do
|
||||||
local drawOrder = nil
|
local drawOrder = nil
|
||||||
local offsets = drawOrderMap["offsets"]
|
local offsets = drawOrderMap["offsets"]
|
||||||
if offsets then
|
if offsets then
|
||||||
@ -762,7 +761,7 @@ function SkeletonJson.new (attachmentLoader)
|
|||||||
local unchanged = {}
|
local unchanged = {}
|
||||||
local originalIndex = 1
|
local originalIndex = 1
|
||||||
local unchangedIndex = 1
|
local unchangedIndex = 1
|
||||||
for ii,offsetMap in ipairs(offsets) do
|
for _,offsetMap in ipairs(offsets) do
|
||||||
local slotIndex = skeletonData:findSlotIndex(offsetMap["slot"])
|
local slotIndex = skeletonData:findSlotIndex(offsetMap["slot"])
|
||||||
if slotIndex == -1 then error("Slot not found: " .. offsetMap["slot"]) end
|
if slotIndex == -1 then error("Slot not found: " .. offsetMap["slot"]) end
|
||||||
-- Collect unchanged items.
|
-- Collect unchanged items.
|
||||||
@ -801,7 +800,7 @@ function SkeletonJson.new (attachmentLoader)
|
|||||||
if events then
|
if events then
|
||||||
local timeline = Animation.EventTimeline.new(#events)
|
local timeline = Animation.EventTimeline.new(#events)
|
||||||
local frameIndex = 0
|
local frameIndex = 0
|
||||||
for i,eventMap in ipairs(events) do
|
for _,eventMap in ipairs(events) do
|
||||||
local eventData = skeletonData:findEvent(eventMap["name"])
|
local eventData = skeletonData:findEvent(eventMap["name"])
|
||||||
if not eventData then error("Event not found: " .. eventMap["name"]) end
|
if not eventData then error("Event not found: " .. eventMap["name"]) end
|
||||||
local event = Event.new(eventMap["time"], eventData)
|
local event = Event.new(eventMap["time"], eventData)
|
||||||
|
|||||||
@ -86,14 +86,14 @@ end
|
|||||||
|
|
||||||
function Skin:findNamesForSlot (slotIndex)
|
function Skin:findNamesForSlot (slotIndex)
|
||||||
local names = {}
|
local names = {}
|
||||||
for k,v in self.attachments do
|
for _,v in self.attachments do
|
||||||
if v[1] == slotIndex then table_insert(names, v[2]) end
|
if v[1] == slotIndex then table_insert(names, v[2]) end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Skin:findAttachmentsForSlot (slotIndex)
|
function Skin:findAttachmentsForSlot (slotIndex)
|
||||||
local attachments = {}
|
local attachments = {}
|
||||||
for k,v in self.attachments do
|
for _,v in self.attachments do
|
||||||
if v[1] == slotIndex then table_insert(attachments, v[3]) end
|
if v[1] == slotIndex then table_insert(attachments, v[3]) end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -235,14 +235,14 @@ function TextureAtlas:parse (atlasContent, imageLoader)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function TextureAtlas:findRegion(name)
|
function TextureAtlas:findRegion(name)
|
||||||
for i, region in ipairs(self.regions) do
|
for _, region in ipairs(self.regions) do
|
||||||
if region.name == name then return region end
|
if region.name == name then return region end
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function TextureAtlas:dispose()
|
function TextureAtlas:dispose()
|
||||||
for i, page in ipairs(self.pairs) do
|
for _, page in ipairs(self.pairs) do
|
||||||
-- FIXME implement disposing of pages
|
-- FIXME implement disposing of pages
|
||||||
-- love2d doesn't support manual disposing
|
-- love2d doesn't support manual disposing
|
||||||
end
|
end
|
||||||
|
|||||||
@ -41,6 +41,7 @@ local table_insert = table.insert
|
|||||||
local math_deg = math.deg
|
local math_deg = math.deg
|
||||||
local math_rad = math.rad
|
local math_rad = math.rad
|
||||||
local math_abs = math.abs
|
local math_abs = math.abs
|
||||||
|
local math_floor = math.floor
|
||||||
|
|
||||||
local TransformConstraint = {}
|
local TransformConstraint = {}
|
||||||
TransformConstraint.__index = TransformConstraint
|
TransformConstraint.__index = TransformConstraint
|
||||||
@ -58,7 +59,7 @@ function TransformConstraint.new (data, skeleton)
|
|||||||
}
|
}
|
||||||
setmetatable(self, TransformConstraint)
|
setmetatable(self, TransformConstraint)
|
||||||
|
|
||||||
for i,bone in ipairs(data.bones) do
|
for _,bone in ipairs(data.bones) do
|
||||||
table_insert(self.bones, skeleton:findBone(bone.name))
|
table_insert(self.bones, skeleton:findBone(bone.name))
|
||||||
end
|
end
|
||||||
self.target = skeleton:findBone(data.target.name)
|
self.target = skeleton:findBone(data.target.name)
|
||||||
@ -101,7 +102,7 @@ function TransformConstraint:applyAbsoluteWorld ()
|
|||||||
local offsetRotation = self.data.offsetRotation * degRadReflect
|
local offsetRotation = self.data.offsetRotation * degRadReflect
|
||||||
local offsetShearY = self.data.offsetShearY * degRadReflect
|
local offsetShearY = self.data.offsetShearY * degRadReflect
|
||||||
local bones = self.bones
|
local bones = self.bones
|
||||||
for i, bone in ipairs(bones) do
|
for _, bone in ipairs(bones) do
|
||||||
local modified = false
|
local modified = false
|
||||||
if rotateMix ~= 0 then
|
if rotateMix ~= 0 then
|
||||||
local a = bone.a
|
local a = bone.a
|
||||||
@ -188,7 +189,7 @@ function TransformConstraint:applyRelativeWorld ()
|
|||||||
local offsetRotation = self.data.offsetRotation * degRadReflect
|
local offsetRotation = self.data.offsetRotation * degRadReflect
|
||||||
local offsetShearY = self.data.offsetShearY * degRadReflect
|
local offsetShearY = self.data.offsetShearY * degRadReflect
|
||||||
local bones = self.bones
|
local bones = self.bones
|
||||||
for i, bone in ipairs(bones) do
|
for _, bone in ipairs(bones) do
|
||||||
local modified = false
|
local modified = false
|
||||||
|
|
||||||
if rotateMix ~= 0 then
|
if rotateMix ~= 0 then
|
||||||
@ -226,7 +227,7 @@ function TransformConstraint:applyRelativeWorld ()
|
|||||||
local s = (math_sqrt(ta * ta + tc * tc) - 1 + self.data.offsetScaleX) * scaleMix + 1
|
local s = (math_sqrt(ta * ta + tc * tc) - 1 + self.data.offsetScaleX) * scaleMix + 1
|
||||||
bone.a = bone.a * s
|
bone.a = bone.a * s
|
||||||
bone.c = bone.c * s
|
bone.c = bone.c * s
|
||||||
local s = (math_sqrt(tb * tb + td * td) - 1 + self.data.offsetScaleY) * scaleMix + 1
|
s = (math_sqrt(tb * tb + td * td) - 1 + self.data.offsetScaleY) * scaleMix + 1
|
||||||
bone.b = bone.b * s
|
bone.b = bone.b * s
|
||||||
bone.d = bone.d * s
|
bone.d = bone.d * s
|
||||||
modified = true
|
modified = true
|
||||||
@ -260,7 +261,7 @@ function TransformConstraint:applyAbsoluteLocal ()
|
|||||||
local target = self.target
|
local target = self.target
|
||||||
if not target.appliedValid then target:updatedAppliedTransform() end
|
if not target.appliedValid then target:updatedAppliedTransform() end
|
||||||
local bones = self.bones
|
local bones = self.bones
|
||||||
for i, bone in ipairs(bones) do
|
for _, bone in ipairs(bones) do
|
||||||
local modified = false
|
local modified = false
|
||||||
if not bone.appliedValid then bone:updateAppliedTransform() end
|
if not bone.appliedValid then bone:updateAppliedTransform() end
|
||||||
|
|
||||||
@ -308,7 +309,7 @@ function TransformConstraint:applyRelativeLocal ()
|
|||||||
local target = self.target
|
local target = self.target
|
||||||
if not target.appliedValid then target:updateAppliedTransform() end
|
if not target.appliedValid then target:updateAppliedTransform() end
|
||||||
local bones = self.bones
|
local bones = self.bones
|
||||||
for i, bone in ipairs(bones) do
|
for _, bone in ipairs(bones) do
|
||||||
if not bone.appliedValid then bone:updateAppliedTransform() end
|
if not bone.appliedValid then bone:updateAppliedTransform() end
|
||||||
|
|
||||||
local rotation = bone.arotation
|
local rotation = bone.arotation
|
||||||
@ -328,7 +329,7 @@ function TransformConstraint:applyRelativeLocal ()
|
|||||||
scaleX = scaleX * (((target.ascaleX - 1 + self.data.offsetScaleX) * scaleMix) + 1)
|
scaleX = scaleX * (((target.ascaleX - 1 + self.data.offsetScaleX) * scaleMix) + 1)
|
||||||
end
|
end
|
||||||
if scaleY > 0.00001 then
|
if scaleY > 0.00001 then
|
||||||
scaleY = scaleY * (((target.ascaleY - 1 + this.data.offsetScaleY) * scaleMix) + 1)
|
scaleY = scaleY * (((target.ascaleY - 1 + self.data.offsetScaleY) * scaleMix) + 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user