Code in Houdini

Houdini expression and script snippets.

General

This is a list of the point attributes that are used with the Copy SOP and point instancing.

1
2
3
4
5
6
7
8
orient // float4 (quaternion)
pscale // float
scale // float3
N // vector
up // vector
v // vector
rot // float4 (quaternion)
trans

Expression Functions

Grab input. Bbox sits on ground.

1
 bbox(opinputpath(".", 0), D_YMIN) * -1.0

VEX

VEX @attribute_name syntax for different datatypes.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
f@name  // float
u@name  // vector2 (2 floats)
v@name  // vector (3 floats)
p@name  // vector4 (4 floats)

i@name  // int

2@name  // matrix2 (2×2 floats)
3@name  // matrix3 (3×3 floats)
4@name  // matrix (4×4 floats)

s@name

Template for point cloud lookup.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
float radius = chf("radius");
int maxpoints = chi("maxpoints");

int handle = pcopen(0, "P", v@P, radius, maxpoints);

int cloud_ptnum = -1;
float cloud_dist = 0.0;
vector cloud_P = {0.0, 0.0, 0.0};
vector cloud_foo = {0.0, 0.0, 0.0};

while (pciterate(handle)) 
{
    // Skip self
    pcimport(handle, "point.number", cloud_ptnum);
    if (cloud_ptnum == i@ptnum) continue;

    pcimport(handle, "point.distance", cloud_dist);
    pcimport(handle, "P", cloud_P);
    pcimport(handle, "foo", cloud_foo);
}

Create orient attribute.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
matrix3 m = ident();
vector z_front;
vector y_up;
vector x_left;

z_front = normalize(v@tangent);           // set front
y_up = normalize(v@normal);               // set up
x_left = normalize(v@bitangent);          // set left

m = set(x_left, y_up, z_front);

p@orient = quaternion(m);

Python

Create default node color.

1
2
3
4
5
import soptoolutils

node = soptoolutils.genericTool(kwargs, '$HDA_NAME')

node.setColor(hou.Color(.4392, .3804, 0.7843))