diff options
Diffstat (limited to 'scene/resources/navigation_mesh.cpp')
-rw-r--r-- | scene/resources/navigation_mesh.cpp | 40 |
1 files changed, 14 insertions, 26 deletions
diff --git a/scene/resources/navigation_mesh.cpp b/scene/resources/navigation_mesh.cpp index e0aff2182e..e815da5d45 100644 --- a/scene/resources/navigation_mesh.cpp +++ b/scene/resources/navigation_mesh.cpp @@ -31,19 +31,19 @@ #include "navigation_mesh.h" void NavigationMesh::create_from_mesh(const Ref<Mesh> &p_mesh) { - vertices = Vector<Vector3>(); clear_polygons(); for (int i = 0; i < p_mesh->get_surface_count(); i++) { - - if (p_mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) + if (p_mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) { continue; + } Array arr = p_mesh->surface_get_arrays(i); Vector<Vector3> varr = arr[Mesh::ARRAY_VERTEX]; Vector<int> iarr = arr[Mesh::ARRAY_INDEX]; - if (varr.size() == 0 || iarr.size() == 0) + if (varr.size() == 0 || iarr.size() == 0) { continue; + } int from = vertices.size(); vertices.append_array(varr); @@ -82,27 +82,24 @@ int NavigationMesh::get_parsed_geometry_type() const { } void NavigationMesh::set_collision_mask(uint32_t p_mask) { - collision_mask = p_mask; } uint32_t NavigationMesh::get_collision_mask() const { - return collision_mask; } void NavigationMesh::set_collision_mask_bit(int p_bit, bool p_value) { - uint32_t mask = get_collision_mask(); - if (p_value) + if (p_value) { mask |= 1 << p_bit; - else + } else { mask &= ~(1 << p_bit); + } set_collision_mask(mask); } bool NavigationMesh::get_collision_mask_bit(int p_bit) const { - return get_collision_mask() & (1 << p_bit); } @@ -253,18 +250,15 @@ bool NavigationMesh::get_filter_walkable_low_height_spans() const { } void NavigationMesh::set_vertices(const Vector<Vector3> &p_vertices) { - vertices = p_vertices; _change_notify(); } Vector<Vector3> NavigationMesh::get_vertices() const { - return vertices; } void NavigationMesh::_set_polygons(const Array &p_array) { - polygons.resize(p_array.size()); for (int i = 0; i < p_array.size(); i++) { polygons.write[i].indices = p_array[i]; @@ -273,7 +267,6 @@ void NavigationMesh::_set_polygons(const Array &p_array) { } Array NavigationMesh::_get_polygons() const { - Array ret; ret.resize(polygons.size()); for (int i = 0; i < ret.size(); i++) { @@ -284,30 +277,29 @@ Array NavigationMesh::_get_polygons() const { } void NavigationMesh::add_polygon(const Vector<int> &p_polygon) { - Polygon polygon; polygon.indices = p_polygon; polygons.push_back(polygon); _change_notify(); } -int NavigationMesh::get_polygon_count() const { +int NavigationMesh::get_polygon_count() const { return polygons.size(); } -Vector<int> NavigationMesh::get_polygon(int p_idx) { +Vector<int> NavigationMesh::get_polygon(int p_idx) { ERR_FAIL_INDEX_V(p_idx, polygons.size(), Vector<int>()); return polygons[p_idx].indices; } -void NavigationMesh::clear_polygons() { +void NavigationMesh::clear_polygons() { polygons.clear(); } Ref<Mesh> NavigationMesh::get_debug_mesh() { - - if (debug_mesh.is_valid()) + if (debug_mesh.is_valid()) { return debug_mesh; + } Vector<Vector3> vertices = get_vertices(); const Vector3 *vr = vertices.ptr(); @@ -334,26 +326,23 @@ Ref<Mesh> NavigationMesh::get_debug_mesh() { int tidx = 0; for (List<Face3>::Element *E = faces.front(); E; E = E->next()) { - const Face3 &f = E->get(); for (int j = 0; j < 3; j++) { - tw[tidx++] = f.vertex[j]; _EdgeKey ek; ek.from = f.vertex[j].snapped(Vector3(CMP_EPSILON, CMP_EPSILON, CMP_EPSILON)); ek.to = f.vertex[(j + 1) % 3].snapped(Vector3(CMP_EPSILON, CMP_EPSILON, CMP_EPSILON)); - if (ek.from < ek.to) + if (ek.from < ek.to) { SWAP(ek.from, ek.to); + } Map<_EdgeKey, bool>::Element *F = edge_map.find(ek); if (F) { - F->get() = false; } else { - edge_map[ek] = true; } } @@ -362,7 +351,6 @@ Ref<Mesh> NavigationMesh::get_debug_mesh() { List<Vector3> lines; for (Map<_EdgeKey, bool>::Element *E = edge_map.front(); E; E = E->next()) { - if (E->get()) { lines.push_back(E->key().from); lines.push_back(E->key().to); |