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
270 stars 27 forks source link

Failure to run the simulation_zone example on blender 4.0 (and 3.6) #41

Open tsatse opened 1 year ago

tsatse commented 1 year ago

Hello, I'm starting from the default cube on which I add a geometry node modifier, I then type the following script (from the documentation) in the built-in editor :

from geometry_script import *

@tree
def test_sim(geometry: Geometry):
    @simulation_zone
    def my_sim(delta_time, geometry: Geometry, value: Float):
        return (False, geometry, value)
    return my_sim(geometry, 0.26).value

I get the following error message :

    Python: Traceback (most recent call last):
      File "\Text", line 4, in <module>
      File "C:\Users\tsatse\AppData\Roaming\Blender Foundation\Blender\4.0\scripts\addons\geometry-script-main\api\tree.py", line 149, in tree
        return build_tree(name)
      File "C:\Users\tsatse\AppData\Roaming\Blender Foundation\Blender\4.0\scripts\addons\geometry-script-main\api\tree.py", line 113, in build_tree
        outputs = builder(**builder_inputs)
      File "\Text", line 8, in test_sim
      File "C:\Users\tsatse\AppData\Roaming\Blender Foundation\Blender\4.0\scripts\addons\geometry-script-main\api\static\simulation.py", line 21, in wrapped
        simulation_in = State.current_node_tree.nodes.new(bpy.types.GeometryNodeSimulationInput.__name__)
    AttributeError: 'NoneType' object has no attribute 'nodes'

(my OS is windows 10)

tsatse commented 1 year ago

I tried to figure out in your code why the state's current node tree wasn't defined but I'm still trying to figure things out. I also tried to make it work with blender 3.6 and your commit that refactors simulation API to use "simulation_zone" but it didn't work either, with a similar error message, ie missing attribute 'nodes' in current_node_tree.

rsaccon commented 1 year ago

I cannot try the example (I am on Blender 3.6, on newer Blender my graphic card is not supported), but looking at the code, especially the signature of my_sym, it looks to me like you are calling it with wrong arguments, the delta_time is missing. Update: I can run the example on Blender 3.6, but also does not work for me

tsatse commented 1 year ago

yes, I tried adding that first argument but it didn't change anything. It looks like the simulation code tries to access the tree while it hasn't been built. I'm trying to understand all the code but I need to read about blender's api now

alphadito commented 11 months ago

Make sure the geometry script add-on folder is called 'geometry_script'. This will ensure that the correct state module is used instead of relying on __init __.py to manually set sys.modules which unfortunately doesn't work in all cases.

tsatse commented 11 months ago

Yesss ! It worked. Thank you so much