2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2009-01-26 23:18:27 +00: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,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-01-26 23:18:27 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup spgraph
|
2011-02-27 20:29:51 +00:00
|
|
|
*/
|
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <float.h>
|
2009-01-26 23:18:27 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2011-06-23 09:27:56 +00:00
|
|
|
#ifdef WITH_AUDASPACE
|
2017-08-18 08:24:12 +02:00
|
|
|
# include <AUD_Special.h>
|
2011-06-23 09:27:56 +00:00
|
|
|
#endif
|
2010-01-01 05:09:30 +00:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
2009-11-10 20:43:45 +00:00
|
|
|
#include "BLI_math.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2009-01-26 23:18:27 +00:00
|
|
|
|
|
|
|
#include "DNA_anim_types.h"
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
#include "RNA_define.h"
|
2009-05-08 10:50:32 +00:00
|
|
|
#include "RNA_enum_types.h"
|
2009-01-26 23:18:27 +00:00
|
|
|
|
2015-08-16 17:32:01 +10:00
|
|
|
#include "BLT_translation.h"
|
2012-03-03 21:42:21 +00:00
|
|
|
|
2018-11-12 19:41:53 +03:00
|
|
|
#include "BKE_animsys.h"
|
2018-06-07 12:47:00 +02:00
|
|
|
#include "BKE_context.h"
|
2009-01-26 23:18:27 +00:00
|
|
|
#include "BKE_fcurve.h"
|
2012-12-06 05:48:51 +00:00
|
|
|
#include "BKE_global.h"
|
2009-06-23 13:25:31 +00:00
|
|
|
#include "BKE_nla.h"
|
2009-02-24 11:23:04 +00:00
|
|
|
#include "BKE_report.h"
|
2009-01-26 23:18:27 +00:00
|
|
|
|
2017-06-08 10:14:53 +02:00
|
|
|
#include "DEG_depsgraph_build.h"
|
|
|
|
|
2019-05-21 11:59:10 +02:00
|
|
|
#include "UI_interface.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "UI_view2d.h"
|
2009-01-26 23:18:27 +00:00
|
|
|
|
|
|
|
#include "ED_anim_api.h"
|
|
|
|
#include "ED_keyframes_edit.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "ED_keyframing.h"
|
|
|
|
#include "ED_markers.h"
|
2009-01-26 23:18:27 +00:00
|
|
|
#include "ED_screen.h"
|
2009-07-08 16:17:47 +00:00
|
|
|
#include "ED_transform.h"
|
2009-01-26 23:18:27 +00:00
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
2009-02-03 12:04:05 +00:00
|
|
|
#include "graph_intern.h"
|
2009-01-26 23:18:27 +00:00
|
|
|
|
|
|
|
/* ************************************************************************** */
|
2020-11-23 15:11:51 +01:00
|
|
|
/* INSERT DUPLICATE AND BAKE KEYFRAMES */
|
2009-01-26 23:18:27 +00:00
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Insert Keyframes Operator
|
|
|
|
* \{ */
|
2009-06-29 03:02:41 +00:00
|
|
|
|
2015-12-15 04:03:25 +13:00
|
|
|
/* Mode defines for insert keyframes tool. */
|
|
|
|
typedef enum eGraphKeys_InsertKey_Types {
|
|
|
|
GRAPHKEYS_INSERTKEY_ALL = (1 << 0),
|
|
|
|
GRAPHKEYS_INSERTKEY_SEL = (1 << 1),
|
|
|
|
GRAPHKEYS_INSERTKEY_CURSOR = (1 << 2),
|
|
|
|
GRAPHKEYS_INSERTKEY_ACTIVE = (1 << 3),
|
|
|
|
} eGraphKeys_InsertKey_Types;
|
|
|
|
|
|
|
|
/* RNA mode types for insert keyframes tool. */
|
2017-10-18 15:07:26 +11:00
|
|
|
static const EnumPropertyItem prop_graphkeys_insertkey_types[] = {
|
2015-12-15 04:03:25 +13:00
|
|
|
{GRAPHKEYS_INSERTKEY_ALL,
|
|
|
|
"ALL",
|
|
|
|
0,
|
|
|
|
"All Channels",
|
|
|
|
"Insert a keyframe on all visible and editable F-Curves using each curve's current value"},
|
|
|
|
{GRAPHKEYS_INSERTKEY_SEL,
|
|
|
|
"SEL",
|
|
|
|
0,
|
|
|
|
"Only Selected Channels",
|
|
|
|
"Insert a keyframe on selected F-Curves using each curve's current value"},
|
|
|
|
{GRAPHKEYS_INSERTKEY_ACTIVE | GRAPHKEYS_INSERTKEY_CURSOR,
|
|
|
|
"CURSOR_ACTIVE",
|
|
|
|
0,
|
2020-12-24 11:07:32 -06:00
|
|
|
"Active Channels at Cursor",
|
2015-12-15 04:03:25 +13:00
|
|
|
"Insert a keyframe for the active F-Curve at the cursor point"},
|
|
|
|
{GRAPHKEYS_INSERTKEY_SEL | GRAPHKEYS_INSERTKEY_CURSOR,
|
|
|
|
"CURSOR_SEL",
|
|
|
|
0,
|
2020-12-24 11:07:32 -06:00
|
|
|
"Selected Channels at Cursor",
|
2015-12-15 04:03:25 +13:00
|
|
|
"Insert a keyframe for selected F-Curves at the cursor point"},
|
2019-02-03 14:01:45 +11:00
|
|
|
{0, NULL, 0, NULL, NULL},
|
2009-06-29 03:02:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* This function is responsible for snapping keyframes to frame-times. */
|
2018-06-04 09:31:30 +02:00
|
|
|
static void insert_graph_keys(bAnimContext *ac, eGraphKeys_InsertKey_Types mode)
|
2009-06-29 03:02:41 +00:00
|
|
|
{
|
|
|
|
ListBase anim_data = {NULL, NULL};
|
2018-11-12 19:41:53 +03:00
|
|
|
ListBase nla_cache = {NULL, NULL};
|
2009-06-29 03:02:41 +00:00
|
|
|
bAnimListElem *ale;
|
|
|
|
int filter;
|
2015-12-15 04:03:25 +13:00
|
|
|
size_t num_items;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-11-17 12:02:36 +00:00
|
|
|
ReportList *reports = ac->reports;
|
2019-02-16 10:16:16 +11:00
|
|
|
SpaceGraph *sipo = (SpaceGraph *)ac->sl;
|
2012-05-08 20:18:33 +00:00
|
|
|
Scene *scene = ac->scene;
|
2016-03-13 03:49:26 +13:00
|
|
|
ToolSettings *ts = scene->toolsettings;
|
2020-03-06 16:45:56 +11:00
|
|
|
eInsertKeyFlags flag = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-06-29 03:02:41 +00:00
|
|
|
/* Filter data. */
|
2012-05-08 20:18:33 +00:00
|
|
|
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FOREDIT |
|
|
|
|
ANIMFILTER_NODUPLIS);
|
2019-04-22 09:19:45 +10:00
|
|
|
if (mode & GRAPHKEYS_INSERTKEY_SEL) {
|
2015-12-15 04:03:25 +13:00
|
|
|
filter |= ANIMFILTER_SEL;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
else if (mode & GRAPHKEYS_INSERTKEY_ACTIVE) {
|
2015-12-15 04:03:25 +13:00
|
|
|
filter |= ANIMFILTER_ACTIVE;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-12-15 04:03:25 +13:00
|
|
|
num_items = ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
|
|
|
|
if (num_items == 0) {
|
2019-04-22 09:19:45 +10:00
|
|
|
if (mode & GRAPHKEYS_INSERTKEY_ACTIVE) {
|
2015-12-15 04:03:25 +13:00
|
|
|
BKE_report(reports,
|
|
|
|
RPT_ERROR,
|
|
|
|
"No active F-Curve to add a keyframe to. Select an editable F-Curve first");
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
else if (mode & GRAPHKEYS_INSERTKEY_SEL) {
|
2015-12-15 04:03:25 +13:00
|
|
|
BKE_report(reports, RPT_ERROR, "No selected F-Curves to add keyframes to");
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
else {
|
2015-12-15 04:03:25 +13:00
|
|
|
BKE_report(reports, RPT_ERROR, "No channels to add keyframes to");
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-12-15 04:03:25 +13:00
|
|
|
return;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-06 16:45:56 +11:00
|
|
|
/* Init key-framing flag. */
|
|
|
|
flag = ANIM_get_keyframing_flags(scene, true);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-06-29 03:02:41 +00:00
|
|
|
/* Insert keyframes. */
|
2015-12-15 04:03:25 +13:00
|
|
|
if (mode & GRAPHKEYS_INSERTKEY_CURSOR) {
|
|
|
|
for (ale = anim_data.first; ale; ale = ale->next) {
|
|
|
|
AnimData *adt = ANIM_nla_mapping_get(ac, ale);
|
|
|
|
FCurve *fcu = (FCurve *)ale->key_data;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-12-15 04:03:25 +13:00
|
|
|
short mapping_flag = ANIM_get_normalization_flags(ac);
|
|
|
|
float offset;
|
|
|
|
float unit_scale = ANIM_unit_mapping_get_factor(
|
|
|
|
ac->scene, ale->id, ale->key_data, mapping_flag, &offset);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-12-15 04:03:25 +13:00
|
|
|
float x, y;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-12-15 04:03:25 +13:00
|
|
|
/* perform time remapping for x-coordinate (if necessary) */
|
2019-04-22 09:19:45 +10:00
|
|
|
if ((sipo) && (sipo->mode == SIPO_MODE_DRIVERS)) {
|
2015-12-15 04:03:25 +13:00
|
|
|
x = sipo->cursorTime;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
else if (adt) {
|
2015-12-15 04:03:25 +13:00
|
|
|
x = BKE_nla_tweakedit_remap(adt, (float)CFRA, NLATIME_CONVERT_UNMAP);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
else {
|
2015-12-15 04:03:25 +13:00
|
|
|
x = (float)CFRA;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-12-15 04:03:25 +13:00
|
|
|
/* Normalise units of cursor's value. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (sipo) {
|
2015-12-15 04:03:25 +13:00
|
|
|
y = (sipo->cursorVal / unit_scale) - offset;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
else {
|
2015-12-15 04:03:25 +13:00
|
|
|
y = 0.0f;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-12-15 04:03:25 +13:00
|
|
|
/* Insert keyframe directly into the F-Curve. */
|
2016-03-13 03:49:26 +13:00
|
|
|
insert_vert_fcurve(fcu, x, y, ts->keyframe_type, 0);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-12-15 04:03:25 +13:00
|
|
|
ale->update |= ANIM_UPDATE_DEFAULT;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2015-12-15 04:03:25 +13:00
|
|
|
}
|
|
|
|
else {
|
T77086 Animation: Passing Dependency Graph to Drivers
Custom driver functions need access to the dependency graph that is
triggering the evaluation of the driver. This patch passes the
dependency graph pointer through all the animation-related calls.
Instead of passing the evaluation time to functions, the code now passes
an `AnimationEvalContext` pointer:
```
typedef struct AnimationEvalContext {
struct Depsgraph *const depsgraph;
const float eval_time;
} AnimationEvalContext;
```
These structs are read-only, meaning that the code cannot change the
evaluation time. Note that the `depsgraph` pointer itself is const, but
it points to a non-const depsgraph.
FCurves and Drivers can be evaluated at a different time than the
current scene time, for example when evaluating NLA strips. This means
that, even though the current time is stored in the dependency graph, we
need an explicit evaluation time.
There are two functions that allow creation of `AnimationEvalContext`
objects:
- `BKE_animsys_eval_context_construct(Depsgraph *depsgraph, float
eval_time)`, which creates a new context object from scratch, and
- `BKE_animsys_eval_context_construct_at(AnimationEvalContext
*anim_eval_context, float eval_time)`, which can be used to create a
`AnimationEvalContext` with the same depsgraph, but at a different
time. This makes it possible to later add fields without changing any
of the code that just want to change the eval time.
This also provides a fix for T75553, although it does require a change
to the custom driver function. The driver should call
`custom_function(depsgraph)`, and the function should use that depsgraph
instead of information from `bpy.context`.
Reviewed By: brecht, sergey
Differential Revision: https://developer.blender.org/D8047
2020-07-17 17:38:09 +02:00
|
|
|
const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct(
|
|
|
|
ac->depsgraph, (float)CFRA);
|
2015-12-15 04:03:25 +13:00
|
|
|
for (ale = anim_data.first; ale; ale = ale->next) {
|
|
|
|
FCurve *fcu = (FCurve *)ale->key_data;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 00:18:34 +10:00
|
|
|
/* Read value from property the F-Curve represents, or from the curve only?
|
|
|
|
*
|
|
|
|
* - ale->id != NULL:
|
|
|
|
* Typically, this means that we have enough info to try resolving the path.
|
|
|
|
* - ale->owner != NULL:
|
|
|
|
* If this is set, then the path may not be resolvable from the ID alone,
|
|
|
|
* so it's easier for now to just read the F-Curve directly.
|
|
|
|
* (TODO: add the full-blown PointerRNA relative parsing case here... (Joshua Leung 2015))
|
|
|
|
* - fcu->driver != NULL:
|
|
|
|
* If this is set, then it's a driver. If we don't check for this, we'd end
|
|
|
|
* up adding the keyframes on a new F-Curve in the action data instead.
|
2015-12-15 04:03:25 +13:00
|
|
|
*/
|
2016-06-04 00:54:28 +10:00
|
|
|
if (ale->id && !ale->owner && !fcu->driver) {
|
2018-06-07 13:04:16 +02:00
|
|
|
insert_keyframe(ac->bmain,
|
|
|
|
reports,
|
|
|
|
ale->id,
|
|
|
|
NULL,
|
|
|
|
((fcu->grp) ? (fcu->grp->name) : (NULL)),
|
2018-11-12 19:41:53 +03:00
|
|
|
fcu->rna_path,
|
|
|
|
fcu->array_index,
|
T77086 Animation: Passing Dependency Graph to Drivers
Custom driver functions need access to the dependency graph that is
triggering the evaluation of the driver. This patch passes the
dependency graph pointer through all the animation-related calls.
Instead of passing the evaluation time to functions, the code now passes
an `AnimationEvalContext` pointer:
```
typedef struct AnimationEvalContext {
struct Depsgraph *const depsgraph;
const float eval_time;
} AnimationEvalContext;
```
These structs are read-only, meaning that the code cannot change the
evaluation time. Note that the `depsgraph` pointer itself is const, but
it points to a non-const depsgraph.
FCurves and Drivers can be evaluated at a different time than the
current scene time, for example when evaluating NLA strips. This means
that, even though the current time is stored in the dependency graph, we
need an explicit evaluation time.
There are two functions that allow creation of `AnimationEvalContext`
objects:
- `BKE_animsys_eval_context_construct(Depsgraph *depsgraph, float
eval_time)`, which creates a new context object from scratch, and
- `BKE_animsys_eval_context_construct_at(AnimationEvalContext
*anim_eval_context, float eval_time)`, which can be used to create a
`AnimationEvalContext` with the same depsgraph, but at a different
time. This makes it possible to later add fields without changing any
of the code that just want to change the eval time.
This also provides a fix for T75553, although it does require a change
to the custom driver function. The driver should call
`custom_function(depsgraph)`, and the function should use that depsgraph
instead of information from `bpy.context`.
Reviewed By: brecht, sergey
Differential Revision: https://developer.blender.org/D8047
2020-07-17 17:38:09 +02:00
|
|
|
&anim_eval_context,
|
2018-11-12 19:41:53 +03:00
|
|
|
ts->keyframe_type,
|
|
|
|
&nla_cache,
|
|
|
|
flag);
|
2016-06-04 00:54:28 +10:00
|
|
|
}
|
|
|
|
else {
|
2018-11-07 18:05:22 +03:00
|
|
|
AnimData *adt = ANIM_nla_mapping_get(ac, ale);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-07 18:05:22 +03:00
|
|
|
/* Adjust current frame for NLA-mapping. */
|
T77086 Animation: Passing Dependency Graph to Drivers
Custom driver functions need access to the dependency graph that is
triggering the evaluation of the driver. This patch passes the
dependency graph pointer through all the animation-related calls.
Instead of passing the evaluation time to functions, the code now passes
an `AnimationEvalContext` pointer:
```
typedef struct AnimationEvalContext {
struct Depsgraph *const depsgraph;
const float eval_time;
} AnimationEvalContext;
```
These structs are read-only, meaning that the code cannot change the
evaluation time. Note that the `depsgraph` pointer itself is const, but
it points to a non-const depsgraph.
FCurves and Drivers can be evaluated at a different time than the
current scene time, for example when evaluating NLA strips. This means
that, even though the current time is stored in the dependency graph, we
need an explicit evaluation time.
There are two functions that allow creation of `AnimationEvalContext`
objects:
- `BKE_animsys_eval_context_construct(Depsgraph *depsgraph, float
eval_time)`, which creates a new context object from scratch, and
- `BKE_animsys_eval_context_construct_at(AnimationEvalContext
*anim_eval_context, float eval_time)`, which can be used to create a
`AnimationEvalContext` with the same depsgraph, but at a different
time. This makes it possible to later add fields without changing any
of the code that just want to change the eval time.
This also provides a fix for T75553, although it does require a change
to the custom driver function. The driver should call
`custom_function(depsgraph)`, and the function should use that depsgraph
instead of information from `bpy.context`.
Reviewed By: brecht, sergey
Differential Revision: https://developer.blender.org/D8047
2020-07-17 17:38:09 +02:00
|
|
|
float cfra = (float)CFRA;
|
2019-04-22 09:19:45 +10:00
|
|
|
if ((sipo) && (sipo->mode == SIPO_MODE_DRIVERS)) {
|
2018-11-07 18:05:22 +03:00
|
|
|
cfra = sipo->cursorTime;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
else if (adt) {
|
2018-11-07 18:05:22 +03:00
|
|
|
cfra = BKE_nla_tweakedit_remap(adt, (float)CFRA, NLATIME_CONVERT_UNMAP);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-01-31 12:17:43 +01:00
|
|
|
const float curval = evaluate_fcurve_only_curve(fcu, cfra);
|
2016-06-04 00:54:28 +10:00
|
|
|
insert_vert_fcurve(fcu, cfra, curval, ts->keyframe_type, 0);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-12-15 04:03:25 +13:00
|
|
|
ale->update |= ANIM_UPDATE_DEFAULT;
|
2009-06-29 03:02:41 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
2018-11-12 19:41:53 +03:00
|
|
|
BKE_animsys_free_nla_keyframing_context_cache(&nla_cache);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-19 00:24:45 +10:00
|
|
|
ANIM_animdata_update(ac, &anim_data);
|
|
|
|
ANIM_animdata_freelist(&anim_data);
|
2009-06-29 03:02:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------- */
|
|
|
|
|
|
|
|
static int graphkeys_insertkey_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
bAnimContext ac;
|
2015-12-15 04:03:25 +13:00
|
|
|
eGraphKeys_InsertKey_Types mode;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-06-29 03:02:41 +00:00
|
|
|
/* Get editor data. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
2009-06-29 03:02:41 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-06-29 03:02:41 +00:00
|
|
|
/* Which channels to affect?. */
|
2012-05-08 20:18:33 +00:00
|
|
|
mode = RNA_enum_get(op->ptr, "type");
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-06-29 03:02:41 +00:00
|
|
|
/* Insert keyframes. */
|
|
|
|
insert_graph_keys(&ac, mode);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-07-10 10:48:25 +00:00
|
|
|
/* Set notifier that keyframes have changed. */
|
2014-04-24 14:26:53 +12:00
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_ADDED, NULL);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-06-29 03:02:41 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void GRAPH_OT_keyframe_insert(wmOperatorType *ot)
|
2009-06-29 03:02:41 +00:00
|
|
|
{
|
|
|
|
/* Identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Insert Keyframes";
|
|
|
|
ot->idname = "GRAPH_OT_keyframe_insert";
|
|
|
|
ot->description = "Insert keyframes for the specified channels";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-06-29 03:02:41 +00:00
|
|
|
/* API callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->invoke = WM_menu_invoke;
|
|
|
|
ot->exec = graphkeys_insertkey_exec;
|
|
|
|
ot->poll = graphop_editable_keyframes_poll;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-06-29 03:02:41 +00:00
|
|
|
/* Flags */
|
2012-05-08 20:18:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-06-29 03:02:41 +00:00
|
|
|
/* Id-props */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->prop = RNA_def_enum(ot->srna, "type", prop_graphkeys_insertkey_types, 0, "Type", "");
|
2009-06-29 03:02:41 +00:00
|
|
|
}
|
2009-01-26 23:18:27 +00:00
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Click-Insert Keyframes Operator
|
|
|
|
* \{ */
|
2009-04-06 12:07:33 +00:00
|
|
|
|
2012-05-08 20:18:33 +00:00
|
|
|
static int graphkeys_click_insert_exec(bContext *C, wmOperator *op)
|
2009-04-06 12:07:33 +00:00
|
|
|
{
|
|
|
|
bAnimContext ac;
|
|
|
|
bAnimListElem *ale;
|
2009-06-23 13:25:31 +00:00
|
|
|
AnimData *adt;
|
2010-01-26 03:16:14 +00:00
|
|
|
FCurve *fcu;
|
2009-04-06 12:07:33 +00:00
|
|
|
float frame, val;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-04-06 12:07:33 +00:00
|
|
|
/* Get animation context. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
2009-04-06 12:07:33 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-04-06 12:07:33 +00:00
|
|
|
/* Get active F-Curve 'anim-list-element'. */
|
2012-05-08 20:18:33 +00:00
|
|
|
ale = get_active_fcurve_channel(&ac);
|
2009-04-06 12:07:33 +00:00
|
|
|
if (ELEM(NULL, ale, ale->data)) {
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ale) {
|
2009-04-06 12:07:33 +00:00
|
|
|
MEM_freeN(ale);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2009-04-06 12:07:33 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
2010-01-26 03:16:14 +00:00
|
|
|
fcu = ale->data;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-11-17 12:02:36 +00:00
|
|
|
/* When there are F-Modifiers on the curve, only allow adding
|
|
|
|
* keyframes if these will be visible after doing so...
|
|
|
|
*/
|
2020-06-05 09:30:15 +02:00
|
|
|
if (BKE_fcurve_is_keyframable(fcu)) {
|
2014-05-19 00:24:45 +10:00
|
|
|
ListBase anim_data;
|
2016-03-13 03:49:26 +13:00
|
|
|
ToolSettings *ts = ac.scene->toolsettings;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-10-29 18:10:52 +00:00
|
|
|
short mapping_flag = ANIM_get_normalization_flags(&ac);
|
2015-04-13 15:57:46 +02:00
|
|
|
float scale, offset;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-05-09 16:58:12 +12:00
|
|
|
/* Preserve selection? */
|
|
|
|
if (RNA_boolean_get(op->ptr, "extend") == false) {
|
2019-04-22 00:18:34 +10:00
|
|
|
/* Deselect all keyframes first,
|
|
|
|
* so that we can immediately start manipulating the newly added one(s)
|
|
|
|
* - only affect the keyframes themselves, as we don't want channels popping in and out. */
|
2016-05-09 16:58:12 +12:00
|
|
|
deselect_graph_keys(&ac, false, SELECT_SUBTRACT, false);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-11-17 12:02:36 +00:00
|
|
|
/* Get frame and value from props. */
|
2012-05-08 20:18:33 +00:00
|
|
|
frame = RNA_float_get(op->ptr, "frame");
|
|
|
|
val = RNA_float_get(op->ptr, "value");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-11-17 12:02:36 +00:00
|
|
|
/* Apply inverse NLA-mapping to frame to get correct time in un-scaled action. */
|
2012-05-08 20:18:33 +00:00
|
|
|
adt = ANIM_nla_mapping_get(&ac, ale);
|
|
|
|
frame = BKE_nla_tweakedit_remap(adt, frame, NLATIME_CONVERT_UNMAP);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-11-17 12:02:36 +00:00
|
|
|
/* Apply inverse unit-mapping to value to get correct value for F-Curves. */
|
2015-04-13 15:57:46 +02:00
|
|
|
scale = ANIM_unit_mapping_get_factor(
|
|
|
|
ac.scene, ale->id, fcu, mapping_flag | ANIM_UNITCONV_RESTORE, &offset);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-04-13 15:57:46 +02:00
|
|
|
val = val * scale - offset;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-11-17 12:02:36 +00:00
|
|
|
/* Insert keyframe on the specified frame + value. */
|
2016-03-13 03:49:26 +13:00
|
|
|
insert_vert_fcurve(fcu, frame, val, ts->keyframe_type, 0);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-19 00:24:45 +10:00
|
|
|
ale->update |= ANIM_UPDATE_DEPS;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-19 00:24:45 +10:00
|
|
|
BLI_listbase_clear(&anim_data);
|
|
|
|
BLI_addtail(&anim_data, ale);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-19 00:24:45 +10:00
|
|
|
ANIM_animdata_update(&ac, &anim_data);
|
2010-11-17 12:02:36 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Warn about why this can't happen. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (fcu->fpt) {
|
2010-11-17 12:02:36 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "Keyframes cannot be added to sampled F-Curves");
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
else if (fcu->flag & FCURVE_PROTECTED) {
|
2010-11-17 12:02:36 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "Active F-Curve is not editable");
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
else {
|
2010-11-17 12:02:36 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "Remove F-Modifiers from F-Curve to add keyframes");
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2010-11-17 12:02:36 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-04-06 12:07:33 +00:00
|
|
|
/* Free temp data. */
|
|
|
|
MEM_freeN(ale);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-07-10 10:48:25 +00:00
|
|
|
/* Set notifier that keyframes have changed. */
|
2012-05-08 20:18:33 +00:00
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-04-06 12:07:33 +00:00
|
|
|
/* Done */
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2013-03-13 09:03:46 +00:00
|
|
|
static int graphkeys_click_insert_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
2009-04-06 12:07:33 +00:00
|
|
|
{
|
|
|
|
bAnimContext ac;
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region;
|
2009-04-06 12:07:33 +00:00
|
|
|
View2D *v2d;
|
|
|
|
int mval[2];
|
|
|
|
float x, y;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-04-06 12:07:33 +00:00
|
|
|
/* Get animation context. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
2009-04-06 12:07:33 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-04-06 12:07:33 +00:00
|
|
|
/* Store mouse coordinates in View2D space, into the operator's properties. */
|
2020-03-06 16:56:42 +01:00
|
|
|
region = ac.region;
|
|
|
|
v2d = ®ion->v2d;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
mval[0] = (event->x - region->winrct.xmin);
|
|
|
|
mval[1] = (event->y - region->winrct.ymin);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-04-06 12:07:33 +00:00
|
|
|
UI_view2d_region_to_view(v2d, mval[0], mval[1], &x, &y);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-04-06 12:07:33 +00:00
|
|
|
RNA_float_set(op->ptr, "frame", x);
|
|
|
|
RNA_float_set(op->ptr, "value", y);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-04-06 12:07:33 +00:00
|
|
|
/* Run exec now. */
|
|
|
|
return graphkeys_click_insert_exec(C, op);
|
|
|
|
}
|
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void GRAPH_OT_click_insert(wmOperatorType *ot)
|
2009-04-06 12:07:33 +00:00
|
|
|
{
|
|
|
|
/* Identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Click-Insert Keyframes";
|
|
|
|
ot->idname = "GRAPH_OT_click_insert";
|
|
|
|
ot->description = "Insert new keyframe at the cursor position for the active F-Curve";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-04-06 12:07:33 +00:00
|
|
|
/* API callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->invoke = graphkeys_click_insert_invoke;
|
|
|
|
ot->exec = graphkeys_click_insert_exec;
|
|
|
|
ot->poll = graphop_active_fcurve_poll;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-04-06 12:07:33 +00:00
|
|
|
/* Flags */
|
2012-05-08 20:18:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-04-06 12:07:33 +00:00
|
|
|
/* Properties */
|
|
|
|
RNA_def_float(ot->srna,
|
|
|
|
"frame",
|
|
|
|
1.0f,
|
|
|
|
-FLT_MAX,
|
|
|
|
FLT_MAX,
|
|
|
|
"Frame Number",
|
|
|
|
"Frame to insert keyframe on",
|
|
|
|
0,
|
|
|
|
100);
|
|
|
|
RNA_def_float(
|
|
|
|
ot->srna, "value", 1.0f, -FLT_MAX, FLT_MAX, "Value", "Value for keyframe on", 0, 100);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-05-09 16:58:12 +12:00
|
|
|
RNA_def_boolean(ot->srna,
|
|
|
|
"extend",
|
|
|
|
false,
|
|
|
|
"Extend",
|
|
|
|
"Extend selection instead of deselecting everything first");
|
2009-04-06 12:07:33 +00:00
|
|
|
}
|
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Copy/Paste Keyframes Operator
|
|
|
|
*
|
|
|
|
* \note the back-end code for this is shared with the dope-sheet editor.
|
|
|
|
* \{ */
|
2009-01-26 23:18:27 +00:00
|
|
|
|
2012-05-08 20:18:33 +00:00
|
|
|
static short copy_graph_keys(bAnimContext *ac)
|
2018-06-04 09:31:30 +02:00
|
|
|
{
|
2009-01-26 23:18:27 +00:00
|
|
|
ListBase anim_data = {NULL, NULL};
|
2012-05-08 20:18:33 +00:00
|
|
|
int filter, ok = 0;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Clear buffer first. */
|
2016-04-03 01:18:23 +13:00
|
|
|
ANIM_fcurves_copybuf_free();
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-05-01 19:17:59 +03:00
|
|
|
/* Filter data
|
|
|
|
* - First time we try to filter more strictly, allowing only selected channels
|
|
|
|
* to allow copying animation between channels.
|
|
|
|
*/
|
2012-05-08 20:18:33 +00:00
|
|
|
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS);
|
2019-05-01 19:17:59 +03:00
|
|
|
|
|
|
|
if (ANIM_animdata_filter(ac, &anim_data, filter | ANIMFILTER_SEL, ac->data, ac->datatype) == 0) {
|
|
|
|
ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-02-24 11:18:24 +00:00
|
|
|
/* Copy keyframes. */
|
2012-05-08 20:18:33 +00:00
|
|
|
ok = copy_animedit_keys(ac, &anim_data);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-02-24 11:18:24 +00:00
|
|
|
/* Clean up. */
|
2014-05-19 00:24:45 +10:00
|
|
|
ANIM_animdata_freelist(&anim_data);
|
2009-01-26 23:18:27 +00:00
|
|
|
|
2009-02-24 16:51:55 +00:00
|
|
|
return ok;
|
|
|
|
}
|
2009-02-24 11:18:24 +00:00
|
|
|
|
2012-05-08 20:18:33 +00:00
|
|
|
static short paste_graph_keys(bAnimContext *ac,
|
2015-01-07 22:25:33 +01:00
|
|
|
const eKeyPasteOffset offset_mode,
|
|
|
|
const eKeyMergeMode merge_mode,
|
|
|
|
bool flip)
|
2018-06-04 09:31:30 +02:00
|
|
|
{
|
2009-01-26 23:18:27 +00:00
|
|
|
ListBase anim_data = {NULL, NULL};
|
2012-05-08 20:18:33 +00:00
|
|
|
int filter, ok = 0;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
|
|
|
/* Filter data
|
|
|
|
* - First time we try to filter more strictly, allowing only selected channels
|
Tweaks for Pasting Keyframes in DopeSheet/Graph Editors
In response to [#31670], I've reviewed the way that the Paste Keyframes tool for
the DopeSheet and Graph Editors works. Previously, it required you to always
select the F-Curves to paste the keyframes into before allowing you to paste
keyframes. This was because it is quite difficult to infer which ID-block's set
of curves is intended if more than one ID-block has similar curves (e.g. a scene
with two materials, and both have their diffuse color animated). The underlying
assumption and intention of the feature here was that the copy+paste were only
being used by animators to copy animation between similar curves, to transfer
and offset animation across block boundaries.
However, it turns out that many people were by far more familiar with the
simpler copy/paste paradigm from everywhere else (i.e. instead of trying to use
duplicate to copy keyframes around within their respective F-Curves).
Furthermore, in most cases there is only going to be a single character being
animated at a time (vs multiple), which means that most of the time the matching
problem is much simpler.
Hence, the Paste now works as follows:
- If there are selected F-Curves, we limit the paste-matching to only consider
those in the selected F-Curves. This makes it possible to still explicitly
specify where to paste.
- In the more general case (no prior selections), pasting will try to match
anything relevant it finds.
TODO:
- Check on whether the strictest matching level needs adjustments to limit the
number of false positives
- Testing and feedback of the new behaviour needed <--- ANIMATORS! PLEASE TEST
2012-06-01 15:00:28 +00:00
|
|
|
* to allow copying animation between channels
|
|
|
|
* - Second time, we loosen things up if nothing was found the first time, allowing
|
2020-09-30 20:09:02 +10:00
|
|
|
* users to just paste keyframes back into the original curve again T31670.
|
Tweaks for Pasting Keyframes in DopeSheet/Graph Editors
In response to [#31670], I've reviewed the way that the Paste Keyframes tool for
the DopeSheet and Graph Editors works. Previously, it required you to always
select the F-Curves to paste the keyframes into before allowing you to paste
keyframes. This was because it is quite difficult to infer which ID-block's set
of curves is intended if more than one ID-block has similar curves (e.g. a scene
with two materials, and both have their diffuse color animated). The underlying
assumption and intention of the feature here was that the copy+paste were only
being used by animators to copy animation between similar curves, to transfer
and offset animation across block boundaries.
However, it turns out that many people were by far more familiar with the
simpler copy/paste paradigm from everywhere else (i.e. instead of trying to use
duplicate to copy keyframes around within their respective F-Curves).
Furthermore, in most cases there is only going to be a single character being
animated at a time (vs multiple), which means that most of the time the matching
problem is much simpler.
Hence, the Paste now works as follows:
- If there are selected F-Curves, we limit the paste-matching to only consider
those in the selected F-Curves. This makes it possible to still explicitly
specify where to paste.
- In the more general case (no prior selections), pasting will try to match
anything relevant it finds.
TODO:
- Check on whether the strictest matching level needs adjustments to limit the
number of false positives
- Testing and feedback of the new behaviour needed <--- ANIMATORS! PLEASE TEST
2012-06-01 15:00:28 +00:00
|
|
|
*/
|
|
|
|
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FOREDIT |
|
|
|
|
ANIMFILTER_NODUPLIS);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ANIM_animdata_filter(ac, &anim_data, filter | ANIMFILTER_SEL, ac->data, ac->datatype) == 0) {
|
Tweaks for Pasting Keyframes in DopeSheet/Graph Editors
In response to [#31670], I've reviewed the way that the Paste Keyframes tool for
the DopeSheet and Graph Editors works. Previously, it required you to always
select the F-Curves to paste the keyframes into before allowing you to paste
keyframes. This was because it is quite difficult to infer which ID-block's set
of curves is intended if more than one ID-block has similar curves (e.g. a scene
with two materials, and both have their diffuse color animated). The underlying
assumption and intention of the feature here was that the copy+paste were only
being used by animators to copy animation between similar curves, to transfer
and offset animation across block boundaries.
However, it turns out that many people were by far more familiar with the
simpler copy/paste paradigm from everywhere else (i.e. instead of trying to use
duplicate to copy keyframes around within their respective F-Curves).
Furthermore, in most cases there is only going to be a single character being
animated at a time (vs multiple), which means that most of the time the matching
problem is much simpler.
Hence, the Paste now works as follows:
- If there are selected F-Curves, we limit the paste-matching to only consider
those in the selected F-Curves. This makes it possible to still explicitly
specify where to paste.
- In the more general case (no prior selections), pasting will try to match
anything relevant it finds.
TODO:
- Check on whether the strictest matching level needs adjustments to limit the
number of false positives
- Testing and feedback of the new behaviour needed <--- ANIMATORS! PLEASE TEST
2012-06-01 15:00:28 +00:00
|
|
|
ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-02-24 11:18:24 +00:00
|
|
|
/* Paste keyframes. */
|
2015-01-07 22:25:33 +01:00
|
|
|
ok = paste_animedit_keys(ac, &anim_data, offset_mode, merge_mode, flip);
|
2014-05-19 00:24:45 +10:00
|
|
|
|
2009-02-24 11:18:24 +00:00
|
|
|
/* Clean up. */
|
2014-05-19 00:24:45 +10:00
|
|
|
ANIM_animdata_freelist(&anim_data);
|
2009-02-24 16:51:55 +00:00
|
|
|
|
|
|
|
return ok;
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------- */
|
|
|
|
|
|
|
|
static int graphkeys_copy_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
bAnimContext ac;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Get editor data. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
2009-01-26 23:18:27 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Copy keyframes. */
|
2012-10-21 05:46:41 +00:00
|
|
|
if (copy_graph_keys(&ac)) {
|
2009-02-24 11:23:04 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "No keyframes copied to keyframes copy/paste buffer");
|
|
|
|
return OPERATOR_CANCELLED;
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-07-10 10:48:25 +00:00
|
|
|
/* Just return - no operator needed here (no changes). */
|
2009-01-26 23:18:27 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void GRAPH_OT_copy(wmOperatorType *ot)
|
2009-01-26 23:18:27 +00:00
|
|
|
{
|
|
|
|
/* Identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Copy Keyframes";
|
|
|
|
ot->idname = "GRAPH_OT_copy";
|
|
|
|
ot->description = "Copy selected keyframes to the copy/paste buffer";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* API callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = graphkeys_copy_exec;
|
|
|
|
ot->poll = graphop_editable_keyframes_poll;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Flags */
|
2012-05-08 20:18:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int graphkeys_paste_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
bAnimContext ac;
|
2010-12-14 15:14:16 +00:00
|
|
|
|
2012-05-08 20:18:33 +00:00
|
|
|
const eKeyPasteOffset offset_mode = RNA_enum_get(op->ptr, "offset");
|
|
|
|
const eKeyMergeMode merge_mode = RNA_enum_get(op->ptr, "merge");
|
2015-01-07 22:25:33 +01:00
|
|
|
const bool flipped = RNA_boolean_get(op->ptr, "flipped");
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Get editor data. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
2009-01-26 23:18:27 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2011-10-27 01:55:10 +00:00
|
|
|
/* Ac.reports by default will be the global reports list, which won't show warnings. */
|
2012-05-08 20:18:33 +00:00
|
|
|
ac.reports = op->reports;
|
2010-12-09 11:49:38 +00:00
|
|
|
|
2011-10-27 01:55:10 +00:00
|
|
|
/* Paste keyframes - non-zero return means an error occurred while trying to paste. */
|
2015-01-07 22:25:33 +01:00
|
|
|
if (paste_graph_keys(&ac, offset_mode, merge_mode, flipped)) {
|
2009-02-24 11:23:04 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-07-10 10:48:25 +00:00
|
|
|
/* Set notifier that keyframes have changed. */
|
2012-05-08 20:18:33 +00:00
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void GRAPH_OT_paste(wmOperatorType *ot)
|
2009-01-26 23:18:27 +00:00
|
|
|
{
|
2015-01-07 22:25:33 +01:00
|
|
|
PropertyRNA *prop;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Paste Keyframes";
|
|
|
|
ot->idname = "GRAPH_OT_paste";
|
|
|
|
ot->description =
|
|
|
|
"Paste keyframes from copy/paste buffer for the selected channels, starting on the current "
|
|
|
|
"frame";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* API callbacks */
|
2020-10-10 18:19:55 +11:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
// ot->invoke = WM_operator_props_popup; /* better wait for graph redo panel */
|
|
|
|
ot->exec = graphkeys_paste_exec;
|
|
|
|
ot->poll = graphop_editable_keyframes_poll;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Flags */
|
2012-05-08 20:18:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Tweaks for Pasting Keyframes in DopeSheet/Graph Editors
In response to [#31670], I've reviewed the way that the Paste Keyframes tool for
the DopeSheet and Graph Editors works. Previously, it required you to always
select the F-Curves to paste the keyframes into before allowing you to paste
keyframes. This was because it is quite difficult to infer which ID-block's set
of curves is intended if more than one ID-block has similar curves (e.g. a scene
with two materials, and both have their diffuse color animated). The underlying
assumption and intention of the feature here was that the copy+paste were only
being used by animators to copy animation between similar curves, to transfer
and offset animation across block boundaries.
However, it turns out that many people were by far more familiar with the
simpler copy/paste paradigm from everywhere else (i.e. instead of trying to use
duplicate to copy keyframes around within their respective F-Curves).
Furthermore, in most cases there is only going to be a single character being
animated at a time (vs multiple), which means that most of the time the matching
problem is much simpler.
Hence, the Paste now works as follows:
- If there are selected F-Curves, we limit the paste-matching to only consider
those in the selected F-Curves. This makes it possible to still explicitly
specify where to paste.
- In the more general case (no prior selections), pasting will try to match
anything relevant it finds.
TODO:
- Check on whether the strictest matching level needs adjustments to limit the
number of false positives
- Testing and feedback of the new behaviour needed <--- ANIMATORS! PLEASE TEST
2012-06-01 15:00:28 +00:00
|
|
|
/* Props */
|
2015-11-23 13:49:52 +11:00
|
|
|
RNA_def_enum(ot->srna,
|
|
|
|
"offset",
|
|
|
|
rna_enum_keyframe_paste_offset_items,
|
|
|
|
KEYFRAME_PASTE_OFFSET_CFRA_START,
|
|
|
|
"Offset",
|
|
|
|
"Paste time offset of keys");
|
|
|
|
RNA_def_enum(ot->srna,
|
|
|
|
"merge",
|
|
|
|
rna_enum_keyframe_paste_merge_items,
|
|
|
|
KEYFRAME_PASTE_MERGE_MIX,
|
|
|
|
"Type",
|
|
|
|
"Method of merging pasted keys and existing");
|
2015-01-07 22:25:33 +01:00
|
|
|
prop = RNA_def_boolean(
|
|
|
|
ot->srna, "flipped", false, "Flipped", "Paste keyframes from mirrored bones if they exist");
|
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Duplicate Keyframes Operator
|
|
|
|
* \{ */
|
2009-02-20 11:17:33 +00:00
|
|
|
|
2012-05-08 20:18:33 +00:00
|
|
|
static void duplicate_graph_keys(bAnimContext *ac)
|
2009-02-20 11:17:33 +00:00
|
|
|
{
|
|
|
|
ListBase anim_data = {NULL, NULL};
|
|
|
|
bAnimListElem *ale;
|
|
|
|
int filter;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-02-20 11:17:33 +00:00
|
|
|
/* Filter data. */
|
2012-05-08 20:18:33 +00:00
|
|
|
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FOREDIT |
|
|
|
|
ANIMFILTER_NODUPLIS);
|
2009-02-20 11:17:33 +00:00
|
|
|
ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-02-20 11:17:33 +00:00
|
|
|
/* Loop through filtered data and delete selected keys. */
|
2012-05-08 20:18:33 +00:00
|
|
|
for (ale = anim_data.first; ale; ale = ale->next) {
|
2009-02-20 11:17:33 +00:00
|
|
|
duplicate_fcurve_keys((FCurve *)ale->key_data);
|
2014-05-19 00:24:45 +10:00
|
|
|
|
|
|
|
ale->update |= ANIM_UPDATE_DEFAULT;
|
2009-02-20 11:17:33 +00:00
|
|
|
}
|
2014-05-19 00:24:45 +10:00
|
|
|
|
|
|
|
ANIM_animdata_update(ac, &anim_data);
|
|
|
|
ANIM_animdata_freelist(&anim_data);
|
2009-02-20 11:17:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------- */
|
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
static int graphkeys_duplicate_exec(bContext *C, wmOperator *UNUSED(op))
|
2009-02-20 11:17:33 +00:00
|
|
|
{
|
|
|
|
bAnimContext ac;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-02-20 11:17:33 +00:00
|
|
|
/* Get editor data. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
2009-02-20 11:17:33 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-02-20 11:17:33 +00:00
|
|
|
/* Duplicate keyframes. */
|
|
|
|
duplicate_graph_keys(&ac);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-07-10 10:48:25 +00:00
|
|
|
/* Set notifier that keyframes have changed. */
|
2014-04-24 14:26:53 +12:00
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_ADDED, NULL);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-02-20 11:17:33 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void GRAPH_OT_duplicate(wmOperatorType *ot)
|
2009-02-20 11:17:33 +00:00
|
|
|
{
|
|
|
|
/* Identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Duplicate Keyframes";
|
|
|
|
ot->idname = "GRAPH_OT_duplicate";
|
|
|
|
ot->description = "Make a copy of all selected keyframes";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-02-20 11:17:33 +00:00
|
|
|
/* API callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = graphkeys_duplicate_exec;
|
|
|
|
ot->poll = graphop_editable_keyframes_poll;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-02-20 11:17:33 +00:00
|
|
|
/* Flags */
|
2012-05-08 20:18:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-02-20 11:17:33 +00:00
|
|
|
/* To give to transform. */
|
2015-11-23 13:49:52 +11:00
|
|
|
RNA_def_enum(ot->srna, "mode", rna_enum_transform_mode_types, TFM_TRANSLATION, "Mode", "");
|
2009-02-20 11:17:33 +00:00
|
|
|
}
|
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Delete Keyframes Operator
|
|
|
|
* \{ */
|
2009-01-26 23:18:27 +00:00
|
|
|
|
2013-11-25 04:55:26 +01:00
|
|
|
static bool delete_graph_keys(bAnimContext *ac)
|
2009-01-26 23:18:27 +00:00
|
|
|
{
|
|
|
|
ListBase anim_data = {NULL, NULL};
|
|
|
|
bAnimListElem *ale;
|
|
|
|
int filter;
|
2014-05-19 00:24:45 +10:00
|
|
|
bool changed_final = false;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Filter data. */
|
2012-05-08 20:18:33 +00:00
|
|
|
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FOREDIT |
|
|
|
|
ANIMFILTER_NODUPLIS);
|
2009-01-26 23:18:27 +00:00
|
|
|
ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Loop through filtered data and delete selected keys. */
|
2012-05-08 20:18:33 +00:00
|
|
|
for (ale = anim_data.first; ale; ale = ale->next) {
|
|
|
|
FCurve *fcu = (FCurve *)ale->key_data;
|
|
|
|
AnimData *adt = ale->adt;
|
2014-05-19 00:24:45 +10:00
|
|
|
bool changed;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-12-04 03:51:52 +00:00
|
|
|
/* Delete selected keyframes only. */
|
2014-05-19 00:24:45 +10:00
|
|
|
changed = delete_fcurve_keys(fcu);
|
|
|
|
|
|
|
|
if (changed) {
|
|
|
|
ale->update |= ANIM_UPDATE_DEFAULT;
|
|
|
|
changed_final = true;
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-12-04 03:51:52 +00:00
|
|
|
/* Only delete curve too if it won't be doing anything anymore. */
|
2019-05-16 09:47:57 +03:00
|
|
|
if (BKE_fcurve_is_empty(fcu)) {
|
2009-12-06 09:37:31 +00:00
|
|
|
ANIM_fcurve_delete_from_animdata(ac, adt, fcu);
|
2014-07-10 13:02:22 +02:00
|
|
|
ale->key_data = NULL;
|
2013-09-03 06:46:17 +00:00
|
|
|
}
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
2013-11-25 04:55:26 +01:00
|
|
|
|
2014-05-19 00:24:45 +10:00
|
|
|
ANIM_animdata_update(ac, &anim_data);
|
|
|
|
ANIM_animdata_freelist(&anim_data);
|
|
|
|
|
|
|
|
return changed_final;
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------- */
|
|
|
|
|
2013-12-20 01:38:07 +01:00
|
|
|
static int graphkeys_delete_exec(bContext *C, wmOperator *UNUSED(op))
|
2009-01-26 23:18:27 +00:00
|
|
|
{
|
|
|
|
bAnimContext ac;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Get editor data. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
2009-01-26 23:18:27 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Delete keyframes. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!delete_graph_keys(&ac)) {
|
2013-12-20 01:38:07 +01:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-07-10 10:48:25 +00:00
|
|
|
/* Set notifier that keyframes have changed. */
|
2014-04-24 14:26:53 +12:00
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_REMOVED, NULL);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void GRAPH_OT_delete(wmOperatorType *ot)
|
2009-01-26 23:18:27 +00:00
|
|
|
{
|
|
|
|
/* Identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Delete Keyframes";
|
|
|
|
ot->idname = "GRAPH_OT_delete";
|
|
|
|
ot->description = "Remove all selected keyframes";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* API callbacks */
|
2013-12-20 01:38:07 +01:00
|
|
|
ot->invoke = WM_operator_confirm;
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = graphkeys_delete_exec;
|
|
|
|
ot->poll = graphop_editable_keyframes_poll;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Flags */
|
2012-05-08 20:18:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Clean Keyframes Operator
|
|
|
|
* \{ */
|
2009-01-26 23:18:27 +00:00
|
|
|
|
2015-05-20 15:30:33 +02:00
|
|
|
static void clean_graph_keys(bAnimContext *ac, float thresh, bool clean_chan)
|
2018-06-04 09:31:30 +02:00
|
|
|
{
|
2009-01-26 23:18:27 +00:00
|
|
|
ListBase anim_data = {NULL, NULL};
|
|
|
|
bAnimListElem *ale;
|
|
|
|
int filter;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Filter data. */
|
2012-05-08 20:18:33 +00:00
|
|
|
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FOREDIT |
|
|
|
|
ANIMFILTER_SEL | ANIMFILTER_NODUPLIS);
|
2009-01-26 23:18:27 +00:00
|
|
|
ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Loop through filtered data and clean curves. */
|
2014-05-19 00:24:45 +10:00
|
|
|
for (ale = anim_data.first; ale; ale = ale->next) {
|
2015-05-20 15:30:33 +02:00
|
|
|
clean_fcurve(ac, ale, thresh, clean_chan);
|
2014-05-19 00:24:45 +10:00
|
|
|
|
|
|
|
ale->update |= ANIM_UPDATE_DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
ANIM_animdata_update(ac, &anim_data);
|
|
|
|
ANIM_animdata_freelist(&anim_data);
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------- */
|
|
|
|
|
|
|
|
static int graphkeys_clean_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
bAnimContext ac;
|
|
|
|
float thresh;
|
2015-05-20 15:30:33 +02:00
|
|
|
bool clean_chan;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Get editor data. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
2009-01-26 23:18:27 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Get cleaning threshold. */
|
2012-05-08 20:18:33 +00:00
|
|
|
thresh = RNA_float_get(op->ptr, "threshold");
|
2015-05-20 15:30:33 +02:00
|
|
|
clean_chan = RNA_boolean_get(op->ptr, "channels");
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Clean keyframes. */
|
2015-05-20 15:30:33 +02:00
|
|
|
clean_graph_keys(&ac, thresh, clean_chan);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-07-10 10:48:25 +00:00
|
|
|
/* Set notifier that keyframes have changed. */
|
2012-05-08 20:18:33 +00:00
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void GRAPH_OT_clean(wmOperatorType *ot)
|
2009-01-26 23:18:27 +00:00
|
|
|
{
|
|
|
|
/* Identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Clean Keyframes";
|
|
|
|
ot->idname = "GRAPH_OT_clean";
|
|
|
|
ot->description = "Simplify F-Curves by removing closely spaced keyframes";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* API callbacks */
|
2019-05-01 11:09:22 +10:00
|
|
|
// ot->invoke = ???; /* XXX we need that number popup for this! */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = graphkeys_clean_exec;
|
|
|
|
ot->poll = graphop_editable_keyframes_poll;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Flags */
|
2012-05-08 20:18:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Properties */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->prop = RNA_def_float(
|
|
|
|
ot->srna, "threshold", 0.001f, 0.0f, FLT_MAX, "Threshold", "", 0.0f, 1000.0f);
|
2015-05-20 15:30:33 +02:00
|
|
|
RNA_def_boolean(ot->srna, "channels", false, "Channels", "");
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Bake F-Curve Operator
|
|
|
|
*
|
|
|
|
* This operator bakes the data of the selected F-Curves to F-Points.
|
|
|
|
* \{ */
|
2009-03-01 11:27:31 +00:00
|
|
|
|
|
|
|
/* Bake each F-Curve into a set of samples. */
|
2012-05-08 20:18:33 +00:00
|
|
|
static void bake_graph_curves(bAnimContext *ac, int start, int end)
|
2018-06-04 09:31:30 +02:00
|
|
|
{
|
2009-03-01 11:27:31 +00:00
|
|
|
ListBase anim_data = {NULL, NULL};
|
|
|
|
bAnimListElem *ale;
|
|
|
|
int filter;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-03-01 11:27:31 +00:00
|
|
|
/* Filter data. */
|
2012-05-08 20:18:33 +00:00
|
|
|
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_SEL |
|
|
|
|
ANIMFILTER_FOREDIT | ANIMFILTER_NODUPLIS);
|
2009-03-01 11:27:31 +00:00
|
|
|
ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-03-01 11:27:31 +00:00
|
|
|
/* Loop through filtered data and add keys between selected keyframes on every frame. */
|
2012-05-08 20:18:33 +00:00
|
|
|
for (ale = anim_data.first; ale; ale = ale->next) {
|
|
|
|
FCurve *fcu = (FCurve *)ale->key_data;
|
|
|
|
ChannelDriver *driver = fcu->driver;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-03-01 11:27:31 +00:00
|
|
|
/* Disable driver so that it don't muck up the sampling process. */
|
2012-05-08 20:18:33 +00:00
|
|
|
fcu->driver = NULL;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-03-01 11:27:31 +00:00
|
|
|
/* Create samples. */
|
|
|
|
fcurve_store_samples(fcu, NULL, start, end, fcurve_samplingcb_evalcurve);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-03-01 11:27:31 +00:00
|
|
|
/* Restore driver. */
|
2012-05-08 20:18:33 +00:00
|
|
|
fcu->driver = driver;
|
2014-05-19 00:24:45 +10:00
|
|
|
|
|
|
|
ale->update |= ANIM_UPDATE_DEPS;
|
2009-03-01 11:27:31 +00:00
|
|
|
}
|
2014-05-19 00:24:45 +10:00
|
|
|
|
|
|
|
ANIM_animdata_update(ac, &anim_data);
|
|
|
|
ANIM_animdata_freelist(&anim_data);
|
2009-03-01 11:27:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------- */
|
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
static int graphkeys_bake_exec(bContext *C, wmOperator *UNUSED(op))
|
2009-03-01 11:27:31 +00:00
|
|
|
{
|
|
|
|
bAnimContext ac;
|
2012-05-08 20:18:33 +00:00
|
|
|
Scene *scene = NULL;
|
2009-03-01 11:27:31 +00:00
|
|
|
int start, end;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-03-01 11:27:31 +00:00
|
|
|
/* Get editor data. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
2009-03-01 11:27:31 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-03-01 11:27:31 +00:00
|
|
|
/* For now, init start/end from preview-range extents. */
|
2018-06-04 09:31:30 +02:00
|
|
|
/* TODO: add properties for this. (Joshua Leung 2009) */
|
2012-05-08 20:18:33 +00:00
|
|
|
scene = ac.scene;
|
|
|
|
start = PSFRA;
|
|
|
|
end = PEFRA;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-03-01 11:27:31 +00:00
|
|
|
/* Bake keyframes. */
|
|
|
|
bake_graph_curves(&ac, start, end);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-07-10 10:48:25 +00:00
|
|
|
/* Set notifier that keyframes have changed. */
|
|
|
|
/* NOTE: some distinction between order/number of keyframes and type should be made? */
|
2012-05-08 20:18:33 +00:00
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-03-01 11:27:31 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void GRAPH_OT_bake(wmOperatorType *ot)
|
2009-03-01 11:27:31 +00:00
|
|
|
{
|
|
|
|
/* Identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Bake Curve";
|
|
|
|
ot->idname = "GRAPH_OT_bake";
|
|
|
|
ot->description = "Bake selected F-Curves to a set of sampled points defining a similar curve";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-03-01 11:27:31 +00:00
|
|
|
/* API callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->invoke = WM_operator_confirm; /* FIXME */
|
|
|
|
ot->exec = graphkeys_bake_exec;
|
2018-06-04 09:31:30 +02:00
|
|
|
ot->poll = graphop_selected_fcurve_poll;
|
|
|
|
|
2009-03-01 11:27:31 +00:00
|
|
|
/* Flags */
|
2012-05-08 20:18:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-03-01 11:27:31 +00:00
|
|
|
/* TODO: add props for start/end frames (Joshua Leung 2009) */
|
|
|
|
}
|
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Un-Bake F-Curve Operator
|
|
|
|
*
|
|
|
|
* This operator un-bakes the data of the selected F-Points to F-Curves.
|
|
|
|
* \{ */
|
2020-10-28 11:45:24 +01:00
|
|
|
|
|
|
|
/* Un-Bake F-Points into F-Curves. */
|
|
|
|
static void unbake_graph_curves(bAnimContext *ac, int start, int end)
|
|
|
|
{
|
|
|
|
ListBase anim_data = {NULL, NULL};
|
|
|
|
bAnimListElem *ale;
|
|
|
|
|
|
|
|
/* Filter data. */
|
|
|
|
const int filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_SEL |
|
|
|
|
ANIMFILTER_FOREDIT | ANIMFILTER_NODUPLIS);
|
|
|
|
ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
|
|
|
|
|
|
|
|
/* Loop through filtered data and add keys between selected keyframes on every frame. */
|
|
|
|
for (ale = anim_data.first; ale; ale = ale->next) {
|
|
|
|
FCurve *fcu = (FCurve *)ale->key_data;
|
|
|
|
|
|
|
|
fcurve_samples_to_keyframes(fcu, start, end);
|
|
|
|
|
|
|
|
ale->update |= ANIM_UPDATE_DEPS;
|
|
|
|
}
|
|
|
|
|
|
|
|
ANIM_animdata_update(ac, &anim_data);
|
|
|
|
ANIM_animdata_freelist(&anim_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------- */
|
|
|
|
|
|
|
|
static int graphkeys_unbake_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
bAnimContext ac;
|
|
|
|
Scene *scene = NULL;
|
|
|
|
int start, end;
|
|
|
|
|
|
|
|
/* Get editor data. */
|
|
|
|
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
scene = ac.scene;
|
|
|
|
start = PSFRA;
|
|
|
|
end = PEFRA;
|
|
|
|
|
|
|
|
/* Unbake keyframes. */
|
|
|
|
unbake_graph_curves(&ac, start, end);
|
|
|
|
|
|
|
|
/* Set notifier that keyframes have changed. */
|
|
|
|
/* NOTE: some distinction between order/number of keyframes and type should be made? */
|
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GRAPH_OT_unbake(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* Identifiers */
|
|
|
|
ot->name = "Un-Bake Curve";
|
|
|
|
ot->idname = "GRAPH_OT_unbake";
|
|
|
|
ot->description = "Un-Bake selected F-Points to F-Curves";
|
|
|
|
|
|
|
|
/* API callbacks */
|
|
|
|
ot->exec = graphkeys_unbake_exec;
|
|
|
|
ot->poll = graphop_selected_fcurve_poll;
|
|
|
|
|
|
|
|
/* Flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
}
|
|
|
|
|
2012-01-09 22:18:04 +00:00
|
|
|
#ifdef WITH_AUDASPACE
|
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Sound Bake F-Curve Operator
|
|
|
|
*
|
|
|
|
* This operator bakes the given sound to the selected F-Curves.
|
|
|
|
* \{ */
|
2010-01-01 05:09:30 +00:00
|
|
|
|
|
|
|
/* ------------------- */
|
|
|
|
|
|
|
|
/* Custom data storage passed to the F-Sample-ing function,
|
|
|
|
* which provides the necessary info for baking the sound.
|
|
|
|
*/
|
|
|
|
typedef struct tSoundBakeInfo {
|
2010-01-26 03:16:14 +00:00
|
|
|
float *samples;
|
2010-01-01 05:09:30 +00:00
|
|
|
int length;
|
|
|
|
int cfra;
|
|
|
|
} tSoundBakeInfo;
|
|
|
|
|
|
|
|
/* ------------------- */
|
|
|
|
|
|
|
|
/* Sampling callback used to determine the value from the sound to
|
|
|
|
* save in the F-Curve at the specified frame.
|
|
|
|
*/
|
2012-05-08 20:18:33 +00:00
|
|
|
static float fcurve_samplingcb_sound(FCurve *UNUSED(fcu), void *data, float evaltime)
|
2010-01-01 05:09:30 +00:00
|
|
|
{
|
2012-05-08 20:18:33 +00:00
|
|
|
tSoundBakeInfo *sbi = (tSoundBakeInfo *)data;
|
2010-01-01 05:09:30 +00:00
|
|
|
|
|
|
|
int position = evaltime - sbi->cfra;
|
2019-04-22 09:19:45 +10:00
|
|
|
if ((position < 0) || (position >= sbi->length)) {
|
2010-01-01 05:09:30 +00:00
|
|
|
return 0.0f;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2010-01-01 05:09:30 +00:00
|
|
|
|
|
|
|
return sbi->samples[position];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------- */
|
|
|
|
|
|
|
|
static int graphkeys_sound_bake_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
bAnimContext ac;
|
|
|
|
ListBase anim_data = {NULL, NULL};
|
|
|
|
bAnimListElem *ale;
|
|
|
|
int filter;
|
|
|
|
|
|
|
|
tSoundBakeInfo sbi;
|
2012-05-08 20:18:33 +00:00
|
|
|
Scene *scene = NULL;
|
2010-01-01 05:09:30 +00:00
|
|
|
int start, end;
|
|
|
|
|
|
|
|
char path[FILE_MAX];
|
|
|
|
|
|
|
|
/* Get editor data. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
2010-01-01 05:09:30 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2010-01-01 05:09:30 +00:00
|
|
|
|
2010-06-14 03:52:10 +00:00
|
|
|
RNA_string_get(op->ptr, "filepath", path);
|
2010-01-01 05:09:30 +00:00
|
|
|
|
2015-05-25 22:12:18 +10:00
|
|
|
if (!BLI_is_file(path)) {
|
|
|
|
BKE_reportf(op->reports, RPT_ERROR, "File not found '%s'", path);
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
2012-05-08 20:18:33 +00:00
|
|
|
scene = ac.scene; /* Current scene. */
|
2010-01-01 05:09:30 +00:00
|
|
|
|
|
|
|
/* Store necessary data for the baking steps. */
|
|
|
|
sbi.samples = AUD_readSoundBuffer(path,
|
2012-05-08 20:18:33 +00:00
|
|
|
RNA_float_get(op->ptr, "low"),
|
|
|
|
RNA_float_get(op->ptr, "high"),
|
|
|
|
RNA_float_get(op->ptr, "attack"),
|
|
|
|
RNA_float_get(op->ptr, "release"),
|
|
|
|
RNA_float_get(op->ptr, "threshold"),
|
2012-10-26 17:29:21 +00:00
|
|
|
RNA_boolean_get(op->ptr, "use_accumulate"),
|
2012-05-08 20:18:33 +00:00
|
|
|
RNA_boolean_get(op->ptr, "use_additive"),
|
2012-10-26 17:29:21 +00:00
|
|
|
RNA_boolean_get(op->ptr, "use_square"),
|
2012-05-08 20:18:33 +00:00
|
|
|
RNA_float_get(op->ptr, "sthreshold"),
|
|
|
|
FPS,
|
|
|
|
&sbi.length);
|
2010-01-01 05:09:30 +00:00
|
|
|
|
|
|
|
if (sbi.samples == NULL) {
|
|
|
|
BKE_report(op->reports, RPT_ERROR, "Unsupported audio format");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine extents of the baking. */
|
|
|
|
sbi.cfra = start = CFRA;
|
|
|
|
end = CFRA + sbi.length - 1;
|
|
|
|
|
|
|
|
/* Filter anim channels. */
|
2012-05-08 20:18:33 +00:00
|
|
|
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_SEL |
|
|
|
|
ANIMFILTER_FOREDIT | ANIMFILTER_NODUPLIS);
|
2010-01-01 05:09:30 +00:00
|
|
|
ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
|
|
|
|
|
|
|
|
/* Loop through all selected F-Curves, replacing its data with the sound samples. */
|
2012-05-08 20:18:33 +00:00
|
|
|
for (ale = anim_data.first; ale; ale = ale->next) {
|
|
|
|
FCurve *fcu = (FCurve *)ale->key_data;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-01-01 05:09:30 +00:00
|
|
|
/* Sample the sound. */
|
|
|
|
fcurve_store_samples(fcu, &sbi, start, end, fcurve_samplingcb_sound);
|
2014-05-19 00:24:45 +10:00
|
|
|
|
|
|
|
ale->update |= ANIM_UPDATE_DEFAULT;
|
2010-01-01 05:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Free sample data. */
|
|
|
|
free(sbi.samples);
|
|
|
|
|
|
|
|
/* Validate keyframes after editing. */
|
2014-05-19 00:24:45 +10:00
|
|
|
ANIM_animdata_update(&ac, &anim_data);
|
|
|
|
ANIM_animdata_freelist(&anim_data);
|
2010-01-01 05:09:30 +00:00
|
|
|
|
|
|
|
/* Set notifier that 'keyframes' have changed. */
|
2012-05-08 20:18:33 +00:00
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
|
2010-01-01 05:09:30 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:09:22 +10:00
|
|
|
#else /* WITH_AUDASPACE */
|
2011-06-23 09:27:56 +00:00
|
|
|
|
|
|
|
static int graphkeys_sound_bake_exec(bContext *UNUSED(C), wmOperator *op)
|
|
|
|
{
|
|
|
|
BKE_report(op->reports, RPT_ERROR, "Compiled without sound support");
|
|
|
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:09:22 +10:00
|
|
|
#endif /* WITH_AUDASPACE */
|
2011-06-23 09:27:56 +00:00
|
|
|
|
2013-03-13 09:03:46 +00:00
|
|
|
static int graphkeys_sound_bake_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
2010-01-01 05:09:30 +00:00
|
|
|
{
|
|
|
|
bAnimContext ac;
|
|
|
|
|
|
|
|
/* Verify editor data. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
2010-01-01 05:09:30 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2010-01-01 05:09:30 +00:00
|
|
|
|
|
|
|
return WM_operator_filesel(C, op, event);
|
|
|
|
}
|
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void GRAPH_OT_sound_bake(wmOperatorType *ot)
|
2010-01-01 05:09:30 +00:00
|
|
|
{
|
|
|
|
/* Identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Bake Sound to F-Curves";
|
|
|
|
ot->idname = "GRAPH_OT_sound_bake";
|
|
|
|
ot->description = "Bakes a sound wave to selected F-Curves";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-01-01 05:09:30 +00:00
|
|
|
/* API callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->invoke = graphkeys_sound_bake_invoke;
|
|
|
|
ot->exec = graphkeys_sound_bake_exec;
|
|
|
|
ot->poll = graphop_selected_fcurve_poll;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-01-01 05:09:30 +00:00
|
|
|
/* Flags */
|
2012-05-08 20:18:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-01-01 05:09:30 +00:00
|
|
|
/* Properties */
|
2016-02-07 22:56:20 +11:00
|
|
|
WM_operator_properties_filesel(ot,
|
|
|
|
FILE_TYPE_FOLDER | FILE_TYPE_SOUND | FILE_TYPE_MOVIE,
|
|
|
|
FILE_SPECIAL,
|
|
|
|
FILE_OPENFILE,
|
UI: File Browser Design Overhaul
This is a general redesign of the File Browser GUI and interaction
methods. For screenshots, check patch D5601.
Main changes in short:
* File Browser as floating window
* New layout of regions
* Popovers for view and filter options
* Vertical list view with interactive column header
* New and updated icons
* Keymap consistency fixes
* Many tweaks and fixes to the drawing of views
----
General:
* The file browser now opens as temporary floating window. It closes on
Esc. The header is hidden then.
* When the file browser is opened as regular editor, the header remains
visible.
* All file browser regions are now defined in Python (the button
layout).
* Adjusted related operator UI names.
Keymap:
Keymap is now consistent with other list-based views in Blender, such as
the Outliner.
* Left click to select, double-click to open
* Right-click context menus
* Shift-click to fill selection
* Ctrl-click to extend selection
Operator options:
These previously overlapped with the source list, which caused numerous
issues with resizing and presenting many settings in a small panel area.
It was also generally inconsistent with Blender.
* Moved to new sidebar, which can easily be shown or hidden using a
prominent Options toggle.
* IO operators have new layouts to match this new sidebar, using
sub-panels. This will have to be committed separately (Add-on
repository).
* If operators want to show the options by default, they have the option
to do so (see `WM_FILESEL_SHOW_PROPS`, `hide_props_region`), otherwise
they are hidden by default.
General Layout:
The layout has been changed to be simpler, more standard, and fits
better in with Blender 2.8.
* More conventional layout (file path at top, file name at the bottom,
execute/cancel buttons in bottom right).
* Use of popovers to group controls, and allow for more descriptive
naming.
* Search box is always live now, just like Outliner.
Views:
* Date Modified column combines both date and time, also uses user
friendly strings for recent dates (i.e. "Yesterday", "Today").
* Details columns (file size, modification date/time) are now toggleable
for all display types, they are not hardcoded per display type.
* File sizes now show as B, KB, MB, ... rather than B, KiB, MiB, … They
are now also calculated using base 10 of course.
* Option to sort in inverse order.
Vertical List View:
* This view now used a much simpler single vertical list with columns
for information.
* Users can click on the headers of these columns to order by that
category, and click again to reverse the ordering.
Icons:
* Updated icons by Jendrzych, with better centering.
* Files and folders have new icons in Icon view.
* Both files and folders have reworked superimposed icons that show
users the file/folder type.
* 3D file documents correctly use the 3d file icon, which was unused
previously.
* Workspaces now show their icon on Link/Append - also when listed in
the Outliner.
Minor Python-API breakage:
* `bpy.types.FileSelectParams.display_type`: `LIST_SHORT` and
`LIST_LONG` are replaced by `LIST_VERTICAL` and `LIST_HORIZONTAL`.
Removes the feature where directories would automatically be created if
they are entered into the file path text button, but don't exist. We
were not sure if users use it enough to keep it. We can definitely bring
it back.
----
//Combined effort by @billreynish, @harley, @jendrzych, my university
colleague Brian Meisenheimer and myself.//
Differential Revision: https://developer.blender.org/D5601
Reviewers: Brecht, Bastien
2019-09-03 15:43:38 +02:00
|
|
|
WM_FILESEL_FILEPATH | WM_FILESEL_SHOW_PROPS,
|
2016-02-07 22:56:20 +11:00
|
|
|
FILE_DEFAULTDISPLAY,
|
2020-11-02 23:55:59 +01:00
|
|
|
FILE_SORT_DEFAULT);
|
2012-10-26 17:29:21 +00:00
|
|
|
RNA_def_float(ot->srna,
|
|
|
|
"low",
|
|
|
|
0.0f,
|
|
|
|
0.0,
|
|
|
|
100000.0,
|
2020-12-24 11:07:32 -06:00
|
|
|
"Lowest Frequency",
|
2012-10-26 17:29:21 +00:00
|
|
|
"Cutoff frequency of a high-pass filter that is applied to the audio data",
|
|
|
|
0.1,
|
|
|
|
1000.00);
|
|
|
|
RNA_def_float(ot->srna,
|
|
|
|
"high",
|
|
|
|
100000.0,
|
|
|
|
0.0,
|
|
|
|
100000.0,
|
2020-12-24 11:07:32 -06:00
|
|
|
"Highest Frequency",
|
2012-10-26 17:29:21 +00:00
|
|
|
"Cutoff frequency of a low-pass filter that is applied to the audio data",
|
|
|
|
0.1,
|
|
|
|
1000.00);
|
|
|
|
RNA_def_float(ot->srna,
|
|
|
|
"attack",
|
|
|
|
0.005,
|
|
|
|
0.0,
|
|
|
|
2.0,
|
2020-12-24 11:07:32 -06:00
|
|
|
"Attack Time",
|
2012-10-26 17:29:21 +00:00
|
|
|
"Value for the hull curve calculation that tells how fast the hull curve can rise "
|
|
|
|
"(the lower the value the steeper it can rise)",
|
|
|
|
0.01,
|
|
|
|
0.1);
|
|
|
|
RNA_def_float(ot->srna,
|
|
|
|
"release",
|
|
|
|
0.2,
|
|
|
|
0.0,
|
|
|
|
5.0,
|
2020-12-24 11:07:32 -06:00
|
|
|
"Release Time",
|
2012-10-26 17:29:21 +00:00
|
|
|
"Value for the hull curve calculation that tells how fast the hull curve can fall "
|
|
|
|
"(the lower the value the steeper it can fall)",
|
|
|
|
0.01,
|
|
|
|
0.2);
|
|
|
|
RNA_def_float(ot->srna,
|
|
|
|
"threshold",
|
|
|
|
0.0,
|
|
|
|
0.0,
|
|
|
|
1.0,
|
|
|
|
"Threshold",
|
|
|
|
"Minimum amplitude value needed to influence the hull curve",
|
|
|
|
0.01,
|
|
|
|
0.1);
|
|
|
|
RNA_def_boolean(ot->srna,
|
|
|
|
"use_accumulate",
|
|
|
|
0,
|
|
|
|
"Accumulate",
|
|
|
|
"Only the positive differences of the hull curve amplitudes are summarized to "
|
|
|
|
"produce the output");
|
|
|
|
RNA_def_boolean(
|
|
|
|
ot->srna,
|
|
|
|
"use_additive",
|
|
|
|
0,
|
|
|
|
"Additive",
|
|
|
|
"The amplitudes of the hull curve are summarized (or, when Accumulate is enabled, "
|
|
|
|
"both positive and negative differences are accumulated)");
|
|
|
|
RNA_def_boolean(ot->srna,
|
|
|
|
"use_square",
|
|
|
|
0,
|
|
|
|
"Square",
|
|
|
|
"The output is a square curve (negative values always result in -1, and "
|
|
|
|
"positive ones in 1)");
|
|
|
|
RNA_def_float(ot->srna,
|
|
|
|
"sthreshold",
|
|
|
|
0.1,
|
|
|
|
0.0,
|
|
|
|
1.0,
|
|
|
|
"Square Threshold",
|
|
|
|
"Square only: all values with an absolute amplitude lower than that result in 0",
|
|
|
|
0.01,
|
|
|
|
0.1);
|
2010-01-01 05:09:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Sample Keyframes Operator
|
|
|
|
*
|
|
|
|
* This operator 'bakes' the values of the curve into new keyframes between pairs
|
2009-03-01 11:27:31 +00:00
|
|
|
* of selected keyframes. It is useful for creating keyframes for tweaking overlap.
|
2020-12-09 14:34:40 +11:00
|
|
|
* \{ */
|
2009-01-26 23:18:27 +00:00
|
|
|
|
|
|
|
/* Evaluates the curves between each selected keyframe on each frame, and keys the value. */
|
2012-05-08 20:18:33 +00:00
|
|
|
static void sample_graph_keys(bAnimContext *ac)
|
2018-06-04 09:31:30 +02:00
|
|
|
{
|
2009-01-26 23:18:27 +00:00
|
|
|
ListBase anim_data = {NULL, NULL};
|
|
|
|
bAnimListElem *ale;
|
|
|
|
int filter;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* filter data */
|
2012-05-08 20:18:33 +00:00
|
|
|
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FOREDIT |
|
|
|
|
ANIMFILTER_NODUPLIS);
|
2009-01-26 23:18:27 +00:00
|
|
|
ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Loop through filtered data and add keys between selected keyframes on every frame. */
|
2014-05-19 00:24:45 +10:00
|
|
|
for (ale = anim_data.first; ale; ale = ale->next) {
|
2009-09-04 04:27:06 +00:00
|
|
|
sample_fcurve((FCurve *)ale->key_data);
|
2014-05-19 00:24:45 +10:00
|
|
|
|
|
|
|
ale->update |= ANIM_UPDATE_DEPS;
|
|
|
|
}
|
|
|
|
|
|
|
|
ANIM_animdata_update(ac, &anim_data);
|
|
|
|
ANIM_animdata_freelist(&anim_data);
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------- */
|
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
static int graphkeys_sample_exec(bContext *C, wmOperator *UNUSED(op))
|
2009-01-26 23:18:27 +00:00
|
|
|
{
|
|
|
|
bAnimContext ac;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Get editor data. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
2009-01-26 23:18:27 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Sample keyframes. */
|
|
|
|
sample_graph_keys(&ac);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-07-10 10:48:25 +00:00
|
|
|
/* Set notifier that keyframes have changed. */
|
2012-05-08 20:18:33 +00:00
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void GRAPH_OT_sample(wmOperatorType *ot)
|
2009-01-26 23:18:27 +00:00
|
|
|
{
|
|
|
|
/* Identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Sample Keyframes";
|
|
|
|
ot->idname = "GRAPH_OT_sample";
|
|
|
|
ot->description = "Add keyframes on every frame between the selected keyframes";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* API callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = graphkeys_sample_exec;
|
|
|
|
ot->poll = graphop_editable_keyframes_poll;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Flags */
|
2012-05-08 20:18:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/** \} */
|
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* ************************************************************************** */
|
2020-11-23 15:11:51 +01:00
|
|
|
/* EXTRAPOLATION MODE AND KEYFRAME HANDLE SETTINGS */
|
2009-01-26 23:18:27 +00:00
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Set Extrapolation-Type Operator
|
|
|
|
* \{ */
|
2009-01-26 23:18:27 +00:00
|
|
|
|
2011-07-07 13:59:28 +00:00
|
|
|
/* Defines for make/clear cyclic extrapolation tools. */
|
2012-05-08 20:18:33 +00:00
|
|
|
#define MAKE_CYCLIC_EXPO -1
|
|
|
|
#define CLEAR_CYCLIC_EXPO -2
|
2011-07-07 13:59:28 +00:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Defines for set extrapolation-type for selected keyframes tool. */
|
2017-10-18 15:07:26 +11:00
|
|
|
static const EnumPropertyItem prop_graphkeys_expo_types[] = {
|
2012-10-15 04:17:29 +00:00
|
|
|
{FCURVE_EXTRAPOLATE_CONSTANT,
|
|
|
|
"CONSTANT",
|
|
|
|
0,
|
|
|
|
"Constant Extrapolation",
|
|
|
|
"Values on endpoint keyframes are held"},
|
|
|
|
{FCURVE_EXTRAPOLATE_LINEAR,
|
|
|
|
"LINEAR",
|
|
|
|
0,
|
|
|
|
"Linear Extrapolation",
|
|
|
|
"Straight-line slope of end segments are extended past the endpoint keyframes"},
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-07-07 13:59:28 +00:00
|
|
|
{MAKE_CYCLIC_EXPO,
|
|
|
|
"MAKE_CYCLIC",
|
|
|
|
0,
|
|
|
|
"Make Cyclic (F-Modifier)",
|
|
|
|
"Add Cycles F-Modifier if one doesn't exist already"},
|
|
|
|
{CLEAR_CYCLIC_EXPO,
|
|
|
|
"CLEAR_CYCLIC",
|
|
|
|
0,
|
|
|
|
"Clear Cyclic (F-Modifier)",
|
|
|
|
"Remove Cycles F-Modifier if not needed anymore"},
|
2019-02-03 14:01:45 +11:00
|
|
|
{0, NULL, 0, NULL, NULL},
|
2009-01-26 23:18:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* This function is responsible for setting extrapolation mode for keyframes. */
|
2018-06-04 09:31:30 +02:00
|
|
|
static void setexpo_graph_keys(bAnimContext *ac, short mode)
|
2009-01-26 23:18:27 +00:00
|
|
|
{
|
|
|
|
ListBase anim_data = {NULL, NULL};
|
|
|
|
bAnimListElem *ale;
|
|
|
|
int filter;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Filter data. */
|
2012-05-08 20:18:33 +00:00
|
|
|
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_SEL |
|
|
|
|
ANIMFILTER_FOREDIT | ANIMFILTER_NODUPLIS);
|
2009-01-26 23:18:27 +00:00
|
|
|
ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Loop through setting mode per F-Curve. */
|
2012-05-08 20:18:33 +00:00
|
|
|
for (ale = anim_data.first; ale; ale = ale->next) {
|
|
|
|
FCurve *fcu = (FCurve *)ale->data;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-07-07 13:59:28 +00:00
|
|
|
if (mode >= 0) {
|
|
|
|
/* Just set mode setting. */
|
2012-05-08 20:18:33 +00:00
|
|
|
fcu->extend = mode;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-28 12:24:47 +10:00
|
|
|
ale->update |= ANIM_UPDATE_HANDLES;
|
2011-07-07 13:59:28 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-06-04 09:31:30 +02:00
|
|
|
/* Shortcuts for managing Cycles F-Modifiers to make it easier to toggle cyclic animation
|
2011-07-07 13:59:28 +00:00
|
|
|
* without having to go through FModifier UI in Graph Editor to do so.
|
|
|
|
*/
|
|
|
|
if (mode == MAKE_CYCLIC_EXPO) {
|
|
|
|
/* Only add if one doesn't exist. */
|
|
|
|
if (list_has_suitable_fmodifier(&fcu->modifiers, FMODIFIER_TYPE_CYCLES, -1) == 0) {
|
|
|
|
/* TODO: add some more preset versions which set different extrapolation options?
|
|
|
|
* (Joshua Leung 2011) */
|
2017-10-17 19:39:10 +03:00
|
|
|
add_fmodifier(&fcu->modifiers, FMODIFIER_TYPE_CYCLES, fcu);
|
2011-07-07 13:59:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mode == CLEAR_CYCLIC_EXPO) {
|
|
|
|
/* Remove all the modifiers fitting this description. */
|
2012-05-08 20:18:33 +00:00
|
|
|
FModifier *fcm, *fcn = NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-07-07 13:59:28 +00:00
|
|
|
for (fcm = fcu->modifiers.first; fcm; fcm = fcn) {
|
|
|
|
fcn = fcm->next;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (fcm->type == FMODIFIER_TYPE_CYCLES) {
|
2011-07-07 13:59:28 +00:00
|
|
|
remove_fmodifier(&fcu->modifiers, fcm);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2011-07-07 13:59:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-19 00:24:45 +10:00
|
|
|
ale->update |= ANIM_UPDATE_DEPS;
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-19 00:24:45 +10:00
|
|
|
ANIM_animdata_update(ac, &anim_data);
|
|
|
|
ANIM_animdata_freelist(&anim_data);
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------- */
|
|
|
|
|
|
|
|
static int graphkeys_expo_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
bAnimContext ac;
|
|
|
|
short mode;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Get editor data. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
2009-01-26 23:18:27 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Get handle setting mode. */
|
2012-05-08 20:18:33 +00:00
|
|
|
mode = RNA_enum_get(op->ptr, "type");
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Set handle type. */
|
|
|
|
setexpo_graph_keys(&ac, mode);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-07-10 10:48:25 +00:00
|
|
|
/* Set notifier that keyframe properties have changed. */
|
2012-05-08 20:18:33 +00:00
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME_PROP, NULL);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void GRAPH_OT_extrapolation_type(wmOperatorType *ot)
|
2009-01-26 23:18:27 +00:00
|
|
|
{
|
|
|
|
/* Identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Set Keyframe Extrapolation";
|
|
|
|
ot->idname = "GRAPH_OT_extrapolation_type";
|
|
|
|
ot->description = "Set extrapolation mode for selected F-Curves";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* API callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->invoke = WM_menu_invoke;
|
|
|
|
ot->exec = graphkeys_expo_exec;
|
|
|
|
ot->poll = graphop_editable_keyframes_poll;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Flags */
|
2012-05-08 20:18:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Id-props */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->prop = RNA_def_enum(ot->srna, "type", prop_graphkeys_expo_types, 0, "Type", "");
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Set Interpolation-Type Operator
|
|
|
|
* \{ */
|
2009-01-26 23:18:27 +00:00
|
|
|
|
|
|
|
/* This function is responsible for setting interpolation mode for keyframes. */
|
2018-06-04 09:31:30 +02:00
|
|
|
static void setipo_graph_keys(bAnimContext *ac, short mode)
|
2009-01-26 23:18:27 +00:00
|
|
|
{
|
|
|
|
ListBase anim_data = {NULL, NULL};
|
|
|
|
bAnimListElem *ale;
|
|
|
|
int filter;
|
2012-05-08 20:18:33 +00:00
|
|
|
KeyframeEditFunc set_cb = ANIM_editkeyframes_ipo(mode);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Filter data. */
|
2012-05-08 20:18:33 +00:00
|
|
|
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FOREDIT |
|
|
|
|
ANIMFILTER_NODUPLIS);
|
2009-01-26 23:18:27 +00:00
|
|
|
ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-22 00:18:34 +10:00
|
|
|
/* Loop through setting BezTriple interpolation
|
|
|
|
* Note: we do not supply KeyframeEditData to the looper yet.
|
|
|
|
* Currently that's not necessary here.
|
2009-01-26 23:18:27 +00:00
|
|
|
*/
|
2014-05-19 00:24:45 +10:00
|
|
|
for (ale = anim_data.first; ale; ale = ale->next) {
|
2010-04-02 12:02:39 +00:00
|
|
|
ANIM_fcurve_keyframes_loop(NULL, ale->key_data, NULL, set_cb, calchandles_fcurve);
|
2014-05-19 00:24:45 +10:00
|
|
|
|
|
|
|
ale->update |= ANIM_UPDATE_DEFAULT_NOHANDLES;
|
|
|
|
}
|
|
|
|
|
|
|
|
ANIM_animdata_update(ac, &anim_data);
|
|
|
|
ANIM_animdata_freelist(&anim_data);
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------- */
|
|
|
|
|
|
|
|
static int graphkeys_ipo_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
bAnimContext ac;
|
|
|
|
short mode;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Get editor data. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
2009-01-26 23:18:27 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Get handle setting mode. */
|
2012-05-08 20:18:33 +00:00
|
|
|
mode = RNA_enum_get(op->ptr, "type");
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Set handle type. */
|
|
|
|
setipo_graph_keys(&ac, mode);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-07-10 10:48:25 +00:00
|
|
|
/* Set notifier that keyframe properties have changed. */
|
2012-05-08 20:18:33 +00:00
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME_PROP, NULL);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void GRAPH_OT_interpolation_type(wmOperatorType *ot)
|
2009-01-26 23:18:27 +00:00
|
|
|
{
|
|
|
|
/* Identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Set Keyframe Interpolation";
|
|
|
|
ot->idname = "GRAPH_OT_interpolation_type";
|
|
|
|
ot->description =
|
|
|
|
"Set interpolation mode for the F-Curve segments starting from the selected keyframes";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* API callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->invoke = WM_menu_invoke;
|
|
|
|
ot->exec = graphkeys_ipo_exec;
|
|
|
|
ot->poll = graphop_editable_keyframes_poll;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Flags */
|
2012-05-08 20:18:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Id-props */
|
2015-11-23 13:49:52 +11:00
|
|
|
ot->prop = RNA_def_enum(
|
|
|
|
ot->srna, "type", rna_enum_beztriple_interpolation_mode_items, 0, "Type", "");
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Set Easing Operator
|
|
|
|
* \{ */
|
2014-03-22 02:50:24 +13:00
|
|
|
|
|
|
|
static void seteasing_graph_keys(bAnimContext *ac, short mode)
|
|
|
|
{
|
|
|
|
ListBase anim_data = {NULL, NULL};
|
|
|
|
bAnimListElem *ale;
|
|
|
|
int filter;
|
|
|
|
KeyframeEditFunc set_cb = ANIM_editkeyframes_easing(mode);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2014-03-22 02:50:24 +13:00
|
|
|
/* Filter data. */
|
|
|
|
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FOREDIT |
|
|
|
|
ANIMFILTER_NODUPLIS);
|
|
|
|
ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-22 00:18:34 +10:00
|
|
|
/* Loop through setting BezTriple easing.
|
|
|
|
* Note: we do not supply KeyframeEditData to the looper yet.
|
|
|
|
* Currently that's not necessary here.
|
2014-03-22 02:50:24 +13:00
|
|
|
*/
|
2014-05-19 00:24:45 +10:00
|
|
|
for (ale = anim_data.first; ale; ale = ale->next) {
|
2014-03-22 02:50:24 +13:00
|
|
|
ANIM_fcurve_keyframes_loop(NULL, ale->key_data, NULL, set_cb, calchandles_fcurve);
|
2014-05-19 00:24:45 +10:00
|
|
|
|
|
|
|
ale->update |= ANIM_UPDATE_DEFAULT_NOHANDLES;
|
|
|
|
}
|
|
|
|
|
|
|
|
ANIM_animdata_update(ac, &anim_data);
|
|
|
|
ANIM_animdata_freelist(&anim_data);
|
2014-03-22 02:50:24 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
static int graphkeys_easing_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
bAnimContext ac;
|
|
|
|
short mode;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2014-03-22 02:50:24 +13:00
|
|
|
/* Get editor data. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
2014-03-22 02:50:24 +13:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2014-03-22 02:50:24 +13:00
|
|
|
/* Get handle setting mode. */
|
|
|
|
mode = RNA_enum_get(op->ptr, "type");
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2014-03-22 02:50:24 +13:00
|
|
|
/* Set handle type. */
|
|
|
|
seteasing_graph_keys(&ac, mode);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2014-03-22 02:50:24 +13:00
|
|
|
/* Set notifier that keyframe properties have changed. */
|
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME_PROP, NULL);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2014-03-22 02:50:24 +13:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GRAPH_OT_easing_type(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* Identifiers */
|
|
|
|
ot->name = "Set Keyframe Easing Type";
|
|
|
|
ot->idname = "GRAPH_OT_easing_type";
|
|
|
|
ot->description =
|
|
|
|
"Set easing type for the F-Curve segments starting from the selected keyframes";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2014-03-22 02:50:24 +13:00
|
|
|
/* API callbacks */
|
|
|
|
ot->invoke = WM_menu_invoke;
|
|
|
|
ot->exec = graphkeys_easing_exec;
|
|
|
|
ot->poll = graphop_editable_keyframes_poll;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2014-03-22 02:50:24 +13:00
|
|
|
/* Flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2014-03-22 02:50:24 +13:00
|
|
|
/* Id-props */
|
2015-11-23 13:49:52 +11:00
|
|
|
ot->prop = RNA_def_enum(
|
|
|
|
ot->srna, "type", rna_enum_beztriple_interpolation_easing_items, 0, "Type", "");
|
2014-03-22 02:50:24 +13:00
|
|
|
}
|
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Set Handle-Type Operator
|
|
|
|
* \{ */
|
2009-01-26 23:18:27 +00:00
|
|
|
|
|
|
|
/* This function is responsible for setting handle-type of selected keyframes. */
|
2018-06-04 09:31:30 +02:00
|
|
|
static void sethandles_graph_keys(bAnimContext *ac, short mode)
|
2009-01-26 23:18:27 +00:00
|
|
|
{
|
|
|
|
ListBase anim_data = {NULL, NULL};
|
|
|
|
bAnimListElem *ale;
|
|
|
|
int filter;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-05-08 20:18:33 +00:00
|
|
|
KeyframeEditFunc edit_cb = ANIM_editkeyframes_handles(mode);
|
|
|
|
KeyframeEditFunc sel_cb = ANIM_editkeyframes_ok(BEZT_OK_SELECTED);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Filter data. */
|
2012-05-08 20:18:33 +00:00
|
|
|
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FOREDIT |
|
|
|
|
ANIMFILTER_NODUPLIS);
|
2009-01-26 23:18:27 +00:00
|
|
|
ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-22 00:18:34 +10:00
|
|
|
/* Loop through setting flags for handles.
|
|
|
|
* Note: we do not supply KeyframeEditData to the looper yet.
|
|
|
|
* Currently that's not necessary here.
|
2009-01-26 23:18:27 +00:00
|
|
|
*/
|
2012-05-08 20:18:33 +00:00
|
|
|
for (ale = anim_data.first; ale; ale = ale->next) {
|
|
|
|
FCurve *fcu = (FCurve *)ale->key_data;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-02-02 21:16:28 +00:00
|
|
|
/* Any selected keyframes for editing? */
|
2010-04-02 12:02:39 +00:00
|
|
|
if (ANIM_fcurve_keyframes_loop(NULL, fcu, NULL, sel_cb, NULL)) {
|
2010-02-02 21:16:28 +00:00
|
|
|
/* Change type of selected handles. */
|
2010-04-02 12:02:39 +00:00
|
|
|
ANIM_fcurve_keyframes_loop(NULL, fcu, NULL, edit_cb, calchandles_fcurve);
|
2014-05-19 00:24:45 +10:00
|
|
|
|
|
|
|
ale->update |= ANIM_UPDATE_DEFAULT;
|
2010-02-02 21:16:28 +00:00
|
|
|
}
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
2014-05-19 00:24:45 +10:00
|
|
|
|
|
|
|
ANIM_animdata_update(ac, &anim_data);
|
|
|
|
ANIM_animdata_freelist(&anim_data);
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
|
|
|
/* ------------------- */
|
|
|
|
|
|
|
|
static int graphkeys_handletype_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
bAnimContext ac;
|
|
|
|
short mode;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Get editor data. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
2009-01-26 23:18:27 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Get handle setting mode. */
|
2012-05-08 20:18:33 +00:00
|
|
|
mode = RNA_enum_get(op->ptr, "type");
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Set handle type. */
|
2010-02-02 21:16:28 +00:00
|
|
|
sethandles_graph_keys(&ac, mode);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-02-01 11:45:24 +00:00
|
|
|
/* Set notifier that keyframe properties have changed. */
|
2012-05-08 20:18:33 +00:00
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME_PROP, NULL);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-05-08 20:18:33 +00:00
|
|
|
void GRAPH_OT_handle_type(wmOperatorType *ot)
|
2009-01-26 23:18:27 +00:00
|
|
|
{
|
|
|
|
/* Identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Set Keyframe Handle Type";
|
|
|
|
ot->idname = "GRAPH_OT_handle_type";
|
|
|
|
ot->description = "Set type of handle for selected keyframes";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* API callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->invoke = WM_menu_invoke;
|
|
|
|
ot->exec = graphkeys_handletype_exec;
|
|
|
|
ot->poll = graphop_editable_keyframes_poll;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Flags */
|
2012-05-08 20:18:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Id-props */
|
2015-11-23 13:49:52 +11:00
|
|
|
ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_keyframe_handle_type_items, 0, "Type", "");
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/** \} */
|
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* ************************************************************************** */
|
2020-11-23 15:11:51 +01:00
|
|
|
/* EULER FILTER */
|
2009-01-26 23:18:27 +00:00
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name 'Euler Filter' Operator
|
|
|
|
*
|
|
|
|
* Euler filter tools (as seen in Maya), are necessary for working with 'baked'
|
2009-03-07 04:24:28 +00:00
|
|
|
* rotation curves (with Euler rotations). The main purpose of such tools is to
|
|
|
|
* resolve any discontinuities that may arise in the curves due to the clamping
|
|
|
|
* of values to -180 degrees to 180 degrees.
|
2020-12-09 14:34:40 +11:00
|
|
|
* \{ */
|
2009-03-07 04:24:28 +00:00
|
|
|
|
2009-03-15 10:39:02 +00:00
|
|
|
/* Set of three euler-rotation F-Curves. */
|
|
|
|
typedef struct tEulerFilter {
|
2011-03-25 03:58:21 +00:00
|
|
|
struct tEulerFilter *next, *prev;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-01-15 23:24:20 +11:00
|
|
|
/** ID-block which owns the channels */
|
|
|
|
ID *id;
|
|
|
|
/** 3 Pointers to F-Curves. */
|
|
|
|
FCurve *(fcurves[3]);
|
|
|
|
/** Pointer to one of the RNA Path's used by one of the F-Curves. */
|
|
|
|
const char *rna_path;
|
2009-03-15 10:39:02 +00:00
|
|
|
} tEulerFilter;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2020-11-23 12:48:04 +01:00
|
|
|
static bool keyframe_time_differs(BezTriple *keyframes[3])
|
|
|
|
{
|
|
|
|
const float precision = 1e-5;
|
|
|
|
return fabs(keyframes[0]->vec[1][0] - keyframes[1]->vec[1][0]) > precision ||
|
|
|
|
fabs(keyframes[1]->vec[1][0] - keyframes[2]->vec[1][0]) > precision ||
|
|
|
|
fabs(keyframes[0]->vec[1][0] - keyframes[2]->vec[1][0]) > precision;
|
|
|
|
}
|
|
|
|
|
2020-11-19 12:03:09 +01:00
|
|
|
/* Find groups of `rotation_euler` channels. */
|
|
|
|
static ListBase /*tEulerFilter*/ euler_filter_group_channels(
|
|
|
|
const ListBase /*bAnimListElem*/ *anim_data, ReportList *reports, int *r_num_groups)
|
2009-03-07 04:24:28 +00:00
|
|
|
{
|
2020-11-19 12:03:09 +01:00
|
|
|
ListBase euler_groups = {NULL, NULL};
|
2020-11-19 13:02:13 +01:00
|
|
|
tEulerFilter *euf = NULL;
|
2020-11-19 12:03:09 +01:00
|
|
|
*r_num_groups = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-19 12:03:09 +01:00
|
|
|
LISTBASE_FOREACH (bAnimListElem *, ale, anim_data) {
|
|
|
|
FCurve *const fcu = (FCurve *)ale->data;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-19 12:03:09 +01:00
|
|
|
/* Check if this is an appropriate F-Curve:
|
2018-11-14 12:53:15 +11:00
|
|
|
* - Only rotation curves.
|
|
|
|
* - For pchan curves, make sure we're only using the euler curves.
|
2009-03-15 10:39:02 +00:00
|
|
|
*/
|
2019-04-22 09:19:45 +10:00
|
|
|
if (strstr(fcu->rna_path, "rotation_euler") == NULL) {
|
2009-03-15 10:39:02 +00:00
|
|
|
continue;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2020-07-03 17:30:31 +02:00
|
|
|
if (ELEM(fcu->array_index, 0, 1, 2) == 0) {
|
2020-11-19 12:03:09 +01:00
|
|
|
BKE_reportf(reports,
|
2011-03-25 03:58:21 +00:00
|
|
|
RPT_WARNING,
|
2012-05-08 20:18:33 +00:00
|
|
|
"Euler Rotation F-Curve has invalid index (ID='%s', Path='%s', Index=%d)",
|
2012-10-26 17:29:21 +00:00
|
|
|
(ale->id) ? ale->id->name : TIP_("<No ID>"),
|
|
|
|
fcu->rna_path,
|
|
|
|
fcu->array_index);
|
2011-03-25 03:58:21 +00:00
|
|
|
continue;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-19 12:03:09 +01:00
|
|
|
/* Assume that this animation channel will be touched by the Euler filter. Doing this here
|
|
|
|
* saves another loop over the animation data. */
|
|
|
|
ale->update |= ANIM_UPDATE_DEFAULT;
|
|
|
|
|
2012-03-02 16:05:54 +00:00
|
|
|
/* Optimization: assume that xyz curves will always be stored consecutively,
|
2018-06-04 09:31:30 +02:00
|
|
|
* so if the paths or the ID's don't match up, then a curve needs to be added
|
2011-03-25 03:58:21 +00:00
|
|
|
* to a new group.
|
2009-03-15 10:39:02 +00:00
|
|
|
*/
|
2015-01-26 16:03:11 +01:00
|
|
|
if ((euf) && (euf->id == ale->id) && (STREQ(euf->rna_path, fcu->rna_path))) {
|
2011-03-25 03:58:21 +00:00
|
|
|
/* This should be fine to add to the existing group then. */
|
2012-05-08 20:18:33 +00:00
|
|
|
euf->fcurves[fcu->array_index] = fcu;
|
2020-11-19 12:03:09 +01:00
|
|
|
continue;
|
2.5 - Assorted Animation UI/Editing Tweaks
Main Feature:
* It is now possible to choose which AnimData block is the 'active' one for editing, and/or select them too. AnimData blocks are generally the dark blue and lighter-blue expanders (i.e. Scene, Object, Camera, Lamp, Curve, Armature, etc.)
* Objects are no longer selected/deselected when AKEY is used to toggle selection of channels. This was getting a bit annoying.
* Following on from selection of AnimData blocks, it is now possible to select/make active an AnimData block in the animation editors, and change the active action for that block via the 'Animation Data' panel in NLA Editor's properties region.
--> Be aware that user-counts are not totally handled correctly there yet, so some funky behaviour might be seen...
--> It is possible to assign a new action, or to assign an existing one, allowing to switch between actions as in the past with Actions/IPO Editors...
Other tweaks:
* Some code tweaks towards making the 'Euler Filter' feature for Graph Editor working sometime soon
* Added some backend code for snapping the values of keyframes to a single value. Still need to work out some UI for it though.
* Shuffled the code for ACT_OT_new() around, and removed the poll() callback so that it worked in NLA too.
* Fixed some more notifier bugs with deleting bones and a few other editmode operations for Armatures.
2009-09-27 04:22:04 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-19 12:03:09 +01:00
|
|
|
/* Just add to a new block. */
|
|
|
|
euf = MEM_callocN(sizeof(tEulerFilter), "tEulerFilter");
|
|
|
|
BLI_addtail(&euler_groups, euf);
|
|
|
|
++*r_num_groups;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-19 12:03:09 +01:00
|
|
|
euf->id = ale->id;
|
|
|
|
/* This should be safe, since we're only using it for a short time. */
|
|
|
|
euf->rna_path = fcu->rna_path;
|
|
|
|
euf->fcurves[fcu->array_index] = fcu;
|
2011-03-25 03:58:21 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-19 12:03:09 +01:00
|
|
|
return euler_groups;
|
|
|
|
}
|
|
|
|
|
2020-11-23 12:48:04 +01:00
|
|
|
/* Perform discontinuity filter based on conversion to matrix and back.
|
|
|
|
* Return true if the curves were filtered (which may have been a no-op), false otherwise. */
|
|
|
|
static bool euler_filter_multi_channel(tEulerFilter *euf, ReportList *reports)
|
|
|
|
{
|
|
|
|
/* Sanity check: ensure that there are enough F-Curves to work on in this group. */
|
|
|
|
if (ELEM(NULL, euf->fcurves[0], euf->fcurves[1], euf->fcurves[2])) {
|
|
|
|
/* Report which components are missing. */
|
|
|
|
BKE_reportf(reports,
|
|
|
|
RPT_INFO,
|
|
|
|
"Missing %s%s%s component(s) of euler rotation for ID='%s' and RNA-Path='%s'",
|
|
|
|
(euf->fcurves[0] == NULL) ? "X" : "",
|
|
|
|
(euf->fcurves[1] == NULL) ? "Y" : "",
|
|
|
|
(euf->fcurves[2] == NULL) ? "Z" : "",
|
|
|
|
euf->id->name,
|
|
|
|
euf->rna_path);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FCurve *fcu_rot_x = euf->fcurves[0];
|
|
|
|
FCurve *fcu_rot_y = euf->fcurves[1];
|
|
|
|
FCurve *fcu_rot_z = euf->fcurves[2];
|
|
|
|
if (fcu_rot_x->totvert != fcu_rot_y->totvert || fcu_rot_y->totvert != fcu_rot_z->totvert) {
|
|
|
|
BKE_reportf(reports,
|
|
|
|
RPT_INFO,
|
|
|
|
"XYZ rotations not equally keyed for ID='%s' and RNA-Path='%s'",
|
|
|
|
euf->id->name,
|
|
|
|
euf->rna_path);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fcu_rot_x->totvert < 2) {
|
|
|
|
/* Empty curves and single keyframes are trivially "filtered". */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
float filtered_euler[3] = {
|
|
|
|
fcu_rot_x->bezt[0].vec[1][1],
|
|
|
|
fcu_rot_y->bezt[0].vec[1][1],
|
|
|
|
fcu_rot_z->bezt[0].vec[1][1],
|
|
|
|
};
|
|
|
|
|
|
|
|
for (int keyframe_index = 1; keyframe_index < fcu_rot_x->totvert; ++keyframe_index) {
|
|
|
|
BezTriple *keyframes[3] = {
|
|
|
|
&fcu_rot_x->bezt[keyframe_index],
|
|
|
|
&fcu_rot_y->bezt[keyframe_index],
|
|
|
|
&fcu_rot_z->bezt[keyframe_index],
|
|
|
|
};
|
|
|
|
|
|
|
|
if (keyframe_time_differs(keyframes)) {
|
|
|
|
/* The X-coordinates of the keyframes are different, so we cannot correct this key. */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const float unfiltered_euler[3] = {
|
|
|
|
keyframes[0]->vec[1][1],
|
|
|
|
keyframes[1]->vec[1][1],
|
|
|
|
keyframes[2]->vec[1][1],
|
|
|
|
};
|
|
|
|
|
|
|
|
/* The conversion back from matrix to Euler angles actually performs the filtering. */
|
|
|
|
float matrix[3][3];
|
|
|
|
eul_to_mat3(matrix, unfiltered_euler);
|
|
|
|
mat3_normalized_to_compatible_eul(filtered_euler, filtered_euler, matrix);
|
|
|
|
|
|
|
|
/* TODO(Sybren): it might be a nice touch to compare `filtered_euler` with `unfiltered_euler`,
|
|
|
|
* to see if there was actually a change. This could improve reporting for the artist. */
|
|
|
|
|
|
|
|
BKE_fcurve_keyframe_move_value_with_handles(keyframes[0], filtered_euler[0]);
|
|
|
|
BKE_fcurve_keyframe_move_value_with_handles(keyframes[1], filtered_euler[1]);
|
|
|
|
BKE_fcurve_keyframe_move_value_with_handles(keyframes[2], filtered_euler[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove 360-degree flips from a single FCurve.
|
|
|
|
* Return true if the curve was modified, false otherwise. */
|
|
|
|
static bool euler_filter_single_channel(FCurve *fcu)
|
2020-11-19 12:03:09 +01:00
|
|
|
{
|
2020-11-23 12:48:04 +01:00
|
|
|
/* Simple method: just treat any difference between keys of greater than 180 degrees as being a
|
|
|
|
* flip. */
|
|
|
|
BezTriple *bezt, *prev;
|
|
|
|
uint i;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-23 12:48:04 +01:00
|
|
|
/* Skip if not enough verts to do a decent analysis. */
|
|
|
|
if (fcu->totvert <= 2) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Prev follows bezt, bezt = "current" point to be fixed. */
|
|
|
|
/* Our method depends on determining a "difference" from the previous vert. */
|
|
|
|
bool is_modified = false;
|
|
|
|
for (i = 1, prev = fcu->bezt, bezt = fcu->bezt + 1; i < fcu->totvert; i++, prev = bezt++) {
|
|
|
|
const float sign = (prev->vec[1][1] > bezt->vec[1][1]) ? 1.0f : -1.0f;
|
|
|
|
|
|
|
|
/* >= 180 degree flip? */
|
|
|
|
if ((sign * (prev->vec[1][1] - bezt->vec[1][1])) < (float)M_PI) {
|
2011-03-25 03:58:21 +00:00
|
|
|
continue;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-23 12:48:04 +01:00
|
|
|
/* 360 degrees to add/subtract frame value until difference
|
|
|
|
* is acceptably small that there's no more flip. */
|
|
|
|
const float fac = sign * 2.0f * (float)M_PI;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-23 12:48:04 +01:00
|
|
|
while ((sign * (prev->vec[1][1] - bezt->vec[1][1])) >= (float)M_PI) {
|
|
|
|
bezt->vec[0][1] += fac;
|
|
|
|
bezt->vec[1][1] += fac;
|
|
|
|
bezt->vec[2][1] += fac;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-23 12:48:04 +01:00
|
|
|
is_modified = true;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-23 12:48:04 +01:00
|
|
|
return is_modified;
|
|
|
|
}
|
2020-11-19 12:03:09 +01:00
|
|
|
|
2020-11-23 12:48:04 +01:00
|
|
|
static void euler_filter_perform_filter(ListBase /*tEulerFilter*/ *eulers,
|
|
|
|
ReportList *reports,
|
|
|
|
int *r_curves_filtered,
|
|
|
|
int *r_curves_seen)
|
|
|
|
{
|
|
|
|
*r_curves_filtered = 0;
|
|
|
|
*r_curves_seen = 0;
|
|
|
|
|
|
|
|
LISTBASE_FOREACH (tEulerFilter *, euf, eulers) {
|
|
|
|
int curves_filtered_this_group = 0;
|
|
|
|
|
|
|
|
if (euler_filter_multi_channel(euf, reports)) {
|
|
|
|
curves_filtered_this_group = 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int channel_index = 0; channel_index < 3; channel_index++) {
|
|
|
|
FCurve *fcu = euf->fcurves[channel_index];
|
|
|
|
if (fcu == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
++*r_curves_seen;
|
|
|
|
|
|
|
|
if (euler_filter_single_channel(fcu)) {
|
|
|
|
++curves_filtered_this_group;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2011-03-25 03:58:21 +00:00
|
|
|
}
|
2020-11-19 12:03:09 +01:00
|
|
|
|
2020-11-23 12:48:04 +01:00
|
|
|
*r_curves_filtered += min_ii(3, curves_filtered_this_group);
|
|
|
|
}
|
2020-11-19 12:03:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int graphkeys_euler_filter_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
/* Get editor data. */
|
|
|
|
bAnimContext ac;
|
|
|
|
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The process is done in two passes:
|
|
|
|
* 1) Sets of three related rotation curves are identified from the selected channels,
|
|
|
|
* and are stored as a single 'operation unit' for the next step.
|
|
|
|
* 2) Each set of three F-Curves is processed for each keyframe, with the values being
|
|
|
|
* processed as necessary.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Step 1: extract only the rotation f-curves. */
|
|
|
|
const int filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_SEL | ANIMFILTER_CURVE_VISIBLE |
|
|
|
|
ANIMFILTER_FOREDIT | ANIMFILTER_NODUPLIS);
|
|
|
|
ListBase anim_data = {NULL, NULL};
|
|
|
|
ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
|
|
|
|
|
|
|
|
int groups = 0;
|
|
|
|
ListBase eulers = euler_filter_group_channels(&anim_data, op->reports, &groups);
|
|
|
|
BLI_assert(BLI_listbase_count(&eulers) == groups);
|
|
|
|
|
|
|
|
if (groups == 0) {
|
|
|
|
ANIM_animdata_freelist(&anim_data);
|
|
|
|
BKE_report(op->reports, RPT_WARNING, "No Euler Rotation F-Curves to fix up");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Step 2: go through each set of curves, processing the values at each keyframe.
|
|
|
|
* - It is assumed that there must be a full set of keyframes at each keyframe position.
|
|
|
|
*/
|
2020-11-23 12:48:04 +01:00
|
|
|
int curves_filtered;
|
|
|
|
int curves_seen;
|
|
|
|
euler_filter_perform_filter(&eulers, op->reports, &curves_filtered, &curves_seen);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-23 12:48:04 +01:00
|
|
|
BLI_freelistN(&eulers);
|
2014-05-19 00:24:45 +10:00
|
|
|
ANIM_animdata_update(&ac, &anim_data);
|
|
|
|
ANIM_animdata_freelist(&anim_data);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-23 12:48:04 +01:00
|
|
|
if (curves_filtered == 0) {
|
|
|
|
if (curves_seen < 3) {
|
|
|
|
/* Showing the entire error message makes no sense when the artist is only trying to filter
|
|
|
|
* one or two curves. */
|
2020-12-07 10:57:08 +01:00
|
|
|
BKE_report(op->reports, RPT_WARNING, "No Euler Rotations could be corrected");
|
2020-11-23 12:48:04 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
BKE_report(op->reports,
|
|
|
|
RPT_ERROR,
|
|
|
|
"No Euler Rotations could be corrected, ensure each rotation has keys for all "
|
|
|
|
"components, "
|
|
|
|
"and that F-Curves for these are in consecutive XYZ order and selected");
|
|
|
|
}
|
2011-03-25 03:58:21 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-23 12:48:04 +01:00
|
|
|
if (curves_filtered != curves_seen) {
|
|
|
|
BLI_assert(curves_filtered < curves_seen);
|
|
|
|
BKE_reportf(op->reports,
|
|
|
|
RPT_INFO,
|
2020-12-07 10:57:08 +01:00
|
|
|
"%d of %d rotation channels were filtered (see the Info window for details)",
|
2020-11-23 12:48:04 +01:00
|
|
|
curves_filtered,
|
|
|
|
curves_seen);
|
|
|
|
}
|
|
|
|
else if (curves_seen == 1) {
|
2020-12-07 10:57:08 +01:00
|
|
|
BKE_report(op->reports, RPT_INFO, "The rotation channel was filtered");
|
2020-11-23 12:48:04 +01:00
|
|
|
}
|
|
|
|
else {
|
2020-12-07 10:57:08 +01:00
|
|
|
BKE_reportf(op->reports, RPT_INFO, "All %d rotation channels were filtered", curves_seen);
|
2011-03-25 03:58:21 +00:00
|
|
|
}
|
2020-07-03 17:30:31 +02:00
|
|
|
|
|
|
|
/* Set notifier that keyframes have changed. */
|
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
|
|
|
|
|
|
|
|
/* Done at last. */
|
|
|
|
return OPERATOR_FINISHED;
|
2009-03-07 04:24:28 +00:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void GRAPH_OT_euler_filter(wmOperatorType *ot)
|
2009-03-07 04:24:28 +00:00
|
|
|
{
|
|
|
|
/* Identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Euler Discontinuity Filter";
|
|
|
|
ot->idname = "GRAPH_OT_euler_filter";
|
2013-06-12 12:32:07 +00:00
|
|
|
ot->description =
|
|
|
|
"Fix large jumps and flips in the selected "
|
|
|
|
"Euler Rotation F-Curves arising from rotation "
|
|
|
|
"values being clipped when baking physics";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-03-07 04:24:28 +00:00
|
|
|
/* API callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = graphkeys_euler_filter_exec;
|
|
|
|
ot->poll = graphop_editable_keyframes_poll;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-03-07 04:24:28 +00:00
|
|
|
/* Flags */
|
2012-05-08 20:18:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-03-07 04:24:28 +00:00
|
|
|
}
|
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/** \} */
|
|
|
|
|
2020-11-23 15:11:51 +01:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* SNAPPING */
|
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Jump to Selected Frames Operator
|
|
|
|
* \{ */
|
2009-01-26 23:18:27 +00:00
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool graphkeys_framejump_poll(bContext *C)
|
2012-12-06 05:48:51 +00:00
|
|
|
{
|
|
|
|
/* Prevent changes during render. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (G.is_rendering) {
|
2020-09-25 10:20:33 +02:00
|
|
|
return false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2012-12-06 05:48:51 +00:00
|
|
|
|
|
|
|
return graphop_visible_keyframes_poll(C);
|
|
|
|
}
|
|
|
|
|
2020-10-16 16:07:50 +02:00
|
|
|
static KeyframeEditData sum_selected_keyframes(bAnimContext *ac)
|
2009-01-26 23:18:27 +00:00
|
|
|
{
|
2012-05-08 20:18:33 +00:00
|
|
|
ListBase anim_data = {NULL, NULL};
|
2009-01-26 23:18:27 +00:00
|
|
|
bAnimListElem *ale;
|
|
|
|
int filter;
|
2010-04-02 12:02:39 +00:00
|
|
|
KeyframeEditData ked;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Init edit data. */
|
2010-04-02 12:02:39 +00:00
|
|
|
memset(&ked, 0, sizeof(KeyframeEditData));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Loop over action data, averaging values. */
|
2012-05-08 20:18:33 +00:00
|
|
|
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS);
|
2020-10-16 16:07:50 +02:00
|
|
|
ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-08 20:18:33 +00:00
|
|
|
for (ale = anim_data.first; ale; ale = ale->next) {
|
2020-10-16 16:07:50 +02:00
|
|
|
AnimData *adt = ANIM_nla_mapping_get(ac, ale);
|
|
|
|
short mapping_flag = ANIM_get_normalization_flags(ac);
|
2013-10-29 18:10:48 +00:00
|
|
|
KeyframeEditData current_ked;
|
2015-04-13 15:57:46 +02:00
|
|
|
float offset;
|
|
|
|
float unit_scale = ANIM_unit_mapping_get_factor(
|
2020-10-16 16:07:50 +02:00
|
|
|
ac->scene, ale->id, ale->key_data, mapping_flag | ANIM_UNITCONV_ONLYKEYS, &offset);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-10-29 18:10:48 +00:00
|
|
|
memset(¤t_ked, 0, sizeof(current_ked));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-06-23 13:25:31 +00:00
|
|
|
if (adt) {
|
2018-06-04 09:31:30 +02:00
|
|
|
ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1);
|
2013-10-29 18:10:48 +00:00
|
|
|
ANIM_fcurve_keyframes_loop(¤t_ked, ale->key_data, NULL, bezt_calc_average, NULL);
|
2018-06-04 09:31:30 +02:00
|
|
|
ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1);
|
2009-06-23 13:25:31 +00:00
|
|
|
}
|
2019-04-22 09:19:45 +10:00
|
|
|
else {
|
2013-10-29 18:10:48 +00:00
|
|
|
ANIM_fcurve_keyframes_loop(¤t_ked, ale->key_data, NULL, bezt_calc_average, NULL);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-10-29 18:10:48 +00:00
|
|
|
ked.f1 += current_ked.f1;
|
|
|
|
ked.i1 += current_ked.i1;
|
2015-04-13 15:57:46 +02:00
|
|
|
ked.f2 += (current_ked.f2 + offset) * unit_scale;
|
2013-10-29 18:10:48 +00:00
|
|
|
ked.i2 += current_ked.i2;
|
2009-06-23 13:25:31 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-19 00:24:45 +10:00
|
|
|
ANIM_animdata_freelist(&anim_data);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-10-16 16:07:50 +02:00
|
|
|
return ked;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Snap current-frame indicator to 'average time' of selected keyframe. */
|
|
|
|
static int graphkeys_framejump_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
bAnimContext ac;
|
|
|
|
|
|
|
|
/* Get editor data. */
|
|
|
|
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
const KeyframeEditData keyframe_sum = sum_selected_keyframes(&ac);
|
|
|
|
const float sum_time = keyframe_sum.f1;
|
|
|
|
const float sum_value = keyframe_sum.f2;
|
|
|
|
const int num_keyframes = keyframe_sum.i1;
|
|
|
|
|
|
|
|
if (num_keyframes == 0) {
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2009-10-22 09:15:56 +00:00
|
|
|
/* Set the new current frame and cursor values, based on the average time and value. */
|
2020-10-16 16:07:50 +02:00
|
|
|
SpaceGraph *sipo = (SpaceGraph *)ac.sl;
|
|
|
|
Scene *scene = ac.scene;
|
|
|
|
|
|
|
|
/* Take the average values, rounding to the nearest int as necessary for int results. */
|
|
|
|
if (sipo->mode == SIPO_MODE_DRIVERS) {
|
|
|
|
/* Drivers Mode - Affects cursor (float) */
|
|
|
|
sipo->cursorTime = sum_time / (float)num_keyframes;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Animation Mode - Affects current frame (int) */
|
|
|
|
CFRA = round_fl_to_int(sum_time / num_keyframes);
|
2020-11-06 11:25:27 +11:00
|
|
|
SUBFRA = 0.0f;
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
2020-10-16 16:07:50 +02:00
|
|
|
sipo->cursorVal = sum_value / (float)num_keyframes;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-04-10 03:34:20 +00:00
|
|
|
/* Set notifier that things have changed. */
|
2012-05-08 20:18:33 +00:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_FRAME, ac.scene);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void GRAPH_OT_frame_jump(wmOperatorType *ot)
|
2009-01-26 23:18:27 +00:00
|
|
|
{
|
|
|
|
/* Identifiers */
|
2012-10-15 03:52:27 +00:00
|
|
|
ot->name = "Jump to Keyframes";
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->idname = "GRAPH_OT_frame_jump";
|
2012-10-15 03:52:27 +00:00
|
|
|
ot->description = "Place the cursor on the midpoint of selected keyframes";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* API callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = graphkeys_framejump_exec;
|
2012-12-06 05:48:51 +00:00
|
|
|
ot->poll = graphkeys_framejump_poll;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Flags */
|
2012-05-08 20:18:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
|
|
|
|
2020-10-16 16:44:06 +02:00
|
|
|
/* snap 2D cursor value to the average value of selected keyframe */
|
|
|
|
static int graphkeys_snap_cursor_value_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
bAnimContext ac;
|
|
|
|
|
|
|
|
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
const KeyframeEditData keyframe_sum = sum_selected_keyframes(&ac);
|
|
|
|
const float sum_value = keyframe_sum.f2;
|
|
|
|
const int num_keyframes = keyframe_sum.i1;
|
|
|
|
|
|
|
|
if (num_keyframes == 0) {
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
SpaceGraph *sipo = (SpaceGraph *)ac.sl;
|
|
|
|
sipo->cursorVal = sum_value / (float)num_keyframes;
|
|
|
|
// WM_event_add_notifier(C, NC_SCENE | ND_FRAME, ac.scene);
|
|
|
|
ED_region_tag_redraw(CTX_wm_region(C));
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GRAPH_OT_snap_cursor_value(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* Identifiers. */
|
|
|
|
ot->name = "Snap Cursor Value to Selected";
|
|
|
|
ot->idname = "GRAPH_OT_snap_cursor_value";
|
|
|
|
ot->description = "Place the cursor value on the average value of selected keyframes";
|
|
|
|
|
|
|
|
/* API callbacks. */
|
|
|
|
ot->exec = graphkeys_snap_cursor_value_exec;
|
|
|
|
ot->poll = graphkeys_framejump_poll;
|
|
|
|
|
|
|
|
/* Flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
}
|
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Snap Keyframes Operator
|
|
|
|
* \{ */
|
2009-01-26 23:18:27 +00:00
|
|
|
|
|
|
|
/* Defines for snap keyframes tool. */
|
2017-10-18 15:07:26 +11:00
|
|
|
static const EnumPropertyItem prop_graphkeys_snap_types[] = {
|
2012-10-21 05:46:41 +00:00
|
|
|
{GRAPHKEYS_SNAP_CFRA,
|
|
|
|
"CFRA",
|
|
|
|
0,
|
2020-10-28 14:06:26 -04:00
|
|
|
"Selection to Current Frame",
|
2012-10-08 05:57:52 +00:00
|
|
|
"Snap selected keyframes to the current frame"},
|
2012-10-21 05:46:41 +00:00
|
|
|
{GRAPHKEYS_SNAP_VALUE,
|
|
|
|
"VALUE",
|
|
|
|
0,
|
2020-10-28 14:06:26 -04:00
|
|
|
"Selection to Cursor Value",
|
2012-10-08 05:57:52 +00:00
|
|
|
"Set values of selected keyframes to the cursor value (Y/Horizontal component)"},
|
2012-10-21 05:46:41 +00:00
|
|
|
{GRAPHKEYS_SNAP_NEAREST_FRAME,
|
|
|
|
"NEAREST_FRAME",
|
|
|
|
0,
|
2020-10-28 14:06:26 -04:00
|
|
|
"Selection to Nearest Frame",
|
2020-12-24 13:11:22 -06:00
|
|
|
"Snap selected keyframes to the nearest (whole) frame (use to fix accidental subframe "
|
2012-10-08 21:03:35 +00:00
|
|
|
"offsets)"},
|
2012-10-21 05:46:41 +00:00
|
|
|
{GRAPHKEYS_SNAP_NEAREST_SECOND,
|
|
|
|
"NEAREST_SECOND",
|
|
|
|
0,
|
2020-10-28 14:06:26 -04:00
|
|
|
"Selection to Nearest Second",
|
2012-10-08 05:57:52 +00:00
|
|
|
"Snap selected keyframes to the nearest second"},
|
2012-10-21 05:46:41 +00:00
|
|
|
{GRAPHKEYS_SNAP_NEAREST_MARKER,
|
|
|
|
"NEAREST_MARKER",
|
|
|
|
0,
|
2020-10-28 14:06:26 -04:00
|
|
|
"Selection to Nearest Marker",
|
2012-10-08 05:57:52 +00:00
|
|
|
"Snap selected keyframes to the nearest marker"},
|
2012-10-21 05:46:41 +00:00
|
|
|
{GRAPHKEYS_SNAP_HORIZONTAL,
|
|
|
|
"HORIZONTAL",
|
|
|
|
0,
|
|
|
|
"Flatten Handles",
|
2012-10-08 05:57:52 +00:00
|
|
|
"Flatten handles for a smoother transition"},
|
2019-02-03 14:01:45 +11:00
|
|
|
{0, NULL, 0, NULL, NULL},
|
2009-01-26 23:18:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* This function is responsible for snapping keyframes to frame-times. */
|
2018-06-04 09:31:30 +02:00
|
|
|
static void snap_graph_keys(bAnimContext *ac, short mode)
|
2009-01-26 23:18:27 +00:00
|
|
|
{
|
|
|
|
ListBase anim_data = {NULL, NULL};
|
|
|
|
bAnimListElem *ale;
|
|
|
|
int filter;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-16 10:16:16 +11:00
|
|
|
SpaceGraph *sipo = (SpaceGraph *)ac->sl;
|
2010-04-02 12:02:39 +00:00
|
|
|
KeyframeEditData ked;
|
|
|
|
KeyframeEditFunc edit_cb;
|
2013-10-29 18:10:48 +00:00
|
|
|
float cursor_value = 0.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Filter data. */
|
2012-05-08 20:18:33 +00:00
|
|
|
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FOREDIT |
|
|
|
|
ANIMFILTER_NODUPLIS);
|
2009-01-26 23:18:27 +00:00
|
|
|
ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-10-26 20:13:29 +13:00
|
|
|
/* Init custom data for iterating over keyframes. */
|
2018-06-04 09:31:30 +02:00
|
|
|
memset(&ked, 0, sizeof(KeyframeEditData));
|
2012-05-08 20:18:33 +00:00
|
|
|
ked.scene = ac->scene;
|
2009-05-09 02:37:12 +00:00
|
|
|
if (mode == GRAPHKEYS_SNAP_NEAREST_MARKER) {
|
2012-05-08 20:18:33 +00:00
|
|
|
ked.list.first = (ac->markers) ? ac->markers->first : NULL;
|
|
|
|
ked.list.last = (ac->markers) ? ac->markers->last : NULL;
|
2009-05-09 02:37:12 +00:00
|
|
|
}
|
2009-10-20 12:04:56 +00:00
|
|
|
else if (mode == GRAPHKEYS_SNAP_VALUE) {
|
2013-10-29 18:10:48 +00:00
|
|
|
cursor_value = (sipo) ? sipo->cursorVal : 0.0f;
|
2009-10-20 12:04:56 +00:00
|
|
|
}
|
2015-10-26 20:13:29 +13:00
|
|
|
else if (mode == GRAPHKEYS_SNAP_CFRA) {
|
|
|
|
/* In drivers mode, use the cursor value instead
|
|
|
|
* (We need to use a different callback for that though)
|
|
|
|
*/
|
|
|
|
if (sipo->mode == SIPO_MODE_DRIVERS) {
|
|
|
|
ked.f1 = sipo->cursorTime;
|
|
|
|
mode = SNAP_KEYS_TIME;
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-10-26 20:13:29 +13:00
|
|
|
/* Get beztriple editing callbacks. */
|
|
|
|
edit_cb = ANIM_editkeyframes_snap(mode);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Snap keyframes. */
|
2012-05-08 20:18:33 +00:00
|
|
|
for (ale = anim_data.first; ale; ale = ale->next) {
|
|
|
|
AnimData *adt = ANIM_nla_mapping_get(ac, ale);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-04-23 16:41:30 +12:00
|
|
|
/* Normalise cursor value (for normalised F-Curves display). */
|
|
|
|
if (mode == GRAPHKEYS_SNAP_VALUE) {
|
|
|
|
short mapping_flag = ANIM_get_normalization_flags(ac);
|
2015-04-13 15:57:46 +02:00
|
|
|
float offset;
|
|
|
|
float unit_scale = ANIM_unit_mapping_get_factor(
|
|
|
|
ac->scene, ale->id, ale->key_data, mapping_flag, &offset);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-04-13 15:57:46 +02:00
|
|
|
ked.f1 = (cursor_value / unit_scale) - offset;
|
2014-04-23 16:41:30 +12:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-04-23 16:41:30 +12:00
|
|
|
/* Perform snapping. */
|
2009-06-23 13:25:31 +00:00
|
|
|
if (adt) {
|
2018-06-04 09:31:30 +02:00
|
|
|
ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 0);
|
2010-04-02 12:02:39 +00:00
|
|
|
ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, edit_cb, calchandles_fcurve);
|
2016-02-06 00:59:32 +13:00
|
|
|
ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 0);
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
2019-04-22 09:19:45 +10:00
|
|
|
else {
|
2010-04-02 12:02:39 +00:00
|
|
|
ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, edit_cb, calchandles_fcurve);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-19 00:24:45 +10:00
|
|
|
ale->update |= ANIM_UPDATE_DEFAULT;
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-19 00:24:45 +10:00
|
|
|
ANIM_animdata_update(ac, &anim_data);
|
|
|
|
ANIM_animdata_freelist(&anim_data);
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------- */
|
|
|
|
|
|
|
|
static int graphkeys_snap_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
bAnimContext ac;
|
|
|
|
short mode;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Get editor data. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
2009-01-26 23:18:27 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Get snapping mode. */
|
2012-05-08 20:18:33 +00:00
|
|
|
mode = RNA_enum_get(op->ptr, "type");
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Snap keyframes. */
|
|
|
|
snap_graph_keys(&ac, mode);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-07-10 10:48:25 +00:00
|
|
|
/* Set notifier that keyframes have changed. */
|
2012-05-08 20:18:33 +00:00
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void GRAPH_OT_snap(wmOperatorType *ot)
|
2009-01-26 23:18:27 +00:00
|
|
|
{
|
|
|
|
/* Identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Snap Keys";
|
|
|
|
ot->idname = "GRAPH_OT_snap";
|
|
|
|
ot->description = "Snap selected keyframes to the chosen times/values";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* API callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->invoke = WM_menu_invoke;
|
|
|
|
ot->exec = graphkeys_snap_exec;
|
|
|
|
ot->poll = graphop_editable_keyframes_poll;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Flags */
|
2012-05-08 20:18:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Id-props */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->prop = RNA_def_enum(ot->srna, "type", prop_graphkeys_snap_types, 0, "Type", "");
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Mirror Keyframes Operator
|
|
|
|
* \{ */
|
2009-01-26 23:18:27 +00:00
|
|
|
|
|
|
|
/* Defines for mirror keyframes tool. */
|
2017-10-18 15:07:26 +11:00
|
|
|
static const EnumPropertyItem prop_graphkeys_mirror_types[] = {
|
2012-10-21 05:46:41 +00:00
|
|
|
{GRAPHKEYS_MIRROR_CFRA,
|
|
|
|
"CFRA",
|
|
|
|
0,
|
2019-09-20 14:31:24 +02:00
|
|
|
"By Times Over Current Frame",
|
2012-10-08 05:57:52 +00:00
|
|
|
"Flip times of selected keyframes using the current frame as the mirror line"},
|
2012-10-21 05:46:41 +00:00
|
|
|
{GRAPHKEYS_MIRROR_VALUE,
|
|
|
|
"VALUE",
|
|
|
|
0,
|
2019-09-20 14:31:24 +02:00
|
|
|
"By Values Over Cursor Value",
|
2012-10-08 20:25:07 +00:00
|
|
|
"Flip values of selected keyframes using the cursor value (Y/Horizontal component) as the "
|
|
|
|
"mirror line"},
|
2012-10-21 05:46:41 +00:00
|
|
|
{GRAPHKEYS_MIRROR_YAXIS,
|
|
|
|
"YAXIS",
|
|
|
|
0,
|
2020-12-13 12:59:36 -08:00
|
|
|
"By Times Over Zero Time",
|
2012-10-08 05:57:52 +00:00
|
|
|
"Flip times of selected keyframes, effectively reversing the order they appear in"},
|
2012-10-21 05:46:41 +00:00
|
|
|
{GRAPHKEYS_MIRROR_XAXIS,
|
|
|
|
"XAXIS",
|
|
|
|
0,
|
2020-12-13 12:59:36 -08:00
|
|
|
"By Values Over Zero Value",
|
2012-10-08 20:25:07 +00:00
|
|
|
"Flip values of selected keyframes (i.e. negative values become positive, and vice versa)"},
|
2012-10-21 05:46:41 +00:00
|
|
|
{GRAPHKEYS_MIRROR_MARKER,
|
|
|
|
"MARKER",
|
|
|
|
0,
|
2019-09-20 14:31:24 +02:00
|
|
|
"By Times Over First Selected Marker",
|
2012-10-08 05:57:52 +00:00
|
|
|
"Flip times of selected keyframes using the first selected marker as the reference point"},
|
2019-02-03 14:01:45 +11:00
|
|
|
{0, NULL, 0, NULL, NULL},
|
2009-01-26 23:18:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* This function is responsible for mirroring keyframes. */
|
2018-06-04 09:31:30 +02:00
|
|
|
static void mirror_graph_keys(bAnimContext *ac, short mode)
|
2009-01-26 23:18:27 +00:00
|
|
|
{
|
|
|
|
ListBase anim_data = {NULL, NULL};
|
|
|
|
bAnimListElem *ale;
|
|
|
|
int filter;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-16 10:16:16 +11:00
|
|
|
SpaceGraph *sipo = (SpaceGraph *)ac->sl;
|
2010-04-02 12:02:39 +00:00
|
|
|
KeyframeEditData ked;
|
|
|
|
KeyframeEditFunc edit_cb;
|
2013-11-04 01:18:33 +00:00
|
|
|
float cursor_value = 0.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-10-26 20:13:29 +13:00
|
|
|
/* Init custom data for looping over keyframes. */
|
2018-06-04 09:31:30 +02:00
|
|
|
memset(&ked, 0, sizeof(KeyframeEditData));
|
2012-05-08 20:18:33 +00:00
|
|
|
ked.scene = ac->scene;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-10-26 20:13:29 +13:00
|
|
|
/* Store mode-specific custom data... */
|
2009-01-28 06:32:47 +00:00
|
|
|
if (mode == GRAPHKEYS_MIRROR_MARKER) {
|
2012-05-08 20:18:33 +00:00
|
|
|
TimeMarker *marker = NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Find first selected marker. */
|
2012-05-08 20:18:33 +00:00
|
|
|
marker = ED_markers_get_first_selected(ac->markers);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Store marker's time (if available). */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (marker) {
|
2012-05-08 20:18:33 +00:00
|
|
|
ked.f1 = (float)marker->frame;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
else {
|
2009-01-26 23:18:27 +00:00
|
|
|
return;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
2009-10-22 09:07:19 +00:00
|
|
|
else if (mode == GRAPHKEYS_MIRROR_VALUE) {
|
2013-10-29 18:10:48 +00:00
|
|
|
cursor_value = (sipo) ? sipo->cursorVal : 0.0f;
|
2009-10-22 09:07:19 +00:00
|
|
|
}
|
2015-10-26 20:13:29 +13:00
|
|
|
else if (mode == GRAPHKEYS_MIRROR_CFRA) {
|
|
|
|
/* In drivers mode, use the cursor value instead
|
|
|
|
* (We need to use a different callback for that though)
|
|
|
|
*/
|
|
|
|
if (sipo->mode == SIPO_MODE_DRIVERS) {
|
|
|
|
ked.f1 = sipo->cursorTime;
|
|
|
|
mode = MIRROR_KEYS_TIME;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2015-10-26 20:13:29 +13:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-10-26 20:13:29 +13:00
|
|
|
/* Get beztriple editing callbacks. */
|
|
|
|
edit_cb = ANIM_editkeyframes_mirror(mode);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Filter data. */
|
2012-05-08 20:18:33 +00:00
|
|
|
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FOREDIT |
|
|
|
|
ANIMFILTER_NODUPLIS);
|
2009-01-26 23:18:27 +00:00
|
|
|
ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Mirror keyframes. */
|
2012-05-08 20:18:33 +00:00
|
|
|
for (ale = anim_data.first; ale; ale = ale->next) {
|
|
|
|
AnimData *adt = ANIM_nla_mapping_get(ac, ale);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-01-26 03:16:14 +00:00
|
|
|
/* Apply unit corrections. */
|
2014-04-23 16:38:09 +12:00
|
|
|
if (mode == GRAPHKEYS_MIRROR_VALUE) {
|
|
|
|
short mapping_flag = ANIM_get_normalization_flags(ac);
|
2015-04-13 15:57:46 +02:00
|
|
|
float offset;
|
|
|
|
float unit_scale = ANIM_unit_mapping_get_factor(
|
|
|
|
ac->scene, ale->id, ale->key_data, mapping_flag | ANIM_UNITCONV_ONLYKEYS, &offset);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-04-13 15:57:46 +02:00
|
|
|
ked.f1 = (cursor_value + offset) * unit_scale;
|
2014-04-23 16:38:09 +12:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-04-23 16:38:09 +12:00
|
|
|
/* Perform actual mirroring. */
|
2009-06-23 13:25:31 +00:00
|
|
|
if (adt) {
|
2018-06-04 09:31:30 +02:00
|
|
|
ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 0);
|
2010-04-02 12:02:39 +00:00
|
|
|
ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, edit_cb, calchandles_fcurve);
|
2016-02-06 00:59:32 +13:00
|
|
|
ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 0);
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
2019-04-22 09:19:45 +10:00
|
|
|
else {
|
2010-04-02 12:02:39 +00:00
|
|
|
ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, edit_cb, calchandles_fcurve);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-19 00:24:45 +10:00
|
|
|
ale->update |= ANIM_UPDATE_DEFAULT;
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-19 00:24:45 +10:00
|
|
|
ANIM_animdata_update(ac, &anim_data);
|
|
|
|
ANIM_animdata_freelist(&anim_data);
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------- */
|
|
|
|
|
|
|
|
static int graphkeys_mirror_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
bAnimContext ac;
|
|
|
|
short mode;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Get editor data. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
2009-01-26 23:18:27 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Get mirroring mode. */
|
2012-05-08 20:18:33 +00:00
|
|
|
mode = RNA_enum_get(op->ptr, "type");
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Mirror keyframes. */
|
|
|
|
mirror_graph_keys(&ac, mode);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-07-10 10:48:25 +00:00
|
|
|
/* Set notifier that keyframes have changed. */
|
2012-05-08 20:18:33 +00:00
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void GRAPH_OT_mirror(wmOperatorType *ot)
|
2009-01-26 23:18:27 +00:00
|
|
|
{
|
|
|
|
/* Identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Mirror Keys";
|
|
|
|
ot->idname = "GRAPH_OT_mirror";
|
|
|
|
ot->description = "Flip selected keyframes over the selected mirror line";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* API callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->invoke = WM_menu_invoke;
|
|
|
|
ot->exec = graphkeys_mirror_exec;
|
|
|
|
ot->poll = graphop_editable_keyframes_poll;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Flags */
|
2012-05-08 20:18:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* Id-props */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->prop = RNA_def_enum(ot->srna, "type", prop_graphkeys_mirror_types, 0, "Type", "");
|
2009-01-26 23:18:27 +00:00
|
|
|
}
|
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Smooth Keyframes Operator
|
|
|
|
* \{ */
|
2009-01-28 09:55:36 +00:00
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
static int graphkeys_smooth_exec(bContext *C, wmOperator *UNUSED(op))
|
2009-01-28 09:55:36 +00:00
|
|
|
{
|
|
|
|
bAnimContext ac;
|
|
|
|
ListBase anim_data = {NULL, NULL};
|
|
|
|
bAnimListElem *ale;
|
|
|
|
int filter;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-28 09:55:36 +00:00
|
|
|
/* Get editor data. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
2009-01-28 09:55:36 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-28 09:55:36 +00:00
|
|
|
/* Filter data. */
|
2012-05-08 20:18:33 +00:00
|
|
|
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FOREDIT |
|
|
|
|
ANIMFILTER_NODUPLIS);
|
2009-01-28 09:55:36 +00:00
|
|
|
ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-28 09:55:36 +00:00
|
|
|
/* Smooth keyframes. */
|
2012-05-08 20:18:33 +00:00
|
|
|
for (ale = anim_data.first; ale; ale = ale->next) {
|
2009-01-28 09:55:36 +00:00
|
|
|
/* For now, we can only smooth by flattening handles AND smoothing curve values.
|
2012-05-20 21:23:26 +00:00
|
|
|
* Perhaps the mode argument could be removed, as that functionality is offered through
|
2009-01-28 09:55:36 +00:00
|
|
|
* Snap->Flatten Handles anyway.
|
|
|
|
*/
|
|
|
|
smooth_fcurve(ale->key_data);
|
2014-05-19 00:24:45 +10:00
|
|
|
|
|
|
|
ale->update |= ANIM_UPDATE_DEFAULT;
|
2009-01-28 09:55:36 +00:00
|
|
|
}
|
2014-05-19 00:24:45 +10:00
|
|
|
|
|
|
|
ANIM_animdata_update(&ac, &anim_data);
|
|
|
|
ANIM_animdata_freelist(&anim_data);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-07-10 10:48:25 +00:00
|
|
|
/* Set notifier that keyframes have changed. */
|
2012-05-08 20:18:33 +00:00
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-28 09:55:36 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void GRAPH_OT_smooth(wmOperatorType *ot)
|
2009-01-28 09:55:36 +00:00
|
|
|
{
|
|
|
|
/* Identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Smooth Keys";
|
|
|
|
ot->idname = "GRAPH_OT_smooth";
|
|
|
|
ot->description = "Apply weighted moving means to make selected F-Curves less bumpy";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-28 09:55:36 +00:00
|
|
|
/* API callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = graphkeys_smooth_exec;
|
|
|
|
ot->poll = graphop_editable_keyframes_poll;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-01-28 09:55:36 +00:00
|
|
|
/* Flags */
|
2012-05-08 20:18:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-01-28 09:55:36 +00:00
|
|
|
}
|
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/** \} */
|
|
|
|
|
2009-01-26 23:18:27 +00:00
|
|
|
/* ************************************************************************** */
|
2009-03-15 10:39:02 +00:00
|
|
|
/* F-CURVE MODIFIERS */
|
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Add F-Modifier Operator
|
|
|
|
* \{ */
|
2009-03-15 10:39:02 +00:00
|
|
|
|
2017-10-18 15:07:26 +11:00
|
|
|
static const EnumPropertyItem *graph_fmodifier_itemf(bContext *C,
|
|
|
|
PointerRNA *UNUSED(ptr),
|
|
|
|
PropertyRNA *UNUSED(prop),
|
|
|
|
bool *r_free)
|
2009-07-03 01:10:46 +00:00
|
|
|
{
|
2014-05-14 14:41:43 +10:00
|
|
|
EnumPropertyItem *item = NULL;
|
|
|
|
int totitem = 0;
|
|
|
|
int i = 0;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2014-05-14 14:41:43 +10:00
|
|
|
if (C == NULL) {
|
2015-11-23 13:49:52 +11:00
|
|
|
return rna_enum_fmodifier_type_items;
|
2014-05-14 14:41:43 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-07-03 01:10:46 +00:00
|
|
|
/* Start from 1 to skip the 'Invalid' modifier type. */
|
|
|
|
for (i = 1; i < FMODIFIER_NUM_TYPES; i++) {
|
2015-03-30 21:17:07 +11:00
|
|
|
const FModifierTypeInfo *fmi = get_fmodifier_typeinfo(i);
|
2014-05-14 14:41:43 +10:00
|
|
|
int index;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-07-03 01:10:46 +00:00
|
|
|
/* Check if modifier is valid for this context. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (fmi == NULL) {
|
2009-07-03 01:10:46 +00:00
|
|
|
continue;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2015-11-23 13:49:52 +11:00
|
|
|
index = RNA_enum_from_value(rna_enum_fmodifier_type_items, fmi->type);
|
2016-04-22 15:23:59 +02:00
|
|
|
if (index != -1) { /* Not all types are implemented yet... */
|
|
|
|
RNA_enum_item_add(&item, &totitem, &rna_enum_fmodifier_type_items[index]);
|
|
|
|
}
|
2009-07-03 01:10:46 +00:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2014-05-14 14:41:43 +10:00
|
|
|
RNA_enum_item_end(&item, &totitem);
|
|
|
|
*r_free = true;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2014-05-14 14:41:43 +10:00
|
|
|
return item;
|
2009-07-03 01:10:46 +00:00
|
|
|
}
|
|
|
|
|
2009-03-15 10:39:02 +00:00
|
|
|
static int graph_fmodifier_add_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
bAnimContext ac;
|
2009-09-25 12:20:31 +00:00
|
|
|
ListBase anim_data = {NULL, NULL};
|
2009-03-15 10:39:02 +00:00
|
|
|
bAnimListElem *ale;
|
2009-09-25 12:20:31 +00:00
|
|
|
int filter;
|
2009-03-15 10:39:02 +00:00
|
|
|
short type;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-03-15 10:39:02 +00:00
|
|
|
/* Get editor data. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
2009-03-15 10:39:02 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-03-15 10:39:02 +00:00
|
|
|
/* Get type of modifier to add. */
|
2012-05-08 20:18:33 +00:00
|
|
|
type = RNA_enum_get(op->ptr, "type");
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-09-25 12:20:31 +00:00
|
|
|
/* Filter data. */
|
2012-05-08 20:18:33 +00:00
|
|
|
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_NODUPLIS);
|
2019-04-22 09:19:45 +10:00
|
|
|
if (RNA_boolean_get(op->ptr, "only_active")) {
|
2012-05-08 20:18:33 +00:00
|
|
|
/* FIXME: enforce in this case only a single channel to get handled? */
|
|
|
|
filter |= ANIMFILTER_ACTIVE;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
else {
|
2012-05-08 20:18:33 +00:00
|
|
|
filter |= (ANIMFILTER_SEL | ANIMFILTER_CURVE_VISIBLE);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2009-09-25 12:20:31 +00:00
|
|
|
ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-03-18 13:04:46 +00:00
|
|
|
/* Add f-modifier to each curve. */
|
2012-05-08 20:18:33 +00:00
|
|
|
for (ale = anim_data.first; ale; ale = ale->next) {
|
|
|
|
FCurve *fcu = (FCurve *)ale->data;
|
2009-09-25 12:20:31 +00:00
|
|
|
FModifier *fcm;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-09-25 12:20:31 +00:00
|
|
|
/* Add F-Modifier of specified type to active F-Curve, and make it the active one. */
|
2017-10-17 19:39:10 +03:00
|
|
|
fcm = add_fmodifier(&fcu->modifiers, type, fcu);
|
2013-03-09 03:46:30 +00:00
|
|
|
if (fcm) {
|
2009-09-25 12:20:31 +00:00
|
|
|
set_active_fmodifier(&fcu->modifiers, fcm);
|
2013-03-09 03:46:30 +00:00
|
|
|
}
|
2011-01-14 05:19:04 +00:00
|
|
|
else {
|
2012-10-26 17:29:21 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "Modifier could not be added (see console for details)");
|
2009-09-25 12:20:31 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2014-05-19 00:24:45 +10:00
|
|
|
ale->update |= ANIM_UPDATE_DEPS;
|
2009-03-18 10:58:18 +00:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2014-05-19 00:24:45 +10:00
|
|
|
ANIM_animdata_update(&ac, &anim_data);
|
|
|
|
ANIM_animdata_freelist(&anim_data);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-03-15 10:39:02 +00:00
|
|
|
/* Set notifier that things have changed. */
|
2016-04-09 18:05:22 +12:00
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-03-15 10:39:02 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void GRAPH_OT_fmodifier_add(wmOperatorType *ot)
|
2009-03-15 10:39:02 +00:00
|
|
|
{
|
2014-05-14 14:41:43 +10:00
|
|
|
PropertyRNA *prop;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-03-15 10:39:02 +00:00
|
|
|
/* Identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Add F-Curve Modifier";
|
|
|
|
ot->idname = "GRAPH_OT_fmodifier_add";
|
2016-04-09 18:05:22 +12:00
|
|
|
ot->description = "Add F-Modifier to the active/selected F-Curves";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-03-15 10:39:02 +00:00
|
|
|
/* API callbacks */
|
2014-05-14 14:41:43 +10:00
|
|
|
ot->invoke = WM_menu_invoke;
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = graph_fmodifier_add_exec;
|
2018-06-04 09:31:30 +02:00
|
|
|
ot->poll = graphop_selected_fcurve_poll;
|
|
|
|
|
2009-03-15 10:39:02 +00:00
|
|
|
/* Flags */
|
2012-05-08 20:18:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-03-15 10:39:02 +00:00
|
|
|
/* Id-props */
|
2015-11-23 13:49:52 +11:00
|
|
|
prop = RNA_def_enum(ot->srna, "type", rna_enum_fmodifier_type_items, 0, "Type", "");
|
2019-05-08 22:02:54 +02:00
|
|
|
RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_ACTION);
|
2014-05-14 14:41:43 +10:00
|
|
|
RNA_def_enum_funcs(prop, graph_fmodifier_itemf);
|
|
|
|
ot->prop = prop;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2011-09-19 12:26:20 +00:00
|
|
|
RNA_def_boolean(
|
|
|
|
ot->srna, "only_active", 1, "Only Active", "Only add F-Modifier to active F-Curve");
|
2009-03-15 10:39:02 +00:00
|
|
|
}
|
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Copy F-Modifiers Operator
|
|
|
|
* \{ */
|
2010-03-18 13:04:46 +00:00
|
|
|
|
|
|
|
static int graph_fmodifier_copy_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
bAnimContext ac;
|
|
|
|
bAnimListElem *ale;
|
2014-04-11 11:25:41 +10:00
|
|
|
bool ok = false;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-03-18 13:04:46 +00:00
|
|
|
/* Get editor data. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
2010-03-18 13:04:46 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-03-18 13:04:46 +00:00
|
|
|
/* Clear buffer first. */
|
2016-04-03 01:18:23 +13:00
|
|
|
ANIM_fmodifiers_copybuf_free();
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-03-18 13:04:46 +00:00
|
|
|
/* Get the active F-Curve. */
|
2012-05-08 20:18:33 +00:00
|
|
|
ale = get_active_fcurve_channel(&ac);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-03-18 13:04:46 +00:00
|
|
|
/* If this exists, call the copy F-Modifiers API function. */
|
|
|
|
if (ale && ale->data) {
|
2012-05-08 20:18:33 +00:00
|
|
|
FCurve *fcu = (FCurve *)ale->data;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-07-06 23:56:59 +00:00
|
|
|
/* TODO: When 'active' vs 'all' boolean is added, change last param! (Joshua Leung 2010) */
|
2012-05-08 20:18:33 +00:00
|
|
|
ok = ANIM_fmodifiers_copy_to_buf(&fcu->modifiers, 0);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-03-18 13:04:46 +00:00
|
|
|
/* Free temp data now. */
|
|
|
|
MEM_freeN(ale);
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-03-18 13:04:46 +00:00
|
|
|
/* Successful or not? */
|
|
|
|
if (ok == 0) {
|
|
|
|
BKE_report(op->reports, RPT_ERROR, "No F-Modifiers available to be copied");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
2020-07-03 17:30:31 +02:00
|
|
|
return OPERATOR_FINISHED;
|
2010-03-18 13:04:46 +00:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void GRAPH_OT_fmodifier_copy(wmOperatorType *ot)
|
2010-03-18 13:04:46 +00:00
|
|
|
{
|
|
|
|
/* Identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Copy F-Modifiers";
|
|
|
|
ot->idname = "GRAPH_OT_fmodifier_copy";
|
|
|
|
ot->description = "Copy the F-Modifier(s) of the active F-Curve";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-03-18 13:04:46 +00:00
|
|
|
/* API callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = graph_fmodifier_copy_exec;
|
2018-06-04 09:31:30 +02:00
|
|
|
ot->poll = graphop_active_fcurve_poll;
|
|
|
|
|
2010-03-18 13:04:46 +00:00
|
|
|
/* Flags */
|
2012-05-08 20:18:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-03-18 13:04:46 +00:00
|
|
|
/* Id-props */
|
2019-04-22 00:18:34 +10:00
|
|
|
#if 0
|
|
|
|
ot->prop = RNA_def_boolean(ot->srna,
|
|
|
|
"all",
|
|
|
|
1,
|
|
|
|
"All F-Modifiers",
|
|
|
|
"Copy all the F-Modifiers, instead of just the active one");
|
|
|
|
#endif
|
2010-03-18 13:04:46 +00:00
|
|
|
}
|
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Paste F-Modifiers Operator
|
|
|
|
* \{ */
|
2010-03-18 13:04:46 +00:00
|
|
|
|
|
|
|
static int graph_fmodifier_paste_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
bAnimContext ac;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-03-18 13:04:46 +00:00
|
|
|
ListBase anim_data = {NULL, NULL};
|
|
|
|
bAnimListElem *ale;
|
2016-04-11 02:39:10 +12:00
|
|
|
int filter;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-04-11 02:39:10 +12:00
|
|
|
const bool replace = RNA_boolean_get(op->ptr, "replace");
|
|
|
|
bool ok = false;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-03-18 13:04:46 +00:00
|
|
|
/* Get editor data. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
2010-03-18 13:04:46 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-03-18 13:04:46 +00:00
|
|
|
/* Filter data. */
|
2016-04-11 02:39:10 +12:00
|
|
|
if (RNA_boolean_get(op->ptr, "only_active")) {
|
|
|
|
/* This should be the default (for buttons) - Just paste to the active FCurve. */
|
|
|
|
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_ACTIVE | ANIMFILTER_FOREDIT |
|
|
|
|
ANIMFILTER_NODUPLIS);
|
|
|
|
}
|
|
|
|
else {
|
2019-04-22 00:18:34 +10:00
|
|
|
/* This is only if the operator gets called from a hotkey or search -
|
|
|
|
* Paste to all visible curves. */
|
2016-04-11 02:39:10 +12:00
|
|
|
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_SEL |
|
|
|
|
ANIMFILTER_FOREDIT | ANIMFILTER_NODUPLIS);
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-03-18 13:04:46 +00:00
|
|
|
ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-03-18 13:04:46 +00:00
|
|
|
/* Paste modifiers. */
|
|
|
|
for (ale = anim_data.first; ale; ale = ale->next) {
|
2012-05-08 20:18:33 +00:00
|
|
|
FCurve *fcu = (FCurve *)ale->data;
|
2014-05-19 00:24:45 +10:00
|
|
|
int tot;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2017-10-17 19:39:10 +03:00
|
|
|
tot = ANIM_fmodifiers_paste_from_buf(&fcu->modifiers, replace, fcu);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2014-05-19 00:24:45 +10:00
|
|
|
if (tot) {
|
|
|
|
ale->update |= ANIM_UPDATE_DEPS;
|
2016-04-11 02:39:10 +12:00
|
|
|
ok = true;
|
2014-05-19 00:24:45 +10:00
|
|
|
}
|
2010-03-18 13:04:46 +00:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2014-05-19 00:24:45 +10:00
|
|
|
if (ok) {
|
|
|
|
ANIM_animdata_update(&ac, &anim_data);
|
|
|
|
}
|
|
|
|
ANIM_animdata_freelist(&anim_data);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-03-18 13:04:46 +00:00
|
|
|
/* Successful or not?. */
|
|
|
|
if (ok) {
|
|
|
|
/* Set notifier that keyframes have changed. */
|
2012-05-08 20:18:33 +00:00
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-03-18 13:04:46 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
2020-07-03 17:30:31 +02:00
|
|
|
|
|
|
|
BKE_report(op->reports, RPT_ERROR, "No F-Modifiers to paste");
|
|
|
|
return OPERATOR_CANCELLED;
|
2010-03-18 13:04:46 +00:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void GRAPH_OT_fmodifier_paste(wmOperatorType *ot)
|
2010-03-18 13:04:46 +00:00
|
|
|
{
|
|
|
|
/* Identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Paste F-Modifiers";
|
|
|
|
ot->idname = "GRAPH_OT_fmodifier_paste";
|
|
|
|
ot->description = "Add copied F-Modifiers to the selected F-Curves";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-03-18 13:04:46 +00:00
|
|
|
/* API callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = graph_fmodifier_paste_exec;
|
|
|
|
ot->poll = graphop_active_fcurve_poll;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-03-18 13:04:46 +00:00
|
|
|
/* Flags */
|
2012-05-08 20:18:33 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-04-11 02:39:10 +12:00
|
|
|
/* Properties */
|
|
|
|
RNA_def_boolean(
|
2020-11-03 17:16:48 +01:00
|
|
|
ot->srna, "only_active", false, "Only Active", "Only paste F-Modifiers on active F-Curve");
|
2018-06-04 09:31:30 +02:00
|
|
|
RNA_def_boolean(
|
|
|
|
ot->srna,
|
|
|
|
"replace",
|
|
|
|
false,
|
|
|
|
"Replace Existing",
|
2016-04-11 02:39:10 +12:00
|
|
|
"Replace existing F-Modifiers, instead of just appending to the end of the existing list");
|
2010-03-18 13:04:46 +00:00
|
|
|
}
|
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/** \} */
|
|
|
|
|
2009-03-15 10:39:02 +00:00
|
|
|
/* ************************************************************************** */
|
2016-04-15 20:04:07 +12:00
|
|
|
/* Drivers */
|
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Copy Driver Variables Operator
|
|
|
|
* \{ */
|
2016-04-15 20:04:07 +12:00
|
|
|
|
|
|
|
static int graph_driver_vars_copy_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
bool ok = false;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-06-16 13:32:50 +03:00
|
|
|
PointerRNA ptr = CTX_data_pointer_get_type(C, "active_editable_fcurve", &RNA_FCurve);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-04-15 20:04:07 +12:00
|
|
|
/* If this exists, call the copy driver vars API function. */
|
2020-03-05 08:33:26 +11:00
|
|
|
FCurve *fcu = ptr.data;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-06-16 13:32:50 +03:00
|
|
|
if (fcu) {
|
2016-04-15 20:04:07 +12:00
|
|
|
ok = ANIM_driver_vars_copy(op->reports, fcu);
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-04-15 20:04:07 +12:00
|
|
|
/* Successful or not?. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ok) {
|
2016-04-15 20:04:07 +12:00
|
|
|
return OPERATOR_FINISHED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2020-07-03 17:30:31 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
2016-04-15 20:04:07 +12:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-04-15 20:04:07 +12:00
|
|
|
void GRAPH_OT_driver_variables_copy(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* Identifiers */
|
|
|
|
ot->name = "Copy Driver Variables";
|
|
|
|
ot->idname = "GRAPH_OT_driver_variables_copy";
|
2019-06-16 13:32:50 +03:00
|
|
|
ot->description = "Copy the driver variables of the active driver";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-04-15 20:04:07 +12:00
|
|
|
/* API callbacks */
|
|
|
|
ot->exec = graph_driver_vars_copy_exec;
|
2019-06-16 13:32:50 +03:00
|
|
|
ot->poll = graphop_active_editable_fcurve_ctx_poll;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-04-15 20:04:07 +12:00
|
|
|
/* Flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
}
|
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Paste Driver Variables Operator
|
|
|
|
* \{ */
|
2016-04-15 20:04:07 +12:00
|
|
|
|
|
|
|
static int graph_driver_vars_paste_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
const bool replace = RNA_boolean_get(op->ptr, "replace");
|
|
|
|
bool ok = false;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-06-16 13:32:50 +03:00
|
|
|
PointerRNA ptr = CTX_data_pointer_get_type(C, "active_editable_fcurve", &RNA_FCurve);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-06-16 13:32:50 +03:00
|
|
|
/* If this exists, call the paste driver vars API function. */
|
2020-03-05 08:33:26 +11:00
|
|
|
FCurve *fcu = ptr.data;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-06-16 13:32:50 +03:00
|
|
|
if (fcu) {
|
|
|
|
ok = ANIM_driver_vars_paste(op->reports, fcu, replace);
|
2016-04-15 20:04:07 +12:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-04-15 20:04:07 +12:00
|
|
|
/* Successful or not?. */
|
|
|
|
if (ok) {
|
2016-04-15 22:08:13 +12:00
|
|
|
/* Rebuild depsgraph, now that there are extra deps here. */
|
2017-06-08 10:14:53 +02:00
|
|
|
DEG_relations_tag_update(CTX_data_main(C));
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-04-15 20:04:07 +12:00
|
|
|
/* Set notifier that keyframes have changed. */
|
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_FRAME, CTX_data_scene(C));
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-04-15 20:04:07 +12:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
2020-07-03 17:30:31 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
2016-04-15 20:04:07 +12:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-04-15 20:04:07 +12:00
|
|
|
void GRAPH_OT_driver_variables_paste(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* Identifiers */
|
|
|
|
ot->name = "Paste Driver Variables";
|
|
|
|
ot->idname = "GRAPH_OT_driver_variables_paste";
|
|
|
|
ot->description = "Add copied driver variables to the active driver";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-04-15 20:04:07 +12:00
|
|
|
/* API callbacks */
|
|
|
|
ot->exec = graph_driver_vars_paste_exec;
|
2019-06-16 13:32:50 +03:00
|
|
|
ot->poll = graphop_active_editable_fcurve_ctx_poll;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-04-15 20:04:07 +12:00
|
|
|
/* Flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-04-15 20:04:07 +12:00
|
|
|
/* Properties */
|
2018-06-04 09:31:30 +02:00
|
|
|
RNA_def_boolean(ot->srna,
|
|
|
|
"replace",
|
|
|
|
false,
|
|
|
|
"Replace Existing",
|
2016-04-15 22:08:13 +12:00
|
|
|
"Replace existing driver variables, instead of just appending to the end of the "
|
|
|
|
"existing list");
|
2016-04-15 20:04:07 +12:00
|
|
|
}
|
|
|
|
|
2020-12-09 14:34:40 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Delete Invalid Drivers Operator
|
|
|
|
* \{ */
|
2018-01-17 12:12:37 +01:00
|
|
|
|
|
|
|
static int graph_driver_delete_invalid_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
bAnimContext ac;
|
|
|
|
ListBase anim_data = {NULL, NULL};
|
|
|
|
bAnimListElem *ale;
|
|
|
|
int filter;
|
|
|
|
bool ok = false;
|
2020-04-03 16:21:24 +11:00
|
|
|
uint deleted = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-17 12:12:37 +01:00
|
|
|
/* Get editor data. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ANIM_animdata_get_context(C, &ac) == 0) {
|
2018-01-17 12:12:37 +01:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-17 12:12:37 +01:00
|
|
|
/* NOTE: We might need a scene update to evaluate the driver flags. */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-17 12:12:37 +01:00
|
|
|
/* Filter data. */
|
2018-01-17 12:38:14 +01:00
|
|
|
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS);
|
2018-01-17 12:12:37 +01:00
|
|
|
ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-17 12:12:37 +01:00
|
|
|
/* Find invalid drivers. */
|
|
|
|
for (ale = anim_data.first; ale; ale = ale->next) {
|
|
|
|
FCurve *fcu = (FCurve *)ale->data;
|
|
|
|
if (ELEM(NULL, fcu, fcu->driver)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!(fcu->driver->flag & DRIVER_FLAG_INVALID)) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-17 12:38:14 +01:00
|
|
|
ok |= ANIM_remove_driver(op->reports, ale->id, fcu->rna_path, fcu->array_index, 0);
|
2018-01-17 12:12:37 +01:00
|
|
|
if (!ok) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
deleted += 1;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-17 12:12:37 +01:00
|
|
|
/* Cleanup. */
|
|
|
|
ANIM_animdata_freelist(&anim_data);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-17 12:12:37 +01:00
|
|
|
if (deleted > 0) {
|
|
|
|
/* Notify the world of any changes. */
|
2018-01-17 12:21:05 +01:00
|
|
|
DEG_relations_tag_update(CTX_data_main(C));
|
2018-01-17 12:12:37 +01:00
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_REMOVED, NULL);
|
|
|
|
WM_reportf(RPT_INFO, "Deleted %u drivers", deleted);
|
2018-01-21 11:41:28 +11:00
|
|
|
}
|
|
|
|
else {
|
2018-01-17 12:12:37 +01:00
|
|
|
WM_report(RPT_INFO, "No drivers deleted");
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-17 12:12:37 +01:00
|
|
|
/* Successful or not?*/
|
|
|
|
if (!ok) {
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-17 12:12:37 +01:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool graph_driver_delete_invalid_poll(bContext *C)
|
2018-01-17 17:14:31 +01:00
|
|
|
{
|
|
|
|
bAnimContext ac;
|
2020-04-03 13:25:03 +02:00
|
|
|
ScrArea *area = CTX_wm_area(C);
|
2018-01-17 17:14:31 +01:00
|
|
|
|
|
|
|
/* Firstly, check if in Graph Editor. */
|
2020-04-03 13:25:03 +02:00
|
|
|
if ((area == NULL) || (area->spacetype != SPACE_GRAPH)) {
|
2020-09-25 10:20:33 +02:00
|
|
|
return false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-01-17 17:14:31 +01:00
|
|
|
|
|
|
|
/* Try to init Anim-Context stuff ourselves and check. */
|
|
|
|
return ANIM_animdata_get_context(C, &ac) != 0;
|
|
|
|
}
|
|
|
|
|
2018-01-17 12:12:37 +01:00
|
|
|
void GRAPH_OT_driver_delete_invalid(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* Identifiers */
|
|
|
|
ot->name = "Delete Invalid Drivers";
|
|
|
|
ot->idname = "GRAPH_OT_driver_delete_invalid";
|
2018-01-28 17:27:53 +01:00
|
|
|
ot->description = "Delete all visible drivers considered invalid";
|
2018-01-17 12:12:37 +01:00
|
|
|
|
|
|
|
/* API callbacks */
|
|
|
|
ot->exec = graph_driver_delete_invalid_exec;
|
2018-01-17 17:14:31 +01:00
|
|
|
ot->poll = graph_driver_delete_invalid_poll;
|
2018-01-17 12:12:37 +01:00
|
|
|
|
|
|
|
/* Flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
}
|
2020-12-09 14:34:40 +11:00
|
|
|
|
|
|
|
/** \} */
|