Expose 2D Delaunay triangulation in Geometry singleton
Can be used via scripting as `Geometry.triangulate_delaunay_2d(points)` The interface is the same as in `Triangulate` library, returning indices into triangulated points.
This commit is contained in:
@ -31,6 +31,7 @@
|
||||
#ifndef GEOMETRY_H
|
||||
#define GEOMETRY_H
|
||||
|
||||
#include "core/math/delaunay.h"
|
||||
#include "core/math/face3.h"
|
||||
#include "core/math/rect2.h"
|
||||
#include "core/math/triangulate.h"
|
||||
@ -857,6 +858,19 @@ public:
|
||||
return points;
|
||||
}
|
||||
|
||||
static Vector<int> triangulate_delaunay_2d(const Vector<Vector2> &p_points) {
|
||||
|
||||
Vector<Delaunay2D::Triangle> tr = Delaunay2D::triangulate(p_points);
|
||||
Vector<int> triangles;
|
||||
|
||||
for (int i = 0; i < tr.size(); i++) {
|
||||
triangles.push_back(tr[i].points[0]);
|
||||
triangles.push_back(tr[i].points[1]);
|
||||
triangles.push_back(tr[i].points[2]);
|
||||
}
|
||||
return triangles;
|
||||
}
|
||||
|
||||
static Vector<int> triangulate_polygon(const Vector<Vector2> &p_polygon) {
|
||||
|
||||
Vector<int> triangles;
|
||||
|
||||
Reference in New Issue
Block a user