diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-10-29 22:10:52 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-10-29 22:10:52 +0400 |
commit | 16d13e0db9d75566735966d81d213958df3ca7e5 (patch) | |
tree | 90d32baaabc12a690360bea0f9129bd2c2e1b436 /source/blender/editors/animation/anim_draw.c | |
parent | f6e504cee9f85867554f5a0ab89b52a66c0f257e (diff) |
Project Pampa request: FCurves normalized display
Added two options to a header of FCurve editor:
- Normalize which makes it so every individual
curve is fit into -1..1 space.
- Auto-normalize, which probably is to be called
"Lock" which "locks" curve normalization scale.
This is useful to prevent curves from jumping
around when tweaking it.
It's debatable whether it need to be a button to
normalize curves n purpose only, and it's fully
depends on animator's workflow.
Here during Project Pampa we've got Francesco
who get used to auto-renormalization and Hjalti
who prefers locked behavior.
Docs are to be ready soon by Francesco.
Thanks Brecht for the review!
Diffstat (limited to 'source/blender/editors/animation/anim_draw.c')
-rw-r--r-- | source/blender/editors/animation/anim_draw.c | 64 |
1 files changed, 62 insertions, 2 deletions
diff --git a/source/blender/editors/animation/anim_draw.c b/source/blender/editors/animation/anim_draw.c index 4a8557a2b1f..dcf9c8e623b 100644 --- a/source/blender/editors/animation/anim_draw.c +++ b/source/blender/editors/animation/anim_draw.c @@ -33,6 +33,7 @@ #include "DNA_anim_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" +#include "DNA_space_types.h" #include "DNA_userdef_types.h" #include "BLI_math.h" @@ -359,9 +360,68 @@ void ANIM_nla_mapping_apply_fcurve(AnimData *adt, FCurve *fcu, short restore, sh /* *************************************************** */ /* UNITS CONVERSION MAPPING (required for drawing and editing keyframes) */ +/* Get flags used for normalization in ANIM_unit_mapping_get_factor. */ +short ANIM_get_normalization_flags(bAnimContext *ac) +{ + if (ac->sl->spacetype == SPACE_IPO) { + SpaceIpo *sipo = (SpaceIpo *) ac->sl; + bool use_normalization = (sipo->flag & SIPO_NORMALIZE) != 0; + bool freeze_normalization = (sipo->flag & SIPO_NORMALIZE_FREEZE) != 0; + return use_normalization + ? (ANIM_UNITCONV_NORMALIZE | (freeze_normalization ? ANIM_UNITCONV_NORMALIZE_FREEZE : 0)) + : 0; + } + + return 0; +} + +static float normalzation_factor_get(FCurve *fcu, short flag) +{ + float factor; + + if (flag & ANIM_UNITCONV_RESTORE) { + return 1.0f / fcu->prev_norm_factor; + } + + if (flag & ANIM_UNITCONV_NORMALIZE_FREEZE) { + return fcu->prev_norm_factor; + } + + if (G.moving & G_TRANSFORM_FCURVES) { + return fcu->prev_norm_factor; + } + + fcu->prev_norm_factor = 1.0f; + if (fcu->bezt) { + BezTriple *bezt; + int i; + float max_coord = -FLT_MAX; + + if (fcu->totvert < 1) { + return 1.0f; + } + + for (i = 0, bezt = fcu->bezt; i < fcu->totvert; i++, bezt++) { + max_coord = max_ff(max_coord, fabsf(bezt->vec[0][1])); + max_coord = max_ff(max_coord, fabsf(bezt->vec[1][1])); + max_coord = max_ff(max_coord, fabsf(bezt->vec[2][1])); + } + + if (max_coord > FLT_EPSILON) { + factor = 1.0f / max_coord; + } + } + fcu->prev_norm_factor = factor; + return factor; +} + /* Get unit conversion factor for given ID + F-Curve */ -float ANIM_unit_mapping_get_factor(Scene *scene, ID *id, FCurve *fcu, short restore) +float ANIM_unit_mapping_get_factor(Scene *scene, ID *id, FCurve *fcu, short flag) { + if (flag & ANIM_UNITCONV_NORMALIZE) { + return normalzation_factor_get(fcu, flag); + } + /* sanity checks */ if (id && fcu && fcu->rna_path) { PointerRNA ptr, id_ptr; @@ -374,7 +434,7 @@ float ANIM_unit_mapping_get_factor(Scene *scene, ID *id, FCurve *fcu, short rest 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.system_rotation == USER_UNIT_ROT_RADIANS) == 0) { - if (restore) + if (flag & ANIM_UNITCONV_RESTORE) return DEG2RADF(1.0f); /* degrees to radians */ else return RAD2DEGF(1.0f); /* radians to degrees */ |