Jump to content

Random Instances on Particles based on percentage


sultan

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:
fit01(rand($PT),0,(opninputs("../switch1")))

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
:mellow:

 

Link to comment
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.

 

stamp_ratio.hipnc

 

post-7292-0-01027000-1441633907_thumb.gi

  • Like 1
Link to comment
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.

Link to comment
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:

 

http://www.tokeru.com/mayawiki/index.php?title=HoudiniVex

http://www.tokeru.com/mayawiki/index.php?title=Houdini_Vops

http://www.tokeru.com/mayawiki/index.php?title=Houdini

 

-matt

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