Microbot – David Fuhrer

David Fuhrer - Houdini 3D Generalist

Moore Neighborhood

One problem with polyneighbour() function in VEX it only finds neighbours based on the hedge. However when you want the moore neighborhood which there is no function for.

https://en.wikipedia.org/wiki/Moore_neighborhood
Also want to share how to expose outer code (header file) in a wrangle so we can write custom functions.

Exposing Outer Code

To expose the outer code. Unlock the Attribute Wrangle and go to Edit Parameter Interface…

Dive inside the Wrangle 2 levels until you reach the snippet vop. On it you will find the Outer Code Parameter (in one line)

Expose the Outer Code by Dragging the parameter into the Edit Parameter Interface. Also Change to Multi-line String and Language to VEX

In the Outer code we can now make our functions:

int[] neighbourM(const int opname; const int primnum)
{
    int moore_neighbours[] = polyneighbours(opname, primnum);
    
    int prims[];
    int temp_array[];
    int point_array[] = primpoints(0, primnum);
    
    foreach (int num; point_array) {
        prims = pointprims(0, num);
        foreach (int prim; prims) {
            if(prim != moore_neighbours[0] && prim != moore_neighbours[1]  && prim != moore_neighbours[1]  && prim != moore_neighbours[2]  && prim != moore_neighbours[3] && prim != primnum)
            {
                append(temp_array, prim);
            } 
        }
    }
    append(moore_neighbours, temp_array);
    
    return sort(moore_neighbours);
}

After that we can call the function like this, you can run this in detail mode so it only runs once.


i[]@m = neighbourM(0, 43);

//As test we just color the surrounding Prims:
foreach(int a; @m) {
    setprimattrib(0, "Cd", a, 0);
}

The results should look like this:

Alternative you can store the function code in a external file in one of your houdini environments. Then load it by #include <filename.h>

Next Post

Previous Post

© 2025 Microbot – David Fuhrer