[Bf-blender-cvs] [3fe42322239] experimental_gp_weight: WIP: First compilation after change weights

Antonio Vazquez noreply at git.blender.org
Tue May 15 18:33:25 CEST 2018


Commit: 3fe423222398968faaf57e2633495627caf65dd9
Author: Antonio Vazquez
Date:   Tue May 15 17:55:13 2018 +0200
Branches: experimental_gp_weight
https://developer.blender.org/rB3fe423222398968faaf57e2633495627caf65dd9

WIP: First compilation after change weights

This code is not tested, but as this is the first compilation without error, save this point as backup.

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

M	source/blender/blenkernel/BKE_gpencil.h
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/blenkernel/intern/gpencil_modifier.c
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M	source/blender/editors/gpencil/gpencil_brush.c
M	source/blender/editors/gpencil/gpencil_data.c
M	source/blender/editors/gpencil/gpencil_edit.c
M	source/blender/editors/gpencil/gpencil_fill.c
M	source/blender/editors/gpencil/gpencil_interpolate.c
M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/editors/gpencil/gpencil_primitive.c
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/makesdna/DNA_gpencil_types.h
M	source/blender/makesrna/intern/rna_gpencil.c
M	source/blender/modifiers/intern/MOD_gpencil_util.c
M	source/blender/modifiers/intern/MOD_gpencil_util.h
M	source/blender/modifiers/intern/MOD_gpencilbuild.c
M	source/blender/modifiers/intern/MOD_gpencilhook.c
M	source/blender/modifiers/intern/MOD_gpencillattice.c
M	source/blender/modifiers/intern/MOD_gpencilnoise.c
M	source/blender/modifiers/intern/MOD_gpenciloffset.c
M	source/blender/modifiers/intern/MOD_gpencilopacity.c
M	source/blender/modifiers/intern/MOD_gpencilsmooth.c
M	source/blender/modifiers/intern/MOD_gpencilsubdiv.c
M	source/blender/modifiers/intern/MOD_gpencilthick.c

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

diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 622ef89e681..4ae2c41fd58 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -52,11 +52,12 @@ struct SimplifyGpencilModifierData;
 struct InstanceGpencilModifierData;
 struct LatticeGpencilModifierData;
 
+struct MDeformVert;
 struct MDeformWeight;
 
 /* ------------ Grease-Pencil API ------------------ */
 
-void BKE_gpencil_free_point_weights(struct bGPDspoint *pt);
+void BKE_gpencil_free_point_weights(struct MDeformVert *dvert);
 void BKE_gpencil_free_stroke_weights(struct bGPDstroke *gps);
 void BKE_gpencil_free_stroke(struct bGPDstroke *gps);
 bool BKE_gpencil_free_strokes(struct bGPDframe *gpf);
@@ -151,10 +152,10 @@ struct BoundBox *BKE_gpencil_boundbox_get(struct Object *ob);
 void BKE_gpencil_centroid_3D(struct bGPdata *gpd, float r_centroid[3]);
 
 /* vertex groups */
-float BKE_gpencil_vgroup_use_index(struct bGPDspoint *pt, int index);
+float BKE_gpencil_vgroup_use_index(struct MDeformVert *dvert, int index);
 void BKE_gpencil_vgroup_remove(struct Object *ob, struct bDeformGroup *defgroup);
-struct MDeformWeight *BKE_gpencil_vgroup_add_point_weight(struct bGPDspoint *pt, int index, float weight);
-bool BKE_gpencil_vgroup_remove_point_weight(struct bGPDspoint *pt, int index);
+struct MDeformWeight *BKE_gpencil_vgroup_add_point_weight(struct MDeformVert *dvert, int index, float weight);
+bool BKE_gpencil_vgroup_remove_point_weight(struct MDeformVert *dvert, int index);
 void BKE_gpencil_stroke_weights_duplicate(struct bGPDstroke *gps_src, struct bGPDstroke *gps_dst);
 
 /* GPencil geometry evaluation */
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index c75ecd45c33..d06bf261ed3 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -92,12 +92,12 @@ void BKE_gpencil_batch_cache_free(bGPdata *gpd)
 /* Memory Management */
 
 /* clean vertex groups weights */
-void BKE_gpencil_free_point_weights(bGPDspoint *pt)
+void BKE_gpencil_free_point_weights(MDeformVert *dvert)
 {
-	if (pt == NULL) {
+	if (dvert == NULL) {
 		return;
 	}
-	MEM_SAFE_FREE(pt->weights);
+	MEM_SAFE_FREE(dvert->dw);
 }
 
 void BKE_gpencil_free_stroke_weights(bGPDstroke *gps)
@@ -105,9 +105,15 @@ void BKE_gpencil_free_stroke_weights(bGPDstroke *gps)
 	if (gps == NULL) {
 		return;
 	}
+
+	if (gps->dvert == NULL) {
+		return;
+	}
+
 	for (int i = 0; i < gps->totpoints; i++) {
-		bGPDspoint *pt = &gps->points[i];
-		BKE_gpencil_free_point_weights(pt);
+		MDeformVert *dvert = &gps->dvert[i];
+		BKE_gpencil_free_point_weights(dvert);
+		MEM_freeN(dvert);
 	}
 }
 
@@ -528,17 +534,20 @@ bGPDstroke *BKE_gpencil_add_stroke(bGPDframe *gpf, int mat_idx, int totpoints, s
 /* ************************************************** */
 /* Data Duplication */
 
-/* make a copy of a given gpencil point weights */
+/* make a copy of a given gpencil weights */
 void BKE_gpencil_stroke_weights_duplicate(bGPDstroke *gps_src, bGPDstroke *gps_dst)
 {
 	if (gps_src == NULL) {
 		return;
 	}
 	BLI_assert(gps_src->totpoints == gps_dst->totpoints);
-	for (int i = 0; i < gps_src->totpoints; ++i) {
-		bGPDspoint *pt_dst = &gps_dst->points[i];
-		bGPDspoint *pt_src = &gps_src->points[i];
-		pt_dst->weights = MEM_dupallocN(pt_src->weights);
+
+	gps_dst->dvert = MEM_dupallocN(gps_src->dvert);
+
+	for (int i = 0; i < gps_src->totpoints; i++) {
+		MDeformVert *dvert_dst = &gps_dst->dvert[i];
+		MDeformVert *dvert_src = &gps_src->dvert[i];
+		dvert_dst->dw = MEM_dupallocN(dvert_src->dw);
 	}
 }
 
@@ -1283,7 +1292,7 @@ void BKE_gpencil_transform(bGPdata *gpd, float mat[4][4])
 void BKE_gpencil_vgroup_remove(Object *ob, bDeformGroup *defgroup)
 {
 	bGPdata *gpd = ob->data;
-	bGPDspoint *pt = NULL;
+	MDeformVert *dvert = NULL;
 	MDeformWeight *gpw = NULL;
 	const int def_nr = BLI_findindex(&ob->defbase, defgroup);
 
@@ -1293,11 +1302,11 @@ void BKE_gpencil_vgroup_remove(Object *ob, bDeformGroup *defgroup)
 			for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
 				for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
 					for (int i = 0; i < gps->totpoints; i++) {
-						pt = &gps->points[i];
-						for (int i2 = 0; i2 < pt->totweight; i2++) {
-							gpw = &pt->weights[i2];
+						dvert = &gps->dvert[i];
+						for (int i2 = 0; i2 < dvert->totweight; i2++) {
+							gpw = &dvert->dw[i2];
 							if (gpw->def_nr == def_nr) {
-								BKE_gpencil_vgroup_remove_point_weight(pt, def_nr);
+								BKE_gpencil_vgroup_remove_point_weight(dvert, def_nr);
 							}
 							/* if index is greater, must be moved one back */
 							if (gpw->def_nr > def_nr) {
@@ -1315,28 +1324,28 @@ void BKE_gpencil_vgroup_remove(Object *ob, bDeformGroup *defgroup)
 }
 
 /* add a new weight */
-MDeformWeight *BKE_gpencil_vgroup_add_point_weight(bGPDspoint *pt, int index, float weight)
+MDeformWeight *BKE_gpencil_vgroup_add_point_weight(MDeformVert *dvert, int index, float weight)
 {
 	MDeformWeight *new_gpw = NULL;
 	MDeformWeight *tmp_gpw;
 
 	/* need to verify if was used before to update */
-	for (int i = 0; i < pt->totweight; i++) {
-		tmp_gpw = &pt->weights[i];
+	for (int i = 0; i < dvert->totweight; i++) {
+		tmp_gpw = &dvert->dw[i];
 		if (tmp_gpw->def_nr == index) {
 			tmp_gpw->weight = weight;
 			return tmp_gpw;
 		}
 	}
 
-	pt->totweight++;
-	if (pt->totweight == 1) {
-		pt->weights = MEM_callocN(sizeof(MDeformWeight), "gp_weight");
+	dvert->totweight++;
+	if (dvert->totweight == 1) {
+		dvert->dw = MEM_callocN(sizeof(MDeformWeight), "gp_weight");
 	}
 	else {
-		pt->weights = MEM_reallocN(pt->weights, sizeof(MDeformWeight) * pt->totweight);
+		dvert->dw = MEM_reallocN(dvert->dw, sizeof(MDeformWeight) * dvert->totweight);
 	}
-	new_gpw = &pt->weights[pt->totweight - 1];
+	new_gpw = &dvert->dw[dvert->totweight - 1];
 	new_gpw->def_nr = index;
 	new_gpw->weight = weight;
 
@@ -1344,11 +1353,11 @@ MDeformWeight *BKE_gpencil_vgroup_add_point_weight(bGPDspoint *pt, int index, fl
 }
 
 /* return the weight if use index  or -1*/
-float BKE_gpencil_vgroup_use_index(bGPDspoint *pt, int index)
+float BKE_gpencil_vgroup_use_index(MDeformVert *dvert, int index)
 {
 	MDeformWeight *gpw;
-	for (int i = 0; i < pt->totweight; i++) {
-		gpw = &pt->weights[i];
+	for (int i = 0; i < dvert->totweight; i++) {
+		gpw = &dvert->dw[i];
 		if (gpw->def_nr == index) {
 			return gpw->weight;
 		}
@@ -1357,29 +1366,29 @@ float BKE_gpencil_vgroup_use_index(bGPDspoint *pt, int index)
 }
 
 /* add a new weight */
-bool BKE_gpencil_vgroup_remove_point_weight(bGPDspoint *pt, int index)
+bool BKE_gpencil_vgroup_remove_point_weight(MDeformVert *dvert, int index)
 {
 	int e = 0;
 
-	if (BKE_gpencil_vgroup_use_index(pt, index) < 0.0f) {
+	if (BKE_gpencil_vgroup_use_index(dvert, index) < 0.0f) {
 		return false;
 	}
 
 	/* if the array get empty, exit */
-	if (pt->totweight == 1) {
-		pt->totweight = 0;
-		MEM_SAFE_FREE(pt->weights);
+	if (dvert->totweight == 1) {
+		dvert->totweight = 0;
+		MEM_SAFE_FREE(dvert->dw);
 		return true;
 	}
 
 	/* realloc weights */
-	MDeformWeight *tmp = MEM_dupallocN(pt->weights);
-	MEM_SAFE_FREE(pt->weights);
-	pt->weights = MEM_callocN(sizeof(MDeformWeight) * pt->totweight - 1, "gp_weights");
+	MDeformWeight *tmp = MEM_dupallocN(dvert->dw);
+	MEM_SAFE_FREE(dvert->dw);
+	dvert->dw = MEM_callocN(sizeof(MDeformWeight) * dvert->totweight - 1, "gp_weights");
 
-	for (int x = 0; x < pt->totweight; x++) {
+	for (int x = 0; x < dvert->totweight; x++) {
 		MDeformWeight *gpw = &tmp[e];
-		MDeformWeight *final_gpw = &pt->weights[e];
+		MDeformWeight *final_gpw = &dvert->dw[e];
 		if (gpw->def_nr != index) {
 			final_gpw->def_nr = gpw->def_nr;
 			final_gpw->weight = gpw->weight;
@@ -1387,7 +1396,7 @@ bool BKE_gpencil_vgroup_remove_point_weight(bGPDspoint *pt, int index)
 		}
 	}
 	MEM_SAFE_FREE(tmp);
-	pt->totweight--;
+	dvert->totweight--;
 
 	return true;
 }
diff --git a/source/blender/blenkernel/intern/gpencil_modifier.c b/source/blender/blenkernel/intern/gpencil_modifier.c
index ecab8096e91..bff8df78836 100644
--- a/source/blender/blenkernel/intern/gpencil_modifier.c
+++ b/source/blender/blenkernel/intern/gpencil_modifier.c
@@ -36,6 +36,7 @@
 #include "BLI_utildefines.h"
 #include "BLI_math_vector.h"
 
+#include "DNA_meshdata_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_object_types.h"
 #include "DNA_gpencil_types.h"
@@ -210,6 +211,7 @@ static void gpencil_rdp_stroke(bGPDstroke *gps, vec2f *points2d, float epsilon)
 
 	/* adding points marked */
 	bGPDspoint *old_points = MEM_dupallocN(gps->points);
+	MDeformVert *old_dvert = MEM_dupallocN(gps->dvert);
 
 	/* resize gps */
 	gps->flag |= GP_STROKE_RECALC_CACHES;
@@ -219,18 +221,24 @@ static void gpencil_rdp_stroke(bGPDstroke *gps, vec2f *points2d, float epsilon)
 	for (int i = 0; i < totpoints; i++) {
 		bGPDspoint *old_pt = &old_points[i];
 		bGPDspoint *pt = &gps->points[j];
+
+		MDeformVert *o_dvert = &old_dvert[i];
+		MDeformVert *dvert = &gps->dvert[i];
+
 		if ((marked[i]) || (i == 0) || (i == totpoints - 1)) {
 			memcpy(pt, old_pt, sizeof(bGPDspoint));
+			memcpy(dvert, o_dvert, sizeof(MDeformVert));
 			j++;
 		}
 		else {
-			BKE_gpencil_free_point_weights(old_pt);
+			BKE_gpencil_free_point_weights(o_dvert);
 		}
 	}
 
 	gps->totpoints = j;
 
 	MEM_SAFE_FREE(old_points);
+	MEM_SAFE_FREE(old_dvert);
 	MEM_SAFE_FREE(marked);
 }
 
@@ -256,6 +264,7 @@ void BKE_gpencil_simplify_fixed(bGPDlayer *UNUSED(gpl), bGPDstroke *gps)
 
 	/* save points */
 	bGPDspoint *old_points = MEM_dupallocN(gps->points);
+	MDeformVert *old_dvert = MEM_dupallocN(gps->dvert);
 
 	/* resize gps */
 	int newtot = (gps->totpoints - 2) / 2;
@@ -265,6 +274,7 @@ void BKE_gpencil_simplify_fixed(bGPDlayer *UNUSED(gpl), bGPDstroke *gps)
 	newtot += 2;
 
 	gps->points = MEM_recallocN(gps->points, sizeof(*gps->points) * newtot);
+	gps->dvert = MEM_recallocN(gps->dvert, sizeof(*gps->dvert) * newtot);
 	gps->flag |= GP_STROKE_RECALC_CACHES;
 	gps->tot_triangles = 0;
 
@@ -273,18 +283,23 @@ void BKE_gpencil_simplify_fixed(bGPDlayer *UNUSED(gpl), bGPDstroke *gps)
 		bGPDspoint *old_pt = &old_points[i];
 		bGPDspoint *pt = &g

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list