Commit Graph

28911 Commits

Author SHA1 Message Date
Campbell Barton
df1da0fbdd Cleanup: pass large arguments by const reference instead of by value 2025-07-20 15:23:07 +10:00
Sean Kim
fef8c23e9e Refactor: Paint: Migrate runtime data out of UnifiedPaintSettings
This commit moves 23 total existing runtime-only properties from the
`UnifiedPaintSettings` struct into the `PaintRuntime` BKE struct. This
shrinks the amount of persisted data by 224 bytes per paint mode per
scene.

In doing this conversion, fields that were previously `char` booleans
have been converted to `bool` types, and C++ math vector types have been
used where appropriate as well.

Some of these attributes may move again in the future to better
distinguish stroke level data from mode level data.

Pull Request: https://projects.blender.org/blender/blender/pulls/141366
2025-07-18 23:18:27 +02:00
Hans Goudey
21f0dace48 Refactor: Make CD_TYPE_AS_MASK into a function with typed argument
So that misuse of this will result in build errors instead of bugs
(this change found three places like that).
2025-07-18 13:23:03 -04:00
Falk David
11d2f48882 Fix #141887: Crash/assert hit after reading Grease Pencil
Since 5.0 (subversion 33) `CurvesGeometry` data is read from and written
to the new attribute storage. See 68759af516.

For backwards compatibility, the `CustomData curve_data`
became `curve_data_legacy` and was only read and then converted in
the versioning code to the attribute storage format.

But since `CurvesGeometry::blend_read` is still reading
`curve_data_legacy`, we need to ensure that this data is valid.

When e.g. duplicating `CurvesGeometry`, the `curve_data_legacy` was left
uninitialized, so in an invalid state. Then the writing code would write
the embedded `CustomData` struct and the reading code would fail.

This could in theory also happen for other IDs that store legacy
custom data.

To ensure that the data is valid when reading, we do the following:
1) After the conversion code ran, we reset the legacy data. This makes
sure that we don't keep the legacy data around at runtime and
potentially when writing the embedded struct.
2) Before writing, we also reset the legacy data. This makes sure that
in case there is some garbage data in the unused struct (e.g. from
copying the ID), we don't write the garbage to file.

Pull Request: https://projects.blender.org/blender/blender/pulls/142327
2025-07-18 17:55:36 +02:00
Richard Antalik
0396316fa4 Fix #141084: Sound glitches in render with equalizer
Ultimately, the issue was caused by updating sound sequence handle in
`AUD_SequenceEntry_setSound` on each new frame regardless if the
modifier data has changed.

This commit fixes the issue by implementing a means for modifiers to
check, if their parameters or inputs are changed.
This is done by storing these parameters in `StripModifierDataRuntime`
struct, that is shared between all modifier types. This is not ideal,
but it significantly simplifies dependency graph runtime store/restore
code.
Function `strip_update_sound_modifiers` passes boolean `needs_update`
to strip stack update functions. If any needs to be updated, it sets
value of `needs_update` to true allowing following update functions to
skip parameter checking to speed up the process.

Original code updated sound sequence handle twice. Once by function
`BKE_sound_update_scene_sound` then by `strip_update_sound_modifiers`.
If sound modifier is used, only `strip_update_sound_modifiers` needs to
be called, so there is condition to decide which one of these functions
is called.

Also fixes #139605

Pull Request: https://projects.blender.org/blender/blender/pulls/141595
2025-07-18 16:34:09 +02:00
Pratik Borhade
ef89c75382 Fix: Grease Pencil: Wrong layer attributes after reorder
Reordering layer nodes by drag-drop, move up/down, add new etc. swaps
layer attributes with wrong layers. This is due to mistake in map
`new_by_old_map`. Values of this map is used as indices in src array.
And keys are indices of dst array. Expected behavior is to copy attribute from
old position (`layer_i_old`) of src array to new position (`layer_i_new`) of
dst array. See: `array_utils::gather`.

Noticed during !141772.

Pull Request: https://projects.blender.org/blender/blender/pulls/141935
2025-07-18 16:30:41 +02:00
Jacques Lucke
20eaa1b1b0 Fix: Attributes: missing null check in when accessing attribute for write 2025-07-18 16:21:25 +02:00
Falk David
99f3beb63f Refactor: VSE: Use new scene context function
This PR switches out the internal scene context function
used from the sequencer. This is done in preparation for
#140271.

Using a separate context function allows us to keep the
existing `context.scene` to refer to the active scene
and use a separate context member to refer to the
sequencer scene in the workspace (which is added in #140271).

Previous attempts simply overrode the `context.scene`
to refer to a different scene than the active one in the window.
This has two issues:
1) Any operator that wants to use the active scene in the window
  can't do it in the context of the sequencer. This is a problem for
  example for poll functions of operators that don't have anything to
  do with the sequencer.
2) For better or for worse, Blender expects the `context.scene` to
  always exist. For the sequencer, we'd like to possibly have no
  sequence selected.

Using a different context member for the sequencer has some
advantages:
1) Although we have to change quite a few places, it's limited to the
  sequencer. We don't have to change other parts of Blender to make
  things work.
2) It allows us to prepare for the future when we might want to
 separate the VSE from the scene. This is a step in that direction.
 Having a different context function makes it easy to find the places
 that would need to be refactored.

Pull Request: https://projects.blender.org/blender/blender/pulls/141271
2025-07-18 16:17:47 +02:00
Omar Emara
a565e96f6c Compositor: Support Menu socket and Menu Switch node
This patch adds support for menu socket in the compositor as well as
the Menu Switch node from Geometry Nodes.

Pull Request: https://projects.blender.org/blender/blender/pulls/141792
2025-07-18 11:08:30 +02:00
Falk David
5194c7d0df Cleanup: Fix typo 2025-07-18 10:58:36 +02:00
Falk David
d2f4d80ac9 Fix #142056: Grease Pencil: Assert on duplicating layer
The asserts were added in 45ab790e80
for better error detection.

The assert was happening because the duplicated layer
was referencing frames of the source layer by default,
causing the actual user counts of the drawings to be
in an invalid state (they they were getting fixed
after the call to `duplicate_layer`, but they could remain
invalid! ).

To fix this, we ensure that the user counts are correct
after calling `duplicate_layer`. New parameters are added
to allow duplicating the frames (with empty drawings) or
duplicating the frames and the drawings.

Pull Request: https://projects.blender.org/blender/blender/pulls/142201
2025-07-18 10:37:46 +02:00
Campbell Barton
ce5c54fef6 Fix #128169: Memory leak in bpy.data.meshes.new_from_object
Resolve leak in new_from_object when preserve_all_data_layers=True and
a sub-surfaced mesh.

A copy was made, then BKE_mesh_wrapper_ensure_subdivision would return
the "mesh_eval" of the copy, leaking the mesh passed to
BKE_mesh_wrapper_ensure_subdivision.

Ref !142176
2025-07-18 11:30:50 +10:00
Mattias Fredriksson
50ec3cb2d4 Cleanup: Mutable Span in geom compare
Data is only accessed but variable is of type MutableSpan unlike `sorted_to_values1`.

Pull Request: https://projects.blender.org/blender/blender/pulls/142224
2025-07-17 16:59:56 +02:00
Jacques Lucke
f2ee95843c Nodes: improve socket tooltips
The main goal of the patch is to make the socket tooltips more useful. This is
achieved in two ways:
* Use better text formatting in the tooltip to make it easier to parse and to
  better separate the current actual value from more general information about
  the socket.
* Add some more information like implicit field inputs when the node is not used
  currently or more details about a color.

This patch basically rewrites the entire tooltip generation, because it's quite
different from before (where we just created a single string for the entire
tooltip).

I'm using monospace for the actual current socket value and type, while the
normal font is used for general information about the socket like it's name,
description, allowed geometry types etc.

Pull Request: https://projects.blender.org/blender/blender/pulls/140540
2025-07-17 12:48:17 +02:00
Christoph Lendenfeld
e80ceb52df Fix #139509: Slot assignment is lost when loading file saved in tweak mode
The issue was that the `AnimData.tmp_slot_handle` had no RNA property associated with it
and so it couldn't be saved in the lib override.

The fix is to add the property. To ensure the correct code is called, most of the previous code
was replaced with a call to `blender::animrig::assign_tmpaction`

Pull Request: https://projects.blender.org/blender/blender/pulls/141395
2025-07-17 11:35:18 +02:00
Falk David
1a46806546 Fix: Grease Pencil: Missing call to finish() writing layer attributes
The `GSpanAttributeWriter` was missing a call to `finish()` to ensure
the changes are tagged and saved.
2025-07-17 11:31:10 +02:00
Lukas Tönne
23d02ec57b Fix armature deform: Avoid accessing parameter data after moving 2025-07-17 09:42:39 +02:00
Jacques Lucke
55e2fd2929 Cleanup: unify naming for named constructors
Previously, we used an inconsistent naming scheme for such "named constructors".
Now it always uses `from_*`.

Pull Request: https://projects.blender.org/blender/blender/pulls/142175
2025-07-17 09:09:16 +02:00
Hans Goudey
b19696c0b8 Mesh: Simplify tangents calculation
- Tangent calculation functions no longer use the CustomData struct as
  an input and output.
- The "orco" and UV map calculations are exposed as separate API
  functions to avoid a confusing internal choice between the two
- Redundancy in the API is removed, function names are clarified
- Code is moved to C++ namespace
- The "orco" case is clarified in the mesh draw tangent VBO extraction
- CD_TANGENT layers are not stored in CustomData anymore, so some of
  that infrastructure is removed.
- Broken logic for caching tangents in CustomData is removed. That
  hasn't worked for many years, if it every worked. We could investigate
  adding caching again later if that's helpful.

Overall the change is motivated by the need to move away from CustomData
for #122398. But the changes should be a general improvement that makes
the code easier to understand either way.

Testing for this PR included using the default render UV in materials,
referencing specific UV tangents by name, using the spherical position-
based tangents in a material, and baking textures (multires and normal
baking).

Pull Request: https://projects.blender.org/blender/blender/pulls/141799
2025-07-17 02:24:09 +02:00
Hans Goudey
e3c5070dfe Cleanup: Remove unused data transfer code
Shape key interpolation was never implemented. Nowadays it's
probably better to implement similar features in different ways
rather than extending this system. Also some layer mapping
generation was unused. The motivation for this is easing some
cleanups to make this modifier less directly reliant on CustomData.

Pull Request: https://projects.blender.org/blender/blender/pulls/142131
2025-07-16 22:53:21 +02:00
Hans Goudey
d669f28e05 Fix: Overlapping data transfer enum values
This code is really weird, I'm not sure if this caused user-visible
errors but these values shouldn't overlap.

Pull Request: https://projects.blender.org/blender/blender/pulls/142130
2025-07-16 22:53:11 +02:00
Hans Goudey
65131f22f8 Cleanup: Use Span arguments for some mesh remapping functions
Pull Request: https://projects.blender.org/blender/blender/pulls/142123
2025-07-16 21:59:25 +02:00
Hans Goudey
b20ecee555 Mesh: Move freestyle tags to generic attributes
This commit moves the freestyle edge and face mark tags to become
generic attributes, similar to other changes over the past years. The
attributes are called "freestyle_edge" and "freestyle_face", and they're
now propagated like regular boolean attributes.

Compatibility wise, forward and backward blend file compatibility are
maintained (for forward compatibility this is implemented a bit
differently than in the past because of the ongoing `AttributeStorage`
transition). In the Python API, `use_freestyle_mark` has been removed;
the attribute API should be used instead (just like bevel weights).
The BMesh (`freestyle`) accessors are removed too.

The conversions benefit from the fact that bit-wise, the old structs are
the same as `bool`, so we can convert to the old and new formats without
reallocating arrays.

Pull Request: https://projects.blender.org/blender/blender/pulls/141996
2025-07-16 18:26:26 +02:00
Namit Bhutani
8602f893ed Fix #141811: Crash with remesh operator
Fixes crash in the remesh operator by moving mesh spatial organization
to appropriate execution contexts and using proper memory handling in
spatial organization's face offset calculations.

Pull Request: https://projects.blender.org/blender/blender/pulls/141842
2025-07-16 14:27:18 +02:00
Jacques Lucke
f7f18cd0c7 Nodes: initial support for built-in menu sockets
So far, only node group were able to have menu input sockets. Built-in nodes did
not support them. Currently, all menus of built-in nodes are stored on the node
instead of on the sockets. This limits their flexibility because it's not
possible to expose these inputs.

This patch adds initial support for having menu inputs in built-in nodes. For
testing purposes, it also changes a couple built-in nodes to use an input socket
instead of a node property: Points to Volume, Transform Geometry, Triangulate,
Volume to Mesh and Match String.

### Compatibility

Forward and backward compatibility is maintained where possible (it's not
possible when the menu input is linked in 5.0). The overall compatibility
approach is the same as what was done for the compositor with two differences:
there are no wrapper RNA properties (not necessary for 5.0, those were removed
for the compositor already too), no need to version animation (animation on the
menu properties was already disabled).

This also makes menu sockets not animatable in general which is kind of brittle
(e.g. doesn't properly update when the menu definition changes). To animate a
menu it's better to animate an integer and to drive an index switch with it.

### Which nodes to update?

Many existing menu properties can become sockets, but it's currently not the
intention to convert all of them. In some cases, converting them might restrict
future improvements too much. This mainly affects Math nodes.

Other existing nodes should be updated but are a bit more tricky to update for
different reasons:
* We don't support dynamic output visibility yet. This is something I'll need to
  look into at some point.
* They are shared with shader/compositor nodes, which may be more limited in
  what can become a socket.
* There may be performance implications unless extra special cases are
  implemented, especially for multi-function nodes.
* Some nodes use socket renaming instead of dynamic socket visibility which
  isn't something we support more generally yet.

### Implementation

The core implementation is fairly straight forward. The heavy lifting is done by
the existing socket visibility inferencing. There is a new simple API that
allows individual nodes to implement custom input-usage-rules based on other
inputs in a decentralized way.

In most cases, the nodes to update just have a single menu, so there is a new
node-declaration utility that links a socket to a specific value of the menu
input. This internally handles the usage inferencing as well as making the
socket available when using link-drag-search.

In the modified nodes, I also had to explicitly set the "main input" now which
is used when inserting the node in a link. The automatic behavior doesn't work
currently when the first input is a menu. This is something we'll have to solve
more generally at some point but is out of scope for this patch.

Pull Request: https://projects.blender.org/blender/blender/pulls/140705
2025-07-16 08:31:59 +02:00
Hans Goudey
0781b90962 Cleanup: Formatting 2025-07-15 17:24:46 -04:00
Hans Goudey
98a1816e01 Cleanup: Clarify comment position in custom data type conversion 2025-07-15 16:37:37 -04:00
Jacques Lucke
655afbb235 Fix: Geometry Nodes: output fields from closures
This fixes the anonymous attribute lifetime inferencing for the closure zone and
the evaluate closure node. It also adds new regression tests for cases where a
closure outputs a field.

Pull Request: https://projects.blender.org/blender/blender/pulls/141925
2025-07-15 06:48:24 +02:00
Sean Kim
8feef54afa Refactor: Use C++ math type for ReshapeGridElement structs
Pull Request: https://projects.blender.org/blender/blender/pulls/141698
2025-07-15 00:01:12 +02:00
Jacques Lucke
00c81f5113 Merge branch 'blender-v4.5-release' 2025-07-14 16:30:38 +02:00
YimingWu
4096309753 Fix #141819: Interface Use a flag for WM_set_locked_interface
Different operations may need to lock different part of the interface,
e.g. for rendering, the image editor may still need refreshing while the
interface is locked, but when baking data into a scene, the image editor
needs to be locked because it is not thread safe to get data from a
partially evaluated depsgraph.

This is a better fix on top of 7c8b8b2457
that addresses the root cause with more flexibility for future
operations that requires different interface locking strategy as
well.

Pull Request: https://projects.blender.org/blender/blender/pulls/141866
2025-07-14 16:17:46 +02:00
Sebastian Parborg
a172b40d56 PointCache: Remove support for LZO and LZMA compression, use ZSTD
LZO and LZMA is only used for compressing point caches inside of
Blender. As we already use ZSTD for compressing other data in Blender it
makes sense to remove LZO and LZMA to simplify our library requirements
(and lessen our library maintenance burden).

I've talked to Sergey about this and he suggested that I leave the LZO/LZMA
libraries and code around but effectively disabled until beta, so if there is a
huge uproar, we can easily reinstate the support.

Pull Request: https://projects.blender.org/blender/blender/pulls/141461
2025-07-14 12:51:04 +02:00
Falk David
45ab790e80 Grease Pencil: Initialize runtime drawing user counts on read
This adds a function `GreasePencil::count_frame_users_for_drawings()`
that computes the drawing user counts from the layer frames. This is used
to correctly initialize the runtime drawing user counts when reading the ID.

Note that we don't expose any functionality to instance drawings currently.
This change is also in preparation for when this will be possible.

Also adds a function `GreasePencil::validate_drawing_user_counts()` that
compares the actual user counts with the runtime user counts that are
stored. Only runs these checks in debug builds.

Pull Request: https://projects.blender.org/blender/blender/pulls/141458
2025-07-14 11:44:57 +02:00
Omar Emara
62e0a9105a Fix #141864: Crash opening files with Alpha Over node
Blender will crash if a file with an Alpha Over node was saved in 4.4,
then in 4.5 alpha, then back to 4.4. This is because the node was
missing forward compatibility code that allocates storage that was
necessary for the file to load correctly on older versions.

This was essentially missed in b62ef2cdd6 and 976efdcac9.

Pull Request: https://projects.blender.org/blender/blender/pulls/141873
2025-07-14 09:31:41 +02:00
Pratik Borhade
07b070404a Fix: Grease Pencil: Problem removing last layer with attributes
Caused by 68759af516
Deleting first layer (i.e. last in the tree view), layer attribute values
of previous layers gets messed up due to wrong offset value when
copying attribute data

Pull Request: https://projects.blender.org/blender/blender/pulls/141772
2025-07-14 08:49:51 +02:00
Hans Goudey
14e2876b73 Core: Replace BLI_buffer.hh with blender::Vector
The C++ Vector container has the benefits of the older C type,
along with improved performance, better type and memory safety,
and significantly improved ergonomics.

Pull Request: https://projects.blender.org/blender/blender/pulls/141759
2025-07-13 17:13:59 +02:00
Campbell Barton
ec8751f826 Cleanup: white-space around C-style comment blocks
Also use C++ style comments for disabling code.
2025-07-13 21:58:53 +10:00
Habib Gahbiche
b35971ad08 Compositor: Rename "Z" to "Depth" in Z Combine Node
Node:
- Rename "Z Combine" node to "Depth Combine"

Sockets:
- First input "Image" -> "A"
- Second input "Image" -> "B"
- First Z -> "Depth A"
- Second Z -> "Depth B"
- Output Image -> "Result"
- Output Z -> "Depth"

This is a breaking change for the Python API

Pull Request: https://projects.blender.org/blender/blender/pulls/141676
2025-07-11 11:58:29 +02:00
Nathan Vegdahl
03332c514d Cleanup: Use prescribed symbol syntax in Path Template code comments
Specifically, #Symbol rather than `Symbol`, as documented in
https://developer.blender.org/docs/handbook/guidelines/c_cpp/#comments

This is a follow up to #139438

Pull Request: https://projects.blender.org/blender/blender/pulls/141775
2025-07-11 11:00:52 +02:00
Jesse Yurkovich
4de536c114 Cleanup: Remove unused includes of grease pencil legacy headers
Removes unnecessary usages of the following headers:
- BKE_gpencil_geom_legacy.h
- BKE_gpencil_legacy.h
- BKE_gpencil_modifier_legacy.h
- BKE_grease_pencil_legacy_convert.hh
- DNA_gpencil_legacy_types.h

Pull Request: https://projects.blender.org/blender/blender/pulls/141471
2025-07-11 05:01:57 +02:00
Hans Goudey
8f65cbd727 Cleanup: Use attribute API for dynamic paint color outputs 2025-07-10 22:18:06 +02:00
Hans Goudey
16aca719e2 Cleanup: Remove unnecessary includes in attributes files 2025-07-10 22:18:06 +02:00
Hans Goudey
2b86b32fc3 Fix: Avoid tagging geometry with uninitialized attribute on add
Mistake in 325ceabb09

Pull Request: https://projects.blender.org/blender/blender/pulls/141747
2025-07-10 19:05:00 +02:00
Sergey Sharybin
93be12fde0 ImBuf: Linearize float buffers from FFmpeg
Blender expects float buffers to be in scene linear space, which was
violated bu the 1012bit movie reading code. While such image buffers
can be displayed correctly, performing operations in various areas
of Blender might lead to unexpected results.

The non-linear colorspace for ImBuf is expected to be "internal-only"
to a specific area, like VSE.

This is only done for Image and MovieClip data-blocks, sequencer still
reads movie files in their original colorspace as it helps performance and
sequencer can not be referenced from places where linear colorspace
for float buffer is really important.

Pull Request: https://projects.blender.org/blender/blender/pulls/141603
2025-07-10 17:39:00 +02:00
Hans Goudey
fc253de467 Cleanup: Use attribute API for Multires unsubdivide index mapping 2025-07-10 16:17:05 +02:00
Hans Goudey
6304609cd8 Cleanup: Simplify vertex group data access in data transfer modifier 2025-07-10 16:17:05 +02:00
Hans Goudey
cec05ab440 Cleanup: Use mesh helper functions to access vertex group data 2025-07-10 16:17:05 +02:00
Hans Goudey
c21a98d76a Cleanup: Use references for CustomData arguments in data transfer 2025-07-10 16:17:05 +02:00
Hans Goudey
325ceabb09 Fix #141721: Adding curve attributes doesn't invalidate caches
In this report, adding the "resolution" attribute didn't clear the
evaluated positions cache. In some cases capturing an attribute on
the mesh might just add the mesh rather than using an attribute
writer.
2025-07-10 10:02:25 -04:00
Nathan Vegdahl
69433a181e Fix #141024: Normalize active vertex group properly
When manually setting a group's vertex weight, auto-normalization would
fail in some circumstances, such as when all other groups are locked.

The root cause of this issue was our approach for ensuring that the
weight specified by the user remained as-is when possible during
normalization. Rather than "when possible", it erroneously *always*
ensured the weight stayed as-is even when that made normalization
impossible. It came down to this:

1. Normalization is done as a post process, with no knowledge of what
   changes were just made to the weights.
2. In order to (try to) make up for that and ensure that the just-set
   weight remains as the user specified, the active group was
   temporarily locked during normalization, which could prevent
   normalization in some cases.

This PR fixes the issue by introducing a new internal-only concept of
"soft locked" vertex groups to the normalization functions, intended to
be used in exactly these cases where there are weights that have just
been set and we want to avoid altering them when possible. Soft-locked
groups are left untouched whenever normalization is achievable without
touching them, but are still modified if normalization can't be achieved
otherwise.

This has been implemented by introducing a new bool array alongside the
"locked" bool array in the core normalization functions.  Although all
uses in this PR only ever specify a single group as "soft locked", using
a bool array will make it easy to use this concept in other weight
painting tools in the future, which may modify more than one group at
once.

Pull Request: https://projects.blender.org/blender/blender/pulls/141045
2025-07-10 14:51:50 +02:00