Commit Graph

25622 Commits

Author SHA1 Message Date
Hans Goudey
8fed30aff2 Fix #134485: Missing depsgraph tag when assigning material
Caused by 81a63153d0.

Previously this was done by BKE_objects_materials_sync_length_all.
Now that function only adds a tag when it actually does something.
2025-02-13 13:16:57 -05:00
Brecht Van Lommel
4786fbe774 Refactor: Remove extern "C" from most headers
The only remaining code in source/blender that must be compiled as C
is now datatoc generated code and the DNA defaults that use designated
initializers.

Pull Request: https://projects.blender.org/blender/blender/pulls/134469
2025-02-13 18:58:08 +01:00
Bastien Montagne
48636fcab4 Merge branch 'blender-v4.4-release' 2025-02-13 18:42:16 +01:00
Bastien Montagne
e30b78fec4 Fix (unreported) invalid usage of C-style allocation for non-trivial C++ data. 2025-02-13 18:41:41 +01:00
Campbell Barton
640e70b6e8 Cleanup: various non-functional changes for C++ 2025-02-13 13:33:09 +11:00
Brecht Van Lommel
c7a33a62a2 Cleanup: Directly include DNA_userdef_types.h and BLI_listbase.h
Instead of relying on them being included indirectly.

Pull Request: https://projects.blender.org/blender/blender/pulls/134406
2025-02-12 23:01:08 +01:00
Hans Goudey
33db2d372f Mesh: Optimize vertex to edge attribute domain interpolation
Instead of using `DefaultMixer`, use the simpler `mix2` function.
This just decreases the overhead of computing each value.
In a simple test storing an attribute with the position of each
edge, I observed a 1.7x performance improvement: a change from
16 ms to ~9ms for an 8 million edge mesh.

Resolves #133196.
2025-02-12 11:50:14 -05:00
Hans Goudey
89b826b2fe Object: Prevent unnecessary depsgraph tags for no-op materials resize
When the object materials array is already the correct size these
functions don't do anything. Avoiding the depsgraph tags can avoid
unnecessary re-evaluations in cases like  sculpt mode where we
purposefully avoid adding tags elsewhere. Split from !133842.
2025-02-12 10:42:29 -05:00
Jacques Lucke
4980dc5e29 Merge branch 'blender-v4.4-release' 2025-02-11 17:47:45 +01:00
Jacques Lucke
374604f188 Refactor: Core: simplify accessing ListBases in Main
This replaces the `set_listbasepointers` function with `BKE_main_lists_get`
which returns an array of `ListBase *`. This simplifies the caller a bit. In
some cases, it can be simplifed further by changing the order in which we iterate
over the listbase. For historical reasons, we iterate from the back to front in
most cases but sometimes the order does not matter. I did keep the iteration order
in this patch though, to avoid regressions.

Pull Request: https://projects.blender.org/blender/blender/pulls/134242
2025-02-11 17:46:07 +01:00
Jacques Lucke
d28cf7a469 Fix #134283: defer freeing tree/node/socket types
Currently, tree, node and socket types are always freed immediately when the
Python code unregisters them. This is problematic, because there may still be
references to those type pointers in evaluated data owned by potentially various
depsgraphs. It's not possible to change data in these depsgraphs, because they
may be independent from the original data and might be worked on by a separate
thread. So when the type pointers are freed directly, there will be a lot of
dangling pointers in evaluated copies. Since those are used to free the nodes,
there will be a crash when the depsgraph updates. In practice, this does not
happen that often, because typically custom node tree addons are not disabled
while in use. They still used to crash often, but only when Blender exits and
unregisters all types.

The solution is to just keep the typeinfo pointers alive and free them all at
the very end. This obviously has the downside that the list of pointers we need
to keep track of can grow endlessly, however in practice that doesn't really
happen under any normal circumstances.

I'm still getting some other crashes when enabling/disabling Sverchok while
testing, but not entirely reliably and also without this patch (the crash there
happens in RNA code). So some additional work will probably be needed later to
make this work properly in all cases.

Pull Request: https://projects.blender.org/blender/blender/pulls/134360
2025-02-11 17:25:10 +01:00
Falk David
9438597b34 Fix: Grease Pencil: Remove invisible layers from evaluated data
Previously, all the layers were part of the evaluated state, even if
they were hidden.

Hidden layers should be treated as "disabled" meaning that we should
not evaluate them and/or render them at all.

This fixes this by removing hidden layers from the evaluated data before
layer adjustments and modifier evaluation starts.

As a consequence, hidden layers are no longer accessible in Geometry
Nodes. Technically, this is a breaking change. In the unlikely case that
a user relied on hidden layers to be evaluated within modifiers, they
need to make sure that the layer is visible.

Pull Request: https://projects.blender.org/blender/blender/pulls/133973
2025-02-11 16:49:51 +01:00
Campbell Barton
677a643046 Merge branch 'blender-v4.4-release' 2025-02-10 19:53:53 +11:00
Campbell Barton
4276437f05 Cleanup: quiet check_spelling_* warnings 2025-02-10 19:48:42 +11:00
Sebastian Parborg
cad4b39af3 Merge branch 'blender-v4.4-release' 2025-02-08 12:03:13 +01:00
Sebastian Parborg
ea380b1efe Revert "Sound: Sync up the screen refresh timer to the audio when seeking"
This reverts commit c952b12a6e.

This caused segfaults when playing back animations and seeking.
See #133542
2025-02-08 12:01:51 +01:00
Brecht Van Lommel
709dcba98c Merge branch 'blender-v4.4-release' 2025-02-07 21:24:36 +01:00
Brecht Van Lommel
cfca7ac952 Fix #133943: Unnecessary image full update mark on file open
This would be done when the frame, layer, pass or view changes compared to
the previous value. But for cases like old files without these members or
loading the image datablock into a different scene, this considered the image
to be always be changed on file load.

Now always reset this state on file load, and don't consider the initial
state as an image update.

This could also happen in the middle of GPU rendering, causing the GPU
texture to be freed while still in use.

Pull Request: https://projects.blender.org/blender/blender/pulls/134198
2025-02-07 21:23:48 +01:00
Bastien Montagne
87a4c0d3a8 Refactor: Make Library.runtime an allocated pointer.
Move `Library.runtime` to be a pointer, move the related
`LibraryRuntime` struct to `BKE_library.hh`. Similar to e.g.
Mesh.runtime, that pointer is expected to always be valid, and is
allocated at readtime or when creating a new Library ID.

Related smaller changes:
* Write code now uses standard ID writing codepath for Library IDs too.
  * Runtime pointer is reset to nullptr before writing.
* Looking up a library by its absolute path is now handled through a
  dedicated utils, `search_filepath_abs`, instead of using
  `BLI_findstring`.

Pull Request: https://projects.blender.org/blender/blender/pulls/134188
2025-02-07 17:47:16 +01:00
Jacques Lucke
190ba72acf Cleanup: Nodes: use utility method to check if node is undefined 2025-02-07 13:40:26 +01:00
Bastien Montagne
9fbde225da Merge branch 'blender-v4.4-release' 2025-02-07 12:45:32 +01:00
Bastien Montagne
3cbfd26bad Fix #134212: Crash when appending into an Excluded collection.
Would only happen in some specific cases. Essentially, do not consider
an excluded collection as 'editable'.

Also refactored `BKE_collection_parent_editable_find_recursive` on the
way, as it was applying the same checks twice to all but the initial
processed collections.
2025-02-07 12:45:12 +01:00
Falk David
445ae53c8e Merge branch 'blender-v4.4-release' 2025-02-07 12:22:59 +01:00
Falk David
8c01a59411 Fix: Grease Pencil: Use ensure_selection_attribute in vgroup_select_verts
This was implemented in the kernel but it shouldn't have been.
Since the function operates at the editor level and doesn't
only work at the low-level, it should be in the `object_vgroup.cc` file
in the `editor` context.

This also means that we can use `ensure_selection_attribute` which
fixes a crash when the selection attribute is on the wrong domain.

Pull Request: https://projects.blender.org/blender/blender/pulls/134060
2025-02-07 12:22:29 +01:00
Hans Goudey
54dc692d7b Refactor: Use StringRef for attribute API and BMesh CustomData functions
Replace `const char *` with `StringRef` for the API in `BKE_attribute.h`.
The benefits are slightly simpler code and possibly slightly improved
performance through avoiding the need to measure string length.

Pull Request: https://projects.blender.org/blender/blender/pulls/134183
2025-02-06 21:38:19 +01:00
Hans Goudey
4f833b0b5f Refactor: Add StringRef overloads to translation functions
Currently UI code always has to use char pointers when interacting with
the translation system. This makes benefiting from the use C++ strings
and StringRef more difficult. That means we're leaving some type safety
and performance on the table. This PR adds StringRef overloads to the
translation API functions and removes the few calls to `.c_str()` that
are now unnecessary.

Pull Request: https://projects.blender.org/blender/blender/pulls/133887
2025-02-06 17:47:52 +01:00
Falk David
8af27ce27e Fix #133969: Crazyspace broken with bezier curves and armature modifier
The issue was that the topology of the drawing changes when the bezier
curves get resampled to poly curves in the armature modifier.
This means that the crazyspace code fails to find deformed positions
with the same length as the original positions.

The fix does multiple things:
* First, we make sure that we create an `GeometryComponentEditData` in
  weight paint mode.
* When the armature modifier runs, we remember the current positions in
  this component.
* Then, we store the curve offsets and weights _before_ converting the
   bezier curves.
* Finally we deform the positions stored in the edit hint component
   (which have the same length as the original positions).

Since the resampling just adds new points, there might be a way to
avoid running the armature deformation a second time on the edit
hints, but I'll leave that for another day as a performance improvement.
In any case, this is only done when we actually need the deformation
(e.g. in weight paint mode when we paint the weights).

Pull Request: https://projects.blender.org/blender/blender/pulls/134030
2025-02-06 11:15:32 +01:00
Falk David
3a85ccde38 Fix #133969: Crazyspace broken with bezier curves and armature modifier
The issue was that the topology of the drawing changes when the bezier
curves get resampled to poly curves in the armature modifier.
This means that the crazyspace code fails to find deformed positions
with the same length as the original positions.

The fix does multiple things:
* First, we make sure that we create an `GeometryComponentEditData` in
  weight paint mode.
* When the armature modifier runs, we remember the current positions in
  this component.
* Then, we store the curve offsets and weights _before_ converting the
   bezier curves.
* Finally we deform the positions stored in the edit hint component
   (which have the same length as the original positions).

Since the resampling just adds new points, there might be a way to
avoid running the armature deformation a second time on the edit
hints, but I'll leave that for another day as a performance improvement.
In any case, this is only done when we actually need the deformation
(e.g. in weight paint mode when we paint the weights).

Pull Request: https://projects.blender.org/blender/blender/pulls/134030
2025-02-06 11:14:23 +01:00
Campbell Barton
3952c58183 Fix buffer overflow from an one error accessing environment variables 2025-02-05 19:08:58 +11:00
Campbell Barton
df3d1bf506 Cleanup: use const arguments & variables where appropriate 2025-02-05 14:38:56 +11:00
Hans Goudey
fc1fe4e78c Cleanup: Rename object materials "test" functions
"test" wasn't descriptive. Rename that part to "sync_length".
Also expose documentation from the function implementation
to describe what the functions do.

Pull Request: https://projects.blender.org/blender/blender/pulls/134058
2025-02-04 17:46:08 +01:00
Falk David
b760c5d6ef Cleanup: Grease Pencil: Add comments about attributes assumptions
In some places of the code we expect some attributes to not exist
and therefore always be created successfully.
2025-02-04 17:42:23 +01:00
Sebastian Parborg
c952b12a6e Sound: Sync up the screen refresh timer to the audio when seeking
This fixes the case when the screen update timer would not be reset
when seeking leading to screen updates happening mid frame.
For example when jumping to a keyframe during playback.

Note that this doesn't reset the timer when no audio is playing.
It would be nice to have it happen there as well. But it is probably not
too noticeable.

Pull Request: https://projects.blender.org/blender/blender/pulls/133542
2025-02-04 15:30:20 +01:00
Pratik Borhade
97a1b9b473 Fix #134003: Grease Pencil: Deleting vgroup shifts other vgroup content
`def_nr` is decremented twice, this results in shuffling of vgroupdata.
`remove_from_vertex_group` should only deal with weights and not tweak
`def_nr` as defgroup name index is updated in `remove_defgroup_index`
after deletion of selected vgroup. So just remove the code from
`remove_from_vertex_group`.

Pull Request: https://projects.blender.org/blender/blender/pulls/134015
2025-02-04 12:40:44 +01:00
Pratik Borhade
ac27bd16db Fix: Grease Pencil: Debug build error when armature is parent
Error is about accessing value of nullopt optional `vert_coords_prev`.
This occurs when armature is parented to grease pencil object.

Pull Request: https://projects.blender.org/blender/blender/pulls/134016
2025-02-04 11:12:40 +01:00
Sean Kim
adda1b085b Cleanup: Remove no longer relevant assert
Missed in 1b80125a67

With the above commit, this assert and comment is no longer relevant, we
now clean up `ustack->step_init` if it is set.

Pull Request: https://projects.blender.org/blender/blender/pulls/133993
2025-02-03 23:33:11 +01:00
Hans Goudey
4e18ebee1b Cleanup: Make paint BVH update tags proper private members
Move some functions to be methods of pbvh::Tree instead.

Pull Request: https://projects.blender.org/blender/blender/pulls/133989
2025-02-03 19:36:33 +01:00
Julian Eisel
1f88645728 UI: Draw loading icon while previews load
Show a dimmed loading icon while previews are being loaded in a
background thread. The asset shelf and asset/file browsers do this
similarly already.

This is implemented in drawing code, so the loading icon will always
appear when an in-progress preview is being drawn. I experimented with
doing this in `ui_def_but_icon()`, but this won't update correctly with
popups that don't support full refreshing.

This also makes any normal icon that is drawn as preview use the normal
icon size. These icons are usually made for smaller sizes and look very
outblown when displayed at the size of a preview. Yet it's useful to
sometimes pass a normal icon. E.g. for the asset shelf we would already
draw the data-block type icon in place of the preview if there was no
preview to display, and we'd use the normal, smaller size already.
Larger can still be drawn differently.
I don't know of any current cases this would affect though.

Pull Request: https://projects.blender.org/blender/blender/pulls/133880
2025-02-03 16:03:06 +01:00
Julian Eisel
7acd7e1246 UI: Rewrite asset shelf preview loading
- Fixes preview flickering on actions like undo/redo in the asset shelf (#93726), not yet for the
  file browser.
- Fixes #130861.

Makes the asset shelf use the asynchronous preview loading system of the UI instead of the file
browser one. The issues above where mostly caused by the file browser caching design.

The asset system and its UIs can now manage previews independently of the file browser back-end.
This is another step towards making the asset system independent of the file browser, see
https://developer.blender.org/docs/features/asset_system/fundamentals/from_file_browser_to_asset_system/.
Code to query asset previews through file browser types is removed.

Quite some work was done to prepare the UI preview system for this, to make it on par with the file
browser preview system. E.g.: 9d83061ed4, 315e7e04a8, 5055adc1c0, 16ab6111f7.

Note that the same change should be done to the asset/file browser, but this requires more work.

Pull Request: https://projects.blender.org/blender/blender/pulls/131871
2025-02-03 13:13:53 +01:00
Lukas Tönne
dc8b2c4bf7 Fix #133096: Specialized function to copy Grease Pencil layers from other objects
Grease Pencil layers can only be duplicated on the same object. Duplicating layers
from other objects will not insert the drawings into the target object and just
assume that drawing indices remain valid, which is not the case. The subsequent
drawing index user update crashes Blender.

This fix adds a new `copy_frames_from_layer` function that makes a full copy
of layer data, regardless of where that layer originates from. This is safe to use
with layers that live in other objects.

Pull Request: https://projects.blender.org/blender/blender/pulls/133722
2025-02-03 11:00:16 +01:00
Jesse Yurkovich
3c9a71b46f Fix #132465: Align Alembic/USD crease values with that of OpenSubdiv
In order to better interop with the broader Alembic/USD ecosystem, align
the crease values we export with what we believe is expected by native
OpenSubdiv, a 0-10 range.

On import we will translate the native OpenSubdiv range back into
Blender's 0-1 range.

To account for SubD assets produced by Blender before this change, a
compat check is put in place for both Alembic and USD to use the old
methodology when encountering such files. The compat check makes use
of the Blender version we place inside the format's metadata fields. Old
assets loaded into a new Blender will look ok. New assets loaded into an
old Blender would need to be reworked.

Pull Request: https://projects.blender.org/blender/blender/pulls/132582
2025-02-03 04:38:58 +01:00
Campbell Barton
36531006da Cleanup: use const pointer for the gravity vector 2025-02-02 13:58:34 +11:00
Hans Goudey
59f9e93413 Mesh: Avoid computing vertex normals for corner normals
The algorithm to calculate face corner normals had a vertex normal
input, with the intention to pre-populate corner normals for vertices
with no sharp connected edges. However corner normals are calculated
separately for these fully sharp vertices later anyway, so this whole
step was completely redundant. Removing the vertex normals calculation
reduces memory usage and improves performance. In a test file with a
character with custom normals, this changed improved the playback FPS
by 15%, from 41 to 47 FPS. The impact will usually be lower than that
but it should be noticeable in other scenes too.

Pull Request: https://projects.blender.org/blender/blender/pulls/133884
2025-01-31 19:59:28 +01:00
Brecht Van Lommel
478426c937 Cleanup: Various clang-tidy warnings in blenkernel
Pull Request: https://projects.blender.org/blender/blender/pulls/133734
2025-01-31 17:03:17 +01:00
Christoph Lendenfeld
de31cecfaf Fix #133731: Performance issue with many stashed actions
When duplicating an action, it is stashed in the NLA on a muted track.
Over time this can slow down blender, because certain code will look at every
FCurve in every action in the NLA.
To fix the performance issue, we can take advantage of the fact that
stashed actions are put onto a muted NLA track.

With this patch any strip on a muted NLA track is ignored in the
Depsgraph evaluation.

Measurements of `DEG_graph_relations_update`

| - | Before | After |
| - | - | - |
| 50 actions | ~140 ms | ~10.0 ms |
| 100 actions | ~250 ms | ~10.7 ms |

Pull Request: https://projects.blender.org/blender/blender/pulls/133864
2025-01-31 16:38:30 +01:00
Nathan Vegdahl
b166fa46b8 Anim: set Action.idroot when writing blend file, for forward compat
When writing an Action to a blend file, for forward compatability
reasons the animation data in the first slot is also written to the old
Animato Action storage locations. That way, loading the Action in an
older version of Blender will still at least have that animation data.

However, we overlooked `Action.idroot`, which indicates which ID
type the Action is for, and therefore all Actions have an unspecified
`idroot` when loaded in pre-layered-action versions of Blender.

This PR fixes that by also setting the `idroot` to match the target ID
type of the first slot when writing to disk.

Pull Request: https://projects.blender.org/blender/blender/pulls/133819
2025-01-31 10:47:16 +01:00
Hans Goudey
c2fd4eb9cc Cleanup: Deduplicate custom VectorSet identifier hash and equality
Add `CustomIDVectorSet` for this purpose.
Based on code from Jacques in #133778.

Pull Request: https://projects.blender.org/blender/blender/pulls/133821
2025-01-30 19:51:40 +01:00
Laurynas Duburas
a806f1c866 Curves: Optimization of ed::curves::duplicate_points
Adds new function `foreach_content_slice_by_offsets` that gathers mask's
indices into `IndexRange` lists grouped by given offsets. New approach
doesn't need temporary `points_to_duplicate` array of size
`curves.points_num()`. Traversal is more effective as only selected
indices get visited. Also point data is copied by point ranges instead
of point by point.

Performance was tested with following code:
```cpp
TEST(curves_geometry, DuplicatePoints)
{
  CurvesGeometry curves = create_basic_curves(100000, 100);

  IndexMaskMemory memory;
  IndexMask every_second = IndexMask::from_predicate(
      curves.points_range(), GrainSize(100), memory, [](const int i) {
        return bool(i % 2);
      });

  for (const int i : IndexRange(1000)) {
    CurvesGeometry copy = curves;
    const int expected_point_count = copy.points_num() + every_second.size();
    ed::curves::duplicate_points(copy, every_second);
    EXPECT_EQ(copy.points_num(), expected_point_count);
  }
}
```
|          |   main   | mask slices | slices & copy by ranges |
| -------- | -------- | ----------- | ----------------------- |
| full copy|  3346 ms | 2270 ms | 1614 ms |
| `i % 2`  |  8084 ms | 5918 ms | 5112 ms |
| `!((i % 10 == 0) or` <br/>`(i % 10 == 1) or` <br/>`(i % 10 == 2))` | 4522 ms | 2860 ms | 2343 ms|
| `(i % 10 == 0) or` <br/> `(i % 10 == 1) or` <br/> `(i % 10 == 2)`| 4088 ms | 1961 ms | 1639 ms|
| `IndexRange(50020, 70)` <br/> <sub>(one small range in the middle)</sub>| 1966 ms | 100 ms | ~75 ms |

Pull Request: https://projects.blender.org/blender/blender/pulls/133101
2025-01-30 17:19:16 +01:00
Philipp Oeser
ae8bd075e5 Fix #133480: Missing animation data conversion on Opacity modifier
Both "factor" and "hardness" were renamed from GPv2 > GPv3.
Use AnimDataConvertor to account for this.

Pull Request: https://projects.blender.org/blender/blender/pulls/133476
2025-01-30 14:19:30 +01:00
Omar Emara
7f4cf5a949 Fix #124566: Compositor Normal node does not update
Changes to the compositor Normal node does not propagate and the
compositor result is not updated. That's because the node is a special
case since its output socket value is used as its input property, which
is not tracked by the node update code.

Apparently, a similar node exists in shader nodes, and a workaround is
implemented for that node in the node updater, so we just need to extend
that check to include the compositor node as well.

Pull Request: https://projects.blender.org/blender/blender/pulls/133803
2025-01-30 11:45:59 +01:00