Commit Graph

46 Commits

Author SHA1 Message Date
Christoph Lendenfeld
dcca6c2b8c Refactor: Remove nla_cache parameter from insert_keyframe
No functional changes.

The parameter was only passed in as `nullptr` or
as empty list that was immediately freed after without use.

Pull Request: https://projects.blender.org/blender/blender/pulls/113817
2023-10-17 11:48:29 +02:00
Campbell Barton
2e0b844b36 Cleanup: spelling in comments 2023-10-14 13:53:00 +11:00
Christoph Lendenfeld
4050b0d6df Refactor: remove argument from ANIM_builtin_keyingset_get_named
No functional changes

`ANIM_builtin_keyingset_get_named` had a `KeyingSet *` argument
that was always passed as `nullptr`
This patch removes it to simplify the code.

Pull Request: https://projects.blender.org/blender/blender/pulls/113677
2023-10-13 15:40:42 +02:00
Christoph Lendenfeld
b753ef73a0 Refactor: convert ListBase of tRKS_DSource to Vector
No functional changes

The keying set code was passing around a list
of `tRKS_DSource` through a lot of functions.
It turns it this was just a ListBase wrapper around `PointerRNA`.

So to make it clearer what is passed around, I replaced the
`ListBase` with a `Vector<PointerRNA>`

To make the use of `ANIM_relative_keyingset_add_source` clearer
I made two functions out of it with different parameters.
Those can take the vector as a reference and
EITHER only an `ID *`
OR an `ID *`, `StructRNA *` and a `void *`

Pull Request: https://projects.blender.org/blender/blender/pulls/113675
2023-10-13 15:06:53 +02:00
Christoph Lendenfeld
7be1b59daa Refactor: keyframing_auto.cc code cleanup
No functional changes

Clean up code by
* moving variables closer to their use
* inverting "if" for early returns
* using the enum type instead of int

Pull Request: https://projects.blender.org/blender/blender/pulls/113617
2023-10-12 17:45:16 +02:00
Christoph Lendenfeld
3792c2720d Refactor: remove ED_ prefix from autokeying functions
No functional changes

Since the functions now live in a namespace,
they no longer need the prefix

as a result there are now 2 functions named
`autokeyframe_object`
which is fine because they take different parameters

If both are needed is for a future patch to investigate

Pull Request: https://projects.blender.org/blender/blender/pulls/113612
2023-10-12 16:32:29 +02:00
Christoph Lendenfeld
1f995917a9 Refactor: Replace autokey macros with functions
No functional changes

The following macros have been replaced with identically named functions
* IS_AUTOKEY_ON
* IS_AUTOKEY_MODE
* IS_AUTOKEY_FLAG

Pull Request: https://projects.blender.org/blender/blender/pulls/113610
2023-10-12 16:20:18 +02:00
Christoph Lendenfeld
a3831fe7af Refactor: Move autokeyframing functions to animrig
No functional changes

The following functions have been moved
`autokeyframe_cfra_can_key`
`autokeyframe_object`
`ED_autokeyframe_object`
`ED_autokeyframe_pchan`
`ED_autokeyframe_property`

they are all in a new file
keyframing_auto.cc
while the declarations are in
ANIM_keyframing.cc

The autokeyframe makros also have been moved

Pull Request: https://projects.blender.org/blender/blender/pulls/113607
2023-10-12 15:44:58 +02:00
Christoph Lendenfeld
edf9bd9acf Refactor: keyframing.cc
No functional changes

Following changes have been made to make the code more readable
* added const where possible
* move variables closer to use
* rename abbreviated variables
* invert `if` and return early

Pull Request: https://projects.blender.org/blender/blender/pulls/113595
2023-10-12 13:27:22 +02:00
Christoph Lendenfeld
555731f8aa Refactor: Move keyframing code to animrig
No functional changes.

Move the following keyframing functions to the animrig folder
* `insert_keyframe_direct`
* `insert_keyframe`
* `delete_keyframe`
* `clear_keyframe`

In order to disentangle the code I had to move the following as well
* `delete_keyframe_fcurve`
* `visualkey_can_use`
* `visualkey_get_values`

In order to sort the functions I made 3 files (and their header counterparts)
* fcurve.cc
* keyframing.cc
* visualkey.cc

The following functions I made public so they won't get duplicated
* `update_autoflags_fcurve_direct`
* `ANIM_setting_get_rna_values`

There are public keyframing functions that
I left in the editors/animation/keyframing.cc file
I'd like to limit the scope of this refactor, and then
clean up the moved functions before moving even more over

Part of #113278

Pull Request: https://projects.blender.org/blender/blender/pulls/113503
2023-10-12 12:46:47 +02:00
Damien Picard
730bb2ee3e I18n: make new bones and bone collections' names translatable
Newly created bones and bone collections get a default name. Like
other types of data, these names should be translated if the user
enabled the translation of new data in the preferences.

This commit adds the appropriate `DATA_()` macro:
- when creating a new armature;
- when creating a new bone;
- when creating a new bone collection through `ANIM_bonecoll_new()`;
- when ensuring that a new bone collection has a unique name;
- when renaming a bone collection;
- in the bone collection tests, to check that new bones have the
  expected translated name.

It also sets the default value of the bone name in the
`ARMATURE_OT_bone_primitive_add()` operator to a null string instead
of "Bone", so that the default name may be chosen while checking for
unique names, since an empty string will default to the translation.

Pull Request: https://projects.blender.org/blender/blender/pulls/113171
2023-10-05 14:38:51 +02:00
Sybren A. Stüvel
ac1c5d943c Anim: make ANIM_bonecolor_posebone_get handle const only
The color returned by `ANIM_bonecolor_posebone_get()` is not supposed
to be edited, so just return it as `const` and take a `const bPoseChannel`
as argument.

This makes the function usable in a wider range of situations, for example
the drawing code (which shouldn't alter any of these colors).
2023-09-25 17:29:04 +02:00
Campbell Barton
aba119e192 Cleanup: quiet CMake uninitialized variable warning, sort file lists 2023-09-22 11:04:25 +10:00
Campbell Barton
31aa6fa073 Cleanup: various non-functional C++ changes 2023-09-22 10:52:40 +10:00
Sybren A. Stüvel
83306754d4 Collada: add bone collection support
Replace the import/export of armature layers with bone collections.

The Old Way:
- Export: Each bone would store which armature layer it was on.
- Import: All armature layers that contain at least a bone are shown.

The New Way:
- Export: Each armature contains a list of its bone collections,
  including which one is active and which ones are visible.
- Export: Each bone stores which bone collection it is on.
- Import: the above data is simply used as-is.

Due to limitations of the current Collada importer code, each "extra"
tag can only occur once per Collada node. This means that it was
impossible to write a `<collection name="Bones">` tag for each bone
collection, as only one of those would actually be stored by the
importer for further processing. To work around this limitation, all
bone collection related tags store their values as newline-separated
strings. Example:

```
<node id="Armature">
  <extra>
    <technique profile="blender">
      <collections sid="collections" type="string">Layer 1
Layer 3b
Group
That One Bone</collections>
      <visible_collections sid="visible_collections" type="string">Layer 1
Layer 3b
That One Bone</visible_collections>
      <active_collection sid="active_collection" type="string">That One Bone</active_collection>
    </technique>
  </extra>
</node>
```
2023-09-21 17:09:25 +02:00
Sybren A. Stüvel
004a348efc Anim, refactor the show/hide all bone collections functions
Instead of setting flags directly, use the `ANIM_bonecoll_{show,hide}`
functions. And introduce the `ANIM_bonecoll_show` function for symmetry.
2023-09-21 17:09:25 +02:00
Sybren A. Stüvel
661065aed4 Refactor: Anim, move function for setting active bone collection by name
Move the 'set active bone collection by name' functionality from RNA
to the ANIM module, so that it can be used in other places.

No functional changes.
2023-09-21 17:09:25 +02:00
Sybren A. Stüvel
62639080bc Anim: armature edit mode, replace 'bone layers' operator with collections
In armature edit mode, replace the 'bone layers' operator with the 'move
to bone collection' operator. This operator now works in both pose mode
and edit mode, and is available with the 'M' hotkey in either mode.
2023-09-19 11:45:40 +02:00
Sybren A. Stüvel
e59944dba4 Anim: armature edit mode 'select by bone color' operator
In the armature edit mode 'select similar' operator, replace the 'select
by same bone group' operator with 'select by same bone color'.
2023-09-18 18:06:06 +02:00
Sybren A. Stüvel
c230c52626 Anim: implement 'Select Grouped' by bone color
The pose mode 'Select Grouped' operator can now select by bone color.
This compares either the theme palette index, or the full custom color.
In other words, if custom colors are visually very similar but binary
not equal, they will be treated as different.

The last bytes of the custom colors (so `solid[3]`, `active[3]`, and
`selected[3]`) aren't used for these comparisons, as the values are
inconsistently either 0 or 255 depending on how the color was set. There
is no way to influence this with the color picker in the GUI, and AFAIK
the alpha channel isn't used for drawing either.
2023-09-18 18:06:06 +02:00
Sybren A. Stüvel
9580c377fe Cleanup: Anim, add some more comments to the bone collection system
Add some TODOs and clarification in comments.

No functional changes.
2023-09-15 14:54:04 +02:00
Sybren A. Stüvel
de13d7861c Anim: when applying overrides, just assert the bone hash is there
Instead of calling `BKE_armature_bone_hash_make(armature)`, just do an
assertion that the bone hash is there.
2023-09-15 14:54:04 +02:00
Sybren A. Stüvel
44d1964b5f Anim: add reverse pointers from bone to collection on overrides
When inserting a bone collection via a library override, make sure that
the reverse pointers (from the bones in the collection to the collection
itself) are also added. These are used for the "given the active bone,
which collections is it in?" kind of queries.
2023-09-15 14:54:04 +02:00
Sybren A. Stüvel
cb2afa6553 Cleanup: Anim, remove out of date note on ANIM_armature_runtime_refresh
The docstring warned about memory not being freed, but that information
is out of date so I removed it.

No functional changes.
2023-09-15 14:54:04 +02:00
Sybren A. Stüvel
8499c6d4b3 Refactor: Anim, consistent abstraction level ANIM_armature_bonecoll_assign
Refactor `ANIM_armature_bonecoll_assign()` to ensure it has a consistent
abstraction level.

No functional changes.
2023-09-15 14:54:03 +02:00
Sybren A. Stüvel
347ffd6262 Anim: add support for renaming bone collections added by overrides
Add a flag `BONE_COLLECTION_OVERRIDE_LIBRARY_LOCAL` that's only set on
bone collections that have been overridden locally.
2023-09-15 14:54:03 +02:00
Sybren A. Stüvel
89aee9defb Anim: store Armature's active bone collection by name
Instead of storing the active bone collection as `BoneCollection*`, store
its name in DNA. This makes it impossible to point to non-owned bone
collections, makes it easier to handle copy-on-write copies, and should
make it possible to use library overrides on it.

This now also introduces a new requirement that bone collections always
have a name. If the name is set to the empty string, the default name
("Bones") will be used instead.

The `active_collection` pointer is still there for ease of access, but
it's been moved to the armature's `runtime` property.

The library overrides part isn't working yet, though.
2023-09-15 14:54:03 +02:00
Sybren A. Stüvel
f1c65c9635 Anim: allow appending bone collections with liboverrides 2023-09-15 14:54:03 +02:00
Nathan Vegdahl
aaddb25fa3 Cleanup: remove unneeded include
In a previous commit fixing a warning, the C++ header include was added,
but the corresponding C header include wasn't removed.  The C++ header
already includes the C header, so including it separately is
redundant.
2023-09-12 10:29:10 +02:00
Campbell Barton
52bd4b73c3 Cleanup: compiler warning from missing include 2023-09-12 14:46:32 +10:00
Nathan Vegdahl
d64e4a387a Fix #111780: bone collections and undo don't work together
The issue was that Armatures have their own edit-mode undo system, but it
didn't account for bone collections yet.

The solution implemented here is to also copy the list of BoneCollections
in each edit-mode undo step, just like EditBones themselves already are.
Additionally, the undo EditBones now have their bone collection membership
remapped to point at those undo copies, so that the entire undo step is
self-contained.

When restoring from an undo step, we simply do the reverse: copy all of
the EditBones and BoneCollections back to the actual armature, and remap
the EditBone collection membership appropriately.

This patch also includes a temporary workaround for a final issue, where
BoneCollection membership information could be lost when undoing pops you
out of edit mode.  The correct solution for this is a bit involved, and
will be part of a future PR.  But the workaround ensures that things
aren't broken in the mean time.

Pull Request: https://projects.blender.org/blender/blender/pulls/111965
2023-09-11 18:28:15 +02:00
Sybren A. Stüvel
0ea79698ac Anim: Add bone.collections.clear() RNA function
Add the RNA function `bone.collections.clear()` to remove a bone from all
its collections.
2023-09-08 15:53:35 +02:00
Nathan Vegdahl
d5b9127e1b Fix: free BoneCollection ID props when the collection is freed 2023-09-05 17:32:01 +02:00
Sybren A. Stüvel
5250ae156e Refactor: move default bone collection name to constant
No functional changes.
2023-09-05 14:57:01 +02:00
Campbell Barton
2a7b2e477f Fix potential non utf8 strings caused by truncation 2023-09-01 11:36:51 +10:00
Campbell Barton
c253d71c67 Fix ANIM_bonecoll_new using a temporary string for the allocation name
Use the function name instead.
2023-09-01 11:25:50 +10:00
Campbell Barton
23e8ffd72d Cleanup: various non-functional C++ changes, format 2023-09-01 11:19:44 +10:00
Pratik Borhade
c75d6ae0ed Fix: Bone collection renaming when empty string
Wrong default value was passed to `BLI_uniquename`.
This default value is used when string is empty after renaming.
the element.

How to reproduce:
- Add bone collection
- double click to rename
- Clear all characters, hit enter (you'll either notice bone collection
  without name or just a suffix)

Pull Request: https://projects.blender.org/blender/blender/pulls/111723
2023-08-31 15:12:27 +02:00
Campbell Barton
3d607be572 Cleanup: spelling in comments 2023-08-30 10:57:12 +10:00
Nathan Vegdahl
a1f081c212 Fix: uninitialized memory in bone collection unit tests
This caused the tests to fail in debug with address sanitizer.
2023-08-29 14:31:18 +02:00
Alexander Gavrilov
f1111808b8 Fix: rename animation curves associated with bone collection properties 2023-08-29 14:31:18 +02:00
Nathan Vegdahl
9eee076a29 Anim: add custom property support for Bone Collections
Pull request: https://projects.blender.org/blender/blender/pulls/109976
2023-08-29 14:31:18 +02:00
Sybren A. Stüvel
998136f7a7 Anim: replace Bone Groups & Armature Layers with Bone Collections
Armature layers (the 32 little dots) and bone groups are replaced with
Bone Collections:

- Bone collections are stored on the armature, and have a name that is
  unique within that armature.
- An armature can have an arbitrary number of bone collections (instead
  of the fixed 32 layers).
- Bones can be assigned to zero or more bone collections.
- Bone collections have a visibility setting, just like objects in scene
  collections.
- When a bone is in at least one collection, and all its collections in
  are hidden, the bone is hidden. In other cases (in any visible
  collection, or in no collection at all), the bone visibility is
  determined by its own 'hidden' flag.
- For now, bone collections cannot be nested; they are a flat list just
  like bone groups were. Nestability of bone collections is intended to
  be implemented in a later 4.x release.
- Since bone collections are defined on the armature, they can be used
  from both pose mode and edit mode.

Versioning converts bone groups and armature layers to new bone
collections. Layers that do not contain any bones are skipped. The old
data structures remain in DNA and are unaltered, for limited forward
compatibility. That way at least a save with Blender 4.0 will not
immediately erase the bone group and armature layers and their bone
assignments.

Shortcuts:

- M/Shift+M in pose/edit mode: move to collection (M) and add to
  collection (shift+M). This works similar to the M/Shift+M menus for
  objects & scene collections.
- Ctrl+G in pose mode shows a port of the old 'bone groups' menu. This
  is likely to be removed in the near future, as the functionality
  overlaps with the M/Shift+M menus.

This is the first commit of a series; the bone collections feature will
be improved before the Blender 4.0 release. See #108941 for more info.

Pull request: https://projects.blender.org/blender/blender/pulls/109976
2023-08-29 14:31:18 +02:00
Sybren A. Stüvel
042c5347f4 Anim: move bone colors from bone groups to individual bones
Move control over the color of bones from bone groups to the bones
themselves. Instead of using bone groups (which are defined on the pose,
and thus owned by the object), the color is stored on:

- the bone (`struct Bone`, or RNA `armature.bones['bone_name'].color`)
- a possible override on the pose bone (`struct bPoseChannel`, or RNA
  `ob.pose.bones['bone_name'].color`).

When the pose bone is set to its default color, the color is determined
by the armature bone. In armature edit mode, the armature bone colors
are always used, as then the pose data is unavailable.

Versioning code converts bone group colors to bone colors. If the
Armature has a single user, the group color is stored on the bones
directly. If it has multiple users, the group colors will be stored on
the pose bones instead.

The bone group color is not removed from DNA for forward compatibility,
that is, to avoid immediate dataloss when saving a 3.6 file with 4.0.

This is part of the replacement of bone groups & armature layers with
bone collections. See the design task at #108941.

Pull request: https://projects.blender.org/blender/blender/pulls/109976
2023-08-29 14:31:18 +02:00
Campbell Barton
e955c94ed3 License Headers: Set copyright to "Blender Authors", add AUTHORS
Listing the "Blender Foundation" as copyright holder implied the Blender
Foundation holds copyright to files which may include work from many
developers.

While keeping copyright on headers makes sense for isolated libraries,
Blender's own code may be refactored or moved between files in a way
that makes the per file copyright holders less meaningful.

Copyright references to the "Blender Foundation" have been replaced with
"Blender Authors", with the exception of `./extern/` since these this
contains libraries which are more isolated, any changed to license
headers there can be handled on a case-by-case basis.

Some directories in `./intern/` have also been excluded:

- `./intern/cycles/` it's own `AUTHORS` file is planned.
- `./intern/opensubdiv/`.

An "AUTHORS" file has been added, using the chromium projects authors
file as a template.

Design task: #110784

Ref !110783.
2023-08-16 00:20:26 +10:00
Sybren A. Stüvel
e604f3db91 Refactor: Anim, abstractions for armature layers
Add an API for armature layer access. Instead of accessing `arm->layer`
and friends directly, the code now uses this API. This will make things
easier to replace by bone collections in the future.

The functions are named "bonecoll" (short for "bone collection"), as
that's the soon-to-be-introduced replacement for armature layers. This
API is the first step towards that replacement, and should help to
reduce the changes necessary when functional changes are committed.

This also creates a new module `source/blender/animrig` for Animation &
Rigging code. This will, for example, house the bone collection system
in the near future.

There is a bunch of code currently spread across blenkernel and editors
in a rather ad-hoc way; it is intended that at some point that code gets
moved into `animrig` as well (or at least the subset of that code where
such a move makes sense; brain still required).

Ref: #108941

No functional changes.
2023-07-27 14:57:01 +02:00