2018-08-26 16:39:01 +02:00
|
|
|
/*
|
2017-01-03 23:29:21 +13:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2016, Blender Foundation
|
|
|
|
* This is a new part of Blender
|
|
|
|
* Operators for interpolating new Grease Pencil frames from existing strokes
|
|
|
|
*/
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup edgpencil
|
2017-01-03 23:29:21 +13:00
|
|
|
*/
|
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <math.h>
|
|
|
|
#include <stddef.h>
|
2017-01-03 23:29:21 +13:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <string.h>
|
2017-01-03 23:29:21 +13:00
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
2017-01-18 19:00:17 +13:00
|
|
|
#include "BLI_easing.h"
|
|
|
|
#include "BLI_math.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_utildefines.h"
|
2017-01-03 23:29:21 +13:00
|
|
|
|
|
|
|
#include "BLT_translation.h"
|
|
|
|
|
2017-01-18 19:00:17 +13:00
|
|
|
#include "DNA_color_types.h"
|
|
|
|
#include "DNA_gpencil_types.h"
|
2018-07-31 10:22:19 +02:00
|
|
|
#include "DNA_meshdata_types.h"
|
2017-01-03 23:29:21 +13:00
|
|
|
#include "DNA_object_types.h"
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
#include "DNA_space_types.h"
|
|
|
|
#include "DNA_view3d_types.h"
|
|
|
|
|
2017-01-18 19:00:17 +13:00
|
|
|
#include "BKE_colortools.h"
|
2017-01-03 23:29:21 +13:00
|
|
|
#include "BKE_context.h"
|
2018-11-07 18:00:24 +01:00
|
|
|
#include "BKE_deform.h"
|
2017-01-03 23:29:21 +13:00
|
|
|
#include "BKE_gpencil.h"
|
2020-03-19 11:35:17 +01:00
|
|
|
#include "BKE_gpencil_geom.h"
|
2017-01-03 23:29:21 +13:00
|
|
|
#include "BKE_report.h"
|
|
|
|
|
|
|
|
#include "UI_interface.h"
|
|
|
|
#include "UI_resources.h"
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
#include "RNA_define.h"
|
|
|
|
#include "RNA_enum_types.h"
|
|
|
|
|
|
|
|
#include "UI_view2d.h"
|
|
|
|
|
|
|
|
#include "ED_gpencil.h"
|
|
|
|
#include "ED_object.h"
|
|
|
|
#include "ED_screen.h"
|
|
|
|
#include "ED_space_api.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "ED_view3d.h"
|
2017-01-03 23:29:21 +13:00
|
|
|
|
2018-07-31 10:22:19 +02:00
|
|
|
#include "DEG_depsgraph.h"
|
|
|
|
#include "DEG_depsgraph_query.h"
|
|
|
|
|
2017-01-03 23:29:21 +13:00
|
|
|
#include "gpencil_intern.h"
|
|
|
|
|
|
|
|
/* ************************************************ */
|
2017-01-18 00:48:15 +13:00
|
|
|
/* Core/Shared Utilities */
|
2017-01-03 23:29:21 +13:00
|
|
|
|
2017-01-18 00:48:15 +13:00
|
|
|
/* Poll callback for interpolation operators */
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool gpencil_view3d_poll(bContext *C)
|
2017-01-18 00:48:15 +13:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bGPdata *gpd = CTX_data_gpencil_data(C);
|
|
|
|
bGPDlayer *gpl = CTX_data_active_gpencil_layer(C);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* only 3D view */
|
2020-04-03 13:25:03 +02:00
|
|
|
ScrArea *area = CTX_wm_area(C);
|
|
|
|
if (area && area->spacetype != SPACE_VIEW3D) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* need data to interpolate */
|
|
|
|
if (ELEM(NULL, gpd, gpl)) {
|
|
|
|
return 0;
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return 1;
|
2017-01-18 00:48:15 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Perform interpolation */
|
2020-06-29 15:28:38 +02:00
|
|
|
static void gpencil_interpolate_update_points(const bGPDstroke *gps_from,
|
|
|
|
const bGPDstroke *gps_to,
|
|
|
|
bGPDstroke *new_stroke,
|
|
|
|
float factor)
|
2017-01-03 23:29:21 +13:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* update points */
|
|
|
|
for (int i = 0; i < new_stroke->totpoints; i++) {
|
|
|
|
const bGPDspoint *prev = &gps_from->points[i];
|
|
|
|
const bGPDspoint *next = &gps_to->points[i];
|
|
|
|
bGPDspoint *pt = &new_stroke->points[i];
|
|
|
|
|
|
|
|
/* Interpolate all values */
|
|
|
|
interp_v3_v3v3(&pt->x, &prev->x, &next->x, factor);
|
|
|
|
pt->pressure = interpf(prev->pressure, next->pressure, 1.0f - factor);
|
|
|
|
pt->strength = interpf(prev->strength, next->strength, 1.0f - factor);
|
|
|
|
CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f);
|
|
|
|
}
|
2017-01-03 23:29:21 +13:00
|
|
|
}
|
|
|
|
|
2017-01-18 00:48:15 +13:00
|
|
|
/* ****************** Interpolate Interactive *********************** */
|
2020-03-09 16:27:24 +01:00
|
|
|
/* Helper: free all temp strokes for display. */
|
2020-06-29 15:28:38 +02:00
|
|
|
static void gpencil_interpolate_free_temp_strokes(bGPDframe *gpf)
|
2020-03-09 16:27:24 +01:00
|
|
|
{
|
|
|
|
if (gpf == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2017-01-18 00:48:15 +13:00
|
|
|
|
2020-03-09 16:27:24 +01:00
|
|
|
LISTBASE_FOREACH_MUTABLE (bGPDstroke *, gps, &gpf->strokes) {
|
|
|
|
if (gps->flag & GP_STROKE_TAG) {
|
|
|
|
BLI_remlink(&gpf->strokes, gps);
|
|
|
|
BKE_gpencil_free_stroke(gps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-25 10:40:09 +02:00
|
|
|
|
|
|
|
/* Helper: Untag all strokes. */
|
2020-07-28 16:23:45 +02:00
|
|
|
static void gpencil_interpolate_untag_strokes(bGPDlayer *gpl)
|
2020-04-25 10:40:09 +02:00
|
|
|
{
|
2020-07-28 16:23:45 +02:00
|
|
|
if (gpl == NULL) {
|
2020-06-19 19:39:21 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-04-25 10:40:09 +02:00
|
|
|
|
2020-07-28 16:23:45 +02:00
|
|
|
LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
|
|
|
|
LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
|
|
|
|
if (gps->flag & GP_STROKE_TAG) {
|
|
|
|
gps->flag &= ~GP_STROKE_TAG;
|
|
|
|
}
|
2020-04-25 10:40:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-03 23:29:21 +13:00
|
|
|
/* Helper: Update all strokes interpolated */
|
2020-06-29 15:28:38 +02:00
|
|
|
static void gpencil_interpolate_update_strokes(bContext *C, tGPDinterpolate *tgpi)
|
2017-01-03 23:29:21 +13:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bGPdata *gpd = tgpi->gpd;
|
|
|
|
const float shift = tgpi->shift;
|
|
|
|
|
2020-03-09 16:27:24 +01:00
|
|
|
LISTBASE_FOREACH (tGPDinterpolate_layer *, tgpil, &tgpi->ilayers) {
|
2019-04-17 06:17:24 +02:00
|
|
|
const float factor = tgpil->factor + shift;
|
|
|
|
|
2020-03-09 16:27:24 +01:00
|
|
|
bGPDframe *gpf = tgpil->gpl->actframe;
|
|
|
|
/* Free temp strokes. */
|
2020-06-29 15:28:38 +02:00
|
|
|
gpencil_interpolate_free_temp_strokes(gpf);
|
2020-03-09 16:27:24 +01:00
|
|
|
|
|
|
|
LISTBASE_FOREACH (bGPDstroke *, new_stroke, &tgpil->interFrame->strokes) {
|
2019-04-17 06:17:24 +02:00
|
|
|
bGPDstroke *gps_from, *gps_to;
|
|
|
|
int stroke_idx;
|
|
|
|
|
|
|
|
if (new_stroke->totpoints == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get strokes to interpolate */
|
|
|
|
stroke_idx = BLI_findindex(&tgpil->interFrame->strokes, new_stroke);
|
|
|
|
|
|
|
|
gps_from = BLI_findlink(&tgpil->prevFrame->strokes, stroke_idx);
|
|
|
|
gps_to = BLI_findlink(&tgpil->nextFrame->strokes, stroke_idx);
|
|
|
|
|
|
|
|
/* update points position */
|
|
|
|
if ((gps_from) && (gps_to)) {
|
2020-06-29 15:28:38 +02:00
|
|
|
gpencil_interpolate_update_points(gps_from, gps_to, new_stroke, factor);
|
2020-03-09 16:27:24 +01:00
|
|
|
|
|
|
|
/* Add temp strokes. */
|
|
|
|
if (gpf) {
|
|
|
|
bGPDstroke *gps_eval = BKE_gpencil_stroke_duplicate(new_stroke, true);
|
|
|
|
gps_eval->flag |= GP_STROKE_TAG;
|
|
|
|
BLI_addtail(&gpf->strokes, gps_eval);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
|
|
|
|
WM_event_add_notifier(C, NC_GPENCIL | NA_EDITED, NULL);
|
2017-01-03 23:29:21 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Helper: Verify valid strokes for interpolation */
|
2020-06-29 15:28:38 +02:00
|
|
|
static bool gpencil_interpolate_check_todo(bContext *C, bGPdata *gpd)
|
2017-01-03 23:29:21 +13:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Object *ob = CTX_data_active_object(C);
|
|
|
|
ToolSettings *ts = CTX_data_tool_settings(C);
|
|
|
|
eGP_Interpolate_SettingsFlag flag = ts->gp_interpolate.flag;
|
|
|
|
|
|
|
|
/* get layers */
|
2020-03-09 16:27:24 +01:00
|
|
|
LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* all layers or only active */
|
|
|
|
if (!(flag & GP_TOOLFLAG_INTERPOLATE_ALL_LAYERS) && !(gpl->flag & GP_LAYER_ACTIVE)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* only editable and visible layers are considered */
|
2020-03-09 16:27:24 +01:00
|
|
|
if (!BKE_gpencil_layer_is_editable(gpl) || (gpl->actframe == NULL)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read strokes */
|
2020-03-09 16:27:24 +01:00
|
|
|
LISTBASE_FOREACH (bGPDstroke *, gps_from, &gpl->actframe->strokes) {
|
2019-04-17 06:17:24 +02:00
|
|
|
bGPDstroke *gps_to;
|
|
|
|
int fFrame;
|
|
|
|
|
|
|
|
/* only selected */
|
|
|
|
if ((flag & GP_TOOLFLAG_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(ob, 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 true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2017-01-03 23:29:21 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Helper: Create internal strokes interpolated */
|
2020-06-29 15:28:38 +02:00
|
|
|
static void gpencil_interpolate_set_points(bContext *C, tGPDinterpolate *tgpi)
|
2017-01-03 23:29:21 +13:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bGPdata *gpd = tgpi->gpd;
|
|
|
|
bGPDlayer *active_gpl = CTX_data_active_gpencil_layer(C);
|
|
|
|
bGPDframe *actframe = active_gpl->actframe;
|
|
|
|
Object *ob = CTX_data_active_object(C);
|
|
|
|
|
|
|
|
/* save initial factor for active layer to define shift limits */
|
|
|
|
tgpi->init_factor = (float)(tgpi->cframe - actframe->framenum) /
|
|
|
|
(actframe->next->framenum - 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 */
|
2020-03-09 16:27:24 +01:00
|
|
|
LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
|
2019-04-17 06:17:24 +02:00
|
|
|
tGPDinterpolate_layer *tgpil;
|
|
|
|
/* all layers or only active */
|
|
|
|
if (!(tgpi->flag & GP_TOOLFLAG_INTERPOLATE_ALL_LAYERS) && (gpl != active_gpl)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* only editable and visible layers are considered */
|
2020-03-09 16:27:24 +01:00
|
|
|
if (!BKE_gpencil_layer_is_editable(gpl) || (gpl->actframe == NULL)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create temp data for each layer */
|
|
|
|
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 */
|
2020-03-09 16:27:24 +01:00
|
|
|
LISTBASE_FOREACH (bGPDstroke *, gps_from, &tgpil->prevFrame->strokes) {
|
2019-04-17 06:17:24 +02:00
|
|
|
bGPDstroke *gps_to;
|
|
|
|
int fFrame;
|
|
|
|
|
|
|
|
bGPDstroke *new_stroke = NULL;
|
|
|
|
bool valid = true;
|
|
|
|
|
|
|
|
/* only selected */
|
|
|
|
if ((tgpi->flag & GP_TOOLFLAG_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(ob, 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 */
|
2020-03-09 16:27:24 +01:00
|
|
|
new_stroke = BKE_gpencil_stroke_duplicate(gps_from, true);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
if (new_stroke->dvert != NULL) {
|
|
|
|
new_stroke->dvert = MEM_recallocN(new_stroke->dvert,
|
|
|
|
sizeof(*new_stroke->dvert) * gps_to->totpoints);
|
|
|
|
}
|
|
|
|
new_stroke->totpoints = gps_to->totpoints;
|
|
|
|
}
|
|
|
|
/* update points position */
|
2020-06-29 15:28:38 +02:00
|
|
|
gpencil_interpolate_update_points(gps_from, gps_to, new_stroke, tgpil->factor);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
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));
|
|
|
|
if (new_stroke->dvert != NULL) {
|
|
|
|
new_stroke->dvert = MEM_recallocN(new_stroke->dvert, sizeof(*new_stroke->dvert));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-09 16:27:24 +01:00
|
|
|
/* Calc geometry data. */
|
|
|
|
BKE_gpencil_stroke_geometry_update(new_stroke);
|
2019-04-17 06:17:24 +02:00
|
|
|
/* add to strokes */
|
|
|
|
BLI_addtail(&tgpil->interFrame->strokes, new_stroke);
|
|
|
|
}
|
|
|
|
}
|
2017-01-03 23:29:21 +13:00
|
|
|
}
|
|
|
|
|
2017-01-18 00:48:15 +13:00
|
|
|
/* ----------------------- */
|
|
|
|
|
2017-01-03 23:29:21 +13:00
|
|
|
/* Helper: calculate shift based on position of mouse (we only use x-axis for now.
|
2017-01-18 00:48:15 +13:00
|
|
|
* since this is more convenient for users to do), and store new shift value
|
|
|
|
*/
|
2017-01-03 23:29:21 +13:00
|
|
|
static void gpencil_mouse_update_shift(tGPDinterpolate *tgpi, wmOperator *op, const wmEvent *event)
|
|
|
|
{
|
2020-03-06 16:56:42 +01:00
|
|
|
float mid = (float)(tgpi->region->winx - tgpi->region->winrct.xmin) / 2.0f;
|
|
|
|
float mpos = event->x - tgpi->region->winrct.xmin;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
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);
|
2017-01-03 23:29:21 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Helper: Draw status message while the user is running the operator */
|
2018-06-26 17:19:25 +02:00
|
|
|
static void gpencil_interpolate_status_indicators(bContext *C, tGPDinterpolate *p)
|
2017-01-03 23:29:21 +13:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Scene *scene = p->scene;
|
|
|
|
char status_str[UI_MAX_DRAW_STR];
|
|
|
|
char msg_str[UI_MAX_DRAW_STR];
|
|
|
|
|
2019-06-11 22:25:01 +02:00
|
|
|
BLI_strncpy(msg_str, TIP_("GPencil Interpolation: "), UI_MAX_DRAW_STR);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2020-04-03 13:25:03 +02:00
|
|
|
ED_area_status_text(p->area, status_str);
|
2019-04-17 06:17:24 +02:00
|
|
|
ED_workspace_status_text(
|
2019-06-11 22:25:01 +02:00
|
|
|
C, TIP_("ESC/RMB to cancel, Enter/LMB to confirm, WHEEL/MOVE to adjust factor"));
|
2017-01-03 23:29:21 +13:00
|
|
|
}
|
|
|
|
|
2017-01-18 00:48:15 +13:00
|
|
|
/* Update screen and stroke */
|
2017-01-03 23:29:21 +13:00
|
|
|
static void gpencil_interpolate_update(bContext *C, wmOperator *op, tGPDinterpolate *tgpi)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* update shift indicator in header */
|
|
|
|
gpencil_interpolate_status_indicators(C, tgpi);
|
|
|
|
/* apply... */
|
|
|
|
tgpi->shift = RNA_float_get(op->ptr, "shift");
|
|
|
|
/* update points position */
|
2020-06-29 15:28:38 +02:00
|
|
|
gpencil_interpolate_update_strokes(C, tgpi);
|
2017-01-03 23:29:21 +13:00
|
|
|
}
|
|
|
|
|
2017-01-18 00:48:15 +13:00
|
|
|
/* ----------------------- */
|
2017-01-03 23:29:21 +13:00
|
|
|
|
|
|
|
/* Exit and free memory */
|
|
|
|
static void gpencil_interpolate_exit(bContext *C, wmOperator *op)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
tGPDinterpolate *tgpi = op->customdata;
|
|
|
|
bGPdata *gpd = tgpi->gpd;
|
|
|
|
|
|
|
|
/* don't assume that operator data exists at all */
|
|
|
|
if (tgpi) {
|
|
|
|
/* clear status message area */
|
2020-04-03 13:25:03 +02:00
|
|
|
ED_area_status_text(tgpi->area, NULL);
|
2019-04-17 06:17:24 +02:00
|
|
|
ED_workspace_status_text(C, NULL);
|
|
|
|
|
2020-03-09 16:27:24 +01:00
|
|
|
/* Clear any temp stroke. */
|
|
|
|
LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
|
|
|
|
LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
|
2020-06-29 15:28:38 +02:00
|
|
|
gpencil_interpolate_free_temp_strokes(gpf);
|
2020-03-09 16:27:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* finally, free memory used by temp data */
|
2020-03-09 16:27:24 +01:00
|
|
|
LISTBASE_FOREACH (tGPDinterpolate_layer *, tgpil, &tgpi->ilayers) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_gpencil_free_strokes(tgpil->interFrame);
|
|
|
|
MEM_freeN(tgpil->interFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_freelistN(&tgpi->ilayers);
|
|
|
|
MEM_freeN(tgpi);
|
|
|
|
}
|
|
|
|
DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
|
|
|
|
WM_event_add_notifier(C, NC_GPENCIL | NA_EDITED, NULL);
|
|
|
|
|
|
|
|
/* clear pointer */
|
|
|
|
op->customdata = NULL;
|
2017-01-03 23:29:21 +13:00
|
|
|
}
|
|
|
|
|
2017-01-18 00:48:15 +13:00
|
|
|
/* Init new temporary interpolation data */
|
2020-06-29 15:28:38 +02:00
|
|
|
static bool gpencil_interpolate_set_init_values(bContext *C, wmOperator *op, tGPDinterpolate *tgpi)
|
2017-01-03 23:29:21 +13:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ToolSettings *ts = CTX_data_tool_settings(C);
|
|
|
|
bGPdata *gpd = CTX_data_gpencil_data(C);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* set current scene and window */
|
2020-03-09 16:27:24 +01:00
|
|
|
tgpi->depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
tgpi->scene = CTX_data_scene(C);
|
2020-04-03 13:25:03 +02:00
|
|
|
tgpi->area = CTX_wm_area(C);
|
2020-03-06 16:56:42 +01:00
|
|
|
tgpi->region = CTX_wm_region(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
tgpi->flag = ts->gp_interpolate.flag;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* set current frame number */
|
|
|
|
tgpi->cframe = tgpi->scene->r.cfra;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* set GP datablock */
|
|
|
|
tgpi->gpd = gpd;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* set interpolation weight */
|
|
|
|
tgpi->shift = RNA_float_get(op->ptr, "shift");
|
|
|
|
/* set layers */
|
2020-06-29 15:28:38 +02:00
|
|
|
gpencil_interpolate_set_points(C, tgpi);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2020-07-28 16:23:45 +02:00
|
|
|
/* Untag strokes to be sure nothing is pending due any canceled process. */
|
|
|
|
LISTBASE_FOREACH (bGPDlayer *, gpl, &tgpi->gpd->layers) {
|
|
|
|
gpencil_interpolate_untag_strokes(gpl);
|
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return 1;
|
2017-01-03 23:29:21 +13:00
|
|
|
}
|
|
|
|
|
2017-01-18 00:48:15 +13:00
|
|
|
/* Allocate memory and initialize values */
|
2020-06-29 15:28:38 +02:00
|
|
|
static tGPDinterpolate *gpencil_session_init_interpolation(bContext *C, wmOperator *op)
|
2017-01-18 00:48:15 +13:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
tGPDinterpolate *tgpi = MEM_callocN(sizeof(tGPDinterpolate), "GPencil Interpolate Data");
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* define initial values */
|
2020-06-29 15:28:38 +02:00
|
|
|
gpencil_interpolate_set_init_values(C, op, tgpi);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* return context data for running operator */
|
|
|
|
return tgpi;
|
2017-01-18 00:48:15 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Init interpolation: Allocate memory and set init values */
|
2017-01-03 23:29:21 +13:00
|
|
|
static int gpencil_interpolate_init(bContext *C, wmOperator *op)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
tGPDinterpolate *tgpi;
|
|
|
|
|
|
|
|
/* check context */
|
2020-06-29 15:28:38 +02:00
|
|
|
tgpi = op->customdata = gpencil_session_init_interpolation(C, op);
|
2019-04-17 06:17:24 +02:00
|
|
|
if (tgpi == NULL) {
|
|
|
|
/* something wasn't set correctly in context */
|
|
|
|
gpencil_interpolate_exit(C, op);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* everything is now setup ok */
|
|
|
|
return 1;
|
2017-01-03 23:29:21 +13:00
|
|
|
}
|
|
|
|
|
2017-01-18 00:48:15 +13:00
|
|
|
/* ----------------------- */
|
2017-01-03 23:29:21 +13:00
|
|
|
|
|
|
|
/* Invoke handler: Initialize the operator */
|
|
|
|
static int gpencil_interpolate_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
wmWindow *win = CTX_wm_window(C);
|
|
|
|
bGPdata *gpd = CTX_data_gpencil_data(C);
|
|
|
|
bGPDlayer *gpl = CTX_data_active_gpencil_layer(C);
|
2019-07-26 14:13:53 +02:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2019-07-29 17:07:24 +02:00
|
|
|
int cfra = CFRA;
|
2019-04-17 06:17:24 +02:00
|
|
|
bGPDframe *actframe = gpl->actframe;
|
|
|
|
tGPDinterpolate *tgpi = NULL;
|
|
|
|
|
|
|
|
/* cannot interpolate if not between 2 frames */
|
|
|
|
if (ELEM(NULL, actframe, actframe->next)) {
|
|
|
|
BKE_report(
|
|
|
|
op->reports,
|
|
|
|
RPT_ERROR,
|
|
|
|
"Cannot find a pair of grease pencil frames to interpolate between in active layer");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cannot interpolate in extremes */
|
2019-07-29 17:07:24 +02:00
|
|
|
if (ELEM(cfra, actframe->framenum, actframe->next->framenum)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_report(op->reports,
|
|
|
|
RPT_ERROR,
|
|
|
|
"Cannot interpolate as current frame already has existing grease pencil frames");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* need editable strokes */
|
2020-06-29 15:28:38 +02:00
|
|
|
if (!gpencil_interpolate_check_todo(C, gpd)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "Interpolation requires some editable strokes");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to initialize context data needed */
|
|
|
|
if (!gpencil_interpolate_init(C, op)) {
|
2019-04-22 09:19:45 +10:00
|
|
|
if (op->customdata) {
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(op->customdata);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
2020-07-03 14:38:26 +02:00
|
|
|
tgpi = op->customdata;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* set cursor to indicate modal */
|
2019-09-26 14:31:48 +02:00
|
|
|
WM_cursor_modal_set(win, WM_CURSOR_EW_SCROLL);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* update shift indicator in header */
|
|
|
|
gpencil_interpolate_status_indicators(C, tgpi);
|
|
|
|
DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
|
|
|
|
WM_event_add_notifier(C, NC_GPENCIL | NA_EDITED, NULL);
|
|
|
|
|
|
|
|
/* add a modal handler for this operator */
|
|
|
|
WM_event_add_modal_handler(C, op);
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
2017-01-03 23:29:21 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Modal handler: Events handling during interactive part */
|
|
|
|
static int gpencil_interpolate_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
tGPDinterpolate *tgpi = op->customdata;
|
|
|
|
wmWindow *win = CTX_wm_window(C);
|
|
|
|
bGPDframe *gpf_dst;
|
2020-03-09 16:27:24 +01:00
|
|
|
bGPDstroke *gps_dst;
|
2019-04-17 06:17:24 +02:00
|
|
|
const bool has_numinput = hasNumInput(&tgpi->num);
|
|
|
|
|
|
|
|
switch (event->type) {
|
|
|
|
case LEFTMOUSE: /* confirm */
|
2020-03-18 10:38:37 -06:00
|
|
|
case EVT_PADENTER:
|
|
|
|
case EVT_RETKEY: {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* return to normal cursor and header status */
|
2020-04-03 13:25:03 +02:00
|
|
|
ED_area_status_text(tgpi->area, NULL);
|
2019-04-17 06:17:24 +02:00
|
|
|
ED_workspace_status_text(C, NULL);
|
|
|
|
WM_cursor_modal_restore(win);
|
|
|
|
|
|
|
|
/* insert keyframes as required... */
|
2020-03-09 16:27:24 +01:00
|
|
|
LISTBASE_FOREACH (tGPDinterpolate_layer *, tgpil, &tgpi->ilayers) {
|
|
|
|
gpf_dst = BKE_gpencil_layer_frame_get(tgpil->gpl, tgpi->cframe, GP_GETFRAME_ADD_NEW);
|
2019-04-17 06:17:24 +02:00
|
|
|
gpf_dst->key_type = BEZT_KEYTYPE_BREAKDOWN;
|
|
|
|
|
|
|
|
/* copy strokes */
|
|
|
|
BLI_listbase_clear(&gpf_dst->strokes);
|
2020-03-09 16:27:24 +01:00
|
|
|
LISTBASE_FOREACH (bGPDstroke *, gps_src, &tgpil->interFrame->strokes) {
|
2019-04-17 06:17:24 +02:00
|
|
|
if (gps_src->totpoints == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make copy of source stroke, then adjust pointer to points too */
|
2020-03-09 16:27:24 +01:00
|
|
|
gps_dst = BKE_gpencil_stroke_duplicate(gps_src, true);
|
2020-07-28 16:23:45 +02:00
|
|
|
gps_dst->flag &= ~GP_STROKE_TAG;
|
|
|
|
|
2020-03-09 16:27:24 +01:00
|
|
|
/* Calc geometry data. */
|
|
|
|
BKE_gpencil_stroke_geometry_update(gps_dst);
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_addtail(&gpf_dst->strokes, gps_dst);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clean up temp data */
|
|
|
|
gpencil_interpolate_exit(C, op);
|
|
|
|
|
|
|
|
/* done! */
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2020-03-18 10:38:37 -06:00
|
|
|
case EVT_ESCKEY: /* cancel */
|
2019-04-17 06:17:24 +02:00
|
|
|
case RIGHTMOUSE: {
|
|
|
|
/* return to normal cursor and header status */
|
2020-04-03 13:25:03 +02:00
|
|
|
ED_area_status_text(tgpi->area, NULL);
|
2019-04-17 06:17:24 +02:00
|
|
|
ED_workspace_status_text(C, NULL);
|
|
|
|
WM_cursor_modal_restore(win);
|
|
|
|
|
|
|
|
/* clean up temp data */
|
|
|
|
gpencil_interpolate_exit(C, op);
|
|
|
|
|
|
|
|
/* canceled! */
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WHEELUPMOUSE: {
|
|
|
|
tgpi->shift = tgpi->shift + 0.01f;
|
|
|
|
CLAMP(tgpi->shift, tgpi->low_limit, tgpi->high_limit);
|
|
|
|
RNA_float_set(op->ptr, "shift", tgpi->shift);
|
|
|
|
|
|
|
|
/* update screen */
|
|
|
|
gpencil_interpolate_update(C, op, tgpi);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WHEELDOWNMOUSE: {
|
|
|
|
tgpi->shift = tgpi->shift - 0.01f;
|
|
|
|
CLAMP(tgpi->shift, tgpi->low_limit, tgpi->high_limit);
|
|
|
|
RNA_float_set(op->ptr, "shift", tgpi->shift);
|
|
|
|
|
|
|
|
/* update screen */
|
|
|
|
gpencil_interpolate_update(C, op, tgpi);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MOUSEMOVE: /* calculate new position */
|
|
|
|
{
|
|
|
|
/* only handle mousemove if not doing numinput */
|
|
|
|
if (has_numinput == false) {
|
|
|
|
/* update shift based on position of mouse */
|
|
|
|
gpencil_mouse_update_shift(tgpi, op, event);
|
|
|
|
|
|
|
|
/* update screen */
|
|
|
|
gpencil_interpolate_update(C, op, tgpi);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
if ((event->val == KM_PRESS) && handleNumInput(C, &tgpi->num, event)) {
|
|
|
|
const float factor = tgpi->init_factor;
|
|
|
|
float value;
|
|
|
|
|
|
|
|
/* Grab shift from numeric input, and store this new value (the user see an int) */
|
|
|
|
value = (factor + tgpi->shift) * 100.0f;
|
|
|
|
applyNumInput(&tgpi->num, &value);
|
|
|
|
tgpi->shift = value / 100.0f;
|
|
|
|
|
|
|
|
/* recalculate the shift to get the right value in the frame scale */
|
|
|
|
tgpi->shift = tgpi->shift - factor;
|
|
|
|
|
|
|
|
CLAMP(tgpi->shift, tgpi->low_limit, tgpi->high_limit);
|
|
|
|
RNA_float_set(op->ptr, "shift", tgpi->shift);
|
|
|
|
|
|
|
|
/* update screen */
|
|
|
|
gpencil_interpolate_update(C, op, tgpi);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2020-07-03 14:38:26 +02:00
|
|
|
/* unhandled event - allow to pass through */
|
|
|
|
return OPERATOR_RUNNING_MODAL | OPERATOR_PASS_THROUGH;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* still running... */
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
2017-01-03 23:29:21 +13:00
|
|
|
}
|
|
|
|
|
2017-01-18 00:48:15 +13:00
|
|
|
/* Cancel handler */
|
|
|
|
static void gpencil_interpolate_cancel(bContext *C, wmOperator *op)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* this is just a wrapper around exit() */
|
|
|
|
gpencil_interpolate_exit(C, op);
|
2017-01-18 00:48:15 +13:00
|
|
|
}
|
|
|
|
|
2017-01-03 23:29:21 +13:00
|
|
|
void GPENCIL_OT_interpolate(wmOperatorType *ot)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Grease Pencil Interpolation";
|
|
|
|
ot->idname = "GPENCIL_OT_interpolate";
|
|
|
|
ot->description = "Interpolate grease pencil strokes between frames";
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
ot->invoke = gpencil_interpolate_invoke;
|
|
|
|
ot->modal = gpencil_interpolate_modal;
|
|
|
|
ot->cancel = gpencil_interpolate_cancel;
|
|
|
|
ot->poll = gpencil_view3d_poll;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_UNDO | OPTYPE_BLOCKING;
|
|
|
|
|
|
|
|
/* properties */
|
|
|
|
RNA_def_float_percentage(
|
|
|
|
ot->srna,
|
|
|
|
"shift",
|
|
|
|
0.0f,
|
|
|
|
-1.0f,
|
|
|
|
1.0f,
|
|
|
|
"Shift",
|
|
|
|
"Bias factor for which frame has more influence on the interpolated strokes",
|
|
|
|
-0.9f,
|
|
|
|
0.9f);
|
2017-01-03 23:29:21 +13:00
|
|
|
}
|
|
|
|
|
2017-01-18 00:48:15 +13:00
|
|
|
/* ****************** Interpolate Sequence *********************** */
|
|
|
|
|
2017-01-18 19:00:17 +13:00
|
|
|
/* Helper: Perform easing equation calculations for GP interpolation operator */
|
2020-06-29 15:28:38 +02:00
|
|
|
static float gpencil_interpolate_seq_easing_calc(GP_Interpolate_Settings *ipo_settings, float time)
|
2017-01-18 19:00:17 +13:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
const float begin = 0.0f;
|
|
|
|
const float change = 1.0f;
|
|
|
|
const float duration = 1.0f;
|
|
|
|
|
|
|
|
const float back = ipo_settings->back;
|
|
|
|
const float amplitude = ipo_settings->amplitude;
|
|
|
|
const float period = ipo_settings->period;
|
|
|
|
|
|
|
|
eBezTriple_Easing easing = ipo_settings->easing;
|
|
|
|
float result = time;
|
|
|
|
|
|
|
|
switch (ipo_settings->type) {
|
|
|
|
case GP_IPO_BACK:
|
|
|
|
switch (easing) {
|
|
|
|
case BEZT_IPO_EASE_IN:
|
|
|
|
result = BLI_easing_back_ease_in(time, begin, change, duration, back);
|
|
|
|
break;
|
|
|
|
case BEZT_IPO_EASE_OUT:
|
|
|
|
result = BLI_easing_back_ease_out(time, begin, change, duration, back);
|
|
|
|
break;
|
|
|
|
case BEZT_IPO_EASE_IN_OUT:
|
|
|
|
result = BLI_easing_back_ease_in_out(time, begin, change, duration, back);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* default/auto: same as ease out */
|
|
|
|
result = BLI_easing_back_ease_out(time, begin, change, duration, back);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GP_IPO_BOUNCE:
|
|
|
|
switch (easing) {
|
|
|
|
case BEZT_IPO_EASE_IN:
|
|
|
|
result = BLI_easing_bounce_ease_in(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
case BEZT_IPO_EASE_OUT:
|
|
|
|
result = BLI_easing_bounce_ease_out(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
case BEZT_IPO_EASE_IN_OUT:
|
|
|
|
result = BLI_easing_bounce_ease_in_out(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* default/auto: same as ease out */
|
|
|
|
result = BLI_easing_bounce_ease_out(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GP_IPO_CIRC:
|
|
|
|
switch (easing) {
|
|
|
|
case BEZT_IPO_EASE_IN:
|
|
|
|
result = BLI_easing_circ_ease_in(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
case BEZT_IPO_EASE_OUT:
|
|
|
|
result = BLI_easing_circ_ease_out(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
case BEZT_IPO_EASE_IN_OUT:
|
|
|
|
result = BLI_easing_circ_ease_in_out(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* default/auto: same as ease in */
|
|
|
|
result = BLI_easing_circ_ease_in(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GP_IPO_CUBIC:
|
|
|
|
switch (easing) {
|
|
|
|
case BEZT_IPO_EASE_IN:
|
|
|
|
result = BLI_easing_cubic_ease_in(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
case BEZT_IPO_EASE_OUT:
|
|
|
|
result = BLI_easing_cubic_ease_out(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
case BEZT_IPO_EASE_IN_OUT:
|
|
|
|
result = BLI_easing_cubic_ease_in_out(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* default/auto: same as ease in */
|
|
|
|
result = BLI_easing_cubic_ease_in(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GP_IPO_ELASTIC:
|
|
|
|
switch (easing) {
|
|
|
|
case BEZT_IPO_EASE_IN:
|
|
|
|
result = BLI_easing_elastic_ease_in(time, begin, change, duration, amplitude, period);
|
|
|
|
break;
|
|
|
|
case BEZT_IPO_EASE_OUT:
|
|
|
|
result = BLI_easing_elastic_ease_out(time, begin, change, duration, amplitude, period);
|
|
|
|
break;
|
|
|
|
case BEZT_IPO_EASE_IN_OUT:
|
|
|
|
result = BLI_easing_elastic_ease_in_out(
|
|
|
|
time, begin, change, duration, amplitude, period);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* default/auto: same as ease out */
|
|
|
|
result = BLI_easing_elastic_ease_out(time, begin, change, duration, amplitude, period);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GP_IPO_EXPO:
|
|
|
|
switch (easing) {
|
|
|
|
case BEZT_IPO_EASE_IN:
|
|
|
|
result = BLI_easing_expo_ease_in(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
case BEZT_IPO_EASE_OUT:
|
|
|
|
result = BLI_easing_expo_ease_out(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
case BEZT_IPO_EASE_IN_OUT:
|
|
|
|
result = BLI_easing_expo_ease_in_out(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* default/auto: same as ease in */
|
|
|
|
result = BLI_easing_expo_ease_in(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GP_IPO_QUAD:
|
|
|
|
switch (easing) {
|
|
|
|
case BEZT_IPO_EASE_IN:
|
|
|
|
result = BLI_easing_quad_ease_in(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
case BEZT_IPO_EASE_OUT:
|
|
|
|
result = BLI_easing_quad_ease_out(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
case BEZT_IPO_EASE_IN_OUT:
|
|
|
|
result = BLI_easing_quad_ease_in_out(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* default/auto: same as ease in */
|
|
|
|
result = BLI_easing_quad_ease_in(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GP_IPO_QUART:
|
|
|
|
switch (easing) {
|
|
|
|
case BEZT_IPO_EASE_IN:
|
|
|
|
result = BLI_easing_quart_ease_in(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
case BEZT_IPO_EASE_OUT:
|
|
|
|
result = BLI_easing_quart_ease_out(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
case BEZT_IPO_EASE_IN_OUT:
|
|
|
|
result = BLI_easing_quart_ease_in_out(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* default/auto: same as ease in */
|
|
|
|
result = BLI_easing_quart_ease_in(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GP_IPO_QUINT:
|
|
|
|
switch (easing) {
|
|
|
|
case BEZT_IPO_EASE_IN:
|
|
|
|
result = BLI_easing_quint_ease_in(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
case BEZT_IPO_EASE_OUT:
|
|
|
|
result = BLI_easing_quint_ease_out(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
case BEZT_IPO_EASE_IN_OUT:
|
|
|
|
result = BLI_easing_quint_ease_in_out(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* default/auto: same as ease in */
|
|
|
|
result = BLI_easing_quint_ease_in(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GP_IPO_SINE:
|
|
|
|
switch (easing) {
|
|
|
|
case BEZT_IPO_EASE_IN:
|
|
|
|
result = BLI_easing_sine_ease_in(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
case BEZT_IPO_EASE_OUT:
|
|
|
|
result = BLI_easing_sine_ease_out(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
case BEZT_IPO_EASE_IN_OUT:
|
|
|
|
result = BLI_easing_sine_ease_in_out(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* default/auto: same as ease in */
|
|
|
|
result = BLI_easing_sine_ease_in(time, begin, change, duration);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("%s: Unknown interpolation type - %d\n", __func__, ipo_settings->type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2017-01-18 19:00:17 +13:00
|
|
|
}
|
|
|
|
|
2017-01-03 23:29:21 +13:00
|
|
|
static int gpencil_interpolate_seq_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bGPdata *gpd = CTX_data_gpencil_data(C);
|
|
|
|
bGPDlayer *active_gpl = CTX_data_active_gpencil_layer(C);
|
|
|
|
bGPDframe *actframe = active_gpl->actframe;
|
|
|
|
|
|
|
|
Object *ob = CTX_data_active_object(C);
|
|
|
|
ToolSettings *ts = CTX_data_tool_settings(C);
|
2019-07-26 14:13:53 +02:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2019-07-29 17:07:24 +02:00
|
|
|
int cfra = CFRA;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
GP_Interpolate_Settings *ipo_settings = &ts->gp_interpolate;
|
|
|
|
eGP_Interpolate_SettingsFlag flag = ipo_settings->flag;
|
2020-09-04 15:36:02 +02:00
|
|
|
const int step = ipo_settings->step;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* cannot interpolate if not between 2 frames */
|
|
|
|
if (ELEM(NULL, actframe, actframe->next)) {
|
|
|
|
BKE_report(
|
|
|
|
op->reports,
|
|
|
|
RPT_ERROR,
|
|
|
|
"Cannot find a pair of grease pencil frames to interpolate between in active layer");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
/* cannot interpolate in extremes */
|
2019-07-29 17:07:24 +02:00
|
|
|
if (ELEM(cfra, actframe->framenum, actframe->next->framenum)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_report(op->reports,
|
|
|
|
RPT_ERROR,
|
|
|
|
"Cannot interpolate as current frame already has existing grease pencil frames");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* loop all layer to check if need interpolation */
|
2020-03-09 16:27:24 +01:00
|
|
|
LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
|
2019-04-17 06:17:24 +02:00
|
|
|
bGPDframe *prevFrame, *nextFrame;
|
|
|
|
bGPDstroke *gps_from, *gps_to;
|
|
|
|
int cframe, fFrame;
|
|
|
|
|
2020-05-06 12:21:53 +02:00
|
|
|
/* Need a set of frames to interpolate. */
|
|
|
|
if ((gpl->actframe == NULL) || (gpl->actframe->next == NULL)) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
/* all layers or only active */
|
|
|
|
if (((flag & GP_TOOLFLAG_INTERPOLATE_ALL_LAYERS) == 0) && (gpl != active_gpl)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* only editable and visible layers are considered */
|
2020-05-06 12:21:53 +02:00
|
|
|
if (!BKE_gpencil_layer_is_editable(gpl)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* store extremes */
|
|
|
|
prevFrame = gpl->actframe;
|
|
|
|
nextFrame = gpl->actframe->next;
|
|
|
|
|
|
|
|
/* Loop over intermediary frames and create the interpolation */
|
2020-09-04 15:36:02 +02:00
|
|
|
for (cframe = prevFrame->framenum + step; cframe < nextFrame->framenum; cframe += step) {
|
2019-04-17 06:17:24 +02:00
|
|
|
bGPDframe *interFrame = NULL;
|
|
|
|
float factor;
|
|
|
|
|
|
|
|
/* get interpolation factor */
|
2019-07-15 16:56:32 +02:00
|
|
|
float framerange = nextFrame->framenum - prevFrame->framenum;
|
|
|
|
CLAMP_MIN(framerange, 1.0f);
|
|
|
|
factor = (float)(cframe - prevFrame->framenum) / framerange;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
if (ipo_settings->type == GP_IPO_CURVEMAP) {
|
|
|
|
/* custom curvemap */
|
|
|
|
if (ipo_settings->custom_ipo) {
|
2019-08-07 03:21:55 +10:00
|
|
|
factor = BKE_curvemapping_evaluateF(ipo_settings->custom_ipo, 0, factor);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
BKE_report(op->reports, RPT_ERROR, "Custom interpolation curve does not exist");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ipo_settings->type >= GP_IPO_BACK) {
|
|
|
|
/* easing equation... */
|
2020-06-29 15:28:38 +02:00
|
|
|
factor = gpencil_interpolate_seq_easing_calc(ipo_settings, factor);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* create new strokes data with interpolated points reading original stroke */
|
|
|
|
for (gps_from = prevFrame->strokes.first; gps_from; gps_from = gps_from->next) {
|
|
|
|
|
|
|
|
/* only selected */
|
|
|
|
if ((flag & GP_TOOLFLAG_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(ob, gpl, gps_from) == false) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get final stroke to interpolate */
|
|
|
|
fFrame = BLI_findindex(&prevFrame->strokes, gps_from);
|
|
|
|
gps_to = BLI_findlink(&nextFrame->strokes, fFrame);
|
|
|
|
if (gps_to == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create a new frame if needed */
|
|
|
|
if (interFrame == NULL) {
|
2020-03-09 16:27:24 +01:00
|
|
|
interFrame = BKE_gpencil_layer_frame_get(gpl, cframe, GP_GETFRAME_ADD_NEW);
|
2019-04-17 06:17:24 +02:00
|
|
|
interFrame->key_type = BEZT_KEYTYPE_BREAKDOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create new stroke */
|
2020-03-09 16:27:24 +01:00
|
|
|
bGPDstroke *new_stroke = BKE_gpencil_stroke_duplicate(gps_from, true);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* if destination stroke is smaller, resize new_stroke to size of gps_to stroke */
|
|
|
|
if (gps_from->totpoints > gps_to->totpoints) {
|
|
|
|
/* free weights of removed points */
|
2019-11-29 16:27:19 +01:00
|
|
|
if (new_stroke->dvert != NULL) {
|
|
|
|
BKE_defvert_array_free_elems(new_stroke->dvert + gps_to->totpoints,
|
2019-04-17 06:17:24 +02:00
|
|
|
gps_from->totpoints - gps_to->totpoints);
|
|
|
|
}
|
|
|
|
|
|
|
|
new_stroke->points = MEM_recallocN(new_stroke->points,
|
|
|
|
sizeof(*new_stroke->points) * gps_to->totpoints);
|
|
|
|
|
|
|
|
if (new_stroke->dvert != NULL) {
|
|
|
|
new_stroke->dvert = MEM_recallocN(new_stroke->dvert,
|
|
|
|
sizeof(*new_stroke->dvert) * gps_to->totpoints);
|
|
|
|
}
|
2020-03-09 16:27:24 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
new_stroke->totpoints = gps_to->totpoints;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* update points position */
|
2020-06-29 15:28:38 +02:00
|
|
|
gpencil_interpolate_update_points(gps_from, gps_to, new_stroke, factor);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-09 16:27:24 +01:00
|
|
|
/* Calc geometry data. */
|
|
|
|
BKE_gpencil_stroke_geometry_update(new_stroke);
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* add to strokes */
|
|
|
|
BLI_addtail(&interFrame->strokes, new_stroke);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* notifiers */
|
|
|
|
DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
|
|
|
|
WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
2017-01-03 23:29:21 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPENCIL_OT_interpolate_sequence(wmOperatorType *ot)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Interpolate Sequence";
|
|
|
|
ot->idname = "GPENCIL_OT_interpolate_sequence";
|
|
|
|
ot->description = "Generate 'in-betweens' to smoothly interpolate between Grease Pencil frames";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = gpencil_interpolate_seq_exec;
|
|
|
|
ot->poll = gpencil_view3d_poll;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2017-01-03 23:29:21 +13:00
|
|
|
}
|
|
|
|
|
2017-01-18 19:40:48 +13:00
|
|
|
/* ******************** Remove Breakdowns ************************ */
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool gpencil_interpolate_reverse_poll(bContext *C)
|
2017-01-18 19:40:48 +13:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!gpencil_view3d_poll(C)) {
|
|
|
|
return 0;
|
|
|
|
}
|
2017-03-29 19:19:25 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bGPDlayer *gpl = CTX_data_active_gpencil_layer(C);
|
2017-03-29 19:19:25 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* need to be on a breakdown frame */
|
|
|
|
if ((gpl->actframe == NULL) || (gpl->actframe->key_type != BEZT_KEYTYPE_BREAKDOWN)) {
|
|
|
|
CTX_wm_operator_poll_msg_set(C, "Expected current frame to be a breakdown");
|
|
|
|
return 0;
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return 1;
|
2017-01-18 19:40:48 +13:00
|
|
|
}
|
|
|
|
|
2017-01-18 12:20:53 +01:00
|
|
|
static int gpencil_interpolate_reverse_exec(bContext *C, wmOperator *UNUSED(op))
|
2017-01-18 19:40:48 +13:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bGPdata *gpd = ED_gpencil_data_get_active(C);
|
|
|
|
|
|
|
|
/* Go through each layer, deleting the breakdowns around the current frame,
|
|
|
|
* but only if there is a keyframe nearby to stop at
|
|
|
|
*/
|
|
|
|
CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) {
|
|
|
|
bGPDframe *start_key = NULL;
|
|
|
|
bGPDframe *end_key = NULL;
|
|
|
|
bGPDframe *gpf, *gpfn;
|
|
|
|
|
|
|
|
/* Only continue if we're currently on a breakdown keyframe */
|
2019-04-22 09:19:45 +10:00
|
|
|
if ((gpl->actframe == NULL) || (gpl->actframe->key_type != BEZT_KEYTYPE_BREAKDOWN)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
continue;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* Search left for "start_key" (i.e. the first breakdown to remove) */
|
|
|
|
gpf = gpl->actframe;
|
|
|
|
while (gpf) {
|
|
|
|
if (gpf->key_type == BEZT_KEYTYPE_BREAKDOWN) {
|
|
|
|
/* A breakdown... keep going left */
|
|
|
|
start_key = gpf;
|
|
|
|
gpf = gpf->prev;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Not a breakdown (may be a key, or an extreme,
|
|
|
|
* or something else that wasn't generated)... stop */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Search right for "end_key" (i.e. the last breakdown to remove) */
|
|
|
|
gpf = gpl->actframe;
|
|
|
|
while (gpf) {
|
|
|
|
if (gpf->key_type == BEZT_KEYTYPE_BREAKDOWN) {
|
|
|
|
/* A breakdown... keep going right */
|
|
|
|
end_key = gpf;
|
|
|
|
gpf = gpf->next;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Not a breakdown... stop */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Did we find anything? */
|
|
|
|
/* NOTE: We should only proceed if there's something before/after these extents...
|
|
|
|
* Otherwise, there's just an extent of breakdowns with no keys to interpolate between
|
|
|
|
*/
|
|
|
|
if ((start_key && end_key) && ELEM(NULL, start_key->prev, end_key->next) == false) {
|
|
|
|
/* Set actframe to the key before start_key, since the keys have been removed now */
|
|
|
|
gpl->actframe = start_key->prev;
|
|
|
|
|
|
|
|
/* Free each frame we're removing (except the last one) */
|
|
|
|
for (gpf = start_key; gpf && gpf != end_key; gpf = gpfn) {
|
|
|
|
gpfn = gpf->next;
|
|
|
|
|
|
|
|
/* free strokes and their associated memory */
|
|
|
|
BKE_gpencil_free_strokes(gpf);
|
|
|
|
BLI_freelinkN(&gpl->frames, gpf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now free the last one... */
|
|
|
|
BKE_gpencil_free_strokes(end_key);
|
|
|
|
BLI_freelinkN(&gpl->frames, end_key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CTX_DATA_END;
|
|
|
|
|
|
|
|
/* notifiers */
|
|
|
|
DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
|
|
|
|
WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
2017-01-18 19:40:48 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPENCIL_OT_interpolate_reverse(wmOperatorType *ot)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Remove Breakdowns";
|
|
|
|
ot->idname = "GPENCIL_OT_interpolate_reverse";
|
|
|
|
ot->description =
|
|
|
|
"Remove breakdown frames generated by interpolating between two Grease Pencil frames";
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
ot->exec = gpencil_interpolate_reverse_exec;
|
|
|
|
ot->poll = gpencil_interpolate_reverse_poll;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2017-01-18 19:40:48 +13:00
|
|
|
}
|
|
|
|
|
2017-01-18 00:48:15 +13:00
|
|
|
/* *************************************************************** */
|