navigation_polygon.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /**************************************************************************/
  2. /* navigation_polygon.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_POLYGON_H
  31. #define NAVIGATION_POLYGON_H
  32. #include "scene/2d/node_2d.h"
  33. #include "scene/resources/navigation_mesh.h"
  34. class NavigationPolygon : public Resource {
  35. GDCLASS(NavigationPolygon, Resource);
  36. Vector<Vector2> vertices;
  37. struct Polygon {
  38. Vector<int> indices;
  39. };
  40. Vector<Polygon> polygons;
  41. Vector<Vector<Vector2>> outlines;
  42. Vector<Vector<Vector2>> baked_outlines;
  43. mutable Rect2 item_rect;
  44. mutable bool rect_cache_dirty = true;
  45. Mutex navigation_mesh_generation;
  46. // Navigation mesh
  47. Ref<NavigationMesh> navigation_mesh;
  48. real_t cell_size = 1.0f; // Must match ProjectSettings default 2D cell_size.
  49. protected:
  50. static void _bind_methods();
  51. void _validate_property(PropertyInfo &p_property) const;
  52. void _set_polygons(const TypedArray<Vector<int32_t>> &p_array);
  53. TypedArray<Vector<int32_t>> _get_polygons() const;
  54. void _set_outlines(const TypedArray<Vector<Vector2>> &p_array);
  55. TypedArray<Vector<Vector2>> _get_outlines() const;
  56. public:
  57. #ifdef TOOLS_ENABLED
  58. Rect2 _edit_get_rect() const;
  59. bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const;
  60. #endif
  61. enum ParsedGeometryType {
  62. PARSED_GEOMETRY_MESH_INSTANCES = 0,
  63. PARSED_GEOMETRY_STATIC_COLLIDERS,
  64. PARSED_GEOMETRY_BOTH,
  65. PARSED_GEOMETRY_MAX
  66. };
  67. enum SourceGeometryMode {
  68. SOURCE_GEOMETRY_ROOT_NODE_CHILDREN = 0,
  69. SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN,
  70. SOURCE_GEOMETRY_GROUPS_EXPLICIT,
  71. SOURCE_GEOMETRY_MAX
  72. };
  73. real_t agent_radius = 10.0f;
  74. ParsedGeometryType parsed_geometry_type = PARSED_GEOMETRY_BOTH;
  75. uint32_t parsed_collision_mask = 0xFFFFFFFF;
  76. SourceGeometryMode source_geometry_mode = SOURCE_GEOMETRY_ROOT_NODE_CHILDREN;
  77. StringName source_geometry_group_name = "navigation_polygon_source_group";
  78. void set_vertices(const Vector<Vector2> &p_vertices);
  79. Vector<Vector2> get_vertices() const;
  80. void add_polygon(const Vector<int> &p_polygon);
  81. int get_polygon_count() const;
  82. void add_outline(const Vector<Vector2> &p_outline);
  83. void add_outline_at_index(const Vector<Vector2> &p_outline, int p_index);
  84. void set_outline(int p_idx, const Vector<Vector2> &p_outline);
  85. Vector<Vector2> get_outline(int p_idx) const;
  86. void remove_outline(int p_idx);
  87. int get_outline_count() const;
  88. void clear_outlines();
  89. #ifndef DISABLE_DEPRECATED
  90. void make_polygons_from_outlines();
  91. #endif // DISABLE_DEPRECATED
  92. void set_polygons(const Vector<Vector<int>> &p_polygons);
  93. const Vector<Vector<int>> &get_polygons() const;
  94. Vector<int> get_polygon(int p_idx);
  95. void clear_polygons();
  96. void set_parsed_geometry_type(ParsedGeometryType p_geometry_type);
  97. ParsedGeometryType get_parsed_geometry_type() const;
  98. void set_parsed_collision_mask(uint32_t p_mask);
  99. uint32_t get_parsed_collision_mask() const;
  100. void set_parsed_collision_mask_value(int p_layer_number, bool p_value);
  101. bool get_parsed_collision_mask_value(int p_layer_number) const;
  102. void set_source_geometry_mode(SourceGeometryMode p_geometry_mode);
  103. SourceGeometryMode get_source_geometry_mode() const;
  104. void set_source_geometry_group_name(StringName p_group_name);
  105. StringName get_source_geometry_group_name() const;
  106. void set_agent_radius(real_t p_value);
  107. real_t get_agent_radius() const;
  108. Ref<NavigationMesh> get_navigation_mesh();
  109. void set_cell_size(real_t p_cell_size);
  110. real_t get_cell_size() const;
  111. void clear();
  112. NavigationPolygon();
  113. ~NavigationPolygon() {}
  114. };
  115. VARIANT_ENUM_CAST(NavigationPolygon::ParsedGeometryType);
  116. VARIANT_ENUM_CAST(NavigationPolygon::SourceGeometryMode);
  117. #endif // NAVIGATION_POLYGON_H