Anim: Change how Only Insert Needed works #115360

Merged
Christoph Lendenfeld merged 11 commits from ChrisLend/blender:refactor_insert_needed_logic into main 2023-11-30 14:45:59 +01:00

When keyframing with the Only Insert Needed flag enabled,
the code was able to delete keyframes in certain cases.
This behavior is removed and replaced with the following rules.

  • If there is a key on the current frame, and it has the same value, skip it.
  • If there is no key, but the FCurve evaluates to the same value, skip it.
  • Add a key in all other cases.

Remove that functionality for consistency and simplify the code around it.


Part of #113278: Anim: Keyframing Rework

When keyframing with the `Only Insert Needed` flag enabled, the code was able to delete keyframes in certain cases. This behavior is removed and replaced with the following rules. * If there is a key on the current frame, and it has the same value, skip it. * If there is no key, but the FCurve evaluates to the same value, skip it. * Add a key in all other cases. Remove that functionality for consistency and simplify the code around it. ---- Part of [#113278: Anim: Keyframing Rework](https://projects.blender.org/blender/blender/issues/113278)
Christoph Lendenfeld added the
Module
Animation & Rigging
label 2023-11-24 16:45:50 +01:00
Christoph Lendenfeld added 3 commits 2023-11-24 16:46:05 +01:00
Christoph Lendenfeld added 1 commit 2023-11-24 17:15:24 +01:00
Christoph Lendenfeld added 1 commit 2023-11-24 17:35:50 +01:00
Christoph Lendenfeld added 1 commit 2023-11-24 17:43:59 +01:00
Christoph Lendenfeld changed title from WIP: Anim: Change how Only Insert Needed works to Anim: Change how Only Insert Needed works 2023-11-24 17:53:22 +01:00
Christoph Lendenfeld added 2 commits 2023-11-28 12:29:37 +01:00
Christoph Lendenfeld requested review from Nathan Vegdahl 2023-11-28 12:40:27 +01:00
Christoph Lendenfeld added 1 commit 2023-11-28 12:40:34 +01:00
Nathan Vegdahl requested changes 2023-11-30 11:47:55 +01:00
Nathan Vegdahl left a comment
Member

This PR is incredible, ha ha. So much simpler and more obvious. And in testing this makes the "Only Insert Needed" feature actually behave the way I always expected it to! Can't wait to land this.

Just some questions and minor nits in the code.

This PR is incredible, ha ha. So much simpler and more obvious. And in testing this makes the "Only Insert Needed" feature actually behave the way I always expected it to! Can't wait to land this. Just some questions and minor nits in the code.
@ -257,3 +241,1 @@
for (int i = 0; i < totCount; i++) {
float prevPosi = 0.0f, prevVal = 0.0f;
float beztPosi = 0.0f, beztVal = 0.0f;
const int diff_ulp = 32;
Member

How did you arrive at this value? I don't mean that you need a super strong justification or anything, mostly just curious.

How did you arrive at this value? I don't mean that you need a super strong justification or anything, mostly just curious.
Author
Member

honestly just a wild guess. 32 numbers difference seemed sufficient for me
Correct me if you think this should be different.

honestly just a wild guess. 32 numbers difference seemed sufficient for me Correct me if you think this should be different.
Member

No, 32 should be fine. I think elsewhere in the code base it's usually 64, but as far as I can tell that's equally arbitrary, and people have basically just been copy/pasting it.

No, 32 should be fine. I think elsewhere in the code base it's usually 64, but as far as I can tell that's equally arbitrary, and people have basically just been copy/pasting it.
nathanvegdahl marked this conversation as resolved
@ -322,1 +247,3 @@
}
if (replace) {
/* If there is already a key, we only need to modify it if the proposed value is different. */
return !compare_ff_relative(fcu->bezt[bezt_index].vec[1][1], value, FLT_EPSILON, diff_ulp);
Member

Is there a particular reason to use compare_ff_relative() for a key that already exists, rather than just a straight == comparison? My intuition is that since there's already a key there, the worst-case with a false positive is that the existing key gets slightly adjusted by a minuscule amount, which seems fine. And then we avoid any risk of false negatives. But I could be missing something.

Is there a particular reason to use `compare_ff_relative()` for a key that already exists, rather than just a straight `==` comparison? My intuition is that since there's already a key there, the worst-case with a false positive is that the existing key gets slightly adjusted by a minuscule amount, which seems fine. And then we avoid any risk of false negatives. But I could be missing something.
Author
Member

Fair point. Changed it to a simple !=

Fair point. Changed it to a simple `!=`
nathanvegdahl marked this conversation as resolved
@ -401,3 +313,3 @@
if (flag & INSERTKEY_NEEDED) {
static short insert_mode = new_key_needed(fcu, cfra, curval);
const bool key_needed = new_key_needed(fcu, cfra, curval);
Member

Since this variable isn't used except inside the if condition, and since new_key_needed() is already named very clearly, I'd say just inline the function call into the if condition.

Since this variable isn't used except inside the if condition, and since `new_key_needed()` is already named very clearly, I'd say just inline the function call into the if condition.
Author
Member

good point

good point
nathanvegdahl marked this conversation as resolved
Christoph Lendenfeld added 2 commits 2023-11-30 14:29:21 +01:00
First-time contributor
  • If there is no key, but the FCurve evaluates to the same value, skip it.

that is, in this case, the key will not be inserted?

> * If there is no key, but the FCurve evaluates to the same value, skip it. that is, in this case, the key will not be inserted? <video src="/attachments/88c2974a-4114-44e2-b444-6799af4b1943" title="2023-11-30 16-36-08.mp4" controls></video>
Christoph Lendenfeld requested review from Nathan Vegdahl 2023-11-30 14:41:17 +01:00
Author
Member

@sanek122005 yes that is correct.

But the option will be split in a subsequent patch for auto-keying and manual-keying.
Because when you are inserting keys manually you usually want to get the key regardless of the surrounding values.

Edit: PR is almost ready, just waiting for this to land first. #115525: WIP: Anim: Separate keying flags

@sanek122005 yes that is correct. But the option will be split in a subsequent patch for auto-keying and manual-keying. Because when you are inserting keys manually you usually want to get the key regardless of the surrounding values. Edit: PR is almost ready, just waiting for this to land first. [#115525: WIP: Anim: Separate keying flags](https://projects.blender.org/blender/blender/pulls/115525)
Nathan Vegdahl approved these changes 2023-11-30 14:44:06 +01:00
Nathan Vegdahl left a comment
Member

Looks good to me!

Looks good to me!
Christoph Lendenfeld merged commit 83287624bc into main 2023-11-30 14:45:59 +01:00
Christoph Lendenfeld deleted branch refactor_insert_needed_logic 2023-11-30 14:46:01 +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#115360
No description provided.