rand() doesn't work inside foreach node

   2642   3   1
User Avatar
Member
479 posts
Joined: Dec. 2009
Offline
I want to randomize the “orientation” of the L-shape block for each patch of a grid surface. The rand() function is used inside a foreach node to decide randomly which of the four corners of a polygon is used as pivot point for the transform node based on the surface ID of a given polygon.

However, I can't get the random form as expected.

Can you kindly advise?

Thanks!

Attachments:
para_urban_v003.hipnc (84.1 KB)
01.PNG (124.4 KB)
02.PNG (14.9 KB)

User Avatar
Member
25 posts
Joined: Oct. 2012
Offline
Since you are looping through each primitive inside the foreach I don't see why you need a separate ID attribute.
For the randomness you could just use the iteration number: rand(stamp(“..”,“FORVALUE”,0)).
User Avatar
Member
479 posts
Joined: Dec. 2009
Offline
Thanks, Doodlez!

I updated my method, too. So, we have two ways to do it via the hscript in the “ctl1” node to drive randomness:

1.
int(rand(prim(“../each1”, 0, “id”, 0)+$F)*10)%4
… which gives you a random integer between 0 and 3 for each frame.

or

2.
int(rand(stamp(“..”,“FORVALUE”,0)+$F)*10)%4


Pls kindly advise if there are other efficient way to do this.

Thanks, again!
User Avatar
Member
25 posts
Joined: Oct. 2012
Offline
I'm not sure which is more efficient but if that is important you should look at getting rid of the cookie nodes unless you are going to use them to create more varied shapes then just L blocks.

Maybe it is intended but with your current expression you have a bias towards the first two possibilities.
  • Quick Links