diff options
author | Colin Marmond <Kdaf> | 2022-04-26 13:29:22 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2022-04-26 13:33:35 +0300 |
commit | 4e57b6ce77b15709d7a76382c2d185f9c845532c (patch) | |
tree | 2ba2d7c1ef368799779fbd3fd484f72077101e36 /source/blender/editors/animation | |
parent | 6cf148227b220dd5087241ad01b6d2d6fe9afb80 (diff) |
Animation: Sensible frame range for motion paths
Motion paths can now be initialised to more sensible frame ranges,
rather than simply 1-250:
- Scene Frame Range
- Selected Keyframes
- All Keyframes
Reviewed By: sybren, looch, dfelinto, pablico
Maniphest Tasks: T93047
Differential Revision: https://developer.blender.org/D13687
Diffstat (limited to 'source/blender/editors/animation')
-rw-r--r-- | source/blender/editors/animation/anim_motion_paths.c | 37 | ||||
-rw-r--r-- | source/blender/editors/animation/keyframes_keylist.cc | 48 |
2 files changed, 78 insertions, 7 deletions
diff --git a/source/blender/editors/animation/anim_motion_paths.c b/source/blender/editors/animation/anim_motion_paths.c index 539227933cf..b15bd3db678 100644 --- a/source/blender/editors/animation/anim_motion_paths.c +++ b/source/blender/editors/animation/anim_motion_paths.c @@ -340,6 +340,43 @@ static void motionpath_free_free_tree_data(ListBase *targets) } } +void animviz_motionpath_compute_range(Object *ob, Scene *scene) +{ + bAnimVizSettings *avs = ob->mode == OB_MODE_POSE ? &ob->pose->avs : &ob->avs; + + const bool has_action = ob->adt && ob->adt->action; + if (avs->path_range == MOTIONPATH_RANGE_SCENE || !has_action || + BLI_listbase_is_empty(&ob->adt->action->curves)) { + avs->path_sf = PSFRA; + avs->path_ef = PEFRA; + return; + } + + struct AnimKeylist *keylist = ED_keylist_create(); + LISTBASE_FOREACH (FCurve *, fcu, &ob->adt->action->curves) { + fcurve_to_keylist(ob->adt, fcu, keylist, 0); + } + + Range2f frame_range; + switch (avs->path_range) { + case MOTIONPATH_RANGE_KEYS_SELECTED: + if (ED_keylist_selected_keys_frame_range(keylist, &frame_range)) { + break; + } + ATTR_FALLTHROUGH; // Fall through if there were no selected keys found. + case MOTIONPATH_RANGE_KEYS_ALL: + ED_keylist_all_keys_frame_range(keylist, &frame_range); + break; + case MOTIONPATH_RANGE_SCENE: + BLI_assert_msg(false, "This should not happen, function should have exited earlier."); + }; + + avs->path_sf = frame_range.min; + avs->path_ef = frame_range.max; + + ED_keylist_free(keylist); +} + void animviz_calc_motionpaths(Depsgraph *depsgraph, Main *bmain, Scene *scene, diff --git a/source/blender/editors/animation/keyframes_keylist.cc b/source/blender/editors/animation/keyframes_keylist.cc index 9ee047fafff..3356ef4d47d 100644 --- a/source/blender/editors/animation/keyframes_keylist.cc +++ b/source/blender/editors/animation/keyframes_keylist.cc @@ -304,7 +304,21 @@ const struct ListBase *ED_keylist_listbase(const AnimKeylist *keylist) return &keylist->key_columns; } -bool ED_keylist_frame_range(const struct AnimKeylist *keylist, Range2f *r_frame_range) +static void keylist_first_last(const struct AnimKeylist *keylist, + const struct ActKeyColumn **first_column, + const struct ActKeyColumn **last_column) +{ + if (keylist->is_runtime_initialized) { + *first_column = &keylist->runtime.key_columns[0]; + *last_column = &keylist->runtime.key_columns[keylist->column_len - 1]; + } + else { + *first_column = static_cast<const ActKeyColumn *>(keylist->key_columns.first); + *last_column = static_cast<const ActKeyColumn *>(keylist->key_columns.last); + } +} + +bool ED_keylist_all_keys_frame_range(const struct AnimKeylist *keylist, Range2f *r_frame_range) { BLI_assert(r_frame_range); @@ -314,13 +328,33 @@ bool ED_keylist_frame_range(const struct AnimKeylist *keylist, Range2f *r_frame_ const ActKeyColumn *first_column; const ActKeyColumn *last_column; - if (keylist->is_runtime_initialized) { - first_column = &keylist->runtime.key_columns[0]; - last_column = &keylist->runtime.key_columns[keylist->column_len - 1]; + keylist_first_last(keylist, &first_column, &last_column); + r_frame_range->min = first_column->cfra; + r_frame_range->max = last_column->cfra; + + return true; +} + +bool ED_keylist_selected_keys_frame_range(const struct AnimKeylist *keylist, + Range2f *r_frame_range) +{ + BLI_assert(r_frame_range); + + if (ED_keylist_is_empty(keylist)) { + return false; } - else { - first_column = static_cast<const ActKeyColumn *>(keylist->key_columns.first); - last_column = static_cast<const ActKeyColumn *>(keylist->key_columns.last); + + const ActKeyColumn *first_column; + const ActKeyColumn *last_column; + keylist_first_last(keylist, &first_column, &last_column); + while (first_column && !(first_column->sel & SELECT)) { + first_column = first_column->next; + } + while (last_column && !(last_column->sel & SELECT)) { + last_column = last_column->prev; + } + if (!first_column || !last_column || first_column == last_column) { + return false; } r_frame_range->min = first_column->cfra; r_frame_range->max = last_column->cfra; |