navigation_mesh_source_geometry_data_2d.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**************************************************************************/
  2. /* navigation_mesh_source_geometry_data_2d.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_SOURCE_GEOMETRY_DATA_2D_H
  31. #define NAVIGATION_MESH_SOURCE_GEOMETRY_DATA_2D_H
  32. #include "core/io/resource.h"
  33. #include "core/os/rw_lock.h"
  34. class NavigationMeshSourceGeometryData2D : public Resource {
  35. friend class NavMeshGenerator2D;
  36. GDCLASS(NavigationMeshSourceGeometryData2D, Resource);
  37. RWLock geometry_rwlock;
  38. Vector<Vector<Vector2>> traversable_outlines;
  39. Vector<Vector<Vector2>> obstruction_outlines;
  40. Rect2 bounds;
  41. bool bounds_dirty = true;
  42. public:
  43. struct ProjectedObstruction;
  44. private:
  45. Vector<ProjectedObstruction> _projected_obstructions;
  46. protected:
  47. bool _set(const StringName &p_name, const Variant &p_value);
  48. bool _get(const StringName &p_name, Variant &r_ret) const;
  49. static void _bind_methods();
  50. public:
  51. struct ProjectedObstruction {
  52. static inline uint32_t VERSION = 1; // Increase when format changes so we can detect outdated formats and provide compatibility.
  53. Vector<float> vertices;
  54. bool carve = false;
  55. };
  56. void _set_traversable_outlines(const Vector<Vector<Vector2>> &p_traversable_outlines);
  57. const Vector<Vector<Vector2>> &_get_traversable_outlines() const;
  58. void _set_obstruction_outlines(const Vector<Vector<Vector2>> &p_obstruction_outlines);
  59. const Vector<Vector<Vector2>> &_get_obstruction_outlines() const;
  60. void _add_traversable_outline(const Vector<Vector2> &p_shape_outline);
  61. void _add_obstruction_outline(const Vector<Vector2> &p_shape_outline);
  62. // kept root node transform here on the geometry data
  63. // if we add this transform to all exposed functions we need to break comp on all functions later
  64. // when navmesh changes from global transform to relative to navregion
  65. // but if it stays here we can just remove it and change the internal functions only
  66. Transform2D root_node_transform;
  67. void set_traversable_outlines(const TypedArray<Vector<Vector2>> &p_traversable_outlines);
  68. TypedArray<Vector<Vector2>> get_traversable_outlines() const;
  69. void set_obstruction_outlines(const TypedArray<Vector<Vector2>> &p_obstruction_outlines);
  70. TypedArray<Vector<Vector2>> get_obstruction_outlines() const;
  71. void append_traversable_outlines(const TypedArray<Vector<Vector2>> &p_traversable_outlines);
  72. void append_obstruction_outlines(const TypedArray<Vector<Vector2>> &p_obstruction_outlines);
  73. void add_traversable_outline(const PackedVector2Array &p_shape_outline);
  74. void add_obstruction_outline(const PackedVector2Array &p_shape_outline);
  75. bool has_data();
  76. void clear();
  77. void clear_projected_obstructions();
  78. void add_projected_obstruction(const Vector<Vector2> &p_vertices, bool p_carve);
  79. Vector<ProjectedObstruction> _get_projected_obstructions() const;
  80. void set_projected_obstructions(const Array &p_array);
  81. Array get_projected_obstructions() const;
  82. void merge(const Ref<NavigationMeshSourceGeometryData2D> &p_other_geometry);
  83. void set_data(const Vector<Vector<Vector2>> &p_traversable_outlines, const Vector<Vector<Vector2>> &p_obstruction_outlines, Vector<ProjectedObstruction> &p_projected_obstructions);
  84. void get_data(Vector<Vector<Vector2>> &r_traversable_outlines, Vector<Vector<Vector2>> &r_obstruction_outlines, Vector<ProjectedObstruction> &r_projected_obstructions);
  85. Rect2 get_bounds();
  86. NavigationMeshSourceGeometryData2D() {}
  87. ~NavigationMeshSourceGeometryData2D() { clear(); }
  88. };
  89. #endif // NAVIGATION_MESH_SOURCE_GEOMETRY_DATA_2D_H