Jump to content
Daniel

Get Neighbors in vex by depth?

Recommended Posts

I'd like to get a list of all connected points to my current point and the vex command "neighbors" does that.  But I'd also like the option to grow this selection to grab the next ring of points.. the same as what the "Group Expand" node does when you increase "steps".  The group expand is too slow as I need to do this for every point on my geometry.  I'm about to embark on a nested loop using the "neighbors" command but it's a bit mind bending and curious if anyone's done that before so I don't have to!  

 

Thanks 

D

Share this post


Link to post
Share on other sites

Hi,

You can do it like this:

function int [ ] getPointNeighbours ( int geo; int ptindex; int depth; int accumulate )
{
    int pts [ ] = array ( ptindex );
    int lastpts [ ] = pts;
    
    for ( int i = 0; i < depth; ++i )
    {
        int newpts [ ] = { };
        foreach ( int pt; lastpts )
        {
            int connected [ ] = neighbours ( geo, pt );
            foreach ( int c; connected )
            {
                if ( find ( pts, c ) < 0 )
                {
                    append ( pts, c );
                    append ( newpts, c );
                }
            }
        }
        lastpts = newpts;
    }
    
    if ( accumulate )
        return pts;
    else
        return lastpts;
}

int pts [ ] = getPointNeighbours ( 0, 42, chi("depth"), chi("accumulate") );
foreach ( int pt; pts )
    setpointgroup ( 0, "pts", pt, 1 );

 

  • Like 3

Share this post


Link to post
Share on other sites

Amazing! thanks for this.  I'll give it a try

D

Share this post


Link to post
Share on other sites

BTW this works exactly as I described.  Thanks !

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×