Blender V2.61 - r43446

ED_keyframing.h

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2008, Blender Foundation
00019  * This is a new part of Blender (with some old code)
00020  *
00021  * Contributor(s): Joshua Leung
00022  *
00023  * ***** END GPL LICENSE BLOCK *****
00024  */
00025 
00030 #ifndef ED_KEYFRAMING_H
00031 #define ED_KEYFRAMING_H
00032 
00033 #ifdef __cplusplus
00034 extern "C" {
00035 #endif
00036 
00037 struct Main;
00038 struct ListBase;
00039 struct ID;
00040 struct Scene;
00041 
00042 struct KeyingSet;
00043 
00044 struct bAction;
00045 struct FCurve;
00046 struct BezTriple;
00047 
00048 struct bPoseChannel;
00049 struct bConstraint;
00050 
00051 struct bContext;
00052 struct wmOperatorType;
00053 struct ReportList;
00054 
00055 struct PointerRNA;
00056 struct PropertyRNA;
00057 struct EnumPropertyItem;
00058 
00059 #include "RNA_types.h"
00060 
00061 /* ************ Keyframing Management **************** */
00062 
00063 /* Get the active settings for keyframing settings from context (specifically the given scene) 
00064  *  - incl_mode: include settings from keyframing mode in the result (i.e. replace only)
00065  */
00066 short ANIM_get_keyframing_flags(struct Scene *scene, short incl_mode);
00067 
00068 /* -------- */
00069 
00070 /* Get (or add relevant data to be able to do so) the Active Action for the given 
00071  * Animation Data block, given an ID block where the Animation Data should reside.
00072  */
00073 struct bAction *verify_adt_action(struct ID *id, short add);
00074 
00075 /* Get (or add relevant data to be able to do so) F-Curve from the given Action. 
00076  * This assumes that all the destinations are valid.
00077  */
00078 struct FCurve *verify_fcurve(struct bAction *act, const char group[], const char rna_path[], const int array_index, short add);
00079 
00080 /* -------- */
00081 
00082 /* Lesser Keyframing API call:
00083  *  Use this when validation of necessary animation data isn't necessary as it already
00084  *  exists, and there is a beztriple that can be directly copied into the array.
00085  */
00086 int insert_bezt_fcurve(struct FCurve *fcu, struct BezTriple *bezt, short flag);
00087 
00088 /* Main Keyframing API call: 
00089  *  Use this when validation of necessary animation data isn't necessary as it
00090  *  already exists. It will insert a keyframe using the current value being keyframed.
00091  *  Returns the index at which a keyframe was added (or -1 if failed)
00092  */
00093 int insert_vert_fcurve(struct FCurve *fcu, float x, float y, short flag);
00094 
00095 /* -------- */
00096 
00097 /* Secondary Keyframing API calls: 
00098  *  Use this to insert a keyframe using the current value being keyframed, in the 
00099  *  nominated F-Curve (no creation of animation data performed). Returns success.
00100  */
00101 short insert_keyframe_direct(struct ReportList *reports, struct PointerRNA ptr, struct PropertyRNA *prop, struct FCurve *fcu, float cfra, short flag);
00102 
00103 /* -------- */
00104 
00105 /* Main Keyframing API calls: 
00106  *  Use this to create any necessary animation data, and then insert a keyframe
00107  *  using the current value being keyframed, in the relevant place. Returns success.
00108  */
00109 short insert_keyframe(struct ReportList *reports, struct ID *id, struct bAction *act, const char group[], const char rna_path[], int array_index, float cfra, short flag);
00110 
00111 /* Main Keyframing API call: 
00112  *  Use this to delete keyframe on current frame for relevant channel. Will perform checks just in case.
00113  */
00114 short delete_keyframe(struct ReportList *reports, struct ID *id, struct bAction *act, const char group[], const char rna_path[], int array_index, float cfra, short flag);
00115 
00116 /* ************ Keying Sets ********************** */
00117 
00118 /* forward decl. for this struct which is declared a bit later... */
00119 struct KeyingSetInfo;
00120 struct ExtensionRNA;
00121 
00122 /* Polling Callback for KeyingSets */
00123 typedef int (*cbKeyingSet_Poll)(struct KeyingSetInfo *ksi, struct bContext *C);
00124 /* Context Iterator Callback for KeyingSets */
00125 typedef void (*cbKeyingSet_Iterator)(struct KeyingSetInfo *ksi, struct bContext *C, struct KeyingSet *ks);
00126 /* Property Specifier Callback for KeyingSets (called from iterators) */
00127 typedef void (*cbKeyingSet_Generate)(struct KeyingSetInfo *ksi, struct bContext *C, struct KeyingSet *ks, struct PointerRNA *ptr); 
00128 
00129 
00130 /* Callback info for 'Procedural' KeyingSets to use */
00131 typedef struct KeyingSetInfo {
00132     struct KeyingSetInfo *next, *prev;
00133     
00134     /* info */
00135         /* identifier so that user can hook this up to a KeyingSet */
00136     char name[64];
00137         /* identifier used for class name, which KeyingSet instances reference as "Typeinfo Name" */
00138     char idname[64];
00139         /* keying settings */
00140     short keyingflag;
00141     
00142     /* polling callbacks */
00143         /* callback for polling the context for whether the right data is available */
00144     cbKeyingSet_Poll poll;
00145     
00146     /* generate callbacks */
00147         /* iterator to use to go through collections of data in context
00148          *  - this callback is separate from the 'adding' stage, allowing 
00149          *    BuiltIn KeyingSets to be manually specified to use 
00150          */
00151     cbKeyingSet_Iterator iter;
00152         /* generator to use to add properties based on the data found by iterator */
00153     cbKeyingSet_Generate generate;
00154     
00155     /* RNA integration */
00156     struct ExtensionRNA ext;
00157 } KeyingSetInfo;
00158 
00159 /* -------- */
00160 
00161 /* Add another data source for Relative Keying Sets to be evaluated with */
00162 void ANIM_relative_keyingset_add_source(ListBase *dsources, struct ID *id, struct StructRNA *srna, void *data);
00163 
00164 
00165 /* mode for modify_keyframes */
00166 typedef enum eModifyKey_Modes {
00167     MODIFYKEY_MODE_INSERT = 0,
00168     MODIFYKEY_MODE_DELETE,
00169 } eModifyKey_Modes;
00170 
00171 /* return codes for errors (with Relative KeyingSets) */
00172 typedef enum eModifyKey_Returns {
00173         /* context info was invalid for using the Keying Set */
00174     MODIFYKEY_INVALID_CONTEXT = -1,
00175         /* there isn't any typeinfo for generating paths from context */
00176     MODIFYKEY_MISSING_TYPEINFO = -2,
00177 } eModifyKey_Returns;
00178 
00179 /* poll the current KeyingSet, updating it's set of paths (if "builtin"/"relative") for context changes */
00180 short ANIM_validate_keyingset(struct bContext *C, ListBase *dsources, struct KeyingSet *ks);
00181 
00182 /* use the specified KeyingSet to add/remove various Keyframes on the specified frame */
00183 int ANIM_apply_keyingset(struct bContext *C, ListBase *dsources, struct bAction *act, struct KeyingSet *ks, short mode, float cfra);
00184 
00185 /* -------- */
00186 
00187 /* Get the first builtin KeyingSet with the given name, which occurs after the given one (or start of list if none given) */
00188 struct KeyingSet *ANIM_builtin_keyingset_get_named(struct KeyingSet *prevKS, const char name[]);
00189 
00190 /* Find KeyingSet type info given a name */
00191 KeyingSetInfo *ANIM_keyingset_info_find_named(const char name[]);
00192 
00193 /* for RNA type registrations... */
00194 void ANIM_keyingset_info_register(KeyingSetInfo *ksi);
00195 void ANIM_keyingset_info_unregister(struct Main *bmain, KeyingSetInfo *ksi);
00196 
00197 /* cleanup on exit */
00198 void ANIM_keyingset_infos_exit(void);
00199 
00200 /* -------- */
00201 
00202 /* Get the active KeyingSet for the given scene */
00203 struct KeyingSet *ANIM_scene_get_active_keyingset(struct Scene *scene);
00204 
00205 /* Get the index of the Keying Set provided, for the given Scene */
00206 int ANIM_scene_get_keyingset_index(struct Scene *scene, struct KeyingSet *ks);
00207 
00208 /* Get Keying Set to use for Auto-Keyframing some transforms */
00209 struct KeyingSet *ANIM_get_keyingset_for_autokeying(struct Scene *scene, const char *tranformKSName);
00210 
00211 /* Create (and show) a menu containing all the Keying Sets which can be used in the current context */
00212 void ANIM_keying_sets_menu_setup(struct bContext *C, const char title[], const char op_name[]);
00213 
00214 /* Dynamically populate an enum of Keying Sets */
00215 struct EnumPropertyItem *ANIM_keying_sets_enum_itemf(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, int *free);
00216 
00217 /* Check if KeyingSet can be used in the current context */
00218 short ANIM_keyingset_context_ok_poll(struct bContext *C, struct KeyingSet *ks);
00219 
00220 /* ************ Drivers ********************** */
00221 
00222 /* Flags for use by driver creation calls */
00223 typedef enum eCreateDriverFlags {
00224     CREATEDRIVER_WITH_DEFAULT_DVAR  = (1<<0),   /* create drivers with a default variable for nicer UI */
00225 } eCreateDriverFlags;
00226 
00227 /* -------- */
00228 
00229 /* Low-level call to add a new driver F-Curve. This shouldn't be used directly for most tools,
00230  * although there are special cases where this approach is preferable.
00231  */
00232 struct FCurve *verify_driver_fcurve(struct ID *id, const char rna_path[], const int array_index, short add);
00233 
00234 /* -------- */
00235 
00236 /* Returns whether there is a driver in the copy/paste buffer to paste */
00237 short ANIM_driver_can_paste(void);
00238 
00239 /* Main Driver Management API calls:
00240  *  Add a new driver for the specified property on the given ID block
00241  */
00242 short ANIM_add_driver(struct ReportList *reports, struct ID *id, const char rna_path[], int array_index, short flag, int type);
00243 
00244 /* Main Driver Management API calls:
00245  *  Remove the driver for the specified property on the given ID block (if available)
00246  */
00247 short ANIM_remove_driver(struct ReportList *reports, struct ID *id, const char rna_path[], int array_index, short flag);
00248 
00249 /* Main Driver Management API calls:
00250  *  Make a copy of the driver for the specified property on the given ID block
00251  */
00252 short ANIM_copy_driver(struct ReportList *reports, struct ID *id, const char rna_path[], int array_index, short flag);
00253 
00254 /* Main Driver Management API calls:
00255  *  Add a new driver for the specified property on the given ID block or replace an existing one
00256  *  with the driver + driver-curve data from the buffer 
00257  */
00258 short ANIM_paste_driver(struct ReportList *reports, struct ID *id, const char rna_path[], int array_index, short flag);
00259 
00260 /* ************ Auto-Keyframing ********************** */
00261 /* Notes:
00262  * - All the defines for this (User-Pref settings and Per-Scene settings)
00263  *  are defined in DNA_userdef_types.h
00264  * - Scene settings take presidence over those for userprefs, with old files
00265  *  inheriting userpref settings for the scene settings
00266  * - "On/Off + Mode" are stored per Scene, but "settings" are currently stored
00267  *  as userprefs
00268  */
00269 
00270 /* Auto-Keying macros for use by various tools */
00271     /* check if auto-keyframing is enabled (per scene takes presidence) */
00272 #define IS_AUTOKEY_ON(scene)    ((scene) ? (scene->toolsettings->autokey_mode & AUTOKEY_ON) : (U.autokey_mode & AUTOKEY_ON))
00273     /* check the mode for auto-keyframing (per scene takes presidence)  */
00274 #define IS_AUTOKEY_MODE(scene, mode)    ((scene) ? (scene->toolsettings->autokey_mode == AUTOKEY_MODE_##mode) : (U.autokey_mode == AUTOKEY_MODE_##mode))
00275     /* check if a flag is set for auto-keyframing (per scene takes presidence) */
00276 #define IS_AUTOKEY_FLAG(scene, flag) \
00277     ((scene)? \
00278         ((scene->toolsettings->autokey_flag & AUTOKEY_FLAG_##flag) || (U.autokey_flag & AUTOKEY_FLAG_##flag)) \
00279      : \
00280         (U.autokey_flag & AUTOKEY_FLAG_##flag))
00281 
00282 /* auto-keyframing feature - checks for whether anything should be done for the current frame */
00283 int autokeyframe_cfra_can_key(struct Scene *scene, struct ID *id);
00284 
00285 /* ************ Keyframe Checking ******************** */
00286 
00287 /* Lesser Keyframe Checking API call:
00288  *  - Used for the buttons to check for keyframes...
00289  */
00290 short fcurve_frame_has_keyframe(struct FCurve *fcu, float frame, short filter);
00291 
00292 /* Main Keyframe Checking API call:
00293  * Checks whether a keyframe exists for the given ID-block one the given frame.
00294  *  - It is recommended to call this method over the other keyframe-checkers directly,
00295  *    in case some detail of the implementation changes...
00296  *  - frame: the value of this is quite often result of BKE_curframe()
00297  */
00298 short id_frame_has_keyframe(struct ID *id, float frame, short filter);
00299 
00300 /* filter flags for id_cfra_has_keyframe 
00301  *
00302  * WARNING: do not alter order of these, as also stored in files
00303  *  (for v3d->keyflags)
00304  */
00305 typedef enum eAnimFilterFlags {
00306         /* general */
00307     ANIMFILTER_KEYS_LOCAL   = (1<<0),       /* only include locally available anim data */
00308     ANIMFILTER_KEYS_MUTED   = (1<<1),       /* include muted elements */
00309     ANIMFILTER_KEYS_ACTIVE  = (1<<2),       /* only include active-subelements */
00310     
00311         /* object specific */
00312     ANIMFILTER_KEYS_NOMAT       = (1<<9),       /* don't include material keyframes */
00313     ANIMFILTER_KEYS_NOSKEY      = (1<<10),      /* don't include shape keys (for geometry) */
00314 } eAnimFilterFlags;
00315 
00316 /* utility funcs for auto keyframe */
00317 int ED_autokeyframe_object(struct bContext *C, struct Scene *scene, struct Object *ob, struct KeyingSet *ks);
00318 int ED_autokeyframe_pchan(struct bContext *C, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, struct KeyingSet *ks);
00319 
00320 /* Names for builtin keying sets so we don't confuse these with labels/text,
00321  * defined in python script: keyingsets_builtins.py */
00322 #define ANIM_KS_LOCATION_ID         "Location"
00323 #define ANIM_KS_ROTATION_ID         "Rotation"
00324 #define ANIM_KS_SCALING_ID          "Scaling"
00325 #define ANIM_KS_LOC_ROT_SCALE_ID    "LocRotScale"
00326 #define ANIM_KS_AVAILABLE_ID        "Available"
00327 #define ANIM_KS_WHOLE_CHARACTER_ID  "Whole Character"
00328 
00329 #ifdef __cplusplus
00330 }
00331 #endif
00332 
00333 #endif /*  ED_KEYFRAMING_H */