mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 17:56:04 +08:00
[lua][love][corona] Added vertex effect support. See #898
This commit is contained in:
parent
943b4f98a7
commit
fdee465333
@ -179,15 +179,18 @@
|
|||||||
* Added `SkeletonClipper` and `Triangulator`, used to implement software clipping of attachments.
|
* Added `SkeletonClipper` and `Triangulator`, used to implement software clipping of attachments.
|
||||||
* `AnimationState#apply` returns boolean indicating if any timeline was applied or not.
|
* `AnimationState#apply` returns boolean indicating if any timeline was applied or not.
|
||||||
* `Animation#apply` and `Timeline#apply`` now take enums `MixPose` and `MixDirection` instead of booleans
|
* `Animation#apply` and `Timeline#apply`` now take enums `MixPose` and `MixDirection` instead of booleans
|
||||||
|
* Added `JitterEffect` and `SwirlEffect` and support for vertex effects in Corona and Love
|
||||||
|
|
||||||
### Love2D
|
### Love2D
|
||||||
* Fixed renderer to work with 3.6 changes
|
* Fixed renderer to work with 3.6 changes
|
||||||
* Added support for two color tinting. Enable it via `SkeletonRenderer.new(true)`.
|
* Added support for two color tinting. Enable it via `SkeletonRenderer.new(true)`.
|
||||||
* Added clipping support.
|
* Added clipping support.
|
||||||
|
* Added support for vertex effects. Set an implementation like "JitterEffect" on `Skeleton.vertexEffect`. See `main.lua` for an example.
|
||||||
|
|
||||||
### Corona
|
### Corona
|
||||||
* Fixed renderer to work with 3.6 changes. Sadly, two color tinting is not supported, as Corona doesn't let us change the vertex format needed and its doesn't allow to modify shaders in the way needed for two color tinting
|
* Fixed renderer to work with 3.6 changes. Sadly, two color tinting is not supported, as Corona doesn't let us change the vertex format needed and its doesn't allow to modify shaders in the way needed for two color tinting
|
||||||
* Added clipping support.
|
* Added clipping support.
|
||||||
|
* Added support for vertex effects. Set an implementation like "JitterEffect" on `SkeletonRenderer.vertexEffect`. See `main.lua` for an example
|
||||||
|
|
||||||
## Typescript/Javascript
|
## Typescript/Javascript
|
||||||
* **Breaking changes**
|
* **Breaking changes**
|
||||||
|
|||||||
@ -5,6 +5,8 @@ local spine = require "spine-corona.spine"
|
|||||||
local skeletons = {}
|
local skeletons = {}
|
||||||
local activeSkeleton = 1
|
local activeSkeleton = 1
|
||||||
local lastTime = 0
|
local lastTime = 0
|
||||||
|
local swirl = spine.SwirlEffect.new(400)
|
||||||
|
local swirlTime = 0
|
||||||
|
|
||||||
function loadSkeleton(atlasFile, jsonFile, x, y, scale, animation, skin)
|
function loadSkeleton(atlasFile, jsonFile, x, y, scale, animation, skin)
|
||||||
-- to load an atlas, we need to define a function that returns
|
-- to load an atlas, we need to define a function that returns
|
||||||
@ -67,7 +69,11 @@ function loadSkeleton(atlasFile, jsonFile, x, y, scale, animation, skin)
|
|||||||
animationState:setAnimationByName(0, "walk", true)
|
animationState:setAnimationByName(0, "walk", true)
|
||||||
local jumpEntry = animationState:addAnimationByName(0, "jump", false, 3)
|
local jumpEntry = animationState:addAnimationByName(0, "jump", false, 3)
|
||||||
animationState:addAnimationByName(0, "run", true, 0)
|
animationState:addAnimationByName(0, "run", true, 0)
|
||||||
else
|
elseif atlasFile == "raptor.atlas" then
|
||||||
|
--skeleton.vertexEffect = spine.JitterEffect.new(5, 5)
|
||||||
|
skeleton.vertexEffect = swirl
|
||||||
|
animationState:setAnimationByName(0, animation, true)
|
||||||
|
else
|
||||||
animationState:setAnimationByName(0, animation, true)
|
animationState:setAnimationByName(0, animation, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -77,10 +83,10 @@ end
|
|||||||
|
|
||||||
-- table.insert(skeletons, loadSkeleton("coin.atlas", "coin-pro.json", 240, 300, 0.4, "rotate"))
|
-- table.insert(skeletons, loadSkeleton("coin.atlas", "coin-pro.json", 240, 300, 0.4, "rotate"))
|
||||||
-- table.insert(skeletons, loadSkeleton("spineboy.atlas", "spineboy-ess.json", 240, 300, 0.4, "walk"))
|
-- table.insert(skeletons, loadSkeleton("spineboy.atlas", "spineboy-ess.json", 240, 300, 0.4, "walk"))
|
||||||
-- table.insert(skeletons, loadSkeleton("raptor.atlas", "raptor-pro.json", 200, 300, 0.25, "walk"))
|
table.insert(skeletons, loadSkeleton("raptor.atlas", "raptor-pro.json", 200, 300, 0.25, "walk"))
|
||||||
-- table.insert(skeletons, loadSkeleton("goblins.atlas", "goblins-pro.json", 240, 300, 0.8, "walk", "goblin"))
|
-- table.insert(skeletons, loadSkeleton("goblins.atlas", "goblins-pro.json", 240, 300, 0.8, "walk", "goblin"))
|
||||||
-- table.insert(skeletons, loadSkeleton("stretchyman.atlas", "stretchyman-pro.json", 40, 300, 0.5, "sneak"))
|
-- table.insert(skeletons, loadSkeleton("stretchyman.atlas", "stretchyman-pro.json", 40, 300, 0.5, "sneak"))
|
||||||
table.insert(skeletons, loadSkeleton("tank.atlas", "tank-pro.json", 400, 300, 0.2, "drive"))
|
-- table.insert(skeletons, loadSkeleton("tank.atlas", "tank-pro.json", 400, 300, 0.2, "drive"))
|
||||||
-- table.insert(skeletons, loadSkeleton("vine.atlas", "vine-pro.json", 240, 300, 0.3, "grow"))
|
-- table.insert(skeletons, loadSkeleton("vine.atlas", "vine-pro.json", 240, 300, 0.3, "grow"))
|
||||||
|
|
||||||
local triangulator = spine.Triangulator.new()
|
local triangulator = spine.Triangulator.new()
|
||||||
@ -109,6 +115,11 @@ Runtime:addEventListener("enterFrame", function (event)
|
|||||||
local currentTime = event.time / 1000
|
local currentTime = event.time / 1000
|
||||||
local delta = currentTime - lastTime
|
local delta = currentTime - lastTime
|
||||||
lastTime = currentTime
|
lastTime = currentTime
|
||||||
|
|
||||||
|
swirlTime = swirlTime + delta
|
||||||
|
local percent = swirlTime % 2
|
||||||
|
if (percent > 1) then percent = 1 - (percent - 1) end
|
||||||
|
swirl.angle = spine.Interpolation.apply(spine.Interpolation.pow2, -60, 60, percent)
|
||||||
|
|
||||||
skeleton = skeletons[activeSkeleton].skeleton
|
skeleton = skeletons[activeSkeleton].skeleton
|
||||||
skeleton.group.isVisible = true
|
skeleton.group.isVisible = true
|
||||||
|
|||||||
@ -65,6 +65,9 @@ spine.AtlasAttachmentLoader = require "spine-lua.AtlasAttachmentLoader"
|
|||||||
spine.Color = require "spine-lua.Color"
|
spine.Color = require "spine-lua.Color"
|
||||||
spine.Triangulator = require "spine-lua.Triangulator"
|
spine.Triangulator = require "spine-lua.Triangulator"
|
||||||
spine.SkeletonClipping = require "spine-lua.SkeletonClipping"
|
spine.SkeletonClipping = require "spine-lua.SkeletonClipping"
|
||||||
|
spine.JitterEffect = require "spine-lua.vertexeffects.JitterEffect"
|
||||||
|
spine.SwirlEffect = require "spine-lua.vertexeffects.SwirlEffect"
|
||||||
|
spine.Interpolation = require "spine-lua.Interpolation"
|
||||||
|
|
||||||
spine.utils.readFile = function (fileName, base)
|
spine.utils.readFile = function (fileName, base)
|
||||||
if not base then base = system.ResourceDirectory end
|
if not base then base = system.ResourceDirectory end
|
||||||
@ -92,6 +95,14 @@ spine.Skeleton.new = function(skeletonData, group)
|
|||||||
self.batches = 0
|
self.batches = 0
|
||||||
self.tempColor = spine.Color.newWith(1, 1, 1, 1)
|
self.tempColor = spine.Color.newWith(1, 1, 1, 1)
|
||||||
self.tempColor2 = spine.Color.newWith(-1, 1, 1, 1)
|
self.tempColor2 = spine.Color.newWith(-1, 1, 1, 1)
|
||||||
|
self.tempVertex = {
|
||||||
|
x = 0,
|
||||||
|
y = 0,
|
||||||
|
u = 0,
|
||||||
|
v = 0,
|
||||||
|
light = spine.Color.newWith(1, 1, 1, 1),
|
||||||
|
dark = spine.Color.newWith(0, 0, 0, 0)
|
||||||
|
}
|
||||||
self.clipper = spine.SkeletonClipping.new()
|
self.clipper = spine.SkeletonClipping.new()
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
@ -119,6 +130,8 @@ function spine.Skeleton:updateWorldTransform()
|
|||||||
local premultipliedAlpha = self.premultipliedAlpha
|
local premultipliedAlpha = self.premultipliedAlpha
|
||||||
|
|
||||||
self.batches = 0
|
self.batches = 0
|
||||||
|
|
||||||
|
if (self.vertexEffect) then self.vertexEffect:beginEffect(self) end
|
||||||
|
|
||||||
-- Remove old drawing group, we will start anew
|
-- Remove old drawing group, we will start anew
|
||||||
if self.drawingGroup then self.drawingGroup:removeSelf() end
|
if self.drawingGroup then self.drawingGroup:removeSelf() end
|
||||||
@ -217,6 +230,7 @@ function spine.Skeleton:updateWorldTransform()
|
|||||||
end
|
end
|
||||||
|
|
||||||
self.clipper:clipEnd2()
|
self.clipper:clipEnd2()
|
||||||
|
if (self.vertexEffect) then self.vertexEffect:endEffect() end
|
||||||
end
|
end
|
||||||
|
|
||||||
function spine.Skeleton:flush(groupVertices, groupUvs, groupIndices, texture, color, blendMode, drawingGroup)
|
function spine.Skeleton:flush(groupVertices, groupUvs, groupIndices, texture, color, blendMode, drawingGroup)
|
||||||
@ -250,13 +264,31 @@ function spine.Skeleton:batch(vertices, uvs, numVertices, indices, groupVertices
|
|||||||
i = 1
|
i = 1
|
||||||
local vertexStart = #groupVertices + 1
|
local vertexStart = #groupVertices + 1
|
||||||
local vertexEnd = vertexStart + numVertices * 2
|
local vertexEnd = vertexStart + numVertices * 2
|
||||||
while vertexStart < vertexEnd do
|
if (self.vertexEffect) then
|
||||||
groupVertices[vertexStart] = vertices[i]
|
local effect = self.vertexEffect
|
||||||
groupVertices[vertexStart+1] = vertices[i+1]
|
local vertex = self.tempVertex
|
||||||
groupUvs[vertexStart] = uvs[i]
|
while vertexStart < vertexEnd do
|
||||||
groupUvs[vertexStart+1] = uvs[i+1]
|
vertex.x = vertices[i]
|
||||||
vertexStart = vertexStart + 2
|
vertex.y = vertices[i+1]
|
||||||
i = i + 2
|
vertex.u = uvs[i]
|
||||||
|
vertex.v = uvs[i+1]
|
||||||
|
effect:transform(vertex);
|
||||||
|
groupVertices[vertexStart] = vertex.x
|
||||||
|
groupVertices[vertexStart+1] = vertex.y
|
||||||
|
groupUvs[vertexStart] = vertex.u
|
||||||
|
groupUvs[vertexStart+1] = vertex.v
|
||||||
|
vertexStart = vertexStart + 2
|
||||||
|
i = i + 2
|
||||||
|
end
|
||||||
|
else
|
||||||
|
while vertexStart < vertexEnd do
|
||||||
|
groupVertices[vertexStart] = vertices[i]
|
||||||
|
groupVertices[vertexStart+1] = vertices[i+1]
|
||||||
|
groupUvs[vertexStart] = uvs[i]
|
||||||
|
groupUvs[vertexStart+1] = uvs[i+1]
|
||||||
|
vertexStart = vertexStart + 2
|
||||||
|
i = i + 2
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -32,6 +32,8 @@ local spine = require "spine-love.spine"
|
|||||||
|
|
||||||
local skeletons = {}
|
local skeletons = {}
|
||||||
local activeSkeleton = 1
|
local activeSkeleton = 1
|
||||||
|
local swirl = spine.SwirlEffect.new(400)
|
||||||
|
local swirlTime = 0
|
||||||
|
|
||||||
function loadSkeleton (jsonFile, atlasFile, animation, skin, scale, x, y)
|
function loadSkeleton (jsonFile, atlasFile, animation, skin, scale, x, y)
|
||||||
local loader = function (path) return love.graphics.newImage("data/" .. path) end
|
local loader = function (path) return love.graphics.newImage("data/" .. path) end
|
||||||
@ -53,13 +55,19 @@ function loadSkeleton (jsonFile, atlasFile, animation, skin, scale, x, y)
|
|||||||
local stateData = spine.AnimationStateData.new(skeletonData)
|
local stateData = spine.AnimationStateData.new(skeletonData)
|
||||||
local state = spine.AnimationState.new(stateData)
|
local state = spine.AnimationState.new(stateData)
|
||||||
state:setAnimationByName(0, animation, true)
|
state:setAnimationByName(0, animation, true)
|
||||||
if (jsonFile == "spineboy") then
|
if (jsonFile == "spineboy-ess") then
|
||||||
stateData:setMix("walk", "jump", 0.5)
|
stateData:setMix("walk", "jump", 0.5)
|
||||||
stateData:setMix("jump", "run", 0.5)
|
stateData:setMix("jump", "run", 0.5)
|
||||||
state:addAnimationByName(0, "jump", false, 3)
|
state:addAnimationByName(0, "jump", false, 3)
|
||||||
state:addAnimationByName(0, "run", true, 0)
|
state:addAnimationByName(0, "run", true, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if (jsonFile == "raptor-pro") then
|
||||||
|
swirl.centerY = -200
|
||||||
|
skeleton.vertexEffect = swirl
|
||||||
|
-- skeleton.vertexEffect = spine.JitterEffect.new(10, 10)
|
||||||
|
end
|
||||||
|
|
||||||
-- set some event callbacks
|
-- set some event callbacks
|
||||||
state.onStart = function (entry)
|
state.onStart = function (entry)
|
||||||
print(entry.trackIndex.." start: "..entry.animation.name)
|
print(entry.trackIndex.." start: "..entry.animation.name)
|
||||||
@ -88,6 +96,7 @@ end
|
|||||||
|
|
||||||
function love.load(arg)
|
function love.load(arg)
|
||||||
if arg[#arg] == "-debug" then require("mobdebug").start() end
|
if arg[#arg] == "-debug" then require("mobdebug").start() end
|
||||||
|
skeletonRenderer = spine.SkeletonRenderer.new(true)
|
||||||
table.insert(skeletons, loadSkeleton("coin-pro", "coin", "rotate", nil, 0.5, 400, 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("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("raptor-pro", "raptor", "walk", nil, 0.3, 400, 500))
|
||||||
@ -95,7 +104,6 @@ function love.load(arg)
|
|||||||
table.insert(skeletons, loadSkeleton("tank-pro", "tank", "drive", nil, 0.2, 600, 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("vine-pro", "vine", "grow", nil, 0.3, 400, 500))
|
||||||
table.insert(skeletons, loadSkeleton("stretchyman-pro", "stretchyman", "sneak", nil, 0.3, 200, 500))
|
table.insert(skeletons, loadSkeleton("stretchyman-pro", "stretchyman", "sneak", nil, 0.3, 200, 500))
|
||||||
skeletonRenderer = spine.SkeletonRenderer.new(true)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.update (delta)
|
function love.update (delta)
|
||||||
@ -105,12 +113,25 @@ function love.update (delta)
|
|||||||
state:update(delta)
|
state:update(delta)
|
||||||
state:apply(skeleton)
|
state:apply(skeleton)
|
||||||
skeleton:updateWorldTransform()
|
skeleton:updateWorldTransform()
|
||||||
|
|
||||||
|
if (skeleton.vertexEffect) then
|
||||||
|
skeletonRenderer.vertexEffect = skeleton.vertexEffect
|
||||||
|
if (skeleton.vertexEffect == swirl) then
|
||||||
|
swirlTime = swirlTime + delta
|
||||||
|
local percent = swirlTime % 2
|
||||||
|
if (percent > 1) then percent = 1 - (percent - 1) end
|
||||||
|
swirl.angle = spine.Interpolation.apply(spine.Interpolation.pow2, -60, 60, percent)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
skeletonRenderer.vertexEffect = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.draw ()
|
function love.draw ()
|
||||||
love.graphics.setBackgroundColor(128, 128, 128, 255)
|
love.graphics.setBackgroundColor(128, 128, 128, 255)
|
||||||
love.graphics.setColor(255, 255, 255)
|
love.graphics.setColor(255, 255, 255)
|
||||||
local skeleton = skeletons[activeSkeleton].skeleton
|
local skeleton = skeletons[activeSkeleton].skeleton
|
||||||
|
|
||||||
skeletonRenderer:draw(skeleton)
|
skeletonRenderer:draw(skeleton)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -67,6 +67,9 @@ spine.AtlasAttachmentLoader = require "spine-lua.AtlasAttachmentLoader"
|
|||||||
spine.Color = require "spine-lua.Color"
|
spine.Color = require "spine-lua.Color"
|
||||||
spine.Triangulator = require "spine-lua.Triangulator"
|
spine.Triangulator = require "spine-lua.Triangulator"
|
||||||
spine.SkeletonClipping = require "spine-lua.SkeletonClipping"
|
spine.SkeletonClipping = require "spine-lua.SkeletonClipping"
|
||||||
|
spine.JitterEffect = require "spine-lua.vertexeffects.JitterEffect"
|
||||||
|
spine.SwirlEffect = require "spine-lua.vertexeffects.SwirlEffect"
|
||||||
|
spine.Interpolation = require "spine-lua.Interpolation"
|
||||||
|
|
||||||
spine.utils.readFile = function (fileName, base)
|
spine.utils.readFile = function (fileName, base)
|
||||||
local path = fileName
|
local path = fileName
|
||||||
@ -139,7 +142,15 @@ function PolygonBatcher.new(vertexCount, useTwoColorTint)
|
|||||||
vertex = { 0, 0, 0, 0, 0, 0, 0, 0 },
|
vertex = { 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||||
indices = nil,
|
indices = nil,
|
||||||
useTwoColorTint = useTwoColorTint,
|
useTwoColorTint = useTwoColorTint,
|
||||||
twoColorTintShader = twoColorTintShader
|
twoColorTintShader = twoColorTintShader,
|
||||||
|
tempVertex = {
|
||||||
|
x = 0,
|
||||||
|
y = 0,
|
||||||
|
u = 0,
|
||||||
|
v = 0,
|
||||||
|
light = spine.Color.newWith(1, 1, 1, 1),
|
||||||
|
dark = spine.Color.newWith(0, 0, 0, 0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
local indices = {}
|
local indices = {}
|
||||||
@ -163,7 +174,7 @@ function PolygonBatcher:begin ()
|
|||||||
self.drawCalls = 0
|
self.drawCalls = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
function PolygonBatcher:draw (texture, vertices, uvs, numVertices, indices, color, darkColor)
|
function PolygonBatcher:draw (texture, vertices, uvs, numVertices, indices, color, darkColor, vertexEffect)
|
||||||
local numIndices = #indices
|
local numIndices = #indices
|
||||||
local mesh = self.mesh
|
local mesh = self.mesh
|
||||||
|
|
||||||
@ -207,14 +218,44 @@ function PolygonBatcher:draw (texture, vertices, uvs, numVertices, indices, colo
|
|||||||
end
|
end
|
||||||
|
|
||||||
local v = 1
|
local v = 1
|
||||||
while vertexStart < vertexEnd do
|
if (vertexEffect) then
|
||||||
vertex[1] = vertices[v]
|
local tempVertex = self.tempVertex
|
||||||
vertex[2] = vertices[v + 1]
|
while vertexStart < vertexEnd do
|
||||||
vertex[3] = uvs[v]
|
tempVertex.x = vertices[v]
|
||||||
vertex[4] = uvs[v + 1]
|
tempVertex.y = vertices[v + 1]
|
||||||
mesh:setVertex(vertexStart, vertex)
|
tempVertex.u = uvs[v]
|
||||||
vertexStart = vertexStart + 1
|
tempVertex.v = uvs[v + 1]
|
||||||
v = v + 2
|
tempVertex.light:setFrom(color)
|
||||||
|
tempVertex.dark:setFrom(darkColor)
|
||||||
|
vertexEffect:transform(tempVertex)
|
||||||
|
vertex[1] = tempVertex.x
|
||||||
|
vertex[2] = tempVertex.y
|
||||||
|
vertex[3] = tempVertex.u
|
||||||
|
vertex[4] = tempVertex.v
|
||||||
|
vertex[5] = tempVertex.light.r * 255
|
||||||
|
vertex[6] = tempVertex.light.g * 255
|
||||||
|
vertex[7] = tempVertex.light.b * 255
|
||||||
|
vertex[8] = tempVertex.light.a * 255
|
||||||
|
if (self.useTwoColorTint) then
|
||||||
|
vertex[9] = tempVertex.dark.r * 255
|
||||||
|
vertex[10] = tempVertex.dark.g * 255
|
||||||
|
vertex[11] = tempVertex.dark.b * 255
|
||||||
|
vertex[12] = tempVertex.dark.a * 255
|
||||||
|
end
|
||||||
|
mesh:setVertex(vertexStart, vertex)
|
||||||
|
vertexStart = vertexStart + 1
|
||||||
|
v = v + 2
|
||||||
|
end
|
||||||
|
else
|
||||||
|
while vertexStart < vertexEnd do
|
||||||
|
vertex[1] = vertices[v]
|
||||||
|
vertex[2] = vertices[v + 1]
|
||||||
|
vertex[3] = uvs[v]
|
||||||
|
vertex[4] = uvs[v + 1]
|
||||||
|
mesh:setVertex(vertexStart, vertex)
|
||||||
|
vertexStart = vertexStart + 1
|
||||||
|
v = v + 2
|
||||||
|
end
|
||||||
end
|
end
|
||||||
self.verticesLength = self.verticesLength + numVertices
|
self.verticesLength = self.verticesLength + numVertices
|
||||||
end
|
end
|
||||||
@ -255,7 +296,8 @@ function SkeletonRenderer.new (useTwoColorTint)
|
|||||||
batcher = PolygonBatcher.new(3 * 500, useTwoColorTint),
|
batcher = PolygonBatcher.new(3 * 500, useTwoColorTint),
|
||||||
premultipliedAlpha = false,
|
premultipliedAlpha = false,
|
||||||
useTwoColorTint = useTwoColorTint,
|
useTwoColorTint = useTwoColorTint,
|
||||||
clipper = spine.SkeletonClipping.new()
|
clipper = spine.SkeletonClipping.new(),
|
||||||
|
vertexEffect = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
setmetatable(self, SkeletonRenderer)
|
setmetatable(self, SkeletonRenderer)
|
||||||
@ -270,6 +312,8 @@ function SkeletonRenderer:draw (skeleton)
|
|||||||
local batcher = self.batcher
|
local batcher = self.batcher
|
||||||
local premultipliedAlpha = self.premultipliedAlpha
|
local premultipliedAlpha = self.premultipliedAlpha
|
||||||
|
|
||||||
|
if (self.vertexEffect) then self.vertexEffect:beginEffect(skeleton) end
|
||||||
|
|
||||||
local lastLoveBlendMode = love.graphics.getBlendMode()
|
local lastLoveBlendMode = love.graphics.getBlendMode()
|
||||||
love.graphics.setBlendMode("alpha")
|
love.graphics.setBlendMode("alpha")
|
||||||
local lastBlendMode = spine.BlendMode.normal
|
local lastBlendMode = spine.BlendMode.normal
|
||||||
@ -342,7 +386,7 @@ function SkeletonRenderer:draw (skeleton)
|
|||||||
indices = self.clipper.clippedTriangles
|
indices = self.clipper.clippedTriangles
|
||||||
end
|
end
|
||||||
|
|
||||||
batcher:draw(texture, vertices, uvs, numVertices, indices, color, dark)
|
batcher:draw(texture, vertices, uvs, numVertices, indices, color, dark, self.vertexEffect)
|
||||||
end
|
end
|
||||||
|
|
||||||
self.clipper:clipEnd(slot)
|
self.clipper:clipEnd(slot)
|
||||||
@ -352,6 +396,7 @@ function SkeletonRenderer:draw (skeleton)
|
|||||||
batcher:stop()
|
batcher:stop()
|
||||||
love.graphics.setBlendMode(lastLoveBlendMode)
|
love.graphics.setBlendMode(lastLoveBlendMode)
|
||||||
self.clipper:clipEnd2()
|
self.clipper:clipEnd2()
|
||||||
|
if (self.vertexEffect) then self.vertexEffect:endEffect(skeleton) end
|
||||||
end
|
end
|
||||||
|
|
||||||
spine.PolygonBatcher = PolygonBatcher
|
spine.PolygonBatcher = PolygonBatcher
|
||||||
|
|||||||
48
spine-lua/Interpolation.lua
Normal file
48
spine-lua/Interpolation.lua
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
-------------------------------------------------------------------------------
|
||||||
|
-- Spine Runtimes Software License v2.5
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2013-2016, Esoteric Software
|
||||||
|
-- All rights reserved.
|
||||||
|
--
|
||||||
|
-- You are granted a perpetual, non-exclusive, non-sublicensable, and
|
||||||
|
-- non-transferable license to use, install, execute, and perform the Spine
|
||||||
|
-- Runtimes software and derivative works solely for personal or internal
|
||||||
|
-- use. Without the written permission of Esoteric Software (see Section 2 of
|
||||||
|
-- the Spine Software License Agreement), you may not (a) modify, translate,
|
||||||
|
-- adapt, or develop new applications using the Spine Runtimes or otherwise
|
||||||
|
-- create derivative works or improvements of the Spine Runtimes or (b) remove,
|
||||||
|
-- delete, alter, or obscure any trademarks or any copyright, trademark, patent,
|
||||||
|
-- or other intellectual property or proprietary rights notices on or in the
|
||||||
|
-- Software, including any copy thereof. Redistributions in binary or source
|
||||||
|
-- form must include this license and terms.
|
||||||
|
--
|
||||||
|
-- THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
|
||||||
|
-- IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
-- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||||
|
-- EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
-- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
|
||||||
|
-- USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||||
|
-- IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
-- POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
local interpolation = {}
|
||||||
|
|
||||||
|
local math_pow = math.pow
|
||||||
|
|
||||||
|
function interpolation.apply (func, start, _end, a)
|
||||||
|
return start + (_end - start) * func(a)
|
||||||
|
end
|
||||||
|
|
||||||
|
function interpolation.pow2(a)
|
||||||
|
if (a <= 0.5) then return math_pow(a * 2, 2) / 2 end
|
||||||
|
return math_pow((a - 1) * 2, 2) / -2 + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
function interpolation.pow2out(a)
|
||||||
|
return math_pow(a - 1, 2) * -1 + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
return interpolation
|
||||||
@ -30,6 +30,9 @@
|
|||||||
|
|
||||||
local utils = {}
|
local utils = {}
|
||||||
|
|
||||||
|
local math_sqrt = math.sqrt
|
||||||
|
local math_random = math.random
|
||||||
|
|
||||||
utils.degRad = math.pi / 180
|
utils.degRad = math.pi / 180
|
||||||
|
|
||||||
function tablePrint (tt, indent, done)
|
function tablePrint (tt, indent, done)
|
||||||
@ -153,4 +156,15 @@ function utils.mod(a, b)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function utils.randomTriangular(min, max)
|
||||||
|
return utils.randomTriangularWith(min, max, (min + max) * 0.5)
|
||||||
|
end
|
||||||
|
|
||||||
|
function utils.randomTriangularWith(min, max, mode)
|
||||||
|
local u = math.random()
|
||||||
|
local d = max - min
|
||||||
|
if (u <= (mode - min) / d) then return min + math_sqrt(u * d * (mode - min)) end
|
||||||
|
return max - math_sqrt((1 - u) * d * (max - mode))
|
||||||
|
end
|
||||||
|
|
||||||
return utils
|
return utils
|
||||||
|
|||||||
64
spine-lua/vertexeffects/JitterEffect.lua
Normal file
64
spine-lua/vertexeffects/JitterEffect.lua
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
-------------------------------------------------------------------------------
|
||||||
|
-- Spine Runtimes Software License v2.5
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2013-2016, Esoteric Software
|
||||||
|
-- All rights reserved.
|
||||||
|
--
|
||||||
|
-- You are granted a perpetual, non-exclusive, non-sublicensable, and
|
||||||
|
-- non-transferable license to use, install, execute, and perform the Spine
|
||||||
|
-- Runtimes software and derivative works solely for personal or internal
|
||||||
|
-- use. Without the written permission of Esoteric Software (see Section 2 of
|
||||||
|
-- the Spine Software License Agreement), you may not (a) modify, translate,
|
||||||
|
-- adapt, or develop new applications using the Spine Runtimes or otherwise
|
||||||
|
-- create derivative works or improvements of the Spine Runtimes or (b) remove,
|
||||||
|
-- delete, alter, or obscure any trademarks or any copyright, trademark, patent,
|
||||||
|
-- or other intellectual property or proprietary rights notices on or in the
|
||||||
|
-- Software, including any copy thereof. Redistributions in binary or source
|
||||||
|
-- form must include this license and terms.
|
||||||
|
--
|
||||||
|
-- THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
|
||||||
|
-- IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
-- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||||
|
-- EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
-- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
|
||||||
|
-- USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||||
|
-- IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
-- POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
local utils = require "spine-lua.utils"
|
||||||
|
|
||||||
|
local setmetatable = setmetatable
|
||||||
|
local math_min = math.min
|
||||||
|
local math_max = math.max
|
||||||
|
local ipairs = ipairs
|
||||||
|
local table_insert = table.insert
|
||||||
|
local table_remove = table.remove
|
||||||
|
|
||||||
|
local JitterEffect = {}
|
||||||
|
JitterEffect.__index = JitterEffect
|
||||||
|
|
||||||
|
function JitterEffect.new (jitterX, jitterY)
|
||||||
|
local self = {
|
||||||
|
jitterX = jitterX,
|
||||||
|
jitterY = jitterY
|
||||||
|
}
|
||||||
|
setmetatable(self, JitterEffect)
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
function JitterEffect:beginEffect (skeleton)
|
||||||
|
end
|
||||||
|
|
||||||
|
function JitterEffect:transform (vertex)
|
||||||
|
vertex.x = vertex.x + utils.randomTriangular(-self.jitterX, self.jitterY)
|
||||||
|
vertex.y = vertex.y + utils.randomTriangular(-self.jitterX, self.jitterY)
|
||||||
|
end
|
||||||
|
|
||||||
|
function JitterEffect:endEffect ()
|
||||||
|
end
|
||||||
|
|
||||||
|
return JitterEffect
|
||||||
85
spine-lua/vertexeffects/SwirlEffect.lua
Normal file
85
spine-lua/vertexeffects/SwirlEffect.lua
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
-------------------------------------------------------------------------------
|
||||||
|
-- Spine Runtimes Software License v2.5
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2013-2016, Esoteric Software
|
||||||
|
-- All rights reserved.
|
||||||
|
--
|
||||||
|
-- You are granted a perpetual, non-exclusive, non-sublicensable, and
|
||||||
|
-- non-transferable license to use, install, execute, and perform the Spine
|
||||||
|
-- Runtimes software and derivative works solely for personal or internal
|
||||||
|
-- use. Without the written permission of Esoteric Software (see Section 2 of
|
||||||
|
-- the Spine Software License Agreement), you may not (a) modify, translate,
|
||||||
|
-- adapt, or develop new applications using the Spine Runtimes or otherwise
|
||||||
|
-- create derivative works or improvements of the Spine Runtimes or (b) remove,
|
||||||
|
-- delete, alter, or obscure any trademarks or any copyright, trademark, patent,
|
||||||
|
-- or other intellectual property or proprietary rights notices on or in the
|
||||||
|
-- Software, including any copy thereof. Redistributions in binary or source
|
||||||
|
-- form must include this license and terms.
|
||||||
|
--
|
||||||
|
-- THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
|
||||||
|
-- IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
-- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||||
|
-- EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
-- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
|
||||||
|
-- USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||||
|
-- IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
-- POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
local utils = require "spine-lua.utils"
|
||||||
|
local interpolation = require "spine-lua.Interpolation"
|
||||||
|
|
||||||
|
local setmetatable = setmetatable
|
||||||
|
local math_min = math.min
|
||||||
|
local math_max = math.max
|
||||||
|
local ipairs = ipairs
|
||||||
|
local table_insert = table.insert
|
||||||
|
local table_remove = table.remove
|
||||||
|
local utils_deg_rad = utils.degRad
|
||||||
|
local math_sqrt = math.sqrt
|
||||||
|
local math_sin = math.sin
|
||||||
|
local math_cos = math.cos
|
||||||
|
|
||||||
|
local SwirlEffect = {}
|
||||||
|
SwirlEffect.__index = SwirlEffect
|
||||||
|
|
||||||
|
function SwirlEffect.new (radius)
|
||||||
|
local self = {
|
||||||
|
worldX = 0,
|
||||||
|
worldY = 0,
|
||||||
|
centerX = 0,
|
||||||
|
centerY = 0,
|
||||||
|
radius = radius,
|
||||||
|
angle = 0,
|
||||||
|
interpolation = interpolation.pow2
|
||||||
|
}
|
||||||
|
setmetatable(self, SwirlEffect)
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
function SwirlEffect:beginEffect (skeleton)
|
||||||
|
self.worldX = skeleton.x + self.centerX
|
||||||
|
self.worldY = skeleton.y + self.centerY
|
||||||
|
self.angleRad = self.angle * utils_deg_rad
|
||||||
|
end
|
||||||
|
|
||||||
|
function SwirlEffect:transform (vertex)
|
||||||
|
local x = vertex.x - self.worldX
|
||||||
|
local y = vertex.y - self.worldY
|
||||||
|
local dist = math_sqrt(x * x + y * y)
|
||||||
|
if (dist < self.radius) then
|
||||||
|
local theta = interpolation.apply(self.interpolation, 0, self.angleRad, (self.radius - dist) / self.radius)
|
||||||
|
local cos = math_cos(theta)
|
||||||
|
local sin = math_sin(theta)
|
||||||
|
vertex.x = cos * x - sin * y + self.worldX
|
||||||
|
vertex.y = sin * x + cos * y + self.worldY
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function SwirlEffect:endEffect ()
|
||||||
|
end
|
||||||
|
|
||||||
|
return SwirlEffect
|
||||||
Loading…
x
Reference in New Issue
Block a user