[Bf-blender-cvs] [cd8cde1a6a] master: Code Cleanup: Move GPencil Interpolation operators into their own file

Joshua Leung noreply at git.blender.org
Wed Jan 18 07:43:15 CET 2017


Commit: cd8cde1a6a4a8294c0c63cf4962a8292a2cda61d
Author: Joshua Leung
Date:   Tue Jan 3 23:29:21 2017 +1300
Branches: master
https://developer.blender.org/rBcd8cde1a6a4a8294c0c63cf4962a8292a2cda61d

Code Cleanup: Move GPencil Interpolation operators into their own file

The interpolation operators (and their associated code) occupied a significant
portion of gpencil_edit.c (which was getting a bit heavy). So, it's best to split
these out into a separate file to make things easier to handle, in preparation
for some further dev work.

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

M	source/blender/editors/gpencil/CMakeLists.txt
M	source/blender/editors/gpencil/gpencil_edit.c
A	source/blender/editors/gpencil/gpencil_interpolate.c

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

diff --git a/source/blender/editors/gpencil/CMakeLists.txt b/source/blender/editors/gpencil/CMakeLists.txt
index 6604d59557..3d5317b2eb 100644
--- a/source/blender/editors/gpencil/CMakeLists.txt
+++ b/source/blender/editors/gpencil/CMakeLists.txt
@@ -44,6 +44,7 @@ set(SRC
 	gpencil_convert.c
 	gpencil_data.c
 	gpencil_edit.c
+	gpencil_interpolate.c
 	gpencil_ops.c
 	gpencil_paint.c
 	gpencil_select.c
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 15f65b394a..f01dfee494 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -2098,673 +2098,3 @@ void GPENCIL_OT_stroke_subdivide(wmOperatorType *ot)
 	RNA_def_property_flag(prop, PROP_SKIP_SAVE);
 
 }
-
-/* =========  Interpolation operators ========================== */
-/* Helper: Update point with interpolation */
-static void gp_interpolate_update_points(bGPDstroke *gps_from, bGPDstroke *gps_to, bGPDstroke *new_stroke, float factor)
-{
-	bGPDspoint *prev, *pt, *next;
-
-	/* update points */
-	for (int i = 0; i < new_stroke->totpoints; i++) {
-		prev = &gps_from->points[i];
-		pt = &new_stroke->points[i];
-		next = &gps_to->points[i];
-
-		/* Interpolate all values */
-		interp_v3_v3v3(&pt->x, &prev->x, &next->x, factor);
-		pt->pressure = interpf(prev->pressure, next->pressure, factor);
-		pt->strength = interpf(prev->strength, next->strength, factor);
-		CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f);
-	}
-}
-
-/* Helper: Update all strokes interpolated */
-static void gp_interpolate_update_strokes(bContext *C, tGPDinterpolate *tgpi)
-{
-	tGPDinterpolate_layer *tgpil;
-	bGPDstroke *new_stroke, *gps_from, *gps_to;
-	int cStroke;
-	float factor;
-	float shift = tgpi->shift;
-
-	for (tgpil = tgpi->ilayers.first; tgpil; tgpil = tgpil->next) {
-		factor = tgpil->factor + shift;
-		for (new_stroke = tgpil->interFrame->strokes.first; new_stroke; new_stroke = new_stroke->next) {
-			if (new_stroke->totpoints == 0) {
-				continue;
-			}
-			/* get strokes to interpolate */
-			cStroke = BLI_findindex(&tgpil->interFrame->strokes, new_stroke);
-			gps_from = BLI_findlink(&tgpil->prevFrame->strokes, cStroke);
-			gps_to = BLI_findlink(&tgpil->nextFrame->strokes, cStroke);
-			/* update points position */
-			if ((gps_from) && (gps_to)) {
-				gp_interpolate_update_points(gps_from, gps_to, new_stroke, factor);
-			}
-		}
-	}
-
-	WM_event_add_notifier(C, NC_GPENCIL | NA_EDITED, NULL);
-}
-
-/* Helper: Verify valid strokes for interpolation */
-static bool gp_interpolate_check_todo(bContext *C, bGPdata *gpd)
-{
-	ToolSettings *ts = CTX_data_tool_settings(C);
-	int flag = ts->gp_sculpt.flag;
-
-	bGPDlayer *gpl;
-	bGPDlayer *active_gpl = CTX_data_active_gpencil_layer(C);
-	bGPDstroke *gps_from, *gps_to;
-	int fFrame;
-
-	/* get layers */
-	for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
-		/* all layers or only active */
-		if (((flag & GP_BRUSHEDIT_FLAG_INTERPOLATE_ALL_LAYERS) == 0) && (gpl != active_gpl)) {
-			continue;
-		}
-		/* only editable and visible layers are considered */
-		if (!gpencil_layer_is_editable(gpl) || (gpl->actframe == NULL)) {
-			continue;
-		}
-		/* read strokes */
-		for (gps_from = gpl->actframe->strokes.first; gps_from; gps_from = gps_from->next) {
-			/* only selected */
-			if ((flag & GP_BRUSHEDIT_FLAG_INTERPOLATE_ONLY_SELECTED) && ((gps_from->flag & GP_STROKE_SELECT) == 0)) {
-				continue;
-			}
-			/* skip strokes that are invalid for current view */
-			if (ED_gpencil_stroke_can_use(C, gps_from) == false) {
-				continue;
-			}
-			/* check if the color is editable */
-			if (ED_gpencil_stroke_color_use(gpl, gps_from) == false) {
-				continue;
-			}
-			/* get final stroke to interpolate */
-			fFrame = BLI_findindex(&gpl->actframe->strokes, gps_from);
-			gps_to = BLI_findlink(&gpl->actframe->next->strokes, fFrame);
-			if (gps_to == NULL) {
-				continue;
-			}
-			return 1;
-		}
-	}
-	return 0;
-}
-
-/* Helper: Create internal strokes interpolated */
-static void gp_interpolate_set_points(bContext *C, tGPDinterpolate *tgpi)
-{
-	bGPDlayer *gpl;
-	bGPdata *gpd = tgpi->gpd;
-	tGPDinterpolate_layer *tgpil;
-	bGPDlayer *active_gpl = CTX_data_active_gpencil_layer(C);
-	bGPDstroke *gps_from, *gps_to, *new_stroke;
-	int fFrame;
-
-	/* save initial factor for active layer to define shift limits */
-	tgpi->init_factor = (float)(tgpi->cframe - active_gpl->actframe->framenum) / (active_gpl->actframe->next->framenum - active_gpl->actframe->framenum + 1);
-	/* limits are 100% below 0 and 100% over the 100% */
-	tgpi->low_limit = -1.0f - tgpi->init_factor;
-	tgpi->high_limit = 2.0f - tgpi->init_factor;
-
-	/* set layers */
-	for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
-		/* all layers or only active */
-		if (((tgpi->flag & GP_BRUSHEDIT_FLAG_INTERPOLATE_ALL_LAYERS) == 0) && (gpl != active_gpl)) {
-			continue;
-		}
-		/* only editable and visible layers are considered */
-		if (!gpencil_layer_is_editable(gpl) || (gpl->actframe == NULL)) {
-			continue;
-		}
-		/* create temp data for each layer */
-		tgpil = NULL;
-		tgpil = MEM_callocN(sizeof(tGPDinterpolate_layer), "GPencil Interpolate Layer");
-
-		tgpil->gpl = gpl;
-		tgpil->prevFrame = gpl->actframe;
-		tgpil->nextFrame = gpl->actframe->next;
-
-		BLI_addtail(&tgpi->ilayers, tgpil);
-		/* create a new temporary frame */
-		tgpil->interFrame = MEM_callocN(sizeof(bGPDframe), "bGPDframe");
-		tgpil->interFrame->framenum = tgpi->cframe;
-
-		/* get interpolation factor by layer (usually must be equal for all layers, but not sure) */
-		tgpil->factor = (float)(tgpi->cframe - tgpil->prevFrame->framenum) / (tgpil->nextFrame->framenum - tgpil->prevFrame->framenum + 1);
-		/* create new strokes data with interpolated points reading original stroke */
-		for (gps_from = tgpil->prevFrame->strokes.first; gps_from; gps_from = gps_from->next) {
-			bool valid = true;
-			/* only selected */
-			if ((tgpi->flag & GP_BRUSHEDIT_FLAG_INTERPOLATE_ONLY_SELECTED) && ((gps_from->flag & GP_STROKE_SELECT) == 0)) {
-				valid = false;
-			}
-
-			/* skip strokes that are invalid for current view */
-			if (ED_gpencil_stroke_can_use(C, gps_from) == false) {
-				valid = false;
-			}
-			/* check if the color is editable */
-			if (ED_gpencil_stroke_color_use(tgpil->gpl, gps_from) == false) {
-				valid = false;
-			}
-			/* get final stroke to interpolate */
-			fFrame = BLI_findindex(&tgpil->prevFrame->strokes, gps_from);
-			gps_to = BLI_findlink(&tgpil->nextFrame->strokes, fFrame);
-			if (gps_to == NULL) {
-				valid = false;
-			}
-			/* create new stroke */
-			new_stroke = MEM_dupallocN(gps_from);
-			new_stroke->points = MEM_dupallocN(gps_from->points);
-			new_stroke->triangles = MEM_dupallocN(gps_from->triangles);
-			if (valid) {
-				/* if destination stroke is smaller, resize new_stroke to size of gps_to stroke */
-				if (gps_from->totpoints > gps_to->totpoints) {
-					new_stroke->points = MEM_recallocN(new_stroke->points, sizeof(*new_stroke->points) * gps_to->totpoints);
-					new_stroke->totpoints = gps_to->totpoints;
-					new_stroke->tot_triangles = 0;
-					new_stroke->flag |= GP_STROKE_RECALC_CACHES;
-				}
-				/* update points position */
-				gp_interpolate_update_points(gps_from, gps_to, new_stroke, tgpil->factor);
-			}
-			else {
-				/* need an empty stroke to keep index correct for lookup, but resize to smallest size */
-				new_stroke->totpoints = 0;
-				new_stroke->points = MEM_recallocN(new_stroke->points, sizeof(*new_stroke->points));
-				new_stroke->tot_triangles = 0;
-				new_stroke->triangles = MEM_recallocN(new_stroke->triangles, sizeof(*new_stroke->triangles));
-			}
-			/* add to strokes */
-			BLI_addtail(&tgpil->interFrame->strokes, new_stroke);
-		}
-	}
-}
-
-/* Helper: calculate shift based on position of mouse (we only use x-axis for now.
-* since this is more convenient for users to do), and store new shift value
-*/
-static void gpencil_mouse_update_shift(tGPDinterpolate *tgpi, wmOperator *op, const wmEvent *event)
-{
-	float mid = (float)(tgpi->ar->winx - tgpi->ar->winrct.xmin) / 2.0f;
-	float mpos = event->x - tgpi->ar->winrct.xmin;
-	if (mpos >= mid) {
-		tgpi->shift = ((mpos - mid) * tgpi->high_limit) / mid;
-	}
-	else {
-		tgpi->shift = tgpi->low_limit - ((mpos * tgpi->low_limit) / mid);
-	}
-
-	CLAMP(tgpi->shift, tgpi->low_limit, tgpi->high_limit);
-	RNA_float_set(op->ptr, "shift", tgpi->shift);
-}
-
-/* Helper: Draw status message while the user is running the operator */
-static void gpencil_interpolate_status_indicators(tGPDinterpolate *p)
-{
-	Scene *scene = p->scene;
-	char status_str[UI_MAX_DRAW_STR];
-	char msg_str[UI_MAX_DRAW_STR];
-	BLI_strncpy(msg_str, IFACE_("GPencil Interpolation: ESC/RMB to cancel, Enter/LMB to confirm, WHEEL/MOVE to adjust, Factor"), UI_MAX_DRAW_STR);
-
-	if (hasNumInput(&p->num)) {
-		char str_offs[NUM_STR_REP_LEN];
-
-		outputNumInput(&p->num, str_offs, &scene->unit);
-
-		BLI_snprintf(status_str, sizeof(status_str), "%s: %s", msg_str, str_offs);
-	}
-	else {
-		BLI_snprintf(status_str, sizeof(status_str), "%s: %d %%", msg_str, (int)((p->init_factor + p->shift)  * 100.0f));
-	}
-
-	ED_area_headerprint(p->sa, status_str);
-}
-
-/* Helper: Update screen and stroke */
-static void gpencil_interpolate_update(bContext *C, wmOperator *op, tGPDinterpolate *tgpi)
-{
-	/* update shift indicator in header */
-	gpencil_interpolate_status_indicators(tgpi);
-	/* apply... */
-	tgpi->shift = RNA_float_get(op->ptr, "shift");
-	/* update points position */
-	gp_interpolate_update_strokes(C, tgpi);
-}
-
-/* init new temporary interpolation data */
-static bool gp_interpolate_set_init_values(bContext *C, wmOperator *op, tGPDinterpolate *tgpi)
-{
-	ToolSettings *ts = CTX_data_tool_settings(C);
-	bGPdata *gpd = CTX_data_gpencil_data(C);
-
-	/* set current scene and window */
-	tgpi->scene = CTX_data_scene(C);
-	tgpi->sa = CTX_wm_area(C);
-	tgpi->ar = CTX_wm_region(C);
-	tgpi->flag = ts->gp_sculpt.flag;
-
-	/* set current frame number */
-	tgpi->cframe = tgpi->scene->r.cfra;
-
-	/* set GP datablock */
-	tgpi->gpd = gpd;
-
-	/* set interpolation weight */
-	tgpi->shift = RNA_float_get(op->ptr, "shift");
-	/* set layers */
-	gp_interpolate_set_points(C,

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list