carson-katri / geometry-script

A scripting API for Blender's Geometry Nodes
https://carson-katri.github.io/geometry-script/
GNU General Public License v3.0
262 stars 26 forks source link

Convert existing node trees to Geometry Script #8

Open BradyAJohnston opened 1 year ago

BradyAJohnston commented 1 year ago

Hi mate!

I don't suppose you've got functionality for going the other direction, converting nodes to code? This would save me a lot of time for not having to rebuild all of the node trees in code form manually.

I've created and maintain a project that relies on a bunch of pre-built geometry nodes groups (https://github.com/BradyAJohnston/MolecularNodes) which I am looking to convert to actual code (geometry-script) so that it can be version-controlled better than the currently opaque .blend file that they live in.

Any advice? cheers for the great project, which I will definitely be utilising in the future!

carson-katri commented 1 year ago

This should definitely be possible, I'll look into it. Your use case is very interesting, looking forward to seeing some geometry script in there!

BradyAJohnston commented 1 year ago

I gave a talk at BCON last year on the use case if you want to hear me talk more about it: https://www.youtube.com/watch?v=adhTmwYwOiA

I'll hold off on converting anything immediately to see if there is an easy solution, but otherwise I'll go through and start converting them manually probably in like a month or so when I've got some more time to dedicate to it. I also personally find that prototyping functions manually inside of Blender is faster, to then be able to quickly save it out as code for git to read would be great.

carson-katri commented 1 year ago

I have a prototype for this implemented in #13. Let me know if you have any problems converting more complex node trees.

BradyAJohnston commented 1 year ago

Ooh very exciting, thanks for the quick turn around. I'll give it a test run and try it out!

tbscode commented 1 year ago

I've been playing around with geometry script for some time now, and I love it! This would be a killer feature for existing geometry node projects, I see that there is already a draft implemented.

Is this still in development? Can I try this somewhere?

carson-katri commented 1 year ago

@tbscode If you go to this page (or just select the nodes-to-script branch), you should be able to download the addon ZIP. Let me know any issues you run into when converting.

tbscode commented 1 year ago

Thanks, jup using this link I could download the current build: https://github.com/carson-katri/geometry-script/archive/refs/heads/nodes-to-script.zip

Though I think I still need some missing commits for the blender 3.5 update ( I'm on 3.6 & linux ). Currently I'm just getting:

*some weird lib error* ``` Read prefs: "/home/tim/.config/blender/3.6/config/userpref.blend" Traceback (most recent call last): File "/home/tim/Data/local/programms/blender-3.6.2-linux-x64/3.6/scripts/modules/addon_utils.py", line 333, in enable mod = __import__(module_name) File "/home/tim/.config/blender/3.6/scripts/addons/geometry-script-nodes_to_script/__init__.py", line 22, in from .api.tree import * File "/home/tim/.config/blender/3.6/scripts/addons/geometry-script-nodes_to_script/api/tree.py", line 9, in from .node_mapper import * File "/home/tim/.config/blender/3.6/scripts/addons/geometry-script-nodes_to_script/api/node_mapper.py", line 124, in category.draw(CategoryStub(), None) File "/home/tim/Data/local/programms/blender-3.6.2-linux-x64/3.6/scripts/startup/bl_ui/node_add_menu_geometry.py", line 459, in draw if context.preferences.experimental.use_new_volume_nodes: AttributeError: 'NoneType' object has no attribute 'preferences' ```

I suppose just cloning this repo to $HOME/.config/blender/3.6/scripts/addons/* should also work, so I'll try merging this locally and test it then.

tbscode commented 1 year ago

Yeah got it to work. Seems to work generally pretty well, so far I saw one issue. The new Simulation nodes output doesn't seem to be correctly serialized:

paired_output=<bpy_struct, GeometryNodeSimulationOutput("Simulation Output") at 0x7fb804f59988>

Should I report my findings somewhere else, as separate issues?

WenbinTan commented 10 months ago

i think that function (Convert existing node trees to Geometry Script) is useful, When i have an idea, i usually use node trees to validate it. if it work, then i will convert it to python code.
So I'm also looking forward to this feature too