Commit Graph

27227 Commits

Author SHA1 Message Date
Sybren A. Stüvel
12fe0dd0cf Anim: make action/slot assignment code more generic
In the `blender::animrig` namespace, add two new functions
`generic_assign_action()` and `generic_assign_action_slot()`. These are
now used as basis for (un)assigning Actions and Action slots, both
directly on the ID and for NLA strips.

The method `Action::assign_id()` has been removed, in favour of free
functions for (un)assigning Actions and slots.

This is almost a non-functional change. The only thing that's different
is when both an Action and a slot should get assigned in one go.

Old behaviour: the slot would be inspected, and if not suitable for the
animated ID, the entire operation would be aborted. In other words, any
previously-assigned Action would still be assigned, making this an
atomic operation.

New behaviour: assigning an Action + a slot is no longer atomic. First
the new Action is assigned (which uses the automatic slot selection
based on the name). If after this the given slot cannot be assigned, the
new Action + the auto-selected slot are still kept.

This makes the Action & slot assignment more uniform in behaviour, where
"assign this Action + this slot" as one operation behaves the same as
two sequential operations "assign this Action" + "assign this slot". If
it turns out to be confusing, we can always improve things.

The return code for slot assignment is now more explicit (enum instead
of boolean), so that the caller can decide what to do in case of which
error (like unassigning the slot if the automatic behaviour is
unwanted).

Pull Request: https://projects.blender.org/blender/blender/pulls/127712
2024-09-16 19:31:35 +02:00
Hans Goudey
22cf74d23b Cleanup: Use C++ Array for dependent shape key data
Avoids manual memory management and potentially avoids
an allocation with the inline buffer.
2024-09-16 12:46:54 -04:00
Sybren A. Stüvel
c64108305e Cleanup: avoid unused parameter warning in non-experimental build
Avoid warnings about unused parameter `slot_handle` when building without
experimental features.

No functional changes.
2024-09-16 12:30:55 +02:00
Falk David
cb0ab83eab Fix #127527: Crash drawing with non-GP material
It was possible for a Grease Pencil object to have a material
with no Grease Pencil settings. This can lead to crashes in many
places because it's often assumed that the material has
these settings.

The fix makes sure that `BKE_object_material_get` returns
a Grease Pencil material when called on a Grease Pencil
object.  If the Grease Pencil settings don't exist,
it returns `nullptr`.

In the future, it should be possible to have these materials
and code that reads from the settings should fall back to
the default material.

Pull Request: https://projects.blender.org/blender/blender/pulls/127570
2024-09-16 12:03:05 +02:00
Campbell Barton
4ec0cce30a WM: improve thumbnail scaling performance (debug builds)
Saving files could take ~3-4 seconds on debug builds because of new
imbuf scaling logic.

Even though debug performance usually isn't much of a consideration,
it gets in the way of development.

Since thumbnails don't require the same accuracy as the sequencer or
compositor, use a faster scaling method that uses a box-filter clamped
to integer bounds & integer math.

In practice the difference between the resulting thumbnails isn't
noticeable in my tests.

For debug build with ASAN this gives a ~25x speedup,
for release builds it gives a ~1.4x speedup which is to be
expected with a more approximate scaling method.
2024-09-16 19:51:32 +10:00
Sybren A. Stüvel
9530852347 Anim: avoid division by zero in Action constraint
Avoid a division by zero when the Action constraint has the same value
for its 'min' and 'max' parameters.

When `min` and `max` are equal, the code will now choose either `min`
(when `target value` ≤ `min`) or max (`target value` > `max`).

Pull Request: https://projects.blender.org/blender/blender/pulls/127583
2024-09-16 11:49:54 +02:00
Hans Goudey
a0eccb4550 Cleanup: Multires: Use FunctionRef and lambdas in reshape 2024-09-15 22:01:13 -04:00
Hans Goudey
aba29c655a Cleanup: Multires: Use C++ threading API in reshape file 2024-09-15 22:01:13 -04:00
Campbell Barton
2360a3911c BLI_listbase: add a utility to check the number of items in the list
To avoid unnecessary looping over listbase items the function
`BLI_listbase_count_at_most` was used however it resulting in an awkward
expression: `BLI_listbase_count_at_most(list, count + 1) == count`
replace this with `BLI_listbase_count_is_equal_to(list, count)`.
2024-09-16 11:39:00 +10:00
Jacques Lucke
13d30e22a1 Fix: modifier execution time not set for grease pencil modifiers 2024-09-15 18:02:51 +02:00
Campbell Barton
8b2ab34ec6 Cleanup: avoid redundant copy to access the filename 2024-09-15 23:14:13 +10:00
Campbell Barton
17f809718a Cleanup: avoid shadowing variables 2024-09-15 23:14:10 +10:00
Campbell Barton
9b39b4c91c Cleanup: use const pointers/references 2024-09-15 23:14:09 +10:00
Campbell Barton
9be29e1bbc Cleanup: match function & declaration names 2024-09-15 23:14:07 +10:00
Campbell Barton
0d9c4bc5b3 BKE_lib: avoid potential read uninitialized memory in BKE_id_copy_*
BKE_id_copy_in_lib took an argument `r_newid` which was was to
initialize `new_id` in the functions body.

While this may not have caused any user visible bugs, it's error prone,
one caller even passed in an uninitialized pointer.

- Rename `r_newid` to `new_id_p` since it's not a return argument.
- Initialize the value from all callers.
2024-09-15 23:07:17 +10:00
Jacques Lucke
35bb4f4711 Geometry Nodes: support accessing repeat zone lazy-function graph from Python
The tricky thing here is that this graph is only generated while geometry nodes
is evaluated and is generally only stored temporarily. To make it accessible via
Python, the accessor method will cause a reevaluation specifically to log the
generated graph.
2024-09-15 00:56:53 +02:00
Hans Goudey
c6ce6dbe01 BLI: Add IndexMask set_bits function
This is like "to_bits" but doesn't clear the bit span first.

Pull Request: https://projects.blender.org/blender/blender/pulls/127625
2024-09-14 21:09:41 +02:00
Hans Goudey
7283cbef65 Cleanup: Sculpt: Add todo comments for PBVH data to remove 2024-09-14 13:01:42 -04:00
Hans Goudey
a021dd36ef Cleanup: Sculpt: Remove unnecessary PBVH node flags
These have been made redundant by previous commits.
Part of #118145.
2024-09-14 13:01:42 -04:00
Hans Goudey
0499e061d0 Cleanup: Sculpt: Remove drawing update tests
Updating attributes is now done specifically for each attribute,
and topology and visibility updates tag the draw cache data
explicitly too. That makes checking for updates with these
tags unnecessary.
2024-09-14 13:01:42 -04:00
Hans Goudey
0b4820b563 Cleanup: Sculpt: Deduplicate node visibility update on build 2024-09-14 13:01:42 -04:00
Hans Goudey
b77ff173b0 Refactor: Sculpt: Use bit vector for visibility update tags
Also refactor topology update tags, which are used quite similarly
(they mean the same for the drawing code, except for BMesh).

Part of #118145.
2024-09-14 13:01:42 -04:00
Hans Goudey
65c2e5abde Cleanup: Sculpt: Remove unused PBVH redraw tag function 2024-09-14 13:01:42 -04:00
Hans Goudey
76c322047e Sculpt: Only re-upload mask attribute data
Similar to the previous commits, previously all GPU buffers
were recreated when only masks changed. Now only
that masks are re-uploaded, using the same mechanism.

Part of #118145.
2024-09-14 13:01:42 -04:00
Hans Goudey
30c1475dfd Sculpt: Update node mask status eagerly
Similar to 7b69c82494.
We didn't make any good use of the time in between changing
mask values and recalculating whether nodes were fully masked
or not masked at all. There was no point in the lazy calculation.
Eager calculation should be faster too, for the same reason as
the above commit.

Part of #118145.
2024-09-14 13:01:42 -04:00
Hans Goudey
d24e8029d2 Sculpt: Only re-upload face color attribute data
Similar to the previous commit, previously all GPU buffers
were recreated when only a color attribute changed. Now only
that attribute is re-uploaded, using the same mechanism.

Part of #118145.
2024-09-14 13:01:42 -04:00
Hans Goudey
60ab232afb Sculpt: Only re-upload face set data when changed
Similar to the previous commit, previously all GPU buffers
were recreated when only face sets changed. Now only face
sets are re-uploaded, using the same mechanism.

Part of #118145.
2024-09-14 13:01:42 -04:00
Hans Goudey
0c677e9494 Sculpt: Only change position draw buffers on PBVH deformation
Previously tagging node positions dirty set the `PBVH_UpdateDrawBuffers`
flag which was then used by `node_draw_update_mask` and
`tag_all_attributes_dirty`, which, as hinted by the name, causes a refresh
of all the PBVH GPU vertex buffers, not just positions and normals.

Instead of using that flag, add a function to the draw cache to tag only
position-related data dirty. This should give a performance improvement
when there are also face sets, masks, and/or generic attributes being
extracted for drawing.

Part of $118145.
2024-09-14 13:01:42 -04:00
Hans Goudey
900184ac4b Sculpt: Use separate bit vector for BVH node normals dirty tags
Similar to 7b69c82494.
Part of #118145.
2024-09-14 13:01:42 -04:00
Hans Goudey
5b03fee0d2 Sculpt: Use bit vector for bounds dirty tags
Reduce the amount of memory used for the tags by 8x
and improve the performance of changed nodes IndexMask
creation.

Part of #118145.
2024-09-14 13:01:41 -04:00
Jacques Lucke
2274d6a4b1 Fix: subversion bump because updated Python API in previous commit
This changed the API: 54a13d462f
2024-09-14 17:28:36 +02:00
Campbell Barton
8a29277ca8 Logging: replace print with logging if an animation fails to load
Also remove noisy print when a thumbnail can't be generated from an
animation. Similar prints have been commented and mainly seem useful
for debugging.
2024-09-14 15:26:12 +10:00
Campbell Barton
6a1bd2ff40 Cleanup: use C++ comments for disabled code 2024-09-14 12:35:00 +10:00
Hans Goudey
7b69c82494 Refactor: Sculpt: Tag all nodes positions changed together, store in array
Replace the `PBVH_UpdateBB` flag with a separate vector of booleans.
The simplest impact of this is that we can tell when there are no changed
nodes in constant time. Besides that, it also works better with the recent
IndexMask usage for selections of nodes, and allows better const
correctness too, since nodes themselves don't have to be changed
when positions are changed. This also leads into plans to change PBVH
draw data tagging to avoid having to reupload all attributes when only
one changes.

Part of #118145.

Pull Request: https://projects.blender.org/blender/blender/pulls/127587
2024-09-13 21:31:08 +02:00
Falk David
d911d673a4 Cleanup: Fix compiler warnings
Cleanup unused variable and remove unecessary typedef.
2024-09-13 17:54:35 +02:00
casey bianco-davis
50770bd8f5 GPv3: Add support for transform object origin.
Implements support for `transform only origins`.

Pull Request: https://projects.blender.org/blender/blender/pulls/126446
2024-09-13 17:06:43 +02:00
Hans Goudey
613e535fb8 Refactor: Sculpt: Remove SculptSession scene pointer
Part of #118145.
2024-09-13 10:26:50 -04:00
Hans Goudey
bde4efe1f5 Refactor: Sculpt: Remove SculptSession face visibility pointer
Part of #118145.
2024-09-13 10:26:50 -04:00
Hans Goudey
27e2062eac Refactor: Sculpt: Remove SculptSession mesh size variables
Part of #118145.
2024-09-13 10:26:50 -04:00
Hans Goudey
1f7d594aca Refactor: Sculpt: Remove SculptSession face sets pointer
Part of #118145.
2024-09-13 10:26:50 -04:00
Sybren A. Stüvel
7916a33be0 Anim: correctly auto-sync NLA strip length for slotted Action
When syncing the NLA strip length with the Action it uses, use the
length of the assigned action slot. Previously the entire Action was
considered when determining the length.

Pull Request: https://projects.blender.org/blender/blender/pulls/127573
2024-09-13 15:10:46 +02:00
Sybren A. Stüvel
b952782a44 Refactor: Anim, move Action queries from BKE to the animrig::Action class
Move the following BKE functions to the `animrig::Action` class. Some of
those will be extended to support slots in a future commit; for now they
still operate on all F-Curves in the Action.

| Old                             | New                                 |
|---------------------------------|-------------------------------------|
| `BKE_action_frame_range_calc()` | `Action::get_frame_range_of_keys()` |
| `BKE_action_frame_range_get()`  | `Action::get_frame_range()`         |
| `BKE_action_has_motion()`       | `Action::has_keyframes()`           |
| `BKE_action_has_single_frame()` | `Action::has_single_frame()`        |
| `BKE_action_is_cyclic()`        | `Action::is_cyclic()`               |

Implementations have been copied from the BKE functions. The frame range
functions now return `float2` instead of requiring two `float *r_…`
return parameters.

The `has_motion` function is now renamed to `has_keyframes`, as that is
what the implementation was actually testing for.

The functions now no longer are null-safe. The BKE functions handled a
null action pointer, but IMO that doesn't make sense, and in none of the
call sites I could find where this would actually be valid.

No functional changes.

Ref: #127489

Pull Request: https://projects.blender.org/blender/blender/pulls/127512
2024-09-13 15:04:47 +02:00
Sybren A. Stüvel
65728f16e7 Fix #127397: Duplicating layered actions makes things not animate
Duplicating an Action stashes the original one on the NLA. The NLA
evaluation code didn't properly handle the special case of an all-muted
NLA (all stashed actions are muted there) when a layered Action was
assigned directly to the animated ID.

The code is now refactored to remove this special handling from the
`animsys_calculate_nla()` function. Instead it now just returns whether it
did anything. The caller can then decide to evaluate the main Action
instead. This ensures that there is only one "evaluate the main Action"
branch in the `BKE_animsys_evaluate_animdata()` function.

Pull Request: https://projects.blender.org/blender/blender/pulls/127569
2024-09-13 14:19:22 +02:00
Sybren A. Stüvel
7cb77d925a Anim: add NLA evaluation of slotted Actions
Add support for slotted Actions to the NLA evaluation code.

This also affects the pose library code and the Action Constraint. These
both share some Action evaluation logic with the NLA. They now
explicitly looks at only the first Action slot. The Action Constraint will
have to be updated to have an explicit slot selector, but that's for another
commit.

Pull Request: https://projects.blender.org/blender/blender/pulls/127425
2024-09-13 12:34:50 +02:00
Sybren A. Stüvel
7cd3f2aabb Refactor: Anim, prepare for slotted Action support to quaternion eval
Refactor to prepare for slotted action support to the evaluation of
quaternion F-Curves.

Since slotted Actions store F-Curves in an array, you cannot iterate over
them any more via the `ListBase` pointer `fcurve.next`. Quaternion
evaluation code has been refactored to work on a span of F-Curves instead
of just getting the first one.

For now, slotted Actions just evaluate their first slot only. A future
commit will add a slot handle parameter to evaluate the correct slot.
2024-09-13 12:34:48 +02:00
casey bianco-davis
1df3388fae GPv3: Create weights on draw for new strokes.
Implements the legacy  `weight_data_add` button for GPv3.

Note: This PR properly accounts for the bone's transformation when applying so that the stroke does not appear to teleport after drawing, unlike the legacy system.

Pull Request: https://projects.blender.org/blender/blender/pulls/119302
2024-09-13 11:15:31 +02:00
Campbell Barton
81e2ccbf2b Cleanup: spelling in comments 2024-09-13 10:56:26 +10:00
Hans Goudey
d64f62e4fa Sculpt: Update BVH node bounds in deformation loops
Updating the node bounds just after deforming the vertices in the
node is faster because the position data is still fresh in CPU caches.
Updating it later on means all the other nodes have been processed
in the meantime which will evict that position data from the caches.

This results in a 1.11x improvement in the brush benchmark timing,
from 0.495s to 0.438s on a Ryzen 7950x (best of 5 runs).

As part of the change, the update tagging has completely moved
to each brush implementation. This continues the process of
making each brush more independent.

Part of #118145.

Pull Request: https://projects.blender.org/blender/blender/pulls/127536
2024-09-12 23:45:52 +02:00
Hans Goudey
dd9b3e4fac Refactor: Sculpt: Remove vertex to face map from SculptSession
Just retrieve it from the mesh as necessary, it's already cached there.
Part of #118145.
2024-09-12 15:47:11 -04:00
Hans Goudey
43476712cf Refactor: Sculpt: Remove SculptSession mesh topology array references
Part of #118145.
2024-09-12 15:36:58 -04:00