From 541b021ab67356119abbd50af31aee81caf9c792 Mon Sep 17 00:00:00 2001 From: jitspoe Date: Fri, 30 Jun 2023 07:25:03 -0400 Subject: [PATCH] Expose compute_convex_mesh_points function to GDScript. --- core/core_bind.cpp | 12 ++++++++++++ core/core_bind.h | 1 + doc/classes/Geometry3D.xml | 7 +++++++ 3 files changed, 20 insertions(+) diff --git a/core/core_bind.cpp b/core/core_bind.cpp index 2d0d24406c9..ac7f69f8503 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -919,6 +919,17 @@ Geometry3D *Geometry3D::get_singleton() { return singleton; } +Vector Geometry3D::compute_convex_mesh_points(const TypedArray &p_planes) { + Vector 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 Geometry3D::build_box_planes(const Vector3 &p_extents) { Variant ret = ::Geometry3D::build_box_planes(p_extents); return ret; @@ -1014,6 +1025,7 @@ Vector Geometry3D::clip_polygon(const Vector &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 6b25510b143..db0e3578a6e 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -318,6 +318,7 @@ protected: public: static Geometry3D *get_singleton(); + Vector compute_convex_mesh_points(const TypedArray &p_planes); TypedArray build_box_planes(const Vector3 &p_extents); TypedArray build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis = Vector3::AXIS_Z); TypedArray 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 2f068b9fa58..39e1459fd80 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. + + + + + Calculates and returns all the vertex points of a convex shape defined by an array of [param planes]. + +