Blender  V2.59
BKE_fcurve.h
Go to the documentation of this file.
00001 /*
00002  * $Id: BKE_fcurve.h 35590 2011-03-17 10:02:37Z aligorith $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2009 Blender Foundation, Joshua Leung
00021  * All rights reserved.
00022  *
00023  * Contributor(s): Joshua Leung (full recode)
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00028 #ifndef BKE_FCURVE_H
00029 #define BKE_FCURVE_H
00030 
00037 #ifdef __cplusplus
00038 extern "C" {
00039 #endif
00040 
00041 struct FCurve;
00042 struct FModifier;
00043 struct ChannelDriver;
00044 struct DriverVar;
00045 struct DriverTarget;
00046 
00047 struct bAction;
00048 struct BezTriple;
00049 struct StructRNA;
00050 struct PointerRNA;
00051 struct PropertyRNA;
00052 
00053 #include "DNA_curve_types.h"
00054 
00055 /* ************** Keyframe Tools ***************** */
00056 
00057 typedef struct CfraElem {
00058         struct CfraElem *next, *prev;
00059         float cfra;
00060         int sel;
00061 } CfraElem;
00062 
00063 void bezt_add_to_cfra_elem(ListBase *lb, struct BezTriple *bezt);
00064 
00065 /* ************** F-Curve Drivers ***************** */
00066 
00067 /* With these iterators for convenience, the variables "tarIndex" and "dtar" can be 
00068  * accessed directly from the code using them, but it is not recommended that their
00069  * values be changed to point at other slots...
00070  */
00071 
00072 /* convenience looper over ALL driver targets for a given variable (even the unused ones) */
00073 #define DRIVER_TARGETS_LOOPER(dvar) \
00074         { \
00075                 DriverTarget *dtar= &dvar->targets[0]; \
00076                 int tarIndex= 0; \
00077                 for (; tarIndex < MAX_DRIVER_TARGETS; tarIndex++, dtar++)
00078                  
00079 /* convenience looper over USED driver targets only */
00080 #define DRIVER_TARGETS_USED_LOOPER(dvar) \
00081         { \
00082                 DriverTarget *dtar= &dvar->targets[0]; \
00083                 int tarIndex= 0; \
00084                 for (; tarIndex < dvar->num_targets; tarIndex++, dtar++)
00085                 
00086 /* tidy up for driver targets loopers */
00087 #define DRIVER_TARGETS_LOOPER_END \
00088         }
00089 
00090 /* ---------------------- */
00091 
00092 void fcurve_free_driver(struct FCurve *fcu);
00093 struct ChannelDriver *fcurve_copy_driver(struct ChannelDriver *driver);
00094 
00095 void driver_free_variable(struct ChannelDriver *driver, struct DriverVar *dvar);
00096 void driver_change_variable_type(struct DriverVar *dvar, int type);
00097 struct DriverVar *driver_add_new_variable(struct ChannelDriver *driver);
00098 
00099 float driver_get_variable_value (struct ChannelDriver *driver, struct DriverVar *dvar);
00100 
00101 /* ************** F-Curve Modifiers *************** */
00102 
00103 /* F-Curve Modifier Type-Info (fmi):
00104  *  This struct provides function pointers for runtime, so that functions can be
00105  *  written more generally (with fewer/no special exceptions for various modifiers).
00106  *
00107  *  Callers of these functions must check that they actually point to something useful,
00108  *  as some constraints don't define some of these.
00109  *
00110  *  Warning: it is not too advisable to reorder order of members of this struct,
00111  *                      as you'll have to edit quite a few ($FMODIFIER_NUM_TYPES) of these
00112  *                      structs.
00113  */
00114 typedef struct FModifierTypeInfo {
00115         /* admin/ident */
00116         short type;                             /* FMODIFIER_TYPE_### */
00117         short size;                             /* size in bytes of the struct */
00118         short acttype;                  /* eFMI_Action_Types */
00119         short requires;                 /* eFMI_Requirement_Flags */
00120         char name[64];                  /* name of modifier in interface */
00121         char structName[64];    /* name of struct for SDNA */
00122         
00123         /* data management function pointers - special handling */
00124                 /* free any data that is allocated separately (optional) */
00125         void (*free_data)(struct FModifier *fcm);
00126                 /* copy any special data that is allocated separately (optional) */
00127         void (*copy_data)(struct FModifier *fcm, struct FModifier *src);
00128                 /* set settings for data that will be used for FCuModifier.data (memory already allocated using MEM_callocN) */
00129         void (*new_data)(void *mdata);
00130                 /* verifies that the modifier settings are valid */
00131         void (*verify_data)(struct FModifier *fcm);
00132         
00133         /* evaluation */
00134                 /* evaluate time that the modifier requires the F-Curve to be evaluated at */
00135         float (*evaluate_modifier_time)(struct FCurve *fcu, struct FModifier *fcm, float cvalue, float evaltime);
00136                 /* evaluate the modifier for the given time and 'accumulated' value */
00137         void (*evaluate_modifier)(struct FCurve *fcu, struct FModifier *fcm, float *cvalue, float evaltime);
00138 } FModifierTypeInfo;
00139 
00140 /* Values which describe the behaviour of a FModifier Type */
00141 typedef enum eFMI_Action_Types {
00142                 /* modifier only modifies values outside of data range */
00143         FMI_TYPE_EXTRAPOLATION = 0,
00144                 /* modifier leaves data-points alone, but adjusts the interpolation between and around them */
00145         FMI_TYPE_INTERPOLATION,
00146                 /* modifier only modifies the values of points (but times stay the same) */
00147         FMI_TYPE_REPLACE_VALUES,
00148                 /* modifier generates a curve regardless of what came before */
00149         FMI_TYPE_GENERATE_CURVE
00150 } eFMI_Action_Types;
00151 
00152 /* Flags for the requirements of a FModifier Type */
00153 typedef enum eFMI_Requirement_Flags {
00154                 /* modifier requires original data-points (kindof beats the purpose of a modifier stack?) */
00155         FMI_REQUIRES_ORIGINAL_DATA              = (1<<0),
00156                 /* modifier doesn't require on any preceding data (i.e. it will generate a curve). 
00157                  * Use in conjunction with FMI_TYPE_GENRATE_CURVE 
00158                  */
00159         FMI_REQUIRES_NOTHING                    = (1<<1),
00160                 /* refer to modifier instance */
00161         FMI_REQUIRES_RUNTIME_CHECK              = (1<<2)
00162 } eFMI_Requirement_Flags;
00163 
00164 /* Function Prototypes for FModifierTypeInfo's */
00165 FModifierTypeInfo *fmodifier_get_typeinfo(struct FModifier *fcm);
00166 FModifierTypeInfo *get_fmodifier_typeinfo(int type);
00167 
00168 /* ---------------------- */
00169 
00170 struct FModifier *add_fmodifier(ListBase *modifiers, int type);
00171 struct FModifier *copy_fmodifier(struct FModifier *src);
00172 void copy_fmodifiers(ListBase *dst, ListBase *src);
00173 int remove_fmodifier(ListBase *modifiers, struct FModifier *fcm);
00174 void free_fmodifiers(ListBase *modifiers);
00175 
00176 struct FModifier *find_active_fmodifier(ListBase *modifiers);
00177 void set_active_fmodifier(ListBase *modifiers, struct FModifier *fcm);
00178 
00179 short list_has_suitable_fmodifier(ListBase *modifiers, int mtype, short acttype);
00180 
00181 float evaluate_time_fmodifiers(ListBase *modifiers, struct FCurve *fcu, float cvalue, float evaltime);
00182 void evaluate_value_fmodifiers(ListBase *modifiers, struct FCurve *fcu, float *cvalue, float evaltime);
00183 
00184 void fcurve_bake_modifiers(struct FCurve *fcu, int start, int end);
00185 
00186 /* ************** F-Curves API ******************** */
00187 
00188 /* -------- Data Managemnt  --------  */
00189 
00190 void free_fcurve(struct FCurve *fcu);
00191 struct FCurve *copy_fcurve(struct FCurve *fcu);
00192 
00193 void free_fcurves(ListBase *list);
00194 void copy_fcurves(ListBase *dst, ListBase *src);
00195 
00196 /* find matching F-Curve in the given list of F-Curves */
00197 struct FCurve *list_find_fcurve(ListBase *list, const char rna_path[], const int array_index);
00198 
00199 struct FCurve *iter_step_fcurve (struct FCurve *fcu_iter, const char rna_path[]);
00200 
00201 /* high level function to get an fcurve from C without having the rna */
00202 struct FCurve *id_data_find_fcurve(ID *id, void *data, struct StructRNA *type, const char *prop_name, int index);
00203 
00204 /* Get list of LinkData's containing pointers to the F-Curves which control the types of data indicated 
00205  *      e.g.  numMatches = list_find_data_fcurves(matches, &act->curves, "pose.bones[", "MyFancyBone");
00206  */
00207 int list_find_data_fcurves(ListBase *dst, ListBase *src, const char *dataPrefix, const char *dataName);
00208 
00209 /* find an f-curve based on an rna property */
00210 struct FCurve *rna_get_fcurve(struct PointerRNA *ptr, struct PropertyRNA *prop, int rnaindex, struct bAction **action, int *driven);
00211 
00212 /* Binary search algorithm for finding where to 'insert' BezTriple with given frame number.
00213  * Returns the index to insert at (data already at that index will be offset if replace is 0)
00214  */
00215 int binarysearch_bezt_index(struct BezTriple array[], float frame, int arraylen, short *replace);
00216 
00217 /* get the time extents for F-Curve */
00218 void calc_fcurve_range(struct FCurve *fcu, float *min, float *max, const short selOnly);
00219 
00220 /* get the bounding-box extents for F-Curve */
00221 void calc_fcurve_bounds(struct FCurve *fcu, float *xmin, float *xmax, float *ymin, float *ymax, const short selOnly);
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);
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*/