Loop Nodes #4
42
nodes.py
42
nodes.py
@ -93,38 +93,52 @@ class RigNodesNodeTree(bpy.types.NodeTree):
|
||||
depsgraph: bpy.types.Depsgraph,
|
||||
to_visit: deque["AbstractRigNodesNode"],
|
||||
depth: int = 1,
|
||||
) -> None:
|
||||
) -> deque['AbstractRigNodesNode']:
|
||||
"""Run one iteration of a loop.
|
||||
|
||||
:return: Node(s) to visit next."""
|
||||
cgtinker marked this conversation as resolved
|
||||
|
||||
indent = '\t' * depth
|
||||
print(f"{indent}\033[38;5;214mRunning {node}\033[0m")
|
||||
|
||||
|
||||
input_node = node
|
||||
output_node = node._get_connection_node()
|
||||
visited: Set["AbstractRigNodesNode"] = set()
|
||||
|
||||
while to_visit:
|
||||
node = to_visit.popleft()
|
||||
|
||||
nested_loop: Optional[deque[AbstractRigNodesNode]] = None
|
||||
if isinstance(node, LoopInputNode) and node != input_node:
|
||||
# Run nested loop.
|
||||
# Find the nested loop.
|
||||
nested_output_node = node._get_connection_node()
|
||||
nested_loop = deque(nested_output_node._get_nodes_between(node))
|
||||
nested_loop.append(nested_output_node)
|
||||
self._run_loop(node, depsgraph, nested_loop, depth+1)
|
||||
# continue
|
||||
|
||||
print(f"{indent}\t-{node}")
|
||||
# Don't revisit nested nodes in the parent loop.
|
||||
for nested_node in nested_loop:
|
||||
visited.add(nested_node)
|
||||
|
||||
# Run the nested loop using the current inputs.
|
||||
for _ in range(node.num_socks):
|
||||
self._run_loop(node, depsgraph, nested_loop.copy(), depth+1)
|
||||
continue
|
||||
|
||||
|
||||
if node in visited:
|
||||
# Nested nodes are added to visited nodes as they get executed in advance.
|
||||
# A Node can alsp be visited when a node has inputs from two different
|
||||
# nodes; both of those will list this node as 'successor'.
|
||||
continue
|
||||
|
||||
print(f"{indent}\tRunning: {node}, remaining runs: {node.iterations}")
|
||||
visited.add(node)
|
||||
node.run(depsgraph)
|
||||
# if node.iterations > 0:
|
||||
# # Add output node for future iterations.
|
||||
# to_visit.append(node)
|
||||
|
||||
if node == output_node:
|
||||
break
|
||||
|
||||
return to_visit
|
||||
|
||||
|
||||
def _run_from_node(
|
||||
self, depsgraph: bpy.types.Depsgraph, start_node: "AbstractRigNodesNode"
|
||||
@ -136,7 +150,7 @@ class RigNodesNodeTree(bpy.types.NodeTree):
|
||||
print(f"\033[38;5;214mRunning tree {self.name}\033[0m")
|
||||
while to_visit:
|
||||
node: AbstractRigNodesNode = to_visit[0]
|
||||
print(f"\t- {node}")
|
||||
print(f"\t- Visiting {node}")
|
||||
|
||||
nodes_before = list(node.exec_order_prerequisites())
|
||||
if nodes_before:
|
||||
@ -146,7 +160,10 @@ class RigNodesNodeTree(bpy.types.NodeTree):
|
||||
continue
|
||||
|
||||
if isinstance(node, LoopInputNode):
|
||||
# Run one iteration if the found loop (recursive if nested).
|
||||
# Run all iterations if the found loop (recursive if nested).
|
||||
# nested_output_node = node._get_connection_node()
|
||||
# nested_loop = deque(nested_output_node._get_nodes_between(node))
|
||||
# nested_loop.append(nested_output_node)
|
||||
self._run_loop(node, depsgraph, to_visit)
|
||||
continue
|
||||
|
||||
@ -161,6 +178,7 @@ class RigNodesNodeTree(bpy.types.NodeTree):
|
||||
continue
|
||||
visited.add(node)
|
||||
|
||||
print(f"\tRunning: {node}")
|
||||
node.run(depsgraph)
|
||||
|
||||
# Queue up the next nodes.
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user
Formatting: when writing multi-line docstrings, the closing
"""
should be on a line of its own (see PEP 257)Sorry, still stumbling.