Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/transform/transform_mode_timeslide.c
| Show All 36 Lines | |||||
| #include "ED_screen.h" | #include "ED_screen.h" | ||||
| #include "UI_interface.h" | #include "UI_interface.h" | ||||
| #include "UI_view2d.h" | #include "UI_view2d.h" | ||||
| #include "BLT_translation.h" | #include "BLT_translation.h" | ||||
| #include "transform.h" | #include "transform.h" | ||||
| #include "transform_data.h" | |||||
| #include "transform_mode.h" | #include "transform_mode.h" | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /* Transform (Animation Time Slide) */ | /* Transform (Animation Time Slide) */ | ||||
| /** \name Transform Animation Time Slide | /** \name Transform Animation Time Slide | ||||
| * \{ */ | * \{ */ | ||||
| Show All 17 Lines | else { | ||||
| BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", val); | BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", val); | ||||
| } | } | ||||
| BLI_snprintf(str, UI_MAX_DRAW_STR, TIP_("TimeSlide: %s"), &tvec[0]); | BLI_snprintf(str, UI_MAX_DRAW_STR, TIP_("TimeSlide: %s"), &tvec[0]); | ||||
| } | } | ||||
| static void applyTimeSlideValue(TransInfo *t, float sval, float cval) | static void applyTimeSlideValue(TransInfo *t, float sval, float cval) | ||||
| { | { | ||||
| int i; | |||||
| const float *range = t->custom.mode.data; | const float *range = t->custom.mode.data; | ||||
| float minx = range[0]; | float minx = range[0]; | ||||
| float maxx = range[1]; | float maxx = range[1]; | ||||
| /* set value for drawing black line */ | /* set value for drawing black line */ | ||||
| if (t->spacetype == SPACE_ACTION) { | if (t->spacetype == SPACE_ACTION) { | ||||
| SpaceAction *saction = (SpaceAction *)t->area->spacedata.first; | SpaceAction *saction = (SpaceAction *)t->area->spacedata.first; | ||||
| saction->timeslide = cval; | saction->timeslide = cval; | ||||
| } | } | ||||
| /* It doesn't matter whether we apply to t->data or | /* It doesn't matter whether we apply to t->data or | ||||
| * t->data2d, but t->data2d is more convenient. */ | * t->data2d, but t->data2d is more convenient. */ | ||||
| FOREACH_TRANS_DATA_CONTAINER (t, tc) { | FOREACH_TRANS_DATA_CONTAINER (t, tc) { | ||||
| TransData *td = tc->data; | TransData *td = tc->data; | ||||
| for (i = 0; i < tc->data_len; i++, td++) { | for (int tdi = 0; tdi < tc->data_len; tdi++) { | ||||
| /* it is assumed that td->extra is a pointer to the AnimData, | /* it is assumed that td->basic[tdi].extra is a pointer to the AnimData, | ||||
| * whose active action is where this keyframe comes from | * whose active action is where this keyframe comes from | ||||
| * (this is only valid when not in NLA) | * (this is only valid when not in NLA) | ||||
| */ | */ | ||||
| AnimData *adt = (t->spacetype != SPACE_NLA) ? td->extra : NULL; | AnimData *adt = (t->spacetype != SPACE_NLA) ? td->basic[tdi].extra : NULL; | ||||
| /* only apply to data if in range */ | /* only apply to data if in range */ | ||||
| if ((sval > minx) && (sval < maxx)) { | if ((sval > minx) && (sval < maxx)) { | ||||
| float cvalc = CLAMPIS(cval, minx, maxx); | float cvalc = CLAMPIS(cval, minx, maxx); | ||||
| float ival = td->ival; | float ival = td->special[tdi].ival; | ||||
| float timefac; | float timefac; | ||||
| /* NLA mapping magic here works as follows: | /* NLA mapping magic here works as follows: | ||||
| * - "ival" goes from strip time to global time | * - "ival" goes from strip time to global time | ||||
| * - calculation is performed into td->val in global time | * - calculation is performed into td->special[tdi].val in global time | ||||
| * (since sval and min/max are all in global time) | * (since sval and min/max are all in global time) | ||||
| * - "td->val" then gets put back into strip time | * - "td->special[tdi].val" then gets put back into strip time | ||||
| */ | */ | ||||
| if (adt) { | if (adt) { | ||||
| /* strip to global */ | /* strip to global */ | ||||
| ival = BKE_nla_tweakedit_remap(adt, ival, NLATIME_CONVERT_MAP); | ival = BKE_nla_tweakedit_remap(adt, ival, NLATIME_CONVERT_MAP); | ||||
| } | } | ||||
| /* left half? */ | /* left half? */ | ||||
| if (ival < sval) { | if (ival < sval) { | ||||
| timefac = (sval - ival) / (sval - minx); | timefac = (sval - ival) / (sval - minx); | ||||
| *(td->val) = cvalc - timefac * (cvalc - minx); | *(td->special[tdi].val) = cvalc - timefac * (cvalc - minx); | ||||
| } | } | ||||
| else { | else { | ||||
| timefac = (ival - sval) / (maxx - sval); | timefac = (ival - sval) / (maxx - sval); | ||||
| *(td->val) = cvalc + timefac * (maxx - cvalc); | *(td->special[tdi].val) = cvalc + timefac * (maxx - cvalc); | ||||
| } | } | ||||
| if (adt) { | if (adt) { | ||||
| /* global to strip */ | /* global to strip */ | ||||
| *(td->val) = BKE_nla_tweakedit_remap(adt, *(td->val), NLATIME_CONVERT_UNMAP); | *(td->special[tdi].val) = BKE_nla_tweakedit_remap( | ||||
| adt, *(td->special[tdi].val), NLATIME_CONVERT_UNMAP); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void applyTimeSlide(TransInfo *t, const int mval[2]) | static void applyTimeSlide(TransInfo *t, const int mval[2]) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | void initTimeSlide(TransInfo *t) | ||||
| { | { | ||||
| Scene *scene = t->scene; | Scene *scene = t->scene; | ||||
| float *range; | float *range; | ||||
| t->custom.mode.data = range = MEM_mallocN(sizeof(float[2]), "TimeSlide Min/Max"); | t->custom.mode.data = range = MEM_mallocN(sizeof(float[2]), "TimeSlide Min/Max"); | ||||
| t->custom.mode.use_free = true; | t->custom.mode.use_free = true; | ||||
| float min = 999999999.0f, max = -999999999.0f; | float min = 999999999.0f, max = -999999999.0f; | ||||
| int i; | |||||
| FOREACH_TRANS_DATA_CONTAINER (t, tc) { | FOREACH_TRANS_DATA_CONTAINER (t, tc) { | ||||
| TransData *td = tc->data; | TransData *td = tc->data; | ||||
| for (i = 0; i < tc->data_len; i++, td++) { | for (int tdi = 0; tdi < tc->data_len; tdi++) { | ||||
| AnimData *adt = (t->spacetype != SPACE_NLA) ? td->extra : NULL; | AnimData *adt = (t->spacetype != SPACE_NLA) ? td->basic[tdi].extra : NULL; | ||||
| float val = *(td->val); | float val = *(td->special[tdi].val); | ||||
| /* strip/action time to global (mapped) time */ | /* strip/action time to global (mapped) time */ | ||||
| if (adt) { | if (adt) { | ||||
| val = BKE_nla_tweakedit_remap(adt, val, NLATIME_CONVERT_MAP); | val = BKE_nla_tweakedit_remap(adt, val, NLATIME_CONVERT_MAP); | ||||
| } | } | ||||
| if (min > val) { | if (min > val) { | ||||
| min = val; | min = val; | ||||
| Show All 32 Lines | |||||