Index VEX
Index Tips
Index Hscript
While loopTop
int count; while(conditionis !=1) { conditionis=rind(a+b); count+=1; if(count>10) break; }
Loop over arrayTop
float arrayName []; float value[]; int countarray= len ( arrayName); for(int i = 0; i<countarray; ++i) { value [i] = ch("parm") == 0 ? ch("parm2"): 1 ;
Short IF statementTop
// example of (condition) ? true : false; @value = (a > b) ? 1 : 0; //nested example of (condition) ? (condition) ? both true : second true : false; @value = (a > b) ? (a < c) ? 2 : 1 : 0 ;
Relax Based on PscaleTop
//RELAX BASED ON PSCALE ( push overlaping from each other) //put this snippet in SOP foreach and fetch feedback, not merge feedbacks //with more iterations, it will average point positions int handle[] = pcfind_radius(0,"P","pscale",@pscale,@P,@pscale*1.5,2); pop(handle,0); //remove itself from array. pop() or removeindex() vector pos,dir; float pscale,dist,dirlen; foreach(int pt; handle) { pos=point(0,"P",pt); pscale=point(0,"pscale",pt); dirlen=length(v@P-pos); dist=(pscale+@pscale-dirlen)/2; //get distance dir=normalize(v@P-pos)*(dist); v@P+=dir; }
Data TypesTop
f@ float u@ vector2 v@ vector3 p@ vector4 i@ int 2@ matrix 3@ matrix3 4@ matrix s@ string
Global VariablesTop
f@Frame f@Time i@SimFrame f@SimTime f@TimeInc v@P i@ptnum i@vtxnum i@primnum i@elemnum i@numpt i@numvtx i@numprim i@numelem //Volume Wrangle f@density v@center v@dPdx, v@dPdy, v@dPdz //Store the change in P that occurs in the x, y, and z voxel indices. i@ix, i@iy, i@iz //Voxel indices. For dense volumes (non-VDB) these range from 0 to resolution-1. i@resx, i@resy, i@resz
16bit VDB's Top
setprimintrinsic(0, 'vdb_is_saved_as_half_float', @primnum, chi('use16bit')); // See if this is vector type string vecmask = chs('vecvolume'); if (match(vecmask, @name)) { setprimintrinsic(0, 'vdb_vector_type', @primnum, 'contravariant relative'); }
Uniqueval Loop Top
int count = nuniqueval(0,"point","name"); for (int i = 0; i < count; i++) { string val = uniqueval(0,"point","name",i); }
Pscale from ID Top
@pscale = fit01( chramp( "r" , rand( i@id ) , 0) , chf( "min" ) , chf( "max" ) ) * chf( "global" );
Normalize Pieces Top
#Put it in foreach looper to iterate over each piece. vector size = getbbox_size(0); vector center = getbbox_center(0); vector pos=v@P-center; vector scale = 2/max(size); matrix m=maketransform(0,0,0,0,scale); @P=pos*m;
Intersections Top
v@P.y+=10; //offset ray origin vector pos; float u,v; intersect(1,@P,{0,-100,0},pos,u,v); // intersect in negative Y v@P=(pos!=v@P)?pos:v@P; // keep only hits
Delete random Top
float treshold = pow(chf("treshold"),chf("pow")); (rand(@ptnum)<treshold)?removepoint(0,@ptnum):0;
Split NameTop
s@name=split(s@objname,"/")[-1];
Vex NoisesTop
referenced from Timucin Ozger
vector freq = {1,1,1}; vector offset = {0,0,0}; float amp = 0; int turb = 5; float rough = 0.5; float atten = 1; onoise(@P*freq - offset, turb, rough, atten) * amp snoise(@P*freq - offset, turb, rough, atten) * amp anoise(@P*freq - offset, turb, rough, atten) * amp vop_correctperlinNoiseVF(@P*freq - offset, turb, rough, atten) * amp vop_correctperlinNoiseVV(@P*freq - offset, turb, rough, atten) * amp vop_simplexNoiseVF(@P*freq - offset, turb, rough, atten) * amp vop_simplexNoiseVV(@P*freq - offset, turb, rough, atten) * amp vop_perlinNoiseVF(@P*freq - offset, turb, rough, atten) * amp vop_perlinNoiseVV(@P*freq - offset, turb, rough, atten) * amp
Split NameTop
s@name=split(s@objname,"/")[-1];
Camera Scale FixTop
//when scaling camera with null, //jump inside alembic, unhide scale parameter and set origin(opinputpath(".",0), "", "SX") origin(opinputpath(".",0), "", "SY") origin(opinputpath(".",0), "", "SZ")
Gas Reduce infoTop
//GAS REDUCE node will give you maximum or average or other operation on field. //in Dest Data put temperature/max , in Source put temperature , set operation. //it will push max data inside field. //you can read those data on parameter with dopfield(stamps("../..", "DOPNET", "../.."),stamps("../..", "OBJID", arg(dopnodeobjs("../.."),0)), "temperature", "Options", 0, "max")
Repeat SolverTop
//in dopsolver beneath substep gas node create repeatsolver and turn on "override minimum with data" //create applydata node beneath smokeobject node and plug switch value node in it. //in switch value node, set dataname field to match name with "minimum Solve pass data" field from gasrepeat //set swich node default operation to "Set always" and you can animate parameter for repeats.. ( many explosion have quick expansion on begining and then slows down. this trick can achieve that look!)
Resize Only Current ClusterTop
//to set resize for each cluster in pyro sim, you need to break in dynamic resize node and inside foreach in wrangler pull dopfield data of cluster number: dopfield(stamps("../..", "DOPNET", "../.."),stamps("../..", "OBJID", arg(dopnodeobjs("../.."),0)), "init", "Options", 0, "init_cluster") //then beneath objectmerge (sop source data) //generate id from name atoi(split(@name,"_")[1]) //assuming name look like cluster_0, cluster_1, etc.. //then you can comapare and remove (id!=clusterid)?removeprim(0,@primnum,1):0; //check Trail cluster data node in Assets page, you can see this method implemented in explanation video
Timeshift indide looperTop
//create wrangler node and input geometry from looper to 2nd input, then geometry outside of looper in 1st input. Match name, if name match as a piece inside looper(2nd input), delete everything else, then you can set timeshift and offset geometry. int matching = match(s@name,prim(1,"name",0); (!matching)?removeprim(0,@primnum,1):0; or (i@class!=prim(1,"class",0)?removeprim(0,@primnum,1):0;
loop in parameterTop
{ if(ch("path")==0) return 2; else if(ch("path")==1) return 1; else return 0; }