GPv3: Assign material #113573
|
@ -554,7 +554,10 @@ class GreasePencilMaterialsPanel:
|
|||
icon_link = 'MESH_DATA' if slot.link == 'DATA' else 'OBJECT_DATA'
|
||||
row.prop(slot, "link", icon=icon_link, icon_only=True)
|
||||
|
||||
if not is_grease_pencil_version3 and ob.data.use_stroke_edit_mode:
|
||||
if is_grease_pencil_version3 and ob.mode == 'EDIT':
|
||||
row = layout.row(align=True)
|
||||
row.operator("grease_pencil.stroke_change_color", text="Assign")
|
||||
elif not is_grease_pencil_version3 and ob.data.use_stroke_edit_mode:
|
||||
row = layout.row(align=True)
|
||||
row.operator("gpencil.stroke_change_color", text="Assign")
|
||||
row.operator("gpencil.material_select", text="Select").deselect = False
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
namespace blender::ed::curves {
|
||||
|
||||
static IndexMask retrieve_selected_curves(const bke::CurvesGeometry &curves,
|
||||
IndexMask retrieve_selected_curves(const bke::CurvesGeometry &curves,
|
||||
IndexMaskMemory &memory)
|
||||
{
|
||||
const IndexRange curves_range = curves.curves_range();
|
||||
|
|
|
@ -799,6 +799,56 @@ static void GREASE_PENCIL_OT_delete_frame(wmOperatorType *ot)
|
|||
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
||||
}
|
||||
|
||||
static int grease_pencil_stroke_change_color_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);
|
||||
const int material_index = object->actcol - 1;
|
||||
|
||||
if (material_index == -1) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
grease_pencil.foreach_editable_drawing(
|
||||
scene->r.cfra, [&](int /*drawing_index*/, bke::greasepencil::Drawing &drawing) {
|
||||
bke::CurvesGeometry &curves = drawing.strokes_for_write();
|
||||
|
||||
if (curves.points_num() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
bke::SpanAttributeWriter<int> materials = curves.attributes_for_write().lookup_or_add_for_write_span<int>(
|
||||
"material_index", ATTR_DOMAIN_CURVE);
|
||||
|
||||
filedescriptor marked this conversation as resolved
|
||||
IndexMaskMemory memory;
|
||||
IndexMask selected_curves = ed::curves::retrieve_selected_curves(curves, memory);
|
||||
|
||||
selected_curves.foreach_index(
|
||||
[&](const int curve_index) { materials.span[curve_index] = material_index;
|
||||
filedescriptor marked this conversation as resolved
Outdated
Falk David
commented
With the change above, you can now do:
With the change above, you can now do:
```
selected_curves.foreach_index([&](GrainSize(512), [&](const int curve_index) {
materials.span[curve_index] = material_index;
});
```
|
||||
});
|
||||
|
||||
materials.finish();
|
||||
});
|
||||
|
||||
DEG_id_tag_update(&grease_pencil.id, ID_RECALC_GEOMETRY);
|
||||
WM_event_add_notifier(C, NC_GEOM | ND_DATA | NA_EDITED, &grease_pencil);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
static void GREASE_PENCIL_OT_stroke_change_color(wmOperatorType* ot)
|
||||
{
|
||||
ot->name = "Change Stroke color";
|
||||
ot->idname = "GREASE_PENCIL_OT_stroke_change_color";
|
||||
ot->description = "Change Stroke color with selected material";
|
||||
|
||||
ot->exec = grease_pencil_stroke_change_color_exec;
|
||||
ot->poll = editable_grease_pencil_poll;
|
||||
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
}
|
||||
/** \} */
|
||||
|
||||
} // namespace blender::ed::greasepencil
|
||||
|
@ -810,6 +860,7 @@ void ED_operatortypes_grease_pencil_edit()
|
|||
WM_operatortype_append(GREASE_PENCIL_OT_stroke_simplify);
|
||||
WM_operatortype_append(GREASE_PENCIL_OT_dissolve);
|
||||
WM_operatortype_append(GREASE_PENCIL_OT_delete_frame);
|
||||
WM_operatortype_append(GREASE_PENCIL_OT_stroke_change_color);
|
||||
}
|
||||
|
||||
void ED_keymap_grease_pencil(wmKeyConfig *keyconf)
|
||||
|
|
|
@ -134,6 +134,7 @@ bool has_anything_selected(const VArray<bool> &varray, IndexRange range_to_check
|
|||
* Find curves that have any point selected (a selection factor greater than zero),
|
||||
* or curves that have their own selection factor greater than zero.
|
||||
*/
|
||||
IndexMask retrieve_selected_curves(const bke::CurvesGeometry &curves, IndexMaskMemory &memory);
|
||||
IndexMask retrieve_selected_curves(const Curves &curves_id, IndexMaskMemory &memory);
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Use
(you'll have to make
retrieve_selected_curves
non-static and declare it in theED_curves.hh
header).