diff --git a/spine-lua/Animation.lua b/spine-lua/Animation.lua index 4146a9930..583f3d3a1 100644 --- a/spine-lua/Animation.lua +++ b/spine-lua/Animation.lua @@ -823,7 +823,7 @@ function Animation.DeformTimeline.new (frameCount) local slotAttachment = slot.attachment if not slotAttachment then return end if not (slotAttachment.type == AttachmentType.mesh or slotAttachment.type == AttachmentType.linkedmesh or slotAttachment.type == AttachmentType.path or slotAttachment.type == AttachmentType.boundingbox) then return end - if not slotAttachment:applyDeform(self.attachment) then return end + if slotAttachment.deformAttachment ~= self.attachment then return end local frames = self.frames local deformArray = slot.deform diff --git a/spine-lua/SkeletonJson.lua b/spine-lua/SkeletonJson.lua index d6f3dc0b9..23054ad23 100644 --- a/spine-lua/SkeletonJson.lua +++ b/spine-lua/SkeletonJson.lua @@ -267,6 +267,12 @@ function SkeletonJson.new (attachmentLoader) if not skin then error("Skin not found: " .. linkedMesh.skin) end local parent = skin:getAttachment(linkedMesh.slotIndex, linkedMesh.parent) if not parent then error("Parent mesh not found: " + linkedMesh.parent) end + if linkedMesh.inheritDeform then + linkedMesh.mesh.deformAttachment = parent + else + linkedMesh.mesh.deformAttachment = linkedMesh.mesh + end + linkedMesh.mesh:setParentMesh(parent) linkedMesh.mesh:updateUVs() end @@ -359,12 +365,12 @@ function SkeletonJson.new (attachmentLoader) local parent = map.parent if parent then - mesh.inheritDeform = getValue(map, "deform", true) table_insert(self.linkedMeshes, { mesh = mesh, skin = getValue(map, "skin", nil), slotIndex = slotIndex, - parent = parent + parent = parent, + inheritDeform = getValue(map, "deform", true) }) return mesh end diff --git a/spine-lua/Skin.lua b/spine-lua/Skin.lua index 54deb01ea..01372587f 100644 --- a/spine-lua/Skin.lua +++ b/spine-lua/Skin.lua @@ -121,19 +121,13 @@ function Skin:copySkin (skin) end local attachments = skin:getAttachments() - for i, entry in ipairs(attachments) do - entry.attachment = entry.attachment:copy() - self:setAttachment(entry.slotIndex, entry.name, entry.attachment) - end - - attachments = self:getAttachments() for i, entry in ipairs(attachments) do if entry.attachment.type == AttachmentType.mesh then - local mesh = entry.attachment - if mesh.parentMesh then - mesh:setParentMesh(self:getAttachment(entry.slotIndex, mesh:getParentMesh().name)) - mesh:updateUVs() - end + entry.attachment = entry.attachment:newLinkedMesh() + self:setAttachment(entry.slotIndex, entry.name, entry.attachment) + else + entry.attachment = entry.attachment:copy() + self:setAttachment(entry.slotIndex, entry.name, entry.attachment) end end end diff --git a/spine-lua/attachments/MeshAttachment.lua b/spine-lua/attachments/MeshAttachment.lua index e7823c517..0f9e94dba 100644 --- a/spine-lua/attachments/MeshAttachment.lua +++ b/spine-lua/attachments/MeshAttachment.lua @@ -49,7 +49,6 @@ function MeshAttachment.new (name) self.color = Color.newWith(1, 1, 1, 1) self.hullLength = 0 self.parentMesh = nil - self.inheritDeform = false self.tempColor = Color.newWith(1, 1, 1, 1) self.width = 0 self.height = 0 @@ -129,10 +128,6 @@ function MeshAttachment:updateUVs () end end -function MeshAttachment:applyDeform (sourceAttachment) - return self == sourceAttachment or (self.inheritDeform and self.parentMesh == sourceAttachment) -end - function MeshAttachment:setParentMesh (parentMesh) self.parentMesh = parentMesh if parentMesh then @@ -146,30 +141,40 @@ function MeshAttachment:setParentMesh (parentMesh) end function MeshAttachment:copy () + if self.parentMesh then return self:newLinkedMesh() end + local copy = MeshAttachment.new(self.name) copy.region = self.region copy.path = self.path - - if not self.parentMesh then - self:copyTo(copy) - copy.regionUVs = utils.copy(self.regionUVs) - copy.uvs = utils.copy(self.uvs) - copy.triangles = utils.copy(self.triangles) - copy.color:setFrom(self.color) - copy.hullLength = self.hullLength - copy.inheritDeform = self.inheritDeform - copy.tempColor:setFrom(self.tempColor) - if self.edges then - copy.edges = utils.copy(edges) - end - copy.width = self.width - copy.height = self.height - else - copy:setParentMesh(self.parentMesh) - copy.updateUVs() + copy.color:setFrom(self.color) + + self:copyTo(copy) + copy.regionUVs = utils.copy(self.regionUVs) + copy.uvs = utils.copy(self.uvs) + copy.triangles = utils.copy(self.triangles) + copy.hullLength = self.hullLength + if self.edges then + copy.edges = utils.copy(edges) end + copy.width = self.width + copy.height = self.height return copy end +function MeshAttachment:newLinkedMesh () + local copy = MeshAttachment.new(self.name) + copy.region = self.region + copy.path = self.path + copy.color:setFrom(self.color) + if self.parentMesh then + copy.deformAttachment = self.parentMesh + else + copy.deformAttachment = self + end + copy:setParentMesh(self.parentMesh) + copy:updateUVs() + return copy +end + return MeshAttachment diff --git a/spine-lua/attachments/VertexAttachment.lua b/spine-lua/attachments/VertexAttachment.lua index d83b78e93..2065194bd 100644 --- a/spine-lua/attachments/VertexAttachment.lua +++ b/spine-lua/attachments/VertexAttachment.lua @@ -52,6 +52,7 @@ function VertexAttachment.new (name, attachmentType) nextID = nextID - 65535 end self.id = nextID * SHL_11 + self.deformAttachment = self nextID = nextID + 1 setmetatable(self, VertexAttachment) return self @@ -147,10 +148,6 @@ function VertexAttachment:computeWorldVertices (slot, start, count, worldVertice end end -function VertexAttachment:applyDeform (sourceAttachment) - return self == sourceAttachment -end - function VertexAttachment:copyTo (attachment) if self.bones then attachment.bones = utils.copy(self.bones) @@ -165,6 +162,7 @@ function VertexAttachment:copyTo (attachment) end attachment.worldVerticesLength = self.worldVerticesLength + attachment.deformAttachment = self.deformAttachment end return VertexAttachment