navigation_mesh.h 7.5 KB

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