Commit Graph

188 Commits

Author SHA1 Message Date
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
Brecht Van Lommel
3725fad82f Cleanup: Various clang-tidy warnings in editors
Pull Request: https://projects.blender.org/blender/blender/pulls/133734
2025-01-31 17:03:17 +01:00
Hans Goudey
7d6e098ca1 Cleanup: Remove unused includes in blenkernel
Pull Request: https://projects.blender.org/blender/blender/pulls/133688
2025-01-28 15:27:34 +01:00
Jacques Lucke
619d9e4e01 Fix #98559: support applying Geometry Nodes through multires modifier
Before, it was only possible to apply modifiers through a multires modifier if
they were deform-only. The Geometry Nodes modifier is of course not deform-only.
However, often one can build a node setup, that only deforms and does nothing
else.

To make it possible to apply the Geometry Nodes modifier in such cases the
following things had to be done:
* Update `BKE_modifier_deform_verts` to work with modifiers that implement
  `modify_geometry_set` instead of `deform_verts`.
* Add error handling for the case when `modify_geometry_set` does more than just
  deformation.
* Allow the Geometry Nodes modifier to be applied through a multi-res modifier.

Two new utility types (`ArrayState` and `MeshTopologyState`) have been
introduced to allow for efficient and accurate checking whether the topology has
been modified. In common cases, they can detect that the topology has not been
changed in constant time, but they fall back to linear time checking if it's not
immediately obvious that the topology has not been changed.

This works with the example files from #98559 and #97603.

Pull Request: https://projects.blender.org/blender/blender/pulls/131904
2025-01-23 17:34:30 +01:00
Hans Goudey
c6f5c44350 Cleanup: Remove unused includes in editors modules
Pull Request: https://projects.blender.org/blender/blender/pulls/133166
2025-01-16 23:17:51 +01:00
Jacques Lucke
684fd4643a Nodes: use BKE_main_ensure_invariants directly instead of ED_node_tree_propagate_change
`BKE_main_ensure_invariants` was added in 1fae5fd8f6. The older
`ED_node_tree_propagate_change` was already implemented as a thin wrapper around
`BKE_main_ensure_invariants`. This patch removes the wrapper and calls the more
general function directly.

A new overload of `BKE_main_ensure_invariants` is added for the common case when
only a single data-block has been modified.

Pull Request: https://projects.blender.org/blender/blender/pulls/133048
2025-01-14 16:26:54 +01:00
Hans Goudey
73ff099405 Cleanup: Remove unnecessary casts for PropertyFlag enum type 2025-01-10 15:18:40 -05:00
Falk David
d413b0064f Cleanup: Move BKE_material.h to C++
The `BKE_material.h` is only renamed to `.hh` to preserve
the history of the file. Changes to the file are done in
the following commit.
2025-01-09 18:11:46 +01:00
Jacques Lucke
038159e96b Refactor: Nodes: improve node tree update API
Main goals of this refactor:
* Make it more obvious which update function should be used.
* Make it more obvious which parameters are required by using references instead
  of pointers.
* Support passing in multiple modified trees instead of just a single one.

No functional changes are expected.

Pull Request: https://projects.blender.org/blender/blender/pulls/132862
2025-01-09 17:00:05 +01:00
Jacques Lucke
db7ff834c9 Refactor: Nodes: remove context argument from propagation function
The part that used the context does not seem to be necessary anymore. If the
given tree has any update tag set, the same notifiers will be sent anyway by the
`tree_changed_fn` callback.

If it turns out that we are now missing some notifier, then we have to change
the caller. It either has to call the proper `BKE_ntree_update_tag_*` function,
or create the notifier directly.

This change helps to generalize the concept of propagating changes in original
data, because the context is rarely available.

Pull Request: https://projects.blender.org/blender/blender/pulls/132810
2025-01-08 19:45:50 +01:00
Hans Goudey
645624130d Cleanup: Simplify creation of mesh for particle system conversion 2024-12-30 11:13:47 -05:00
Hans Goudey
c3cc3c019d Fix #103785: Geometry Nodes attribute inputs aren't overridable
The "use attribute" and "attribute name" IDProperties were missing
the overrideable status and the static type status. This was an oversight
from when those tags were added.

This commit fixes the flag on new modifier properties as they're created
and applies versioning to old properties. It also fixes the poll of the toggle
input attribute operator so that it isn't possible on non-editable objects.

Pull Request: https://projects.blender.org/blender/blender/pulls/131768
2024-12-12 13:48:52 +01:00
Jacques Lucke
289962911c Fix #131577: missing node tree updates after duplicating tree 2024-12-09 13:42:47 +01:00
Hans Goudey
4ded260cf3 UI: Allow setting active modifier on linked object
The poll function doesn't apply here because it just checks for object
editability and edit mode, object types, and modifier types. We shouldn't
have a poll function at all because the hovered modifier might not be
part of the context.

Resolves #90008.

Pull Request: https://projects.blender.org/blender/blender/pulls/131384
2024-12-04 16:43:13 +01:00
Campbell Barton
b9f055459a Cleanup: ensure trailing space around comment blocks 2024-11-27 19:01:00 +11:00
Hans Goudey
0684639e1b Cleanup: Grease Pencil: Remove indirect includes from headers
To avoid unnecessary header parsing during compilation.

Pull Request: https://projects.blender.org/blender/blender/pulls/130285
2024-11-14 22:07:19 +01:00
Hans Goudey
cb62d74658 Merge branch 'blender-v4.3-release' 2024-11-14 11:26:37 -05:00
Hans Goudey
a9209f10a6 Fix #130250: Modifier copy to selected crash using quick favorites
The rest of this function has null checks for the modifier because it
might not be part of the context and retrieved during invocation later.

Pull Request: https://projects.blender.org/blender/blender/pulls/130272
2024-11-14 16:04:19 +01:00
Falk David
4b1d542363 Merge branch 'blender-v4.3-release' 2024-11-08 13:14:49 +01:00
Falk David
f0614a4a3f Fix: GPv3: Regression when applying modifiers after recent commit
This was caused by 9a03f283e8.

The change disregarded the `orig_layers_to_apply` mask and
introduced some issues regarding clearing keyframes of deleted layers.

The fix does two things:
 * Add a `orig_layers_to_apply` set that contains the pointers of the
   original layers that we want to apply.
* Add a `orig_layers_to_clear` set that contains the pointers of original
  layers that need their keyframe cleared.

When a layer is removed during modifier execution, we don't want
the layer to be deleted in the original geometry. Instead we clear
the keyframes by deleting all the curves geometry. A layer
can be removed by e.g. using the  `Grease Pencil to Curves` node to
get curve instances, then the `Delete Geometry` node to delete
some instances, and finally `Curves to Grease Pencil` to convert back
to Grease Pencil.

Pull Request: https://projects.blender.org/blender/blender/pulls/130028
2024-11-08 13:08:58 +01:00
Lukas Tönne
021e010a07 Merge branch 'blender-v4.3-release' 2024-11-08 10:22:58 +01:00
Lukas Tönne
9a03f283e8 Fix #129346: GPv3: Merge layers into correct groups when applying modifier
Applying a modifier on Grease Pencil objects tries to maintain the
original layer order by inserting each layer after the previous. This
ignores layer groups and all layers get move to the root group.
This patch replaces the simple `previous_node` with a per-group pointer
map, which maintains order within each group only.

The code is also creating new layers when the original node of the same
name is a group. This was creating duplicate names which are not allowed
and break various things (layer editing buttons, panel open/close
toggles, etc.). Now these new layer names are made unique to avoid a
name conflict.

One remaining issue is that mixed layer/group ordering is lost: All the
layers get pushed to the bottom of the stack, due to the way
`geometry::merge_layers` ignores layer groups. The existing groups in
the orig data are not sorted along with the evaluated layers, so they
move to the top of the stack. This requires changes to `merge_layers`
and should be handled separately.

Pull Request: https://projects.blender.org/blender/blender/pulls/129943
2024-11-08 08:28:06 +01:00
Xavier Hallade
57a7a940e1 Merge branch 'blender-v4.3-release' 2024-11-04 11:34:05 +01:00
Marco Rotili
b6481372b9 Fix #129629: Crash when applying Geometry Nodes modifier on all keyframes on a Grease Pencil object
The input `md_eval` is invalidated when calling `BKE_scene_graph_update_for_newframe`.

The fix uses `BKE_modifier_get_original` to pass the original modifier
to `apply_grease_pencil_for_modifier_all_keyframes` then calls `BKE_modifier_get_evaluated`
after `BKE_scene_graph_update_for_newframe` to ensure the `md_eval` pointer is valid.

Pull Request: https://projects.blender.org/blender/blender/pulls/129732
2024-11-04 10:38:46 +01:00
Campbell Barton
77a4954b68 Merge branch 'blender-v4.3-release' 2024-10-31 18:52:19 +11:00
Campbell Barton
5b53ff078d Fix "Apply Modifier as Shape" ignoring Alt to apply to selected
The property was set & checked but the operator didn't define it.
2024-10-31 18:45:46 +11:00
Damien Picard
5715693a97 UI: Use title case for Grease Pencil, Freestyle, Line Art
This was already the case for the vast majority of occurrences, and is
recommended by the human interface guideline's writing style.

Pull Request: https://projects.blender.org/blender/blender/pulls/129000
2024-10-15 13:00:47 +02:00
Falk David
9d9dc3fc8f GPv3: Apply modifier to all frames
This adds an option `all_keyframes` to the `object.modifier_apply` operator.
With the option enabled, the operator will iterate through all the keyframes,
then apply the modifier and merge the result back into the original
object. This is only done for Grease Pencil objects.

This is how the default `Apply` operation worked in GPv2. This adds the
functionality back but also keeps the current `Apply` behavior for consistency
with other object types.

The UI is also changed to show both options in the dropdown menu.
Again, this is only shown for Grease Pencil objects.

With Geometry Nodes it's possible to add new layers to the geometry.
When applying, this will create a single keyframe on the first frame of
evaluation.  Layers with duplicated names in evaluated geometry will
be deduplicated. It's also possible to have layers with empty names.
When applying these get renamed to `Layer` (and `Layer.001` etc.
when such a layer already exists in the original geometry).

Pull Request: https://projects.blender.org/blender/blender/pulls/128487
2024-10-04 11:51:30 +02:00
Sean Kim
eac36baafd Cleanup: Extract multires modifier operators into separate file
Pull Request: https://projects.blender.org/blender/blender/pulls/128397
2024-10-01 17:51:43 +02:00
Falk David
53b9594ee2 Geometry Nodes: Add "Merge Layers" node
This patch improves working with grease pencil layers in geometry nodes.
* Allow layers to have duplicate names in geometry nodes. In original data, unique names are enforced.
  * This allows e.g. duplicating layers and then merging them by name in the end.
  * It also resolves a big serial bottleneck when working with many grease pencil layers in geometry nodes. Enforcing unique names is inefficient.
* New `Merge Layers` node that can merge multiple layers by name or by a custom group id.
* Applying a grease pencil modifier now first merges all layers with the same name to ensure all names are unique.

Co-authored-by: Jacques Lucke <jacques@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/127873
2024-09-27 13:17:18 +02:00
Campbell Barton
381898b6dc Refactor: move BLI_path_util header to C++, rename to BLI_path_utils
Move to a C++ header to allow C++ features to be used there,
use the "utils" suffix as it's preferred for new files.

Ref !128147
2024-09-26 21:13:39 +10:00
Jacques Lucke
6810084a47 Attributes: improve API to iterate over attributes
This improve the API in multiple aspects:
* No need for an additional `lookup` call to get the current attribute. This
  would internally iterate over all attributes again. This leads to O(n^2)
  behavior. Note that there are still other reasons for O(n^2) behavior when
  processing attributes (where n is the number of attributes).
* Remove the need to return a value from the iteration code to indicate that the
  iteration should continue. This is now the default behavior. The iteration can
  still be stopped by calling `iter.stop()`.
* Easier access to `is_builtin` property.
* Iterator callback only has a single parameter instead of two (of which one is
  sometimes unused).

Pull Request: https://projects.blender.org/blender/blender/pulls/128128
2024-09-26 12:59:00 +02:00
Falk David
3c8d4becc8 Cleanup: GPv3: Return reference from GreasePencil::layer() functions
Since we only assert and never return `nullptr`, it's better to just return a reference.
The access into the span already asserts anyway.

Pull Request: https://projects.blender.org/blender/blender/pulls/128025
2024-09-23 13:54:02 +02:00
Pratik Borhade
eb44c39824 Fix #127616: Copy to selected adds modifier to linked object
Add extra check to prevent copying modifier on selected linked objects

Pull Request: https://projects.blender.org/blender/blender/pulls/127797
2024-09-18 12:47:52 +02:00
Jacques Lucke
89ae1ba38a Attributes: remove AttributeIDRef in favor of just using strings
Previously, the `AttributeIDRef` wrapper was needed because it also had to
contain a pointer to an `AnonymousAttributeID`. However, since
b279a6d703 this is not necessary anymore.
Therefore we can use "raw" `StringRef` now which reduces the mental overhead
when working with attributes and also simplifies code.

Pull Request: https://projects.blender.org/blender/blender/pulls/127140
2024-09-04 16:13:03 +02:00
Falk David
81d78e3416 GPv3: Apply Modifier
This implements the `Apply Modifier` operator for GPv3.

Applies the modifier to the current frame. Drawings at the current frame will be updated.
If the result of the modifier creates new layers, the layers will be added and a drawing
at the current frame will be inserted.

Applying a modifier will run the following steps:
* Create a localized copy of the original Grease Pencil data and insert it into a geometry
   set that owns it.
* Execute the `modifiy_geometry_set` function of the modifier with this geometry set.
* In the resulting Grease Pencil data loop over all layers:
   * If the original data has a layer with the same name, overwrite its drawing data in the
      current frame.
   * Otherwise create a new layer in the original data and insert a resulting drawing at
      the current frame.
* Remove all original layers that are not mapped to from a result layer.
* Remap the material indices for all drawings that have not been updated (e.g. the ones
    that are not on the current frame).
* Copy all the layer attributes to the original Grease Pencil.

Pull Request: https://projects.blender.org/blender/blender/pulls/124543
2024-08-13 15:02:25 +02:00
Jacques Lucke
5861b078f7 Core: rename ID.flag and ID.tag values
Previously, values for `ID.flag` and `ID.tag` used the prefixes `LIB_` and
`LIB_TAG` respectively. This was somewhat confusing because it's not really
related to libraries in general. This patch changes the prefix to `ID_FLAG_` and
`ID_TAG_`. This makes it more obvious what they correspond to, simplifying code.

Pull Request: https://projects.blender.org/blender/blender/pulls/125811
2024-08-07 12:12:17 +02:00
Jacques Lucke
6b9b958668 Fix #125291: crash when applying curves modifier when there is a bake
The crash was caused by attempting to write-back to the original data after it
has been removed (`add_data_block_items_writeback`).

This write-back is already disabled when applying a modifier, however the
corresponding flag was only set when applying modifiers on mesh objects. This
patch fixes this issue with two small changes:
* Rename `MOD_APPLY_TO_BASE_MESH` to `MOD_APPLY_TO_ORIGINAL` to make it more
  generic.
* Pass this flag into modifier evaluation for other geometry types besides
  meshes in `modifier_apply_obdata`.

Pull Request: https://projects.blender.org/blender/blender/pulls/125761
2024-08-01 13:36:43 +02:00
Falk David
0f42f277b7 Grease Pencil: Remove legacy modifiers
This removes the legacy Grease Pencil modifiers from the code.
These should have already been inaccessible from the UI and hidden from
the user. The modifiers have been reimplemented for the new GPv3
data structure.

On top of the modifier code, some other related things have been
removed as well:
 * Operators related to the legacy modifiers.
 * Keymaps for the legacy modifier operators.
 * Some bits of code that used modifier functions.

Some code has to be kept, because it is still used:
 * The core line art code, which is used by the new line art modifier. It's
    moved to `modifiers/lineart`.
 * The DNA structs for the legacy modifiers. They are still needed for
    conversion.
 * A few kernel functions for the modifiers are kept (also for conversion).

Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/125102
2024-07-29 10:37:29 +02:00
Bastien Montagne
c607ead4b7 Refactor: Makesrna: move generated code further in C++.
This commit moves generated `RNA_blender.h`, `RNA_prototype.h` and
`RNA_blender_cpp.h` headers to become C++ header files.

It also removes the now useless `RNA_EXTERN_C` defines, and just
directly use the `extern` keyword. We do not need anymore `extern "C"`
declarations here.

Pull Request: https://projects.blender.org/blender/blender/pulls/124469
2024-07-15 16:39:45 +02:00
Pratik Borhade
7ee2938bc1 Fix #124468: UI is not refreshed after copying modifier using Outliner
Add notifier when copying a modifier to a different object so that
Properties and Outliner can update and redraw.

Pull Request: https://projects.blender.org/blender/blender/pulls/124510
2024-07-11 20:55:21 +02:00
Campbell Barton
61e4d1818e Cleanup: follow operator callback & argument naming 2024-05-24 14:08:33 +10:00
Hans Goudey
5733f6e906 Cleanup: Move mesh evaluation functions to C++ namespace
And move them out of the DerivedMesh header so that can just be used
for the actual DerivedMesh code.
2024-05-20 13:11:18 -04:00
Jacques Lucke
2f289857af Object: add Shade Auto Smooth operator
Based on the design in #120230.
* Replaces the `Shade Smooth by Angle` operator with `Shade Auto Smooth`
  in the object context menu menu.
* The new operator automatically adds and removes the modifier instead
  of being a destructive operation.
* The `Shade Smooth` and `Shade Flat` operators now remove the
  `Smooth by Angle` modifier automatically.
* Add a pin option to modifiers, which limits dragging and keeps the
  modifier after newly added modifiers in the list.

Co-authored-by: Hans Goudey <hans@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/121494
2024-05-08 20:24:10 +02:00
Hans Goudey
a214d00f28 UI: Check for object modifier support in operator poll functions
Check whether the object supports modifiers in the clear and
copy to selected operators.
2024-05-02 10:12:46 -04:00
Hans Goudey
e63c8bb3c2 UI: Add Modifiers submenu to 3D view header
Add a menu similar to the "Object > Constraints" menu that allows adding,
copying, and clearing modifiers. The "copy all modifiers to selected" and
"clear modifiers" operators are new, to mirror the functionality we already
have for constraints.

The "Add" menu is the same that's used in the property editor. In the 3D
view, modifiers are always added to all selected objects.

Part of #120230

Pull Request: https://projects.blender.org/blender/blender/pulls/121286
2024-05-01 14:15:53 +02:00
Hans Goudey
02f2d73b78 Refactor: Deduplicate modifier copy to selected functions
There were two functions copying modifiers. The modifier operator
exposed in the property editor reported for various failures. Outliner
drag and drop did not. This commit refactors code a bit to unify the
two. Outliner drag and drop should now report why it fails too.
2024-04-30 16:02:08 -04:00
Hans Goudey
5b6c776ef4 Cleanup: Rename modifier_clear function to add plural
Make it more obvious that the function removes all modifiers.
2024-04-30 16:02:08 -04:00
Pratik Borhade
7c89efd787 Fix #120809: Skip saving use_selected_objects
Issue came with the new feature of adding modifiers to selected objects
by holding alt: 9a7f4a3b58. `use_selected_objects` state should not be
remembered. Otherwise, it's possible to add/edit modifier of multiple
object without holding alt

Pull Request: https://projects.blender.org/blender/blender/pulls/120810
2024-04-19 14:00:49 +02:00
Hans Goudey
9a7f4a3b58 Modifiers: Affect all selected objects when holding alt
Support holding alt while invoking modifier operations for add, apply,
remove, and move to index in the property editor. This affects all selected
editable objects instead of just the active object.

Though the alt key is not that visible, it's consistent with the
existing multi-object property editing shortcut. If/when multi-
object editing is every made the default, the alt key could
be reversed here too.

Changes as part of #120230.

Pull Request: https://projects.blender.org/blender/blender/pulls/120695
2024-04-18 17:40:50 +02:00