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
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2009-03-01 14:27:31 +0300
committerJoshua Leung <aligorith@gmail.com>2009-03-01 14:27:31 +0300
commitd9c9108a6e62894d6ab696235af9a0af25693c76 (patch)
tree1261d026d7e7f873bea23d449d7fe9523805a366 /source/blender/blenkernel
parentdb472a3d14f81086ea1b472d4da6dded0879d84c (diff)
Graph Editor: Added operator to 'bake' keyframe-based F-Curves to be composed of samples.
This operator can be activated using the 'Alt-C' hotkey for now, and operates on selected + editable F-Curves. This is currently still highly experimental, and does crash I've implemented this as a way to test out the FPoints/samples code, which will be used to provide better support of the dense F-Curves which result from importing Mocap/BVH data. These should use considerably less memory + have a few additional benefits over keyframes when they're working in a stable fashion.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_fcurve.h21
-rw-r--r--source/blender/blenkernel/intern/fcurve.c84
2 files changed, 84 insertions, 21 deletions
diff --git a/source/blender/blenkernel/BKE_fcurve.h b/source/blender/blenkernel/BKE_fcurve.h
index dd5e0dd6e21..a8b1ad49648 100644
--- a/source/blender/blenkernel/BKE_fcurve.h
+++ b/source/blender/blenkernel/BKE_fcurve.h
@@ -108,5 +108,26 @@ float evaluate_fcurve(struct FCurve *fcu, float evaltime);
/* evaluate fcurve and store value */
void calculate_fcurve(struct FCurve *fcu, float ctime);
+/* ************* F-Curve Samples API ******************** */
+
+/* -------- Defines -------- */
+
+/* Basic signature for F-Curve sample-creation function
+ * - fcu: the F-Curve being operated on
+ * - data: pointer to some specific data that may be used by one of the callbacks
+ */
+typedef float (*FcuSampleFunc)(struct FCurve *fcu, void *data, float evaltime);
+
+/* ----- Sampling Callbacks ------ */
+
+/* Basic sampling callback which acts as a wrapper for evaluate_fcurve() */
+float fcurve_samplingcb_evalcurve(struct FCurve *fcu, void *data, float evaltime);
+
+/* -------- Main Methods -------- */
+
+/* Main API function for creating a set of sampled curve data, given some callback function
+ * used to retrieve the values to store.
+ */
+void fcurve_store_samples(struct FCurve *fcu, void *data, int start, int end, FcuSampleFunc sample_cb);
#endif /* BKE_FCURVE_H*/
diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c
index 49d1b06d9a2..f04d24e8803 100644
--- a/source/blender/blenkernel/intern/fcurve.c
+++ b/source/blender/blenkernel/intern/fcurve.c
@@ -294,6 +294,60 @@ void bezt_add_to_cfra_elem (ListBase *lb, BezTriple *bezt)
cen->sel= bezt->f2;
}
+/* ***************************** Samples Utilities ******************************* */
+/* Some utilities for working with FPoints (i.e. 'sampled' animation curve data, such as
+ * data imported from BVH/Mocap files), which are specialised for use with high density datasets,
+ * which BezTriples/Keyframe data are ill equipped to do.
+ */
+
+
+/* Basic sampling callback which acts as a wrapper for evaluate_fcurve()
+ * 'data' arg here is unneeded here...
+ */
+float fcurve_samplingcb_evalcurve (FCurve *fcu, void *data, float evaltime)
+{
+ /* assume any interference from drivers on the curve is intended... */
+ return evaluate_fcurve(fcu, evaltime);
+}
+
+
+/* Main API function for creating a set of sampled curve data, given some callback function
+ * used to retrieve the values to store.
+ */
+void fcurve_store_samples (FCurve *fcu, void *data, int start, int end, FcuSampleFunc sample_cb)
+{
+ FPoint *fpt, *new_fpt;
+ int cfra;
+
+ /* sanity checks */
+ // TODO: make these tests report errors using reports not printf's
+ if ELEM(NULL, fcu, sample_cb) {
+ printf("Error: No F-Curve with F-Curve Modifiers to Bake\n");
+ return;
+ }
+ if (start >= end) {
+ printf("Error: Frame range for Sampled F-Curve creation is inappropriate \n");
+ return;
+ }
+
+ /* set up sample data */
+ fpt= new_fpt= MEM_callocN(sizeof(FPoint)*(end-start+1), "FPoint Samples");
+
+ /* use the sampling callback at 1-frame intervals from start to end frames */
+ for (cfra= start; cfra <= end; cfra++, fpt++) {
+ fpt->vec[0]= (float)cfra;
+ fpt->vec[1]= sample_cb(fcu, data, (float)cfra);
+ }
+
+ /* free any existing sample/keyframe data on curve */
+ if (fcu->bezt) MEM_freeN(fcu->bezt);
+ if (fcu->fpt) MEM_freeN(fcu->fpt);
+
+ /* store the samples */
+ fcu->fpt= new_fpt;
+ fcu->totvert= end - start + 1;
+}
+
/* ***************************** F-Curve Sanity ********************************* */
/* The functions here are used in various parts of Blender, usually after some editing
* of keyframe data has occurred. They ensure that keyframe data is properly ordered and
@@ -1596,8 +1650,7 @@ void fcurve_free_modifiers (FCurve *fcu)
*/
void fcurve_bake_modifiers (FCurve *fcu, int start, int end)
{
- FPoint *fpt, *new_fpt;
- int cfra;
+ ChannelDriver *driver;
/* sanity checks */
// TODO: make these tests report errors using reports not printf's
@@ -1605,30 +1658,19 @@ void fcurve_bake_modifiers (FCurve *fcu, int start, int end)
printf("Error: No F-Curve with F-Curve Modifiers to Bake\n");
return;
}
- if (start >= end) {
- printf("Error: Frame range for F-Curve Modifier Baking inappropriate \n");
- return;
- }
- /* set up sample data */
- fpt= new_fpt= MEM_callocN(sizeof(FPoint)*(end-start+1), "FPoint FModifier Samples");
+ /* temporarily, disable driver while we sample, so that they don't influence the outcome */
+ driver= fcu->driver;
+ fcu->driver= NULL;
- /* sample the curve at 1-frame intervals from start to end frames
- * - assume that any ChannelDriver possibly present did not interfere in any way
- */
- for (cfra= start; cfra <= end; cfra++, fpt++) {
- fpt->vec[0]= (float)cfra;
- fpt->vec[1]= evaluate_fcurve(fcu, (float)cfra);
- }
+ /* bake the modifiers, by sampling the curve at each frame */
+ fcurve_store_samples(fcu, NULL, start, end, fcurve_samplingcb_evalcurve);
- /* free any existing sample/keyframe data on curve, and all modifiers */
- if (fcu->bezt) MEM_freeN(fcu->bezt);
- if (fcu->fpt) MEM_freeN(fcu->fpt);
+ /* free the modifiers now */
fcurve_free_modifiers(fcu);
- /* store the samples */
- fcu->fpt= new_fpt;
- fcu->totvert= end - start + 1;
+ /* restore driver */
+ fcu->driver= driver;
}
/* ***************************** F-Curve - Evaluation ********************************* */