== NLA - Scale Related Fixes ==

* Old files now get initialised with the correct scale. The wrong calculation was being used

* Added a new tool to Alt-S menu: "Apply Scale"
This tool causes all the keyframes in the active strip to be moved to their NLA-scaled times, the scale to be set to 1.0, and the frame ranges recalculated accordingly (to remove any nasty weird errors)

* Scale field now draws red when the action-range is < 1, and the tooltip in this case instructs the user how to fix this (by using "Apply Scale").
This commit is contained in:
Joshua Leung 2007-12-07 10:50:02 +00:00
parent 9723e3ef39
commit be7192c0bd
5 changed files with 57 additions and 25 deletions

@ -443,7 +443,6 @@ static float get_actionstrip_frame(bActionStrip *strip, float cframe, int invert
length = repeat * scale * actlength; length = repeat * scale * actlength;
/* invert = convert action-strip time to global time */ /* invert = convert action-strip time to global time */
// FIXME?
if (invert) if (invert)
return length*(cframe - strip->actstart)/(repeat*actlength) + strip->start; return length*(cframe - strip->actstart)/(repeat*actlength) + strip->start;
else else

@ -7211,8 +7211,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
if (length == 0.0f) length= 1.0f; if (length == 0.0f) length= 1.0f;
actlength = strip->actend-strip->actstart; actlength = strip->actend-strip->actstart;
// right calculation? strip->scale = length / (repeat * actlength);
strip->scale = actlength / (length * repeat);
if (strip->scale == 0.0f) strip->scale= 1.0f; if (strip->scale == 0.0f) strip->scale= 1.0f;
} }
} }

@ -639,7 +639,13 @@ static void nla_panel_properties(short cntrl) // NLA_HANDLER_PROPERTIES
uiBlockBeginAlign(block); uiBlockBeginAlign(block);
// FIXME: repeat and scale are too cramped! // FIXME: repeat and scale are too cramped!
uiDefButF(block, NUM, B_NLA_SCALE, "Repeat:", 160,100,75,19, &strip->repeat, 0.001, 1000.0f, 100, 0, "Number of times the action should repeat"); uiDefButF(block, NUM, B_NLA_SCALE, "Repeat:", 160,100,75,19, &strip->repeat, 0.001, 1000.0f, 100, 0, "Number of times the action should repeat");
uiDefButF(block, NUM, B_NLA_SCALE, "Scale:", 235,100,75,19, &strip->scale, 0.001, 10000.0f, 100, 0, "Amount the action should be scaled by"); if ((strip->actend - strip->actstart) < 1.0f) {
uiBlockSetCol(block, TH_REDALERT);
uiDefButF(block, NUM, B_NLA_SCALE, "Scale:", 235,100,75,19, &strip->scale, 0.001, 1000.0f, 100, 0, "Please run Alt-S to fix up this error");
uiBlockSetCol(block, TH_AUTO);
}
else
uiDefButF(block, NUM, B_NLA_SCALE, "Scale:", 235,100,75,19, &strip->scale, 0.001, 1000.0f, 100, 0, "Amount the action should be scaled by");
but= uiDefButC(block, TEX, B_NLA_PANEL, "OffsBone:", 160,80,150,19, strip->offs_bone, 0, 31.0f, 0, 0, "Name of Bone that defines offset for repeat"); but= uiDefButC(block, TEX, B_NLA_PANEL, "OffsBone:", 160,80,150,19, strip->offs_bone, 0, 31.0f, 0, 0, "Name of Bone that defines offset for repeat");
uiButSetCompleteFunc(but, autocomplete_bone, (void *)ob); uiButSetCompleteFunc(but, autocomplete_bone, (void *)ob);
uiDefButBitS(block, TOG, ACTSTRIP_HOLDLASTFRAME, B_NLA_PANEL, "Hold", 160,60,75,19, &strip->flag, 0, 0, 0, 0, "Toggles whether to continue displaying the last frame past the end of the strip"); uiDefButBitS(block, TOG, ACTSTRIP_HOLDLASTFRAME, B_NLA_PANEL, "Hold", 160,60,75,19, &strip->flag, 0, 0, 0, 0, "Toggles whether to continue displaying the last frame past the end of the strip");

@ -199,11 +199,11 @@ void synchronize_action_strips(void)
calc_action_range(strip->act, &actstart, &actend, 1); calc_action_range(strip->act, &actstart, &actend, 1);
if ((strip->actstart!=actstart) || (strip->actend!=actend)) { if ((strip->actstart!=actstart) || (strip->actend!=actend)) {
float offset; float offset = strip->scale * (actstart - strip->actstart);
float actlen = actend - actstart;
offset= strip->scale * (actstart - strip->actstart);
strip->start += offset; strip->start += offset;
strip->end = strip->scale * strip->repeat * (actend-actstart) + strip->start; strip->end = (strip->scale * strip->repeat * actlen) + strip->start;
strip->actstart= actstart; strip->actstart= actstart;
strip->actend= actend; strip->actend= actend;
@ -372,15 +372,41 @@ void reset_action_strips(int val)
for (strip = base->object->nlastrips.last; strip; strip=strip->prev) { for (strip = base->object->nlastrips.last; strip; strip=strip->prev) {
if (strip->flag & ACTSTRIP_SELECT) { if (strip->flag & ACTSTRIP_SELECT) {
if(val==2) { switch (val) {
case 1:
{
/* clear scaling - reset to 1.0 without touching keys */
float actlen= (strip->actend - strip->actstart);
strip->scale= 1.0f;
strip->end= (strip->repeat * actlen) + strip->start;
}
break;
case 2:
{
/* reset action-range */
calc_action_range(strip->act, &strip->actstart, &strip->actend, 1); calc_action_range(strip->act, &strip->actstart, &strip->actend, 1);
} }
else if(val==1) { break;
float mapping= (strip->actend - strip->actstart)/(strip->end - strip->start); case 3:
{
/* apply scale to keys - scale is reset to 1.0f, but keys stay at the same times */
bActionChannel *achan;
strip->end= strip->start + mapping*(strip->end - strip->start); if (strip->act) {
for (achan= strip->act->chanbase.first; achan; achan= achan->next) {
actstrip_map_ipo_keys(base->object, achan->ipo, 0, 0);
} }
base->object->ctime= -1234567.0f; // eveil!
/* now we can reset scale */
calc_action_range(strip->act, &strip->actstart, &strip->actend, 1);
strip->scale= 1.0f;
strip->end = (strip->repeat * (strip->actend - strip->actstart)) + strip->start;
}
}
break;
}
base->object->ctime= -1234567.0f; // evil!
DAG_object_flush_update(G.scene, base->object, OB_RECALC_OB|OB_RECALC_DATA); DAG_object_flush_update(G.scene, base->object, OB_RECALC_OB|OB_RECALC_DATA);
} }
} }
@ -1850,14 +1876,12 @@ void winqreadnlaspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
break; break;
case SKEY: case SKEY:
if(G.qual==LR_ALTKEY) { if (G.qual==LR_ALTKEY) {
val= pupmenu("Action Strip Scale%t|Clear Strip Scale%x1|Remap Start/End%x2"); val= pupmenu("Action Strip Scale%t|Reset Strip Scale%x1|Remap Action Start/End%x2|Apply Scale%x3");
if(val==1) if (val > 0)
reset_action_strips(1); reset_action_strips(val);
else if(val==2)
reset_action_strips(2);
} }
else if(G.qual & LR_SHIFTKEY) { else if (G.qual & LR_SHIFTKEY) {
if (snla->flag & SNLA_DRAWTIME) if (snla->flag & SNLA_DRAWTIME)
val= pupmenu("Snap To%t|Nearest Second%x3|Current Time%x2"); val= pupmenu("Snap To%t|Nearest Second%x3|Current Time%x2");
else else

@ -331,7 +331,7 @@ static void do_nla_stripmenu(void *arg, int event)
case 7: /* Move Down */ case 7: /* Move Down */
shift_nlastrips_down(); shift_nlastrips_down();
break; break;
case 8: /* size */ case 8: /* reset scale */
reset_action_strips(1); reset_action_strips(1);
break; break;
case 9: /* reset start/end of action */ case 9: /* reset start/end of action */
@ -340,6 +340,9 @@ static void do_nla_stripmenu(void *arg, int event)
case 10: /* add new action as new action strip */ case 10: /* add new action as new action strip */
add_empty_nlablock(); add_empty_nlablock();
break; break;
case 11: /* apply scale */
reset_action_strips(3);
break;
} }
} }
@ -353,10 +356,11 @@ static uiBlock *nla_stripmenu(void *arg_unused)
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Strip Properties...|N", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Strip Properties...|N", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
uiDefIconTextBlockBut(block, nla_strip_transformmenu, NULL, ICON_RIGHTARROW_THIN, "Transform", 0, yco-=20, 120, 20, ""); uiDefIconTextBlockBut(block, nla_strip_transformmenu, NULL, ICON_RIGHTARROW_THIN, "Transform", 0, yco-=20, 120, 20, "");
uiDefIconTextBlockBut(block, nla_strip_snapmenu, NULL, ICON_RIGHTARROW_THIN, "Snap To Frame", 0, yco-=20, 120, 20, ""); uiDefIconTextBlockBut(block, nla_strip_snapmenu, NULL, ICON_RIGHTARROW_THIN, "Snap", 0, yco-=20, 120, 20, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Reset Strip Size|Alt S", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Reset Strip Scale|Alt S", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Reset Action Start/End|Alt S", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Reset Action Start/End|Alt S", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Apply Strip Scaling|Alt S", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 11, "");
uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");