Jump to content

Get Neighbors in vex by depth?


Daniel

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

Link to comment
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 4
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...