Jump to content
NoSOPforStupidity

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?

 

Thanks!

Share this post


Link to post
Share on other sites

Hi,

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

image.thumb.png.d0da9245e07cacfd0e403da287f4698f.png

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 );
    ++index;
}

 

  • Like 1

Share this post


Link to post
Share on other sites
Posted (edited)

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:

2022-05-05_09h56_21.thumb.png.4ae34e7d74bebdfdcf5fdb988ded2651.png

 

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:

2022-05-05_09h58_06.thumb.png.6e655c5722b2f5e75d70c4895fa55125.png

 

Edited by NoSOPforStupidity

Share this post


Link to post
Share on other sites
Posted (edited)

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

Edited by animatrix

Share this post


Link to post
Share on other sites
Posted (edited)
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

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

×