Commit Graph

80 Commits

Author SHA1 Message Date
Brecht Van Lommel
aab29c1ba6 Merge branch 'blender-v5.0-release' 2025-10-17 16:42:22 +02:00
Damien Picard
58b8ae1717 UI: Fix a few typos
- "Acion Slot" -> "Action": typo.
- "Specifies the input node used the created zone" -> "by the created
  zone": typo.
- "No reference available {!r}, Update..." -> "update": lower case.
- "uninitialized file-list" -> "Uninitialized": sentence case.

Some issues reported by Alexandr Fatih.

Pull Request: https://projects.blender.org/blender/blender/pulls/148265
2025-10-17 16:13:30 +02:00
Jacques Lucke
1a5daab0d3 Merge branch 'blender-v5.0-release' 2025-10-16 18:37:47 +02:00
quackarooni
ce88d773db Fix: Nodes: bad ui for adding panel toggles
Adding panel toggles in nodegroups have somewhat of a UX antipattern. When
running the operator, it checks for conditions that indicate it should not run,
and if those are hit, it cancels execution and mentions the invalid condition in
the footer bar.

This is not ideal, the user should not have to call the operator to find out
whether it can be called.

Why it got implemented like this is likely a consequence of all interface items
being the same "New Item" operator. Poll functions cannot use operator
properties, so variants of the same operator cannot check for different
conditions for execution.

This is a problem for panel toggles, as they have more restrictions to when they
can be added that don't apply to other interface items.

This patch creates a separate operator for adding panel toggles. This allows the
condition checks to be implemented in the poll function, which enables greying
out the operator buttons and showing on tooltips what condition is invalid.

Pull Request: https://projects.blender.org/blender/blender/pulls/146379
2025-10-16 18:37:22 +02:00
Campbell Barton
7a249222be Cleanup: tweak multi-line parenthesis for Python scripts
Reduce right shift, moving closing parenthesis onto own line
for clarity & reducing diff noise in some cases.

Ref !147857
2025-10-12 03:31:31 +00:00
Damien Picard
c35de6f92d I18n: Translate labels using node UI function from node_add_menu.py
In 2a1a658492, layout functions for nodes were refactored and new
methods were introduced, but this change was not applied to the
translation extraction script.

This commit adds these method names and argument order to Python
extraction: "node_operator", "node_operator_with_outputs",
"simulation_zone", "repeat_zone", "for_each_element_zone",
"closure_zone".

Tooltips specified in a special structure are manually extracted using
`n_()`.

Actual translation is done manually in the UI methods inside NodeMenu,
in order to override the context, which by default would have been
"Operator".

Reported by Ye Gui in #43295.

Pull Request: https://projects.blender.org/blender/blender/pulls/147582
2025-10-09 12:09:25 +02:00
quackarooni
1a6d932fbd Fix: Nodes: Inaccurate placement of framed nodes in swap operators
The swap operators use `Node.location` for location calculations. This expresses
a node's location relative to their parent frames.

This can lead to inaccurate location calculations if nodes have different parent
frames. This was partly addressed by using the custom `temporary_unframe`
context manager. However, that method is sensitive to the order of steps
executed by the operator, making it easy to accidentally let a few location bugs
go through.

This patch fixes the issue by using `Node.location_absolute` which gives the
node's absolute location. This also gets rid of the need for
`temporary_unframe`, and makes the location calculations more straightforward.

Pull Request: https://projects.blender.org/blender/blender/pulls/147424
2025-10-07 12:33:30 +02:00
Damien Picard
6983b97640 I18n: Translate newly-created node group names
Reported by Ye Gui in #43295.
2025-09-29 11:07:03 +02:00
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