1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-22 15:06:45 +00:00

Merge pull request #83353 from Chubercik/expose_delaunay_3d

Expose 3D Delaunay tetrahedralization in `Geometry3D`
This commit is contained in:
Rémi Verschelde
2024-01-04 16:39:23 +01:00
4 changed files with 29 additions and 0 deletions

View File

@@ -1040,6 +1040,10 @@ Vector<Vector3> Geometry3D::clip_polygon(const Vector<Vector3> &p_points, const
return ::Geometry3D::clip_polygon(p_points, p_plane);
}
Vector<int32_t> Geometry3D::tetrahedralize_delaunay(const Vector<Vector3> &p_points) {
return ::Geometry3D::tetrahedralize_delaunay(p_points);
}
void Geometry3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("compute_convex_mesh_points", "planes"), &Geometry3D::compute_convex_mesh_points);
ClassDB::bind_method(D_METHOD("build_box_planes", "extents"), &Geometry3D::build_box_planes);
@@ -1061,6 +1065,7 @@ void Geometry3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("segment_intersects_convex", "from", "to", "planes"), &Geometry3D::segment_intersects_convex);
ClassDB::bind_method(D_METHOD("clip_polygon", "points", "plane"), &Geometry3D::clip_polygon);
ClassDB::bind_method(D_METHOD("tetrahedralize_delaunay", "points"), &Geometry3D::tetrahedralize_delaunay);
}
////// Marshalls //////

View File

@@ -337,6 +337,7 @@ public:
Vector<Vector3> segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const TypedArray<Plane> &p_planes);
Vector<Vector3> clip_polygon(const Vector<Vector3> &p_points, const Plane &p_plane);
Vector<int32_t> tetrahedralize_delaunay(const Vector<Vector3> &p_points);
Geometry3D() { singleton = this; }
};

View File

@@ -31,6 +31,7 @@
#ifndef GEOMETRY_3D_H
#define GEOMETRY_3D_H
#include "core/math/delaunay_3d.h"
#include "core/math/face3.h"
#include "core/object/object.h"
#include "core/templates/local_vector.h"
@@ -532,6 +533,21 @@ public:
return clipped;
}
static Vector<int32_t> tetrahedralize_delaunay(const Vector<Vector3> &p_points) {
Vector<Delaunay3D::OutputSimplex> tetr = Delaunay3D::tetrahedralize(p_points);
Vector<int32_t> tetrahedrons;
tetrahedrons.resize(4 * tetr.size());
int32_t *ptr = tetrahedrons.ptrw();
for (int i = 0; i < tetr.size(); i++) {
*ptr++ = tetr[i].points[0];
*ptr++ = tetr[i].points[1];
*ptr++ = tetr[i].points[2];
*ptr++ = tetr[i].points[3];
}
return tetrahedrons;
}
// Create a "wrap" that encloses the given geometry.
static Vector<Face3> wrap_geometry(Vector<Face3> p_array, real_t *p_error = nullptr);