navigation_mesh.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*************************************************************************/
  2. /* navigation_mesh.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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. #ifndef NAVIGATION_MESH_H
  31. #define NAVIGATION_MESH_H
  32. #include "scene/3d/spatial.h"
  33. #include "scene/resources/mesh.h"
  34. class Mesh;
  35. class NavigationMesh : public Resource {
  36. GDCLASS(NavigationMesh, Resource);
  37. PoolVector<Vector3> vertices;
  38. struct Polygon {
  39. Vector<int> indices;
  40. };
  41. Vector<Polygon> polygons;
  42. Ref<ArrayMesh> debug_mesh;
  43. struct _EdgeKey {
  44. Vector3 from;
  45. Vector3 to;
  46. bool operator<(const _EdgeKey &p_with) const { return from == p_with.from ? to < p_with.to : from < p_with.from; }
  47. };
  48. protected:
  49. static void _bind_methods();
  50. void _set_polygons(const Array &p_array);
  51. Array _get_polygons() const;
  52. public:
  53. enum SamplePartitionType {
  54. SAMPLE_PARTITION_WATERSHED = 0,
  55. SAMPLE_PARTITION_MONOTONE,
  56. SAMPLE_PARTITION_LAYERS,
  57. SAMPLE_PARTITION_MAX
  58. };
  59. protected:
  60. float cell_size;
  61. float cell_height;
  62. float agent_height;
  63. float agent_radius;
  64. float agent_max_climb;
  65. float agent_max_slope;
  66. float region_min_size;
  67. float region_merge_size;
  68. float edge_max_length;
  69. float edge_max_error;
  70. float verts_per_poly;
  71. float detail_sample_distance;
  72. float detail_sample_max_error;
  73. SamplePartitionType partition_type;
  74. bool filter_low_hanging_obstacles;
  75. bool filter_ledge_spans;
  76. bool filter_walkable_low_height_spans;
  77. public:
  78. // Recast settings
  79. void set_sample_partition_type(int p_value);
  80. int get_sample_partition_type() const;
  81. void set_cell_size(float p_value);
  82. float get_cell_size() const;
  83. void set_cell_height(float p_value);
  84. float get_cell_height() const;
  85. void set_agent_height(float p_value);
  86. float get_agent_height() const;
  87. void set_agent_radius(float p_value);
  88. float get_agent_radius();
  89. void set_agent_max_climb(float p_value);
  90. float get_agent_max_climb() const;
  91. void set_agent_max_slope(float p_value);
  92. float get_agent_max_slope() const;
  93. void set_region_min_size(float p_value);
  94. float get_region_min_size() const;
  95. void set_region_merge_size(float p_value);
  96. float get_region_merge_size() const;
  97. void set_edge_max_length(float p_value);
  98. float get_edge_max_length() const;
  99. void set_edge_max_error(float p_value);
  100. float get_edge_max_error() const;
  101. void set_verts_per_poly(float p_value);
  102. float get_verts_per_poly() const;
  103. void set_detail_sample_distance(float p_value);
  104. float get_detail_sample_distance() const;
  105. void set_detail_sample_max_error(float p_value);
  106. float get_detail_sample_max_error() const;
  107. void set_filter_low_hanging_obstacles(bool p_value);
  108. bool get_filter_low_hanging_obstacles() const;
  109. void set_filter_ledge_spans(bool p_value);
  110. bool get_filter_ledge_spans() const;
  111. void set_filter_walkable_low_height_spans(bool p_value);
  112. bool get_filter_walkable_low_height_spans() const;
  113. void create_from_mesh(const Ref<Mesh> &p_mesh);
  114. void set_vertices(const PoolVector<Vector3> &p_vertices);
  115. PoolVector<Vector3> get_vertices() const;
  116. void add_polygon(const Vector<int> &p_polygon);
  117. int get_polygon_count() const;
  118. Vector<int> get_polygon(int p_idx);
  119. void clear_polygons();
  120. Ref<Mesh> get_debug_mesh();
  121. NavigationMesh();
  122. };
  123. class Navigation;
  124. class NavigationMeshInstance : public Spatial {
  125. GDCLASS(NavigationMeshInstance, Spatial);
  126. bool enabled;
  127. int nav_id;
  128. Navigation *navigation;
  129. Ref<NavigationMesh> navmesh;
  130. Node *debug_view;
  131. protected:
  132. void _notification(int p_what);
  133. static void _bind_methods();
  134. public:
  135. void set_enabled(bool p_enabled);
  136. bool is_enabled() const;
  137. void set_navigation_mesh(const Ref<NavigationMesh> &p_navmesh);
  138. Ref<NavigationMesh> get_navigation_mesh() const;
  139. String get_configuration_warning() const;
  140. NavigationMeshInstance();
  141. };
  142. #endif // NAVIGATION_MESH_H