Tuesday, April 6, 2021

My production vex snippets

 //Volumesample


float dist = volumesample(1,0,@P);

vector grad = volumegradient(1,0,@P);


if(dist<chf('val')){

    //removepoint(0,@ptnum);

    @Cd = set(1,0,0);

    }


//=====================================


//Antialias noise

#include <voptype.h>

#include <voplib.h>

float amp = chf('amplitude');

vector freq = chv('freq');

vector offset = chv('offset');

float roughness = chf('roughness');


vector noise = vop_fbmNoiseVV(@P * freq - offset, roughness, 8, "noise")*amp;


v@N = v@v+noise;


//=====================================


//Delete by value

if(@P.y<chf('val')){

    removepoint(0,@ptnum);

    }


//=====================================


//Delete by index

vector bbox = relbbox(0,@P);

vector size = getbbox_size(0);

int max_index = find(set(size), max(size));

@Cd = chramp("clr_ramp",bbox[max_index]);


//=====================================


//Displace along normal

@P += @N*chf('push');


//=====================================


 

 

//Noise fade

if(@Frame>fit01(@noise,chf("fade_start"),chf("fade_end"))){

    removepoint(0,@ptnum);

    } 

//=====================================


//Random pscale

i@pid = @ptnum;

@pscale = fit01(rand(@pid*chf('seed')),chf('min_val'),chf('max_val'));


//=====================================


//Center N direction


vector pos = point(1,"P",0);

vector mid = normalize(pos-@P);

float adist = distance(@P,pos);

float dist = fit(adist,1,7,chf('min_dist'),chf('max_dist'));


@N = slerp(@N,mid,chf("bias"))*dist;


//=====================================



//Curve color ramp


float ramp = @ptnum/ float (@numpt-1);

@Cd = chramp("ramp",ramp);


//=====================================


//Radial push

int maxpts = chi("max_points");

float maxdist = chf("max_dist");

 

int n[] = nearpoints(1,@P,maxdist,maxpts);

 

foreach(int pt; n){

    vector pos = point(1,"P",pt);

    int id_match = point(1,"cid",pt);

    float dist = distance(pos,@P);

    @dist = dist;

    if(id_match==@cid && dist>=0){

        @N = normalize(pos-@P);

        @P += @N * min(chf("push")*pow(fit(dist,0,0.2,0,1),1.25),dist);

        }

 

//=====================================

//Curve lookup

float radius = chf("radius");

int maxpt = chi("maxpt");


int closepts[] = pcfind(1,"P",@P,radius,maxpt);

i[]@test = closepts;


foreach(int pt; closepts){

    float int_radius= chf("int_radius");

    int int_maxpt= chi("int_maxpt");

    int h = pcopen(1,"P",@P,int_radius,int_maxpt);

    vector clr = pcfilter(h,"Cd");

    vector dir = pcfilter(h,"N");

    float cnum = pcfilter(h,"curve_num");

    @ttest = cnum;

    if(cnum==@cid){

        @Cd = clr;

        @N=dir;

        }


}


//=====================================

 

//Points lookup from second input to create a soft Cd attrib transfer falloff 

  

float maxrad = chf("maxrad"); 

int maxpt = chi("maxpts"); 

//int handle = pcopen(1,"P",@P,maxrad,maxpt); 

int closept[] = pcfind(1,"P", @P, maxrad,maxpt); 

foreach(int pt; closept){ 

float pscale = point(1, "pscale", pt); 

vector color = point(1, "Cd", pt); 

vector pos =  point(1, "P", pt); 

    i@id = point(1,"id",pt); 

@Cd = pow(max(@Cd,color * fit(distance(@P, pos), 0, pscale, 1, 0)),0.9); 

  

 

//=====================================


 

 

 

 

 

 

// Push on direction and applying noise on impacted region (position push and direction from the center) 

  

#include <voptype.h> 

#include <voplib.h> 

 

int ref_pt = idtopoint(1, i@id); 

vector pos = point(1, 'P', ref_pt); 

vector point_POS = point(1,"P",ref_pt); 

float flow_red = @Cd.r; 

  

if(flow_red>0){ 

@Cd.r = flow_red; 

vector dir_POS = normalize (point_POS - @P); 

vector freq = chv("freq"); 

vector offset = chv("offset"); 

float amp = chf("amp"); 

//float dist_N = len(@N); 

float noise; 

noise = abs(vop_fbmNoiseVV(v@rest * freq - offset, 0.1, 4, "noise")); 

noise = fit01(noise,0,0.7); 

noise *= amp; 

            noise *= flow_red; 

//float noise = (noise(@P*freq+offset)*amp)*flow_red; 

//dir_POS *= dist_N*0.4; 

            dir_POS *=  chf("scale")*noise; 

//v@dir_POS=dir_POS; 

@P += dir_POS*flow_red; 

}  


//=====================================


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

//Rotating vector for thruster direction 

  

v@N = normalize(@N); 

vector pos = point(1,"P",0); 

vector pos1 = point(2,"P",0); 

vector z = normalize(@P-pos); 

vector y = normalize(@P-pos1); 

vector x = normalize(cross(y,z)); // z-axis (horizontal rotation) 

  

v@x = x ; // NEW NORMAL 

v@y = y ; 

v@z  = z ; 

v@up = y; 

v@N = x; 

  

matrix3 m = ident(); 

float angle1 = chf("angle1"); 

rotate(m,angle1,z); 

v@N *= m; 

  

matrix3 m1 = ident(); 

float angle2 = chf("angle2"); 

rotate(m1,angle2,y); 

v@N *= m1;


//=====================================






















//String attribute iterate/hack


string seperate[]  = split(s@path,"/");

s@splitgrp = seperate[4];

string getv = s@splitgrp;

s@catch_sup = getv[0:14];

//s@middle = getv[7:-9];

i@length = len(getv);

//s@catch = getv[7:-8];

//s@name = "debri"+@catch;

if(@length>23){

    s@catch = getv[7:-7];

    }

    else if (@length==23){

        s@catch = getv[7:-8];

        }

    else if (@length<23){

        s@catch = getv[7:-8];

        }

if(@length==23 && s@catch_sup=="catwalkSupport"){

    s@catch += getv[15];

    }


string num = re_find("([0-9]+)",s@catch);

s@aaa = num;

    

/*

string sep_catch[] = split(s@catch,"Support");

s[]@sep_catch = sep_catch;


string num = re_find("Shape", s@csplitgrp);

//s@tst = num;

s@csplitgrp = re_replace(num,"",@csplitgrp);    

    

*/

=====================================================================

//Path Isolate

string seperate[]  = split(s@path,"/");

s@splitgrp = seperate[3];

string getv = s@splitgrp;

i@length = len(getv);

s@catch = getv[13];

s@debri = "debri"+@catch;

=====================================================================






https://docs.google.com/document/d/1e-ZVp2HR4kfuAG39ITbQHVjbta4SyY5eUNJJrbmL36s/edit?usp=sharing