Commit Graph

27270 Commits

Author SHA1 Message Date
Jacques Lucke
4aa99f5647 Fix: add missing virtual destructor 2024-09-20 19:24:37 +02:00
Julian Eisel
a38c96b92c Sculpt/Paint: Bring back support for multiple brush based tools
Design: https://projects.blender.org/blender/blender/issues/126032

The brush assets project merged all brush based tools into a single, "Brush"
tool. After feedback, we want to bring back some of the previous brush based
tools. For example in grease pencil draw mode, not having an eraser or fill tool
available, and having to go through all the brush assets instead made the
workflow more cumbersome, and features less discoverable (an eraser tool in the
toolbar is quite easy to find, a brush deep down in the asset library may not
be).

With this commit we can add back some tools for specific brush types in sculpt &
paint modes. The follow up commit will start with the eraser and fill tools for
grease pencil draw mode, but more tools in other modes are expected to follow.

For every brush type that has a tool in the toolbar, the last used brush is
remembered. This is the biggest part of the changes here.

Brush asset popups will only show the brushes supported by the active tool for
now. The permanent asset shelf region displays all brushes. Activating a brush
that isn't compatible with the current tool will also activate the general
"Brush" tool, but while the brush tool is active we never switch to another one
(e.g. activating an eraser brush will keep the "Brush" tool active). All this
might change after further feedback.

Pull Request: https://projects.blender.org/blender/blender/pulls/125449
2024-09-20 18:09:31 +02:00
Jacques Lucke
3ccfa65245 Geometry Nodes: support packing bakes into .blend files
Previously, it was only possible to bake to disk with geometry nodes. This patch
adds support for storing the baked data directly in the .blend file.

By default, new bakes are stored in the .blend file now. Whether a new bake
should be packed or stored on disk can be configured in two places: in the
properties of the bake node and in the bake panel of the modifier. These
settings don't affect existing bakes, only the next bake.

To unpack or pack an individual bake, there is a new operator button next to the
bake button. The icon and the label below indicate where the bake is currently
stored. The label now also contains the size of the bake.

To unpack or pack all bakes, the `File > External Data > Pack Resources / Unpack
Resources` operators can be used. The unpack operator also has a new title that
mentions the number if individual files separate from the number of bakes. This
works better than just listing a number of files because a bake can consist of
many files.

Pull Request: https://projects.blender.org/blender/blender/pulls/124230
2024-09-20 16:18:12 +02:00
Bastien Montagne
b2e50d5886 Revert "Cleanup: add missing struct qualifier"
`struct` keyword for members and parameters is not necessary in C++
headers, as long as the struct has been declared previously.

This reverts commit 09e459589f.
2024-09-20 13:42:13 +02:00
Bastien Montagne
3e03576b09 Add more control over ID renaming behavior.
This commit adds low-level logic in BKE to support three behaviors in
case of name conflict when renaming an ID:
1. Always tweak new name of the renamed ID (never modify the other ID
  name).
2. Always set requested name in renamed ID, modifying as needed the
  other ID name.
3. Only modify the other ID name if it shares the same root name with the
  current renamed ID's name.

It also adds quite some changes to IDTemplate, Outliner code, and
RNA-defined UILayout code, and the lower-level UI button API, to allow
for the new behavior defined in the design (i.e. option three from above list).

When renaming from the UI either 'fails' (falls back to adjusted name) or forces
renaming another ID, an INFO report is displayed.

This commit also fixes several issues in existing code, especially
regarding undo handling in rename operations (which could lead to saving
the wrong name in undo step, and/or over-generating undo steps).

API wise, the bahavior when directly assigning a name to the `ID.name`
property remains unchanged (option one from the list above). But a new
API call `ID.rename` has been added, which offers all three behaviors.

Unittests were added to cover the new implemented behaviors (both at
BKE level, and the RNA/Py API).

This commit implements #119139 design.

Pull Request: https://projects.blender.org/blender/blender/pulls/126996
2024-09-20 13:36:50 +02:00
Campbell Barton
09e459589f Cleanup: add missing struct qualifier 2024-09-20 19:52:01 +10:00
Bastien Montagne
60013228e1 Fix #126205: Do not rebuild collection caches on any ID deletion.
Deleting ID would systematically call `BKE_main_collection_sync_remap`,
which would invalidate all collection caches. This should only be needed
when deleting a Scene, Collection or Object ID.

Pull Request: https://projects.blender.org/blender/blender/pulls/127866
2024-09-20 11:14:22 +02:00
Sybren A. Stüvel
615cb46412 Anim: add Action Slot selector to Action Constraint
Add slotted Actions support to Action constraints.

The user interface can be improved once #127751 lands.

Ref: #120406
Pull Request: https://projects.blender.org/blender/blender/pulls/127749
2024-09-20 08:07:15 +02:00
Sean Kim
e37f5616f5 Cleanup: Make depth naming variables consistent
Follow up to 5d40992fe8.

In the PBVH API, some contexts that take a `float *` parameter named
`depth` use it purely as a return value, other places, however, read
from and write to this parameter.

In the former case, this commit either adds or keeps the `r_` prefix, in
the latter, this commit ensures the parameter has no prefix to avoid
misleading future readers.

Pull Request: https://projects.blender.org/blender/blender/pulls/127886
2024-09-20 06:50:54 +02:00
Hans Goudey
9d225f7116 Sculpt: Avoid face corners counting overhead in drawing code
Currently the `sum_group_sizes` call used to count the number
of elements in GPU vertex buffers for each PBVH node stands out
in profiles, taking a few percent of the total time when building
PBVH GPU data. Since the number of corners in a node doesn't
change, it's simpler to just store it in the node. We could
eventually cache it somewhere else too, if there was a benefit
to not storing it in the node itself.
2024-09-19 22:31:55 -04:00
Sean Kim
4dc51e56b2 Cleanup: Silence clang defaulted-function-deleted warning
Because the pbvh::Tree has a unique_ptr, the copy assignment constructor
is implicitly deleted. This change makes that fact explicit by declaring
the entire object's copy assignment constructor as deleted.

Pull Request: https://projects.blender.org/blender/blender/pulls/127884
2024-09-20 03:02:52 +02:00
Sean Kim
5d40992fe8 Cleanup: Various non-functional PBVH raycast changes
A set of general tidying steps prior to making some PBVHVertRef changes

* Add const where possible
* Add r_ prefix for return parameters
* Use pass-by-reference instead of pointer for some return parameters
* Use std::array's .size() operator for some iteration bounds
* Use float3 for some variables

Pull Request: https://projects.blender.org/blender/blender/pulls/127832
2024-09-19 21:27:41 +02:00
Hans Goudey
43e4f93ca3 Cleanup: Use index mask utility function for setting bits 2024-09-19 15:16:58 -04:00
Hans Goudey
c2dd238ba1 Refactor: Sculpt: Use static constructors for PBVH build 2024-09-19 15:14:35 -04:00
Hans Goudey
c8ed2b695a Cleanup: Formatting 2024-09-19 14:54:25 -04:00
Hans Goudey
598c2a1032 Mesh: Add version of set custom normals functions for normalized values
Followup to 1939eb03a7.
The values are expected to already be normalized in these cases.
2024-09-19 14:18:08 -04:00
notrudyyy
1939eb03a7 Refactor: Mesh: Normalize input normals in set custom normals
To reduce code duplication in importers, modifies the C++
set_custom_normals API functions to normalize the input normals.

Reverts !124336, !124267, and !124261 as the normalization now
occurs in the API call.

Resolves #124358.

Pull Request: https://projects.blender.org/blender/blender/pulls/127814
2024-09-19 20:12:40 +02:00
Jacques Lucke
08b29ac143 Refactor: Core: add getter functions for data-block name
This adds a new `BKE_id_name` function. It should be used in places where we
currently do something like `id.name + 2`.

This patch just adds the function and uses them in a small subset of possible
cases. Given that there are >700 cases that need to be replaced, I'd rather to
that in chunks instead of all at once.

Pull Request: https://projects.blender.org/blender/blender/pulls/127410
2024-09-19 18:13:47 +02:00
Sybren A. Stüvel
fe68190923 Anim: fix group name check in Action constraint
Action constraints on an Object will pass a `nullptr` as group name to
another function, which didn't handle this properly.

Pull Request: https://projects.blender.org/blender/blender/pulls/127865
2024-09-19 17:25:52 +02:00
Sybren A. Stüvel
6ebe7a3985 Anim: don't evaluate the Action constraint if it has no Action
Skip the evaluation of the Action constraint when no Action is set.

Before, the constraint would run an entire animation data evaluation
cycle on a fake object, with the given (but NULL) Action. Now it's just
skipped.
2024-09-19 17:25:51 +02:00
casey bianco-davis
421d6c55ae GPv3: Implement the set_origin operator.
Add support the "Set Origin" operator for Grease Pencil objects.
Unlike GPv2, this will update radius properly.

Pull Request: https://projects.blender.org/blender/blender/pulls/127543
2024-09-19 15:27:29 +02:00
Hans Goudey
f82af7fa19 Cleanup: Sculpt: Remove unused PBVHVertRef function
Part of #118145.
2024-09-19 09:09:42 -04:00
Sybren A. Stüvel
823ee1ac92 Anim: add F-Curve getter functions that work with legacy & layered Actions
Add some F-Curve getter functions that work in all these situations:

- Built without experimental features.
- Built with experimental features, and called with legacy Action.
- Built with experimental features, and called with layered Action.

No functional changes, just useful tools for migrating to the new
Actions API.

Ref: #120406

Pull Request: https://projects.blender.org/blender/blender/pulls/127841
2024-09-19 14:46:25 +02:00
Sybren A. Stüvel
38e15412dd Fix #127755: 4.3 regression: Some rigged meshes do not load properly
Revert part of 9530852347 as that did not
take into account that the `max` property may actually be smaller than
the `min` property.

I've also taken the liberty to document this fact in some comments.

The fix for the crash when `min == max` is still in place.
2024-09-19 13:57:30 +02:00
Lukas Tönne
3a1ab067f2 Fix #127342: Support Curve domain when selecting by vertex group
This requires writing selection attributes to a different domain than
the Point domain.

Note that for assigning/removing from vgroups the `adapt_domain`
function is used implicitly by always looking up attributes from the
Point domain: ".selection" may be stored on Curves and will
automatically be adapted to points. For select-by-vgroup `adapt_domain`
cannot be used because the selection has to be "greedy" (one point
selects the whole curve).

Pull Request: https://projects.blender.org/blender/blender/pulls/127799
2024-09-19 10:59:55 +02:00
Campbell Barton
3a555b60f7 Fix crash making objects single user
Add BKE_view_layer_synced_ensure to the FOREACH_OBJECT_FLAG_BEGIN
macro. This macro was only used by the single-user operator.
2024-09-19 17:22:07 +10:00
Campbell Barton
67638a72e3 Logging: suppress BKE_bpath summary reports for non-operator callers
Saving for the first time or using save-as printed a summary, e.g.

`Total files 0 | Changed 0 | Failed 0`

When path operations were added it was only accessed from the UI,
where reporting a summary makes sense. Having the summary reported when
path manipulation is done as part of another action isn't useful.
It's also not clear what the summary relates to.

Now the summary is only shown in operator reports.
2024-09-19 14:49:03 +10:00
Campbell Barton
b63aa7f713 Cleanup: use bool return value for image write functions 2024-09-19 13:08:14 +10:00
Sean Kim
6a68a924fd Refactor: Sculpt: Remove PBVHVertRef usage in sculpt_expand.cc
Part of #118145

Also removes other now-unused functions & macros.

Pull Request: https://projects.blender.org/blender/blender/pulls/127821
2024-09-19 04:52:01 +02:00
Hans Goudey
e3fc40dfc3 Cleanup: Sculpt: Remove unused PBVHVertRef functions 2024-09-18 16:59:49 -04:00
Hans Goudey
f52819c044 Cleanup: Sculpt: Simplify grids indexing in two places 2024-09-18 08:47:32 -04:00
Habib Gahbiche
50f2857b1a Fix #127793: Crash on startup on macOS 15
std::sort() requires a strict weak ordering, i.e. `x < x` must be false. Therefore `id_order_compare(ID *a, ID *b)` must return false for `a.name == b.name`
Pull Request: https://projects.blender.org/blender/blender/pulls/127794
2024-09-18 14:46:02 +02:00
Sebastian Parborg
928ab6dc0f Fix: Compile error when building without WITH_EXPERIMENTAL_FEATURES 2024-09-18 12:47:28 +02:00
Jacques Lucke
9db50bed04 Fix: Geometry Nodes: use better hash for InstanceReference
Before, sometimes instance references that would compare equal could
have different hashes.
2024-09-17 23:01:45 +02:00
Nathan Vegdahl
7acdb8f90d Fix: compiler warning from using memcpy on non-trivial type
Also return a pointer from `Layer::duplicate_with_shallow_strip_copies()`
rather than a reference, since it doesn't maintain ownership of the
returned item.
2024-09-17 18:55:30 +02:00
Nathan Vegdahl
e0d5379ef8 Anim: change how action strip data is stored
This updates the layered action data model to store strip data differently.  Specifically:

- `Strip` is now just a single, POD type that only stores the data common to all
  strips, such as start/end frames.
- The data that might be of a completely different nature between strips (e.g.
  keyframe data vs modifier data) is now stored in arrays on the action itself.
- `Strip`s indicate their type with an enum, and specify their data with an
  index into the array on the action that stores data for that type.

This approach requires a little more data juggling, but has the advantage of
making `Strip`s themselves super simple POD types, and also opening the door to
trivial strip instancing later on: instances are just strips that point at the
same data.

The intention is that the RNA API remains the same: from RNA's perspective there
is no data storage separate from the strips, and a strip's data is presented as
fields and methods directly on the strip itself. Different strip types will be
presented as different subtypes of `ActionStrip`, each with their own fields and
methods specific to their underlying data's type. However, this PR doesn't
implement that sub-typing, leaving it for a future PR. It does, however, put the
fields and methods of the one strip type we have so far directly on the strip,
which avoids changing the APIs we have so far.

This PR implements the bulk of this new approach, and everything should be
functional and working correctly. However, there are two TODO items left over
that will be implemented in forthcoming PRs:

- Type refinement in the RNA api. This PR actually removes the existing type
  refinement code that was implemented in terms of the inheritance tree of the
  actual C++ types, and this will need to be reimplemented in terms of the new
  data model. The RNA API still works without the type refinement since there
  are only keyframe strips right now, but it will be needed in preparation for
  more strip types down the road.
- Strip data deletion. This PR only deletes data from the strip data arrays when
  the whole action is deleted, and otherwise just accumulates strip data as more
  and more strips are added, never removing the data when the corresponding
  strips get removed. That's fine in the short term, especially since we only
  support single strips right now. But it does need to be implemented in
  preparation for proper layered actions.

Pull Request: https://projects.blender.org/blender/blender/pulls/126559
2024-09-17 17:31:09 +02:00
Lukas Stockner
1c7c1829b6 Cleanup: Refactor animdata iterators to C++ callbacks
Pull Request: https://projects.blender.org/blender/blender/pulls/125485
2024-09-17 17:26:47 +02:00
Bastien Montagne
37c0e3668e Fix (unreported) broken IPO to FCurve versionning code.
Code would try to use a random ID as a legacy curve one, without any
check on the actual ID type. When trying to open
`tests/data/io_tests/blend_big_endian/2.30/dolphin.blend` recently added
to our collection of regression tests, this ended up 'converting' a
shapekey into a legacy curve ID, leading to invalid memory access
detected by ASAN.
2024-09-17 16:57:07 +02:00
Falk David
5857238432 Fix: GPv3: Build Modifier missing object after conversion
The Build Modifier was not copying the ID pointer to the object.
This resulted in the object field being empty when loading a GPv2
file.

The fix makes sure the ID pointer is copied.
2024-09-17 11:12:56 +02:00
Campbell Barton
65d71c2672 Cleanup: spelling in comments 2024-09-17 17:28:02 +10:00
Campbell Barton
b70925a8cc Cleanup: prefer ASCII characters
Use ASCII quotes, punctuation so strings are easily editable.
2024-09-17 17:28:01 +10:00
Campbell Barton
0791f53029 Fix shape-keys always being freed in BKE_mesh_nomain_to_mesh
Regression in [0] caused vertex numbers always detect as being changed.

Detect vertex count change before clearing vertices.

[0]: 21f2bacad9
2024-09-17 17:27:59 +10:00
Campbell Barton
cb4a203677 Fix #93911: Multires Unsubdivide destroys the vertex groups
Resolve regression since 3.0 when running un-subdivide.
2024-09-17 17:04:55 +10:00
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