Loop Nodes #4
17
nodes.py
17
nodes.py
@ -73,10 +73,7 @@ class RigNodesNodeTree(bpy.types.NodeTree):
|
||||
self._reset_nodes()
|
||||
|
||||
# Find all loops in the tree.
|
||||
output_nodes = list()
|
||||
for node in self.nodes:
|
||||
if isinstance(node, LoopOutputNode):
|
||||
output_nodes.append(node)
|
||||
output_nodes = (node for node in self.nodes if isinstance(node, LoopOutputNode))
|
||||
|
||||
# Set iteration count foreach (nested) loop.
|
||||
for output_node in output_nodes:
|
||||
cgtinker marked this conversation as resolved
|
||||
@ -93,7 +90,8 @@ class RigNodesNodeTree(bpy.types.NodeTree):
|
||||
) -> deque["AbstractRigNodesNode"]:
|
||||
"""Runs (nested) loops.
|
||||
|
||||
:return: Node(s) to visit next."""
|
||||
:return: Node(s) to visit next.
|
||||
"""
|
||||
|
||||
indent = "\t" * depth
|
||||
print(f"{indent}\033[38;5;214mRunning {node}\033[0m")
|
||||
@ -299,7 +297,8 @@ class AbstractRigNodesNode(bpy.types.Node):
|
||||
return self.outputs
|
||||
|
||||
def _get_innern_loop_nodes(
|
||||
self: "LoopOutputNode", input_node: "LoopInputNode",
|
||||
self: "LoopOutputNode",
|
||||
input_node: "LoopInputNode",
|
||||
) -> Iterable["AbstractRigNodesNode"]:
|
||||
"""Generator, yields nodes between the loop input and the loop output node"""
|
||||
visited: Set["AbstractRigNodesNode"] = set()
|
||||
@ -377,7 +376,7 @@ class AbstractRigNodesNode(bpy.types.Node):
|
||||
raise
|
||||
finally:
|
||||
self.iterations -= 1
|
||||
if self.iterations == 0:
|
||||
if self.iterations <= 0:
|
||||
self.has_run = True
|
||||
|
||||
def __str__(self) -> str:
|
||||
@ -613,6 +612,10 @@ class LoopInputNode(AbstractRigNodesNode):
|
||||
self.index = 0
|
||||
self.iterations = self.num_socks
|
||||
|
||||
@AbstractRigNodesNode._outputs.getter # type: ignore
|
||||
def _outputs(self):
|
||||
return self.outputs[1:]
|
||||
|
||||
def init(self, context: bpy.types.Context) -> None:
|
||||
for index in range(self.num_socks):
|
||||
match self.dtype:
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user
This can be written as:
And since it's only being iterated over once, there even no need to construct a list, so a generator expression does the trick as well: