# FIND NEIGHBORS OF PRIMS HOUDINI

## Recommended Posts

Hi! I want to trace the adjacent triangles of an icosahedron in order to find the average of their values and equalize them.  Any ideas?

##### Share on other sites

Looks like you were on the right track with the use of half edges. You could approach the problem using a primitive wrangle as follows:

```// Array of neighbouring prims
int prim_neighbours[];

// Loop through the primitives vertices
foreach (int vtx; primvertices(0, @primnum))
{
// Get the forward half edge for the vertex
int this_hedge = vertexhedge(0, vtx);

// Only process if a valid half edge
if (hedge_isvalid(0, this_hedge))
{
int equiv_hedge = this_hedge;

// Loop through equivalent half edges and get the neighbouring prims
do
{
equiv_hedge = hedge_nextequiv(0, equiv_hedge);

if (equiv_hedge != this_hedge)
{
// !! Get your attribues here !!
push(prim_neighbours, hedge_prim(0, equiv_hedge));
}

} while (equiv_hedge != this_hedge);
}
}

i[]@neighbours = prim_neighbours;```

Edited by Wooshum
Code mistake
• 1

##### Share on other sites

Thank you very much Dan! Now, I am able to see the list of the neighbours on points but still, I can't see it in the primitives. Do you know what can be wrong?

##### Share on other sites

Are you operating on primitives instead of points? Have attached an example hip.

##### Share on other sites

Oh yes, I keep forgetting that! thanks a lot! It works great!!

##### Share on other sites

another way:

```//primwrangle

int pt = addpoint(0, @P); //center for each primitive
removeprim(0, @primnum, 1); //we just want the new created points```

connect adjacent pieces with type set to adj. points. set radius to correct value to not get too many connections. unit icosahedron would be 0.3 for example

```//pointwrangle

int nb[] = neighbours(0, @ptnum); //this array is the neighours for each point. point numbers correspond to prim numbers```

##### Share on other sites

Dan, one more question. It seems that now I have a list of points and a list of primitives with 5 attributes instead of three.  I guess it is because I found the adjacent points. How can I create a list with the adjacent primitives - triangles?

##### Share on other sites

The number of neigbouring primitives returned is dependent on the number of edges each primitive (as in face/polygon) shares with another primitive. So in your example a Dodecahedron will return 5 neighbours per prim as each face has 5 shared edges. If you start with a Icosahedron you will return 3 neighbours per prim, etc.

Primitives in houdini are n-sided polygons so can have any number of shared edges.

##### Share on other sites
Posted (edited)

Building from myself some hardsurface procedural methods, one issue i have.. Is it possible to filter generated clusters? Merging small cluster which area is too small or area too stretched to the most adjacent cluster?

Off course, it's also hard to know if the cluster has to be removed or not . I mean in mure term of design, the size should not be the only element to take into consideration, but that's off couse another more complex question

Might i ask if that speak to you ?

Thanks you !

________________________________________________________________

Vincent Thomas   (VFX and Art since 1998)
Senior Env and Lighting  artist & Houdini generalist & Creative Concepts

Edited by vinyvince

##### Share on other sites

Hi Vincent,

this could be what you mean:

• 1

##### Share on other sites

Thanks @konstantin magnus. Totalyl agree with you on your comment, sadly here the clustering is not based on the voronoi diagram, i know already these tricks but i can't apply it here. Even with clean geo, it could creat some small pocket areas you may not want.

Basically how i see will be to loop to eachpiece, if  the area or stretch value is under a certain value, look around (point cloud ) to find the neighbour cluster, pick the best one, and change the cluster attribute value of the considering unwanted area.

I guess there is not need to shift the cluster value as some will be missing in the total amount.

Now will be to vexify this method. Sam thing coudl be apply to merge small group actually.

A second  probably more tricky point is,  how to define "stretched area"?

One with quite different ratio? Not easy in a non planar space... At least when you have an artistic approach

## Create an account

Register a new account