Animation: Graph Editor Handle Selection #108142

Closed
Denys Hsu wants to merge 3 commits from cgtinker/blender:select_handles_patch into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Contributor

In a recent module meeting we realised there are no tools to select handles. This patch includes an operator, which (de)selects handles based on the given selection.

As the user may uses the operator to work on b.e. the left handles and the right handles afterwards, the operator acts on any bezt selection. When working with handles, we usually don’t want keyframes to be selected, therefore those get deselected by default. The design of the operator does not include the selection of keyframes based on active handles which may be useful in some cases - this should probably be added as separate operator as user would not expect that handle selection includes keyframe selection.

Another concept could be to remap selections. This could be done with radio buttons so the user can select a certain selection status which he wants to remap to another selection status (b.e. if the left handle is selected, deselect it and select the right handle + key [ Ls | K | R ] -> [ L | Ks | Rs ]) . However this seems like a more special case and is probably confusing.

In a recent module meeting we realised there are no tools to select handles. This patch includes an operator, which (de)selects handles based on the given selection. As the user may uses the operator to work on b.e. the left handles and the right handles afterwards, the operator acts on any bezt selection. When working with handles, we usually don’t want keyframes to be selected, therefore those get deselected by default. The design of the operator does not include the selection of keyframes based on active handles which may be useful in some cases - this should probably be added as separate operator as user would not expect that handle selection includes keyframe selection. Another concept could be to remap selections. This could be done with radio buttons so the user can select a certain selection status which he wants to remap to another selection status (b.e. if the left handle is selected, deselect it and select the right handle + key [ Ls | K | R ] -> [ L | Ks | Rs ]) . However this seems like a more special case and is probably confusing.
Denys Hsu added 1 commit 2023-05-22 12:24:09 +02:00
Iliya Katueshenock added this to the Animation & Rigging project 2023-05-22 15:18:23 +02:00
Iliya Katueshenock added the
Interest
User Interface
label 2023-05-22 15:18:28 +02:00
Denys Hsu requested review from Christoph Lendenfeld 2023-06-15 18:30:13 +02:00
Christoph Lendenfeld requested changes 2023-06-16 10:02:01 +02:00
Christoph Lendenfeld left a comment
Member

thanks for the patch. In terms of functionality no complaints
I left a few comments on things to change from a code point of view

thanks for the patch. In terms of functionality no complaints I left a few comments on things to change from a code point of view
@ -195,1 +195,4 @@
layout.separator()
# layout.operator("graph.select_handles", text="All").action = 'SELECT'
layout.operator("graph.select_handles")

I think we should add separate entries for "select left handles" and "select right handles"
this makes it a lot more discoverable for artists and they can easily assign a hotkey by right clicking the menu entry

I think we should add separate entries for "select left handles" and "select right handles" this makes it a lot more discoverable for artists and they can easily assign a hotkey by right clicking the menu entry
cgtinker marked this conversation as resolved
@ -74,6 +74,13 @@ enum eGraphKeys_LeftRightSelect_Mode {
GRAPHKEYS_LRSEL_RIGHT,
};
/* Defines for handle selection */

comments end with a "."

comments end with a "."
cgtinker marked this conversation as resolved
@ -216,2 +216,3 @@
if ((!prevbezt && (bezt1->ipo == BEZT_IPO_BEZ)) ||
(prevbezt && (prevbezt->ipo == BEZT_IPO_BEZ))) {
(prevbezt && (prevbezt->ipo == BEZT_IPO_BEZ)))
{

when running make format this gets undone
check that you have your clang-format pointed to the binary that comes with blender. that should be in "blender-git/lib//llvm/bin"

when running `make format` this gets undone check that you have your clang-format pointed to the binary that comes with blender. that should be in "blender-git/lib/<platform-name>/llvm/bin"
Author
Contributor

thanks for the hint, pointed llvm to the wrong binary

thanks for the hint, pointed llvm to the wrong binary
cgtinker marked this conversation as resolved
@ -2038,0 +2040,4 @@
/* defines for left-right select tool */
static const EnumPropertyItem prop_graphkeys_leftright_handle_select_types[] = {
{GRAPHKEYS_HANDLESEL_LR, "CHECK", 0, "Select Both Handles", ""},

why is the option to select both handles called "CHECK"
"BOTH" would make more sense to me but maybe I am missing something

Also check the code style for the comment above. Comments should start with a capital letter and end with a "."

why is the option to select both handles called "CHECK" "BOTH" would make more sense to me but maybe I am missing something Also check the code style for the comment above. Comments should start with a capital letter and end with a "."
Author
Contributor

I think I copied an existing enum and modified it back then, there is no checking. In the 'C' scripts are lots of comments that don't follow this convention which is misleading, probably it would be good to create a small formatter to fix them?

I think I copied an existing enum and modified it back then, there is no checking. In the 'C' scripts are lots of comments that don't follow this convention which is misleading, probably it would be good to create a small formatter to fix them?

yeah there is quite a bit of old comments floating around that need cleaning up

yeah there is quite a bit of old comments floating around that need cleaning up
cgtinker marked this conversation as resolved
@ -2038,0 +2046,4 @@
{0, NULL, 0, NULL, NULL},
};
short bezt_sel_left_handles(KeyframeEditData *ked, BezTriple *bezt)

make that KeyframeEditData *UNUSED(ked) for all those functions
This removes the warning you get when compiling

make that `KeyframeEditData *UNUSED(ked)` for all those functions This removes the warning you get when compiling
cgtinker marked this conversation as resolved
@ -2038,0 +2081,4 @@
return 0;
}
static void graphkeys_de_select_handles(bAnimContext *ac, short mode, const bool desel_kf)

leave a comment on what kind of enum short mode is
also can be const

leave a comment on what kind of enum `short mode` is also can be const
cgtinker marked this conversation as resolved
@ -2038,0 +2089,4 @@
KeyframeEditData ked;
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FCURVESONLY |

can be const int filter = ...

can be `const int filter = ...`
cgtinker marked this conversation as resolved
@ -2038,0 +2093,4 @@
ANIMFILTER_NODUPLIS);
ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
for (ale = anim_data.first; ale; ale = ale->next) {

this can be LISTBASE_FOREACH(bAnimListElem *, ale, &anim_data)
you then also don't need to have bAnimListElem *ale; before

this can be `LISTBASE_FOREACH(bAnimListElem *, ale, &anim_data)` you then also don't need to have `bAnimListElem *ale;` before
cgtinker marked this conversation as resolved
@ -2038,0 +2102,4 @@
}
switch (mode) {
case GRAPHKEYS_HANDLESEL_LR: {
ANIM_fcurve_keyframes_loop(&ked, fcu, NULL, bezt_sel_both_handles, NULL);

I did a test and you can just pass NULL instead of &ked since you are not doing anything with ked afterwards

I did a test and you can just pass `NULL` instead of `&ked` since you are not doing anything with `ked` afterwards
cgtinker marked this conversation as resolved
@ -2038,0 +2103,4 @@
switch (mode) {
case GRAPHKEYS_HANDLESEL_LR: {
ANIM_fcurve_keyframes_loop(&ked, fcu, NULL, bezt_sel_both_handles, NULL);
} break;

so far i've only seen break within the curly bracket block
but I am not sure if this is convention or not. Something to check with sybren

so far i've only seen `break` within the curly bracket block but I am not sure if this is convention or not. Something to check with sybren
Author
Contributor

Afaik it does not change anything, I just put them inside

Afaik it does not change anything, I just put them inside
cgtinker marked this conversation as resolved
@ -2038,0 +2129,4 @@
return OPERATOR_CANCELLED;
}
short leftright = RNA_enum_get(op->ptr, "mode");

i think calling the variable also mode would be clearer
and desel_kf should be deselect_keyframe. in general we try to avoid abbreviations these days to make the code more readable.

i think calling the variable also `mode` would be clearer and `desel_kf` should be `deselect_keyframe`. in general we try to avoid abbreviations these days to make the code more readable.
cgtinker marked this conversation as resolved
@ -2038,0 +2156,4 @@
/* flags */
ot->flag = OPTYPE_UNDO | OPTYPE_REGISTER;
ot->prop = RNA_def_enum(ot->srna,

you don't need to assign the RNA_def functions to anything
that way you can also remove PropertyRNA *prop; for which I get an unused warning anyway

you don't need to assign the `RNA_def` functions to anything that way you can also remove `PropertyRNA *prop;` for which I get an unused warning anyway
cgtinker marked this conversation as resolved
Denys Hsu added 1 commit 2023-06-16 12:16:23 +02:00
Denys Hsu requested review from Christoph Lendenfeld 2023-06-16 12:42:15 +02:00
Christoph Lendenfeld approved these changes 2023-06-21 15:42:11 +02:00
Christoph Lendenfeld left a comment
Member

apart from the two minor things that I am unsure about it looks good to me
i'll let sybren be the final judge

apart from the two minor things that I am unsure about it looks good to me i'll let sybren be the final judge
@ -2038,0 +2082,4 @@
static void graphkeys_de_select_handles(
bAnimContext *ac,
const short mode, // prop_graphkeys_leftright_handle_select_types

I meant add a comment that this is an enum and which it is.
e.g. enum eGraphKey_HandleSelect_Mode

also I am not sure we are supposed to use comments with //
sybren can elaborate on that

I meant add a comment that this is an enum and which it is. e.g. `enum eGraphKey_HandleSelect_Mode` also I am not sure we are supposed to use comments with // sybren can elaborate on that

Nope, see https://wiki.blender.org/wiki/Style_Guide/C_Cpp#Comments

Also, why use short here at all? IMO it should just be enum eGraphKey_HandleSelect_Mode mode.

Nope, see https://wiki.blender.org/wiki/Style_Guide/C_Cpp#Comments Also, why use `short` here at all? IMO it should just be `enum eGraphKey_HandleSelect_Mode mode`.
Author
Contributor

Also, why use short here at all? IMO it should just be enum eGraphKey_HandleSelect_Mode mode.

Yeah it should be eGraphKey_HandleSelect_Mode, will change that. Within the file all functions use a short instead of the enum prop, thought that had a reason and followed the "convention".

> Also, why use `short` here at all? IMO it should just be `enum eGraphKey_HandleSelect_Mode mode`. Yeah it should be `eGraphKey_HandleSelect_Mode`, will change that. Within the file all functions use a `short` instead of the enum prop, thought that had a reason and followed the "convention".
cgtinker marked this conversation as resolved
@ -2038,0 +2155,4 @@
/* flags */
ot->flag = OPTYPE_UNDO | OPTYPE_REGISTER;
ot->prop = RNA_def_enum(ot->srna,

you don't need to assign the RNA_def to anything
so it can just be RNA_def... instead of ot->prop = RNA_def

now I didn't know the operator type had a prop. And I am not sure what it is used for.
Maybe also something for sybren to clear up

you don't need to assign the RNA_def to anything so it can just be `RNA_def...` instead of `ot->prop = RNA_def` now I didn't know the operator type had a prop. And I am not sure what it is used for. Maybe also something for sybren to clear up

It's documented as:

  /**
   * Default rna property to use for generic invoke functions.
   * menus, enum search... etc. Example: Enum 'type' for a Delete menu.
   *
   * When assigned a string/number property,
   * immediately edit the value when used in a popup. see: #UI_BUT_ACTIVATE_ON_INIT.
   */
  PropertyRNA *prop;

So this means that it can be used for certain interactions as a special property.

@ChrisLend is right in that here the assignment is unnecessary. And if there is a property that should be marked as that special one property, it should only be assigned once, and not assigned and then immediately be overwritten again.

It's documented as: ```c /** * Default rna property to use for generic invoke functions. * menus, enum search... etc. Example: Enum 'type' for a Delete menu. * * When assigned a string/number property, * immediately edit the value when used in a popup. see: #UI_BUT_ACTIVATE_ON_INIT. */ PropertyRNA *prop; ``` So this means that it can be used for certain interactions as a special property. @ChrisLend is right in that here the assignment is unnecessary. And if there is a property that should be marked as that special one property, it should only be assigned once, and not assigned and then immediately be overwritten again.
cgtinker marked this conversation as resolved
Christoph Lendenfeld requested review from Sybren A. Stüvel 2023-06-21 15:42:20 +02:00
Author
Contributor

apart from the two minor things that I am unsure about it looks good to me
i'll let sybren be the final judge

great, thanks for the review!

> apart from the two minor things that I am unsure about it looks good to me > i'll let sybren be the final judge great, thanks for the review!
Sybren A. Stüvel requested changes 2023-06-22 17:24:06 +02:00
Sybren A. Stüvel left a comment
Member

This is some nice functionality. I feel that there's one thing missing though: for all selected handles, select they keys, optionally deselecting the handles themselves. The addition of that 'mode' would make it possible to quickly move the selection from left handle, to the key itself, to the right handle, etc.

As for the attached video, please stick to formats that are widely supported by webbrowsers (h.264/MP4, or VC9/WebM).

This is some nice functionality. I feel that there's one thing missing though: for all selected handles, select they keys, optionally deselecting the handles themselves. The addition of that 'mode' would make it possible to quickly move the selection from left handle, to the key itself, to the right handle, etc. As for the attached video, please stick to formats that are widely supported by webbrowsers (h.264/MP4, or VC9/WebM).
@ -75,2 +75,4 @@
};
/* Defines for handle selection. */
enum eGraphKey_HandleSelect_Mode {

I think 'side' would be a better noun than 'mode' here. IMO the 'mode' should also include whether the keys themselves are selected/deselected or not, which is not part of this enum.

I think 'side' would be a better noun than 'mode' here. IMO the 'mode' should also include whether the keys themselves are selected/deselected or not, which is not part of this enum.
cgtinker marked this conversation as resolved
@ -2038,0 +2039,4 @@
/* Defines for handle select tool. */
static const EnumPropertyItem prop_graphkeys_leftright_handle_select_types[] = {
{GRAPHKEYS_HANDLESEL_LR, "BOTH", 0, "Select Both Handles", ""},

Just for consistency, rename GRAPHKEYS_HANDLESEL_LR to GRAPHKEYS_HANDLESEL_BOTH.

Just for consistency, rename `GRAPHKEYS_HANDLESEL_LR` to `GRAPHKEYS_HANDLESEL_BOTH`.
cgtinker marked this conversation as resolved
@ -2038,0 +2080,4 @@
return 0;
}
static void graphkeys_de_select_handles(

Remove the _de_, there are many more functions that are called 'select' but also allow deselecting.

Remove the `_de_`, there are many more functions that are called 'select' but also allow deselecting.
cgtinker marked this conversation as resolved
@ -2038,0 +2083,4 @@
static void graphkeys_de_select_handles(
bAnimContext *ac,
const short mode, // prop_graphkeys_leftright_handle_select_types
const bool deselect_keyframe)

It's not a good idea to have negated booleans (i.e. 'enable to disable' style ones). Just use const bool select.

Having said that, looking at the code this does something else than I expected, so definitely add a comment above the function that explains what the parameters do.

It's not a good idea to have negated booleans (i.e. 'enable to disable' style ones). Just use `const bool select`. Having said that, looking at the code this does something else than I expected, so definitely add a comment above the function that explains what the parameters do.
cgtinker marked this conversation as resolved
@ -2038,0 +2092,4 @@
ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) {
FCurve *fcu = (FCurve *)ale->key_data;

Add BLI_assert(ale->type, ANIMTYPE_FCURVE) before the cast, just to have a little extra check that the cast is actually valid.

Add `BLI_assert(ale->type, ANIMTYPE_FCURVE)` before the cast, just to have a little extra check that the cast is actually valid.
cgtinker marked this conversation as resolved
@ -2038,0 +2131,4 @@
}
short leftright = RNA_enum_get(op->ptr, "mode");
bool deselect_keyframe = RNA_boolean_get(op->ptr, "deselect_keyframe");

These variables can be const.

These variables can be `const`.
cgtinker marked this conversation as resolved
@ -2038,0 +2160,4 @@
prop_graphkeys_leftright_handle_select_types,
GRAPHKEYS_HANDLESEL_LR,
"Mode",
"(De)Select handles based on selection");

"Select handles based on selection" is too vague.

"Select handles based on selection" is too vague.
cgtinker marked this conversation as resolved
@ -2038,0 +2161,4 @@
GRAPHKEYS_HANDLESEL_LR,
"Mode",
"(De)Select handles based on selection");
ot->prop = RNA_def_boolean(ot->srna, "deselect_keyframe", 1, "Deselect Keyframes", "");

This should have a tooltip that explains what it does.

This should have a tooltip that explains what it does.
cgtinker marked this conversation as resolved
Author
Contributor

This is some nice functionality. I feel that there's one thing missing though: for all selected handles, select they keys, optionally deselecting the handles themselves. The addition of that 'mode' would make it possible to quickly move the selection from left handle, to the key itself, to the right handle, etc.

Thanks!

As mentioned in the PR I'm not sure if the selection of keyframes should be within the selection of handles. Implementing a select keyframes option within the select handles operator seems confusing, even more while having the option to preserve the keyframe selection.

If the keyframe selection is not relevant it would be the easiest to make the bool actually selecting / deselecting the keyframes. ed: Either it should be separated, or an option within the enum.

> This is some nice functionality. I feel that there's one thing missing though: for all selected handles, select they keys, optionally deselecting the handles themselves. The addition of that 'mode' would make it possible to quickly move the selection from left handle, to the key itself, to the right handle, etc. Thanks! As mentioned in the PR I'm not sure if the selection of keyframes should be within the selection of handles. Implementing a `select keyframes` option within the `select handles` operator seems confusing, even more while having the option to preserve the keyframe selection. ~~If the keyframe selection is not relevant it would be the easiest to make the bool actually selecting / deselecting the keyframes.~~ ed: Either it should be separated, or an option within the enum.
Denys Hsu added 1 commit 2023-06-26 12:58:30 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
4870e67ee5
improved descriptions and keyframe selection
Author
Contributor

Decided to give selecting keyframes a try. While it feels good to have it within the handle selection and it seems a little out of place. Separating it would also seem wrong.

Besides decided to only draw the "deselect keyframes" bool when selecting handles...

Decided to give selecting keyframes a try. While it feels good to have it within the handle selection and it seems a little out of place. Separating it would also seem wrong. Besides decided to only draw the "deselect keyframes" bool when selecting handles...
Denys Hsu requested review from Sybren A. Stüvel 2023-06-26 13:02:47 +02:00

@blender-bot package

@blender-bot package
Member

Package build started. Download here when ready.

Package build started. [Download here](https://builder.blender.org/download/patch/PR108142) when ready.
Member

Since @cgtinker is no longer available, I'm continuing this PR in #111143, with code updated to latest main.

Since @cgtinker is no longer available, I'm continuing this PR in #111143, with code updated to latest main.
Nathan Vegdahl closed this pull request 2023-08-15 17:02:11 +02:00
Some checks failed
buildbot/vexp-code-patch-coordinator Build done.

Pull request closed

Sign in to join this conversation.
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
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 Assignees
5 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#108142
No description provided.