Jump to content
Sign in to follow this  
cgcris

[SOLVED] VEX - addpoint randomly on geo

Recommended Posts

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 by cgcris

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 by holycause
  • Like 1

Share this post


Link to post
Share on other sites

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

 

 

 

 

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
Sign in to follow this  

×