diff --git a/core/core_bind.cpp b/core/core_bind.cpp index 2149ee45121..a164221fc23 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -709,6 +709,17 @@ Vector Geometry2D::convex_hull(const Vector &p_points) { return ::Geometry2D::convex_hull(p_points); } +TypedArray Geometry2D::decompose_polygon_in_convex(const Vector &p_polygon) { + Vector> decomp = ::Geometry2D::decompose_polygon_in_convex(p_polygon); + + TypedArray ret; + + for (int i = 0; i < decomp.size(); ++i) { + ret.push_back(decomp[i]); + } + return ret; +} + TypedArray Geometry2D::merge_polygons(const Vector &p_polygon_a, const Vector &p_polygon_b) { Vector> polys = ::Geometry2D::merge_polygons(p_polygon_a, p_polygon_b); @@ -840,6 +851,7 @@ void Geometry2D::_bind_methods() { ClassDB::bind_method(D_METHOD("triangulate_polygon", "polygon"), &Geometry2D::triangulate_polygon); ClassDB::bind_method(D_METHOD("triangulate_delaunay", "points"), &Geometry2D::triangulate_delaunay); ClassDB::bind_method(D_METHOD("convex_hull", "points"), &Geometry2D::convex_hull); + ClassDB::bind_method(D_METHOD("decompose_polygon_in_convex", "polygon"), &Geometry2D::decompose_polygon_in_convex); ClassDB::bind_method(D_METHOD("merge_polygons", "polygon_a", "polygon_b"), &Geometry2D::merge_polygons); ClassDB::bind_method(D_METHOD("clip_polygons", "polygon_a", "polygon_b"), &Geometry2D::clip_polygons); diff --git a/core/core_bind.h b/core/core_bind.h index 345c517b995..3ca2da0acf6 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -289,6 +289,7 @@ public: Vector triangulate_polygon(const Vector &p_polygon); Vector triangulate_delaunay(const Vector &p_points); Vector convex_hull(const Vector &p_points); + TypedArray decompose_polygon_in_convex(const Vector &p_polygon); enum PolyBooleanOperation { OPERATION_UNION, diff --git a/doc/classes/Geometry2D.xml b/doc/classes/Geometry2D.xml index e613ab1a557..0142018f1a5 100644 --- a/doc/classes/Geometry2D.xml +++ b/doc/classes/Geometry2D.xml @@ -33,6 +33,13 @@ Given an array of [Vector2]s, returns the convex hull as a list of points in counterclockwise order. The last point is the same as the first one. + + + + + Decomposes the [param polygon] into multiple convex hulls and returns an array of [PackedVector2Array]. + +