Selaa lähdekoodia

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

badlogic 6 vuotta sitten
vanhempi
commit
2eca53763f

+ 1 - 1
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

+ 8 - 2
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

+ 5 - 11
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

+ 27 - 22
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,29 +141,39 @@ 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
+  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
   
-  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
+  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:setParentMesh(self.parentMesh)
-    copy.updateUVs()
+    copy.deformAttachment = self
   end
-  
+  copy:setParentMesh(self.parentMesh)
+  copy:updateUVs()
   return copy
 end
 

+ 2 - 4
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