Jump to content

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

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