Fix #107918: Weight Gradient tool paints over locked vertex groups #108974

Manually merged
Sybren A. Stüvel merged 4 commits from PratikPB2123/blender:107918-gradient-lock-vgroup into main 2023-07-27 11:32:38 +02:00
3 changed files with 25 additions and 3 deletions

View File

@ -143,6 +143,12 @@ bool BKE_object_defgroup_check_lock_relative_multi(int defbase_tot,
const bool *lock_flags,
const bool *selected,
int sel_tot);
/**
* Return lock status of active vertex group.
*/
bool BKE_object_defgroup_active_is_locked(struct Object *ob);

ob should be a const pointer, as it won't get changed by this function.

`ob` should be a `const` pointer, as it won't get changed by this function.
/**
* Takes a pair of boolean masks of all locked and all deform groups, and computes
* a pair of masks for locked deform and unlocked deform groups. Output buffers may

View File

@ -679,6 +679,14 @@ bool BKE_object_defgroup_check_lock_relative_multi(int defbase_tot,
return true;
}
bool BKE_object_defgroup_active_is_locked(Object *ob)
{
Mesh *me = (Mesh *)ob->data;
bDeformGroup *dg = (bDeformGroup *)BLI_findlink(&me->vertex_group_names,
me->vertex_group_active_index - 1);
return dg->flag & DG_LOCK_WEIGHT;
}
void BKE_object_defgroup_split_locked_validmap(
int defbase_tot, const bool *locked, const bool *deform, bool *r_locked, bool *r_unlocked)
{

View File

@ -731,7 +731,16 @@ static int paint_weight_gradient_modal(bContext *C, wmOperator *op, const wmEven
wmGesture *gesture = static_cast<wmGesture *>(op->customdata);
WPGradient_vertStoreBase *vert_cache = static_cast<WPGradient_vertStoreBase *>(
gesture->user_data.data);
int ret = WM_gesture_straightline_modal(C, op, event);
Object *ob = CTX_data_active_object(C);
int ret;
if (BKE_object_defgroup_active_is_locked(ob)) {
BKE_report(op->reports, RPT_WARNING, "Active group is locked, aborting");
ret = OPERATOR_CANCELLED;
}
else {
ret = WM_gesture_straightline_modal(C, op, event);
}
if (ret & OPERATOR_RUNNING_MODAL) {
if (event->type == LEFTMOUSE && event->val == KM_RELEASE) { /* XXX, hardcoded */
@ -743,10 +752,9 @@ static int paint_weight_gradient_modal(bContext *C, wmOperator *op, const wmEven
}
if (ret & OPERATOR_CANCELLED) {
Object *ob = CTX_data_active_object(C);
if (vert_cache != nullptr) {
Mesh *me = static_cast<Mesh *>(ob->data);
if (vert_cache->wpp.wpaint_prev) {
Mesh *me = static_cast<Mesh *>(ob->data);
MDeformVert *dvert = BKE_mesh_deform_verts_for_write(me);
BKE_defvert_array_free_elems(dvert, me->totvert);
BKE_defvert_array_copy(dvert, vert_cache->wpp.wpaint_prev, me->totvert);