Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NavigationPolygon cell_size property #78172

Merged
merged 1 commit into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/classes/NavigationPolygon.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,9 @@
</description>
</method>
</methods>
<members>
<member name="cell_size" type="float" setter="set_cell_size" getter="get_cell_size" default="1.0">
The cell size used to rasterize the navigation mesh vertices. Must match with the cell size on the navigation map.
</member>
</members>
</class>
14 changes: 14 additions & 0 deletions scene/resources/navigation_polygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ Ref<NavigationMesh> NavigationPolygon::get_navigation_mesh() {
for (int i(0); i < get_polygon_count(); i++) {
navigation_mesh->add_polygon(get_polygon(i));
}
navigation_mesh->set_cell_size(cell_size); // Needed to not fail the cell size check on the server
}

return navigation_mesh;
Expand Down Expand Up @@ -322,6 +323,15 @@ void NavigationPolygon::make_polygons_from_outlines() {
emit_changed();
}

void NavigationPolygon::set_cell_size(real_t p_cell_size) {
cell_size = p_cell_size;
get_navigation_mesh()->set_cell_size(cell_size);
}

real_t NavigationPolygon::get_cell_size() const {
return cell_size;
}

void NavigationPolygon::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_vertices", "vertices"), &NavigationPolygon::set_vertices);
ClassDB::bind_method(D_METHOD("get_vertices"), &NavigationPolygon::get_vertices);
Expand All @@ -347,7 +357,11 @@ void NavigationPolygon::_bind_methods() {
ClassDB::bind_method(D_METHOD("_set_outlines", "outlines"), &NavigationPolygon::_set_outlines);
ClassDB::bind_method(D_METHOD("_get_outlines"), &NavigationPolygon::_get_outlines);

ClassDB::bind_method(D_METHOD("set_cell_size", "cell_size"), &NavigationPolygon::set_cell_size);
ClassDB::bind_method(D_METHOD("get_cell_size"), &NavigationPolygon::get_cell_size);

ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR2_ARRAY, "vertices", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "set_vertices", "get_vertices");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "polygons", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_polygons", "_get_polygons");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "outlines", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_outlines", "_get_outlines");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "cell_size", PROPERTY_HINT_RANGE, "0.01,500.0,0.01,or_greater,suffix:px"), "set_cell_size", "get_cell_size");
}
5 changes: 5 additions & 0 deletions scene/resources/navigation_polygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class NavigationPolygon : public Resource {
// Navigation mesh
Ref<NavigationMesh> navigation_mesh;

real_t cell_size = 1.0f;

protected:
static void _bind_methods();

Expand Down Expand Up @@ -87,6 +89,9 @@ class NavigationPolygon : public Resource {

Ref<NavigationMesh> get_navigation_mesh();

void set_cell_size(real_t p_cell_size);
real_t get_cell_size() const;

NavigationPolygon() {}
~NavigationPolygon() {}
};
Expand Down