navigation_mesh.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /**************************************************************************/
  2. /* navigation_mesh.h */
  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. #ifndef NAVIGATION_MESH_H
  31. #define NAVIGATION_MESH_H
  32. #include "scene/resources/mesh.h"
  33. class Mesh;
  34. class NavigationMeshGenerator;
  35. class NavigationMesh : public Resource {
  36. GDCLASS(NavigationMesh, Resource);
  37. friend class NavigationMeshGenerator;
  38. PoolVector<Vector3> vertices;
  39. struct Polygon {
  40. Vector<int> indices;
  41. };
  42. Vector<Polygon> polygons;
  43. Ref<ArrayMesh> debug_mesh;
  44. struct _EdgeKey {
  45. Vector3 from;
  46. Vector3 to;
  47. bool operator<(const _EdgeKey &p_with) const { return from == p_with.from ? to < p_with.to : from < p_with.from; }
  48. };
  49. protected:
  50. static void _bind_methods();
  51. virtual void _validate_property(PropertyInfo &property) const;
  52. #ifndef DISABLE_DEPRECATED
  53. bool _set(const StringName &p_name, const Variant &p_value);
  54. bool _get(const StringName &p_name, Variant &r_ret) const;
  55. #endif // DISABLE_DEPRECATED
  56. void _set_polygons(const Array &p_array);
  57. Array _get_polygons() const;
  58. public:
  59. enum SamplePartitionType {
  60. SAMPLE_PARTITION_WATERSHED = 0,
  61. SAMPLE_PARTITION_MONOTONE,
  62. SAMPLE_PARTITION_LAYERS,
  63. SAMPLE_PARTITION_MAX
  64. };
  65. enum ParsedGeometryType {
  66. PARSED_GEOMETRY_MESH_INSTANCES = 0,
  67. PARSED_GEOMETRY_STATIC_COLLIDERS,
  68. PARSED_GEOMETRY_BOTH,
  69. PARSED_GEOMETRY_MAX
  70. };
  71. enum SourceGeometryMode {
  72. SOURCE_GEOMETRY_NAVMESH_CHILDREN = 0,
  73. SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN,
  74. SOURCE_GEOMETRY_GROUPS_EXPLICIT,
  75. SOURCE_GEOMETRY_MAX
  76. };
  77. protected:
  78. float cell_size = 0.25f;
  79. float cell_height = 0.25f;
  80. float agent_height = 1.5f;
  81. float agent_radius = 0.5f;
  82. float agent_max_climb = 0.25f;
  83. float agent_max_slope = 45.0f;
  84. float region_min_size = 2.0f;
  85. float region_merge_size = 20.0f;
  86. float edge_max_length = 12.0f;
  87. float edge_max_error = 1.3f;
  88. float verts_per_poly = 6.0f;
  89. float detail_sample_distance = 6.0f;
  90. float detail_sample_max_error = 1.0f;
  91. SamplePartitionType partition_type = SAMPLE_PARTITION_WATERSHED;
  92. ParsedGeometryType parsed_geometry_type = PARSED_GEOMETRY_MESH_INSTANCES;
  93. uint32_t collision_mask = 0xFFFFFFFF;
  94. SourceGeometryMode source_geometry_mode = SOURCE_GEOMETRY_NAVMESH_CHILDREN;
  95. StringName source_group_name = "navmesh";
  96. bool filter_low_hanging_obstacles = false;
  97. bool filter_ledge_spans = false;
  98. bool filter_walkable_low_height_spans = false;
  99. AABB filter_baking_aabb;
  100. Vector3 filter_baking_aabb_offset;
  101. public:
  102. // Recast settings
  103. void set_sample_partition_type(SamplePartitionType p_value);
  104. SamplePartitionType get_sample_partition_type() const;
  105. void set_parsed_geometry_type(ParsedGeometryType p_value);
  106. ParsedGeometryType get_parsed_geometry_type() const;
  107. void set_collision_mask(uint32_t p_mask);
  108. uint32_t get_collision_mask() const;
  109. void set_collision_mask_bit(int p_bit, bool p_value);
  110. bool get_collision_mask_bit(int p_bit) const;
  111. void set_source_geometry_mode(SourceGeometryMode p_geometry_mode);
  112. SourceGeometryMode get_source_geometry_mode() const;
  113. void set_source_group_name(StringName p_group_name);
  114. StringName get_source_group_name() const;
  115. void set_cell_size(float p_value);
  116. float get_cell_size() const;
  117. void set_cell_height(float p_value);
  118. float get_cell_height() const;
  119. void set_agent_height(float p_value);
  120. float get_agent_height() const;
  121. void set_agent_radius(float p_value);
  122. float get_agent_radius();
  123. void set_agent_max_climb(float p_value);
  124. float get_agent_max_climb() const;
  125. void set_agent_max_slope(float p_value);
  126. float get_agent_max_slope() const;
  127. void set_region_min_size(float p_value);
  128. float get_region_min_size() const;
  129. void set_region_merge_size(float p_value);
  130. float get_region_merge_size() const;
  131. void set_edge_max_length(float p_value);
  132. float get_edge_max_length() const;
  133. void set_edge_max_error(float p_value);
  134. float get_edge_max_error() const;
  135. void set_verts_per_poly(float p_value);
  136. float get_verts_per_poly() const;
  137. void set_detail_sample_distance(float p_value);
  138. float get_detail_sample_distance() const;
  139. void set_detail_sample_max_error(float p_value);
  140. float get_detail_sample_max_error() const;
  141. void set_filter_low_hanging_obstacles(bool p_value);
  142. bool get_filter_low_hanging_obstacles() const;
  143. void set_filter_ledge_spans(bool p_value);
  144. bool get_filter_ledge_spans() const;
  145. void set_filter_walkable_low_height_spans(bool p_value);
  146. bool get_filter_walkable_low_height_spans() const;
  147. void set_filter_baking_aabb(const AABB &p_aabb);
  148. AABB get_filter_baking_aabb() const;
  149. void set_filter_baking_aabb_offset(const Vector3 &p_aabb_offset);
  150. Vector3 get_filter_baking_aabb_offset() const;
  151. void create_from_mesh(const Ref<Mesh> &p_mesh);
  152. void set_vertices(const PoolVector<Vector3> &p_vertices);
  153. PoolVector<Vector3> get_vertices() const;
  154. void add_polygon(const Vector<int> &p_polygon);
  155. int get_polygon_count() const;
  156. Vector<int> get_polygon(int p_idx);
  157. void clear_polygons();
  158. Ref<Mesh> get_debug_mesh();
  159. NavigationMesh();
  160. };
  161. VARIANT_ENUM_CAST(NavigationMesh::SamplePartitionType);
  162. VARIANT_ENUM_CAST(NavigationMesh::ParsedGeometryType);
  163. VARIANT_ENUM_CAST(NavigationMesh::SourceGeometryMode);
  164. #endif // NAVIGATION_MESH_H