| 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_server_3d.h" |
| 35 | #endif // DEBUG_ENABLED |
| 36 | |
| 37 | void NavigationMesh::create_from_mesh(const Ref<Mesh> &p_mesh) { |
| 38 | ERR_FAIL_COND(p_mesh.is_null()); |
| 39 | |
| 40 | vertices = Vector<Vector3>(); |
| 41 | clear_polygons(); |
| 42 | |
| 43 | for (int i = 0; i < p_mesh->get_surface_count(); i++) { |
| 44 | if (p_mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) { |
| 45 | 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." ); |
| 46 | continue; |
| 47 | } |
| 48 | Array arr = p_mesh->surface_get_arrays(i); |
| 49 | ERR_CONTINUE(arr.size() != Mesh::ARRAY_MAX); |
| 50 | |
| 51 | Vector<Vector3> varr = arr[Mesh::ARRAY_VERTEX]; |
| 52 | Vector<int> iarr = arr[Mesh::ARRAY_INDEX]; |
| 53 | if (varr.size() == 0 || iarr.size() == 0) { |
| 54 | WARN_PRINT("A mesh surface was skipped when creating a NavigationMesh due to an empty vertex or index array." ); |
| 55 | continue; |
| 56 | } |
| 57 | |
| 58 | int from = vertices.size(); |
| 59 | vertices.append_array(varr); |
| 60 | int rlen = iarr.size(); |
| 61 | const int *r = iarr.ptr(); |
| 62 | |
| 63 | for (int j = 0; j < rlen; j += 3) { |
| 64 | Vector<int> vi; |
| 65 | vi.resize(3); |
| 66 | vi.write[0] = r[j + 0] + from; |
| 67 | vi.write[1] = r[j + 1] + from; |
| 68 | vi.write[2] = r[j + 2] + from; |
| 69 | |
| 70 | add_polygon(vi); |
| 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(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_agent_height(float p_value) { |
| 157 | ERR_FAIL_COND(p_value < 0); |
| 158 | agent_height = p_value; |
| 159 | } |
| 160 | |
| 161 | float NavigationMesh::get_agent_height() const { |
| 162 | return agent_height; |
| 163 | } |
| 164 | |
| 165 | void NavigationMesh::set_agent_radius(float p_value) { |
| 166 | ERR_FAIL_COND(p_value < 0); |
| 167 | agent_radius = p_value; |
| 168 | } |
| 169 | |
| 170 | float NavigationMesh::get_agent_radius() { |
| 171 | return agent_radius; |
| 172 | } |
| 173 | |
| 174 | void NavigationMesh::set_agent_max_climb(float p_value) { |
| 175 | ERR_FAIL_COND(p_value < 0); |
| 176 | agent_max_climb = p_value; |
| 177 | } |
| 178 | |
| 179 | float NavigationMesh::get_agent_max_climb() const { |
| 180 | return agent_max_climb; |
| 181 | } |
| 182 | |
| 183 | void NavigationMesh::set_agent_max_slope(float p_value) { |
| 184 | ERR_FAIL_COND(p_value < 0 || p_value > 90); |
| 185 | agent_max_slope = p_value; |
| 186 | } |
| 187 | |
| 188 | float NavigationMesh::get_agent_max_slope() const { |
| 189 | return agent_max_slope; |
| 190 | } |
| 191 | |
| 192 | void NavigationMesh::set_region_min_size(float p_value) { |
| 193 | ERR_FAIL_COND(p_value < 0); |
| 194 | region_min_size = p_value; |
| 195 | } |
| 196 | |
| 197 | float NavigationMesh::get_region_min_size() const { |
| 198 | return region_min_size; |
| 199 | } |
| 200 | |
| 201 | void NavigationMesh::set_region_merge_size(float p_value) { |
| 202 | ERR_FAIL_COND(p_value < 0); |
| 203 | region_merge_size = p_value; |
| 204 | } |
| 205 | |
| 206 | float NavigationMesh::get_region_merge_size() const { |
| 207 | return region_merge_size; |
| 208 | } |
| 209 | |
| 210 | void NavigationMesh::set_edge_max_length(float p_value) { |
| 211 | ERR_FAIL_COND(p_value < 0); |
| 212 | edge_max_length = p_value; |
| 213 | } |
| 214 | |
| 215 | float NavigationMesh::get_edge_max_length() const { |
| 216 | return edge_max_length; |
| 217 | } |
| 218 | |
| 219 | void NavigationMesh::set_edge_max_error(float p_value) { |
| 220 | ERR_FAIL_COND(p_value < 0); |
| 221 | edge_max_error = p_value; |
| 222 | } |
| 223 | |
| 224 | float NavigationMesh::get_edge_max_error() const { |
| 225 | return edge_max_error; |
| 226 | } |
| 227 | |
| 228 | void NavigationMesh::set_vertices_per_polygon(float p_value) { |
| 229 | ERR_FAIL_COND(p_value < 3); |
| 230 | vertices_per_polygon = p_value; |
| 231 | } |
| 232 | |
| 233 | float NavigationMesh::get_vertices_per_polygon() const { |
| 234 | return vertices_per_polygon; |
| 235 | } |
| 236 | |
| 237 | void NavigationMesh::set_detail_sample_distance(float p_value) { |
| 238 | ERR_FAIL_COND(p_value < 0.1); |
| 239 | detail_sample_distance = p_value; |
| 240 | } |
| 241 | |
| 242 | float NavigationMesh::get_detail_sample_distance() const { |
| 243 | return detail_sample_distance; |
| 244 | } |
| 245 | |
| 246 | void NavigationMesh::set_detail_sample_max_error(float p_value) { |
| 247 | ERR_FAIL_COND(p_value < 0); |
| 248 | detail_sample_max_error = p_value; |
| 249 | } |
| 250 | |
| 251 | float NavigationMesh::get_detail_sample_max_error() const { |
| 252 | return detail_sample_max_error; |
| 253 | } |
| 254 | |
| 255 | void NavigationMesh::set_filter_low_hanging_obstacles(bool p_value) { |
| 256 | filter_low_hanging_obstacles = p_value; |
| 257 | } |
| 258 | |
| 259 | bool NavigationMesh::get_filter_low_hanging_obstacles() const { |
| 260 | return filter_low_hanging_obstacles; |
| 261 | } |
| 262 | |
| 263 | void NavigationMesh::set_filter_ledge_spans(bool p_value) { |
| 264 | filter_ledge_spans = p_value; |
| 265 | } |
| 266 | |
| 267 | bool NavigationMesh::get_filter_ledge_spans() const { |
| 268 | return filter_ledge_spans; |
| 269 | } |
| 270 | |
| 271 | void NavigationMesh::set_filter_walkable_low_height_spans(bool p_value) { |
| 272 | filter_walkable_low_height_spans = p_value; |
| 273 | } |
| 274 | |
| 275 | bool NavigationMesh::get_filter_walkable_low_height_spans() const { |
| 276 | return filter_walkable_low_height_spans; |
| 277 | } |
| 278 | |
| 279 | void NavigationMesh::set_filter_baking_aabb(const AABB &p_aabb) { |
| 280 | filter_baking_aabb = p_aabb; |
| 281 | emit_changed(); |
| 282 | } |
| 283 | |
| 284 | AABB NavigationMesh::get_filter_baking_aabb() const { |
| 285 | return filter_baking_aabb; |
| 286 | } |
| 287 | |
| 288 | void NavigationMesh::set_filter_baking_aabb_offset(const Vector3 &p_aabb_offset) { |
| 289 | filter_baking_aabb_offset = p_aabb_offset; |
| 290 | emit_changed(); |
| 291 | } |
| 292 | |
| 293 | Vector3 NavigationMesh::get_filter_baking_aabb_offset() const { |
| 294 | return filter_baking_aabb_offset; |
| 295 | } |
| 296 | |
| 297 | void NavigationMesh::set_vertices(const Vector<Vector3> &p_vertices) { |
| 298 | vertices = p_vertices; |
| 299 | notify_property_list_changed(); |
| 300 | } |
| 301 | |
| 302 | Vector<Vector3> NavigationMesh::get_vertices() const { |
| 303 | return vertices; |
| 304 | } |
| 305 | |
| 306 | void NavigationMesh::_set_polygons(const Array &p_array) { |
| 307 | polygons.resize(p_array.size()); |
| 308 | for (int i = 0; i < p_array.size(); i++) { |
| 309 | polygons.write[i].indices = p_array[i]; |
| 310 | } |
| 311 | notify_property_list_changed(); |
| 312 | } |
| 313 | |
| 314 | Array NavigationMesh::_get_polygons() const { |
| 315 | Array ret; |
| 316 | ret.resize(polygons.size()); |
| 317 | for (int i = 0; i < ret.size(); i++) { |
| 318 | ret[i] = polygons[i].indices; |
| 319 | } |
| 320 | |
| 321 | return ret; |
| 322 | } |
| 323 | |
| 324 | void NavigationMesh::add_polygon(const Vector<int> &p_polygon) { |
| 325 | Polygon polygon; |
| 326 | polygon.indices = p_polygon; |
| 327 | polygons.push_back(polygon); |
| 328 | notify_property_list_changed(); |
| 329 | } |
| 330 | |
| 331 | int NavigationMesh::get_polygon_count() const { |
| 332 | return polygons.size(); |
| 333 | } |
| 334 | |
| 335 | Vector<int> NavigationMesh::get_polygon(int p_idx) { |
| 336 | ERR_FAIL_INDEX_V(p_idx, polygons.size(), Vector<int>()); |
| 337 | return polygons[p_idx].indices; |
| 338 | } |
| 339 | |
| 340 | void NavigationMesh::clear_polygons() { |
| 341 | polygons.clear(); |
| 342 | } |
| 343 | |
| 344 | void NavigationMesh::clear() { |
| 345 | polygons.clear(); |
| 346 | vertices.clear(); |
| 347 | } |
| 348 | |
| 349 | #ifdef DEBUG_ENABLED |
| 350 | Ref<ArrayMesh> NavigationMesh::get_debug_mesh() { |
| 351 | if (debug_mesh.is_valid()) { |
| 352 | // Blocks further updates for now, code below is intended for dynamic updates e.g. when settings change. |
| 353 | return debug_mesh; |
| 354 | } |
| 355 | |
| 356 | if (!debug_mesh.is_valid()) { |
| 357 | debug_mesh = Ref<ArrayMesh>(memnew(ArrayMesh)); |
| 358 | } else { |
| 359 | debug_mesh->clear_surfaces(); |
| 360 | } |
| 361 | |
| 362 | if (vertices.size() == 0) { |
| 363 | return debug_mesh; |
| 364 | } |
| 365 | |
| 366 | int polygon_count = get_polygon_count(); |
| 367 | |
| 368 | if (polygon_count < 1) { |
| 369 | // no face, no play |
| 370 | return debug_mesh; |
| 371 | } |
| 372 | |
| 373 | // build geometry face surface |
| 374 | Vector<Vector3> face_vertex_array; |
| 375 | face_vertex_array.resize(polygon_count * 3); |
| 376 | |
| 377 | for (int i = 0; i < polygon_count; i++) { |
| 378 | Vector<int> polygon = get_polygon(i); |
| 379 | |
| 380 | face_vertex_array.push_back(vertices[polygon[0]]); |
| 381 | face_vertex_array.push_back(vertices[polygon[1]]); |
| 382 | face_vertex_array.push_back(vertices[polygon[2]]); |
| 383 | } |
| 384 | |
| 385 | Array face_mesh_array; |
| 386 | face_mesh_array.resize(Mesh::ARRAY_MAX); |
| 387 | face_mesh_array[Mesh::ARRAY_VERTEX] = face_vertex_array; |
| 388 | |
| 389 | // if enabled add vertex colors to colorize each face individually |
| 390 | bool enabled_geometry_face_random_color = NavigationServer3D::get_singleton()->get_debug_navigation_enable_geometry_face_random_color(); |
| 391 | if (enabled_geometry_face_random_color) { |
| 392 | Color debug_navigation_geometry_face_color = NavigationServer3D::get_singleton()->get_debug_navigation_geometry_face_color(); |
| 393 | Color polygon_color = debug_navigation_geometry_face_color; |
| 394 | |
| 395 | Vector<Color> face_color_array; |
| 396 | face_color_array.resize(polygon_count * 3); |
| 397 | |
| 398 | for (int i = 0; i < polygon_count; i++) { |
| 399 | polygon_color = debug_navigation_geometry_face_color * (Color(Math::randf(), Math::randf(), Math::randf())); |
| 400 | |
| 401 | face_color_array.push_back(polygon_color); |
| 402 | face_color_array.push_back(polygon_color); |
| 403 | face_color_array.push_back(polygon_color); |
| 404 | } |
| 405 | face_mesh_array[Mesh::ARRAY_COLOR] = face_color_array; |
| 406 | } |
| 407 | |
| 408 | debug_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, face_mesh_array); |
| 409 | Ref<StandardMaterial3D> debug_geometry_face_material = NavigationServer3D::get_singleton()->get_debug_navigation_geometry_face_material(); |
| 410 | debug_mesh->surface_set_material(0, debug_geometry_face_material); |
| 411 | |
| 412 | // if enabled build geometry edge line surface |
| 413 | bool enabled_edge_lines = NavigationServer3D::get_singleton()->get_debug_navigation_enable_edge_lines(); |
| 414 | |
| 415 | if (enabled_edge_lines) { |
| 416 | Vector<Vector3> line_vertex_array; |
| 417 | line_vertex_array.resize(polygon_count * 6); |
| 418 | |
| 419 | for (int i = 0; i < polygon_count; i++) { |
| 420 | Vector<int> polygon = get_polygon(i); |
| 421 | |
| 422 | line_vertex_array.push_back(vertices[polygon[0]]); |
| 423 | line_vertex_array.push_back(vertices[polygon[1]]); |
| 424 | line_vertex_array.push_back(vertices[polygon[1]]); |
| 425 | line_vertex_array.push_back(vertices[polygon[2]]); |
| 426 | line_vertex_array.push_back(vertices[polygon[2]]); |
| 427 | line_vertex_array.push_back(vertices[polygon[0]]); |
| 428 | } |
| 429 | |
| 430 | Array line_mesh_array; |
| 431 | line_mesh_array.resize(Mesh::ARRAY_MAX); |
| 432 | line_mesh_array[Mesh::ARRAY_VERTEX] = line_vertex_array; |
| 433 | debug_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_LINES, line_mesh_array); |
| 434 | Ref<StandardMaterial3D> debug_geometry_edge_material = NavigationServer3D::get_singleton()->get_debug_navigation_geometry_edge_material(); |
| 435 | debug_mesh->surface_set_material(1, debug_geometry_edge_material); |
| 436 | } |
| 437 | |
| 438 | return debug_mesh; |
| 439 | } |
| 440 | #endif // DEBUG_ENABLED |
| 441 | |
| 442 | void NavigationMesh::_bind_methods() { |
| 443 | ClassDB::bind_method(D_METHOD("set_sample_partition_type" , "sample_partition_type" ), &NavigationMesh::set_sample_partition_type); |
| 444 | ClassDB::bind_method(D_METHOD("get_sample_partition_type" ), &NavigationMesh::get_sample_partition_type); |
| 445 | |
| 446 | ClassDB::bind_method(D_METHOD("set_parsed_geometry_type" , "geometry_type" ), &NavigationMesh::set_parsed_geometry_type); |
| 447 | ClassDB::bind_method(D_METHOD("get_parsed_geometry_type" ), &NavigationMesh::get_parsed_geometry_type); |
| 448 | |
| 449 | ClassDB::bind_method(D_METHOD("set_collision_mask" , "mask" ), &NavigationMesh::set_collision_mask); |
| 450 | ClassDB::bind_method(D_METHOD("get_collision_mask" ), &NavigationMesh::get_collision_mask); |
| 451 | |
| 452 | ClassDB::bind_method(D_METHOD("set_collision_mask_value" , "layer_number" , "value" ), &NavigationMesh::set_collision_mask_value); |
| 453 | ClassDB::bind_method(D_METHOD("get_collision_mask_value" , "layer_number" ), &NavigationMesh::get_collision_mask_value); |
| 454 | |
| 455 | ClassDB::bind_method(D_METHOD("set_source_geometry_mode" , "mask" ), &NavigationMesh::set_source_geometry_mode); |
| 456 | ClassDB::bind_method(D_METHOD("get_source_geometry_mode" ), &NavigationMesh::get_source_geometry_mode); |
| 457 | |
| 458 | ClassDB::bind_method(D_METHOD("set_source_group_name" , "mask" ), &NavigationMesh::set_source_group_name); |
| 459 | ClassDB::bind_method(D_METHOD("get_source_group_name" ), &NavigationMesh::get_source_group_name); |
| 460 | |
| 461 | ClassDB::bind_method(D_METHOD("set_cell_size" , "cell_size" ), &NavigationMesh::set_cell_size); |
| 462 | ClassDB::bind_method(D_METHOD("get_cell_size" ), &NavigationMesh::get_cell_size); |
| 463 | |
| 464 | ClassDB::bind_method(D_METHOD("set_cell_height" , "cell_height" ), &NavigationMesh::set_cell_height); |
| 465 | ClassDB::bind_method(D_METHOD("get_cell_height" ), &NavigationMesh::get_cell_height); |
| 466 | |
| 467 | ClassDB::bind_method(D_METHOD("set_agent_height" , "agent_height" ), &NavigationMesh::set_agent_height); |
| 468 | ClassDB::bind_method(D_METHOD("get_agent_height" ), &NavigationMesh::get_agent_height); |
| 469 | |
| 470 | ClassDB::bind_method(D_METHOD("set_agent_radius" , "agent_radius" ), &NavigationMesh::set_agent_radius); |
| 471 | ClassDB::bind_method(D_METHOD("get_agent_radius" ), &NavigationMesh::get_agent_radius); |
| 472 | |
| 473 | ClassDB::bind_method(D_METHOD("set_agent_max_climb" , "agent_max_climb" ), &NavigationMesh::set_agent_max_climb); |
| 474 | ClassDB::bind_method(D_METHOD("get_agent_max_climb" ), &NavigationMesh::get_agent_max_climb); |
| 475 | |
| 476 | ClassDB::bind_method(D_METHOD("set_agent_max_slope" , "agent_max_slope" ), &NavigationMesh::set_agent_max_slope); |
| 477 | ClassDB::bind_method(D_METHOD("get_agent_max_slope" ), &NavigationMesh::get_agent_max_slope); |
| 478 | |
| 479 | ClassDB::bind_method(D_METHOD("set_region_min_size" , "region_min_size" ), &NavigationMesh::set_region_min_size); |
| 480 | ClassDB::bind_method(D_METHOD("get_region_min_size" ), &NavigationMesh::get_region_min_size); |
| 481 | |
| 482 | ClassDB::bind_method(D_METHOD("set_region_merge_size" , "region_merge_size" ), &NavigationMesh::set_region_merge_size); |
| 483 | ClassDB::bind_method(D_METHOD("get_region_merge_size" ), &NavigationMesh::get_region_merge_size); |
| 484 | |
| 485 | ClassDB::bind_method(D_METHOD("set_edge_max_length" , "edge_max_length" ), &NavigationMesh::set_edge_max_length); |
| 486 | ClassDB::bind_method(D_METHOD("get_edge_max_length" ), &NavigationMesh::get_edge_max_length); |
| 487 | |
| 488 | ClassDB::bind_method(D_METHOD("set_edge_max_error" , "edge_max_error" ), &NavigationMesh::set_edge_max_error); |
| 489 | ClassDB::bind_method(D_METHOD("get_edge_max_error" ), &NavigationMesh::get_edge_max_error); |
| 490 | |
| 491 | ClassDB::bind_method(D_METHOD("set_vertices_per_polygon" , "vertices_per_polygon" ), &NavigationMesh::set_vertices_per_polygon); |
| 492 | ClassDB::bind_method(D_METHOD("get_vertices_per_polygon" ), &NavigationMesh::get_vertices_per_polygon); |
| 493 | |
| 494 | ClassDB::bind_method(D_METHOD("set_detail_sample_distance" , "detail_sample_dist" ), &NavigationMesh::set_detail_sample_distance); |
| 495 | ClassDB::bind_method(D_METHOD("get_detail_sample_distance" ), &NavigationMesh::get_detail_sample_distance); |
| 496 | |
| 497 | ClassDB::bind_method(D_METHOD("set_detail_sample_max_error" , "detail_sample_max_error" ), &NavigationMesh::set_detail_sample_max_error); |
| 498 | ClassDB::bind_method(D_METHOD("get_detail_sample_max_error" ), &NavigationMesh::get_detail_sample_max_error); |
| 499 | |
| 500 | ClassDB::bind_method(D_METHOD("set_filter_low_hanging_obstacles" , "filter_low_hanging_obstacles" ), &NavigationMesh::set_filter_low_hanging_obstacles); |
| 501 | ClassDB::bind_method(D_METHOD("get_filter_low_hanging_obstacles" ), &NavigationMesh::get_filter_low_hanging_obstacles); |
| 502 | |
| 503 | ClassDB::bind_method(D_METHOD("set_filter_ledge_spans" , "filter_ledge_spans" ), &NavigationMesh::set_filter_ledge_spans); |
| 504 | ClassDB::bind_method(D_METHOD("get_filter_ledge_spans" ), &NavigationMesh::get_filter_ledge_spans); |
| 505 | |
| 506 | ClassDB::bind_method(D_METHOD("set_filter_walkable_low_height_spans" , "filter_walkable_low_height_spans" ), &NavigationMesh::set_filter_walkable_low_height_spans); |
| 507 | ClassDB::bind_method(D_METHOD("get_filter_walkable_low_height_spans" ), &NavigationMesh::get_filter_walkable_low_height_spans); |
| 508 | ClassDB::bind_method(D_METHOD("set_filter_baking_aabb" , "baking_aabb" ), &NavigationMesh::set_filter_baking_aabb); |
| 509 | ClassDB::bind_method(D_METHOD("get_filter_baking_aabb" ), &NavigationMesh::get_filter_baking_aabb); |
| 510 | ClassDB::bind_method(D_METHOD("set_filter_baking_aabb_offset" , "baking_aabb_offset" ), &NavigationMesh::set_filter_baking_aabb_offset); |
| 511 | ClassDB::bind_method(D_METHOD("get_filter_baking_aabb_offset" ), &NavigationMesh::get_filter_baking_aabb_offset); |
| 512 | |
| 513 | ClassDB::bind_method(D_METHOD("set_vertices" , "vertices" ), &NavigationMesh::set_vertices); |
| 514 | ClassDB::bind_method(D_METHOD("get_vertices" ), &NavigationMesh::get_vertices); |
| 515 | |
| 516 | ClassDB::bind_method(D_METHOD("add_polygon" , "polygon" ), &NavigationMesh::add_polygon); |
| 517 | ClassDB::bind_method(D_METHOD("get_polygon_count" ), &NavigationMesh::get_polygon_count); |
| 518 | ClassDB::bind_method(D_METHOD("get_polygon" , "idx" ), &NavigationMesh::get_polygon); |
| 519 | ClassDB::bind_method(D_METHOD("clear_polygons" ), &NavigationMesh::clear_polygons); |
| 520 | |
| 521 | ClassDB::bind_method(D_METHOD("create_from_mesh" , "mesh" ), &NavigationMesh::create_from_mesh); |
| 522 | |
| 523 | ClassDB::bind_method(D_METHOD("_set_polygons" , "polygons" ), &NavigationMesh::_set_polygons); |
| 524 | ClassDB::bind_method(D_METHOD("_get_polygons" ), &NavigationMesh::_get_polygons); |
| 525 | |
| 526 | ClassDB::bind_method(D_METHOD("clear" ), &NavigationMesh::clear); |
| 527 | |
| 528 | ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR3_ARRAY, "vertices" , PROPERTY_HINT_NONE, "" , PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "set_vertices" , "get_vertices" ); |
| 529 | ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "polygons" , PROPERTY_HINT_NONE, "" , PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_polygons" , "_get_polygons" ); |
| 530 | |
| 531 | ADD_GROUP("Sampling" , "sample_" ); |
| 532 | ADD_PROPERTY(PropertyInfo(Variant::INT, "sample_partition_type" , PROPERTY_HINT_ENUM, "Watershed,Monotone,Layers" ), "set_sample_partition_type" , "get_sample_partition_type" ); |
| 533 | ADD_GROUP("Geometry" , "geometry_" ); |
| 534 | 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" ); |
| 535 | ADD_PROPERTY(PropertyInfo(Variant::INT, "geometry_collision_mask" , PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask" , "get_collision_mask" ); |
| 536 | ADD_PROPERTY_DEFAULT("geometry_collision_mask" , 0xFFFFFFFF); |
| 537 | 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" ); |
| 538 | ADD_PROPERTY(PropertyInfo(Variant::STRING, "geometry_source_group_name" ), "set_source_group_name" , "get_source_group_name" ); |
| 539 | ADD_PROPERTY_DEFAULT("geometry_source_group_name" , StringName("navigation_mesh_source_group" )); |
| 540 | ADD_GROUP("Cells" , "cell_" ); |
| 541 | 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" ); |
| 542 | 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" ); |
| 543 | ADD_GROUP("Agents" , "agent_" ); |
| 544 | 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" ); |
| 545 | 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" ); |
| 546 | 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" ); |
| 547 | 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" ); |
| 548 | ADD_GROUP("Regions" , "region_" ); |
| 549 | 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" ); |
| 550 | 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" ); |
| 551 | ADD_GROUP("Edges" , "edge_" ); |
| 552 | 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" ); |
| 553 | 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" ); |
| 554 | ADD_GROUP("Polygons" , "" ); |
| 555 | 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" ); |
| 556 | ADD_GROUP("Details" , "detail_" ); |
| 557 | 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" ); |
| 558 | 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" ); |
| 559 | ADD_GROUP("Filters" , "filter_" ); |
| 560 | ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter_low_hanging_obstacles" ), "set_filter_low_hanging_obstacles" , "get_filter_low_hanging_obstacles" ); |
| 561 | ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter_ledge_spans" ), "set_filter_ledge_spans" , "get_filter_ledge_spans" ); |
| 562 | ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter_walkable_low_height_spans" ), "set_filter_walkable_low_height_spans" , "get_filter_walkable_low_height_spans" ); |
| 563 | ADD_PROPERTY(PropertyInfo(Variant::AABB, "filter_baking_aabb" ), "set_filter_baking_aabb" , "get_filter_baking_aabb" ); |
| 564 | ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "filter_baking_aabb_offset" ), "set_filter_baking_aabb_offset" , "get_filter_baking_aabb_offset" ); |
| 565 | |
| 566 | BIND_ENUM_CONSTANT(SAMPLE_PARTITION_WATERSHED); |
| 567 | BIND_ENUM_CONSTANT(SAMPLE_PARTITION_MONOTONE); |
| 568 | BIND_ENUM_CONSTANT(SAMPLE_PARTITION_LAYERS); |
| 569 | BIND_ENUM_CONSTANT(SAMPLE_PARTITION_MAX); |
| 570 | |
| 571 | BIND_ENUM_CONSTANT(PARSED_GEOMETRY_MESH_INSTANCES); |
| 572 | BIND_ENUM_CONSTANT(PARSED_GEOMETRY_STATIC_COLLIDERS); |
| 573 | BIND_ENUM_CONSTANT(PARSED_GEOMETRY_BOTH); |
| 574 | BIND_ENUM_CONSTANT(PARSED_GEOMETRY_MAX); |
| 575 | |
| 576 | BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_ROOT_NODE_CHILDREN); |
| 577 | BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN); |
| 578 | BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_GROUPS_EXPLICIT); |
| 579 | BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_MAX); |
| 580 | } |
| 581 | |
| 582 | void NavigationMesh::_validate_property(PropertyInfo &p_property) const { |
| 583 | if (p_property.name == "geometry_collision_mask" ) { |
| 584 | if (parsed_geometry_type == PARSED_GEOMETRY_MESH_INSTANCES) { |
| 585 | p_property.usage = PROPERTY_USAGE_NONE; |
| 586 | return; |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | if (p_property.name == "geometry_source_group_name" ) { |
| 591 | if (source_geometry_mode == SOURCE_GEOMETRY_ROOT_NODE_CHILDREN) { |
| 592 | p_property.usage = PROPERTY_USAGE_NONE; |
| 593 | return; |
| 594 | } |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | #ifndef DISABLE_DEPRECATED |
| 599 | bool NavigationMesh::_set(const StringName &p_name, const Variant &p_value) { |
| 600 | if (p_name == "polygon_verts_per_poly" ) { // Renamed in 4.0 beta 9. |
| 601 | set_vertices_per_polygon(p_value); |
| 602 | return true; |
| 603 | } |
| 604 | return false; |
| 605 | } |
| 606 | |
| 607 | bool NavigationMesh::_get(const StringName &p_name, Variant &r_ret) const { |
| 608 | if (p_name == "polygon_verts_per_poly" ) { // Renamed in 4.0 beta 9. |
| 609 | r_ret = get_vertices_per_polygon(); |
| 610 | return true; |
| 611 | } |
| 612 | return false; |
| 613 | } |
| 614 | #endif // DISABLE_DEPRECATED |
| 615 | |
| 616 | NavigationMesh::NavigationMesh() {} |
| 617 | |