GP: Changes in API to make internal update
Now, the internal data is recalculated when add or remove a point. The change in the API affect to stroke.points.add() that now requires a datablock parameter. This parameter is required to identify the datablock affected. For example: stroke.points.add(gpencil, 1) instead of stroke.points.add(1) This is the second try to fix T59600
This commit is contained in:
@@ -186,6 +186,10 @@ static bool gpencil_batch_cache_valid(GpencilBatchCache *cache, bGPdata *gpd, in
|
||||
else if (gpd->flag & GP_DATA_CACHE_IS_DIRTY) {
|
||||
valid = false;
|
||||
}
|
||||
else if (gpd->flag & GP_DATA_PYTHON_UPDATED) {
|
||||
gpd->flag &= ~GP_DATA_PYTHON_UPDATED;
|
||||
valid = false;
|
||||
}
|
||||
else if (DRW_gpencil_onion_active(gpd)) {
|
||||
/* if onion, set as dirty always
|
||||
* This reduces performance, but avoid any crash in the multiple
|
||||
|
||||
@@ -481,6 +481,8 @@ typedef enum eGPdata_Flag {
|
||||
GP_DATA_UV_ADAPTATIVE = (1 << 19),
|
||||
/* Autolock not active layers */
|
||||
GP_DATA_AUTOLOCK_LAYERS = (1 << 20),
|
||||
/* Internal flag for python update */
|
||||
GP_DATA_PYTHON_UPDATED = (1 << 21),
|
||||
} eGPdata_Flag;
|
||||
|
||||
/* gpd->onion_flag */
|
||||
|
||||
@@ -500,7 +500,7 @@ static void rna_GPencil_stroke_point_select_set(PointerRNA *ptr, const bool valu
|
||||
}
|
||||
}
|
||||
|
||||
static void rna_GPencil_stroke_point_add(bGPDstroke *stroke, int count, float pressure, float strength)
|
||||
static void rna_GPencil_stroke_point_add(bGPDstroke *stroke, bGPdata *gpd, int count, float pressure, float strength)
|
||||
{
|
||||
if (count > 0) {
|
||||
/* create space at the end of the array for extra points */
|
||||
@@ -525,10 +525,19 @@ static void rna_GPencil_stroke_point_add(bGPDstroke *stroke, int count, float pr
|
||||
}
|
||||
|
||||
stroke->totpoints += count;
|
||||
|
||||
stroke->flag |= GP_STROKE_RECALC_CACHES;
|
||||
|
||||
DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
|
||||
|
||||
gpd->flag |= GP_DATA_PYTHON_UPDATED;
|
||||
DEG_id_tag_update(&gpd->id, ID_RECALC_COPY_ON_WRITE);
|
||||
|
||||
WM_main_add_notifier(NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void rna_GPencil_stroke_point_pop(bGPDstroke *stroke, ReportList *reports, int index)
|
||||
static void rna_GPencil_stroke_point_pop(bGPDstroke *stroke, ReportList *reports, bGPdata *gpd, int index)
|
||||
{
|
||||
bGPDspoint *pt_tmp = stroke->points;
|
||||
MDeformVert *pt_dvert = stroke->dvert;
|
||||
@@ -571,6 +580,12 @@ static void rna_GPencil_stroke_point_pop(bGPDstroke *stroke, ReportList *reports
|
||||
MEM_freeN(pt_dvert);
|
||||
}
|
||||
|
||||
stroke->flag |= GP_STROKE_RECALC_CACHES;
|
||||
|
||||
DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
|
||||
|
||||
gpd->flag |= GP_DATA_PYTHON_UPDATED;
|
||||
DEG_id_tag_update(&gpd->id, ID_RECALC_COPY_ON_WRITE);
|
||||
WM_main_add_notifier(NC_GPENCIL | NA_EDITED, NULL);
|
||||
}
|
||||
|
||||
@@ -805,6 +820,8 @@ static void rna_def_gpencil_stroke_points_api(BlenderRNA *brna, PropertyRNA *cpr
|
||||
|
||||
func = RNA_def_function(srna, "add", "rna_GPencil_stroke_point_add");
|
||||
RNA_def_function_ui_description(func, "Add a new grease pencil stroke point");
|
||||
parm = RNA_def_pointer(func, "gpd", "GreasePencil", "", "Grease pencil datablock");
|
||||
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
|
||||
parm = RNA_def_int(func, "count", 1, 0, INT_MAX, "Number", "Number of points to add to the stroke", 0, INT_MAX);
|
||||
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
|
||||
RNA_def_float(func, "pressure", 1.0f, 0.0f, 1.0f, "Pressure", "Pressure for newly created points", 0.0f, 1.0f);
|
||||
@@ -812,6 +829,8 @@ static void rna_def_gpencil_stroke_points_api(BlenderRNA *brna, PropertyRNA *cpr
|
||||
|
||||
func = RNA_def_function(srna, "pop", "rna_GPencil_stroke_point_pop");
|
||||
RNA_def_function_ui_description(func, "Remove a grease pencil stroke point");
|
||||
parm = RNA_def_pointer(func, "gpd", "GreasePencil", "", "Grease pencil datablock");
|
||||
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
|
||||
RNA_def_function_flag(func, FUNC_USE_REPORTS);
|
||||
RNA_def_int(func, "index", -1, INT_MIN, INT_MAX, "Index", "point index", INT_MIN, INT_MAX);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user