Sebastien Rousseau Posted April 21, 2020 Share Posted April 21, 2020 (edited) Hi, I raytrace millions of points on a geometry with vex, I using the fonction intersect() for that and this return me the prim number of the hit surface, but I looking to find a way to find all primitives inside a radius for each point raytraced. their is way to find points inside radius with pcfind() and xyzdist() but I want to limit my search to prim for many reasons. Someone had solved this problem or have an idea ? Edited April 21, 2020 by Sebastien Rousseau Quote Link to comment Share on other sites More sharing options...
anim Posted April 21, 2020 Share Posted April 21, 2020 there is primfind(), but that will find near prims based on bbox intersection while it doesn't guarantee that the prim (e.g. poly) is within the bbox, it can narrow down your searches to just prims whose bbox overlap search bbox 1 Quote Link to comment Share on other sites More sharing options...
konstantin magnus Posted April 21, 2020 Share Posted April 21, 2020 A combination of primfind() and xyzdist() might get you there. // finds primitives within f@pscale radius vector pos_min = v@P - vector(f@pscale); vector pos_max = v@P + vector(f@pscale); int prims_bbox[] = primfind(1, pos_min, pos_max); i[]@prims_sphere = {}; foreach(int pr; prims_bbox){ string grp = itoa(pr); float dist = xyzdist(1, grp, v@P); if(dist <= f@pscale){ append(@prims_sphere, pr); } } nearby_prims.hipnc 1 Quote Link to comment Share on other sites More sharing options...
Sebastien Rousseau Posted April 22, 2020 Author Share Posted April 22, 2020 (edited) Excellent, very fast to compute with primfind, good find! But, unfortunatly, primfind seam to not behave correctly on small bbox value and with large points count. It missing a lot of prim, it's weird. I will think to an other method for picking a group of prims and filter them based on your logic. Put the hipfile if you want to take a look, I added an other temporary solution I did meanwhile but slow and not 100% effective. Primfind.hip Edited April 22, 2020 by Sebastien Rousseau Quote Link to comment Share on other sites More sharing options...
konstantin magnus Posted April 22, 2020 Share Posted April 22, 2020 Hi Sebastien, would it work for you to make the primitives unique first and store the numbers into their points before searching? // Input 0: points to search from // Input 1: points from primitives float radius = chf('radius'); int max_pts = chi('max_points'); int pts[] = pcfind(1, 'P', v@P, radius, max_pts); i[]@prims = {}; foreach(int pt; pts){ int prim_id = point(1, 'prim_id', pt); int found = find(@prims, prim_id); if(found < 0){ append(@prims, prim_id); } } If it does not, eg. because your search radii fall below primitive sizes, maybe try converting your mesh into a volume. int prim; vector uvw; xyzdist(1, v@P, prim, uvw); f@prim_num = float(prim); int pt = addpoint(0, v@P); setpointattrib(0, 'prim_id', pt, prim, 'set'); Again, this is untested. prim_find_via_points.hipnc prim_find_via_volume.hipnc Quote Link to comment Share on other sites More sharing options...
Sebastien Rousseau Posted April 23, 2020 Author Share Posted April 23, 2020 Hi Konstantin, thx you for the help, you gave me some clues on how to approach the problem and finally I found a way to resolve it. very helpfull. I used a fonction of the scatter node, which it scatter a fixed points number by prim based on attribute and store the prims number in the points at the same time. I used an average of prim area and perimeter with a fit fonction for defining min\max points number to scatter on each prims. Then after, used the pcfind fonction. This is fast. 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.