| 1 | /**************************************************************************/ |
| 2 | /* navigation_mesh.cpp */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #include "navigation_mesh.h" |
| 32 | |
| 33 | #ifdef DEBUG_ENABLED |
| 34 | #include "servers/navigation_3d/navigation_server_3d.h" |
| 35 | #endif // DEBUG_ENABLED |
| 36 | |
| 37 | void NavigationMesh::create_from_mesh(const Ref<Mesh> &p_mesh) { |
| 38 | RWLockWrite write_lock(rwlock); |
| 39 | ERR_FAIL_COND(p_mesh.is_null()); |
| 40 | |
| 41 | vertices = Vector<Vector3>(); |
| 42 | polygons.clear(); |
| 43 | |
| 44 | for (int i = 0; i < p_mesh->get_surface_count(); i++) { |
| 45 | if (p_mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) { |
| 46 | WARN_PRINT("A mesh surface was skipped when creating a NavigationMesh due to wrong primitive type in the source mesh. Mesh surface must be made out of triangles."); |
| 47 | continue; |
| 48 | } |
| 49 | Array arr = p_mesh->surface_get_arrays(i); |
| 50 | ERR_CONTINUE(arr.size() != Mesh::ARRAY_MAX); |
| 51 | |
| 52 | Vector<Vector3> varr = arr[Mesh::ARRAY_VERTEX]; |
| 53 | Vector<int> iarr = arr[Mesh::ARRAY_INDEX]; |
| 54 | if (varr.is_empty() || iarr.is_empty()) { |
| 55 | WARN_PRINT("A mesh surface was skipped when creating a NavigationMesh due to an empty vertex or index array."); |
| 56 | continue; |
| 57 | } |
| 58 | |
| 59 | int from = vertices.size(); |
| 60 | vertices.append_array(varr); |
| 61 | int rlen = iarr.size(); |
| 62 | const int *r = iarr.ptr(); |
| 63 | |
| 64 | Vector<int> polygon; |
| 65 | for (int j = 0; j < rlen; j += 3) { |
| 66 | polygon.resize(3); |
| 67 | polygon.write[0] = r[j + 0] + from; |
| 68 | polygon.write[1] = r[j + 1] + from; |
| 69 | polygon.write[2] = r[j + 2] + from; |
| 70 | polygons.push_back(polygon); |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | void NavigationMesh::set_sample_partition_type(SamplePartitionType p_value) { |
| 76 | ERR_FAIL_INDEX(p_value, SAMPLE_PARTITION_MAX); |
| 77 | partition_type = p_value; |
| 78 | } |
| 79 | |
| 80 | NavigationMesh::SamplePartitionType NavigationMesh::get_sample_partition_type() const { |
| 81 | return partition_type; |
| 82 | } |
| 83 | |
| 84 | void NavigationMesh::set_parsed_geometry_type(ParsedGeometryType p_value) { |
| 85 | ERR_FAIL_INDEX(p_value, PARSED_GEOMETRY_MAX); |
| 86 | parsed_geometry_type = p_value; |
| 87 | notify_property_list_changed(); |
| 88 | } |
| 89 | |
| 90 | NavigationMesh::ParsedGeometryType NavigationMesh::get_parsed_geometry_type() const { |
| 91 | return parsed_geometry_type; |
| 92 | } |
| 93 | |
| 94 | void NavigationMesh::set_collision_mask(uint32_t p_mask) { |
| 95 | collision_mask = p_mask; |
| 96 | } |
| 97 | |
| 98 | uint32_t NavigationMesh::get_collision_mask() const { |
| 99 | return collision_mask; |
| 100 | } |
| 101 | |
| 102 | void NavigationMesh::set_collision_mask_value(int p_layer_number, bool p_value) { |
| 103 | ERR_FAIL_COND_MSG(p_layer_number < 1, "Collision layer number must be between 1 and 32 inclusive."); |
| 104 | ERR_FAIL_COND_MSG(p_layer_number > 32, "Collision layer number must be between 1 and 32 inclusive."); |
| 105 | uint32_t mask = get_collision_mask(); |
| 106 | if (p_value) { |
| 107 | mask |= 1 << (p_layer_number - 1); |
| 108 | } else { |
| 109 | mask &= ~(1 << (p_layer_number - 1)); |
| 110 | } |
| 111 | set_collision_mask(mask); |
| 112 | } |
| 113 | |
| 114 | bool NavigationMesh::get_collision_mask_value(int p_layer_number) const { |
| 115 | ERR_FAIL_COND_V_MSG(p_layer_number < 1, false, "Collision layer number must be between 1 and 32 inclusive."); |
| 116 | ERR_FAIL_COND_V_MSG(p_layer_number > 32, false, "Collision layer number must be between 1 and 32 inclusive."); |
| 117 | return get_collision_mask() & (1 << (p_layer_number - 1)); |
| 118 | } |
| 119 | |
| 120 | void NavigationMesh::set_source_geometry_mode(SourceGeometryMode p_geometry_mode) { |
| 121 | ERR_FAIL_INDEX(p_geometry_mode, SOURCE_GEOMETRY_MAX); |
| 122 | source_geometry_mode = p_geometry_mode; |
| 123 | notify_property_list_changed(); |
| 124 | } |
| 125 | |
| 126 | NavigationMesh::SourceGeometryMode NavigationMesh::get_source_geometry_mode() const { |
| 127 | return source_geometry_mode; |
| 128 | } |
| 129 | |
| 130 | void NavigationMesh::set_source_group_name(const StringName &p_group_name) { |
| 131 | source_group_name = p_group_name; |
| 132 | } |
| 133 | |
| 134 | StringName NavigationMesh::get_source_group_name() const { |
| 135 | return source_group_name; |
| 136 | } |
| 137 | |
| 138 | void NavigationMesh::set_cell_size(float p_value) { |
| 139 | ERR_FAIL_COND(p_value <= 0); |
| 140 | cell_size = p_value; |
| 141 | } |
| 142 | |
| 143 | float NavigationMesh::get_cell_size() const { |
| 144 | return cell_size; |
| 145 | } |
| 146 | |
| 147 | void NavigationMesh::set_cell_height(float p_value) { |
| 148 | ERR_FAIL_COND(p_value <= 0); |
| 149 | cell_height = p_value; |
| 150 | } |
| 151 | |
| 152 | float NavigationMesh::get_cell_height() const { |
| 153 | return cell_height; |
| 154 | } |
| 155 | |
| 156 | void NavigationMesh::set_border_size(float p_value) { |
| 157 | ERR_FAIL_COND(p_value < 0); |
| 158 | border_size = p_value; |
| 159 | } |
| 160 | |
| 161 | float NavigationMesh::get_border_size() const { |
| 162 | return border_size; |
| 163 | } |
| 164 | |
| 165 | void NavigationMesh::set_agent_height(float p_value) { |
| 166 | ERR_FAIL_COND(p_value < 0); |
| 167 | agent_height = p_value; |
| 168 | } |
| 169 | |
| 170 | float NavigationMesh::get_agent_height() const { |
| 171 | return agent_height; |
| 172 | } |
| 173 | |
| 174 | void NavigationMesh::set_agent_radius(float p_value) { |
| 175 | ERR_FAIL_COND(p_value < 0); |
| 176 | agent_radius = p_value; |
| 177 | } |
| 178 | |
| 179 | float NavigationMesh::get_agent_radius() { |
| 180 | return agent_radius; |
| 181 | } |
| 182 | |
| 183 | void NavigationMesh::set_agent_max_climb(float p_value) { |
| 184 | ERR_FAIL_COND(p_value < 0); |
| 185 | agent_max_climb = p_value; |
| 186 | } |
| 187 | |
| 188 | float NavigationMesh::get_agent_max_climb() const { |
| 189 | return agent_max_climb; |
| 190 | } |
| 191 | |
| 192 | void NavigationMesh::set_agent_max_slope(float p_value) { |
| 193 | ERR_FAIL_COND(p_value < 0 || p_value > 90); |
| 194 | agent_max_slope = p_value; |
| 195 | } |
| 196 | |
| 197 | float NavigationMesh::get_agent_max_slope() const { |
| 198 | return agent_max_slope; |
| 199 | } |
| 200 | |
| 201 | void NavigationMesh::set_region_min_size(float p_value) { |
| 202 | ERR_FAIL_COND(p_value < 0); |
| 203 | region_min_size = p_value; |
| 204 | } |
| 205 | |
| 206 | float NavigationMesh::get_region_min_size() const { |
| 207 | return region_min_size; |
| 208 | } |
| 209 | |
| 210 | void NavigationMesh::set_region_merge_size(float p_value) { |
| 211 | ERR_FAIL_COND(p_value < 0); |
| 212 | region_merge_size = p_value; |
| 213 | } |
| 214 | |
| 215 | float NavigationMesh::get_region_merge_size() const { |
| 216 | return region_merge_size; |
| 217 | } |
| 218 | |
| 219 | void NavigationMesh::set_edge_max_length(float p_value) { |
| 220 | ERR_FAIL_COND(p_value < 0); |
| 221 | edge_max_length = p_value; |
| 222 | } |
| 223 | |
| 224 | float NavigationMesh::get_edge_max_length() const { |
| 225 | return edge_max_length; |
| 226 | } |
| 227 | |
| 228 | void NavigationMesh::set_edge_max_error(float p_value) { |
| 229 | ERR_FAIL_COND(p_value < 0); |
| 230 | edge_max_error = p_value; |
| 231 | } |
| 232 | |
| 233 | float NavigationMesh::get_edge_max_error() const { |
| 234 | return edge_max_error; |
| 235 | } |
| 236 | |
| 237 | void NavigationMesh::set_vertices_per_polygon(float p_value) { |
| 238 | ERR_FAIL_COND(p_value < 3); |
| 239 | vertices_per_polygon = p_value; |
| 240 | } |
| 241 | |
| 242 | float NavigationMesh::get_vertices_per_polygon() const { |
| 243 | return vertices_per_polygon; |
| 244 | } |
| 245 | |
| 246 | void NavigationMesh::set_detail_sample_distance(float p_value) { |
| 247 | ERR_FAIL_COND(p_value < 0.1); |
| 248 | detail_sample_distance = p_value; |
| 249 | } |
| 250 | |
| 251 | float NavigationMesh::get_detail_sample_distance() const { |
| 252 | return detail_sample_distance; |
| 253 | } |
| 254 | |
| 255 | void NavigationMesh::set_detail_sample_max_error(float p_value) { |
| 256 | ERR_FAIL_COND(p_value < 0); |
| 257 | detail_sample_max_error = p_value; |
| 258 | } |
| 259 | |
| 260 | float NavigationMesh::get_detail_sample_max_error() const { |
| 261 | return detail_sample_max_error; |
| 262 | } |
| 263 | |
| 264 | void NavigationMesh::set_filter_low_hanging_obstacles(bool p_value) { |
| 265 | filter_low_hanging_obstacles = p_value; |
| 266 | } |
| 267 | |
| 268 | bool NavigationMesh::get_filter_low_hanging_obstacles() const { |
| 269 | return filter_low_hanging_obstacles; |
| 270 | } |
| 271 | |
| 272 | void NavigationMesh::set_filter_ledge_spans(bool p_value) { |
| 273 | filter_ledge_spans = p_value; |
| 274 | } |
| 275 | |
| 276 | bool NavigationMesh::get_filter_ledge_spans() const { |
| 277 | return filter_ledge_spans; |
| 278 | } |
| 279 | |
| 280 | void NavigationMesh::set_filter_walkable_low_height_spans(bool p_value) { |
| 281 | filter_walkable_low_height_spans = p_value; |
| 282 | } |
| 283 | |
| 284 | bool NavigationMesh::get_filter_walkable_low_height_spans() const { |
| 285 | return filter_walkable_low_height_spans; |
| 286 | } |
| 287 | |
| 288 | void NavigationMesh::set_filter_baking_aabb(const AABB &p_aabb) { |
| 289 | filter_baking_aabb = p_aabb; |
| 290 | emit_changed(); |
| 291 | } |
| 292 | |
| 293 | AABB NavigationMesh::get_filter_baking_aabb() const { |
| 294 | return filter_baking_aabb; |
| 295 | } |
| 296 | |
| 297 | void NavigationMesh::set_filter_baking_aabb_offset(const Vector3 &p_aabb_offset) { |
| 298 | filter_baking_aabb_offset = p_aabb_offset; |
| 299 | emit_changed(); |
| 300 | } |
| 301 | |
| 302 | Vector3 NavigationMesh::get_filter_baking_aabb_offset() const { |
| 303 | return filter_baking_aabb_offset; |
| 304 | } |
| 305 | |
| 306 | void NavigationMesh::set_vertices(const Vector<Vector3> &p_vertices) { |
| 307 | RWLockWrite write_lock(rwlock); |
| 308 | vertices = p_vertices; |
| 309 | notify_property_list_changed(); |
| 310 | } |
| 311 | |
| 312 | Vector<Vector3> NavigationMesh::get_vertices() const { |
| 313 | RWLockRead read_lock(rwlock); |
| 314 | return vertices; |
| 315 | } |
| 316 | |
| 317 | void NavigationMesh::_set_polygons(const Array &p_array) { |
| 318 | RWLockWrite write_lock(rwlock); |
| 319 | polygons.resize(p_array.size()); |
| 320 | for (int i = 0; i < p_array.size(); i++) { |
| 321 | polygons.write[i] = p_array[i]; |
| 322 | } |
| 323 | notify_property_list_changed(); |
| 324 | } |
| 325 | |
| 326 | Array NavigationMesh::_get_polygons() const { |
| 327 | RWLockRead read_lock(rwlock); |
| 328 | Array ret; |
| 329 | ret.resize(polygons.size()); |
| 330 | for (int i = 0; i < ret.size(); i++) { |
| 331 | ret[i] = polygons[i]; |
| 332 | } |
| 333 | |
| 334 | return ret; |
| 335 | } |
| 336 | |
| 337 | void NavigationMesh::set_polygons(const Vector<Vector<int>> &p_polygons) { |
| 338 | RWLockWrite write_lock(rwlock); |
| 339 | polygons = p_polygons; |
| 340 | notify_property_list_changed(); |
| 341 | } |
| 342 | |
| 343 | Vector<Vector<int>> NavigationMesh::get_polygons() const { |
| 344 | RWLockRead read_lock(rwlock); |
| 345 | return polygons; |
| 346 | } |
| 347 | |
| 348 | void NavigationMesh::add_polygon(const Vector<int> &p_polygon) { |
| 349 | RWLockWrite write_lock(rwlock); |
| 350 | polygons.push_back(p_polygon); |
| 351 | notify_property_list_changed(); |
| 352 | } |
| 353 | |
| 354 | int NavigationMesh::get_polygon_count() const { |
| 355 | RWLockRead read_lock(rwlock); |
| 356 | return polygons.size(); |
| 357 | } |
| 358 | |
| 359 | Vector<int> NavigationMesh::get_polygon(int p_idx) { |
| 360 | RWLockRead read_lock(rwlock); |
| 361 | ERR_FAIL_INDEX_V(p_idx, polygons.size(), Vector<int>()); |
| 362 | return polygons[p_idx]; |
| 363 | } |
| 364 | |
| 365 | void NavigationMesh::clear_polygons() { |
| 366 | RWLockWrite write_lock(rwlock); |
| 367 | polygons.clear(); |
| 368 | } |
| 369 | |
| 370 | void NavigationMesh::clear() { |
| 371 | RWLockWrite write_lock(rwlock); |
| 372 | polygons.clear(); |
| 373 | vertices.clear(); |
| 374 | } |
| 375 | |
| 376 | void NavigationMesh::set_data(const Vector<Vector3> &p_vertices, const Vector<Vector<int>> &p_polygons) { |
| 377 | RWLockWrite write_lock(rwlock); |
| 378 | vertices = p_vertices; |
| 379 | polygons = p_polygons; |
| 380 | } |
| 381 | |
| 382 | void NavigationMesh::get_data(Vector<Vector3> &r_vertices, Vector<Vector<int>> &r_polygons) { |
| 383 | RWLockRead read_lock(rwlock); |
| 384 | r_vertices = vertices; |
| 385 | r_polygons = polygons; |
| 386 | } |
| 387 | |
| 388 | #ifdef DEBUG_ENABLED |
| 389 | Ref<ArrayMesh> NavigationMesh::get_debug_mesh() { |
| 390 | if (debug_mesh.is_valid()) { |
| 391 | // Blocks further updates for now, code below is intended for dynamic updates e.g. when settings change. |
| 392 | return debug_mesh; |
| 393 | } |
| 394 | |
| 395 | if (debug_mesh.is_null()) { |
| 396 | debug_mesh.instantiate(); |
| 397 | } else { |
| 398 | debug_mesh->clear_surfaces(); |
| 399 | } |
| 400 | |
| 401 | if (vertices.is_empty()) { |
| 402 | return debug_mesh; |
| 403 | } |
| 404 | |
| 405 | RWLockRead read_lock(rwlock); |
| 406 | |
| 407 | int polygon_count = get_polygon_count(); |
| 408 | |
| 409 | if (polygon_count < 1) { |
| 410 | // no face, no play |
| 411 | return debug_mesh; |
| 412 | } |
| 413 | |
| 414 | // build geometry face surface |
| 415 | Vector<Vector3> face_vertex_array; |
| 416 | face_vertex_array.resize(polygon_count * 3); |
| 417 | |
| 418 | for (int i = 0; i < polygon_count; i++) { |
| 419 | Vector<int> polygon = get_polygon(i); |
| 420 | |
| 421 | face_vertex_array.push_back(vertices[polygon[0]]); |
| 422 | face_vertex_array.push_back(vertices[polygon[1]]); |
| 423 | face_vertex_array.push_back(vertices[polygon[2]]); |
| 424 | } |
| 425 | |
| 426 | Array face_mesh_array; |
| 427 | face_mesh_array.resize(Mesh::ARRAY_MAX); |
| 428 | face_mesh_array[Mesh::ARRAY_VERTEX] = face_vertex_array; |
| 429 | |
| 430 | // if enabled add vertex colors to colorize each face individually |
| 431 | bool enabled_geometry_face_random_color = NavigationServer3D::get_singleton()->get_debug_navigation_enable_geometry_face_random_color(); |
| 432 | if (enabled_geometry_face_random_color) { |
| 433 | Color debug_navigation_geometry_face_color = NavigationServer3D::get_singleton()->get_debug_navigation_geometry_face_color(); |
| 434 | Color polygon_color = debug_navigation_geometry_face_color; |
| 435 | |
| 436 | Vector<Color> face_color_array; |
| 437 | face_color_array.resize(polygon_count * 3); |
| 438 | |
| 439 | for (int i = 0; i < polygon_count; i++) { |
| 440 | polygon_color = debug_navigation_geometry_face_color * (Color(Math::randf(), Math::randf(), Math::randf())); |
| 441 | |
| 442 | face_color_array.push_back(polygon_color); |
| 443 | face_color_array.push_back(polygon_color); |
| 444 | face_color_array.push_back(polygon_color); |
| 445 | } |
| 446 | face_mesh_array[Mesh::ARRAY_COLOR] = face_color_array; |
| 447 | } |
| 448 | |
| 449 | debug_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, face_mesh_array); |
| 450 | Ref<StandardMaterial3D> debug_geometry_face_material = NavigationServer3D::get_singleton()->get_debug_navigation_geometry_face_material(); |
| 451 | debug_mesh->surface_set_material(0, debug_geometry_face_material); |
| 452 | |
| 453 | // if enabled build geometry edge line surface |
| 454 | bool enabled_edge_lines = NavigationServer3D::get_singleton()->get_debug_navigation_enable_edge_lines(); |
| 455 | |
| 456 | if (enabled_edge_lines) { |
| 457 | Vector<Vector3> line_vertex_array; |
| 458 | line_vertex_array.resize(polygon_count * 6); |
| 459 | |
| 460 | for (int i = 0; i < polygon_count; i++) { |
| 461 | Vector<int> polygon = get_polygon(i); |
| 462 | |
| 463 | line_vertex_array.push_back(vertices[polygon[0]]); |
| 464 | line_vertex_array.push_back(vertices[polygon[1]]); |
| 465 | line_vertex_array.push_back(vertices[polygon[1]]); |
| 466 | line_vertex_array.push_back(vertices[polygon[2]]); |
| 467 | line_vertex_array.push_back(vertices[polygon[2]]); |
| 468 | line_vertex_array.push_back(vertices[polygon[0]]); |
| 469 | } |
| 470 | |
| 471 | Array line_mesh_array; |
| 472 | line_mesh_array.resize(Mesh::ARRAY_MAX); |
| 473 | line_mesh_array[Mesh::ARRAY_VERTEX] = line_vertex_array; |
| 474 | debug_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_LINES, line_mesh_array); |
| 475 | Ref<StandardMaterial3D> debug_geometry_edge_material = NavigationServer3D::get_singleton()->get_debug_navigation_geometry_edge_material(); |
| 476 | debug_mesh->surface_set_material(1, debug_geometry_edge_material); |
| 477 | } |
| 478 | |
| 479 | return debug_mesh; |
| 480 | } |
| 481 | #endif // DEBUG_ENABLED |
| 482 | |
| 483 | void NavigationMesh::_bind_methods() { |
| 484 | ClassDB::bind_method(D_METHOD("set_sample_partition_type", "sample_partition_type"), &NavigationMesh::set_sample_partition_type); |
| 485 | ClassDB::bind_method(D_METHOD("get_sample_partition_type"), &NavigationMesh::get_sample_partition_type); |
| 486 | |
| 487 | ClassDB::bind_method(D_METHOD("set_parsed_geometry_type", "geometry_type"), &NavigationMesh::set_parsed_geometry_type); |
| 488 | ClassDB::bind_method(D_METHOD("get_parsed_geometry_type"), &NavigationMesh::get_parsed_geometry_type); |
| 489 | |
| 490 | ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &NavigationMesh::set_collision_mask); |
| 491 | ClassDB::bind_method(D_METHOD("get_collision_mask"), &NavigationMesh::get_collision_mask); |
| 492 | |
| 493 | ClassDB::bind_method(D_METHOD("set_collision_mask_value", "layer_number", "value"), &NavigationMesh::set_collision_mask_value); |
| 494 | ClassDB::bind_method(D_METHOD("get_collision_mask_value", "layer_number"), &NavigationMesh::get_collision_mask_value); |
| 495 | |
| 496 | ClassDB::bind_method(D_METHOD("set_source_geometry_mode", "mask"), &NavigationMesh::set_source_geometry_mode); |
| 497 | ClassDB::bind_method(D_METHOD("get_source_geometry_mode"), &NavigationMesh::get_source_geometry_mode); |
| 498 | |
| 499 | ClassDB::bind_method(D_METHOD("set_source_group_name", "mask"), &NavigationMesh::set_source_group_name); |
| 500 | ClassDB::bind_method(D_METHOD("get_source_group_name"), &NavigationMesh::get_source_group_name); |
| 501 | |
| 502 | ClassDB::bind_method(D_METHOD("set_cell_size", "cell_size"), &NavigationMesh::set_cell_size); |
| 503 | ClassDB::bind_method(D_METHOD("get_cell_size"), &NavigationMesh::get_cell_size); |
| 504 | |
| 505 | ClassDB::bind_method(D_METHOD("set_cell_height", "cell_height"), &NavigationMesh::set_cell_height); |
| 506 | ClassDB::bind_method(D_METHOD("get_cell_height"), &NavigationMesh::get_cell_height); |
| 507 | |
| 508 | ClassDB::bind_method(D_METHOD("set_border_size", "border_size"), &NavigationMesh::set_border_size); |
| 509 | ClassDB::bind_method(D_METHOD("get_border_size"), &NavigationMesh::get_border_size); |
| 510 | |
| 511 | ClassDB::bind_method(D_METHOD("set_agent_height", "agent_height"), &NavigationMesh::set_agent_height); |
| 512 | ClassDB::bind_method(D_METHOD("get_agent_height"), &NavigationMesh::get_agent_height); |
| 513 | |
| 514 | ClassDB::bind_method(D_METHOD("set_agent_radius", "agent_radius"), &NavigationMesh::set_agent_radius); |
| 515 | ClassDB::bind_method(D_METHOD("get_agent_radius"), &NavigationMesh::get_agent_radius); |
| 516 | |
| 517 | ClassDB::bind_method(D_METHOD("set_agent_max_climb", "agent_max_climb"), &NavigationMesh::set_agent_max_climb); |
| 518 | ClassDB::bind_method(D_METHOD("get_agent_max_climb"), &NavigationMesh::get_agent_max_climb); |
| 519 | |
| 520 | ClassDB::bind_method(D_METHOD("set_agent_max_slope", "agent_max_slope"), &NavigationMesh::set_agent_max_slope); |
| 521 | ClassDB::bind_method(D_METHOD("get_agent_max_slope"), &NavigationMesh::get_agent_max_slope); |
| 522 | |
| 523 | ClassDB::bind_method(D_METHOD("set_region_min_size", "region_min_size"), &NavigationMesh::set_region_min_size); |
| 524 | ClassDB::bind_method(D_METHOD("get_region_min_size"), &NavigationMesh::get_region_min_size); |
| 525 | |
| 526 | ClassDB::bind_method(D_METHOD("set_region_merge_size", "region_merge_size"), &NavigationMesh::set_region_merge_size); |
| 527 | ClassDB::bind_method(D_METHOD("get_region_merge_size"), &NavigationMesh::get_region_merge_size); |
| 528 | |
| 529 | ClassDB::bind_method(D_METHOD("set_edge_max_length", "edge_max_length"), &NavigationMesh::set_edge_max_length); |
| 530 | ClassDB::bind_method(D_METHOD("get_edge_max_length"), &NavigationMesh::get_edge_max_length); |
| 531 | |
| 532 | ClassDB::bind_method(D_METHOD("set_edge_max_error", "edge_max_error"), &NavigationMesh::set_edge_max_error); |
| 533 | ClassDB::bind_method(D_METHOD("get_edge_max_error"), &NavigationMesh::get_edge_max_error); |
| 534 | |
| 535 | ClassDB::bind_method(D_METHOD("set_vertices_per_polygon", "vertices_per_polygon"), &NavigationMesh::set_vertices_per_polygon); |
| 536 | ClassDB::bind_method(D_METHOD("get_vertices_per_polygon"), &NavigationMesh::get_vertices_per_polygon); |
| 537 | |
| 538 | ClassDB::bind_method(D_METHOD("set_detail_sample_distance", "detail_sample_dist"), &NavigationMesh::set_detail_sample_distance); |
| 539 | ClassDB::bind_method(D_METHOD("get_detail_sample_distance"), &NavigationMesh::get_detail_sample_distance); |
| 540 | |
| 541 | ClassDB::bind_method(D_METHOD("set_detail_sample_max_error", "detail_sample_max_error"), &NavigationMesh::set_detail_sample_max_error); |
| 542 | ClassDB::bind_method(D_METHOD("get_detail_sample_max_error"), &NavigationMesh::get_detail_sample_max_error); |
| 543 | |
| 544 | ClassDB::bind_method(D_METHOD("set_filter_low_hanging_obstacles", "filter_low_hanging_obstacles"), &NavigationMesh::set_filter_low_hanging_obstacles); |
| 545 | ClassDB::bind_method(D_METHOD("get_filter_low_hanging_obstacles"), &NavigationMesh::get_filter_low_hanging_obstacles); |
| 546 | |
| 547 | ClassDB::bind_method(D_METHOD("set_filter_ledge_spans", "filter_ledge_spans"), &NavigationMesh::set_filter_ledge_spans); |
| 548 | ClassDB::bind_method(D_METHOD("get_filter_ledge_spans"), &NavigationMesh::get_filter_ledge_spans); |
| 549 | |
| 550 | ClassDB::bind_method(D_METHOD("set_filter_walkable_low_height_spans", "filter_walkable_low_height_spans"), &NavigationMesh::set_filter_walkable_low_height_spans); |
| 551 | ClassDB::bind_method(D_METHOD("get_filter_walkable_low_height_spans"), &NavigationMesh::get_filter_walkable_low_height_spans); |
| 552 | ClassDB::bind_method(D_METHOD("set_filter_baking_aabb", "baking_aabb"), &NavigationMesh::set_filter_baking_aabb); |
| 553 | ClassDB::bind_method(D_METHOD("get_filter_baking_aabb"), &NavigationMesh::get_filter_baking_aabb); |
| 554 | ClassDB::bind_method(D_METHOD("set_filter_baking_aabb_offset", "baking_aabb_offset"), &NavigationMesh::set_filter_baking_aabb_offset); |
| 555 | ClassDB::bind_method(D_METHOD("get_filter_baking_aabb_offset"), &NavigationMesh::get_filter_baking_aabb_offset); |
| 556 | |
| 557 | ClassDB::bind_method(D_METHOD("set_vertices", "vertices"), &NavigationMesh::set_vertices); |
| 558 | ClassDB::bind_method(D_METHOD("get_vertices"), &NavigationMesh::get_vertices); |
| 559 | |
| 560 | ClassDB::bind_method(D_METHOD("add_polygon", "polygon"), &NavigationMesh::add_polygon); |
| 561 | ClassDB::bind_method(D_METHOD("get_polygon_count"), &NavigationMesh::get_polygon_count); |
| 562 | ClassDB::bind_method(D_METHOD("get_polygon", "idx"), &NavigationMesh::get_polygon); |
| 563 | ClassDB::bind_method(D_METHOD("clear_polygons"), &NavigationMesh::clear_polygons); |
| 564 | |
| 565 | ClassDB::bind_method(D_METHOD("create_from_mesh", "mesh"), &NavigationMesh::create_from_mesh); |
| 566 | |
| 567 | ClassDB::bind_method(D_METHOD("_set_polygons", "polygons"), &NavigationMesh::_set_polygons); |
| 568 | ClassDB::bind_method(D_METHOD("_get_polygons"), &NavigationMesh::_get_polygons); |
| 569 | |
| 570 | ClassDB::bind_method(D_METHOD("clear"), &NavigationMesh::clear); |
| 571 | |
| 572 | ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR3_ARRAY, "vertices", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "set_vertices", "get_vertices"); |
| 573 | ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "polygons", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_polygons", "_get_polygons"); |
| 574 | |
| 575 | ADD_GROUP("Sampling", "sample_"); |
| 576 | ADD_PROPERTY(PropertyInfo(Variant::INT, "sample_partition_type", PROPERTY_HINT_ENUM, "Watershed,Monotone,Layers"), "set_sample_partition_type", "get_sample_partition_type"); |
| 577 | ADD_GROUP("Geometry", "geometry_"); |
| 578 | ADD_PROPERTY(PropertyInfo(Variant::INT, "geometry_parsed_geometry_type", PROPERTY_HINT_ENUM, "Mesh Instances,Static Colliders,Both"), "set_parsed_geometry_type", "get_parsed_geometry_type"); |
| 579 | ADD_PROPERTY(PropertyInfo(Variant::INT, "geometry_collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask"); |
| 580 | ADD_PROPERTY_DEFAULT("geometry_collision_mask", 0xFFFFFFFF); |
| 581 | ADD_PROPERTY(PropertyInfo(Variant::INT, "geometry_source_geometry_mode", PROPERTY_HINT_ENUM, "Root Node Children,Group With Children,Group Explicit"), "set_source_geometry_mode", "get_source_geometry_mode"); |
| 582 | ADD_PROPERTY(PropertyInfo(Variant::STRING, "geometry_source_group_name"), "set_source_group_name", "get_source_group_name"); |
| 583 | ADD_PROPERTY_DEFAULT("geometry_source_group_name", StringName("navigation_mesh_source_group")); |
| 584 | ADD_GROUP("Cells", ""); |
| 585 | ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "cell_size", PROPERTY_HINT_RANGE, "0.01,500.0,0.01,or_greater,suffix:m"), "set_cell_size", "get_cell_size"); |
| 586 | ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "cell_height", PROPERTY_HINT_RANGE, "0.01,500.0,0.01,or_greater,suffix:m"), "set_cell_height", "get_cell_height"); |
| 587 | ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "border_size", PROPERTY_HINT_RANGE, "0.0,500.0,0.01,or_greater,suffix:m"), "set_border_size", "get_border_size"); |
| 588 | ADD_GROUP("Agents", "agent_"); |
| 589 | ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "agent_height", PROPERTY_HINT_RANGE, "0.0,500.0,0.01,or_greater,suffix:m"), "set_agent_height", "get_agent_height"); |
| 590 | ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "agent_radius", PROPERTY_HINT_RANGE, "0.0,500.0,0.01,or_greater,suffix:m"), "set_agent_radius", "get_agent_radius"); |
| 591 | ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "agent_max_climb", PROPERTY_HINT_RANGE, "0.0,500.0,0.01,or_greater,suffix:m"), "set_agent_max_climb", "get_agent_max_climb"); |
| 592 | ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "agent_max_slope", PROPERTY_HINT_RANGE, "0.02,90.0,0.01,degrees"), "set_agent_max_slope", "get_agent_max_slope"); |
| 593 | ADD_GROUP("Regions", "region_"); |
| 594 | ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "region_min_size", PROPERTY_HINT_RANGE, "0.0,150.0,0.01,or_greater"), "set_region_min_size", "get_region_min_size"); |
| 595 | ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "region_merge_size", PROPERTY_HINT_RANGE, "0.0,150.0,0.01,or_greater"), "set_region_merge_size", "get_region_merge_size"); |
| 596 | ADD_GROUP("Edges", "edge_"); |
| 597 | ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "edge_max_length", PROPERTY_HINT_RANGE, "0.0,50.0,0.01,or_greater,suffix:m"), "set_edge_max_length", "get_edge_max_length"); |
| 598 | ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "edge_max_error", PROPERTY_HINT_RANGE, "0.1,3.0,0.01,or_greater,suffix:m"), "set_edge_max_error", "get_edge_max_error"); |
| 599 | ADD_GROUP("Polygons", ""); |
| 600 | ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "vertices_per_polygon", PROPERTY_HINT_RANGE, "3.0,12.0,1.0,or_greater"), "set_vertices_per_polygon", "get_vertices_per_polygon"); |
| 601 | ADD_GROUP("Details", "detail_"); |
| 602 | ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "detail_sample_distance", PROPERTY_HINT_RANGE, "0.1,16.0,0.01,or_greater,suffix:m"), "set_detail_sample_distance", "get_detail_sample_distance"); |
| 603 | ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "detail_sample_max_error", PROPERTY_HINT_RANGE, "0.0,16.0,0.01,or_greater,suffix:m"), "set_detail_sample_max_error", "get_detail_sample_max_error"); |
| 604 | ADD_GROUP("Filters", "filter_"); |
| 605 | ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter_low_hanging_obstacles"), "set_filter_low_hanging_obstacles", "get_filter_low_hanging_obstacles"); |
| 606 | ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter_ledge_spans"), "set_filter_ledge_spans", "get_filter_ledge_spans"); |
| 607 | ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter_walkable_low_height_spans"), "set_filter_walkable_low_height_spans", "get_filter_walkable_low_height_spans"); |
| 608 | ADD_PROPERTY(PropertyInfo(Variant::AABB, "filter_baking_aabb"), "set_filter_baking_aabb", "get_filter_baking_aabb"); |
| 609 | ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "filter_baking_aabb_offset"), "set_filter_baking_aabb_offset", "get_filter_baking_aabb_offset"); |
| 610 | |
| 611 | BIND_ENUM_CONSTANT(SAMPLE_PARTITION_WATERSHED); |
| 612 | BIND_ENUM_CONSTANT(SAMPLE_PARTITION_MONOTONE); |
| 613 | BIND_ENUM_CONSTANT(SAMPLE_PARTITION_LAYERS); |
| 614 | BIND_ENUM_CONSTANT(SAMPLE_PARTITION_MAX); |
| 615 | |
| 616 | BIND_ENUM_CONSTANT(PARSED_GEOMETRY_MESH_INSTANCES); |
| 617 | BIND_ENUM_CONSTANT(PARSED_GEOMETRY_STATIC_COLLIDERS); |
| 618 | BIND_ENUM_CONSTANT(PARSED_GEOMETRY_BOTH); |
| 619 | BIND_ENUM_CONSTANT(PARSED_GEOMETRY_MAX); |
| 620 | |
| 621 | BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_ROOT_NODE_CHILDREN); |
| 622 | BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN); |
| 623 | BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_GROUPS_EXPLICIT); |
| 624 | BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_MAX); |
| 625 | } |
| 626 | |
| 627 | void NavigationMesh::_validate_property(PropertyInfo &p_property) const { |
| 628 | if (p_property.name == "geometry_collision_mask") { |
| 629 | if (parsed_geometry_type == PARSED_GEOMETRY_MESH_INSTANCES) { |
| 630 | p_property.usage = PROPERTY_USAGE_NONE; |
| 631 | return; |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | if (p_property.name == "geometry_source_group_name") { |
| 636 | if (source_geometry_mode == SOURCE_GEOMETRY_ROOT_NODE_CHILDREN) { |
| 637 | p_property.usage = PROPERTY_USAGE_NONE; |
| 638 | return; |
| 639 | } |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | #ifndef DISABLE_DEPRECATED |
| 644 | bool NavigationMesh::_set(const StringName &p_name, const Variant &p_value) { |
| 645 | if (p_name == "polygon_verts_per_poly") { // Renamed in 4.0 beta 9. |
| 646 | set_vertices_per_polygon(p_value); |
| 647 | return true; |
| 648 | } |
| 649 | return false; |
| 650 | } |
| 651 | |
| 652 | bool NavigationMesh::_get(const StringName &p_name, Variant &r_ret) const { |
| 653 | if (p_name == "polygon_verts_per_poly") { // Renamed in 4.0 beta 9. |
| 654 | r_ret = get_vertices_per_polygon(); |
| 655 | return true; |
| 656 | } |
| 657 | return false; |
| 658 | } |
| 659 | #endif // DISABLE_DEPRECATED |