Commit Graph

121 Commits

Author SHA1 Message Date
Omar Emara
1c315c62d2 Fix: Crash when duplicating node editor
Blender crashes when duplicating a node editor with an active
compositor session. That's because the runtime data of the editor is
nullptr upon duplication. This is a regression in 51a7961e09, where the
runtime data was set to nullptr upon duplication, while it should be
assigned a newly allocated structure or duplicate the existing
structure. To fix this, we do the former and allocate a new structure
because that's what the developer intended in the original patch.

The crash is rare and went unnoticed because the runtime data is
initialized in the init method as well, which typically gets called
quickly right after the area is duplicated.

Pull Request: https://projects.blender.org/blender/blender/pulls/122506
2024-05-31 15:22:21 +02:00
Bastien Montagne
435b6743fd Fix #121733: Linked masks/moviclips/images used by editors get lost on file reload.
This was a consequence of the work done in #106321, where this specific
'active in UI' case was not identified and properly handled.

Now, consider most ID usages from UI (editors) as 'weak links', i.e.
keep a reference to these IDs even if they are only indirectly used.

Note that missing weak links will not create placeholders if the source
data is not found in the library anymore on load. they are just silently
dropped.

Pull Request: https://projects.blender.org/blender/blender/pulls/122207
2024-05-27 13:35:53 +02:00
Falk David
4f2f97d498 Formatting 2024-05-13 16:28:19 +02:00
Iliya Katueshenock
75d17b1db5 Cleanup: Move BKE_node to namespace
Move all header file into namespace.
Unnecessary namespaces was removed from implementations file.
Part of forward declarations in header was moved in the top part
of file just to do not have a lot of separate namespaces.

Pull Request: https://projects.blender.org/blender/blender/pulls/121637
2024-05-13 16:07:12 +02:00
Guillermo Venegas
615100acda IO: Use FileHandler in Node Editors
Use `FileHandlers` to handle file drag-n-drop in Node Editors. Drop-boxes
still remain since they handle Images ID drag-n-drop.

This also allows to open/drag-n-drop multiple files at once.

Also this will allow add-ons to also support drag-n-drop for images and
movies in node editors while still providing access to Blender's native
support since File Handlers let users choose which to invoke if there's
multiple configured.

Pull Request: https://projects.blender.org/blender/blender/pulls/121051
2024-04-26 16:40:16 +02:00
Brecht Van Lommel
15b9ae5436 Refactor: Use typed functions for blend file data reading
This makes the read and write API functions match more closely, and adds
asserts to check that the data size is as expected.

There are still a few places remaining that use BLO_read_data_address
and similar generic functions, these should eventually be replaced as well.

Pull Request: https://projects.blender.org/blender/blender/pulls/120994
2024-04-24 17:01:22 +02:00
Hans Goudey
efee753e8f Cleanup: Move BKE_idprop.h to C++ 2024-03-26 13:07:04 -04:00
Hans Goudey
72758f3296 Cleanup: Use FunctionRef for IDRemapper callback
This avoids the need for a separate argument struct in a few cases
and generally makes the remapping friendlier to use with lambdas.
2024-03-07 09:30:22 -05:00
Hans Goudey
5f16d23971 Fix: Null pointer dereference in node editor ID remapping
This didn't cause a crash because `offsetof(bNodeTree, id) == 0`.
But still, it is wrong.
2024-03-04 10:36:21 -05:00
Bastien Montagne
5baef63a20 BKE ID remap: Refactor: Remove C API around CPP IDRemapper.
The ID remapper code was already largely defined in a CPP struct
(IDRemapper). Make this an actual class, and remove the C API wrapper
around.

This makes the code cleaner, easier to follow, and easier to extend or
modify in the future.

Pull Request: https://projects.blender.org/blender/blender/pulls/118146
2024-02-13 15:36:38 +01:00
Campbell Barton
b372ebae68 Cleanup: unused headers for source/blender/editors
Remove 1317 includes from editors.
2024-02-13 10:02:53 +11:00
Hans Goudey
f78d3a807a Cleanup: Store space types in vector of unique_ptr
- Use unique_ptr instead of raw pointers
- Use Vector instead of a linked list
- Use a destructor instead of a free function
- Remove the space type template-- it's much clearer to copy functional code

Pull Request: https://projects.blender.org/blender/blender/pulls/117766
2024-02-02 20:59:20 +01:00
Guillermo Venegas
da77f90744 Fix unreported: Avoid using unknown file types in dropboxes
Most of the `WM_DRAG_PATH` poll functions include
unknown file types (`0`) as fallback, preventing file handlers
from being used with explicit defined file extensions.

Pull Request: https://projects.blender.org/blender/blender/pulls/117189
2024-01-26 03:43:31 +01:00
Jacques Lucke
311ca3e6af Core: rename Session UUID to Session UID
`UUID` generally stands for "universally unique identifier". The session identifier that
we use is neither universally unique, nor does it follow the standard. Therefor, the term
"session uuid" is confusing and should be replaced.

In #116888 we briefly talked about a better name and ended up with "session uid".
The reason for "uid" instead of "id" is that the latter is a very overloaded term in Blender
already.

This patch changes all uses of "uuid" to "uid" where it's used in the context of a
"session uid". It's not always trivial to see whether a specific mention of "uuid" refers
to an actual uuid or something else. Therefore, I might have missed some renames.
I can't think of an automated way to differentiate the case.

BMesh also uses the term "uuid" sometimes in a the wrong context (e.g. `UUIDFaceStepItem`)
but there it also does not mean "session uid", so it's *not* changed by this patch.

Pull Request: https://projects.blender.org/blender/blender/pulls/117350
2024-01-22 13:47:13 +01:00
Bastien Montagne
03c1cc4310 Cleanup: Move BKE_lib_query header to Cpp era. 2024-01-18 12:21:19 +01:00
Hans Goudey
3e76a1a6c2 Cleanup: Move BKE_lib_id.h to C++ 2024-01-15 12:44:14 -05:00
Omar Emara
e165624885 Compositor: Only execute compositor if result is viewed
This patch makes it such that the compositor only executes when its
result is viewed either through the backdrop or through an image editor.

Pull Request: https://projects.blender.org/blender/blender/pulls/116326
2023-12-21 10:22:51 +01:00
Guillermo Venegas
c00c8b1b37 IO: Add support for multiple drag-n-drop files
There are operators in Blender that allow the user to import multiple
files at the same time, however this functionality is only implemented
when importing with blender's file browser, drag and drop files only
takes first selected file.

The patch adds support for drag and drop multiple files.

Notes:
* The files are filtered according to the extension of the first
  selected file.
* Not all operators that import files support importing multiple files,
  so they will still import one.
* Changes must be made to allow importers to read all file paths.

This will be used in upcoming drag & drop import.

Pull Request: https://projects.blender.org/blender/blender/pulls/107230
2023-12-12 18:46:12 +01:00
Omar Emara
5e370ee643 Fix: Missing compositor update upon changing tree options
The compositor doesn't run when changing node tree options. That was due
to a nullptr notifier reference for RNA node tree edits.

This patch uses the node tree ID for the notifier reference.
Additionally, the listener code was extended to always tag the node tree
when the reference is null, which converts missing updates issues like
this one to superfluous updates, since it is safer.

Pull Request: https://projects.blender.org/blender/blender/pulls/115532
2023-12-01 15:13:04 +01:00
Bastien Montagne
fe3cb11ae4 BKE_lib: Convert BKE_lib_remap and lib_intern headers to be fully C++. 2023-11-30 19:51:22 +01:00
Philipp Oeser
864b07011a Fix #115037: Crash deleting tool node group from outliner
Prevent heap-use-after-free of SpaceNode `geometry_nodes_tool_tree`,
remapping it in `node_id_remap_cb` (so it get null when deleted).

Pull Request: https://projects.blender.org/blender/blender/pulls/115047
2023-11-30 15:48:42 +01:00
Jacques Lucke
74dd1e044b Nodes: improve socket picking tolerances
The goal here is to make it easier to make node links. Previously, it was quite
easy to accidentally start box selection or to trigger the link-drag-search when
that was not intended.

Now, the tolerances are a bit easier to work with. Also, instead of trying to use
the first socket that is close enough, it will find the closest socket instead. It feels
much better in my testing already, but obviously the values can be tuned more
with some testing.

Also we have to make sure to not accidentally make other things like resizing
nodes harder.

Pull Request: https://projects.blender.org/blender/blender/pulls/115010
2023-11-25 15:23:31 +01:00
Jacques Lucke
96b3afe065 Cleanup: rename node group to group node context
`GroupNodeComputeContext` is the more correct name because it's
specifically about a group node that invokes another node tree.
The old name makes it sound like it should be used because a node group
is invoked but does not tell anything about what invoked it.
For example, the current context in a node group can also be a
`ModifierComputeContext` if that's what invoked it.
2023-11-21 14:12:23 +01:00
Jacques Lucke
78b2c15c4d Nodes: support storing caller tree and node in node group compute context
This is used by #112677.
2023-11-21 13:52:45 +01:00
Omar Emara
7ea54b7472 Fix #114648: Compositor executes upon editing non-compositor trees
The compositor currently executes when editing node trees that are not
compositor related, like geometry and shader node trees.

That's because the node space listener always tags the compositor to
execute for any node edit notifier. To fix this, we add the ID of the
edited node tree as a reference to the edit notifier and only tag for
an update when the space tree matches the reference one.

Pull Request: https://projects.blender.org/blender/blender/pulls/114978
2023-11-17 08:52:47 +01:00
Hans Goudey
3d57bc4397 Cleanup: Move several blenkernel headers to C++
Mostly focus on areas where we're already using C++ features,
where combining C and C++ APIs is getting in the way.

Pull Request: https://projects.blender.org/blender/blender/pulls/114972
2023-11-16 11:41:55 +01:00
Omar Emara
c98308a77e Fix #113653: Compositor superfluously executes on scene changes
The compositor executes superfluously on scene changes when adding or
removing objects.

This was due to an explicit handling of a certain notifier, which was
introduced in commit 1e948b251d. The exact reasoning behind the
addition is unknown, so this patch removes it until we have an informed
decision to keep it.
2023-11-13 13:33:22 +02:00
Hans Goudey
f64ed2e963 Cleanup: Simplifying freeing node editor space data 2023-10-21 14:56:06 +02:00
Hans Goudey
1ccba4d9fe Nodes: Use index instead of reordering for draw order
Currently nodes are reordered so that the "on top" nodes are last in
the list. Node order changing for simple operations like selection
means we either have to reevaluate the node tree data-block on
selections or accept that the evaluated order can be different from the
original. Currently we do the latter (see d76a0e98ba), but
makes it complex to access nodes by index, and is hard to reason about.

Instead of reordering nodes, store the ui order in the node itself
and sort the nodes before drawing them or doing any processing
that depends on the "depth."

The "selected_nodes" list in the context is no longer ordered by the
recent selection.

Pull Request: https://projects.blender.org/blender/blender/pulls/113419
2023-10-10 10:57:51 +02:00
Hans Goudey
9e495c5b06 Geometry Nodes: Store tool group in a separate editor property
This enables switching back and forth between the modifier and tool
contexts of the geometry node editor without losing the assigned tool
node group.

See #101778

Pull Request: https://projects.blender.org/blender/blender/pulls/112926
2023-09-27 15:47:22 +02:00
Jacques Lucke
c8cc169d6f Geometry Nodes: add Inspection Index to Repeat Zone
Previously, it was only possible to inspect the data from the first iteration. That
applied to both, the viewer node as well as socket inspection. Now, there is a
new `Inspection Index` setting in the zone properties. It specifies which iteration
should be used by the inspection features.

In theory we could support features like counting the index from the end, but
that can be done separately as well, as it likely requires more UI.

Pull Request: https://projects.blender.org/blender/blender/pulls/112818
2023-09-27 11:09:39 +02:00
Jacques Lucke
ad169ba67a Geometry Nodes: support baking individual simulations
Previously, it was only possible to bake all simulations at once. This is great
for simple use-cases that, but in more complex setups one can have independent
simulations that should also be baked independently. This patch allows baking
individual simulation zones.

Furthermore, each simulation zone can now also have its own bake path and
simulation frame range. By default the simulation frame range is the scene frame
range, but it can also be customized on the scene or simulation zone level. The
bake path is generated based on the modifier bake path by default, but can be
set to another absolute or relative (to the .blend file) path.

The timeline drawing has been modified as well to be able to show more information
in the case when some simulations are baked and others are not. Instead of showing
a line for every simulation, it shows a condensed view of the important information
using at most two lines:
Is something baked? Is something valid or invalid? Also see #112232.

Pull Request: https://projects.blender.org/blender/blender/pulls/112723
2023-09-26 20:30:46 +02:00
Hans Goudey
916d4c9d9b Cleanup: Move BKE_screen.h to C++
See #103343
2023-09-25 17:53:11 -04:00
Jacques Lucke
7015d83368 Cleanup: Geometry Nodes: move functions to a more reusable place 2023-09-24 21:07:56 +02:00
Hans Goudey
867f99c2af Cleanup: Move depsgraph headers to C++
Pull Request: https://projects.blender.org/blender/blender/pulls/110816
2023-09-22 03:18:17 +02:00
Hans Goudey
d2d4de8c71 Geometry Nodes: Show uncategorized assets in separate menus
In the add modifier menu, 3D viewport menus for node tools, and the node
editor add menu, assets not in catalogs are added to an "No Catalog"
menu rather than not being accessible at all.

This makes the default behavior when adding a node tool "not broken"
so at least something happens by default. The question of "How do I
add a catalog?" is much better than "Why didn't anything happen?"

Implements #111529
See #101778

---

![image](/attachments/b943e2c4-f660-4812-b9ab-f7c116b68b98)
![image](/attachments/e6ee94d7-cd14-475f-8fa6-abcc6774fd7e)
![image](/attachments/b1718d0c-4182-49c5-867a-1399082e98f0)

Pull Request: https://projects.blender.org/blender/blender/pulls/112355
2023-09-14 17:35:24 +02:00
Campbell Barton
c7cd1c8d0b Cleanup: use enum literals for space_type & region_type arguments
Also remove unique names for grease pencil keymaps.
There was not advantage in having separate names for each grease pencil
key-map.
2023-09-14 13:36:34 +10:00
Philipp Oeser
e924f316a7 Fix #112021: Crash dragging node groups into an empty node editor
Mistake in 30e3caaf82 (which wasnt checking if an `edittree` actually
existed).

Pull Request: https://projects.blender.org/blender/blender/pulls/112023
2023-09-06 13:51:18 +02:00
Harley Acheson
8c826afc7b Cleanup: Make format
Just changes resulting from Make Format. Just space_node.cc
2023-09-04 16:08:54 -07:00
Philipp Oeser
30e3caaf82 Fix #111779: drop asset shading group to GN editor still imports
Dropbox poll function was not sufficiently checking compatibility, so we
could end up calling
`WM_drag_get_local_ID_or_import_from_asset`. The asset might not
actually be used because of further checks later (so it would end up as
an orphan which would go away after save/reload), but still the import
should be avoided.

This fixes the case for dropping a shader nodegroup to the Geometry
Nodes Editor by getting asset metadata (and checking if the nodetree
type matches editor) in the dropbox poll function.

Will check on other possible cases of drag-drop to incompatible editors
next.

Pull Request: https://projects.blender.org/blender/blender/pulls/111921
2023-09-04 12:43:56 +02:00
Hans Goudey
fa34992def Cleanup: Remove unnecessary includes from C++ data structure headers
The hash tables and vector blenlib headers were pulling many more
headers than they actually need, including the C base math header,
our C string API header, and the StringRef header. All of this
potentially slows down compilation and polutes autocomplete
with unrelated information.

Also remove the `ListBase` constructor for `Vector`. It wasn't used
much, and making it easy to use `ListBase` isn't worth it for the
same reasons mentioned above.

It turns out a lot of files depended on indirect includes of
`BLI_string.h` and `BLI_listbase.h`, so those are fixed here.

Pull Request: https://projects.blender.org/blender/blender/pulls/111801
2023-09-01 21:37:11 +02:00
Daybreak
aa83fb0337 Geometry Nodes: Support drag & drop for Materials
Allows for materials to be dragged and dropped into the
geometry nodes editor, similar to collections or objects.

Pull Request: https://projects.blender.org/blender/blender/pulls/111368
2023-08-29 15:51:18 +02:00
Hans Goudey
3db523ab3e Cleanup: Move BLO headers to C++
Except for BLO_readfile.h, which is still included by C files.

Pull Request: https://projects.blender.org/blender/blender/pulls/111610
2023-08-28 15:01:05 +02:00
Bastien Montagne
b53c7a804a Readfile: Replace the 'lib_link' specific code by generic usage of foreach_id.
The `lib_link` callback cannot always be fully replaced/removed, as in
some case it is also doing some validation checks, or data editing based
on the result of lib_linking internal ID pointers.

The callback has been renamed for that purpose, from `read_lib` to
`read_after_liblink`. It is now called after all ID pointers have been
fully lib-linked for the current ID, but still before the call to
`do_versions_after_linking`.

This change should not have any behavioral effect. Although in theory
the side-effect of this commit (to split lib linking itself, and the
validation/further processing code) into two completely separated steps
could have some effects, in practice none are expected, and tests did
not show any changes in behavior either..

Part of implementing #105134: Removal of readfile's lib_link & expand code.
2023-08-24 16:33:31 +02:00
Philipp Oeser
686ffaaed9 Fix #111174: dropped nodegroups from the asset browser show selector
There was a difference between drag&drop assets from the asset browser
vs. using the search menu (in that doing it from the menu would
correctly hide the data-block selector on the nodegroup).

Since drag&drop in the Node Editor uses `NODE_OT_add_group` (not
`NODE_OT_add_group_asset` as the menu does), we have to add the hiding
here too (for this, an operator property is added which is set in
`node_group_drop_copy` if we are dropping an asset.

Alternatively, we could use `NODE_OT_add_group_asset`, too, but that
would require somehow setting the "asset" context pointer from the
dropbox copy function [how to do this wasnt obvious for me]. In that
case, we would need to set up a separate dropbox with appropriate poll
functions (so there would be one for asset groups and for the the other
groups).

Pull Request: https://projects.blender.org/blender/blender/pulls/111427
2023-08-24 15:12:00 +02:00
Bastien Montagne
710b47fe7c Tweak SpaceNode foreach_id callback handling of nodetree ID pointer.
The fact that this pointer may be either to a regular ID, or an embedded
one, without any way to tell it withour accessing the nodetree data,
makes it tricky to handle properly when such 'other ID' access is not
allowed. Here there can still be assumptions and heuristics based on
other data, but this remains fragile and really sub-optimal code.

Should not have any behavioral change in current code, but required for
replacing `blend_read_lib`/`blend_read_expand` by `foreach_id`
(#105666).
2023-08-22 22:17:04 +02:00
Bastien Montagne
d7d487e13a Refactor: Move Editors' 'foreach_id' code into a new SpaceType callback.
Was a known pending TODO for quite some time already.

This commit should have no behavior change at all.
2023-08-17 16:08:05 +02:00
Campbell Barton
e955c94ed3 License Headers: Set copyright to "Blender Authors", add AUTHORS
Listing the "Blender Foundation" as copyright holder implied the Blender
Foundation holds copyright to files which may include work from many
developers.

While keeping copyright on headers makes sense for isolated libraries,
Blender's own code may be refactored or moved between files in a way
that makes the per file copyright holders less meaningful.

Copyright references to the "Blender Foundation" have been replaced with
"Blender Authors", with the exception of `./extern/` since these this
contains libraries which are more isolated, any changed to license
headers there can be handled on a case-by-case basis.

Some directories in `./intern/` have also been excluded:

- `./intern/cycles/` it's own `AUTHORS` file is planned.
- `./intern/opensubdiv/`.

An "AUTHORS" file has been added, using the chromium projects authors
file as a template.

Design task: #110784

Ref !110783.
2023-08-16 00:20:26 +10:00
Philipp Oeser
4cefe0ec80 Fix #110723: cant drop object name on object field/socket in node editor
Reason was a difference in poll functions (dropbox poll function vs.
operator poll function).

So the dropbox was actually recognized as being active (see
`dropbox_active`) but then when actually dropping, the corresponding
operator wasnt called (but instead another operator was).

In detail, the way `wm_handlers_do_intern` works, it checks all
dropboxes poll function if one succeeds it calls the dropbox operator.
But if that operators poll function fails, `wm_handlers_do_intern`
happily continues and "ends" the drop operations in a way we dont
actually get to the "real" dropbox & operator that was also recognized
as being active.

In the case of the report:
- dropbox for `UI_OT_drop_name` is active
- dropbox poll for `NODE_OT_add_object` (`node_object_drop_poll`)
succeeds though
- operator poll for `NODE_OT_add_object` (`node_add_object_poll`) fails
(it checks `UI_but_active_drop_name` already)

So in order to make this work, add the check for `UI_but_active_drop_name` to two dropbox poll
functions (and remove from the operator polls).

Probably good for LTS as well.

Pull Request: https://projects.blender.org/blender/blender/pulls/110929
2023-08-14 13:12:33 +02:00
Jacques Lucke
cc4d5c432c RNA: move headers to C++
Also see #103343.

Pull Request: https://projects.blender.org/blender/blender/pulls/111022
2023-08-10 22:40:27 +02:00