bendmorris / spinehaxe

Spine runtime for Haxe 3. Based on current AS3/libgdx runtimes.
Other
64 stars 28 forks source link

SkeletonBounds.hx : polygon duplicate vertices #19

Closed jhice closed 9 years ago

jhice commented 9 years ago

Hi,

I ran into an issue I could not understand but I tried to debug. Some of the polygons has vertices duplicated at the end of the polygon (the bounding boxes are always ok in the json and in the code). At some place I cant find, vertices were added.

As I cant find why, I looked in the libgdx code and the AS3 code, in the place I think it occurs. In those libs, in SkeletonBounds exists this code, just before computing world vertices for the polygon :

libgdx int vertexCount = boundingBox.getVertices().length; polygon.ensureCapacity(vertexCount); polygon.size = vertexCount;

AS3 polygon.vertices.length = boundingBox.vertices.length;

Perhaps there is a reason why this code is here and it seems to go in my direction. So I inserted this code at line 80 of SkeletonBounds.hx :

polygon.vertices.splice(boundingBox.vertices.length, polygon.vertices.length - boundingBox.vertices.length); // Truncate added vertices

It solves the problem, I can now draw the polygons as in Spine or SkeletonViewer :)

It was quite hard for me to dive into this so perhaps I've been mistaken somewhere, I don't know. I want to do polygon collision between two FlxSpine objects and wanted to be sure the polygons were right. From this point I want to loop over the polygons (after done aabb checks for better speed), I'm not sure how to use the built-in methods from SkeletonBounds to achieve this. Can you show me the path ? Thanks.

PS : If needed, I can give you the .json file that has vertices added once used in the runtime and show you where it happens.

bendmorris commented 9 years ago

Thanks, good catch. You solution looks good - do you want to open a pull request?

jhice commented 9 years ago

Never done this but interested in, so I look how to do this. It will be easier if I have other modifications later (we never know!).