Jump to content
DonRomano

Procedurally split faces

Recommended Posts

Hey guys, it's me again, I have another "complicated" question : is it possible to procedurally split faces with vex ?
 

I'm modeling roofs, and I needed to split the top faces to get to and be able to get a triangle shape (by translating the created point on the Y axis). The edge divide sop makes a wonderful job, but sometimes it doesn't cut faces properly (it's very rare but very annoying).

bug.thumb.png.f12965266fa492fb3589530ad84452d6.png

For now, I detect the bugged faces by counting the vertices on each face, and if one has 6 vertices then it's a bugged face; but I don't know how to split them procedurally. One method that came to my mind was making a python script that creates a polysplit node for each face with the split coords but it's not very efficient..

If anyone has an idea !

 

Cheers,

 

edit : added a screenshot for a better explanation!

Edited by DonRomano

Share this post


Link to post
Share on other sites
17 hours ago, eimk said:

There's probably loads of ways to do this, but here's one:

split_polys.hipnc

Thanks for the answer, very cool, didn't thought about that as I was blocked on just fixing the non-cutted faces and totally forgot that I could split all the faces like this instead of using the edge divide. Anyway, I found a solution to fix this, the code goes into a detail wrangle in a for loop over each bugged face :

int pts[] = findattribval(0, "point", "bugged", 1);

i[]@pts = pts;

int p0_ = pts[0];
int p1_ = pts[1];
    
int in(int target; int array[])
{
    //iterate through list to find if a item is in or not
    int found = 0;  

    foreach(int a; array)
    {
        if(target == a) found = 1;
        else found = 0;
    }
    
    return found;
}


void splitFace(int p0_, p1_, prim0)
{
    // create neighbours pairs
    int p0[] = neighbours(0, p0_);
    int p1[] = neighbours(0, p1_);
    
    int x0_ = p0[0];
    int y0_ = p0[1];
    int x1_ = p1[0];
    int y1_ = p1[1];
    
    int x0[] = neighbours(0, x0_);
    int y0[] = neighbours(0, y0_);
    int x1[] = neighbours(0, x1_);
    int y1[] = neighbours(0, y1_);
    
    // create arrays
    int array1[], array2[];
    
    //array 1
    if(in(x0_, y1) == 1)
    
    {
        setcomp(array1, x0_, 0);
        setcomp(array1, y1_, 1);
        setcomp(array1, p1_, 2);
        setcomp(array1, p0_, 3);
    }
    
    if(in(x0_, x1) == 1)
    {
        setcomp(array1, x0_, 0);
        setcomp(array1, x1_, 1);
        setcomp(array1, p1_, 2);
        setcomp(array1, p0_, 3);
    }
    
    //array 2
    if(in(y1_, y0) == 1)
    {
        setcomp(array2, p0_, 0);
        setcomp(array2, p1_, 1);
        setcomp(array2, y1_, 2);
        setcomp(array2, y0_, 3);
    }
    
    if(in(y0_, x1) == 1)
    {
        setcomp(array2, p0_, 0);
        setcomp(array2, p1_, 1);
        setcomp(array2, x1_, 2);
        setcomp(array2, y0_, 3);
    }
        
    
    setdetailattrib(0, "a1", array1, "set"); //debug
    setdetailattrib(0, "a2", array2, "set"); //debug
    
    // create polys
    removeprim(0, prim0, 0);
    addprim(0, "poly", reverse(array1));
    addprim(0, "poly", reverse(array2));
    
}

splitFace(p0_, p1_, 0);

 

Edited by DonRomano
I've made my own find function because the base find() function seems buggy in if statements
  • Like 1

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

×