GPv3: Invert weight operator
Port gp legacy "invert weight" operator. Pull Request: https://projects.blender.org/blender/blender/pulls/126275
This commit is contained in:
committed by
Pratik Borhade
parent
94d3b764e7
commit
7bfdc6dfea
@@ -5986,7 +5986,8 @@ class VIEW3D_MT_weight_grease_pencil(Menu):
|
||||
bl_label = "Weights"
|
||||
|
||||
def draw(self, _context):
|
||||
pass
|
||||
layout = self.layout
|
||||
layout.operator("grease_pencil.weight_invert", text="Invert Weight")
|
||||
|
||||
|
||||
class VIEW3D_MT_gpencil_animation(Menu):
|
||||
|
||||
@@ -357,6 +357,63 @@ static void GREASE_PENCIL_OT_weight_toggle_direction(wmOperatorType *ot)
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
}
|
||||
|
||||
static int grease_pencil_weight_invert_exec(bContext *C, wmOperator * /*op*/)
|
||||
{
|
||||
const Scene &scene = *CTX_data_scene(C);
|
||||
Object *object = CTX_data_active_object(C);
|
||||
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(object->data);
|
||||
|
||||
/* Object vgroup index. */
|
||||
const int active_index = BKE_object_defgroup_active_index_get(object) - 1;
|
||||
if (active_index == -1) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
const bDeformGroup *active_defgroup = static_cast<const bDeformGroup *>(
|
||||
BLI_findlink(BKE_object_defgroup_list(object), active_index));
|
||||
|
||||
Vector<MutableDrawingInfo> drawings = retrieve_editable_drawings(scene, grease_pencil);
|
||||
|
||||
threading::parallel_for_each(drawings, [&](MutableDrawingInfo info) {
|
||||
bke::CurvesGeometry &curves = info.drawing.strokes_for_write();
|
||||
/* Active vgroup index of drawing. */
|
||||
const int drawing_vgroup_index = BLI_findstringindex(
|
||||
&curves.vertex_group_names, active_defgroup->name, offsetof(bDeformGroup, name));
|
||||
BLI_assert(drawing_vgroup_index != -1);
|
||||
|
||||
VMutableArray<float> weights = bke::varray_for_mutable_deform_verts(
|
||||
curves.deform_verts_for_write(), drawing_vgroup_index);
|
||||
|
||||
if (weights.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const int i : weights.index_range()) {
|
||||
const float invert_weight = 1 - weights[i];
|
||||
weights.set(i, invert_weight);
|
||||
}
|
||||
});
|
||||
|
||||
DEG_id_tag_update(&grease_pencil.id, ID_RECALC_GEOMETRY);
|
||||
WM_event_add_notifier(C, NC_GEOM | ND_DATA, &grease_pencil);
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
void GREASE_PENCIL_OT_weight_invert(wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
ot->name = "Invert Weight";
|
||||
ot->idname = "GREASE_PENCIL_OT_weight_invert";
|
||||
ot->description = "Invert the weight of active vertex group";
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec = grease_pencil_weight_invert_exec;
|
||||
ot->poll = grease_pencil_weight_painting_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_UNDO | OPTYPE_REGISTER;
|
||||
}
|
||||
|
||||
} // namespace blender::ed::greasepencil
|
||||
|
||||
void ED_operatortypes_grease_pencil_weight_paint()
|
||||
@@ -364,4 +421,5 @@ void ED_operatortypes_grease_pencil_weight_paint()
|
||||
using namespace blender::ed::greasepencil;
|
||||
WM_operatortype_append(GREASE_PENCIL_OT_weight_toggle_direction);
|
||||
WM_operatortype_append(GREASE_PENCIL_OT_weight_sample);
|
||||
WM_operatortype_append(GREASE_PENCIL_OT_weight_invert);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user