Jump to content

foreach problem [H14]


j00ey

Recommended Posts

HI

 

I have a problem with a couple of nested foreach SOPs that I can't for the life of me figure out.

 

I have a load of spaghetti-like tubes and I want to add a random number of randomly sized gaps to each. I thought this would be relatively straightforward but it's just not working.

 

I've put down a foreach primitive, and inside that a foreach number - on this one I generate a random maximum number,  then inside of that I put down a carve SOP to make the random gaps but it's not behaving as I'd expected. I'm only getting back my first prim, but copied a lot of times [with carves]

 

I've made a simple scene to demonstrate the problem. Can someone tell me what I'm doing wrong?

gappy_tubes.hip

Link to comment
Share on other sites

When you use nested FOREACH you have to remember to change the index variable of the second one to a unique name or the second one will clobber the first one's value.

 

Like this...

for (i=0; i < 10; i++) {
    for (i=0; i<2; i++) {
        //do work.
    }
}

In this case the index variables are the same and the loops won't work right.

  • Like 1
Link to comment
Share on other sites

Also i think you need to disable in your'e second foreach the merge result option else it merges the result of each iteration together.

To get a different gap pattern for each tube you also need to add both foreach indexes to the random value in the carve node.

 

 

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...