2019-03-22 11:57:03 +01:00
|
|
|
import bpy
|
|
|
|
from collections import namedtuple
|
|
|
|
|
2019-09-19 10:34:13 +02:00
|
|
|
from . base import BaseTree, BaseNode
|
2019-03-22 11:57:03 +01:00
|
|
|
|
|
|
|
FunctionInput = namedtuple("FunctionInput",
|
|
|
|
["data_type", "name", "identifier"])
|
|
|
|
|
|
|
|
FunctionOutput = namedtuple("FunctionOutput",
|
|
|
|
["data_type", "name", "identifier"])
|
|
|
|
|
2019-07-02 12:40:01 +02:00
|
|
|
class TreeWithFunctionNodes:
|
|
|
|
def iter_dependency_trees(self):
|
2019-07-16 12:57:30 +02:00
|
|
|
trees = set()
|
2019-07-02 12:40:01 +02:00
|
|
|
for node in self.nodes:
|
2019-09-19 10:34:13 +02:00
|
|
|
if isinstance(node, BaseNode):
|
|
|
|
trees.update(node.iter_dependency_trees())
|
2019-07-16 12:57:30 +02:00
|
|
|
yield from trees
|
2019-07-02 12:40:01 +02:00
|
|
|
|
|
|
|
class FunctionTree(bpy.types.NodeTree, BaseTree, TreeWithFunctionNodes):
|
2019-03-22 11:57:03 +01:00
|
|
|
bl_idname = "FunctionTree"
|
|
|
|
bl_icon = "MOD_DATA_TRANSFER"
|
|
|
|
bl_label = "Function Nodes"
|
|
|
|
|
|
|
|
def iter_function_inputs(self):
|
|
|
|
node = self.get_input_node()
|
|
|
|
if node is None:
|
|
|
|
return
|
|
|
|
|
|
|
|
for socket in node.outputs[:-1]:
|
|
|
|
yield FunctionInput(
|
|
|
|
socket.data_type,
|
2019-04-05 12:29:07 +02:00
|
|
|
socket.name,
|
2019-03-22 11:57:03 +01:00
|
|
|
socket.identifier)
|
|
|
|
|
|
|
|
def iter_function_outputs(self):
|
|
|
|
node = self.get_output_node()
|
|
|
|
if node is None:
|
|
|
|
return
|
|
|
|
|
|
|
|
for socket in node.inputs[:-1]:
|
|
|
|
yield FunctionOutput(
|
|
|
|
socket.data_type,
|
2019-04-05 12:29:07 +02:00
|
|
|
socket.name,
|
2019-03-22 11:57:03 +01:00
|
|
|
socket.identifier)
|
|
|
|
|
|
|
|
def get_input_node(self):
|
|
|
|
for node in self.nodes:
|
|
|
|
if node.bl_idname == "fn_FunctionInputNode":
|
|
|
|
return node
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_output_node(self):
|
|
|
|
for node in self.nodes:
|
|
|
|
if node.bl_idname == "fn_FunctionOutputNode":
|
|
|
|
return node
|
2019-04-04 14:26:20 +02:00
|
|
|
return None
|