Script Clips

You are here:

Points, Vertices and Primitives

POINTS :

• These are vector positions in 3d space only, standalone position in space. This only includes a position ( x ,y ,z , w ) and cant not connect anything together

VERTICES :

• A reference to a point that CAN connect something like a polygon. This will bind a primitive to a point.

PRIMITIVES :

• Polygon primitive - This is a polygon created by vertices.

ATTRIBUTE TYPES

 float f@attribute Decimal numbers : 1.2, 3.8 , 3.14 integer i@attribute Whole numbers like : 1,2,8,150 vector2 u@attribute 2 sets of numbers { x, y } vector (this is a 3 vector) v@attribute 3 sets of numbers { x, y, z } vector4 p@attribute 4 sets of numbers { r, g, b, a } matrix2 2@attribute 2 sets of 2 numbers { {a,b}, {c,d} } matrix3 3@attribute 3 sets of 3 numbers { {a,b,c}, {d,e,f}, {g,h,i} } matrix4 4@attribute { {a,b,c,d}, {e,f,g,h}, {i,j,k,l}, {m,n,o,p} } string s@attribute { 'the','cat', 'is', 'black' } the point id @ptnum total number of points @numpt current time, in seconds @Time current frame @Frame the primitive id @primnum the total number of primitives @numprim

ATTRIBUTES VALUES

• @ symbol is used to GET a attribute that can be seen in the geometry spreadsheet
• As above it is good practice to pre label your GET with a attribute type
• Example: @Cd = v@mycolor; This tells Houdini your attribute is a vector 3
• Example: @id = i@myid; This tells Houdini your attribute is a integer
 CODE TYPE MATH @P Point Position vector 3 @P.x Point Position channel float @N Normal vector 4 @Cd Color vector (Vector 3) @orient Orientation vector (Vector 3) @id ID number Integer @name Name String @anyattribute You can create your own any attribute type

IF

if ( statement ){    do something;    }  OR if ( statement ) function()

EXAMPLES

• if ( a > b ){ c==1 }

IF ELSE

if ( condition  ) {    do something if true;    } [else do something if false;]

EXAMPLES

• if ( a > b ){  c=c+1 } [else c=c-1];

DO LOOPS

DO LOOPS

do statement [while ( condition is true )];

EXAMPLES

• do a > b [while ( c > 1 )];

FOR LOOPS

for ( init number ; condition , change ) statement

EXAMPLES

• for (i , a > b, c)  c = c + 1;

FOR EACH

foreach ( value ; array) statement

foreach ( index, value; array ) statement

• This foreach index has a , not a ;

EXAMPLE

WHILE LOOP

while ( condition ) statement

EXAMPLE

while ( a > b ) c = c +1;

MATH

ShortCode

myvar = 50

myvar = myvar +10 // returns 60
myvar += 10 // returns 60

myvar = myvar - 10 // returns 40
myvar -= 10 // returns 40

myvar = myvar * 10 // returns 500
myvar *= 10 // returns 500

Increment/decrement

myvar++ // returns 51
myvar-- // returns 49

OR AND XOR

AND - &&
Logic checks for must also
if (a > b && a > c ){ c=c+1 }

OR - ||
Logic checks for can also
if (a > b || a > c ){ c=c+1 }

XOR - ^^
Logic check if one is true the other is false.
if (a > b ^^ a > c ){ c=c+1 }

CONDITIONAL - ?:
a > b ?  c=c+1 : c=c-1;

Is NOT - !

if (!a){ c=c+1 }

Equals or does Equal

Equals

@myvalue = 1;

Does Equal ( This is a condition check )

if (@myvalue == 1;) { do something };

ARRAYS

float array[];
int array[];
vector v , array[];
string str_array[];
EXAMPLE:
float decimalValues[]; [ 1.3, 0.2, 11.4, 3.0,5.9 ];
int intagerValues[]; [ 1, 2, 11, 3, 5 ];
vector v , vectorValues[]; { {1,2,3} {4,5,2} {11,8,3} };

ACCESSING ARRAYS

int intagerValues[]; [ 1, 2, 11, 8, 5 ];
int n = intagerValues[3]; // returns 8, this is get from start of an array
int n = intagerValues[-3]; // returns 11, this is get from the end of array

CHANNELS

ch() = UI component

@Cd = ch('myColor')

This creates a channel called myColor and can now be controlled via the UI

When creating custom channels you need to set the type

@Cd = ch('myColor') // Houdini already knows @Cd is a vector

i@myinteger = chi('setInteger') // notice the chi
f@myramp = chramp('setRamp') // notice the chramp this creates a ramp

FUNCTIONS

rand( seed )
Creates a random number between 0 and 1.

@randomNumber = rand(123); // might get a number like 0.2564
i@randomNumber = int( rand(123) * 100 ); // might get a number like 67

fit( value, oldmin, oldmax, newmin, newmax )
Fits a number into a new min and max range.

@randomNumber = int( rand(123) * 100 ); // returns 67.14348
@randomNumber = fit( @randomNumber , 0 , 100 , 0 , 1); // returns .6714348

length( vector )
Measures the length of a vector. Can be used for getting length of a force vector

length = length(v@myvector) // Could return 0.6

distance (vector, vector)
Measures the distance between two points

v@worldCenter = {0,0,0};
v@myPosition = {1,1,1};
distance = distance( v@worldCenter, v@myPosition) // Returns 1

normalize( value )
This normalizes a value 0 - 1

normalize ( 2458.25469) // Returns .2458

abs ( value )
Makes values positive

abs (-1234) // Returns 1234