mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
This commit is contained in:
parent
6d8baa17fd
commit
bdfd390dae
@ -41,6 +41,9 @@ local math_signum = utils.signum
|
|||||||
local math_floor = math.floor
|
local math_floor = math.floor
|
||||||
local math_ceil = math.ceil
|
local math_ceil = math.ceil
|
||||||
local math_mod = utils.mod
|
local math_mod = utils.mod
|
||||||
|
local testBit = utils.testBit
|
||||||
|
local setBit = utils.setBit
|
||||||
|
local clearBit = utils.clearBit
|
||||||
|
|
||||||
local function zlen(array)
|
local function zlen(array)
|
||||||
return #array + 1
|
return #array + 1
|
||||||
@ -50,7 +53,8 @@ local EMPTY_ANIMATION = Animation.new("<empty>", {}, 0)
|
|||||||
local SUBSEQUENT = 0
|
local SUBSEQUENT = 0
|
||||||
local FIRST = 1
|
local FIRST = 1
|
||||||
local HOLD = 2
|
local HOLD = 2
|
||||||
local HOLD_MIX = 3;
|
local HOLD_MIX = 3
|
||||||
|
local NOT_LAST = 4
|
||||||
|
|
||||||
local EventType = {
|
local EventType = {
|
||||||
start = 0,
|
start = 0,
|
||||||
@ -357,7 +361,7 @@ function AnimationState:apply (skeleton)
|
|||||||
|
|
||||||
for ii,timeline in ipairs(timelines) do
|
for ii,timeline in ipairs(timelines) do
|
||||||
local timelineBlend = MixBlend.setup
|
local timelineBlend = MixBlend.setup
|
||||||
if timelineMode[ii] == SUBSEQUENT then timelineBlend = blend end
|
if clearBit(timelineMode[ii], NOT_LAST) == SUBSEQUENT then timelineBlend = blend end
|
||||||
|
|
||||||
if timeline.type == Animation.TimelineType.rotate then
|
if timeline.type == Animation.TimelineType.rotate then
|
||||||
self:applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, ii * 2,
|
self:applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, ii * 2,
|
||||||
@ -421,15 +425,21 @@ function AnimationState:applyMixingFrom (to, skeleton, blend)
|
|||||||
local direction = MixDirection.out;
|
local direction = MixDirection.out;
|
||||||
local timelineBlend = MixBlend.setup
|
local timelineBlend = MixBlend.setup
|
||||||
local alpha = 0
|
local alpha = 0
|
||||||
if timelineMode[i] == SUBSEQUENT then
|
if clearBit(timelineMode[i], NOT_LAST) == SUBSEQUENT then
|
||||||
if not attachments and timeline.type == Animation.TimelineType.attachment then skipSubsequent = true end
|
if not attachments and timeline.type == Animation.TimelineType.attachment then
|
||||||
|
if testBit(timelineMode[i], NOT_LAST) then
|
||||||
|
skipSubsequent = true
|
||||||
|
else
|
||||||
|
blend = MixBlend.setup
|
||||||
|
end
|
||||||
|
end
|
||||||
if not drawOrder and timeline.type == Animation.TimelineType.drawOrder then skipSubsequent = true end
|
if not drawOrder and timeline.type == Animation.TimelineType.drawOrder then skipSubsequent = true end
|
||||||
timelineBlend = blend
|
timelineBlend = blend
|
||||||
alpha = alphaMix
|
alpha = alphaMix
|
||||||
elseif timelineMode[i] == FIRST then
|
elseif clearBit(timelineMode[i], NOT_LAST) == FIRST then
|
||||||
timelineBlend = MixBlend.setup
|
timelineBlend = MixBlend.setup
|
||||||
alpha = alphaMix
|
alpha = alphaMix
|
||||||
elseif timelineMode[i] == HOLD then
|
elseif clearBit(timelineMode[i], NOT_LAST) == HOLD then
|
||||||
timelineBlend = MixBlend.setup
|
timelineBlend = MixBlend.setup
|
||||||
alpha = alphaHold
|
alpha = alphaHold
|
||||||
else
|
else
|
||||||
@ -445,7 +455,7 @@ function AnimationState:applyMixingFrom (to, skeleton, blend)
|
|||||||
else
|
else
|
||||||
if timelineBlend == MixBlend.setup then
|
if timelineBlend == MixBlend.setup then
|
||||||
if timeline.type == Animation.TimelineType.attachment then
|
if timeline.type == Animation.TimelineType.attachment then
|
||||||
if attachments then direction = MixDirection._in end
|
if attachments or testBit(timelineMode[i], NOT_LAST) then direction = MixDirection._in end
|
||||||
elseif timeline.type == Animation.TimelineType.drawOrder then
|
elseif timeline.type == Animation.TimelineType.drawOrder then
|
||||||
if drawOrder then direction = MixDirection._in end
|
if drawOrder then direction = MixDirection._in end
|
||||||
end
|
end
|
||||||
@ -803,7 +813,10 @@ function AnimationState:_animationsChanged ()
|
|||||||
|
|
||||||
self.propertyIDs = {}
|
self.propertyIDs = {}
|
||||||
|
|
||||||
|
local highestIndex = -1
|
||||||
for i, entry in pairs(self.tracks) do
|
for i, entry in pairs(self.tracks) do
|
||||||
|
if i > highestIndex then highestIndex = i end
|
||||||
|
|
||||||
if entry then
|
if entry then
|
||||||
while entry.mixingFrom do
|
while entry.mixingFrom do
|
||||||
entry = entry.mixingFrom
|
entry = entry.mixingFrom
|
||||||
@ -811,15 +824,45 @@ function AnimationState:_animationsChanged ()
|
|||||||
|
|
||||||
repeat
|
repeat
|
||||||
if (entry.mixingTo == nil or entry.mixBlend ~= MixBlend.add) then
|
if (entry.mixingTo == nil or entry.mixBlend ~= MixBlend.add) then
|
||||||
self:setTimelineModes(entry)
|
self:computeHold(entry)
|
||||||
end
|
end
|
||||||
entry = entry.mixingTo
|
entry = entry.mixingTo
|
||||||
until (entry == nil)
|
until (entry == nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.propertyIDs = {}
|
||||||
|
for i = highestIndex, 0, -1 do
|
||||||
|
entry = self.tracks[i]
|
||||||
|
while entry do
|
||||||
|
self:computeNotLast(entry)
|
||||||
|
entry = entry.mixingFrom
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function AnimationState:setTimelineModes(entry)
|
function AnimationState:computeNotLast(entry)
|
||||||
|
local timelines = entry.animation.timelines
|
||||||
|
local timelinesCount = #entry.animation.timelines
|
||||||
|
local timelineMode = entry.timelineMode
|
||||||
|
local propertyIDs = self.propertyIDs
|
||||||
|
|
||||||
|
local i = 1
|
||||||
|
while i <= timelinesCount do
|
||||||
|
local timeline = timelines[i]
|
||||||
|
if (timeline.type == Animation.TimelineType.attachment) then
|
||||||
|
local slotIndex = timeline.slotIndex
|
||||||
|
if not (propertyIDs[slotIndex] == nil) then
|
||||||
|
timelineMode[i] = setBit(timelineMode[i], NOT_LAST)
|
||||||
|
else
|
||||||
|
propertyIDs[slotIndex] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
i = i + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function AnimationState:computeHold(entry)
|
||||||
local to = entry.mixingTo
|
local to = entry.mixingTo
|
||||||
local timelines = entry.animation.timelines
|
local timelines = entry.animation.timelines
|
||||||
local timelinesCount = #entry.animation.timelines
|
local timelinesCount = #entry.animation.timelines
|
||||||
@ -847,7 +890,11 @@ function AnimationState:setTimelineModes(entry)
|
|||||||
timelineMode[i] = SUBSEQUENT
|
timelineMode[i] = SUBSEQUENT
|
||||||
else
|
else
|
||||||
propertyIDs[id] = id
|
propertyIDs[id] = id
|
||||||
if to == nil or not self:hasTimeline(to, id) then
|
local timeline = timelines[i]
|
||||||
|
if to == nil or timeline.type == Animation.TimelineType.attachment
|
||||||
|
or timeline.type == Animation.TimelineType.drawOrder
|
||||||
|
or timeline.type == Animation.TimelineType.event
|
||||||
|
or not self:hasTimeline(to, id) then
|
||||||
timelineMode[i] = FIRST
|
timelineMode[i] = FIRST
|
||||||
else
|
else
|
||||||
local next = to.mixingTo
|
local next = to.mixingTo
|
||||||
|
|||||||
@ -166,4 +166,22 @@ function utils.randomTriangularWith(min, max, mode)
|
|||||||
return max - math_sqrt((1 - u) * d * (max - mode))
|
return max - math_sqrt((1 - u) * d * (max - mode))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function utils.testBit(value, bit)
|
||||||
|
return value % (2 * bit) >= bit
|
||||||
|
end
|
||||||
|
|
||||||
|
function utils.setBit(value, bit)
|
||||||
|
if value % (2 * bit) >= bit then
|
||||||
|
return value
|
||||||
|
end
|
||||||
|
return value + bit
|
||||||
|
end
|
||||||
|
|
||||||
|
function utils.clearBit(value, bit)
|
||||||
|
if value % (2 * bit) >= bit then
|
||||||
|
return value - bit
|
||||||
|
end
|
||||||
|
return value
|
||||||
|
end
|
||||||
|
|
||||||
return utils
|
return utils
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user