Commit Graph

517 Commits

Author SHA1 Message Date
Campbell Barton
84694bf635 Cleanup: add inline array size comments and minor corrections 2025-05-23 14:03:20 +10:00
Bastien Montagne
4be7dad854 Cleanup: Replace incorrect MAX_ID_NAME-2 string length by MAX_NAME.
Also make use of recent 4e7b9185a4 change, and move size-hint comments
inside the brackets of the char array declaration.
2025-05-22 14:35:19 +02:00
Matvey Smorodin
2ae62e3774 Cleanup: Remove Strip::slot_data_remove() in favour of looping over the strip data arrays
Refactor `Action::slot_remove`: implemented iteration over
`strip_keyframe_data_array` and direct calling
`StripKeyFrameData::slot_data_remove()`. Also removed
`Strip::slot_data_remove()` as well as `Layer::slot_data_remove` as it
had no usages after refactoring.

Fixes: #137095

Pull Request: https://projects.blender.org/blender/blender/pulls/138343
2025-05-16 15:17:58 +02:00
Christoph Lendenfeld
9c35656766 Refactor: Move bone functions to separate file and into namespace
No functional changes intended.

This moves the functions
* ANIM_bone_is_visible
* ANIM_bone_is_visible_ebone
* ANIM_bone_is_visible_pchan

into new files `ANIM_armature.hh`/`armature.cc`.
They were previously in `ANIM_bone_collections.hh` but don't
directly have anything to do with bone collections.

It also puts the functions into the `blender::animrig::` namespace
and removes the `ANIM_` prefix as is the standard for C++ files.

Part of #138482

Pull Request: https://projects.blender.org/blender/blender/pulls/138833
2025-05-16 14:45:46 +02:00
Christoph Lendenfeld
45240026a2 Refactor: Remove unused bone flag
No functional changes intended.

This removes the `BONE_HIDDEN_PG` flag for Bones.
It was never set, only read so it had no effect.

Part of #138482

Pull Request: https://projects.blender.org/blender/blender/pulls/138802
2025-05-16 13:43:56 +02:00
Christoph Lendenfeld
9ee5196db7 Refactor: Remove PBONE_VISIBLE and EBONE_VISIBLE macros
No functional changes intended.

This just replaces all calls to `PBONE_VISIBLE` and `EBONE_VISIBLE`
with appropriate functions.
In the case of editbones it is just the function that the macro already contained.
For pose bones, a new function was added that mirrors what the macro had.

Using a function will make it easier to change how selection is queried in the future.

part of #138482

Pull Request: https://projects.blender.org/blender/blender/pulls/138819
2025-05-13 15:51:12 +02:00
Jacques Lucke
d9b91c73e3 Core: use template for BKE_id_new
This is the same change as e09ccc9b35 but for `BKE_id_new`.

Pull Request: https://projects.blender.org/blender/blender/pulls/138667
2025-05-09 16:13:25 +02:00
Jacques Lucke
e09ccc9b35 Core: add templated version of BKE_id_new_nomain to reduce explicit casting
This adds a version of `BKE_id_new_nomain` that takes the ID type parameter as
template argument. This allows the function the return the newly created ID with
the correct type, removing the need to use `static_cast` on the call-site.

To make this work, I added a static `id_type` member to every ID struct. This
can also be used to create a similar API for other id management functions in
future patches.

```cpp
// Old
Mesh *mesh = static_cast<Mesh *>(BKE_id_new_nomain(ID_ME, "Mesh"));

// New
Mesh *mesh = BKE_id_new_nomain<Mesh>("Mesh");
```

Pull Request: https://projects.blender.org/blender/blender/pulls/138383
2025-05-05 18:41:03 +02:00
Jacques Lucke
c271c3b291 Fix: ID code not should not be passed as part of name
Found in #138383.
2025-05-05 11:47:42 +02:00
Campbell Barton
43af16a4c1 Cleanup: spelling in comments, correct comment block formatting
Also use doxygen comments more consistently.
2025-05-01 11:44:33 +10:00
Campbell Barton
c90e8bae0b Cleanup: spelling in comments & replace some use of single quotes
Previously spell checker ignored text in single quotes however this
meant incorrect spelling was ignored in text where it shouldn't have
been.

In cases single quotes were used for literal strings
(such as variables, code & compiler flags),
replace these with back-ticks.

In cases they were used for UI labels,
replace these with double quotes.

In cases they were used to reference symbols,
replace them with doxygens symbol link syntax (leading hash).

Apply some spelling corrections & tweaks (for check_spelling_* targets).
2025-04-26 11:17:13 +00:00
Nathan Vegdahl
b69a4380b6 Fix: non-trivial memcpy compiler warnings on animrig copy constructors
The copy constructors for `animrig::Strip`, `animrig::Slot`, and
`animrig::StripKeyframeData` used a `memcpy` call as part of the copy
implementation. However, this produced warnings on clang 20.  For example:

```
warning: first argument in call to 'memcpy' is a pointer to
non-trivially copyable type 'blender::animrig::Strip'
[-Wnontrivial-memcall]`
```

These warnings did not reflect any actual bugs, because the underlying DNA
structs that those types wrap are in fact trivial. Nevertheless, it's worth
fixing the warnings.

This fixes the warnings by replacing the uses of `memcpy` with equivalents that
amount to a `memcpy` anyway, but which the compiler understands are valid for
the types.

There was also one additional use of `memcpy` in `Strip::create()` that did not
trigger a warning because it operated directly on the underlying DNA struct, but
was also unnecessary. This PR also replaces that with a simple assignment.

Pull Request: https://projects.blender.org/blender/blender/pulls/137467
2025-04-22 10:42:20 +02:00
Brecht Van Lommel
d061b00455 Refactor: Eliminate various unsafe memcpy and memset
Some of these already have warnings with clang-tidy, others are more
safe in case these structs get (copy) constructors in the future.

Pull Request: https://projects.blender.org/blender/blender/pulls/137404
2025-04-21 17:59:41 +02:00
Brecht Van Lommel
637c6497e9 Refactor: Use more typed MEM_calloc<>, avoid unnecessary size_t cast
Handle some cases that were missed in previous refactor. And eliminate
unnecessary size_t casts as these could hide issues.

Pull Request: https://projects.blender.org/blender/blender/pulls/137404
2025-04-21 17:59:41 +02:00
Campbell Barton
3933f45f52 Cleanup: move doc-strings to declarations
Move into headers or to the top of the function body for internal
implementation details, in some cases remove duplicate doc-strings.
2025-04-18 22:58:36 +10:00
Campbell Barton
64f5dee6d7 Cleanup: spelling in comments (make check_spelling_*) 2025-04-17 12:06:12 +10:00
Aras Pranckevicius
6b9de30ff1 Anim: Add function for batch-creation of many f-curves, use in USD import
Creating f-curves one by one is quadratic complexity due to:
1) scanning all existing f-curves for possible name+index duplicates,
2) channelbag invariants recalculation after each f-curve addition.
3) f-curve array storage is reallocated for each f-curve addition.

In cases when many f-curves are created at once (primary case:
importing an animated character), using the newly added
fcurve_create_many is much faster, because it:
1) uses a hashtable for duplicate name+index checking, instead of
   linear scan, and
2) recalculates channelbag invariants just once.
3) does f-curve array reallocation just once.

Importing USD file exported out of Blender Studio "Rain Restaurant"
scene (about 20k f-curves), on Ryzen 5950X goes 2.0 sec -> 0.9 sec.

Pull Request: https://projects.blender.org/blender/blender/pulls/137004
2025-04-15 13:58:01 +02:00
Campbell Barton
d700bc5f54 Cleanup: remove use of unsafe string functions 2025-04-12 18:42:44 +10:00
Jacques Lucke
b92fdff697 Refactor: BLI: use FunctionRef in BLI_uniquename api
This simplifies the API usage, removes the need for intermediate structs
and reduces the overall amount of code.

Pull Request: https://projects.blender.org/blender/blender/pulls/137300
2025-04-10 20:30:45 +02:00
Sybren A. Stüvel
9b1a34e83e Fix #136947: Duplicate Action Slot doesn't duplicate animation data
The "new/duplicate" button in the Action Slot selector did not actually
duplicate, and always acted as a "new" button.

This introduces the RNA function `ActionSlot.duplicate()`, which takes
care of duplicating all the animation data associated with the slot as
well. The semantics of this function should remain valid in the
future, when Actions support multiple layers & strips. Note that this
new function does not assign the slot, it just duplicates it and its
data. The assignment of this duplicated slot is done in Python,
through the already-existing API for this.

Pull Request: https://projects.blender.org/blender/blender/pulls/137087
2025-04-07 16:14:49 +02:00
Sybren A. Stüvel
a9f4f211d4 Fix #136967: Crash on Merge Animation when Slot has no Channelbag
The Merge Animation operator assumed that when a keyframe strip exists,
it always has a channelbag for the to-be-moved slot. This isn't
necessarily the case, so now it only moves the channelbag if it exists.

Pull Request: https://projects.blender.org/blender/blender/pulls/136978
2025-04-04 12:22:47 +02:00
Campbell Barton
86ec6d4290 Cleanup: resolve tautological-pointer-compare warning for CLANG
The array can never be null.
2025-04-01 11:54:34 +11:00
Campbell Barton
42ad772a1f Cleanup: spelling & repeated terms (make check_spelling_*)
Also use comment blocks for English text.
2025-03-27 01:13:34 +00:00
Sybren A. Stüvel
6ffb0e368d Fix #136388: Move slots to new action not maintaining animation data
When moving slots (with all their associated animation data) from one
Action to another, tag the data-blocks that are affected by the slot
move, so that they get re-evaluated. Without this, their (out of date)
evaluated copy would still point to the original Action, which no longer
has animation data for the moved slot.

Pull Request: https://projects.blender.org/blender/blender/pulls/136454
2025-03-25 11:44:48 +01:00
Sybren A. Stüvel
a7d787f5b9 Fix #136347: Keyframe interpolation behavior changed for BoolProperty
F-Curve interpolation uses the `FCURVE_INT_VALUES` and
`FCURVE_DISCRETE_VALUES` flags, which were not set in the keyframe
insertion function for slotted Actions. This is now resolved by making
the RNA property type part of the `FCurveDescriptor`.

Existing code has been refactored a bit, mostly to allow calling
`update_autoflags_fcurve_direct()` with just the RNA property type,
instead of passing the property itself. This avoided the need to include
pointers to RNA properties in `FCurveDescriptor`, which I think is a
slightly nicer design. It also makes it more explicit which aspect of
the property is used.

Because there's now another `std::optional<>` in the `FCurveDescriptor`,
I've also changed some `std::nullopt` to `{}` for brevity of the code,
as repeating that another time would have caused longer lines with more
rewrapping.

Pull Request: https://projects.blender.org/blender/blender/pulls/136446
2025-03-25 10:34:19 +01:00
Philipp Oeser
e22ff684f3 Cleanup: Anim: convert cstyle-casts
Using clang-tidy "cppcoreguidelines-pro-type-cstyle-cast" to find them.

This PR touches `bf_animrig` & `bf_editor_animation` & `bf_editor_armature`

NOTE: Also some case where untouched (not straightforward) same as
expanded macros (e.g. `LISTBASE` or `GS`)
NOTE: a couple of cases of "inconsistent-declaration-parameter" as well

Pull Request: https://projects.blender.org/blender/blender/pulls/136044
2025-03-17 19:49:45 +01:00
Sergey Sharybin
f243f13549 Merge branch 'blender-v4.4-release' 2025-03-14 18:36:53 +01:00
Sybren A. Stüvel
63c3db3e96 Fix #135923: Library Overrides break action constraints
Fix an issue with library overrides that was caused by Action
assignments getting versioned too late in the versioning process. Now
the versioning of Action assignments (which assigns the
created-by-versioning action slots) happens in the 'after linking'
stage, as well as in the 'after setup' stage. The latter is still
necessary for the conversion of pre-2.5x animation data.

It is likely that the versioning code can now be simplified, as the
tagging for "this needs upgrading" may no longer be necessary. We're now
too close to the 4.4 release to comfortably make such bigger refactors,
though, so I'd rather keep the overall code structure as-is.

Pull Request: https://projects.blender.org/blender/blender/pulls/135988
2025-03-14 18:26:17 +01:00
Philipp Oeser
d79274ae53 Merge branch 'blender-v4.4-release' 2025-03-14 17:34:51 +01:00
Philipp Oeser
6f02a485aa Fix #135927: Crash moving empty slots to new action
Check existence of layer and slot before handling Channelbags.
The existing asserts dont catch this (they are skipping the "empty
layers" case) and rightfully so, think there might be usecases for
moving **empty** slots as well.

Pull Request: https://projects.blender.org/blender/blender/pulls/135963
2025-03-14 17:19:06 +01:00
Thomas Dinges
d8e4789244 Merge branch 'blender-v4.4-release' 2025-03-11 17:11:00 +01:00
Christoph Lendenfeld
e7410abaca Fix #135666: Renaming a slot used by multiple IDs breaks animation on certain channels
The issue was that the `FCURVE_DISABLED` flag is set when an
RNA path cannot be resolved, and that skips evaluation.
However in the specific case, that is actually something expected as
the property only exists on one ID and not the other.

Pull Request: https://projects.blender.org/blender/blender/pulls/135782
2025-03-11 16:40:23 +01:00
Sybren A. Stüvel
b986b6d76d Cleanup: add explanation why key insert does not flush animation
Add an explanation to the keyframe insertion function
`animrig::insert_keyframes()` as to why it does not use
`ID_RECALC_ANIMATION`:

Animation flushing would be quite annoying in the following case:

- Key Cube's loc/rot/scale.
- Go to another frame.
- Translate, rotate, and scale the cube.
- Hover over the loc/rot/scale properties and one by one press 'I' to
  insert a key there.

If `ID_RECALC_ANIMATION` were used, keying the location would immediately
cause a flush of the animation data, popping the rotation and scale back
to their animated values.

No functional changes.
2025-03-11 14:52:56 +01:00
Bastien Montagne
1e00054195 Cleanup: Replace 'void' MEM_[cm]allocN with templated, type-safe MEM_[cm]allocN<T>.
The main issue of 'type-less' standard C allocations is that there is no check on
allocated type possible.

This is a serious source of annoyance (and crashes) when making some
low-level structs non-trivial, as tracking down all usages of these
structs in higher-level other structs and their allocation is... really
painful.

`MEM_[cm]allocN<T>` templates on the other hand do check that the
given type is trivial, at build time (static assert), which makes such issue...
trivial to catch.

NOTE: New code should strive to use `MEM_new` (i.e. allocation and
construction) as much as possible, even for trivial PoD types.

Pull Request: https://projects.blender.org/blender/blender/pulls/134452
2025-03-07 10:44:49 +01:00
Christoph Lendenfeld
ba1e51cff9 Merge branch 'blender-v4.4-release' 2025-03-06 15:54:03 +01:00
Christoph Lendenfeld
b834ca4fb1 Fix: Custom Properties named identical to existing properties fails to key
When inserting keys in the viewport by pressing `I`,
certain custom properties would not get keyed if their name
was identical to existing properties (for example `scale`).

That was because we use the name of the property to resolve
an rna path and check if the path resolved. This was of course
true in the described case and the square brackets would never be added.
The solution is to check for `RNA_property_is_runtime` which is false
for properties defined inside Blender.

Pull Request: https://projects.blender.org/blender/blender/pulls/135304
2025-03-06 15:52:29 +01:00
Bastien Montagne
dd168a35c5 Refactor: Replace MEM_cnew with a type-aware template version of MEM_callocN.
The general idea is to keep the 'old', C-style MEM_callocN signature, and slowly
replace most of its usages with the new, C++-style type-safer template version.

* `MEM_cnew<T>` allocation version is renamed to `MEM_callocN<T>`.
* `MEM_cnew_array<T>` allocation version is renamed to `MEM_calloc_arrayN<T>`.
* `MEM_cnew<T>` duplicate version is renamed to `MEM_dupallocN<T>`.

Similar templates type-safe version of `MEM_mallocN` will be added soon
as well.

Following discussions in !134452.

NOTE: For now static type checking in `MEM_callocN` and related are slightly
different for Windows MSVC. This compiler seems to consider structs using the
`DNA_DEFINE_CXX_METHODS` macro as non-trivial (likely because their default
copy constructors are deleted). So using checks on trivially
constructible/destructible instead on this compiler/system.

Pull Request: https://projects.blender.org/blender/blender/pulls/134771
2025-03-05 16:35:09 +01:00
Julian Eisel
a308bfca69 Merge branch 'blender-v4.4-release' 2025-03-04 17:20:43 +01:00
Sybren A. Stüvel
f980f80dd4 Cleanup: add explanatory comment about action slot auto-assignment
Add more explanation to the current action slot auto-assignment logic.

No functional changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/135445
2025-03-04 16:40:25 +01:00
Sybren A. Stüvel
963f291901 Merge remote-tracking branch 'origin/blender-v4.4-release' 2025-02-21 12:34:32 +01:00
Sybren A. Stüvel
6225c3e667 Refactor: make FCurve and Channelbag 'ensure' functions return a reference
Make `action_channelbag_ensure()` and `action_fcurve_ensure()` return a
reference. Earlier it returned pointer that should never be `nullptr`,
but in certain cases (which would indicate a bug, as the function's
preconditions aren't met) could technically still be a `nullptr`.

Instead, the preconditions are checked with `BLI_assert()`, and a
release build will simply assume that they are met. This simplifies the
code of the functions themselves, as well as the callers.

For reference: this was discussed in !134866.

No functional changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/134918
2025-02-21 11:55:56 +01:00
Sybren A. Stüvel
73bd35e63f Merge remote-tracking branch 'origin/blender-v4.4-release' 2025-02-21 11:22:39 +01:00
Sybren A. Stüvel
f046fa5272 Refactor: pass FCurveDescriptor as const reference instead of value
Over time the `FCurveDescriptor` class has grown, and some concern was
raised (!134866) about the performance impact of passing it by value.
It's now passed by const reference instead.

No functional changes. I did find some non-`const` uses that are now
also `const`.

Pull Request: https://projects.blender.org/blender/blender/pulls/134913
2025-02-21 11:22:13 +01:00
Sybren A. Stüvel
3473680f39 Merge remote-tracking branch 'origin/blender-v4.4-release' 2025-02-20 17:07:03 +01:00
Sybren A. Stüvel
2185143fc2 Refactor: split animrig::action_fcurve_ensure() into two components
Split the majority of `animrig::action_fcurve_ensure()` into a new
function `action_channelbag_ensure()`. This ensures that the Action has
a layer, keyframe strip, action slot, and channelbag for the given ID.

`animrig::action_fcurve_ensure()` now just calls into that function, and
then ensures that there is an F-Curve in that channelbag.

No functional changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/134864
2025-02-20 17:04:23 +01:00
Sybren A. Stüvel
611a138719 Merge remote-tracking branch 'origin/blender-v4.4-release' 2025-02-20 12:54:26 +01:00
Sybren A. Stüvel
3dbede128e Fix #134581: Regression: Animation breaking going from 4.3 to 4.4
Fix an issue where the versioning of Action & slot assignments did not
use RNA properties to do the slot assignment. This caused certain
on-update callbacks to be missed, which in turn meant that an Action
constraint could remain disabled even though its action slot assignment
had been corrected.

This is now resolved by actually using RNA to set the assigned slot in
the versioning code.

Unfortunately that does mean that any reporting done will be by the
generic RNA code as well, and won't be specific to versioning. This
shouldn't be much of an issue in practice, as any warning was only shown
in the rare case of mis-matched `action.idroot` properties.

Pull Request: https://projects.blender.org/blender/blender/pulls/134759
2025-02-20 11:58:01 +01:00
Hans Goudey
2555f68267 Merge branch 'blender-v4.4-release' 2025-02-18 10:55:49 -05:00
Sybren A. Stüvel
2393d498cb Anim: add RNA function Action.fcurve_ensure_for_datablock(...)
Expose the convenience function `blender::animrig::action_fcurve_ensure()`
to RNA as `Action.fcurve_ensure_for_datablock(...)`.

The function requires that the Action is already assigned to the
data-block. It then takes care of slot assignment / creation, as well as
the creation of a layer and a keyframe strip.

This function call:

```python
fcurve = action.fcurve_ensure_for_datablock(ob_cube, "location", index=2)
```

effectively performs this logic:

```python
# Ensure the slot exists and is assigned:
slot = ob_cube.animation_data.slot
if not slot:
    slot = find_slot_for_keying(action)
if not slot:
    slot = action.slots.new(ob_cube.name)
ob_cube.animation_data.slot = slot

# Ensure a layer exists:
if action.layers:
    layer = action.layers[0]
else:
    layer = action.layers.new("Layer")

# Ensure a keyframe strip exists:
if layer.strips:
    strip = layer.strips[0]
else:
    strip = layer.strips.new('KEYFRAME')

# Ensure the channelbag exists:
channelbag = strip.channelbag(slot, ensure=True)

# Ensure the F-Curve exists:
fcurve = channelbag.fcurves.find("location", index=1)
if not fcurve:
    fcurve = channelbag.fcurves.new("location", index=1)
```

Here `find_slot_for_keying()` represents the logic that's also used when
creating keys via the user interface or the `bpy_struct.keyframe_insert()`
function.

Pull Request: https://projects.blender.org/blender/blender/pulls/134686
2025-02-18 16:04:00 +01:00
Campbell Barton
4c5424d9fc Merge branch 'blender-v4.4-release' 2025-02-16 19:45:34 +11:00