navigation_mesh.cpp 20 KB

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