Node Wrangler: LTS: backport many bugfixes from main #105169

Merged
Damien Picard merged 7 commits from pioverfour/blender-addons:dp_nw_3.6 into blender-v3.6-release 2024-02-21 18:57:14 +01:00
Member

This PR includes many bug fixes to Node Wrangler done over the past few months. Some of these fixes relied on previous refactors, so they are included as well.

Main areas affected are the Preview and Add Reroute operators.


This was discussed with @PratikPB2123 in #105095, and a fix for that issue is included as well.

This PR includes many bug fixes to Node Wrangler done over the past few months. Some of these fixes relied on previous refactors, so they are included as well. Main areas affected are the Preview and Add Reroute operators. ----- This was discussed with @PratikPB2123 in #105095, and a fix for that issue is included as well.
Damien Picard added 18 commits 2024-02-08 18:45:22 +01:00
7274a3eabe Fix: Node Wrangler: wrong API in CopySettings operator
Previous commit dc6c334c4d changed the API used to create links
between nodes, but the call for the CopySettings operator was not
updated properly.
0e0844499f Refactor: Node Wrangler: PreviewNode operator
This commit refactors the PreviewNode operator so that code is
deduplicated between the Geometry Nodes and the shader branches.

- The link collected in `make_links` is redundant as it would have
  been created later in the function.
- Remove intermediate variable `node_socket`.
- Extract `get_output_index()` and `create_links()` to methods to
  avoid duplication in `invoke()`
- Return `{'CANCELLED'}` instead of `{'FINISHED'}` when there was no
  change.
- Exit early when possible.
- Use `if ... is None:` instead of `if ...:` when applicable.
- Remove bits of unused code.
- Tweak comments and convert them to docstrings when extracted to a
  function.
- Convert methods to `staticmethod`s or `classmethod`s when possible.

Removes a warning when previewing inside a group:
"Sockets do not belong to the same node tree"
bac0dea7ae Refactor: Node Wrangler: poll methods
Chain conditions with boolean operators instead of setting a default
False variable and nested `if`s.
7de11727b4 Node Wrangler: make tree type check more granular in operator polls
Currently, all Node Wrangler operators call `nw_check()` as part of
their poll method. Among other things, this function ensures that
operators can only be run on built-in node types. But many useful NW
operators work as well on custom Python nodes.

This commit replaces this type check with a more specific
`nw_check_space_type()` function, with appropriate checks where needed
in individual polls. This function also sets the poll message to
report why an operator cannot be called.
f4d395decf Fix #100973: Node Wrangler: Previewing node if hierarchy not active
Node Wrangler's preview_node operator can link the active node to the
output node. If the current node tree is a node group inside the base
tree, it can go up the hierarchy to connect until reaching the output
node.

Until now it used a recursive function to go through each active node
from the base tree. If only a single node editor is open, the user can
only open a node group by activating it. But otherwise, they can
select another node at a lower level in the node group hierachy and
the recursion breaks.

This commit changes the operator to use instead the
`SpaceNodeEditor.path`, which gets each node tree in the hierarchy.
This way, we no longer depend on any node in the group hierarchy being
active or not.
31a4b1a1d5 Fix #100895: Node Wrangler not working properly inside Groups
The logic getting the next available socket for the active node when
trying to preview several sockets in turn, was only ever implemented
for materials and not for geometry nodes.
99278d6b05 Fix: Node Wrangler: error previewing input node with virtual socket
When searching for the socket to preview, we need to consider the case
where there is one socket available, but we cannot preview it, such as
with group input nodes' virtual socket.

The check was already there for Geometry Nodes, and this commit adds
it for shading nodes.
b5b7dd9e34 Node Wrangler: make users of GN node groups independent for viewer
A GN node group may be used by multiple modifiers. If multiple nodes
inside a nested node group are viewed by different modifiers, the
other users would get disconnected because the group output was
recreated.

Instead, check for other users of this group and create a new socket
if needed. This was already the behavior for Shaders.
b654e24050 Refactor: Node Wrangler: NWAddReroutes operator
- Remove unused variables.
- Exit early.
e281baeb1a Node Wrangler: do not add reroutes to unavailable outputs
This avoids unconnected reroutes in some nodes such as the Shader
Editor's Mix node. This node has multiple modes, and one output for
each mode, but only one is shown at a time. The others are unavailable
and should be ignored.
e7138d6699 Node Wrangler: select only newly-created nodes when adding reroutes
Selection was not always coherent after adding reroutes, such as with
hidden nodes.

This also allows restoring selection and cancelling the operator if no
change was made.
9f68635acf Fix: Node Wrangler: new reroute locations on hidden nodes
When a node was hidden, the NWAddReroutes operator used a hack to
calculate its width. This was broken since at least 2.80, and not
really needed AFAICT.

Replace this hack with the width directly read from the node.
280867f827 Fix: Node Wrangler: new reroutes offset when output hidden
Depending on option, some outputs would be counted in the offset of
the new reroutes, even though they were hidden and no reroute was
created. This resulted in a misalignment.

Reroutes are now offset according to the actual spacing of displayed
outputs.
e6070989ed Node Wrangler: add more specific poll methods
Since it is useful to set a poll message to tell the user why an
operator cannot be called, decompose poll conditions into basic
functions and make every operator use them.

- Make the basic nw_check report issues.
- Add functions to check that:
  - the node tree is not empty,
  - a node is active,
  - a specified number of nodes are selected,
  - the active node is of a specific type,
  - it has visible outputs,
  - there is a viewer image.
- These functions report the issue to the poll message otherwise.
- Go through operators and add or update poll methods using those
  various functions.
- In a few operators, remove obsolete error reports that are now
  caught at the poll stage.

Fixes a few issues:
- PreviewNode would not work immediately when the active node was a
  material or world output.
- ReloadImages needed an active node.
0c44af5635 Fix #104991: Node Wrangler Merge Nodes shadows other keymaps (Ctrl+,)
Node Wrangler's Merge Nodes operator uses many shortcuts to merge
inputs in different ways. One of those shortcuts is Ctrl + , (comma)
which was not used by default until Blender 4.0. In this version it
was affected the Open Preferences Operator, resulting in a conflict.

In many cases, the operator will have no action, such as when no node
tree is active, or when no node is selected. In those cases, the
operator can simply return {'PASS_THROUGH'} and let the shortcut be
handled by another operator.

A cleaner solution to this issue would be to refactor the operator so
that the list of nodes to act on is gathered in the poll() method, and
not call the operator at all if there is nothing to do, but this
refactor would require deeper changes.
abc910a7fb Fix #104941: Node Wrangler cannot use both bump and normal
Currently, if both bump and normal maps are selected in Principled
Setup, only one of them will be used. But they can both be used in a
PBR setup by plugging the normal output to the bump input.

See for instance Brecht's answer at
https://blender.stackexchange.com/a/16447.

This commit separates setup of bump and normal so they can both be
used at the same time.
6636ee5856 Node Wrangler: skip internal attributes while populating menu
The Attributes menu generated by node wrangler for the shader editor included internal attributes not meant for use in shaders.

Pull Request: #105084
07ed2593ad Node Wrangler: bump version
This version is specific to Blender 3.6 LTS. Since NW only uses major
and minor version numbers, adding a bugfix version will not collide
with main (4.0+).
Member
@lichtwerk ^
Member

Please include this in #109399 so it is not forgotten

Please include this in #109399 so it is not forgotten
Member

I tried to check with others if such larger refactors are fine for LTS, but havent recieved feedback yet...

I tried to check with others if such larger refactors are fine for LTS, but havent recieved feedback yet...
Author
Member

I tried to check with others if such larger refactors are fine for LTS, but havent recieved feedback yet...

I’d understand if they weren’t honestly, especially since I don’t know how to write tests for interactive tools. If the refactors are unacceptable, I could maybe still extract a few easy fixes out of this, but I won’t rewrite each commit that relies on the refactors.
Thanks for considering it anyway :)

> I tried to check with others if such larger refactors are fine for LTS, but havent recieved feedback yet... I’d understand if they weren’t honestly, especially since I don’t know how to write tests for interactive tools. If the refactors are unacceptable, I could maybe still extract a few easy fixes out of this, but I won’t rewrite each commit that relies on the refactors. Thanks for considering it anyway :)

I think this is beyond the types of bugfixes we should backport. It's too hard to review this and conclude with some certainty that it won't introduce new bugs.

I think this is beyond the types of bugfixes we should backport. It's too hard to review this and conclude with some certainty that it won't introduce new bugs.
Damien Picard force-pushed dp_nw_3.6 from 07ed2593ad to f42344c798 2024-02-16 18:43:33 +01:00 Compare
Author
Member

That’s understandable. I removed the more involved commits, and will keep them available in my personal fork.

That’s understandable. I removed the more involved commits, and will keep them available in [my personal fork](https://projects.blender.org/pioverfour/blender-addons/src/branch/blender-v3.6-release).
Brecht Van Lommel approved these changes 2024-02-19 22:41:09 +01:00
Author
Member

Just to be clear, am I expected to merge this myself or must this be handled by @lichtwerk as part of LTS maintenance?

Just to be clear, am I expected to merge this myself or must this be handled by @lichtwerk as part of LTS maintenance?

You can merge it yourself.

You can merge it yourself.
Damien Picard merged commit 6f58d34eb1 into blender-v3.6-release 2024-02-21 18:57:14 +01:00
Damien Picard deleted branch dp_nw_3.6 2024-02-21 18:57:15 +01:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#105169
No description provided.