Jump to content

forEach and clip SOP


etudenc

Recommended Posts

Hi all,

I am trying to figure out how to cut a 2x2 grid into (let's say) 10 random primitives. I feel sure the right way to do it is thru a clip SOP inside a forEach SOP, but the thing is I want each new primitive to be affected by the clip SOP and not the "previous" primitive(s) or the entire grid.

Hopefully the image I've attached will help illustrate what I'm after.

Thank you for any responses!

post-6043-131828152505_thumb.jpg

Link to comment
Share on other sites

Had a play with this, there is something wrong with the way I am getting the seed for the random direction for the cut ... but it basically works.

It is a nested foreach, the top layer is a foreach feedback loop, and the inner foreach is for each connected piece (so that you can get a different cut for each piece)

post-4420-131828985083_thumb.png

recursiveCut.hip

Link to comment
Share on other sites

You need recursion for that. A ForEach won't be enough. I don't know how to do that with nodes tho.

One can simulate recursion using iteration through the use of a stack. It's bit of pain but I've done it before. You make a string attribute say that has a list of your primitive numbers (separated by spaces). Then through string manipulation, you can "pop" items off the stack by removing the last primitive number, and you can "push" an item onto the stack by appending your primitive number.

Link to comment
Share on other sites

One can simulate recursion using iteration through the use of a stack. It's bit of pain but I've done it before. You make a string attribute say that has a list of your primitive numbers (separated by spaces). Then through string manipulation, you can "pop" items off the stack by removing the last primitive number, and you can "push" an item onto the stack by appending your primitive number.

I get the idea of using a stack but not how to use it together with a ForEach or some other node.

If doing it by code i would make a stack of primitive numbers with a pair attribute being the depth of how many times they have been recursively clipped.

Then pop-ing one from the top, clipping and ++ the depth and add them on the stack again. Use a random number to decide what depth that are allowed for the individual primitive. Keep looping while there is anything on the stack.

I would love to see an example on how something similar could be setup with nodes.

Link to comment
Share on other sites

Yes, the problem is that you don't know when to stop but that's ok. Just give it a high enough number of iterations to ensure that you reach a state where your stack is empty. :)

Ahhh, using the Each Number of course. Got my string of primitive numbers now and most other stuff. Just need to figure out how to modify the string.

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