|
@@ -35,10 +35,11 @@
|
|
|
#endif // DEBUG_ENABLED
|
|
|
|
|
|
void NavigationMesh::create_from_mesh(const Ref<Mesh> &p_mesh) {
|
|
|
+ RWLockWrite write_lock(rwlock);
|
|
|
ERR_FAIL_COND(p_mesh.is_null());
|
|
|
|
|
|
vertices = Vector<Vector3>();
|
|
|
- clear_polygons();
|
|
|
+ polygons.clear();
|
|
|
|
|
|
for (int i = 0; i < p_mesh->get_surface_count(); i++) {
|
|
|
if (p_mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) {
|
|
@@ -61,13 +62,12 @@ void NavigationMesh::create_from_mesh(const Ref<Mesh> &p_mesh) {
|
|
|
const int *r = iarr.ptr();
|
|
|
|
|
|
for (int j = 0; j < rlen; j += 3) {
|
|
|
- Vector<int> vi;
|
|
|
- vi.resize(3);
|
|
|
- vi.write[0] = r[j + 0] + from;
|
|
|
- vi.write[1] = r[j + 1] + from;
|
|
|
- vi.write[2] = r[j + 2] + from;
|
|
|
-
|
|
|
- add_polygon(vi);
|
|
|
+ Polygon polygon;
|
|
|
+ polygon.indices.resize(3);
|
|
|
+ polygon.indices.write[0] = r[j + 0] + from;
|
|
|
+ polygon.indices.write[1] = r[j + 1] + from;
|
|
|
+ polygon.indices.write[2] = r[j + 2] + from;
|
|
|
+ polygons.push_back(polygon);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -304,15 +304,18 @@ Vector3 NavigationMesh::get_filter_baking_aabb_offset() const {
|
|
|
}
|
|
|
|
|
|
void NavigationMesh::set_vertices(const Vector<Vector3> &p_vertices) {
|
|
|
+ RWLockWrite write_lock(rwlock);
|
|
|
vertices = p_vertices;
|
|
|
notify_property_list_changed();
|
|
|
}
|
|
|
|
|
|
Vector<Vector3> NavigationMesh::get_vertices() const {
|
|
|
+ RWLockRead read_lock(rwlock);
|
|
|
return vertices;
|
|
|
}
|
|
|
|
|
|
void NavigationMesh::_set_polygons(const Array &p_array) {
|
|
|
+ RWLockWrite write_lock(rwlock);
|
|
|
polygons.resize(p_array.size());
|
|
|
for (int i = 0; i < p_array.size(); i++) {
|
|
|
polygons.write[i].indices = p_array[i];
|
|
@@ -321,6 +324,7 @@ void NavigationMesh::_set_polygons(const Array &p_array) {
|
|
|
}
|
|
|
|
|
|
Array NavigationMesh::_get_polygons() const {
|
|
|
+ RWLockRead read_lock(rwlock);
|
|
|
Array ret;
|
|
|
ret.resize(polygons.size());
|
|
|
for (int i = 0; i < ret.size(); i++) {
|
|
@@ -331,6 +335,7 @@ Array NavigationMesh::_get_polygons() const {
|
|
|
}
|
|
|
|
|
|
void NavigationMesh::add_polygon(const Vector<int> &p_polygon) {
|
|
|
+ RWLockWrite write_lock(rwlock);
|
|
|
Polygon polygon;
|
|
|
polygon.indices = p_polygon;
|
|
|
polygons.push_back(polygon);
|
|
@@ -338,23 +343,45 @@ void NavigationMesh::add_polygon(const Vector<int> &p_polygon) {
|
|
|
}
|
|
|
|
|
|
int NavigationMesh::get_polygon_count() const {
|
|
|
+ RWLockRead read_lock(rwlock);
|
|
|
return polygons.size();
|
|
|
}
|
|
|
|
|
|
Vector<int> NavigationMesh::get_polygon(int p_idx) {
|
|
|
+ RWLockRead read_lock(rwlock);
|
|
|
ERR_FAIL_INDEX_V(p_idx, polygons.size(), Vector<int>());
|
|
|
return polygons[p_idx].indices;
|
|
|
}
|
|
|
|
|
|
void NavigationMesh::clear_polygons() {
|
|
|
+ RWLockWrite write_lock(rwlock);
|
|
|
polygons.clear();
|
|
|
}
|
|
|
|
|
|
void NavigationMesh::clear() {
|
|
|
+ RWLockWrite write_lock(rwlock);
|
|
|
polygons.clear();
|
|
|
vertices.clear();
|
|
|
}
|
|
|
|
|
|
+void NavigationMesh::set_data(const Vector<Vector3> &p_vertices, const Vector<Vector<int>> &p_polygons) {
|
|
|
+ RWLockWrite write_lock(rwlock);
|
|
|
+ vertices = p_vertices;
|
|
|
+ polygons.resize(p_polygons.size());
|
|
|
+ for (int i = 0; i < p_polygons.size(); i++) {
|
|
|
+ polygons.write[i].indices = p_polygons[i];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void NavigationMesh::get_data(Vector<Vector3> &r_vertices, Vector<Vector<int>> &r_polygons) {
|
|
|
+ RWLockRead read_lock(rwlock);
|
|
|
+ r_vertices = vertices;
|
|
|
+ r_polygons.resize(polygons.size());
|
|
|
+ for (int i = 0; i < polygons.size(); i++) {
|
|
|
+ r_polygons.write[i] = polygons[i].indices;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
Ref<ArrayMesh> NavigationMesh::get_debug_mesh() {
|
|
|
if (debug_mesh.is_valid()) {
|
|
@@ -372,6 +399,8 @@ Ref<ArrayMesh> NavigationMesh::get_debug_mesh() {
|
|
|
return debug_mesh;
|
|
|
}
|
|
|
|
|
|
+ RWLockRead read_lock(rwlock);
|
|
|
+
|
|
|
int polygon_count = get_polygon_count();
|
|
|
|
|
|
if (polygon_count < 1) {
|