-
COFFEE script modification for 3 sided polygons (or failing that a quick way to delete all triangular polygons at once)
Hello folk who are smarter than I.
I am using Douwe’s d_Polysize effector to populate a mograph cloner onto a complicated (but flat) plane – the face of the plane is set to regular grid quads. But at the borders there are triangles.
Its working really well for the quads, however as all the border triangles are different sizes its screwing the calculations there and creating undesireable results.
So what I want to achieve is to tell the script if it finds a 3 sided polygon, then it should kill this clone or set it’s size to 0.
Thanks in advance!
Below is the script:
map(input, inMin, inMax, outMin, outMax)
{
var inrange;
if((inMax-inMin) != 0) { inrange = (input-inMin)/(inMax-inMin); }
else inrange = 0;
return inrange * (outMax-outMin) + outMin;
}main(doc,op)
{
var md = GeGetMoData(op);
if (!md) return false;
var cnt = md->GetCount();
var marr = md->GetArray(MODATA_MATRIX);
var fall = md->GetFalloffs();
var cloner = md->GetGenerator();
var obj = cloner#MG_OBJECT_LINK;
var polycount = obj -> GetPolygonCount();
var poly = obj -> GetPolygons();
var points = obj -> GetPoints();
var ud_scale_factor = op#ID_USERDATA:1;
var ud_min_scale = op#ID_USERDATA:2;
var ud_max_scale = op#ID_USERDATA:3;
var i, scale, map_surface;
var hi_pol_size = 0;
var lo_pol_size = 9999999999999999999999999999;
var part_1,part_2,a,b,c,d,e,f,s;
var area = new(array,100000);
var arr_A = new(array,100000);
var arr_B = new(array,100000);
var arr_C = new(array,100000);
var arr_D = new(array,100000);for (i = 0; i < (polycount*4); i++) {
if (i % 4 == 0) arr_A[i/4] = points[poly[i]];
if (i % 4 == 1) arr_B[i/4] = points[poly[i]];
if (i % 4 == 2) arr_C[i/4] = points[poly[i]];
if (i % 4 == 3) arr_D[i/4] = points[poly[i]];
}for (i = 0; i < polycount; i++) {
a = vlen(arr_A[i] – arr_B[i]);
b = vlen(arr_B[i] – arr_C[i]);
c = vlen(arr_A[i] – arr_C[i]);
s = (a+b+c)/2;
part_1 = sqrt (s*(s-a)*(s-b)*(s-c));
d = vlen(arr_A[i] – arr_C[i]);
e = vlen(arr_A[i] – arr_D[i]);
f = vlen(arr_D[i] – arr_C[i]);
s = (d+e+f)/2;
part_2 = sqrt (s*(s-d)*(s-e)*(s-f));
area[i] = part_1 + part_2;if (area[i]< lo_pol_size){ lo_pol_size = area[i]; }
if (area[i]> hi_pol_size){ hi_pol_size = area[i]; }
}for (i = cnt – 1; i >= 0; –i)
{
if (!area[i]){ area[i]= lo_pol_size; } // line for yader. in surface mode if clones > polys
map_surface = map(area[i], lo_pol_size, hi_pol_size, ud_min_scale, ud_max_scale);
scale = map_surface * (ud_scale_factor) ;marr[i]->SetV1(marr[i]->GetV1()*scale);
marr[i]->SetV2(marr[i]->GetV2()*scale);
marr[i]->SetV3(marr[i]->GetV3()*scale);
}
md->SetArray(MODATA_MATRIX, marr, true);
return true;
}