Anim: implement 3D viewport keyframing functionality for the Animation data-block #120428
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
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#120428
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "nathanvegdahl/blender:baklava_keyframing"
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?
(Continues and supersedes #119669)
This PR has been abandoned in favor of splitting the same changes into multiple smaller PRs:
SingleKeyingResult
, sothat the failure cases for the new animation system can be propagated and reported to the user.
insert_vert_fcurve()
, since that function is thecommon code path between the old and new animation system, and thus we can avoid duplicating
that logic. It also just generally seems like a reasonable place for it to be.
animation system take the same top-level code path.
TODO
CombinedKeyingResult
is currently mostly stubbed out, and needs to be properly filled in.KeyframeStrip::keyframe_insert()
.For future PRs (previously part of TODO above):
insert_key_rna()
should likely be merged withinsert_keyframe()
.insert_key_rna()
currently keys all elements of an array property (e.g. object location), but should instead take each element of the property separately to allow individual keying.6179a5d1ac
toa75d2d5cb5
WIP: Anim: implement keyframing functionality for the Animation data-blockto WIP: Anim: implement 3D viewport keyframing functionality for the Animation data-blockINSERTKEY_NEEDED
flag 831c4952bf@ -493,3 +533,3 @@
for (n = 1, fp = value_cache; n < range && fp; n++, fp++) {
blender::animrig::insert_vert_fcurve(
fcu, {fp->frame, fp->val}, settings, eInsertKeyFlags(1));
fcu, {fp->frame, fp->val}, settings, INSERTKEY_NOFLAGS);
Note to reviewers: this is changed to
INSERTKEY_NOFLAGS
because the flag previously passed was actually not used byinsert_vert_fcurve()
, but now is. So this actually preserves the previous behavior.This same change is elsewhere in this PR as well, for the same reason.
@ -1071,2 +1072,4 @@
rna_tag_animation_update(bmain, id);
bool replace;
const int index = BKE_fcurve_bezt_binarysearch_index(fcu->bezt, frame, fcu->totvert, &replace);
Note to reviewers: this is indeed a bit less efficient (though not too bad: just another binary search). In the future we can change
insert_vert_fcurve()
to return a "result" type of some kind, to allow returning the index again without preventing the error code from being propagated on failure.WIP: Anim: implement 3D viewport keyframing functionality for the Animation data-blockto Anim: implement 3D viewport keyframing functionality for the Animation data-block@blender-bot build
I found an issue with "Only Insert Available" with this PR.
to reproduce:
I
to create keyframes on all channels of the default cubeThis seems to be because channels are not deleted when the last key is deleted, opposed to the behavior of the old Action
@ -443,1 +444,4 @@
SingleKeyingResult result_loc_a = key_strip.keyframe_insert(
binding, "location", 0, {1.0f, 47.0f}, INSERTKEY_NOFLAGS, settings);
ASSERT_EQ(SingleKeyingResult::SUCCESS, result_loc_a)
<< "Expect all the necessary data structures to be created on insertion of a key";
This description isn't really fitting anymore.
I'd expect something more like
Expected keyframe insertion to be successful
To be honest, I don't think it was a fitting description even before. But I think the message here probably communicates the intent of what it's supposed to be testing, so maybe instead of changing the message I can change the test to match the message?
you are already doing that further down by checking the amount of FCurves created, which is why I thought it is enough to just modify this message
Ah, that's a good point. Done.
@ -291,1 +340,3 @@
return -1;
/* TODO: we need more info from `insert_bezt_fcurve()` called above to
* return a more specific failure. */
return SingleKeyingResult::GENERIC_FAILURE;
could be possible to add a
FCURVE_KEYING_FAILED
.Depends on if you plan to use the generic failure more often in the future.
Currently it is only used here though
I'm using it as a marker for "we can't do proper error propagation here yet". The idea is that it should be completely removed in the future once error handling is properly threaded down to all the lower-level keying functions.
fair point :)
Maybe renaming it to
UNKNOWN_FAILURE
would be good, since that's the case wherever it's used: I only use it where we haven't propagated enough information to that site yet to know what caused keying to fail.@ -1060,2 +1169,3 @@
AnimData *adt = BKE_animdata_from_id(id);
if (USER_EXPERIMENTAL_TEST(&U, use_animation_baklava) && (adt->animation || !adt->action)) {
/* TODO: Don't hardcode key settings. */
that comment needs to move down
@ -43,6 +43,11 @@ static eInsertKeyFlags get_autokey_flags(Scene *scene)
flag |= INSERTKEY_NEEDED;
}
/* Only insert available. */
I don't think the changes to the autokeying code should be part of this PR.
While it's a really good change, I don't see how this is related to the Animation datablock.
That's totally fair. However, I did need to change something, because the old code was structured such that if there was an Animation datablock (as opposed to an action) and
AUTOKEY_FLAG_INSERTAVAILABLE
was set, it would always return early without doing anything.The alternative way to do this (at least that occurred to me) without changing the structure of the code is to add an additional branch inside the
if (is_keying_flag(scene, AUTOKEY_FLAG_INSERTAVAILABLE)) {
block, to do different things depending on whether it's an action or an animation datablock. That would more-or-less end up duplicating the code that's at the end of the function anyway, but maybe that's indeed best for this PR, and then I can make a separate PR that changes things to this version.Does that sound good?
what speaks against extracting that part of the PR and landing it beforehand? Might not be possible but that would be the cleanest option.
Ah! Fair point. Yeah, I'll do that. Thanks for the suggestion. :-)
Here's a separate PR for that:
#121476
Yeah, I ran into that as well. I don't think it's clear whether this is a bug in this PR vs the keyframe deletion code, though.
We basically need to decide whether fcurves should be removed when their last key is (like they are with actions), or whether it's okay for them to stay behind and the semantics of "Only Insert Available" need to change. (Or we could do both!) I'm fine either way, but I figured that's something we can address separately from this PR.
GENERIC_FAILURE
toUNKNOWN_FAILURE
d626e30f2cPersonally I'm fine with "available" meaning "there already is an F-Curve for this property", or in other words "insertion of the key can happen without creating a new F-Curve". So from that perspective, it seems this PR is doing the right thing.
Could this be extracted to another PR, that'll be landed prior to this one?
I think this was already extracted into another PR?
From what I can see (but I may be wrong) it could also be possible to move the handling of key insertion flags by the
Animation
datablock code into a separate PR? That could already be a nice improvement for keying via the Python API.@ -72,0 +87,4 @@
/**
* Return whether a new fcurve can be created according to the given keyframing
* flags.
I think a concrete example would help here:
The generic naming (this is just in the
animrig::
namespace) also threw me off a bit, as it's always possible to create a new FCurve. Maybe something likekey_insertion_may_create_fcurve()
?@ -646,3 +646,3 @@
BLI_assert(StringRef(this->name).size() >= name_length_min);
/* Avoid accessing an uninitialized part of the string accidentally. */
/* Avoid accessing an uninitialised part of the string accidentally. */
Commit such unrelated corrections separately. But also I think this was spelled correctly?
Yeah, not sure how that happened. Thanks for catching that!
@ -878,3 +872,1 @@
array_index,
binding.name);
return nullptr;
/* Get the fcurve, or if one doesn't exist and the keying flags allow then
Replace "then" with a comma and add one after "or":
Or maybe just reorder and simplify:
@ -454,1 +455,3 @@
<< "Expect same (binding/rna path/array index) tuple to return the same FCurve.";
SingleKeyingResult result_loc_b = key_strip.keyframe_insert(
binding, "location", 0, {5.0f, 47.1f}, INSERTKEY_NOFLAGS, settings);
ASSERT_EQ(SingleKeyingResult::SUCCESS, result_loc_b);
I think this should be an
EXPECT_EQ
as it's not a necessity for the rest of the code to not crash.@ -455,0 +457,4 @@
ASSERT_EQ(SingleKeyingResult::SUCCESS, result_loc_b);
ASSERT_EQ(1, channels->fcurves().size()) << "Expect insertion with the same (binding/rna "
"path/array index) tuple to go into the same FCurve";
ASSERT_EQ(2, channels->fcurves()[0]->totvert)
I think this should be an
EXPECT_EQ
as it's not a necessity for the rest of the code to not crash.Same with similar asserts below.
@ -455,0 +458,4 @@
ASSERT_EQ(1, channels->fcurves().size()) << "Expect insertion with the same (binding/rna "
"path/array index) tuple to go into the same FCurve";
ASSERT_EQ(2, channels->fcurves()[0]->totvert)
<< "Expect insertion with the same (binding/rna "
I think this code is wrapped a bit weird (or at least inconsistent with the very similar code above). Probably best to un-split the string and let the auto-formatter do its job. I think it can auto-split, but not auto-unsplit.
@ -77,0 +86,4 @@
* this? If it's never supposed to happen, an assert would be better. If
* it *is* supposed to happen, then printf doesn't seem like the right way
* to report it, if it should be reported at all. */
printf("ERROR: Couldn't add AnimData (ID = %s)\n", (id) ? (id->name) : "<None>");
This is supposed to happen, as not all IDs are animatable. But it's kinda moot, given that this function will likely disappear when you update this PR for #121357.
@ -278,1 +290,4 @@
*/
static bool new_key_needed(FCurve *fcu, const float frame, const float value)
{
if (fcu == nullptr) {
I don't think passing
fcu = nullptr
is a valid use case, just as callinginsert_vert_fcurve(fcu=nullptr, ...)
is not valid.Use a reference
FCurve &fcu
instead. And since this is just a query, and not changingfcu
, making itconst
would be appropriate....
I only now saw that this code was just move verbatim from another file. Fine to keep as-is for PR simplicity sake, but IMO this should be addressed at some point.
For posterity:
fcu
cannot be madeconst
, because the functions that this function calls don't take it asconst
(even though they themselves are just query functions).Hopefully we can follow the call chain and fix that all up as a separate PR relatively straightforwardly, as long as it's not too much of a tangled web. Fingers crossed.
Took a bit of time to see what it would take to make this const: #121788
@ -92,6 +97,17 @@ void CombinedKeyingResult::generate_reports(ReportList *reports)
}
Vector<std::string> errors;
if (this->get_count(SingleKeyingResult::UNKNOWN_FAILURE) > 0) {
Check the discussion about this in
#animation-module
. We'll have to simplify these messages to just a single string that covers both singular & plural."Could not insert {:d} key(s) for unknown reasons."
Got it. If that gets addressed for the other report messages in main first, then I'll update these ones as well before merging. Otherwise I think it makes sense to merge as-is, and then they can all be changed together.
@ -1045,0 +1071,4 @@
const eInsertKeyFlags insert_key_flags,
const KeyframeSettings &key_settings)
{
if (layer.strips().size() == 0) {
Currently this code assumes that if a strip exists, it's the right one to insert keys into. However, it doesn't document this assumption, and doesn't have any guards to check that the assumption holds.
I think it's better for the
Layer
itself to determine whichStrip
the key is supposed to go into. Something likeLayer::strip_for_keys(key_data.position[0])
. Or, if we want to separate these concerns (which I actually think might be a nice idea), it should at least be a separate class / function from the "insert keys into layer" function. That way thisinsert_key_layer()
function can be reduced to two steps:Or, since the data model is now still so simple, just have a function
ensure_layer_strip_for_keying(anim)
that returns references to the Layer and Strip. That one function can then have the assumptions & logic for "create if not exists" in one place, and the rest of the code is more straight-forward.Replace
.size() == 0
with.is_empty()
Yeah, I think that's a really good idea. I feel like it shouldn't even need to be specific to keyframing. Maybe
Layer::strip_at_time(...)
. We'll need to reassess that interface when we introduce overlapping strips, but putting it in one clear place will make it easy to see what impacts that change will have when we make it.@ -1045,0 +1094,4 @@
ID *id = rna_pointer->owner_id;
CombinedKeyingResult combined_result;
Binding *binding = anim.binding_for_id(*id);
It's probably better to use
anim.find_suitable_binding_for(*id)
here. That uses the same logic asanim.assign_id()
to find a suitable binding. I'll write a TODO for myself to document that API better (once #121357 lands, I don't want to create Git conflicts now).Also I feel that "prepare this ID for being keyed with this Animation" should be done in a separate function. That can then also be properly documented about the post-call guarantees it makes.
@ -1045,0 +1100,4 @@
const bool success = anim.assign_id(binding, *id);
if (!success) {
/* TODO: count the rna paths properly (e.g. accounting for multi-element properties). */
combined_result.add(SingleKeyingResult::NO_VALID_BINDING, rna_paths.size());
With a new Binding, the only reason
Action::assign_id()
can returnfalse
is when the ID itself cannot be animated. In that case I feel thatNO_VALID_BINDING
is a misleading thing to report, even when it's technically correct.It's probably better to check that the ID can be animated far before this function gets called, and then use
BLI_assert_msg()
to check for this more locally.@ -1045,0 +1107,4 @@
Layer *layer;
if (anim.layers().size() == 0) {
layer = &anim.layer_add("Layer 0");
Similar to the code above, I don't think that "preparing the Animation for key insertion" should be done by this function.
@ -1045,0 +1113,4 @@
layer = anim.layer(0);
}
if (layer == nullptr) {
This can only happen when
anim.layer(0)
returnsnullptr
, which should never happen. I think it's safe to turn this into aBLI_assert()
.@ -1045,0 +1120,4 @@
}
for (const std::string &rna_path : rna_paths) {
const bool visual_keyframing = insert_key_flags & INSERTKEY_MATRIX;
Booleans typically start with
use_
,do_
,is_
etc. In this caseuse_visual_keyframing
would be better IMO.@ -1045,0 +1126,4 @@
const bool path_resolved = RNA_path_resolve_property(
rna_pointer, rna_path.c_str(), &ptr, &prop);
if (!path_resolved) {
combined_result.add(SingleKeyingResult::CANNOT_RESOLVE_PATH);
Print to stdout which path could not be resolved. That'll make debugging things considerably easier.
@ -1045,0 +1129,4 @@
combined_result.add(SingleKeyingResult::CANNOT_RESOLVE_PATH);
continue;
}
const std::optional<std::string> rna_path_id_to_prop = RNA_path_from_ID_to_property(&ptr,
This
std::optional<>
isn't checked for emptyness, so the.value()
call below may crash.@ -1045,0 +1131,4 @@
}
const std::optional<std::string> rna_path_id_to_prop = RNA_path_from_ID_to_property(&ptr,
prop);
Vector<float> rna_values = get_keyframe_values(&ptr, prop, visual_keyframing);
Since the
visual_keyframing
constant is only used here, either move it here (to clarify the location of its use) or move it out of the loop (to clarify it's loop-invariant).@ -1045,0 +1138,4 @@
key_data.array_index = property_index;
key_data.position = {scene_frame, rna_values[property_index]};
const SingleKeyingResult result = insert_key_layer(
*layer, *binding, rna_path_id_to_prop.value(), key_data, insert_key_flags, key_settings);
I got a bit confused by the
.value()
call, as above there's alsorna_values
. It's mostly me (I should stop this review for now and go home), but try out*rna_path_id_to_prop
instead, to see how that looks for you.*rna_path_id_to_prop
looks like a pointer dereference to me. In this case it's close to whererna_path_id_to_prop
is defined, so it's fairly obvious what's actually going on. But IMO being explicit with.value()
makes it clearer in the general case, and is the convention I'd prefer we follow.Having said that, that also comes from my Rust background and the (nearly) equivalent
.unwrap()
call. So maybe it's just because it's what I'm used to.I read
*
as "the value of what this thing points to", which also applies tostd::optional<>
. I usually useif (!optional) { handle no-value case }
and*optional
to get the value. But also I don't have a strong opinion here, apart from the already-mentioned confusion between "the value of the optional" and "the RNA values".Personally I'd prefer Rust's
.unwrap()
over.value()
, as the latter is a bit too generic for my taste ;-)Yeah, that's a good point. And indeed, "value" is quite generic compared to "unwrap".
(
unwrap()
also has slightly different semantics thanvalue()
: it actually moves/extracts the contained value out, rather than just providing access to it. With the way Rust's move semantics work, this works out really nicely. But it's not totally clear to me whether it could work the same way in C++ without being a giant foot gun. And it's moot in any case, since it doesn't work that way.)For me that's exactly why it feels weird:
std::optional
doesn't point to anything, it contains something. But to counter my own point there, I think there's an alternative framing:*
means something like "resolve indirection". And I think that applies well enough tostd::optional
: you only have indirect access to the contained value.I think part of my gut feeling here also comes from the correspondence between
std::optional
and a hypotheticalResult
type in the future. I supposeResult
could also use*
to access the success value, and only accessing the error would be done via an explicit method call. But I like the explicitness of things likeresult.is_ok()
,result.unwrap()
, andresult.unwrap_err()
in Rust.In any case, I think for now going with
*
is fine. And we can see how things shake out in the future, and if it starts to feel weird once we have aResult
type.@ -289,3 +262,1 @@
}
}
}
/* Optimization: if there's no animation at all and "Only Insert Available" is
Same question as above: is this really necessary, given that it creates sub-optimal reporting?
Closing in favor of #121661, after splitting off a bunch of parts of this into other PRs:
(I'm doing it this way to reduce the chances of gitea losing the context for all of the comments I already got on this PR so far.)
Pull request closed