Anim: Bake Channel operator #111263
No reviewers
Labels
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
4 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#111263
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "ChrisLend/blender:bake_channel_operator"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This is a replacement for the workflow that uses "Bake Curve" and "Unbake Curve" to quickly generate dense key data.
Compared to the existing workflow it has the advantage of allowing the user more control over the key types, and distance between keys, as well as the frame range affected.
Operator options
The operator can be found in the Graph Editor under
Channel->Bake Channels
Part of this task
#111050: Better Baking in the Graph Editor
Animation: Bake Channel operatorto WIP: Animation: Bake Channel operator@blender-bot package
Package build started. Download here when ready.
WIP: Animation: Bake Channel operatorto Animation: Bake Channel operator@blender-bot package
Package build started. Download here when ready.
@blender-bot package
Package build started. Download here when ready.
@blender-bot package
Package build started. Download here when ready.
Animation: Bake Channel operatorto Anim: Bake Channel operatorFound a couple of bugs while testing:
And I have a couple of questions about functionality:
thanks for having a look at it
fixed that by clamping the range
The hardmin is 0.01 so it will get quite slow on high frame count. But I am not sure what the minimum number should be. I thought about setting it to 0.1 (so 10 subframes) but it feels like an arbitrary number so I kept it at 0.01 because I don't see anyone wanting more than 100 subframes. Users that venture into that realm better be careful. Let me know what you think
yes good point. Will make it inclusive
Made the default to remove in range.
Still kept the option to not remove any keys. While I don't have an immediate use case, it feels more complete to have it, and it doesn't add much complexity.
Generally looking good! But there are some changes I'd like.
@ -4326,0 +4327,4 @@
static const EnumPropertyItem channel_bake_key_options[] = {
{CHANNEL_BAKE_KEEP, "KEEP", 0, "Keep", "Keep the current key types"},
{BEZT_IPO_BEZ, "BEZIER", 0, "Bezier", "New keys will be beziers"},
I'd prefer new constants for this enum, rather than awkwardly having just one that's new and defined arbitrarily high to avoid conflicting with the others. It's not as convenient in other code, because then you have to map between the two sets of constants later. But it feels cleaner to me that way.
not sure I agree with this. It would add a level of indirection to the enum which I think isn't needed. Atm it is quite clear what key types the options correspond to since they use the same constants.
I agree it does feel a bit weird, but I feel like it is the better option
That's fair. Let's leave it as-is, then. Thanks!
@ -4326,0 +4449,4 @@
/* Identifiers */
ot->name = "Bake Channels";
ot->idname = "ANIM_OT_channels_bake";
ot->description = "Create keyframes on the F-Curves of selected channels";
This description feels non-specific to me. There are a lot of operators that create key frames.
On the other hand, I'm struggling to think of a succinct alternative that doesn't suffer similar problems.
I think I made it better
Create keyframes following the current shape of F-Curves of selected channels
The distinction to other keyframe adding operators is that this one looks at the shape of the current curve, so I think it makes sense to mention that
Yeah, that's great. Thanks!
@ -4326,0 +4480,4 @@
RNA_def_enum(ot->srna,
"remove_existing",
channel_bake_remove_options,
int(BakeCurveRemove::REMOVE_NONE),
If we do keep these options as-are, I think
REMOVE_IN_RANGE
is a better default. I don't think people usually want to leave behind the old keys in the range being baked.@ -4326,0 +4482,4 @@
channel_bake_remove_options,
int(BakeCurveRemove::REMOVE_NONE),
"Remove Existing Keys",
"If enabled removes the keys that currently make up the curve");
This description reads like it's a boolean option.
indeed it used to be a boolean. changed it to be more representative of the enum
While that's true, this is also accidentally quadratic, because on every removal (
BKE_fcurve_delete_key
) it has to shift all the keys after the removed key back. If you iterate forward and keep track of the gap as it's created, you can shift keys over the gap as you go for linear runtime.Oops, I think a change got pushed while I was reviewing, so these last two comments got detached. I'll resubmit them.
This is also accidentally quadratic (actually slightly worse, because it additionally does a binary search to find where to insert each key), and does an allocation and full copy of the f-curve's entire bezt data on every insert.
However, this one is a bit dicier (but certainly not impossible) to make linear. So maybe it's better to leave this one as an optimization for later.
(Re-attached comments.)
@ -1219,0 +1222,4 @@
const BakeCurveRemove removal_mode)
{
/* Iterating backwards to not cause issues because the bezt array is modified during the
* loop. */
While that's true, this is also accidentally quadratic, because on every removal (BKE_fcurve_delete_key) it has to shift all the keys after the removed key back. If you iterate forward and keep track of the gap as it's created, you can shift keys over the gap as you go for linear runtime.
solved by adding a new function
BKE_fcurve_delete_keys
that removes a range of keys in one swoop@ -1219,0 +1265,4 @@
}
for (int i = 0; i < sample_count; i++) {
insert_vert_fcurve(
This is also accidentally quadratic (actually slightly worse, because it additionally does a binary search to find where to insert each key), and does an allocation and full copy of the f-curve's entire bezt data on every insert.
However, this one is a bit dicier (but certainly not impossible) to make linear. So maybe it's better to leave this one as an optimization for later.
I ran it through a profiler. 90% of the time was spent on
BKE_fcurve_recalc_handles
I changed the flag to
INSERTKEY_FAST
so it doesn't recalculate on every key insertNow 83% is spent on
__memcpy_avx_unaligned_erms
which I have no Idea where that comes fromOoooh, got it. Yeah, since you have to manually type it in for < 1.0, that's probably fine.
With some testing, I also suspect this is running into the quadratic performance I mentioned in the code review. Just counting seconds off, the time it takes to bake seems to increase super-linearly with the number of baked keys as the step size gets smaller.
My concern isn't the complexity, but rather that it makes the drop-down initially confusing (or at least it was to me). But maybe it could be made clearer by just changing the naming a bit? Like, "In Range" -> "Old In Range". And/or maybe it would be easier to grok if it was two boolean options ("Remove Keys In Range" and "Remove Keys Outside Range") rather than a single four-way option.
@nathanvegdahl I addressed the review comments but I am not quite ready for another review. The operator just runs too poorly on heavy scenes. The profiler tells me its the key insertion that eats the time and it makes sense since for every insert it reallocates the bezt array and copies data over.
I will look into a better way
That makes sense.
I was thinking a good approach might be to make a new function that takes two fcurves and merges them into a new one. That way all the complexity can be contained there (and it seems like the kind of utility function that would be generally useful). Then in the baking code you could start by creating two fcurves: the fcurve with the desired keys removed, and the fcurve with the new baked keys. And then you finish by simply merging them.
@nathanvegdahl I implemented a function
BKE_bezier_array_merge
. Now the thing runs on my heavy test scene.It's not realtime, but profiling it, most of the time is taken up by recalculating the handles. The merge function is insanely fast. I was quite surprised by that. The first block on the left above bake_fcurve is the merge
It might be possible to use that in other places as well.
@blender-bot package
@BClark can you review this once more. Should be super fast now, even on heavy scenes
Package build started. Download here when ready.
Wow it works great!!!! That is so nice to have the control over the modifier bake and to be able to replace keys!!!!
Testing this was a joy. So much faster now! Awesome work.
There are just a few things I think need to be addressed, but it's really close to being ready.
@ -483,11 +484,23 @@ bool BKE_fcurve_bezt_subdivide_handles(struct BezTriple *bezt,
*/
void BKE_fcurve_bezt_shrink(struct FCurve *fcu, int new_totvert);
/** In case of keys on identical frames, "a" takes precedence. Allocates a new array of BezTriple.
I think we should start holding ourselves to a bit of a higher standard for API documentation. And I say this for myself as well, not at all picking on you. With that in mind:
a
andb
together into a new bezier key array." It can feel redundant with the function name, but I think having a consistent flow for all documentation is useful, and I believe that's what Doxygen expects anyway.a
orb
."a
andb
in this case.@ -486,0 +488,4 @@
* Caller is expected to free data.
* Assumes that both arrays are sorted for the x-position. */
BezTriple *BKE_bezier_array_merge(
BezTriple *a, int size_a, BezTriple *b, int size_b, int *merged_size);
Can
a
andb
beconst
here?Also, IIRC Blender uses the convention of prefixing "out" arguments with
r_
(for "return"). Somerged_size
->r_merged_size
.@ -488,3 +495,4 @@
*/
void BKE_fcurve_delete_key(struct FCurve *fcu, int index);
/** Delete an index range of keyframes from an F-curve. This is more performant than individually
Since this is for performance, I think it makes sense to document the performance characteristics of this as well: performance is independent of the number of keys being removed, and on average O(N) with respect to the total number of keys remaining after removal.
I think the performance analysis you added is mistaken:
The number of keys removed doesn't affect performance at all, I don't think. The thing that affects the performance linearly is the number of keys that follow the removed range of keys, since those have to be shifted backwards to fill the gap.
So I think it's fine to say "O(N) with respect to the number of keys in
fcu
", because that's roughly true. In practice it's a little more involved than that, but it's a good enough summary analysis to inform the caller of the main impacting factor.that is true, changed it :)
@ -1708,0 +1737,4 @@
while (iterator_a < size_a || iterator_b < size_b) {
if (iterator_a >= size_a) {
memcpy(&large_array[*merged_size], &b[iterator_b], sizeof(BezTriple));
iterator_b++;
If I understand correctly, this case and the one immediately below are when one or the other of the two arrays are completely merged in already, and the remaining keys in the other just need to be appended to the end. If that's correct, then I think these can be made a bit faster by just memcopying the the remaining keys in one go, rather than one at a time.
good point, changed that.
This also improves readability a bit because now I can
break
from the if statement@ -1708,0 +1743,4 @@
memcpy(&large_array[*merged_size], &a[iterator_a], sizeof(BezTriple));
iterator_a++;
}
else if (a[iterator_a].vec[1][0] == b[iterator_b].vec[1][0]) {
Should we be using some kind of epsilon threshold for the equality comparison here? Elsewhere in Blender's code I seem to recall there being some limit of how close keys can be before they're considered the same, and we should probably try to be consistent with that.
good point, used
compare_ff_relative
withBEZT_BINARYSEARCH_THRESH
Looks good.
A side-thought: in the future, I wonder if we should track down all the places where key x-coordinates are compared for equality, and make a single function for that, to ensure it gets done consistently everywhere (which I strongly suspect it currently isn't). But certainly not something for this PR.
@nathanvegdahl thanks for the review, should be addressed now.
Keep in mind I did remove the option to keep the keyframe interpolation with the latest update.
This wasn't working anymore with the merge function. Instead it defaults to Bezier.
@ -491,0 +505,4 @@
* removing keys.
* Has a complexity of O(N) with respect to number of keys in `fcu`.
*
* \param index_range is exclusive.
Very minor nit: I'm pretty sure anyone will already know what you mean, but "right exclusive" might be slightly clearer, emphasizing that the range is only exclusive on the right.
yeah that's true, changed now
You mean the keyframe interpolation of the new baked frames? Testing it out, it still seems to keep the keyframe interpolation of the frames outside of the bake range. I think that's fine, and is basically what I would expect anyway.
One thing I noticed while testing is that when the keys you're baking are constant, the right-side behavior feels weird due to the right-most key being bezier. Here's a video demonstrating that:
This weirdness doesn't happen for the left side because the interpolation mode of a key actually means the interpolation mode of the segment that follows it. So I wonder if it makes sense to think of this in terms of segments, in which case the right-most baked key should take on the interpolation mode of the pre-bake key that's <= to it on the x axis. That way unbaked segments keep their interpolation mode.
Maybe that's more trouble than it's worth, though.
@nathanvegdahl wasnn't sure at first, but now that I've implemented it, it feels like the correct way to do it.
Left a comment because it's not entirely obvious what the code is doing. Let me know if it is clear.
This does create a bit of a weird behavior though when you only bake a single key, the key doesn't have the interpolation defined in the operator.
In testing, it now works as I would expect:
Ah, that's a good point. I think that's fine, though, because if the user only wants to bake a single key, that's otherwise equivalent to just inserting a new key... so they can just do that, then.
One last thing: I want to re-raise the question of removing the option to keep the keys within the baked range. It's not clear to me what the concrete use case is, and if we get rid of that then the whole removal option reduces to simply whether the keys outside the bake range are kept or not, which seems a lot simpler and clearer to me. @BClark Do you have any thoughts on this?
@nathanvegdahl a bit of context on that in the parent todo
#111050: Better Baking in the Graph Editor
It felt more complete to me to be able to have complete control over where keys are removed.
I can't think of a concrete use case, but it doesn't add a lot of complexity imo
From that thread, it looks like @BClark was just asking to choose to remove the keys outside of the range or not.
I agree that it doesn't add much complexity to the code. But from a user perspective it definitely takes some extra brain power to figure out what each of the four options do, and then which one you want. Whereas "keep/discard the keys outside the baking range" is really fast to grasp and choose. So if in practice those are the only two options people are going to use anyway, I think it's a UX win to only expose those two options.
But as always, I may be missing something.
Would this be worth discussing at the next module meeting, to get peoples' thoughts? Because other than deciding this one thing, this is ready to land, I think.
Let me re-test it with that question in mind
Let me re-test it with that question in mind
@nathanvegdahl updated to use boolean property
internally the enum to specify exactly what to remove still exists. It's just no longer exposed to the user
@ -4313,0 +4476,4 @@
RNA_def_boolean(ot->srna,
"remove_outside_range",
false,
"Remove Existing Keys",
It might just be me, but "Remove Existing Keys" makes me feel like no keys will be removed if it's unchecked, when in reality the inside-range keys are always removed.
I think "Remove Keys Outside Range" might make it more clear that the only behavior that changes is what happens to outside-range keys. Unfortunately, that does leave it ambiguous what happens to the inside-range keys. But at least it leaves the user with the question of what happens to those keys, which they can then find out via testing or documentation. Whereas "Remove Existing Keys" feels to me like it answers that question, but incorrectly.
Then again, I could be the odd one out here.
That was my first idea, but the label is so long it is cut off in the redo panel. So I tried finding something more concise.
I think the same logic of "let the user play with it to learn" applies to "Remove Existing Keys" as well. By default it will keep keys outside the given range and quickly toggling the property should be very obvious.
Let me know what you think
Oh, that makes sense. Nuts. How do you feel about just "Remove Outside Range" or "Clear Outside Range"? Those don't include "keys" in the label, but that can be made clear in the tool tip, or just by toggling it.
Alternatively, can we make the redo panel wider for this operator?
renamed to "Remove Outside Range" :)
Just one final nit about the label (also applies to the tooltip) of the
remove_outside_range
parameter. But I don't feel strongly about it, so feel free to land if you prefer it as-is.Looks good to me! I already approved, so feel free to merge. :-)
Great work!
Edit: oops, didn't notice that you did already merge (which is great). Need to read the activity more carefully, ha ha.