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 | |
31 | #ifndef NAVIGATION_POLYGON_H |
32 | #define NAVIGATION_POLYGON_H |
33 | |
34 | #include "scene/2d/node_2d.h" |
35 | #include "scene/resources/navigation_mesh.h" |
36 | |
37 | class NavigationPolygon : public Resource { |
38 | GDCLASS(NavigationPolygon, Resource); |
39 | |
40 | Vector<Vector2> vertices; |
41 | struct Polygon { |
42 | Vector<int> indices; |
43 | }; |
44 | Vector<Polygon> polygons; |
45 | Vector<Vector<Vector2>> outlines; |
46 | |
47 | mutable Rect2 item_rect; |
48 | mutable bool rect_cache_dirty = true; |
49 | |
50 | Mutex navigation_mesh_generation; |
51 | // Navigation mesh |
52 | Ref<NavigationMesh> navigation_mesh; |
53 | |
54 | real_t cell_size = 1.0f; // Must match ProjectSettings default 2D cell_size. |
55 | |
56 | protected: |
57 | static void _bind_methods(); |
58 | |
59 | void _set_polygons(const TypedArray<Vector<int32_t>> &p_array); |
60 | TypedArray<Vector<int32_t>> _get_polygons() const; |
61 | |
62 | void _set_outlines(const TypedArray<Vector<Vector2>> &p_array); |
63 | TypedArray<Vector<Vector2>> _get_outlines() const; |
64 | |
65 | public: |
66 | #ifdef TOOLS_ENABLED |
67 | Rect2 _edit_get_rect() const; |
68 | bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const; |
69 | #endif |
70 | |
71 | void set_vertices(const Vector<Vector2> &p_vertices); |
72 | Vector<Vector2> get_vertices() const; |
73 | |
74 | void add_polygon(const Vector<int> &p_polygon); |
75 | int get_polygon_count() const; |
76 | |
77 | void add_outline(const Vector<Vector2> &p_outline); |
78 | void add_outline_at_index(const Vector<Vector2> &p_outline, int p_index); |
79 | void set_outline(int p_idx, const Vector<Vector2> &p_outline); |
80 | Vector<Vector2> get_outline(int p_idx) const; |
81 | void remove_outline(int p_idx); |
82 | int get_outline_count() const; |
83 | |
84 | void clear_outlines(); |
85 | void make_polygons_from_outlines(); |
86 | |
87 | Vector<int> get_polygon(int p_idx); |
88 | void clear_polygons(); |
89 | |
90 | Ref<NavigationMesh> get_navigation_mesh(); |
91 | |
92 | void set_cell_size(real_t p_cell_size); |
93 | real_t get_cell_size() const; |
94 | |
95 | void clear(); |
96 | |
97 | NavigationPolygon() {} |
98 | ~NavigationPolygon() {} |
99 | }; |
100 | |
101 | #endif // NAVIGATION_POLYGON_H |
102 | |