diff options
Diffstat (limited to 'source/blender/editors/gpencil/gpencil_interpolate.c')
-rw-r--r-- | source/blender/editors/gpencil/gpencil_interpolate.c | 80 |
1 files changed, 41 insertions, 39 deletions
diff --git a/source/blender/editors/gpencil/gpencil_interpolate.c b/source/blender/editors/gpencil/gpencil_interpolate.c index 5cb49600d05..3a7029b1288 100644 --- a/source/blender/editors/gpencil/gpencil_interpolate.c +++ b/source/blender/editors/gpencil/gpencil_interpolate.c @@ -100,10 +100,10 @@ static bool gpencil_view3d_poll(bContext *C) } /* Perform interpolation */ -static void gp_interpolate_update_points(const bGPDstroke *gps_from, - const bGPDstroke *gps_to, - bGPDstroke *new_stroke, - float factor) +static void gpencil_interpolate_update_points(const bGPDstroke *gps_from, + const bGPDstroke *gps_to, + bGPDstroke *new_stroke, + float factor) { /* update points */ for (int i = 0; i < new_stroke->totpoints; i++) { @@ -121,7 +121,7 @@ static void gp_interpolate_update_points(const bGPDstroke *gps_from, /* ****************** Interpolate Interactive *********************** */ /* Helper: free all temp strokes for display. */ -static void gp_interpolate_free_temp_strokes(bGPDframe *gpf) +static void gpencil_interpolate_free_temp_strokes(bGPDframe *gpf) { if (gpf == NULL) { return; @@ -136,19 +136,23 @@ static void gp_interpolate_free_temp_strokes(bGPDframe *gpf) } /* Helper: Untag all strokes. */ -static void gp_interpolate_untag_strokes(bGPDframe *gpf) +static void gpencil_interpolate_untag_strokes(bGPDlayer *gpl) { - BLI_assert(gpf != NULL); + if (gpl == NULL) { + return; + } - LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { - if (gps->flag & GP_STROKE_TAG) { - gps->flag &= ~GP_STROKE_TAG; + LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { + if (gps->flag & GP_STROKE_TAG) { + gps->flag &= ~GP_STROKE_TAG; + } } } } /* Helper: Update all strokes interpolated */ -static void gp_interpolate_update_strokes(bContext *C, tGPDinterpolate *tgpi) +static void gpencil_interpolate_update_strokes(bContext *C, tGPDinterpolate *tgpi) { bGPdata *gpd = tgpi->gpd; const float shift = tgpi->shift; @@ -158,7 +162,7 @@ static void gp_interpolate_update_strokes(bContext *C, tGPDinterpolate *tgpi) bGPDframe *gpf = tgpil->gpl->actframe; /* Free temp strokes. */ - gp_interpolate_free_temp_strokes(gpf); + gpencil_interpolate_free_temp_strokes(gpf); LISTBASE_FOREACH (bGPDstroke *, new_stroke, &tgpil->interFrame->strokes) { bGPDstroke *gps_from, *gps_to; @@ -176,7 +180,7 @@ static void gp_interpolate_update_strokes(bContext *C, tGPDinterpolate *tgpi) /* update points position */ if ((gps_from) && (gps_to)) { - gp_interpolate_update_points(gps_from, gps_to, new_stroke, factor); + gpencil_interpolate_update_points(gps_from, gps_to, new_stroke, factor); /* Add temp strokes. */ if (gpf) { @@ -193,7 +197,7 @@ static void gp_interpolate_update_strokes(bContext *C, tGPDinterpolate *tgpi) } /* Helper: Verify valid strokes for interpolation */ -static bool gp_interpolate_check_todo(bContext *C, bGPdata *gpd) +static bool gpencil_interpolate_check_todo(bContext *C, bGPdata *gpd) { Object *ob = CTX_data_active_object(C); ToolSettings *ts = CTX_data_tool_settings(C); @@ -243,7 +247,7 @@ static bool gp_interpolate_check_todo(bContext *C, bGPdata *gpd) } /* Helper: Create internal strokes interpolated */ -static void gp_interpolate_set_points(bContext *C, tGPDinterpolate *tgpi) +static void gpencil_interpolate_set_points(bContext *C, tGPDinterpolate *tgpi) { bGPdata *gpd = tgpi->gpd; bGPDlayer *active_gpl = CTX_data_active_gpencil_layer(C); @@ -261,7 +265,6 @@ static void gp_interpolate_set_points(bContext *C, tGPDinterpolate *tgpi) /* set layers */ LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { tGPDinterpolate_layer *tgpil; - /* all layers or only active */ if (!(tgpi->flag & GP_TOOLFLAG_INTERPOLATE_ALL_LAYERS) && (gpl != active_gpl)) { continue; @@ -278,10 +281,6 @@ static void gp_interpolate_set_points(bContext *C, tGPDinterpolate *tgpi) tgpil->prevFrame = gpl->actframe; tgpil->nextFrame = gpl->actframe->next; - /* Untag interpolated strokes to be sure nothing is pending. */ - gp_interpolate_untag_strokes(tgpil->prevFrame); - gp_interpolate_untag_strokes(tgpil->nextFrame); - BLI_addtail(&tgpi->ilayers, tgpil); /* create a new temporary frame */ @@ -337,7 +336,7 @@ static void gp_interpolate_set_points(bContext *C, tGPDinterpolate *tgpi) new_stroke->totpoints = gps_to->totpoints; } /* update points position */ - gp_interpolate_update_points(gps_from, gps_to, new_stroke, tgpil->factor); + gpencil_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 */ @@ -413,7 +412,7 @@ static void gpencil_interpolate_update(bContext *C, wmOperator *op, tGPDinterpol /* apply... */ tgpi->shift = RNA_float_get(op->ptr, "shift"); /* update points position */ - gp_interpolate_update_strokes(C, tgpi); + gpencil_interpolate_update_strokes(C, tgpi); } /* ----------------------- */ @@ -433,7 +432,7 @@ static void gpencil_interpolate_exit(bContext *C, wmOperator *op) /* Clear any temp stroke. */ LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { - gp_interpolate_free_temp_strokes(gpf); + gpencil_interpolate_free_temp_strokes(gpf); } } @@ -454,7 +453,7 @@ static void gpencil_interpolate_exit(bContext *C, wmOperator *op) } /* Init new temporary interpolation data */ -static bool gp_interpolate_set_init_values(bContext *C, wmOperator *op, tGPDinterpolate *tgpi) +static bool gpencil_interpolate_set_init_values(bContext *C, wmOperator *op, tGPDinterpolate *tgpi) { ToolSettings *ts = CTX_data_tool_settings(C); bGPdata *gpd = CTX_data_gpencil_data(C); @@ -475,18 +474,23 @@ static bool gp_interpolate_set_init_values(bContext *C, wmOperator *op, tGPDinte /* set interpolation weight */ tgpi->shift = RNA_float_get(op->ptr, "shift"); /* set layers */ - gp_interpolate_set_points(C, tgpi); + gpencil_interpolate_set_points(C, tgpi); + + /* Untag strokes to be sure nothing is pending due any canceled process. */ + LISTBASE_FOREACH (bGPDlayer *, gpl, &tgpi->gpd->layers) { + gpencil_interpolate_untag_strokes(gpl); + } return 1; } /* Allocate memory and initialize values */ -static tGPDinterpolate *gp_session_init_interpolation(bContext *C, wmOperator *op) +static tGPDinterpolate *gpencil_session_init_interpolation(bContext *C, wmOperator *op) { tGPDinterpolate *tgpi = MEM_callocN(sizeof(tGPDinterpolate), "GPencil Interpolate Data"); /* define initial values */ - gp_interpolate_set_init_values(C, op, tgpi); + gpencil_interpolate_set_init_values(C, op, tgpi); /* return context data for running operator */ return tgpi; @@ -498,7 +502,7 @@ static int gpencil_interpolate_init(bContext *C, wmOperator *op) tGPDinterpolate *tgpi; /* check context */ - tgpi = op->customdata = gp_session_init_interpolation(C, op); + tgpi = op->customdata = gpencil_session_init_interpolation(C, op); if (tgpi == NULL) { /* something wasn't set correctly in context */ gpencil_interpolate_exit(C, op); @@ -540,7 +544,7 @@ static int gpencil_interpolate_invoke(bContext *C, wmOperator *op, const wmEvent } /* need editable strokes */ - if (!gp_interpolate_check_todo(C, gpd)) { + if (!gpencil_interpolate_check_todo(C, gpd)) { BKE_report(op->reports, RPT_ERROR, "Interpolation requires some editable strokes"); return OPERATOR_CANCELLED; } @@ -552,9 +556,7 @@ static int gpencil_interpolate_invoke(bContext *C, wmOperator *op, const wmEvent } return OPERATOR_CANCELLED; } - else { - tgpi = op->customdata; - } + tgpi = op->customdata; /* set cursor to indicate modal */ WM_cursor_modal_set(win, WM_CURSOR_EW_SCROLL); @@ -602,6 +604,8 @@ static int gpencil_interpolate_modal(bContext *C, wmOperator *op, const wmEvent /* make copy of source stroke, then adjust pointer to points too */ gps_dst = BKE_gpencil_stroke_duplicate(gps_src, true); + gps_dst->flag &= ~GP_STROKE_TAG; + /* Calc geometry data. */ BKE_gpencil_stroke_geometry_update(gps_dst); @@ -681,10 +685,8 @@ static int gpencil_interpolate_modal(bContext *C, wmOperator *op, const wmEvent break; } - else { - /* unhandled event - allow to pass through */ - return OPERATOR_RUNNING_MODAL | OPERATOR_PASS_THROUGH; - } + /* unhandled event - allow to pass through */ + return OPERATOR_RUNNING_MODAL | OPERATOR_PASS_THROUGH; } } @@ -731,7 +733,7 @@ void GPENCIL_OT_interpolate(wmOperatorType *ot) /* ****************** Interpolate Sequence *********************** */ /* Helper: Perform easing equation calculations for GP interpolation operator */ -static float gp_interpolate_seq_easing_calc(GP_Interpolate_Settings *ipo_settings, float time) +static float gpencil_interpolate_seq_easing_calc(GP_Interpolate_Settings *ipo_settings, float time) { const float begin = 0.0f; const float change = 1.0f; @@ -1008,7 +1010,7 @@ static int gpencil_interpolate_seq_exec(bContext *C, wmOperator *op) } else if (ipo_settings->type >= GP_IPO_BACK) { /* easing equation... */ - factor = gp_interpolate_seq_easing_calc(ipo_settings, factor); + factor = gpencil_interpolate_seq_easing_calc(ipo_settings, factor); } /* create new strokes data with interpolated points reading original stroke */ @@ -1064,7 +1066,7 @@ static int gpencil_interpolate_seq_exec(bContext *C, wmOperator *op) } /* update points position */ - gp_interpolate_update_points(gps_from, gps_to, new_stroke, factor); + gpencil_interpolate_update_points(gps_from, gps_to, new_stroke, factor); /* Calc geometry data. */ BKE_gpencil_stroke_geometry_update(new_stroke); |