mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-13 02:28:44 +08:00
[lua] Clipping fix, see #1219
This commit is contained in:
parent
54bb7b7e5f
commit
183973cfd6
@ -66,9 +66,9 @@ function loadSkeleton(atlasFile, jsonFile, x, y, scale, animation, skin)
|
||||
if atlasFile == "spineboy.atlas" then
|
||||
animationStateData:setMix("walk", "jump", 0.4)
|
||||
animationStateData:setMix("jump", "run", 0.4);
|
||||
animationState:setAnimationByName(0, "portal", true)
|
||||
-- local jumpEntry = animationState:addAnimationByName(0, "jump", false, 3)
|
||||
-- animationState:addAnimationByName(0, "run", true, 0)
|
||||
animationState:setAnimationByName(0, "walk", true)
|
||||
local jumpEntry = animationState:addAnimationByName(0, "jump", false, 3)
|
||||
animationState:addAnimationByName(0, "run", true, 0)
|
||||
elseif atlasFile == "raptor.atlas" then
|
||||
--skeleton.vertexEffect = spine.JitterEffect.new(5, 5)
|
||||
skeleton.vertexEffect = swirl
|
||||
@ -81,7 +81,7 @@ function loadSkeleton(atlasFile, jsonFile, x, y, scale, animation, skin)
|
||||
return { skeleton = skeleton, state = animationState }
|
||||
end
|
||||
|
||||
table.insert(skeletons, loadSkeleton("spineboy.atlas", "spineboy-pro.json", 240, 300, 0.4, "portal"))
|
||||
table.insert(skeletons, loadSkeleton("spineboy.atlas", "spineboy-pro.json", 240, 300, 0.4, "walk"))
|
||||
table.insert(skeletons, loadSkeleton("stretchyman.atlas", "stretchyman-stretchy-ik-pro.json", 40, 300, 0.5, "sneak"))
|
||||
table.insert(skeletons, loadSkeleton("coin.atlas", "coin-pro.json", 240, 160, 0.4, "animation"))
|
||||
table.insert(skeletons, loadSkeleton("raptor.atlas", "raptor-pro.json", 200, 300, 0.25, "walk"))
|
||||
|
||||
@ -34,6 +34,7 @@ local Triangulator = require "spine-lua.Triangulator"
|
||||
local setmetatable = setmetatable
|
||||
local math_min = math.min
|
||||
local math_max = math.max
|
||||
local math_abs = math.abs
|
||||
local ipairs = ipairs
|
||||
local table_insert = table.insert
|
||||
local table_remove = table.remove
|
||||
@ -256,16 +257,28 @@ function SkeletonClipping:clip(x1, y1, x2, y2, x3, y3, clippingArea, output)
|
||||
-- v1 inside, v2 outside
|
||||
local c0 = inputY2 - inputY
|
||||
local c2 = inputX2 - inputX
|
||||
local ua = (c2 * (edgeY - inputY) - c0 * (edgeX - inputX)) / (c0 * (edgeX2 - edgeX) - c2 * (edgeY2 - edgeY))
|
||||
table_insert(output, edgeX + (edgeX2 - edgeX) * ua)
|
||||
table_insert(output, edgeY + (edgeY2 - edgeY) * ua)
|
||||
local s = c0 * (edgeX2 - edgeX) - c2 * (edgeY2 - edgeY)
|
||||
if math_abs(s) > 0.000001 then
|
||||
local ua = (c2 * (edgeY - inputY) - c0 * (edgeX - inputX)) / s
|
||||
table_insert(output, edgeX + (edgeX2 - edgeX) * ua)
|
||||
table_insert(output, edgeY + (edgeY2 - edgeY) * ua)
|
||||
else
|
||||
table_insert(output, edgeX)
|
||||
table_insert(output, edgeY)
|
||||
end
|
||||
end
|
||||
elseif side2 then -- v1 outside, v2 inside
|
||||
local c0 = inputY2 - inputY
|
||||
local c2 = inputX2 - inputX
|
||||
local ua = (c2 * (edgeY - inputY) - c0 * (edgeX - inputX)) / (c0 * (edgeX2 - edgeX) - c2 * (edgeY2 - edgeY))
|
||||
table_insert(output, edgeX + (edgeX2 - edgeX) * ua)
|
||||
table_insert(output, edgeY + (edgeY2 - edgeY) * ua)
|
||||
local s = c0 * (edgeX2 - edgeX) - c2 * (edgeY2 - edgeY)
|
||||
if math_abs(s) > 0.000001 then
|
||||
local ua = (c2 * (edgeY - inputY) - c0 * (edgeX - inputX)) / s
|
||||
table_insert(output, edgeX + (edgeX2 - edgeX) * ua)
|
||||
table_insert(output, edgeY + (edgeY2 - edgeY) * ua)
|
||||
else
|
||||
table_insert(output, edgeX)
|
||||
table_insert(output, edgeY)
|
||||
end
|
||||
table_insert(output, inputX2)
|
||||
table_insert(output, inputY2)
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user