top of page

Useful Houdini VEX Code Snippets

Updated: Feb 6

Make Camera focus on a group called focus_cam - vlength(vtorigin(".", "../cam_focus"))

[input into focus distance attr of camera]


Vortex Vex Code

float angle = radians(ch("angle")) * length(@P*{1,0,1}) * relbbox(0, @P).y;

vector newPos = qrotate(quaternion(angle, {0,1,0}), @P);

@density = volumesample(0,0,newPos);


Delete by nearpoints

float maxdist = chf("max_dist");

f@nearpt = nearpoint(1,@P,maxdist);

f@test = maxdist;

if(@nearpt > -1){

removepoint(0,@ptnum);

}


Find Min and Max value of an attribute

float value;

float values[];

string attrname = "id";

float max_value;

float min_value;


for (int i=0; i<@numpt; i++){

value = point(geoself(), attrname, i);

append(values,value);

}


min_value = min(values);

max_value = max(values);


Attribute Randomize by Power (Powerful)


i@id = @ptnum+1;

float pts = @id;

float distro = pow(chramp("distro",rand(pts+chi("seed"))),ch("pow"));

float distro2 = pow(chramp("distro_pieces",rand(pts+chi("seed"))),ch("pow"));

float d = fit(distro,0,1,ch("pscaleMin"),ch("pscaleMax")) * ch("mult");

float d2 = fit(distro2,0,1,ch("pscaleMin"),ch("pscaleMax")) * ch("mult");

f@pscale = d;

i@copyPiece = rint(fit(d2,0,1,0,2));



//rotate object using VEX

matrix m = ident();

rotate(m, radians(chf("angle")), {1, 0, 0});

@P *= m;



Noise from a null (Hscript)

if ($F>1080 && $F<1095, snoise($FF+10,$FF,$FF)*1, 0) - input into rotation of null and attach to camera



//Calculate nearest point of 1st input to the point of the second input

int nearpt[] = nearpoints(0, point(1,"P",0), chf("max"));

foreach(int pt; nearpt){

if(@ptnum == pt){

@group_activate = 1;

}

}

if(@group_activate != 1){

removepoint(0,@ptnum);

}


//Expression to calculate degree between two vectors

f@angle = degrees(acos(dot(vector1, vector2)));


//Create primitive groups based on string (Use to export face sets for Houdini to Unreal)

setprimgroup(0, s@name+"_group", @primnum, 1);


//Keep characters in a string after a particular character


string inputStr = @name;

string asterix = "*";

string issue = chs("remove_After");

string culprit = asterix + issue + asterix;

if(i@match = match(culprit, inputStr) == 1){

string parts[] = split(inputStr, issue);

s@newName = parts[-1];

}




//Create lines based on Point proximity (nearpoints) and maximum and minimum distance


int maxConnections = chi("max");

int initial = 0;

float initDist = chf("mindist");

i[]@nearpt = nearpoints(0, @P, chf("maxdist"));


foreach(int x; @nearpt){


float distance = distance(@P, point(0, "P", x));

if(initDist < distance){

if(initial < maxConnections){

addprim(0, "polyline", @ptnum, x);

initial++;

} else {

break;

}

}

}

276 views0 comments
bottom of page