Coder Social home page Coder Social logo

brendanparmer / nodetopython Goto Github PK

View Code? Open in Web Editor NEW
223.0 223.0 21.0 4.81 MB

Convert Blender node groups to a Python add-on

License: MIT License

Python 100.00%
add-on art blender blender-addon blender-python blender-script geometry-nodes geonodes material node-editor node-to-python procedural procedural-art python

nodetopython's People

Contributors

brendanparmer avatar carls3d avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

nodetopython's Issues

Better UI

Current placement doesn't make much sense. Additionally, a user should just be able to select the node group from a list of options instead of having to type out its full name

Node name not included in script

The Name attribute of nodes is not replicated when exported as a script. It is used to name the variable in the resulting script, but the attribute isn't initialized with the name.
This is what I get from a Value node currently:

#node Foo
foo = paint_visualizer_002.nodes.new("ShaderNodeValue")
foo.label = "FooLabel"

But would be great if it also populated name, like this:

#node Foo
foo = paint_visualizer_002.nodes.new("ShaderNodeValue")
foo.name = "Foo"
foo.label = "FooLabel"

Stop creating new node group if exist

file.write((f"{inner}if {str_to_py_str(nt_name)} in bpy.data.node_groups:\n"))
file.write((f"{inner}\treturn\n"))
file.write((f"{inner}else:\n"))
file.write((f"{inner}\t{nt_var}"
        f"= bpy.data.node_groups.new("
        f"type = \'ShaderNodeTree\', "
        f"name = {str_to_py_str(nt_name)})\n"))
file.write("\n")

Something like this I think.

Does this need a custom node?

Traceback (most recent call last):
File "/Applications/Blender.app/Contents/Resources/3.3/scripts/modules/addon_utils.py", line 421, in disable
mod.unregister()
File "/Users/zhangbinqi/Library/Application Support/Blender/3.3/scripts/addons/node_to_python.py", line 464, in unregister
bpy.utils.unregister_class(NodeToPython)
RuntimeError: unregister_class(...):, missing bl_rna attribute from 'RNAMeta' instance (may not be registered)

Float curves seem to have double values at 0 and 1.

It looks like the initial values on a curve do not get removed when new values are added.
blender_YeeeSKDPTv
Above, How the curves are in the geometry nodes.
Below, How the curves are when using the addon created for these geometry nodes.
blender_FE1TRLgPSR

Ran into this when trying out the plugin on this fantasy tree by RC12
https://rc12.gumroad.com/l/fantasytree

Reprosteps:

  1. get the .blend file from the gumroad linked above.
  2. use the 'NodeToPython' addon on the tree object in the scene.
  3. Install and activate the newly created 'Fantasy tree' Addon.
  4. add a cube to the scene.
  5. use "bpy.ops.object.fantasy_tree()" on the cube.
  6. Inspect the curves in the newly created tree and compare them to the curves of the original.

Weird issue with node spacing

  • Doesn't seem to be cause by frame nodes
  • Turning off Auto Offset doesn't seem to work either

Node network still functions the same, it's just real ugly

Can't convert Node Groups in Blender 4.0

I tried to use the NodeToPython add-on to convert Material Node Groups in Blender 4.0, but it gives the following error:

Python: Traceback (most recent call last):
   File "C:\ [...] \Blender Foundation\Blender\4.0\scripts\addons\NodeToPython\materials.py", line 246, in execute
     process_mat_node_group(nt, level, node_vars, used_vars)
   File "C:\ [...] \Blender Foundation\Blender\4.0\scripts\addons\NodeToPython\materials.py", line 192, in process_mat_node_group
     process_mat_node_group(node_nt, level + 1, node_vars,
   File "C:\ [...] \Blender Foundation\Blender\4.0\scripts\addons\NodeToPython\materials.py", line 212, in process_mat_node_group
     group_io_settings(node, file, inner, "output", nt_var, node_tree)
   File "C:\Users\Golden Dragon\AppData\Roaming\Blender Foundation\Blender\4.0\scripts\addons\NodeToPython\utils.py", line 276, in group_io_settings
     ntio = node_tree.outputs
AttributeError: 'ShaderNodeTree' object has no attribute 'outputs'

I'm pretty sure it's because of Blender 4.0's new NodeTrees system.

I would love to have it fixed.
(By the way, thanks for the great add-on, it really helps me!)

Suggestion: Code to text block or clipboard

Rather than creating an addon from scratch, I mainly want to "copy" my node tree into existing code.
Maybe something where the code starts from creating a new node_group datablock, and adds all the nodes and links rather than the full boilerplate and zip version. That way I can just insert the code to my addons where I know when it gets to it, it'll just create a copy of my node graph and then continue with what I need afterwards. I wouldn't even assign it to a modifier or anything either, I'd leave that up to the end user to integrate the code.

Code separation

Separate code further, with different files for

  • The operator itself
  • The menu class
  • The panel class
  • The node settings (which could be configurable based on the Blender version)

Asset Library Creation

  • Add option to include current blend file in add-on
  • Create an asset library with referenced
    • Materials
    • Collections
    • Objects
    • Worlds

Not creating links properly on nodes with multiple inputs with the same name

Example, an capture_attribute node have 5 inputs called 'Value', so when creating links like
aaaaa.links.new(radius.outputs["Radius"], capture_attribute.inputs["Value"]), and using Float, it doesnt create the link properly.
changing "Value" with 2 aaaaa.links.new(radius.outputs["Radius"], capture_attribute.inputs[2]), works as intended

ps. just seen this issue was closed before.

Scene handling

  • If a scene referenced by a node/socket is the current scene, then initialize the generated version with the current scene
  • If it's not, I don't think there's a good way of handling that aside from importing an entire scene from a packaged blend file. Might push handling this case to a future release

3.4 Update

Add new Geometry Nodes from Blender 3.4 or research if the API lets us get all the necessary info about each node without hard-coding them in

Re-route nodes are not handled correctly.

While using re-route node, I am getting several different types of errors. It seems re-route node is either not handled correctly or not tested extensively. The error msg varies from case to case. Sometimes it says, 4 default values are expected instead of 3, sometimes it says that a set is expected instead of float. It seems the error msg depends on the type of nodes the re-route node connects to. Not every time it throws an error. So a rigorous testing is needed with complex node trees having extensive use of reroute nodes.

We use re-route node for better formatting. So one idea can be to do away with this altogether and create a direct link between the source and the destination nodes. That is what I did for some of my projects and it worked correctly. The same thing can be automated, so the add-on won't include the re-route nodes. That is just a workaround in case the original problem cannot be fully resolved.

Node output default values

Some default values for nodes are set in the output socket list. Currently the addon doesn't handle this

Curve nodes default points not joining curve

The addon adds in the points for the curves, but it won't update the node.

Thought there might've been a refresh or update function. If not, we may be able to hack it by adding and deleting a point.

Set geometry node inputs

The add-on currently sets the geometry node input default values, but not the actual inputs used. For example, images inputs don't have a default_value attribute and aren't set. This shouldn't be too hard a fix. There maybe should be a UI option to disable this, as it may not always be wanted.

Blender 4.0 nodes

Geometry Nodes

  • Repeat zone
  • Points to Curves node
  • Rotation sockets
  • New rotation nodes
  • Node Tools
  • New Node Tools nodes
  • Group input single value override

Shader Nodes

  • Merging of Glossy and Anisotropic BSDF

Compositor Nodes

  • Reorganize node setting list
  • Classic Kuwahara
  • Anisotropic Kuwahara

General

  • NodeTree -> NodeTree.interface in 4.0+
  • Node panels

Shader Nodes

Would be cool to do it with materials too

  • Maybe copy and import textures and stuff too

Group nodes don't use correct tree if one already present in scene

Let's say we turn a tree into python, and the tree has a group node using tree called "A", which does x. If there's already a group called "A" (doing y) in the scene when we run the generated add-on, then the generated add-on defaults to the group doing y, which could result in errors

Registering add-on of same name

Looks like Blender doesn't like it if you register two add-ons of the same name, investigate further what issues can arise and potential fixes

Programmatically determine node settings

Currently the script just looks up what settings (ex. Vertex/Edge/Face/Face Corner domain options) a node needs to be set with a hard-coded dictionary. This will be increasingly more difficult to maintain many versions of Blender as it grows, and is a bit of a headache everytime they release a new version. By programmatically determining the node settings, then NodeToPython should be compatible with several different versions without much maintenance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.