[Bf-blender-cvs] [8ddbcd67f4f] greasepencil-object: Add weights to subdivide points

Antonioya noreply at git.blender.org
Thu Aug 23 10:34:10 CEST 2018


Commit: 8ddbcd67f4fecd14ce0e5f25913b24bc936de0d4
Author: Antonioya
Date:   Mon Aug 20 13:57:08 2018 +0200
Branches: greasepencil-object
https://developer.blender.org/rB8ddbcd67f4fecd14ce0e5f25913b24bc936de0d4

Add weights to subdivide points

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

M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/gpencil/gpencil_edit.c

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

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index a990e9213c3..ba56852e016 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -6594,8 +6594,10 @@ static void direct_link_gpencil(FileData *fd, bGPdata *gpd)
 				gps->points = newdataadr(fd, gps->points);
 
 				/* relink weight data */
-				gps->dvert = newdataadr(fd, gps->dvert);
-				direct_link_dverts(fd, gps->totpoints, gps->dvert);
+				if (gps->dvert) {
+					gps->dvert = newdataadr(fd, gps->dvert);
+					direct_link_dverts(fd, gps->totpoints, gps->dvert);
+				}
 
 				/* the triangulation is not saved, so need to be recalculated */
 				gps->triangles = NULL;
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index f7c08239647..beef2cf7c94 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -2878,6 +2878,8 @@ static int gp_stroke_subdivide_exec(bContext *C, wmOperator *op)
 {
 	bGPdata *gpd = ED_gpencil_data_get_active(C);
 	bGPDspoint *temp_points;
+	MDeformVert *temp_dverts;
+
 	const int cuts = RNA_int_get(op->ptr, "number_cuts");
 
 	int totnewpoints, oldtotpoints;
@@ -2899,20 +2901,25 @@ static int gp_stroke_subdivide_exec(bContext *C, wmOperator *op)
 				}
 				/* duplicate points in a temp area */
 				temp_points = MEM_dupallocN(gps->points);
+				if (gps->dvert == NULL) {
+					gps->dvert = MEM_callocN(sizeof(MDeformVert) * gps->totpoints, "gp_stroke_weights");
+				}
+				temp_dverts = MEM_dupallocN(gps->dvert);
+
 				oldtotpoints = gps->totpoints;
 
 				/* resize the points arrys */
 				gps->totpoints += totnewpoints;
 				gps->points = MEM_recallocN(gps->points, sizeof(*gps->points) * gps->totpoints);
-				if (gps->dvert != NULL) {
-					gps->dvert = MEM_recallocN(gps->dvert, sizeof(*gps->dvert) * gps->totpoints);
-				}
+				gps->dvert = MEM_recallocN(gps->dvert, sizeof(*gps->dvert) * gps->totpoints);
+
 				gps->flag |= GP_STROKE_RECALC_CACHES;
 
 				/* loop and interpolate */
 				i2 = 0;
 				for (int i = 0; i < oldtotpoints; i++) {
 					bGPDspoint *pt = &temp_points[i];
+					MDeformVert *dvert = &temp_dverts[i];
 					bGPDspoint *pt_final = &gps->points[i2];
 
 					MDeformVert *dvert_final = &gps->dvert[i2];
@@ -2924,8 +2931,8 @@ static int gp_stroke_subdivide_exec(bContext *C, wmOperator *op)
 					pt_final->time = pt->time;
 					pt_final->flag = pt->flag;
 
-					dvert_final->totweight = 0;
-					dvert_final->dw = NULL;
+					dvert_final->totweight = dvert->totweight;
+					dvert_final->dw = dvert->dw;
 					i2++;
 
 					/* if next point is selected add a half way point */
@@ -2945,9 +2952,8 @@ static int gp_stroke_subdivide_exec(bContext *C, wmOperator *op)
 								pt_final->time = interpf(pt->time, next->time, 0.5f);
 								pt_final->flag |= GP_SPOINT_SELECT;
 
-								dvert_final->totweight = 0;
-								dvert_final->dw = NULL;
-
+								dvert_final->totweight = dvert->totweight;
+								dvert_final->dw = MEM_dupallocN(dvert->dw);
 								i2++;
 							}
 						}
@@ -2955,6 +2961,7 @@ static int gp_stroke_subdivide_exec(bContext *C, wmOperator *op)
 				}
 				/* free temp memory */
 				MEM_freeN(temp_points);
+				MEM_freeN(temp_dverts);
 			}
 		}
 	}



More information about the Bf-blender-cvs mailing list