cgcris Posted July 12, 2016 Share Posted July 12, 2016 (edited) Hi guys, I am trying to replicate the scatter behaviour, when plugin something like a grid. Using VEX, what's the best way of adding a point on a geometry randomly? Thanks, Cris Edited July 15, 2016 by cgcris Quote Link to comment Share on other sites More sharing options...
animatrix Posted July 12, 2016 Share Posted July 12, 2016 You can pre-generate N points using Point Generate SOP, then generate a random integer from 0 to nprims(1)-1 using something like ptnum and a random position (using another seed) and then feed these into primuv VEX function for the second input. This will move your points randomly over a surface. Quote Link to comment Share on other sites More sharing options...
holycause Posted July 13, 2016 Share Posted July 13, 2016 (edited) set your wrangle in detail mode and connect your geo to the second input int prims = nprimitives(1); int count = chi("count"); float seed = clamp(chf("seed"),1E-3, 1E8); for(int i=0; i<count; i++){ float rr = random(prims*i*seed); int prnum = int(rr*prims); float u,v; u = rand(i*seed); v = rand(i*rr*seed); vector pos = primuv(1, "P", prnum, set(u,v,0)); addpoint(0, pos); } just noticed that I wasn't using the correct variable to initialize my for loop It s fixed now ^^ Edited July 13, 2016 by holycause 1 Quote Link to comment Share on other sites More sharing options...
cgcris Posted July 13, 2016 Author Share Posted July 13, 2016 Hi Guys, Thanks a lot for your replies, now looking at the code Ruben. There is one line that doesnt work, I am guessing is a typo float rr = random(prims*i*seed); // should be float rr = rand(prims*i*seed); weirdly when using random the value doesn't update when changing the seed. Thanks for your help putting this together! Best, Cris Quote Link to comment Share on other sites More sharing options...
animatrix Posted July 14, 2016 Share Posted July 14, 2016 Here is an implementation I put together in a few mins: https://www.dropbox.com/s/1hqlv5n5nf3gk6c/vex_vs_scatter.hip?dl=0 It takes face area into account for even distribution. It's ~8 times faster on my PC than the SESI's Scatter SOP (no relaxing, no copying of attributes). So the more cores you have the faster it should get. 4 Quote Link to comment Share on other sites More sharing options...
cgcris Posted July 15, 2016 Author Share Posted July 15, 2016 Nice one pusat, will enjoy going through your example!! 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.