Assorted F-Curve/Keyframe API stuff (for use with some Sequencer editing):
* Added function for F-Curves to find the F-Curves in a given list which affect some named data, such as bones, nodes, or sequence strips. * Added a BezTriple offsetting callback to be used with the F-Curve+Keyframe loopers in use for many of the keyframe editing tools.
This commit is contained in:
@@ -158,7 +158,12 @@ void copy_fcurves(ListBase *dst, ListBase *src);
|
||||
struct FCurve *list_find_fcurve(ListBase *list, const char rna_path[], const int array_index);
|
||||
|
||||
/* high level function to get an fcurve from C without having the rna */
|
||||
struct FCurve *id_data_find_fcurve(ID* id, void *data, struct StructRNA *type, char *prop_name, int index);
|
||||
struct FCurve *id_data_find_fcurve(ID *id, void *data, struct StructRNA *type, char *prop_name, int index);
|
||||
|
||||
/* Get list of LinkData's containing pointers to the F-Curves which control the types of data indicated
|
||||
* e.g. numMatches = list_find_data_fcurves(matches, &act->curves, "pose.bones[", "MyFancyBone");
|
||||
*/
|
||||
int list_find_data_fcurves(ListBase *dst, ListBase *src, const char *dataPrefix, const char *dataName);
|
||||
|
||||
/* Binary search algorithm for finding where to 'insert' BezTriple with given frame number.
|
||||
* Returns the index to insert at (data already at that index will be offset if replace is 0)
|
||||
|
||||
@@ -167,53 +167,42 @@ void copy_fcurves (ListBase *dst, ListBase *src)
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------- Relink --------------------------- */
|
||||
|
||||
#if 0
|
||||
/* uses id->newid to match pointers with other copied data
|
||||
* - called after single-user or other such
|
||||
*/
|
||||
if (icu->driver)
|
||||
ID_NEW(icu->driver->ob);
|
||||
#endif
|
||||
|
||||
/* --------------------- Finding -------------------------- */
|
||||
|
||||
/* high level function to get an fcurve from C without having the rna */
|
||||
FCurve *id_data_find_fcurve(ID *id, void *data, StructRNA *type, char *prop_name, int index)
|
||||
{
|
||||
/* anim vars */
|
||||
AnimData *adt;
|
||||
AnimData *adt= BKE_animdata_from_id(id);
|
||||
FCurve *fcu= NULL;
|
||||
|
||||
/* rna vars */
|
||||
PointerRNA ptr;
|
||||
PropertyRNA *prop;
|
||||
char *path;
|
||||
|
||||
adt= BKE_animdata_from_id(id);
|
||||
|
||||
|
||||
/* only use the current action ??? */
|
||||
if(adt==NULL || adt->action==NULL)
|
||||
if (ELEM(NULL, adt, adt->action))
|
||||
return NULL;
|
||||
|
||||
|
||||
RNA_pointer_create(id, type, data, &ptr);
|
||||
prop = RNA_struct_find_property(&ptr, prop_name);
|
||||
|
||||
if(prop) {
|
||||
|
||||
if (prop) {
|
||||
path= RNA_path_from_ID_to_property(&ptr, prop);
|
||||
|
||||
if(path) {
|
||||
|
||||
if (path) {
|
||||
/* animation takes priority over drivers */
|
||||
if(adt->action && adt->action->curves.first)
|
||||
if ((adt->action) && (adt->action->curves.first))
|
||||
fcu= list_find_fcurve(&adt->action->curves, path, index);
|
||||
|
||||
|
||||
/* if not animated, check if driven */
|
||||
#if 0
|
||||
if(!fcu && (adt->drivers.first)) {
|
||||
if ((fcu == NULL) && (adt->drivers.first)) {
|
||||
fcu= list_find_fcurve(&adt->drivers, path, but->rnaindex);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
MEM_freeN(path);
|
||||
}
|
||||
}
|
||||
@@ -245,6 +234,54 @@ FCurve *list_find_fcurve (ListBase *list, const char rna_path[], const int array
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Get list of LinkData's containing pointers to the F-Curves which control the types of data indicated
|
||||
* Lists...
|
||||
* - dst: list of LinkData's matching the criteria returned.
|
||||
* List must be freed after use, and is assumed to be empty when passed.
|
||||
* - src: list of F-Curves to search through
|
||||
* Filters...
|
||||
* - dataPrefix: i.e. 'pose.bones[' or 'nodes['
|
||||
* - dataName: name of entity within "" immediately following the prefix
|
||||
*/
|
||||
int list_find_data_fcurves (ListBase *dst, ListBase *src, const char *dataPrefix, const char *dataName)
|
||||
{
|
||||
FCurve *fcu;
|
||||
int matches = 0;
|
||||
|
||||
/* sanity checks */
|
||||
if (ELEM4(NULL, dst, src, dataPrefix, dataName))
|
||||
return 0;
|
||||
else if ((dataPrefix[0] == 0) || (dataName[0] == 0))
|
||||
return 0;
|
||||
|
||||
/* search each F-Curve one by one */
|
||||
for (fcu= src->first; fcu; fcu= fcu->next) {
|
||||
/* check if quoted string matches the path */
|
||||
if ((fcu->rna_path) && strstr(fcu->rna_path, dataPrefix)) {
|
||||
char *quotedName= BLI_getQuotedStr(fcu->rna_path, dataPrefix);
|
||||
|
||||
if (quotedName) {
|
||||
/* check if the quoted name matches the required name */
|
||||
if (strcmp(quotedName, dataName) == 0) {
|
||||
LinkData *ld= MEM_callocN(sizeof(LinkData), "list_find_data_fcurves");
|
||||
|
||||
ld->data= fcu;
|
||||
BLI_addtail(dst, ld);
|
||||
|
||||
matches++;
|
||||
}
|
||||
|
||||
/* always free the quoted string, since it needs freeing */
|
||||
MEM_freeN(quotedName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* return the number of matches */
|
||||
return matches;
|
||||
}
|
||||
|
||||
|
||||
/* threshold for binary-searching keyframes - threshold here should be good enough for now, but should become userpref */
|
||||
#define BEZT_BINARYSEARCH_THRESH 0.00001f
|
||||
|
||||
|
||||
@@ -559,6 +559,22 @@ short bezt_to_cfraelem(BeztEditData *bed, BezTriple *bezt)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* used to remap times from one range to another
|
||||
* requires: bed->data = BeztEditCD_Remap
|
||||
*/
|
||||
short bezt_remap_times(BeztEditData *bed, BezTriple *bezt)
|
||||
{
|
||||
BeztEditCD_Remap *rmap= (BeztEditCD_Remap*)bed->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
|
||||
|
||||
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 */
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
* fine to have these calls here.
|
||||
*
|
||||
* There are also a few tools here which cannot be easily coded for in the other system (yet).
|
||||
* These may also be moved around at some point, but for now, they
|
||||
* These may also be moved around at some point, but for now, they are best added here.
|
||||
*
|
||||
* - Joshua Leung, Dec 2008
|
||||
*/
|
||||
|
||||
@@ -100,11 +100,19 @@ typedef struct BeztEditData {
|
||||
|
||||
/* ------- Function Pointer Typedefs ---------------- */
|
||||
|
||||
/* callback function that refreshes the IPO curve after use */
|
||||
/* callback function that refreshes the F-Curve after use */
|
||||
typedef void (*FcuEditFunc)(struct FCurve *fcu);
|
||||
/* callback function that operates on the given BezTriple */
|
||||
typedef short (*BeztEditFunc)(BeztEditData *bed, struct BezTriple *bezt);
|
||||
|
||||
/* ------- Custom Data Type Defines ------------------ */
|
||||
|
||||
/* Custom data for remapping one range to another in a fixed way */
|
||||
typedef struct BeztEditCD_Remap {
|
||||
float oldMin, oldMax; /* old range */
|
||||
float newMin, newMax; /* new range */
|
||||
} BeztEditCD_Remap;
|
||||
|
||||
/* ---------------- Looping API --------------------- */
|
||||
|
||||
/* functions for looping over keyframes */
|
||||
@@ -137,9 +145,17 @@ BeztEditFunc ANIM_editkeyframes_keytype(short mode);
|
||||
|
||||
/* ----------- BezTriple Callback (Assorted Utilities) ---------- */
|
||||
|
||||
/* used to calculate the the average location of all relevant BezTriples by summing their locations */
|
||||
short bezt_calc_average(BeztEditData *bed, struct BezTriple *bezt);
|
||||
|
||||
/* used to extract a set of cfra-elems from the keyframes */
|
||||
short bezt_to_cfraelem(BeztEditData *bed, struct BezTriple *bezt);
|
||||
|
||||
/* used to remap times from one range to another
|
||||
* requires: bed->custom = BeztEditCD_Remap
|
||||
*/
|
||||
short bezt_remap_times(BeztEditData *bed, struct BezTriple *bezt);
|
||||
|
||||
/* ************************************************ */
|
||||
/* Destructive Editing API (keyframes_general.c) */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user