[Bf-blender-cvs] [e77a8b97e11] functions: initial support for calling subprograms
Jacques Lucke
noreply at git.blender.org
Fri Mar 22 11:58:04 CET 2019
Commit: e77a8b97e11e5d52632e7d34a8738cc87803cce5
Author: Jacques Lucke
Date: Fri Mar 22 11:57:03 2019 +0100
Branches: functions
https://developer.blender.org/rBe77a8b97e11e5d52632e7d34a8738cc87803cce5
initial support for calling subprograms
===================================================================
M release/scripts/startup/function_nodes/base.py
A release/scripts/startup/function_nodes/function_tree.py
M release/scripts/startup/function_nodes/menu.py
A release/scripts/startup/function_nodes/nodes/call.py
M release/scripts/startup/function_nodes/socket_decl.py
M release/scripts/startup/function_nodes/tree_panel.py
M release/scripts/startup/function_nodes/update.py
M source/blender/functions/frontends/data_flow_nodes/function_generation.cpp
M source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp
===================================================================
diff --git a/release/scripts/startup/function_nodes/base.py b/release/scripts/startup/function_nodes/base.py
index a76076ee2b2..5b02bfa1cb6 100644
--- a/release/scripts/startup/function_nodes/base.py
+++ b/release/scripts/startup/function_nodes/base.py
@@ -16,12 +16,6 @@ class BaseTree:
update_function_trees()
-class FunctionTree(bpy.types.NodeTree, BaseTree):
- bl_idname = "FunctionTree"
- bl_icon = "MOD_DATA_TRANSFER"
- bl_label = "Function Nodes"
-
-
class NodeStorage:
def __init__(self, node):
self.node = node
diff --git a/release/scripts/startup/function_nodes/function_tree.py b/release/scripts/startup/function_nodes/function_tree.py
new file mode 100644
index 00000000000..7782d78a1ed
--- /dev/null
+++ b/release/scripts/startup/function_nodes/function_tree.py
@@ -0,0 +1,49 @@
+import bpy
+from collections import namedtuple
+
+from . base import BaseTree
+
+FunctionInput = namedtuple("FunctionInput",
+ ["data_type", "name", "identifier"])
+
+FunctionOutput = namedtuple("FunctionOutput",
+ ["data_type", "name", "identifier"])
+
+class FunctionTree(bpy.types.NodeTree, BaseTree):
+ 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,
+ "hello",
+ 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,
+ "bye",
+ 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
+ return None
\ No newline at end of file
diff --git a/release/scripts/startup/function_nodes/menu.py b/release/scripts/startup/function_nodes/menu.py
index 2ce14b068a6..14166b92701 100644
--- a/release/scripts/startup/function_nodes/menu.py
+++ b/release/scripts/startup/function_nodes/menu.py
@@ -1,5 +1,5 @@
import bpy
-from . base import FunctionTree
+from . function_tree import FunctionTree
def draw_menu(self, context):
tree = context.space_data.node_tree
diff --git a/release/scripts/startup/function_nodes/nodes/call.py b/release/scripts/startup/function_nodes/nodes/call.py
new file mode 100644
index 00000000000..f82277c2a50
--- /dev/null
+++ b/release/scripts/startup/function_nodes/nodes/call.py
@@ -0,0 +1,27 @@
+import bpy
+from bpy.props import *
+from .. base import FunctionNode
+from .. socket_decl import TreeInterfaceDecl
+
+class CallNode(bpy.types.Node, FunctionNode):
+ bl_idname = "fn_CallNode"
+ bl_label = "Call"
+
+ function_tree: PointerProperty(
+ name="Function Tree",
+ type=bpy.types.NodeTree,
+ update=FunctionNode.refresh,
+ )
+
+ def get_sockets(self):
+ if self.function_tree is None:
+ return [], []
+
+ return [
+ TreeInterfaceDecl("inputs", self.function_tree, "IN"),
+ ], [
+ TreeInterfaceDecl("outputs", self.function_tree, "OUT"),
+ ]
+
+ def draw(self, layout):
+ layout.prop(self, "function_tree", text="")
\ No newline at end of file
diff --git a/release/scripts/startup/function_nodes/socket_decl.py b/release/scripts/startup/function_nodes/socket_decl.py
index e46ef644a41..72ef7c992dd 100644
--- a/release/scripts/startup/function_nodes/socket_decl.py
+++ b/release/scripts/startup/function_nodes/socket_decl.py
@@ -1,6 +1,7 @@
import bpy
from bpy.props import *
from dataclasses import dataclass
+from . function_tree import FunctionTree
from . sockets import OperatorSocket
from . types import type_infos
from . base import DataSocket
@@ -38,6 +39,45 @@ class FixedSocketDecl(SocketDeclBase):
def amount(self, node):
return 1
+class TreeInterfaceDecl(SocketDeclBase):
+ def __init__(self, identifier: str, tree: FunctionTree, in_or_out: str):
+ assert tree is not None
+ self.identifier = identifier
+ self.tree = tree
+ self.in_or_out = in_or_out
+
+ def build(self, node, node_sockets):
+ if self.in_or_out == "IN":
+ return list(self._build_inputs(node_sockets))
+ elif self.in_or_out == "OUT":
+ return list(self._build_outputs(node_sockets))
+ else:
+ assert False
+
+ def _build_inputs(self, node_sockets):
+ for data_type, name, identifier in self.tree.iter_function_inputs():
+ yield type_infos.build(
+ data_type,
+ node_sockets,
+ name,
+ self.identifier + identifier)
+
+ def _build_outputs(self, node_sockets):
+ for data_type, name, identifier in self.tree.iter_function_outputs():
+ yield type_infos.build(
+ data_type,
+ node_sockets,
+ name,
+ self.identifier + identifier)
+
+ def amount(self, node):
+ if self.in_or_out == "IN":
+ return len(tuple(self.tree.iter_function_inputs()))
+ elif self.in_or_out == "OUT":
+ return len(tuple(self.tree.iter_function_outputs()))
+ else:
+ assert False
+
class ListSocketDecl(SocketDeclBase):
def __init__(self, identifier: str, display_name: str, prop_name: str, list_or_base: str):
self.identifier = identifier
diff --git a/release/scripts/startup/function_nodes/tree_panel.py b/release/scripts/startup/function_nodes/tree_panel.py
index 41b4feb9b1f..9a8b47b3e84 100644
--- a/release/scripts/startup/function_nodes/tree_panel.py
+++ b/release/scripts/startup/function_nodes/tree_panel.py
@@ -1,5 +1,5 @@
import bpy
-from . base import FunctionTree
+from . function_tree import FunctionTree
class TreePanel(bpy.types.Panel):
bl_idname = "fn_tree_panel"
diff --git a/release/scripts/startup/function_nodes/update.py b/release/scripts/startup/function_nodes/update.py
index 5661b6dfc86..01eb5fdf684 100644
--- a/release/scripts/startup/function_nodes/update.py
+++ b/release/scripts/startup/function_nodes/update.py
@@ -2,9 +2,10 @@ import bpy
from collections import defaultdict
from contextlib import contextmanager
+from . base import DataSocket
from . types import type_infos
from . sockets import OperatorSocket
-from . base import DataSocket, FunctionTree
+from . function_tree import FunctionTree
from . utils.graph import iter_connected_components
from . socket_decl import (
@@ -12,6 +13,7 @@ from . socket_decl import (
ListSocketDecl,
PackListDecl,
AnyVariadicDecl,
+ TreeInterfaceDecl,
)
@@ -157,7 +159,7 @@ def iter_possible_list_component_types(component, decision_users, linked_sockets
for socket in decision_users[decision_id]["LIST"]:
for other_node, other_socket in linked_sockets[socket]:
other_decl = other_socket.get_decl(other_node)
- if isinstance(other_decl, (FixedSocketDecl, AnyVariadicDecl)):
+ if data_sockets_are_static(other_decl):
data_type = other_socket.data_type
if type_infos.is_list(data_type):
yield type_infos.to_base(data_type)
@@ -166,7 +168,7 @@ def iter_possible_list_component_types(component, decision_users, linked_sockets
for socket in decision_users[decision_id]["BASE"]:
for other_node, other_socket in linked_sockets[socket]:
other_decl = other_socket.get_decl(other_node)
- if isinstance(other_decl, (FixedSocketDecl, AnyVariadicDecl)):
+ if data_sockets_are_static(other_decl):
data_type = other_socket.data_type
if type_infos.is_base(data_type):
yield data_type
@@ -186,7 +188,7 @@ def make_pack_list_decisions(tree, linked_sockets, list_decisions):
assert len(linked_sockets[socket]) == 1
origin_node, origin_socket = next(iter(linked_sockets[socket]))
origin_decl = origin_socket.get_decl(origin_node)
- if isinstance(origin_decl, (FixedSocketDecl, AnyVariadicDecl)):
+ if data_sockets_are_static(origin_decl):
data_type = origin_socket.data_type
if data_type == decl.base_type:
decisions[decision_id] = "BASE"
@@ -211,6 +213,9 @@ def make_pack_list_decisions(tree, linked_sockets, list_decisions):
return decisions
+def data_sockets_are_static(decl):
+ return isinstance(decl, (FixedSocketDecl, AnyVariadicDecl, TreeInterfaceDecl))
+
def iter_pack_list_sockets(tree):
for node in tree.nodes:
for decl, sockets in node.storage.sockets_per_decl.items():
diff --git a/source/blender/functions/frontends/data_flow_nodes/function_generation.cpp b/source/blender/functions/frontends/data_flow_nodes/function_generation.cpp
index 3937312261e..c7d6550263d 100644
--- a/source/blender/functions/frontends/data_flow_nodes/function_generation.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/function_generation.cpp
@@ -20,9 +20,9 @@ namespace FN { namespace DataFlowNodes {
auto fn = SharedFunction::New(btree->id.name, fgraph.signature());
fgraph_add_DependenciesBody(fn, fgraph);
- //fgraph_add_TupleCallBody(fn, fgraph);
- fgraph_add_LLVMBuildIRBody(fn, fgraph);
- derive_TupleCallBody_from_LLVMBuildIRBody(fn, *(new llvm::LLVMContext()));
+ fgraph_add_TupleCallBody(fn, fgraph);
+ // fgraph_add_LLVMBuildIRBody(fn, fgraph);
+ // derive_TupleCallBody_from_LLVMBuildIRBody(fn, *(new llvm::LLVMContext()));
return fn;
}
diff --git a/source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp b/source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp
index f95abb1584c.
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list