@@ -23,6 +23,9 @@ def _as_iterable(x):
23
23
except TypeError :
24
24
return [x ,]
25
25
26
+ get_node_inputs = lambda x : [i for i in x .interface .items_tree if i .item_type == 'SOCKET' and i .in_out == 'INPUT' ]
27
+ get_node_outputs = lambda x : [i for i in x .interface .items_tree if i .item_type == 'SOCKET' and i .in_out == 'OUTPUT' ]
28
+
26
29
def tree (name ):
27
30
tree_name = name
28
31
def build_tree (builder ):
@@ -34,13 +37,20 @@ def build_tree(builder):
34
37
node_group = bpy .data .node_groups [tree_name ]
35
38
else :
36
39
node_group = bpy .data .node_groups .new (tree_name , 'GeometryNodeTree' )
40
+
41
+ node_group .is_modifier = True
42
+
37
43
# Clear the node group before building
38
44
for node in node_group .nodes :
39
45
node_group .nodes .remove (node )
40
- while len (node_group .inputs ) > sum (map (lambda p : len (p .annotation .__annotations__ ) if issubclass (p .annotation , InputGroup ) else 1 , list (signature .parameters .values ()))):
41
- node_group .inputs .remove (node_group .inputs [- 1 ])
42
- for group_output in node_group .outputs :
43
- node_group .outputs .remove (group_output )
46
+
47
+ node_inputs = get_node_inputs (node_group )
48
+ input_count = sum (map (lambda p : len (p .annotation .__annotations__ ) if issubclass (p .annotation , InputGroup ) else 1 , list (signature .parameters .values ())))
49
+ for node_input in node_inputs [input_count :]:
50
+ node_group .interface .remove (node_input )
51
+
52
+ for group_output in get_node_outputs (node_group ):
53
+ node_group .interface .remove (group_output )
44
54
45
55
# Setup the group inputs
46
56
group_input_node = node_group .nodes .new ('NodeGroupInput' )
@@ -65,19 +75,22 @@ def validate_param(param):
65
75
inputs [param .name ] = (param .annotation , param .default , None , None )
66
76
67
77
# Create the input sockets and collect input values.
68
- for i , node_input in enumerate (node_group .inputs ):
78
+ node_inputs = get_node_inputs (node_group )
79
+ for i , node_input in enumerate (node_inputs ):
69
80
if node_input .bl_socket_idname != list (inputs .values ())[i ][0 ].socket_type :
70
- for ni in node_group . inputs :
71
- node_group .inputs .remove (ni )
81
+ for ni in node_inputs :
82
+ node_group .interface .remove (ni )
72
83
break
73
84
builder_inputs = {}
85
+
86
+ node_inputs = get_node_inputs (node_group )
74
87
for i , arg in enumerate (inputs .items ()):
75
88
input_name = arg [0 ].replace ('_' , ' ' ).title ()
76
- if len (node_group . inputs ) > i :
77
- node_group . inputs [i ].name = input_name
78
- node_input = node_group . inputs [i ]
89
+ if len (node_inputs ) > i :
90
+ node_inputs [i ].name = input_name
91
+ node_input = node_inputs [i ]
79
92
else :
80
- node_input = node_group .inputs . new ( arg [1 ][0 ].socket_type , input_name )
93
+ node_input = node_group .interface . new_socket ( socket_type = arg [1 ][0 ].socket_type , name = input_name , in_out = 'INPUT' )
81
94
if arg [1 ][1 ] != inspect .Parameter .empty :
82
95
node_input .default_value = arg [1 ][1 ]
83
96
if arg [1 ][2 ] is not None :
@@ -104,22 +117,22 @@ def validate_param(param):
104
117
for i , (k , v ) in enumerate (outputs .items ()):
105
118
if not issubclass (type (v ), Type ):
106
119
v = Type (value = v )
107
- node_group .outputs . new ( v .socket_type , k )
120
+ node_group .interface . new_socket ( socket_type = v .socket_type , name = k , in_out = 'OUTPUT' )
108
121
node_group .links .new (v ._socket , group_output_node .inputs [i ])
109
122
else :
110
123
for i , result in enumerate (_as_iterable (outputs )):
111
124
if not issubclass (type (result ), Type ):
112
125
result = Type (value = result )
113
126
# raise Exception(f"Return value '{result}' is not a valid 'Type' subclass.")
114
- node_group .outputs . new ( result .socket_type , 'Result' )
127
+ node_group .interface . new_socket ( socket_type = result .socket_type , name = 'Result' , in_out = 'OUTPUT ' )
115
128
node_group .links .new (result ._socket , group_output_node .inputs [i ])
116
129
117
130
_arrange (node_group )
118
131
119
132
# Return a function that creates a NodeGroup node in the tree.
120
133
# This lets @trees be used in other @trees via simple function calls.
121
134
def group_reference (* args , ** kwargs ):
122
- result = group (node_tree = node_group , * args , ** kwargs )
135
+ result = geometrynodegroup (node_tree = node_group , * args , ** kwargs )
123
136
group_outputs = []
124
137
for group_output in result ._socket .node .outputs :
125
138
group_outputs .append (Type (group_output ))
0 commit comments