diff options
-rw-r--r-- | source/blender/editors/object/object_vgroup.cc | 91 |
1 files changed, 34 insertions, 57 deletions
diff --git a/source/blender/editors/object/object_vgroup.cc b/source/blender/editors/object/object_vgroup.cc index 2fe6e888fc6..d874226f04e 100644 --- a/source/blender/editors/object/object_vgroup.cc +++ b/source/blender/editors/object/object_vgroup.cc @@ -2376,10 +2376,6 @@ void ED_vgroup_mirror(Object *ob, /* TODO: vgroup locking. * TODO: face masking. */ - BMVert *eve, *eve_mirr; - MDeformVert *dvert_mirr; - char sel, sel_mirr; - int *flip_map = nullptr, flip_map_len; const int def_nr = BKE_object_defgroup_active_index_get(ob) - 1; int totmirr = 0, totfail = 0; @@ -2392,6 +2388,8 @@ void ED_vgroup_mirror(Object *ob, return; } + int *flip_map = nullptr; + int flip_map_len; if (flip_vgroups) { flip_map = all_vgroups ? BKE_object_defgroup_flip_map(ob, false, &flip_map_len) : BKE_object_defgroup_flip_map_single(ob, false, def_nr, &flip_map_len); @@ -2426,30 +2424,27 @@ void ED_vgroup_mirror(Object *ob, BM_mesh_elem_hflag_disable_all(em->bm, BM_VERT, BM_ELEM_TAG, false); /* Go through the list of edit-vertices and assign them. */ + BMVert *eve, *eve_mirr; BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { if (!BM_elem_flag_test(eve, BM_ELEM_TAG)) { if ((eve_mirr = EDBM_verts_mirror_get(em, eve))) { if (eve_mirr != eve) { if (!BM_elem_flag_test(eve_mirr, BM_ELEM_TAG)) { - sel = BM_elem_flag_test(eve, BM_ELEM_SELECT); - sel_mirr = BM_elem_flag_test(eve_mirr, BM_ELEM_SELECT); + const bool sel = BM_elem_flag_test(eve, BM_ELEM_SELECT); + const bool sel_mirr = BM_elem_flag_test(eve_mirr, BM_ELEM_SELECT); if ((sel || sel_mirr) && (eve != eve_mirr)) { - MDeformVert *dvert = static_cast<MDeformVert *>( - BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset)); - dvert_mirr = static_cast<MDeformVert *>( - BM_ELEM_CD_GET_VOID_P(eve_mirr, cd_dvert_offset)); - - dvert_mirror_op(dvert, - dvert_mirr, - sel, - sel_mirr, - flip_map, - flip_map_len, - mirror_weights, - flip_vgroups, - all_vgroups, - def_nr); + dvert_mirror_op( + static_cast<MDeformVert *>(BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset)), + static_cast<MDeformVert *>(BM_ELEM_CD_GET_VOID_P(eve_mirr, cd_dvert_offset)), + sel, + sel_mirr, + flip_map, + flip_map_len, + mirror_weights, + flip_vgroups, + all_vgroups, + def_nr); totmirr++; } @@ -2468,40 +2463,30 @@ void ED_vgroup_mirror(Object *ob, } else { /* object mode / weight paint */ - int vidx, vidx_mirr; const bool use_vert_sel = (me->editflag & ME_EDIT_PAINT_VERT_SEL) != 0; if (me->deform_verts().is_empty()) { goto cleanup; } - if (!use_vert_sel) { - sel = sel_mirr = true; - } - BLI_bitmap *vert_tag = BLI_BITMAP_NEW(me->totvert, __func__); MutableSpan<MDeformVert> dverts = me->deform_verts_for_write(); const bke::AttributeAccessor attributes = me->attributes(); const VArray<bool> select_vert = attributes.lookup_or_default<bool>( ".select_vert", ATTR_DOMAIN_POINT, false); - for (vidx = 0; vidx < me->totvert; vidx++) { + for (int vidx = 0; vidx < me->totvert; vidx++) { if (!BLI_BITMAP_TEST(vert_tag, vidx)) { + int vidx_mirr; if ((vidx_mirr = mesh_get_x_mirror_vert(ob, nullptr, vidx, use_topology)) != -1) { if (vidx != vidx_mirr) { if (!BLI_BITMAP_TEST(vert_tag, vidx_mirr)) { - - if (use_vert_sel) { - sel = select_vert[vidx]; - sel_mirr = select_vert[vidx_mirr]; - } + const bool sel = use_vert_sel ? select_vert[vidx] : true; + const bool sel_mirr = use_vert_sel ? select_vert[vidx_mirr] : true; if (sel || sel_mirr) { - MDeformVert *dvert = &dverts[vidx]; - dvert_mirr = &dverts[vidx_mirr]; - - dvert_mirror_op(dvert, - dvert_mirr, + dvert_mirror_op(&dverts[vidx], + &dverts[vidx_mirr], sel, sel_mirr, flip_map, @@ -2529,9 +2514,6 @@ void ED_vgroup_mirror(Object *ob, } else if (ob->type == OB_LATTICE) { Lattice *lt = vgroup_edit_lattice(ob); - int i1, i2; - int u, v, w; - int pntsu_half; /* half but found up odd value */ if (lt->pntsu == 1 || lt->dvert == nullptr) { @@ -2541,30 +2523,25 @@ void ED_vgroup_mirror(Object *ob, /* unlike editmesh we know that by only looping over the first half of * the 'u' indices it will cover all points except the middle which is * ok in this case */ - pntsu_half = lt->pntsu / 2; + int pntsu_half = lt->pntsu / 2; - for (w = 0; w < lt->pntsw; w++) { - for (v = 0; v < lt->pntsv; v++) { - for (u = 0; u < pntsu_half; u++) { + for (int w = 0; w < lt->pntsw; w++) { + for (int v = 0; v < lt->pntsv; v++) { + for (int u = 0; u < pntsu_half; u++) { int u_inv = (lt->pntsu - 1) - u; if (u != u_inv) { - BPoint *bp, *bp_mirr; + const int i1 = BKE_lattice_index_from_uvw(lt, u, v, w); + const int i2 = BKE_lattice_index_from_uvw(lt, u_inv, v, w); - i1 = BKE_lattice_index_from_uvw(lt, u, v, w); - i2 = BKE_lattice_index_from_uvw(lt, u_inv, v, w); + const BPoint *bp = <->def[i1]; + const BPoint *bp_mirr = <->def[i2]; - bp = <->def[i1]; - bp_mirr = <->def[i2]; - - sel = bp->f1 & SELECT; - sel_mirr = bp_mirr->f1 & SELECT; + const bool sel = bp->f1 & SELECT; + const bool sel_mirr = bp_mirr->f1 & SELECT; if (sel || sel_mirr) { - MDeformVert *dvert = <->dvert[i1]; - dvert_mirr = <->dvert[i2]; - - dvert_mirror_op(dvert, - dvert_mirr, + dvert_mirror_op(<->dvert[i1], + <->dvert[i2], sel, sel_mirr, flip_map, |