Jump to content

[SOLVED] VEX - addpoint randomly on geo


cgcris

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

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

 

 

 

 

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...