Jump to content

Sorting randomized prim order on a unknown incoming shapes

Recommended Posts

Top level goal is that I want to take incoming objects that are quads and triangulate each polygon, but alternating direction of the triangulation from one poly face to the next.

This is easy for clean meshes generated in houdini. My issues is I'm importing a wide variety of objects from other DCCs and often the primid and vert order is totally randomized. I have tried to get a perfectly clean selection of alternating faces by all kinds of sort methods, I tried and failed to proceedurally generate a uv and set the prim id's based on the uvs, and nothing seems to work.

Imagine a flared cylinder for the simplest example but each vert and prim id totally randomized, how would you get a group defined of every other prim like a checkerboard?



Link to comment
Share on other sites


If your geometry's topology is uniform without poles unlike the one I am using, here is one way you could do it:


function int [ ] getPrimNeighbours ( int input; int pr )
    int allprims [ ] = { };
    int hedge = primhedge ( input, pr );
    for ( int i = 0; i < primvertexcount ( input, pr ); ++i )
        for ( int f = 0; f < hedge_equivcount ( input, hedge ); ++f )
            int hedgeNext = hedge_nextequiv ( input, hedge );
            int primindex = hedge_prim ( input, hedgeNext );
            if ( primindex != pr )
                append ( allprims, primindex );
            hedge = hedgeNext;
        hedge = hedge_next ( input, hedge );

    return allprims;

int firstprim = chi("first_prim");
setprimgroup ( 0, "prims1", firstprim, 1 );

int allprims [ ] = array ( firstprim );
int lastprims [ ] = array ( firstprim );

int index = 1;
int primcount = -1;
while ( primcount != 0 )
    string groupname = index % 2 ? "prims2" : "prims1";
    int newprims [ ] = { };
    foreach ( int pr; lastprims )
        int connected [ ] = getPrimNeighbours ( 0, pr );
        foreach ( int c; connected )
            if ( find ( allprims, c ) < 0 )
                append ( allprims, c );
                append ( newprims, c );
    lastprims = newprims;
    foreach ( int pr; newprims )
        setprimgroup ( 0, groupname, pr, 1 );
    primcount = len ( newprims );


  • Like 1
Link to comment
Share on other sites

Thanks a ton! I really appreciate you sharing this!

Is there any way to leverage this to understanding of what's connected to unify the direction that a divide operation would be applied in? My goal is to turn quads into alternating triangles like below:



Your vex helps me isolate every other poly even if the primids are randomized, but not sure how to make sure the divide orientation is uniform... likely should be its own thread but figured i'd ask:



Edited by NoSOPforStupidity
Link to comment
Share on other sites

16 minutes ago, animatrix said:

Did you try Reverse SOP -> Shift -> U Offset = 1 for one of the primitive groups, and then adding a Divide SOP after?

I just did and that works to flip them! unfortunately my issue is that the orientation of the divide is not unified for the group to begin with. I think I need help unifying the direction for all of the prims on the object, and then im good to reverse the direction for just one of the prim groups.

Edited by NoSOPforStupidity
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.

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...