# Procedurally split faces

## Recommended Posts

Posted (edited)

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

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 on other sites

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

• 1

##### Share on other sites
Posted (edited)
17 hours ago, eimk said:

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

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);

}

splitFace(p0_, p1_, 0);```

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

##### Share on other sites

Crag Splits Face................crudely.

• 2

##### Share on other sites

+1 to Noobini for the Gauntlet throwback

• 1

## Create an account

Register a new account