Jump to content
Sign in to follow this  
monomind

Get all points on a prim?

Recommended Posts

I have a grid, and I scatter points on it using the scatter sop.

I want to access the number of scattered points per each prim of the grid.

What's the most efficient way to achieve this?

My current workaround contains a foreach loop, that creates "bounds" using the bounds sop per each prim, and groups scattered points using the "Bounding Object" bounding type. Then I write the count of points as a primitive attribute using a wrangle. This is very slow - would love to know how else to achieve this..

Share this post


Link to post
Share on other sites

on the scatter, under Output atributes, turn on Prim Num Attribute

then use a primitivewrangle, plug the grid into the first and scatter into second input:

i@scattered = findattribvalcount(1, "point", "sourceprim", @primnum);

 

  • Thanks 1

Share this post


Link to post
Share on other sites

Wow, this is amazing. What if I want to access the average @P of all points on the prim?

 

Share this post


Link to post
Share on other sites

same wrangle, add following lines of code

vector avg = {0,0,0};
for(int i = 0; i!=@scattered; ++i)
{
    int pt = findattribval(1, "point", "sourceprim", @primnum, i);
    vector p = point(1, "P", pt);
    avg += p;
}
avg /= float(@scattered);
v@avgP = avg;

 

  • Like 1

Share this post


Link to post
Share on other sites

With a little modification and correction, seems to work perfectly.

Thank you sir!

int scattered = findattribvalcount(1, "point", "sourceprim", @primnum);

vector avg = {0,0,0};
for(int i = 0; i<scattered; i++)
{
    int pt = findattribval(1, "point", "sourceprim", @primnum, i);
    vector p = point(1, "P", pt);
    avg += p;
}
avg /= float(scattered);
v@avgP = avg;

 

  • Like 1

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  

×