navigation_mesh.h 7.4 KB

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