This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/editors/animation/keyframes_edit.c

1126 lines
32 KiB
C
Raw Normal View History

/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* 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.
*
* The Original Code is Copyright (C) 2008 Blender Foundation
*
* Contributor(s): Joshua Leung
*
* ***** END GPL LICENSE BLOCK *****
*/
2011-02-27 20:29:51 +00:00
/** \file blender/editors/animation/keyframes_edit.c
* \ingroup edanimation
*/
#include <stdlib.h>
#include <string.h>
#include <math.h>
2.5 - Action Editor: All Keyframe Selection Tools Ported User Notes (for using tools whose behaviour has changed): * Mouse Selection Tools: 1) Click on keyframe to modify its selection. Holding the 'Shift' modifier when doing so, will result in keyframe selection being toggled instead of replacing existing selections. 2) Click on either side of the current frame indicator while holding the 'Alt' modifier. This will select only all the keyframes on the relevant side of the current frame indicator. 3) Click on a keyframe while holding the 'Ctrl' modifier. This will select all the keyframes that fall on that frame. * Borderselect Tools 1) BKEY selects all the keyframes within the specified range (as per normal) 2) ALT-BKEY will select either all the keyframes in the frame-range specified or the channel range specified, depending on which axis of the select region was larger. This method is prejudiced towards frame-range selection. Code Notes: * Finished porting over all of the remaining keyframe selection tools, and recoded the ported ones to make them easier to use (after running into some technical limitations) * Simplified the way to check if 'animation context' is valid by moving a necessary check into that function. * Refactored internal keyframe-looping tools to reduce the amount of code needed per tool to edit keyframes, removing a lot of the unnecessary bulk. Now, the ipo/icu_keys_bezier_loop functions recieve a few more arguments (1st arg is pointer to generic customdata, and another defines a validation callback which makes it easier to reuse some of the select callbacks). * Added 'totrect' adjustment for number of channels being shown in Action Editor, so that scrolling will be limited to where there is data (and also so that scroller displays more relevant context info). For this to work, filtering channels now returns the number of channels extracted. This may come into use for other tools if there's such a need. * I still need to port over some code for markers, which is required for some of the tools which use them. For now, those tools do nothing. * Grease-Pencil editing mode in Action Editor is currently non-functional (code is commented out due to missing dependencies). This is currently pending the re-implementation of Grease Pencil in 2.5
2008-12-26 10:55:07 +00:00
#include <float.h>
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BLI_math.h"
#include "BLI_utildefines.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 "DNA_anim_types.h"
#include "DNA_armature_types.h"
#include "DNA_camera_types.h"
#include "DNA_key_types.h"
#include "DNA_lamp_types.h"
#include "DNA_lattice_types.h"
#include "DNA_mesh_types.h"
#include "DNA_material_types.h"
#include "DNA_object_types.h"
#include "DNA_meta_types.h"
#include "DNA_node_types.h"
#include "DNA_particle_types.h"
#include "DNA_scene_types.h"
#include "DNA_space_types.h"
#include "DNA_world_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 "BKE_fcurve.h"
#include "BKE_key.h"
#include "BKE_material.h"
#include "ED_anim_api.h"
#include "ED_keyframes_edit.h"
#include "ED_markers.h"
/* This file defines an API and set of callback-operators for non-destructive editing of keyframe data.
*
* Two API functions are defined for actually performing the operations on the data:
* ANIM_fcurve_keyframes_loop()
* which take the data they operate on, a few callbacks defining what operations to perform.
*
* As operators which work on keyframes usually apply the same operation on all BezTriples in
* every channel, the code has been optimized providing a set of functions which will get the
* appropriate bezier-modify function to set. These functions (ANIM_editkeyframes_*) will need
* to be called before getting any channels.
*
2.5 - Action Editor: All Keyframe Selection Tools Ported User Notes (for using tools whose behaviour has changed): * Mouse Selection Tools: 1) Click on keyframe to modify its selection. Holding the 'Shift' modifier when doing so, will result in keyframe selection being toggled instead of replacing existing selections. 2) Click on either side of the current frame indicator while holding the 'Alt' modifier. This will select only all the keyframes on the relevant side of the current frame indicator. 3) Click on a keyframe while holding the 'Ctrl' modifier. This will select all the keyframes that fall on that frame. * Borderselect Tools 1) BKEY selects all the keyframes within the specified range (as per normal) 2) ALT-BKEY will select either all the keyframes in the frame-range specified or the channel range specified, depending on which axis of the select region was larger. This method is prejudiced towards frame-range selection. Code Notes: * Finished porting over all of the remaining keyframe selection tools, and recoded the ported ones to make them easier to use (after running into some technical limitations) * Simplified the way to check if 'animation context' is valid by moving a necessary check into that function. * Refactored internal keyframe-looping tools to reduce the amount of code needed per tool to edit keyframes, removing a lot of the unnecessary bulk. Now, the ipo/icu_keys_bezier_loop functions recieve a few more arguments (1st arg is pointer to generic customdata, and another defines a validation callback which makes it easier to reuse some of the select callbacks). * Added 'totrect' adjustment for number of channels being shown in Action Editor, so that scrolling will be limited to where there is data (and also so that scroller displays more relevant context info). For this to work, filtering channels now returns the number of channels extracted. This may come into use for other tools if there's such a need. * I still need to port over some code for markers, which is required for some of the tools which use them. For now, those tools do nothing. * Grease-Pencil editing mode in Action Editor is currently non-functional (code is commented out due to missing dependencies). This is currently pending the re-implementation of Grease Pencil in 2.5
2008-12-26 10:55:07 +00:00
* A set of 'validation' callbacks are provided for checking if a BezTriple should be operated on.
* These should only be used when using a 'general' BezTriple editor (i.e. selection setters which
* don't check existing selection status).
*
* - Joshua Leung, Dec 2008
*/
/* ************************************************************************** */
/* Keyframe Editing Loops - Exposed API */
/* --------------------------- Base Functions ------------------------------------ */
/* This function is used to loop over BezTriples in the given F-Curve, applying a given
* operation on them, and optionally applies an F-Curve validation function afterwards.
*/
// TODO: make this function work on samples too...
short ANIM_fcurve_keyframes_loop(KeyframeEditData *ked, FCurve *fcu, KeyframeEditFunc key_ok, KeyframeEditFunc key_cb, FcuEditFunc fcu_cb)
{
BezTriple *bezt;
short ok = 0;
unsigned int i;
/* sanity check */
if (ELEM(NULL, fcu, fcu->bezt))
return 0;
/* set the F-Curve into the editdata so that it can be accessed */
if (ked) {
2012-05-08 15:30:00 +00:00
ked->fcu = fcu;
ked->curIndex = 0;
ked->curflags = ok;
}
/* if function to apply to bezier curves is set, then loop through executing it on beztriples */
if (key_cb) {
2.5 - Action Editor: All Keyframe Selection Tools Ported User Notes (for using tools whose behaviour has changed): * Mouse Selection Tools: 1) Click on keyframe to modify its selection. Holding the 'Shift' modifier when doing so, will result in keyframe selection being toggled instead of replacing existing selections. 2) Click on either side of the current frame indicator while holding the 'Alt' modifier. This will select only all the keyframes on the relevant side of the current frame indicator. 3) Click on a keyframe while holding the 'Ctrl' modifier. This will select all the keyframes that fall on that frame. * Borderselect Tools 1) BKEY selects all the keyframes within the specified range (as per normal) 2) ALT-BKEY will select either all the keyframes in the frame-range specified or the channel range specified, depending on which axis of the select region was larger. This method is prejudiced towards frame-range selection. Code Notes: * Finished porting over all of the remaining keyframe selection tools, and recoded the ported ones to make them easier to use (after running into some technical limitations) * Simplified the way to check if 'animation context' is valid by moving a necessary check into that function. * Refactored internal keyframe-looping tools to reduce the amount of code needed per tool to edit keyframes, removing a lot of the unnecessary bulk. Now, the ipo/icu_keys_bezier_loop functions recieve a few more arguments (1st arg is pointer to generic customdata, and another defines a validation callback which makes it easier to reuse some of the select callbacks). * Added 'totrect' adjustment for number of channels being shown in Action Editor, so that scrolling will be limited to where there is data (and also so that scroller displays more relevant context info). For this to work, filtering channels now returns the number of channels extracted. This may come into use for other tools if there's such a need. * I still need to port over some code for markers, which is required for some of the tools which use them. For now, those tools do nothing. * Grease-Pencil editing mode in Action Editor is currently non-functional (code is commented out due to missing dependencies). This is currently pending the re-implementation of Grease Pencil in 2.5
2008-12-26 10:55:07 +00:00
/* if there's a validation func, include that check in the loop
* (this is should be more efficient than checking for it in every loop)
*/
if (key_ok) {
2012-05-08 15:30:00 +00:00
for (bezt = fcu->bezt, i = 0; i < fcu->totvert; bezt++, i++) {
if (ked) {
/* advance the index, and reset the ok flags (to not influence the result) */
2012-05-08 15:30:00 +00:00
ked->curIndex = i;
ked->curflags = 0;
}
2.5 - Action Editor: All Keyframe Selection Tools Ported User Notes (for using tools whose behaviour has changed): * Mouse Selection Tools: 1) Click on keyframe to modify its selection. Holding the 'Shift' modifier when doing so, will result in keyframe selection being toggled instead of replacing existing selections. 2) Click on either side of the current frame indicator while holding the 'Alt' modifier. This will select only all the keyframes on the relevant side of the current frame indicator. 3) Click on a keyframe while holding the 'Ctrl' modifier. This will select all the keyframes that fall on that frame. * Borderselect Tools 1) BKEY selects all the keyframes within the specified range (as per normal) 2) ALT-BKEY will select either all the keyframes in the frame-range specified or the channel range specified, depending on which axis of the select region was larger. This method is prejudiced towards frame-range selection. Code Notes: * Finished porting over all of the remaining keyframe selection tools, and recoded the ported ones to make them easier to use (after running into some technical limitations) * Simplified the way to check if 'animation context' is valid by moving a necessary check into that function. * Refactored internal keyframe-looping tools to reduce the amount of code needed per tool to edit keyframes, removing a lot of the unnecessary bulk. Now, the ipo/icu_keys_bezier_loop functions recieve a few more arguments (1st arg is pointer to generic customdata, and another defines a validation callback which makes it easier to reuse some of the select callbacks). * Added 'totrect' adjustment for number of channels being shown in Action Editor, so that scrolling will be limited to where there is data (and also so that scroller displays more relevant context info). For this to work, filtering channels now returns the number of channels extracted. This may come into use for other tools if there's such a need. * I still need to port over some code for markers, which is required for some of the tools which use them. For now, those tools do nothing. * Grease-Pencil editing mode in Action Editor is currently non-functional (code is commented out due to missing dependencies). This is currently pending the re-implementation of Grease Pencil in 2.5
2008-12-26 10:55:07 +00:00
/* Only operate on this BezTriple if it fullfills the criteria of the validation func */
if ( (ok = key_ok(ked, bezt)) ) {
2012-05-08 15:30:00 +00:00
if (ked) ked->curflags = ok;
2.5 - Action Editor: All Keyframe Selection Tools Ported User Notes (for using tools whose behaviour has changed): * Mouse Selection Tools: 1) Click on keyframe to modify its selection. Holding the 'Shift' modifier when doing so, will result in keyframe selection being toggled instead of replacing existing selections. 2) Click on either side of the current frame indicator while holding the 'Alt' modifier. This will select only all the keyframes on the relevant side of the current frame indicator. 3) Click on a keyframe while holding the 'Ctrl' modifier. This will select all the keyframes that fall on that frame. * Borderselect Tools 1) BKEY selects all the keyframes within the specified range (as per normal) 2) ALT-BKEY will select either all the keyframes in the frame-range specified or the channel range specified, depending on which axis of the select region was larger. This method is prejudiced towards frame-range selection. Code Notes: * Finished porting over all of the remaining keyframe selection tools, and recoded the ported ones to make them easier to use (after running into some technical limitations) * Simplified the way to check if 'animation context' is valid by moving a necessary check into that function. * Refactored internal keyframe-looping tools to reduce the amount of code needed per tool to edit keyframes, removing a lot of the unnecessary bulk. Now, the ipo/icu_keys_bezier_loop functions recieve a few more arguments (1st arg is pointer to generic customdata, and another defines a validation callback which makes it easier to reuse some of the select callbacks). * Added 'totrect' adjustment for number of channels being shown in Action Editor, so that scrolling will be limited to where there is data (and also so that scroller displays more relevant context info). For this to work, filtering channels now returns the number of channels extracted. This may come into use for other tools if there's such a need. * I still need to port over some code for markers, which is required for some of the tools which use them. For now, those tools do nothing. * Grease-Pencil editing mode in Action Editor is currently non-functional (code is commented out due to missing dependencies). This is currently pending the re-implementation of Grease Pencil in 2.5
2008-12-26 10:55:07 +00:00
/* Exit with return-code '1' if function returns positive
* This is useful if finding if some BezTriple satisfies a condition.
*/
if (key_cb(ked, bezt)) return 1;
2.5 - Action Editor: All Keyframe Selection Tools Ported User Notes (for using tools whose behaviour has changed): * Mouse Selection Tools: 1) Click on keyframe to modify its selection. Holding the 'Shift' modifier when doing so, will result in keyframe selection being toggled instead of replacing existing selections. 2) Click on either side of the current frame indicator while holding the 'Alt' modifier. This will select only all the keyframes on the relevant side of the current frame indicator. 3) Click on a keyframe while holding the 'Ctrl' modifier. This will select all the keyframes that fall on that frame. * Borderselect Tools 1) BKEY selects all the keyframes within the specified range (as per normal) 2) ALT-BKEY will select either all the keyframes in the frame-range specified or the channel range specified, depending on which axis of the select region was larger. This method is prejudiced towards frame-range selection. Code Notes: * Finished porting over all of the remaining keyframe selection tools, and recoded the ported ones to make them easier to use (after running into some technical limitations) * Simplified the way to check if 'animation context' is valid by moving a necessary check into that function. * Refactored internal keyframe-looping tools to reduce the amount of code needed per tool to edit keyframes, removing a lot of the unnecessary bulk. Now, the ipo/icu_keys_bezier_loop functions recieve a few more arguments (1st arg is pointer to generic customdata, and another defines a validation callback which makes it easier to reuse some of the select callbacks). * Added 'totrect' adjustment for number of channels being shown in Action Editor, so that scrolling will be limited to where there is data (and also so that scroller displays more relevant context info). For this to work, filtering channels now returns the number of channels extracted. This may come into use for other tools if there's such a need. * I still need to port over some code for markers, which is required for some of the tools which use them. For now, those tools do nothing. * Grease-Pencil editing mode in Action Editor is currently non-functional (code is commented out due to missing dependencies). This is currently pending the re-implementation of Grease Pencil in 2.5
2008-12-26 10:55:07 +00:00
}
}
}
else {
2012-05-08 15:30:00 +00:00
for (bezt = fcu->bezt, i = 0; i < fcu->totvert; bezt++, i++) {
if (ked) ked->curIndex = i;
2.5 - Action Editor: All Keyframe Selection Tools Ported User Notes (for using tools whose behaviour has changed): * Mouse Selection Tools: 1) Click on keyframe to modify its selection. Holding the 'Shift' modifier when doing so, will result in keyframe selection being toggled instead of replacing existing selections. 2) Click on either side of the current frame indicator while holding the 'Alt' modifier. This will select only all the keyframes on the relevant side of the current frame indicator. 3) Click on a keyframe while holding the 'Ctrl' modifier. This will select all the keyframes that fall on that frame. * Borderselect Tools 1) BKEY selects all the keyframes within the specified range (as per normal) 2) ALT-BKEY will select either all the keyframes in the frame-range specified or the channel range specified, depending on which axis of the select region was larger. This method is prejudiced towards frame-range selection. Code Notes: * Finished porting over all of the remaining keyframe selection tools, and recoded the ported ones to make them easier to use (after running into some technical limitations) * Simplified the way to check if 'animation context' is valid by moving a necessary check into that function. * Refactored internal keyframe-looping tools to reduce the amount of code needed per tool to edit keyframes, removing a lot of the unnecessary bulk. Now, the ipo/icu_keys_bezier_loop functions recieve a few more arguments (1st arg is pointer to generic customdata, and another defines a validation callback which makes it easier to reuse some of the select callbacks). * Added 'totrect' adjustment for number of channels being shown in Action Editor, so that scrolling will be limited to where there is data (and also so that scroller displays more relevant context info). For this to work, filtering channels now returns the number of channels extracted. This may come into use for other tools if there's such a need. * I still need to port over some code for markers, which is required for some of the tools which use them. For now, those tools do nothing. * Grease-Pencil editing mode in Action Editor is currently non-functional (code is commented out due to missing dependencies). This is currently pending the re-implementation of Grease Pencil in 2.5
2008-12-26 10:55:07 +00:00
/* Exit with return-code '1' if function returns positive
* This is useful if finding if some BezTriple satisfies a condition.
*/
if (key_cb(ked, bezt)) return 1;
2.5 - Action Editor: All Keyframe Selection Tools Ported User Notes (for using tools whose behaviour has changed): * Mouse Selection Tools: 1) Click on keyframe to modify its selection. Holding the 'Shift' modifier when doing so, will result in keyframe selection being toggled instead of replacing existing selections. 2) Click on either side of the current frame indicator while holding the 'Alt' modifier. This will select only all the keyframes on the relevant side of the current frame indicator. 3) Click on a keyframe while holding the 'Ctrl' modifier. This will select all the keyframes that fall on that frame. * Borderselect Tools 1) BKEY selects all the keyframes within the specified range (as per normal) 2) ALT-BKEY will select either all the keyframes in the frame-range specified or the channel range specified, depending on which axis of the select region was larger. This method is prejudiced towards frame-range selection. Code Notes: * Finished porting over all of the remaining keyframe selection tools, and recoded the ported ones to make them easier to use (after running into some technical limitations) * Simplified the way to check if 'animation context' is valid by moving a necessary check into that function. * Refactored internal keyframe-looping tools to reduce the amount of code needed per tool to edit keyframes, removing a lot of the unnecessary bulk. Now, the ipo/icu_keys_bezier_loop functions recieve a few more arguments (1st arg is pointer to generic customdata, and another defines a validation callback which makes it easier to reuse some of the select callbacks). * Added 'totrect' adjustment for number of channels being shown in Action Editor, so that scrolling will be limited to where there is data (and also so that scroller displays more relevant context info). For this to work, filtering channels now returns the number of channels extracted. This may come into use for other tools if there's such a need. * I still need to port over some code for markers, which is required for some of the tools which use them. For now, those tools do nothing. * Grease-Pencil editing mode in Action Editor is currently non-functional (code is commented out due to missing dependencies). This is currently pending the re-implementation of Grease Pencil in 2.5
2008-12-26 10:55:07 +00:00
}
}
}
/* unset the F-Curve from the editdata now that it's done */
if (ked) {
2012-05-08 15:30:00 +00:00
ked->fcu = NULL;
ked->curIndex = 0;
ked->curflags = 0;
}
/* if fcu_cb (F-Curve post-editing callback) has been specified then execute it */
if (fcu_cb)
fcu_cb(fcu);
/* done */
return 0;
}
/* -------------------------------- Further Abstracted (Not Exposed Directly) ----------------------------- */
2.5 - Action Editor: All Keyframe Selection Tools Ported User Notes (for using tools whose behaviour has changed): * Mouse Selection Tools: 1) Click on keyframe to modify its selection. Holding the 'Shift' modifier when doing so, will result in keyframe selection being toggled instead of replacing existing selections. 2) Click on either side of the current frame indicator while holding the 'Alt' modifier. This will select only all the keyframes on the relevant side of the current frame indicator. 3) Click on a keyframe while holding the 'Ctrl' modifier. This will select all the keyframes that fall on that frame. * Borderselect Tools 1) BKEY selects all the keyframes within the specified range (as per normal) 2) ALT-BKEY will select either all the keyframes in the frame-range specified or the channel range specified, depending on which axis of the select region was larger. This method is prejudiced towards frame-range selection. Code Notes: * Finished porting over all of the remaining keyframe selection tools, and recoded the ported ones to make them easier to use (after running into some technical limitations) * Simplified the way to check if 'animation context' is valid by moving a necessary check into that function. * Refactored internal keyframe-looping tools to reduce the amount of code needed per tool to edit keyframes, removing a lot of the unnecessary bulk. Now, the ipo/icu_keys_bezier_loop functions recieve a few more arguments (1st arg is pointer to generic customdata, and another defines a validation callback which makes it easier to reuse some of the select callbacks). * Added 'totrect' adjustment for number of channels being shown in Action Editor, so that scrolling will be limited to where there is data (and also so that scroller displays more relevant context info). For this to work, filtering channels now returns the number of channels extracted. This may come into use for other tools if there's such a need. * I still need to port over some code for markers, which is required for some of the tools which use them. For now, those tools do nothing. * Grease-Pencil editing mode in Action Editor is currently non-functional (code is commented out due to missing dependencies). This is currently pending the re-implementation of Grease Pencil in 2.5
2008-12-26 10:55:07 +00:00
/* This function is used to loop over the keyframe data in an Action Group */
static short agrp_keyframes_loop(KeyframeEditData *ked, bActionGroup *agrp, KeyframeEditFunc key_ok, KeyframeEditFunc key_cb, FcuEditFunc fcu_cb)
{
FCurve *fcu;
/* sanity check */
if (agrp == NULL)
return 0;
/* only iterate over the F-Curves that are in this group */
2012-05-08 15:30:00 +00:00
for (fcu = agrp->channels.first; fcu && fcu->grp == agrp; fcu = fcu->next) {
if (ANIM_fcurve_keyframes_loop(ked, fcu, key_ok, key_cb, fcu_cb))
return 1;
}
return 0;
}
/* This function is used to loop over the keyframe data in an Action */
static short act_keyframes_loop(KeyframeEditData *ked, bAction *act, KeyframeEditFunc key_ok, KeyframeEditFunc key_cb, FcuEditFunc fcu_cb)
{
FCurve *fcu;
/* sanity check */
if (act == NULL)
return 0;
/* just loop through all F-Curves */
2012-05-08 15:30:00 +00:00
for (fcu = act->curves.first; fcu; fcu = fcu->next) {
if (ANIM_fcurve_keyframes_loop(ked, fcu, key_ok, key_cb, fcu_cb))
return 1;
}
return 0;
}
/* This function is used to loop over the keyframe data in an Object */
static short ob_keyframes_loop(KeyframeEditData *ked, bDopeSheet *ads, Object *ob, KeyframeEditFunc key_ok, KeyframeEditFunc key_cb, FcuEditFunc fcu_cb)
{
bAnimContext ac = {NULL};
ListBase anim_data = {NULL, NULL};
bAnimListElem *ale;
int filter;
2012-05-08 15:30:00 +00:00
int ret = 0;
bAnimListElem dummychan = {NULL};
Base dummybase = {NULL};
if (ob == NULL)
return 0;
/* create a dummy wrapper data to work with */
dummybase.object = ob;
dummychan.type = ANIMTYPE_OBJECT;
dummychan.data = &dummybase;
dummychan.id = &ob->id;
dummychan.adt = ob->adt;
ac.ads = ads;
ac.data = &dummychan;
ac.datatype = ANIMCONT_CHANNEL;
/* get F-Curves to take keyframes from */
2012-05-08 15:30:00 +00:00
filter = ANIMFILTER_DATA_VISIBLE; // curves only
ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
/* loop through each F-Curve, applying the operation as required, but stopping on the first one */
2012-05-08 15:30:00 +00:00
for (ale = anim_data.first; ale; ale = ale->next) {
if (ANIM_fcurve_keyframes_loop(ked, (FCurve *)ale->data, key_ok, key_cb, fcu_cb)) {
ret = 1;
break;
}
}
BLI_freelistN(&anim_data);
/* return return code - defaults to zero if nothing happened */
return ret;
}
/* This function is used to loop over the keyframe data in a Scene */
static short scene_keyframes_loop(KeyframeEditData *ked, bDopeSheet *ads, Scene *sce, KeyframeEditFunc key_ok, KeyframeEditFunc key_cb, FcuEditFunc fcu_cb)
{
bAnimContext ac = {NULL};
ListBase anim_data = {NULL, NULL};
bAnimListElem *ale;
int filter;
2012-05-08 15:30:00 +00:00
int ret = 0;
bAnimListElem dummychan = {NULL};
if (sce == NULL)
return 0;
/* create a dummy wrapper data to work with */
dummychan.type = ANIMTYPE_SCENE;
dummychan.data = sce;
dummychan.id = &sce->id;
dummychan.adt = sce->adt;
ac.ads = ads;
ac.data = &dummychan;
ac.datatype = ANIMCONT_CHANNEL;
/* get F-Curves to take keyframes from */
2012-05-08 15:30:00 +00:00
filter = ANIMFILTER_DATA_VISIBLE; // curves only
ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
/* loop through each F-Curve, applying the operation as required, but stopping on the first one */
2012-05-08 15:30:00 +00:00
for (ale = anim_data.first; ale; ale = ale->next) {
if (ANIM_fcurve_keyframes_loop(ked, (FCurve *)ale->data, key_ok, key_cb, fcu_cb)) {
ret = 1;
break;
}
}
BLI_freelistN(&anim_data);
/* return return code - defaults to zero if nothing happened */
return ret;
}
/* This function is used to loop over the keyframe data in a DopeSheet summary */
static short summary_keyframes_loop(KeyframeEditData *ked, bAnimContext *ac, KeyframeEditFunc key_ok, KeyframeEditFunc key_cb, FcuEditFunc fcu_cb)
{
ListBase anim_data = {NULL, NULL};
bAnimListElem *ale;
2012-05-08 15:30:00 +00:00
int filter, ret_code = 0;
/* sanity check */
if (ac == NULL)
return 0;
/* get F-Curves to take keyframes from */
2012-05-08 15:30:00 +00:00
filter = ANIMFILTER_DATA_VISIBLE;
ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
/* loop through each F-Curve, working on the keyframes until the first curve aborts */
2012-05-08 15:30:00 +00:00
for (ale = anim_data.first; ale; ale = ale->next) {
ret_code = ANIM_fcurve_keyframes_loop(ked, ale->data, key_ok, key_cb, fcu_cb);
if (ret_code)
break;
}
BLI_freelistN(&anim_data);
return ret_code;
}
/* --- */
2.5 - Action Editor: All Keyframe Selection Tools Ported User Notes (for using tools whose behaviour has changed): * Mouse Selection Tools: 1) Click on keyframe to modify its selection. Holding the 'Shift' modifier when doing so, will result in keyframe selection being toggled instead of replacing existing selections. 2) Click on either side of the current frame indicator while holding the 'Alt' modifier. This will select only all the keyframes on the relevant side of the current frame indicator. 3) Click on a keyframe while holding the 'Ctrl' modifier. This will select all the keyframes that fall on that frame. * Borderselect Tools 1) BKEY selects all the keyframes within the specified range (as per normal) 2) ALT-BKEY will select either all the keyframes in the frame-range specified or the channel range specified, depending on which axis of the select region was larger. This method is prejudiced towards frame-range selection. Code Notes: * Finished porting over all of the remaining keyframe selection tools, and recoded the ported ones to make them easier to use (after running into some technical limitations) * Simplified the way to check if 'animation context' is valid by moving a necessary check into that function. * Refactored internal keyframe-looping tools to reduce the amount of code needed per tool to edit keyframes, removing a lot of the unnecessary bulk. Now, the ipo/icu_keys_bezier_loop functions recieve a few more arguments (1st arg is pointer to generic customdata, and another defines a validation callback which makes it easier to reuse some of the select callbacks). * Added 'totrect' adjustment for number of channels being shown in Action Editor, so that scrolling will be limited to where there is data (and also so that scroller displays more relevant context info). For this to work, filtering channels now returns the number of channels extracted. This may come into use for other tools if there's such a need. * I still need to port over some code for markers, which is required for some of the tools which use them. For now, those tools do nothing. * Grease-Pencil editing mode in Action Editor is currently non-functional (code is commented out due to missing dependencies). This is currently pending the re-implementation of Grease Pencil in 2.5
2008-12-26 10:55:07 +00:00
/* This function is used to apply operation to all keyframes, regardless of the type */
short ANIM_animchannel_keyframes_loop(KeyframeEditData *ked, bDopeSheet *ads, bAnimListElem *ale, KeyframeEditFunc key_ok, KeyframeEditFunc key_cb, FcuEditFunc fcu_cb)
{
/* sanity checks */
if (ale == NULL)
return 0;
/* method to use depends on the type of keyframe data */
switch (ale->datatype) {
/* direct keyframe data (these loops are exposed) */
case ALE_FCURVE: /* F-Curve */
return ANIM_fcurve_keyframes_loop(ked, ale->key_data, key_ok, key_cb, fcu_cb);
/* indirect 'summaries' (these are not exposed directly)
* NOTE: must keep this code in sync with the drawing code and also the filtering code!
*/
case ALE_GROUP: /* action group */
return agrp_keyframes_loop(ked, (bActionGroup *)ale->data, key_ok, key_cb, fcu_cb);
case ALE_ACT: /* action */
return act_keyframes_loop(ked, (bAction *)ale->key_data, key_ok, key_cb, fcu_cb);
case ALE_OB: /* object */
return ob_keyframes_loop(ked, ads, (Object *)ale->key_data, key_ok, key_cb, fcu_cb);
case ALE_SCE: /* scene */
return scene_keyframes_loop(ked, ads, (Scene *)ale->data, key_ok, key_cb, fcu_cb);
case ALE_ALL: /* 'all' (DopeSheet summary) */
return summary_keyframes_loop(ked, (bAnimContext *)ale->data, key_ok, key_cb, fcu_cb);
}
2.5 - Action Editor: All Keyframe Selection Tools Ported User Notes (for using tools whose behaviour has changed): * Mouse Selection Tools: 1) Click on keyframe to modify its selection. Holding the 'Shift' modifier when doing so, will result in keyframe selection being toggled instead of replacing existing selections. 2) Click on either side of the current frame indicator while holding the 'Alt' modifier. This will select only all the keyframes on the relevant side of the current frame indicator. 3) Click on a keyframe while holding the 'Ctrl' modifier. This will select all the keyframes that fall on that frame. * Borderselect Tools 1) BKEY selects all the keyframes within the specified range (as per normal) 2) ALT-BKEY will select either all the keyframes in the frame-range specified or the channel range specified, depending on which axis of the select region was larger. This method is prejudiced towards frame-range selection. Code Notes: * Finished porting over all of the remaining keyframe selection tools, and recoded the ported ones to make them easier to use (after running into some technical limitations) * Simplified the way to check if 'animation context' is valid by moving a necessary check into that function. * Refactored internal keyframe-looping tools to reduce the amount of code needed per tool to edit keyframes, removing a lot of the unnecessary bulk. Now, the ipo/icu_keys_bezier_loop functions recieve a few more arguments (1st arg is pointer to generic customdata, and another defines a validation callback which makes it easier to reuse some of the select callbacks). * Added 'totrect' adjustment for number of channels being shown in Action Editor, so that scrolling will be limited to where there is data (and also so that scroller displays more relevant context info). For this to work, filtering channels now returns the number of channels extracted. This may come into use for other tools if there's such a need. * I still need to port over some code for markers, which is required for some of the tools which use them. For now, those tools do nothing. * Grease-Pencil editing mode in Action Editor is currently non-functional (code is commented out due to missing dependencies). This is currently pending the re-implementation of Grease Pencil in 2.5
2008-12-26 10:55:07 +00:00
return 0;
}
/* This function is used to apply operation to all keyframes, regardless of the type without needed an AnimListElem wrapper */
short ANIM_animchanneldata_keyframes_loop(KeyframeEditData *ked, bDopeSheet *ads, void *data, int keytype, KeyframeEditFunc key_ok, KeyframeEditFunc key_cb, FcuEditFunc fcu_cb)
{
/* sanity checks */
if (data == NULL)
return 0;
/* method to use depends on the type of keyframe data */
switch (keytype) {
/* direct keyframe data (these loops are exposed) */
case ALE_FCURVE: /* F-Curve */
return ANIM_fcurve_keyframes_loop(ked, data, key_ok, key_cb, fcu_cb);
/* indirect 'summaries' (these are not exposed directly)
* NOTE: must keep this code in sync with the drawing code and also the filtering code!
*/
case ALE_GROUP: /* action group */
return agrp_keyframes_loop(ked, (bActionGroup *)data, key_ok, key_cb, fcu_cb);
case ALE_ACT: /* action */
return act_keyframes_loop(ked, (bAction *)data, key_ok, key_cb, fcu_cb);
case ALE_OB: /* object */
return ob_keyframes_loop(ked, ads, (Object *)data, key_ok, key_cb, fcu_cb);
case ALE_SCE: /* scene */
return scene_keyframes_loop(ked, ads, (Scene *)data, key_ok, key_cb, fcu_cb);
case ALE_ALL: /* 'all' (DopeSheet summary) */
return summary_keyframes_loop(ked, (bAnimContext *)data, key_ok, key_cb, fcu_cb);
}
return 0;
}
/* ************************************************************************** */
/* Keyframe Integrity Tools */
/* Rearrange keyframes if some are out of order */
// used to be recalc_*_ipos() where * was object or action
void ANIM_editkeyframes_refresh(bAnimContext *ac)
{
ListBase anim_data = {NULL, NULL};
bAnimListElem *ale;
int filter;
/* when not in graph view, don't use handles */
2012-05-08 15:30:00 +00:00
SpaceIpo *sipo = (ac->spacetype == SPACE_IPO) ? (SpaceIpo *)ac->sl : NULL;
const short use_handle = sipo ? !(sipo->flag & SIPO_NOHANDLES) : FALSE;
/* filter animation data */
2012-05-08 15:30:00 +00:00
filter = ANIMFILTER_DATA_VISIBLE;
ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
/* loop over F-Curves that are likely to have been edited, and check them */
2012-05-08 15:30:00 +00:00
for (ale = anim_data.first; ale; ale = ale->next) {
FCurve *fcu = ale->key_data;
/* make sure keyframes in F-Curve are all in order, and handles are in valid positions */
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
sort_time_fcurve(fcu);
testhandles_fcurve(fcu, use_handle);
}
/* free temp data */
BLI_freelistN(&anim_data);
}
2.5 - Action Editor: All Keyframe Selection Tools Ported User Notes (for using tools whose behaviour has changed): * Mouse Selection Tools: 1) Click on keyframe to modify its selection. Holding the 'Shift' modifier when doing so, will result in keyframe selection being toggled instead of replacing existing selections. 2) Click on either side of the current frame indicator while holding the 'Alt' modifier. This will select only all the keyframes on the relevant side of the current frame indicator. 3) Click on a keyframe while holding the 'Ctrl' modifier. This will select all the keyframes that fall on that frame. * Borderselect Tools 1) BKEY selects all the keyframes within the specified range (as per normal) 2) ALT-BKEY will select either all the keyframes in the frame-range specified or the channel range specified, depending on which axis of the select region was larger. This method is prejudiced towards frame-range selection. Code Notes: * Finished porting over all of the remaining keyframe selection tools, and recoded the ported ones to make them easier to use (after running into some technical limitations) * Simplified the way to check if 'animation context' is valid by moving a necessary check into that function. * Refactored internal keyframe-looping tools to reduce the amount of code needed per tool to edit keyframes, removing a lot of the unnecessary bulk. Now, the ipo/icu_keys_bezier_loop functions recieve a few more arguments (1st arg is pointer to generic customdata, and another defines a validation callback which makes it easier to reuse some of the select callbacks). * Added 'totrect' adjustment for number of channels being shown in Action Editor, so that scrolling will be limited to where there is data (and also so that scroller displays more relevant context info). For this to work, filtering channels now returns the number of channels extracted. This may come into use for other tools if there's such a need. * I still need to port over some code for markers, which is required for some of the tools which use them. For now, those tools do nothing. * Grease-Pencil editing mode in Action Editor is currently non-functional (code is commented out due to missing dependencies). This is currently pending the re-implementation of Grease Pencil in 2.5
2008-12-26 10:55:07 +00:00
/* ************************************************************************** */
/* BezTriple Validation Callbacks */
/* ------------------------ */
/* Some macros to make this easier... */
/* run the given check on the 3 handles
* - check should be a macro, which takes the handle index as its single arg, which it substitutes later
* - requires that a var, of type short, is named 'ok', and has been initialized to 0
*/
#define KEYFRAME_OK_CHECKS(check) \
{ \
if (check(1)) \
ok |= KEYFRAME_OK_KEY; \
\
if (ked && (ked->iterflags & KEYFRAME_ITER_INCL_HANDLES)) { \
if (check(0)) \
ok |= KEYFRAME_OK_H1; \
if (check(2)) \
ok |= KEYFRAME_OK_H2; \
} \
2012-05-27 20:13:59 +00:00
} (void)0
/* ------------------------ */
static short ok_bezier_frame(KeyframeEditData *ked, BezTriple *bezt)
{
short ok = 0;
2.5 - Action Editor: All Keyframe Selection Tools Ported User Notes (for using tools whose behaviour has changed): * Mouse Selection Tools: 1) Click on keyframe to modify its selection. Holding the 'Shift' modifier when doing so, will result in keyframe selection being toggled instead of replacing existing selections. 2) Click on either side of the current frame indicator while holding the 'Alt' modifier. This will select only all the keyframes on the relevant side of the current frame indicator. 3) Click on a keyframe while holding the 'Ctrl' modifier. This will select all the keyframes that fall on that frame. * Borderselect Tools 1) BKEY selects all the keyframes within the specified range (as per normal) 2) ALT-BKEY will select either all the keyframes in the frame-range specified or the channel range specified, depending on which axis of the select region was larger. This method is prejudiced towards frame-range selection. Code Notes: * Finished porting over all of the remaining keyframe selection tools, and recoded the ported ones to make them easier to use (after running into some technical limitations) * Simplified the way to check if 'animation context' is valid by moving a necessary check into that function. * Refactored internal keyframe-looping tools to reduce the amount of code needed per tool to edit keyframes, removing a lot of the unnecessary bulk. Now, the ipo/icu_keys_bezier_loop functions recieve a few more arguments (1st arg is pointer to generic customdata, and another defines a validation callback which makes it easier to reuse some of the select callbacks). * Added 'totrect' adjustment for number of channels being shown in Action Editor, so that scrolling will be limited to where there is data (and also so that scroller displays more relevant context info). For this to work, filtering channels now returns the number of channels extracted. This may come into use for other tools if there's such a need. * I still need to port over some code for markers, which is required for some of the tools which use them. For now, those tools do nothing. * Grease-Pencil editing mode in Action Editor is currently non-functional (code is commented out due to missing dependencies). This is currently pending the re-implementation of Grease Pencil in 2.5
2008-12-26 10:55:07 +00:00
/* frame is stored in f1 property (this float accuracy check may need to be dropped?) */
#define KEY_CHECK_OK(_index) IS_EQF(bezt->vec[_index][0], ked->f1)
2012-05-08 15:30:00 +00:00
KEYFRAME_OK_CHECKS(KEY_CHECK_OK);
#undef KEY_CHECK_OK
/* return ok flags */
return ok;
2.5 - Action Editor: All Keyframe Selection Tools Ported User Notes (for using tools whose behaviour has changed): * Mouse Selection Tools: 1) Click on keyframe to modify its selection. Holding the 'Shift' modifier when doing so, will result in keyframe selection being toggled instead of replacing existing selections. 2) Click on either side of the current frame indicator while holding the 'Alt' modifier. This will select only all the keyframes on the relevant side of the current frame indicator. 3) Click on a keyframe while holding the 'Ctrl' modifier. This will select all the keyframes that fall on that frame. * Borderselect Tools 1) BKEY selects all the keyframes within the specified range (as per normal) 2) ALT-BKEY will select either all the keyframes in the frame-range specified or the channel range specified, depending on which axis of the select region was larger. This method is prejudiced towards frame-range selection. Code Notes: * Finished porting over all of the remaining keyframe selection tools, and recoded the ported ones to make them easier to use (after running into some technical limitations) * Simplified the way to check if 'animation context' is valid by moving a necessary check into that function. * Refactored internal keyframe-looping tools to reduce the amount of code needed per tool to edit keyframes, removing a lot of the unnecessary bulk. Now, the ipo/icu_keys_bezier_loop functions recieve a few more arguments (1st arg is pointer to generic customdata, and another defines a validation callback which makes it easier to reuse some of the select callbacks). * Added 'totrect' adjustment for number of channels being shown in Action Editor, so that scrolling will be limited to where there is data (and also so that scroller displays more relevant context info). For this to work, filtering channels now returns the number of channels extracted. This may come into use for other tools if there's such a need. * I still need to port over some code for markers, which is required for some of the tools which use them. For now, those tools do nothing. * Grease-Pencil editing mode in Action Editor is currently non-functional (code is commented out due to missing dependencies). This is currently pending the re-implementation of Grease Pencil in 2.5
2008-12-26 10:55:07 +00:00
}
static short ok_bezier_framerange(KeyframeEditData *ked, BezTriple *bezt)
2.5 - Action Editor: All Keyframe Selection Tools Ported User Notes (for using tools whose behaviour has changed): * Mouse Selection Tools: 1) Click on keyframe to modify its selection. Holding the 'Shift' modifier when doing so, will result in keyframe selection being toggled instead of replacing existing selections. 2) Click on either side of the current frame indicator while holding the 'Alt' modifier. This will select only all the keyframes on the relevant side of the current frame indicator. 3) Click on a keyframe while holding the 'Ctrl' modifier. This will select all the keyframes that fall on that frame. * Borderselect Tools 1) BKEY selects all the keyframes within the specified range (as per normal) 2) ALT-BKEY will select either all the keyframes in the frame-range specified or the channel range specified, depending on which axis of the select region was larger. This method is prejudiced towards frame-range selection. Code Notes: * Finished porting over all of the remaining keyframe selection tools, and recoded the ported ones to make them easier to use (after running into some technical limitations) * Simplified the way to check if 'animation context' is valid by moving a necessary check into that function. * Refactored internal keyframe-looping tools to reduce the amount of code needed per tool to edit keyframes, removing a lot of the unnecessary bulk. Now, the ipo/icu_keys_bezier_loop functions recieve a few more arguments (1st arg is pointer to generic customdata, and another defines a validation callback which makes it easier to reuse some of the select callbacks). * Added 'totrect' adjustment for number of channels being shown in Action Editor, so that scrolling will be limited to where there is data (and also so that scroller displays more relevant context info). For this to work, filtering channels now returns the number of channels extracted. This may come into use for other tools if there's such a need. * I still need to port over some code for markers, which is required for some of the tools which use them. For now, those tools do nothing. * Grease-Pencil editing mode in Action Editor is currently non-functional (code is commented out due to missing dependencies). This is currently pending the re-implementation of Grease Pencil in 2.5
2008-12-26 10:55:07 +00:00
{
short ok = 0;
2.5 - Action Editor: All Keyframe Selection Tools Ported User Notes (for using tools whose behaviour has changed): * Mouse Selection Tools: 1) Click on keyframe to modify its selection. Holding the 'Shift' modifier when doing so, will result in keyframe selection being toggled instead of replacing existing selections. 2) Click on either side of the current frame indicator while holding the 'Alt' modifier. This will select only all the keyframes on the relevant side of the current frame indicator. 3) Click on a keyframe while holding the 'Ctrl' modifier. This will select all the keyframes that fall on that frame. * Borderselect Tools 1) BKEY selects all the keyframes within the specified range (as per normal) 2) ALT-BKEY will select either all the keyframes in the frame-range specified or the channel range specified, depending on which axis of the select region was larger. This method is prejudiced towards frame-range selection. Code Notes: * Finished porting over all of the remaining keyframe selection tools, and recoded the ported ones to make them easier to use (after running into some technical limitations) * Simplified the way to check if 'animation context' is valid by moving a necessary check into that function. * Refactored internal keyframe-looping tools to reduce the amount of code needed per tool to edit keyframes, removing a lot of the unnecessary bulk. Now, the ipo/icu_keys_bezier_loop functions recieve a few more arguments (1st arg is pointer to generic customdata, and another defines a validation callback which makes it easier to reuse some of the select callbacks). * Added 'totrect' adjustment for number of channels being shown in Action Editor, so that scrolling will be limited to where there is data (and also so that scroller displays more relevant context info). For this to work, filtering channels now returns the number of channels extracted. This may come into use for other tools if there's such a need. * I still need to port over some code for markers, which is required for some of the tools which use them. For now, those tools do nothing. * Grease-Pencil editing mode in Action Editor is currently non-functional (code is commented out due to missing dependencies). This is currently pending the re-implementation of Grease Pencil in 2.5
2008-12-26 10:55:07 +00:00
/* frame range is stored in float properties */
#define KEY_CHECK_OK(_index) ((bezt->vec[_index][0] > ked->f1) && (bezt->vec[_index][0] < ked->f2))
2012-05-08 15:30:00 +00:00
KEYFRAME_OK_CHECKS(KEY_CHECK_OK);
#undef KEY_CHECK_OK
/* return ok flags */
return ok;
}
static short ok_bezier_selected(KeyframeEditData *UNUSED(ked), BezTriple *bezt)
2.5 - Action Editor: All Keyframe Selection Tools Ported User Notes (for using tools whose behaviour has changed): * Mouse Selection Tools: 1) Click on keyframe to modify its selection. Holding the 'Shift' modifier when doing so, will result in keyframe selection being toggled instead of replacing existing selections. 2) Click on either side of the current frame indicator while holding the 'Alt' modifier. This will select only all the keyframes on the relevant side of the current frame indicator. 3) Click on a keyframe while holding the 'Ctrl' modifier. This will select all the keyframes that fall on that frame. * Borderselect Tools 1) BKEY selects all the keyframes within the specified range (as per normal) 2) ALT-BKEY will select either all the keyframes in the frame-range specified or the channel range specified, depending on which axis of the select region was larger. This method is prejudiced towards frame-range selection. Code Notes: * Finished porting over all of the remaining keyframe selection tools, and recoded the ported ones to make them easier to use (after running into some technical limitations) * Simplified the way to check if 'animation context' is valid by moving a necessary check into that function. * Refactored internal keyframe-looping tools to reduce the amount of code needed per tool to edit keyframes, removing a lot of the unnecessary bulk. Now, the ipo/icu_keys_bezier_loop functions recieve a few more arguments (1st arg is pointer to generic customdata, and another defines a validation callback which makes it easier to reuse some of the select callbacks). * Added 'totrect' adjustment for number of channels being shown in Action Editor, so that scrolling will be limited to where there is data (and also so that scroller displays more relevant context info). For this to work, filtering channels now returns the number of channels extracted. This may come into use for other tools if there's such a need. * I still need to port over some code for markers, which is required for some of the tools which use them. For now, those tools do nothing. * Grease-Pencil editing mode in Action Editor is currently non-functional (code is commented out due to missing dependencies). This is currently pending the re-implementation of Grease Pencil in 2.5
2008-12-26 10:55:07 +00:00
{
/* this macro checks all beztriple handles for selection...
2012-05-08 15:30:00 +00:00
* only one of the verts has to be selected for this to be ok...
*/
if (BEZSELECTED(bezt))
return KEYFRAME_OK_ALL;
else
return 0;
2.5 - Action Editor: All Keyframe Selection Tools Ported User Notes (for using tools whose behaviour has changed): * Mouse Selection Tools: 1) Click on keyframe to modify its selection. Holding the 'Shift' modifier when doing so, will result in keyframe selection being toggled instead of replacing existing selections. 2) Click on either side of the current frame indicator while holding the 'Alt' modifier. This will select only all the keyframes on the relevant side of the current frame indicator. 3) Click on a keyframe while holding the 'Ctrl' modifier. This will select all the keyframes that fall on that frame. * Borderselect Tools 1) BKEY selects all the keyframes within the specified range (as per normal) 2) ALT-BKEY will select either all the keyframes in the frame-range specified or the channel range specified, depending on which axis of the select region was larger. This method is prejudiced towards frame-range selection. Code Notes: * Finished porting over all of the remaining keyframe selection tools, and recoded the ported ones to make them easier to use (after running into some technical limitations) * Simplified the way to check if 'animation context' is valid by moving a necessary check into that function. * Refactored internal keyframe-looping tools to reduce the amount of code needed per tool to edit keyframes, removing a lot of the unnecessary bulk. Now, the ipo/icu_keys_bezier_loop functions recieve a few more arguments (1st arg is pointer to generic customdata, and another defines a validation callback which makes it easier to reuse some of the select callbacks). * Added 'totrect' adjustment for number of channels being shown in Action Editor, so that scrolling will be limited to where there is data (and also so that scroller displays more relevant context info). For this to work, filtering channels now returns the number of channels extracted. This may come into use for other tools if there's such a need. * I still need to port over some code for markers, which is required for some of the tools which use them. For now, those tools do nothing. * Grease-Pencil editing mode in Action Editor is currently non-functional (code is commented out due to missing dependencies). This is currently pending the re-implementation of Grease Pencil in 2.5
2008-12-26 10:55:07 +00:00
}
static short ok_bezier_value(KeyframeEditData *ked, BezTriple *bezt)
{
short ok = 0;
2.5 - Action Editor: All Keyframe Selection Tools Ported User Notes (for using tools whose behaviour has changed): * Mouse Selection Tools: 1) Click on keyframe to modify its selection. Holding the 'Shift' modifier when doing so, will result in keyframe selection being toggled instead of replacing existing selections. 2) Click on either side of the current frame indicator while holding the 'Alt' modifier. This will select only all the keyframes on the relevant side of the current frame indicator. 3) Click on a keyframe while holding the 'Ctrl' modifier. This will select all the keyframes that fall on that frame. * Borderselect Tools 1) BKEY selects all the keyframes within the specified range (as per normal) 2) ALT-BKEY will select either all the keyframes in the frame-range specified or the channel range specified, depending on which axis of the select region was larger. This method is prejudiced towards frame-range selection. Code Notes: * Finished porting over all of the remaining keyframe selection tools, and recoded the ported ones to make them easier to use (after running into some technical limitations) * Simplified the way to check if 'animation context' is valid by moving a necessary check into that function. * Refactored internal keyframe-looping tools to reduce the amount of code needed per tool to edit keyframes, removing a lot of the unnecessary bulk. Now, the ipo/icu_keys_bezier_loop functions recieve a few more arguments (1st arg is pointer to generic customdata, and another defines a validation callback which makes it easier to reuse some of the select callbacks). * Added 'totrect' adjustment for number of channels being shown in Action Editor, so that scrolling will be limited to where there is data (and also so that scroller displays more relevant context info). For this to work, filtering channels now returns the number of channels extracted. This may come into use for other tools if there's such a need. * I still need to port over some code for markers, which is required for some of the tools which use them. For now, those tools do nothing. * Grease-Pencil editing mode in Action Editor is currently non-functional (code is commented out due to missing dependencies). This is currently pending the re-implementation of Grease Pencil in 2.5
2008-12-26 10:55:07 +00:00
/* value is stored in f1 property
* - this float accuracy check may need to be dropped?
* - should value be stored in f2 instead so that we won't have conflicts when using f1 for frames too?
*/
#define KEY_CHECK_OK(_index) IS_EQF(bezt->vec[_index][1], ked->f1)
2012-05-08 15:30:00 +00:00
KEYFRAME_OK_CHECKS(KEY_CHECK_OK);
#undef KEY_CHECK_OK
/* return ok flags */
return ok;
2.5 - Action Editor: All Keyframe Selection Tools Ported User Notes (for using tools whose behaviour has changed): * Mouse Selection Tools: 1) Click on keyframe to modify its selection. Holding the 'Shift' modifier when doing so, will result in keyframe selection being toggled instead of replacing existing selections. 2) Click on either side of the current frame indicator while holding the 'Alt' modifier. This will select only all the keyframes on the relevant side of the current frame indicator. 3) Click on a keyframe while holding the 'Ctrl' modifier. This will select all the keyframes that fall on that frame. * Borderselect Tools 1) BKEY selects all the keyframes within the specified range (as per normal) 2) ALT-BKEY will select either all the keyframes in the frame-range specified or the channel range specified, depending on which axis of the select region was larger. This method is prejudiced towards frame-range selection. Code Notes: * Finished porting over all of the remaining keyframe selection tools, and recoded the ported ones to make them easier to use (after running into some technical limitations) * Simplified the way to check if 'animation context' is valid by moving a necessary check into that function. * Refactored internal keyframe-looping tools to reduce the amount of code needed per tool to edit keyframes, removing a lot of the unnecessary bulk. Now, the ipo/icu_keys_bezier_loop functions recieve a few more arguments (1st arg is pointer to generic customdata, and another defines a validation callback which makes it easier to reuse some of the select callbacks). * Added 'totrect' adjustment for number of channels being shown in Action Editor, so that scrolling will be limited to where there is data (and also so that scroller displays more relevant context info). For this to work, filtering channels now returns the number of channels extracted. This may come into use for other tools if there's such a need. * I still need to port over some code for markers, which is required for some of the tools which use them. For now, those tools do nothing. * Grease-Pencil editing mode in Action Editor is currently non-functional (code is commented out due to missing dependencies). This is currently pending the re-implementation of Grease Pencil in 2.5
2008-12-26 10:55:07 +00:00
}
static short ok_bezier_valuerange(KeyframeEditData *ked, BezTriple *bezt)
{
short ok = 0;
/* value range is stored in float properties */
#define KEY_CHECK_OK(_index) ((bezt->vec[_index][1] > ked->f1) && (bezt->vec[_index][1] < ked->f2))
2012-05-08 15:30:00 +00:00
KEYFRAME_OK_CHECKS(KEY_CHECK_OK);
#undef KEY_CHECK_OK
/* return ok flags */
return ok;
}
static short ok_bezier_region(KeyframeEditData *ked, BezTriple *bezt)
{
/* rect is stored in data property (it's of type rectf, but may not be set) */
if (ked->data) {
short ok = 0;
#define KEY_CHECK_OK(_index) BLI_in_rctf(ked->data, bezt->vec[_index][0], bezt->vec[_index][1])
2012-05-08 15:30:00 +00:00
KEYFRAME_OK_CHECKS(KEY_CHECK_OK);
#undef KEY_CHECK_OK
/* return ok flags */
return ok;
}
else
return 0;
}
2.5 - Action Editor: All Keyframe Selection Tools Ported User Notes (for using tools whose behaviour has changed): * Mouse Selection Tools: 1) Click on keyframe to modify its selection. Holding the 'Shift' modifier when doing so, will result in keyframe selection being toggled instead of replacing existing selections. 2) Click on either side of the current frame indicator while holding the 'Alt' modifier. This will select only all the keyframes on the relevant side of the current frame indicator. 3) Click on a keyframe while holding the 'Ctrl' modifier. This will select all the keyframes that fall on that frame. * Borderselect Tools 1) BKEY selects all the keyframes within the specified range (as per normal) 2) ALT-BKEY will select either all the keyframes in the frame-range specified or the channel range specified, depending on which axis of the select region was larger. This method is prejudiced towards frame-range selection. Code Notes: * Finished porting over all of the remaining keyframe selection tools, and recoded the ported ones to make them easier to use (after running into some technical limitations) * Simplified the way to check if 'animation context' is valid by moving a necessary check into that function. * Refactored internal keyframe-looping tools to reduce the amount of code needed per tool to edit keyframes, removing a lot of the unnecessary bulk. Now, the ipo/icu_keys_bezier_loop functions recieve a few more arguments (1st arg is pointer to generic customdata, and another defines a validation callback which makes it easier to reuse some of the select callbacks). * Added 'totrect' adjustment for number of channels being shown in Action Editor, so that scrolling will be limited to where there is data (and also so that scroller displays more relevant context info). For this to work, filtering channels now returns the number of channels extracted. This may come into use for other tools if there's such a need. * I still need to port over some code for markers, which is required for some of the tools which use them. For now, those tools do nothing. * Grease-Pencil editing mode in Action Editor is currently non-functional (code is commented out due to missing dependencies). This is currently pending the re-implementation of Grease Pencil in 2.5
2008-12-26 10:55:07 +00:00
KeyframeEditFunc ANIM_editkeyframes_ok(short mode)
2.5 - Action Editor: All Keyframe Selection Tools Ported User Notes (for using tools whose behaviour has changed): * Mouse Selection Tools: 1) Click on keyframe to modify its selection. Holding the 'Shift' modifier when doing so, will result in keyframe selection being toggled instead of replacing existing selections. 2) Click on either side of the current frame indicator while holding the 'Alt' modifier. This will select only all the keyframes on the relevant side of the current frame indicator. 3) Click on a keyframe while holding the 'Ctrl' modifier. This will select all the keyframes that fall on that frame. * Borderselect Tools 1) BKEY selects all the keyframes within the specified range (as per normal) 2) ALT-BKEY will select either all the keyframes in the frame-range specified or the channel range specified, depending on which axis of the select region was larger. This method is prejudiced towards frame-range selection. Code Notes: * Finished porting over all of the remaining keyframe selection tools, and recoded the ported ones to make them easier to use (after running into some technical limitations) * Simplified the way to check if 'animation context' is valid by moving a necessary check into that function. * Refactored internal keyframe-looping tools to reduce the amount of code needed per tool to edit keyframes, removing a lot of the unnecessary bulk. Now, the ipo/icu_keys_bezier_loop functions recieve a few more arguments (1st arg is pointer to generic customdata, and another defines a validation callback which makes it easier to reuse some of the select callbacks). * Added 'totrect' adjustment for number of channels being shown in Action Editor, so that scrolling will be limited to where there is data (and also so that scroller displays more relevant context info). For this to work, filtering channels now returns the number of channels extracted. This may come into use for other tools if there's such a need. * I still need to port over some code for markers, which is required for some of the tools which use them. For now, those tools do nothing. * Grease-Pencil editing mode in Action Editor is currently non-functional (code is commented out due to missing dependencies). This is currently pending the re-implementation of Grease Pencil in 2.5
2008-12-26 10:55:07 +00:00
{
/* eEditKeyframes_Validate */
switch (mode) {
case BEZT_OK_FRAME: /* only if bezt falls on the right frame (float) */
return ok_bezier_frame;
case BEZT_OK_FRAMERANGE: /* only if bezt falls within the specified frame range (floats) */
return ok_bezier_framerange;
2012-05-08 15:30:00 +00:00
case BEZT_OK_SELECTED: /* only if bezt is selected (self) */
2.5 - Action Editor: All Keyframe Selection Tools Ported User Notes (for using tools whose behaviour has changed): * Mouse Selection Tools: 1) Click on keyframe to modify its selection. Holding the 'Shift' modifier when doing so, will result in keyframe selection being toggled instead of replacing existing selections. 2) Click on either side of the current frame indicator while holding the 'Alt' modifier. This will select only all the keyframes on the relevant side of the current frame indicator. 3) Click on a keyframe while holding the 'Ctrl' modifier. This will select all the keyframes that fall on that frame. * Borderselect Tools 1) BKEY selects all the keyframes within the specified range (as per normal) 2) ALT-BKEY will select either all the keyframes in the frame-range specified or the channel range specified, depending on which axis of the select region was larger. This method is prejudiced towards frame-range selection. Code Notes: * Finished porting over all of the remaining keyframe selection tools, and recoded the ported ones to make them easier to use (after running into some technical limitations) * Simplified the way to check if 'animation context' is valid by moving a necessary check into that function. * Refactored internal keyframe-looping tools to reduce the amount of code needed per tool to edit keyframes, removing a lot of the unnecessary bulk. Now, the ipo/icu_keys_bezier_loop functions recieve a few more arguments (1st arg is pointer to generic customdata, and another defines a validation callback which makes it easier to reuse some of the select callbacks). * Added 'totrect' adjustment for number of channels being shown in Action Editor, so that scrolling will be limited to where there is data (and also so that scroller displays more relevant context info). For this to work, filtering channels now returns the number of channels extracted. This may come into use for other tools if there's such a need. * I still need to port over some code for markers, which is required for some of the tools which use them. For now, those tools do nothing. * Grease-Pencil editing mode in Action Editor is currently non-functional (code is commented out due to missing dependencies). This is currently pending the re-implementation of Grease Pencil in 2.5
2008-12-26 10:55:07 +00:00
return ok_bezier_selected;
case BEZT_OK_VALUE: /* only if bezt value matches (float) */
return ok_bezier_value;
case BEZT_OK_VALUERANGE: /* only if bezier falls within the specified value range (floats) */
return ok_bezier_valuerange;
case BEZT_OK_REGION: /* only if bezier falls within the specified rect (data -> rectf) */
return ok_bezier_region;
2.5 - Action Editor: All Keyframe Selection Tools Ported User Notes (for using tools whose behaviour has changed): * Mouse Selection Tools: 1) Click on keyframe to modify its selection. Holding the 'Shift' modifier when doing so, will result in keyframe selection being toggled instead of replacing existing selections. 2) Click on either side of the current frame indicator while holding the 'Alt' modifier. This will select only all the keyframes on the relevant side of the current frame indicator. 3) Click on a keyframe while holding the 'Ctrl' modifier. This will select all the keyframes that fall on that frame. * Borderselect Tools 1) BKEY selects all the keyframes within the specified range (as per normal) 2) ALT-BKEY will select either all the keyframes in the frame-range specified or the channel range specified, depending on which axis of the select region was larger. This method is prejudiced towards frame-range selection. Code Notes: * Finished porting over all of the remaining keyframe selection tools, and recoded the ported ones to make them easier to use (after running into some technical limitations) * Simplified the way to check if 'animation context' is valid by moving a necessary check into that function. * Refactored internal keyframe-looping tools to reduce the amount of code needed per tool to edit keyframes, removing a lot of the unnecessary bulk. Now, the ipo/icu_keys_bezier_loop functions recieve a few more arguments (1st arg is pointer to generic customdata, and another defines a validation callback which makes it easier to reuse some of the select callbacks). * Added 'totrect' adjustment for number of channels being shown in Action Editor, so that scrolling will be limited to where there is data (and also so that scroller displays more relevant context info). For this to work, filtering channels now returns the number of channels extracted. This may come into use for other tools if there's such a need. * I still need to port over some code for markers, which is required for some of the tools which use them. For now, those tools do nothing. * Grease-Pencil editing mode in Action Editor is currently non-functional (code is commented out due to missing dependencies). This is currently pending the re-implementation of Grease Pencil in 2.5
2008-12-26 10:55:07 +00:00
default: /* nothing was ok */
return NULL;
}
}
/* ******************************************* */
/* Assorted Utility Functions */
/* helper callback for <animeditor>_cfrasnap_exec() -> used to help get the average time of all selected beztriples */
short bezt_calc_average(KeyframeEditData *ked, BezTriple *bezt)
{
/* only if selected */
if (bezt->f2 & SELECT) {
/* store average time in float 1 (only do rounding at last step) */
ked->f1 += bezt->vec[1][0];
/* store average value in float 2 (only do rounding at last step)
* - this isn't always needed, but some operators may also require this
*/
ked->f2 += bezt->vec[1][1];
/* increment number of items */
ked->i1++;
}
return 0;
}
/* helper callback for columnselect_<animeditor>_keys() -> populate list CfraElems with frame numbers from selected beztriples */
short bezt_to_cfraelem(KeyframeEditData *ked, BezTriple *bezt)
{
/* only if selected */
if (bezt->f2 & SELECT) {
2012-05-08 15:30:00 +00:00
CfraElem *ce = MEM_callocN(sizeof(CfraElem), "cfraElem");
BLI_addtail(&ked->list, ce);
2012-05-08 15:30:00 +00:00
ce->cfra = bezt->vec[1][0];
}
return 0;
}
/* used to remap times from one range to another
* requires: ked->data = KeyframeEditCD_Remap
*/
void bezt_remap_times(KeyframeEditData *ked, BezTriple *bezt)
{
2012-05-08 15:30:00 +00:00
KeyframeEditCD_Remap *rmap = (KeyframeEditCD_Remap *)ked->data;
const float scale = (rmap->newMax - rmap->newMin) / (rmap->oldMax - rmap->oldMin);
/* perform transform on all three handles unless indicated otherwise */
// TODO: need to include some checks for that
2012-05-08 15:30:00 +00:00
bezt->vec[0][0] = scale * (bezt->vec[0][0] - rmap->oldMin) + rmap->newMin;
bezt->vec[1][0] = scale * (bezt->vec[1][0] - rmap->oldMin) + rmap->newMin;
bezt->vec[2][0] = scale * (bezt->vec[2][0] - rmap->oldMin) + rmap->newMin;
}
/* ******************************************* */
/* Transform */
/* snaps the keyframe to the nearest frame */
static short snap_bezier_nearest(KeyframeEditData *UNUSED(ked), BezTriple *bezt)
{
if (bezt->f2 & SELECT)
2012-05-08 15:30:00 +00:00
bezt->vec[1][0] = (float)(floorf(bezt->vec[1][0] + 0.5f));
return 0;
}
/* snaps the keyframe to the neares second */
static short snap_bezier_nearestsec(KeyframeEditData *ked, BezTriple *bezt)
{
2012-05-08 15:30:00 +00:00
const Scene *scene = ked->scene;
2009-01-02 06:03:53 +00:00
const float secf = (float)FPS;
2.5 - Action Editor: All Keyframe Selection Tools Ported User Notes (for using tools whose behaviour has changed): * Mouse Selection Tools: 1) Click on keyframe to modify its selection. Holding the 'Shift' modifier when doing so, will result in keyframe selection being toggled instead of replacing existing selections. 2) Click on either side of the current frame indicator while holding the 'Alt' modifier. This will select only all the keyframes on the relevant side of the current frame indicator. 3) Click on a keyframe while holding the 'Ctrl' modifier. This will select all the keyframes that fall on that frame. * Borderselect Tools 1) BKEY selects all the keyframes within the specified range (as per normal) 2) ALT-BKEY will select either all the keyframes in the frame-range specified or the channel range specified, depending on which axis of the select region was larger. This method is prejudiced towards frame-range selection. Code Notes: * Finished porting over all of the remaining keyframe selection tools, and recoded the ported ones to make them easier to use (after running into some technical limitations) * Simplified the way to check if 'animation context' is valid by moving a necessary check into that function. * Refactored internal keyframe-looping tools to reduce the amount of code needed per tool to edit keyframes, removing a lot of the unnecessary bulk. Now, the ipo/icu_keys_bezier_loop functions recieve a few more arguments (1st arg is pointer to generic customdata, and another defines a validation callback which makes it easier to reuse some of the select callbacks). * Added 'totrect' adjustment for number of channels being shown in Action Editor, so that scrolling will be limited to where there is data (and also so that scroller displays more relevant context info). For this to work, filtering channels now returns the number of channels extracted. This may come into use for other tools if there's such a need. * I still need to port over some code for markers, which is required for some of the tools which use them. For now, those tools do nothing. * Grease-Pencil editing mode in Action Editor is currently non-functional (code is commented out due to missing dependencies). This is currently pending the re-implementation of Grease Pencil in 2.5
2008-12-26 10:55:07 +00:00
if (bezt->f2 & SELECT)
2012-05-08 15:30:00 +00:00
bezt->vec[1][0] = ((float)floor(bezt->vec[1][0] / secf + 0.5f) * secf);
return 0;
}
/* snaps the keyframe to the current frame */
static short snap_bezier_cframe(KeyframeEditData *ked, BezTriple *bezt)
{
2012-05-08 15:30:00 +00:00
const Scene *scene = ked->scene;
if (bezt->f2 & SELECT)
2012-05-08 15:30:00 +00:00
bezt->vec[1][0] = (float)CFRA;
return 0;
}
/* snaps the keyframe time to the nearest marker's frame */
static short snap_bezier_nearmarker(KeyframeEditData *ked, BezTriple *bezt)
{
if (bezt->f2 & SELECT)
2012-05-08 15:30:00 +00:00
bezt->vec[1][0] = (float)ED_markers_find_nearest_marker_time(&ked->list, bezt->vec[1][0]);
return 0;
}
/* make the handles have the same value as the key */
static short snap_bezier_horizontal(KeyframeEditData *UNUSED(ked), BezTriple *bezt)
{
if (bezt->f2 & SELECT) {
2012-05-08 15:30:00 +00:00
bezt->vec[0][1] = bezt->vec[2][1] = bezt->vec[1][1];
2012-05-08 15:30:00 +00:00
if (ELEM3(bezt->h1, HD_AUTO, HD_AUTO_ANIM, HD_VECT)) bezt->h1 = HD_ALIGN;
if (ELEM3(bezt->h2, HD_AUTO, HD_AUTO_ANIM, HD_VECT)) bezt->h2 = HD_ALIGN;
}
return 0;
}
/* value to snap to is stored in the custom data -> first float value slot */
static short snap_bezier_value(KeyframeEditData *ked, BezTriple *bezt)
{
if (bezt->f2 & SELECT)
2012-05-08 15:30:00 +00:00
bezt->vec[1][1] = ked->f1;
return 0;
}
KeyframeEditFunc ANIM_editkeyframes_snap(short type)
{
2.5 - Action Editor: All Keyframe Selection Tools Ported User Notes (for using tools whose behaviour has changed): * Mouse Selection Tools: 1) Click on keyframe to modify its selection. Holding the 'Shift' modifier when doing so, will result in keyframe selection being toggled instead of replacing existing selections. 2) Click on either side of the current frame indicator while holding the 'Alt' modifier. This will select only all the keyframes on the relevant side of the current frame indicator. 3) Click on a keyframe while holding the 'Ctrl' modifier. This will select all the keyframes that fall on that frame. * Borderselect Tools 1) BKEY selects all the keyframes within the specified range (as per normal) 2) ALT-BKEY will select either all the keyframes in the frame-range specified or the channel range specified, depending on which axis of the select region was larger. This method is prejudiced towards frame-range selection. Code Notes: * Finished porting over all of the remaining keyframe selection tools, and recoded the ported ones to make them easier to use (after running into some technical limitations) * Simplified the way to check if 'animation context' is valid by moving a necessary check into that function. * Refactored internal keyframe-looping tools to reduce the amount of code needed per tool to edit keyframes, removing a lot of the unnecessary bulk. Now, the ipo/icu_keys_bezier_loop functions recieve a few more arguments (1st arg is pointer to generic customdata, and another defines a validation callback which makes it easier to reuse some of the select callbacks). * Added 'totrect' adjustment for number of channels being shown in Action Editor, so that scrolling will be limited to where there is data (and also so that scroller displays more relevant context info). For this to work, filtering channels now returns the number of channels extracted. This may come into use for other tools if there's such a need. * I still need to port over some code for markers, which is required for some of the tools which use them. For now, those tools do nothing. * Grease-Pencil editing mode in Action Editor is currently non-functional (code is commented out due to missing dependencies). This is currently pending the re-implementation of Grease Pencil in 2.5
2008-12-26 10:55:07 +00:00
/* eEditKeyframes_Snap */
switch (type) {
case SNAP_KEYS_NEARFRAME: /* snap to nearest frame */
return snap_bezier_nearest;
case SNAP_KEYS_CURFRAME: /* snap to current frame */
return snap_bezier_cframe;
case SNAP_KEYS_NEARMARKER: /* snap to nearest marker */
return snap_bezier_nearmarker;
case SNAP_KEYS_NEARSEC: /* snap to nearest second */
return snap_bezier_nearestsec;
case SNAP_KEYS_HORIZONTAL: /* snap handles to same value */
return snap_bezier_horizontal;
case SNAP_KEYS_VALUE: /* snap to given value */
return snap_bezier_value;
default: /* just in case */
return snap_bezier_nearest;
}
}
/* --------- */
static short mirror_bezier_cframe(KeyframeEditData *ked, BezTriple *bezt)
{
2012-05-08 15:30:00 +00:00
const Scene *scene = ked->scene;
float diff;
if (bezt->f2 & SELECT) {
2012-05-08 15:30:00 +00:00
diff = ((float)CFRA - bezt->vec[1][0]);
bezt->vec[1][0] = ((float)CFRA + diff);
}
return 0;
}
static short mirror_bezier_yaxis(KeyframeEditData *UNUSED(ked), BezTriple *bezt)
{
float diff;
if (bezt->f2 & SELECT) {
2012-05-08 15:30:00 +00:00
diff = (0.0f - bezt->vec[1][0]);
bezt->vec[1][0] = (0.0f + diff);
}
return 0;
}
static short mirror_bezier_xaxis(KeyframeEditData *UNUSED(ked), BezTriple *bezt)
{
float diff;
if (bezt->f2 & SELECT) {
2012-05-08 15:30:00 +00:00
diff = (0.0f - bezt->vec[1][1]);
bezt->vec[1][1] = (0.0f + diff);
}
return 0;
}
static short mirror_bezier_marker(KeyframeEditData *ked, BezTriple *bezt)
{
/* mirroring time stored in f1 */
if (bezt->f2 & SELECT) {
2012-05-08 15:30:00 +00:00
const float diff = (ked->f1 - bezt->vec[1][0]);
bezt->vec[1][0] = (ked->f1 + diff);
}
return 0;
}
static short mirror_bezier_value(KeyframeEditData *ked, BezTriple *bezt)
{
float diff;
/* value to mirror over is stored in the custom data -> first float value slot */
if (bezt->f2 & SELECT) {
2012-05-08 15:30:00 +00:00
diff = (ked->f1 - bezt->vec[1][1]);
bezt->vec[1][1] = (ked->f1 + diff);
}
return 0;
}
/* Note: for markers and 'value', the values to use must be supplied as the first float value */
// calchandles_fcurve
KeyframeEditFunc ANIM_editkeyframes_mirror(short type)
{
switch (type) {
case MIRROR_KEYS_CURFRAME: /* mirror over current frame */
return mirror_bezier_cframe;
case MIRROR_KEYS_YAXIS: /* mirror over frame 0 */
return mirror_bezier_yaxis;
case MIRROR_KEYS_XAXIS: /* mirror over value 0 */
return mirror_bezier_xaxis;
case MIRROR_KEYS_MARKER: /* mirror over marker */
return mirror_bezier_marker;
case MIRROR_KEYS_VALUE: /* mirror over given value */
return mirror_bezier_value;
default: /* just in case */
return mirror_bezier_yaxis;
}
}
/* ******************************************* */
/* Settings */
/* standard validation step for a few of these (implemented as macro for inlining without fn-call overhead):
* "if the handles are not of the same type, set them to type free"
*/
#define ENSURE_HANDLES_MATCH(bezt) \
if (bezt->h1 != bezt->h2) { \
if (ELEM3(bezt->h1, HD_ALIGN, HD_AUTO, HD_AUTO_ANIM)) \
2012-05-08 15:30:00 +00:00
bezt->h1 = HD_FREE; \
if (ELEM3(bezt->h2, HD_ALIGN, HD_AUTO, HD_AUTO_ANIM)) \
2012-05-08 15:30:00 +00:00
bezt->h2 = HD_FREE; \
2012-05-27 20:13:59 +00:00
} (void)0
/* Sets the selected bezier handles to type 'auto' */
static short set_bezier_auto(KeyframeEditData *UNUSED(ked), BezTriple *bezt)
{
if ((bezt->f1 & SELECT) || (bezt->f3 & SELECT)) {
2012-05-08 15:30:00 +00:00
if (bezt->f1 & SELECT) bezt->h1 = HD_AUTO;
if (bezt->f3 & SELECT) bezt->h2 = HD_AUTO;
ENSURE_HANDLES_MATCH(bezt);
}
return 0;
}
/* Sets the selected bezier handles to type 'auto-clamped'
* NOTE: this is like auto above, but they're handled a bit different
*/
static short set_bezier_auto_clamped(KeyframeEditData *UNUSED(ked), BezTriple *bezt)
{
if ((bezt->f1 & SELECT) || (bezt->f3 & SELECT)) {
2012-05-08 15:30:00 +00:00
if (bezt->f1 & SELECT) bezt->h1 = HD_AUTO_ANIM;
if (bezt->f3 & SELECT) bezt->h2 = HD_AUTO_ANIM;
ENSURE_HANDLES_MATCH(bezt);
}
return 0;
}
/* Sets the selected bezier handles to type 'vector' */
static short set_bezier_vector(KeyframeEditData *UNUSED(ked), BezTriple *bezt)
{
2012-05-08 15:30:00 +00:00
if (bezt->f1 & SELECT) bezt->h1 = HD_VECT;
if (bezt->f3 & SELECT) bezt->h2 = HD_VECT;
return 0;
}
/* Queries if the handle should be set to 'free' or 'align' */
// NOTE: this was used for the 'toggle free/align' option
// currently this isn't used, but may be restored later
static short bezier_isfree(KeyframeEditData *UNUSED(ked), BezTriple *bezt)
{
if ((bezt->f1 & SELECT) && (bezt->h1)) return 1;
if ((bezt->f3 & SELECT) && (bezt->h2)) return 1;
return 0;
}
/* Sets selected bezier handles to type 'align' */
static short set_bezier_align(KeyframeEditData *UNUSED(ked), BezTriple *bezt)
{
2012-05-08 15:30:00 +00:00
if (bezt->f1 & SELECT) bezt->h1 = HD_ALIGN;
if (bezt->f3 & SELECT) bezt->h2 = HD_ALIGN;
return 0;
}
/* Sets selected bezier handles to type 'free' */
static short set_bezier_free(KeyframeEditData *UNUSED(ked), BezTriple *bezt)
{
2012-05-08 15:30:00 +00:00
if (bezt->f1 & SELECT) bezt->h1 = HD_FREE;
if (bezt->f3 & SELECT) bezt->h2 = HD_FREE;
return 0;
}
/* Set all selected Bezier Handles to a single type */
// calchandles_fcurve
KeyframeEditFunc ANIM_editkeyframes_handles(short code)
{
switch (code) {
case HD_AUTO: /* auto */
return set_bezier_auto;
case HD_AUTO_ANIM: /* auto clamped */
return set_bezier_auto_clamped;
case HD_VECT: /* vector */
return set_bezier_vector;
case HD_FREE: /* free */
return set_bezier_free;
case HD_ALIGN: /* align */
return set_bezier_align;
default: /* check for toggle free or align? */
return bezier_isfree;
}
}
/* ------- */
static short set_bezt_constant(KeyframeEditData *UNUSED(ked), BezTriple *bezt)
{
if (bezt->f2 & SELECT)
2012-05-08 15:30:00 +00:00
bezt->ipo = BEZT_IPO_CONST;
return 0;
}
static short set_bezt_linear(KeyframeEditData *UNUSED(ked), BezTriple *bezt)
{
if (bezt->f2 & SELECT)
2012-05-08 15:30:00 +00:00
bezt->ipo = BEZT_IPO_LIN;
return 0;
}
static short set_bezt_bezier(KeyframeEditData *UNUSED(ked), BezTriple *bezt)
{
if (bezt->f2 & SELECT)
2012-05-08 15:30:00 +00:00
bezt->ipo = BEZT_IPO_BEZ;
return 0;
}
/* Set the interpolation type of the selected BezTriples in each F-Curve to the specified one */
// ANIM_editkeyframes_ipocurve_ipotype() !
KeyframeEditFunc ANIM_editkeyframes_ipo(short code)
{
switch (code) {
case BEZT_IPO_CONST: /* constant */
return set_bezt_constant;
case BEZT_IPO_LIN: /* linear */
return set_bezt_linear;
default: /* bezier */
return set_bezt_bezier;
}
}
/* ------- */
static short set_keytype_keyframe(KeyframeEditData *UNUSED(ked), BezTriple *bezt)
{
if (bezt->f2 & SELECT)
2012-05-08 15:30:00 +00:00
BEZKEYTYPE(bezt) = BEZT_KEYTYPE_KEYFRAME;
return 0;
}
static short set_keytype_breakdown(KeyframeEditData *UNUSED(ked), BezTriple *bezt)
{
if (bezt->f2 & SELECT)
2012-05-08 15:30:00 +00:00
BEZKEYTYPE(bezt) = BEZT_KEYTYPE_BREAKDOWN;
return 0;
}
static short set_keytype_extreme(KeyframeEditData *UNUSED(ked), BezTriple *bezt)
{
if (bezt->f2 & SELECT)
2012-05-08 15:30:00 +00:00
BEZKEYTYPE(bezt) = BEZT_KEYTYPE_EXTREME;
return 0;
}
static short set_keytype_jitter(KeyframeEditData *UNUSED(ked), BezTriple *bezt)
{
if (bezt->f2 & SELECT)
2012-05-08 15:30:00 +00:00
BEZKEYTYPE(bezt) = BEZT_KEYTYPE_JITTER;
return 0;
}
/* Set the interpolation type of the selected BezTriples in each F-Curve to the specified one */
KeyframeEditFunc ANIM_editkeyframes_keytype(short code)
{
switch (code) {
case BEZT_KEYTYPE_BREAKDOWN: /* breakdown */
return set_keytype_breakdown;
case BEZT_KEYTYPE_EXTREME: /* extreme keyframe */
return set_keytype_extreme;
case BEZT_KEYTYPE_JITTER: /* jitter keyframe */
return set_keytype_jitter;
case BEZT_KEYTYPE_KEYFRAME: /* proper keyframe */
default:
return set_keytype_keyframe;
}
}
/* ******************************************* */
/* Selection */
static short select_bezier_add(KeyframeEditData *ked, BezTriple *bezt)
{
/* if we've got info on what to select, use it, otherwise select all */
if ((ked) && (ked->iterflags & KEYFRAME_ITER_INCL_HANDLES)) {
if (ked->curflags & KEYFRAME_OK_KEY)
bezt->f2 |= SELECT;
if (ked->curflags & KEYFRAME_OK_H1)
bezt->f1 |= SELECT;
if (ked->curflags & KEYFRAME_OK_H2)
bezt->f3 |= SELECT;
}
else {
BEZ_SEL(bezt);
}
return 0;
}
static short select_bezier_subtract(KeyframeEditData *ked, BezTriple *bezt)
{
/* if we've got info on what to deselect, use it, otherwise deselect all */
if ((ked) && (ked->iterflags & KEYFRAME_ITER_INCL_HANDLES)) {
if (ked->curflags & KEYFRAME_OK_KEY)
bezt->f2 &= ~SELECT;
if (ked->curflags & KEYFRAME_OK_H1)
bezt->f1 &= ~SELECT;
if (ked->curflags & KEYFRAME_OK_H2)
bezt->f3 &= ~SELECT;
}
else {
BEZ_DESEL(bezt);
}
return 0;
}
static short select_bezier_invert(KeyframeEditData *UNUSED(ked), BezTriple *bezt)
{
/* Invert the selection for the whole bezier triple */
bezt->f2 ^= SELECT;
if (bezt->f2 & SELECT) {
bezt->f1 |= SELECT;
bezt->f3 |= SELECT;
}
else {
bezt->f1 &= ~SELECT;
bezt->f3 &= ~SELECT;
}
return 0;
}
KeyframeEditFunc ANIM_editkeyframes_select(short selectmode)
{
switch (selectmode) {
case SELECT_ADD: /* add */
return select_bezier_add;
case SELECT_SUBTRACT: /* subtract */
return select_bezier_subtract;
case SELECT_INVERT: /* invert */
return select_bezier_invert;
default: /* replace (need to clear all, then add) */
return select_bezier_add;
}
}
/* ******************************************* */
/* Selection Maps */
/* Selection maps are simply fancy names for char arrays that store on/off
* info for whether the selection status. The main purpose for these is to
* allow extra info to be tagged to the keyframes without influencing their
* values or having to be removed later.
*/
/* ----------- */
static short selmap_build_bezier_more(KeyframeEditData *ked, BezTriple *bezt)
{
2012-05-08 15:30:00 +00:00
FCurve *fcu = ked->fcu;
char *map = ked->data;
int i = ked->curIndex;
/* if current is selected, just make sure it stays this way */
if (BEZSELECTED(bezt)) {
2012-05-08 15:30:00 +00:00
map[i] = 1;
return 0;
}
/* if previous is selected, that means that selection should extend across */
if (i > 0) {
2012-05-08 15:30:00 +00:00
BezTriple *prev = bezt - 1;
if (BEZSELECTED(prev)) {
2012-05-08 15:30:00 +00:00
map[i] = 1;
return 0;
}
}
/* if next is selected, that means that selection should extend across */
2012-05-08 15:30:00 +00:00
if (i < (fcu->totvert - 1)) {
BezTriple *next = bezt + 1;
if (BEZSELECTED(next)) {
2012-05-08 15:30:00 +00:00
map[i] = 1;
return 0;
}
}
return 0;
}
static short selmap_build_bezier_less(KeyframeEditData *ked, BezTriple *bezt)
{
2012-05-08 15:30:00 +00:00
FCurve *fcu = ked->fcu;
char *map = ked->data;
int i = ked->curIndex;
/* if current is selected, check the left/right keyframes
* since it might need to be deselected (but otherwise no)
*/
if (BEZSELECTED(bezt)) {
/* if previous is not selected, we're on the tip of an iceberg */
if (i > 0) {
2012-05-08 15:30:00 +00:00
BezTriple *prev = bezt - 1;
if (BEZSELECTED(prev) == 0)
return 0;
}
else if (i == 0) {
/* current keyframe is selected at an endpoint, so should get deselected */
return 0;
}
/* if next is not selected, we're on the tip of an iceberg */
2012-05-08 15:30:00 +00:00
if (i < (fcu->totvert - 1)) {
BezTriple *next = bezt + 1;
if (BEZSELECTED(next) == 0)
return 0;
}
2012-05-08 15:30:00 +00:00
else if (i == (fcu->totvert - 1)) {
/* current keyframe is selected at an endpoint, so should get deselected */
return 0;
}
/* if we're still here, that means that keyframe should remain untouched */
2012-05-08 15:30:00 +00:00
map[i] = 1;
}
return 0;
}
/* Get callback for building selection map */
KeyframeEditFunc ANIM_editkeyframes_buildselmap(short mode)
{
switch (mode) {
case SELMAP_LESS: /* less */
return selmap_build_bezier_less;
case SELMAP_MORE: /* more */
default:
return selmap_build_bezier_more;
}
}
/* ----------- */
/* flush selection map values to the given beztriple */
short bezt_selmap_flush(KeyframeEditData *ked, BezTriple *bezt)
{
2012-05-08 15:30:00 +00:00
char *map = ked->data;
short on = map[ked->curIndex];
/* select or deselect based on whether the map allows it or not */
if (on) {
BEZ_SEL(bezt);
}
else {
BEZ_DESEL(bezt);
}
return 0;
}