[Bf-blender-cvs] [ed7048ee053] blender2.8: GP: Add multiframe support to vertex group operators

Antonioya noreply at git.blender.org
Thu Sep 6 13:38:28 CEST 2018


Commit: ed7048ee0537090e9149c9cbb3e6e55aab218677
Author: Antonioya
Date:   Thu Sep 6 13:37:37 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBed7048ee0537090e9149c9cbb3e6e55aab218677

GP: Add multiframe support to vertex group operators

Before, the operators only worked in the current frame

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

M	source/blender/editors/gpencil/gpencil_utils.c

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

diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index b78c292236a..c0aea452385 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -1212,26 +1212,53 @@ void ED_gpencil_add_defaults(bContext *C)
 /* assign points to vertex group */
 void ED_gpencil_vgroup_assign(bContext *C, Object *ob, float weight)
 {
+	bGPdata *gpd = (bGPdata *)ob->data;
+	const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
 	const int def_nr = ob->actdef - 1;
 	if (!BLI_findlink(&ob->defbase, def_nr))
 		return;
 
-	CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes)
+	CTX_DATA_BEGIN(C, bGPDlayer *, gpl, editable_gpencil_layers)
 	{
-		if (gps->flag & GP_STROKE_SELECT) {
-			/* verify the weight array is created */
-			BKE_gpencil_dvert_ensure(gps);
+		bGPDframe *init_gpf = gpl->actframe;
+		bGPDstroke *gps = NULL;
+		if (is_multiedit) {
+			init_gpf = gpl->frames.first;
+		}
 
-			for (int i = 0; i < gps->totpoints; i++) {
-				bGPDspoint *pt = &gps->points[i];
-				MDeformVert *dvert = &gps->dvert[i];
-				if (pt->flag & GP_SPOINT_SELECT) {
-					MDeformWeight *dw = defvert_verify_index(dvert, def_nr);
-					if (dw) {
-						dw->weight = weight;
+		for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) {
+			if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) {
+				if (gpf == NULL)
+					continue;
+
+				for (gps = gpf->strokes.first; gps; gps = gps->next) {
+
+					/* skip strokes that are invalid for current view */
+					if (ED_gpencil_stroke_can_use(C, gps) == false)
+						continue;
+
+					if (gps->flag & GP_STROKE_SELECT) {
+						/* verify the weight array is created */
+						BKE_gpencil_dvert_ensure(gps);
+
+						for (int i = 0; i < gps->totpoints; i++) {
+							bGPDspoint *pt = &gps->points[i];
+							MDeformVert *dvert = &gps->dvert[i];
+							if (pt->flag & GP_SPOINT_SELECT) {
+								MDeformWeight *dw = defvert_verify_index(dvert, def_nr);
+								if (dw) {
+									dw->weight = weight;
+								}
+							}
+						}
 					}
 				}
 			}
+
+			/* if not multiedit, exit loop*/
+			if (!is_multiedit) {
+				break;
+			}
 		}
 	}
 	CTX_DATA_END;
@@ -1240,25 +1267,52 @@ void ED_gpencil_vgroup_assign(bContext *C, Object *ob, float weight)
 /* remove points from vertex group */
 void ED_gpencil_vgroup_remove(bContext *C, Object *ob)
 {
+	bGPdata *gpd = (bGPdata *)ob->data;
+	const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
 	const int def_nr = ob->actdef - 1;
 	if (!BLI_findlink(&ob->defbase, def_nr))
 		return;
 
-	CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes)
+	CTX_DATA_BEGIN(C, bGPDlayer *, gpl, editable_gpencil_layers)
 	{
-		for (int i = 0; i < gps->totpoints; i++) {
-			bGPDspoint *pt = &gps->points[i];
-			if (gps->dvert == NULL) {
-				continue;
-			}
-			MDeformVert *dvert = &gps->dvert[i];
+		bGPDframe *init_gpf = gpl->actframe;
+		bGPDstroke *gps = NULL;
+		if (is_multiedit) {
+			init_gpf = gpl->frames.first;
+		}
+
+		for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) {
+			if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) {
+				if (gpf == NULL)
+					continue;
+
+				for (gps = gpf->strokes.first; gps; gps = gps->next) {
 
-			if ((pt->flag & GP_SPOINT_SELECT) && (dvert->totweight > 0)) {
-				MDeformWeight *dw = defvert_find_index(dvert, def_nr);
-				if (dw != NULL) {
-					defvert_remove_group(dvert, dw);
+					/* skip strokes that are invalid for current view */
+					if (ED_gpencil_stroke_can_use(C, gps) == false)
+						continue;
+
+					for (int i = 0; i < gps->totpoints; i++) {
+						bGPDspoint *pt = &gps->points[i];
+						if (gps->dvert == NULL) {
+							continue;
+						}
+						MDeformVert *dvert = &gps->dvert[i];
+
+						if ((pt->flag & GP_SPOINT_SELECT) && (dvert->totweight > 0)) {
+							MDeformWeight *dw = defvert_find_index(dvert, def_nr);
+							if (dw != NULL) {
+								defvert_remove_group(dvert, dw);
+							}
+						}
+					}
 				}
 			}
+
+			/* if not multiedit, exit loop*/
+			if (!is_multiedit) {
+				break;
+			}
 		}
 	}
 	CTX_DATA_END;
@@ -1267,22 +1321,49 @@ void ED_gpencil_vgroup_remove(bContext *C, Object *ob)
 /* select points of vertex group */
 void ED_gpencil_vgroup_select(bContext *C, Object *ob)
 {
+	bGPdata *gpd = (bGPdata *)ob->data;
+	const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
 	const int def_nr = ob->actdef - 1;
 	if (!BLI_findlink(&ob->defbase, def_nr))
 		return;
 
-	CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes)
+	CTX_DATA_BEGIN(C, bGPDlayer *, gpl, editable_gpencil_layers)
 	{
-		for (int i = 0; i < gps->totpoints; i++) {
-			bGPDspoint *pt = &gps->points[i];
-			if (gps->dvert == NULL) {
-				continue;
+		bGPDframe *init_gpf = gpl->actframe;
+		bGPDstroke *gps = NULL;
+		if (is_multiedit) {
+			init_gpf = gpl->frames.first;
+		}
+
+		for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) {
+			if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) {
+				if (gpf == NULL)
+					continue;
+
+				for (gps = gpf->strokes.first; gps; gps = gps->next) {
+
+					/* skip strokes that are invalid for current view */
+					if (ED_gpencil_stroke_can_use(C, gps) == false)
+						continue;
+
+					for (int i = 0; i < gps->totpoints; i++) {
+						bGPDspoint *pt = &gps->points[i];
+						if (gps->dvert == NULL) {
+							continue;
+						}
+						MDeformVert *dvert = &gps->dvert[i];
+
+						if (defvert_find_index(dvert, def_nr) != NULL) {
+							pt->flag |= GP_SPOINT_SELECT;
+							gps->flag |= GP_STROKE_SELECT;
+						}
+					}
+				}
 			}
-			MDeformVert *dvert = &gps->dvert[i];
 
-			if (defvert_find_index(dvert, def_nr) != NULL) {
-				pt->flag |= GP_SPOINT_SELECT;
-				gps->flag |= GP_STROKE_SELECT;
+			/* if not multiedit, exit loop*/
+			if (!is_multiedit) {
+				break;
 			}
 		}
 	}
@@ -1292,22 +1373,48 @@ void ED_gpencil_vgroup_select(bContext *C, Object *ob)
 /* unselect points of vertex group */
 void ED_gpencil_vgroup_deselect(bContext *C, Object *ob)
 {
+	bGPdata *gpd = (bGPdata *)ob->data;
+	const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
 	const int def_nr = ob->actdef - 1;
 	if (!BLI_findlink(&ob->defbase, def_nr))
 		return;
 
-	CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes)
+	CTX_DATA_BEGIN(C, bGPDlayer *, gpl, editable_gpencil_layers)
 	{
-		for (int i = 0; i < gps->totpoints; i++) {
-			bGPDspoint *pt = &gps->points[i];
-			if (gps->dvert == NULL) {
-				continue;
+		bGPDframe *init_gpf = gpl->actframe;
+		bGPDstroke *gps = NULL;
+		if (is_multiedit) {
+			init_gpf = gpl->frames.first;
+		}
+
+		for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) {
+			if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) {
+				if (gpf == NULL)
+					continue;
+
+				for (gps = gpf->strokes.first; gps; gps = gps->next) {
+
+					/* skip strokes that are invalid for current view */
+					if (ED_gpencil_stroke_can_use(C, gps) == false)
+						continue;
+
+					for (int i = 0; i < gps->totpoints; i++) {
+						bGPDspoint *pt = &gps->points[i];
+						if (gps->dvert == NULL) {
+							continue;
+						}
+						MDeformVert *dvert = &gps->dvert[i];
+
+						if (defvert_find_index(dvert, def_nr) != NULL) {
+							pt->flag &= ~GP_SPOINT_SELECT;
+						}
+					}
+				}
 			}
-			MDeformVert *dvert = &gps->dvert[i];
 
-			if (defvert_find_index(dvert, def_nr) != NULL) {
-				pt->flag &= ~GP_SPOINT_SELECT;
-				gps->flag |= GP_STROKE_SELECT;
+			/* if not multiedit, exit loop*/
+			if (!is_multiedit) {
+				break;
 			}
 		}
 	}



More information about the Bf-blender-cvs mailing list