FXPHD class 1

https://www.tokeru.com/cgwiki/?title=HoudiniVex

Vex

Python

vex statement: float x = 10; ( a line of code that ends with a semi colon)

vex is an expresion language, this gets translated to cvex in VOPS that cvan be compiled.

#include <math.h> = preprocessor directives

reprocessor directives are lines included in the code of programs preceded by a hash sign (#). These lines are not program statements but directives for the preprocessor. The preprocessor examines the code before actual compilation of code begins and resolves all these directives before any code is actually generated by regular statements.
frome -> https://www.cplusplus.com/doc/tutorial/preprocessor/

Attribute declaration is done using @ symbol. you need to pretend it with a explicit datatype like d,i,v,f,s,m,u...
After the @ there is an identifier or name of an attribute.

declaring an attribute = i@id;
defining an attribute = i@id = 1;
attributes can not be deleted in vex

list of dataypes:

float   =   f@height = v@P.y;
int     =   i@id = @ptnum;
vector  =   v@new_pos = v@P;
string  =   s@name = 'attribname'
dict    =   d@car_age = set('toyota', 1880, 'bmw', 1799, 'mercedes', 1805); 
            sidefx.com/docs/houdini/vex/dicts
            

vector2 =   u@uv = set(v@P.x, v@P.y);
vector4 =   p@attrib = quaternion({0,1,0}*rot);
matrix2 =   2@attrib = { {1,0}, {0,1} };
matrix3 =   3@attrib = { {1,0,0}, {0,1,0}, {0,0,1} };
matrix  =   4@orient = { {1,0,0,0}, {0,1,0,0}, {0,0,1,0}, {0,0,0,1} };

array   =   i[]@point_array;
struct  =   struct positions {vector pos_a, pos_b, pos_c; };
            sidefx.com/docs/houdini/vex/lang.html#structs

group   =   i@group_id = 1; || setpointgroup(0, 'id',@ptnum,1,'set');

list of global variables:

general geometry volumes shading inherited by copy to points
@ptnum @P @density @Vd @P
@numpt @N @ix, @iy, @iz @Alpha @pscale
@Time @v @center @uv @scale
@Frame @pscale @orig @Cs @N
@primnum @scale @size @Cr @up
@numprim @up @dPdx, @dPdy, @dPdz @Ct @orient
@vtxnum @orient @BB @Ce @rot
@numvtx @rot @rough @v
@trans @fresnel @trans
@transform @shadow @transform
@pivot @sbias @pivot
@lod
@rest
@force
@age
@life

tablesgenerator.com/markdown_tables
stephanosterburg.gitbook.io/scrapbook/untitled/popular-built-in-vex-attributes-global-variables

Individual attribute components can be accessed by using the subscript operator[]

x = v@P[0];
bmw_age = d@car_age['bmw'];

Or by using the dot operator. the dot operator can be used with "uv, xyz, rgba"

x = v@P.x;
x = v@P.r;
xx = 4@orient.xx;

The dot operator ban also be used to switch components.
pos = @P.zxy;


FXPHD class 2

functions

example: xyzdist function.

float  xyzdist(<geometry>geometry, vector origin)
float  xyzdist(<geometry>geometry, vector origin, int &prim, vector &uv)
...

There are multiple function definitions. that is called function overloading. this gives flexibility in what data we can get out with the information we have.

Arguments starting with & are special. these variables are passed by reference and will be overwritten on return. they act as an alias to other declared variables.
this bypasses the concept that functions can only return 1 output

attributes are stored on the geometry, variables are only stored locally. (They will be destroyed after the operation is complete.)

example: scatter points on moving character.
problem: every frame the point position and index move. we want for the points to stick to the geometry.
solution: scatter points on a static frame and interpolate the point position.

conditionals
A conditional statement allow to change the flow of the program by returning True of False.
In the case of vex, anything that isn't 0, will be True. if it is 0, it will return False.

one-liner
if(@ptnum%5) removepoint(0,@ptnum);

multi-line (using blocks{})
if(@ptnum%5!=0){
@group_pt = 1;
@Cd={1,0,0};
}

User interface controls
ch("float");
chi("int");
chv("vector");
chramp("channel_ramp", 1); <-- This creates a spline ramp. A colorramp has to be changed "in edit parameter interface".

tip: pcopen() and pcfilter() can create an attribute tranfer node.

tip: removepoint() expects 3 arguments.geohandle, point_number, 1 or 0 to remove prims)

typecasting= casting from 1 datatype to another.


full .hip file with popnet can be referenced here: "./fxphd_class2.hiplc"


## FXPHD class 3

note to self: learn OOP first.


## FXPHD class 4

Python in houdini
HOM (houdini object model)

houdini API

python can be written in:

python in houdini can manipulate nodes, the viewport, the interface (python states)

In the HOM, data is represented as objects.

so when you want to create a new object, it involves defining a class in python. when you create a class, you are basicallly defining a new datatype. everyhtin in pythin is an object, an integer, a matrix, a vector, a list.. they are all their own datatypes. so they have their own classers, with their fields ands attributes.
ex: if you us the append method on a list, you are using a method of the list class.

tip: python lists can store data of different dataypes. A python array can only store data from a single dataype.

tip: python convention says that classes have their first letter capitalized while functions, fields and methods and variables aren't.