Implemented NN Search on Rtree

Just binded the library to Godot so we can use later to have more
options on how to create holes.
This commit is contained in:
2025-11-23 18:36:41 -05:00
parent c208d069bb
commit 703285f555
6 changed files with 21 additions and 3 deletions

Binary file not shown.

View File

@@ -102,7 +102,6 @@ func _draw():
var meshGenerator = GeoPolyMesh.new(vector_indexes, vectors, extrusion_direction, depth) var meshGenerator = GeoPolyMesh.new(vector_indexes, vectors, extrusion_direction, depth)
var commited_mesh = meshGenerator.commit_mesh(meshInstance3d.get_active_material(0)) var commited_mesh = meshGenerator.commit_mesh(meshInstance3d.get_active_material(0))
meshGenerator.free() meshGenerator.free()
meshInstance3d.mesh = commited_mesh meshInstance3d.mesh = commited_mesh
meshInstance3d.position += depth_position_offset meshInstance3d.position += depth_position_offset
@@ -111,10 +110,11 @@ func _draw():
func _re_draw(): func _re_draw():
var vector_indexes = GeoPolyTriangulization.triangulate(outer_polygon, inner_polygons.get_holes()) var vector_indexes = GeoPolyTriangulization.triangulate(outer_polygon, inner_polygons.get_holes())
var vectors = []
var vectors = []
vectors.append_array(outer_polygon) vectors.append_array(outer_polygon)
vectors.append_array(inner_polygons.get_hole_verticies()) vectors.append_array(inner_polygons.get_hole_verticies())
WorkerThreadPool.add_task(_generate_mesh.bind(vector_indexes, vectors)) WorkerThreadPool.add_task(_generate_mesh.bind(vector_indexes, vectors))
func _deffered_draw(mesh: Mesh, task_id: int): func _deffered_draw(mesh: Mesh, task_id: int):

View File

@@ -2,7 +2,7 @@
#include "godot_cpp/core/class_db.hpp" #include "godot_cpp/core/class_db.hpp"
#include "godot_cpp/variant/packed_int32_array.hpp" #include "godot_cpp/variant/packed_int32_array.hpp"
#include "godot_cpp/variant/packed_vector2_array.hpp" #include "godot_cpp/variant/packed_vector2_array.hpp"
#include "godot_cpp/variant/typed_array.hpp" #include "godot_cpp/variant/vector2.hpp"
RectangleTree::RectangleTree() {} RectangleTree::RectangleTree() {}
@@ -14,6 +14,8 @@ void RectangleTree::_bind_methods() {
&RectangleTree::remove); &RectangleTree::remove);
ClassDB::bind_method(godot::D_METHOD("query", "point"), ClassDB::bind_method(godot::D_METHOD("query", "point"),
&RectangleTree::query); &RectangleTree::query);
ClassDB::bind_method(godot::D_METHOD("nearest", "point", "number"),
&RectangleTree::nearest);
} }
void RectangleTree::add(const Vector2 &min_bound, const Vector2 &max_bound, void RectangleTree::add(const Vector2 &min_bound, const Vector2 &max_bound,
@@ -41,3 +43,18 @@ PackedInt32Array RectangleTree::query(const Vector2 &point) {
return return_value; return return_value;
} }
PackedInt32Array RectangleTree::nearest(const Vector2 &point,
const int &number) {
Rect rect = Rect(point.x, point.y, point.x, point.y);
PackedInt32Array return_value;
auto callbackLambda = [&return_value, &number](int index, float) {
return_value.push_back(index);
return return_value.size() < number;
};
tree.NNSearch(rect.min, rect.max, callbackLambda);
return return_value;
}

View File

@@ -50,4 +50,5 @@ public:
const int &polgon_index); const int &polgon_index);
void remove(const int &polygon_index); void remove(const int &polygon_index);
PackedInt32Array query(const Vector2 &point); PackedInt32Array query(const Vector2 &point);
PackedInt32Array nearest(const Vector2 &point, const int &number);
}; };

Binary file not shown.