Skip to content

Basics

Important!

The most important thing to learn about vex HoudiniVex - Parallel

That’s hard to read, summarise please Ok fine. Imagine you’re a point: Me affecting me, good. Others affecting me, good.Me affecting others, bad. Gross oversimplification, but that’s the general idea.

A good example would be breadth search in a parallel context

Create

  • Set a new vector / Create a new vector
vex
v@Cd = {0,0,0};
v@P = set(0,some_var,0);
  • Access components of a vector
vex
v@P.y
  • Create array attribute using vex
vex
// for this example running in detail mode
string unique[] = uniquevals(0, "prim", "name");
s[]@unique = unique;
i@maxunique = len(unique);

Operators

Ternary

vex
v@Cg = (grp==0) ? {1.0, 0.0, 0.0} : {0.0 , 1.0 , 0.0};

For Loops

for

vex
// in the detail context
for (int i=0; i< i@numprim ; i++){
if (prim(0, "plate", i) > 0) push(found, i);
}

foreach

//TODO

Groups

Create a group

the “group_” tells vex that is a group

vex
i@group_visited;
i@group_frontier;

Add point to a group

vex
setpointgroup(0, "grp_name", @ptnum, 1);

Expressions

Groups expression Node Randomize

vex
rand(@elemnum) > chf("Amount")

Negate group

As an expression “^somegrp”

vex
//All but grp
^grp

Get all the points in a group

vex
// get all the points is in the target group 'target_pts'
// make sure the group is a point group
int targets[] = expandpointgroup(0, "target_pts", "unordered");

Ad-hoc groups

source file: corruption.hiplc In point mode

vex
// I will use this as a tag to create an adhoc group down stream
s@prim_owner = itoa(@primnum);
// itoa will cast int to a string

How to use the ad-hoc grp

vex
//to limit the nearpts search to only consider the points
//of the current primitive,
//an ad-hoc groups is created from a string tag
string s_primnum= itoa(@primnum); // cast int to string
string grp = "@prim_owner="+s_primnum; // build group expression
// grp is used to limit the search
int nearpts[] = nearpoints(0, grp, v@hingedir, 1, 3);
if (len(nearpts) == 0) return;
vector p0 = point(0,'P',nearpts[0]);
vector p1 = point(0,'P',nearpts[1]);
vector pivot = (p0+p1)/2; // the middle point
v@hinge = pivot;
// export points
i[]@nearpts = array(nearpts[0], nearpts[1]);

More ad-hoc groups

To create groups on the fly using vex, there are several functions, one vor each type of context expandpointgroup

  • expandprimgroup
  • expandpointgroup

Reference

Most of the tables were obtained from: cgwiki

General

typenamedescription
int@ptnumPoint Number
int@numptTotal number of points
float@TimeCurrent time, in seconds
float@TimeIncTime increment per frame in seconds
int@primnumPrimitive Number
float@FrameCurrent frame
int@numprimTotal number of primitives
int@vtxnumVertex number
int@numvtxTotal number of vertices

Geometry

typenamedescription
vec3@PPoint/Primitive Position
vec3@NPoint/Primitive/Vertex Normal
vec3@vVelocity (ex: motion blur in particle systems)
float@pscaleUniform scale. Used in copy-SOP or particle systems
vec3@scaleNon-Uniform scale. For use see pscale
vec3@upUp-Vector. Used together with @N to orient point/particle/instance
vec4@orientQuaternion defining the rotation of a point/particle/instance
vec3@rotQuaternion defining additional rotation
vec3@transTranslation of instance
matrix@transformTransformation matrix (used for example in Copy-Sop)
vec3@pivotLocal pivot point for instance
float@lodDetail/Primitive level of detail
vec3@restRest position
vec3@forceForce (acting on particle)
float@ageParticle Age
float@lifeMax. Particle Life

Volumes

typenamedescription
float@densityDensity of voxel
int@ix, @iy, @izVoxel indices along each axis. Ranging from 0 to resolution -1
vec3@centerCenter of current Volume
vec3@origBottom left corner of current Volume
vec3@sizeSize of current Volume
vec3@dPdxChange in position to get from one voxel to the next in x direction
vec3@dPdyChange in position to get from one voxel to the next in y direction
vec3@dPdzChange in position to get from one voxel to the next in z direction
vec3@BBrelative position inside bounding box. Ranging from {0,0,0} to {1,1,1}

Shading

TypeNameDescription
vec3@CdDiffuse Color
float@AlphaAlpha Transparency
vec3@uvPoint/Vertex/ UV coordinates
vec3@CsSpecular Color
vec3@CrReflective Color
vec3@CtTransmissive Color
vec3@CeEmissive Color
float@roughRoughness
float@fresnelFresnel Coefficient
float@shadowShadow intensity
float@sbiasShadow bias

Types as Attributes

typeas @attribExample Value
inti@myint5
floatf@myfloat12.3
vector2u@myvector2{0.6, 0.5}
vectorv@myvector{1,2,3}
quaternionp@myquat{0,0,0,1}
matrix2x22@mymatrix2{1,2,3,4}
matrix3x33@mymatrix3{1,2,3,4,5,6,7,8,9}
matrix4x44@mymatrix4{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}
strings@mystring’single quotes string’ or “inside double quotes str”
dictionaryd@mydict{} // instantiate empty
dictionaryd@mydict[‘key’]“str value” or other type, int, float, vector…
vex
// floats and integers
f@myfloat = 12.234; // float
i@myint = 5; // integer
// vectors
u@myvector2 = {0.6, 0.5}; // vector2 (2 floats)
v@myvector = {1,2,3}; // vector (3 floats)
p@myquat = {0,0,0,1}; // quaternion / vector4 / 4 floats
// matricies
2@mymatrix2 = {1,2,3,4}; // matrix2 (2x2 floats)
3@mymatrix3 = {1,2,3,4,5,6,7,8,9}; // matrix3 (3x3 floats)
4@mymatrix4 = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; // matrix (4x4 floats)
// strings and dictionaries
s@mystring = 'a string'; // string
d@mydict = {}; // dict, can only instantiate as empty type
d@mydict['key'] = 'value'; // can set values once instantiated

Functions, write by reference

vex
// use export keyword
function void voronoise(vector position; export int seed; export float dist; export float edge_dist){
...
seed = some_value;
dist = some_value;
edge_dist = some_value;
}
// Declare
float dist, edge_dist;
int seed;
// Write
voronoise(@P, seed, dist, edge_dist);