Refactor: use insert_key_rna() for button keyframing #121491

Closed
Nathan Vegdahl wants to merge 3 commits from nathanvegdahl/blender:button_keying_uniformity into main

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

This commit does two things:

  • Switches manual (not auto) keyframing of buttons to use
    insert_key_rna() instead of insert_keyframe().
  • Modifies insert_key_rna() to accept and understand rna paths that
    specify an array element (for array properties), in order to make
    the above possible.

This is part of a progressive refactor that is unifying the keyframing
code to use the same keyframing functions (in particular converging
on insert_key_rna()), rather than many different functions with
subtly different behavior.

Notes for reviewers:

  • @ChrisLend and I already discussed that we want insert_key_rna() to be able to take paths with fully qualified array indices. However, I'm not 100% sold on appending "[##]" to the path string to accomplish that. An alternative is for insert_key_rna() to take a span of string + int pairs rather than just a span strings like it does now.
  • This refactor is also partially in preparation for enabling button keyframing for Baklava, because insert_key_rna() will already handle Baklava keying after #120428 lands.
This commit does two things: - Switches manual (not auto) keyframing of buttons to use `insert_key_rna()` instead of `insert_keyframe()`. - Modifies `insert_key_rna()` to accept and understand rna paths that specify an array element (for array properties), in order to make the above possible. This is part of a progressive refactor that is unifying the keyframing code to use the same keyframing functions (in particular converging on `insert_key_rna()`), rather than many different functions with subtly different behavior. **Notes for reviewers:** - @ChrisLend and I already discussed that we want `insert_key_rna()` to be able to take paths with fully qualified array indices. However, I'm not 100% sold on appending "[##]" to the path string to accomplish that. An alternative is for `insert_key_rna()` to take a span of string + int pairs rather than just a span strings like it does now. - This refactor is also partially in preparation for enabling button keyframing for Baklava, because `insert_key_rna()` will already handle Baklava keying after #120428 lands.
Nathan Vegdahl added the
Module
Animation & Rigging
label 2024-05-06 17:55:36 +02:00
Nathan Vegdahl added 1 commit 2024-05-06 17:55:46 +02:00
This commit does two things:
- Modifies `insert_key_rna()` to accept and understand rna paths that
  specify a specific array element of an array property.
- Switches manual (not auto) keyframing of property buttons to use
  `insert_key_rna()` instead of `insert_keyframe()` like it was before.

This is part of a progressive refactor that is trying to unify the
keyframing code to use the same keyframing functions, rather than many
different functions with subtley different behavior.
Nathan Vegdahl requested review from Christoph Lendenfeld 2024-05-06 17:56:10 +02:00
Nathan Vegdahl requested review from Sybren A. Stüvel 2024-05-06 17:56:44 +02:00
Christoph Lendenfeld approved these changes 2024-05-07 10:00:19 +02:00
Christoph Lendenfeld left a comment
Member

Curious what sybren thinks of this, but I like this solution.
It keeps the function interface of insert_key_rna really simple.

The only thing that is slightly annoying is having to hardcode the [] into the string.

Curious what sybren thinks of this, but I like this solution. It keeps the function interface of `insert_key_rna` really simple. The only thing that is slightly annoying is having to hardcode the `[]` into the string.
Author
Member

Yeah, I think this is a perfectly reasonable solution. And I agree that it keeps the interface for insert_key_rna() simpler when looking at just insert_key_rna().

However, I suspect that in practice it will make insert_key_rna() more complicated to call from most places: you usually have the index as an integer, not already embedded in the path string, so this way you have to take the time and code space to append that index to the string before you can call insert_key_rna(). Whereas if it's passed as an integer alongside the path, you can just do that directly without any real prep work.

Having said that, I think it would be a pretty straightforward refactor going from one to the other, so I don't think it's critical that we get it "right" straight away.

Yeah, I think this is a perfectly reasonable solution. And I agree that it keeps the interface for `insert_key_rna()` simpler when looking at just `insert_key_rna()`. However, I suspect that in practice it will make `insert_key_rna()` more complicated to call from most places: you usually have the index as an integer, not already embedded in the path string, so this way you have to take the time and code space to append that index to the string before you can call `insert_key_rna()`. Whereas if it's passed as an integer alongside the path, you can just do that directly without any real prep work. Having said that, I think it would be a pretty straightforward refactor going from one to the other, so I don't think it's critical that we get it "right" straight away.
Nathan Vegdahl added 1 commit 2024-05-10 15:13:17 +02:00
It turns out that you can just create a temporary Span with initializer
lists, and it works fine.  (Confirmed with Jacques Lucke, who wrote
Span.)
Nathan Vegdahl added 1 commit 2024-05-10 15:13:31 +02:00
Author
Member

After some discussion about a related refactor with @ChrisLend, I think I'm going to split off the Modifies insert_key_rna() to accept and understand rna paths that specify an array element part of this into a separate PR.

Edit: here's that PR: #121879

After some discussion about a related refactor with @ChrisLend, I think I'm going to split off the `Modifies insert_key_rna() to accept and understand rna paths that specify an array element` part of this into a separate PR. Edit: here's that PR: #121879
Sybren A. Stüvel requested changes 2024-06-26 17:52:03 +02:00
@ -1083,3 +1083,2 @@
PropertyRNA *prop = nullptr;
const bool path_resolved = RNA_path_resolve_property(
rna_pointer, rna_path.c_str(), &ptr, &prop);
int index;

I think this is the array index, and if so, please name it array_index. That just makes it more concrete.

I *think* this is the array index, and if so, please name it `array_index`. That just makes it more concrete.
@ -1037,0 +1016,4 @@
* then add the specific index of the element we're keying to end of the
* path. */
std::string real_path = std::move(path.value());
if (!all) {

Given that #121879 has landed in main, why is this still necessary?

Given that #121879 has landed in `main`, why is this still necessary?
Author
Member

Gah! Yeah, this whole PR is redundant with other stuff that's already landed. Will close.

Gah! Yeah, this whole PR is redundant with other stuff that's already landed. Will close.
Author
Member

Everything this PR was trying to do has now been taken care of in #121879 and #122053. So it's no longer needed.

Everything this PR was trying to do has now been taken care of in #121879 and #122053. So it's no longer needed.
Nathan Vegdahl closed this pull request 2024-06-27 10:43:24 +02:00

Pull request closed

Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
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
Asset Browser Project
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#121491
No description provided.