//catenary chaine
//y=2*\cosh(x/2)cos
float a = ch("a");
float normX = fit01(float(@ptnum)/float(@numpt),-1,1);
@P.y += a*cosh(normX/a);
float offset= a *cosh(-1/a);
@P.y-=offset;
int pointProche [] = nearpoints(0,@P,ch("dist"),5);
removeindex(pointProche,0);
int maxIt = len(pointProche);
foreach (int i ;pointProche){
vector oPt = point(0,"P",i);
if (@P.x==oPt.x && @P.y==oPt.y || @P.x==oPt.x && @P.z==oPt.z || @P.y==oPt.y && @P.z==oPt.z ){
addprim(0,"polyline",@ptnum,i);
}
}
// dans un pt wrangle dans un solver
//mouvement
v@P+=normalize(v@dir)*0.01;
//intersect
vector dir,pos,uvw,nPtpos,bias,tempDir;
int newPt,intersect;
dir = normalize(v@dir)*0.01;
intersect = intersect(0,@P,dir,pos,uvw);
if (intersect>=0 && i@source!=intersect){
@group_mouv=0;
// add newpt
v@P=pos;
bias =fit01(rand(@ptnum),0.1,0.9);
nPtpos = lerp(v@startPos,v@P,bias);
//tempDir = set(v@dir.z,0,v@dir.x);
tempDir = normalize(cross(normalize(v@dir),{0,1,0}));
//tempDir = {1,0,0};
//create new point
int newStart = addpoint(0,nPtpos);
int mouvingPt = addpoint(0,nPtpos);
addprim(0,"polyline",newStart,mouvingPt);
//set attrip on new mouving points
setpointgroup(0,"mouv",mouvingPt,1,"set");
setpointattrib(0,"dir",mouvingPt,tempDir,"set");
setpointattrib(0,"startPos",mouvingPt,nPtpos,"set");
setpointattrib(0,"source",mouvingPt,i@source,"set");
}
//dans un autre wrangle appres
float rand;
vector dir;
//ortho dir
rand = floor(fit01(rand(@ptnum+1),0,2));
rand = fit(rand,0,1,-1,1);
if (rand(@ptnum+3)>=0.5)
dir = set(rand,0,0);
else
dir = set(0,0,rand);
v@dir = dir;
//pt wrangle
vector dir,pos;
float rand;
int newPt;
// init parameter
@group_mouv = 1;
v@startPos = v@P;
//ortho dir
rand = floor(fit01(rand(@ptnum+1),0,2));
rand = fit(rand,0,1,-1,1);
if (rand(@ptnum+3)>=0.5)
dir = set(rand,0,0);
else
dir = set(0,0,rand);
v@dir = dir;
//createline
pos = point(0,"P",@ptnum);
newPt=addpoint(0,pos);
addprim(0,"polyline",@ptnum,newPt);
//dans un autre wrangle apres
int prims[] = pointprims(0,@ptnum);
i@source = prims[0];
int numPts [] = primpoints(0,@primnum);
float lum[];
int indexSort[];
int id[];
vector color[];
float demarage = ch("demarage");
float stop = ch("stop");
int selection = 0;
foreach(int numPt; numPts){
vector ptColor = point(0,"Cd",numPt);
float ptLum = avg(ptColor);
if (selection== 0 && ptLum>demarage){
selection = 1;
}
if (selection == 1){
//remplir listes
push(lum,ptLum);
push(color,ptColor);
push(id,numPt);
}
if (selection == 1 && ptLum<stop){
selection = 0;
//trier listes
indexSort = argsort(lum);
//appliquer la couleur
setpointattrib(0,"Cd",numPt,{0,1,0},"set");
foreach(int tempId; id){
int tempIndex= pop(indexSort);
vector tempColor = color[tempIndex];
setpointattrib(0,"Cd",tempId,tempColor,"set");
}
// ma soluce il faut reverse indexSort
//foreach(int index ;int val; indexSort){
//vector tempColor = color[val];
//int tempId = id[index];
//setpointattrib(0,"Cd",tempId,tempColor,"set");
//}
//vider listes
resize(lum,0);
resize(id,0);
resize(color,0);
resize(indexSort,0);
}
}
int numPts [] = primpoints(0,@primnum);
float lum[];
int indexSort[];
int id[];
vector color[];
float demarage = ch("demarage");
float stop = ch("stop");
int selection = 0;
foreach(int numPt; numPts){
vector ptColor = point(0,"Cd",numPt);
float ptLum = avg(ptColor);
push(lum,ptLum);
push(color,ptColor);
push(id,numPt);
//trier listes
indexSort = argsort(lum);
foreach(int tempId; id){
int tempIndex= pop(indexSort);
vector tempColor = lum[tempIndex];
setpointattrib(0,"Cd",tempId,tempColor,"set");
}
}
vector posMin,posMax,midPt,newPtTop,newPtBot,sideC,sideD,sideE,sideF;
vector pos[];
float dir = rand(ch("seed"));
int points [] = primpoints(0,0);
foreach (int pt; points){
vector posA = point(0,"P",pt);
push(pos,posA);
}
posMin = min(pos);
posMax = max(pos);
midPt = posMin+(posMax-posMin)*0.25;
removeprim(0,0,1);
if (dir > 0.5 ){
newPtTop = set(midPt.x,0,posMin.z);
newPtBot = set(midPt.x,0,posMax.z);
sideC = posMin;
sideD = set(posMin.x,0,posMax.z);
sideE = set(posMax.x,0,posMin.z);
sideF = posMax ;
}
else {
newPtTop = set(posMin.x,0,midPt.z);
newPtBot = set(posMax.x,0,midPt.z);
sideC = posMin;
sideD = set(posMax.x,0,posMin.z);
sideE = set(posMin.x,0,posMax.z);
sideF = posMax ;
}
//addpoint(0,midPt);
int sideA = addpoint(0,sideC);
int sideB = addpoint(0,sideD);
int bot = addpoint(0,newPtBot);
int top = addpoint(0,newPtTop);
int sideEpt = addpoint(0,sideE);
int sideFpt = addpoint(0,sideF);
addprim(0,"poly",sideA,sideB,bot,top);
addprim(0,"poly",sideEpt,sideFpt,bot,top);
i@ok = @numprim;
int subdiv(int numprim;){
int num = numprim;
int it = chi("it");
for (int prim = 0 ; prim<num; prim++){
vector posMin,posMax,midPt,newPtTop,newPtBot,sideC,sideD,sideE,sideF,diag;
vector pos[];
float dir ;
int points [] = primpoints(0,prim);
foreach (int pt; points){
vector posA = point(0,"P",pt);
push(pos,posA);
}
posMin = min(pos);
posMax = max(pos);
midPt = posMin+(posMax-posMin)*fit01(rand(prim+231+it),0.01,0.98);
diag = posMax-posMin;
if (abs(diag.z)>abs(diag.x)){
dir = 0.0;
}
else {
dir = 1.1;
}
removeprim(0,prim,1);
if (dir > 0.5 ){
newPtTop = set(midPt.x,0,posMin.z);
newPtBot = set(midPt.x,0,posMax.z);
sideC = posMin;
sideD = set(posMin.x,0,posMax.z);
sideE = set(posMax.x,0,posMin.z);
sideF = posMax ;
}
else {
newPtTop = set(posMin.x,0,midPt.z);
newPtBot = set(posMax.x,0,midPt.z);
sideC = posMin;
sideD = set(posMax.x,0,posMin.z);
sideE = set(posMin.x,0,posMax.z);
sideF = posMax ;
}
//addpoint(0,midPt);
int sideA = addpoint(0,sideC);
int sideB = addpoint(0,sideD);
int bot = addpoint(0,newPtBot);
int top = addpoint(0,newPtTop);
int sideEpt = addpoint(0,sideE);
int sideFpt = addpoint(0,sideF);
addprim(0,"poly",sideA,sideB,bot,top);
addprim(0,"poly",sideEpt,sideFpt,bot,top);
}
int output = num*2;
return output;
}
int out = subdiv(@numprim);
function int subdiv(int numprim;){
int num = numprim;
int it = chi("it");
//for each prim
for (int prim = 0 ; prim<num; prim++){
//declaration
vector posMin,posMax,midPt,newPtTop,newPtBot,sideC,sideD,sideE,sideF,diag;
vector pos[];
float dir ;
int points [] = primpoints(0,prim);
//recup les points de la prim courrente dans un tableau
foreach (int pt; points){
vector posA = point(0,"P",pt);
push(pos,posA);
}
//recup min et max
posMin = min(pos);
posMax = max(pos);
midPt = posMin+(posMax-posMin)*fit01(rand(prim+231+it),0.1,0.9);
// calc la direction
diag = posMax-posMin;
if (abs(diag.z)>abs(diag.x)){
dir = 0.0;
}
else {
dir = 1.1;
}
// removeprim
removeprim(0,prim,1);
// calcul des position voulues
if (dir > 0.5 ){
newPtTop = set(midPt.x,0,posMin.z);
newPtBot = set(midPt.x,0,posMax.z);
sideC = posMin;
sideD = set(posMin.x,0,posMax.z);
sideE = set(posMax.x,0,posMin.z);
sideF = posMax ;
}
else {
newPtTop = set(posMin.x,0,midPt.z);
newPtBot = set(posMax.x,0,midPt.z);
sideC = posMin;
sideD = set(posMax.x,0,posMin.z);
sideE = set(posMin.x,0,posMax.z);
sideF = posMax ;
}
//creation des points
int sideA = addpoint(0,sideC);
int sideB = addpoint(0,sideD);
int bot = addpoint(0,newPtBot);
int top = addpoint(0,newPtTop);
int sideEpt = addpoint(0,sideE);
int sideFpt = addpoint(0,sideF);
//creation des polygones
addprim(0,"poly",sideA,sideB,bot,top);
addprim(0,"poly",sideEpt,sideFpt,bot,top);
}
int output = num*2;
return output;
}
int out = subdiv(@numprim);
VEX