Loop Nodes #4

Open
Denys Hsu wants to merge 5 commits from cgtinker/powership:loop into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
2 changed files with 10 additions and 7 deletions
Showing only changes of commit 30fd4a91da - Show all commits

View File

@ -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

This can be written as:

output_nodes = [node for node in self.nodes
                if isinstance(node, LoopOutputNode)]

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:

output_nodes = (node for node in self.nodes
                if isinstance(node, LoopOutputNode))
This can be written as: ```py output_nodes = [node for node in self.nodes if isinstance(node, LoopOutputNode)] ``` 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: ```py output_nodes = (node for node in self.nodes if isinstance(node, LoopOutputNode)) ```
@ -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.