# VexCheatSheet

A glossary of terms and stuff, more complete explainations are over on the HoudiniVex page, or more beginner level explainations on the JoyOfVex pages.

### Vex type prefixes

```// floats and integers
f@myfloat = 12.234; // float, vex assumes float if you don't specify prefix. Good if you're lazy, bad if you forget and mis-assign things!
i@myint = 5; // integer

// vectors
u@myvector2 = {0.6, 0.5}; // vector2 (2 floats)
v@myvector = {1,2,3}; // vector (3 floats)
p@myquat = {0,0,0,1}; // quaternion / vector4 / 4 floats

// matricies
2@mymatrix2 = {1,2,3,4}; // matrix2 (2x2 floats)
3@mymatrix3 = {1,2,3,4,5,6,7,8,9}; // matrix3 (3x3 floats)
4@mymatrix4 = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; // matrix (4x4 floats)

// strings and dictionaries
s@mystring = 'a string'; // string
d@mydict = {}; // dict, can only instantiate as empty type
d@mydict['key'] = 'value'; // can set values once instantiated
```

The sidefx documentation is here: https://www.sidefx.com/docs/houdini/vex/snippets.html#attributes

### Common attribute names

The ones I use a lot, more can often be found by opening a vop for various contexts and looking at the default global ins and outs, pulling apart sidefx nodes.

I've added prefix types here too. You don't need them, but its good practice, both to remind you what these attrib types are, and to avoid accidentally setting normal as a float or a transform as a quaternion. :)

```i@Frame; // current frame
f@Time; // current time in seconds
i@ptnum; // current point number
i@vtxnum; // current vertex number
i@primnum; // current prim number
i@elemnum; // handy morphing attribute; if you're in a point wrangle its ptnum, if in a vertex wrangle its @vtxnum, primwrangle @primnum.
i@numpt; // total number of points. both @ptnum and @numpt are integers, so if dividing, remember to cast @ptnum to a float
i@numvtx; // total number of verticies
i@numprim; // total number of prims

v@N; // the normal. If this hasn't been set, vex will calculate it for you just by calling it without initialised values
v@up; // a vector to control the spin around the normal when using instancing/copytopoints/etc
p@orient; // vector4 used as explicit rotation for instances
3@transform; // matrix3 used to control rotation and scale for instances
4@localtransform; // matrix (4x4) used for kinefx joints
f@pscale; // uniform scale for instances
v@scale; // XYZ scale control for instances

v@P; // current elements position. can be set for points, can be read for vertices and prims. Prims will guess the midpoint, not always reliable!
v@Cd; // diffuse colour

v@v; // velocity, used for rendering and simulation
v@w; // spin velocity used for rbd generally
v@force; // used in simulation for many solvers that don't like you to edit v directly, but v will be calculated after updating force
```

There's many attributes used by instancing/copytopoints, but I don't use them that often. You can find the full list and explainations at

### Crack transform and make transform defines

The cracktransform() and maketransform() functions use some obtuse integers to represent what the translate/rotate/scale order. Swalsch went and found them in math.h, here they are for quick reference:

```// Defines for the maketransform() VEX function.  The function takes two
// integer arguments which determine the order that the transform gets made.
#define XFORM_SRT    0    // Scale, Rotate, Translate
#define XFORM_STR    1    // Scale, Translate, Rotate
#define XFORM_RST    2    // Rotate, Scale, Translate
#define XFORM_RTS    3    // Rotate, Translate, Scale
#define XFORM_TSR    4    // Translate, Scale, Rotate
#define XFORM_TRS    5    // Translate, Rotate, Scale

#define XFORM_XYZ    0    // Rotate order X, Y, Z
#define XFORM_XZY    1    // Rotate order X, Z, Y
#define XFORM_YXZ    2    // Rotate order Y, X, Z
#define XFORM_YZX    3    // Rotate order Y, Z, X
#define XFORM_ZXY    4    // Rotate order Z, X, Y
#define XFORM_ZYX    5    // Rotate order Z, Y, X
```

### Lops attrib conversion

```@P => points
@N => normals
@v => velocities
@w => angularVelocities
@accel => accelerations
@id => ids
@uv => primvars:st
@Cd => primvars:displayColor
@Alpha => primvars:displayOpacity
@width,@widths,@pscale =>  widths
```