diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-05-27 02:20:29 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-05-27 02:20:29 +0400 |
commit | d9fa6db75ba2e38436d9e72a0454b2ba0dcaa359 (patch) | |
tree | f074fac1e8e4c8c1a25b3c62b6403ff97cbb64e3 /source/blender/editors/sculpt_paint | |
parent | 4b9a63c6d3b6fc90259bea708355d678d3681bc3 (diff) |
weight paint mirror, move duplicate code into a function.
Diffstat (limited to 'source/blender/editors/sculpt_paint')
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_vertex.c | 83 |
1 files changed, 40 insertions, 43 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index ecdf49a321a..0380dba7592 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -288,6 +288,43 @@ static void make_vertexcol(Object *ob) /* single ob */ } +/* mirror_vgroup is set to -1 when invalid */ +static void wpaint_mirror_vgroup_ensure(Object *ob, int *vgroup_mirror) +{ + bDeformGroup *defgroup= BLI_findlink(&ob->defbase, ob->actdef - 1); + + if(defgroup) { + bDeformGroup *curdef; + int mirrdef; + char name[MAXBONENAME]; + + flip_side_name(name, defgroup->name, FALSE); + + if(strcmp(name, defgroup->name) != 0) { + for (curdef= ob->defbase.first, mirrdef; curdef; curdef=curdef->next, mirrdef++) { + if (!strcmp(curdef->name, name)) { + break; + } + } + + if(curdef==NULL) { + int olddef= ob->actdef; /* tsk, ED_vgroup_add sets the active defgroup */ + curdef= ED_vgroup_add_name(ob, name); + ob->actdef= olddef; + } + + /* curdef should never be NULL unless this is + * a lamp and ED_vgroup_add_name fails */ + if(curdef) { + *vgroup_mirror= mirrdef; + return; + } + } + } + + *vgroup_mirror= -1; +} + static void copy_vpaint_prev(VPaint *vp, unsigned int *mcol, int tot) { if(vp->vpaint_prev) { @@ -383,32 +420,11 @@ void wpaint_fill(VPaint *wp, Object *ob, float paintweight) } vgroup= ob->actdef-1; - - /* directly copied from weight_paint, should probaby split into a separate function */ + /* if mirror painting, find the other group */ if(me->editflag & ME_EDIT_MIRROR_X) { - bDeformGroup *defgroup= BLI_findlink(&ob->defbase, ob->actdef-1); - if(defgroup) { - bDeformGroup *curdef; - int actdef= 0; - char name[32]; - - flip_side_name(name, defgroup->name, FALSE); - - for (curdef = ob->defbase.first; curdef; curdef=curdef->next, actdef++) - if (!strcmp(curdef->name, name)) - break; - if(curdef==NULL) { - int olddef= ob->actdef; /* tsk, ED_vgroup_add sets the active defgroup */ - curdef= ED_vgroup_add_name (ob, name); - ob->actdef= olddef; - } - - if(curdef && curdef!=defgroup) - vgroup_mirror= actdef; - } + wpaint_mirror_vgroup_ensure(ob, &vgroup_mirror); } - /* end copy from weight_paint*/ copy_wpaint_prev(wp, me->dvert, me->totvert); @@ -1351,26 +1367,7 @@ static int wpaint_stroke_test_start(bContext *C, wmOperator *op, wmEvent *UNUSED /* if mirror painting, find the other group */ if(me->editflag & ME_EDIT_MIRROR_X) { - bDeformGroup *defgroup= BLI_findlink(&ob->defbase, ob->actdef-1); - if(defgroup) { - bDeformGroup *curdef; - int actdef= 0; - char name[32]; - - flip_side_name(name, defgroup->name, FALSE); - - for (curdef = ob->defbase.first; curdef; curdef=curdef->next, actdef++) - if (!strcmp(curdef->name, name)) - break; - if(curdef==NULL) { - int olddef= ob->actdef; /* tsk, ED_vgroup_add sets the active defgroup */ - curdef= ED_vgroup_add_name (ob, name); - ob->actdef= olddef; - } - - if(curdef && curdef!=defgroup) - wpd->vgroup_mirror= actdef; - } + wpaint_mirror_vgroup_ensure(ob, &wpd->vgroup_mirror); } return 1; |