Jump to content

Need help with loops and Foreach


Werner

Recommended Posts

I'm trying to understand how loops and Foreach works, but need some help on how to iterate over primitives with different offsets and angles in my cuts.

Here is an image I found online to explain what I want to do...or something similar.

1. Use clip to cut a primitive once

2. Loop over the new primitives and cut again, but at different positions and angles.

Loop_Question.jpg

  • Haha 1
Link to comment
Share on other sites

here's my foolin' around...I put a bias in mine so it can break up the biggus first rather than an even chance for each prim..not sure if I've set up my logic right tho....one thing, tried the compiled block and Sort ain't compilable yet :(

vu_generic_recursive_div.hipnc

Edited by Noobini
  • Like 4
Link to comment
Share on other sites

Thanks Mestela!   I had a look at your Greeble example as well.

It seems to do exactly what I had in mind...it's just for learning so your file is very welcome. You should put it up on your website.

Thanks again.



 

Edited by Werner
Link to comment
Share on other sites

Forgot to mention where I got the idea from. There is a beautiful render on the SideFX gall done by Dimitris Ladopoulos, that made me want to explore loops Foreeach. 
https://www.sidefx.com/gallery/algorithm/

Thanks again for the great example Mestela. I'm yet to understand how it all works, but I will take my time.

one more for fun.

 

 

Rec_SubD_102.jpg

  • Like 2
Link to comment
Share on other sites

Great renders!

I agree, it'll make a nice mid-length article for the wiki, the way I worked it out with lots of mis-steps and incorrect toggles and whatnot was actually a good way to learn, I have a feeling a slightly meandery tutorial that follows the same path would be good. Anyways, some quick notes:

The outer loop is in 'by count' mode in feedback mode on both the begin and end blocks. This means its purely a 'repeat the inner process x times' loop.

Eg, create a sphere, put down a new foreach loop, begin block method to 'fetch feedback', end block iteration to 'by count', gather method to 'feedback each iteration'. By default nothing happens. Put a transform sop inside the loop, with transformX as 1.0. The end result is the sphere moved 10 units, because the same geo is fed back into the loop, and moved 1 unit on x each time.

The inner loop begin block is in 'fetch piece or point' mode, end block in 'by pieces or points', 'merge each iteration', 'primitives'. This means it goes through each primitive, applies the inner loop to just that primitive, and accumulates all the results.

The tricky stuff is if you use a clip, the clip is defined in worldspace, not relative to the prim being clipped. As such, the wrangle does some bookkeeping to work out the center of the prim being processed, and clips there. That looked too regular, so I added some randomness. Then it looked too much in one direction, so I choose a random x or z direction for each prim, and the switch sop flips between them based on that random x or z.

That'll all be easier to explain with gifs. :)

 

  • Like 2
Link to comment
Share on other sites

No, your explanation is great.

Looking at your file, I got the foreach loop part right(thanks to the Masterclass tutorial). I could not find a way to make the clip SOP to work. That is when I got lazy and posted here.
My mind was heading in the right direction, but only starting to learn VEX now. I can see how much more control I will have once I understand it better.

It would be awesome if you placed it on your wiki. The format and explanation is easy to follow, and would help me to understand the VEX part.
Thanks for the incredible resource and effort. Your wiki page is permanently open on my pc.

Now, the idea is to see if I can ad two more clip SOPS at -45 and 45, so that it randomly  switches between the 4 angles.

Thanks again.

 

  • Like 1
Link to comment
Share on other sites

Hey @Werner and @mestela

I was surprised to find this thread with the Algorithm stuff I posted a few days ago.

See more at https://www.behance.net/gallery/59061121/Algorithm

I'm glad it got you interested and thankful for people like mestela!

I am also relatively new, so my method might not be very efficient or elegant, but here it goes:

I tried a couple of way but ended up using polysplit with edge loops in order to have local space rather than world space.

I ended up with 2 variations. 1st one splits each primitive with a random number of edge loops (eg. 0-4). Blue loop splits horizontally, green loop splits vertically. I could only get equally spaced splits so in the 2nd example I tried to make it split each primitive a random number but at a random distance (0.2-0.8) each time.

Hope this helps.

 

 

 

1st method.png

2nd method.png

  • Like 4
Link to comment
Share on other sites

Excellent @Dimitris , saw your renders the other day and wondered how you did it. 

Thanks too @mestela for your file and write up on the for loops. Added in some diagonal cuts too to your file. These cuts are also with a for loop that I modified from a file @henderthing was kind enough to let me dig around in a while back. Still trying to get my head around these loops, like a lot of Houdini stuff, it's a bit of a dark art. :rolleyes:

cuts3.jpg

cuts2.jpg

  • Like 3
Link to comment
Share on other sites

Been playing with this ever since prototyping a basic version for a crystal card in "the Last Mimzy"...

It's also fun to build this way in 3D, filling a cube or volume, and flesh out the wireframe that lives on the resulting edges... Will post a version of that when i get some time...
Here are a couple low detail animations from several months ago:

 

 

  • Like 5
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...