option to transform markers in the dope sheet, needed for re-timing animation. currently supports translate and extend.

TODO:
- select markers in dope sheet.
- transform time scale.
This commit is contained in:
Campbell Barton 2010-03-08 09:06:58 +00:00
parent 581efb4346
commit 3b105657d5
6 changed files with 83 additions and 28 deletions

@ -77,6 +77,7 @@ class DOPESHEET_MT_view(bpy.types.Menu):
layout.prop(st, "show_cframe_indicator")
layout.prop(st, "show_sliders")
layout.prop(st, "automerge_keyframes")
layout.prop(st, "use_marker_sync")
if st.show_seconds:
layout.operator("anim.time_toggle", text="Show Frames")

@ -70,6 +70,8 @@ struct Object *scene_find_camera_switch(struct Scene *scene); // DURIAN_CAMERA_S
char *scene_find_marker_name(struct Scene *scene, int frame);
char *scene_find_last_marker_name(struct Scene *scene, int frame);
int scene_marker_tfm_translate(struct Scene *scene, int delta, int flag);
int scene_marker_tfm_extend(struct Scene *scene, int delta, int flag, int frame, char side);
struct Base *scene_add_base(struct Scene *sce, struct Object *ob);
void scene_deselect_all(struct Scene *sce);

@ -783,6 +783,39 @@ char *scene_find_last_marker_name(Scene *scene, int frame)
return best_marker ? best_marker->name : NULL;
}
/* markers need transforming from different parts of the code so have
* a generic function to do this */
int scene_marker_tfm_translate(Scene *scene, int delta, int flag)
{
TimeMarker *marker;
int tot= 0;
for (marker= scene->markers.first; marker; marker= marker->next) {
if ((marker->flag & flag) == flag) {
marker->frame += delta;
tot++;
}
}
return tot;
}
int scene_marker_tfm_extend(Scene *scene, int delta, int flag, int frame, char side)
{
TimeMarker *marker;
int tot= 0;
for (marker= scene->markers.first; marker; marker= marker->next) {
if ((marker->flag & flag) == flag) {
if((side=='L' && marker->frame < frame) || (side=='R' && marker->frame > frame)) {
marker->frame += delta;
tot++;
}
}
}
return tot;
}
Base *scene_add_base(Scene *sce, Object *ob)
{

@ -100,6 +100,7 @@
#include "BKE_bmesh.h"
#include "BKE_context.h"
#include "BKE_report.h"
#include "BKE_scene.h"
//#include "BIF_editview.h"
//#include "BIF_editlattice.h"
@ -288,7 +289,7 @@ static void set_prop_dist(TransInfo *t, short with_dist)
static void createTransTexspace(bContext *C, TransInfo *t)
{
Scene *scene = CTX_data_scene(C);
Scene *scene = t->scene;
TransData *td;
Object *ob;
ID *id;
@ -2460,7 +2461,7 @@ static void createTransUVs(bContext *C, TransInfo *t)
{
SpaceImage *sima = CTX_wm_space_image(C);
Image *ima = CTX_data_edit_image(C);
Scene *scene = CTX_data_scene(C);
Scene *scene = t->scene;
TransData *td = NULL;
TransData2D *td2d = NULL;
MTFace *tf;
@ -2617,7 +2618,7 @@ static short FrameOnMouseSide(char side, float frame, float cframe)
static void createTransNlaData(bContext *C, TransInfo *t)
{
Scene *scene= CTX_data_scene(C);
Scene *scene= t->scene;
TransData *td = NULL;
TransDataNla *tdn = NULL;
@ -2627,7 +2628,6 @@ static void createTransNlaData(bContext *C, TransInfo *t)
int filter;
int count=0;
char side;
/* determine what type of data we are operating on */
if (ANIM_animdata_get_context(C, &ac) == 0)
@ -2643,11 +2643,11 @@ static void createTransNlaData(bContext *C, TransInfo *t)
float xmouse, ymouse;
UI_view2d_region_to_view(&ac.ar->v2d, t->imval[0], t->imval[1], &xmouse, &ymouse);
side = (xmouse > CFRA) ? 'R' : 'L'; // XXX use t->frame_side
t->frame_side= (xmouse > CFRA) ? 'R' : 'L'; // XXX use t->frame_side
}
else {
/* normal transform - both sides of current frame are considered */
side = 'B';
t->frame_side = 'B';
}
/* loop 1: count how many strips are selected (consider each strip as 2 points) */
@ -2664,8 +2664,8 @@ static void createTransNlaData(bContext *C, TransInfo *t)
/* transition strips can't get directly transformed */
if (strip->type != NLASTRIP_TYPE_TRANSITION) {
if (strip->flag & NLASTRIP_FLAG_SELECT) {
if (FrameOnMouseSide(side, strip->start, (float)CFRA)) count++;
if (FrameOnMouseSide(side, strip->end, (float)CFRA)) count++;
if (FrameOnMouseSide(t->frame_side, strip->start, (float)CFRA)) count++;
if (FrameOnMouseSide(t->frame_side, strip->end, (float)CFRA)) count++;
}
}
}
@ -2728,7 +2728,7 @@ static void createTransNlaData(bContext *C, TransInfo *t)
center[2]= 0.0f;
/* set td's based on which handles are applicable */
if (FrameOnMouseSide(side, strip->start, (float)CFRA))
if (FrameOnMouseSide(t->frame_side, strip->start, (float)CFRA))
{
/* just set tdn to assume that it only has one handle for now */
tdn->handle= -1;
@ -2759,7 +2759,7 @@ static void createTransNlaData(bContext *C, TransInfo *t)
td->extra= tdn;
td++;
}
if (FrameOnMouseSide(side, strip->end, (float)CFRA))
if (FrameOnMouseSide(t->frame_side, strip->end, (float)CFRA))
{
/* if tdn is already holding the start handle, then we're doing both, otherwise, only end */
tdn->handle= (tdn->handle) ? 2 : 1;
@ -3156,7 +3156,7 @@ static int GPLayerToTransData (TransData *td, tGPFtransdata *tfd, bGPDlayer *gpl
static void createTransActionData(bContext *C, TransInfo *t)
{
Scene *scene= CTX_data_scene(C);
Scene *scene= t->scene;
TransData *td = NULL;
tGPFtransdata *tfd = NULL;
@ -3167,7 +3167,6 @@ static void createTransActionData(bContext *C, TransInfo *t)
int count=0;
float cfra;
char side;
/* determine what type of data we are operating on */
if (ANIM_animdata_get_context(C, &ac) == 0)
@ -3186,11 +3185,11 @@ static void createTransActionData(bContext *C, TransInfo *t)
float xmouse, ymouse;
UI_view2d_region_to_view(&ac.ar->v2d, t->imval[0], t->imval[1], &xmouse, &ymouse);
side = (xmouse > CFRA) ? 'R' : 'L'; // XXX use t->frame_side
t->frame_side = (xmouse > CFRA) ? 'R' : 'L'; // XXX use t->frame_side
}
else {
/* normal transform - both sides of current frame are considered */
side = 'B';
t->frame_side = 'B';
}
/* loop 1: fully select ipo-keys and count how many BezTriples are selected */
@ -3206,9 +3205,9 @@ static void createTransActionData(bContext *C, TransInfo *t)
cfra = (float)CFRA;
//if (ale->type == ANIMTYPE_GPLAYER)
// count += count_gplayer_frames(ale->data, side, cfra);
// count += count_gplayer_frames(ale->data, t->frame_side, cfra);
//else
count += count_fcurve_keys(ale->key_data, side, cfra);
count += count_fcurve_keys(ale->key_data, t->frame_side, cfra);
}
/* stop if trying to build list if nothing selected */
@ -3243,7 +3242,7 @@ static void createTransActionData(bContext *C, TransInfo *t)
// bGPDlayer *gpl= (bGPDlayer *)ale->data;
// int i;
//
// i = GPLayerToTransData(td, tfd, gpl, side, cfra);
// i = GPLayerToTransData(td, tfd, gpl, t->frame_side, cfra);
// td += i;
// tfd += i;
//}
@ -3259,7 +3258,7 @@ static void createTransActionData(bContext *C, TransInfo *t)
else
cfra = (float)CFRA;
td= FCurveToTransData(td, fcu, adt, side, cfra);
td= FCurveToTransData(td, fcu, adt, t->frame_side, cfra);
//}
}
@ -3351,8 +3350,8 @@ static void bezt_to_transdata (TransData *td, TransData2D *td2d, AnimData *adt,
static void createTransGraphEditData(bContext *C, TransInfo *t)
{
SpaceIpo *sipo= CTX_wm_space_graph(C);
Scene *scene= CTX_data_scene(C);
ARegion *ar= CTX_wm_region(C);
Scene *scene= t->scene;
ARegion *ar= t->ar;
View2D *v2d= &ar->v2d;
TransData *td = NULL;
@ -3366,7 +3365,6 @@ static void createTransGraphEditData(bContext *C, TransInfo *t)
BezTriple *bezt;
int count=0, i;
float cfra;
char side;
/* determine what type of data we are operating on */
if (ANIM_animdata_get_context(C, &ac) == 0)
@ -3383,11 +3381,11 @@ static void createTransGraphEditData(bContext *C, TransInfo *t)
float xmouse, ymouse;
UI_view2d_region_to_view(v2d, t->imval[0], t->imval[1], &xmouse, &ymouse);
side = (xmouse > CFRA) ? 'R' : 'L'; // XXX use t->frame_side
t->frame_side = (xmouse > CFRA) ? 'R' : 'L'; // XXX use t->frame_side
}
else {
/* normal transform - both sides of current frame are considered */
side = 'B';
t->frame_side = 'B';
}
/* loop 1: count how many BezTriples (specifically their verts) are selected (or should be edited) */
@ -3409,7 +3407,7 @@ static void createTransGraphEditData(bContext *C, TransInfo *t)
/* only include BezTriples whose 'keyframe' occurs on the same side of the current frame as mouse */
for (i=0, bezt=fcu->bezt; i < fcu->totvert; i++, bezt++) {
if (FrameOnMouseSide(side, bezt->vec[1][0], cfra)) {
if (FrameOnMouseSide(t->frame_side, bezt->vec[1][0], cfra)) {
if (sipo->around == V3D_LOCAL) {
/* for local-pivot we only need to count the number of selected handles only, so that centerpoints don't
* don't get moved wrong
@ -3469,7 +3467,7 @@ static void createTransGraphEditData(bContext *C, TransInfo *t)
/* 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++) {
if (FrameOnMouseSide(side, bezt->vec[1][0], cfra)) {
if (FrameOnMouseSide(t->frame_side, bezt->vec[1][0], cfra)) {
TransDataCurveHandleFlags *hdata = NULL;
short h1=1, h2=1;
@ -4147,7 +4145,7 @@ static void createTransSeqData(bContext *C, TransInfo *t)
{
View2D *v2d= UI_view2d_fromcontext(C);
Scene *scene= CTX_data_scene(C);
Scene *scene= t->scene;
Editing *ed= seq_give_editing(t->scene, FALSE);
TransData *td = NULL;
TransData2D *td2d= NULL;
@ -4200,7 +4198,7 @@ static void createTransSeqData(bContext *C, TransInfo *t)
/* transcribe given object into TransData for Transforming */
static void ObjectToTransData(bContext *C, TransInfo *t, TransData *td, Object *ob)
{
Scene *scene = CTX_data_scene(C);
Scene *scene = t->scene;
Object *track;
float obmtx[3][3];
short constinv;
@ -4795,6 +4793,21 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
posttrans_action_clean(&ac, (bAction *)ac.data);
}
}
/* marker transform, not especially nice but we may want to move markers
* at the same time as keyframes in the dope sheet. */
if ((saction->flag & SACTION_MARKERS_MOVE) && (cancelled == 0)) {
/* cant use , TFM_TIME_EXTEND
* for some reason EXTEND is changed into TRANSLATE, so use frame_side instead */
if(t->mode == TFM_TIME_TRANSLATE) {
if(t->frame_side == 'B')
scene_marker_tfm_translate(t->scene, floor(t->vec[0] + 0.5f), SELECT);
else if (ELEM(t->frame_side, 'L', 'R'))
scene_marker_tfm_extend(t->scene, floor(t->vec[0] + 0.5f), SELECT, t->scene->r.cfra, t->frame_side);
}
}
#if 0 // XXX future of this is still not clear
else if (ac.datatype == ANIMCONT_GPENCIL) {
/* remove duplicate frames and also make sure points are in order! */
@ -5139,7 +5152,7 @@ void createTransNodeData(bContext *C, TransInfo *t)
void createTransData(bContext *C, TransInfo *t)
{
Scene *scene = CTX_data_scene(C);
Scene *scene = t->scene;
Object *ob = OBACT;
if (t->options & CTX_TEXTURE) {

@ -597,6 +597,8 @@ typedef enum eSAction_Flag {
SACTION_TEMP_NEEDCHANSYNC = (1<<9),
/* don't perform realtime updates */
SACTION_NOREALTIMEUPDATES = (1<<10),
/* move markers as well as keyframes */
SACTION_MARKERS_MOVE = (1<<11),
} eSAction_Flag;
/* SpaceAction Mode Settings */

@ -1457,6 +1457,10 @@ static void rna_def_space_dopesheet(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Realtime Updates", "When transforming keyframes, changes to the animation data are flushed to other views");
RNA_def_property_update(prop, NC_SPACE|ND_SPACE_DOPESHEET, NULL);
prop= RNA_def_property(srna, "use_marker_sync", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", SACTION_MARKERS_MOVE);
RNA_def_property_ui_text(prop, "Sync Markers", "Sync Markers with keyframe edits");
/* dopesheet */
prop= RNA_def_property(srna, "dopesheet", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "DopeSheet");