Jump to content

storing values between FOREACH iterations - pattern making


sim

Recommended Posts

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.

 
post-10718-0-03109300-1392887198_thumb.j

 

 

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.

post-10718-0-03109300-1392887198_thumb.j

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

post-10718-0-58342600-1393418349_thumb.j

pineConeArray.hipnc

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...