DaVikingCode / Citrus-Engine

Modern AS3 Game Engine
http://citrusengine.com/
Other
549 stars 231 forks source link

convexDecomposition failes from Tiled #243

Closed jaunusa closed 9 years ago

jaunusa commented 9 years ago

I don't know if your are still working on this engine, I have found a small misbehavior in the createShape() method in NapePhysicsObject when you parse a polyline from a tiled file. You use Vec2.weak() to push the vertices, so they can only be passed once to a nape method. If the ValidationResult is CONCAVE, the vertices are already disposed and the convexDecomposition() method returns an empty GeomPolyList.

Fix suggenstion:

var geomPoly:GeomPoly = new GeomPoly(verts);
var polygon:Polygon = new Polygon(geomPoly, _material);
var validation:ValidationResult = polygon.validity();

if (validation == ValidationResult.VALID)
    _shape = polygon;

else if (validation == ValidationResult.CONCAVE) {

    var convex:GeomPolyList = geomPoly.convexDecomposition();
    convex.foreach(function(p:GeomPoly):void {
        _body.shapes.add(new Polygon(p));
    });

    return;

} else
    throw new Error("Invalid polygon/polyline");
alamboley commented 9 years ago

Hey, thanks for the bug fix !