Search - User list
Full Version: VEX primitive neighbours function
Root » Technical Discussion » VEX primitive neighbours function
altobi
Hi wizards,

Here's a VEX function to get primitive neighbours either by shared points or by shared edges. Use the type function input for the two different methods (0 points, 1 edges);

function int []primneighbours (int geometry; int prim; int type)
{

    int primPts[] = primpoints(geometry, prim);
    int nearPrims[];
    int sharedPrims[];
    
    // Find primitives attached to the input primitive-points
    foreach(int num; int pt; primPts)
    {
        int ptPrims[] = pointprims(geometry, pt);
        
        foreach(int num1; int ptPrim; ptPrims)
        {
            int used = 0;
            
            foreach(int num2; int usedPrim; nearPrims)
            {
                if(usedPrim == ptPrim)
                {
                    used = 1;
                }
            }
            
            if(used == 0)
            {
                append(nearPrims, ptPrim);
            }
        }
    }
    
    // Find primitives sharing the two or more points with the input primitive
    foreach(int num3; int nearPrim; nearPrims)
    {
        int tempPrimPts[] = primpoints(geometry, nearPrim);
        int similarPts = 0;
        
        foreach(int num4; int tempPrimPt; tempPrimPts)
        {
            foreach(int num5; int primPt; primPts)
            {
                if(tempPrimPt == primPt)
                {
                    similarPts++;
                }
            }
        }
        
        if(similarPts > 1)
        {
            append(sharedPrims, nearPrim);
        }
    }
    
    // Return based on input type
    if(type > 0)
    {
        return sharedPrims;
    }
    else
    {
        return nearPrims;
    }
}


Use the function like this (outside the function itself):
int neigh[] = primneighbours(0, @primnum, 1);


Grouping neighbours example:

int neigh[] = primneighbours(0, 70, 1);
foreach(int num; int prim; neigh)
{
    setprimgroup(0, "nearPrims", prim, 1, "set");
}


Enjoy!
AbePoppy
Thank you thank you thank you.
Why this function is not official?
Konstantin Magnus
There is a built-in function called polyneighbours:
https://www.sidefx.com/docs/houdini/vex/functions/polyneighbours.html [www.sidefx.com]

i[]@prims_nb = polyneighbours(0, i@primnum);

Also, the group expand SOP has similar and more functionality and can be called with Python verbs apparently.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB