I want to layout a set of geos in a line on (say) the z-axis. The geos have arbitrary length in their z-axis. There may be multiple copies or each geo (think floorboards here).
In the ForEach loop I need to keep track of length of the previously placed goes is so I know to where to translate the current geo.
I have tried many, many options but seems attributes keep getting reset each time through the loop and I cannot get the sum.
Things like this are very common when programming so I'm likely missing something simple.
Thanks!
Greg
Accumulating a Value in a ForEach Loop
392 9 2- GregBollella
- Member
- 35 posts
- Joined: June 2021
- Offline
- toadstorm
- Member
- 382 posts
- Joined: April 2017
- Offline
It's easier to diagnose a problem if you post a hip file, but it sounds like your for/each block is just misconfigured? Make sure the Block Begin is set to Fetch Feedback, and the Block End is set to Feedback Each Iteration.
MOPs (Motion Operators for Houdini): http://www.motionoperators.com [www.motionoperators.com]
- GregBollella
- Member
- 35 posts
- Joined: June 2021
- Offline
- toadstorm
- Member
- 382 posts
- Joined: April 2017
- Offline
There's a few things in here that need refactoring. First, when designing a for/each loop like this, you want to make sure that anything that's being controlled in the loop, such as your Switch SOP, is inside the loop. You can use Fetch Input nodes as part of your block to make this happen. Second, you can't have parameter expressions referencing downstream nodes, even if you're in a for/each loop... that'll cause an infinite recursion. You can only lookup nodes that are not a direct dependent of your current node.
You don't really need to bind attributes for this to work, anyways... you just need to know the bounding box maximum of the current geometry in the loop, and the new geometry you want to add for each iteration. I'm attaching an example showing you what I mean.
You don't really need to bind attributes for this to work, anyways... you just need to know the bounding box maximum of the current geometry in the loop, and the new geometry you want to add for each iteration. I'm attaching an example showing you what I mean.
MOPs (Motion Operators for Houdini): http://www.motionoperators.com [www.motionoperators.com]
- GOgraphR
- Member
- 72 posts
- Joined: Oct. 2018
- Offline
- GregBollella
- Member
- 35 posts
- Joined: June 2021
- Offline
toadstorm
There's a few things in here that need refactoring. First, when designing a for/each loop like this, you want to make sure that anything that's being controlled in the loop, such as your Switch SOP, is inside the loop. You can use Fetch Input nodes as part of your block to make this happen. Second, you can't have parameter expressions referencing downstream nodes, even if you're in a for/each loop... that'll cause an infinite recursion. You can only lookup nodes that are not a direct dependent of your current node.
You don't really need to bind attributes for this to work, anyways... you just need to know the bounding box maximum of the current geometry in the loop, and the new geometry you want to add for each iteration. I'm attaching an example showing you what I mean.
Thanks. I understand your solution. Would not have thought about just moving the points of the current geo to new x-coord. Seems that I see a lot of this kind of thinking in Houdini. For large, complex geos, though, this might be computationally heavy? Accumulating a simple float offset each iteration seems might be more efficient, no?
Greg
- GregBollella
- Member
- 35 posts
- Joined: June 2021
- Offline
- toadstorm
- Member
- 382 posts
- Joined: April 2017
- Offline
GregBollella
Thanks. I understand your solution. Would not have thought about just moving the points of the current geo to new x-coord. Seems that I see a lot of this kind of thinking in Houdini. For large, complex geos, though, this might be computationally heavy? Accumulating a simple float offset each iteration seems might be more efficient, no?
Greg
I don't think you'll likely see a huge computational difference but you could totally benchmark it if you want. A Transform in SOPs context is multiplying every point by the matrix you define in that interface anyways... I wouldn't expect adding a fixed value to P every frame to change that too much.
If you're trying to do this in the most straightforward way possible, I wouldn't even bother with a For/Each loop. Just use the Chain SOP and provide a straight line as the curve input, it'll handle it for you. Just figured this example with VEX and loops would be a good way to show you how Houdini thinks and better answer your original question.
MOPs (Motion Operators for Houdini): http://www.motionoperators.com [www.motionoperators.com]
- GregBollella
- Member
- 35 posts
- Joined: June 2021
- Offline
toadstorm
I don't think you'll likely see a huge computational difference but you could totally benchmark it if you want. A Transform in SOPs context is multiplying every point by the matrix you define in that interface anyways... I wouldn't expect adding a fixed value to P every frame to change that too much.
If you're trying to do this in the most straightforward way possible, I wouldn't even bother with a For/Each loop. Just use the Chain SOP and provide a straight line as the curve input, it'll handle it for you. Just figured this example with VEX and loops would be a good way to show you how Houdini thinks and better answer your original question.
Ah, good point about the Transform SOP moving every point anyway.
Thanks, I will give the Chain SOP a look!
Greg
- GregBollella
- Member
- 35 posts
- Joined: June 2021
- Offline
-
- Quick Links