From b202bf05646b89c8b1f9f24a1d0f9750914997b1 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 30 Nov 2011 07:11:29 +0000 Subject: [PATCH] fix [#29450] Mirror Vertex Groups issue --- source/blender/blenkernel/BKE_deform.h | 1 + source/blender/blenkernel/intern/deform.c | 25 +++++++++++++++++++ source/blender/editors/object/object_vgroup.c | 14 ++++++++--- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/source/blender/blenkernel/BKE_deform.h b/source/blender/blenkernel/BKE_deform.h index 3e643fe961c..2dcafd769d8 100644 --- a/source/blender/blenkernel/BKE_deform.h +++ b/source/blender/blenkernel/BKE_deform.h @@ -57,6 +57,7 @@ float defvert_find_weight(const struct MDeformVert *dvert, const int group_num) float defvert_array_find_weight_safe(const struct MDeformVert *dvert, int index, int group_num); void defvert_copy(struct MDeformVert *dvert_r, const struct MDeformVert *dvert); +void defvert_copy_index(struct MDeformVert *dv_dst, const struct MDeformVert *dv_src, const int defgroup); void defvert_sync(struct MDeformVert *dvert_r, const struct MDeformVert *dvert, int use_verify); void defvert_sync_mapped(struct MDeformVert *dvert_r, const struct MDeformVert *dvert, const int *flip_map, const int flip_map_len, const int use_verify); void defvert_remap (struct MDeformVert *dvert, int *map); diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c index 0c3c78f6eef..021433dee9e 100644 --- a/source/blender/blenkernel/intern/deform.c +++ b/source/blender/blenkernel/intern/deform.c @@ -94,6 +94,31 @@ void defvert_copy (MDeformVert *dvert_r, const MDeformVert *dvert) } } +/* copy an index from one dvert to another + * - do nothing if neither are set. + * - add destination weight if needed. + */ +void defvert_copy_index (MDeformVert *dv_dst, const MDeformVert *dv_src, const int defgroup) +{ + MDeformWeight *dw_src, *dw_dst; + + dw_src= defvert_find_index(dv_src, defgroup); + + if (dw_src) { + /* source is valid, verify destination */ + dw_dst= defvert_verify_index(dv_dst, defgroup); + dw_dst->weight= dw_src->weight; + } + else { + /* source was NULL, assign zero, could also remove */ + dw_dst= defvert_find_index(dv_dst, defgroup); + + if (dw_dst) { + dw_dst->weight= 0.0f; + } + } +} + /* only sync over matching weights, don't add or remove groups * warning, loop within loop. */ diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index d6300dc1fe3..16073434cc7 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -1576,13 +1576,21 @@ static void dvert_mirror_op(MDeformVert *dvert, MDeformVert *dvert_mirr, } } else { - /* dvert should always be the target */ + /* dvert should always be the target, only swaps pointer */ if(sel_mirr) { SWAP(MDeformVert *, dvert, dvert_mirr); } - if(mirror_weights) - defvert_copy(dvert, dvert_mirr); + if(mirror_weights) { + if (all_vgroups) { + defvert_copy(dvert, dvert_mirr); + } + else { + defvert_copy_index(dvert, dvert_mirr, act_vgroup); + } + } + + /* flip map already modified for 'all_vgroups' */ if(flip_vgroups) { defvert_flip(dvert, flip_map, flip_map_len); }