Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
hkunz opened this issue Mar 9, 2024 · 4 comments · Fixed by #99
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@hkunz
Copy link

hkunz commented Mar 9, 2024

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
Copy link
Author

hkunz commented Mar 9, 2024

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

@hkunz
Copy link
Author

hkunz commented Mar 10, 2024

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

@scurest
Copy link

scurest commented Mar 10, 2024

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).

@BrendanParmer BrendanParmer added this to the v3.1 milestone Mar 16, 2024
@BrendanParmer
Copy link
Owner

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 BrendanParmer linked a pull request Mar 17, 2024 that will close this issue
@BrendanParmer BrendanParmer self-assigned this Mar 17, 2024
@BrendanParmer BrendanParmer added the enhancement New feature or request label Mar 17, 2024
@BrendanParmer BrendanParmer mentioned this issue Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants