FFD fixes

Mesh attachment

Animation fixes (still seem to be timing issues looping frames)

Fix for loading default skin

Zeroing out vertices when loading

Miscellaneous indexing and name issues
This commit is contained in:
Steven Johnson 2016-02-23 16:30:35 -06:00
parent 678c6b1e14
commit 48f8ea1707
4 changed files with 32 additions and 29 deletions

View File

@ -604,7 +604,7 @@ function Animation.FfdTimeline.new ()
function self:apply (skeleton, lastTime, time, firedEvents, alpha) function self:apply (skeleton, lastTime, time, firedEvents, alpha)
local slot = skeleton.slots[self.slotIndex] local slot = skeleton.slots[self.slotIndex]
if slot.attachment ~= attachment then return end if slot.attachment ~= self.attachment then return end
local frames = self.frames local frames = self.frames
if time < frames[0] then return end -- Time is before first frame. if time < frames[0] then return end -- Time is before first frame.
@ -612,7 +612,7 @@ function Animation.FfdTimeline.new ()
local frameVertices = self.frameVertices local frameVertices = self.frameVertices
local vertexCount = #frameVertices[0] local vertexCount = #frameVertices[0]
local vertices = slot.attachmentVertices local vertices = slot.attachmentVertices
if #vertices < vertexCount then if not vertices or #vertices < vertexCount then
vertices = {} vertices = {}
slot.attachmentVertices = vertices slot.attachmentVertices = vertices
end end
@ -620,16 +620,15 @@ function Animation.FfdTimeline.new ()
alpha = 1 -- Don't mix from uninitialized slot vertices. alpha = 1 -- Don't mix from uninitialized slot vertices.
end end
slot.attachmentVerticesCount = vertexCount slot.attachmentVerticesCount = vertexCount
if time >= frames[#frames - 1] then -- Time is after last frame.
if time >= frames[#frames] then -- Time is after last frame. local lastVertices = frameVertices[#frames - 1]
local lastVertices = frameVertices[#frames]
if alpha < 1 then if alpha < 1 then
for i = 0, vertexCount do for i = 1, vertexCount do
local vertex = vertices[i] local vertex = vertices[i]
vertices[i] = vertex + (lastVertices[i] - vertex) * alpha vertices[i] = vertex + (lastVertices[i] - vertex) * alpha
end end
else else
for i = 0, vertexCount do for i = 1, vertexCount do
vertices[i] = lastVertices[i] vertices[i] = lastVertices[i]
end end
end end
@ -647,13 +646,13 @@ function Animation.FfdTimeline.new ()
local nextVertices = frameVertices[frameIndex] local nextVertices = frameVertices[frameIndex]
if alpha < 1 then if alpha < 1 then
for i = 0, vertexCount do for i = 1, vertexCount do
local prev = prevVertices[i] local prev = prevVertices[i]
local vertices = vertices[i] local vertex = vertices[i]
vertices[i] = vertices + (prev + (nextVertices[i] - prev) * percent - vertices) * alpha vertices[i] = vertex + (prev + (nextVertices[i] - prev) * percent - vertex) * alpha
end end
else else
for i = 0, vertexCount do for i = 1, vertexCount do
local prev = prevVertices[i] local prev = prevVertices[i]
vertices[i] = prev + (nextVertices[i] - prev) * percent vertices[i] = prev + (nextVertices[i] - prev) * percent
end end

View File

@ -34,7 +34,7 @@ local AttachmentType = require "spine-lua.AttachmentType"
local MeshAttachment = {} local MeshAttachment = {}
function MeshAttachment.new (name) function MeshAttachment.new (name)
if not name then error("name cannot be nil", 2) end if not name then error("name cannot be nil", 2) end
local self = { local self = {
name = name, name = name,
type = AttachmentType.mesh, type = AttachmentType.mesh,
@ -46,7 +46,7 @@ function MeshAttachment.new (name)
r = 1, g = 1, b = 1, a = 1, r = 1, g = 1, b = 1, a = 1,
path = nil, path = nil,
rendererObject = nil, rendererObject = nil,
regionU = 0, regionV = 0, regionU2 = 0, regionV2 = 0, regionRotate = false, regionU = 0, regionV = 0, regionU2 = 1, regionV2 = 1, regionRotate = false,
regionOffsetX = 0, regionOffsetY = 0, regionOffsetX = 0, regionOffsetY = 0,
regionWidth = 0, regionHeight = 0, regionWidth = 0, regionHeight = 0,
regionOriginalWidth = 0, regionOriginalHeight = 0, regionOriginalWidth = 0, regionOriginalHeight = 0,
@ -75,12 +75,13 @@ function MeshAttachment.new (name)
function self:computeWorldVertices (x, y, slot, worldVertices) function self:computeWorldVertices (x, y, slot, worldVertices)
local bone = slot.bone local bone = slot.bone
x,y=slot.bone.skeleton.x,slot.bone.skeleton.y
x = x + bone.worldX x = x + bone.worldX
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 vertices = self.vertices local vertices = self.vertices
local verticesCount = vertices.length local verticesCount = #vertices
if #slot.attachmentVertices == verticesCount then vertices = slot.attachmentVertices end if slot.attachmentVertices and #slot.attachmentVertices == verticesCount then vertices = slot.attachmentVertices end
for i = 1, verticesCount, 2 do for i = 1, verticesCount, 2 do
local vx = vertices[i] local vx = vertices[i]
local vy = vertices[i + 1] local vy = vertices[i + 1]

View File

@ -178,9 +178,8 @@ function SkeletonJson.new (attachmentLoader)
end end
if skin.name == "default" then if skin.name == "default" then
skeletonData.defaultSkin = skin skeletonData.defaultSkin = skin
else
table.insert(skeletonData.skins, skin)
end end
table.insert(skeletonData.skins, skin)
end end
end end
@ -470,22 +469,21 @@ function SkeletonJson.new (attachmentLoader)
local ffd = map["ffd"] local ffd = map["ffd"]
if ffd then if ffd then
for skinName,slotMap in pairs(ffd) do for skinName,slotMap in pairs(ffd) do
local skin = skeletonData.findSkin(skinName) local skin = skeletonData:findSkin(skinName)
for slotName,meshMap in pairs(slotMap) do for slotName,meshMap in pairs(slotMap) do
local slotIndex = skeletonData.findSlotIndex(slotName) local slotIndex = skeletonData:findSlotIndex(slotName)
for meshName,values in pairs(meshMap) do for meshName,values in pairs(meshMap) do
local timeline = Animation.FfdTimeline.new() local timeline = Animation.FfdTimeline.new()
local attachment = skin:getAttachment(slotIndex, meshName) local attachment = skin:getAttachment(slotIndex, meshName)
if not attachment then error("FFD attachment not found: " .. meshName) end if not attachment then error("FFD attachment not found: " .. meshName) end
timeline.slotIndex = slotIndex timeline.slotIndex = slotIndex
timeline.attachment = attachment timeline.attachment = attachment
local isMesh = attachment.type == AttachmentType.mesh local isMesh = attachment.type == AttachmentType.mesh
local vertexCount local vertexCount
if isMesh then if isMesh then
vertexCount = attachment.vertices.length vertexCount = #attachment.vertices
else else
vertexCount = attachment.weights.length / 3 * 2 vertexCount = #attachment.weights / 3 * 2
end end
local frameIndex = 0 local frameIndex = 0
@ -496,12 +494,18 @@ function SkeletonJson.new (attachmentLoader)
vertices = attachment.vertices vertices = attachment.vertices
else else
vertices = {} vertices = {}
vertices.length = vertexCount for i = 1, vertexCount do
vertices[i] = 0
end
end end
else else
local verticesValue = valueMap["vertices"] local verticesValue = valueMap["vertices"]
local vertices = {} local scale = self.scale
vertices = {}
local start = valueMap["offset"] or 0 local start = valueMap["offset"] or 0
for ii = 1, start do
vertices[ii] = 0
end
if scale == 1 then if scale == 1 then
for ii = 1, #verticesValue do for ii = 1, #verticesValue do
vertices[ii + start] = verticesValue[ii] vertices[ii + start] = verticesValue[ii]
@ -520,7 +524,6 @@ function SkeletonJson.new (attachmentLoader)
vertices[vertexCount] = 0 vertices[vertexCount] = 0
end end
end end
timeline:setFrame(frameIndex, valueMap["time"], vertices) timeline:setFrame(frameIndex, valueMap["time"], vertices)
readCurve(timeline, frameIndex, valueMap) readCurve(timeline, frameIndex, valueMap)
frameIndex = frameIndex + 1 frameIndex = frameIndex + 1

View File

@ -47,7 +47,7 @@ function SkinnedMeshAttachment.new (name)
r = 1, g = 1, b = 1, a = 1, r = 1, g = 1, b = 1, a = 1,
path = nil, path = nil,
rendererObject = nil, rendererObject = nil,
regionU = 0, regionV = 0, regionU2 = 0, regionV2 = 0, regionRotate = false, regionU = 0, regionV = 0, regionU2 = 1, regionV2 = 1, regionRotate = false,
regionOffsetX = 0, regionOffsetY = 0, regionOffsetX = 0, regionOffsetY = 0,
regionWidth = 0, regionHeight = 0, regionWidth = 0, regionHeight = 0,
regionOriginalWidth = 0, regionOriginalHeight = 0, regionOriginalWidth = 0, regionOriginalHeight = 0,
@ -76,9 +76,9 @@ function SkinnedMeshAttachment.new (name)
function self:computeWorldVertices (x, y, slot, worldVertices) function self:computeWorldVertices (x, y, slot, worldVertices)
local skeletonBones = slot.bone.skeleton.bones local skeletonBones = slot.bone.skeleton.bones
x,y=slot.bone.skeleton.x,slot.bone.skeleton.y
local weights = self.weights local weights = self.weights
local bones = self.bones local bones = self.bones
local w, v, b, f = 1, 1, 1, 1 local w, v, b, f = 1, 1, 1, 1
local n = #bones local n = #bones
local wx, wy, bone, vx, vy, weight local wx, wy, bone, vx, vy, weight
@ -104,13 +104,13 @@ function SkinnedMeshAttachment.new (name)
end end
else else
local ffd = slot.attachmentVertices local ffd = slot.attachmentVertices
while v < n do while v <= n do
wx = 0 wx = 0
wy = 0 wy = 0
local nn = bones[v] + v local nn = bones[v] + v
v = v + 1 v = v + 1
while v <= nn do while v <= nn do
bone = skeletonBones[bones[v]] bone = skeletonBones[bones[v] + 1]
vx = weights[b] + ffd[f] vx = weights[b] + ffd[f]
vy = weights[b + 1] + ffd[f + 1] vy = weights[b + 1] + ffd[f + 1]
weight = weights[b + 2] weight = weights[b + 2]