summaryrefslogtreecommitdiffstats
path: root/scene/resources/navigation_mesh.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources/navigation_mesh.cpp')
-rw-r--r--scene/resources/navigation_mesh.cpp41
1 files changed, 22 insertions, 19 deletions
diff --git a/scene/resources/navigation_mesh.cpp b/scene/resources/navigation_mesh.cpp
index 2866ae7219..67ed65df0d 100644
--- a/scene/resources/navigation_mesh.cpp
+++ b/scene/resources/navigation_mesh.cpp
@@ -61,12 +61,12 @@ void NavigationMesh::create_from_mesh(const Ref<Mesh> &p_mesh) {
int rlen = iarr.size();
const int *r = iarr.ptr();
+ Vector<int> polygon;
for (int j = 0; j < rlen; j += 3) {
- 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;
+ polygon.resize(3);
+ polygon.write[0] = r[j + 0] + from;
+ polygon.write[1] = r[j + 1] + from;
+ polygon.write[2] = r[j + 2] + from;
polygons.push_back(polygon);
}
}
@@ -318,7 +318,7 @@ 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];
+ polygons.write[i] = p_array[i];
}
notify_property_list_changed();
}
@@ -328,17 +328,26 @@ Array NavigationMesh::_get_polygons() const {
Array ret;
ret.resize(polygons.size());
for (int i = 0; i < ret.size(); i++) {
- ret[i] = polygons[i].indices;
+ ret[i] = polygons[i];
}
return ret;
}
+void NavigationMesh::set_polygons(const Vector<Vector<int>> &p_polygons) {
+ RWLockWrite write_lock(rwlock);
+ polygons = p_polygons;
+ notify_property_list_changed();
+}
+
+Vector<Vector<int>> NavigationMesh::get_polygons() const {
+ RWLockRead read_lock(rwlock);
+ return polygons;
+}
+
void NavigationMesh::add_polygon(const Vector<int> &p_polygon) {
RWLockWrite write_lock(rwlock);
- Polygon polygon;
- polygon.indices = p_polygon;
- polygons.push_back(polygon);
+ polygons.push_back(p_polygon);
notify_property_list_changed();
}
@@ -350,7 +359,7 @@ int NavigationMesh::get_polygon_count() const {
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;
+ return polygons[p_idx];
}
void NavigationMesh::clear_polygons() {
@@ -367,19 +376,13 @@ void NavigationMesh::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];
- }
+ polygons = p_polygons;
}
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;
- }
+ r_polygons = polygons;
}
#ifdef DEBUG_ENABLED