Weight Paint: Make multi-paint & mirror work as if bone selection was symmetric

The simplest way of handling mirroring in multi-paint is creating a
uniform symmetric selection and relying on existing symmetric weights
to direct changes to the appropriate vertex groups. This already works
if mirror bones are selected manually, and can be made easier to use
by doing it implicitly.
This commit is contained in:
Alexander Gavrilov 2016-01-21 08:03:15 +11:00 committed by Campbell Barton
parent 3c74968aa4
commit 5ef2ed23e1
4 changed files with 44 additions and 5 deletions

View File

@ -68,6 +68,10 @@ bool *BKE_object_defgroup_lock_flags_get(struct Object *ob, const int defbase_to
bool *BKE_object_defgroup_validmap_get(struct Object *ob, const int defbase_tot);
bool *BKE_object_defgroup_selected_get(struct Object *ob, int defbase_tot, int *r_dg_flags_sel_tot);
void BKE_object_defgroup_mirror_selection(
struct Object *ob, int defbase_tot, const bool *selection,
bool *dg_flags_sel, int *r_dg_flags_sel_tot);
#ifdef __cplusplus
}
#endif

View File

@ -1322,7 +1322,8 @@ enum {
CALC_WP_GROUP_USER_ALL = (1 << 2),
CALC_WP_MULTIPAINT = (1 << 3),
CALC_WP_AUTO_NORMALIZE = (1 << 4)
CALC_WP_AUTO_NORMALIZE = (1 << 4),
CALC_WP_MIRROR_X = (1 << 5),
};
typedef struct DMWeightColorInfo {
@ -1331,12 +1332,13 @@ typedef struct DMWeightColorInfo {
} DMWeightColorInfo;
static int dm_drawflag_calc(const ToolSettings *ts)
static int dm_drawflag_calc(const ToolSettings *ts, const Mesh *me)
{
return ((ts->multipaint ? CALC_WP_MULTIPAINT : 0) |
/* CALC_WP_GROUP_USER_ACTIVE or CALC_WP_GROUP_USER_ALL*/
(1 << ts->weightuser) |
(ts->auto_normalize ? CALC_WP_AUTO_NORMALIZE : 0));
(ts->auto_normalize ? CALC_WP_AUTO_NORMALIZE : 0) |
((me->editflag & ME_EDIT_MIRROR_X) ? CALC_WP_MIRROR_X : 0));
}
static void weightpaint_color(unsigned char r_col[4], DMWeightColorInfo *dm_wcinfo, const float input)
@ -1442,6 +1444,10 @@ static void calc_weightpaint_vert_array(
if (draw_flag & CALC_WP_MULTIPAINT) {
defbase_sel = BKE_object_defgroup_selected_get(ob, defbase_tot, &defbase_sel_tot);
if (defbase_sel_tot > 1 && (draw_flag & CALC_WP_MIRROR_X)) {
BKE_object_defgroup_mirror_selection(ob, defbase_tot, defbase_sel, defbase_sel, &defbase_sel_tot);
}
}
for (i = numVerts; i != 0; i--, wc++, dv++) {
@ -1716,7 +1722,7 @@ static void mesh_calc_modifiers(
bool multires_applied = false;
const bool sculpt_mode = ob->mode & OB_MODE_SCULPT && ob->sculpt && !useRenderParams;
const bool sculpt_dyntopo = (sculpt_mode && ob->sculpt->bm) && !useRenderParams;
const int draw_flag = dm_drawflag_calc(scene->toolsettings);
const int draw_flag = dm_drawflag_calc(scene->toolsettings, me);
/* Generic preview only in object mode! */
const bool do_mod_mcol = (ob->mode == OB_MODE_OBJECT);
@ -2257,7 +2263,7 @@ static void editbmesh_calc_modifiers(
int i, numVerts = 0, cageIndex = modifiers_getCageIndex(scene, ob, NULL, 1);
CDMaskLink *datamasks, *curr;
const int required_mode = eModifierMode_Realtime | eModifierMode_Editmode;
int draw_flag = dm_drawflag_calc(scene->toolsettings);
int draw_flag = dm_drawflag_calc(scene->toolsettings, ob->data);
// const bool do_mod_mcol = true; // (ob->mode == OB_MODE_OBJECT);
#if 0 /* XXX Will re-enable this when we have global mod stack options. */

View File

@ -596,6 +596,30 @@ bool *BKE_object_defgroup_selected_get(Object *ob, int defbase_tot, int *r_dg_fl
return dg_selection;
}
/* Marks mirror vgroups in output and counts them. Output and counter assumed to be already initialized.
* Designed to be usable after BKE_object_defgroup_selected_get to extend selection to mirror.
*/
void BKE_object_defgroup_mirror_selection(
struct Object *ob, int defbase_tot, const bool *dg_selection,
bool *dg_flags_sel, int *r_dg_flags_sel_tot)
{
bDeformGroup *defgroup;
unsigned int i, i_mirr;
for (i = 0, defgroup = ob->defbase.first; i < defbase_tot && defgroup; defgroup = defgroup->next, i++) {
if (dg_selection[i]) {
char name_flip[MAXBONENAME];
BKE_deform_flip_side_name(name_flip, defgroup->name, false);
i_mirr = STREQ(name_flip, defgroup->name) ? i : defgroup_name_index(ob, name_flip);
if ((i_mirr >= 0 && i_mirr < defbase_tot) && (dg_flags_sel[i_mirr] == false)) {
dg_flags_sel[i_mirr] = true;
(*r_dg_flags_sel_tot) += 1;
}
}
}
}
/**
* Return the subset type of the Vertex Group Selection

View File

@ -1017,6 +1017,11 @@ static int weight_sample_invoke(bContext *C, wmOperator *op, const wmEvent *even
bool *defbase_sel = BKE_object_defgroup_selected_get(vc.obact, defbase_tot, &defbase_tot_sel);
if (defbase_tot_sel > 1) {
if (me->editflag & ME_EDIT_MIRROR_X) {
BKE_object_defgroup_mirror_selection(
vc.obact, defbase_tot, defbase_sel, defbase_sel, &defbase_tot_sel);
}
vgroup_weight = BKE_defvert_multipaint_collective_weight(
&me->dvert[v_idx_best], defbase_tot, defbase_sel, defbase_tot_sel, ts->auto_normalize);