Jump to content

Procedurally split faces


DonRomano

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
Link to comment
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
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...