From 84dcd6ba25d0dc523768700973e196e4c89f18a1 Mon Sep 17 00:00:00 2001 From: badlogic Date: Tue, 24 Jul 2018 15:01:20 +0200 Subject: [PATCH] [lua] Ported flipX/flipY -> scaleX/scaleY change. See #1142. --- spine-corona/main.lua | 2 +- spine-love/main.lua | 5 ++-- spine-lua/AnimationState.lua | 43 ++++------------------------ spine-lua/Bone.lua | 54 +++++++++++------------------------- spine-lua/Skeleton.lua | 2 +- 5 files changed, 25 insertions(+), 81 deletions(-) diff --git a/spine-corona/main.lua b/spine-corona/main.lua index b31b93258..687b28f70 100644 --- a/spine-corona/main.lua +++ b/spine-corona/main.lua @@ -25,7 +25,7 @@ function loadSkeleton(atlasFile, jsonFile, x, y, scale, animation, skin) json.scale = scale local skeletonData = json:readSkeletonDataFile("data/" .. jsonFile) local skeleton = spine.Skeleton.new(skeletonData) - skeleton.flipY = true -- Corona's coordinate system has its y-axis point downwards + skeleton.scaleY = -1 -- Corona's coordinate system has its y-axis point downwards skeleton.group.x = x skeleton.group.y = y diff --git a/spine-love/main.lua b/spine-love/main.lua index abb89a797..4e3f21bbd 100644 --- a/spine-love/main.lua +++ b/spine-love/main.lua @@ -45,8 +45,7 @@ function loadSkeleton (jsonFile, atlasFile, animation, skin, scale, x, y) local skeleton = spine.Skeleton.new(skeletonData) skeleton.x = x skeleton.y = y - skeleton.flipX = false - skeleton.flipY = true + skeleton.scaleY = -1 if skin then skeleton:setSkin(skin) end @@ -97,13 +96,13 @@ end function love.load(arg) if arg[#arg] == "-debug" then require("mobdebug").start() end skeletonRenderer = spine.SkeletonRenderer.new(true) + table.insert(skeletons, loadSkeleton("stretchyman-pro", "stretchyman", "sneak", nil, 0.3, 200, 500)) table.insert(skeletons, loadSkeleton("coin-pro", "coin", "rotate", nil, 0.5, 400, 500)) table.insert(skeletons, loadSkeleton("spineboy-ess", "spineboy", "walk", nil, 0.5, 400, 500)) table.insert(skeletons, loadSkeleton("raptor-pro", "raptor", "walk", nil, 0.3, 400, 500)) table.insert(skeletons, loadSkeleton("goblins-pro", "goblins", "walk", "goblin", 1, 400, 500)) table.insert(skeletons, loadSkeleton("tank-pro", "tank", "drive", nil, 0.2, 600, 500)) table.insert(skeletons, loadSkeleton("vine-pro", "vine", "grow", nil, 0.3, 400, 500)) - table.insert(skeletons, loadSkeleton("stretchyman-pro", "stretchyman", "sneak", nil, 0.3, 200, 500)) end function love.update (delta) diff --git a/spine-lua/AnimationState.lua b/spine-lua/AnimationState.lua index 9c5f4c1b9..d8780737d 100644 --- a/spine-lua/AnimationState.lua +++ b/spine-lua/AnimationState.lua @@ -377,7 +377,7 @@ function AnimationState:apply (skeleton) for i,current in pairs(tracks) do if not (current == nil or current.delay > 0) then applied = true -<<<<<<< HEAD + local blend = current.mixBlend if i == 0 then blend = MixBlend.first end @@ -385,15 +385,6 @@ function AnimationState:apply (skeleton) local mix = current.alpha if current.mixingFrom then mix = mix * self:applyMixingFrom(current, skeleton, blend) -======= - local currrentPose = MixPose.currentLayered - if i == 0 then currentPose = MixPose.current end - - -- Apply mixing from entries first. - local mix = current.alpha - if current.mixingFrom then - mix = mix * self:applyMixingFrom(current, skeleton, currentPose) ->>>>>>> 3.6 elseif current.trackTime >= current.trackEnd and current.next == nil then mix = 0 end @@ -411,19 +402,13 @@ function AnimationState:apply (skeleton) local firstFrame = #current.timelinesRotation == 0 local timelinesRotation = current.timelinesRotation - for i,timeline in ipairs(timelines) do -<<<<<<< HEAD + for ii,timeline in ipairs(timelines) do local timelineBlend = MixBlend.setup - if timelineData[i] == SUBSEQUENT then timelineBlend = blend end + if timelineData[ii] == SUBSEQUENT then timelineBlend = blend end -======= - local pose = MixPose.currentPose - if timelineData[i] >= FIRST then pose = MixPose.setup end - ->>>>>>> 3.6 if timeline.type == Animation.TimelineType.rotate then - self:applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, i * 2, - firstFrame) -- FIXME passing ii * 2, indexing correct? + self:applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, ii * 2, + firstFrame) else timeline:apply(skeleton, animationLast, animationTime, events, mix, timelineBlend, MixDirection._in) end @@ -468,7 +453,6 @@ function AnimationState:applyMixingFrom (to, skeleton, blend) for i,timeline in ipairs(timelines) do timeline:apply(skeleton, animationLast, animationTime, events, alphaMix, blend, MixDirection.out) end -<<<<<<< HEAD else local timelineData = from.timelineData local timelineDipMix = from.timelineDipMix @@ -493,13 +477,6 @@ function AnimationState:applyMixingFrom (to, skeleton, blend) elseif timelineData[i] == DIP then timelineBlend = MixBlend.setup alpha = alphaDip -======= - - if not skipSubsequent then - from.totalAlpha = from.totalAlpha + alpha - if timeline.type == Animation.TimelineType.rotate then - self:applyRotateTimeline(timeline, skeleton, animationTime, alpha, pose, timelinesRotation, i * 2, firstFrame) ->>>>>>> 3.6 else timelineBlend = MixBlend.setup local dipMix = timelineDipMix[i] @@ -525,13 +502,8 @@ function AnimationState:applyMixingFrom (to, skeleton, blend) return mix end -<<<<<<< HEAD function AnimationState:applyRotateTimeline (timeline, skeleton, time, alpha, blend, timelinesRotation, i, firstFrame) if firstFrame then -======= -function AnimationState:applyRotateTimeline (timeline, skeleton, time, alpha, pose, timelinesRotation, i, firstFrame) - if firstFrame then ->>>>>>> 3.6 timelinesRotation[i] = 0 timelinesRotation[i+1] = 0 end @@ -858,13 +830,8 @@ function AnimationState:_animationsChanged () local mixingTo = self.mixingTo for i, entry in pairs(self.tracks) do -<<<<<<< HEAD if entry and (i == 0 or entry.mixBlend ~= MixBlend.add) then entry:setTimelineData(nil, mixingTo, propertyIDs) -======= - if entry then - entry:setTimelineData(nil, mixingTo, propertyIDs) ->>>>>>> 3.6 end end end diff --git a/spine-lua/Bone.lua b/spine-lua/Bone.lua index 967fd23c9..c3daa5182 100644 --- a/spine-lua/Bone.lua +++ b/spine-lua/Bone.lua @@ -95,33 +95,22 @@ function Bone:updateWorldTransformWith (x, y, rotation, scaleX, scaleY, shearX, self.ashearX = shearX self.ashearY = shearY self.appliedValid = true + + local sx = self.skeleton.scaleX; + local sy = self.skeleton.scaleY; local parent = self.parent if parent == nil then local rotationY = rotation + 90 + shearY local rotationRad = math_rad(rotation + shearX) - local rotationYRad = math_rad(rotationY) - local la = math_cos(rotationRad) * scaleX - local lb = math_cos(rotationYRad) * scaleY - local lc = math_sin(rotationRad) * scaleX - local ld = math_sin(rotationYRad) * scaleY + local rotationYRad = math_rad(rotationY) local skeleton = self.skeleton - if skeleton.flipX then - x = -x - la = -la - lb = -lb - end - if skeleton.flipY then - y = -y - lc = -lc - ld = -ld - end - self.a = la - self.b = lb - self.c = lc - self.d = ld - self.worldX = x + skeleton.x - self.worldY = y + skeleton.y + self.a = math_cos(rotationRad) * scaleX * sx + self.b = math_cos(rotationYRad) * scaleY * sy + self.c = math_sin(rotationRad) * scaleX * sx + self.d = math_sin(rotationYRad) * scaleY * sy + self.worldX = x * sx + skeleton.x + self.worldY = y * sy + skeleton.y return end @@ -176,8 +165,8 @@ function Bone:updateWorldTransformWith (x, y, rotation, scaleX, scaleY, shearX, elseif transformMode == TransformMode.noScale or transformMode == TransformMode.noScaleOrReflection then local cos = math_cos(math_rad(rotation)) local sin = math_sin(math_rad(rotation)) - local za = pa * cos + pb * sin - local zc = pc * cos + pd * sin + local za = (pa * cos + pb * sin) / sx + local zc = (pc * cos + pd * sin) / sy local s = math_sqrt(za * za + zc * zc) if s > 0.00001 then s = 1 / s end za = za * s @@ -190,27 +179,16 @@ function Bone:updateWorldTransformWith (x, y, rotation, scaleX, scaleY, shearX, local lb = math_cos(math_rad(90 + shearY)) * scaleY; local lc = math_sin(math_rad(shearX)) * scaleX; local ld = math_sin(math_rad(90 + shearY)) * scaleY; - local flip = self.skeleton.flipX ~= self.skeleton.flipY - if transformMode ~= TransformMode.noScaleOrReflection then flip = pa * pd - pb * pc < 0 end - if flip then - zb = -zb - zd = -zd - end self.a = za * la + zb * lc self.b = za * lb + zb * ld self.c = zc * la + zd * lc self.d = zc * lb + zd * ld - return end - if self.skeleton.flipX then - self.a = -self.a - self.b = -self.b - end - if self.skeleton.flipY then - self.c = -self.c - self.d = -self.d - end + self.a = self.a * sx + self.b = self.b * sx + self.c = self.c * sy + self.d = self.d * sy end function Bone:setToSetupPose () diff --git a/spine-lua/Skeleton.lua b/spine-lua/Skeleton.lua index e93d5bc3e..cb468861e 100644 --- a/spine-lua/Skeleton.lua +++ b/spine-lua/Skeleton.lua @@ -63,7 +63,7 @@ function Skeleton.new (data) skin = nil, color = Color.newWith(1, 1, 1, 1), time = 0, - flipX = false, flipY = false, + scaleX = 1, scaleY = 1, x = 0, y = 0 } setmetatable(self, Skeleton)