etudenc Posted October 10, 2011 Share Posted October 10, 2011 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! Quote Link to comment Share on other sites More sharing options...
Erik_JE Posted October 10, 2011 Share Posted October 10, 2011 (edited) You need recursion for that. A ForEach won't be enough. I don't know how to do that with nodes tho. Edited October 10, 2011 by Erik_JE Quote Link to comment Share on other sites More sharing options...
mikelyndon Posted October 10, 2011 Share Posted October 10, 2011 Hey dude. Have you tried using the voronoi fracture tools? That might be a more elegant solution to your problem. Mike Quote Link to comment Share on other sites More sharing options...
Tom Posted October 10, 2011 Share Posted October 10, 2011 (edited) If this is what you want, then you can check attached files. But im not using "cut" method. Im doing that with point node. test01.hipnc test02.hipnc Edited October 10, 2011 by Tom Quote Link to comment Share on other sites More sharing options...
sam.h Posted October 10, 2011 Share Posted October 10, 2011 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) recursiveCut.hip Quote Link to comment Share on other sites More sharing options...
rdg Posted October 10, 2011 Share Posted October 10, 2011 I did something like this awhile ago with nodes: I think I used the clipSOP. Quote Link to comment Share on other sites More sharing options...
edward Posted October 11, 2011 Share Posted October 11, 2011 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. Quote Link to comment Share on other sites More sharing options...
etudenc Posted October 11, 2011 Author Share Posted October 11, 2011 Wow, thank you for all the helpful responses and example files! The nested forEach SOPs are particularly interesting. Thanks so much! Quote Link to comment Share on other sites More sharing options...
Erik_JE Posted October 11, 2011 Share Posted October 11, 2011 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. Quote Link to comment Share on other sites More sharing options...
edward Posted October 12, 2011 Share Posted October 12, 2011 Keep looping while there is anything on the stack. 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. Quote Link to comment Share on other sites More sharing options...
Erik_JE Posted October 12, 2011 Share Posted October 12, 2011 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. Quote Link to comment Share on other sites More sharing options...
Erik_JE Posted October 12, 2011 Share Posted October 12, 2011 Here we go if anyone is interested. String stack recursive using ForEach. recursiveSplit.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.