navigation_mesh.cpp 25 KB

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