Move `Library.runtime` to be a pointer, move the related
`LibraryRuntime` struct to `BKE_library.hh`. Similar to e.g.
Mesh.runtime, that pointer is expected to always be valid, and is
allocated at readtime or when creating a new Library ID.
Related smaller changes:
* Write code now uses standard ID writing codepath for Library IDs too.
* Runtime pointer is reset to nullptr before writing.
* Looking up a library by its absolute path is now handled through a
dedicated utils, `search_filepath_abs`, instead of using
`BLI_findstring`.
Pull Request: https://projects.blender.org/blender/blender/pulls/134188
The previous name was confusingly similar to the new method
`identifier_prefix()` that was introduced in #133983. This new name
better distinguishes them while also reflecting its actual functionality
better and being shorter.
Pull Request: https://projects.blender.org/blender/blender/pulls/134046
Previously it was possible to make the type prefix of a Slot's identifier get
out-of-sync with its actual target ID type, by setting the identifier via
Python.
This PR changes `Slot.identifier` assignment to ensure that the type prefix is
set to match `target_id_type`. This now makes it impossible for the identifier
prefix and `target_id_type` to get out of sync, since this API previously was
the only way to accomplish that.
When the prefix that the user attempts to set doesn't match the `target_id_type`
of the Slot, a warning is issued telling the user about the mismatch and that
the identifier has been set with the correct prefix instead.
Pull Request: https://projects.blender.org/blender/blender/pulls/133983
Most of the old Animato properties on an Action (e.g. FCurve list, Channel
Groups) already act as proxies for the data for the first slot in the first
strip of the first layer. (Say that three times fast!) However, this was not yet
the case for `Action.id_root`.
This PR changes `Action.id_root` to act as a proxy for the first Slot's
`target_id_type` property, both for reading and writing.
If the Action has no Slots, then reading always returns 'UNSPECIFIED', and
writing will create a Slot and set its `target_id_type`.
Note that the ability to write to the first Slot's `target_id_type` via
`Action.id_root` conflicts with `target_id_type` supposedly only being writable
when it's still 'UNSPECIFIED' (#133883). Although that's certainly a little
weird, practically speaking this doesn't break anything for now, and is a
temporary kludge to keep `id_root` working until we can remove it in Blender
5.0. `id_root` will be removed entirely in 5.0, resolving this inconsistency.
Pull Request: https://projects.blender.org/blender/blender/pulls/133823
Similar to how brush assets are created and managed this
PR allows to export pose assets into a different library.
Because of this there is a limitation to this where each
asset is stored in a separate blend file.
This may be lifted in the future as there are planned changes in
the design phase: #122061
### Create Asset
Now available in the 3D viewport in the "Pose" menu: "Create Pose Asset".
The button in the Dope Sheet will now call this new operator as well.
Clicking either of those will open a popup in which you can:
* Choose the name of the asset, which library and catalog it goes into.
* Clicking "Create" will create a pose asset on disk in the given library.
It is possible to create files into an outside library or add it in the current file.
The latter option does a lot less since it basically just creates the
action and tags it as an asset.
If no Asset Shelf **AND** no Asset Browser is visible anywhere in Blender,
the Asset Shelf will be shown on the 3D viewport from which
the operator was called.
### Adjust Pose Asset
Right clicking a pose asset that has been created in the way described
before will have options to overwrite it.
Only the active object will be considered for updating a pose asset
Available Options (the latter 3 under the "Modify Pose Asset" submenu):
* Adjust Pose Asset: From the selected bones, update ONLY channels that
are also present in the asset. This is the default.
* Replace: Will completely replace the data in the Pose Asset from
the current selection
* Add: Adds the current selection to the Pose Asset. Any already existing
channels have their values updated
* Remove: Remove selected bones from the pose asset
Currently this refreshes the thumbnail. In the case of custom
thumbnails it might not be something want
### Deleting an existing Pose Asset
Right click on a Pose Asset and hit "Delete Pose Asset". Works in the shelf
and in the asset library. Doing so will pop up a confirmation dialog,
if confirming, the asset is gone forever. Deleting a local asset is basically the
same as clearing the asset. This is a bit confusing because you get
two options that basically do the same thing sometimes,
but "Delete" works in other cases as well.
I currently don't see a way around that.
Part of design #131840
Pull Request: https://projects.blender.org/blender/blender/pulls/132747
Previously, when use of the legacy Action APIs (specifically the `fcurves` and
`groups` properties) caused a new Slot to be created, it would be named "Slot".
This PR changes things so that Slots created that way are named "Legacy Slot",
just like Slots from upgraded legacy Actions.
The rationale is that Slots created in this way are expected (by the code that
created them) to be used as if the Action were still a legacy Action, and it's
good to reflect that in the name of the data. This also makes it clearer to
users when e.g. scripts and addons they're using may not yet have been updated
to fully work with Slotted Actions.
For consistency, this PR also names Layers created in the same way "Legacy
Layer", the same as Layers from upgraded legacy Actions.
Pull Request: https://projects.blender.org/blender/blender/pulls/133888
When loading old blend files, versioned Actions can end up having a slot with an
'UNSPECIFIED' `target_id_type`. Assigning the slot to an ID will then set the
slot's `target_id_type` to match the type of the ID, but there was previously no
way to directly set it via Python if needed.
This PR changes the writability of `target_id_type` to match the extent of its
mutability when assigning a slot to an IDs. Which is to say, it can be set if
it's 'UNSPECIFIED', but not otherwise.
RNA doesn't have a good way to represent this, so we accomplish this with a
custom set function that simply ignores the write if the slot's `target_id_type`
isn't 'UNSPECIFIED'. This isn't ideal, but is the least-bad solution at the
moment.
Pull Request: https://projects.blender.org/blender/blender/pulls/133883
Add `ensure` boolean parameter to the `ActionKeyframeStrip.channels()` RNA
function. Passing `ensure=True` will ensure the channelbag for the given
action slot handle exists. This makes it more straight-forward to create
F-Curves for a slot regardless of whether there already was a channelbag
for those F-Cuves:
```python
strip = action.layers[0].strips[0]
slot = action.slots[0]
# Old:
channelbag = strip.channels(slot.handle)
if not channelbag:
channelbag = strip.channelbags.new(action_slot)
ob_loc_x = channelbag.fcurves.new('location', index=0)
# New:
channelbag = strip.channels(slot.handle, ensure=True)
ob_loc_x = channelbag.fcurves.new('location', index=0)
```
Pull Request: https://projects.blender.org/blender/blender/pulls/133678
When writing an Action to a blend file, for forward compatability
reasons the animation data in the first slot is also written to the old
Animato Action storage locations. That way, loading the Action in an
older version of Blender will still at least have that animation data.
However, we overlooked `Action.idroot`, which indicates which ID
type the Action is for, and therefore all Actions have an unspecified
`idroot` when loaded in pre-layered-action versions of Blender.
This PR fixes that by also setting the `idroot` to match the target ID
type of the first slot when writing to disk.
Pull Request: https://projects.blender.org/blender/blender/pulls/133819
Refactor the keyframe copy-paste code to prepare for supporting action slots.
This is a non-functional change, as the slots are stored but otherwise completely ignored. This way the refactor to the new data structure can be reviewed & tested before actually changing the behaviour.
Related: #129690
Pull Request: https://projects.blender.org/blender/blender/pulls/133497
There were three methods with succinct but slightly unclear names:
- Action::slot_move()
- Channelbag::channel_group_move()
- Channelbag::fcurve_move()
The ambiguity is due to other functions with similar names that e.g.
move fcurves *between* Channelbags, etc. Whereas these methods only move
items to other positions within the array they're already in.
To make this clearer, this PR adds `_to_index` to the end of these
array-oriented methods.
Pull Request: https://projects.blender.org/blender/blender/pulls/133730
This updates the Move Channels operator in the Action Editor channel list to
also work with Slots, allowing Slots to be reordered within an Action.
Note that the Move Channels operator already had interesting behavior when
channels are selected in multiple levels of the channel hierarchy (e.g. when
both channel groups and f-curve channels are selected). For Slots, I've chosen
a simpler behavior: if any Slot is moved, all non-Slot channels (i.e. those
lower in the hierarchy) are left alone.
In the future we may want to change channel group rearrangement to work the same
way with respect to f-curve channels, but I've left that alone for now.
Pull Request: https://projects.blender.org/blender/blender/pulls/133328
When assigning an Action to an ID, a slot can be automatically
assigned as well. This behaviour is now extended by making untyped
slot identifiers (like `XXSlot`) act as wildcards.
If the last-used slot identifier was 'untyped' (like `XXSlot`), and a
slot with the same name that is specific to the animated ID's type
exists, that slot will be chosen.
Similarly, if the last-used slot identifier was 'typed' (like
`OBSlot`), a slot `OBSlot` does NOT exist, but an untyped slot with
the same name exists (like `XXSlot`), that one will be chosen.
If there is any ambiguity in the matter, the more specific slot is
chosen. In other words, in this case:
- last_slot_identifier = `XXSlot`
- both `XXSlot` and `OBSlot` exist on the Action (where `OB`
represents the ID type of `animated_id`).
the `OBSlot` should be chosen. This means that `XXSlot` NOT being
auto-assigned if there is an alternative. Since untyped slots are
bound on assignment, this design keeps the Action as-is, which means
that the `XXSlot` remains untyped and thus the user is free to assign
this to another ID type if desired.
Pull Request: https://projects.blender.org/blender/blender/pulls/133653
When an action slot does not have an ID type, and it is assigned to some
ID, the slot is bound to that ID's type. This now no longer happens when
the Action is linked, because linked data should not be modified.
Pull Request: https://projects.blender.org/blender/blender/pulls/133670
Deduplicate `assign_action_ensure_slot_for_keying()` and
`generic_slot_for_autoassign()`.
Some of the functionality of the latter function was copied into the
former. This has now been replaced by actually calling the function in
the appropriate spot.
No functional changes.
Pull Request: https://projects.blender.org/blender/blender/pulls/133652
An Action slot usually has a specific ID type (`ActionSlot::idtype`).
When this is set to 0, it is not specifc to any particular ID type. The
latter case was called "unbound", and is now called "untyped".
Note that untyped slots are given an ID type as soon as they are
actually assigned to any ID.
No functional changes.
Pull Request: https://projects.blender.org/blender/blender/pulls/133651
This patch adds support to apply a pose asset to multiple armatures in pose mode at once.
In case there is a suitable slot for the armature, it will be used to read from, otherwise
the system falls back to slot 0.
Part of #131840
Pull Request: https://projects.blender.org/blender/blender/pulls/132601
Just like legacy Actions get a slot "Legacy Slot" when they're
versioned, their layer is now also called "Legacy Layer" to be
consistent with that.
When upgrading a legacy Action to a slotted Action, it also gets a layer
and a keyframe strip on that layer. Those are not shown in the user
interface yet, but will in the future.
Pull Request: https://projects.blender.org/blender/blender/pulls/133009
Internationalize the default Action layer name. Instead of `"Layer"`,
use `DATA_("Layer")`. This is the same for other defaults in Blender.
When upgrading a legacy Action to a slotted Action, it also gets a layer
and a keyframe strip on that layer. Those are not shown in the user
interface yet, but will in the future.
Pull Request: https://projects.blender.org/blender/blender/pulls/133009
A pass at cleaning up / improving the code documentation for the layered action
C++ classes.
There is still more work to do here, but this should be good for an initial
first pass. I've focused on clarifying the behavior of and updating stale docs
of the methods in the action-related C++ classes.
Pull Request: https://projects.blender.org/blender/blender/pulls/131318
The issue was that we were passing a pointer-to-a-pointer to
`BLI_addtail()`, which expects a pointer to something castable to a
`Link`. This in turn led to an invalid memory access when trying to
access the fields of the supposed `Link`.
This fixes the issue by passing a pointer to a zero-initialized `Link`
instead.
This also takes the opportunity to more simply zero-initialize the
`bAction` structs used in the tests as well.
Pull Request: https://projects.blender.org/blender/blender/pulls/132860
Empty legacy Actions were skipped from versioning, because they are
technically valid layered Actions as well. However, this created an
issue where there was no "Legacy Slot" created for those. Furthermore,
their `idroot` could still be set to a non-zero value, which is not
allowed on layered Actions.
`bAction::idroot` is not a very reliable field. It can be zero on legacy
Actions as well, and it can in certain cases be downright wrong (can
happen in certain linking scenarios). Because of this, the field is not
included in any "is this a layered or a legacy Action?" checks.
Pull Request: https://projects.blender.org/blender/blender/pulls/132757
Split the versioning of legacy Actions to slotted ones into two steps:
1. Versioning the Actions themselves, in the regular versioning code
(`do_versions_after_linking_400`). This has to happen in the 'after
linking' stage, and not in the 'before linking' stage, as there's
older 'after linking' code that will break when it gets fed slotted
actions. Any ID that is using a legacy Action will get tagged.
2. Versioning Action assignments, where the correct Action Slot has to
be chosen & assigned for each tagged ID. This has to happen in the
`do_versions_after_setup` stage, as choosing a slot requires that the
actions (both local & linked) have been converted already.
This also includes some necessary changes to the pre-2.50 Action versioning
code.
Note that this change does not handle library overrides. That's dealt
with in !131426.
Pull Request: https://projects.blender.org/blender/blender/pulls/131627
The code for converting pre-Animato actions was not getting run properly
because `chanbase` (where animation data used to be stored) was
erroneously getting cleared before the relevant versioning code was run.
The root cause was that the code checking whether an action was already
valid as a layered action or not was NOT confirming that `chanbase` was
empty as part of that check (as it is a DNA-deprecated field), which in
turn triggered code that defensively clears `chanbase` (among other
things) when an action is identified as layered.
Note that the conversion of IPO curves and other pre-Animato data
happens quite late in the versioning, even _after_ the "versioning after
linking" stage. This is not introduced in this commit, this is just to
illuminate pre-existing design that might not be entirely obvious.
Pull Request: https://projects.blender.org/blender/blender/pulls/131975
When using clangd or running clang-tidy on headers there are
currently many errors. These are noisy in IDEs, make auto fixes
impossible, and break features like code completion, refactoring
and navigation.
This makes source/blender headers work by themselves, which is
generally the goal anyway. But #includes and forward declarations
were often incomplete.
* Add #includes and forward declarations
* Add IWYU pragma: export in a few places
* Remove some unused #includes (but there are many more)
* Tweak ShaderCreateInfo macros to work better with clangd
Some types of headers still have errors, these could be fixed or
worked around with more investigation. Mostly preprocessor
template headers like NOD_static_types.h.
Note that that disabling WITH_UNITY_BUILD is required for clangd to
work properly, otherwise compile_commands.json does not contain
the information for the relevant source files.
For more details see the developer docs:
https://developer.blender.org/docs/handbook/tooling/clangd/
Pull Request: https://projects.blender.org/blender/blender/pulls/132608
This caused build errors on the docs builder, I can't seem to reproduce
locally, so revert for now and have another look at some point in the
future.
Sadly as these changes usually go, this took 5c515e26bb and
2f0fc7fc9f with it as well.
Pull Request: https://projects.blender.org/blender/blender/pulls/132559
The issue is that certain RNA paths cannot be generated to come
from an ID and `RNA_path_from_ID_to_property` will return no value.
We are using that function in the keyframing code to allow passing
in a pointer to a bone and a path relative to that bone.
Since there is currently no good way to find the path from the ID to an arbitrary
struct pointer (see #122427), this patch is a workaround that uses
the struct_pointer IF that happens to be an ID pointer.
Of course that still has the core limitation in place but until a
better solution is available on the RNA side this is the best we can do.
Pull Request: https://projects.blender.org/blender/blender/pulls/132552
This patch makes the internal functions for the pose library aware of action slots.
* Allows to apply poses with more than 1 slot.
* The slot is chosen based on a best guess, with a fallback to the first slot.
Not in this patch:
There is no straightforward way to create multi slot pose assets yet. That will come later.
It is possible to manually tag an action with more than 1 slot as an asset though.
When applying poses, only the active object is modified. Multi object editing support will come later.
Part of Design #131840
Pull Request: https://projects.blender.org/blender/blender/pulls/132161
Action Slots point to the IDs they animate, and after swapping IDs they
also need some swappage (as the Action that first animated `id_a` will
now animate `id_b`, and vice versa).
Instead of doing this in the `id_swap()` function (and requiring
knowledge of how that's supposed to be done), just mark these pointers
as dirty so that they're rebuilt at first use.
This commit contains a little more code than strictly necessary, to add
a function in BKE for this cache invalidation. This avoids having to
have a dependency on the animrig module just for this purpose.
Fixes: #130136
Pull Request: https://projects.blender.org/blender/blender/pulls/131809
The crash happened because `bNodeSocket.runtime` was a nullptr.
That was because the struct pointer was passed instead of the
resolved pointer. Passing the resolved pointer into `BKE_animsys_nla_remap_keyframe_values`
fixes the issue
Pull Request: https://projects.blender.org/blender/blender/pulls/132012
The autokeying code for cameras used the keyingset code to insert keys.
In the case of "Only Insert Available" turned on this would use the "Available" keyingset.
However, in the case of looking through the camera and moving the viewport
when the camera is not active, the poll function of that keyingset would return false.
Instead of modifying the poll function, the fix is to use the more direct keying code
using `RNAPath`.
This can be backported to 4.2 but not 3.6 due to the changes to the keying code done in 4.0
Pull Request: https://projects.blender.org/blender/blender/pulls/131796
Instead of using `BKE_library_foreach_ID_link()` as a way to find
embedded IDs in a generic way, explicitly just get the embedded node
tree. That's the only animatable embeddable ID anyway. And calling
`BKE_library_foreach_ID_link()` can have some unwanted side-effects
(especially when the rebuilding happens while already using a similar
function to loop over IDs).
Pull Request: https://projects.blender.org/blender/blender/pulls/131807
`animrig::Slot::users_remove()` now also works when there are multiple
occurrences of the same ID. Because of the above-mentioned pointer
remapping now working correctly, the pointers in the slot user list
are not 100% under control of the Slot class, and thus there could
hypothetically be duplicates there.
This doesn't fix any concrete issues, it's just a safety measure.
Pull Request: https://projects.blender.org/blender/blender/pulls/131806