[Bf-blender-cvs] [faf45091b45] master: GPencil: New python API to force stroke triangulation data update

Antonio Vazquez noreply at git.blender.org
Fri Feb 5 19:15:16 CET 2021


Commit: faf45091b454bb99089e82533b12b549efb1a5c7
Author: Antonio Vazquez
Date:   Fri Feb 5 19:14:35 2021 +0100
Branches: master
https://developer.blender.org/rBfaf45091b454bb99089e82533b12b549efb1a5c7

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()`

===================================================================

M	source/blender/makesrna/intern/rna_gpencil.c

===================================================================

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 */



More information about the Bf-blender-cvs mailing list