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)
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
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 vertexCount = #frameVertices[0]
local vertices = slot.attachmentVertices
if #vertices < vertexCount then
if not vertices or #vertices < vertexCount then
vertices = {}
slot.attachmentVertices = vertices
end
@ -620,16 +620,15 @@ function Animation.FfdTimeline.new ()
alpha = 1 -- Don't mix from uninitialized slot vertices.
end
slot.attachmentVerticesCount = vertexCount
if time >= frames[#frames] then -- Time is after last frame.
local lastVertices = frameVertices[#frames]
if time >= frames[#frames - 1] then -- Time is after last frame.
local lastVertices = frameVertices[#frames - 1]
if alpha < 1 then
for i = 0, vertexCount do
for i = 1, vertexCount do
local vertex = vertices[i]
vertices[i] = vertex + (lastVertices[i] - vertex) * alpha
end
else
for i = 0, vertexCount do
for i = 1, vertexCount do
vertices[i] = lastVertices[i]
end
end
@ -647,13 +646,13 @@ function Animation.FfdTimeline.new ()
local nextVertices = frameVertices[frameIndex]
if alpha < 1 then
for i = 0, vertexCount do
for i = 1, vertexCount do
local prev = prevVertices[i]
local vertices = vertices[i]
vertices[i] = vertices + (prev + (nextVertices[i] - prev) * percent - vertices) * alpha
local vertex = vertices[i]
vertices[i] = vertex + (prev + (nextVertices[i] - prev) * percent - vertex) * alpha
end
else
for i = 0, vertexCount do
for i = 1, vertexCount do
local prev = prevVertices[i]
vertices[i] = prev + (nextVertices[i] - prev) * percent
end

View File

@ -46,7 +46,7 @@ function MeshAttachment.new (name)
r = 1, g = 1, b = 1, a = 1,
path = 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,
regionWidth = 0, regionHeight = 0,
regionOriginalWidth = 0, regionOriginalHeight = 0,
@ -75,12 +75,13 @@ function MeshAttachment.new (name)
function self:computeWorldVertices (x, y, slot, worldVertices)
local bone = slot.bone
x,y=slot.bone.skeleton.x,slot.bone.skeleton.y
x = x + bone.worldX
y = y + bone.worldY
local m00, m01, m10, m11 = bone.m00, bone.m01, bone.m10, bone.m11
local vertices = self.vertices
local verticesCount = vertices.length
if #slot.attachmentVertices == verticesCount then vertices = slot.attachmentVertices end
local verticesCount = #vertices
if slot.attachmentVertices and #slot.attachmentVertices == verticesCount then vertices = slot.attachmentVertices end
for i = 1, verticesCount, 2 do
local vx = vertices[i]
local vy = vertices[i + 1]

View File

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

View File

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