Animation: Add "Frame Channel" operators #104523

Merged
Christoph Lendenfeld merged 27 commits from ChrisLend/blender:frame-channel-operator into main 2023-02-17 18:11:10 +01:00

When animating it is often useful to frame the Graph Editor/Dope Sheet to whatever frames are in a given channel.
This patch adds the option to frame on selected channels OR frame on whatever channel is under the cursor.

If a preview range is set it will only focus on keys in that range.

Supports FCurve and keyframe data

Frame to selected is called with

  • Right click in the channel section -> Frame Selected Channels
  • or in Channel → Frame Selected Channels
  • or hitting . on the numpad

Frame to channel under cursor is done with

ALT + Middle Mouse Button


old patch on phabricator

https://archive.blender.org/developer/D17005

When animating it is often useful to frame the Graph Editor/Dope Sheet to whatever frames are in a given channel. This patch adds the option to frame on selected channels OR frame on whatever channel is under the cursor. If a preview range is set it will only focus on keys in that range. Supports FCurve and keyframe data Frame to selected is called with * Right click in the channel section -> Frame Selected Channels * or in Channel → Frame Selected Channels * or hitting . on the numpad Frame to channel under cursor is done with ALT + Middle Mouse Button ----- old patch on phabricator https://archive.blender.org/developer/D17005
Christoph Lendenfeld added 18 commits 2023-02-09 16:31:52 +01:00
Author
Member

frame channels video demo

frame channels video demo
Sybren A. Stüvel added the
Module
Animation & Rigging
label 2023-02-09 16:43:56 +01:00
Christoph Lendenfeld requested review from Sybren A. Stüvel 2023-02-10 17:19:34 +01:00
Brecht Van Lommel added this to the Animation & Rigging project 2023-02-13 09:13:45 +01:00
Sybren A. Stüvel requested changes 2023-02-14 14:46:38 +01:00
Sybren A. Stüvel left a comment
Member

Nice addition! Just some small nags.

Nice addition! Just some small nags.
@ -375,3 +375,3 @@
* Calculate the extents of F-Curve's data.
*/
bool BKE_fcurve_calc_bounds(const struct FCurve *fcu,
bool BKE_fcurve_calc_bounds(struct FCurve *fcu,

AFAICS the fcu parameter can remain const.

AFAICS the `fcu` parameter can remain `const`.
ChrisLend marked this conversation as resolved
@ -382,2 +382,3 @@
bool do_sel_only,
bool include_handles);
bool include_handles,
const float range[2]);

Document what the range parameter is for, and what the behaviour is when it's NULL.

Document what the `range` parameter is for, and what the behaviour is when it's `NULL`.
ChrisLend marked this conversation as resolved
@ -625,3 +626,1 @@
/* Get endpoint keyframes. */
foundvert = get_fcurve_end_keyframes(fcu, &bezt_first, &bezt_last, do_sel_only);
if (range == NULL) {

I think it's nicer to have a const bool use_range = range != NULL; at the start of the function, and then just use use_range in the rest of the code. That limits the 'knowledge' of "NULL means do not use" to a single line of code.

This if can then be flipped, and become if (use_range) ... else ... to avoid a negation.

I think it's nicer to have a `const bool use_range = range != NULL;` at the start of the function, and then just use `use_range` in the rest of the code. That limits the 'knowledge' of "NULL means do not use" to a single line of code. This `if` can then be flipped, and become `if (use_range) ... else ...` to avoid a negation.
ChrisLend marked this conversation as resolved
@ -628,0 +628,4 @@
foundvert = get_fcurve_end_keyframes(fcu, &bezt_first, &bezt_last, do_sel_only);
}
else {
/* If a range is passed in find the first and last keyframe within that range. */

IMO this should be a separate function, as finding the first/last keyframes is something different than calculating the bounds (single responsibility principle).

IMO this should be a separate function, as finding the first/last keyframes is something different than calculating the bounds (single responsibility principle).
ChrisLend marked this conversation as resolved
@ -3640,0 +3642,4 @@
/** \name View Channel Operator
* \{ */
static void get_normalized_fcurve_bounds(FCurve *fcu,

I think these three pointers can all be const, as this only gets the bounds and shouldn't set anything.

I think these three pointers can all be `const`, as this only gets the bounds and shouldn't set anything.
Author
Member

only ale can be const in this case
because ANIM_get_normalization_flags and ANIM_unit_mapping_get_factor would throw warnings otherwise since they aren't set to const

only `ale` can be const in this case because `ANIM_get_normalization_flags` and `ANIM_unit_mapping_get_factor` would throw warnings otherwise since they aren't set to const
dr.sybren marked this conversation as resolved
@ -3640,0 +3645,4 @@
static void get_normalized_fcurve_bounds(FCurve *fcu,
bAnimContext *ac,
bAnimListElem *ale,
bool include_handles,

const

`const`
ChrisLend marked this conversation as resolved
@ -3640,0 +3660,4 @@
range);
float unitFac, offset;
short mapping_flag = ANIM_get_normalization_flags(ac);

const

`const`
ChrisLend marked this conversation as resolved
@ -3640,0 +3661,4 @@
float unitFac, offset;
short mapping_flag = ANIM_get_normalization_flags(ac);
unitFac = ANIM_unit_mapping_get_factor(ac->scene, ale->id, fcu, mapping_flag, &offset);

Declaring unitFac here makes it possible to const float it.

Declaring `unitFac` here makes it possible to `const float` it.
ChrisLend marked this conversation as resolved
@ -3640,0 +3665,4 @@
r_bounds->ymin += offset;
r_bounds->ymax += offset;
r_bounds->ymin *= unitFac;
r_bounds->ymax *= unitFac;

I think it's nicer to see the entire formula in one go:

r_bounds->ymin = unitFac * (r_bounds->ymin + offset);
I think it's nicer to see the entire formula in one go: ```c r_bounds->ymin = unitFac * (r_bounds->ymin + offset); ```
ChrisLend marked this conversation as resolved
@ -3640,0 +3726,4 @@
}
}
/* Take regions into account, that could block the view.

How can the view be blocked, by taking regions into account?
I think for the right meaning the comma has to be removed.

Having said that, the comment is a bit vague, "take into account" doesn't mean that much until you know where & how the function is used.

It's better to be more descriptive of what it does, rather than about where it is supposed to be used.

How can the view be blocked, by taking regions into account? I think for the right meaning the comma has to be removed. Having said that, the comment is a bit vague, "take into account" doesn't mean that much until you know where & how the function is used. It's better to be more descriptive of what it does, rather than about where it is supposed to be used.
Author
Member

let me know if the comment makes more sense now

let me know if the comment makes more sense now
dr.sybren marked this conversation as resolved
@ -3640,0 +3733,4 @@
BLI_rctf_scale(bounds, 1.1f);
float pad_top = UI_TIME_SCRUB_MARGIN_Y;
float pad_bottom = BLI_listbase_is_empty(ED_context_get_markers(C)) ? V2D_SCROLL_HANDLE_HEIGHT :

const

`const`
ChrisLend marked this conversation as resolved
@ -3640,0 +3738,4 @@
BLI_rctf_pad_y(bounds, ac->region->winy, pad_bottom, pad_top);
}
/* Iterates through regions because the operator might not have been called from the correct

Within the context of this patch "the operator" can be understood, but once this is in Blender's sources, it's a bit vague. The doc also explains what this code does in terms of what other code didn't do, and that creates a tight coupling that's not wanted.

Within the context of this patch "the operator" can be understood, but once this is in Blender's sources, it's a bit vague. The doc also explains what this code does in terms of what other code didn't do, and that creates a tight coupling that's not wanted.
Author
Member

I hope the comment is better now

I hope the comment is better now
dr.sybren marked this conversation as resolved
@ -3640,0 +3764,4 @@
size_t anim_data_length = ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
if (anim_data_length == 0) {
return OPERATOR_CANCELLED;

Use WM_report to show a warning that explains why the operator couldn't run.

Use `WM_report` to show a warning that explains why the operator couldn't run.
ChrisLend marked this conversation as resolved
Christoph Lendenfeld added 4 commits 2023-02-16 13:22:55 +01:00
Christoph Lendenfeld added 2 commits 2023-02-16 13:26:25 +01:00
Christoph Lendenfeld added 1 commit 2023-02-16 13:27:59 +01:00
Christoph Lendenfeld requested review from Sybren A. Stüvel 2023-02-16 13:30:05 +01:00
Sybren A. Stüvel approved these changes 2023-02-17 15:06:07 +01:00
Sybren A. Stüvel left a comment
Member

LGTM!

LGTM!

There's one small issue I just noticed, I'll leave it up to you if you want to address that in this patch or in another one.

When alt-middleclicking on a single channel that has no Y-range (so all keys have the same value), the view is a bit jumpy. It seems to zoom out and quickly zoom back in again.

There's one small issue I just noticed, I'll leave it up to you if you want to address that in this patch or in another one. When alt-middleclicking on a single channel that has no Y-range (so all keys have the same value), the view is a bit jumpy. It seems to zoom out and quickly zoom back in again.
Christoph Lendenfeld added 2 commits 2023-02-17 17:17:43 +01:00
Christoph Lendenfeld reviewed 2023-02-17 17:19:00 +01:00
@ -3641,0 +3663,4 @@
const float min_height = 0.01f;
const float height = BLI_rctf_size_y(r_bounds);
if (height < min_height) {
Author
Member

@dr.sybren
fixed the issue with the flat curves with that

@dr.sybren fixed the issue with the flat curves with that
Christoph Lendenfeld merged commit d7dd7ee24c into main 2023-02-17 18:11:10 +01:00
Christoph Lendenfeld deleted branch frame-channel-operator 2023-02-17 18:11:11 +01:00
First-time contributor

The focus is correct in Graph Editor.
But it is not in Timeline/Dopesheet.

When I do a select Frame Select Channels and channel selected is at bottom of channels list, X framing is correctly relative to keyframes.
But Y framing is reset to Top of Dopesheet.
So, user has to scroll down after each alt middle click.

The focus is correct in Graph Editor. But it is not in Timeline/Dopesheet. When I do a select Frame Select Channels and channel selected is at bottom of channels list, X framing is correctly relative to keyframes. But Y framing is reset to Top of Dopesheet. So, user has to scroll down after each alt middle click.
Sybren A. Stüvel removed this from the Animation & Rigging project 2023-03-02 17:00:42 +01:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#104523
No description provided.