From ccc5922ece2c6dc9b313cb07ed373e8bb658d486 Mon Sep 17 00:00:00 2001 From: Falk David Date: Tue, 23 Jul 2024 15:23:35 +0200 Subject: [PATCH] GPv3: Add "Set Curve Resolution" operator Set the resolution of the selected curves. Pull Request: https://projects.blender.org/blender/blender/pulls/125235 --- scripts/startup/bl_ui/space_view3d.py | 1 + .../blenkernel/intern/grease_pencil.cc | 1 + .../intern/grease_pencil_edit.cc | 67 +++++++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/scripts/startup/bl_ui/space_view3d.py b/scripts/startup/bl_ui/space_view3d.py index 5e961615070..0a3aad1a652 100644 --- a/scripts/startup/bl_ui/space_view3d.py +++ b/scripts/startup/bl_ui/space_view3d.py @@ -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): diff --git a/source/blender/blenkernel/intern/grease_pencil.cc b/source/blender/blenkernel/intern/grease_pencil.cc index be1de9a6feb..c1f311b96c2 100644 --- a/source/blender/blenkernel/intern/grease_pencil.cc +++ b/source/blender/blenkernel/intern/grease_pencil.cc @@ -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() diff --git a/source/blender/editors/grease_pencil/intern/grease_pencil_edit.cc b/source/blender/editors/grease_pencil/intern/grease_pencil_edit.cc index 8325398e62b..3fb4c0a55d3 100644 --- a/source/blender/editors/grease_pencil/intern/grease_pencil_edit.cc +++ b/source/blender/editors/grease_pencil/intern/grease_pencil_edit.cc @@ -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(object->data); + + const int resolution = RNA_int_get(op->ptr, "resolution"); + + bool changed = false; + const Vector 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); }