In houdini it is posslible to create a for loop to repeat functions easily, is this possible in geometry nodes? the setup below is my current solution,its extremely messy and not very scalable has anyone found a better solution to this problem?
-
2$\begingroup$ can you describe what you want to do inside the loop (pseudocode). in some cases it is possible to construct a node group such that combining them linearly in a chain, will also give the same result $\endgroup$– Shantanu AryanCommented May 25, 2022 at 16:13
-
$\begingroup$ @ShantanuAryan since Blender 4.0 there are loops in Blender - it's called a "Repeat Zone". It doesn't allow you to break early, and you can't loop indefinitely - so you need to know in advance how many iterations you want the loop to have. You can work around it by nesting the repeat zones to support a lot of iterations without significant overhead once you reach the final state - so you don't break still, but the outer repeat zone uses a switch to not use any inner repeat zones anymore. $\endgroup$– Markus von BroadyCommented Jun 11 at 9:33
1 Answer
It is not possible to create loops in Geometry Nodes. There is a better solution for many problems that uses an Instance on Points node to create the duplication. Here is a rough example:
The mesh line is used to generate a number of points, its Count value. It can also be modified by a Set Position node to control the locations. Many other nodes or node groups can substitute depending on your need.
The key is the Instance input to the Instance on Points node. Not shown in this picture, whatever feeds it is the geometry you want to repeat. That's usually replaced by whatever geometry you want to repeat.
There are similar approaches for other looping-like constructs. They rely on the fact that 3.x Geometry Nodes uses Fields and you can set up the contents of a field as if it were your loop variable and then modify it with nodes like Instance on Points
-
1$\begingroup$ I saw that their was a proposal for loops here, it looks promising devtalk.blender.org/t/loops-in-geometry-nodes-proposal/21357. If I cant get your suggestion to work I think I am just going to put this project off until they add it. $\endgroup$ Commented May 25, 2022 at 22:06