Jump to content

Random Instances on Particles based on percentage

Recommended Posts

Hello all :)

Examples provided by sidefx.com:

/examples/nodes/sop/copy/StampRandom.otl and ParticleCopyScale.otl
does show use of switch node to switch between instances (say, sphere, cube, tube, torus) which are selected using:

But how can we select random instances based on percentage?
Like we want 80% of spheres, 5% of cubes, 7% of tubes and remaining as torus on the particles


Share this post

Link to post
Share on other sites

I guess you can do channel reference and control the values


Hello sfpar :)

i am learning Houdini, so not much aware of channel referencing :mellow:

Share this post

Link to post
Share on other sites

Here's one way to do it. Rather than use local variables on the copy sop (which I always find a little clunky), I'm using attributes on the grid points directly via a point wrangle.


I've turned off the stamp variable on the copy sop, and typed 'switch' into the attribute stamps field, so it'll look for that attribute on the points instead.


In the point wrangle I:


-create a 'pscale' attribute, just cos I thought the default scale of the shapes was too small to read. :)

-create a random number per point between 0 and 1, and call it 'seed'

-filter that number through a ramp channel to get the ratios you mentioned

-multiply it by 4, because there's a choice of 4 shapes

-convert to an integer, because that's what the stamp parameter expects.


Wrangles with ramps are awesome. The gif should help explain how it works.


The vertical axis represents the shape to choose (ie, 0 to 0.25 is sphere, 0.25 to 0.5 = tube, 0.5 to 0.75 = torus, 0.75-1 = box).


The horizontal axis is the distribution. Because the random number 'seed' should be evenly distributed, if you make 0 to 0.8 all have a y-height of 0, that means 80% of the points will be spheres. The other points in the ramp are set to the other ratios you describe.





  • Like 1

Share this post

Link to post
Share on other sites

Hi mestela :)

Saw your file and your explanation.. Just have 1 word.. Excellent B):)

Thanks mestela :)

have to test the same with heavy particle sim data and will reply again.


And any suggestion how to gain knowledge on using Wrangle nodes ? :mellow:

Because i would not have understood your file if you wouldnt have explained with your written text and gif file.

Share this post

Link to post
Share on other sites

Start with vops, they're a nice intro to vex, and its harder to break things. Eventually you'll realise some operations are easier in vex, and start to write little vex wrangles like the one I did.


Ari made a pretty good intro for 12.5, still valid today (but it's even easier now with the little plug icon, which will make UI sliders for you)



I've been keeping little notes for myself too:







  • Like 1

Share this post

Link to post
Share on other sites

Wow !!! :) Thanks matt :)

The web links are superb !! Simple basic operations to learn the nodes.

Thanks for sharing your study :)

Will check Ari's video as well.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now