GPv3: Set selected curve material as active material
This operator assigns the material of the first selected curve as active material. Related to #113569 Pull Request: https://projects.blender.org/blender/blender/pulls/114188
This commit is contained in:
committed by
Falk David
parent
212a1cfb4c
commit
a8cb0b0ca0
@@ -5833,6 +5833,10 @@ class VIEW3D_MT_edit_greasepencil_stroke(Menu):
|
||||
|
||||
layout.separator()
|
||||
|
||||
layout.operator("grease_pencil.set_active_material")
|
||||
|
||||
layout.separator()
|
||||
|
||||
layout.operator("grease_pencil.cyclical_set", text="Toggle Cyclic").type = 'TOGGLE'
|
||||
|
||||
|
||||
|
||||
@@ -957,6 +957,54 @@ static void GREASE_PENCIL_OT_cyclical_set(wmOperatorType *ot)
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Set selected material as active material
|
||||
* \{ */
|
||||
static int grease_pencil_set_active_material_exec(bContext *C, wmOperator * /*op*/)
|
||||
{
|
||||
using namespace blender;
|
||||
const Scene *scene = CTX_data_scene(C);
|
||||
Object *object = CTX_data_active_object(C);
|
||||
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(object->data);
|
||||
|
||||
if (object->totcol == 0) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
const Array<MutableDrawingInfo> drawings = retrieve_editable_drawings(*scene, grease_pencil);
|
||||
for (const MutableDrawingInfo &info : drawings) {
|
||||
bke::CurvesGeometry &curves = info.drawing.strokes_for_write();
|
||||
|
||||
IndexMaskMemory memory;
|
||||
IndexMask selected_curves = ed::curves::retrieve_selected_curves(curves, memory);
|
||||
if (selected_curves.is_empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const blender::VArray<int> materials = *curves.attributes().lookup_or_default<int>(
|
||||
"material_index", ATTR_DOMAIN_CURVE, 0);
|
||||
object->actcol = materials[selected_curves.first()] + 1;
|
||||
break;
|
||||
};
|
||||
|
||||
WM_event_add_notifier(C, NC_GEOM | ND_DATA | NA_EDITED, &grease_pencil);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
static void GREASE_PENCIL_OT_set_active_material(wmOperatorType *ot)
|
||||
{
|
||||
ot->name = "Set Active Material";
|
||||
ot->idname = "GREASE_PENCIL_OT_set_active_material";
|
||||
ot->description = "Set the selected stroke material as the active material";
|
||||
|
||||
ot->exec = grease_pencil_set_active_material_exec;
|
||||
ot->poll = editable_grease_pencil_poll;
|
||||
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
}
|
||||
/** \} */
|
||||
|
||||
} // namespace blender::ed::greasepencil
|
||||
|
||||
void ED_operatortypes_grease_pencil_edit()
|
||||
@@ -968,6 +1016,7 @@ void ED_operatortypes_grease_pencil_edit()
|
||||
WM_operatortype_append(GREASE_PENCIL_OT_delete_frame);
|
||||
WM_operatortype_append(GREASE_PENCIL_OT_stroke_material_set);
|
||||
WM_operatortype_append(GREASE_PENCIL_OT_cyclical_set);
|
||||
WM_operatortype_append(GREASE_PENCIL_OT_set_active_material);
|
||||
}
|
||||
|
||||
void ED_keymap_grease_pencil(wmKeyConfig *keyconf)
|
||||
|
||||
Reference in New Issue
Block a user