From 7dcd777379b0d9327b7a9e34e8a1b037267bb7e6 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 24 Oct 2023 19:39:21 +0200 Subject: [PATCH] Fix #114077: Duplicate edges for two point evaluated curves A curve with only two points shouldn't be considered cyclic. Otherwise a duplicate edge is added between the points. This fixes the utility that calculates the segment count to account for this and adjusts other code to account for that as necessary. Curves now evaluate correctly to a single evaluated segment in this case (in the case of Bezier and NURBS curves, it depends on the resolution though). Co-authored-by: Dalai Felinto Pull Request: https://projects.blender.org/blender/blender/pulls/114095 --- .../blenkernel/intern/curve_to_mesh_convert.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/source/blender/blenkernel/intern/curve_to_mesh_convert.cc b/source/blender/blenkernel/intern/curve_to_mesh_convert.cc index 00bd97d51bc..94f487fc723 100644 --- a/source/blender/blenkernel/intern/curve_to_mesh_convert.cc +++ b/source/blender/blenkernel/intern/curve_to_mesh_convert.cc @@ -22,6 +22,14 @@ namespace blender::bke { +static int segments_num_no_duplicate_edge(const int points_num, const bool cyclic) +{ + if (points_num <= 2) { + return curves::segments_num(points_num, false); + } + return curves::segments_num(points_num, cyclic); +} + static void fill_mesh_topology(const int vert_offset, const int edge_offset, const int face_offset, @@ -36,7 +44,7 @@ static void fill_mesh_topology(const int vert_offset, MutableSpan corner_edges, MutableSpan face_offsets) { - const int main_segment_num = curves::segments_num(main_point_num, main_cyclic); + const int main_segment_num = segments_num_no_duplicate_edge(main_point_num, main_cyclic); const int profile_segment_num = curves::segments_num(profile_point_num, profile_cyclic); if (profile_point_num == 1) { @@ -46,7 +54,7 @@ static void fill_mesh_topology(const int vert_offset, edge[1] = vert_offset + i + 1; } - if (main_cyclic && main_segment_num > 1) { + if (main_cyclic && main_segment_num > 2) { int2 &edge = edges[edge_offset + main_segment_num - 1]; edge[0] = vert_offset + main_point_num - 1; edge[1] = vert_offset; @@ -268,7 +276,7 @@ static ResultOffsets calculate_result_offsets(const CurvesInfo &info, const bool for (const int i_main : main_offsets.index_range()) { const bool main_cyclic = info.main_cyclic[i_main]; const int main_point_num = main_offsets[i_main].size(); - const int main_segment_num = curves::segments_num(main_point_num, main_cyclic); + const int main_segment_num = segments_num_no_duplicate_edge(main_point_num, main_cyclic); for (const int i_profile : profile_offsets.index_range()) { result.vert[mesh_index] = vert_offset; result.edge[mesh_index] = edge_offset;