[Bf-blender-cvs] [36e09d2] object_nodes: Generalize the node compiler functions a bit to prepare for node groups.
Lukas Tönne
noreply at git.blender.org
Sun Dec 6 13:44:41 CET 2015
Commit: 36e09d2a4e9b36c19eff549490b1963e278b886d
Author: Lukas Tönne
Date: Sun Dec 6 12:10:37 2015 +0100
Branches: object_nodes
https://developer.blender.org/rB36e09d2a4e9b36c19eff549490b1963e278b886d
Generalize the node compiler functions a bit to prepare for node groups.
===================================================================
M release/scripts/nodes/common_nodes.py
M release/scripts/nodes/node_compiler.py
===================================================================
diff --git a/release/scripts/nodes/common_nodes.py b/release/scripts/nodes/common_nodes.py
index e5ef476..193c3a3 100644
--- a/release/scripts/nodes/common_nodes.py
+++ b/release/scripts/nodes/common_nodes.py
@@ -56,8 +56,10 @@ def socket_type_to_bvm(socket):
class NodeTreeBase():
def bvm_compile(self, context, graph):
- comp = NodeCompiler(context, graph)
+ compiler = NodeCompiler(context, graph)
+ self.compile_nodes(compiler)
+ def compile_nodes(self, compiler):
input_map = dict()
output_map = dict()
@@ -72,7 +74,7 @@ class NodeTreeBase():
for binput in bnode.inputs:
itype = socket_type_to_bvm(binput)
- proxy = comp.add_node("PASS_%s" % itype)
+ proxy = compiler.add_node("PASS_%s" % itype)
bnode_inputs[binput.identifier] = proxy.outputs[0]
input_map[(bnode, binput)] = proxy.inputs[0]
@@ -83,18 +85,13 @@ class NodeTreeBase():
for boutput in bnode.outputs:
otype = socket_type_to_bvm(boutput)
- proxy = comp.add_node("PASS_%s" % otype)
+ proxy = compiler.add_node("PASS_%s" % otype)
bnode_outputs[boutput.identifier] = proxy.inputs[0]
output_map[(bnode, boutput)] = proxy.outputs[0]
- comp.bnode = bnode
- comp.bnode_inputs = bnode_inputs
- comp.bnode_outputs = bnode_outputs
- bnode.compile(comp)
-
- comp.bnode = None
- comp.bnode_inputs = None
- comp.bnode_outputs = None
+ compiler.push(bnode, bnode_inputs, bnode_outputs)
+ bnode.compile(compiler)
+ compiler.pop()
for blink in self.links:
if not blink.is_valid:
@@ -102,7 +99,7 @@ class NodeTreeBase():
src = (blink.from_node, blink.from_socket)
dst = (blink.to_node, blink.to_socket)
- comp.link(output_map[src], input_map[dst])
+ compiler.link(output_map[src], input_map[dst])
###############################################################################
# Generic Nodes
diff --git a/release/scripts/nodes/node_compiler.py b/release/scripts/nodes/node_compiler.py
index ccab8b9..9ce2819 100644
--- a/release/scripts/nodes/node_compiler.py
+++ b/release/scripts/nodes/node_compiler.py
@@ -108,9 +108,13 @@ class NodeCompiler:
def __init__(self, context, graph):
self.context = context
self.graph = graph
- self.bnode = None
- self.bnode_inputs = None
- self.bnode_outputs = None
+ self.bnode_stack = []
+
+ def push(self, bnode, bnode_inputs, bnode_outputs):
+ self.bnode_stack.append((bnode, bnode_inputs, bnode_outputs))
+
+ def pop(self):
+ self.bnode_stack.pop()
def add_node(self, type, name=""):
node = self.graph.add_node(type, name)
@@ -133,14 +137,16 @@ class NodeCompiler:
to_input.gnode.set_input_link(to_input.ginput, from_output.gnode, from_output.goutput)
def map_input(self, key, socket):
- if key not in self.bnode_inputs:
- raise KeyError("Input %r not found in node %r" % (key, self.bnode))
- self.link(self.bnode_inputs[key], socket)
+ bnode, bnode_inputs, bnode_outputs = self.bnode_stack[-1]
+ if key not in bnode_inputs:
+ raise KeyError("Input %r not found in node %r" % (key, bnode))
+ self.link(bnode_inputs[key], socket)
def map_output(self, key, socket):
- if key not in self.bnode_outputs:
- raise KeyError("Output %r not found in node %r" % (key, self.bnode))
- self.link(socket, self.bnode_outputs[key])
+ bnode, bnode_inputs, bnode_outputs = self.bnode_stack[-1]
+ if key not in bnode_outputs:
+ raise KeyError("Output %r not found in node %r" % (key, bnode))
+ self.link(socket, bnode_outputs[key])
###############################################################################
More information about the Bf-blender-cvs
mailing list