Commit Graph

81 Commits

Author SHA1 Message Date
Christoph Lendenfeld
83287624bc Anim: Change how Only Insert Needed works
When keyframing with the `Only Insert Needed` flag enabled,
the code was able to delete keyframes in certain cases.
This behavior is removed and replaced with the following rules.

* If there is a key on the current frame, and it has the same value, skip it.
* If there is no key, but the FCurve evaluates to the same value, skip it.
* Add a key in all other cases.

Remove that functionality for consistency and simplify the code around it.

Pull Request: https://projects.blender.org/blender/blender/pulls/115360
2023-11-30 14:45:47 +01:00
Campbell Barton
dfbda79cbd Cleanup: declare pointers const where possible 2023-11-30 16:42:40 +11:00
Campbell Barton
15db0cb446 Cleanup: use style for doxygen comment blocks 2023-11-30 14:15:11 +11:00
Christoph Lendenfeld
265aebd7be Fix: FCurve colors on bones
New FCurves for bones were not automatically set to `FCURVE_COLOR_AUTO_RGB`
because the RNA path couldn't be resolved.

That was because the `PointerRNA` passed into the function points to the bone,
but the rna path is relative to the ID.
Fixed by resolving the path from the bones owner ID

Pull Request: https://projects.blender.org/blender/blender/pulls/115517
2023-11-28 13:29:46 +01:00
Ray Molenkamp
6b70c04724 Cleanup: CMake: Modernize bf_depsgraph dependencies
Pretty straightforward

- Remove any bf_depsgraph paths from INC
- Add a dependency though LIB when missing

context: https://devtalk.blender.org/t/cmake-cleanup/30260

Pull Request: https://projects.blender.org/blender/blender/pulls/115422
2023-11-25 22:51:59 +01:00
Christoph Lendenfeld
a65cd72479 Fix: Segfault when inserting keyframes
`action_fcurve_ensure` can be passed a nullptr for
the PointerRNA, which the function didn't check for
after the refactor.
2023-11-24 15:28:20 +01:00
Christoph Lendenfeld
bb10004377 FIx: memory leak when inserting keys
The issue was that RNA_path_from_ID_to_property
returns a char * that the caller is expected to free.
But the code was storing it in a std::string
2023-11-24 13:07:09 +01:00
Christoph Lendenfeld
30b0c5b225 Fix: Inserting keys no longer sets the FCurve channel color
When pressing `I` in the viewport, the colors of the FCurve channels were no longer set correctly.

Caused by #113504

Fix by removing the flag that determined that in the first place,
and read straight from the user preferences. Then move the code
that sets the mode on the FCurve into the function that actually creates it.

For 99% of cases the code went to the user preference flag `AUTOKEY_FLAG_XYZ2RGB`
and if that was set, the `INSERTKEY_XYZ2RGB` would be set. The only case where this
was not from the user preferences was from custom keying sets.
There was an override flag for FCurve colors on custom keying sets.
I removed that with this patch since the use case is not apparent
and custom keying sets are hardly used.

Pull Request: https://projects.blender.org/blender/blender/pulls/115297
2023-11-24 13:05:10 +01:00
Christoph Lendenfeld
fc0ede2799 Refactor: Move insert_key_rna from editors to animrig
No functional changes.

The function is useful for autokeying as well, which is why
it is being moved out of the editors.

Pull Request: https://projects.blender.org/blender/blender/pulls/115349
2023-11-24 12:56:46 +01:00
Christoph Lendenfeld
1905667967 Refactor: Rename eAutokey_Flag enum
No functional changes.

Rename the `eAutokey_Flag` to `eKeyInsert_Flag`
to indicate that it is not only used for auto keying.
Also rename the enum items to better reflect what they are used for.

Pull Request: https://projects.blender.org/blender/blender/pulls/115295
2023-11-23 12:09:23 +01:00
Christoph Lendenfeld
a99e419b6e Anim: Insert keyframes without keying sets
When animators want to key something in the viewport,
the code needs to know *which properties* should be keyed of that selected thing.
So far that was done with keying sets, and a pop-up that let's
you choose the keying set to use. You can get rid of the popup by
choosing a keying set ahead of time. But that is also not always desirable.

That pop-up is quite confusing and gives way too many options.
To simplify this process this PR adds a User Preference option to choose one or more of:
* Location
* Rotation
* Scale
* Rotation Mode
* Custom Properties

Now whenever the `I` key is pressed in the viewport,
and no keying set is enabled, it reads the preferences for which channels to insert.

# User Facing changes
* The popup will not be shown when pressing the hotkey,
 but you can still explicitly use keying sets by going to the menu
* Which channels are keyed is defined by a User Preference setting under animation
* when a keying set is used explicitly, the User Preference settings are ignored

Part of #113278

Pull Request: https://projects.blender.org/blender/blender/pulls/113504
2023-11-21 15:38:01 +01:00
Christoph Lendenfeld
a4f086ec1b Refactor: move autokeyframe_pose
No functional changes.

Move the function `autokeyframe_pose` from
`transform_convert_armature.cc` to `keyframing_auto.cc`

The function has a lot of overlap with `autokeyframe_object` so it
can potentially be simplified later on.

Pull Request: https://projects.blender.org/blender/blender/pulls/115051
2023-11-17 16:06:15 +01:00
Christoph Lendenfeld
10fae637aa Refactor: Extract function to initialize a BezTriple
No functional changes.

The function `insert_vert_fcurve` also initialized a `BezTriple` from the flags it got.
Extract that logic into a separate function so it can be reused elsewhere

Pull Request: https://projects.blender.org/blender/blender/pulls/115039
2023-11-17 11:34:30 +01:00
Hans Goudey
3d57bc4397 Cleanup: Move several blenkernel headers to C++
Mostly focus on areas where we're already using C++ features,
where combining C and C++ APIs is getting in the way.

Pull Request: https://projects.blender.org/blender/blender/pulls/114972
2023-11-16 11:41:55 +01:00
Christoph Lendenfeld
06bcbc644c Refactor: extract function from insert_keyframe_value
No functional changes.

Extract code from the function `insert_keyframe_value`
to make it easier to use in other places.
I created a new function `remap_driver_frame` that
removes 3 parameters from the function.
And I removed the requirement for a `ReportList`
by just returning false and letting the caller
create a message.

Pull Request: https://projects.blender.org/blender/blender/pulls/114700
2023-11-10 12:22:45 +01:00
Campbell Barton
58ea0e051f Cleanup: spelling in comments 2023-11-09 09:54:28 +11:00
Campbell Barton
6bba008325 Cleanup: format 2023-11-09 09:34:49 +11:00
Christoph Lendenfeld
1b95e74b8a Cleanup: comment style in animrig
No functional changes.

Functions moved to animrig recently did not adhere to
the comment style guidelines

Pull Request: https://projects.blender.org/blender/blender/pulls/114586
2023-11-07 17:24:36 +01:00
Christoph Lendenfeld
c8ccd3d58a Refactor: Rename functions in ANIM_animdata.hh
No functional changes.

Renaming the following functions
`ANIM_remove_empty_action_from_animdata` and
`ANIM_fcurve_delete_from_animdata`
to
`animdata_remove_empty_action` and
`animdata_fcurve_delete`

The `ANIM` prefix was no longer needed since the code is now in
a namespace. In order to make the function name consistent with
the functions in `fcurve.cc` the thing it modifies is now at the
start of the function name

Pull Request: https://projects.blender.org/blender/blender/pulls/114584
2023-11-07 17:03:29 +01:00
Christoph Lendenfeld
fc74f341a5 Refactor: Move code related to animdata to animrig
No functional changes.

Move the following functions
`ANIM_fcurve_delete_from_animdata` and
`ANIM_remove_empty_action_from_animdata`
to
`ANIM_animdata.hh` / `animdata.cc`
in animrig

This removes some includes to `ED_anim_api.hh`
from animrig

Pull Request: https://projects.blender.org/blender/blender/pulls/114581
2023-11-07 16:46:38 +01:00
Christoph Lendenfeld
69a3c5c7fc Refactor: move code related to fcurve keyframe insertion
No functional changes.

Move the functions
`insert_vert_fcurve` and
`insert_bezt_fcurve`
from `ED_keyframing.hh` / `keyframing.cc`
to `ANIM_fcurve.hh` / `fcurve.cc`
in animrig

Pull Request: https://projects.blender.org/blender/blender/pulls/114570
2023-11-07 14:33:52 +01:00
Christoph Lendenfeld
d08582c4d6 Cleanup: Remove unused declaration and include
No functional changes.
2023-11-07 13:20:46 +01:00
Christoph Lendenfeld
02b41a5d23 Refactor: Move code for actions into its own file
No functional changes.

Moving the following functions
`action_fcurve_ensure` and
`action_fcurve_find`
from
`ANIM_fcurve.hh`/`fcurve.cc`
to
`ANIM_action.hh`/`action.cc`

This is an effort to ensure that the fcurve files don't need to know
about the container they are stored in so we can swap out
the container more easily.

Pull Request: https://projects.blender.org/blender/blender/pulls/114575
2023-11-07 13:17:43 +01:00
Christoph Lendenfeld
a338ecb9cb Refactor: fcurve.cc
No functional changes.

Improve the readability of the code by

* returning early where possible
* moving variables closer to where they are used
* renaming variables

Pull Request: https://projects.blender.org/blender/blender/pulls/114568
2023-11-07 10:53:43 +01:00
Campbell Barton
6297bbe931 License headers: attribute copyright to "Blender Authors"
See #110784, it seems that merging functionality reintroduced the old
convention.
2023-11-07 15:42:52 +11:00
Christoph Lendenfeld
794565ba0d Refactor: Rename functions in animrig to remove prefix
No functional changes.

Since the following functions are now in a C++ namespace, their prefix can be removed:
* ANIM_setting_get_rna_values -> get_rna_values
* ED_action_fcurve_find -> action_fcurve_find
* ED_action_fcurve_ensure -> action_fcurve_ensure

Pull Request: https://projects.blender.org/blender/blender/pulls/114450
2023-11-03 12:03:35 +01:00
Christoph Lendenfeld
cfb50a2e2e Cleanup: Comments in animrig
No functional changes.

For all the recently moved keyframing code I did the following:
* Remove comments that just repeat what the code is doing.
* Move comments for public functions to their location in the header file.
* Make sure comments are formatted properly with a capital letter at the start and a dot at the end.

Pull Request: https://projects.blender.org/blender/blender/pulls/114448
2023-11-03 11:53:42 +01:00
Christoph Lendenfeld
0f5e7c7469 Refactor: Move fcurve functions to animrig
No functional changes.

Moving the following two functions to animrig
`ED_action_fcurve_ensure`
`ED_action_fcurve_find`

Pull Request: https://projects.blender.org/blender/blender/pulls/114445
2023-11-03 11:15:27 +01:00
Christoph Lendenfeld
5beb513be1 Refactor: move ANIM_setting_get_rna_values to animrig
No functional changes.

Moving `ANIM_setting_get_rna_values` to the animrig folder and into the `blender::animrig namespace`

Pull Request: https://projects.blender.org/blender/blender/pulls/114444
2023-11-03 10:55:10 +01:00
Campbell Barton
6983c14955 Cleanup: spelling in comments, use doxygen doc-strings 2023-11-02 16:43:04 +11:00
Christoph Lendenfeld
265858525e Refactor: ANIM_setting_get_rna_values to return a Vector
No functional changes.

Changing old C code to C++ by returning a `Vector` from `ANIM_setting_get_rna_values`.
This reduces the argument count for that function and simplifies the code.

Pull Request: https://projects.blender.org/blender/blender/pulls/113931
2023-10-24 09:01:38 +02:00
Campbell Barton
14247f9194 Cleanup: add missing source files to CMake 2023-10-23 10:19:57 +11:00
Campbell Barton
87a969e7fc Cleanup: sort files in CMake 2023-10-23 10:09:52 +11:00
Sergey Sharybin
85c557ffa2 Cleanup: Rename BLI_string_utils.h to BLI_string_utils.hh
All users of it are now C++, which opens doors to add C++ to the
public API.
2023-10-20 10:27:26 +02:00
Christoph Lendenfeld
3fc2077c2a Fix: autokeyframing when pasting poses no longer worked
The if check wasn't properly inverted in
7be1b59daa

Pull Request: https://projects.blender.org/blender/blender/pulls/113940
2023-10-19 16:23:04 +02:00
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