GPv3: Add "Set Curve Resolution" operator

Set the resolution of the selected curves.

Pull Request: https://projects.blender.org/blender/blender/pulls/125235
This commit is contained in:
Falk David
2024-07-23 15:23:35 +02:00
committed by Falk David
parent 752fad886a
commit ccc5922ece
3 changed files with 69 additions and 0 deletions

View File

@@ -6148,6 +6148,7 @@ class VIEW3D_MT_edit_greasepencil_stroke(Menu):
layout.separator()
layout.operator_menu_enum("grease_pencil.set_curve_type", property="type")
layout.operator("grease_pencil.set_curve_resolution")
class VIEW3D_MT_edit_greasepencil_point(Menu):

View File

@@ -752,6 +752,7 @@ void Drawing::tag_positions_changed()
void Drawing::tag_topology_changed()
{
this->tag_positions_changed();
this->strokes_for_write().tag_topology_changed();
}
DrawingReference::DrawingReference()

View File

@@ -3129,6 +3129,72 @@ static void GREASE_PENCIL_OT_set_handle_type(wmOperatorType *ot)
/** \} */
/* -------------------------------------------------------------------- */
/** \name Set Curve Resolution Operator
* \{ */
static int grease_pencil_set_curve_resolution_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);
const int resolution = RNA_int_get(op->ptr, "resolution");
bool changed = false;
const Vector<MutableDrawingInfo> drawings = retrieve_editable_drawings(*scene, grease_pencil);
threading::parallel_for_each(drawings, [&](const MutableDrawingInfo &info) {
bke::CurvesGeometry &curves = info.drawing.strokes_for_write();
IndexMaskMemory memory;
const IndexMask editable_strokes = ed::greasepencil::retrieve_editable_and_selected_strokes(
*object, info.drawing, info.layer_index, memory);
if (editable_strokes.is_empty()) {
return;
}
if (curves.is_single_type(CURVE_TYPE_POLY)) {
return;
}
index_mask::masked_fill(curves.resolution_for_write(), resolution, editable_strokes);
info.drawing.tag_positions_changed();
changed = true;
});
if (changed) {
DEG_id_tag_update(&grease_pencil.id, ID_RECALC_GEOMETRY);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, &grease_pencil);
}
return OPERATOR_FINISHED;
}
static void GREASE_PENCIL_OT_set_curve_resolution(wmOperatorType *ot)
{
/* Identifiers. */
ot->name = "Set Curve Resolution";
ot->idname = "GREASE_PENCIL_OT_set_curve_resolution";
ot->description = "Set resolution of selected curves";
/* Callbacks. */
ot->exec = grease_pencil_set_curve_resolution_exec;
ot->poll = editable_grease_pencil_poll;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
RNA_def_int(ot->srna,
"resolution",
12,
0,
10000,
"Resolution",
"The resolution to use for each curve segment",
1,
64);
}
/** \} */
} // namespace blender::ed::greasepencil
void ED_operatortypes_grease_pencil_edit()
@@ -3162,5 +3228,6 @@ void ED_operatortypes_grease_pencil_edit()
WM_operatortype_append(GREASE_PENCIL_OT_snap_to_cursor);
WM_operatortype_append(GREASE_PENCIL_OT_snap_cursor_to_selected);
WM_operatortype_append(GREASE_PENCIL_OT_set_curve_type);
WM_operatortype_append(GREASE_PENCIL_OT_set_curve_resolution);
WM_operatortype_append(GREASE_PENCIL_OT_set_handle_type);
}