| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/2d/node_2d.h" |
| 34 |
#include "scene/resources/navigation_mesh.h" |
| 35 |
#include "servers/navigation_2d/navigation_constants_2d.h" |
| 36 |
|
| 37 |
class NavigationPolygon : public Resource { |
| 38 |
GDCLASS(NavigationPolygon, Resource); |
| 39 |
RWLock rwlock; |
| 40 |
|
| 41 |
Vector<Vector2> vertices; |
| 42 |
Vector<Vector<int>> polygons; |
| 43 |
Vector<Vector<Vector2>> outlines; |
| 44 |
|
| 45 |
mutable Rect2 item_rect; |
| 46 |
mutable bool rect_cache_dirty = true; |
| 47 |
|
| 48 |
Mutex navigation_mesh_generation; |
| 49 |
|
| 50 |
Ref<NavigationMesh> navigation_mesh; |
| 51 |
|
| 52 |
real_t cell_size = NavigationDefaults2D::NAV_MESH_CELL_SIZE; |
| 53 |
real_t border_size = 0.0f; |
| 54 |
|
| 55 |
Rect2 baking_rect; |
| 56 |
Vector2 baking_rect_offset; |
| 57 |
|
| 58 |
protected: |
| 59 |
static void _bind_methods(); |
| 60 |
void _validate_property(PropertyInfo &p_property) const; |
| 61 |
|
| 62 |
void _set_polygons(const TypedArray<Vector<int32_t>> &p_array); |
| 63 |
TypedArray<Vector<int32_t>> _get_polygons() const; |
| 64 |
|
| 65 |
void _set_outlines(const TypedArray<Vector<Vector2>> &p_array); |
| 66 |
TypedArray<Vector<Vector2>> _get_outlines() const; |
| 67 |
|
| 68 |
public: |
| 69 |
#ifdef DEBUG_ENABLED |
| 70 |
Rect2 _edit_get_rect() const; |
| 71 |
bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const; |
| 72 |
#endif |
| 73 |
|
| 74 |
enum SamplePartitionType { |
| 75 |
SAMPLE_PARTITION_CONVEX_PARTITION = 0, |
| 76 |
SAMPLE_PARTITION_TRIANGULATE, |
| 77 |
SAMPLE_PARTITION_MAX |
| 78 |
}; |
| 79 |
|
| 80 |
enum ParsedGeometryType { |
| 81 |
PARSED_GEOMETRY_MESH_INSTANCES = 0, |
| 82 |
PARSED_GEOMETRY_STATIC_COLLIDERS, |
| 83 |
PARSED_GEOMETRY_BOTH, |
| 84 |
PARSED_GEOMETRY_MAX |
| 85 |
}; |
| 86 |
|
| 87 |
enum SourceGeometryMode { |
| 88 |
SOURCE_GEOMETRY_ROOT_NODE_CHILDREN = 0, |
| 89 |
SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN, |
| 90 |
SOURCE_GEOMETRY_GROUPS_EXPLICIT, |
| 91 |
SOURCE_GEOMETRY_MAX |
| 92 |
}; |
| 93 |
|
| 94 |
real_t agent_radius = 10.0f; |
| 95 |
|
| 96 |
SamplePartitionType partition_type = SAMPLE_PARTITION_CONVEX_PARTITION; |
| 97 |
ParsedGeometryType parsed_geometry_type = PARSED_GEOMETRY_BOTH; |
| 98 |
uint32_t parsed_collision_mask = 0xFFFFFFFF; |
| 99 |
|
| 100 |
SourceGeometryMode source_geometry_mode = SOURCE_GEOMETRY_ROOT_NODE_CHILDREN; |
| 101 |
StringName source_geometry_group_name = "navigation_polygon_source_geometry_group"; |
| 102 |
|
| 103 |
void set_vertices(const Vector<Vector2> &p_vertices); |
| 104 |
Vector<Vector2> get_vertices() const; |
| 105 |
|
| 106 |
void add_polygon(const Vector<int> &p_polygon); |
| 107 |
int get_polygon_count() const; |
| 108 |
|
| 109 |
void add_outline(const Vector<Vector2> &p_outline); |
| 110 |
void add_outline_at_index(const Vector<Vector2> &p_outline, int p_index); |
| 111 |
void set_outline(int p_idx, const Vector<Vector2> &p_outline); |
| 112 |
Vector<Vector2> get_outline(int p_idx) const; |
| 113 |
void remove_outline(int p_idx); |
| 114 |
int get_outline_count() const; |
| 115 |
void set_outlines(const Vector<Vector<Vector2>> &p_outlines); |
| 116 |
Vector<Vector<Vector2>> get_outlines() const; |
| 117 |
|
| 118 |
void clear_outlines(); |
| 119 |
#ifndef DISABLE_DEPRECATED |
| 120 |
void make_polygons_from_outlines(); |
| 121 |
#endif |
| 122 |
|
| 123 |
void set_polygons(const Vector<Vector<int>> &p_polygons); |
| 124 |
Vector<Vector<int>> get_polygons() const; |
| 125 |
Vector<int> get_polygon(int p_idx); |
| 126 |
void clear_polygons(); |
| 127 |
|
| 128 |
void set_sample_partition_type(SamplePartitionType p_value); |
| 129 |
SamplePartitionType get_sample_partition_type() const; |
| 130 |
|
| 131 |
void set_parsed_geometry_type(ParsedGeometryType p_geometry_type); |
| 132 |
ParsedGeometryType get_parsed_geometry_type() const; |
| 133 |
|
| 134 |
void set_parsed_collision_mask(uint32_t p_mask); |
| 135 |
uint32_t get_parsed_collision_mask() const; |
| 136 |
|
| 137 |
void set_parsed_collision_mask_value(int p_layer_number, bool p_value); |
| 138 |
bool get_parsed_collision_mask_value(int p_layer_number) const; |
| 139 |
|
| 140 |
void set_source_geometry_mode(SourceGeometryMode p_geometry_mode); |
| 141 |
SourceGeometryMode get_source_geometry_mode() const; |
| 142 |
|
| 143 |
void set_source_geometry_group_name(const StringName &p_group_name); |
| 144 |
StringName get_source_geometry_group_name() const; |
| 145 |
|
| 146 |
void set_agent_radius(real_t p_value); |
| 147 |
real_t get_agent_radius() const; |
| 148 |
|
| 149 |
Ref<NavigationMesh> get_navigation_mesh(); |
| 150 |
|
| 151 |
void set_cell_size(real_t p_cell_size); |
| 152 |
real_t get_cell_size() const; |
| 153 |
|
| 154 |
void set_border_size(real_t p_value); |
| 155 |
real_t get_border_size() const; |
| 156 |
|
| 157 |
void set_baking_rect(const Rect2 &p_rect); |
| 158 |
Rect2 get_baking_rect() const; |
| 159 |
|
| 160 |
void set_baking_rect_offset(const Vector2 &p_rect_offset); |
| 161 |
Vector2 get_baking_rect_offset() const; |
| 162 |
|
| 163 |
void clear(); |
| 164 |
|
| 165 |
void set_data(const Vector<Vector2> &p_vertices, const Vector<Vector<int>> &p_polygons); |
| 166 |
void set_data(const Vector<Vector2> &p_vertices, const Vector<Vector<int>> &p_polygons, const Vector<Vector<Vector2>> &p_outlines); |
| 167 |
void get_data(Vector<Vector2> &r_vertices, Vector<Vector<int>> &r_polygons); |
| 168 |
void get_data(Vector<Vector2> &r_vertices, Vector<Vector<int>> &r_polygons, Vector<Vector<Vector2>> &r_outlines); |
| 169 |
}; |
| 170 |
|
| 171 |
VARIANT_ENUM_CAST(NavigationPolygon::SamplePartitionType); |
| 172 |
VARIANT_ENUM_CAST(NavigationPolygon::ParsedGeometryType); |
| 173 |
VARIANT_ENUM_CAST(NavigationPolygon::SourceGeometryMode); |