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>2010-01-26 06:16:14 +0300
committerJoshua Leung <aligorith@gmail.com>2010-01-26 06:16:14 +0300
commit14d4feca576e78d3707872bfb8b29c749bb20572 (patch)
tree1f9b6fa131a1011ea6d4f60876b3fccca2ca8e78 /source/blender/editors/animation
parente6a23762da3f6b88da21669b7ae30c834ace2f55 (diff)
Radians vs Degrees: The Second Attempt
F-Curves now internally store radians again instead of degrees. - This solves problems with inconsistencies when working with drivers. - No need to version patch old files, potentially screwing them up. As such, removed the version patching for F-Curves. - Is better suited to optionally showing radians throughout the UI instead or degrees. As a result, values are now converted on the fly in the Graph Editor for display and operators that operate on values. I've made the conversion system for this rather general, so that other unit type conversions can also be hooked up with the type conversion backend. Also, made some tweaks to F-Curve RNA wrapping to make it represent the data better. TODO: - Transform code currently still needs to be corrected to work with these changes. Currently moving keyframes for rotation curves will make them change too rapidly vertically when using degrees.
Diffstat (limited to 'source/blender/editors/animation')
-rw-r--r--source/blender/editors/animation/anim_draw.c98
-rw-r--r--source/blender/editors/animation/keyframing.c15
2 files changed, 99 insertions, 14 deletions
diff --git a/source/blender/editors/animation/anim_draw.c b/source/blender/editors/animation/anim_draw.c
index 6b1933a791f..b99aefebfe7 100644
--- a/source/blender/editors/animation/anim_draw.c
+++ b/source/blender/editors/animation/anim_draw.c
@@ -62,6 +62,8 @@
#include "WM_api.h"
#include "WM_types.h"
+#include "RNA_access.h"
+
#include "BIF_gl.h"
#include "BIF_glutil.h"
@@ -237,6 +239,7 @@ void ANIM_draw_previewrange (const bContext *C, View2D *v2d)
/* NLA-MAPPING UTILITIES (required for drawing and also editing keyframes) */
/* Obtain the AnimData block providing NLA-mapping for the given channel (if applicable) */
+// TODO: do not supply return this if the animdata tells us that there is no mapping to perform
AnimData *ANIM_nla_mapping_get(bAnimContext *ac, bAnimListElem *ale)
{
/* sanity checks */
@@ -252,11 +255,6 @@ AnimData *ANIM_nla_mapping_get(bAnimContext *ac, bAnimListElem *ale)
/* ------------------- */
-typedef struct NlaMappingApplyBackup {
- struct NlaMappingBackup *next, *prev;
- BezTriple bezt;
-} NlaMappingApplyBackup;
-
/* helper function for ANIM_nla_mapping_apply_fcurve() -> "restore", i.e. mapping points back to action-time */
static short bezt_nlamapping_restore(BeztEditData *bed, BezTriple *bezt)
{
@@ -322,3 +320,93 @@ void ANIM_nla_mapping_apply_fcurve (AnimData *adt, FCurve *fcu, short restore, s
}
/* *************************************************** */
+/* UNITS CONVERSION MAPPING (required for drawing and editing keyframes) */
+
+/* Get unit conversion factor for given ID + F-Curve */
+float ANIM_unit_mapping_get_factor (Scene *scene, ID *id, FCurve *fcu, short restore)
+{
+ /* sanity checks */
+ if (id && fcu && fcu->rna_path)
+ {
+ PointerRNA ptr, id_ptr;
+ PropertyRNA *prop;
+
+ /* get RNA property that F-Curve affects */
+ RNA_id_pointer_create(id, &id_ptr);
+ if (RNA_path_resolve(&id_ptr, fcu->rna_path, &ptr, &prop))
+ {
+ /* rotations: radians <-> degrees? */
+ if (RNA_SUBTYPE_UNIT(RNA_property_subtype(prop)) == PROP_UNIT_ROTATION)
+ {
+ /* if the radians flag is not set, default to using degrees which need conversions */
+ if ((scene) && (scene->unit.flag & USER_UNIT_ROT_RADIANS) == 0) {
+ if (restore)
+ return M_PI / 180.0f; /* degrees to radians */
+ else
+ return 180.0f / M_PI; /* radians to degrees */
+ }
+ }
+
+ // TODO: other rotation types here as necessary
+ }
+ }
+
+ /* no mapping needs to occur... */
+ return 1.0f;
+}
+
+/* ----------------------- */
+
+/* helper function for ANIM_unit_mapping_apply_fcurve -> mapping callback for unit mapping */
+static short bezt_unit_mapping_apply (BeztEditData *bed, BezTriple *bezt)
+{
+ /* mapping factor is stored in f1, only_keys option is stored in i1 */
+ short only_keys= (short)bed->i1;
+ float fac= bed->f1;
+
+ /* adjust BezTriple handles only if allowed to */
+ if (only_keys == 0) {
+ bezt->vec[0][1] *= fac;
+ bezt->vec[2][1] *= fac;
+ }
+
+ bezt->vec[1][1] *= fac;
+
+ return 0;
+}
+
+/* Apply/Unapply units conversions to keyframes */
+void ANIM_unit_mapping_apply_fcurve (Scene *scene, ID *id, FCurve *fcu, short restore, short only_keys)
+{
+ BeztEditData bed;
+ float fac;
+
+ /* calculate mapping factor, and abort if nothing to change */
+ fac= ANIM_unit_mapping_get_factor(scene, id, fcu, restore);
+ if (fac == 1.0f)
+ return;
+
+ /* init edit data
+ * - mapping factor is stored in f1
+ * - only_keys is stored in 'i1'
+ */
+ memset(&bed, 0, sizeof(BeztEditData));
+ bed.f1= (float)fac;
+ bed.i1= (int)only_keys;
+
+ /* apply to F-Curve */
+ ANIM_fcurve_keys_bezier_loop(&bed, fcu, NULL, bezt_unit_mapping_apply, NULL);
+
+ // FIXME: loop here for samples should be generalised
+ if (fcu->fpt) {
+ FPoint *fpt;
+ int i;
+
+ for (i=0, fpt=fcu->fpt; i < fcu->totvert; i++, fpt++) {
+ /* apply unit mapping */
+ fpt->vec[1] *= fac;
+ }
+ }
+}
+
+/* *************************************************** */
diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c
index 1ad3c0dd587..c11a7197dee 100644
--- a/source/blender/editors/animation/keyframing.c
+++ b/source/blender/editors/animation/keyframing.c
@@ -783,11 +783,6 @@ short insert_keyframe_direct (PointerRNA ptr, PropertyRNA *prop, FCurve *fcu, fl
curval= setting_get_rna_value(&ptr, prop, fcu->array_index);
}
- /* convert to degrees */
- if (RNA_SUBTYPE_UNIT(RNA_property_subtype(prop)) == PROP_UNIT_ROTATION) {
- curval *= 180.0/M_PI;
- }
-
/* only insert keyframes where they are needed */
if (flag & INSERTKEY_NEEDED) {
short insert_mode;
@@ -900,10 +895,6 @@ short insert_keyframe (ID *id, bAction *act, const char group[], const char rna_
}
}
- /* mark the curve if it's a new rotation curve */
- if ((fcu->totvert == 0) && (RNA_SUBTYPE_UNIT(RNA_property_subtype(prop)) == PROP_UNIT_ROTATION))
- fcu->flag |= FCURVE_ROTATION_DEGREES;
-
/* insert keyframe */
ret += insert_keyframe_direct(ptr, prop, fcu, cfra, flag);
}
@@ -926,6 +917,12 @@ short delete_keyframe (ID *id, bAction *act, const char group[], const char rna_
AnimData *adt= BKE_animdata_from_id(id);
FCurve *fcu = NULL;
+ /* sanity checks */
+ if ELEM(NULL, id, adt) {
+ printf("ERROR: no ID-block and/or AnimData to delete keyframe from \n");
+ break;
+ }
+
/* get F-Curve
* Note: here is one of the places where we don't want new Action + F-Curve added!
* so 'add' var must be 0