Blender V2.61 - r43446

BKE_fcurve.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) 2009 Blender Foundation, Joshua Leung
00019  * All rights reserved.
00020  *
00021  * Contributor(s): Joshua Leung (full recode)
00022  *
00023  * ***** END GPL LICENSE BLOCK *****
00024  */
00025 
00026 #ifndef BKE_FCURVE_H
00027 #define BKE_FCURVE_H
00028 
00035 #ifdef __cplusplus
00036 extern "C" {
00037 #endif
00038 
00039 struct FCurve;
00040 struct FModifier;
00041 struct ChannelDriver;
00042 struct DriverVar;
00043 struct DriverTarget;
00044 
00045 struct bAction;
00046 struct BezTriple;
00047 struct StructRNA;
00048 struct PointerRNA;
00049 struct PropertyRNA;
00050 
00051 #include "DNA_curve_types.h"
00052 
00053 /* ************** Keyframe Tools ***************** */
00054 
00055 typedef struct CfraElem {
00056     struct CfraElem *next, *prev;
00057     float cfra;
00058     int sel;
00059 } CfraElem;
00060 
00061 void bezt_add_to_cfra_elem(ListBase *lb, struct BezTriple *bezt);
00062 
00063 /* ************** F-Curve Drivers ***************** */
00064 
00065 /* With these iterators for convenience, the variables "tarIndex" and "dtar" can be 
00066  * accessed directly from the code using them, but it is not recommended that their
00067  * values be changed to point at other slots...
00068  */
00069 
00070 /* convenience looper over ALL driver targets for a given variable (even the unused ones) */
00071 #define DRIVER_TARGETS_LOOPER(dvar) \
00072     { \
00073         DriverTarget *dtar= &dvar->targets[0]; \
00074         int tarIndex= 0; \
00075         for (; tarIndex < MAX_DRIVER_TARGETS; tarIndex++, dtar++)
00076          
00077 /* convenience looper over USED driver targets only */
00078 #define DRIVER_TARGETS_USED_LOOPER(dvar) \
00079     { \
00080         DriverTarget *dtar= &dvar->targets[0]; \
00081         int tarIndex= 0; \
00082         for (; tarIndex < dvar->num_targets; tarIndex++, dtar++)
00083         
00084 /* tidy up for driver targets loopers */
00085 #define DRIVER_TARGETS_LOOPER_END \
00086     }
00087 
00088 /* ---------------------- */
00089 
00090 void fcurve_free_driver(struct FCurve *fcu);
00091 struct ChannelDriver *fcurve_copy_driver(struct ChannelDriver *driver);
00092 
00093 void driver_free_variable(struct ChannelDriver *driver, struct DriverVar *dvar);
00094 void driver_change_variable_type(struct DriverVar *dvar, int type);
00095 struct DriverVar *driver_add_new_variable(struct ChannelDriver *driver);
00096 
00097 float driver_get_variable_value (struct ChannelDriver *driver, struct DriverVar *dvar);
00098 
00099 /* ************** F-Curve Modifiers *************** */
00100 
00101 /* F-Curve Modifier Type-Info (fmi):
00102  *  This struct provides function pointers for runtime, so that functions can be
00103  *  written more generally (with fewer/no special exceptions for various modifiers).
00104  *
00105  *  Callers of these functions must check that they actually point to something useful,
00106  *  as some constraints don't define some of these.
00107  *
00108  *  Warning: it is not too advisable to reorder order of members of this struct,
00109  *          as you'll have to edit quite a few ($FMODIFIER_NUM_TYPES) of these
00110  *          structs.
00111  */
00112 typedef struct FModifierTypeInfo {
00113     /* admin/ident */
00114     short type;             /* FMODIFIER_TYPE_### */
00115     short size;             /* size in bytes of the struct */
00116     short acttype;          /* eFMI_Action_Types */
00117     short requires;         /* eFMI_Requirement_Flags */
00118     char name[64];          /* name of modifier in interface */
00119     char structName[64];    /* name of struct for SDNA */
00120     
00121     /* data management function pointers - special handling */
00122         /* free any data that is allocated separately (optional) */
00123     void (*free_data)(struct FModifier *fcm);
00124         /* copy any special data that is allocated separately (optional) */
00125     void (*copy_data)(struct FModifier *fcm, struct FModifier *src);
00126         /* set settings for data that will be used for FCuModifier.data (memory already allocated using MEM_callocN) */
00127     void (*new_data)(void *mdata);
00128         /* verifies that the modifier settings are valid */
00129     void (*verify_data)(struct FModifier *fcm);
00130     
00131     /* evaluation */
00132         /* evaluate time that the modifier requires the F-Curve to be evaluated at */
00133     float (*evaluate_modifier_time)(struct FCurve *fcu, struct FModifier *fcm, float cvalue, float evaltime);
00134         /* evaluate the modifier for the given time and 'accumulated' value */
00135     void (*evaluate_modifier)(struct FCurve *fcu, struct FModifier *fcm, float *cvalue, float evaltime);
00136 } FModifierTypeInfo;
00137 
00138 /* Values which describe the behaviour of a FModifier Type */
00139 typedef enum eFMI_Action_Types {
00140         /* modifier only modifies values outside of data range */
00141     FMI_TYPE_EXTRAPOLATION = 0,
00142         /* modifier leaves data-points alone, but adjusts the interpolation between and around them */
00143     FMI_TYPE_INTERPOLATION,
00144         /* modifier only modifies the values of points (but times stay the same) */
00145     FMI_TYPE_REPLACE_VALUES,
00146         /* modifier generates a curve regardless of what came before */
00147     FMI_TYPE_GENERATE_CURVE
00148 } eFMI_Action_Types;
00149 
00150 /* Flags for the requirements of a FModifier Type */
00151 typedef enum eFMI_Requirement_Flags {
00152         /* modifier requires original data-points (kindof beats the purpose of a modifier stack?) */
00153     FMI_REQUIRES_ORIGINAL_DATA      = (1<<0),
00154         /* modifier doesn't require on any preceding data (i.e. it will generate a curve). 
00155          * Use in conjunction with FMI_TYPE_GENRATE_CURVE 
00156          */
00157     FMI_REQUIRES_NOTHING            = (1<<1),
00158         /* refer to modifier instance */
00159     FMI_REQUIRES_RUNTIME_CHECK      = (1<<2)
00160 } eFMI_Requirement_Flags;
00161 
00162 /* Function Prototypes for FModifierTypeInfo's */
00163 FModifierTypeInfo *fmodifier_get_typeinfo(struct FModifier *fcm);
00164 FModifierTypeInfo *get_fmodifier_typeinfo(int type);
00165 
00166 /* ---------------------- */
00167 
00168 struct FModifier *add_fmodifier(ListBase *modifiers, int type);
00169 struct FModifier *copy_fmodifier(struct FModifier *src);
00170 void copy_fmodifiers(ListBase *dst, ListBase *src);
00171 int remove_fmodifier(ListBase *modifiers, struct FModifier *fcm);
00172 void free_fmodifiers(ListBase *modifiers);
00173 
00174 struct FModifier *find_active_fmodifier(ListBase *modifiers);
00175 void set_active_fmodifier(ListBase *modifiers, struct FModifier *fcm);
00176 
00177 short list_has_suitable_fmodifier(ListBase *modifiers, int mtype, short acttype);
00178 
00179 float evaluate_time_fmodifiers(ListBase *modifiers, struct FCurve *fcu, float cvalue, float evaltime);
00180 void evaluate_value_fmodifiers(ListBase *modifiers, struct FCurve *fcu, float *cvalue, float evaltime);
00181 
00182 void fcurve_bake_modifiers(struct FCurve *fcu, int start, int end);
00183 
00184 /* ************** F-Curves API ******************** */
00185 
00186 /* -------- Data Managemnt  --------  */
00187 
00188 void free_fcurve(struct FCurve *fcu);
00189 struct FCurve *copy_fcurve(struct FCurve *fcu);
00190 
00191 void free_fcurves(ListBase *list);
00192 void copy_fcurves(ListBase *dst, ListBase *src);
00193 
00194 /* find matching F-Curve in the given list of F-Curves */
00195 struct FCurve *list_find_fcurve(ListBase *list, const char rna_path[], const int array_index);
00196 
00197 struct FCurve *iter_step_fcurve (struct FCurve *fcu_iter, const char rna_path[]);
00198 
00199 /* high level function to get an fcurve from C without having the rna */
00200 struct FCurve *id_data_find_fcurve(ID *id, void *data, struct StructRNA *type, const char *prop_name, int index, char *driven);
00201 
00202 /* Get list of LinkData's containing pointers to the F-Curves which control the types of data indicated 
00203  *  e.g.  numMatches = list_find_data_fcurves(matches, &act->curves, "pose.bones[", "MyFancyBone");
00204  */
00205 int list_find_data_fcurves(ListBase *dst, ListBase *src, const char *dataPrefix, const char *dataName);
00206 
00207 /* find an f-curve based on an rna property */
00208 struct FCurve *rna_get_fcurve(struct PointerRNA *ptr, struct PropertyRNA *prop, int rnaindex, struct bAction **action, int *driven);
00209 
00210 /* Binary search algorithm for finding where to 'insert' BezTriple with given frame number.
00211  * Returns the index to insert at (data already at that index will be offset if replace is 0)
00212  */
00213 int binarysearch_bezt_index(struct BezTriple array[], float frame, int arraylen, short *replace);
00214 
00215 /* get the time extents for F-Curve */
00216 void calc_fcurve_range(struct FCurve *fcu, float *min, float *max,
00217                        const short do_sel_only, const short do_min_length);
00218 
00219 /* get the bounding-box extents for F-Curve */
00220 void calc_fcurve_bounds(struct FCurve *fcu, float *xmin, float *xmax, float *ymin, float *ymax,
00221                         const short do_sel_only);
00222 
00223 /* .............. */
00224 
00225 /* Are keyframes on F-Curve of any use (to final result, and to show in editors)? */
00226 short fcurve_are_keyframes_usable(struct FCurve *fcu);
00227 
00228 /* Can keyframes be added to F-Curve? */
00229 short fcurve_is_keyframable(struct FCurve *fcu);
00230 
00231 /* -------- Curve Sanity --------  */
00232 
00233 void calchandles_fcurve(struct FCurve *fcu);
00234 void testhandles_fcurve(struct FCurve *fcu, const short use_handle);
00235 void sort_time_fcurve(struct FCurve *fcu);
00236 short test_time_fcurve(struct FCurve *fcu);
00237 
00238 void correct_bezpart(float *v1, float *v2, float *v3, float *v4);
00239 
00240 /* -------- Evaluation --------  */
00241 
00242 /* evaluate fcurve */
00243 float evaluate_fcurve(struct FCurve *fcu, float evaltime);
00244 /* evaluate fcurve and store value */
00245 void calculate_fcurve(struct FCurve *fcu, float ctime);
00246 
00247 /* ************* F-Curve Samples API ******************** */
00248 
00249 /* -------- Defines --------  */
00250 
00251 /* Basic signature for F-Curve sample-creation function 
00252  *  - fcu: the F-Curve being operated on
00253  *  - data: pointer to some specific data that may be used by one of the callbacks
00254  */
00255 typedef float (*FcuSampleFunc)(struct FCurve *fcu, void *data, float evaltime);
00256 
00257 /* ----- Sampling Callbacks ------  */
00258 
00259 /* Basic sampling callback which acts as a wrapper for evaluate_fcurve() */
00260 float fcurve_samplingcb_evalcurve(struct FCurve *fcu, void *data, float evaltime);
00261 
00262 /* -------- Main Methods --------  */
00263 
00264 /* Main API function for creating a set of sampled curve data, given some callback function 
00265  * used to retrieve the values to store.
00266  */
00267 void fcurve_store_samples(struct FCurve *fcu, void *data, int start, int end, FcuSampleFunc sample_cb);
00268 
00269 #ifdef __cplusplus
00270 }
00271 #endif
00272 
00273 #endif /* BKE_FCURVE_H*/