summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-08-16 09:11:53 +0200
committerRémi Verschelde <rverschelde@gmail.com>2023-08-16 09:11:53 +0200
commit20127ab6931787fda57ceb13a6eebae63a849462 (patch)
tree50d65d26d0021069a901059cc85275e8ceca9ba0
parentb44867b9477a297e5385bd3bb2ab51894728aabf (diff)
parent541b021ab67356119abbd50af31aee81caf9c792 (diff)
downloadredot-engine-20127ab6931787fda57ceb13a6eebae63a849462.tar.gz
Merge pull request #78871 from jitspoe/master.pr_compute_convex_mesh_points
Expose `compute_convex_mesh_points` function to GDScript
-rw-r--r--core/core_bind.cpp12
-rw-r--r--core/core_bind.h1
-rw-r--r--doc/classes/Geometry3D.xml7
3 files changed, 20 insertions, 0 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp
index 4e220d0839..05fe393a2f 100644
--- a/core/core_bind.cpp
+++ b/core/core_bind.cpp
@@ -929,6 +929,17 @@ Geometry3D *Geometry3D::get_singleton() {
return singleton;
}
+Vector<Vector3> Geometry3D::compute_convex_mesh_points(const TypedArray<Plane> &p_planes) {
+ Vector<Plane> planes_vec;
+ int size = p_planes.size();
+ planes_vec.resize(size);
+ for (int i = 0; i < size; ++i) {
+ planes_vec.set(i, p_planes[i]);
+ }
+ Variant ret = ::Geometry3D::compute_convex_mesh_points(planes_vec.ptr(), size);
+ return ret;
+}
+
TypedArray<Plane> Geometry3D::build_box_planes(const Vector3 &p_extents) {
Variant ret = ::Geometry3D::build_box_planes(p_extents);
return ret;
@@ -1029,6 +1040,7 @@ Vector<Vector3> Geometry3D::clip_polygon(const Vector<Vector3> &p_points, const
}
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);
ClassDB::bind_method(D_METHOD("build_cylinder_planes", "radius", "height", "sides", "axis"), &Geometry3D::build_cylinder_planes, DEFVAL(Vector3::AXIS_Z));
ClassDB::bind_method(D_METHOD("build_capsule_planes", "radius", "height", "sides", "lats", "axis"), &Geometry3D::build_capsule_planes, DEFVAL(Vector3::AXIS_Z));
diff --git a/core/core_bind.h b/core/core_bind.h
index 1cbbcdd251..5f51b64eb7 100644
--- a/core/core_bind.h
+++ b/core/core_bind.h
@@ -320,6 +320,7 @@ protected:
public:
static Geometry3D *get_singleton();
+ Vector<Vector3> compute_convex_mesh_points(const TypedArray<Plane> &p_planes);
TypedArray<Plane> build_box_planes(const Vector3 &p_extents);
TypedArray<Plane> build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis = Vector3::AXIS_Z);
TypedArray<Plane> build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis = Vector3::AXIS_Z);
diff --git a/doc/classes/Geometry3D.xml b/doc/classes/Geometry3D.xml
index 85b8965faf..a85d17d925 100644
--- a/doc/classes/Geometry3D.xml
+++ b/doc/classes/Geometry3D.xml
@@ -45,6 +45,13 @@
Clips the polygon defined by the points in [param points] against the [param plane] and returns the points of the clipped polygon.
</description>
</method>
+ <method name="compute_convex_mesh_points">
+ <return type="PackedVector3Array" />
+ <param index="0" name="planes" type="Plane[]" />
+ <description>
+ Calculates and returns all the vertex points of a convex shape defined by an array of [param planes].
+ </description>
+ </method>
<method name="get_closest_point_to_segment">
<return type="Vector3" />
<param index="0" name="point" type="Vector3" />