sim Posted February 20, 2014 Share Posted February 20, 2014 Hello, I'm trying to find a way to write out certain values from inside a foreach iteration to somewhere else, so that I can refer to it in subsequent iterations. On showing off my newly acquired Houdini knowledge to a friend I was tasked with procedurally generating something much like a pine cone. -I have bitten off more than I can chew. I've found it very tricky to procedurally generate this object. -The idea is that the 'scales' of the cone start off large at the bottom of the cone, and as it moves up they get smaller and smaller. For simplicity right now I've just gone with putting scales over the surface of a cone like shape. I'm using a FOREACH node to do all the work. -I have a curve that represents the height of the cone. -Inside the FOREACH node I use a 'carve' sop to cut the line at a certain point for each iteration and put in a circle of scales. Initially I was using a maths function that didn't need any knowledge of what the previous iteration had done, but I'm not getting enough control over the distribution. (Bottom scales too big, top scales too small) What I'd really like to do is write out the distance travelled up the line in each iteration to somewhere, so that it can be referred to by the next iteration. For example, the bottom scales are 10% of the total height and I want them to shrink by 1% each time. -> 10% - 9% - 8% - 7% - 6%: My maths isn't good enough to just know how high up the line the next iteration needs to be placed. Ideally I can keep a running total of what;s been done that the sops inside the foreach node can refer to. I'd appreciate any help on this. 'regards Sim. Quote Link to comment Share on other sites More sharing options...
sim Posted February 20, 2014 Author Share Posted February 20, 2014 Okay, so heading home I thought the answer might be quite simple. I put an attribcreate at the end of the chain inside the foreach sop and added a detail attribute with the name distance_N, where N is the current stamp value. And gave the attribute the current distance moved. This was looking quite promising because coming out of the foreach sop every value was there. However when I added a 2nd attribcreate inside that attempted get it's value by reading the (N-1) value created previously - it returned zero every time.... back to the drawing board. Sim Quote Link to comment Share on other sites More sharing options...
magneto Posted February 20, 2014 Share Posted February 20, 2014 I don't think you need to use the Foreach SOP for this. You can create a pscale point attribute that goes from large to small along the length of the line and then copy your objects to it as a ring using the Copy SOP and they will be scaled accordingly. You could easily vary other things like rotation around the line, etc. Quote Link to comment Share on other sites More sharing options...
edward Posted February 22, 2014 Share Posted February 22, 2014 I would just use a ramp parameter to control the radius as it goes up, and then just do copy stamping with something like chramp("/path/to/ramp", $PT/($NPT-1)) with a vertical line as the template points. Quote Link to comment Share on other sites More sharing options...
sim Posted February 25, 2014 Author Share Posted February 25, 2014 Thanks for the replies guys, what I ended up doing was using a python sop external to the foreach sop that calculated the successive size of each ring of scales and the distance between each ring. -For all the rings and then storing the values as prim attributes. Getting the distance right was the hard part. Ryan and edward, you both had similar solutions. But I can't see how either of them would 'easily' allow for the packing of the rings of scales as they get smaller and smaller. For example I could use a vertical line with template points, but the distribution of points would need to start further apart and then get tighter and tighter travelling up the line. 'cheers, Sim. Quote Link to comment Share on other sites More sharing options...
edward Posted February 26, 2014 Share Posted February 26, 2014 You just use the "stamping" feature of the Cop SOP. Here's a simple example stampRampShape.hipnc Quote Link to comment Share on other sites More sharing options...
sim Posted February 26, 2014 Author Share Posted February 26, 2014 Thanks for the example edward, I checked it out. It makes sense. I quite like how you can use the ramp to adjust the profile of the circles on the way up. Though I still don't think it can acheive the shrinking packing density needed as the scales get smaller and smaller travelling up the line. To show you what I mean here's a pic from my solution. Look at how the 'scales' keep their pattern/formation all the way up the surface even as they get smaller. That made made everything more complicated for me. For me the problem was quite complex and my solution feels complex too, I've attached it here for anyones curiosity. But I'd be interested in a simpler, more elegant, solution. Sim. pineConeArray.hipnc 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.