VEX primitive neighbours function

   5169   2   1
User Avatar
Member
3 posts
Joined: 11月 2017
Offline
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!
Edited by altobi - 2019年12月12日 04:17:23
Director / Lead FX TD
User Avatar
Member
3 posts
Joined: 9月 2017
Offline
Thank you thank you thank you.
Why this function is not official?
User Avatar
Member
682 posts
Joined: 9月 2013
Offline
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.
https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
  • Quick Links