navigation_mesh.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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. #include "navigation_mesh.h"
  31. #ifdef DEBUG_ENABLED
  32. #include "servers/navigation_server_3d.h"
  33. #endif // DEBUG_ENABLED
  34. void NavigationMesh::create_from_mesh(const Ref<Mesh> &p_mesh) {
  35. RWLockWrite write_lock(rwlock);
  36. ERR_FAIL_COND(p_mesh.is_null());
  37. vertices = Vector<Vector3>();
  38. polygons.clear();
  39. for (int i = 0; i < p_mesh->get_surface_count(); i++) {
  40. if (p_mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) {
  41. 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.");
  42. continue;
  43. }
  44. Array arr = p_mesh->surface_get_arrays(i);
  45. ERR_CONTINUE(arr.size() != Mesh::ARRAY_MAX);
  46. Vector<Vector3> varr = arr[Mesh::ARRAY_VERTEX];
  47. Vector<int> iarr = arr[Mesh::ARRAY_INDEX];
  48. if (varr.size() == 0 || iarr.size() == 0) {
  49. WARN_PRINT("A mesh surface was skipped when creating a NavigationMesh due to an empty vertex or index array.");
  50. continue;
  51. }
  52. int from = vertices.size();
  53. vertices.append_array(varr);
  54. int rlen = iarr.size();
  55. const int *r = iarr.ptr();
  56. Vector<int> polygon;
  57. for (int j = 0; j < rlen; j += 3) {
  58. polygon.resize(3);
  59. polygon.write[0] = r[j + 0] + from;
  60. polygon.write[1] = r[j + 1] + from;
  61. polygon.write[2] = r[j + 2] + from;
  62. polygons.push_back(polygon);
  63. }
  64. }
  65. }
  66. void NavigationMesh::set_sample_partition_type(SamplePartitionType p_value) {
  67. ERR_FAIL_INDEX(p_value, SAMPLE_PARTITION_MAX);
  68. partition_type = p_value;
  69. }
  70. NavigationMesh::SamplePartitionType NavigationMesh::get_sample_partition_type() const {
  71. return partition_type;
  72. }
  73. void NavigationMesh::set_parsed_geometry_type(ParsedGeometryType p_value) {
  74. ERR_FAIL_INDEX(p_value, PARSED_GEOMETRY_MAX);
  75. parsed_geometry_type = p_value;
  76. notify_property_list_changed();
  77. }
  78. NavigationMesh::ParsedGeometryType NavigationMesh::get_parsed_geometry_type() const {
  79. return parsed_geometry_type;
  80. }
  81. void NavigationMesh::set_collision_mask(uint32_t p_mask) {
  82. collision_mask = p_mask;
  83. }
  84. uint32_t NavigationMesh::get_collision_mask() const {
  85. return collision_mask;
  86. }
  87. void NavigationMesh::set_collision_mask_value(int p_layer_number, bool p_value) {
  88. ERR_FAIL_COND_MSG(p_layer_number < 1, "Collision layer number must be between 1 and 32 inclusive.");
  89. ERR_FAIL_COND_MSG(p_layer_number > 32, "Collision layer number must be between 1 and 32 inclusive.");
  90. uint32_t mask = get_collision_mask();
  91. if (p_value) {
  92. mask |= 1 << (p_layer_number - 1);
  93. } else {
  94. mask &= ~(1 << (p_layer_number - 1));
  95. }
  96. set_collision_mask(mask);
  97. }
  98. bool NavigationMesh::get_collision_mask_value(int p_layer_number) const {
  99. ERR_FAIL_COND_V_MSG(p_layer_number < 1, false, "Collision layer number must be between 1 and 32 inclusive.");
  100. ERR_FAIL_COND_V_MSG(p_layer_number > 32, false, "Collision layer number must be between 1 and 32 inclusive.");
  101. return get_collision_mask() & (1 << (p_layer_number - 1));
  102. }
  103. void NavigationMesh::set_source_geometry_mode(SourceGeometryMode p_geometry_mode) {
  104. ERR_FAIL_INDEX(p_geometry_mode, SOURCE_GEOMETRY_MAX);
  105. source_geometry_mode = p_geometry_mode;
  106. notify_property_list_changed();
  107. }
  108. NavigationMesh::SourceGeometryMode NavigationMesh::get_source_geometry_mode() const {
  109. return source_geometry_mode;
  110. }
  111. void NavigationMesh::set_source_group_name(const StringName &p_group_name) {
  112. source_group_name = p_group_name;
  113. }
  114. StringName NavigationMesh::get_source_group_name() const {
  115. return source_group_name;
  116. }
  117. void NavigationMesh::set_cell_size(float p_value) {
  118. ERR_FAIL_COND(p_value <= 0);
  119. cell_size = p_value;
  120. }
  121. float NavigationMesh::get_cell_size() const {
  122. return cell_size;
  123. }
  124. void NavigationMesh::set_cell_height(float p_value) {
  125. ERR_FAIL_COND(p_value <= 0);
  126. cell_height = p_value;
  127. }
  128. float NavigationMesh::get_cell_height() const {
  129. return cell_height;
  130. }
  131. void NavigationMesh::set_border_size(float p_value) {
  132. ERR_FAIL_COND(p_value < 0);
  133. border_size = p_value;
  134. }
  135. float NavigationMesh::get_border_size() const {
  136. return border_size;
  137. }
  138. void NavigationMesh::set_agent_height(float p_value) {
  139. ERR_FAIL_COND(p_value < 0);
  140. agent_height = p_value;
  141. }
  142. float NavigationMesh::get_agent_height() const {
  143. return agent_height;
  144. }
  145. void NavigationMesh::set_agent_radius(float p_value) {
  146. ERR_FAIL_COND(p_value < 0);
  147. agent_radius = p_value;
  148. }
  149. float NavigationMesh::get_agent_radius() {
  150. return agent_radius;
  151. }
  152. void NavigationMesh::set_agent_max_climb(float p_value) {
  153. ERR_FAIL_COND(p_value < 0);
  154. agent_max_climb = p_value;
  155. }
  156. float NavigationMesh::get_agent_max_climb() const {
  157. return agent_max_climb;
  158. }
  159. void NavigationMesh::set_agent_max_slope(float p_value) {
  160. ERR_FAIL_COND(p_value < 0 || p_value > 90);
  161. agent_max_slope = p_value;
  162. }
  163. float NavigationMesh::get_agent_max_slope() const {
  164. return agent_max_slope;
  165. }
  166. void NavigationMesh::set_region_min_size(float p_value) {
  167. ERR_FAIL_COND(p_value < 0);
  168. region_min_size = p_value;
  169. }
  170. float NavigationMesh::get_region_min_size() const {
  171. return region_min_size;
  172. }
  173. void NavigationMesh::set_region_merge_size(float p_value) {
  174. ERR_FAIL_COND(p_value < 0);
  175. region_merge_size = p_value;
  176. }
  177. float NavigationMesh::get_region_merge_size() const {
  178. return region_merge_size;
  179. }
  180. void NavigationMesh::set_edge_max_length(float p_value) {
  181. ERR_FAIL_COND(p_value < 0);
  182. edge_max_length = p_value;
  183. }
  184. float NavigationMesh::get_edge_max_length() const {
  185. return edge_max_length;
  186. }
  187. void NavigationMesh::set_edge_max_error(float p_value) {
  188. ERR_FAIL_COND(p_value < 0);
  189. edge_max_error = p_value;
  190. }
  191. float NavigationMesh::get_edge_max_error() const {
  192. return edge_max_error;
  193. }
  194. void NavigationMesh::set_vertices_per_polygon(float p_value) {
  195. ERR_FAIL_COND(p_value < 3);
  196. vertices_per_polygon = p_value;
  197. }
  198. float NavigationMesh::get_vertices_per_polygon() const {
  199. return vertices_per_polygon;
  200. }
  201. void NavigationMesh::set_detail_sample_distance(float p_value) {
  202. ERR_FAIL_COND(p_value < 0.1);
  203. detail_sample_distance = p_value;
  204. }
  205. float NavigationMesh::get_detail_sample_distance() const {
  206. return detail_sample_distance;
  207. }
  208. void NavigationMesh::set_detail_sample_max_error(float p_value) {
  209. ERR_FAIL_COND(p_value < 0);
  210. detail_sample_max_error = p_value;
  211. }
  212. float NavigationMesh::get_detail_sample_max_error() const {
  213. return detail_sample_max_error;
  214. }
  215. void NavigationMesh::set_filter_low_hanging_obstacles(bool p_value) {
  216. filter_low_hanging_obstacles = p_value;
  217. }
  218. bool NavigationMesh::get_filter_low_hanging_obstacles() const {
  219. return filter_low_hanging_obstacles;
  220. }
  221. void NavigationMesh::set_filter_ledge_spans(bool p_value) {
  222. filter_ledge_spans = p_value;
  223. }
  224. bool NavigationMesh::get_filter_ledge_spans() const {
  225. return filter_ledge_spans;
  226. }
  227. void NavigationMesh::set_filter_walkable_low_height_spans(bool p_value) {
  228. filter_walkable_low_height_spans = p_value;
  229. }
  230. bool NavigationMesh::get_filter_walkable_low_height_spans() const {
  231. return filter_walkable_low_height_spans;
  232. }
  233. void NavigationMesh::set_filter_baking_aabb(const AABB &p_aabb) {
  234. filter_baking_aabb = p_aabb;
  235. emit_changed();
  236. }
  237. AABB NavigationMesh::get_filter_baking_aabb() const {
  238. return filter_baking_aabb;
  239. }
  240. void NavigationMesh::set_filter_baking_aabb_offset(const Vector3 &p_aabb_offset) {
  241. filter_baking_aabb_offset = p_aabb_offset;
  242. emit_changed();
  243. }
  244. Vector3 NavigationMesh::get_filter_baking_aabb_offset() const {
  245. return filter_baking_aabb_offset;
  246. }
  247. void NavigationMesh::set_vertices(const Vector<Vector3> &p_vertices) {
  248. RWLockWrite write_lock(rwlock);
  249. vertices = p_vertices;
  250. notify_property_list_changed();
  251. }
  252. Vector<Vector3> NavigationMesh::get_vertices() const {
  253. RWLockRead read_lock(rwlock);
  254. return vertices;
  255. }
  256. void NavigationMesh::_set_polygons(const Array &p_array) {
  257. RWLockWrite write_lock(rwlock);
  258. polygons.resize(p_array.size());
  259. for (int i = 0; i < p_array.size(); i++) {
  260. polygons.write[i] = p_array[i];
  261. }
  262. notify_property_list_changed();
  263. }
  264. Array NavigationMesh::_get_polygons() const {
  265. RWLockRead read_lock(rwlock);
  266. Array ret;
  267. ret.resize(polygons.size());
  268. for (int i = 0; i < ret.size(); i++) {
  269. ret[i] = polygons[i];
  270. }
  271. return ret;
  272. }
  273. void NavigationMesh::set_polygons(const Vector<Vector<int>> &p_polygons) {
  274. RWLockWrite write_lock(rwlock);
  275. polygons = p_polygons;
  276. notify_property_list_changed();
  277. }
  278. Vector<Vector<int>> NavigationMesh::get_polygons() const {
  279. RWLockRead read_lock(rwlock);
  280. return polygons;
  281. }
  282. void NavigationMesh::add_polygon(const Vector<int> &p_polygon) {
  283. RWLockWrite write_lock(rwlock);
  284. polygons.push_back(p_polygon);
  285. notify_property_list_changed();
  286. }
  287. int NavigationMesh::get_polygon_count() const {
  288. RWLockRead read_lock(rwlock);
  289. return polygons.size();
  290. }
  291. Vector<int> NavigationMesh::get_polygon(int p_idx) {
  292. RWLockRead read_lock(rwlock);
  293. ERR_FAIL_INDEX_V(p_idx, polygons.size(), Vector<int>());
  294. return polygons[p_idx];
  295. }
  296. void NavigationMesh::clear_polygons() {
  297. RWLockWrite write_lock(rwlock);
  298. polygons.clear();
  299. }
  300. void NavigationMesh::clear() {
  301. RWLockWrite write_lock(rwlock);
  302. polygons.clear();
  303. vertices.clear();
  304. }
  305. void NavigationMesh::set_data(const Vector<Vector3> &p_vertices, const Vector<Vector<int>> &p_polygons) {
  306. RWLockWrite write_lock(rwlock);
  307. vertices = p_vertices;
  308. polygons = p_polygons;
  309. }
  310. void NavigationMesh::get_data(Vector<Vector3> &r_vertices, Vector<Vector<int>> &r_polygons) {
  311. RWLockRead read_lock(rwlock);
  312. r_vertices = vertices;
  313. r_polygons = polygons;
  314. }
  315. #ifdef DEBUG_ENABLED
  316. Ref<ArrayMesh> NavigationMesh::get_debug_mesh() {
  317. if (debug_mesh.is_valid()) {
  318. // Blocks further updates for now, code below is intended for dynamic updates e.g. when settings change.
  319. return debug_mesh;
  320. }
  321. if (debug_mesh.is_null()) {
  322. debug_mesh.instantiate();
  323. } else {
  324. debug_mesh->clear_surfaces();
  325. }
  326. if (vertices.size() == 0) {
  327. return debug_mesh;
  328. }
  329. RWLockRead read_lock(rwlock);
  330. int polygon_count = get_polygon_count();
  331. if (polygon_count < 1) {
  332. // no face, no play
  333. return debug_mesh;
  334. }
  335. // build geometry face surface
  336. Vector<Vector3> face_vertex_array;
  337. face_vertex_array.resize(polygon_count * 3);
  338. for (int i = 0; i < polygon_count; i++) {
  339. Vector<int> polygon = get_polygon(i);
  340. face_vertex_array.push_back(vertices[polygon[0]]);
  341. face_vertex_array.push_back(vertices[polygon[1]]);
  342. face_vertex_array.push_back(vertices[polygon[2]]);
  343. }
  344. Array face_mesh_array;
  345. face_mesh_array.resize(Mesh::ARRAY_MAX);
  346. face_mesh_array[Mesh::ARRAY_VERTEX] = face_vertex_array;
  347. // if enabled add vertex colors to colorize each face individually
  348. bool enabled_geometry_face_random_color = NavigationServer3D::get_singleton()->get_debug_navigation_enable_geometry_face_random_color();
  349. if (enabled_geometry_face_random_color) {
  350. Color debug_navigation_geometry_face_color = NavigationServer3D::get_singleton()->get_debug_navigation_geometry_face_color();
  351. Color polygon_color = debug_navigation_geometry_face_color;
  352. Vector<Color> face_color_array;
  353. face_color_array.resize(polygon_count * 3);
  354. for (int i = 0; i < polygon_count; i++) {
  355. polygon_color = debug_navigation_geometry_face_color * (Color(Math::randf(), Math::randf(), Math::randf()));
  356. face_color_array.push_back(polygon_color);
  357. face_color_array.push_back(polygon_color);
  358. face_color_array.push_back(polygon_color);
  359. }
  360. face_mesh_array[Mesh::ARRAY_COLOR] = face_color_array;
  361. }
  362. debug_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, face_mesh_array);
  363. Ref<StandardMaterial3D> debug_geometry_face_material = NavigationServer3D::get_singleton()->get_debug_navigation_geometry_face_material();
  364. debug_mesh->surface_set_material(0, debug_geometry_face_material);
  365. // if enabled build geometry edge line surface
  366. bool enabled_edge_lines = NavigationServer3D::get_singleton()->get_debug_navigation_enable_edge_lines();
  367. if (enabled_edge_lines) {
  368. Vector<Vector3> line_vertex_array;
  369. line_vertex_array.resize(polygon_count * 6);
  370. for (int i = 0; i < polygon_count; i++) {
  371. Vector<int> polygon = get_polygon(i);
  372. line_vertex_array.push_back(vertices[polygon[0]]);
  373. line_vertex_array.push_back(vertices[polygon[1]]);
  374. line_vertex_array.push_back(vertices[polygon[1]]);
  375. line_vertex_array.push_back(vertices[polygon[2]]);
  376. line_vertex_array.push_back(vertices[polygon[2]]);
  377. line_vertex_array.push_back(vertices[polygon[0]]);
  378. }
  379. Array line_mesh_array;
  380. line_mesh_array.resize(Mesh::ARRAY_MAX);
  381. line_mesh_array[Mesh::ARRAY_VERTEX] = line_vertex_array;
  382. debug_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_LINES, line_mesh_array);
  383. Ref<StandardMaterial3D> debug_geometry_edge_material = NavigationServer3D::get_singleton()->get_debug_navigation_geometry_edge_material();
  384. debug_mesh->surface_set_material(1, debug_geometry_edge_material);
  385. }
  386. return debug_mesh;
  387. }
  388. #endif // DEBUG_ENABLED
  389. void NavigationMesh::_bind_methods() {
  390. ClassDB::bind_method(D_METHOD("set_sample_partition_type", "sample_partition_type"), &NavigationMesh::set_sample_partition_type);
  391. ClassDB::bind_method(D_METHOD("get_sample_partition_type"), &NavigationMesh::get_sample_partition_type);
  392. ClassDB::bind_method(D_METHOD("set_parsed_geometry_type", "geometry_type"), &NavigationMesh::set_parsed_geometry_type);
  393. ClassDB::bind_method(D_METHOD("get_parsed_geometry_type"), &NavigationMesh::get_parsed_geometry_type);
  394. ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &NavigationMesh::set_collision_mask);
  395. ClassDB::bind_method(D_METHOD("get_collision_mask"), &NavigationMesh::get_collision_mask);
  396. ClassDB::bind_method(D_METHOD("set_collision_mask_value", "layer_number", "value"), &NavigationMesh::set_collision_mask_value);
  397. ClassDB::bind_method(D_METHOD("get_collision_mask_value", "layer_number"), &NavigationMesh::get_collision_mask_value);
  398. ClassDB::bind_method(D_METHOD("set_source_geometry_mode", "mask"), &NavigationMesh::set_source_geometry_mode);
  399. ClassDB::bind_method(D_METHOD("get_source_geometry_mode"), &NavigationMesh::get_source_geometry_mode);
  400. ClassDB::bind_method(D_METHOD("set_source_group_name", "mask"), &NavigationMesh::set_source_group_name);
  401. ClassDB::bind_method(D_METHOD("get_source_group_name"), &NavigationMesh::get_source_group_name);
  402. ClassDB::bind_method(D_METHOD("set_cell_size", "cell_size"), &NavigationMesh::set_cell_size);
  403. ClassDB::bind_method(D_METHOD("get_cell_size"), &NavigationMesh::get_cell_size);
  404. ClassDB::bind_method(D_METHOD("set_cell_height", "cell_height"), &NavigationMesh::set_cell_height);
  405. ClassDB::bind_method(D_METHOD("get_cell_height"), &NavigationMesh::get_cell_height);
  406. ClassDB::bind_method(D_METHOD("set_border_size", "border_size"), &NavigationMesh::set_border_size);
  407. ClassDB::bind_method(D_METHOD("get_border_size"), &NavigationMesh::get_border_size);
  408. ClassDB::bind_method(D_METHOD("set_agent_height", "agent_height"), &NavigationMesh::set_agent_height);
  409. ClassDB::bind_method(D_METHOD("get_agent_height"), &NavigationMesh::get_agent_height);
  410. ClassDB::bind_method(D_METHOD("set_agent_radius", "agent_radius"), &NavigationMesh::set_agent_radius);
  411. ClassDB::bind_method(D_METHOD("get_agent_radius"), &NavigationMesh::get_agent_radius);
  412. ClassDB::bind_method(D_METHOD("set_agent_max_climb", "agent_max_climb"), &NavigationMesh::set_agent_max_climb);
  413. ClassDB::bind_method(D_METHOD("get_agent_max_climb"), &NavigationMesh::get_agent_max_climb);
  414. ClassDB::bind_method(D_METHOD("set_agent_max_slope", "agent_max_slope"), &NavigationMesh::set_agent_max_slope);
  415. ClassDB::bind_method(D_METHOD("get_agent_max_slope"), &NavigationMesh::get_agent_max_slope);
  416. ClassDB::bind_method(D_METHOD("set_region_min_size", "region_min_size"), &NavigationMesh::set_region_min_size);
  417. ClassDB::bind_method(D_METHOD("get_region_min_size"), &NavigationMesh::get_region_min_size);
  418. ClassDB::bind_method(D_METHOD("set_region_merge_size", "region_merge_size"), &NavigationMesh::set_region_merge_size);
  419. ClassDB::bind_method(D_METHOD("get_region_merge_size"), &NavigationMesh::get_region_merge_size);
  420. ClassDB::bind_method(D_METHOD("set_edge_max_length", "edge_max_length"), &NavigationMesh::set_edge_max_length);
  421. ClassDB::bind_method(D_METHOD("get_edge_max_length"), &NavigationMesh::get_edge_max_length);
  422. ClassDB::bind_method(D_METHOD("set_edge_max_error", "edge_max_error"), &NavigationMesh::set_edge_max_error);
  423. ClassDB::bind_method(D_METHOD("get_edge_max_error"), &NavigationMesh::get_edge_max_error);
  424. ClassDB::bind_method(D_METHOD("set_vertices_per_polygon", "vertices_per_polygon"), &NavigationMesh::set_vertices_per_polygon);
  425. ClassDB::bind_method(D_METHOD("get_vertices_per_polygon"), &NavigationMesh::get_vertices_per_polygon);
  426. ClassDB::bind_method(D_METHOD("set_detail_sample_distance", "detail_sample_dist"), &NavigationMesh::set_detail_sample_distance);
  427. ClassDB::bind_method(D_METHOD("get_detail_sample_distance"), &NavigationMesh::get_detail_sample_distance);
  428. ClassDB::bind_method(D_METHOD("set_detail_sample_max_error", "detail_sample_max_error"), &NavigationMesh::set_detail_sample_max_error);
  429. ClassDB::bind_method(D_METHOD("get_detail_sample_max_error"), &NavigationMesh::get_detail_sample_max_error);
  430. ClassDB::bind_method(D_METHOD("set_filter_low_hanging_obstacles", "filter_low_hanging_obstacles"), &NavigationMesh::set_filter_low_hanging_obstacles);
  431. ClassDB::bind_method(D_METHOD("get_filter_low_hanging_obstacles"), &NavigationMesh::get_filter_low_hanging_obstacles);
  432. ClassDB::bind_method(D_METHOD("set_filter_ledge_spans", "filter_ledge_spans"), &NavigationMesh::set_filter_ledge_spans);
  433. ClassDB::bind_method(D_METHOD("get_filter_ledge_spans"), &NavigationMesh::get_filter_ledge_spans);
  434. ClassDB::bind_method(D_METHOD("set_filter_walkable_low_height_spans", "filter_walkable_low_height_spans"), &NavigationMesh::set_filter_walkable_low_height_spans);
  435. ClassDB::bind_method(D_METHOD("get_filter_walkable_low_height_spans"), &NavigationMesh::get_filter_walkable_low_height_spans);
  436. ClassDB::bind_method(D_METHOD("set_filter_baking_aabb", "baking_aabb"), &NavigationMesh::set_filter_baking_aabb);
  437. ClassDB::bind_method(D_METHOD("get_filter_baking_aabb"), &NavigationMesh::get_filter_baking_aabb);
  438. ClassDB::bind_method(D_METHOD("set_filter_baking_aabb_offset", "baking_aabb_offset"), &NavigationMesh::set_filter_baking_aabb_offset);
  439. ClassDB::bind_method(D_METHOD("get_filter_baking_aabb_offset"), &NavigationMesh::get_filter_baking_aabb_offset);
  440. ClassDB::bind_method(D_METHOD("set_vertices", "vertices"), &NavigationMesh::set_vertices);
  441. ClassDB::bind_method(D_METHOD("get_vertices"), &NavigationMesh::get_vertices);
  442. ClassDB::bind_method(D_METHOD("add_polygon", "polygon"), &NavigationMesh::add_polygon);
  443. ClassDB::bind_method(D_METHOD("get_polygon_count"), &NavigationMesh::get_polygon_count);
  444. ClassDB::bind_method(D_METHOD("get_polygon", "idx"), &NavigationMesh::get_polygon);
  445. ClassDB::bind_method(D_METHOD("clear_polygons"), &NavigationMesh::clear_polygons);
  446. ClassDB::bind_method(D_METHOD("create_from_mesh", "mesh"), &NavigationMesh::create_from_mesh);
  447. ClassDB::bind_method(D_METHOD("_set_polygons", "polygons"), &NavigationMesh::_set_polygons);
  448. ClassDB::bind_method(D_METHOD("_get_polygons"), &NavigationMesh::_get_polygons);
  449. ClassDB::bind_method(D_METHOD("clear"), &NavigationMesh::clear);
  450. ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR3_ARRAY, "vertices", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "set_vertices", "get_vertices");
  451. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "polygons", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_polygons", "_get_polygons");
  452. ADD_GROUP("Sampling", "sample_");
  453. ADD_PROPERTY(PropertyInfo(Variant::INT, "sample_partition_type", PROPERTY_HINT_ENUM, "Watershed,Monotone,Layers"), "set_sample_partition_type", "get_sample_partition_type");
  454. ADD_GROUP("Geometry", "geometry_");
  455. 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");
  456. ADD_PROPERTY(PropertyInfo(Variant::INT, "geometry_collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask");
  457. ADD_PROPERTY_DEFAULT("geometry_collision_mask", 0xFFFFFFFF);
  458. 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");
  459. ADD_PROPERTY(PropertyInfo(Variant::STRING, "geometry_source_group_name"), "set_source_group_name", "get_source_group_name");
  460. ADD_PROPERTY_DEFAULT("geometry_source_group_name", StringName("navigation_mesh_source_group"));
  461. ADD_GROUP("Cells", "");
  462. 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");
  463. 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");
  464. 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");
  465. ADD_GROUP("Agents", "agent_");
  466. 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");
  467. 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");
  468. 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");
  469. 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");
  470. ADD_GROUP("Regions", "region_");
  471. 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");
  472. 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");
  473. ADD_GROUP("Edges", "edge_");
  474. 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");
  475. 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");
  476. ADD_GROUP("Polygons", "");
  477. 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");
  478. ADD_GROUP("Details", "detail_");
  479. 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");
  480. 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");
  481. ADD_GROUP("Filters", "filter_");
  482. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter_low_hanging_obstacles"), "set_filter_low_hanging_obstacles", "get_filter_low_hanging_obstacles");
  483. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter_ledge_spans"), "set_filter_ledge_spans", "get_filter_ledge_spans");
  484. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter_walkable_low_height_spans"), "set_filter_walkable_low_height_spans", "get_filter_walkable_low_height_spans");
  485. ADD_PROPERTY(PropertyInfo(Variant::AABB, "filter_baking_aabb"), "set_filter_baking_aabb", "get_filter_baking_aabb");
  486. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "filter_baking_aabb_offset"), "set_filter_baking_aabb_offset", "get_filter_baking_aabb_offset");
  487. BIND_ENUM_CONSTANT(SAMPLE_PARTITION_WATERSHED);
  488. BIND_ENUM_CONSTANT(SAMPLE_PARTITION_MONOTONE);
  489. BIND_ENUM_CONSTANT(SAMPLE_PARTITION_LAYERS);
  490. BIND_ENUM_CONSTANT(SAMPLE_PARTITION_MAX);
  491. BIND_ENUM_CONSTANT(PARSED_GEOMETRY_MESH_INSTANCES);
  492. BIND_ENUM_CONSTANT(PARSED_GEOMETRY_STATIC_COLLIDERS);
  493. BIND_ENUM_CONSTANT(PARSED_GEOMETRY_BOTH);
  494. BIND_ENUM_CONSTANT(PARSED_GEOMETRY_MAX);
  495. BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_ROOT_NODE_CHILDREN);
  496. BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN);
  497. BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_GROUPS_EXPLICIT);
  498. BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_MAX);
  499. }
  500. void NavigationMesh::_validate_property(PropertyInfo &p_property) const {
  501. if (p_property.name == "geometry_collision_mask") {
  502. if (parsed_geometry_type == PARSED_GEOMETRY_MESH_INSTANCES) {
  503. p_property.usage = PROPERTY_USAGE_NONE;
  504. return;
  505. }
  506. }
  507. if (p_property.name == "geometry_source_group_name") {
  508. if (source_geometry_mode == SOURCE_GEOMETRY_ROOT_NODE_CHILDREN) {
  509. p_property.usage = PROPERTY_USAGE_NONE;
  510. return;
  511. }
  512. }
  513. }
  514. #ifndef DISABLE_DEPRECATED
  515. bool NavigationMesh::_set(const StringName &p_name, const Variant &p_value) {
  516. if (p_name == "polygon_verts_per_poly") { // Renamed in 4.0 beta 9.
  517. set_vertices_per_polygon(p_value);
  518. return true;
  519. }
  520. return false;
  521. }
  522. bool NavigationMesh::_get(const StringName &p_name, Variant &r_ret) const {
  523. if (p_name == "polygon_verts_per_poly") { // Renamed in 4.0 beta 9.
  524. r_ret = get_vertices_per_polygon();
  525. return true;
  526. }
  527. return false;
  528. }
  529. #endif // DISABLE_DEPRECATED