Welcome to my Everyday FX Script Collection!


DISCOVER A SET OF ESSENTIAL VEX SCRIPTS I USE DAILY IN MY FX WORK. FROM PROCEDURAL MODELING TO SIMULATION, THESE SCRIPTS STREAMLINE TASKS AND ENHANCE PRODUCTIVITY. WHETHER YOU'RE A SEASONED PRO OR JUST STARTING, THESE TOOLS ARE DESIGNED TO ELEVATE YOUR FX PROJECTS. FEEL FREE TO EXPLORE, ADAPT, AND INTEGRATE THEM INTO YOUR WORKFLOW. HAPPY SCRIPTING!! 

Ali Rizvi

Senior FX TD / Artist

​//=====================================


// Filtering data based of SDF 

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

if(dist<chf('val')){
    //removepoint(0,@ptnum);
    @Cd = set(1,0,0);
    }


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

// Noise in vex same as vops using Antialias noise function

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


// Another antialias noise function example


#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;
@nv = noise.x;
@noise = fit(noise.x,chf('old_min'),chf('old_max'),chf('new_min'),chf('new_max'));
@N *= @noise;


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

// Delete by Y axis position value


if(@P.y<chf('val')){
    removepoint(0,@ptnum);
    }
//=====================================

// Delete by max size 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]);

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


// Coloring based of bounding box information


vector bound = relbbox(0,@P);
v@Cd = set(0,0,0);
float boundfit  = fit01(bound[0],0,1);
f@Cd.x = vector(chramp("color_ramp",boundfit));


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


// Displace along normal


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

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

// Noise fade over a frame range


if(@Frame>fit01(@noise,chf("fade_start"),chf("fade_end"))){
    removepoint(0,@ptnum);
    } 

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

// Randomize pscale based of point numbers

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); //cid is an color attribute value coming in from previous input
    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 attriuteb 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 source/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;

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


// Create orient attribute based on Normal and UP vectors


vector z = {0,0,1};
v@up = normalize(cross(v@N, z));
v@N = -normalize(v@N);
@orient = quaternion(maketransform(@N, @up));

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


// Create a color ramp on a curve


float ramp = 1-@ptnum / float (@numpt);
v@map = vector(chramp("ramp",ramp));

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


// Create an array based of a point group then fech the data from index value


int rt_grp[] =expandpointgroup(0,"root");
i@root_num= rt_grp[0];


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


// Finding a nearby point using pcfind


float radius = 0.01;
int maxpts = 1;
int closept[] = pcfind(1,"P",@P,radius,maxpts);
i@root_ptnum = closept[0];
//i[]@test = closept;


// Use the above example  to iterate over found points


foreach(int num; closept){
    @map = point(1,"map",num);
    }


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


// Interpolating points on a curve/surface


f@sourceprim=0;
v@sourceprimuv[0]=@ptnum / float (@numpt);

float distance = xyzdistance(0,@P,sourceprim,sourceprimuv,maxdistance)


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


// This is commonly used inside solver sop if 2 inputs are coming in to record something based of any event over time


if(@trig!=1){

    vector pos = point(1,"P",0);
    float dist = distance(@P,pos);
    //f@dist=dist;
    if(dist>0.01){
        @trig=1;
        i@getFrame = @Frame;
        }
}


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


// Trasform a curve if it has proper tangents and normal at origin

vector tangentu_orig= point(0,"tangentu",0);
vector tangentv_orig= point(0,"tangentv",0);
vector NCross = cross(normalize(v@tangentu),normalize(v@tangentv));
//v@N = NCross;
vector center = getbbox_center(0);
vector P0 = point(0,"P",npoints(0)-1);
vector X = tangentu_orig;;
vector Y = v@N;//tangentu_orig;//v@tangentv;
vector Z = tangentv_orig;//v@tangentu;

matrix m = set(X,Y,Z,P0);
setcomp(m,0,0,3);
setcomp(m,0,1,3);
setcomp(m,0,2,3);

@P *= invert(m);


// Scaling and animating it using maketransform sop


@rEnd = ceil(fit01(rand(@prim_Id*seed),@getFrame,$FEND-@offset));

@range= fit(@Frame,@getFrame,@rEnd,0,1);
f@c_angle = fit(@Frame,@getFrame,@rEnd,180,0);

vector t=set(0,0,0);
vector r=set(@c_angle,0,0)*@map;//*@range*@map;
vector s=set(1,1,1)*@range*@trig;
vector p= point(0,"P",npoints(0)-1);

vector temp_r = set(0,0,0);
vector temp_s = set(1,1,1);
matrix xform = maketransform(0,0,t,r,s,p);
//4@myTransform *=xform;

v@P *= xform;

// Transforming it back to original location using second input


matrix myTransform = point(1,"myTransform",@ptnum);
@P *= myTransform;


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


// Postition & Vector Transformation


vector P1 = point(0,"P",0);
vector P2 = point(1,"P",0);
vector upVector = set(0,1,0);
vector xAxis = normalize(P2-P1);
vector zAxis = normalize(cross(xAxis,upVector));
vector yAxis = normalize(cross(zAxis,xAxis));

v@xAxis= xAxis;
v@yAxis= yAxis;
v@zAxis= zAxis;

vector center = P1 + (P2-P1) / 2;

matrix myTransform = set(xAxis,yAxis,zAxis,center);
setcomponent(myTransform,0,0,3);
setcomponent(myTransform,0,1,3);
setcomponent(myTransform,0,2,3);

4@myTransform = myTransform;

//----------------------------------------


matrix myTransform = point(1,"myTransform",0);

@P *= invert(myTransform);
@N *= matrix3 (invert(myTransform));
@v *= matrix3 (invert(myTransform));


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