Refactor: Pass Keyframe settings as arguments #115898

Merged
Christoph Lendenfeld merged 6 commits from ChrisLend/blender:refactor_insert_vert_arguments into main 2023-12-08 13:09:19 +01:00

No functional changes.

Before this PR the interpolation mode of a new keyframe was read from the User Preference at the deepest level where the keyframe is created.
In case where this shouldn't be done, the flag INSERTKEY_NO_USERPREF was passed in. In this case it would fall back to some default values.

In order to make these low level functions more flexible, the keyframe settings are now passed in.
I've made a new struct KeyframeSettings that holds the

  • interpolation
  • key type
  • handle type

and a function get_keyframe_settings that allows you to quickly get this settings struct.

This is a first step that will allow to pass in the interpolation mode from python in the future.

Part of: #113278: Anim: Keyframing Rework

No functional changes. Before this PR the interpolation mode of a new keyframe was read from the User Preference at the deepest level where the keyframe is created. In case where this shouldn't be done, the flag `INSERTKEY_NO_USERPREF` was passed in. In this case it would fall back to some default values. In order to make these low level functions more flexible, the keyframe settings are now passed in. I've made a new struct `KeyframeSettings` that holds the * interpolation * key type * handle type and a function `get_keyframe_settings` that allows you to quickly get this settings struct. This is a first step that will allow to pass in the interpolation mode from python in the future. Part of: [#113278: Anim: Keyframing Rework](https://projects.blender.org/blender/blender/issues/113278)
Christoph Lendenfeld added the
Module
Animation & Rigging
label 2023-12-07 16:18:44 +01:00
Christoph Lendenfeld added 1 commit 2023-12-07 16:18:53 +01:00
Christoph Lendenfeld added 1 commit 2023-12-07 16:24:04 +01:00
Christoph Lendenfeld added 1 commit 2023-12-07 16:26:42 +01:00
Hans Goudey reviewed 2023-12-07 16:33:03 +01:00
@ -15,11 +15,21 @@ struct FCurve;
namespace blender::animrig {
typedef struct KeyframeSettings {
Member

typedef is unnecessary in C++

`typedef` is unnecessary in C++
@ -21,1 +21,4 @@
KeyframeSettings get_keyframe_settings(const bool from_userprefs)
{
KeyframeSettings settings = {.keyframe_type = BEZT_KEYTYPE_KEYFRAME,
Member

Designated initializers are a C++ 20 feature and currently don't compile on Windows.
Usually you can do this:

KeyframeSettings settings{};
settings.keyframe_type = BEZT_KEYTYPE_KEYFRAME;
...
Designated initializers are a C++ 20 feature and currently don't compile on Windows. Usually you can do this: ``` KeyframeSettings settings{}; settings.keyframe_type = BEZT_KEYTYPE_KEYFRAME; ... ```
Author
Member

Oh good to know. Just for my sanity: This used to be possible with C right?

Oh good to know. Just for my sanity: This used to be possible with C right?
Member

Yes, and will be again when we can switch to C++ 20

Yes, and will be again when we can switch to C++ 20
Christoph Lendenfeld requested review from Sybren A. Stüvel 2023-12-07 16:45:50 +01:00
Christoph Lendenfeld added 1 commit 2023-12-07 16:46:38 +01:00
Sybren A. Stüvel approved these changes 2023-12-08 11:55:07 +01:00
Sybren A. Stüvel left a comment
Member

I like this PR a lot:

  • Merging related settings into a single struct.
  • Normalising the negative "NO_USERPREFS" flag to a positive "use_userprefs" bool.
  • Separating the concerns of determining which settings to use, and applying those settings.
  • And the actual goal of having more control over which settings are used.

Especially when only one setting was set by the flags, and the rest was supposed to come from the userprefs, the new code in this PR makes that so much clearer!

Just a few tiny nags that can be handled before landing.

I like this PR a lot: - Merging related settings into a single struct. - Normalising the negative "NO_USERPREFS" flag to a positive "use_userprefs" bool. - Separating the concerns of determining which settings to use, and applying those settings. - And the actual goal of having more control over which settings are used. Especially when only one setting was set by the flags, and the rest was supposed to come from the userprefs, the new code in this PR makes that so much clearer! Just a few tiny nags that can be handled before landing.
@ -15,11 +15,21 @@ struct FCurve;
namespace blender::animrig {
struct KeyframeSettings {

Since this is not part of the keyframe itself (in DNA), but "just" a useful way to pass this info to various functions, it might be good to document that. Just to set expectations when people find this struct.

Since this is not part of the keyframe itself (in DNA), but "just" a useful way to pass this info to various functions, it might be good to document that. Just to set expectations when people find this struct.
@ -18,0 +24,4 @@
/**
* Helper function to generate the KeyframeSettings struct.
*/
KeyframeSettings get_keyframe_settings(bool from_userprefs);

Document what is returned when from_userprefs == false.

Story time: As a kid I was confused by the DOOM graphics setting "Use 8-Bit Textures". When it is ON it makes total sense. But what happens when it's off? Would it go for 4-bit textures? Or 16-bit textures?

Document what is returned when `from_userprefs == false`. Story time: As a kid I was confused by the DOOM graphics setting "Use 8-Bit Textures". When it is ON it makes total sense. But what happens when it's off? Would it go for 4-bit textures? Or 16-bit textures?
Author
Member

good point, added a \param for it

good point, added a `\param` for it
@ -36,2 +35,2 @@
insert_vert_fcurve(fcu, {2.0f, 13.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF);
insert_vert_fcurve(fcu, {3.0f, 19.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF);
KeyframeSettings settings = get_keyframe_settings(false);

About this block & similar blocks below: since settings is only used by the block of code directly following it, personally I'd remove the newline under the get_keyframe_settings() call. No strong feelings either way, do with this as you please, I just wanted to voice a minor personal preference ;-)

About this block & similar blocks below: since `settings` is only used by the block of code directly following it, personally I'd remove the newline under the `get_keyframe_settings()` call. No strong feelings either way, do with this as you please, I just wanted to voice a minor personal preference ;-)
@ -128,3 +128,1 @@
fcu, {0.0f, 0.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_FAST | INSERTKEY_NO_USERPREF);
blender::animrig::insert_vert_fcurve(
fcu, {1.0f, 1.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_FAST | INSERTKEY_NO_USERPREF);
KeyframeSettings settings = get_keyframe_settings(false);

Many of these lines can actually use const KeyframeSettings settings = ...

Many of these lines can actually use `const KeyframeSettings settings = ...`
Christoph Lendenfeld added 2 commits 2023-12-08 12:50:11 +01:00
Author
Member

addressed comments by

  • adding a comment to the KeyframeSettings struct
  • mentioning the functionality of from_userprefs
  • making KeyframeSettings settings const where possible
  • removing the lines between creation and usage of settings
addressed comments by * adding a comment to the `KeyframeSettings` struct * mentioning the functionality of `from_userprefs` * making `KeyframeSettings settings` const where possible * removing the lines between creation and usage of `settings`
Christoph Lendenfeld merged commit 48d35bfe53 into main 2023-12-08 13:09:19 +01:00
Christoph Lendenfeld deleted branch refactor_insert_vert_arguments 2023-12-08 13:09:21 +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#115898
No description provided.