VEX Help Sheet

-Here is a helpful cheat sheet to remember some VEX scripts. These are some that I use on a regular basis.

Cheers!

 

Point Wrangle

Randomize point orientation: @orient = rand(@ptnum);

 

Rotate the point normal: 

 

  • float angle = 0.8;

  • matrix rot = ident();

  • vector axis = {0,1,0};

  • rotate(rot, angle , axis);

  • vector rotateP = @P * rot;

  • @P = rotateP;

 

To get rotating geometry on a set of points(constantly spinning)

 

  • float angle;

  •  vector axis; 

  •  angle = ch('angle');

  •  angle += @ptnum*ch('offset');

  •  angle += @Time*ch('speed');

  •  axis = chv('axis');

  •  @orient = quaternion(angle, axis);

 

Rotate points into a twirl or spiral:

 

  • float angle = atan(@P.x, @P.y);

  • float r = length(set(@P.x, @P.y));

  • float amount = radians(ch('amount'));

  • float twirl = r*ch('twirl');

  • @P.x = sin(amount+angle+twirl)*r;

  • @P.y = cos(amount+angle+twirl)*r;

 

Orient and rotate packed primitives:

 

  • float angle = @Time *@ptnum;

  • vector axis = {0,1,0};

  • matrix3 m = ident();

  • rotate(m, angle, axis);

  • setprimintrinsic(0, ‘transform’, @ptnum, m, ‘set’);

Group number of points randomly:

 

  • int num = chi("num_points");

  • string name = chs("grp_name");

  • for (int i=0; i< num ; i++){

  •     int index = int(nrandom() * npoints(0));

  •     setpointgroup(0, name , index ,1);

 

Set pscale based on distance to the closest point:

  •  

  • float searchRad = ch("searchRadius");

  • int closePt = nearpoints(0,@P,searchRad)[1];

  • @pscale = distance(v@P,point(0,"P",closePt))/2;

 

Attribute Wrangle 

 

Remove a primitive in VEX: removeprim(0, @primnum, 1);

 

Set point attribute per chosen point attribute:  setpointattrib(0, "Attrib", pt, attrib(same as “Attrib”));

 

Add polyline: int polyline = addprim(0, "polyline");

 

Set pscale: f@pscale = 1.0;

 

Set velocity/motion blur if object has none to begin with: v@v = set(0,0,1);

Add more velocity/motion blur if object already has velocity: v@v *= set(0,0,1);

 

Rotate geometry with a matrix:

 

  • vector axis = {0,0,1};

  • float angle = radians(ch('amount'));

  • angle *= ch('twirl')*length(set(@P.x, @P.y));

  • matrix3 m = ident();

  • rotate(m, angle, axis);

  • @P *= m;

 

Set active and non-active group:

 

  • i@active = 0; or i@active = 1;

 

Displace geometry by the velocity of an object traveling across its surface. (You need to set up an attribute transfer before the attribute wrangle to transfer the velocity to the object you would like to displace):

 

  • @P.y+=@v.y*chf('scale');

Detail Wrangle:

 

Create a Phyllotaxy formation by orientation of points(Arrangement of leaves on a plant stem or crisscrossing spirals):

  • v@pos = {0,0,0};

  • addpoint(0,@pos);

  • addpointattrib(0,"yellow",0);

  •  

  • float dist = ch("distance");

  • float angle = ch("angle");

  • int count = chi("count");

  • float aInterval = radians(ch("angleInterval"));

  • float dInterval = ch("distanceInterval");

  •  

  • vector angleToVector(float theta; float radius;) {

  •     return set(cos(theta)*radius, 0, sin(theta)*radius);

  • }

  •  

  • for (int n; n < count ; n++){

  •     angle += aInterval ;

  •     dist  += dInterval ; 

  •     v@pos = angleToVector(angle,dist);

  •     int newpoint = addpoint(0,@pos);   

 

*Set angle interval to 137.5.

 

POP Wrangle 

 

Using Hittotal to change the particle colour:

 

  • @Cd={1,0,0};

  • if (@hittotal>0) {

  •    @Cd={0,1,0};

  • }

 

Make particles look like they are fake rolling:

 

  • v@axis = cross(normalize(@v), {0,1,0});

  • vector4 newgroup = quaternion(@axis*-length(@v)*0.5);

  • @orient = qmultiply(newq, @orient);


 

DOP and SOP Commands:

 

$F == 1 : Emit first frame

 

$F<=23 : Emit or switch emitter after frame 23.


 

Other Helpful resources:

 

VEX Wrangle Cheat Sheet: https://mrkunz.com/blog/08_22_2018_VEX_Wrangle_Cheat_Sheet.html

 

Wrangle-Pattern: https://sites.google.com/site/fujitarium/Houdini/sop/wrangle/wrangle-pattern

 

HoudiniVex:

https://www.tokeru.com/cgwiki/index.php?title=HoudiniVex#Rotate_a_single_point_with_sin_and_cos

 

Using @orient attribute with instances: https://vfxbrain.wordpress.com/2018/12/04/using-orient-attribute-with-instances/

 

MO-VFX: https://sites.google.com/site/mocgnotes/home

 

A 20 DAY PROGRAM OF VEX: https://www.giahuyproduction.com/a-20-day-program-of-vex.html