NodeToPython icon indicating copy to clipboard operation
NodeToPython copied to clipboard

Blender 4.0 generated setup not behaving same as original setup despite being identical setups

Open hkunz opened this issue 1 year ago • 4 comments

I'm not sure if this is a bug in Blender 4.0 or a bug from this software. Please can you confirm? I have an original GN setup in this file which voxelizes a mesh. Notice how this works correctly with colors correctly positioned. But then when I use this tool to generate the equivalent python code and then open a new Blender 4.0 file and execute it, the new setup, despite identical to the original, does not reproduce the correct output as seen in this blend file. Please can you confirm and let me know if this is a bug for the Blender development team? Or perhaps there is an incorrect python usage in the script causing this anomaly?

image

It should have looked like this:

image

hkunz avatar Mar 09 '24 01:03 hkunz

its probably a blender bug https://projects.blender.org/blender/blender/issues/119258 can u confirm?

hkunz avatar Mar 09 '24 21:03 hkunz

I have confirmed there is a bug in NodeToPython that it interchanges the noodles going into Join Geometry node causing the problem described in this thread. The generated python script interchanges the noodles as demonstrated below. There is a critical difference especially when dealing with objects having different materials.

image

hkunz avatar Mar 10 '24 06:03 hkunz

Blender 4.1 just got a Python API for retrieving the order of multi-input links last week, see https://projects.blender.org/blender/blender/pulls/118987.

So I believe this will fix it, but only for Blender versions that have that new API

diff --git a/ntp_operator.py b/ntp_operator.py
index da2e642..6b8ee08 100644
--- a/ntp_operator.py
+++ b/ntp_operator.py
@@ -1104,6 +1104,9 @@ class NTP_Operator(Operator):
         if links:
             self._write(f"#initialize {nt_var} links")
 
+        if links and hasattr(links[0], 'multi_input_sort_id'):
+            links = sorted(links, key=lambda link: link.multi_input_sort_id)
+
         for link in links:
             in_node_var = self._node_vars[link.from_node]
             input_socket = link.from_socket

Note that when doing links.new, links are created from the bottom up (earlier created links have lower multi_input_sort_ids).

scurest avatar Mar 10 '24 07:03 scurest

Thanks for the report and investigation everyone, I'll incorporate the change in NTP 3.1. Blender 4.1 or higher will be required to generate the link ordering automatically. If generating a node tree in earlier versions, you'll need to reorder the links manually unfortunately

BrendanParmer avatar Mar 16 '24 23:03 BrendanParmer