# vex return list of prims numbers inside radius

## Recommended Posts

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 by Sebastien Rousseau

##### Share on other sites

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

##### Share on other sites

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

##### Share on other sites

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 by Sebastien Rousseau

##### Share on other sites

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
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);
setpointattrib(0, 'prim_id', pt, prim, 'set');```

Again, this is untested.

prim_find_via_points.hipnc

prim_find_via_volume.hipnc

##### Share on other sites

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.

## Create an account

Register a new account