From 6a4d8d4b5cdb6c24dc92201a5fdd8131d12b604a Mon Sep 17 00:00:00 2001 From: smix8 <52464204+smix8@users.noreply.github.com> Date: Wed, 27 Mar 2024 01:28:13 +0100 Subject: [PATCH] Change 2D navigation mesh baking to use floating point coordinates Replaces internal uses of Clipper2 integer structs to their floating point equivalents. --- .../navigation/2d/nav_mesh_generator_2d.cpp | 94 +++++++++---------- 1 file changed, 46 insertions(+), 48 deletions(-) diff --git a/modules/navigation/2d/nav_mesh_generator_2d.cpp b/modules/navigation/2d/nav_mesh_generator_2d.cpp index 13399b858ed..15a645816cd 100644 --- a/modules/navigation/2d/nav_mesh_generator_2d.cpp +++ b/modules/navigation/2d/nav_mesh_generator_2d.cpp @@ -284,7 +284,7 @@ void NavMeshGenerator2D::generator_parse_meshinstance2d_node(const Refget_surface_count(); i++) { if (mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) { @@ -295,7 +295,7 @@ void NavMeshGenerator2D::generator_parse_meshinstance2d_node(const Refsurface_get_format(i) & Mesh::ARRAY_FORMAT_INDEX) { @@ -314,19 +314,19 @@ void NavMeshGenerator2D::generator_parse_meshinstance2d_node(const Ref mesh_indices = a[Mesh::ARRAY_INDEX]; for (int vertex_index : mesh_indices) { const Vector2 &vertex = mesh_vertices[vertex_index]; - const Point64 &point = Point64(vertex.x, vertex.y); + const PointD &point = PointD(vertex.x, vertex.y); subject_path.push_back(point); } } else { for (const Vector2 &vertex : mesh_vertices) { - const Point64 &point = Point64(vertex.x, vertex.y); + const PointD &point = PointD(vertex.x, vertex.y); subject_path.push_back(point); } } subject_paths.push_back(subject_path); } - Paths64 path_solution; + PathsD path_solution; path_solution = Union(subject_paths, dummy_clip_paths, FillRule::NonZero); @@ -334,9 +334,9 @@ void NavMeshGenerator2D::generator_parse_meshinstance2d_node(const Ref> polypaths; - for (const Path64 &scaled_path : path_solution) { + for (const PathD &scaled_path : path_solution) { Vector shape_outline; - for (const Point64 &scaled_point : scaled_path) { + for (const PointD &scaled_point : scaled_path) { shape_outline.push_back(Point2(static_cast(scaled_point.x), static_cast(scaled_point.y))); } @@ -372,7 +372,7 @@ void NavMeshGenerator2D::generator_parse_multimeshinstance2d_node(const Refget_surface_count(); i++) { if (mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) { @@ -383,7 +383,7 @@ void NavMeshGenerator2D::generator_parse_multimeshinstance2d_node(const Refsurface_get_format(i) & Mesh::ARRAY_FORMAT_INDEX) { @@ -402,19 +402,19 @@ void NavMeshGenerator2D::generator_parse_multimeshinstance2d_node(const Ref mesh_indices = a[Mesh::ARRAY_INDEX]; for (int vertex_index : mesh_indices) { const Vector2 &vertex = mesh_vertices[vertex_index]; - const Point64 &point = Point64(vertex.x, vertex.y); + const PointD &point = PointD(vertex.x, vertex.y); subject_path.push_back(point); } } else { for (const Vector2 &vertex : mesh_vertices) { - const Point64 &point = Point64(vertex.x, vertex.y); + const PointD &point = PointD(vertex.x, vertex.y); subject_path.push_back(point); } } mesh_subject_paths.push_back(subject_path); } - Paths64 mesh_path_solution = Union(mesh_subject_paths, dummy_clip_paths, FillRule::NonZero); + PathsD mesh_path_solution = Union(mesh_subject_paths, dummy_clip_paths, FillRule::NonZero); //path_solution = RamerDouglasPeucker(path_solution, 0.025); @@ -428,10 +428,10 @@ void NavMeshGenerator2D::generator_parse_multimeshinstance2d_node(const Refget_instance_transform_2d(i); - for (const Path64 &mesh_path : mesh_path_solution) { + for (const PathD &mesh_path : mesh_path_solution) { Vector shape_outline; - for (const Point64 &mesh_path_point : mesh_path) { + for (const PointD &mesh_path_point : mesh_path) { shape_outline.push_back(Point2(static_cast(mesh_path_point.x), static_cast(mesh_path_point.y))); } @@ -793,12 +793,12 @@ void NavMeshGenerator2D::generator_parse_source_geometry_data(Ref &p_tppl_in_polygon, const Clipper2Lib::PolyPath64 *p_polypath_item) { +static void generator_recursive_process_polytree_items(List &p_tppl_in_polygon, const Clipper2Lib::PolyPathD *p_polypath_item) { using namespace Clipper2Lib; Vector polygon_vertices; - for (const Point64 &polypath_point : p_polypath_item->Polygon()) { + for (const PointD &polypath_point : p_polypath_item->Polygon()) { polygon_vertices.push_back(Vector2(static_cast(polypath_point.x), static_cast(polypath_point.y))); } @@ -817,7 +817,7 @@ static void generator_recursive_process_polytree_items(List &p_tppl_in p_tppl_in_polygon.push_back(tp); for (size_t i = 0; i < p_polypath_item->Count(); i++) { - const PolyPath64 *polypath_item = p_polypath_item->Child(i); + const PolyPathD *polypath_item = p_polypath_item->Child(i); generator_recursive_process_polytree_items(p_tppl_in_polygon, polypath_item); } } @@ -892,38 +892,38 @@ void NavMeshGenerator2D::generator_bake_from_source_geometry_data(Ref &traversable_outline = p_navigation_mesh->get_outline(i); - Path64 subject_path; + PathD subject_path; subject_path.reserve(traversable_outline.size()); for (const Vector2 &traversable_point : traversable_outline) { - const Point64 &point = Point64(traversable_point.x, traversable_point.y); + const PointD &point = PointD(traversable_point.x, traversable_point.y); subject_path.push_back(point); } traversable_polygon_paths.push_back(subject_path); } for (const Vector &traversable_outline : traversable_outlines) { - Path64 subject_path; + PathD subject_path; subject_path.reserve(traversable_outline.size()); for (const Vector2 &traversable_point : traversable_outline) { - const Point64 &point = Point64(traversable_point.x, traversable_point.y); + const PointD &point = PointD(traversable_point.x, traversable_point.y); subject_path.push_back(point); } traversable_polygon_paths.push_back(subject_path); } for (const Vector &obstruction_outline : obstruction_outlines) { - Path64 clip_path; + PathD clip_path; clip_path.reserve(obstruction_outline.size()); for (const Vector2 &obstruction_point : obstruction_outline) { - const Point64 &point = Point64(obstruction_point.x, obstruction_point.y); + const PointD &point = PointD(obstruction_point.x, obstruction_point.y); clip_path.push_back(point); } obstruction_polygon_paths.push_back(clip_path); @@ -940,10 +940,10 @@ void NavMeshGenerator2D::generator_bake_from_source_geometry_data(Ref> new_baked_outlines; - for (const Path64 &scaled_path : path_solution) { + for (const PathD &scaled_path : path_solution) { Vector polypath; - for (const Point64 &scaled_point : scaled_path) { + for (const PointD &scaled_point : scaled_path) { polypath.push_back(Vector2(static_cast(scaled_point.x), static_cast(scaled_point.y))); } new_baked_outlines.push_back(polypath); @@ -1043,13 +1041,13 @@ void NavMeshGenerator2D::generator_bake_from_source_geometry_data(Ref &baked_outline : new_baked_outlines) { - Path64 polygon_path; + PathD polygon_path; for (const Vector2 &baked_outline_point : baked_outline) { - const Point64 &point = Point64(baked_outline_point.x, baked_outline_point.y); + const PointD &point = PointD(baked_outline_point.x, baked_outline_point.y); polygon_path.push_back(point); } polygon_paths.push_back(polygon_path); @@ -1059,14 +1057,14 @@ void NavMeshGenerator2D::generator_bake_from_source_geometry_data(Ref tppl_in_polygon, tppl_out_polygon; - PolyTree64 polytree; - Clipper64 clipper_64; + PolyTreeD polytree; + ClipperD clipper_D; - clipper_64.AddSubject(polygon_paths); - clipper_64.Execute(clipper_cliptype, FillRule::NonZero, polytree); + clipper_D.AddSubject(polygon_paths); + clipper_D.Execute(clipper_cliptype, FillRule::NonZero, polytree); for (size_t i = 0; i < polytree.Count(); i++) { - const PolyPath64 *polypath_item = polytree[i]; + const PolyPathD *polypath_item = polytree[i]; generator_recursive_process_polytree_items(tppl_in_polygon, polypath_item); }