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()`
This commit is contained in:
Antonio Vazquez 2021-02-05 19:14:35 +01:00
parent 5dc87a3ca5
commit faf45091b4
1 changed files with 19 additions and 0 deletions

View File

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