Houdini Vex


attributes vs variables
    f@name  // Attribute, assigned to geo
    float name  // Variable, within wrangle only
declaring data types
    // Float
    f@name  or  float name
    // Integer
    i@name  or  int name
    // String
    s@name  or  string name
    // Vector
    v@name  or  vector name
    // Array (List)
    string name[], float name[], etc.
some built-in attributes
    @ptnum  // Point id
    @numpt  // Total number of points
    @primnum  // Primitive id
    @numprim  // Total number of primitives
    @Time  // Current time, in seconds
    @Frame  // Current frame
    
    // With sub-components
    @Cd (@Cd.r, @Cd.g, @Cd.b)  // Color
    @P (@P.x, @P.y, @P.z)  // Position
    @N (@N.x, @N.y, @N.z)  // Normal

sub-components can use rgb, xyz, or [0][1][2]


working with strings
    // Convert from float to string
    string name = sprintf("%f", float);
    
    // Combine strings
    string name = concat("string", "string");
    // Result: stringstring
    
    // Split a string
    string parts[] = split("string_01", "_");
    // Result: ["string", "01"]

channel references on wrangles
    ch('channel_name')  // Float channel
    chi('channel_name')  // Integer channel
    chv ('channel_name')  // Vector channel
    chs ('channel_name')  // String channel
    chramp ('channel_name', attr)  // Ramp channel (in 0-1 range)

click the plug button to the right to automatically create non-existing channels


some functions
    fit(attr, oldmin, oldmax, newmin, newmax)
    // Takes a number between 2 values and fits it between 2 new values
    
    rand()  // Generates a random number between 0 and 1
    
    sin(), cos()  // Sine and Cosine, in radians
    radians(degrees)  // Converts a number from degrees to radians
    
    length(vector)  // Measures the length of a vector
    distance(pt1, pt2)  // Measures the distance between two points
    
    len(list)  // Counts the number of items in a list

normalize point number
    float(@ptnum)/@numpt;
invert (must be in 0-1 range)
    f@result = 1 - @attribute;
measure the distance between a point and the origin
    float dist = length(@P);

general syntax
    // Each line must end with ;
    
    // If statements
    if (test == value) {
        code to execute;
        code to execute;
    }

Some useful HScript

point attribute reference
    point("path/to/node", point_num, "attribute", attribute_index)
    
    // For example:
    point("../transform", 1, "P", 0)  // Reads @P.x for point 1
primitive attribute reference
    prim("/path/to/node", prim_num, "attribute", attribute_index)