2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2009-07-02 05:25:14 +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-07-02 05:25:14 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2009 Blender Foundation, Joshua Leung
|
|
|
|
* All rights reserved.
|
2008-12-20 08:24:24 +00:00
|
|
|
*/
|
2011-02-27 20:29:51 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup edanimation
|
2011-02-27 20:29:51 +00:00
|
|
|
*/
|
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <float.h>
|
|
|
|
#include <math.h>
|
2009-02-09 10:04:11 +00:00
|
|
|
#include <stddef.h>
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <stdio.h>
|
2008-12-20 08:24:24 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#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"
|
2008-12-20 08:24:24 +00:00
|
|
|
|
2015-08-16 17:32:01 +10:00
|
|
|
#include "BLT_translation.h"
|
2012-10-18 16:25:58 +00:00
|
|
|
|
2.5: Blender "Animato" - New Animation System
Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future.
Highlights of the new system:
* Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action.
- F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves.
- The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc.
* F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated.
* Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place)
* F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place)
* NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still)
There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details:
http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html
So, what currently works:
* I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code.
* Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock.
* Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc.
Notes:
* Drivers haven't been hooked up yet
* Only objects and data directly linked to objects can be animated.
* Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change).
* Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor)
* I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review.
In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
2009-01-17 03:12:50 +00:00
|
|
|
#include "DNA_anim_types.h"
|
2009-01-24 10:58:34 +00:00
|
|
|
#include "DNA_armature_types.h"
|
2008-12-20 08:24:24 +00:00
|
|
|
#include "DNA_constraint_types.h"
|
|
|
|
#include "DNA_key_types.h"
|
|
|
|
#include "DNA_material_types.h"
|
2010-08-04 04:01:27 +00:00
|
|
|
#include "DNA_object_types.h"
|
2013-01-28 01:02:14 +00:00
|
|
|
#include "DNA_rigidbody_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_scene_types.h"
|
2008-12-20 08:24:24 +00:00
|
|
|
|
|
|
|
#include "BKE_action.h"
|
2020-04-03 13:07:36 +02:00
|
|
|
#include "BKE_anim_data.h"
|
2018-06-07 12:47:00 +02:00
|
|
|
#include "BKE_animsys.h"
|
2011-02-07 11:51:28 +00:00
|
|
|
#include "BKE_armature.h"
|
2018-06-07 12:47:00 +02:00
|
|
|
#include "BKE_context.h"
|
2.5: Blender "Animato" - New Animation System
Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future.
Highlights of the new system:
* Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action.
- F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves.
- The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc.
* F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated.
* Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place)
* F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place)
* NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still)
There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details:
http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html
So, what currently works:
* I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code.
* Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock.
* Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc.
Notes:
* Drivers haven't been hooked up yet
* Only objects and data directly linked to objects can be animated.
* Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change).
* Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor)
* I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review.
In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
2009-01-17 03:12:50 +00:00
|
|
|
#include "BKE_fcurve.h"
|
2020-05-01 12:43:12 +02:00
|
|
|
#include "BKE_fcurve_driver.h"
|
2009-05-11 02:26:18 +00:00
|
|
|
#include "BKE_global.h"
|
2020-03-19 19:37:00 +01:00
|
|
|
#include "BKE_idtype.h"
|
2008-12-20 08:24:24 +00:00
|
|
|
#include "BKE_key.h"
|
2018-06-07 12:47:00 +02:00
|
|
|
#include "BKE_main.h"
|
2008-12-20 08:24:24 +00:00
|
|
|
#include "BKE_material.h"
|
2018-06-07 12:47:00 +02:00
|
|
|
#include "BKE_nla.h"
|
|
|
|
#include "BKE_report.h"
|
2008-12-20 08:24:24 +00:00
|
|
|
|
2017-06-08 10:14:53 +02:00
|
|
|
#include "DEG_depsgraph.h"
|
|
|
|
#include "DEG_depsgraph_build.h"
|
WIP COW Fix: Insert keyframe operators/api now queries depsgraph for evaluated data
When using copy on write, insert keyframe operators were reading from old
bmain data instead of COW data. This meant that inserting keyframes would
often read old/stale data, resulting in invalid keyframes getting created
(e.g. from last transform operation, instead of actual current state).
This commit makes it so that keyframing operators will ask depsgraph for
the evaluated copy of the data, so that it can read values from that. It
introduces a new function - `DEG_get_evaluated_rna_pointer()`, which when
working correctly/fully, should work just like the other `DEG_get_evaluated_*()`
functions, except it lets you pass in an RNA Pointer.
However, currently, this is only done for Pose Bones (as a dirty hack, since this
is an important/pivotal requirement for production) and/or datablock
properties directly (since we can just use the DEG_get_evaluated_id() directly).
on the datablock.
Committing to a branch for now as this all needs more testing. More work to come
later at a more sane time of day!
2018-05-18 20:36:48 +02:00
|
|
|
#include "DEG_depsgraph_query.h"
|
2017-06-08 10:14:53 +02:00
|
|
|
|
2008-12-29 01:19:25 +00:00
|
|
|
#include "ED_anim_api.h"
|
|
|
|
#include "ED_keyframes_edit.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "ED_keyframing.h"
|
2014-04-26 01:44:55 +09:00
|
|
|
#include "ED_object.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "ED_screen.h"
|
2008-12-20 08:24:24 +00:00
|
|
|
|
2009-02-11 12:19:42 +00:00
|
|
|
#include "UI_interface.h"
|
2012-03-08 14:04:06 +00:00
|
|
|
#include "UI_resources.h"
|
2009-02-11 12:19:42 +00:00
|
|
|
|
2009-01-05 09:54:39 +00:00
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
2.5: Blender "Animato" - New Animation System
Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future.
Highlights of the new system:
* Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action.
- F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves.
- The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc.
* F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated.
* Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place)
* F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place)
* NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still)
There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details:
http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html
So, what currently works:
* I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code.
* Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock.
* Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc.
Notes:
* Drivers haven't been hooked up yet
* Only objects and data directly linked to objects can be animated.
* Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change).
* Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor)
* I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review.
In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
2009-01-17 03:12:50 +00:00
|
|
|
#include "RNA_access.h"
|
|
|
|
#include "RNA_define.h"
|
2011-01-03 05:36:52 +00:00
|
|
|
#include "RNA_enum_types.h"
|
2008-12-20 08:24:24 +00:00
|
|
|
|
2009-04-13 02:40:56 +00:00
|
|
|
#include "anim_intern.h"
|
2008-12-20 08:24:24 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static KeyingSet *keyingset_get_from_op_with_error(wmOperator *op,
|
|
|
|
PropertyRNA *prop,
|
|
|
|
Scene *scene);
|
2019-04-10 11:27:32 +02:00
|
|
|
|
2009-12-14 12:09:20 +00:00
|
|
|
/* ************************************************** */
|
|
|
|
/* Keyframing Setting Wrangling */
|
|
|
|
|
|
|
|
/* Get the active settings for keyframing settings from context (specifically the given scene) */
|
2020-03-06 16:45:56 +11:00
|
|
|
eInsertKeyFlags ANIM_get_keyframing_flags(Scene *scene, const bool use_autokey_mode)
|
2009-12-14 12:09:20 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
eInsertKeyFlags flag = INSERTKEY_NOFLAGS;
|
|
|
|
|
|
|
|
/* standard flags */
|
|
|
|
{
|
|
|
|
/* visual keying */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (IS_AUTOKEY_FLAG(scene, AUTOMATKEY)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
flag |= INSERTKEY_MATRIX;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* only needed */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (IS_AUTOKEY_FLAG(scene, INSERTNEEDED)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
flag |= INSERTKEY_NEEDED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* default F-Curve color mode - RGB from XYZ indices */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (IS_AUTOKEY_FLAG(scene, XYZ2RGB)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
flag |= INSERTKEY_XYZ2RGB;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* only if including settings from the autokeying mode... */
|
2020-03-06 16:45:56 +11:00
|
|
|
if (use_autokey_mode) {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* keyframing mode - only replace existing keyframes */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (IS_AUTOKEY_MODE(scene, EDITKEYS)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
flag |= INSERTKEY_REPLACE;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* cycle-aware keyframe insertion - preserve cycle period and flow */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (IS_AUTOKEY_FLAG(scene, CYCLEAWARE)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
flag |= INSERTKEY_CYCLE_AWARE;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return flag;
|
2009-12-14 12:09:20 +00:00
|
|
|
}
|
|
|
|
|
2.5: Blender "Animato" - New Animation System
Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future.
Highlights of the new system:
* Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action.
- F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves.
- The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc.
* F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated.
* Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place)
* F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place)
* NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still)
There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details:
http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html
So, what currently works:
* I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code.
* Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock.
* Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc.
Notes:
* Drivers haven't been hooked up yet
* Only objects and data directly linked to objects can be animated.
* Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change).
* Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor)
* I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review.
In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
2009-01-17 03:12:50 +00:00
|
|
|
/* ******************************************* */
|
|
|
|
/* Animation Data Validation */
|
2008-12-29 01:19:25 +00:00
|
|
|
|
2018-06-04 09:31:30 +02:00
|
|
|
/* Get (or add relevant data to be able to do so) the Active Action for the given
|
2009-04-15 01:10:36 +00:00
|
|
|
* Animation Data block, given an ID block where the Animation Data should reside.
|
2008-12-29 01:19:25 +00:00
|
|
|
*/
|
2020-03-06 13:41:27 +11:00
|
|
|
bAction *ED_id_action_ensure(Main *bmain, ID *id)
|
2008-12-29 01:19:25 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
AnimData *adt;
|
|
|
|
|
|
|
|
/* init animdata if none available yet */
|
|
|
|
adt = BKE_animdata_from_id(id);
|
2020-03-06 13:41:27 +11:00
|
|
|
if (adt == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
adt = BKE_animdata_add_id(id);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
if (adt == NULL) {
|
|
|
|
/* if still none (as not allowed to add, or ID doesn't have animdata for some reason) */
|
|
|
|
printf("ERROR: Couldn't add AnimData (ID = %s)\n", (id) ? (id->name) : "<None>");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* init action if none available yet */
|
|
|
|
/* TODO: need some wizardry to handle NLA stuff correct */
|
2020-03-06 13:41:27 +11:00
|
|
|
if (adt->action == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* init action name from name of ID block */
|
|
|
|
char actname[sizeof(id->name) - 2];
|
|
|
|
BLI_snprintf(actname, sizeof(actname), "%sAction", id->name + 2);
|
|
|
|
|
|
|
|
/* create action */
|
|
|
|
adt->action = BKE_action_add(bmain, actname);
|
|
|
|
|
|
|
|
/* set ID-type from ID-block that this is going to be assigned to
|
|
|
|
* so that users can't accidentally break actions by assigning them
|
|
|
|
* to the wrong places
|
|
|
|
*/
|
2020-09-25 11:07:32 +02:00
|
|
|
BKE_animdata_action_ensure_idroot(id, adt->action);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* Tag depsgraph to be rebuilt to include time dependency. */
|
|
|
|
DEG_relations_tag_update(bmain);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEG_id_tag_update(&adt->action->id, ID_RECALC_ANIMATION_NO_FLUSH);
|
|
|
|
|
|
|
|
/* return the action */
|
|
|
|
return adt->action;
|
2009-04-15 01:10:36 +00:00
|
|
|
}
|
|
|
|
|
2020-03-06 13:41:27 +11:00
|
|
|
/**
|
|
|
|
* Find the F-Curve from the Active Action,
|
2009-04-15 01:10:36 +00:00
|
|
|
* for the given Animation Data block. This assumes that all the destinations are valid.
|
|
|
|
*/
|
2020-03-06 13:41:27 +11:00
|
|
|
FCurve *ED_action_fcurve_find(struct bAction *act, const char rna_path[], const int array_index)
|
|
|
|
{
|
|
|
|
/* Sanity checks. */
|
|
|
|
if (ELEM(NULL, act, rna_path)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2020-06-05 09:30:15 +02:00
|
|
|
return BKE_fcurve_find(&act->curves, rna_path, array_index);
|
2020-03-06 13:41:27 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get (or add relevant data to be able to do so) F-Curve from the Active Action,
|
|
|
|
* for the given Animation Data block. This assumes that all the destinations are valid.
|
|
|
|
*/
|
|
|
|
FCurve *ED_action_fcurve_ensure(struct Main *bmain,
|
|
|
|
struct bAction *act,
|
|
|
|
const char group[],
|
|
|
|
struct PointerRNA *ptr,
|
|
|
|
const char rna_path[],
|
|
|
|
const int array_index)
|
2009-04-15 01:10:36 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bActionGroup *agrp;
|
|
|
|
FCurve *fcu;
|
|
|
|
|
2020-03-06 13:41:27 +11:00
|
|
|
/* Sanity checks. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ELEM(NULL, act, rna_path)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* try to find f-curve matching for this setting
|
|
|
|
* - add if not found and allowed to add one
|
|
|
|
* TODO: add auto-grouping support? how this works will need to be resolved
|
|
|
|
*/
|
2020-06-05 09:30:15 +02:00
|
|
|
fcu = BKE_fcurve_find(&act->curves, rna_path, array_index);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-06 13:41:27 +11:00
|
|
|
if (fcu == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* use default settings to make a F-Curve */
|
2020-06-05 08:41:09 +02:00
|
|
|
fcu = BKE_fcurve_create();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
fcu->flag = (FCURVE_VISIBLE | FCURVE_SELECTED);
|
2019-10-01 21:38:44 +03:00
|
|
|
fcu->auto_smoothing = U.auto_smoothing_new;
|
2019-04-22 09:19:45 +10:00
|
|
|
if (BLI_listbase_is_empty(&act->curves)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
fcu->flag |= FCURVE_ACTIVE; /* first one added active */
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* store path - make copy, and store that */
|
|
|
|
fcu->rna_path = BLI_strdup(rna_path);
|
|
|
|
fcu->array_index = array_index;
|
|
|
|
|
|
|
|
/* if a group name has been provided, try to add or find a group, then add F-Curve to it */
|
|
|
|
if (group) {
|
|
|
|
/* try to find group */
|
|
|
|
agrp = BKE_action_group_find_name(act, group);
|
|
|
|
|
|
|
|
/* no matching groups, so add one */
|
|
|
|
if (agrp == NULL) {
|
|
|
|
agrp = action_groups_add_new(act, group);
|
|
|
|
|
|
|
|
/* sync bone group colors if applicable */
|
|
|
|
if (ptr && (ptr->type == &RNA_PoseBone)) {
|
2019-08-23 09:52:12 +02:00
|
|
|
Object *ob = (Object *)ptr->owner_id;
|
2020-03-05 08:33:26 +11:00
|
|
|
bPoseChannel *pchan = ptr->data;
|
2019-04-17 06:17:24 +02:00
|
|
|
bPose *pose = ob->pose;
|
|
|
|
bActionGroup *grp;
|
|
|
|
|
|
|
|
/* find bone group (if present), and use the color from that */
|
|
|
|
grp = (bActionGroup *)BLI_findlink(&pose->agroups, (pchan->agrp_index - 1));
|
|
|
|
if (grp) {
|
|
|
|
agrp->customCol = grp->customCol;
|
|
|
|
action_group_colors_sync(agrp, grp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add F-Curve to group */
|
|
|
|
action_groups_add_channel(act, agrp, fcu);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* just add F-Curve to end of Action's list */
|
|
|
|
BLI_addtail(&act->curves, fcu);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* New f-curve was added, meaning it's possible that it affects
|
|
|
|
* dependency graph component which wasn't previously animated.
|
|
|
|
*/
|
|
|
|
DEG_relations_tag_update(bmain);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return the F-Curve */
|
|
|
|
return fcu;
|
2008-12-29 01:19:25 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 02:37:14 +13:00
|
|
|
/* Helper for update_autoflags_fcurve() */
|
2013-12-17 09:40:52 +01:00
|
|
|
static void update_autoflags_fcurve_direct(FCurve *fcu, PropertyRNA *prop)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* set additional flags for the F-Curve (i.e. only integer values) */
|
|
|
|
fcu->flag &= ~(FCURVE_INT_VALUES | FCURVE_DISCRETE_VALUES);
|
|
|
|
switch (RNA_property_type(prop)) {
|
|
|
|
case PROP_FLOAT:
|
|
|
|
/* do nothing */
|
|
|
|
break;
|
|
|
|
case PROP_INT:
|
|
|
|
/* do integer (only 'whole' numbers) interpolation between all points */
|
|
|
|
fcu->flag |= FCURVE_INT_VALUES;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* do 'discrete' (i.e. enum, boolean values which cannot take any intermediate
|
|
|
|
* values at all) interpolation between all points
|
|
|
|
* - however, we must also ensure that evaluated values are only integers still
|
|
|
|
*/
|
|
|
|
fcu->flag |= (FCURVE_DISCRETE_VALUES | FCURVE_INT_VALUES);
|
|
|
|
break;
|
|
|
|
}
|
2013-12-17 09:40:52 +01:00
|
|
|
}
|
|
|
|
|
2014-02-22 02:37:14 +13:00
|
|
|
/* Update integer/discrete flags of the FCurve (used when creating/inserting keyframes,
|
|
|
|
* but also through RNA when editing an ID prop, see T37103).
|
2013-12-17 09:40:52 +01:00
|
|
|
*/
|
2013-12-17 10:46:21 +01:00
|
|
|
void update_autoflags_fcurve(FCurve *fcu, bContext *C, ReportList *reports, PointerRNA *ptr)
|
2013-12-17 09:40:52 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PointerRNA tmp_ptr;
|
|
|
|
PropertyRNA *prop;
|
|
|
|
int old_flag = fcu->flag;
|
|
|
|
|
2019-08-23 09:52:12 +02:00
|
|
|
if ((ptr->owner_id == NULL) && (ptr->data == NULL)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_report(reports, RPT_ERROR, "No RNA pointer available to retrieve values for this fcurve");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to get property we should be affecting */
|
|
|
|
if (RNA_path_resolve_property(ptr, fcu->rna_path, &tmp_ptr, &prop) == false) {
|
|
|
|
/* property not found... */
|
2019-08-23 09:52:12 +02:00
|
|
|
const char *idname = (ptr->owner_id) ? ptr->owner_id->name : TIP_("<No ID pointer>");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
BKE_reportf(reports,
|
|
|
|
RPT_ERROR,
|
|
|
|
"Could not update flags for this fcurve, as RNA path is invalid for the given ID "
|
|
|
|
"(ID = %s, path = %s)",
|
|
|
|
idname,
|
|
|
|
fcu->rna_path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* update F-Curve flags */
|
|
|
|
update_autoflags_fcurve_direct(fcu, prop);
|
|
|
|
|
|
|
|
if (old_flag != fcu->flag) {
|
|
|
|
/* Same as if keyframes had been changed */
|
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
|
|
|
|
}
|
2013-12-17 09:40:52 +01:00
|
|
|
}
|
|
|
|
|
2008-12-20 08:24:24 +00:00
|
|
|
/* ************************************************** */
|
|
|
|
/* KEYFRAME INSERTION */
|
|
|
|
|
2018-10-14 13:04:34 +03:00
|
|
|
/* Move the point where a key is about to be inserted to be inside the main cycle range.
|
|
|
|
* Returns the type of the cycle if it is enabled and valid.
|
|
|
|
*/
|
|
|
|
static eFCU_Cycle_Type remap_cyclic_keyframe_location(FCurve *fcu, float *px, float *py)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (fcu->totvert < 2 || !fcu->bezt) {
|
|
|
|
return FCU_CYCLE_NONE;
|
|
|
|
}
|
2018-10-14 13:04:34 +03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
eFCU_Cycle_Type type = BKE_fcurve_get_cycle_type(fcu);
|
2018-10-14 13:04:34 +03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (type == FCU_CYCLE_NONE) {
|
|
|
|
return FCU_CYCLE_NONE;
|
|
|
|
}
|
2018-10-14 13:04:34 +03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BezTriple *first = &fcu->bezt[0], *last = &fcu->bezt[fcu->totvert - 1];
|
|
|
|
float start = first->vec[1][0], end = last->vec[1][0];
|
2018-10-14 13:04:34 +03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (start >= end) {
|
|
|
|
return FCU_CYCLE_NONE;
|
|
|
|
}
|
2018-10-14 13:04:34 +03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (*px < start || *px > end) {
|
|
|
|
float period = end - start;
|
|
|
|
float step = floorf((*px - start) / period);
|
|
|
|
*px -= step * period;
|
2018-10-14 13:04:34 +03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (type == FCU_CYCLE_OFFSET) {
|
|
|
|
/* Nasty check to handle the case when the modes are different better. */
|
|
|
|
FMod_Cycles *data = ((FModifier *)fcu->modifiers.first)->data;
|
|
|
|
short mode = (step >= 0) ? data->after_mode : data->before_mode;
|
2018-10-14 13:04:34 +03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (mode == FCM_EXTRAPOLATE_CYCLIC_OFFSET) {
|
|
|
|
*py -= step * (last->vec[1][1] - first->vec[1][1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-14 13:04:34 +03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return type;
|
2018-10-14 13:04:34 +03:00
|
|
|
}
|
|
|
|
|
2008-12-20 08:24:24 +00:00
|
|
|
/* -------------- BezTriple Insertion -------------------- */
|
|
|
|
|
2018-10-14 13:04:34 +03:00
|
|
|
/* Change the Y position of a keyframe to match the input, adjusting handles. */
|
|
|
|
static void replace_bezt_keyframe_ypos(BezTriple *dst, const BezTriple *bezt)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* just change the values when replacing, so as to not overwrite handles */
|
|
|
|
float dy = bezt->vec[1][1] - dst->vec[1][1];
|
2018-10-14 13:04:34 +03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* just apply delta value change to the handle values */
|
|
|
|
dst->vec[0][1] += dy;
|
|
|
|
dst->vec[1][1] += dy;
|
|
|
|
dst->vec[2][1] += dy;
|
2018-10-14 13:04:34 +03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
dst->f1 = bezt->f1;
|
|
|
|
dst->f2 = bezt->f2;
|
|
|
|
dst->f3 = bezt->f3;
|
2018-10-14 13:04:34 +03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* TODO: perform some other operations? */
|
2018-10-14 13:04:34 +03:00
|
|
|
}
|
|
|
|
|
2018-06-04 09:31:30 +02:00
|
|
|
/* This function adds a given BezTriple to an F-Curve. It will allocate
|
2008-12-20 08:24:24 +00:00
|
|
|
* memory for the array if needed, and will insert the BezTriple into a
|
|
|
|
* suitable place in chronological order.
|
2018-06-01 18:19:39 +02:00
|
|
|
*
|
|
|
|
* NOTE: any recalculate of the F-Curve that needs to be done will need to
|
2012-05-08 11:48:19 +00:00
|
|
|
* be done by the caller.
|
2008-12-20 08:24:24 +00:00
|
|
|
*/
|
2018-04-18 18:21:27 +02:00
|
|
|
int insert_bezt_fcurve(FCurve *fcu, const BezTriple *bezt, eInsertKeyFlags flag)
|
2008-12-20 08:24:24 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
/* are there already keyframes? */
|
|
|
|
if (fcu->bezt) {
|
|
|
|
bool replace;
|
2020-10-13 16:36:31 +11:00
|
|
|
i = BKE_fcurve_bezt_binarysearch_index(fcu->bezt, bezt->vec[1][0], fcu->totvert, &replace);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* replace an existing keyframe? */
|
|
|
|
if (replace) {
|
|
|
|
/* sanity check: 'i' may in rare cases exceed arraylen */
|
|
|
|
if ((i >= 0) && (i < fcu->totvert)) {
|
|
|
|
if (flag & INSERTKEY_OVERWRITE_FULL) {
|
|
|
|
fcu->bezt[i] = *bezt;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
replace_bezt_keyframe_ypos(&fcu->bezt[i], bezt);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flag & INSERTKEY_CYCLE_AWARE) {
|
2019-04-22 00:18:34 +10:00
|
|
|
/* If replacing an end point of a cyclic curve without offset,
|
|
|
|
* modify the other end too. */
|
2019-04-17 06:17:24 +02:00
|
|
|
if ((i == 0 || i == fcu->totvert - 1) &&
|
|
|
|
BKE_fcurve_get_cycle_type(fcu) == FCU_CYCLE_PERFECT) {
|
|
|
|
replace_bezt_keyframe_ypos(&fcu->bezt[i == 0 ? fcu->totvert - 1 : 0], bezt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* keyframing modes allow to not replace keyframe */
|
|
|
|
else if ((flag & INSERTKEY_REPLACE) == 0) {
|
|
|
|
/* insert new - if we're not restricted to replacing keyframes only */
|
|
|
|
BezTriple *newb = MEM_callocN((fcu->totvert + 1) * sizeof(BezTriple), "beztriple");
|
|
|
|
|
2019-04-22 00:18:34 +10:00
|
|
|
/* Add the beztriples that should occur before the beztriple to be pasted
|
|
|
|
* (originally in fcu). */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (i > 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
memcpy(newb, fcu->bezt, i * sizeof(BezTriple));
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* add beztriple to paste at index i */
|
|
|
|
*(newb + i) = *bezt;
|
|
|
|
|
|
|
|
/* add the beztriples that occur after the beztriple to be pasted (originally in fcu) */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (i < fcu->totvert) {
|
2019-04-17 06:17:24 +02:00
|
|
|
memcpy(newb + i + 1, fcu->bezt + i, (fcu->totvert - i) * sizeof(BezTriple));
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* replace (+ free) old with new, only if necessary to do so */
|
|
|
|
MEM_freeN(fcu->bezt);
|
|
|
|
fcu->bezt = newb;
|
|
|
|
|
|
|
|
fcu->totvert++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* no keyframes already, but can only add if...
|
|
|
|
* 1) keyframing modes say that keyframes can only be replaced, so adding new ones won't know
|
|
|
|
* 2) there are no samples on the curve
|
2020-10-10 18:19:55 +11:00
|
|
|
* NOTE: maybe we may want to allow this later when doing samples -> bezt conversions,
|
|
|
|
* but for now, having both is asking for trouble
|
2019-04-17 06:17:24 +02:00
|
|
|
*/
|
|
|
|
else if ((flag & INSERTKEY_REPLACE) == 0 && (fcu->fpt == NULL)) {
|
|
|
|
/* create new keyframes array */
|
|
|
|
fcu->bezt = MEM_callocN(sizeof(BezTriple), "beztriple");
|
|
|
|
*(fcu->bezt) = *bezt;
|
|
|
|
fcu->totvert = 1;
|
|
|
|
}
|
|
|
|
/* cannot add anything */
|
|
|
|
else {
|
|
|
|
/* return error code -1 to prevent any misunderstandings */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we need to return the index, so that some tools which do post-processing can
|
|
|
|
* detect where we added the BezTriple in the array
|
|
|
|
*/
|
|
|
|
return i;
|
2008-12-20 08:24:24 +00:00
|
|
|
}
|
|
|
|
|
2020-10-05 13:16:10 +02:00
|
|
|
/** Update the FCurve to allow insertion of `bezt` without modifying the curve shape.
|
|
|
|
*
|
|
|
|
* Checks whether it is necessary to apply Bezier subdivision due to involvement of non-auto
|
|
|
|
* handles. If necessary, changes `bezt` handles from Auto to Aligned.
|
|
|
|
*
|
|
|
|
* \param bezt: key being inserted
|
|
|
|
* \param prev: keyframe before that key
|
|
|
|
* \param next: keyframe after that key
|
|
|
|
*/
|
|
|
|
static void subdivide_nonauto_handles(const FCurve *fcu,
|
|
|
|
BezTriple *bezt,
|
|
|
|
BezTriple *prev,
|
|
|
|
BezTriple *next)
|
|
|
|
{
|
|
|
|
if (prev->ipo != BEZT_IPO_BEZ || bezt->ipo != BEZT_IPO_BEZ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't change Vector handles, or completely auto regions. */
|
|
|
|
const bool bezt_auto = BEZT_IS_AUTOH(bezt) || (bezt->h1 == HD_VECT && bezt->h2 == HD_VECT);
|
|
|
|
const bool prev_auto = BEZT_IS_AUTOH(prev) || (prev->h2 == HD_VECT);
|
|
|
|
const bool next_auto = BEZT_IS_AUTOH(next) || (next->h1 == HD_VECT);
|
|
|
|
if (bezt_auto && prev_auto && next_auto) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Subdivide the curve. */
|
|
|
|
float delta;
|
2020-10-13 16:36:31 +11:00
|
|
|
if (!BKE_fcurve_bezt_subdivide_handles(bezt, prev, next, &delta)) {
|
2020-10-05 13:16:10 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Decide when to force auto to manual. */
|
2020-10-07 16:40:51 +02:00
|
|
|
if (!BEZT_IS_AUTOH(bezt)) {
|
2020-10-05 13:16:10 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((prev_auto || next_auto) && fcu->auto_smoothing == FCURVE_SMOOTH_CONT_ACCEL) {
|
|
|
|
const float hx = bezt->vec[1][0] - bezt->vec[0][0];
|
|
|
|
const float dx = bezt->vec[1][0] - prev->vec[1][0];
|
|
|
|
|
|
|
|
/* This mode always uses 1/3 of key distance for handle x size. */
|
|
|
|
const bool auto_works_well = fabsf(hx - dx / 3.0f) < 0.001f;
|
|
|
|
if (auto_works_well) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Turn off auto mode. */
|
|
|
|
bezt->h1 = bezt->h2 = HD_ALIGN;
|
|
|
|
}
|
|
|
|
|
2016-03-24 18:05:10 +11:00
|
|
|
/**
|
2019-04-14 10:48:42 +02:00
|
|
|
* This function is a wrapper for #insert_bezt_fcurve(), and should be used when
|
2018-06-01 18:19:39 +02:00
|
|
|
* adding a new keyframe to a curve, when the keyframe doesn't exist anywhere else yet.
|
2009-09-04 04:27:06 +00:00
|
|
|
* It returns the index at which the keyframe was added.
|
2016-03-13 03:49:26 +13:00
|
|
|
*
|
2019-04-14 10:48:42 +02:00
|
|
|
* \param keyframe_type: The type of keyframe (#eBezTriple_KeyframeType).
|
2018-06-01 18:19:39 +02:00
|
|
|
* \param flag: Optional flags (eInsertKeyFlags) for controlling how keys get added
|
2019-04-14 10:48:42 +02:00
|
|
|
* and/or whether updates get done.
|
2008-12-20 08:24:24 +00:00
|
|
|
*/
|
2019-04-17 06:17:24 +02:00
|
|
|
int insert_vert_fcurve(
|
|
|
|
FCurve *fcu, float x, float y, eBezTriple_KeyframeType keyframe_type, eInsertKeyFlags flag)
|
2008-12-20 08:24:24 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BezTriple beztr = {{{0}}};
|
2020-04-03 16:21:24 +11:00
|
|
|
uint oldTot = fcu->totvert;
|
2019-04-17 06:17:24 +02:00
|
|
|
int a;
|
|
|
|
|
|
|
|
/* set all three points, for nicer start position
|
|
|
|
* NOTE: +/- 1 on vec.x for left and right handles is so that 'free' handles work ok...
|
|
|
|
*/
|
|
|
|
beztr.vec[0][0] = x - 1.0f;
|
|
|
|
beztr.vec[0][1] = y;
|
|
|
|
beztr.vec[1][0] = x;
|
|
|
|
beztr.vec[1][1] = y;
|
|
|
|
beztr.vec[2][0] = x + 1.0f;
|
|
|
|
beztr.vec[2][1] = y;
|
|
|
|
beztr.f1 = beztr.f2 = beztr.f3 = SELECT;
|
|
|
|
|
|
|
|
/* set default handle types and interpolation mode */
|
|
|
|
if (flag & INSERTKEY_NO_USERPREF) {
|
|
|
|
/* for Py-API, we want scripts to have predictable behavior,
|
|
|
|
* hence the option to not depend on the userpref defaults
|
|
|
|
*/
|
|
|
|
beztr.h1 = beztr.h2 = HD_AUTO_ANIM;
|
|
|
|
beztr.ipo = BEZT_IPO_BEZ;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* for UI usage - defaults should come from the userprefs and/or toolsettings */
|
|
|
|
beztr.h1 = beztr.h2 = U.keyhandles_new; /* use default handle type here */
|
|
|
|
|
|
|
|
/* use default interpolation mode, with exceptions for int/discrete values */
|
|
|
|
beztr.ipo = U.ipo_new;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* interpolation type used is constrained by the type of values the curve can take */
|
|
|
|
if (fcu->flag & FCURVE_DISCRETE_VALUES) {
|
|
|
|
beztr.ipo = BEZT_IPO_CONST;
|
|
|
|
}
|
|
|
|
else if ((beztr.ipo == BEZT_IPO_BEZ) && (fcu->flag & FCURVE_INT_VALUES)) {
|
|
|
|
beztr.ipo = BEZT_IPO_LIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set keyframe type value (supplied), which should come from the scene settings in most cases */
|
|
|
|
BEZKEYTYPE(&beztr) = keyframe_type;
|
|
|
|
|
|
|
|
/* set default values for "easing" interpolation mode settings
|
|
|
|
* NOTE: Even if these modes aren't currently used, if users switch
|
|
|
|
* to these later, we want these to work in a sane way out of
|
|
|
|
* the box.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* "back" easing - this value used to be used when overshoot=0, but that
|
|
|
|
* introduced discontinuities in how the param worked. */
|
|
|
|
beztr.back = 1.70158f;
|
|
|
|
|
2019-07-07 15:38:41 +10:00
|
|
|
/* "elastic" easing - values here were hand-optimized for a default duration of
|
2019-04-17 06:17:24 +02:00
|
|
|
* ~10 frames (typical mograph motion length) */
|
|
|
|
beztr.amplitude = 0.8f;
|
|
|
|
beztr.period = 4.1f;
|
|
|
|
|
|
|
|
/* add temp beztriple to keyframes */
|
|
|
|
a = insert_bezt_fcurve(fcu, &beztr, flag);
|
2020-10-12 16:55:46 +02:00
|
|
|
BKE_fcurve_active_keyframe_set(fcu, &fcu->bezt[a]);
|
2020-10-07 08:27:58 -05:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* what if 'a' is a negative index?
|
|
|
|
* for now, just exit to prevent any segfaults
|
|
|
|
*/
|
2019-04-22 09:19:45 +10:00
|
|
|
if (a < 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return -1;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* set handletype and interpolation */
|
|
|
|
if ((fcu->totvert > 2) && (flag & INSERTKEY_REPLACE) == 0) {
|
|
|
|
BezTriple *bezt = (fcu->bezt + a);
|
|
|
|
|
2019-04-22 00:18:34 +10:00
|
|
|
/* Set interpolation from previous (if available),
|
|
|
|
* but only if we didn't just replace some keyframe:
|
|
|
|
* - Replacement is indicated by no-change in number of verts.
|
|
|
|
* - When replacing, the user may have specified some interpolation that should be kept.
|
2019-04-17 06:17:24 +02:00
|
|
|
*/
|
|
|
|
if (fcu->totvert > oldTot) {
|
2019-04-22 09:19:45 +10:00
|
|
|
if (a > 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
bezt->ipo = (bezt - 1)->ipo;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
else if (a < fcu->totvert - 1) {
|
2019-04-17 06:17:24 +02:00
|
|
|
bezt->ipo = (bezt + 1)->ipo;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-10-05 13:16:10 +02:00
|
|
|
if (0 < a && a < (fcu->totvert - 1) && (flag & INSERTKEY_OVERWRITE_FULL) == 0) {
|
|
|
|
subdivide_nonauto_handles(fcu, bezt, bezt - 1, bezt + 1);
|
|
|
|
}
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
2020-10-05 13:16:10 +02:00
|
|
|
/* don't recalculate handles if fast is set
|
|
|
|
* - this is a hack to make importers faster
|
|
|
|
* - we may calculate twice (due to autohandle needing to be calculated twice)
|
|
|
|
*/
|
|
|
|
if ((flag & INSERTKEY_FAST) == 0) {
|
|
|
|
calchandles_fcurve(fcu);
|
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* return the index at which the keyframe was added */
|
|
|
|
return a;
|
2008-12-20 08:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------- 'Smarter' Keyframing Functions -------------------- */
|
|
|
|
/* return codes for new_key_needed */
|
2011-02-17 22:34:41 +00:00
|
|
|
enum {
|
2019-04-17 06:17:24 +02:00
|
|
|
KEYNEEDED_DONTADD = 0,
|
|
|
|
KEYNEEDED_JUSTADD,
|
|
|
|
KEYNEEDED_DELPREV,
|
|
|
|
KEYNEEDED_DELNEXT,
|
2011-02-17 22:34:41 +00:00
|
|
|
} /*eKeyNeededStatus*/;
|
2008-12-20 08:24:24 +00:00
|
|
|
|
|
|
|
/* This helper function determines whether a new keyframe is needed */
|
|
|
|
/* Cases where keyframes should not be added:
|
2018-11-14 12:53:15 +11:00
|
|
|
* 1. Keyframe to be added between two keyframes with similar values
|
|
|
|
* 2. Keyframe to be added on frame where two keyframes are already situated
|
|
|
|
* 3. Keyframe lies at point that intersects the linear line between two keyframes
|
2008-12-20 08:24:24 +00:00
|
|
|
*/
|
2012-05-08 11:48:19 +00:00
|
|
|
static short new_key_needed(FCurve *fcu, float cFrame, float nValue)
|
2008-12-20 08:24:24 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* safety checking */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (fcu == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return KEYNEEDED_JUSTADD;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2020-09-09 18:41:07 +02:00
|
|
|
int totCount = fcu->totvert;
|
2019-04-22 09:19:45 +10:00
|
|
|
if (totCount == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return KEYNEEDED_JUSTADD;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* loop through checking if any are the same */
|
2020-09-09 18:41:07 +02:00
|
|
|
BezTriple *bezt = fcu->bezt;
|
|
|
|
BezTriple *prev = NULL;
|
|
|
|
for (int i = 0; i < totCount; i++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
float prevPosi = 0.0f, prevVal = 0.0f;
|
|
|
|
float beztPosi = 0.0f, beztVal = 0.0f;
|
|
|
|
|
|
|
|
/* get current time+value */
|
|
|
|
beztPosi = bezt->vec[1][0];
|
|
|
|
beztVal = bezt->vec[1][1];
|
|
|
|
|
|
|
|
if (prev) {
|
|
|
|
/* there is a keyframe before the one currently being examined */
|
|
|
|
|
|
|
|
/* get previous time+value */
|
|
|
|
prevPosi = prev->vec[1][0];
|
|
|
|
prevVal = prev->vec[1][1];
|
|
|
|
|
|
|
|
/* keyframe to be added at point where there are already two similar points? */
|
|
|
|
if (IS_EQF(prevPosi, cFrame) && IS_EQF(beztPosi, cFrame) && IS_EQF(beztPosi, prevPosi)) {
|
|
|
|
return KEYNEEDED_DONTADD;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* keyframe between prev+current points ? */
|
|
|
|
if ((prevPosi <= cFrame) && (cFrame <= beztPosi)) {
|
|
|
|
/* is the value of keyframe to be added the same as keyframes on either side ? */
|
|
|
|
if (IS_EQF(prevVal, nValue) && IS_EQF(beztVal, nValue) && IS_EQF(prevVal, beztVal)) {
|
|
|
|
return KEYNEEDED_DONTADD;
|
|
|
|
}
|
|
|
|
|
2020-07-03 14:51:19 +02:00
|
|
|
float realVal;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-07-03 14:51:19 +02:00
|
|
|
/* get real value of curve at that point */
|
|
|
|
realVal = evaluate_fcurve(fcu, cFrame);
|
|
|
|
|
|
|
|
/* compare whether it's the same as proposed */
|
|
|
|
if (IS_EQF(realVal, nValue)) {
|
|
|
|
return KEYNEEDED_DONTADD;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2020-07-03 14:51:19 +02:00
|
|
|
return KEYNEEDED_JUSTADD;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* new keyframe before prev beztriple? */
|
|
|
|
if (cFrame < prevPosi) {
|
|
|
|
/* A new keyframe will be added. However, whether the previous beztriple
|
|
|
|
* stays around or not depends on whether the values of previous/current
|
|
|
|
* beztriples and new keyframe are the same.
|
|
|
|
*/
|
2019-04-22 09:19:45 +10:00
|
|
|
if (IS_EQF(prevVal, nValue) && IS_EQF(beztVal, nValue) && IS_EQF(prevVal, beztVal)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return KEYNEEDED_DELNEXT;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2020-07-03 14:51:19 +02:00
|
|
|
|
|
|
|
return KEYNEEDED_JUSTADD;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* just add a keyframe if there's only one keyframe
|
|
|
|
* and the new one occurs before the existing one does.
|
|
|
|
*/
|
2019-04-22 09:19:45 +10:00
|
|
|
if ((cFrame < beztPosi) && (totCount == 1)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return KEYNEEDED_JUSTADD;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* continue. frame to do not yet passed (or other conditions not met) */
|
|
|
|
if (i < (totCount - 1)) {
|
|
|
|
prev = bezt;
|
|
|
|
bezt++;
|
|
|
|
}
|
2019-04-22 09:19:45 +10:00
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Frame in which to add a new-keyframe occurs after all other keys
|
|
|
|
* -> If there are at least two existing keyframes, then if the values of the
|
|
|
|
* last two keyframes and the new-keyframe match, the last existing keyframe
|
|
|
|
* gets deleted as it is no longer required.
|
|
|
|
* -> Otherwise, a keyframe is just added. 1.0 is added so that fake-2nd-to-last
|
|
|
|
* keyframe is not equal to last keyframe.
|
|
|
|
*/
|
|
|
|
bezt = (fcu->bezt + (fcu->totvert - 1));
|
2020-09-09 18:41:07 +02:00
|
|
|
float valA = bezt->vec[1][1];
|
|
|
|
float valB;
|
2019-04-22 09:19:45 +10:00
|
|
|
if (prev) {
|
2019-04-17 06:17:24 +02:00
|
|
|
valB = prev->vec[1][1];
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
valB = bezt->vec[1][1] + 1.0f;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (IS_EQF(valA, nValue) && IS_EQF(valA, valB)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return KEYNEEDED_DELPREV;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2020-07-03 14:51:19 +02:00
|
|
|
|
|
|
|
return KEYNEEDED_JUSTADD;
|
2008-12-20 08:24:24 +00:00
|
|
|
}
|
|
|
|
|
2.5: Blender "Animato" - New Animation System
Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future.
Highlights of the new system:
* Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action.
- F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves.
- The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc.
* F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated.
* Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place)
* F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place)
* NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still)
There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details:
http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html
So, what currently works:
* I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code.
* Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock.
* Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc.
Notes:
* Drivers haven't been hooked up yet
* Only objects and data directly linked to objects can be animated.
* Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change).
* Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor)
* I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review.
In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
2009-01-17 03:12:50 +00:00
|
|
|
/* ------------------ RNA Data-Access Functions ------------------ */
|
|
|
|
|
|
|
|
/* Try to read value using RNA-properties obtained already */
|
2019-07-31 12:22:43 +02:00
|
|
|
static float *setting_get_rna_values(
|
|
|
|
PointerRNA *ptr, PropertyRNA *prop, float *buffer, int buffer_size, int *r_count)
|
2.5: Blender "Animato" - New Animation System
Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future.
Highlights of the new system:
* Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action.
- F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves.
- The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc.
* F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated.
* Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place)
* F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place)
* NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still)
There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details:
http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html
So, what currently works:
* I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code.
* Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock.
* Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc.
Notes:
* Drivers haven't been hooked up yet
* Only objects and data directly linked to objects can be animated.
* Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change).
* Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor)
* I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review.
In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
2009-01-17 03:12:50 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(buffer_size >= 1);
|
|
|
|
|
|
|
|
float *values = buffer;
|
|
|
|
|
|
|
|
if (RNA_property_array_check(prop)) {
|
|
|
|
int length = *r_count = RNA_property_array_length(ptr, prop);
|
|
|
|
bool *tmp_bool;
|
|
|
|
int *tmp_int;
|
|
|
|
|
|
|
|
if (length > buffer_size) {
|
|
|
|
values = MEM_malloc_arrayN(sizeof(float), length, __func__);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (RNA_property_type(prop)) {
|
|
|
|
case PROP_BOOLEAN:
|
|
|
|
tmp_bool = MEM_malloc_arrayN(sizeof(*tmp_bool), length, __func__);
|
|
|
|
RNA_property_boolean_get_array(ptr, prop, tmp_bool);
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
values[i] = (float)tmp_bool[i];
|
|
|
|
}
|
|
|
|
MEM_freeN(tmp_bool);
|
|
|
|
break;
|
|
|
|
case PROP_INT:
|
|
|
|
tmp_int = MEM_malloc_arrayN(sizeof(*tmp_int), length, __func__);
|
|
|
|
RNA_property_int_get_array(ptr, prop, tmp_int);
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
values[i] = (float)tmp_int[i];
|
|
|
|
}
|
|
|
|
MEM_freeN(tmp_int);
|
|
|
|
break;
|
|
|
|
case PROP_FLOAT:
|
|
|
|
RNA_property_float_get_array(ptr, prop, values);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
memset(values, 0, sizeof(float) * length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*r_count = 1;
|
|
|
|
|
|
|
|
switch (RNA_property_type(prop)) {
|
|
|
|
case PROP_BOOLEAN:
|
|
|
|
*values = (float)RNA_property_boolean_get(ptr, prop);
|
|
|
|
break;
|
|
|
|
case PROP_INT:
|
|
|
|
*values = (float)RNA_property_int_get(ptr, prop);
|
|
|
|
break;
|
|
|
|
case PROP_FLOAT:
|
|
|
|
*values = RNA_property_float_get(ptr, prop);
|
|
|
|
break;
|
|
|
|
case PROP_ENUM:
|
|
|
|
*values = (float)RNA_property_enum_get(ptr, prop);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*values = 0.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return values;
|
2.5: Blender "Animato" - New Animation System
Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future.
Highlights of the new system:
* Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action.
- F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves.
- The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc.
* F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated.
* Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place)
* F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place)
* NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still)
There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details:
http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html
So, what currently works:
* I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code.
* Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock.
* Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc.
Notes:
* Drivers haven't been hooked up yet
* Only objects and data directly linked to objects can be animated.
* Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change).
* Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor)
* I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review.
In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
2009-01-17 03:12:50 +00:00
|
|
|
}
|
|
|
|
|
2008-12-20 08:24:24 +00:00
|
|
|
/* ------------------ 'Visual' Keyframing Functions ------------------ */
|
|
|
|
|
|
|
|
/* internal status codes for visualkey_can_use */
|
|
|
|
enum {
|
2019-04-17 06:17:24 +02:00
|
|
|
VISUALKEY_NONE = 0,
|
|
|
|
VISUALKEY_LOC,
|
|
|
|
VISUALKEY_ROT,
|
|
|
|
VISUALKEY_SCA,
|
2008-12-20 08:24:24 +00:00
|
|
|
};
|
|
|
|
|
2018-06-04 09:31:30 +02:00
|
|
|
/* This helper function determines if visual-keyframing should be used when
|
2008-12-20 08:24:24 +00:00
|
|
|
* inserting keyframes for the given channel. As visual-keyframing only works
|
2018-06-01 18:19:39 +02:00
|
|
|
* on Object and Pose-Channel blocks, this should only get called for those
|
|
|
|
* blocktypes, when using "standard" keying but 'Visual Keying' option in Auto-Keying
|
2008-12-20 08:24:24 +00:00
|
|
|
* settings is on.
|
|
|
|
*/
|
2013-01-28 01:41:15 +00:00
|
|
|
static bool visualkey_can_use(PointerRNA *ptr, PropertyRNA *prop)
|
2008-12-20 08:24:24 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bConstraint *con = NULL;
|
|
|
|
short searchtype = VISUALKEY_NONE;
|
|
|
|
bool has_rigidbody = false;
|
|
|
|
bool has_parent = false;
|
|
|
|
const char *identifier = NULL;
|
|
|
|
|
|
|
|
/* validate data */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ELEM(NULL, ptr, ptr->data, prop)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* get first constraint and determine type of keyframe constraints to check for
|
|
|
|
* - constraints can be on either Objects or PoseChannels, so we only check if the
|
|
|
|
* ptr->type is RNA_Object or RNA_PoseBone, which are the RNA wrapping-info for
|
|
|
|
* those structs, allowing us to identify the owner of the data
|
|
|
|
*/
|
|
|
|
if (ptr->type == &RNA_Object) {
|
|
|
|
/* Object */
|
2020-03-05 08:33:26 +11:00
|
|
|
Object *ob = ptr->data;
|
2019-04-17 06:17:24 +02:00
|
|
|
RigidBodyOb *rbo = ob->rigidbody_object;
|
|
|
|
|
|
|
|
con = ob->constraints.first;
|
|
|
|
identifier = RNA_property_identifier(prop);
|
|
|
|
has_parent = (ob->parent != NULL);
|
|
|
|
|
|
|
|
/* active rigidbody objects only, as only those are affected by sim */
|
|
|
|
has_rigidbody = ((rbo) && (rbo->type == RBO_TYPE_ACTIVE));
|
|
|
|
}
|
|
|
|
else if (ptr->type == &RNA_PoseBone) {
|
|
|
|
/* Pose Channel */
|
2020-03-05 08:33:26 +11:00
|
|
|
bPoseChannel *pchan = ptr->data;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
con = pchan->constraints.first;
|
|
|
|
identifier = RNA_property_identifier(prop);
|
|
|
|
has_parent = (pchan->parent != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if any data to search using */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ELEM(NULL, con, identifier) && (has_parent == false) && (has_rigidbody == false)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* location or rotation identifiers only... */
|
|
|
|
if (identifier == NULL) {
|
|
|
|
printf("%s failed: NULL identifier\n", __func__);
|
|
|
|
return false;
|
|
|
|
}
|
2020-07-03 14:51:19 +02:00
|
|
|
|
|
|
|
if (strstr(identifier, "location")) {
|
2019-04-17 06:17:24 +02:00
|
|
|
searchtype = VISUALKEY_LOC;
|
|
|
|
}
|
|
|
|
else if (strstr(identifier, "rotation")) {
|
|
|
|
searchtype = VISUALKEY_ROT;
|
|
|
|
}
|
|
|
|
else if (strstr(identifier, "scale")) {
|
|
|
|
searchtype = VISUALKEY_SCA;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("%s failed: identifier - '%s'\n", __func__, identifier);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* only search if a searchtype and initial constraint are available */
|
|
|
|
if (searchtype) {
|
|
|
|
/* parent or rigidbody are always matching */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (has_parent || has_rigidbody) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* constraints */
|
|
|
|
for (; con; con = con->next) {
|
|
|
|
/* only consider constraint if it is not disabled, and has influence */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (con->flag & CONSTRAINT_DISABLE) {
|
2019-04-17 06:17:24 +02:00
|
|
|
continue;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
if (con->enforce == 0.0f) {
|
2019-04-17 06:17:24 +02:00
|
|
|
continue;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* some constraints may alter these transforms */
|
|
|
|
switch (con->type) {
|
|
|
|
/* multi-transform constraints */
|
|
|
|
case CONSTRAINT_TYPE_CHILDOF:
|
|
|
|
case CONSTRAINT_TYPE_ARMATURE:
|
|
|
|
return true;
|
|
|
|
case CONSTRAINT_TYPE_TRANSFORM:
|
|
|
|
case CONSTRAINT_TYPE_TRANSLIKE:
|
|
|
|
return true;
|
|
|
|
case CONSTRAINT_TYPE_FOLLOWPATH:
|
|
|
|
return true;
|
|
|
|
case CONSTRAINT_TYPE_KINEMATIC:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/* single-transform constraints */
|
|
|
|
case CONSTRAINT_TYPE_TRACKTO:
|
2019-04-22 09:19:45 +10:00
|
|
|
if (searchtype == VISUALKEY_ROT) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case CONSTRAINT_TYPE_DAMPTRACK:
|
2019-04-22 09:19:45 +10:00
|
|
|
if (searchtype == VISUALKEY_ROT) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case CONSTRAINT_TYPE_ROTLIMIT:
|
2019-04-22 09:19:45 +10:00
|
|
|
if (searchtype == VISUALKEY_ROT) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case CONSTRAINT_TYPE_LOCLIMIT:
|
2019-04-22 09:19:45 +10:00
|
|
|
if (searchtype == VISUALKEY_LOC) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case CONSTRAINT_TYPE_SIZELIMIT:
|
2019-04-22 09:19:45 +10:00
|
|
|
if (searchtype == VISUALKEY_SCA) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case CONSTRAINT_TYPE_DISTLIMIT:
|
2019-04-22 09:19:45 +10:00
|
|
|
if (searchtype == VISUALKEY_LOC) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case CONSTRAINT_TYPE_ROTLIKE:
|
2019-04-22 09:19:45 +10:00
|
|
|
if (searchtype == VISUALKEY_ROT) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case CONSTRAINT_TYPE_LOCLIKE:
|
2019-04-22 09:19:45 +10:00
|
|
|
if (searchtype == VISUALKEY_LOC) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case CONSTRAINT_TYPE_SIZELIKE:
|
2019-04-22 09:19:45 +10:00
|
|
|
if (searchtype == VISUALKEY_SCA) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case CONSTRAINT_TYPE_LOCKTRACK:
|
2019-04-22 09:19:45 +10:00
|
|
|
if (searchtype == VISUALKEY_ROT) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case CONSTRAINT_TYPE_MINMAX:
|
2019-04-22 09:19:45 +10:00
|
|
|
if (searchtype == VISUALKEY_LOC) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* when some condition is met, this function returns, so that means we've got nothing */
|
|
|
|
return false;
|
2008-12-20 08:24:24 +00:00
|
|
|
}
|
|
|
|
|
2018-06-04 09:31:30 +02:00
|
|
|
/* This helper function extracts the value to use for visual-keyframing
|
2008-12-20 08:24:24 +00:00
|
|
|
* In the event that it is not possible to perform visual keying, try to fall-back
|
2.5: Blender "Animato" - New Animation System
Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future.
Highlights of the new system:
* Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action.
- F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves.
- The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc.
* F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated.
* Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place)
* F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place)
* NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still)
There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details:
http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html
So, what currently works:
* I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code.
* Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock.
* Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc.
Notes:
* Drivers haven't been hooked up yet
* Only objects and data directly linked to objects can be animated.
* Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change).
* Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor)
* I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review.
In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
2009-01-17 03:12:50 +00:00
|
|
|
* to using the default method. Assumes that all data it has been passed is valid.
|
2008-12-20 08:24:24 +00:00
|
|
|
*/
|
2019-07-31 12:22:43 +02:00
|
|
|
static float *visualkey_get_values(
|
|
|
|
PointerRNA *ptr, PropertyRNA *prop, float *buffer, int buffer_size, int *r_count)
|
2008-12-20 08:24:24 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(buffer_size >= 4);
|
|
|
|
|
|
|
|
const char *identifier = RNA_property_identifier(prop);
|
|
|
|
float tmat[4][4];
|
|
|
|
int rotmode;
|
|
|
|
|
|
|
|
/* handle for Objects or PoseChannels only
|
|
|
|
* - only Location, Rotation or Scale keyframes are supported currently
|
|
|
|
* - constraints can be on either Objects or PoseChannels, so we only check if the
|
|
|
|
* ptr->type is RNA_Object or RNA_PoseBone, which are the RNA wrapping-info for
|
|
|
|
* those structs, allowing us to identify the owner of the data
|
|
|
|
* - assume that array_index will be sane
|
|
|
|
*/
|
|
|
|
if (ptr->type == &RNA_Object) {
|
2020-03-05 08:33:26 +11:00
|
|
|
Object *ob = ptr->data;
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Loc code is specific... */
|
|
|
|
if (strstr(identifier, "location")) {
|
2019-07-31 12:22:43 +02:00
|
|
|
copy_v3_v3(buffer, ob->obmat[3]);
|
2019-04-17 06:17:24 +02:00
|
|
|
*r_count = 3;
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2019-07-31 12:22:43 +02:00
|
|
|
copy_m4_m4(tmat, ob->obmat);
|
|
|
|
rotmode = ob->rotmode;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else if (ptr->type == &RNA_PoseBone) {
|
2020-03-05 08:33:26 +11:00
|
|
|
bPoseChannel *pchan = ptr->data;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-07-31 12:22:43 +02:00
|
|
|
BKE_armature_mat_pose_to_bone(pchan, pchan->pose_mat, tmat);
|
|
|
|
rotmode = pchan->rotmode;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* Loc code is specific... */
|
|
|
|
if (strstr(identifier, "location")) {
|
|
|
|
/* only use for non-connected bones */
|
|
|
|
if ((pchan->bone->parent == NULL) || !(pchan->bone->flag & BONE_CONNECTED)) {
|
|
|
|
copy_v3_v3(buffer, tmat[3]);
|
|
|
|
*r_count = 3;
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2019-07-31 12:22:43 +02:00
|
|
|
return setting_get_rna_values(ptr, prop, buffer, buffer_size, r_count);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Rot/Scale code are common! */
|
|
|
|
if (strstr(identifier, "rotation_euler")) {
|
|
|
|
mat4_to_eulO(buffer, rotmode, tmat);
|
|
|
|
|
|
|
|
*r_count = 3;
|
|
|
|
return buffer;
|
|
|
|
}
|
2020-07-03 14:51:19 +02:00
|
|
|
|
|
|
|
if (strstr(identifier, "rotation_quaternion")) {
|
2019-04-17 06:17:24 +02:00
|
|
|
float mat3[3][3];
|
|
|
|
|
|
|
|
copy_m3_m4(mat3, tmat);
|
|
|
|
mat3_to_quat_is_ok(buffer, mat3);
|
|
|
|
|
|
|
|
*r_count = 4;
|
|
|
|
return buffer;
|
|
|
|
}
|
2020-07-03 14:51:19 +02:00
|
|
|
|
|
|
|
if (strstr(identifier, "rotation_axis_angle")) {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* w = 0, x,y,z = 1,2,3 */
|
|
|
|
mat4_to_axis_angle(buffer + 1, buffer, tmat);
|
|
|
|
|
|
|
|
*r_count = 4;
|
|
|
|
return buffer;
|
|
|
|
}
|
2020-07-03 14:51:19 +02:00
|
|
|
|
|
|
|
if (strstr(identifier, "scale")) {
|
2019-04-17 06:17:24 +02:00
|
|
|
mat4_to_size(buffer, tmat);
|
|
|
|
|
|
|
|
*r_count = 3;
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* as the function hasn't returned yet, read value from system in the default way */
|
2019-07-31 12:22:43 +02:00
|
|
|
return setting_get_rna_values(ptr, prop, buffer, buffer_size, r_count);
|
2008-12-20 08:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------- Insert Key API ------------------------- */
|
|
|
|
|
2019-04-29 19:29:41 +10:00
|
|
|
/**
|
|
|
|
* Retrieve current property values to keyframe,
|
|
|
|
* possibly applying NLA correction when necessary.
|
|
|
|
*/
|
2019-07-31 12:22:43 +02:00
|
|
|
static float *get_keyframe_values(ReportList *reports,
|
2019-04-17 06:17:24 +02:00
|
|
|
PointerRNA ptr,
|
|
|
|
PropertyRNA *prop,
|
|
|
|
int index,
|
|
|
|
struct NlaKeyframingContext *nla_context,
|
|
|
|
eInsertKeyFlags flag,
|
|
|
|
float *buffer,
|
|
|
|
int buffer_size,
|
|
|
|
int *r_count,
|
|
|
|
bool *r_force_all)
|
2019-01-08 18:49:38 +03:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
float *values;
|
|
|
|
|
|
|
|
if ((flag & INSERTKEY_MATRIX) && (visualkey_can_use(&ptr, prop))) {
|
|
|
|
/* visual-keying is only available for object and pchan datablocks, as
|
|
|
|
* it works by keyframing using a value extracted from the final matrix
|
|
|
|
* instead of using the kt system to extract a value.
|
|
|
|
*/
|
2019-07-31 12:22:43 +02:00
|
|
|
values = visualkey_get_values(&ptr, prop, buffer, buffer_size, r_count);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* read value from system */
|
2019-07-31 12:22:43 +02:00
|
|
|
values = setting_get_rna_values(&ptr, prop, buffer, buffer_size, r_count);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* adjust the value for NLA factors */
|
|
|
|
if (!BKE_animsys_nla_remap_keyframe_values(
|
|
|
|
nla_context, &ptr, prop, values, *r_count, index, r_force_all)) {
|
|
|
|
BKE_report(
|
|
|
|
reports, RPT_ERROR, "Could not insert keyframe due to zero NLA influence or base value");
|
|
|
|
|
|
|
|
if (values != buffer) {
|
|
|
|
MEM_freeN(values);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return values;
|
2019-01-08 18:49:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Insert the specified keyframe value into a single F-Curve. */
|
2019-04-17 06:17:24 +02:00
|
|
|
static bool insert_keyframe_value(ReportList *reports,
|
|
|
|
PointerRNA *ptr,
|
|
|
|
PropertyRNA *prop,
|
|
|
|
FCurve *fcu,
|
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,
|
2019-04-17 06:17:24 +02:00
|
|
|
float curval,
|
|
|
|
eBezTriple_KeyframeType keytype,
|
|
|
|
eInsertKeyFlags flag)
|
2019-01-08 18:49:38 +03:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* F-Curve not editable? */
|
2020-06-05 09:30:15 +02:00
|
|
|
if (BKE_fcurve_is_keyframable(fcu) == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_reportf(
|
|
|
|
reports,
|
|
|
|
RPT_ERROR,
|
|
|
|
"F-Curve with path '%s[%d]' cannot be keyframed, ensure that it is not locked or sampled, "
|
|
|
|
"and try removing F-Modifiers",
|
|
|
|
fcu->rna_path,
|
|
|
|
fcu->array_index);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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 = anim_eval_context->eval_time;
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* adjust frame on which to add keyframe */
|
|
|
|
if ((flag & INSERTKEY_DRIVER) && (fcu->driver)) {
|
|
|
|
PathResolvedRNA anim_rna;
|
|
|
|
|
|
|
|
if (RNA_path_resolved_create(ptr, prop, fcu->array_index, &anim_rna)) {
|
|
|
|
/* for making it easier to add corrective drivers... */
|
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
|
|
|
cfra = evaluate_driver(&anim_rna, fcu->driver, fcu->driver, anim_eval_context);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
cfra = 0.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* adjust coordinates for cycle aware insertion */
|
|
|
|
if (flag & INSERTKEY_CYCLE_AWARE) {
|
|
|
|
if (remap_cyclic_keyframe_location(fcu, &cfra, &curval) != FCU_CYCLE_PERFECT) {
|
|
|
|
/* inhibit action from insert_vert_fcurve unless it's a perfect cycle */
|
|
|
|
flag &= ~INSERTKEY_CYCLE_AWARE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* only insert keyframes where they are needed */
|
|
|
|
if (flag & INSERTKEY_NEEDED) {
|
|
|
|
short insert_mode;
|
|
|
|
|
|
|
|
/* check whether this curve really needs a new keyframe */
|
|
|
|
insert_mode = new_key_needed(fcu, cfra, curval);
|
|
|
|
|
|
|
|
/* only return success if keyframe added */
|
|
|
|
if (insert_mode == KEYNEEDED_DONTADD) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* insert new keyframe at current frame */
|
|
|
|
if (insert_vert_fcurve(fcu, cfra, curval, keytype, flag) < 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* delete keyframe immediately before/after newly added */
|
|
|
|
switch (insert_mode) {
|
|
|
|
case KEYNEEDED_DELPREV:
|
|
|
|
delete_fcurve_key(fcu, fcu->totvert - 2, 1);
|
|
|
|
break;
|
|
|
|
case KEYNEEDED_DELNEXT:
|
|
|
|
delete_fcurve_key(fcu, 1, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2020-07-03 14:51:19 +02:00
|
|
|
|
|
|
|
/* just insert keyframe */
|
|
|
|
return insert_vert_fcurve(fcu, cfra, curval, keytype, flag) >= 0;
|
2019-01-08 18:49:38 +03:00
|
|
|
}
|
|
|
|
|
2018-06-04 09:31:30 +02:00
|
|
|
/* Secondary Keyframing API call:
|
2019-04-22 00:18:34 +10:00
|
|
|
* Use this when validation of necessary animation data is not necessary,
|
|
|
|
* since an RNA-pointer to the necessary data being keyframed,
|
|
|
|
* and a pointer to the F-Curve to use have both been provided.
|
2009-07-08 05:00:10 +00:00
|
|
|
*
|
2019-01-08 18:49:38 +03:00
|
|
|
* This function can't keyframe quaternion channels on some NLA strip types.
|
|
|
|
*
|
2018-11-14 12:53:15 +11:00
|
|
|
* keytype is the "keyframe type" (eBezTriple_KeyframeType), as shown in the Dope Sheet.
|
2016-03-13 03:49:26 +13:00
|
|
|
*
|
2018-11-14 12:53:15 +11:00
|
|
|
* The flag argument is used for special settings that alter the behavior of
|
|
|
|
* the keyframe insertion. These include the 'visual' keyframing modes, quick refresh,
|
|
|
|
* and extra keyframe filtering.
|
2009-07-08 05:00:10 +00:00
|
|
|
*/
|
2019-07-31 12:22:43 +02:00
|
|
|
bool insert_keyframe_direct(ReportList *reports,
|
2019-04-17 06:17:24 +02:00
|
|
|
PointerRNA ptr,
|
|
|
|
PropertyRNA *prop,
|
|
|
|
FCurve *fcu,
|
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,
|
2019-04-17 06:17:24 +02:00
|
|
|
eBezTriple_KeyframeType keytype,
|
|
|
|
struct NlaKeyframingContext *nla_context,
|
|
|
|
eInsertKeyFlags flag)
|
2009-07-08 05:00:10 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
float curval = 0.0f;
|
|
|
|
|
|
|
|
/* no F-Curve to add keyframe to? */
|
|
|
|
if (fcu == NULL) {
|
|
|
|
BKE_report(reports, RPT_ERROR, "No F-Curve to add keyframes to");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if no property given yet, try to validate from F-Curve info */
|
2019-08-23 09:52:12 +02:00
|
|
|
if ((ptr.owner_id == NULL) && (ptr.data == NULL)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_report(
|
|
|
|
reports, RPT_ERROR, "No RNA pointer available to retrieve values for keyframing from");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (prop == NULL) {
|
|
|
|
PointerRNA tmp_ptr;
|
|
|
|
|
|
|
|
/* try to get property we should be affecting */
|
|
|
|
if (RNA_path_resolve_property(&ptr, fcu->rna_path, &tmp_ptr, &prop) == false) {
|
|
|
|
/* property not found... */
|
2019-08-23 09:52:12 +02:00
|
|
|
const char *idname = (ptr.owner_id) ? ptr.owner_id->name : TIP_("<No ID pointer>");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
BKE_reportf(reports,
|
|
|
|
RPT_ERROR,
|
|
|
|
"Could not insert keyframe, as RNA path is invalid for the given ID (ID = %s, "
|
|
|
|
"path = %s)",
|
|
|
|
idname,
|
|
|
|
fcu->rna_path);
|
|
|
|
return false;
|
|
|
|
}
|
2020-07-03 14:51:19 +02:00
|
|
|
|
|
|
|
/* property found, so overwrite 'ptr' to make later code easier */
|
|
|
|
ptr = tmp_ptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* update F-Curve flags to ensure proper behavior for property type */
|
|
|
|
update_autoflags_fcurve_direct(fcu, prop);
|
|
|
|
|
|
|
|
/* Obtain the value to insert. */
|
|
|
|
float value_buffer[RNA_MAX_ARRAY_LENGTH];
|
|
|
|
int value_count;
|
|
|
|
int index = fcu->array_index;
|
|
|
|
|
2019-07-31 12:22:43 +02:00
|
|
|
float *values = get_keyframe_values(reports,
|
2019-04-17 06:17:24 +02:00
|
|
|
ptr,
|
|
|
|
prop,
|
|
|
|
index,
|
|
|
|
nla_context,
|
|
|
|
flag,
|
|
|
|
value_buffer,
|
|
|
|
RNA_MAX_ARRAY_LENGTH,
|
|
|
|
&value_count,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (values == NULL) {
|
|
|
|
/* This happens if NLA rejects this insertion. */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index >= 0 && index < value_count) {
|
|
|
|
curval = values[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (values != value_buffer) {
|
|
|
|
MEM_freeN(values);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
return insert_keyframe_value(reports, &ptr, prop, fcu, anim_eval_context, curval, keytype, flag);
|
2019-01-08 18:49:38 +03:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-01-08 18:49:38 +03:00
|
|
|
/* Find or create the FCurve based on the given path, and insert the specified value into it. */
|
2019-04-17 06:17:24 +02:00
|
|
|
static bool insert_keyframe_fcurve_value(Main *bmain,
|
|
|
|
ReportList *reports,
|
|
|
|
PointerRNA *ptr,
|
|
|
|
PropertyRNA *prop,
|
|
|
|
bAction *act,
|
|
|
|
const char group[],
|
|
|
|
const char rna_path[],
|
|
|
|
int 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
|
|
|
const AnimationEvalContext *anim_eval_context,
|
2019-04-17 06:17:24 +02:00
|
|
|
float curval,
|
|
|
|
eBezTriple_KeyframeType keytype,
|
|
|
|
eInsertKeyFlags flag)
|
2019-01-08 18:49:38 +03:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* make sure the F-Curve exists
|
|
|
|
* - if we're replacing keyframes only, DO NOT create new F-Curves if they do not exist yet
|
|
|
|
* but still try to get the F-Curve if it exists...
|
|
|
|
*/
|
2019-05-11 21:16:46 +03:00
|
|
|
bool can_create_curve = (flag & (INSERTKEY_REPLACE | INSERTKEY_AVAILABLE)) == 0;
|
2020-03-06 13:41:27 +11:00
|
|
|
FCurve *fcu = can_create_curve ?
|
|
|
|
ED_action_fcurve_ensure(bmain, act, group, ptr, rna_path, array_index) :
|
|
|
|
ED_action_fcurve_find(act, rna_path, array_index);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* we may not have a F-Curve when we're replacing only... */
|
|
|
|
if (fcu) {
|
|
|
|
/* set color mode if the F-Curve is new (i.e. without any keyframes) */
|
|
|
|
if ((fcu->totvert == 0) && (flag & INSERTKEY_XYZ2RGB)) {
|
|
|
|
/* for Loc/Rot/Scale and also Color F-Curves, the color of the F-Curve in the Graph Editor,
|
|
|
|
* is determined by the array index for the F-Curve
|
|
|
|
*/
|
|
|
|
PropertySubType prop_subtype = RNA_property_subtype(prop);
|
|
|
|
if (ELEM(prop_subtype, PROP_TRANSLATION, PROP_XYZ, PROP_EULER, PROP_COLOR, PROP_COORDS)) {
|
|
|
|
fcu->color_mode = FCURVE_COLOR_AUTO_RGB;
|
|
|
|
}
|
|
|
|
else if (ELEM(prop_subtype, PROP_QUATERNION)) {
|
|
|
|
fcu->color_mode = FCURVE_COLOR_AUTO_YRGB;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* update F-Curve flags to ensure proper behavior for property type */
|
|
|
|
update_autoflags_fcurve_direct(fcu, prop);
|
|
|
|
|
|
|
|
/* insert keyframe */
|
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
|
|
|
return insert_keyframe_value(
|
|
|
|
reports, ptr, prop, fcu, anim_eval_context, curval, keytype, flag);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2020-07-03 14:51:19 +02:00
|
|
|
|
|
|
|
return false;
|
2009-07-08 05:00:10 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
static AnimationEvalContext nla_time_remap(const AnimationEvalContext *anim_eval_context,
|
|
|
|
PointerRNA *id_ptr,
|
|
|
|
AnimData *adt,
|
|
|
|
bAction *act,
|
|
|
|
ListBase *nla_cache,
|
|
|
|
NlaKeyframingContext **r_nla_context)
|
|
|
|
{
|
|
|
|
if (adt && adt->action == act) {
|
|
|
|
/* Get NLA context for value remapping. */
|
|
|
|
*r_nla_context = BKE_animsys_get_nla_keyframing_context(
|
|
|
|
nla_cache, id_ptr, adt, anim_eval_context, false);
|
|
|
|
|
|
|
|
/* Apply NLA-mapping to frame. */
|
|
|
|
const float remapped_frame = BKE_nla_tweakedit_remap(
|
|
|
|
adt, anim_eval_context->eval_time, NLATIME_CONVERT_UNMAP);
|
|
|
|
return BKE_animsys_eval_context_construct_at(anim_eval_context, remapped_frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
*r_nla_context = NULL;
|
|
|
|
return *anim_eval_context;
|
|
|
|
}
|
|
|
|
|
2020-03-06 16:45:56 +11:00
|
|
|
/**
|
|
|
|
* Main Keyframing API call
|
|
|
|
*
|
2018-11-14 12:53:15 +11:00
|
|
|
* Use this when validation of necessary animation data is necessary, since it may not exist yet.
|
2018-06-01 18:19:39 +02:00
|
|
|
*
|
2018-11-14 12:53:15 +11:00
|
|
|
* The flag argument is used for special settings that alter the behavior of
|
|
|
|
* the keyframe insertion. These include the 'visual' keyframing modes, quick refresh,
|
|
|
|
* and extra keyframe filtering.
|
2009-11-04 14:06:10 +00:00
|
|
|
*
|
2018-11-14 12:53:15 +11:00
|
|
|
* index of -1 keys all array indices
|
2020-03-06 16:45:56 +11:00
|
|
|
*
|
|
|
|
* \return The number of key-frames inserted.
|
2008-12-20 08:24:24 +00:00
|
|
|
*/
|
2020-03-06 16:45:56 +11:00
|
|
|
int insert_keyframe(Main *bmain,
|
|
|
|
ReportList *reports,
|
|
|
|
ID *id,
|
|
|
|
bAction *act,
|
|
|
|
const char group[],
|
|
|
|
const char rna_path[],
|
|
|
|
int 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
|
|
|
const AnimationEvalContext *anim_eval_context,
|
2020-03-06 16:45:56 +11:00
|
|
|
eBezTriple_KeyframeType keytype,
|
|
|
|
ListBase *nla_cache,
|
|
|
|
eInsertKeyFlags flag)
|
2018-06-04 09:31:30 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PointerRNA id_ptr, ptr;
|
|
|
|
PropertyRNA *prop = NULL;
|
|
|
|
AnimData *adt;
|
|
|
|
ListBase tmp_nla_cache = {NULL, NULL};
|
|
|
|
NlaKeyframingContext *nla_context = NULL;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/* validate pointer first - exit if failure */
|
|
|
|
if (id == NULL) {
|
|
|
|
BKE_reportf(reports, RPT_ERROR, "No ID block to insert keyframe in (path = %s)", rna_path);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
RNA_id_pointer_create(id, &id_ptr);
|
|
|
|
if (RNA_path_resolve_property(&id_ptr, rna_path, &ptr, &prop) == false) {
|
|
|
|
BKE_reportf(
|
|
|
|
reports,
|
|
|
|
RPT_ERROR,
|
|
|
|
"Could not insert keyframe, as RNA path is invalid for the given ID (ID = %s, path = %s)",
|
|
|
|
(id) ? id->name : TIP_("<Missing ID block>"),
|
|
|
|
rna_path);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if no action is provided, keyframe to the default one attached to this ID-block */
|
|
|
|
if (act == NULL) {
|
|
|
|
/* get action to add F-Curve+keyframe to */
|
2020-03-06 13:41:27 +11:00
|
|
|
act = ED_id_action_ensure(bmain, id);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
if (act == NULL) {
|
|
|
|
BKE_reportf(reports,
|
|
|
|
RPT_ERROR,
|
|
|
|
"Could not insert keyframe, as this type does not support animation data (ID = "
|
|
|
|
"%s, path = %s)",
|
|
|
|
id->name,
|
|
|
|
rna_path);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* apply NLA-mapping to frame to use (if applicable) */
|
|
|
|
adt = BKE_animdata_from_id(id);
|
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 remapped_context = nla_time_remap(
|
|
|
|
anim_eval_context, &id_ptr, adt, act, nla_cache ? nla_cache : &tmp_nla_cache, &nla_context);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* Obtain values to insert. */
|
|
|
|
float value_buffer[RNA_MAX_ARRAY_LENGTH];
|
|
|
|
int value_count;
|
|
|
|
bool force_all;
|
|
|
|
|
2019-07-31 12:22:43 +02:00
|
|
|
float *values = get_keyframe_values(reports,
|
2019-04-17 06:17:24 +02:00
|
|
|
ptr,
|
|
|
|
prop,
|
|
|
|
array_index,
|
|
|
|
nla_context,
|
|
|
|
flag,
|
|
|
|
value_buffer,
|
|
|
|
RNA_MAX_ARRAY_LENGTH,
|
|
|
|
&value_count,
|
|
|
|
&force_all);
|
|
|
|
|
|
|
|
if (values != NULL) {
|
|
|
|
/* Key the entire array. */
|
|
|
|
if (array_index == -1 || force_all) {
|
|
|
|
/* In force mode, if any of the curves succeeds, drop the replace mode and restart. */
|
2019-05-11 21:16:46 +03:00
|
|
|
if (force_all && (flag & (INSERTKEY_REPLACE | INSERTKEY_AVAILABLE)) != 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
int exclude = -1;
|
|
|
|
|
|
|
|
for (array_index = 0; array_index < value_count; array_index++) {
|
|
|
|
if (insert_keyframe_fcurve_value(bmain,
|
|
|
|
reports,
|
|
|
|
&ptr,
|
|
|
|
prop,
|
|
|
|
act,
|
|
|
|
group,
|
|
|
|
rna_path,
|
|
|
|
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
|
|
|
&remapped_context,
|
2019-04-17 06:17:24 +02:00
|
|
|
values[array_index],
|
|
|
|
keytype,
|
|
|
|
flag)) {
|
|
|
|
ret++;
|
|
|
|
exclude = array_index;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exclude != -1) {
|
2019-05-11 21:16:46 +03:00
|
|
|
flag &= ~(INSERTKEY_REPLACE | INSERTKEY_AVAILABLE);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
for (array_index = 0; array_index < value_count; array_index++) {
|
|
|
|
if (array_index != exclude) {
|
|
|
|
ret += insert_keyframe_fcurve_value(bmain,
|
|
|
|
reports,
|
|
|
|
&ptr,
|
|
|
|
prop,
|
|
|
|
act,
|
|
|
|
group,
|
|
|
|
rna_path,
|
|
|
|
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
|
|
|
&remapped_context,
|
2019-04-17 06:17:24 +02:00
|
|
|
values[array_index],
|
|
|
|
keytype,
|
|
|
|
flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Simply insert all channels. */
|
|
|
|
else {
|
|
|
|
for (array_index = 0; array_index < value_count; array_index++) {
|
|
|
|
ret += insert_keyframe_fcurve_value(bmain,
|
|
|
|
reports,
|
|
|
|
&ptr,
|
|
|
|
prop,
|
|
|
|
act,
|
|
|
|
group,
|
|
|
|
rna_path,
|
|
|
|
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
|
|
|
&remapped_context,
|
2019-04-17 06:17:24 +02:00
|
|
|
values[array_index],
|
|
|
|
keytype,
|
|
|
|
flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Key a single index. */
|
|
|
|
else {
|
|
|
|
if (array_index >= 0 && array_index < value_count) {
|
|
|
|
ret += insert_keyframe_fcurve_value(bmain,
|
|
|
|
reports,
|
|
|
|
&ptr,
|
|
|
|
prop,
|
|
|
|
act,
|
|
|
|
group,
|
|
|
|
rna_path,
|
|
|
|
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
|
|
|
&remapped_context,
|
2019-04-17 06:17:24 +02:00
|
|
|
values[array_index],
|
|
|
|
keytype,
|
|
|
|
flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-14 16:12:16 +02:00
|
|
|
if (values != value_buffer) {
|
|
|
|
MEM_freeN(values);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BKE_animsys_free_nla_keyframing_context_cache(&tmp_nla_cache);
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
if (act != NULL) {
|
|
|
|
DEG_id_tag_update(&act->id, ID_RECALC_ANIMATION_NO_FLUSH);
|
|
|
|
}
|
|
|
|
if (adt != NULL && adt->action != NULL && adt->action != act) {
|
|
|
|
DEG_id_tag_update(&adt->action->id, ID_RECALC_ANIMATION_NO_FLUSH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2008-12-20 08:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ************************************************** */
|
|
|
|
/* KEYFRAME DELETION */
|
|
|
|
|
|
|
|
/* Main Keyframing API call:
|
2018-11-14 12:53:15 +11:00
|
|
|
* Use this when validation of necessary animation data isn't necessary as it
|
|
|
|
* already exists. It will delete a keyframe at the current frame.
|
2018-06-01 18:19:39 +02:00
|
|
|
*
|
2018-11-14 12:53:15 +11:00
|
|
|
* The flag argument is used for special settings that alter the behavior of
|
|
|
|
* the keyframe deletion. These include the quick refresh options.
|
2008-12-20 08:24:24 +00:00
|
|
|
*/
|
2013-10-02 16:37:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \note caller needs to run #BKE_nla_tweakedit_remap to get NLA relative frame.
|
|
|
|
* caller should also check #BKE_fcurve_is_protected before keying.
|
|
|
|
*/
|
|
|
|
static bool delete_keyframe_fcurve(AnimData *adt, FCurve *fcu, float cfra)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bool found;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* try to find index of beztriple to get rid of */
|
2020-10-13 16:36:31 +11:00
|
|
|
i = BKE_fcurve_bezt_binarysearch_index(fcu->bezt, cfra, fcu->totvert, &found);
|
2019-04-17 06:17:24 +02:00
|
|
|
if (found) {
|
|
|
|
/* delete the key at the index (will sanity check + do recalc afterwards) */
|
|
|
|
delete_fcurve_key(fcu, i, 1);
|
|
|
|
|
|
|
|
/* 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)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ANIM_fcurve_delete_from_animdata(NULL, adt, fcu);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* return success */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2013-10-02 16:37:47 +00:00
|
|
|
}
|
|
|
|
|
2019-02-28 18:08:22 +01:00
|
|
|
static void deg_tag_after_keyframe_delete(Main *bmain, ID *id, AnimData *adt)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (adt->action == NULL) {
|
2019-08-18 04:11:50 +10:00
|
|
|
/* In the case last f-curve was removed need to inform dependency graph
|
2019-04-17 06:17:24 +02:00
|
|
|
* about relations update, since it needs to get rid of animation operation
|
2019-08-18 04:11:50 +10:00
|
|
|
* for this data-block. */
|
2019-04-17 06:17:24 +02:00
|
|
|
DEG_id_tag_update_ex(bmain, id, ID_RECALC_ANIMATION_NO_FLUSH);
|
|
|
|
DEG_relations_tag_update(bmain);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
DEG_id_tag_update_ex(bmain, &adt->action->id, ID_RECALC_ANIMATION_NO_FLUSH);
|
|
|
|
}
|
2019-02-28 18:08:22 +01:00
|
|
|
}
|
|
|
|
|
2020-03-06 16:45:56 +11:00
|
|
|
/**
|
|
|
|
* \return The number of key-frames deleted.
|
|
|
|
*/
|
|
|
|
int delete_keyframe(Main *bmain,
|
|
|
|
ReportList *reports,
|
|
|
|
ID *id,
|
|
|
|
bAction *act,
|
|
|
|
const char rna_path[],
|
|
|
|
int array_index,
|
|
|
|
float cfra)
|
2008-12-20 08:24:24 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
AnimData *adt = BKE_animdata_from_id(id);
|
|
|
|
PointerRNA id_ptr, ptr;
|
|
|
|
PropertyRNA *prop;
|
|
|
|
int array_index_max = array_index + 1;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/* sanity checks */
|
|
|
|
if (ELEM(NULL, id, adt)) {
|
|
|
|
BKE_report(reports, RPT_ERROR, "No ID block and/or AnimData to delete keyframe from");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* validate pointer first - exit if failure */
|
|
|
|
RNA_id_pointer_create(id, &id_ptr);
|
|
|
|
if (RNA_path_resolve_property(&id_ptr, rna_path, &ptr, &prop) == false) {
|
|
|
|
BKE_reportf(
|
|
|
|
reports,
|
|
|
|
RPT_ERROR,
|
|
|
|
"Could not delete keyframe, as RNA path is invalid for the given ID (ID = %s, path = %s)",
|
|
|
|
id->name,
|
|
|
|
rna_path);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get F-Curve
|
|
|
|
* Note: here is one of the places where we don't want new Action + F-Curve added!
|
|
|
|
* so 'add' var must be 0
|
|
|
|
*/
|
|
|
|
if (act == NULL) {
|
|
|
|
/* if no action is provided, use the default one attached to this ID-block
|
|
|
|
* - if it doesn't exist, then we're out of options...
|
|
|
|
*/
|
|
|
|
if (adt->action) {
|
|
|
|
act = adt->action;
|
|
|
|
|
|
|
|
/* apply NLA-mapping to frame to use (if applicable) */
|
|
|
|
cfra = BKE_nla_tweakedit_remap(adt, cfra, NLATIME_CONVERT_UNMAP);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BKE_reportf(reports, RPT_ERROR, "No action to delete keyframes from for ID = %s", id->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* key entire array convenience method */
|
|
|
|
if (array_index == -1) {
|
|
|
|
array_index = 0;
|
|
|
|
array_index_max = RNA_property_array_length(&ptr, prop);
|
|
|
|
|
|
|
|
/* for single properties, increase max_index so that the property itself gets included,
|
|
|
|
* but don't do this for standard arrays since that can cause corruption issues
|
|
|
|
* (extra unused curves)
|
|
|
|
*/
|
2019-04-22 09:19:45 +10:00
|
|
|
if (array_index_max == array_index) {
|
2019-04-17 06:17:24 +02:00
|
|
|
array_index_max++;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* will only loop once unless the array index was -1 */
|
|
|
|
for (; array_index < array_index_max; array_index++) {
|
2020-03-06 13:41:27 +11:00
|
|
|
FCurve *fcu = ED_action_fcurve_find(act, rna_path, array_index);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* check if F-Curve exists and/or whether it can be edited */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (fcu == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
continue;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
if (BKE_fcurve_is_protected(fcu)) {
|
|
|
|
BKE_reportf(reports,
|
|
|
|
RPT_WARNING,
|
|
|
|
"Not deleting keyframe for locked F-Curve '%s' for %s '%s'",
|
|
|
|
fcu->rna_path,
|
2020-03-19 19:37:00 +01:00
|
|
|
BKE_idtype_idcode_to_name(GS(id->name)),
|
2019-04-17 06:17:24 +02:00
|
|
|
id->name + 2);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret += delete_keyframe_fcurve(adt, fcu, cfra);
|
|
|
|
}
|
|
|
|
if (ret) {
|
|
|
|
deg_tag_after_keyframe_delete(bmain, id, adt);
|
|
|
|
}
|
|
|
|
/* return success/failure */
|
|
|
|
return ret;
|
2008-12-20 08:24:24 +00:00
|
|
|
}
|
|
|
|
|
2012-07-17 15:16:44 +00:00
|
|
|
/* ************************************************** */
|
|
|
|
/* KEYFRAME CLEAR */
|
|
|
|
|
2020-03-06 16:45:56 +11:00
|
|
|
/**
|
|
|
|
* Main Keyframing API call:
|
2018-11-14 12:53:15 +11:00
|
|
|
* Use this when validation of necessary animation data isn't necessary as it
|
|
|
|
* already exists. It will clear the current buttons fcurve(s).
|
2012-07-17 15:16:44 +00:00
|
|
|
*
|
2018-11-14 12:53:15 +11:00
|
|
|
* The flag argument is used for special settings that alter the behavior of
|
|
|
|
* the keyframe deletion. These include the quick refresh options.
|
2020-03-06 16:45:56 +11:00
|
|
|
*
|
|
|
|
* \return The number of f-curves removed.
|
2012-07-17 15:16:44 +00:00
|
|
|
*/
|
2020-03-06 16:45:56 +11:00
|
|
|
static int clear_keyframe(Main *bmain,
|
|
|
|
ReportList *reports,
|
|
|
|
ID *id,
|
|
|
|
bAction *act,
|
|
|
|
const char rna_path[],
|
|
|
|
int array_index,
|
|
|
|
eInsertKeyFlags UNUSED(flag))
|
2012-07-17 15:16:44 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
AnimData *adt = BKE_animdata_from_id(id);
|
|
|
|
PointerRNA id_ptr, ptr;
|
|
|
|
PropertyRNA *prop;
|
|
|
|
int array_index_max = array_index + 1;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/* sanity checks */
|
|
|
|
if (ELEM(NULL, id, adt)) {
|
|
|
|
BKE_report(reports, RPT_ERROR, "No ID block and/or AnimData to delete keyframe from");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* validate pointer first - exit if failure */
|
|
|
|
RNA_id_pointer_create(id, &id_ptr);
|
|
|
|
if (RNA_path_resolve_property(&id_ptr, rna_path, &ptr, &prop) == false) {
|
|
|
|
BKE_reportf(
|
|
|
|
reports,
|
|
|
|
RPT_ERROR,
|
|
|
|
"Could not clear keyframe, as RNA path is invalid for the given ID (ID = %s, path = %s)",
|
|
|
|
id->name,
|
|
|
|
rna_path);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get F-Curve
|
|
|
|
* Note: here is one of the places where we don't want new Action + F-Curve added!
|
|
|
|
* so 'add' var must be 0
|
|
|
|
*/
|
|
|
|
if (act == NULL) {
|
|
|
|
/* if no action is provided, use the default one attached to this ID-block
|
|
|
|
* - if it doesn't exist, then we're out of options...
|
|
|
|
*/
|
|
|
|
if (adt->action) {
|
|
|
|
act = adt->action;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BKE_reportf(reports, RPT_ERROR, "No action to delete keyframes from for ID = %s", id->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* key entire array convenience method */
|
|
|
|
if (array_index == -1) {
|
|
|
|
array_index = 0;
|
|
|
|
array_index_max = RNA_property_array_length(&ptr, prop);
|
|
|
|
|
|
|
|
/* for single properties, increase max_index so that the property itself gets included,
|
|
|
|
* but don't do this for standard arrays since that can cause corruption issues
|
|
|
|
* (extra unused curves)
|
|
|
|
*/
|
2019-04-22 09:19:45 +10:00
|
|
|
if (array_index_max == array_index) {
|
2019-04-17 06:17:24 +02:00
|
|
|
array_index_max++;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* will only loop once unless the array index was -1 */
|
|
|
|
for (; array_index < array_index_max; array_index++) {
|
2020-03-06 13:41:27 +11:00
|
|
|
FCurve *fcu = ED_action_fcurve_find(act, rna_path, array_index);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* check if F-Curve exists and/or whether it can be edited */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (fcu == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
continue;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
if (BKE_fcurve_is_protected(fcu)) {
|
|
|
|
BKE_reportf(reports,
|
|
|
|
RPT_WARNING,
|
|
|
|
"Not clearing all keyframes from locked F-Curve '%s' for %s '%s'",
|
|
|
|
fcu->rna_path,
|
2020-03-19 19:37:00 +01:00
|
|
|
BKE_idtype_idcode_to_name(GS(id->name)),
|
2019-04-17 06:17:24 +02:00
|
|
|
id->name + 2);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ANIM_fcurve_delete_from_animdata(NULL, adt, fcu);
|
|
|
|
|
|
|
|
/* return success */
|
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
if (ret) {
|
|
|
|
deg_tag_after_keyframe_delete(bmain, id, adt);
|
|
|
|
}
|
|
|
|
/* return success/failure */
|
|
|
|
return ret;
|
2012-07-17 15:16:44 +00:00
|
|
|
}
|
|
|
|
|
2009-03-31 22:36:13 +00:00
|
|
|
/* ******************************************* */
|
|
|
|
/* KEYFRAME MODIFICATION */
|
|
|
|
|
|
|
|
/* mode for commonkey_modifykey */
|
2011-02-17 22:34:41 +00:00
|
|
|
enum {
|
2019-04-17 06:17:24 +02:00
|
|
|
COMMONKEY_MODE_INSERT = 0,
|
|
|
|
COMMONKEY_MODE_DELETE,
|
2011-02-17 22:34:41 +00:00
|
|
|
} /*eCommonModifyKey_Modes*/;
|
2009-03-31 22:36:13 +00:00
|
|
|
|
2009-02-25 10:55:03 +00:00
|
|
|
/* Polling callback for use with ANIM_*_keyframe() operators
|
|
|
|
* This is based on the standard ED_operator_areaactive callback,
|
|
|
|
* except that it does special checks for a few spacetypes too...
|
|
|
|
*/
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool modify_key_op_poll(bContext *C)
|
2009-02-25 10:55:03 +00:00
|
|
|
{
|
2020-04-03 13:25:03 +02:00
|
|
|
ScrArea *area = CTX_wm_area(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* if no area or active scene */
|
2020-04-03 13:25:03 +02:00
|
|
|
if (ELEM(NULL, area, scene)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* should be fine */
|
|
|
|
return true;
|
2009-02-25 10:55:03 +00:00
|
|
|
}
|
|
|
|
|
2.5: Blender "Animato" - New Animation System
Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future.
Highlights of the new system:
* Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action.
- F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves.
- The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc.
* F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated.
* Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place)
* F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place)
* NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still)
There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details:
http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html
So, what currently works:
* I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code.
* Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock.
* Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc.
Notes:
* Drivers haven't been hooked up yet
* Only objects and data directly linked to objects can be animated.
* Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change).
* Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor)
* I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review.
In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
2009-01-17 03:12:50 +00:00
|
|
|
/* Insert Key Operator ------------------------ */
|
|
|
|
|
2012-05-08 11:48:19 +00:00
|
|
|
static int insert_key_exec(bContext *C, wmOperator *op)
|
2009-02-13 09:46:08 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
Object *obedit = CTX_data_edit_object(C);
|
|
|
|
bool ob_edit_mode = false;
|
|
|
|
|
2020-10-10 18:19:55 +11:00
|
|
|
float cfra = (float)CFRA; /* XXX for now, don't bother about all the yucky offset crap */
|
2020-03-06 11:32:38 +01:00
|
|
|
int num_channels;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
KeyingSet *ks = keyingset_get_from_op_with_error(op, op->type->prop, scene);
|
|
|
|
if (ks == NULL) {
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* exit the edit mode to make sure that those object data properties that have been
|
|
|
|
* updated since the last switching to the edit mode will be keyframed correctly
|
|
|
|
*/
|
|
|
|
if (obedit && ANIM_keyingset_find_id(ks, (ID *)obedit->data)) {
|
2020-06-03 15:23:26 +10:00
|
|
|
ED_object_mode_set(C, OB_MODE_OBJECT);
|
2019-04-17 06:17:24 +02:00
|
|
|
ob_edit_mode = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to insert keyframes for the channels specified by KeyingSet */
|
2020-03-06 11:32:38 +01:00
|
|
|
num_channels = ANIM_apply_keyingset(C, NULL, NULL, ks, MODIFYKEY_MODE_INSERT, cfra);
|
2019-04-22 09:19:45 +10:00
|
|
|
if (G.debug & G_DEBUG) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_reportf(op->reports,
|
|
|
|
RPT_INFO,
|
|
|
|
"Keying set '%s' - successfully added %d keyframes",
|
|
|
|
ks->name,
|
2020-03-06 11:32:38 +01:00
|
|
|
num_channels);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* restore the edit mode if necessary */
|
|
|
|
if (ob_edit_mode) {
|
2020-06-03 15:23:26 +10:00
|
|
|
ED_object_mode_set(C, OB_MODE_EDIT);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* report failure or do updates? */
|
2020-03-06 11:36:37 +01:00
|
|
|
if (num_channels < 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "No suitable context info for active keying set");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
2020-07-03 14:51:19 +02:00
|
|
|
|
|
|
|
if (num_channels > 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* if the appropriate properties have been set, make a note that we've inserted something */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (RNA_boolean_get(op->ptr, "confirm_success")) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_reportf(op->reports,
|
|
|
|
RPT_INFO,
|
|
|
|
"Successfully added %d keyframes for keying set '%s'",
|
2020-03-06 11:32:38 +01:00
|
|
|
num_channels,
|
2019-04-17 06:17:24 +02:00
|
|
|
ks->name);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* send notifiers that keyframes have been changed */
|
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_ADDED, NULL);
|
|
|
|
}
|
2019-04-22 09:19:45 +10:00
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_report(op->reports, RPT_WARNING, "Keying set failed to insert any keyframes");
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
2009-02-13 09:46:08 +00:00
|
|
|
}
|
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void ANIM_OT_keyframe_insert(wmOperatorType *ot)
|
2009-02-13 09:46:08 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Insert Keyframe";
|
|
|
|
ot->idname = "ANIM_OT_keyframe_insert";
|
|
|
|
ot->description =
|
|
|
|
"Insert keyframes on the current frame for all properties in the specified Keying Set";
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
ot->exec = insert_key_exec;
|
|
|
|
ot->poll = modify_key_op_poll;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
|
|
|
|
/* keyingset to use (dynamic enum) */
|
|
|
|
prop = RNA_def_enum(
|
|
|
|
ot->srna, "type", DummyRNA_DEFAULT_items, 0, "Keying Set", "The Keying Set to use");
|
|
|
|
RNA_def_enum_funcs(prop, ANIM_keying_sets_enum_itemf);
|
|
|
|
RNA_def_property_flag(prop, PROP_HIDDEN);
|
|
|
|
ot->prop = prop;
|
|
|
|
|
|
|
|
/* confirm whether a keyframe was added by showing a popup
|
|
|
|
* - by default, this is enabled, since this operator is assumed to be called independently
|
|
|
|
*/
|
|
|
|
prop = RNA_def_boolean(ot->srna,
|
|
|
|
"confirm_success",
|
|
|
|
1,
|
|
|
|
"Confirm Successful Insert",
|
|
|
|
"Show a popup when the keyframes get successfully added");
|
|
|
|
RNA_def_property_flag(prop, PROP_HIDDEN);
|
2009-02-13 09:46:08 +00:00
|
|
|
}
|
|
|
|
|
2019-04-10 11:27:32 +02:00
|
|
|
/* Clone of 'ANIM_OT_keyframe_insert' which uses a name for the keying set instead of an enum. */
|
|
|
|
void ANIM_OT_keyframe_insert_by_name(wmOperatorType *ot)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Insert Keyframe (by name)";
|
|
|
|
ot->idname = "ANIM_OT_keyframe_insert_by_name";
|
|
|
|
ot->description = "Alternate access to 'Insert Keyframe' for keymaps to use";
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
ot->exec = insert_key_exec;
|
|
|
|
ot->poll = modify_key_op_poll;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
|
|
|
|
/* keyingset to use (idname) */
|
|
|
|
prop = RNA_def_string_file_path(ot->srna, "type", "Type", MAX_ID_NAME - 2, "", "");
|
|
|
|
RNA_def_property_flag(prop, PROP_HIDDEN);
|
|
|
|
ot->prop = prop;
|
|
|
|
|
|
|
|
/* confirm whether a keyframe was added by showing a popup
|
|
|
|
* - by default, this is enabled, since this operator is assumed to be called independently
|
|
|
|
*/
|
|
|
|
prop = RNA_def_boolean(ot->srna,
|
|
|
|
"confirm_success",
|
|
|
|
1,
|
|
|
|
"Confirm Successful Insert",
|
|
|
|
"Show a popup when the keyframes get successfully added");
|
|
|
|
RNA_def_property_flag(prop, PROP_HIDDEN);
|
2019-04-10 11:27:32 +02:00
|
|
|
}
|
|
|
|
|
2009-03-31 22:36:13 +00:00
|
|
|
/* Insert Key Operator (With Menu) ------------------------ */
|
2018-06-04 09:31:30 +02:00
|
|
|
/* This operator checks if a menu should be shown for choosing the KeyingSet to use,
|
2018-06-01 18:19:39 +02:00
|
|
|
* then calls the menu if necessary before
|
2009-02-13 09:46:08 +00:00
|
|
|
*/
|
2009-03-31 22:36:13 +00:00
|
|
|
|
2013-03-13 09:03:46 +00:00
|
|
|
static int insert_key_menu_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
|
2009-11-24 04:21:32 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
|
|
|
|
/* if prompting or no active Keying Set, show the menu */
|
|
|
|
if ((scene->active_keyingset == 0) || RNA_boolean_get(op->ptr, "always_prompt")) {
|
|
|
|
uiPopupMenu *pup;
|
|
|
|
uiLayout *layout;
|
|
|
|
|
|
|
|
/* call the menu, which will call this operator again, hence the canceled */
|
2019-06-04 15:50:15 +02:00
|
|
|
pup = UI_popup_menu_begin(C, WM_operatortype_name(op->type, op->ptr), ICON_NONE);
|
2019-04-17 06:17:24 +02:00
|
|
|
layout = UI_popup_menu_layout(pup);
|
2020-09-15 08:10:23 -06:00
|
|
|
uiItemsEnumO(layout, "ANIM_OT_keyframe_insert_menu", "type");
|
2019-04-17 06:17:24 +02:00
|
|
|
UI_popup_menu_end(C, pup);
|
|
|
|
|
|
|
|
return OPERATOR_INTERFACE;
|
|
|
|
}
|
|
|
|
|
2020-07-03 14:51:19 +02:00
|
|
|
/* just call the exec() on the active keyingset */
|
|
|
|
RNA_enum_set(op->ptr, "type", 0);
|
|
|
|
RNA_boolean_set(op->ptr, "confirm_success", true);
|
|
|
|
|
|
|
|
return op->type->exec(C, op);
|
2009-03-31 22:36:13 +00:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void ANIM_OT_keyframe_insert_menu(wmOperatorType *ot)
|
2009-03-31 22:36:13 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Insert Keyframe Menu";
|
|
|
|
ot->idname = "ANIM_OT_keyframe_insert_menu";
|
|
|
|
ot->description =
|
|
|
|
"Insert Keyframes for specified Keying Set, with menu of available Keying Sets if undefined";
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
ot->invoke = insert_key_menu_invoke;
|
|
|
|
ot->exec = insert_key_exec;
|
|
|
|
ot->poll = ED_operator_areaactive;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
|
|
|
|
/* keyingset to use (dynamic enum) */
|
|
|
|
prop = RNA_def_enum(
|
|
|
|
ot->srna, "type", DummyRNA_DEFAULT_items, 0, "Keying Set", "The Keying Set to use");
|
|
|
|
RNA_def_enum_funcs(prop, ANIM_keying_sets_enum_itemf);
|
|
|
|
RNA_def_property_flag(prop, PROP_HIDDEN);
|
|
|
|
ot->prop = prop;
|
|
|
|
|
|
|
|
/* confirm whether a keyframe was added by showing a popup
|
|
|
|
* - by default, this is disabled so that if a menu is shown, this doesn't come up too
|
|
|
|
*/
|
2020-10-10 18:19:55 +11:00
|
|
|
/* XXX should this just be always on? */
|
2019-04-17 06:17:24 +02:00
|
|
|
prop = RNA_def_boolean(ot->srna,
|
|
|
|
"confirm_success",
|
|
|
|
0,
|
|
|
|
"Confirm Successful Insert",
|
|
|
|
"Show a popup when the keyframes get successfully added");
|
|
|
|
RNA_def_property_flag(prop, PROP_HIDDEN);
|
|
|
|
|
|
|
|
/* whether the menu should always be shown
|
|
|
|
* - by default, the menu should only be shown when there is no active Keying Set (2.5 behavior),
|
|
|
|
* although in some cases it might be useful to always shown (pre 2.5 behavior)
|
|
|
|
*/
|
|
|
|
prop = RNA_def_boolean(ot->srna, "always_prompt", 0, "Always Show Menu", "");
|
|
|
|
RNA_def_property_flag(prop, PROP_HIDDEN);
|
2009-03-31 22:36:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete Key Operator ------------------------ */
|
|
|
|
|
2012-05-08 11:48:19 +00:00
|
|
|
static int delete_key_exec(bContext *C, wmOperator *op)
|
2009-02-13 09:46:08 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2020-10-10 18:19:55 +11:00
|
|
|
float cfra = (float)CFRA; /* XXX for now, don't bother about all the yucky offset crap */
|
2020-03-06 11:32:38 +01:00
|
|
|
int num_channels;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
KeyingSet *ks = keyingset_get_from_op_with_error(op, op->type->prop, scene);
|
|
|
|
if (ks == NULL) {
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int prop_type = RNA_property_type(op->type->prop);
|
|
|
|
if (prop_type == PROP_ENUM) {
|
|
|
|
int type = RNA_property_enum_get(op->ptr, op->type->prop);
|
|
|
|
ks = ANIM_keyingset_get_from_enum_type(scene, type);
|
|
|
|
if (ks == NULL) {
|
2019-06-28 21:44:19 +02:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "No active Keying Set");
|
2019-04-17 06:17:24 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (prop_type == PROP_STRING) {
|
|
|
|
char type_id[MAX_ID_NAME - 2];
|
|
|
|
RNA_property_string_get(op->ptr, op->type->prop, type_id);
|
|
|
|
ks = ANIM_keyingset_get_from_idname(scene, type_id);
|
|
|
|
|
|
|
|
if (ks == NULL) {
|
2019-06-28 21:44:19 +02:00
|
|
|
BKE_reportf(op->reports, RPT_ERROR, "Active Keying Set '%s' not found", type_id);
|
2019-04-17 06:17:24 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BLI_assert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* report failure */
|
|
|
|
if (ks == NULL) {
|
|
|
|
BKE_report(op->reports, RPT_ERROR, "No active Keying Set");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to delete keyframes for the channels specified by KeyingSet */
|
2020-03-06 11:32:38 +01:00
|
|
|
num_channels = ANIM_apply_keyingset(C, NULL, NULL, ks, MODIFYKEY_MODE_DELETE, cfra);
|
2019-04-22 09:19:45 +10:00
|
|
|
if (G.debug & G_DEBUG) {
|
2020-03-06 11:32:38 +01:00
|
|
|
printf("KeyingSet '%s' - Successfully removed %d Keyframes\n", ks->name, num_channels);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* report failure or do updates? */
|
2020-03-06 11:36:37 +01:00
|
|
|
if (num_channels < 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "No suitable context info for active keying set");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
2020-07-03 14:51:19 +02:00
|
|
|
|
|
|
|
if (num_channels > 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* if the appropriate properties have been set, make a note that we've inserted something */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (RNA_boolean_get(op->ptr, "confirm_success")) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_reportf(op->reports,
|
|
|
|
RPT_INFO,
|
|
|
|
"Successfully removed %d keyframes for keying set '%s'",
|
2020-03-06 11:32:38 +01:00
|
|
|
num_channels,
|
2019-04-17 06:17:24 +02:00
|
|
|
ks->name);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* send notifiers that keyframes have been changed */
|
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_REMOVED, NULL);
|
|
|
|
}
|
2019-04-22 09:19:45 +10:00
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_report(op->reports, RPT_WARNING, "Keying set failed to remove any keyframes");
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
2009-02-13 09:46:08 +00:00
|
|
|
}
|
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void ANIM_OT_keyframe_delete(wmOperatorType *ot)
|
2009-02-13 09:46:08 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Delete Keying-Set Keyframe";
|
|
|
|
ot->idname = "ANIM_OT_keyframe_delete";
|
|
|
|
ot->description =
|
|
|
|
"Delete keyframes on the current frame for all properties in the specified Keying Set";
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
ot->exec = delete_key_exec;
|
|
|
|
ot->poll = modify_key_op_poll;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
|
|
|
|
/* keyingset to use (dynamic enum) */
|
|
|
|
prop = RNA_def_enum(
|
|
|
|
ot->srna, "type", DummyRNA_DEFAULT_items, 0, "Keying Set", "The Keying Set to use");
|
|
|
|
RNA_def_enum_funcs(prop, ANIM_keying_sets_enum_itemf);
|
|
|
|
RNA_def_property_flag(prop, PROP_HIDDEN);
|
|
|
|
ot->prop = prop;
|
|
|
|
|
|
|
|
/* confirm whether a keyframe was added by showing a popup
|
|
|
|
* - by default, this is enabled, since this operator is assumed to be called independently
|
|
|
|
*/
|
|
|
|
RNA_def_boolean(ot->srna,
|
|
|
|
"confirm_success",
|
|
|
|
1,
|
|
|
|
"Confirm Successful Delete",
|
|
|
|
"Show a popup when the keyframes get successfully removed");
|
2008-12-20 08:24:24 +00:00
|
|
|
}
|
|
|
|
|
2019-04-10 11:27:32 +02:00
|
|
|
void ANIM_OT_keyframe_delete_by_name(wmOperatorType *ot)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Delete Keying-Set Keyframe (by name)";
|
|
|
|
ot->idname = "ANIM_OT_keyframe_delete_by_name";
|
|
|
|
ot->description = "Alternate access to 'Delete Keyframe' for keymaps to use";
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
ot->exec = delete_key_exec;
|
|
|
|
ot->poll = modify_key_op_poll;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
|
|
|
|
/* keyingset to use (idname) */
|
|
|
|
prop = RNA_def_string_file_path(ot->srna, "type", "Type", MAX_ID_NAME - 2, "", "");
|
|
|
|
RNA_def_property_flag(prop, PROP_HIDDEN);
|
|
|
|
ot->prop = prop;
|
|
|
|
|
|
|
|
/* confirm whether a keyframe was added by showing a popup
|
|
|
|
* - by default, this is enabled, since this operator is assumed to be called independently
|
|
|
|
*/
|
|
|
|
RNA_def_boolean(ot->srna,
|
|
|
|
"confirm_success",
|
|
|
|
1,
|
|
|
|
"Confirm Successful Delete",
|
|
|
|
"Show a popup when the keyframes get successfully removed");
|
2019-04-10 11:27:32 +02:00
|
|
|
}
|
|
|
|
|
2.5: Blender "Animato" - New Animation System
Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future.
Highlights of the new system:
* Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action.
- F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves.
- The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc.
* F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated.
* Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place)
* F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place)
* NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still)
There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details:
http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html
So, what currently works:
* I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code.
* Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock.
* Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc.
Notes:
* Drivers haven't been hooked up yet
* Only objects and data directly linked to objects can be animated.
* Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change).
* Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor)
* I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review.
In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
2009-01-17 03:12:50 +00:00
|
|
|
/* Delete Key Operator ------------------------ */
|
2012-10-04 10:58:03 +00:00
|
|
|
/* NOTE: Although this version is simpler than the more generic version for KeyingSets,
|
|
|
|
* it is more useful for animators working in the 3D view.
|
2.5: Blender "Animato" - New Animation System
Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future.
Highlights of the new system:
* Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action.
- F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves.
- The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc.
* F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated.
* Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place)
* F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place)
* NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still)
There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details:
http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html
So, what currently works:
* I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code.
* Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock.
* Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc.
Notes:
* Drivers haven't been hooked up yet
* Only objects and data directly linked to objects can be animated.
* Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change).
* Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor)
* I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review.
In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
2009-01-17 03:12:50 +00:00
|
|
|
*/
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2013-12-20 01:38:07 +01:00
|
|
|
static int clear_anim_v3d_exec(bContext *C, wmOperator *UNUSED(op))
|
2012-10-04 10:58:03 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bool changed = false;
|
|
|
|
|
|
|
|
CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
|
|
|
|
/* just those in active action... */
|
|
|
|
if ((ob->adt) && (ob->adt->action)) {
|
|
|
|
AnimData *adt = ob->adt;
|
|
|
|
bAction *act = adt->action;
|
|
|
|
FCurve *fcu, *fcn;
|
|
|
|
|
|
|
|
for (fcu = act->curves.first; fcu; fcu = fcn) {
|
|
|
|
bool can_delete = false;
|
|
|
|
|
|
|
|
fcn = fcu->next;
|
|
|
|
|
|
|
|
/* in pose mode, only delete the F-Curve if it belongs to a selected bone */
|
|
|
|
if (ob->mode & OB_MODE_POSE) {
|
|
|
|
if ((fcu->rna_path) && strstr(fcu->rna_path, "pose.bones[")) {
|
|
|
|
bPoseChannel *pchan;
|
|
|
|
char *bone_name;
|
|
|
|
|
|
|
|
/* get bone-name, and check if this bone is selected */
|
|
|
|
bone_name = BLI_str_quoted_substrN(fcu->rna_path, "pose.bones[");
|
|
|
|
pchan = BKE_pose_channel_find_name(ob->pose, bone_name);
|
2019-04-22 09:19:45 +10:00
|
|
|
if (bone_name) {
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(bone_name);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* delete if bone is selected*/
|
|
|
|
if ((pchan) && (pchan->bone)) {
|
2019-04-22 09:19:45 +10:00
|
|
|
if (pchan->bone->flag & BONE_SELECTED) {
|
2019-04-17 06:17:24 +02:00
|
|
|
can_delete = true;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* object mode - all of Object's F-Curves are affected */
|
|
|
|
can_delete = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* delete F-Curve completely */
|
|
|
|
if (can_delete) {
|
|
|
|
ANIM_fcurve_delete_from_animdata(NULL, adt, fcu);
|
|
|
|
DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM);
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
2019-05-02 14:51:43 +03:00
|
|
|
|
|
|
|
/* Delete the action itself if it is empty. */
|
|
|
|
if (ANIM_remove_empty_action_from_animdata(adt)) {
|
|
|
|
changed = true;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
CTX_DATA_END;
|
|
|
|
|
|
|
|
if (!changed) {
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send updates */
|
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_KEYS, NULL);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
2012-10-04 10:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ANIM_OT_keyframe_clear_v3d(wmOperatorType *ot)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Remove Animation";
|
|
|
|
ot->description = "Remove all keyframe animation for selected objects";
|
|
|
|
ot->idname = "ANIM_OT_keyframe_clear_v3d";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* callbacks */
|
|
|
|
ot->invoke = WM_operator_confirm;
|
|
|
|
ot->exec = clear_anim_v3d_exec;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ot->poll = ED_operator_areaactive;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2012-10-04 10:58:03 +00:00
|
|
|
}
|
|
|
|
|
2012-05-08 11:48:19 +00:00
|
|
|
static int delete_key_v3d_exec(bContext *C, wmOperator *op)
|
2008-12-20 08:24:24 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
float cfra = (float)CFRA;
|
|
|
|
|
2019-07-19 18:43:12 +10:00
|
|
|
int selected_objects_len = 0;
|
|
|
|
int selected_objects_success_len = 0;
|
|
|
|
int success_multi = 0;
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
|
|
|
|
ID *id = &ob->id;
|
|
|
|
int success = 0;
|
|
|
|
|
2019-07-19 18:43:12 +10:00
|
|
|
selected_objects_len += 1;
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* just those in active action... */
|
|
|
|
if ((ob->adt) && (ob->adt->action)) {
|
|
|
|
AnimData *adt = ob->adt;
|
|
|
|
bAction *act = adt->action;
|
|
|
|
FCurve *fcu, *fcn;
|
|
|
|
const float cfra_unmap = BKE_nla_tweakedit_remap(adt, cfra, NLATIME_CONVERT_UNMAP);
|
|
|
|
|
|
|
|
for (fcu = act->curves.first; fcu; fcu = fcn) {
|
|
|
|
fcn = fcu->next;
|
|
|
|
|
|
|
|
/* don't touch protected F-Curves */
|
|
|
|
if (BKE_fcurve_is_protected(fcu)) {
|
|
|
|
BKE_reportf(op->reports,
|
|
|
|
RPT_WARNING,
|
|
|
|
"Not deleting keyframe for locked F-Curve '%s', object '%s'",
|
|
|
|
fcu->rna_path,
|
|
|
|
id->name + 2);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-04-22 00:18:34 +10:00
|
|
|
/* Special exception for bones, as this makes this operator more convenient to use
|
|
|
|
* NOTE: This is only done in pose mode.
|
|
|
|
* In object mode, we're dealing with the entire object.
|
2019-04-17 06:17:24 +02:00
|
|
|
*/
|
|
|
|
if ((ob->mode & OB_MODE_POSE) && strstr(fcu->rna_path, "pose.bones[\"")) {
|
|
|
|
bPoseChannel *pchan;
|
|
|
|
char *bone_name;
|
|
|
|
|
|
|
|
/* get bone-name, and check if this bone is selected */
|
|
|
|
bone_name = BLI_str_quoted_substrN(fcu->rna_path, "pose.bones[");
|
|
|
|
pchan = BKE_pose_channel_find_name(ob->pose, bone_name);
|
2019-04-22 09:19:45 +10:00
|
|
|
if (bone_name) {
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(bone_name);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* skip if bone is not selected */
|
|
|
|
if ((pchan) && (pchan->bone)) {
|
|
|
|
/* bones are only selected/editable if visible... */
|
|
|
|
bArmature *arm = (bArmature *)ob->data;
|
|
|
|
|
|
|
|
/* skipping - not visible on currently visible layers */
|
2019-04-22 09:19:45 +10:00
|
|
|
if ((arm->layer & pchan->bone->layer) == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
continue;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
/* skipping - is currently hidden */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (pchan->bone->flag & BONE_HIDDEN_P) {
|
2019-04-17 06:17:24 +02:00
|
|
|
continue;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* selection flag... */
|
2019-04-22 09:19:45 +10:00
|
|
|
if ((pchan->bone->flag & BONE_SELECTED) == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
continue;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* delete keyframes on current frame
|
|
|
|
* WARNING: this can delete the next F-Curve, hence the "fcn" copying
|
|
|
|
*/
|
|
|
|
success += delete_keyframe_fcurve(adt, fcu, cfra_unmap);
|
|
|
|
}
|
|
|
|
DEG_id_tag_update(&ob->adt->action->id, ID_RECALC_ANIMATION_NO_FLUSH);
|
|
|
|
}
|
|
|
|
|
2019-07-19 18:43:12 +10:00
|
|
|
/* Only for reporting. */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (success) {
|
2019-07-19 18:43:12 +10:00
|
|
|
selected_objects_success_len += 1;
|
|
|
|
success_multi += success;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM);
|
|
|
|
}
|
|
|
|
CTX_DATA_END;
|
|
|
|
|
2019-07-19 18:43:12 +10:00
|
|
|
/* report success (or failure) */
|
|
|
|
if (selected_objects_success_len) {
|
|
|
|
BKE_reportf(op->reports,
|
|
|
|
RPT_INFO,
|
|
|
|
"%d object(s) successfully had %d keyframes removed",
|
|
|
|
selected_objects_success_len,
|
|
|
|
success_multi);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BKE_reportf(
|
|
|
|
op->reports, RPT_ERROR, "No keyframes removed from %d object(s)", selected_objects_len);
|
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* send updates */
|
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_KEYS, NULL);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
2008-12-20 08:24:24 +00:00
|
|
|
}
|
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void ANIM_OT_keyframe_delete_v3d(wmOperatorType *ot)
|
2.5: Blender "Animato" - New Animation System
Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future.
Highlights of the new system:
* Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action.
- F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves.
- The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc.
* F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated.
* Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place)
* F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place)
* NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still)
There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details:
http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html
So, what currently works:
* I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code.
* Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock.
* Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc.
Notes:
* Drivers haven't been hooked up yet
* Only objects and data directly linked to objects can be animated.
* Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change).
* Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor)
* I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review.
In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
2009-01-17 03:12:50 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Delete Keyframe";
|
|
|
|
ot->description = "Remove keyframes on current frame for selected objects and bones";
|
|
|
|
ot->idname = "ANIM_OT_keyframe_delete_v3d";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* callbacks */
|
|
|
|
ot->invoke = WM_operator_confirm;
|
|
|
|
ot->exec = delete_key_v3d_exec;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ot->poll = ED_operator_areaactive;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2.5: Blender "Animato" - New Animation System
Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future.
Highlights of the new system:
* Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action.
- F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves.
- The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc.
* F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated.
* Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place)
* F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place)
* NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still)
There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details:
http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html
So, what currently works:
* I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code.
* Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock.
* Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc.
Notes:
* Drivers haven't been hooked up yet
* Only objects and data directly linked to objects can be animated.
* Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change).
* Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor)
* I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review.
In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
2009-01-17 03:12:50 +00:00
|
|
|
}
|
2008-12-21 10:33:24 +00:00
|
|
|
|
2009-04-03 23:30:32 +00:00
|
|
|
/* Insert Key Button Operator ------------------------ */
|
|
|
|
|
2012-05-08 11:48:19 +00:00
|
|
|
static int insert_key_button_exec(bContext *C, wmOperator *op)
|
2009-04-03 23:30:32 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
ToolSettings *ts = scene->toolsettings;
|
2019-08-23 09:52:12 +02:00
|
|
|
PointerRNA ptr = {NULL};
|
2019-04-17 06:17:24 +02:00
|
|
|
PropertyRNA *prop = NULL;
|
|
|
|
char *path;
|
|
|
|
uiBut *but;
|
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(
|
|
|
|
CTX_data_depsgraph_pointer(C), (float)CFRA);
|
2020-03-06 16:45:56 +11:00
|
|
|
bool changed = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
int index;
|
|
|
|
const bool all = RNA_boolean_get(op->ptr, "all");
|
|
|
|
eInsertKeyFlags flag = INSERTKEY_NOFLAGS;
|
|
|
|
|
|
|
|
/* flags for inserting keyframes */
|
2020-03-06 16:45:56 +11:00
|
|
|
flag = ANIM_get_keyframing_flags(scene, true);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* try to insert keyframe using property retrieved from UI */
|
|
|
|
if (!(but = UI_context_active_but_prop_get(C, &ptr, &prop, &index))) {
|
|
|
|
/* pass event on if no active button found */
|
|
|
|
return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH);
|
|
|
|
}
|
|
|
|
|
2019-08-23 09:52:12 +02:00
|
|
|
if ((ptr.owner_id && ptr.data && prop) && RNA_property_animateable(&ptr, prop)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ptr.type == &RNA_NlaStrip) {
|
|
|
|
/* Handle special properties for NLA Strips, whose F-Curves are stored on the
|
|
|
|
* strips themselves. These are stored separately or else the properties will
|
|
|
|
* not have any effect.
|
|
|
|
*/
|
2020-03-05 08:33:26 +11:00
|
|
|
NlaStrip *strip = ptr.data;
|
2020-06-05 09:30:15 +02:00
|
|
|
FCurve *fcu = BKE_fcurve_find(&strip->fcurves, RNA_property_identifier(prop), index);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
if (fcu) {
|
2020-03-06 16:45:56 +11:00
|
|
|
changed = insert_keyframe_direct(
|
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
|
|
|
op->reports, ptr, prop, fcu, &anim_eval_context, ts->keyframe_type, NULL, 0);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
BKE_report(op->reports,
|
|
|
|
RPT_ERROR,
|
|
|
|
"This property cannot be animated as it will not get updated correctly");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (UI_but_flag_is_set(but, UI_BUT_DRIVEN)) {
|
|
|
|
/* Driven property - Find driver */
|
|
|
|
FCurve *fcu;
|
|
|
|
bool driven, special;
|
|
|
|
|
2020-06-05 09:30:15 +02:00
|
|
|
fcu = BKE_fcurve_find_by_rna_context_ui(C, &ptr, prop, index, NULL, NULL, &driven, &special);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
if (fcu && driven) {
|
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
|
|
|
changed = insert_keyframe_direct(op->reports,
|
|
|
|
ptr,
|
|
|
|
prop,
|
|
|
|
fcu,
|
|
|
|
&anim_eval_context,
|
|
|
|
ts->keyframe_type,
|
|
|
|
NULL,
|
|
|
|
INSERTKEY_DRIVER);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* standard properties */
|
|
|
|
path = RNA_path_from_ID_to_property(&ptr, prop);
|
|
|
|
|
|
|
|
if (path) {
|
|
|
|
const char *identifier = RNA_property_identifier(prop);
|
|
|
|
const char *group = NULL;
|
|
|
|
|
|
|
|
/* Special exception for keyframing transforms:
|
2019-04-22 00:18:34 +10:00
|
|
|
* Set "group" for this manually, instead of having them appearing at the bottom
|
|
|
|
* (ungrouped) part of the channels list.
|
|
|
|
* Leaving these ungrouped is not a nice user behavior in this case.
|
2019-04-17 06:17:24 +02:00
|
|
|
*
|
|
|
|
* TODO: Perhaps we can extend this behavior in future for other properties...
|
|
|
|
*/
|
|
|
|
if (ptr.type == &RNA_PoseBone) {
|
2020-03-05 08:33:26 +11:00
|
|
|
bPoseChannel *pchan = ptr.data;
|
2019-04-17 06:17:24 +02:00
|
|
|
group = pchan->name;
|
|
|
|
}
|
|
|
|
else if ((ptr.type == &RNA_Object) &&
|
|
|
|
(strstr(identifier, "location") || strstr(identifier, "rotation") ||
|
|
|
|
strstr(identifier, "scale"))) {
|
|
|
|
/* NOTE: Keep this label in sync with the "ID" case in
|
|
|
|
* keyingsets_utils.py :: get_transform_generators_base_info()
|
|
|
|
*/
|
|
|
|
group = "Object Transforms";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (all) {
|
|
|
|
/* -1 indicates operating on the entire array (or the property itself otherwise) */
|
|
|
|
index = -1;
|
|
|
|
}
|
|
|
|
|
2020-03-06 16:45:56 +11:00
|
|
|
changed = (insert_keyframe(bmain,
|
|
|
|
op->reports,
|
|
|
|
ptr.owner_id,
|
|
|
|
NULL,
|
|
|
|
group,
|
|
|
|
path,
|
|
|
|
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,
|
2020-03-06 16:45:56 +11:00
|
|
|
ts->keyframe_type,
|
|
|
|
NULL,
|
|
|
|
flag) != 0);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
MEM_freeN(path);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BKE_report(op->reports,
|
|
|
|
RPT_WARNING,
|
|
|
|
"Failed to resolve path to property, "
|
|
|
|
"try manually specifying this using a Keying Set instead");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (prop && !RNA_property_animateable(&ptr, prop)) {
|
|
|
|
BKE_reportf(op->reports,
|
|
|
|
RPT_WARNING,
|
|
|
|
"\"%s\" property cannot be animated",
|
|
|
|
RNA_property_identifier(prop));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BKE_reportf(op->reports,
|
|
|
|
RPT_WARNING,
|
|
|
|
"Button doesn't appear to have any property information attached (ptr.data = "
|
|
|
|
"%p, prop = %p)",
|
2020-03-05 08:33:26 +11:00
|
|
|
ptr.data,
|
2019-04-17 06:17:24 +02:00
|
|
|
(void *)prop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-06 16:45:56 +11:00
|
|
|
if (changed) {
|
2019-08-23 09:52:12 +02:00
|
|
|
ID *id = ptr.owner_id;
|
2019-04-17 06:17:24 +02:00
|
|
|
AnimData *adt = BKE_animdata_from_id(id);
|
|
|
|
if (adt->action != NULL) {
|
|
|
|
DEG_id_tag_update(&adt->action->id, ID_RECALC_ANIMATION_NO_FLUSH);
|
|
|
|
}
|
|
|
|
DEG_id_tag_update(id, ID_RECALC_ANIMATION_NO_FLUSH);
|
|
|
|
|
|
|
|
/* send updates */
|
|
|
|
UI_context_update_anim_flag(C);
|
|
|
|
|
|
|
|
/* send notifiers that keyframes have been changed */
|
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_ADDED, NULL);
|
|
|
|
}
|
|
|
|
|
2020-03-06 16:45:56 +11:00
|
|
|
return (changed) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
|
2009-04-03 23:30:32 +00:00
|
|
|
}
|
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void ANIM_OT_keyframe_insert_button(wmOperatorType *ot)
|
2009-04-03 23:30:32 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Insert Keyframe (Buttons)";
|
|
|
|
ot->idname = "ANIM_OT_keyframe_insert_button";
|
|
|
|
ot->description = "Insert a keyframe for current UI-active property";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* callbacks */
|
|
|
|
ot->exec = insert_key_button_exec;
|
|
|
|
ot->poll = modify_key_op_poll;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_UNDO | OPTYPE_INTERNAL;
|
2009-04-03 23:30:32 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* properties */
|
|
|
|
RNA_def_boolean(ot->srna, "all", 1, "All", "Insert a keyframe for all element of the array");
|
2009-04-03 23:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete Key Button Operator ------------------------ */
|
|
|
|
|
2012-05-08 11:48:19 +00:00
|
|
|
static int delete_key_button_exec(bContext *C, wmOperator *op)
|
2009-04-03 23:30:32 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2019-08-23 09:52:12 +02:00
|
|
|
PointerRNA ptr = {NULL};
|
2019-04-17 06:17:24 +02:00
|
|
|
PropertyRNA *prop = NULL;
|
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
char *path;
|
2020-10-10 18:19:55 +11:00
|
|
|
float cfra = (float)CFRA; /* XXX for now, don't bother about all the yucky offset crap */
|
2020-03-06 16:45:56 +11:00
|
|
|
bool changed = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
int index;
|
|
|
|
const bool all = RNA_boolean_get(op->ptr, "all");
|
|
|
|
|
|
|
|
/* try to insert keyframe using property retrieved from UI */
|
|
|
|
if (!UI_context_active_but_prop_get(C, &ptr, &prop, &index)) {
|
|
|
|
/* pass event on if no active button found */
|
|
|
|
return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH);
|
|
|
|
}
|
|
|
|
|
2019-08-23 09:52:12 +02:00
|
|
|
if (ptr.owner_id && ptr.data && prop) {
|
2019-04-17 06:17:24 +02:00
|
|
|
if (BKE_nlastrip_has_curves_for_property(&ptr, prop)) {
|
|
|
|
/* Handle special properties for NLA Strips, whose F-Curves are stored on the
|
|
|
|
* strips themselves. These are stored separately or else the properties will
|
|
|
|
* not have any effect.
|
|
|
|
*/
|
2019-08-23 09:52:12 +02:00
|
|
|
ID *id = ptr.owner_id;
|
2020-03-05 08:33:26 +11:00
|
|
|
NlaStrip *strip = ptr.data;
|
2020-06-05 09:30:15 +02:00
|
|
|
FCurve *fcu = BKE_fcurve_find(&strip->fcurves, RNA_property_identifier(prop), 0);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
if (fcu) {
|
|
|
|
if (BKE_fcurve_is_protected(fcu)) {
|
|
|
|
BKE_reportf(
|
|
|
|
op->reports,
|
|
|
|
RPT_WARNING,
|
|
|
|
"Not deleting keyframe for locked F-Curve for NLA Strip influence on %s - %s '%s'",
|
|
|
|
strip->name,
|
2020-03-19 19:37:00 +01:00
|
|
|
BKE_idtype_idcode_to_name(GS(id->name)),
|
2019-04-17 06:17:24 +02:00
|
|
|
id->name + 2);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* remove the keyframe directly
|
|
|
|
* NOTE: cannot use delete_keyframe_fcurve(), as that will free the curve,
|
|
|
|
* and delete_keyframe() expects the FCurve to be part of an action
|
|
|
|
*/
|
|
|
|
bool found = false;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* try to find index of beztriple to get rid of */
|
2020-10-13 16:36:31 +11:00
|
|
|
i = BKE_fcurve_bezt_binarysearch_index(fcu->bezt, cfra, fcu->totvert, &found);
|
2019-04-17 06:17:24 +02:00
|
|
|
if (found) {
|
|
|
|
/* delete the key at the index (will sanity check + do recalc afterwards) */
|
|
|
|
delete_fcurve_key(fcu, i, 1);
|
2020-03-06 16:45:56 +11:00
|
|
|
changed = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* standard properties */
|
|
|
|
path = RNA_path_from_ID_to_property(&ptr, prop);
|
|
|
|
|
|
|
|
if (path) {
|
|
|
|
if (all) {
|
|
|
|
/* -1 indicates operating on the entire array (or the property itself otherwise) */
|
|
|
|
index = -1;
|
|
|
|
}
|
|
|
|
|
2020-03-06 16:45:56 +11:00
|
|
|
changed = delete_keyframe(bmain, op->reports, ptr.owner_id, NULL, path, index, cfra) != 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(path);
|
|
|
|
}
|
2019-04-22 09:19:45 +10:00
|
|
|
else if (G.debug & G_DEBUG) {
|
2019-04-17 06:17:24 +02:00
|
|
|
printf("Button Delete-Key: no path to property\n");
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (G.debug & G_DEBUG) {
|
2020-03-05 08:33:26 +11:00
|
|
|
printf("ptr.data = %p, prop = %p\n", ptr.data, (void *)prop);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
2020-03-06 16:45:56 +11:00
|
|
|
if (changed) {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* send updates */
|
|
|
|
UI_context_update_anim_flag(C);
|
|
|
|
|
|
|
|
/* send notifiers that keyframes have been changed */
|
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_REMOVED, NULL);
|
|
|
|
}
|
|
|
|
|
2020-03-06 16:45:56 +11:00
|
|
|
return (changed) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
|
2009-04-03 23:30:32 +00:00
|
|
|
}
|
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void ANIM_OT_keyframe_delete_button(wmOperatorType *ot)
|
2009-04-03 23:30:32 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Delete Keyframe (Buttons)";
|
|
|
|
ot->idname = "ANIM_OT_keyframe_delete_button";
|
|
|
|
ot->description = "Delete current keyframe of current UI-active property";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* callbacks */
|
|
|
|
ot->exec = delete_key_button_exec;
|
|
|
|
ot->poll = modify_key_op_poll;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_UNDO | OPTYPE_INTERNAL;
|
2009-04-03 23:30:32 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* properties */
|
|
|
|
RNA_def_boolean(ot->srna, "all", 1, "All", "Delete keyframes from all elements of the array");
|
2012-07-17 15:16:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear Key Button Operator ------------------------ */
|
|
|
|
|
|
|
|
static int clear_key_button_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2019-08-23 09:52:12 +02:00
|
|
|
PointerRNA ptr = {NULL};
|
2019-04-17 06:17:24 +02:00
|
|
|
PropertyRNA *prop = NULL;
|
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
char *path;
|
2020-03-06 16:45:56 +11:00
|
|
|
bool changed = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
int index;
|
|
|
|
const bool all = RNA_boolean_get(op->ptr, "all");
|
|
|
|
|
|
|
|
/* try to insert keyframe using property retrieved from UI */
|
|
|
|
if (!UI_context_active_but_prop_get(C, &ptr, &prop, &index)) {
|
|
|
|
/* pass event on if no active button found */
|
|
|
|
return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH);
|
|
|
|
}
|
|
|
|
|
2019-08-23 09:52:12 +02:00
|
|
|
if (ptr.owner_id && ptr.data && prop) {
|
2019-04-17 06:17:24 +02:00
|
|
|
path = RNA_path_from_ID_to_property(&ptr, prop);
|
|
|
|
|
|
|
|
if (path) {
|
|
|
|
if (all) {
|
|
|
|
/* -1 indicates operating on the entire array (or the property itself otherwise) */
|
|
|
|
index = -1;
|
|
|
|
}
|
|
|
|
|
2020-03-06 16:45:56 +11:00
|
|
|
changed |= (clear_keyframe(bmain, op->reports, ptr.owner_id, NULL, path, index, 0) != 0);
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(path);
|
|
|
|
}
|
2019-04-22 09:19:45 +10:00
|
|
|
else if (G.debug & G_DEBUG) {
|
2019-04-17 06:17:24 +02:00
|
|
|
printf("Button Clear-Key: no path to property\n");
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else if (G.debug & G_DEBUG) {
|
2020-03-05 08:33:26 +11:00
|
|
|
printf("ptr.data = %p, prop = %p\n", ptr.data, (void *)prop);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
2020-03-06 16:45:56 +11:00
|
|
|
if (changed) {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* send updates */
|
|
|
|
UI_context_update_anim_flag(C);
|
|
|
|
|
|
|
|
/* send notifiers that keyframes have been changed */
|
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_REMOVED, NULL);
|
|
|
|
}
|
|
|
|
|
2020-03-06 16:45:56 +11:00
|
|
|
return (changed) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
|
2012-07-17 15:16:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ANIM_OT_keyframe_clear_button(wmOperatorType *ot)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Clear Keyframe (Buttons)";
|
|
|
|
ot->idname = "ANIM_OT_keyframe_clear_button";
|
|
|
|
ot->description = "Clear all keyframes on the currently active property";
|
2012-07-17 15:16:44 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* callbacks */
|
|
|
|
ot->exec = clear_key_button_exec;
|
|
|
|
ot->poll = modify_key_op_poll;
|
2012-07-17 15:16:44 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_UNDO | OPTYPE_INTERNAL;
|
2012-07-17 15:16:44 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* properties */
|
|
|
|
RNA_def_boolean(ot->srna, "all", 1, "All", "Clear keyframes from all elements of the array");
|
2009-04-03 23:30:32 +00:00
|
|
|
}
|
|
|
|
|
2.5: Blender "Animato" - New Animation System
Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future.
Highlights of the new system:
* Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action.
- F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves.
- The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc.
* F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated.
* Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place)
* F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place)
* NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still)
There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details:
http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html
So, what currently works:
* I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code.
* Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock.
* Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc.
Notes:
* Drivers haven't been hooked up yet
* Only objects and data directly linked to objects can be animated.
* Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change).
* Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor)
* I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review.
In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
2009-01-17 03:12:50 +00:00
|
|
|
/* ******************************************* */
|
2009-07-12 02:06:15 +00:00
|
|
|
/* AUTO KEYFRAME */
|
|
|
|
|
2020-03-13 17:27:11 +11:00
|
|
|
bool autokeyframe_cfra_can_key(const Scene *scene, ID *id)
|
2009-07-12 02:06:15 +00:00
|
|
|
{
|
2020-10-10 18:19:55 +11:00
|
|
|
float cfra = (float)CFRA; /* XXX for now, this will do */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* only filter if auto-key mode requires this */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (IS_AUTOKEY_ON(scene) == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
if (IS_AUTOKEY_MODE(scene, EDITKEYS)) {
|
|
|
|
/* Replace Mode:
|
|
|
|
* For whole block, only key if there's a keyframe on that frame already
|
|
|
|
* This is a valid assumption when we're blocking + tweaking
|
|
|
|
*/
|
|
|
|
return id_frame_has_keyframe(id, cfra, ANIMFILTER_KEYS_LOCAL);
|
|
|
|
}
|
|
|
|
|
2020-07-03 14:51:19 +02:00
|
|
|
/* Normal Mode (or treat as being normal mode):
|
|
|
|
*
|
|
|
|
* Just in case the flags aren't set properly (i.e. only on/off is set, without a mode)
|
|
|
|
* let's set the "normal" flag too, so that it will all be sane everywhere...
|
|
|
|
*/
|
|
|
|
scene->toolsettings->autokey_mode = AUTOKEY_MODE_NORMAL;
|
|
|
|
|
|
|
|
/* Can insert anytime we like... */
|
|
|
|
return true;
|
2009-07-12 02:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ******************************************* */
|
2008-12-20 08:24:24 +00:00
|
|
|
/* KEYFRAME DETECTION */
|
|
|
|
|
|
|
|
/* --------------- API/Per-Datablock Handling ------------------- */
|
|
|
|
|
2009-07-08 12:30:09 +00:00
|
|
|
/* Checks if some F-Curve has a keyframe for a given frame */
|
2014-02-03 18:55:59 +11:00
|
|
|
bool fcurve_frame_has_keyframe(FCurve *fcu, float frame, short filter)
|
2009-07-08 12:30:09 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* quick sanity check */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ELEM(NULL, fcu, fcu->bezt)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* we either include all regardless of muting, or only non-muted */
|
|
|
|
if ((filter & ANIMFILTER_KEYS_MUTED) || (fcu->flag & FCURVE_MUTED) == 0) {
|
|
|
|
bool replace;
|
2020-10-13 16:36:31 +11:00
|
|
|
int i = BKE_fcurve_bezt_binarysearch_index(fcu->bezt, frame, fcu->totvert, &replace);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-10-13 16:36:31 +11:00
|
|
|
/* BKE_fcurve_bezt_binarysearch_index will set replace to be 0 or 1
|
2019-04-17 06:17:24 +02:00
|
|
|
* - obviously, 1 represents a match
|
|
|
|
*/
|
|
|
|
if (replace) {
|
|
|
|
/* sanity check: 'i' may in rare cases exceed arraylen */
|
2019-04-22 09:19:45 +10:00
|
|
|
if ((i >= 0) && (i < fcu->totvert)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2009-07-08 12:30:09 +00:00
|
|
|
}
|
|
|
|
|
2018-12-07 03:26:20 +01:00
|
|
|
/* Returns whether the current value of a given property differs from the interpolated value. */
|
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
|
|
|
bool fcurve_is_changed(PointerRNA ptr,
|
|
|
|
PropertyRNA *prop,
|
|
|
|
FCurve *fcu,
|
|
|
|
const AnimationEvalContext *anim_eval_context)
|
2018-12-07 03:26:20 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PathResolvedRNA anim_rna;
|
|
|
|
anim_rna.ptr = ptr;
|
|
|
|
anim_rna.prop = prop;
|
|
|
|
anim_rna.prop_index = fcu->array_index;
|
2018-12-07 03:26:20 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
float buffer[RNA_MAX_ARRAY_LENGTH];
|
|
|
|
int count, index = fcu->array_index;
|
2019-07-31 12:22:43 +02:00
|
|
|
float *values = setting_get_rna_values(&ptr, prop, buffer, RNA_MAX_ARRAY_LENGTH, &count);
|
2019-01-08 18:49:38 +03:00
|
|
|
|
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 fcurve_val = calculate_fcurve(&anim_rna, fcu, anim_eval_context);
|
2019-04-17 06:17:24 +02:00
|
|
|
float cur_val = (index >= 0 && index < count) ? values[index] : 0.0f;
|
2019-01-08 18:49:38 +03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (values != buffer) {
|
|
|
|
MEM_freeN(values);
|
|
|
|
}
|
2018-12-07 03:26:20 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return !compare_ff_relative(fcurve_val, cur_val, FLT_EPSILON, 64);
|
2018-12-07 03:26:20 +01:00
|
|
|
}
|
|
|
|
|
2019-04-29 19:29:41 +10:00
|
|
|
/**
|
|
|
|
* Checks whether an Action has a keyframe for a given frame
|
|
|
|
* Since we're only concerned whether a keyframe exists,
|
|
|
|
* we can simply loop until a match is found.
|
2008-12-20 08:24:24 +00:00
|
|
|
*/
|
2014-04-01 11:34:00 +11:00
|
|
|
static bool action_frame_has_keyframe(bAction *act, float frame, short filter)
|
2008-12-20 08:24:24 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
FCurve *fcu;
|
|
|
|
|
|
|
|
/* can only find if there is data */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (act == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* if only check non-muted, check if muted */
|
2019-04-22 09:19:45 +10:00
|
|
|
if ((filter & ANIMFILTER_KEYS_MUTED) || (act->flag & ACT_MUTED)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* loop over F-Curves, using binary-search to try to find matches
|
|
|
|
* - this assumes that keyframes are only beztriples
|
|
|
|
*/
|
|
|
|
for (fcu = act->curves.first; fcu; fcu = fcu->next) {
|
|
|
|
/* only check if there are keyframes (currently only of type BezTriple) */
|
|
|
|
if (fcu->bezt && fcu->totvert) {
|
2019-04-22 09:19:45 +10:00
|
|
|
if (fcurve_frame_has_keyframe(fcu, frame, filter)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* nothing found */
|
|
|
|
return false;
|
2008-12-20 08:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Checks whether an Object has a keyframe for a given frame */
|
2014-04-01 11:34:00 +11:00
|
|
|
static bool object_frame_has_keyframe(Object *ob, float frame, short filter)
|
2008-12-20 08:24:24 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* error checking */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ob == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* check own animation data - specifically, the action it contains */
|
|
|
|
if ((ob->adt) && (ob->adt->action)) {
|
|
|
|
/* T41525 - When the active action is a NLA strip being edited,
|
|
|
|
* we need to correct the frame number to "look inside" the
|
|
|
|
* remapped action
|
|
|
|
*/
|
|
|
|
float ob_frame = BKE_nla_tweakedit_remap(ob->adt, frame, NLATIME_CONVERT_UNMAP);
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (action_frame_has_keyframe(ob->adt->action, ob_frame, filter)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* try shapekey keyframes (if available, and allowed by filter) */
|
|
|
|
if (!(filter & ANIMFILTER_KEYS_LOCAL) && !(filter & ANIMFILTER_KEYS_NOSKEY)) {
|
|
|
|
Key *key = BKE_key_from_object(ob);
|
|
|
|
|
|
|
|
/* shapekeys can have keyframes ('Relative Shape Keys')
|
|
|
|
* or depend on time (old 'Absolute Shape Keys')
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* 1. test for relative (with keyframes) */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (id_frame_has_keyframe((ID *)key, frame, filter)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* 2. test for time */
|
|
|
|
/* TODO... yet to be implemented (this feature may evolve before then anyway) */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try materials */
|
|
|
|
if (!(filter & ANIMFILTER_KEYS_LOCAL) && !(filter & ANIMFILTER_KEYS_NOMAT)) {
|
|
|
|
/* if only active, then we can skip a lot of looping */
|
|
|
|
if (filter & ANIMFILTER_KEYS_ACTIVE) {
|
2020-02-05 11:23:58 +01:00
|
|
|
Material *ma = BKE_object_material_get(ob, (ob->actcol + 1));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* we only retrieve the active material... */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (id_frame_has_keyframe((ID *)ma, frame, filter)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
int a;
|
|
|
|
|
|
|
|
/* loop over materials */
|
|
|
|
for (a = 0; a < ob->totcol; a++) {
|
2020-02-05 11:23:58 +01:00
|
|
|
Material *ma = BKE_object_material_get(ob, a + 1);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (id_frame_has_keyframe((ID *)ma, frame, filter)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* nothing found */
|
|
|
|
return false;
|
2008-12-20 08:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------- API ------------------- */
|
|
|
|
|
|
|
|
/* Checks whether a keyframe exists for the given ID-block one the given frame */
|
2014-04-01 11:34:00 +11:00
|
|
|
bool id_frame_has_keyframe(ID *id, float frame, short filter)
|
2008-12-20 08:24:24 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* sanity checks */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (id == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* perform special checks for 'macro' types */
|
|
|
|
switch (GS(id->name)) {
|
|
|
|
case ID_OB: /* object */
|
|
|
|
return object_frame_has_keyframe((Object *)id, frame, filter);
|
2013-07-21 08:16:37 +00:00
|
|
|
#if 0
|
2020-10-10 18:19:55 +11:00
|
|
|
/* XXX TODO... for now, just use 'normal' behavior */
|
2019-04-17 06:17:24 +02:00
|
|
|
case ID_SCE: /* scene */
|
|
|
|
break;
|
2013-07-21 08:16:37 +00:00
|
|
|
#endif
|
2019-04-17 06:17:24 +02:00
|
|
|
default: /* 'normal type' */
|
|
|
|
{
|
|
|
|
AnimData *adt = BKE_animdata_from_id(id);
|
|
|
|
|
|
|
|
/* only check keyframes in active action */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (adt) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return action_frame_has_keyframe(adt->action, frame, filter);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no keyframe found */
|
|
|
|
return false;
|
2008-12-20 08:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ************************************************** */
|
2011-10-10 12:56:21 +00:00
|
|
|
|
2014-03-31 23:39:08 +11:00
|
|
|
bool ED_autokeyframe_object(bContext *C, Scene *scene, Object *ob, KeyingSet *ks)
|
2011-10-10 12:56:21 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* auto keyframing */
|
|
|
|
if (autokeyframe_cfra_can_key(scene, &ob->id)) {
|
|
|
|
ListBase dsources = {NULL, NULL};
|
|
|
|
|
2020-03-22 12:09:48 +11:00
|
|
|
/* Now insert the key-frame(s) using the Keying Set:
|
|
|
|
* 1) Add data-source override for the Object.
|
|
|
|
* 2) Insert key-frames.
|
|
|
|
* 3) Free the extra info.
|
2019-04-17 06:17:24 +02:00
|
|
|
*/
|
|
|
|
ANIM_relative_keyingset_add_source(&dsources, &ob->id, NULL, NULL);
|
|
|
|
ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
|
|
|
|
BLI_freelistN(&dsources);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2020-07-03 14:51:19 +02:00
|
|
|
return false;
|
2011-10-10 12:56:21 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bool ED_autokeyframe_pchan(
|
|
|
|
bContext *C, Scene *scene, Object *ob, bPoseChannel *pchan, KeyingSet *ks)
|
2011-10-10 12:56:21 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (autokeyframe_cfra_can_key(scene, &ob->id)) {
|
|
|
|
ListBase dsources = {NULL, NULL};
|
|
|
|
|
2020-03-22 12:09:48 +11:00
|
|
|
/* Now insert the keyframe(s) using the Keying Set:
|
|
|
|
* 1) Add data-source override for the pose-channel.
|
|
|
|
* 2) Insert key-frames.
|
|
|
|
* 3) Free the extra info.
|
2019-04-17 06:17:24 +02:00
|
|
|
*/
|
|
|
|
ANIM_relative_keyingset_add_source(&dsources, &ob->id, &RNA_PoseBone, pchan);
|
|
|
|
ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
|
|
|
|
BLI_freelistN(&dsources);
|
|
|
|
|
|
|
|
/* clear any unkeyed tags */
|
|
|
|
if (pchan->bone) {
|
|
|
|
pchan->bone->flag &= ~BONE_UNKEYED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-07-03 14:51:19 +02:00
|
|
|
/* add unkeyed tags */
|
|
|
|
if (pchan->bone) {
|
|
|
|
pchan->bone->flag |= BONE_UNKEYED;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2020-07-03 14:51:19 +02:00
|
|
|
|
|
|
|
return false;
|
2011-10-10 12:56:21 +00:00
|
|
|
}
|
2019-04-10 11:27:32 +02:00
|
|
|
|
2020-01-14 16:32:14 +11:00
|
|
|
/**
|
|
|
|
* Use for auto-keyframing from the UI.
|
|
|
|
*/
|
|
|
|
bool ED_autokeyframe_property(
|
|
|
|
bContext *C, Scene *scene, PointerRNA *ptr, PropertyRNA *prop, int rnaindex, float cfra)
|
|
|
|
{
|
|
|
|
Main *bmain = CTX_data_main(C);
|
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
|
|
|
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
|
|
|
|
const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct(depsgraph,
|
|
|
|
cfra);
|
2020-01-14 16:32:14 +11:00
|
|
|
ID *id;
|
|
|
|
bAction *action;
|
|
|
|
FCurve *fcu;
|
|
|
|
bool driven;
|
|
|
|
bool special;
|
|
|
|
bool changed = false;
|
|
|
|
|
2020-08-12 13:20:32 +02:00
|
|
|
/* for entire array buttons we check the first component, it's not perfect
|
|
|
|
* but works well enough in typical cases */
|
|
|
|
const int rnaindex_check = (rnaindex == -1) ? 0 : rnaindex;
|
2020-06-05 09:30:15 +02:00
|
|
|
fcu = BKE_fcurve_find_by_rna_context_ui(
|
2020-08-12 13:20:32 +02:00
|
|
|
C, ptr, prop, rnaindex_check, NULL, &action, &driven, &special);
|
2020-01-14 16:32:14 +11:00
|
|
|
|
|
|
|
if (fcu == NULL) {
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (special) {
|
|
|
|
/* NLA Strip property */
|
|
|
|
if (IS_AUTOKEY_ON(scene)) {
|
|
|
|
ReportList *reports = CTX_wm_reports(C);
|
|
|
|
ToolSettings *ts = scene->toolsettings;
|
|
|
|
|
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
|
|
|
changed = insert_keyframe_direct(
|
|
|
|
reports, *ptr, prop, fcu, &anim_eval_context, ts->keyframe_type, NULL, 0);
|
2020-01-14 16:32:14 +11:00
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (driven) {
|
|
|
|
/* Driver - Try to insert keyframe using the driver's input as the frame,
|
|
|
|
* making it easier to set up corrective drivers
|
|
|
|
*/
|
|
|
|
if (IS_AUTOKEY_ON(scene)) {
|
|
|
|
ReportList *reports = CTX_wm_reports(C);
|
|
|
|
ToolSettings *ts = scene->toolsettings;
|
|
|
|
|
|
|
|
changed = insert_keyframe_direct(
|
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
|
|
|
reports, *ptr, prop, fcu, &anim_eval_context, ts->keyframe_type, NULL, INSERTKEY_DRIVER);
|
2020-01-14 16:32:14 +11:00
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
id = ptr->owner_id;
|
|
|
|
|
|
|
|
/* TODO: this should probably respect the keyingset only option for anim */
|
|
|
|
if (autokeyframe_cfra_can_key(scene, id)) {
|
|
|
|
ReportList *reports = CTX_wm_reports(C);
|
|
|
|
ToolSettings *ts = scene->toolsettings;
|
2020-03-06 16:45:56 +11:00
|
|
|
const eInsertKeyFlags flag = ANIM_get_keyframing_flags(scene, true);
|
2020-01-14 16:32:14 +11:00
|
|
|
|
|
|
|
/* Note: We use rnaindex instead of fcu->array_index,
|
|
|
|
* because a button may control all items of an array at once.
|
|
|
|
* E.g., color wheels (see T42567). */
|
|
|
|
BLI_assert((fcu->array_index == rnaindex) || (rnaindex == -1));
|
|
|
|
changed = insert_keyframe(bmain,
|
|
|
|
reports,
|
|
|
|
id,
|
|
|
|
action,
|
|
|
|
((fcu->grp) ? (fcu->grp->name) : (NULL)),
|
|
|
|
fcu->rna_path,
|
|
|
|
rnaindex,
|
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,
|
2020-01-14 16:32:14 +11:00
|
|
|
ts->keyframe_type,
|
|
|
|
NULL,
|
|
|
|
flag) != 0;
|
|
|
|
|
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
2019-04-10 11:27:32 +02:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Internal Utilities
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
/** Use for insert/delete key-frame. */
|
|
|
|
static KeyingSet *keyingset_get_from_op_with_error(wmOperator *op, PropertyRNA *prop, Scene *scene)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
KeyingSet *ks = NULL;
|
|
|
|
const int prop_type = RNA_property_type(prop);
|
|
|
|
if (prop_type == PROP_ENUM) {
|
|
|
|
int type = RNA_property_enum_get(op->ptr, prop);
|
|
|
|
ks = ANIM_keyingset_get_from_enum_type(scene, type);
|
|
|
|
if (ks == NULL) {
|
2019-06-28 21:44:19 +02:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "No active Keying Set");
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (prop_type == PROP_STRING) {
|
|
|
|
char type_id[MAX_ID_NAME - 2];
|
|
|
|
RNA_property_string_get(op->ptr, prop, type_id);
|
|
|
|
ks = ANIM_keyingset_get_from_idname(scene, type_id);
|
|
|
|
|
|
|
|
if (ks == NULL) {
|
|
|
|
BKE_reportf(op->reports, RPT_ERROR, "Keying set '%s' not found", type_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BLI_assert(0);
|
|
|
|
}
|
|
|
|
return ks;
|
2019-04-10 11:27:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** \} */
|