navigation_mesh.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. /*************************************************************************/
  2. /* navigation_mesh.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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 = Vector<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. continue;
  38. }
  39. Array arr = p_mesh->surface_get_arrays(i);
  40. Vector<Vector3> varr = arr[Mesh::ARRAY_VERTEX];
  41. Vector<int> iarr = arr[Mesh::ARRAY_INDEX];
  42. if (varr.size() == 0 || iarr.size() == 0) {
  43. continue;
  44. }
  45. int from = vertices.size();
  46. vertices.append_array(varr);
  47. int rlen = iarr.size();
  48. const int *r = iarr.ptr();
  49. for (int j = 0; j < rlen; j += 3) {
  50. Vector<int> vi;
  51. vi.resize(3);
  52. vi.write[0] = r[j + 0] + from;
  53. vi.write[1] = r[j + 1] + from;
  54. vi.write[2] = r[j + 2] + from;
  55. add_polygon(vi);
  56. }
  57. }
  58. }
  59. void NavigationMesh::set_sample_partition_type(SamplePartitionType p_value) {
  60. ERR_FAIL_INDEX(p_value, SAMPLE_PARTITION_MAX);
  61. partition_type = p_value;
  62. }
  63. NavigationMesh::SamplePartitionType NavigationMesh::get_sample_partition_type() const {
  64. return partition_type;
  65. }
  66. void NavigationMesh::set_parsed_geometry_type(ParsedGeometryType p_value) {
  67. ERR_FAIL_INDEX(p_value, PARSED_GEOMETRY_MAX);
  68. parsed_geometry_type = p_value;
  69. notify_property_list_changed();
  70. }
  71. NavigationMesh::ParsedGeometryType NavigationMesh::get_parsed_geometry_type() const {
  72. return parsed_geometry_type;
  73. }
  74. void NavigationMesh::set_collision_mask(uint32_t p_mask) {
  75. collision_mask = p_mask;
  76. }
  77. uint32_t NavigationMesh::get_collision_mask() const {
  78. return collision_mask;
  79. }
  80. void NavigationMesh::set_collision_mask_bit(int p_bit, bool p_value) {
  81. ERR_FAIL_INDEX_MSG(p_bit, 32, "Collision mask bit must be between 0 and 31 inclusive.");
  82. uint32_t mask = get_collision_mask();
  83. if (p_value) {
  84. mask |= 1 << p_bit;
  85. } else {
  86. mask &= ~(1 << p_bit);
  87. }
  88. set_collision_mask(mask);
  89. }
  90. bool NavigationMesh::get_collision_mask_bit(int p_bit) const {
  91. ERR_FAIL_INDEX_V_MSG(p_bit, 32, false, "Collision mask bit must be between 0 and 31 inclusive.");
  92. return get_collision_mask() & (1 << p_bit);
  93. }
  94. void NavigationMesh::set_source_geometry_mode(SourceGeometryMode p_geometry_mode) {
  95. ERR_FAIL_INDEX(p_geometry_mode, SOURCE_GEOMETRY_MAX);
  96. source_geometry_mode = p_geometry_mode;
  97. notify_property_list_changed();
  98. }
  99. NavigationMesh::SourceGeometryMode NavigationMesh::get_source_geometry_mode() const {
  100. return source_geometry_mode;
  101. }
  102. void NavigationMesh::set_source_group_name(StringName p_group_name) {
  103. source_group_name = p_group_name;
  104. }
  105. StringName NavigationMesh::get_source_group_name() const {
  106. return source_group_name;
  107. }
  108. void NavigationMesh::set_cell_size(float p_value) {
  109. ERR_FAIL_COND(p_value <= 0);
  110. cell_size = p_value;
  111. }
  112. float NavigationMesh::get_cell_size() const {
  113. return cell_size;
  114. }
  115. void NavigationMesh::set_cell_height(float p_value) {
  116. ERR_FAIL_COND(p_value <= 0);
  117. cell_height = p_value;
  118. }
  119. float NavigationMesh::get_cell_height() const {
  120. return cell_height;
  121. }
  122. void NavigationMesh::set_agent_height(float p_value) {
  123. ERR_FAIL_COND(p_value < 0);
  124. agent_height = p_value;
  125. }
  126. float NavigationMesh::get_agent_height() const {
  127. return agent_height;
  128. }
  129. void NavigationMesh::set_agent_radius(float p_value) {
  130. ERR_FAIL_COND(p_value < 0);
  131. agent_radius = p_value;
  132. }
  133. float NavigationMesh::get_agent_radius() {
  134. return agent_radius;
  135. }
  136. void NavigationMesh::set_agent_max_climb(float p_value) {
  137. ERR_FAIL_COND(p_value < 0);
  138. agent_max_climb = p_value;
  139. }
  140. float NavigationMesh::get_agent_max_climb() const {
  141. return agent_max_climb;
  142. }
  143. void NavigationMesh::set_agent_max_slope(float p_value) {
  144. ERR_FAIL_COND(p_value < 0 || p_value > 90);
  145. agent_max_slope = p_value;
  146. }
  147. float NavigationMesh::get_agent_max_slope() const {
  148. return agent_max_slope;
  149. }
  150. void NavigationMesh::set_region_min_size(float p_value) {
  151. ERR_FAIL_COND(p_value < 0);
  152. region_min_size = p_value;
  153. }
  154. float NavigationMesh::get_region_min_size() const {
  155. return region_min_size;
  156. }
  157. void NavigationMesh::set_region_merge_size(float p_value) {
  158. ERR_FAIL_COND(p_value < 0);
  159. region_merge_size = p_value;
  160. }
  161. float NavigationMesh::get_region_merge_size() const {
  162. return region_merge_size;
  163. }
  164. void NavigationMesh::set_edge_max_length(float p_value) {
  165. ERR_FAIL_COND(p_value < 0);
  166. edge_max_length = p_value;
  167. }
  168. float NavigationMesh::get_edge_max_length() const {
  169. return edge_max_length;
  170. }
  171. void NavigationMesh::set_edge_max_error(float p_value) {
  172. ERR_FAIL_COND(p_value < 0);
  173. edge_max_error = p_value;
  174. }
  175. float NavigationMesh::get_edge_max_error() const {
  176. return edge_max_error;
  177. }
  178. void NavigationMesh::set_verts_per_poly(float p_value) {
  179. ERR_FAIL_COND(p_value < 3);
  180. verts_per_poly = p_value;
  181. }
  182. float NavigationMesh::get_verts_per_poly() const {
  183. return verts_per_poly;
  184. }
  185. void NavigationMesh::set_detail_sample_distance(float p_value) {
  186. ERR_FAIL_COND(p_value < 0);
  187. detail_sample_distance = p_value;
  188. }
  189. float NavigationMesh::get_detail_sample_distance() const {
  190. return detail_sample_distance;
  191. }
  192. void NavigationMesh::set_detail_sample_max_error(float p_value) {
  193. ERR_FAIL_COND(p_value < 0);
  194. detail_sample_max_error = p_value;
  195. }
  196. float NavigationMesh::get_detail_sample_max_error() const {
  197. return detail_sample_max_error;
  198. }
  199. void NavigationMesh::set_filter_low_hanging_obstacles(bool p_value) {
  200. filter_low_hanging_obstacles = p_value;
  201. }
  202. bool NavigationMesh::get_filter_low_hanging_obstacles() const {
  203. return filter_low_hanging_obstacles;
  204. }
  205. void NavigationMesh::set_filter_ledge_spans(bool p_value) {
  206. filter_ledge_spans = p_value;
  207. }
  208. bool NavigationMesh::get_filter_ledge_spans() const {
  209. return filter_ledge_spans;
  210. }
  211. void NavigationMesh::set_filter_walkable_low_height_spans(bool p_value) {
  212. filter_walkable_low_height_spans = p_value;
  213. }
  214. bool NavigationMesh::get_filter_walkable_low_height_spans() const {
  215. return filter_walkable_low_height_spans;
  216. }
  217. void NavigationMesh::set_vertices(const Vector<Vector3> &p_vertices) {
  218. vertices = p_vertices;
  219. notify_property_list_changed();
  220. }
  221. Vector<Vector3> NavigationMesh::get_vertices() const {
  222. return vertices;
  223. }
  224. void NavigationMesh::_set_polygons(const Array &p_array) {
  225. polygons.resize(p_array.size());
  226. for (int i = 0; i < p_array.size(); i++) {
  227. polygons.write[i].indices = p_array[i];
  228. }
  229. notify_property_list_changed();
  230. }
  231. Array NavigationMesh::_get_polygons() const {
  232. Array ret;
  233. ret.resize(polygons.size());
  234. for (int i = 0; i < ret.size(); i++) {
  235. ret[i] = polygons[i].indices;
  236. }
  237. return ret;
  238. }
  239. void NavigationMesh::add_polygon(const Vector<int> &p_polygon) {
  240. Polygon polygon;
  241. polygon.indices = p_polygon;
  242. polygons.push_back(polygon);
  243. notify_property_list_changed();
  244. }
  245. int NavigationMesh::get_polygon_count() const {
  246. return polygons.size();
  247. }
  248. Vector<int> NavigationMesh::get_polygon(int p_idx) {
  249. ERR_FAIL_INDEX_V(p_idx, polygons.size(), Vector<int>());
  250. return polygons[p_idx].indices;
  251. }
  252. void NavigationMesh::clear_polygons() {
  253. polygons.clear();
  254. }
  255. Ref<Mesh> NavigationMesh::get_debug_mesh() {
  256. if (debug_mesh.is_valid()) {
  257. return debug_mesh;
  258. }
  259. Vector<Vector3> vertices = get_vertices();
  260. const Vector3 *vr = vertices.ptr();
  261. List<Face3> faces;
  262. for (int i = 0; i < get_polygon_count(); i++) {
  263. Vector<int> p = get_polygon(i);
  264. for (int j = 2; j < p.size(); j++) {
  265. Face3 f;
  266. f.vertex[0] = vr[p[0]];
  267. f.vertex[1] = vr[p[j - 1]];
  268. f.vertex[2] = vr[p[j]];
  269. faces.push_back(f);
  270. }
  271. }
  272. Map<_EdgeKey, bool> edge_map;
  273. Vector<Vector3> tmeshfaces;
  274. tmeshfaces.resize(faces.size() * 3);
  275. {
  276. Vector3 *tw = tmeshfaces.ptrw();
  277. int tidx = 0;
  278. for (const Face3 &f : faces) {
  279. for (int j = 0; j < 3; j++) {
  280. tw[tidx++] = f.vertex[j];
  281. _EdgeKey ek;
  282. ek.from = f.vertex[j].snapped(Vector3(CMP_EPSILON, CMP_EPSILON, CMP_EPSILON));
  283. ek.to = f.vertex[(j + 1) % 3].snapped(Vector3(CMP_EPSILON, CMP_EPSILON, CMP_EPSILON));
  284. if (ek.from < ek.to) {
  285. SWAP(ek.from, ek.to);
  286. }
  287. Map<_EdgeKey, bool>::Element *F = edge_map.find(ek);
  288. if (F) {
  289. F->get() = false;
  290. } else {
  291. edge_map[ek] = true;
  292. }
  293. }
  294. }
  295. }
  296. List<Vector3> lines;
  297. for (Map<_EdgeKey, bool>::Element *E = edge_map.front(); E; E = E->next()) {
  298. if (E->get()) {
  299. lines.push_back(E->key().from);
  300. lines.push_back(E->key().to);
  301. }
  302. }
  303. Vector<Vector3> varr;
  304. varr.resize(lines.size());
  305. {
  306. Vector3 *w = varr.ptrw();
  307. int idx = 0;
  308. for (const Vector3 &E : lines) {
  309. w[idx++] = E;
  310. }
  311. }
  312. debug_mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
  313. Array arr;
  314. arr.resize(Mesh::ARRAY_MAX);
  315. arr[Mesh::ARRAY_VERTEX] = varr;
  316. debug_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_LINES, arr);
  317. return debug_mesh;
  318. }
  319. void NavigationMesh::_bind_methods() {
  320. ClassDB::bind_method(D_METHOD("set_sample_partition_type", "sample_partition_type"), &NavigationMesh::set_sample_partition_type);
  321. ClassDB::bind_method(D_METHOD("get_sample_partition_type"), &NavigationMesh::get_sample_partition_type);
  322. ClassDB::bind_method(D_METHOD("set_parsed_geometry_type", "geometry_type"), &NavigationMesh::set_parsed_geometry_type);
  323. ClassDB::bind_method(D_METHOD("get_parsed_geometry_type"), &NavigationMesh::get_parsed_geometry_type);
  324. ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &NavigationMesh::set_collision_mask);
  325. ClassDB::bind_method(D_METHOD("get_collision_mask"), &NavigationMesh::get_collision_mask);
  326. ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &NavigationMesh::set_collision_mask_bit);
  327. ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &NavigationMesh::get_collision_mask_bit);
  328. ClassDB::bind_method(D_METHOD("set_source_geometry_mode", "mask"), &NavigationMesh::set_source_geometry_mode);
  329. ClassDB::bind_method(D_METHOD("get_source_geometry_mode"), &NavigationMesh::get_source_geometry_mode);
  330. ClassDB::bind_method(D_METHOD("set_source_group_name", "mask"), &NavigationMesh::set_source_group_name);
  331. ClassDB::bind_method(D_METHOD("get_source_group_name"), &NavigationMesh::get_source_group_name);
  332. ClassDB::bind_method(D_METHOD("set_cell_size", "cell_size"), &NavigationMesh::set_cell_size);
  333. ClassDB::bind_method(D_METHOD("get_cell_size"), &NavigationMesh::get_cell_size);
  334. ClassDB::bind_method(D_METHOD("set_cell_height", "cell_height"), &NavigationMesh::set_cell_height);
  335. ClassDB::bind_method(D_METHOD("get_cell_height"), &NavigationMesh::get_cell_height);
  336. ClassDB::bind_method(D_METHOD("set_agent_height", "agent_height"), &NavigationMesh::set_agent_height);
  337. ClassDB::bind_method(D_METHOD("get_agent_height"), &NavigationMesh::get_agent_height);
  338. ClassDB::bind_method(D_METHOD("set_agent_radius", "agent_radius"), &NavigationMesh::set_agent_radius);
  339. ClassDB::bind_method(D_METHOD("get_agent_radius"), &NavigationMesh::get_agent_radius);
  340. ClassDB::bind_method(D_METHOD("set_agent_max_climb", "agent_max_climb"), &NavigationMesh::set_agent_max_climb);
  341. ClassDB::bind_method(D_METHOD("get_agent_max_climb"), &NavigationMesh::get_agent_max_climb);
  342. ClassDB::bind_method(D_METHOD("set_agent_max_slope", "agent_max_slope"), &NavigationMesh::set_agent_max_slope);
  343. ClassDB::bind_method(D_METHOD("get_agent_max_slope"), &NavigationMesh::get_agent_max_slope);
  344. ClassDB::bind_method(D_METHOD("set_region_min_size", "region_min_size"), &NavigationMesh::set_region_min_size);
  345. ClassDB::bind_method(D_METHOD("get_region_min_size"), &NavigationMesh::get_region_min_size);
  346. ClassDB::bind_method(D_METHOD("set_region_merge_size", "region_merge_size"), &NavigationMesh::set_region_merge_size);
  347. ClassDB::bind_method(D_METHOD("get_region_merge_size"), &NavigationMesh::get_region_merge_size);
  348. ClassDB::bind_method(D_METHOD("set_edge_max_length", "edge_max_length"), &NavigationMesh::set_edge_max_length);
  349. ClassDB::bind_method(D_METHOD("get_edge_max_length"), &NavigationMesh::get_edge_max_length);
  350. ClassDB::bind_method(D_METHOD("set_edge_max_error", "edge_max_error"), &NavigationMesh::set_edge_max_error);
  351. ClassDB::bind_method(D_METHOD("get_edge_max_error"), &NavigationMesh::get_edge_max_error);
  352. ClassDB::bind_method(D_METHOD("set_verts_per_poly", "verts_per_poly"), &NavigationMesh::set_verts_per_poly);
  353. ClassDB::bind_method(D_METHOD("get_verts_per_poly"), &NavigationMesh::get_verts_per_poly);
  354. ClassDB::bind_method(D_METHOD("set_detail_sample_distance", "detail_sample_dist"), &NavigationMesh::set_detail_sample_distance);
  355. ClassDB::bind_method(D_METHOD("get_detail_sample_distance"), &NavigationMesh::get_detail_sample_distance);
  356. ClassDB::bind_method(D_METHOD("set_detail_sample_max_error", "detail_sample_max_error"), &NavigationMesh::set_detail_sample_max_error);
  357. ClassDB::bind_method(D_METHOD("get_detail_sample_max_error"), &NavigationMesh::get_detail_sample_max_error);
  358. ClassDB::bind_method(D_METHOD("set_filter_low_hanging_obstacles", "filter_low_hanging_obstacles"), &NavigationMesh::set_filter_low_hanging_obstacles);
  359. ClassDB::bind_method(D_METHOD("get_filter_low_hanging_obstacles"), &NavigationMesh::get_filter_low_hanging_obstacles);
  360. ClassDB::bind_method(D_METHOD("set_filter_ledge_spans", "filter_ledge_spans"), &NavigationMesh::set_filter_ledge_spans);
  361. ClassDB::bind_method(D_METHOD("get_filter_ledge_spans"), &NavigationMesh::get_filter_ledge_spans);
  362. ClassDB::bind_method(D_METHOD("set_filter_walkable_low_height_spans", "filter_walkable_low_height_spans"), &NavigationMesh::set_filter_walkable_low_height_spans);
  363. ClassDB::bind_method(D_METHOD("get_filter_walkable_low_height_spans"), &NavigationMesh::get_filter_walkable_low_height_spans);
  364. ClassDB::bind_method(D_METHOD("set_vertices", "vertices"), &NavigationMesh::set_vertices);
  365. ClassDB::bind_method(D_METHOD("get_vertices"), &NavigationMesh::get_vertices);
  366. ClassDB::bind_method(D_METHOD("add_polygon", "polygon"), &NavigationMesh::add_polygon);
  367. ClassDB::bind_method(D_METHOD("get_polygon_count"), &NavigationMesh::get_polygon_count);
  368. ClassDB::bind_method(D_METHOD("get_polygon", "idx"), &NavigationMesh::get_polygon);
  369. ClassDB::bind_method(D_METHOD("clear_polygons"), &NavigationMesh::clear_polygons);
  370. ClassDB::bind_method(D_METHOD("create_from_mesh", "mesh"), &NavigationMesh::create_from_mesh);
  371. ClassDB::bind_method(D_METHOD("_set_polygons", "polygons"), &NavigationMesh::_set_polygons);
  372. ClassDB::bind_method(D_METHOD("_get_polygons"), &NavigationMesh::_get_polygons);
  373. ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR3_ARRAY, "vertices", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "set_vertices", "get_vertices");
  374. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "polygons", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_polygons", "_get_polygons");
  375. ADD_PROPERTY(PropertyInfo(Variant::INT, "sample_partition_type/sample_partition_type", PROPERTY_HINT_ENUM, "Watershed,Monotone,Layers"), "set_sample_partition_type", "get_sample_partition_type");
  376. 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");
  377. ADD_PROPERTY(PropertyInfo(Variant::INT, "geometry/collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask");
  378. 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");
  379. ADD_PROPERTY(PropertyInfo(Variant::STRING, "geometry/source_group_name"), "set_source_group_name", "get_source_group_name");
  380. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "cell/size", PROPERTY_HINT_RANGE, "0.1,1.0,0.01,or_greater"), "set_cell_size", "get_cell_size");
  381. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "cell/height", PROPERTY_HINT_RANGE, "0.1,1.0,0.01,or_greater"), "set_cell_height", "get_cell_height");
  382. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "agent/height", PROPERTY_HINT_RANGE, "0.1,5.0,0.01,or_greater"), "set_agent_height", "get_agent_height");
  383. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "agent/radius", PROPERTY_HINT_RANGE, "0.1,5.0,0.01,or_greater"), "set_agent_radius", "get_agent_radius");
  384. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "agent/max_climb", PROPERTY_HINT_RANGE, "0.1,5.0,0.01,or_greater"), "set_agent_max_climb", "get_agent_max_climb");
  385. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "agent/max_slope", PROPERTY_HINT_RANGE, "0.0,90.0,0.1"), "set_agent_max_slope", "get_agent_max_slope");
  386. 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");
  387. 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");
  388. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "edge/max_length", PROPERTY_HINT_RANGE, "0.0,50.0,0.01,or_greater"), "set_edge_max_length", "get_edge_max_length");
  389. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "edge/max_error", PROPERTY_HINT_RANGE, "0.1,3.0,0.01,or_greater"), "set_edge_max_error", "get_edge_max_error");
  390. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "polygon/verts_per_poly", PROPERTY_HINT_RANGE, "3.0,12.0,1.0,or_greater"), "set_verts_per_poly", "get_verts_per_poly");
  391. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "detail/sample_distance", PROPERTY_HINT_RANGE, "0.0,16.0,0.01,or_greater"), "set_detail_sample_distance", "get_detail_sample_distance");
  392. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "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");
  393. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter/low_hanging_obstacles"), "set_filter_low_hanging_obstacles", "get_filter_low_hanging_obstacles");
  394. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter/ledge_spans"), "set_filter_ledge_spans", "get_filter_ledge_spans");
  395. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter/filter_walkable_low_height_spans"), "set_filter_walkable_low_height_spans", "get_filter_walkable_low_height_spans");
  396. BIND_ENUM_CONSTANT(SAMPLE_PARTITION_WATERSHED);
  397. BIND_ENUM_CONSTANT(SAMPLE_PARTITION_MONOTONE);
  398. BIND_ENUM_CONSTANT(SAMPLE_PARTITION_LAYERS);
  399. BIND_ENUM_CONSTANT(SAMPLE_PARTITION_MAX);
  400. BIND_ENUM_CONSTANT(PARSED_GEOMETRY_MESH_INSTANCES);
  401. BIND_ENUM_CONSTANT(PARSED_GEOMETRY_STATIC_COLLIDERS);
  402. BIND_ENUM_CONSTANT(PARSED_GEOMETRY_BOTH);
  403. BIND_ENUM_CONSTANT(PARSED_GEOMETRY_MAX);
  404. BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_NAVMESH_CHILDREN);
  405. BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN);
  406. BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_GROUPS_EXPLICIT);
  407. BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_MAX);
  408. }
  409. void NavigationMesh::_validate_property(PropertyInfo &property) const {
  410. if (property.name == "geometry/collision_mask") {
  411. if (parsed_geometry_type == PARSED_GEOMETRY_MESH_INSTANCES) {
  412. property.usage = PROPERTY_USAGE_NONE;
  413. return;
  414. }
  415. }
  416. if (property.name == "geometry/source_group_name") {
  417. if (source_geometry_mode == SOURCE_GEOMETRY_NAVMESH_CHILDREN) {
  418. property.usage = PROPERTY_USAGE_NONE;
  419. return;
  420. }
  421. }
  422. }
  423. NavigationMesh::NavigationMesh() {}