[Bf-blender-cvs] [36121a1bdcd] blender2.8: GP: Changes in API to make internal update

Antonioya noreply at git.blender.org
Thu Dec 20 16:54:39 CET 2018


Commit: 36121a1bdcd8b0122996d9125e0cd4972dd51ff0
Author: Antonioya
Date:   Thu Dec 20 16:52:03 2018 +0100
Branches: blender2.8
https://developer.blender.org/rB36121a1bdcd8b0122996d9125e0cd4972dd51ff0

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

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

M	source/blender/draw/engines/gpencil/gpencil_cache_utils.c
M	source/blender/makesdna/DNA_gpencil_types.h
M	source/blender/makesrna/intern/rna_gpencil.c

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
index 63af8ecc141..e733b7e0f1f 100644
--- a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
@@ -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
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index 934ef4a4829..4ed87a487fc 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -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 */
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index 9c90628f262..8c6ad207bc4 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -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);
 }



More information about the Bf-blender-cvs mailing list