Commit Graph

67 Commits

Author SHA1 Message Date
YimingWu
db96265568 Fix #148061: Prevent unknown socket type from crashing when reading file
`socket.socket_typeinfo()` can be nullptr when reading blend files that
contains custom socket types that are not registered yet. This fix
prevents crashing when this happenes (but the socket will stay
unregistered).

Pull Request: https://projects.blender.org/blender/blender/pulls/148103
2025-10-15 16:54:08 +02:00
Jacques Lucke
01ccf31d20 Fix: Nodes: propagated menu expanded state to group input
Previously, when a new group input was created from an expanded menu
socket, the expanded flag was not set on the group input.
2025-09-29 18:28:20 +02:00
Jacques Lucke
ef92735a95 Nodes: support optional labels for group inputs
Built-in nodes already used the functionality to hide the input labels in a few
situations. However, this functionality was not exposed for node groups before.
It required some refactoring to get the semantics of the flag right. The tricky
aspect is that "Hide Label" would be an incorrect name, because the label is
still shown under various circumstances. Instead, the flag merely indicates that
drawing code may skip drawing the label.

This adds a new "Optional Label" input for node group inputs. Other names are
possible like "Requires Label" which would be the inverse.

Overall the implementation is pretty straight forward after
1f489ea31a,
469a70dba9 and
f79896f5b9.

Pull Request: https://projects.blender.org/blender/blender/pulls/146939
2025-09-29 18:14:41 +02:00
Lukas Tönne
dab6b45336 Fix #143551: Cache invalidation causes crash when changing node tree item properties
Changing a node tree item property (such as the default value) was using a very
broad and generic "tag" function which invalidates the runtime items cache.
This also invalidates any python iterators due to the API using the runtime
cache. Changing node tree items in a loop will then crash.

It's not necessary to invalidate the runtime items cache when the actual item
pointers have not changed. Most RNA updates only change superficial properties,
or at most require a recursive node tree update due to change of identifiers or
types.

This PR introduces a simpler "tag" function to only tag for tree updates by not
rebuild the entire runtime items cache. It also renames existing functions and
docstrings to better explain what each of them does and should be used for.

The `NodeTreeInterfaceChangedFlag` is removed completely because it is only ever
used as a simple boolean indicator of "item changes" that require a cache
rebuild. It is replaced with an atomic bool like flags used for runtime caches.

Pull Request: https://projects.blender.org/blender/blender/pulls/143932
2025-08-12 11:00:10 +02:00
Jacques Lucke
baf68516f0 Fix: Nodes: missing socket descriptions when grouping node 2025-06-20 10:23:32 +02:00
Jacques Lucke
af3f9ac66e Fix #138085: Nodes: allow panel toggles in panels with outputs
Currently, there is the general rule that outputs must be above inputs in any
given panel. Since internally a panel toggle input is part of the panel that it
toggles and has to be the first item in a panel, it was not possible to have a
panel toggle for a panel with outputs.

This patch relaxes the rule for ordering of inputs and outputs for the special
case of panel toggles.

Pull Request: https://projects.blender.org/blender/blender/pulls/140054
2025-06-09 16:09:27 +02:00
Hans Goudey
b80f1f5322 Geometry Nodes: Socket structure type and display changes
Implementation of #127106.
This is just a visual representation of the field/single/grid
status of sockets to make the workflow more intuitive. With
a visual representation for volume grid sockets, volume features
should be unblocked for further development. The structure type
will also be used to distinguish list sockets in the interface.

Group input nodes now have a "Structure Type" option instead of
the existing "Single Value Only". Usually the auto option should be
enough, but in some cases where the inferencing cannot (yet) make
a clear determination, it can be helpful to choose a specific type.

The new visualization and the group input structure type option
are hidden behind a new experimental option for now.

Pull Request: https://projects.blender.org/blender/blender/pulls/134811
2025-05-28 02:33:47 +02:00
Omar Emara
02a95d088e Nodes: Add support for 2D and 4D vector sockets
This patch adds support for 2D and 4D vector sockets. The default value
structure for vectors was extended to include a new dimensions input,
which can be 2, 3, or 4. The default value was also extended to be a
float4, but only some of its components might be used depending on the
dimensions members.

Each vector subtype now has three variants ending with 2D or 4D as a
prefix depending on its dimensions, and the 2D/4D prefix was taken into
account for the socket type RNA enum functions.

All node systems currently always treat the vectors as 3D, but support
for it in the compositor will shortly follow in another patch.

Depends on #138805.

Pull Request: https://projects.blender.org/blender/blender/pulls/138824
2025-05-26 11:41:54 +02:00
Jacques Lucke
363eff4f59 Fix: Nodes: missing null check
This caused a crash when creating a group from a node which has
a virtual input socket (e.g. Menu Switch).
2025-05-23 09:21:18 +02:00
Jacques Lucke
c55ffb5258 Nodes: improve implicit inputs
This improves implicit node inputs in multiple ways:
* Fix crash when switching a group input socket type from e.g. vector to
  integer, while the default input is set to "position". Now, the default input
  type is reset automatically if it's invalid.
* Add Left/Right Handle as possible implicit vector inputs (next to Position and
  Normal). Those were the only ones that we used internally that were not
  exposed yet.
* When creating a new group input from an existing socket, also initialize the
  default input based on the socket. E.g. when grouping a `Set Position` node,
  the `Position` input of the group will now also use the position attribute by
  default.

In addition to these user-level changes, some internal changes were done too:
* Use unified `NodeDefaultInputType` in node declaration instead of function
  pointers which were hard to propagate to node groups.
* Use a new reusable `socket_type_supports_default_input_type` function in rna
  to filter the list of possible input items.

Pull Request: https://projects.blender.org/blender/blender/pulls/139139
2025-05-20 17:54:49 +02:00
Jacques Lucke
81275eff60 Nodes: improve forward compatibility for unknown interface item types
#138747 adds a new interface item type for separators. Unfortunately, the
current code is not forward-compatible with those. This patch improves forward
compatibility by removing all unknown tree interface item types on-load.

Pull Request: https://projects.blender.org/blender/blender/pulls/139015
2025-05-19 17:52:15 +02:00
Jacques Lucke
d04699397b Fix: Nodes: off-by-one error when reordering tree interface items
It was possible to move an input socket above one output socket.

Caused by 45eb746250.
2025-05-17 15:18:26 +02:00
Jacques Lucke
45eb746250 Cleanup: Nodes: generalize finding valid insert position for tree view item
Currently, there are some constraints on the interface of node groups:
* Sockets have to be above panels.
* Outputs have to be above inputs.

The current code that ensures these constraints wasn't able to handle the
case when there are more interface items without the same constraints.

This patch is extracted from #138747.
2025-05-17 11:35:07 +02:00
Jacques Lucke
b2b22cb66d Cleanup: Nodes: switch using enum instead of int
This simplifies adding more interface item types, because there will
be a compiler warning when it's not handled somewhere.
2025-05-17 11:31:08 +02:00
Jacques Lucke
5d98465acd Fix: Geometry Nodes: wrong struct passed to BLO_read_struct
This didn't cause issues so far, because only the size of that passed in
struct is taken into account currently.
2025-05-17 11:27:45 +02:00
Bastien Montagne
dd168a35c5 Refactor: Replace MEM_cnew with a type-aware template version of MEM_callocN.
The general idea is to keep the 'old', C-style MEM_callocN signature, and slowly
replace most of its usages with the new, C++-style type-safer template version.

* `MEM_cnew<T>` allocation version is renamed to `MEM_callocN<T>`.
* `MEM_cnew_array<T>` allocation version is renamed to `MEM_calloc_arrayN<T>`.
* `MEM_cnew<T>` duplicate version is renamed to `MEM_dupallocN<T>`.

Similar templates type-safe version of `MEM_mallocN` will be added soon
as well.

Following discussions in !134452.

NOTE: For now static type checking in `MEM_callocN` and related are slightly
different for Windows MSVC. This compiler seems to consider structs using the
`DNA_DEFINE_CXX_METHODS` macro as non-trivial (likely because their default
copy constructors are deleted). So using checks on trivially
constructible/destructible instead on this compiler/system.

Pull Request: https://projects.blender.org/blender/blender/pulls/134771
2025-03-05 16:35:09 +01:00
Falk David
2822777f13 Nodes: support boolean inputs as toggles in panel headers
Adds the option to create a boolean socket that can be used as a panel toggle.
This allows creating simpler and more compact node group UIs when a panel
can be "disabled".

The toggle input is a normal input socket that is just drawn a bit differently in
the UI. Whether a boolean is a toggle input or not does not affect evaluation.

Also see #133936 for guides on how to add and remove panel toggles.

Pull Request: https://projects.blender.org/blender/blender/pulls/133936
2025-02-28 19:07:02 +01:00
Pratik Borhade
3a1e7ffebe Fix #134737: Node: Panel deleted when Parented with children
Skip `move_to_parent()` operation when new_parent is already
children of "item" to avoid running into this situation.

Pull Request: https://projects.blender.org/blender/blender/pulls/135148
2025-02-26 14:13:33 +01:00
илья _
119fc054f8 Cleanup: BKE: Nodes: Pass-by-reference
Restriction of the nodes api to clearly define never-null function arguments.
Side effects: some assertions and null-check (with early return) were removed.
On the caller side is ensured to never derefer null to pass argument (mainly in RNA).
In addition, one pointer argument now actually a return type.

By-reference return types instead of pointers going to be separate kind of
change since also imply of cleaning up variables created from reference.

Also good future improvement would be to mark a copy-constructor as
explicit for DNA node types.

Pull Request: https://projects.blender.org/blender/blender/pulls/134627
2025-02-19 13:44:11 +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
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
01be014b3d Fix: add missing node tree topology cache 2025-01-13 15:06:50 +01:00
Hans Goudey
13b79072e2 Refactor: Nodes: Use C++ new, std::string in node/socket/tree types
Make the type structs non-trivial, use new and delete for allocation and
freeing, and use std::string for most strings they contain. Also use
StringRef instead of char pointers in a few places. Mainly this improves
ergonomics when working with the strings.

Pull Request: https://projects.blender.org/blender/blender/pulls/132750
2025-01-08 16:34:41 +01:00
Brecht Van Lommel
920e709069 Refactor: Make header files more clangd and clang-tidy friendly
When using clangd or running clang-tidy on headers there are
currently many errors. These are noisy in IDEs, make auto fixes
impossible, and break features like code completion, refactoring
and navigation.

This makes source/blender headers work by themselves, which is
generally the goal anyway. But #includes and forward declarations
were often incomplete.

* Add #includes and forward declarations
* Add IWYU pragma: export in a few places
* Remove some unused #includes (but there are many more)
* Tweak ShaderCreateInfo macros to work better with clangd

Some types of headers still have errors, these could be fixed or
worked around with more investigation. Mostly preprocessor
template headers like NOD_static_types.h.

Note that that disabling WITH_UNITY_BUILD is required for clangd to
work properly, otherwise compile_commands.json does not contain
the information for the relevant source files.

For more details see the developer docs:
https://developer.blender.org/docs/handbook/tooling/clangd/

Pull Request: https://projects.blender.org/blender/blender/pulls/132608
2025-01-07 12:39:13 +01:00
Jacques Lucke
8bec7dce35 Nodes: avoid O(n^2) when looking up interface input indices
Previously, the code was O(n^2) because it iterated over all interface sockets,
and for each it tried to find the corresponding index by iterating over all
inputs again. Now, a `VectorSet` is used to make finding the index `O(1)`. The
new utility function may also be useful elsewhere.

Pull Request: https://projects.blender.org/blender/blender/pulls/132272
2024-12-23 15:01:07 +01:00
Hans Goudey
de8f882817 Cleanup: Use "this" keyword to access class members 2024-12-11 11:47:20 -05:00
Jacques Lucke
4fd49ae9f3 Fix #119341: improve propagating node tree interface settings
Copy the interface socket directly which makes sure that all relevant data is passed on.
The default is still adapted from the current socket value.

There are still places that could be improved that are not covered by this patch yet.
For example creating a group from a Set Position node changes the default Position input.
That could be fixed separately.

I removed one `assert` that did not seem important. It was making sure that an interface
item is only copied within a group, but I don't see a reason for why it should not be possible
to copy an item to a different group.

Pull Request: https://projects.blender.org/blender/blender/pulls/131394
2024-12-05 13:15:51 +01:00
Iliya Katueshenock
7348e670b3 Cleanup: BKE: Use StringRefNull instead of char *
Use StringRefNull for all function arguments and return types.
Not a StringRef but StringRefNull since there is still large
interaction with C api so null-termination usually necessary.

If string is expected to be not only empty but also a null then
optional is used. This change depends on #130935.

Pull Request: https://projects.blender.org/blender/blender/pulls/131204
2024-12-02 19:24:07 +01:00
Jacques Lucke
7dc630069b Nodes: support subpanels in node group interface
Previously, only one level of panels was supported. Now, they can be nested arbitrarily.
Panels still have to come at the bottom though.

The panel color used to be just the node color darkened a bit. Now it uses the
`TH_PANEL_SUB_BACK` theme setting which is also used by panels in other places
in Blender. However, the contrast of that is a bit weaker than what we had in nodes before.
Therefore I increased the contrast a bit.

Pull Request: https://projects.blender.org/blender/blender/pulls/128886
2024-11-26 17:01:14 +01:00
Jacques Lucke
74f266c119 Fix #127855: crash when changing interface socket type with custom sockets
There were multiple issues that popped up when following the reproduction steps
in the report:
* Somehow, `socket.socket_data` was set for a custom socket type. I don't know
  how that happened yet. I added some code to clean it up on file-load.
* `declaration_for_interface_socket` did not work yet when the socket type is
  not registered. Now it just creates a custom socket with the correct idname,
  even if that's not registered yet.
* There was a missing node tree update when changing `bl_socket_idname` of
  interface sockets.

Pull Request: https://projects.blender.org/blender/blender/pulls/128191
2024-09-26 20:41:06 +02:00
Iliya Katueshenock
1b67be14c6 Cleanup: BKE: Nodes: Functions renaming
Use snake style naming for all the kernel nodes functions.
Omit kernel prefix in the names since of the using namespace.
Use full forms of the terms
('iter' -> 'iterator', 'ntree' -> 'node_tree', 'rem' -> 'remove', ...).

Pull Request: https://projects.blender.org/blender/blender/pulls/126416
2024-08-19 20:27:37 +02:00
Campbell Barton
c071030ac3 Cleanup: spelling in comments 2024-08-04 13:45:06 +10:00
Bastien Montagne
8f70a803b5 Nodes Read/Write: Add FIXME comments about usages of 'raw data' BLO API.
`BLO_read_data_address` should basically almost never be used. However,
this code is not trivial to update, and it has an active team working on
it, so for now just tagging the issue there.
2024-07-31 19:52:12 +02:00
Bastien Montagne
80948f43ca Refactor: BLO: Add array size parameter to BLO_read_pointer_array.
For some reason this was the only one of these 'read array' functions
with no such parameter.
2024-07-31 16:55:29 +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
Campbell Barton
9918488bb1 Cleanup: use uppercase tags, following own style guide 2024-05-03 11:33:21 +10: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
Iliya Katueshenock
f8efd4fad0 Fix #120367: Attach to root panel if new parent is null
If pointer to new parent is null, use pointer to root panel of interface.

Pull Request: https://projects.blender.org/blender/blender/pulls/120369
2024-04-08 12:42:34 +02:00
Hans Goudey
e0567eadbd Cleanup: Use FunctionRef for IDProperty iteration callback
Avoid the need for a seaprate user_data argument.
2024-03-26 15:39:39 -04:00
Hans Goudey
efee753e8f Cleanup: Move BKE_idprop.h to C++ 2024-03-26 13:07:04 -04:00
Jacques Lucke
067daec270 Nodes: don't use combined input/output sockets in node tree interface
Those shouldn't really exist at all currently, since we forbid them in 354915cf3c.
Unfortunately, not all cases were removed, and many node trees with such sockets
have been created during the development of 4.1 due to the auto-smooth changes.

I'm not entirely sure if it's still possible to properly remove them now. The commit
above mentions that we might lose links due to changed identifiers. Maybe we're
better off just supporting these inlined sockets while also allowing the "align with
previous socket" functionality.

Either way, not creating more of such node trees for now is reasonable, since we
explicitly disabled that functionality for now.

Pull Request: https://projects.blender.org/blender/blender/pulls/119654
2024-03-20 11:26:07 +01:00
Lukas Tönne
5ad49f4142 Geometry Nodes: Menu Switch Node
This patch adds support for _Menu Switch_ nodes and enum definitions in
node trees more generally. The design is based on the outcome of the
[2022 Nodes Workshop](https://code.blender.org/2022/11/geometry-nodes-workshop-2022/#menu-switch).

The _Menu Switch_ node is an advanced version of the _Switch_ node which
has a customizable **menu input socket** instead of a simple boolean.
The _items_ of this menu are owned by the node itself. Each item has a
name and description and unique identifier that is used internally. A
menu _socket_ represents a concrete value out of the list of items.

To enable selection of an enum value for unconnected sockets the menu is
presented as a dropdown list like built-in enums. When the socket is
connected a shared pointer to the enum definition is propagated along
links and stored in socket default values. This allows node groups to
expose a menu from an internal menu switch as a parameter. The enum
definition is a runtime copy of the enum items in DNA that allows
sharing.

A menu socket can have multiple connections, which can lead to
ambiguity. If two or more different menu source nodes are connected to a
socket it gets marked as _undefined_. Any connection to an undefined
menu socket is invalid as a hint to users that there is a problem. A
warning/error is also shown on nodes with undefined menu sockets.

At runtime the value of a menu socket is the simple integer identifier.
This can also be a field in geometry nodes. The identifier is unique
within each enum definition, and it is persistent even when items are
added, removed, or changed. Changing the name of an item does not affect
the internal identifier, so users can rename enum items without breaking
existing input values. This also persists if, for example, a linked node
group is temporarily unavailable.

Pull Request: https://projects.blender.org/blender/blender/pulls/113445
2024-01-26 12:40:01 +01:00
Bastien Montagne
03c1cc4310 Cleanup: Move BKE_lib_query header to Cpp era. 2024-01-18 12:21:19 +01:00
Jacques Lucke
c954940e76 Fix: remove assert when creating interface socket
We don't actually protect against interface sockets with empty
names elsewhere. This assert was triggered when trying to group
a `Bake` node, because it tried to create an interface socket of
the extend socket. This case is handled by the check below.
2024-01-17 14:27:51 +01:00
Hans Goudey
3e76a1a6c2 Cleanup: Move BKE_lib_id.h to C++ 2024-01-15 12:44:14 -05:00
Jacques Lucke
c29857fffa Fix #113532: geometry nodes is always reevaluated after undo
The issue was that the undo system detected that node trees have been changed
even though they have not. This is because the memory dump of the node tree
changed after unrelated changes. The root issue was that
`bNodeTreeInterface::write` also wrote the struct, and the pointer of the
`bNodeTreeInterface` itself. While this pointer is generally stable, it is not
during file-write, because when IDs are written, a shallow copy is created
first (see `BLO_write_init_id_buffer_from_id`). The temporary buffer for this
shallow copy is allocated on the heap, so its pointer may change over time.

The fix is to simply not write the `bNodeTreeInterface` separately, since it's
already embedded in `bNodeTree`.

Pull Request: https://projects.blender.org/blender/blender/pulls/114322
2023-10-31 13:46:31 +01:00
Lukas Tönne
dfc3f75e77 Fix #113860: Nullptr checks for node socket and panel name pointers
In 3.6 the names of node group sockets were using char arrays, but now
use allocated strings. The RNA system assigns nullptr to such strings
when assigning an empty string through python (UI assignment appears to
always generate a valid string). This creates issues with many STL
functions, in particular assigning nullptr to `std::string` will crash.

We have to check for valid pointers before using them in places that
don't handle nullptrs.

Pull Request: https://projects.blender.org/blender/blender/pulls/113924
2023-10-19 11:48:08 +02:00
Hans Goudey
ecb52140cd Fix #113128: Socket hide value not copied to group input
This needs to be copied explicitly to the interface socket.

Pull Request: https://projects.blender.org/blender/blender/pulls/113286
2023-10-06 00:43:45 +02:00
Lukas Tönne
71732a9600 Fix #113014: Improved sorting to keep node group outputs above inputs
The position validation when manipulating node group items now includes
outputs..inputs order in addition to sockets..panels order. The method
for finding a valid position has been simplified, it's just a single
iteration of insertion sort.

Versioning has been added to ensure files from 4.0 alpha with
potentially unsorted sockets get re-sorted. This uses `std::stable_sort`
so that sockets keep their relative order apart from the input/output
grouping.

Pull Request: https://projects.blender.org/blender/blender/pulls/113060
2023-10-03 12:18:36 +02:00
Hans Goudey
c6380d772c Fix: Debug build error after recent cleanup
Caused by 8954b70d49
2023-09-22 11:22:30 -04:00