diff options
Diffstat (limited to 'source/blender/editors/space_graph')
-rw-r--r-- | source/blender/editors/space_graph/graph_draw.c | 70 | ||||
-rw-r--r-- | source/blender/editors/space_graph/graph_edit.c | 45 | ||||
-rw-r--r-- | source/blender/editors/space_graph/graph_select.c | 12 |
3 files changed, 100 insertions, 27 deletions
diff --git a/source/blender/editors/space_graph/graph_draw.c b/source/blender/editors/space_graph/graph_draw.c index 9681d20c13b..553e52ae27e 100644 --- a/source/blender/editors/space_graph/graph_draw.c +++ b/source/blender/editors/space_graph/graph_draw.c @@ -163,7 +163,7 @@ static void draw_fcurve_modifier_controls_envelope (FCurve *fcu, FModifier *fcm, /* Points ---------------- */ /* helper func - draw keyframe vertices only for an F-Curve */ -static void draw_fcurve_vertices_keyframes (FCurve *fcu, View2D *v2d, short edit, short sel) +static void draw_fcurve_vertices_keyframes (bAnimContext *ac, FCurve *fcu, View2D *v2d, short edit, short sel) { BezTriple *bezt= fcu->bezt; const float fac= 0.05f * (v2d->cur.xmax - v2d->cur.xmin); @@ -235,7 +235,7 @@ static void draw_fcurve_handle_control (float x, float y, float xscale, float ys } /* helper func - draw handle vertices only for an F-Curve (if it is not protected) */ -static void draw_fcurve_vertices_handles (SpaceIpo *sipo, FCurve *fcu, View2D *v2d, short sel) +static void draw_fcurve_vertices_handles (bAnimContext *ac, SpaceIpo *sipo, FCurve *fcu, View2D *v2d, short sel) { BezTriple *bezt= fcu->bezt; BezTriple *prevbezt = NULL; @@ -300,7 +300,7 @@ static void set_fcurve_vertex_color (SpaceIpo *sipo, FCurve *fcu, short sel) } -void draw_fcurve_vertices (SpaceIpo *sipo, ARegion *ar, FCurve *fcu) +void draw_fcurve_vertices (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, FCurve *fcu) { View2D *v2d= &ar->v2d; @@ -318,18 +318,18 @@ void draw_fcurve_vertices (SpaceIpo *sipo, ARegion *ar, FCurve *fcu) (sipo->flag & SIPO_NOHANDLES)==0 && (fcu->totvert > 1)) { set_fcurve_vertex_color(sipo, fcu, 0); - draw_fcurve_vertices_handles(sipo, fcu, v2d, 0); + draw_fcurve_vertices_handles(ac, sipo, fcu, v2d, 0); set_fcurve_vertex_color(sipo, fcu, 1); - draw_fcurve_vertices_handles(sipo, fcu, v2d, 1); + draw_fcurve_vertices_handles(ac, sipo, fcu, v2d, 1); } /* draw keyframes over the handles */ set_fcurve_vertex_color(sipo, fcu, 0); - draw_fcurve_vertices_keyframes(fcu, v2d, !(fcu->flag & FCURVE_PROTECTED), 0); + draw_fcurve_vertices_keyframes(ac, fcu, v2d, !(fcu->flag & FCURVE_PROTECTED), 0); set_fcurve_vertex_color(sipo, fcu, 1); - draw_fcurve_vertices_keyframes(fcu, v2d, !(fcu->flag & FCURVE_PROTECTED), 1); + draw_fcurve_vertices_keyframes(ac, fcu, v2d, !(fcu->flag & FCURVE_PROTECTED), 1); glPointSize(1.0f); } @@ -337,7 +337,7 @@ void draw_fcurve_vertices (SpaceIpo *sipo, ARegion *ar, FCurve *fcu) /* Handles ---------------- */ /* draw lines for F-Curve handles only (this is only done in EditMode) */ -static void draw_fcurve_handles (SpaceIpo *sipo, ARegion *ar, FCurve *fcu) +static void draw_fcurve_handles (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, FCurve *fcu) { extern unsigned int nurbcol[]; int sel, b; @@ -458,7 +458,7 @@ static void draw_fcurve_sample_control (float x, float y, float xscale, float ys } /* helper func - draw keyframe vertices only for an F-Curve */ -static void draw_fcurve_samples (SpaceIpo *sipo, ARegion *ar, FCurve *fcu) +static void draw_fcurve_samples (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, FCurve *fcu) { FPoint *first, *last; float hsize, xscale, yscale; @@ -497,16 +497,19 @@ static void draw_fcurve_samples (SpaceIpo *sipo, ARegion *ar, FCurve *fcu) #define MINGRIDSTEP 35 /* helper func - just draw the F-Curve by sampling the visible region (for drawing curves with modifiers) */ -static void draw_fcurve_curve (FCurve *fcu, SpaceIpo *sipo, View2D *v2d, View2DGrid *grid) +static void draw_fcurve_curve (bAnimContext *ac, ID *id, FCurve *fcu, SpaceIpo *sipo, View2D *v2d, View2DGrid *grid) { ChannelDriver *driver; float samplefreq, ctime; float stime, etime; + float unitFac; /* disable any drivers temporarily */ driver= fcu->driver; fcu->driver= NULL; + /* compute unit correction factor */ + unitFac= ANIM_unit_mapping_get_factor(ac->scene, id, fcu, 0); /* Note about sampling frequency: * Ideally, this is chosen such that we have 1-2 pixels = 1 segment @@ -532,11 +535,14 @@ static void draw_fcurve_curve (FCurve *fcu, SpaceIpo *sipo, View2D *v2d, View2DG etime= v2d->cur.xmax; - /* at each sampling interval, add a new vertex */ + /* at each sampling interval, add a new vertex + * - apply the unit correction factor to the calculated values so that + * the displayed values appear correctly in the viewport + */ glBegin(GL_LINE_STRIP); for (ctime= stime; ctime <= etime; ctime += samplefreq) - glVertex2f( ctime, evaluate_fcurve(fcu, ctime) ); + glVertex2f( ctime, evaluate_fcurve(fcu, ctime)*unitFac ); glEnd(); @@ -545,7 +551,7 @@ static void draw_fcurve_curve (FCurve *fcu, SpaceIpo *sipo, View2D *v2d, View2DG } /* helper func - draw a samples-based F-Curve */ -static void draw_fcurve_curve_samples (FCurve *fcu, View2D *v2d) +static void draw_fcurve_curve_samples (bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d) { FPoint *prevfpt= fcu->fpt; FPoint *fpt= prevfpt + 1; @@ -554,6 +560,9 @@ static void draw_fcurve_curve_samples (FCurve *fcu, View2D *v2d) glBegin(GL_LINE_STRIP); + /* apply unit mapping */ + ANIM_unit_mapping_apply_fcurve(ac->scene, id, fcu, 0, 0); + /* extrapolate to left? - left-side of view comes before first keyframe? */ if (prevfpt->vec[0] > v2d->cur.xmin) { v[0]= v2d->cur.xmin; @@ -612,11 +621,14 @@ static void draw_fcurve_curve_samples (FCurve *fcu, View2D *v2d) glVertex2fv(v); } + /* unapply unit mapping */ + ANIM_unit_mapping_apply_fcurve(ac->scene, id, fcu, 1, 0); + glEnd(); } /* helper func - draw one repeat of an F-Curve */ -static void draw_fcurve_curve_bezts (FCurve *fcu, View2D *v2d, View2DGrid *grid) +static void draw_fcurve_curve_bezts (bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d, View2DGrid *grid) { BezTriple *prevbezt= fcu->bezt; BezTriple *bezt= prevbezt+1; @@ -628,6 +640,9 @@ static void draw_fcurve_curve_bezts (FCurve *fcu, View2D *v2d, View2DGrid *grid) glBegin(GL_LINE_STRIP); + /* apply unit mapping */ + ANIM_unit_mapping_apply_fcurve(ac->scene, id, fcu, 0, 0); + /* extrapolate to left? */ if (prevbezt->vec[1][0] > v2d->cur.xmin) { /* left-side of view comes before first keyframe, so need to extend as not cyclic */ @@ -759,12 +774,17 @@ static void draw_fcurve_curve_bezts (FCurve *fcu, View2D *v2d, View2DGrid *grid) glVertex2fv(v1); } + /* unapply unit mapping */ + ANIM_unit_mapping_apply_fcurve(ac->scene, id, fcu, 1, 0); + glEnd(); } /* Public Curve-Drawing API ---------------- */ -/* Draw the 'ghost' F-Curves (i.e. snapshots of the curve) */ +/* Draw the 'ghost' F-Curves (i.e. snapshots of the curve) + * NOTE: unit mapping has already been applied to the values, so do not try and apply again + */ void graph_draw_ghost_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGrid *grid) { FCurve *fcu; @@ -786,7 +806,7 @@ void graph_draw_ghost_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, Vie glColor4f(fcu->color[0], fcu->color[1], fcu->color[2], 0.5f); /* simply draw the stored samples */ - draw_fcurve_curve_samples(fcu, &ar->v2d); + draw_fcurve_curve_samples(ac, NULL, fcu, &ar->v2d); } /* restore settings */ @@ -859,14 +879,14 @@ void graph_draw_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGri /* draw a curve affected by modifiers or only allowed to have integer values * by sampling it at various small-intervals over the visible region */ - draw_fcurve_curve(fcu, sipo, &ar->v2d, grid); + draw_fcurve_curve(ac, ale->id, fcu, sipo, &ar->v2d, grid); } else if ( ((fcu->bezt) || (fcu->fpt)) && (fcu->totvert) ) { /* just draw curve based on defined data (i.e. no modifiers) */ if (fcu->bezt) - draw_fcurve_curve_bezts(fcu, &ar->v2d, grid); + draw_fcurve_curve_bezts(ac, ale->id, fcu, &ar->v2d, grid); else if (fcu->fpt) - draw_fcurve_curve_samples(fcu, &ar->v2d); + draw_fcurve_curve_samples(ac, ale->id, fcu, &ar->v2d); } /* restore settings */ @@ -891,18 +911,24 @@ 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); + if (fcu->bezt) { /* only draw handles/vertices on keyframes */ glEnable(GL_BLEND); - draw_fcurve_handles(sipo, ar, fcu); + draw_fcurve_handles(ac, sipo, ar, fcu); glDisable(GL_BLEND); - draw_fcurve_vertices(sipo, ar, fcu); + draw_fcurve_vertices(ac, sipo, ar, fcu); } else { /* samples: only draw two indicators at either end as indicators */ - draw_fcurve_samples(sipo, ar, fcu); + draw_fcurve_samples(ac, sipo, ar, fcu); } + + /* unapply unit mapping */ + ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, fcu, 1, 0); } } diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c index b3532963c3b..9842d2ae9ae 100644 --- a/source/blender/editors/space_graph/graph_edit.c +++ b/source/blender/editors/space_graph/graph_edit.c @@ -121,15 +121,22 @@ void get_graph_keyframe_extents (bAnimContext *ac, float *xmin, float *xmax, flo AnimData *adt= ANIM_nla_mapping_get(ac, ale); FCurve *fcu= (FCurve *)ale->key_data; float txmin, txmax, tymin, tymax; + float unitFac; - /* get range and apply necessary scaling before */ + /* get range */ calc_fcurve_bounds(fcu, &txmin, &txmax, &tymin, &tymax); + /* apply NLA scaling */ if (adt) { txmin= BKE_nla_tweakedit_remap(adt, txmin, NLATIME_CONVERT_MAP); txmax= BKE_nla_tweakedit_remap(adt, txmax, NLATIME_CONVERT_MAP); } + /* apply unit corrections */ + unitFac= ANIM_unit_mapping_get_factor(ac->scene, ale->id, fcu, 0); + tymin *= unitFac; + tymax *= unitFac; + /* try to set cur using these values, if they're more extreme than previously set values */ if ((xmin) && (txmin < *xmin)) *xmin= txmin; if ((xmax) && (txmax > *xmax)) *xmax= txmax; @@ -280,11 +287,15 @@ static void create_ghost_curves (bAnimContext *ac, int start, int end) AnimData *adt= ANIM_nla_mapping_get(ac, ale); ChannelDriver *driver= fcu->driver; FPoint *fpt; + float unitFac; int cfra; /* disable driver so that it don't muck up the sampling process */ fcu->driver= NULL; + /* calculate unit-mapping factor */ + unitFac= ANIM_unit_mapping_get_factor(ac->scene, ale->id, fcu, 0); + /* create samples, but store them in a new curve * - we cannot use fcurve_store_samples() as that will only overwrite the original curve */ @@ -508,6 +519,7 @@ static int graphkeys_click_insert_exec (bContext *C, wmOperator *op) bAnimContext ac; bAnimListElem *ale; AnimData *adt; + FCurve *fcu; float frame, val; /* get animation context */ @@ -520,7 +532,8 @@ static int graphkeys_click_insert_exec (bContext *C, wmOperator *op) if (ale) MEM_freeN(ale); return OPERATOR_CANCELLED; } - + fcu = ale->data; + /* get frame and value from props */ frame= RNA_float_get(op->ptr, "frame"); val= RNA_float_get(op->ptr, "value"); @@ -529,8 +542,11 @@ static int graphkeys_click_insert_exec (bContext *C, wmOperator *op) adt= ANIM_nla_mapping_get(&ac, ale); frame= BKE_nla_tweakedit_remap(adt, frame, NLATIME_CONVERT_UNMAP); + /* apply inverse unit-mapping to value to get correct value for F-Curves */ + val *= ANIM_unit_mapping_get_factor(ac.scene, ale->id, fcu, 1); + /* insert keyframe on the specified frame + value */ - insert_vert_fcurve((FCurve *)ale->data, frame, val, 0); + insert_vert_fcurve(fcu, frame, val, 0); /* free temp data */ MEM_freeN(ale); @@ -1002,7 +1018,7 @@ void GRAPH_OT_bake (wmOperatorType *ot) * which provides the necessary info for baking the sound */ typedef struct tSoundBakeInfo { - float* samples; + float *samples; int length; int cfra; } tSoundBakeInfo; @@ -1075,7 +1091,7 @@ static int graphkeys_sound_bake_exec(bContext *C, wmOperator *op) /* loop through all selected F-Curves, replacing its data with the sound samples */ for (ale= anim_data.first; ale; ale= ale->next) { FCurve *fcu= (FCurve *)ale->key_data; - + /* sample the sound */ fcurve_store_samples(fcu, &sbi, start, end, fcurve_samplingcb_sound); } @@ -1557,6 +1573,9 @@ static int graphkeys_framejump_exec(bContext *C, wmOperator *op) for (ale= anim_data.first; ale; ale= ale->next) { 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); + if (adt) { ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1); ANIM_fcurve_keys_bezier_loop(&bed, ale->key_data, NULL, bezt_calc_average, NULL); @@ -1565,6 +1584,8 @@ static int graphkeys_framejump_exec(bContext *C, wmOperator *op) else 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); } BLI_freelistN(&anim_data); @@ -1645,6 +1666,9 @@ static void snap_graph_keys(bAnimContext *ac, short mode) for (ale= anim_data.first; ale; ale= ale->next) { 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); + if (adt) { ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1); ANIM_fcurve_keys_bezier_loop(&bed, ale->key_data, NULL, edit_cb, calchandles_fcurve); @@ -1652,7 +1676,11 @@ static void snap_graph_keys(bAnimContext *ac, short mode) } else 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); } + BLI_freelistN(&anim_data); } @@ -1762,6 +1790,9 @@ static void mirror_graph_keys(bAnimContext *ac, short mode) for (ale= anim_data.first; ale; ale= ale->next) { 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); + if (adt) { ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1); ANIM_fcurve_keys_bezier_loop(&bed, ale->key_data, NULL, edit_cb, calchandles_fcurve); @@ -1769,7 +1800,11 @@ static void mirror_graph_keys(bAnimContext *ac, short mode) } else 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); } + 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 d6b7e809617..8ab39bc41ba 100644 --- a/source/blender/editors/space_graph/graph_select.c +++ b/source/blender/editors/space_graph/graph_select.c @@ -247,6 +247,9 @@ static void borderselect_graphkeys (bAnimContext *ac, rcti rect, short mode, sho AnimData *adt= ANIM_nla_mapping_get(ac, ale); FCurve *fcu= (FCurve *)ale->key_data; + /* apply unit corrections */ + ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, ale->key_data, 0, 1); + /* apply NLA mapping to all the keyframes, since it's easier than trying to * guess when a callback might use something different */ @@ -282,6 +285,9 @@ static void borderselect_graphkeys (bAnimContext *ac, rcti rect, short mode, sho /* un-apply NLA mapping from all the keyframes */ if (adt) 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, 0, 1); } /* cleanup */ @@ -602,6 +608,9 @@ static short findnearest_fcurve_vert (bAnimContext *ac, int mval[2], FCurve **fc FCurve *fcu= (FCurve *)ale->key_data; 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); + /* try to progressively get closer to the right point... */ if (fcu->bezt) { BezTriple *bezt1=fcu->bezt, *prevbezt=NULL; @@ -668,6 +677,9 @@ static short findnearest_fcurve_vert (bAnimContext *ac, int mval[2], FCurve **fc if (adt) 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, 0); } /* free channels */ |