diff options
author | Mariano Suligoy <marianognu.easyrpg@gmail.com> | 2019-03-03 23:05:43 -0300 |
---|---|---|
committer | Mariano Suligoy <marianognu.easyrpg@gmail.com> | 2019-03-04 21:03:10 -0300 |
commit | 078b869d9a93b7cdfe89461b713de8c123b96d7c (patch) | |
tree | 7f81719c3017220d5ec56eb9e30846eccf2c38d6 /scene/2d/collision_polygon_2d.cpp | |
parent | 3aff78f53242df3a5541747e818ce4ac68219a16 (diff) | |
download | redot-engine-078b869d9a93b7cdfe89461b713de8c123b96d7c.tar.gz |
TileSet/TileMap: Decompose solid non-convex polygons into convexes. Real fix for #24003
Diffstat (limited to 'scene/2d/collision_polygon_2d.cpp')
-rw-r--r-- | scene/2d/collision_polygon_2d.cpp | 35 |
1 files changed, 1 insertions, 34 deletions
diff --git a/scene/2d/collision_polygon_2d.cpp b/scene/2d/collision_polygon_2d.cpp index 5edd49b3a3..ef7644fcab 100644 --- a/scene/2d/collision_polygon_2d.cpp +++ b/scene/2d/collision_polygon_2d.cpp @@ -78,40 +78,7 @@ void CollisionPolygon2D::_build_polygon() { } Vector<Vector<Vector2> > CollisionPolygon2D::_decompose_in_convex() { - - Vector<Vector<Vector2> > decomp; - List<TriangulatorPoly> in_poly, out_poly; - - TriangulatorPoly inp; - inp.Init(polygon.size()); - for (int i = 0; i < polygon.size(); i++) { - inp.GetPoint(i) = polygon[i]; - } - inp.SetOrientation(TRIANGULATOR_CCW); - in_poly.push_back(inp); - TriangulatorPartition tpart; - if (tpart.ConvexPartition_HM(&in_poly, &out_poly) == 0) { //failed! - ERR_PRINT("Convex decomposing failed!"); - return decomp; - } - - decomp.resize(out_poly.size()); - int idx = 0; - - for (List<TriangulatorPoly>::Element *I = out_poly.front(); I; I = I->next()) { - - TriangulatorPoly &tp = I->get(); - - decomp.write[idx].resize(tp.GetNumPoints()); - - for (int i = 0; i < tp.GetNumPoints(); i++) { - - decomp.write[idx].write[i] = tp.GetPoint(i); - } - - idx++; - } - + Vector<Vector<Vector2> > decomp = Geometry::decompose_polygon_in_convex(polygon); return decomp; } |