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 12:25:32 +0300
committerJoshua Leung <aligorith@gmail.com>2010-01-26 12:25:32 +0300
commit0e1eca2d08035a24067406167aa5cdea0b16d274 (patch)
tree181af1578c718a52cc3713533eaa2640a8360707
parent3150e4ee12ed6fbe6e9f60d013a6d43c85cca8ce (diff)
Finishing off the Transform code changes for Degrees/Radians:
Added flags for the mapping function offering more control over what values were affected and when. In the WIP code, the values for unselected verts were getting the restoration conversion being repeatedly applied, resulting in the values tending to zero.
-rw-r--r--source/blender/editors/animation/anim_draw.c33
-rw-r--r--source/blender/editors/include/ED_anim_api.h14
-rw-r--r--source/blender/editors/space_graph/graph_draw.c12
-rw-r--r--source/blender/editors/space_graph/graph_edit.c12
-rw-r--r--source/blender/editors/space_graph/graph_select.c8
-rw-r--r--source/blender/editors/transform/transform_conversions.c2
-rw-r--r--source/blender/editors/transform/transform_generics.c3
7 files changed, 55 insertions, 29 deletions
diff --git a/source/blender/editors/animation/anim_draw.c b/source/blender/editors/animation/anim_draw.c
index b99aefebfe7..93beb819a2b 100644
--- a/source/blender/editors/animation/anim_draw.c
+++ b/source/blender/editors/animation/anim_draw.c
@@ -42,6 +42,7 @@
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
+#include "BLI_math.h"
#include "BKE_animsys.h"
#include "BKE_action.h"
@@ -360,44 +361,56 @@ float ANIM_unit_mapping_get_factor (Scene *scene, ID *id, FCurve *fcu, short res
/* 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;
+ /* mapping factor is stored in f1, flags are stored in i1 */
+ short only_keys= (bed->i1 & ANIM_UNITCONV_ONLYKEYS);
+ short sel_vs= (bed->i1 & ANIM_UNITCONV_SELVERTS);
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;
+ if ((sel_vs==0) || (bezt->f1 & SELECT))
+ bezt->vec[0][1] *= fac;
+ if ((sel_vs==0) || (bezt->f3 & SELECT))
+ bezt->vec[2][1] *= fac;
}
- bezt->vec[1][1] *= fac;
+ if ((sel_vs == 0) || (bezt->f2 & SELECT))
+ 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)
+void ANIM_unit_mapping_apply_fcurve (Scene *scene, ID *id, FCurve *fcu, short flag)
{
BeztEditData bed;
+ BeztEditFunc sel_cb;
float fac;
/* calculate mapping factor, and abort if nothing to change */
- fac= ANIM_unit_mapping_get_factor(scene, id, fcu, restore);
+ fac= ANIM_unit_mapping_get_factor(scene, id, fcu, (flag & ANIM_UNITCONV_RESTORE));
if (fac == 1.0f)
return;
/* init edit data
* - mapping factor is stored in f1
- * - only_keys is stored in 'i1'
+ * - flags are stored in 'i1'
*/
memset(&bed, 0, sizeof(BeztEditData));
bed.f1= (float)fac;
- bed.i1= (int)only_keys;
+ bed.i1= (int)flag;
+
+ /* only selected? */
+ if (flag & ANIM_UNITCONV_ONLYSEL)
+ sel_cb= ANIM_editkeyframes_ok(BEZT_OK_SELECTED);
+ else
+ sel_cb= NULL;
/* apply to F-Curve */
- ANIM_fcurve_keys_bezier_loop(&bed, fcu, NULL, bezt_unit_mapping_apply, NULL);
+ ANIM_fcurve_keys_bezier_loop(&bed, fcu, sel_cb, bezt_unit_mapping_apply, NULL);
// FIXME: loop here for samples should be generalised
+ // TODO: only sel?
if (fcu->fpt) {
FPoint *fpt;
int i;
diff --git a/source/blender/editors/include/ED_anim_api.h b/source/blender/editors/include/ED_anim_api.h
index 5b5733a3d43..1b1b31ff704 100644
--- a/source/blender/editors/include/ED_anim_api.h
+++ b/source/blender/editors/include/ED_anim_api.h
@@ -467,11 +467,23 @@ void ED_nla_postop_refresh(bAnimContext *ac);
/* ------------- Unit Conversion Mappings ------------- */
/* anim_draw.c */
+/* flags for conversion mapping */
+typedef enum eAnimUnitConv_Flags {
+ /* restore to original internal values */
+ ANIM_UNITCONV_RESTORE = (1<<0),
+ /* ignore handles (i.e. only touch main keyframes) */
+ ANIM_UNITCONV_ONLYKEYS = (1<<1),
+ /* only touch selected BezTriples */
+ ANIM_UNITCONV_ONLYSEL = (1<<2),
+ /* only touch selected vertices */
+ ANIM_UNITCONV_SELVERTS = (1<<3),
+} eAnimUnitConv_Flags;
+
/* Get unit conversion factor for given ID + F-Curve */
float ANIM_unit_mapping_get_factor(struct Scene *scene, struct ID *id, struct FCurve *fcu, short restore);
/* Apply/Unapply units conversions to keyframes */
-void ANIM_unit_mapping_apply_fcurve(struct Scene *scene, struct ID *id, struct FCurve *fcu, short restore, short only_keys);
+void ANIM_unit_mapping_apply_fcurve(struct Scene *scene, struct ID *id, struct FCurve *fcu, short flag);
/* ------------- Utility macros ----------------------- */
diff --git a/source/blender/editors/space_graph/graph_draw.c b/source/blender/editors/space_graph/graph_draw.c
index 553e52ae27e..b52fc1b9e6a 100644
--- a/source/blender/editors/space_graph/graph_draw.c
+++ b/source/blender/editors/space_graph/graph_draw.c
@@ -561,7 +561,7 @@ static void draw_fcurve_curve_samples (bAnimContext *ac, ID *id, FCurve *fcu, Vi
glBegin(GL_LINE_STRIP);
/* apply unit mapping */
- ANIM_unit_mapping_apply_fcurve(ac->scene, id, fcu, 0, 0);
+ ANIM_unit_mapping_apply_fcurve(ac->scene, id, fcu, 0);
/* extrapolate to left? - left-side of view comes before first keyframe? */
if (prevfpt->vec[0] > v2d->cur.xmin) {
@@ -622,7 +622,7 @@ static void draw_fcurve_curve_samples (bAnimContext *ac, ID *id, FCurve *fcu, Vi
}
/* unapply unit mapping */
- ANIM_unit_mapping_apply_fcurve(ac->scene, id, fcu, 1, 0);
+ ANIM_unit_mapping_apply_fcurve(ac->scene, id, fcu, ANIM_UNITCONV_RESTORE);
glEnd();
}
@@ -641,7 +641,7 @@ static void draw_fcurve_curve_bezts (bAnimContext *ac, ID *id, FCurve *fcu, View
glBegin(GL_LINE_STRIP);
/* apply unit mapping */
- ANIM_unit_mapping_apply_fcurve(ac->scene, id, fcu, 0, 0);
+ ANIM_unit_mapping_apply_fcurve(ac->scene, id, fcu, 0);
/* extrapolate to left? */
if (prevbezt->vec[1][0] > v2d->cur.xmin) {
@@ -775,7 +775,7 @@ static void draw_fcurve_curve_bezts (bAnimContext *ac, ID *id, FCurve *fcu, View
}
/* unapply unit mapping */
- ANIM_unit_mapping_apply_fcurve(ac->scene, id, fcu, 1, 0);
+ ANIM_unit_mapping_apply_fcurve(ac->scene, id, fcu, ANIM_UNITCONV_RESTORE);
glEnd();
}
@@ -912,7 +912,7 @@ void graph_draw_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGri
}
else if ( ((fcu->bezt) || (fcu->fpt)) && (fcu->totvert) ) {
/* apply unit mapping */
- ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, fcu, 0, 0);
+ ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, fcu, 0);
if (fcu->bezt) {
/* only draw handles/vertices on keyframes */
@@ -928,7 +928,7 @@ void graph_draw_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGri
}
/* unapply unit mapping */
- ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, fcu, 1, 0);
+ ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, fcu, ANIM_UNITCONV_RESTORE);
}
}
diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c
index 9842d2ae9ae..00951db61d3 100644
--- a/source/blender/editors/space_graph/graph_edit.c
+++ b/source/blender/editors/space_graph/graph_edit.c
@@ -1574,7 +1574,7 @@ static int graphkeys_framejump_exec(bContext *C, wmOperator *op)
AnimData *adt= ANIM_nla_mapping_get(&ac, ale);
/* apply unit corrections */
- ANIM_unit_mapping_apply_fcurve(ac.scene, ale->id, ale->key_data, 0, 1);
+ ANIM_unit_mapping_apply_fcurve(ac.scene, ale->id, ale->key_data, ANIM_UNITCONV_ONLYKEYS);
if (adt) {
ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1);
@@ -1585,7 +1585,7 @@ static int graphkeys_framejump_exec(bContext *C, wmOperator *op)
ANIM_fcurve_keys_bezier_loop(&bed, ale->key_data, NULL, bezt_calc_average, NULL);
/* unapply unit corrections */
- ANIM_unit_mapping_apply_fcurve(ac.scene, ale->id, ale->key_data, 1, 1);
+ ANIM_unit_mapping_apply_fcurve(ac.scene, ale->id, ale->key_data, ANIM_UNITCONV_RESTORE|ANIM_UNITCONV_ONLYKEYS);
}
BLI_freelistN(&anim_data);
@@ -1667,7 +1667,7 @@ static void snap_graph_keys(bAnimContext *ac, short mode)
AnimData *adt= ANIM_nla_mapping_get(ac, ale);
/* apply unit corrections */
- ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, ale->key_data, 0, 0);
+ ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, ale->key_data, 0);
if (adt) {
ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1);
@@ -1678,7 +1678,7 @@ static void snap_graph_keys(bAnimContext *ac, short mode)
ANIM_fcurve_keys_bezier_loop(&bed, ale->key_data, NULL, edit_cb, calchandles_fcurve);
/* apply unit corrections */
- ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, ale->key_data, 1, 0);
+ ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, ale->key_data, ANIM_UNITCONV_RESTORE);
}
BLI_freelistN(&anim_data);
@@ -1791,7 +1791,7 @@ static void mirror_graph_keys(bAnimContext *ac, short mode)
AnimData *adt= ANIM_nla_mapping_get(ac, ale);
/* apply unit corrections */
- ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, ale->key_data, 0, 1);
+ ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, ale->key_data, ANIM_UNITCONV_ONLYKEYS);
if (adt) {
ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1);
@@ -1802,7 +1802,7 @@ static void mirror_graph_keys(bAnimContext *ac, short mode)
ANIM_fcurve_keys_bezier_loop(&bed, ale->key_data, NULL, edit_cb, calchandles_fcurve);
/* unapply unit corrections */
- ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, ale->key_data, 1, 1);
+ ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, ale->key_data, ANIM_UNITCONV_ONLYKEYS|ANIM_UNITCONV_RESTORE);
}
BLI_freelistN(&anim_data);
diff --git a/source/blender/editors/space_graph/graph_select.c b/source/blender/editors/space_graph/graph_select.c
index e9b6cb226d0..b90d5a48d9a 100644
--- a/source/blender/editors/space_graph/graph_select.c
+++ b/source/blender/editors/space_graph/graph_select.c
@@ -248,7 +248,7 @@ static void borderselect_graphkeys (bAnimContext *ac, rcti rect, short mode, sho
FCurve *fcu= (FCurve *)ale->key_data;
/* apply unit corrections */
- ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, ale->key_data, 0, 1);
+ ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, ale->key_data, ANIM_UNITCONV_ONLYKEYS);
/* apply NLA mapping to all the keyframes, since it's easier than trying to
* guess when a callback might use something different
@@ -287,7 +287,7 @@ static void borderselect_graphkeys (bAnimContext *ac, rcti rect, short mode, sho
ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1);
/* unapply unit corrections */
- ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, ale->key_data, 1, 1);
+ ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, ale->key_data, ANIM_UNITCONV_RESTORE|ANIM_UNITCONV_ONLYKEYS);
}
/* cleanup */
@@ -609,7 +609,7 @@ static short findnearest_fcurve_vert (bAnimContext *ac, int mval[2], FCurve **fc
AnimData *adt= ANIM_nla_mapping_get(ac, ale);
/* apply unit corrections */
- ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, ale->key_data, 0, 0);
+ ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, ale->key_data, 0);
/* try to progressively get closer to the right point... */
if (fcu->bezt) {
@@ -679,7 +679,7 @@ static short findnearest_fcurve_vert (bAnimContext *ac, int mval[2], FCurve **fc
}
/* unapply unit corrections */
- ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, ale->key_data, 1, 0);
+ ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, ale->key_data, ANIM_UNITCONV_RESTORE);
}
/* free channels */
diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c
index a92af31211d..52e5a634011 100644
--- a/source/blender/editors/transform/transform_conversions.c
+++ b/source/blender/editors/transform/transform_conversions.c
@@ -3495,7 +3495,7 @@ static void createTransGraphEditData(bContext *C, TransInfo *t)
if (fcu->bezt == NULL)
continue;
- ANIM_unit_mapping_apply_fcurve(ac.scene, ale->id, ale->key_data, 0, 0);
+ ANIM_unit_mapping_apply_fcurve(ac.scene, ale->id, ale->key_data, ANIM_UNITCONV_ONLYSEL|ANIM_UNITCONV_SELVERTS);
/* only include BezTriples whose 'keyframe' occurs on the same side of the current frame as mouse (if applicable) */
for (i=0, bezt= fcu->bezt; i < fcu->totvert; i++, bezt++) {
diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c
index 1e3bddc769e..892ee467a69 100644
--- a/source/blender/editors/transform/transform_generics.c
+++ b/source/blender/editors/transform/transform_generics.c
@@ -408,7 +408,8 @@ void recalcData(TransInfo *t)
for (ale= anim_data.first; ale; ale= ale->next) {
FCurve *fcu= (FCurve *)ale->key_data;
- ANIM_unit_mapping_apply_fcurve(ac.scene, ale->id, ale->key_data, 1, 0);
+ // fixme: only do this for selected verts...
+ ANIM_unit_mapping_apply_fcurve(ac.scene, ale->id, ale->key_data, ANIM_UNITCONV_ONLYSEL|ANIM_UNITCONV_SELVERTS|ANIM_UNITCONV_RESTORE);
/* watch it: if the time is wrong: do not correct handles yet */