[lua] Many fixes, a few things still broken.

This commit is contained in:
Nathan Sweet 2021-06-06 23:17:26 -04:00
parent 6428b82e1e
commit 0b26b5e74a
4 changed files with 29 additions and 45 deletions

View File

@ -155,7 +155,7 @@ function Animation.Timeline.new (timelineType, frameEntries, frameCount, propert
local self = {
timelineType = timelineType,
propertyIds = propertyIds,
frames = utils.newNumberArrayZero((frameCount - 1) * frameEntries)
frames = utils.newNumberArrayZero(frameCount * frameEntries)
}
function self:getFrameEntries ()
@ -201,19 +201,10 @@ local BEZIER_SIZE = 18
Animation.CurveTimeline = {}
function Animation.CurveTimeline.new (timelineType, frameEntries, frameCount, bezierCount, propertyIds)
local LINEAR = 0
local STEPPED = 1
local BEZIER = 2
local BEZIER_SIZE = 10 * 2 - 1
local self = Animation.Timeline.new(timelineType, frameEntries, frameCount, propertyIds)
self.curves = utils.newNumberArrayZero(frameCount + bezierCount * BEZIER_SIZE)
self.curves[frameCount - 1] = STEPPED
function self:getFrameCount ()
return math_floor(zlen(self.curves) / BEZIER_SIZE) + 1
end
function self:setStepped (frame)
self.curves[frame] = STEPPED
end
@ -1459,8 +1450,8 @@ function Animation.DeformTimeline.new (frameCount, bezierCount, slotIndex, attac
end
utils.setArraySize(deform, vertexCount)
if time >= frames[zlen(frames) - 1] then -- Time is after last frame.
local lastVertices = vertices[zlen(frames) - 1]
if time >= frames[#frames] then -- Time is after last frame.
local lastVertices = vertices[#frames]
if alpha == 1 then
if blend == MixBlend.add then
if vertexAttachment.bones == nil then

View File

@ -551,7 +551,7 @@ end
function AnimationState:applyRotateTimeline (timeline, skeleton, time, alpha, blend, timelinesRotation, i, firstFrame)
if firstFrame then
timelinesRotation[i] = 0
timelinesRotation[i+1] = 0
timelinesRotation[i + 1] = 0
end
if alpha == 1 then

View File

@ -859,7 +859,7 @@ function SkeletonJson.new (attachmentLoader)
for i,keyMap in ipairs(timelineMap) do
local frame = i - 1
timeline:setFrame(frame, time, mixRotate, mixX, mixY, mixScaleX, mixScaleY, mixShearY)
local nextMap = timelineMap[frame + 1]
local nextMap = timelineMap[i + 1]
if not nextMap then
timeline:shrink(bezier)
break
@ -927,7 +927,7 @@ function SkeletonJson.new (attachmentLoader)
for i,keyMap in ipairs(timelineMap) do
local frame = i - 1
timeline:setFrame(frame, time, mixRotate, mixX, mixY)
local nextMap = timelineMap[frame + 1]
local nextMap = timelineMap[i + 1]
if not nextMap then
timeline:shrink(bezier)
break
@ -981,8 +981,11 @@ function SkeletonJson.new (attachmentLoader)
local deform = nil
local verticesValue = getValue(keyMap, "vertices", nil)
if verticesValue == nil then
if weighted then
deform = utils.newNumberArray(deformLength)
else
deform = vertices
if weighted then deform = utils.newNumberArray(deformLength) end
end
else
deform = utils.newNumberArray(deformLength)
local start = getValue(keyMap, "offset", 0) + 1
@ -1005,7 +1008,7 @@ function SkeletonJson.new (attachmentLoader)
end
end
timeline:setFrame(frame, time, deform)
local nextMap = timelineMap[frame + 1]
local nextMap = timelineMap[i + 1]
if not nextMap then
timeline:shrink(bezier)
break
@ -1109,16 +1112,6 @@ function SkeletonJson.new (attachmentLoader)
table_insert(skeletonData.animations, Animation.new(name, timelines, duration))
end
readCurve = function (map, timeline, frame)
local curve = map["curve"]
if not curve then return end
if curve == "stepped" then
timeline:setStepped(frame)
else
timeline:setCurve(frame, getValue(map, "curve", 0), getValue(map, "c2", 0), getValue(map, "c3", 1), getValue(map, "c4", 1))
end
end
readTimeline1 = function (keys, timeline, defaultValue, scale)
local keyMap = keys[1]
local time = getValue(keyMap, "time", 0)
@ -1127,17 +1120,17 @@ function SkeletonJson.new (attachmentLoader)
for i,keyMap in ipairs(keys) do
local frame = i - 1
timeline:setFrame(frame, time, value)
local nextMap = keys[frame + 1]
if not nextMap then break end
local nextMap = keys[i + 1]
if not nextMap then
timeline:shrink(bezier)
return timeline
end
local time2 = getValue(nextMap, "time", 0)
local value2 = getValue(nextMap, "value", defaultValue) * scale
local curve = keyMap.curve
if curve then bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, value, value2, scale) end
if keyMap.curve then bezier = readCurve(keyMap.curve, timeline, bezier, frame, 0, time, time2, value, value2, scale) end
time = time2
value = value2
end
timeline:shrink(bezier)
return timeline
end
readTimeline2 = function (keys, timeline, name1, name2, defaultValue, scale)
@ -1149,8 +1142,11 @@ function SkeletonJson.new (attachmentLoader)
for i,keyMap in ipairs(keys) do
local frame = i - 1
timeline:setFrame(frame, time, value1, value2)
local nextMap = keys[frame + 1]
if not nextMap then break end
local nextMap = keys[i + 1]
if not nextMap then
timeline:shrink(bezier)
return timeline
end
local time2 = getValue(nextMap, "time", 0)
local nvalue1 = getValue(nextMap, name1, defaultValue) * scale
local nvalue2 = getValue(nextMap, name2, defaultValue) * scale
@ -1163,8 +1159,6 @@ function SkeletonJson.new (attachmentLoader)
value1 = nvalue1
value2 = nvalue2
end
timeline:shrink(bezier)
return timeline
end
readCurve = function (curve, timeline, bezier, frame, value, time1, time2, value1, value2, scale)

View File

@ -61,11 +61,11 @@ end
function VertexAttachment:computeWorldVertices (slot, start, count, worldVertices, offset, stride)
count = offset + (count / 2) * stride
local skeleton = slot.bone.skeleton
local deformArray = slot.deform
local deform = slot.deform
local vertices = self.vertices
local bones = self.bones
if not bones then
if #deformArray > 0 then vertices = deformArray end
if #deform > 0 then vertices = deform end
local bone = slot.bone
x = bone.worldX
y = bone.worldY
@ -95,7 +95,7 @@ function VertexAttachment:computeWorldVertices (slot, start, count, worldVertice
i = i + 2
end
local skeletonBones = skeleton.bones
if #deformArray == 0 then
if #deform == 0 then
local w = offset
local b = skip * 3
while w < count do
@ -119,7 +119,6 @@ function VertexAttachment:computeWorldVertices (slot, start, count, worldVertice
w = w + stride
end
else
local deform = deformArray
local w = offset
local b = skip * 3
local f = skip * 2