[lua] Ported all skin API changes, see #841.

This commit is contained in:
badlogic 2019-06-04 08:29:35 +02:00
parent 68f8cc40c4
commit 2eca53763f
5 changed files with 44 additions and 41 deletions

View File

@ -823,7 +823,7 @@ function Animation.DeformTimeline.new (frameCount)
local slotAttachment = slot.attachment local slotAttachment = slot.attachment
if not slotAttachment then return end 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.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 frames = self.frames
local deformArray = slot.deform local deformArray = slot.deform

View File

@ -267,6 +267,12 @@ function SkeletonJson.new (attachmentLoader)
if not skin then error("Skin not found: " .. linkedMesh.skin) end if not skin then error("Skin not found: " .. linkedMesh.skin) end
local parent = skin:getAttachment(linkedMesh.slotIndex, linkedMesh.parent) local parent = skin:getAttachment(linkedMesh.slotIndex, linkedMesh.parent)
if not parent then error("Parent mesh not found: " + linkedMesh.parent) end 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:setParentMesh(parent)
linkedMesh.mesh:updateUVs() linkedMesh.mesh:updateUVs()
end end
@ -359,12 +365,12 @@ function SkeletonJson.new (attachmentLoader)
local parent = map.parent local parent = map.parent
if parent then if parent then
mesh.inheritDeform = getValue(map, "deform", true)
table_insert(self.linkedMeshes, { table_insert(self.linkedMeshes, {
mesh = mesh, mesh = mesh,
skin = getValue(map, "skin", nil), skin = getValue(map, "skin", nil),
slotIndex = slotIndex, slotIndex = slotIndex,
parent = parent parent = parent,
inheritDeform = getValue(map, "deform", true)
}) })
return mesh return mesh
end end

View File

@ -122,19 +122,13 @@ function Skin:copySkin (skin)
local attachments = skin:getAttachments() local attachments = skin:getAttachments()
for i, entry in ipairs(attachments) do for i, entry in ipairs(attachments) do
if entry.attachment.type == AttachmentType.mesh then
entry.attachment = entry.attachment:newLinkedMesh()
self:setAttachment(entry.slotIndex, entry.name, entry.attachment)
else
entry.attachment = entry.attachment:copy() entry.attachment = entry.attachment:copy()
self:setAttachment(entry.slotIndex, entry.name, entry.attachment) self:setAttachment(entry.slotIndex, entry.name, entry.attachment)
end 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
end
end end
end end

View File

@ -49,7 +49,6 @@ function MeshAttachment.new (name)
self.color = Color.newWith(1, 1, 1, 1) self.color = Color.newWith(1, 1, 1, 1)
self.hullLength = 0 self.hullLength = 0
self.parentMesh = nil self.parentMesh = nil
self.inheritDeform = false
self.tempColor = Color.newWith(1, 1, 1, 1) self.tempColor = Color.newWith(1, 1, 1, 1)
self.width = 0 self.width = 0
self.height = 0 self.height = 0
@ -129,10 +128,6 @@ function MeshAttachment:updateUVs ()
end end
end end
function MeshAttachment:applyDeform (sourceAttachment)
return self == sourceAttachment or (self.inheritDeform and self.parentMesh == sourceAttachment)
end
function MeshAttachment:setParentMesh (parentMesh) function MeshAttachment:setParentMesh (parentMesh)
self.parentMesh = parentMesh self.parentMesh = parentMesh
if parentMesh then if parentMesh then
@ -146,30 +141,40 @@ function MeshAttachment:setParentMesh (parentMesh)
end end
function MeshAttachment:copy () function MeshAttachment:copy ()
if self.parentMesh then return self:newLinkedMesh() end
local copy = MeshAttachment.new(self.name) local copy = MeshAttachment.new(self.name)
copy.region = self.region copy.region = self.region
copy.path = self.path copy.path = self.path
copy.color:setFrom(self.color)
if not self.parentMesh then
self:copyTo(copy) self:copyTo(copy)
copy.regionUVs = utils.copy(self.regionUVs) copy.regionUVs = utils.copy(self.regionUVs)
copy.uvs = utils.copy(self.uvs) copy.uvs = utils.copy(self.uvs)
copy.triangles = utils.copy(self.triangles) copy.triangles = utils.copy(self.triangles)
copy.color:setFrom(self.color)
copy.hullLength = self.hullLength copy.hullLength = self.hullLength
copy.inheritDeform = self.inheritDeform
copy.tempColor:setFrom(self.tempColor)
if self.edges then if self.edges then
copy.edges = utils.copy(edges) copy.edges = utils.copy(edges)
end end
copy.width = self.width copy.width = self.width
copy.height = self.height copy.height = self.height
else
copy:setParentMesh(self.parentMesh)
copy.updateUVs()
end
return copy return copy
end 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 return MeshAttachment

View File

@ -52,6 +52,7 @@ function VertexAttachment.new (name, attachmentType)
nextID = nextID - 65535 nextID = nextID - 65535
end end
self.id = nextID * SHL_11 self.id = nextID * SHL_11
self.deformAttachment = self
nextID = nextID + 1 nextID = nextID + 1
setmetatable(self, VertexAttachment) setmetatable(self, VertexAttachment)
return self return self
@ -147,10 +148,6 @@ function VertexAttachment:computeWorldVertices (slot, start, count, worldVertice
end end
end end
function VertexAttachment:applyDeform (sourceAttachment)
return self == sourceAttachment
end
function VertexAttachment:copyTo (attachment) function VertexAttachment:copyTo (attachment)
if self.bones then if self.bones then
attachment.bones = utils.copy(self.bones) attachment.bones = utils.copy(self.bones)
@ -165,6 +162,7 @@ function VertexAttachment:copyTo (attachment)
end end
attachment.worldVerticesLength = self.worldVerticesLength attachment.worldVerticesLength = self.worldVerticesLength
attachment.deformAttachment = self.deformAttachment
end end
return VertexAttachment return VertexAttachment