- 수정됨
spine-love generating inverted bounding boxes?
Hi,
Can you tell me if I'm doing something wrong or if it's a bug in the spine-love runtime? The bounding box vertices seem to have inverted y coordinates.
package.path = package.path .. ";../spine-runtimes/spine-love/?.lua;../spine-runtimes/?.lua"
Spine = require('spine-love.spine')
function love.load()
local json = Spine.SkeletonJson.new()
local skeletonData = json:readSkeletonDataFile("skeleton.json")
skeleton = Spine.Skeleton.new(skeletonData)
skeleton.x = 400
skeleton.y = 300
skeleton:updateWorldTransform()
bounds = Spine.SkeletonBounds.new()
bounds:update(skeleton, false)
end
function love.update(dt)
skeleton:update(dt)
x, y = love.mouse.getPosition()
end
function love.draw()
love.graphics.setColor(255, 255, 255)
love.graphics.print(string.format('(%f, %f)', x, y), 20, 20)
love.graphics.setColor(0, 255, 0)
local p1 = bounds:getPolygon(skeleton:getAttachment('p1', 'p1'))
print('p1', unpack(p1))
love.graphics.polygon('line', p1)
local p2 = bounds:getPolygon(skeleton:getAttachment('p2', 'p2'))
print('p2', unpack(p2))
love.graphics.polygon('line', p2)
love.graphics.setColor(255, 0, 0)
love.graphics.point(400, 300)
end
I've attached a zip of the spine project and love code. I'm running spine-runtimes from master (059cc6), love 0.9.1 on OS X 10.9.4.
EDIT:
I created a hacky workaround, but there must be a better way:
Thank you for the nicely detailed post, I'm not a programmer so I can't help you out with it, but I've marked it as high priority and let Nate know about it.
Sorry for the problem you are having with it, it does look like something is off there!
The Spine runtimes use a y-up coordinate system. When toolkits use a y-down coordinate system, as LÖVE does, it's best to flip the sign of the y coordinate in the toolkit specific code. If this is not possible or something in the runtime needs to know if y-up or y-down is in use, then normally this is set on Bone, eg:
https://github.com/EsotericSoftware/spi ... one.cs#L35
Used here:
https://github.com/EsotericSoftware/spi ... one.cs#L85
spine-lua doesn't actually have a Bone.yDown
field, instead spine-corona and spine-love flip the coordinates in toolkit specific code. Because of that, when BoundingBoxAttachment
transforms the polygon vertices, they use the y-up transform of the bone and don't match the toolkit. So the right fix is to add Bone.yDown
, set it to true in spine-corona and spine-love, and have Bone
respect it when flipping the y coordinate. Then the bounding boxes will be transformed correctly. Unfortunately I don't have time at the moment to do this and properly test it, but I will do it when I can.
Thanks for pointing me in the right direction. I submitted a pull request adding the yDown parameter and fixing the LÖVE and Corona runtimes:
https://github.com/EsotericSoftware/spi ... s/pull/269
I tested it out on both and it looks good, and fixes my bounding box bug as well, but please let me know if I missed something.
Thanks, I don't know when Nate will be able to look at the pull requests, but I'll let him know about it