Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/resources/2d/navigation_polygon.h
21884 views
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
#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
// Navigation mesh
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 // DEBUG_ENABLED
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 // DISABLE_DEPRECATED
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);
174
175