Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2009-12-22 13:14:13 +0300
committerJoshua Leung <aligorith@gmail.com>2009-12-22 13:14:13 +0300
commit5a3ac3ceeb0d3550c14987f5cfd607e1ad126e64 (patch)
treea8745cb5bf1ad23a1702993f964a96ddf64092a3 /source
parente207d045322db4656f42f68ae9fa092ac1478635 (diff)
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.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/BKE_fcurve.h7
-rw-r--r--source/blender/blenkernel/intern/fcurve.c85
-rw-r--r--source/blender/editors/animation/keyframes_edit.c16
-rw-r--r--source/blender/editors/animation/keyframes_general.c2
-rw-r--r--source/blender/editors/include/ED_keyframes_edit.h18
5 files changed, 101 insertions, 27 deletions
diff --git a/source/blender/blenkernel/BKE_fcurve.h b/source/blender/blenkernel/BKE_fcurve.h
index 5888c6d7530..fa6b8969edb 100644
--- a/source/blender/blenkernel/BKE_fcurve.h
+++ b/source/blender/blenkernel/BKE_fcurve.h
@@ -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)
diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c
index b5f3d0a4be0..d5e033652a8 100644
--- a/source/blender/blenkernel/intern/fcurve.c
+++ b/source/blender/blenkernel/intern/fcurve.c
@@ -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
diff --git a/source/blender/editors/animation/keyframes_edit.c b/source/blender/editors/animation/keyframes_edit.c
index 83acfbee940..9476aa479a7 100644
--- a/source/blender/editors/animation/keyframes_edit.c
+++ b/source/blender/editors/animation/keyframes_edit.c
@@ -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 */
diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c
index 3b717bafc70..fb9d4d53b0f 100644
--- a/source/blender/editors/animation/keyframes_general.c
+++ b/source/blender/editors/animation/keyframes_general.c
@@ -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
*/
diff --git a/source/blender/editors/include/ED_keyframes_edit.h b/source/blender/editors/include/ED_keyframes_edit.h
index 4a0a3ee24db..26290d8771c 100644
--- a/source/blender/editors/include/ED_keyframes_edit.h
+++ b/source/blender/editors/include/ED_keyframes_edit.h
@@ -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) */