Commit Graph

72 Commits

Author SHA1 Message Date
quackarooni
e7cae0b220 Fix: Nodes: Occasional crashing when using swap operators
Calling the swap operators can result in Blender crashing. From my
testing, the behavior is inconsistent, as sometimes a crash is triggered
and other times it isn't. Though notably, they seem involve nodes
already linked to other nodes, or zones.

The crashing stems from the operators trying to access deleted data.
There were two places where this happens that were identified, one
involving removed links and the other involving removed nodes.

Pull Request: https://projects.blender.org/blender/blender/pulls/146909
2025-09-28 19:40:55 +02:00
Campbell Barton
9ebc02fc99 Cleanup: spelling, repeated words (make check_spelling_*) 2025-09-26 22:00:27 +10:00
Campbell Barton
9c5fda87a5 Cleanup: use format specifier, full sentences 2025-09-26 05:10:23 +00:00
Campbell Barton
945590c1d9 Fix: un-escaped strings for node operators/UI
Correct error [0] constructing data paths without escaping.

[0]: 2a1a658492
2025-09-26 14:40:43 +10:00
Campbell Barton
b4fbc0c32d Cleanup: remove f-strings use, use double quotes, quiet pylint warnings 2025-09-26 14:31:05 +10:00
quackarooni
2a1a658492 Nodes: Swap Node Operator
Implement a native method to swap between different node and zone types.

This implementation repurposes the existing menu definitions as base
classes, from which both an "Add" and a "Swap" version would be generated
from. This allows both menus to have the same layout, but use their own
operators for handling the different node/zone types.

In this PR, support for all node editors has been implemented.

Invoking the menu is currently bound to `Shift + S`, same as the old
implementation in Node Wrangler. Since "Swap" is implemented as a
regular menu, features that menus already have such as type-to-search
and adding to Quick Favorites don't require any extra caveats to
consider.

Resolves #133452

Pull Request: https://projects.blender.org/blender/blender/pulls/143997
2025-09-25 16:12:02 +02:00
Habib Gahbiche
ac84e076db Nodes: Deactivate viewer if shortcut exists and viewer is active
Original right click select:
https://blender.community/c/rightclickselect/wRzz/

Pressing 1,2,3,... to activate a viewer with shortcut now toggles that
viewer instead of always activating it. See PR description for examples

The code is generic but the compositor requires one viewer to be active
so only geometry nodes viewers are supported.

Pull Request: https://projects.blender.org/blender/blender/pulls/145509
2025-09-10 15:17:16 +02:00
Jacques Lucke
32c301e3cf Shader Nodes: support repeat zones, closures and bundles
This adds a function that can turn an existing `bNodeTree` into an inlined one.
The new node tree has all node groups, repeat zones, closures and bundles
inlined. So it's just a flat tree that ideally can be consumed easily by render
engines. As part of the process, it also does constant folding.

The goal is to support more advanced features from geometry nodes (repeat zones,
etc.) in shader nodes which the evaluator is more limited because it has to be
able to run on the GPU. Creating an inlined `bNodeTree` is likely the most
direct way to get but may also be limiting in the future. Since this is a fairly
local change, it's likely still worth it to support these features in all render
engines without having to make their evaluators significantly more complex.

Some limitations apply here that do not apply in Geometry Nodes. For example,
the iterations count in a repeat zone has to be a constant after constant
folding.

There is also a `Test Inlining Shader Nodes` operator that creates the inlined
tree and creates a group node for it. This is just for testing purposes.

#145811 will make this functionality available to the Python API as well so that
external renderers can use it too.
2025-09-09 16:15:43 +02:00
Damien Picard
3611b8a592 Fix: Operator cheatsheet error due to property items not available
When collecting operators for the operator cheatsheet (Help menu),
`node.interface_item_new` gave an error because its property
`active_item` could not gather items. This happened because `context`
was unavailable to its `get_items` method at that time.

This commit refactors the method to return early in case the context is not
found.

Pull Request: https://projects.blender.org/blender/blender/pulls/145930
2025-09-09 12:05:20 +02:00
Habib Gahbiche
588052f97f Fix: viewer shortcut description mentions compositor only
Pull Request: https://projects.blender.org/blender/blender/pulls/145513
2025-09-02 16:19:30 +02:00
Maxime-Cots
7a01f736a5 Nodes: Make context path breadcrumbs interactive
Make it possible to navigate in/out node groups through the breacrumbs
context path overlay.

See PR for details and screenshots.

Pull Request: https://projects.blender.org/blender/blender/pulls/141292
2025-08-20 17:53:34 +02:00
Jacques Lucke
252b983c0c Geometry Nodes: change idnames of experimental bundle and closure nodes
This removes the "Geometry" part from their name because we want to use them in
other node tree types too (see #141936).

Usually, we don't change idnames because they are the primary identifier of
nodes and is expected to stay the same. Since they are generally not shown to
users (just Python developers), it's also not urgent to change them. However, in
this specific case we have the opportunity to update the idname before the node
becomes an official feature, so it's not as bad to change it.

This patch has full backward compatibility, but no forward compatibility (for
files that used the experimental feature).

Pull Request: https://projects.blender.org/blender/blender/pulls/143823
2025-08-02 10:17:39 +02:00
илья _
e15537c049 Nodes: clamp new node starting position to region bounds
Simular to #141838.

Trivial clip of top left node corner to area of editor +-10% at all sides.

Pull Request: https://projects.blender.org/blender/blender/pulls/142479
2025-07-24 07:43:48 +02:00
Campbell Barton
19ee3932c3 Fix #141948: No error on arbitrary assignments to PropertyGroup
Declare `__slots__` to prevent arbitrary assignment.
2025-07-16 17:44:06 +10:00
quackarooni
5bb21bfa07 Fix #141610: Nodes: Active selection points to internal toggle socket after running "Remove Item"
Panel toggles are implemented by having a boolean socket with
`is_panel_toggle` set to `True`, as the first item in that panel's children.
These sockets are then hidden from the user, as the checkbox gets drawn
in the panel's UI.

In specific circumstances described in the bug report, the active selection
can sometimes land on these sockets. Leading to the user being able to
directly access these internal sockets.

The changes in the patch make the "Remove Item" operator check if
the resulting selection lands in a toggle socket, and move the selection
to that toggle's parent panel if that is the case.

Pull Request: https://projects.blender.org/blender/blender/pulls/141859
2025-07-16 07:11:14 +02:00
Damien Picard
0bd797a433 I18n: Allow translation of a few reports using formatting
Reports whose message uses string formatting needs to be first
translated, then formatted. Also in one instance, use rpt_() instead
of iface_().
2025-06-16 12:39:02 +02:00
Jacques Lucke
7b291de3c3 Fix #140193: error when deleting panel with subpanel as first item 2025-06-11 14:26:00 +02:00
Jacques Lucke
39a3b44a72 Nodes: support searching for outputs of various input nodes directly
Previously, one had to search for the name of an input node (Geometry, Light
Path, etc.) instead of for the actual desired values.

This patch makes it possible to search for the output names of various input
nodes directly. All other outputs of the input node are hidden automatically.
This was partially support for the Scene Time before.

Supported nodes:
* Compositor: Scene Time
* Geometry Nodes: Camera Info, Mouse Position, Scene Time, Viewport Transform
* Shader Nodes: Camera Data, Curves Info, Geometry, Volume Info, Light Path,
  Object Info, Particle Info

Right now, the output names are hardcoded in the menu. We don't have a great way
to access those without an actual node instance currently. For that we'll need
to make the node declarations available in Python, which is a good project but
out of scope for this this feature. It also does not seem too bad to have more
explicit control over what's shown in the search.

Pull Request: https://projects.blender.org/blender/blender/pulls/139477
2025-05-28 05:41:37 +02:00
Jacques Lucke
9e0e94e6e2 Nodes: simplify adding new empty node group
The main way to create a new node group right now is to select some nodes and
then press ctrl+G. This works well for the common case when one already has some
nodes to group. However, there is no good alternative currently for when one
wants to create a new group from scratch. A common workaround currently is to
add some dummy node, then press ctrl+G and then to delete the dummy node in the
group again. Obviously, we can do better than that.

This patch adds a `New Group` entry in the menu. It's available in geometry,
compositing and shading Nodes. The operator adds a new node group called
"NodeGroup" (the same default name we use for ctrl+G currently). Then it adds a
new group node and assigns the new group to it. The group itself does not have
any inputs or outputs by default because any such socket would just be a guess
that's likely wrong and more annoying than useful.

A nice side benefit of adding this operator is that the Group menu is not empty
in shading and compositing nodes initially which always looked a bit off.

Pull Request: https://projects.blender.org/blender/blender/pulls/138430
2025-05-08 10:17:56 +02:00
Pratik Borhade
ac9a7ca0b8 Fix: Remove header socket along with panel
If panel has boolean header socket, deleting this panel won't remove
its boolean socket. Now Handled this case in `NODE_OT_interface_item_remove`.

Pull Request: https://projects.blender.org/blender/blender/pulls/135430
2025-04-16 12:09:40 +02:00
Hans Goudey
8ade553987 Cleanup: Formatting 2025-04-15 10:05:27 -04:00
quackarooni
d3639828f8 Fix: Nodes: "Make Panel Toggle" can turn Boolean output sockets into panel toggles
The "Make Panel Toggle" operator does not check if active item is an input socket,
leading to a situation where it can be called on Boolean output sockets.

Doing this creates weird behavior where the panel and associated
operators believe it has a toggle, but is not reflected in the UI drawing.

Other weird behaviors include being able to rearrange output sockets
and apply the operator again to another output socket.

This patch adds a check in the operator's poll function to prevent it
from being called on output sockets.

Pull Request: https://projects.blender.org/blender/blender/pulls/137526
2025-04-15 15:26:44 +02:00
Jacques Lucke
8ec9c62d3e Geometry Nodes: add Closures and Bundles behind experimental feature flag
This implements bundles and closures which are described in more detail in this
blog post: https://code.blender.org/2024/11/geometry-nodes-workshop-october-2024/

tl;dr:
* Bundles are containers that allow storing multiple socket values in a single
  value. Each value in the bundle is identified by a name. Bundles can be
  nested.
* Closures are functions that are created with the Closure Zone and can be
  evaluated with the Evaluate Closure node.

To use the patch, the `Bundle and Closure Nodes` experimental feature has to be
enabled. This is necessary, because these features are not fully done yet and
still need iterations to improve the workflow before they can be officially
released. These iterations are easier to do in `main` than in a separate branch
though. That's because this patch is quite large and somewhat prone to merge
conflicts. Also other work we want to do, depends on this.

This adds the following new nodes:
* Combine Bundle: can pack multiple values into one.
* Separate Bundle: extracts values from a bundle.
* Closure Zone: outputs a closure zone for use in the `Evaluate Closure` node.
* Evaluate Closure: evaluates the passed in closure.

Things that will be added soon after this lands:
* Fields in bundles and closures. The way this is done changes with #134811, so
  I rather implement this once both are in `main`.
* UI features for keeping sockets in sync (right now there are warnings only).

One bigger issue is the limited support for lazyness. For example, all inputs of
a Combine Bundle node will be evaluated, even if they are not all needed. The
same is true for all captured values of a closure. This is a deeper limitation
that needs to be resolved at some point. This will likely be done after an
initial version of this patch is done.

Pull Request: https://projects.blender.org/blender/blender/pulls/128340
2025-04-03 15:44:06 +02:00
Omar Emara
7c0c31efb0 Nodes: Enable panel toggles in the Compositor
This patch enables panel toggles in the compositor since it now supports
boolean sockets. This essentially reverts c3957f432a.
2025-03-24 10:20:39 +02:00
Guillermo Venegas
61783caa7f UI: Rename Add File Node operator to Add Image as Node
`Add File Node` name is too generic. This operator only handles
opening images and movies as nodes, not script files or other kind of files as nodes.

Pull Request: https://projects.blender.org/blender/blender/pulls/122561
2025-03-21 22:49:13 +01:00
Campbell Barton
bd2c0f2b49 Cleanup: remove unused variable 2025-03-21 15:07:07 +11:00
Habib Gahbiche
d8d09cdadb Geometry Nodes: shortcuts for viewer nodes
Implement shortcuts for viewer nodes. Viewer nodes are now activated using the operator `bpy.ops.node.activate_viewer()` instead of activating the viewer by setting the node to active.

This also unifies the behavior with viewer shortcuts in the compositor (see attachment in the original PR).

Pull Request: https://projects.blender.org/blender/blender/pulls/134555
2025-03-14 11:26:57 +01:00
Campbell Barton
5558491bf1 Merge branch 'blender-v4.4-release' 2025-03-06 15:54:01 +11:00
Campbell Barton
1635595f94 Fix exceptions in node operator poll functions 2025-03-06 15:24:52 +11:00
Campbell Barton
4177b75e7a Cleanup: quiet warnings from ruff, use static sets 2025-03-04 16:02:55 +11:00
Jacques Lucke
c3957f432a Fix: Nodes: only expose panel toggles in geometry and shader nodes
The compositor does not support boolean sockets currently.
2025-02-28 19:23:44 +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
Campbell Barton
ec40ad0b3f Cleanup: use str.format to format strings in Python 2025-01-31 13:22:10 +11:00
Campbell Barton
20c08147b3 Cleanup: resolve warnings from pylint
- `self` -> `cls` for class methods.
- quiet long line & unused variable warnings.
2025-01-31 13:22:04 +11:00
Campbell Barton
c86d3b429e Cleanup: spelling in comments 2025-01-30 14:18:40 +11:00
Habib Gahbiche
4e544a89d6 Fix #133780: Menu search Python error in terminal
`poll()`  method must check properly for space type.

Pull Request: https://projects.blender.org/blender/blender/pulls/133781
2025-01-30 00:28:22 +01:00
Habib Gahbiche
b51c560f6e Compositor: Implement shortcuts for Viewer nodes
Artists often want to quickly switch back and forth between two or more nodes while compositing.

This patch implements two operators `NODE_OT_viewer_shortcut_set` and `NODE_OT_viewer_shortcut_get` that allow users to map a viewer node to a shortcut. For example, pressing `cltr+1` while a node is selected, assigns that node to the shortcut `1`, creates a viewer node if it has none attached and sets that viewer node to active. Pressing `1` will set the active node with shortcut `1` to active.

Shortcuts are saved in DNA to preserve them after saving/loading blend files.

Limitations:
- Only compositor node tree is supported, because shading editor has no viewer node and geometry nodes viewer works differently.

Pull Request: https://projects.blender.org/blender/blender/pulls/123641
2025-01-29 18:35:26 +01:00
Campbell Barton
6ab0efad41 Cleanup: defer import until needed 2024-10-30 15:16:25 +11:00
Campbell Barton
c3b067dc80 Cleanup: single/double quote use in scripts 2024-10-16 14:45:08 +11:00
Jacques Lucke
6e5e01e630 Geometry Nodes: new For Each Geometry Element zone
This adds a new type of zone to Geometry Nodes that allows executing some nodes
for each element in a geometry.

## Features

* The `Selection` input allows iterating over a subset of elements on the set
  domain.
* Fields passed into the input node are available as single values inside of the
  zone.
* The input geometry can be split up into separate (completely independent)
  geometries for each element (on all domains except face corner).
* New attributes can be created on the input geometry by outputting a single
  value from each iteration.
* New geometries can be generated in each iteration.
    * All of these geometries are joined to form the final output.
    * Attributes from the input geometry are propagated to the output
      geometries.

## Evaluation

The evaluation strategy is similar to the one used for repeat zones. Namely, it
dynamically builds a `lazy_function::Graph` once it knows how many iterations
are necessary. It contains a separate node for each iteration. The inputs for
each iteration are hardcoded into the graph. The outputs of each iteration a
passed to a separate lazy-function that reduces all the values down to the final
outputs. This final output can have a huge number of inputs and that is not
ideal for multi-threading yet, but that can still be improved in the future.

## Performance

There is a non-neglilible amount of overhead for each iteration. The overhead is
way larger than the per-element overhead when just doing field evaluation.
Therefore, normal field evaluation should be preferred when possible. That can
partially still be optimized if there is only some number crunching going on in
the zone but that optimization is not implemented yet.

However, processing many small geometries (e.g. each hair of a character
separately) will likely **always be slower** than working on fewer larger
geoemtries. The additional flexibility you get by processing each element
separately comes at the cost that Blender can't optimize the operation as well.
For node groups that need to handle lots of geometry elements, we recommend
trying to design the node setup so that iteration over tiny sub-geometries is
not required.

An opposite point is true as well though. It can be faster to process more
medium sized geometries in parallel than fewer very large geometries because of
more multi-threading opportunities. The exact threshold between tiny, medium and
large geometries depends on a lot of factors though.

Overall, this initial version of the new zone does not implement all
optimization opportunities yet, but the points mentioned above will still hold
true later.

Pull Request: https://projects.blender.org/blender/blender/pulls/127331
2024-09-24 11:52:02 +02:00
Campbell Barton
dc74a98b9e Cleanup: remove unused imports 2024-07-23 15:58:21 +10:00
Brecht Van Lommel
a926f5b67d Refactor: Replace ID_IS_LINKED by !ID_IS_EDITABLE
Add new ID_IS_EDITABLE macro that checks if the ID can be edited in the
user interface. Replace usage of ID_IS_LINKED where it is used with this
meaning.

Also add a corresponding ID.is_editable property for Python.

This prepares for the ability to edit some linked datablocks for brush
assets.

Pull Request: https://projects.blender.org/blender/blender/pulls/121838
2024-05-16 14:53:09 +02:00
Jacques Lucke
6176e66636 Nodes: add node group description
This allows node groups to have a description that is shown in the add menu
or when hovering over the node header.

This new description is stored in `bNodeTree.description`. Unfortunately, it
conflicts a bit with `ID.asset_data.description`. The difference is that the latter
only exists for assets. However, it makes sense for node groups to have
descriptions even if they are not assets (just like `static` functions in C++ should
also be able to have comments). In some cases, node groups are also generated
by addons for a specific purpose. Those should still have a description without
being reusable to make it easier to understand for users.

The solution here is to use the asset description if the node group is an asset,
and to use `bNodeTree.description` otherwise. The description is synced
automatically when marking or clearing assets.

A side benefit of this solution is that appended node group assets can keep their
description, which is currently always lost.

Pull Request: https://projects.blender.org/blender/blender/pulls/121334
2024-05-08 11:25:00 +02:00
Jacques Lucke
176c6ef329 Geometry Nodes: unify menu switch with other nodes with dynamic sockets
This changes the menu switch socket to use the socket-items system
(`NOD_socket_items.hh`) that is already used by the simulation zone, repeat
zone, bake node and index switch node. By using this system, the per-node
boilerplate can be removed significantly. This is especially important as we
plan to have dynamic socket amounts in more nodes in the future.

There are some user visible changes which make the node more consistent with
others:
* Move the menu items list into the properties panel as in 0c585a1b8a.
* Add an extend socket.
* Duplicating a menu item keeps the name of the old one.

There is also a (backward compatible) change in the Python API: It's now
possible to directly access `node.enum_items` and `node.active_index` instead of
having to use `node.enum_definition.enum_items`. This is consistent with the
other nodes. For backward compatibility, `node.enum_definition` still exists,
but simply returns the node itself.

Many API functions from `NodeEnumDefinition` like
`NodeEnumDefinition::remove_item` have been removed. Those are not used anymore
and are unnecessary boilerplate. If ever necessary, they can be implemented back
in terms of the socket-items system.

The socket-items system had to be extended a little bit to support the case for
the menu switch node where each socket item has a name but no type. Previously,
there was the case without name and type in the index switch node, and the case
with both in the bake node and zones. The system was trivial to extend to this
case.

Pull Request: https://projects.blender.org/blender/blender/pulls/121234
2024-04-30 10:19:32 +02:00
Campbell Barton
0c4d3754f1 Cleanup: replace {!s} with {:s} when used with strings
When passing strings to str.format(..) use `{:s}` format specifier
which only takes strings and wont run `.__str__()` on non-strings.

While `{!s}` is an equivalent to `%s`, for the most part `%s` was
used for strings, so using `{:s}` is clearer and more specific.
2024-04-27 16:02:37 +10:00
Campbell Barton
0e3b594edb Refactor: scripts under scripts/startup/ to use str.format
Part of modernizing scripts in Blender, where the previous convention
was to use percentage formatting which has become the "old" way to
format strings in Python.

See proposal for details #120453.

Ref !120552
2024-04-27 16:02:36 +10: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
Damien Picard
c306677119 I18n: extract and disambiguate a few messages
Extract
- Statuses for the external text editor
- Newly created enum node item
- Newly created plane track data
- Newly created custom orientation data
- Operator names in drag and drop menu (need to use operator's
  translation context)
- GN attribute statistic node inputs

Disambiguate
- Single-letter colors: A and B can mean Alpha and Blue, or simply A
  and B as in two operands in an operation
- Dissolve: issue reported by Tamar Mebonia in #43295
- Translate in the User Preferences. This introduces a new
  BLT_I18NCONTEXT_EDITOR_PREFERENCES ("Preferences") translation
  context
- Planar (reported by deathblood)
  This one is incomplete, because there is currently no way to
  disambiguate presets or GN fields. I don't see how either could be
  achieved cleanly.
  The former would need to define the context inside the preset and
  evaluate the file prior to showing it in the presets menu, which
  sound bad.
  The latter would need to introduce an additional string inside
  `FieldInput`s, which would be controversial given how little it
  would be used.

Remove
- Unused translation `iface_("%s")` in toolbar
- Remove obsolete N_() tags in a few node descriptions.

Pull Request: https://projects.blender.org/blender/blender/pulls/119065
2024-04-15 12:02:17 +02:00
Campbell Barton
d07d6f1c10 Cleanup: un-wrap lines that fit within 120 width for Python scripts 2024-03-15 10:04:03 +11: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