TileSet: Maintain NavigationPolygon sub-polygons when rotating

The original implementation merged sub-polygons into a single polygon
when rotating. This can cause non-simple geometries downstream
algorithms cannot handle.
This commit is contained in:
Patrick Sean Klein 2024-06-09 22:42:03 +01:00
parent 5833f59786
commit 2dc42e8a93
No known key found for this signature in database
GPG Key ID: B6D50F39A56F6906

View File

@ -6489,18 +6489,16 @@ Ref<NavigationPolygon> TileData::get_navigation_polygon(int p_layer_id, bool p_f
PackedVector2Array new_points = get_transformed_vertices(layer_tile_data.navigation_polygon->get_vertices(), p_flip_h, p_flip_v, p_transpose); PackedVector2Array new_points = get_transformed_vertices(layer_tile_data.navigation_polygon->get_vertices(), p_flip_h, p_flip_v, p_transpose);
transformed_polygon->set_vertices(new_points); transformed_polygon->set_vertices(new_points);
int num_polygons = layer_tile_data.navigation_polygon->get_polygon_count();
for (int i = 0; i < num_polygons; ++i) {
transformed_polygon->add_polygon(layer_tile_data.navigation_polygon->get_polygon(i));
}
for (int i = 0; i < layer_tile_data.navigation_polygon->get_outline_count(); i++) { for (int i = 0; i < layer_tile_data.navigation_polygon->get_outline_count(); i++) {
PackedVector2Array new_outline = get_transformed_vertices(layer_tile_data.navigation_polygon->get_outline(i), p_flip_h, p_flip_v, p_transpose); PackedVector2Array new_outline = get_transformed_vertices(layer_tile_data.navigation_polygon->get_outline(i), p_flip_h, p_flip_v, p_transpose);
transformed_polygon->add_outline(new_outline); transformed_polygon->add_outline(new_outline);
} }
PackedInt32Array indices;
indices.resize(new_points.size());
int *w = indices.ptrw();
for (int i = 0; i < new_points.size(); i++) {
w[i] = i;
}
transformed_polygon->add_polygon(indices);
layer_tile_data.transformed_navigation_polygon[key] = transformed_polygon; layer_tile_data.transformed_navigation_polygon[key] = transformed_polygon;
return transformed_polygon; return transformed_polygon;
} else { } else {