diff options
Diffstat (limited to 'source/blender/modifiers/intern/MOD_weld.cc')
-rw-r--r-- | source/blender/modifiers/intern/MOD_weld.cc | 131 |
1 files changed, 63 insertions, 68 deletions
diff --git a/source/blender/modifiers/intern/MOD_weld.cc b/source/blender/modifiers/intern/MOD_weld.cc index 3a06c6a649b..3199bdc834f 100644 --- a/source/blender/modifiers/intern/MOD_weld.cc +++ b/source/blender/modifiers/intern/MOD_weld.cc @@ -331,7 +331,7 @@ static void weld_assert_poly_no_vert_repetition(const WeldPoly &wp, } else { int i = 0; - while (weld_iter_loop_of_poly_next(&iter)) { + while (weld_iter_loop_of_poly_next(iter)) { verts[i++] = iter.v; } } @@ -676,7 +676,7 @@ static void weld_edge_groups_setup(const int medge_len, /** \name Weld Poly and Loop API * \{ */ -static bool weld_iter_loop_of_poly_begin(WeldLoopOfPolyIter *iter, +static bool weld_iter_loop_of_poly_begin(WeldLoopOfPolyIter &iter, const WeldPoly &wp, Span<WeldLoop> wloop, Span<MLoop> mloop, @@ -687,19 +687,19 @@ static bool weld_iter_loop_of_poly_begin(WeldLoopOfPolyIter *iter, return false; } - iter->loop_start = wp.loop_start; - iter->loop_end = wp.loop_end; - iter->wloop = wloop; - iter->mloop = mloop; - iter->loop_map = loop_map; - iter->group = group_buffer; + iter.loop_start = wp.loop_start; + iter.loop_end = wp.loop_end; + iter.wloop = wloop; + iter.mloop = mloop; + iter.loop_map = loop_map; + iter.group = group_buffer; int group_len = 0; if (group_buffer) { /* First loop group needs more attention. */ int loop_start, loop_end, l; - loop_start = iter->loop_start; - loop_end = l = iter->loop_end; + loop_start = iter.loop_start; + loop_end = l = iter.loop_end; while (l >= loop_start) { const int loop_ctx = loop_map[l]; if (loop_ctx != OUT_OF_CONTEXT) { @@ -715,30 +715,30 @@ static bool weld_iter_loop_of_poly_begin(WeldLoopOfPolyIter *iter, group_len = loop_end - l; int i = 0; while (l < loop_end) { - iter->group[i++] = ++l; + iter.group[i++] = ++l; } } } - iter->group_len = group_len; + iter.group_len = group_len; - iter->l_next = iter->loop_start; + iter.l_next = iter.loop_start; #ifdef USE_WELD_DEBUG - iter->v = OUT_OF_CONTEXT; + iter.v = OUT_OF_CONTEXT; #endif return true; } -static bool weld_iter_loop_of_poly_next(WeldLoopOfPolyIter *iter) +static bool weld_iter_loop_of_poly_next(WeldLoopOfPolyIter &iter) { - int loop_end = iter->loop_end; - Span<WeldLoop> wloop = iter->wloop; - Span<int> loop_map = iter->loop_map; - int l = iter->l_curr = iter->l_next; - if (l == iter->loop_start) { + const int loop_end = iter.loop_end; + Span<WeldLoop> wloop = iter.wloop; + Span<int> loop_map = iter.loop_map; + int l = iter.l_curr = iter.l_next; + if (l == iter.loop_start) { /* `grupo_len` is already calculated in the first loop */ } else { - iter->group_len = 0; + iter.group_len = 0; } while (l <= loop_end) { int l_next = l + 1; @@ -749,32 +749,32 @@ static bool weld_iter_loop_of_poly_next(WeldLoopOfPolyIter *iter) l_next = wl->loop_skip_to; } if (wl->flag == ELEM_COLLAPSED) { - if (iter->group) { - iter->group[iter->group_len++] = l; + if (iter.group) { + iter.group[iter.group_len++] = l; } l = l_next; continue; } #ifdef USE_WELD_DEBUG - BLI_assert(iter->v != wl->vert); + BLI_assert(iter.v != wl->vert); #endif - iter->v = wl->vert; - iter->e = wl->edge; - iter->type = 1; + iter.v = wl->vert; + iter.e = wl->edge; + iter.type = 1; } else { - const MLoop *ml = &iter->mloop[l]; + const MLoop &ml = iter.mloop[l]; #ifdef USE_WELD_DEBUG - BLI_assert((uint)iter->v != ml->v); + BLI_assert((uint)iter.v != ml.v); #endif - iter->v = ml->v; - iter->e = ml->e; - iter->type = 0; + iter.v = ml.v; + iter.e = ml.e; + iter.type = 0; } - if (iter->group) { - iter->group[iter->group_len++] = l; + if (iter.group) { + iter.group[iter.group_len++] = l; } - iter->l_next = l_next; + iter.l_next = l_next; return true; } @@ -1026,18 +1026,13 @@ static void weld_poly_loop_ctx_setup(Span<MLoop> mloop, MutableSpan<WeldGroup> r_vlinks, WeldMesh *r_weld_mesh) { - int poly_kill_len, loop_kill_len, wpoly_len, wpoly_new_len; - - WeldPoly *wpoly_new; - WeldLoop *wl; - MutableSpan<WeldPoly> wpoly = r_weld_mesh->wpoly; MutableSpan<WeldLoop> wloop = r_weld_mesh->wloop; - wpoly_new = r_weld_mesh->wpoly_new; - wpoly_len = r_weld_mesh->wpoly_len; - wpoly_new_len = 0; - poly_kill_len = 0; - loop_kill_len = 0; + WeldPoly *wpoly_new = r_weld_mesh->wpoly_new; + int wpoly_len = r_weld_mesh->wpoly_len; + int wpoly_new_len = 0; + int poly_kill_len = 0; + int loop_kill_len = 0; Span<int> loop_map = r_weld_mesh->loop_map; @@ -1051,7 +1046,7 @@ static void weld_poly_loop_ctx_setup(Span<MLoop> mloop, int poly_len = wp.len; int ctx_verts_len = 0; - wl = &wloop[ctx_loops_ofs]; + WeldLoop *wl = &wloop[ctx_loops_ofs]; for (int l = ctx_loops_len; l--; wl++) { const int edge_dest = wl->edge; if (edge_dest == ELEM_COLLAPSED) { @@ -1108,7 +1103,7 @@ static void weld_poly_loop_ctx_setup(Span<MLoop> mloop, /* Setup Polygon Overlap. */ - int wpoly_and_new_len = wpoly_len + wpoly_new_len; + const int wpoly_and_new_len = wpoly_len + wpoly_new_len; r_vlinks.fill({0, 0}); MutableSpan<WeldGroup> v_links = r_vlinks; @@ -1116,8 +1111,8 @@ static void weld_poly_loop_ctx_setup(Span<MLoop> mloop, for (const int i : IndexRange(wpoly_and_new_len)) { const WeldPoly &wp = wpoly[i]; WeldLoopOfPolyIter iter; - if (weld_iter_loop_of_poly_begin(&iter, wp, wloop, mloop, loop_map, nullptr)) { - while (weld_iter_loop_of_poly_next(&iter)) { + if (weld_iter_loop_of_poly_begin(iter, wp, wloop, mloop, loop_map, nullptr)) { + while (weld_iter_loop_of_poly_next(iter)) { v_links[iter.v].len++; } } @@ -1135,8 +1130,8 @@ static void weld_poly_loop_ctx_setup(Span<MLoop> mloop, for (const int i : IndexRange(wpoly_and_new_len)) { const WeldPoly &wp = wpoly[i]; WeldLoopOfPolyIter iter; - if (weld_iter_loop_of_poly_begin(&iter, wp, wloop, mloop, loop_map, nullptr)) { - while (weld_iter_loop_of_poly_next(&iter)) { + if (weld_iter_loop_of_poly_begin(iter, wp, wloop, mloop, loop_map, nullptr)) { + while (weld_iter_loop_of_poly_next(iter)) { link_poly_buffer[v_links[iter.v].ofs++] = i; } } @@ -1159,8 +1154,8 @@ static void weld_poly_loop_ctx_setup(Span<MLoop> mloop, } WeldLoopOfPolyIter iter; - weld_iter_loop_of_poly_begin(&iter, wp, wloop, mloop, loop_map, nullptr); - weld_iter_loop_of_poly_next(&iter); + weld_iter_loop_of_poly_begin(iter, wp, wloop, mloop, loop_map, nullptr); + weld_iter_loop_of_poly_next(iter); struct WeldGroup *link_a = &v_links[iter.v]; polys_len_a = link_a->len; if (polys_len_a == 1) { @@ -1181,7 +1176,7 @@ static void weld_poly_loop_ctx_setup(Span<MLoop> mloop, } WeldLoopOfPolyIter iter_b = iter; - while (weld_iter_loop_of_poly_next(&iter_b)) { + while (weld_iter_loop_of_poly_next(iter_b)) { struct WeldGroup *link_b = &v_links[iter_b.v]; polys_len_b = link_b->len; if (polys_len_b == 1) { @@ -1253,15 +1248,15 @@ static void weld_poly_loop_ctx_setup(Span<MLoop> mloop, /** \name Weld Mesh API * \{ */ -static void weld_mesh_context_create(const Mesh *mesh, +static void weld_mesh_context_create(const Mesh &mesh, MutableSpan<int> vert_dest_map, const int vert_kill_len, WeldMesh *r_weld_mesh) { - Span<MEdge> medge{mesh->medge, mesh->totedge}; - Span<MPoly> mpoly{mesh->mpoly, mesh->totpoly}; - Span<MLoop> mloop{mesh->mloop, mesh->totloop}; - const int mvert_len = mesh->totvert; + Span<MEdge> medge{mesh.medge, mesh.totedge}; + Span<MPoly> mpoly{mesh.mpoly, mesh.totpoly}; + Span<MLoop> mloop{mesh.mloop, mesh.totloop}; + const int mvert_len = mesh.totvert; Vector<WeldVert> wvert = weld_vert_ctx_alloc_and_setup(vert_dest_map, vert_kill_len); r_weld_mesh->vert_kill_len = vert_kill_len; @@ -1686,7 +1681,7 @@ static Mesh *weldModifier_doWeld(WeldModifierData *wmd, } WeldMesh weld_mesh; - weld_mesh_context_create(mesh, vert_dest_map, vert_kill_len, &weld_mesh); + weld_mesh_context_create(*mesh, vert_dest_map, vert_kill_len, &weld_mesh); const int result_nverts = totvert - weld_mesh.vert_kill_len; const int result_nedges = totedge - weld_mesh.edge_kill_len; @@ -1740,7 +1735,7 @@ static Mesh *weldModifier_doWeld(WeldModifierData *wmd, dest_index = 0; for (int i = 0; i < totedge; i++) { - int source_index = i; + const int source_index = i; int count = 0; while (i < totedge && weld_mesh.edge_groups_map[i] == OUT_OF_CONTEXT) { edge_final[i] = dest_index + count; @@ -1787,8 +1782,8 @@ static Mesh *weldModifier_doWeld(WeldModifierData *wmd, Array<int, 64> group_buffer(weld_mesh.max_poly_len); for (const int i : mpoly.index_range()) { const MPoly &mp = mpoly[i]; - int loop_start = loop_cur; - int poly_ctx = weld_mesh.poly_map[i]; + const int loop_start = loop_cur; + const int poly_ctx = weld_mesh.poly_map[i]; if (poly_ctx == OUT_OF_CONTEXT) { int mp_loop_len = mp.totloop; CustomData_copy_data(&mesh->ldata, &result->ldata, mp.loopstart, loop_cur, mp_loop_len); @@ -1802,14 +1797,14 @@ static Mesh *weldModifier_doWeld(WeldModifierData *wmd, const WeldPoly &wp = weld_mesh.wpoly[poly_ctx]; WeldLoopOfPolyIter iter; if (!weld_iter_loop_of_poly_begin( - &iter, wp, weld_mesh.wloop, mloop, weld_mesh.loop_map, group_buffer.data())) { + iter, wp, weld_mesh.wloop, mloop, weld_mesh.loop_map, group_buffer.data())) { continue; } if (wp.poly_dst != OUT_OF_CONTEXT) { continue; } - while (weld_iter_loop_of_poly_next(&iter)) { + while (weld_iter_loop_of_poly_next(iter)) { customdata_weld( &mesh->ldata, &result->ldata, group_buffer.data(), iter.group_len, loop_cur); int v = vert_final[iter.v]; @@ -1834,17 +1829,17 @@ static Mesh *weldModifier_doWeld(WeldModifierData *wmd, for (const int i : IndexRange(weld_mesh.wpoly_new_len)) { const WeldPoly &wp = weld_mesh.wpoly_new[i]; - int loop_start = loop_cur; + const int loop_start = loop_cur; WeldLoopOfPolyIter iter; if (!weld_iter_loop_of_poly_begin( - &iter, wp, weld_mesh.wloop, mloop, weld_mesh.loop_map, group_buffer.data())) { + iter, wp, weld_mesh.wloop, mloop, weld_mesh.loop_map, group_buffer.data())) { continue; } if (wp.poly_dst != OUT_OF_CONTEXT) { continue; } - while (weld_iter_loop_of_poly_next(&iter)) { + while (weld_iter_loop_of_poly_next(iter)) { customdata_weld(&mesh->ldata, &result->ldata, group_buffer.data(), iter.group_len, loop_cur); int v = vert_final[iter.v]; int e = edge_final[iter.e]; |