monomind Posted November 9, 2019 Share Posted November 9, 2019 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.. Quote Link to comment Share on other sites More sharing options...
3dome Posted November 9, 2019 Share Posted November 9, 2019 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); 1 Quote Link to comment Share on other sites More sharing options...
monomind Posted November 9, 2019 Author Share Posted November 9, 2019 Wow, this is amazing. What if I want to access the average @P of all points on the prim? Quote Link to comment Share on other sites More sharing options...
3dome Posted November 9, 2019 Share Posted November 9, 2019 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; 1 Quote Link to comment Share on other sites More sharing options...
monomind Posted November 9, 2019 Author Share Posted November 9, 2019 seems to show {0,0,0} for each avgP Quote Link to comment Share on other sites More sharing options...
monomind Posted November 9, 2019 Author Share Posted November 9, 2019 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; 1 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.