navigation_mesh.cpp 24 KB

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