Anim: Bake Channel operator #111263

Merged
Christoph Lendenfeld merged 49 commits from ChrisLend/blender:bake_channel_operator into main 2023-12-14 11:35:32 +01:00

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

  • Range: the range that will be baked. Defaults to the scene range or preview range.
  • Step: Distance between keyframes. Can be used to bake on 2s or even bake to subframes.
  • Remove Existing Keys: Boolean option that if enabled also removes keys outside the specified baking range
  • Interpolation Type: Choose which interpolation type new keys should have, e.g. Constant or Bezier
  • Bake Modifiers: If true bakes the effect of the modifier stack to keys and deletes the modifier stack. If false, the code disables the modifiers before baking, so the resulting keys will behave as if the modifiers didn't exist

The operator can be found in the Graph Editor under Channel->Bake Channels


Part of this task
#111050: Better Baking in the Graph Editor

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 * Range: the range that will be baked. Defaults to the scene range or preview range. * Step: Distance between keyframes. Can be used to bake on 2s or even bake to subframes. * Remove Existing Keys: Boolean option that if enabled also removes keys outside the specified baking range * Interpolation Type: Choose which interpolation type new keys should have, e.g. Constant or Bezier * Bake Modifiers: If true bakes the effect of the modifier stack to keys and deletes the modifier stack. If false, the code disables the modifiers before baking, so the resulting keys will behave as if the modifiers didn't exist The operator can be found in the Graph Editor under `Channel->Bake Channels` ------ Part of this task [#111050: Better Baking in the Graph Editor](https://projects.blender.org/blender/blender/issues/111050)
Christoph Lendenfeld added the
Module
Animation & Rigging
label 2023-08-18 14:48:42 +02:00
Christoph Lendenfeld added 4 commits 2023-08-18 14:48:54 +02:00
Christoph Lendenfeld changed title from Animation: Bake Channel operator to WIP: Animation: Bake Channel operator 2023-08-18 14:49:02 +02:00
Author
Member

@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/PR111263) when ready.
Christoph Lendenfeld added 2 commits 2023-09-01 11:07:02 +02:00
Christoph Lendenfeld added 1 commit 2023-09-01 11:11:38 +02:00
Christoph Lendenfeld changed title from WIP: Animation: Bake Channel operator to Animation: Bake Channel operator 2023-09-01 11:16:49 +02:00
Christoph Lendenfeld requested review from Brad Clark 2023-09-01 11:17:25 +02:00
Christoph Lendenfeld requested review from Nathan Vegdahl 2023-09-01 11:17:36 +02:00
Christoph Lendenfeld added 1 commit 2023-09-01 11:18:54 +02:00
rename key_type to interpolation_type
Some checks failed
buildbot/vexp-code-patch-coordinator Build done.
8e784d4331
Christoph Lendenfeld added this to the Animation & Rigging project 2023-09-01 11:19:06 +02:00
Author
Member

@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/PR111263) when ready.
Christoph Lendenfeld added 1 commit 2023-09-12 11:05:45 +02:00
Christoph Lendenfeld added 2 commits 2023-09-14 12:11:38 +02:00
Author
Member

@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/PR111263) when ready.
Christoph Lendenfeld added 2 commits 2023-09-15 11:22:46 +02:00
Author
Member

@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/PR111263) when ready.
Christoph Lendenfeld changed title from Animation: Bake Channel operator to Anim: Bake Channel operator 2023-09-15 11:57:19 +02:00
Christoph Lendenfeld added 1 commit 2023-09-21 10:49:30 +02:00
Member

Found a couple of bugs while testing:

  • If you set the start range > end range, Blender crashes.
  • If you set the frame step <= 0.0, Blender freezes.

And I have a couple of questions about functionality:

  • This appears to treat the frame range as exclusive on the right. I think we may want it to be inclusive on both sides, because right now it just feels like the last key doesn't get baked. This is particularly jarring when "Remove Existing" is set to "All".
  • Regarding the "Remove Existing" option, it's not clear to me why someone would ever not want to remove the in-range keys, since the point is to bake that range instead. I get that with the frame step set > 1 it has an effect. And functionally it's not a problem to have the option, of course. But I was initially confused by the set of options because of this, and I think it might be confusing to others as well. So if there's not a strong use case, maybe we can change the option to only be about removing the out-of-range keys or not.
Found a couple of bugs while testing: - If you set the start range > end range, Blender crashes. - If you set the frame step <= 0.0, Blender freezes. And I have a couple of questions about functionality: - This appears to treat the frame range as exclusive on the right. I think we may want it to be inclusive on both sides, because right now it just feels like the last key doesn't get baked. This is particularly jarring when "Remove Existing" is set to "All". - Regarding the "Remove Existing" option, it's not clear to me why someone would ever *not* want to remove the in-range keys, since the point is to bake that range instead. I get that with the frame step set > 1 it has an effect. And functionally it's not a problem to have the option, of course. But I was initially confused by the set of options because of this, and I think it might be confusing to others as well. So if there's not a strong use case, maybe we can change the option to only be about removing the out-of-range keys or not.
Christoph Lendenfeld added 1 commit 2023-09-21 16:25:29 +02:00
Christoph Lendenfeld added 1 commit 2023-09-21 17:01:58 +02:00
Christoph Lendenfeld added 1 commit 2023-09-21 17:08:55 +02:00
Author
Member

thanks for having a look at it

  • If you set the start range > end range, Blender crashes.

fixed that by clamping the range

  • If you set the frame step <= 0.0, Blender freezes.

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

  • This appears to treat the frame range as exclusive on the right. I think we may want it to be inclusive on both sides, because right now it just feels like the last key doesn't get baked. This is particularly jarring when "Remove Existing" is set to "All".

yes good point. Will make it inclusive

  • Regarding the "Remove Existing" option, it's not clear to me why someone would ever not want to remove the in-range keys, since the point is to bake that range instead. I get that with the frame step set > 1 it has an effect. And functionally it's not a problem to have the option, of course. But I was initially confused by the set of options because of this, and I think it might be confusing to others as well. So if there's not a strong use case, maybe we can change the option to only be about removing the out-of-range keys or not.

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.

thanks for having a look at it > - If you set the start range > end range, Blender crashes. fixed that by clamping the range > - If you set the frame step <= 0.0, Blender freezes. 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 > - This appears to treat the frame range as exclusive on the right. I think we may want it to be inclusive on both sides, because right now it just feels like the last key doesn't get baked. This is particularly jarring when "Remove Existing" is set to "All". yes good point. Will make it inclusive > - Regarding the "Remove Existing" option, it's not clear to me why someone would ever *not* want to remove the in-range keys, since the point is to bake that range instead. I get that with the frame step set > 1 it has an effect. And functionally it's not a problem to have the option, of course. But I was initially confused by the set of options because of this, and I think it might be confusing to others as well. So if there's not a strong use case, maybe we can change the option to only be about removing the out-of-range keys or not. 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.
Nathan Vegdahl requested changes 2023-09-21 17:12:38 +02:00
Nathan Vegdahl left a comment
Member

Generally looking good! But there are some changes I'd like.

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"},
Member

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.

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.
Author
Member

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

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
Member

That's fair. Let's leave it as-is, then. Thanks!

That's fair. Let's leave it as-is, then. Thanks!
nathanvegdahl marked this conversation as resolved
@ -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";
Member

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.

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.
Author
Member

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

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
Member

Yeah, that's great. Thanks!

Yeah, that's great. Thanks!
nathanvegdahl marked this conversation as resolved
@ -4326,0 +4480,4 @@
RNA_def_enum(ot->srna,
"remove_existing",
channel_bake_remove_options,
int(BakeCurveRemove::REMOVE_NONE),
Member

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.

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.
nathanvegdahl marked this conversation as resolved
@ -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");
Member

This description reads like it's a boolean option.

This description reads like it's a boolean option.
Author
Member

indeed it used to be a boolean. changed it to be more representative of the enum

indeed it used to be a boolean. changed it to be more representative of the enum
nathanvegdahl marked this conversation as resolved
Member

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.

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.
Member

Oops, I think a change got pushed while I was reviewing, so these last two comments got detached. I'll resubmit them.

Oops, I think a change got pushed while I was reviewing, so these last two comments got detached. I'll resubmit them.
nathanvegdahl marked this conversation as resolved
Member

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.

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.
nathanvegdahl marked this conversation as resolved
Nathan Vegdahl requested changes 2023-09-21 17:18:01 +02:00
Nathan Vegdahl left a comment
Member

(Re-attached comments.)

(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. */
Member

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.

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.
Author
Member

solved by adding a new function BKE_fcurve_delete_keys that removes a range of keys in one swoop

solved by adding a new function `BKE_fcurve_delete_keys` that removes a range of keys in one swoop
nathanvegdahl marked this conversation as resolved
@ -1219,0 +1265,4 @@
}
for (int i = 0; i < sample_count; i++) {
insert_vert_fcurve(
Member

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.

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.
Author
Member

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 insert
Now 83% is spent on __memcpy_avx_unaligned_erms which I have no Idea where that comes from

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 insert Now 83% is spent on `__memcpy_avx_unaligned_erms` which I have no Idea where that comes from
Member

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

Ooooh, 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.

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.

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.

> 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 Ooooh, 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. > 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. 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.
Christoph Lendenfeld added 1 commit 2023-09-22 11:15:08 +02:00
Christoph Lendenfeld added 1 commit 2023-09-22 11:35:43 +02:00
Christoph Lendenfeld added 1 commit 2023-09-22 11:48:02 +02:00
Christoph Lendenfeld added 1 commit 2023-09-22 11:54:22 +02:00
Christoph Lendenfeld added 1 commit 2023-09-22 12:30:45 +02:00
Christoph Lendenfeld added 2 commits 2023-09-22 15:02:17 +02:00
Author
Member

@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

@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
Member

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.

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.

> 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. 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.
Christoph Lendenfeld added 1 commit 2023-09-26 09:16:29 +02:00
Christoph Lendenfeld added 1 commit 2023-11-17 10:12:14 +01:00
Christoph Lendenfeld added 4 commits 2023-11-17 12:44:29 +01:00
Author
Member

@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.

image

@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. ![image](/attachments/789cb2ec-e38e-43c1-b51d-b06c06d61ac6)
Christoph Lendenfeld requested review from Nathan Vegdahl 2023-11-17 12:47:52 +01:00
Christoph Lendenfeld added this to the 4.1 milestone 2023-11-17 12:52:09 +01:00
Author
Member

@blender-bot package

@BClark can you review this once more. Should be super fast now, even on heavy scenes

@blender-bot package @BClark can you review this once more. Should be super fast now, even on heavy scenes
Member

Package build started. Download here when ready.

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

Wow it works great!!!! That is so nice to have the control over the modifier bake and to be able to replace keys!!!!

Wow it works great!!!! That is so nice to have the control over the modifier bake and to be able to replace keys!!!!
Nathan Vegdahl requested changes 2023-12-07 12:08:52 +01:00
Nathan Vegdahl left a comment
Member

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.

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.
Member

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:

  • The first line should be a quick summary description of what the function does. Something like, "Merge keyframes from a and b 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.
  • Since return values aren't named, I think it makes sense to always add documentation for that unless it's extremely trivial. "Returns the newly allocated merged array." Or something like that.
  • Your documentation of the invariants is great! 👍 Nit: rather than "Caller is expected to free data," maybe "This function does not free a or b."
  • For potentially performance-sensitive functions like this, it wouldn't hurt to document its computational complexity, which I believe is O(N) with respect to the length of a and b in this case.
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: - The first line should be a quick summary description of what the function does. Something like, "Merge keyframes from `a` and `b` 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. - Since return values aren't named, I think it makes sense to always add documentation for that unless it's *extremely* trivial. "Returns the newly allocated merged array." Or something like that. - Your documentation of the invariants is great! 👍 Nit: rather than "Caller is expected to free data," maybe "This function does not free `a` or `b`." - For potentially performance-sensitive functions like this, it wouldn't hurt to document its computational complexity, which I believe is O(N) with respect to the length of `a` and `b` in this case.
nathanvegdahl marked this conversation as resolved
@ -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);
Member

Can a and b be const here?

Also, IIRC Blender uses the convention of prefixing "out" arguments with r_ (for "return"). So merged_size -> r_merged_size.

Can `a` and `b` be `const` here? Also, IIRC Blender uses the convention of prefixing "out" arguments with `r_` (for "return"). So `merged_size` -> `r_merged_size`.
nathanvegdahl marked this conversation as resolved
@ -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
Member

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.

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.
Member

I think the performance analysis you added is mistaken:

Has a complexity of O(N) with respect to the amount of keys removed.

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.

I think the performance analysis you added is mistaken: > Has a complexity of O(N) with respect to the amount of keys removed. 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.
Author
Member

that is true, changed it :)

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++;
Member

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.

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.
Author
Member

good point, changed that.
This also improves readability a bit because now I can break from the if statement

good point, changed that. This also improves readability a bit because now I can `break` from the if statement
nathanvegdahl marked this conversation as resolved
@ -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]) {
Member

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.

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.
Author
Member

good point, used compare_ff_relative with BEZT_BINARYSEARCH_THRESH

good point, used `compare_ff_relative` with `BEZT_BINARYSEARCH_THRESH`
Member

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.

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 marked this conversation as resolved
Christoph Lendenfeld added 5 commits 2023-12-07 13:08:08 +01:00
Christoph Lendenfeld added 1 commit 2023-12-07 13:13:32 +01:00
Christoph Lendenfeld added 1 commit 2023-12-07 13:16:29 +01:00
Author
Member

@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.

@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.
Christoph Lendenfeld requested review from Nathan Vegdahl 2023-12-07 13:20:27 +01:00
Christoph Lendenfeld added 1 commit 2023-12-07 14:28:14 +01:00
Nathan Vegdahl reviewed 2023-12-07 16:51:44 +01:00
@ -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.
Member

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.

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.
Author
Member

yeah that's true, changed now

yeah that's true, changed now
nathanvegdahl marked this conversation as resolved
Christoph Lendenfeld added 1 commit 2023-12-07 16:57:22 +01:00
Member

Keep in mind I did remove the option to keep the keyframe interpolation with the latest update.

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.

> Keep in mind I did remove the option to keep the keyframe interpolation with the latest update. 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: <video src="/attachments/113a2ef4-f6b0-4d61-826b-89a5ef48a7d8" title="right_side_weirdness.mp4" controls></video> 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.
Christoph Lendenfeld added 3 commits 2023-12-08 11:56:39 +01:00
Author
Member

@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.

@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.
Member

In testing, it now works as I would expect:

  • If the right-most baked key is on a segment, it gets the interpolation of that segment.
  • Otherwise it gets the interpolation specified by the operator.

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.

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?

In testing, it now works as I would expect: - If the right-most baked key is on a segment, it gets the interpolation of that segment. - Otherwise it gets the interpolation specified by the operator. > 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. 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?
Author
Member

@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

@nathanvegdahl a bit of context on that in the parent todo [#111050: Better Baking in the Graph Editor](https://projects.blender.org/blender/blender/issues/111050) 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
Christoph Lendenfeld added 2 commits 2023-12-08 13:21:32 +01:00
Member

a bit of context on that in the parent todo
#111050: Better Baking in the Graph Editor

From that thread, it looks like @BClark was just asking to choose to remove the keys outside of the range or not.

I can't think of a concrete use case, but it doesn't add a lot of complexity imo

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.

> a bit of context on that in the parent todo > #111050: Better Baking in the Graph Editor From that thread, it looks like @BClark was just asking to choose to remove the keys outside of the range or not. > I can't think of a concrete use case, but it doesn't add a lot of complexity imo 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.
Member

Let me re-test it with that question in mind

Let me re-test it with that question in mind
Brad Clark closed this pull request 2023-12-12 05:03:33 +01:00
Member

Let me re-test it with that question in mind

Let me re-test it with that question in mind
Brad Clark reopened this pull request 2023-12-12 05:03:59 +01:00
Christoph Lendenfeld added 2 commits 2023-12-12 14:55:06 +01:00
Author
Member

@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

@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
Christoph Lendenfeld added 1 commit 2023-12-12 15:00:23 +01:00
Nathan Vegdahl reviewed 2023-12-14 10:42:37 +01:00
@ -4313,0 +4476,4 @@
RNA_def_boolean(ot->srna,
"remove_outside_range",
false,
"Remove Existing Keys",
Member

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.

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.
Author
Member

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

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
Member

but the label is so long it is cut off in the redo panel

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?

> but the label is so long it is cut off in the redo panel 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?
Author
Member

renamed to "Remove Outside Range" :)

renamed to "Remove Outside Range" :)
nathanvegdahl marked this conversation as resolved
Nathan Vegdahl approved these changes 2023-12-14 10:44:33 +01:00
Nathan Vegdahl left a comment
Member

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.

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.
Christoph Lendenfeld added 2 commits 2023-12-14 11:15:48 +01:00
Christoph Lendenfeld merged commit 1e931f5bd7 into main 2023-12-14 11:35:32 +01:00
Christoph Lendenfeld deleted branch bake_channel_operator 2023-12-14 11:35:34 +01:00
Member

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.

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