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:
BIN
.sconsign.dblite
BIN
.sconsign.dblite
Binary file not shown.
@@ -103,7 +103,6 @@ func _draw():
|
|||||||
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
|
||||||
meshInstance3d.create_trimesh_collision()
|
meshInstance3d.create_trimesh_collision()
|
||||||
@@ -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):
|
||||||
|
|||||||
Binary file not shown.
@@ -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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -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.
Reference in New Issue
Block a user