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
Previous commit dc6c334c4d changed the API used to create links
between nodes, but the call for the CopySettings operator was not
updated properly.
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"
Chain conditions with boolean operators instead of setting a default
False variable and nested `if`s.
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.
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.
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.
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.
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.
- Remove unused variables.
- Exit early.
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.
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.
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.
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.
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.
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.
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.
The Attributes menu generated by node wrangler for the shader editor included internal attributes not meant for use in shaders.

Pull Request: #105084
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.