j00ey Posted November 5, 2015 Share Posted November 5, 2015 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 Quote Link to comment Share on other sites More sharing options...
Atom Posted November 5, 2015 Share Posted November 5, 2015 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. 1 Quote Link to comment Share on other sites More sharing options...
j00ey Posted November 5, 2015 Author Share Posted November 5, 2015 Ah I hadn't thought of that but it makes total sense. Thanks very much for the pointer. Quote Link to comment Share on other sites More sharing options...
Maurits Posted November 5, 2015 Share Posted November 5, 2015 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. Quote Link to comment Share on other sites More sharing options...
j00ey Posted November 5, 2015 Author Share Posted November 5, 2015 Yes I just discovered I needed to switch off the merge results. Thanks for the tip regards the for each indices though, I was just trying to figure out why the pattern is otherwise quite uniform Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.