(Houdini, Vex)

Small reminder code snippets

Houdini Snippets

A list with some small Houdini Wrangle Snippets.

VEX Move point

Houdini Screenshot mit Punkten

Houdini, Vex |

Move point along a given vector

Move point along normal

Create a line, then add a point wrangle with the following code and create the spare parameters.

Move Point along Normal

if (@ptnum == 0) {
    v@N = normalize(point(0, "P", 1) - @P);
}
if (@ptnum == 1) {
    v@N = normalize(point(0, "P", 0) - @P);
}
@P += @N * chf("distance");

VEX Blend UVs

Houdini, Vex |

Blend/lerp attributes

How to Blend Attributes / UVs in Houdini

Use this code in a Point Wrangle. Create UVs and a UV Edit Node. Assign original UVs to first input and the edited UVs as second input. Set Run Over to Vertices, if you have vertex uvs. ... read more

Blend UVs

// Set run over to type with the attribute
@uv = lerp(@uv,v@opinput1_uv,chf("blend"));

VEX Move Primitive

Houdini, Vex |

Move primitive along a given vector

Move Primitive along Normal

Create a Box or Sphere and set Primitive Type to Polygon Mesh. Create a facet Node with "Unique Points" checked to create separated Prims. Create a Primitive Wrangle with this snippet and create the Spare Parameter.

Move Primitive

vector offset = prim_normal(0, @primnum, {0,0,0}) * chv("scale");
int points[] = primpoints(0,@primnum);

foreach(int point_no; points) {
    vector point_pos = point(0, "P", point_no);
    point_pos += offset;
    setpointattrib(0, "P", point_no, point_pos);
}

VEX Spherize a Box

Houdini, Vex |

Build a quads only sphere

Spherize a Box

Create a box and set Primitive Type to Polygon Mesh. Set Axis Divisions to maybe 10. Create a Point Wrangle with this snippet and create the Spare Parameter.

Spherize a Box

vector min, max;
getbbox(0, min, max);
vector center = (min+max)/2;
@P = chf("radius") * normalize(@P - center) + center;

VEX Rotate around Edge

Houdini, Vex |

Rotate Primitive Points around an Edge

Rotate around Edge

Create a Box or Sphere and set Primitive Type to Polygon Mesh. Create a facet Node with "Unique Points" checked to create separated Prims. Create a Point Wrangle with this snippet and create the Spare Parameter.

Rotate around Edge

float angle = radians(chf("angle"));
matrix3 rotm = ident();
int points[] = primpoints(0, @primnum);
vector p0 = point( 0, "P", points[2] );
vector p1 = point( 0, "P", points[1] );
vector axis = normalize( p0 - p1 );

rotate(rotm, angle, axis);

@P -= p0;
@P *= rotm;
@P += p0;

VEX Create Primitive

Houdini, Vex |

Simpe Snippet Code to create a primitive

Create Primitive Circle

Create a Attribute Wrangle (Run Over: Detail) with this snippet and create the Spare Parameter. Maybe change the "close_poly" and "add_end" parameters to Type "Toggle" manually.

Create Circle

// define pi or use $PI
float pi = 3.14159265358979323846;
// prepare parameters
int close = chi("close_poly");
int add_end = chi("add_end") && !chi("close_poly")? 1 : 0;
float count = chi("point_count") + add_end;
float mul = (count - add_end) / pi / 2; // * 4
// create empty arrayfor points
int pts[];
// create points and add them to point array
for (int i = 0; i < count; i++) {
    float x = sin(i/mul);
    float z = cos(i/mul);
    int pt = addpoint(0, set(x,0,z));
    push(pts,pt);
}
// create open or closed primitve
if (close) {
    addprim(0,"poly",pts);
} else {
    addprim(0,"polyline",pts);
}

VEX Create Vertex UVs

Houdini, Vex |

Create a simple Primitive with Vertex UVs

Create Vertex UVs

Create an Attribute Wrangle (Run Over: Detail) with this snippet and create the Spare Parameters.

Create Vertex UVs

// create parameters
float _x = chf("width");
float _z = chf("height");
// create point positions
vector _pos[] = array({0,0,0},set(_x,0,0),set(_x,0,_z),set(0,0,_z));
// create empty point array
int _pts[];
// loop over point positions and create the points
foreach (vector _pt_pos; _pos) {
    push(_pts,addpoint(0, _pt_pos));
}
// create primitive and add the points
int _prim = addprim(0,"poly",_pts);
// maybe create initial uv value if needed
// addvertexattrib(0,"uv",{0,0,0});
// loop over points and set new uv values
foreach (int _pt; _pts) {
    float _u = _pos[_pt][0];
    float _v = _pos[_pt][2];
    setvertexattrib(0, "uv", _prim, _pt, set(_u,_v,0), "set");
}