From faf45091b454bb99089e82533b12b549efb1a5c7 Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Fri, 5 Feb 2021 19:14:35 +0100 Subject: GPencil: New python API to force stroke triangulation data update In some python scripts, the coordinates of the points are manipulated, but there are no way to force the recalculation and need hack to force the refresh. The new api allows to call to the refresh function directly. example: `gp_stroke.points.update()` --- source/blender/makesrna/intern/rna_gpencil.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'source/blender/makesrna') diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c index 209dc21d386..4d9c53df013 100644 --- a/source/blender/makesrna/intern/rna_gpencil.c +++ b/source/blender/makesrna/intern/rna_gpencil.c @@ -816,6 +816,21 @@ static void rna_GPencil_stroke_point_pop(ID *id, WM_main_add_notifier(NC_GPENCIL | NA_EDITED, NULL); } +static void rna_GPencil_stroke_point_update(ID *id, bGPDstroke *stroke) +{ + bGPdata *gpd = (bGPdata *)id; + + /* Calc geometry data. */ + if (stroke) { + BKE_gpencil_stroke_geometry_update(gpd, stroke); + + DEG_id_tag_update(&gpd->id, + ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE); + + WM_main_add_notifier(NC_GPENCIL | NA_EDITED, NULL); + } +} + static bGPDstroke *rna_GPencil_stroke_new(bGPDframe *frame) { bGPDstroke *stroke = BKE_gpencil_stroke_new(0, 0, 1.0f); @@ -1274,6 +1289,10 @@ static void rna_def_gpencil_stroke_points_api(BlenderRNA *brna, PropertyRNA *cpr RNA_def_function_ui_description(func, "Remove a grease pencil stroke point"); RNA_def_function_flag(func, FUNC_USE_REPORTS | FUNC_USE_SELF_ID); RNA_def_int(func, "index", -1, INT_MIN, INT_MAX, "Index", "point index", INT_MIN, INT_MAX); + + func = RNA_def_function(srna, "update", "rna_GPencil_stroke_point_update"); + RNA_def_function_ui_description(func, "Recalculate internal triangulation data"); + RNA_def_function_flag(func, FUNC_USE_SELF_ID); } /* This information is read only and it can be used by add-ons */ -- cgit v1.2.3